pdf.worker.js 1.1 MB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232312333123431235312363123731238312393124031241312423124331244312453124631247312483124931250312513125231253312543125531256312573125831259312603126131262312633126431265312663126731268312693127031271312723127331274312753127631277312783127931280312813128231283312843128531286312873128831289312903129131292312933129431295312963129731298312993130031301313023130331304313053130631307313083130931310313113131231313313143131531316313173131831319313203132131322313233132431325313263132731328313293133031331313323133331334313353133631337313383133931340313413134231343313443134531346313473134831349313503135131352313533135431355313563135731358313593136031361313623136331364313653136631367313683136931370313713137231373313743137531376313773137831379313803138131382313833138431385313863138731388313893139031391313923139331394313953139631397313983139931400314013140231403314043140531406314073140831409314103141131412314133141431415314163141731418314193142031421314223142331424314253142631427314283142931430314313143231433314343143531436314373143831439314403144131442314433144431445314463144731448314493145031451314523145331454314553145631457314583145931460314613146231463314643146531466314673146831469314703147131472314733147431475314763147731478314793148031481314823148331484314853148631487314883148931490314913149231493314943149531496314973149831499315003150131502315033150431505315063150731508315093151031511315123151331514315153151631517315183151931520315213152231523315243152531526315273152831529315303153131532315333153431535315363153731538315393154031541315423154331544315453154631547315483154931550315513155231553315543155531556315573155831559315603156131562315633156431565315663156731568315693157031571315723157331574315753157631577315783157931580315813158231583315843158531586315873158831589315903159131592315933159431595315963159731598315993160031601316023160331604316053160631607316083160931610316113161231613316143161531616316173161831619316203162131622316233162431625316263162731628316293163031631316323163331634316353163631637316383163931640316413164231643316443164531646316473164831649316503165131652316533165431655316563165731658316593166031661316623166331664316653166631667316683166931670316713167231673316743167531676316773167831679316803168131682316833168431685316863168731688316893169031691316923169331694316953169631697316983169931700317013170231703317043170531706317073170831709317103171131712317133171431715317163171731718317193172031721317223172331724317253172631727317283172931730317313173231733317343173531736317373173831739317403174131742317433174431745317463174731748317493175031751317523175331754317553175631757317583175931760317613176231763317643176531766317673176831769317703177131772317733177431775317763177731778317793178031781317823178331784317853178631787317883178931790317913179231793317943179531796317973179831799318003180131802318033180431805318063180731808318093181031811318123181331814318153181631817318183181931820318213182231823318243182531826318273182831829318303183131832318333183431835318363183731838318393184031841318423184331844318453184631847318483184931850318513185231853318543185531856318573185831859318603186131862318633186431865318663186731868318693187031871318723187331874318753187631877318783187931880318813188231883318843188531886318873188831889318903189131892318933189431895318963189731898318993190031901319023190331904319053190631907319083190931910319113191231913319143191531916319173191831919319203192131922319233192431925319263192731928319293193031931319323193331934319353193631937319383193931940319413194231943319443194531946319473194831949319503195131952319533195431955319563195731958319593196031961319623196331964319653196631967319683196931970319713197231973319743197531976319773197831979319803198131982319833198431985319863198731988319893199031991319923199331994319953199631997319983199932000320013200232003320043200532006320073200832009320103201132012320133201432015320163201732018320193202032021320223202332024320253202632027320283202932030320313203232033320343203532036320373203832039320403204132042320433204432045320463204732048320493205032051320523205332054320553205632057320583205932060320613206232063320643206532066320673206832069320703207132072320733207432075320763207732078320793208032081320823208332084320853208632087320883208932090320913209232093320943209532096320973209832099321003210132102321033210432105321063210732108321093211032111321123211332114321153211632117321183211932120321213212232123321243212532126321273212832129321303213132132321333213432135321363213732138321393214032141321423214332144321453214632147321483214932150321513215232153321543215532156321573215832159321603216132162321633216432165321663216732168321693217032171321723217332174321753217632177321783217932180321813218232183321843218532186321873218832189321903219132192321933219432195321963219732198321993220032201322023220332204322053220632207322083220932210322113221232213322143221532216322173221832219322203222132222322233222432225322263222732228322293223032231322323223332234322353223632237322383223932240322413224232243322443224532246322473224832249322503225132252322533225432255322563225732258322593226032261322623226332264322653226632267322683226932270322713227232273322743227532276322773227832279322803228132282322833228432285322863228732288322893229032291322923229332294322953229632297322983229932300323013230232303323043230532306323073230832309323103231132312323133231432315323163231732318323193232032321323223232332324323253232632327323283232932330323313233232333323343233532336323373233832339323403234132342323433234432345323463234732348323493235032351323523235332354323553235632357323583235932360323613236232363323643236532366323673236832369323703237132372323733237432375323763237732378323793238032381323823238332384323853238632387323883238932390323913239232393323943239532396323973239832399324003240132402324033240432405324063240732408324093241032411324123241332414324153241632417324183241932420324213242232423324243242532426324273242832429324303243132432324333243432435324363243732438324393244032441324423244332444324453244632447324483244932450324513245232453324543245532456324573245832459324603246132462324633246432465324663246732468324693247032471324723247332474324753247632477324783247932480324813248232483324843248532486324873248832489324903249132492324933249432495324963249732498324993250032501325023250332504325053250632507325083250932510325113251232513325143251532516325173251832519325203252132522325233252432525325263252732528325293253032531325323253332534325353253632537325383253932540325413254232543325443254532546325473254832549325503255132552325533255432555325563255732558325593256032561325623256332564325653256632567325683256932570325713257232573325743257532576325773257832579325803258132582325833258432585325863258732588325893259032591325923259332594325953259632597325983259932600326013260232603326043260532606326073260832609326103261132612326133261432615326163261732618326193262032621326223262332624326253262632627326283262932630326313263232633326343263532636326373263832639326403264132642326433264432645326463264732648326493265032651326523265332654326553265632657326583265932660326613266232663326643266532666326673266832669326703267132672326733267432675326763267732678326793268032681326823268332684326853268632687326883268932690326913269232693326943269532696326973269832699327003270132702327033270432705327063270732708327093271032711327123271332714327153271632717327183271932720327213272232723327243272532726327273272832729327303273132732327333273432735327363273732738327393274032741327423274332744327453274632747327483274932750327513275232753327543275532756327573275832759327603276132762327633276432765327663276732768327693277032771327723277332774327753277632777327783277932780327813278232783327843278532786327873278832789327903279132792327933279432795327963279732798327993280032801328023280332804328053280632807328083280932810328113281232813328143281532816328173281832819328203282132822328233282432825328263282732828328293283032831328323283332834328353283632837328383283932840328413284232843328443284532846328473284832849328503285132852328533285432855328563285732858328593286032861328623286332864328653286632867328683286932870328713287232873328743287532876328773287832879328803288132882328833288432885328863288732888328893289032891328923289332894328953289632897328983289932900329013290232903329043290532906329073290832909329103291132912329133291432915329163291732918329193292032921329223292332924329253292632927329283292932930329313293232933329343293532936329373293832939329403294132942329433294432945329463294732948329493295032951329523295332954329553295632957329583295932960329613296232963329643296532966329673296832969329703297132972329733297432975329763297732978329793298032981329823298332984329853298632987329883298932990329913299232993329943299532996329973299832999330003300133002330033300433005330063300733008330093301033011330123301333014330153301633017330183301933020330213302233023330243302533026330273302833029330303303133032330333303433035330363303733038330393304033041330423304333044330453304633047330483304933050330513305233053330543305533056330573305833059330603306133062330633306433065330663306733068330693307033071330723307333074330753307633077330783307933080330813308233083330843308533086330873308833089330903309133092330933309433095330963309733098330993310033101331023310333104331053310633107331083310933110331113311233113331143311533116331173311833119331203312133122331233312433125331263312733128331293313033131331323313333134331353313633137331383313933140331413314233143331443314533146331473314833149331503315133152331533315433155331563315733158331593316033161331623316333164331653316633167331683316933170331713317233173331743317533176331773317833179331803318133182331833318433185331863318733188331893319033191331923319333194331953319633197331983319933200332013320233203332043320533206332073320833209332103321133212332133321433215332163321733218332193322033221332223322333224332253322633227332283322933230332313323233233332343323533236332373323833239332403324133242332433324433245332463324733248332493325033251332523325333254332553325633257332583325933260332613326233263332643326533266332673326833269332703327133272332733327433275332763327733278332793328033281332823328333284332853328633287332883328933290332913329233293332943329533296332973329833299333003330133302333033330433305333063330733308333093331033311333123331333314333153331633317333183331933320333213332233323333243332533326333273332833329333303333133332333333333433335333363333733338333393334033341333423334333344333453334633347333483334933350333513335233353333543335533356333573335833359333603336133362333633336433365333663336733368333693337033371333723337333374333753337633377333783337933380333813338233383333843338533386333873338833389333903339133392333933339433395333963339733398333993340033401334023340333404334053340633407334083340933410334113341233413334143341533416334173341833419334203342133422334233342433425334263342733428334293343033431334323343333434334353343633437334383343933440334413344233443334443344533446334473344833449334503345133452334533345433455334563345733458334593346033461334623346333464334653346633467334683346933470334713347233473334743347533476334773347833479334803348133482334833348433485334863348733488334893349033491334923349333494334953349633497334983349933500335013350233503335043350533506335073350833509335103351133512335133351433515335163351733518335193352033521335223352333524335253352633527335283352933530335313353233533335343353533536335373353833539335403354133542335433354433545335463354733548335493355033551335523355333554335553355633557335583355933560335613356233563335643356533566335673356833569335703357133572335733357433575335763357733578335793358033581335823358333584335853358633587335883358933590335913359233593335943359533596335973359833599336003360133602336033360433605336063360733608336093361033611336123361333614336153361633617336183361933620336213362233623336243362533626336273362833629336303363133632336333363433635336363363733638336393364033641336423364333644336453364633647336483364933650336513365233653336543365533656336573365833659336603366133662336633366433665336663366733668336693367033671336723367333674336753367633677336783367933680336813368233683336843368533686336873368833689336903369133692336933369433695336963369733698336993370033701337023370333704337053370633707337083370933710337113371233713337143371533716337173371833719337203372133722337233372433725337263372733728337293373033731337323373333734337353373633737337383373933740337413374233743337443374533746337473374833749337503375133752337533375433755337563375733758337593376033761337623376333764337653376633767337683376933770337713377233773337743377533776337773377833779337803378133782337833378433785337863378733788337893379033791337923379333794337953379633797337983379933800338013380233803338043380533806338073380833809338103381133812338133381433815338163381733818338193382033821338223382333824338253382633827338283382933830338313383233833338343383533836338373383833839338403384133842338433384433845338463384733848338493385033851338523385333854338553385633857338583385933860338613386233863338643386533866338673386833869338703387133872338733387433875338763387733878338793388033881338823388333884338853388633887338883388933890338913389233893338943389533896338973389833899339003390133902339033390433905339063390733908339093391033911339123391333914339153391633917339183391933920339213392233923339243392533926339273392833929339303393133932339333393433935339363393733938339393394033941339423394333944339453394633947339483394933950339513395233953339543395533956339573395833959339603396133962339633396433965339663396733968339693397033971339723397333974339753397633977339783397933980339813398233983339843398533986339873398833989339903399133992339933399433995339963399733998339993400034001340023400334004340053400634007340083400934010340113401234013340143401534016340173401834019340203402134022340233402434025340263402734028340293403034031340323403334034340353403634037340383403934040340413404234043340443404534046340473404834049340503405134052340533405434055340563405734058340593406034061340623406334064340653406634067340683406934070340713407234073340743407534076340773407834079340803408134082340833408434085340863408734088340893409034091340923409334094340953409634097340983409934100341013410234103341043410534106341073410834109341103411134112341133411434115341163411734118341193412034121341223412334124341253412634127341283412934130341313413234133341343413534136341373413834139341403414134142341433414434145341463414734148341493415034151341523415334154341553415634157341583415934160341613416234163341643416534166341673416834169341703417134172341733417434175341763417734178341793418034181341823418334184341853418634187341883418934190341913419234193341943419534196341973419834199342003420134202342033420434205342063420734208342093421034211342123421334214342153421634217342183421934220342213422234223342243422534226342273422834229342303423134232342333423434235342363423734238342393424034241342423424334244342453424634247342483424934250342513425234253342543425534256342573425834259342603426134262342633426434265342663426734268342693427034271342723427334274342753427634277342783427934280342813428234283342843428534286342873428834289342903429134292342933429434295342963429734298342993430034301343023430334304343053430634307343083430934310343113431234313343143431534316343173431834319343203432134322343233432434325343263432734328343293433034331343323433334334343353433634337343383433934340343413434234343343443434534346343473434834349343503435134352343533435434355343563435734358343593436034361343623436334364343653436634367343683436934370343713437234373343743437534376343773437834379343803438134382343833438434385343863438734388343893439034391343923439334394343953439634397343983439934400344013440234403344043440534406344073440834409344103441134412344133441434415344163441734418344193442034421344223442334424344253442634427344283442934430344313443234433344343443534436344373443834439344403444134442344433444434445344463444734448344493445034451344523445334454344553445634457344583445934460344613446234463344643446534466344673446834469344703447134472344733447434475344763447734478344793448034481344823448334484344853448634487344883448934490344913449234493344943449534496344973449834499345003450134502345033450434505345063450734508345093451034511345123451334514345153451634517345183451934520345213452234523345243452534526345273452834529345303453134532345333453434535345363453734538345393454034541345423454334544345453454634547345483454934550345513455234553345543455534556345573455834559345603456134562345633456434565345663456734568345693457034571345723457334574345753457634577345783457934580345813458234583345843458534586345873458834589345903459134592345933459434595345963459734598345993460034601346023460334604346053460634607346083460934610346113461234613346143461534616346173461834619346203462134622346233462434625346263462734628346293463034631346323463334634346353463634637346383463934640346413464234643346443464534646346473464834649346503465134652346533465434655346563465734658346593466034661346623466334664346653466634667346683466934670346713467234673346743467534676346773467834679346803468134682346833468434685346863468734688346893469034691346923469334694346953469634697346983469934700347013470234703347043470534706347073470834709347103471134712347133471434715347163471734718347193472034721347223472334724347253472634727347283472934730347313473234733347343473534736347373473834739347403474134742347433474434745347463474734748347493475034751347523475334754347553475634757347583475934760347613476234763347643476534766347673476834769347703477134772347733477434775347763477734778347793478034781347823478334784347853478634787347883478934790347913479234793347943479534796347973479834799348003480134802348033480434805348063480734808348093481034811348123481334814348153481634817348183481934820348213482234823348243482534826348273482834829348303483134832348333483434835348363483734838348393484034841348423484334844348453484634847348483484934850348513485234853348543485534856348573485834859348603486134862348633486434865348663486734868348693487034871348723487334874348753487634877348783487934880348813488234883348843488534886348873488834889348903489134892348933489434895348963489734898348993490034901349023490334904349053490634907349083490934910349113491234913349143491534916349173491834919349203492134922349233492434925349263492734928349293493034931349323493334934349353493634937349383493934940349413494234943349443494534946349473494834949349503495134952349533495434955349563495734958349593496034961349623496334964349653496634967349683496934970349713497234973349743497534976349773497834979349803498134982349833498434985349863498734988349893499034991349923499334994349953499634997349983499935000350013500235003350043500535006350073500835009350103501135012350133501435015350163501735018350193502035021350223502335024350253502635027350283502935030350313503235033350343503535036350373503835039350403504135042350433504435045350463504735048350493505035051350523505335054350553505635057350583505935060350613506235063350643506535066350673506835069350703507135072350733507435075350763507735078350793508035081350823508335084350853508635087350883508935090350913509235093350943509535096350973509835099351003510135102351033510435105351063510735108351093511035111351123511335114351153511635117351183511935120351213512235123351243512535126351273512835129351303513135132351333513435135351363513735138351393514035141351423514335144351453514635147351483514935150351513515235153351543515535156351573515835159351603516135162351633516435165351663516735168351693517035171351723517335174351753517635177351783517935180351813518235183351843518535186351873518835189351903519135192351933519435195351963519735198351993520035201352023520335204352053520635207352083520935210352113521235213352143521535216352173521835219352203522135222352233522435225352263522735228352293523035231352323523335234352353523635237352383523935240352413524235243352443524535246352473524835249352503525135252352533525435255352563525735258352593526035261352623526335264352653526635267352683526935270352713527235273352743527535276352773527835279352803528135282352833528435285352863528735288352893529035291352923529335294352953529635297352983529935300353013530235303353043530535306353073530835309353103531135312353133531435315353163531735318353193532035321353223532335324353253532635327353283532935330353313533235333353343533535336353373533835339353403534135342353433534435345353463534735348353493535035351353523535335354353553535635357353583535935360353613536235363353643536535366353673536835369353703537135372353733537435375353763537735378353793538035381353823538335384353853538635387353883538935390353913539235393353943539535396353973539835399354003540135402354033540435405354063540735408354093541035411354123541335414354153541635417354183541935420354213542235423354243542535426354273542835429354303543135432354333543435435354363543735438354393544035441354423544335444354453544635447354483544935450354513545235453354543545535456354573545835459354603546135462354633546435465354663546735468354693547035471354723547335474354753547635477354783547935480354813548235483354843548535486354873548835489354903549135492354933549435495354963549735498354993550035501355023550335504355053550635507355083550935510355113551235513355143551535516355173551835519355203552135522355233552435525355263552735528355293553035531355323553335534355353553635537355383553935540355413554235543355443554535546355473554835549355503555135552355533555435555355563555735558355593556035561355623556335564355653556635567355683556935570355713557235573355743557535576355773557835579355803558135582355833558435585355863558735588355893559035591355923559335594355953559635597355983559935600356013560235603356043560535606356073560835609356103561135612356133561435615356163561735618356193562035621356223562335624356253562635627356283562935630356313563235633356343563535636356373563835639356403564135642356433564435645356463564735648356493565035651356523565335654356553565635657356583565935660356613566235663356643566535666356673566835669356703567135672356733567435675356763567735678356793568035681356823568335684356853568635687356883568935690356913569235693356943569535696356973569835699357003570135702357033570435705357063570735708357093571035711357123571335714357153571635717357183571935720357213572235723357243572535726357273572835729357303573135732357333573435735357363573735738357393574035741357423574335744357453574635747357483574935750357513575235753357543575535756357573575835759357603576135762357633576435765357663576735768357693577035771357723577335774357753577635777357783577935780357813578235783357843578535786357873578835789357903579135792357933579435795357963579735798357993580035801358023580335804358053580635807358083580935810358113581235813358143581535816358173581835819358203582135822358233582435825358263582735828358293583035831358323583335834358353583635837358383583935840358413584235843358443584535846358473584835849358503585135852358533585435855358563585735858358593586035861358623586335864358653586635867358683586935870358713587235873358743587535876358773587835879358803588135882358833588435885358863588735888358893589035891358923589335894358953589635897358983589935900359013590235903359043590535906359073590835909359103591135912359133591435915359163591735918359193592035921359223592335924359253592635927359283592935930359313593235933359343593535936359373593835939359403594135942359433594435945359463594735948359493595035951359523595335954359553595635957359583595935960359613596235963359643596535966359673596835969359703597135972359733597435975359763597735978359793598035981359823598335984359853598635987359883598935990359913599235993359943599535996359973599835999360003600136002360033600436005360063600736008360093601036011360123601336014360153601636017360183601936020360213602236023360243602536026360273602836029360303603136032360333603436035360363603736038360393604036041360423604336044360453604636047360483604936050360513605236053360543605536056360573605836059360603606136062360633606436065360663606736068360693607036071360723607336074360753607636077360783607936080360813608236083360843608536086360873608836089360903609136092360933609436095360963609736098360993610036101361023610336104361053610636107361083610936110361113611236113361143611536116361173611836119361203612136122361233612436125361263612736128361293613036131361323613336134361353613636137361383613936140361413614236143361443614536146361473614836149361503615136152361533615436155361563615736158361593616036161361623616336164361653616636167361683616936170361713617236173361743617536176361773617836179361803618136182361833618436185361863618736188361893619036191361923619336194361953619636197361983619936200362013620236203362043620536206362073620836209362103621136212362133621436215362163621736218362193622036221362223622336224362253622636227362283622936230362313623236233362343623536236362373623836239362403624136242362433624436245362463624736248362493625036251362523625336254362553625636257362583625936260362613626236263362643626536266362673626836269362703627136272362733627436275362763627736278362793628036281362823628336284362853628636287362883628936290362913629236293362943629536296362973629836299363003630136302363033630436305363063630736308363093631036311363123631336314363153631636317363183631936320363213632236323363243632536326363273632836329363303633136332363333633436335363363633736338363393634036341363423634336344363453634636347363483634936350363513635236353363543635536356363573635836359363603636136362363633636436365363663636736368363693637036371363723637336374363753637636377363783637936380363813638236383363843638536386363873638836389363903639136392363933639436395363963639736398363993640036401364023640336404364053640636407364083640936410364113641236413364143641536416364173641836419364203642136422364233642436425364263642736428364293643036431364323643336434364353643636437364383643936440364413644236443364443644536446364473644836449364503645136452364533645436455364563645736458364593646036461364623646336464364653646636467364683646936470364713647236473364743647536476364773647836479364803648136482364833648436485364863648736488364893649036491364923649336494364953649636497364983649936500365013650236503365043650536506365073650836509365103651136512365133651436515365163651736518365193652036521365223652336524365253652636527365283652936530365313653236533365343653536536365373653836539365403654136542365433654436545365463654736548365493655036551365523655336554365553655636557365583655936560365613656236563365643656536566365673656836569365703657136572365733657436575365763657736578365793658036581365823658336584365853658636587365883658936590365913659236593365943659536596365973659836599366003660136602366033660436605366063660736608366093661036611366123661336614366153661636617366183661936620366213662236623366243662536626366273662836629366303663136632366333663436635366363663736638366393664036641366423664336644366453664636647366483664936650366513665236653366543665536656366573665836659366603666136662366633666436665366663666736668366693667036671366723667336674366753667636677366783667936680366813668236683366843668536686366873668836689366903669136692366933669436695366963669736698366993670036701367023670336704367053670636707367083670936710367113671236713367143671536716367173671836719367203672136722367233672436725367263672736728367293673036731367323673336734367353673636737367383673936740367413674236743367443674536746367473674836749367503675136752367533675436755367563675736758367593676036761367623676336764367653676636767367683676936770367713677236773367743677536776367773677836779367803678136782367833678436785367863678736788367893679036791367923679336794367953679636797367983679936800368013680236803368043680536806368073680836809368103681136812368133681436815368163681736818368193682036821368223682336824368253682636827368283682936830368313683236833368343683536836368373683836839368403684136842368433684436845368463684736848368493685036851368523685336854368553685636857368583685936860368613686236863368643686536866368673686836869368703687136872368733687436875368763687736878368793688036881368823688336884368853688636887368883688936890368913689236893368943689536896368973689836899369003690136902369033690436905369063690736908369093691036911369123691336914369153691636917369183691936920369213692236923369243692536926369273692836929369303693136932369333693436935369363693736938369393694036941369423694336944369453694636947369483694936950369513695236953369543695536956369573695836959369603696136962369633696436965369663696736968369693697036971369723697336974369753697636977369783697936980369813698236983369843698536986369873698836989369903699136992369933699436995369963699736998369993700037001370023700337004370053700637007370083700937010370113701237013370143701537016370173701837019370203702137022370233702437025370263702737028370293703037031370323703337034370353703637037370383703937040370413704237043370443704537046370473704837049370503705137052370533705437055370563705737058370593706037061370623706337064370653706637067370683706937070370713707237073370743707537076370773707837079370803708137082370833708437085370863708737088370893709037091370923709337094370953709637097370983709937100371013710237103371043710537106371073710837109371103711137112371133711437115371163711737118371193712037121371223712337124371253712637127371283712937130371313713237133371343713537136371373713837139371403714137142371433714437145371463714737148371493715037151
  1. /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
  3. /* Copyright 2012 Mozilla Foundation
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. /*jshint globalstrict: false */
  18. /* globals PDFJS */
  19. // Initializing PDFJS global object (if still undefined)
  20. if (typeof PDFJS === 'undefined') {
  21. (typeof window !== 'undefined' ? window : this).PDFJS = {};
  22. }
  23. PDFJS.version = '1.0.529';
  24. PDFJS.build = '6d6e09b';
  25. (function pdfjsWrapper() {
  26. // Use strict in our context only - users might not want it
  27. 'use strict';
  28. /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  29. /* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
  30. /* Copyright 2012 Mozilla Foundation
  31. *
  32. * Licensed under the Apache License, Version 2.0 (the "License");
  33. * you may not use this file except in compliance with the License.
  34. * You may obtain a copy of the License at
  35. *
  36. * http://www.apache.org/licenses/LICENSE-2.0
  37. *
  38. * Unless required by applicable law or agreed to in writing, software
  39. * distributed under the License is distributed on an "AS IS" BASIS,
  40. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  41. * See the License for the specific language governing permissions and
  42. * limitations under the License.
  43. */
  44. /* globals Cmd, ColorSpace, Dict, MozBlobBuilder, Name, PDFJS, Ref, URL,
  45. Promise */
  46. 'use strict';
  47. var globalScope = (typeof window === 'undefined') ? this : window;
  48. var isWorker = (typeof window == 'undefined');
  49. var FONT_IDENTITY_MATRIX = [0.001, 0, 0, 0.001, 0, 0];
  50. var TextRenderingMode = {
  51. FILL: 0,
  52. STROKE: 1,
  53. FILL_STROKE: 2,
  54. INVISIBLE: 3,
  55. FILL_ADD_TO_PATH: 4,
  56. STROKE_ADD_TO_PATH: 5,
  57. FILL_STROKE_ADD_TO_PATH: 6,
  58. ADD_TO_PATH: 7,
  59. FILL_STROKE_MASK: 3,
  60. ADD_TO_PATH_FLAG: 4
  61. };
  62. var ImageKind = {
  63. GRAYSCALE_1BPP: 1,
  64. RGB_24BPP: 2,
  65. RGBA_32BPP: 3
  66. };
  67. var AnnotationType = {
  68. WIDGET: 1,
  69. TEXT: 2,
  70. LINK: 3
  71. };
  72. var StreamType = {
  73. UNKNOWN: 0,
  74. FLATE: 1,
  75. LZW: 2,
  76. DCT: 3,
  77. JPX: 4,
  78. JBIG: 5,
  79. A85: 6,
  80. AHX: 7,
  81. CCF: 8,
  82. RL: 9
  83. };
  84. var FontType = {
  85. UNKNOWN: 0,
  86. TYPE1: 1,
  87. TYPE1C: 2,
  88. CIDFONTTYPE0: 3,
  89. CIDFONTTYPE0C: 4,
  90. TRUETYPE: 5,
  91. CIDFONTTYPE2: 6,
  92. TYPE3: 7,
  93. OPENTYPE: 8,
  94. TYPE0: 9,
  95. MMTYPE1: 10
  96. };
  97. // The global PDFJS object exposes the API
  98. // In production, it will be declared outside a global wrapper
  99. // In development, it will be declared here
  100. if (!globalScope.PDFJS) {
  101. globalScope.PDFJS = {};
  102. }
  103. globalScope.PDFJS.pdfBug = false;
  104. PDFJS.VERBOSITY_LEVELS = {
  105. errors: 0,
  106. warnings: 1,
  107. infos: 5
  108. };
  109. // All the possible operations for an operator list.
  110. var OPS = PDFJS.OPS = {
  111. // Intentionally start from 1 so it is easy to spot bad operators that will be
  112. // 0's.
  113. dependency: 1,
  114. setLineWidth: 2,
  115. setLineCap: 3,
  116. setLineJoin: 4,
  117. setMiterLimit: 5,
  118. setDash: 6,
  119. setRenderingIntent: 7,
  120. setFlatness: 8,
  121. setGState: 9,
  122. save: 10,
  123. restore: 11,
  124. transform: 12,
  125. moveTo: 13,
  126. lineTo: 14,
  127. curveTo: 15,
  128. curveTo2: 16,
  129. curveTo3: 17,
  130. closePath: 18,
  131. rectangle: 19,
  132. stroke: 20,
  133. closeStroke: 21,
  134. fill: 22,
  135. eoFill: 23,
  136. fillStroke: 24,
  137. eoFillStroke: 25,
  138. closeFillStroke: 26,
  139. closeEOFillStroke: 27,
  140. endPath: 28,
  141. clip: 29,
  142. eoClip: 30,
  143. beginText: 31,
  144. endText: 32,
  145. setCharSpacing: 33,
  146. setWordSpacing: 34,
  147. setHScale: 35,
  148. setLeading: 36,
  149. setFont: 37,
  150. setTextRenderingMode: 38,
  151. setTextRise: 39,
  152. moveText: 40,
  153. setLeadingMoveText: 41,
  154. setTextMatrix: 42,
  155. nextLine: 43,
  156. showText: 44,
  157. showSpacedText: 45,
  158. nextLineShowText: 46,
  159. nextLineSetSpacingShowText: 47,
  160. setCharWidth: 48,
  161. setCharWidthAndBounds: 49,
  162. setStrokeColorSpace: 50,
  163. setFillColorSpace: 51,
  164. setStrokeColor: 52,
  165. setStrokeColorN: 53,
  166. setFillColor: 54,
  167. setFillColorN: 55,
  168. setStrokeGray: 56,
  169. setFillGray: 57,
  170. setStrokeRGBColor: 58,
  171. setFillRGBColor: 59,
  172. setStrokeCMYKColor: 60,
  173. setFillCMYKColor: 61,
  174. shadingFill: 62,
  175. beginInlineImage: 63,
  176. beginImageData: 64,
  177. endInlineImage: 65,
  178. paintXObject: 66,
  179. markPoint: 67,
  180. markPointProps: 68,
  181. beginMarkedContent: 69,
  182. beginMarkedContentProps: 70,
  183. endMarkedContent: 71,
  184. beginCompat: 72,
  185. endCompat: 73,
  186. paintFormXObjectBegin: 74,
  187. paintFormXObjectEnd: 75,
  188. beginGroup: 76,
  189. endGroup: 77,
  190. beginAnnotations: 78,
  191. endAnnotations: 79,
  192. beginAnnotation: 80,
  193. endAnnotation: 81,
  194. paintJpegXObject: 82,
  195. paintImageMaskXObject: 83,
  196. paintImageMaskXObjectGroup: 84,
  197. paintImageXObject: 85,
  198. paintInlineImageXObject: 86,
  199. paintInlineImageXObjectGroup: 87,
  200. paintImageXObjectRepeat: 88,
  201. paintImageMaskXObjectRepeat: 89,
  202. paintSolidColorImageMask: 90,
  203. constructPath: 91
  204. };
  205. // A notice for devs. These are good for things that are helpful to devs, such
  206. // as warning that Workers were disabled, which is important to devs but not
  207. // end users.
  208. function info(msg) {
  209. if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.infos) {
  210. console.log('Info: ' + msg);
  211. }
  212. }
  213. // Non-fatal warnings.
  214. function warn(msg) {
  215. if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.warnings) {
  216. console.log('Warning: ' + msg);
  217. }
  218. }
  219. // Fatal errors that should trigger the fallback UI and halt execution by
  220. // throwing an exception.
  221. function error(msg) {
  222. // If multiple arguments were passed, pass them all to the log function.
  223. if (arguments.length > 1) {
  224. var logArguments = ['Error:'];
  225. logArguments.push.apply(logArguments, arguments);
  226. console.log.apply(console, logArguments);
  227. // Join the arguments into a single string for the lines below.
  228. msg = [].join.call(arguments, ' ');
  229. } else {
  230. console.log('Error: ' + msg);
  231. }
  232. console.log(backtrace());
  233. UnsupportedManager.notify(UNSUPPORTED_FEATURES.unknown);
  234. throw new Error(msg);
  235. }
  236. function backtrace() {
  237. try {
  238. throw new Error();
  239. } catch (e) {
  240. return e.stack ? e.stack.split('\n').slice(2).join('\n') : '';
  241. }
  242. }
  243. function assert(cond, msg) {
  244. if (!cond) {
  245. error(msg);
  246. }
  247. }
  248. var UNSUPPORTED_FEATURES = PDFJS.UNSUPPORTED_FEATURES = {
  249. unknown: 'unknown',
  250. forms: 'forms',
  251. javaScript: 'javaScript',
  252. smask: 'smask',
  253. shadingPattern: 'shadingPattern',
  254. font: 'font'
  255. };
  256. var UnsupportedManager = PDFJS.UnsupportedManager =
  257. (function UnsupportedManagerClosure() {
  258. var listeners = [];
  259. return {
  260. listen: function (cb) {
  261. listeners.push(cb);
  262. },
  263. notify: function (featureId) {
  264. warn('Unsupported feature "' + featureId + '"');
  265. for (var i = 0, ii = listeners.length; i < ii; i++) {
  266. listeners[i](featureId);
  267. }
  268. }
  269. };
  270. })();
  271. // Combines two URLs. The baseUrl shall be absolute URL. If the url is an
  272. // absolute URL, it will be returned as is.
  273. function combineUrl(baseUrl, url) {
  274. if (!url) {
  275. return baseUrl;
  276. }
  277. if (/^[a-z][a-z0-9+\-.]*:/i.test(url)) {
  278. return url;
  279. }
  280. var i;
  281. if (url.charAt(0) == '/') {
  282. // absolute path
  283. i = baseUrl.indexOf('://');
  284. if (url.charAt(1) === '/') {
  285. ++i;
  286. } else {
  287. i = baseUrl.indexOf('/', i + 3);
  288. }
  289. return baseUrl.substring(0, i) + url;
  290. } else {
  291. // relative path
  292. var pathLength = baseUrl.length;
  293. i = baseUrl.lastIndexOf('#');
  294. pathLength = i >= 0 ? i : pathLength;
  295. i = baseUrl.lastIndexOf('?', pathLength);
  296. pathLength = i >= 0 ? i : pathLength;
  297. var prefixLength = baseUrl.lastIndexOf('/', pathLength);
  298. return baseUrl.substring(0, prefixLength + 1) + url;
  299. }
  300. }
  301. // Validates if URL is safe and allowed, e.g. to avoid XSS.
  302. function isValidUrl(url, allowRelative) {
  303. if (!url) {
  304. return false;
  305. }
  306. // RFC 3986 (http://tools.ietf.org/html/rfc3986#section-3.1)
  307. // scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
  308. var protocol = /^[a-z][a-z0-9+\-.]*(?=:)/i.exec(url);
  309. if (!protocol) {
  310. return allowRelative;
  311. }
  312. protocol = protocol[0].toLowerCase();
  313. switch (protocol) {
  314. case 'http':
  315. case 'https':
  316. case 'ftp':
  317. case 'mailto':
  318. return true;
  319. default:
  320. return false;
  321. }
  322. }
  323. PDFJS.isValidUrl = isValidUrl;
  324. function shadow(obj, prop, value) {
  325. Object.defineProperty(obj, prop, { value: value,
  326. enumerable: true,
  327. configurable: true,
  328. writable: false });
  329. return value;
  330. }
  331. var PasswordResponses = PDFJS.PasswordResponses = {
  332. NEED_PASSWORD: 1,
  333. INCORRECT_PASSWORD: 2
  334. };
  335. var PasswordException = (function PasswordExceptionClosure() {
  336. function PasswordException(msg, code) {
  337. this.name = 'PasswordException';
  338. this.message = msg;
  339. this.code = code;
  340. }
  341. PasswordException.prototype = new Error();
  342. PasswordException.constructor = PasswordException;
  343. return PasswordException;
  344. })();
  345. var UnknownErrorException = (function UnknownErrorExceptionClosure() {
  346. function UnknownErrorException(msg, details) {
  347. this.name = 'UnknownErrorException';
  348. this.message = msg;
  349. this.details = details;
  350. }
  351. UnknownErrorException.prototype = new Error();
  352. UnknownErrorException.constructor = UnknownErrorException;
  353. return UnknownErrorException;
  354. })();
  355. var InvalidPDFException = (function InvalidPDFExceptionClosure() {
  356. function InvalidPDFException(msg) {
  357. this.name = 'InvalidPDFException';
  358. this.message = msg;
  359. }
  360. InvalidPDFException.prototype = new Error();
  361. InvalidPDFException.constructor = InvalidPDFException;
  362. return InvalidPDFException;
  363. })();
  364. var MissingPDFException = (function MissingPDFExceptionClosure() {
  365. function MissingPDFException(msg) {
  366. this.name = 'MissingPDFException';
  367. this.message = msg;
  368. }
  369. MissingPDFException.prototype = new Error();
  370. MissingPDFException.constructor = MissingPDFException;
  371. return MissingPDFException;
  372. })();
  373. var NotImplementedException = (function NotImplementedExceptionClosure() {
  374. function NotImplementedException(msg) {
  375. this.message = msg;
  376. }
  377. NotImplementedException.prototype = new Error();
  378. NotImplementedException.prototype.name = 'NotImplementedException';
  379. NotImplementedException.constructor = NotImplementedException;
  380. return NotImplementedException;
  381. })();
  382. var MissingDataException = (function MissingDataExceptionClosure() {
  383. function MissingDataException(begin, end) {
  384. this.begin = begin;
  385. this.end = end;
  386. this.message = 'Missing data [' + begin + ', ' + end + ')';
  387. }
  388. MissingDataException.prototype = new Error();
  389. MissingDataException.prototype.name = 'MissingDataException';
  390. MissingDataException.constructor = MissingDataException;
  391. return MissingDataException;
  392. })();
  393. var XRefParseException = (function XRefParseExceptionClosure() {
  394. function XRefParseException(msg) {
  395. this.message = msg;
  396. }
  397. XRefParseException.prototype = new Error();
  398. XRefParseException.prototype.name = 'XRefParseException';
  399. XRefParseException.constructor = XRefParseException;
  400. return XRefParseException;
  401. })();
  402. function bytesToString(bytes) {
  403. var length = bytes.length;
  404. var MAX_ARGUMENT_COUNT = 8192;
  405. if (length < MAX_ARGUMENT_COUNT) {
  406. return String.fromCharCode.apply(null, bytes);
  407. }
  408. var strBuf = [];
  409. for (var i = 0; i < length; i += MAX_ARGUMENT_COUNT) {
  410. var chunkEnd = Math.min(i + MAX_ARGUMENT_COUNT, length);
  411. var chunk = bytes.subarray(i, chunkEnd);
  412. strBuf.push(String.fromCharCode.apply(null, chunk));
  413. }
  414. return strBuf.join('');
  415. }
  416. function stringToArray(str) {
  417. var length = str.length;
  418. var array = [];
  419. for (var i = 0; i < length; ++i) {
  420. array[i] = str.charCodeAt(i);
  421. }
  422. return array;
  423. }
  424. function stringToBytes(str) {
  425. var length = str.length;
  426. var bytes = new Uint8Array(length);
  427. for (var i = 0; i < length; ++i) {
  428. bytes[i] = str.charCodeAt(i) & 0xFF;
  429. }
  430. return bytes;
  431. }
  432. function string32(value) {
  433. return String.fromCharCode((value >> 24) & 0xff, (value >> 16) & 0xff,
  434. (value >> 8) & 0xff, value & 0xff);
  435. }
  436. function log2(x) {
  437. var n = 1, i = 0;
  438. while (x > n) {
  439. n <<= 1;
  440. i++;
  441. }
  442. return i;
  443. }
  444. function readInt8(data, start) {
  445. return (data[start] << 24) >> 24;
  446. }
  447. function readUint16(data, offset) {
  448. return (data[offset] << 8) | data[offset + 1];
  449. }
  450. function readUint32(data, offset) {
  451. return ((data[offset] << 24) | (data[offset + 1] << 16) |
  452. (data[offset + 2] << 8) | data[offset + 3]) >>> 0;
  453. }
  454. // Lazy test the endianness of the platform
  455. // NOTE: This will be 'true' for simulated TypedArrays
  456. function isLittleEndian() {
  457. var buffer8 = new Uint8Array(2);
  458. buffer8[0] = 1;
  459. var buffer16 = new Uint16Array(buffer8.buffer);
  460. return (buffer16[0] === 1);
  461. }
  462. Object.defineProperty(PDFJS, 'isLittleEndian', {
  463. configurable: true,
  464. get: function PDFJS_isLittleEndian() {
  465. return shadow(PDFJS, 'isLittleEndian', isLittleEndian());
  466. }
  467. });
  468. // Lazy test if the userAgant support CanvasTypedArrays
  469. function hasCanvasTypedArrays() {
  470. var canvas = document.createElement('canvas');
  471. canvas.width = canvas.height = 1;
  472. var ctx = canvas.getContext('2d');
  473. var imageData = ctx.createImageData(1, 1);
  474. return (typeof imageData.data.buffer !== 'undefined');
  475. }
  476. Object.defineProperty(PDFJS, 'hasCanvasTypedArrays', {
  477. configurable: true,
  478. get: function PDFJS_hasCanvasTypedArrays() {
  479. return shadow(PDFJS, 'hasCanvasTypedArrays', hasCanvasTypedArrays());
  480. }
  481. });
  482. var Uint32ArrayView = (function Uint32ArrayViewClosure() {
  483. function Uint32ArrayView(buffer, length) {
  484. this.buffer = buffer;
  485. this.byteLength = buffer.length;
  486. this.length = length === undefined ? (this.byteLength >> 2) : length;
  487. ensureUint32ArrayViewProps(this.length);
  488. }
  489. Uint32ArrayView.prototype = Object.create(null);
  490. var uint32ArrayViewSetters = 0;
  491. function createUint32ArrayProp(index) {
  492. return {
  493. get: function () {
  494. var buffer = this.buffer, offset = index << 2;
  495. return (buffer[offset] | (buffer[offset + 1] << 8) |
  496. (buffer[offset + 2] << 16) | (buffer[offset + 3] << 24)) >>> 0;
  497. },
  498. set: function (value) {
  499. var buffer = this.buffer, offset = index << 2;
  500. buffer[offset] = value & 255;
  501. buffer[offset + 1] = (value >> 8) & 255;
  502. buffer[offset + 2] = (value >> 16) & 255;
  503. buffer[offset + 3] = (value >>> 24) & 255;
  504. }
  505. };
  506. }
  507. function ensureUint32ArrayViewProps(length) {
  508. while (uint32ArrayViewSetters < length) {
  509. Object.defineProperty(Uint32ArrayView.prototype,
  510. uint32ArrayViewSetters,
  511. createUint32ArrayProp(uint32ArrayViewSetters));
  512. uint32ArrayViewSetters++;
  513. }
  514. }
  515. return Uint32ArrayView;
  516. })();
  517. var IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0];
  518. var Util = PDFJS.Util = (function UtilClosure() {
  519. function Util() {}
  520. var rgbBuf = ['rgb(', 0, ',', 0, ',', 0, ')'];
  521. // makeCssRgb() can be called thousands of times. Using |rgbBuf| avoids
  522. // creating many intermediate strings.
  523. Util.makeCssRgb = function Util_makeCssRgb(rgb) {
  524. rgbBuf[1] = rgb[0];
  525. rgbBuf[3] = rgb[1];
  526. rgbBuf[5] = rgb[2];
  527. return rgbBuf.join('');
  528. };
  529. // Concatenates two transformation matrices together and returns the result.
  530. Util.transform = function Util_transform(m1, m2) {
  531. return [
  532. m1[0] * m2[0] + m1[2] * m2[1],
  533. m1[1] * m2[0] + m1[3] * m2[1],
  534. m1[0] * m2[2] + m1[2] * m2[3],
  535. m1[1] * m2[2] + m1[3] * m2[3],
  536. m1[0] * m2[4] + m1[2] * m2[5] + m1[4],
  537. m1[1] * m2[4] + m1[3] * m2[5] + m1[5]
  538. ];
  539. };
  540. // For 2d affine transforms
  541. Util.applyTransform = function Util_applyTransform(p, m) {
  542. var xt = p[0] * m[0] + p[1] * m[2] + m[4];
  543. var yt = p[0] * m[1] + p[1] * m[3] + m[5];
  544. return [xt, yt];
  545. };
  546. Util.applyInverseTransform = function Util_applyInverseTransform(p, m) {
  547. var d = m[0] * m[3] - m[1] * m[2];
  548. var xt = (p[0] * m[3] - p[1] * m[2] + m[2] * m[5] - m[4] * m[3]) / d;
  549. var yt = (-p[0] * m[1] + p[1] * m[0] + m[4] * m[1] - m[5] * m[0]) / d;
  550. return [xt, yt];
  551. };
  552. // Applies the transform to the rectangle and finds the minimum axially
  553. // aligned bounding box.
  554. Util.getAxialAlignedBoundingBox =
  555. function Util_getAxialAlignedBoundingBox(r, m) {
  556. var p1 = Util.applyTransform(r, m);
  557. var p2 = Util.applyTransform(r.slice(2, 4), m);
  558. var p3 = Util.applyTransform([r[0], r[3]], m);
  559. var p4 = Util.applyTransform([r[2], r[1]], m);
  560. return [
  561. Math.min(p1[0], p2[0], p3[0], p4[0]),
  562. Math.min(p1[1], p2[1], p3[1], p4[1]),
  563. Math.max(p1[0], p2[0], p3[0], p4[0]),
  564. Math.max(p1[1], p2[1], p3[1], p4[1])
  565. ];
  566. };
  567. Util.inverseTransform = function Util_inverseTransform(m) {
  568. var d = m[0] * m[3] - m[1] * m[2];
  569. return [m[3] / d, -m[1] / d, -m[2] / d, m[0] / d,
  570. (m[2] * m[5] - m[4] * m[3]) / d, (m[4] * m[1] - m[5] * m[0]) / d];
  571. };
  572. // Apply a generic 3d matrix M on a 3-vector v:
  573. // | a b c | | X |
  574. // | d e f | x | Y |
  575. // | g h i | | Z |
  576. // M is assumed to be serialized as [a,b,c,d,e,f,g,h,i],
  577. // with v as [X,Y,Z]
  578. Util.apply3dTransform = function Util_apply3dTransform(m, v) {
  579. return [
  580. m[0] * v[0] + m[1] * v[1] + m[2] * v[2],
  581. m[3] * v[0] + m[4] * v[1] + m[5] * v[2],
  582. m[6] * v[0] + m[7] * v[1] + m[8] * v[2]
  583. ];
  584. };
  585. // This calculation uses Singular Value Decomposition.
  586. // The SVD can be represented with formula A = USV. We are interested in the
  587. // matrix S here because it represents the scale values.
  588. Util.singularValueDecompose2dScale =
  589. function Util_singularValueDecompose2dScale(m) {
  590. var transpose = [m[0], m[2], m[1], m[3]];
  591. // Multiply matrix m with its transpose.
  592. var a = m[0] * transpose[0] + m[1] * transpose[2];
  593. var b = m[0] * transpose[1] + m[1] * transpose[3];
  594. var c = m[2] * transpose[0] + m[3] * transpose[2];
  595. var d = m[2] * transpose[1] + m[3] * transpose[3];
  596. // Solve the second degree polynomial to get roots.
  597. var first = (a + d) / 2;
  598. var second = Math.sqrt((a + d) * (a + d) - 4 * (a * d - c * b)) / 2;
  599. var sx = first + second || 1;
  600. var sy = first - second || 1;
  601. // Scale values are the square roots of the eigenvalues.
  602. return [Math.sqrt(sx), Math.sqrt(sy)];
  603. };
  604. // Normalize rectangle rect=[x1, y1, x2, y2] so that (x1,y1) < (x2,y2)
  605. // For coordinate systems whose origin lies in the bottom-left, this
  606. // means normalization to (BL,TR) ordering. For systems with origin in the
  607. // top-left, this means (TL,BR) ordering.
  608. Util.normalizeRect = function Util_normalizeRect(rect) {
  609. var r = rect.slice(0); // clone rect
  610. if (rect[0] > rect[2]) {
  611. r[0] = rect[2];
  612. r[2] = rect[0];
  613. }
  614. if (rect[1] > rect[3]) {
  615. r[1] = rect[3];
  616. r[3] = rect[1];
  617. }
  618. return r;
  619. };
  620. // Returns a rectangle [x1, y1, x2, y2] corresponding to the
  621. // intersection of rect1 and rect2. If no intersection, returns 'false'
  622. // The rectangle coordinates of rect1, rect2 should be [x1, y1, x2, y2]
  623. Util.intersect = function Util_intersect(rect1, rect2) {
  624. function compare(a, b) {
  625. return a - b;
  626. }
  627. // Order points along the axes
  628. var orderedX = [rect1[0], rect1[2], rect2[0], rect2[2]].sort(compare),
  629. orderedY = [rect1[1], rect1[3], rect2[1], rect2[3]].sort(compare),
  630. result = [];
  631. rect1 = Util.normalizeRect(rect1);
  632. rect2 = Util.normalizeRect(rect2);
  633. // X: first and second points belong to different rectangles?
  634. if ((orderedX[0] === rect1[0] && orderedX[1] === rect2[0]) ||
  635. (orderedX[0] === rect2[0] && orderedX[1] === rect1[0])) {
  636. // Intersection must be between second and third points
  637. result[0] = orderedX[1];
  638. result[2] = orderedX[2];
  639. } else {
  640. return false;
  641. }
  642. // Y: first and second points belong to different rectangles?
  643. if ((orderedY[0] === rect1[1] && orderedY[1] === rect2[1]) ||
  644. (orderedY[0] === rect2[1] && orderedY[1] === rect1[1])) {
  645. // Intersection must be between second and third points
  646. result[1] = orderedY[1];
  647. result[3] = orderedY[2];
  648. } else {
  649. return false;
  650. }
  651. return result;
  652. };
  653. Util.sign = function Util_sign(num) {
  654. return num < 0 ? -1 : 1;
  655. };
  656. Util.appendToArray = function Util_appendToArray(arr1, arr2) {
  657. Array.prototype.push.apply(arr1, arr2);
  658. };
  659. Util.prependToArray = function Util_prependToArray(arr1, arr2) {
  660. Array.prototype.unshift.apply(arr1, arr2);
  661. };
  662. Util.extendObj = function extendObj(obj1, obj2) {
  663. for (var key in obj2) {
  664. obj1[key] = obj2[key];
  665. }
  666. };
  667. Util.getInheritableProperty = function Util_getInheritableProperty(dict,
  668. name) {
  669. while (dict && !dict.has(name)) {
  670. dict = dict.get('Parent');
  671. }
  672. if (!dict) {
  673. return null;
  674. }
  675. return dict.get(name);
  676. };
  677. Util.inherit = function Util_inherit(sub, base, prototype) {
  678. sub.prototype = Object.create(base.prototype);
  679. sub.prototype.constructor = sub;
  680. for (var prop in prototype) {
  681. sub.prototype[prop] = prototype[prop];
  682. }
  683. };
  684. Util.loadScript = function Util_loadScript(src, callback) {
  685. var script = document.createElement('script');
  686. var loaded = false;
  687. script.setAttribute('src', src);
  688. if (callback) {
  689. script.onload = function() {
  690. if (!loaded) {
  691. callback();
  692. }
  693. loaded = true;
  694. };
  695. }
  696. document.getElementsByTagName('head')[0].appendChild(script);
  697. };
  698. return Util;
  699. })();
  700. /**
  701. * PDF page viewport created based on scale, rotation and offset.
  702. * @class
  703. * @alias PDFJS.PageViewport
  704. */
  705. var PageViewport = PDFJS.PageViewport = (function PageViewportClosure() {
  706. /**
  707. * @constructor
  708. * @private
  709. * @param viewBox {Array} xMin, yMin, xMax and yMax coordinates.
  710. * @param scale {number} scale of the viewport.
  711. * @param rotation {number} rotations of the viewport in degrees.
  712. * @param offsetX {number} offset X
  713. * @param offsetY {number} offset Y
  714. * @param dontFlip {boolean} if true, axis Y will not be flipped.
  715. */
  716. function PageViewport(viewBox, scale, rotation, offsetX, offsetY, dontFlip) {
  717. this.viewBox = viewBox;
  718. this.scale = scale;
  719. this.rotation = rotation;
  720. this.offsetX = offsetX;
  721. this.offsetY = offsetY;
  722. // creating transform to convert pdf coordinate system to the normal
  723. // canvas like coordinates taking in account scale and rotation
  724. var centerX = (viewBox[2] + viewBox[0]) / 2;
  725. var centerY = (viewBox[3] + viewBox[1]) / 2;
  726. var rotateA, rotateB, rotateC, rotateD;
  727. rotation = rotation % 360;
  728. rotation = rotation < 0 ? rotation + 360 : rotation;
  729. switch (rotation) {
  730. case 180:
  731. rotateA = -1; rotateB = 0; rotateC = 0; rotateD = 1;
  732. break;
  733. case 90:
  734. rotateA = 0; rotateB = 1; rotateC = 1; rotateD = 0;
  735. break;
  736. case 270:
  737. rotateA = 0; rotateB = -1; rotateC = -1; rotateD = 0;
  738. break;
  739. //case 0:
  740. default:
  741. rotateA = 1; rotateB = 0; rotateC = 0; rotateD = -1;
  742. break;
  743. }
  744. if (dontFlip) {
  745. rotateC = -rotateC; rotateD = -rotateD;
  746. }
  747. var offsetCanvasX, offsetCanvasY;
  748. var width, height;
  749. if (rotateA === 0) {
  750. offsetCanvasX = Math.abs(centerY - viewBox[1]) * scale + offsetX;
  751. offsetCanvasY = Math.abs(centerX - viewBox[0]) * scale + offsetY;
  752. width = Math.abs(viewBox[3] - viewBox[1]) * scale;
  753. height = Math.abs(viewBox[2] - viewBox[0]) * scale;
  754. } else {
  755. offsetCanvasX = Math.abs(centerX - viewBox[0]) * scale + offsetX;
  756. offsetCanvasY = Math.abs(centerY - viewBox[1]) * scale + offsetY;
  757. width = Math.abs(viewBox[2] - viewBox[0]) * scale;
  758. height = Math.abs(viewBox[3] - viewBox[1]) * scale;
  759. }
  760. // creating transform for the following operations:
  761. // translate(-centerX, -centerY), rotate and flip vertically,
  762. // scale, and translate(offsetCanvasX, offsetCanvasY)
  763. this.transform = [
  764. rotateA * scale,
  765. rotateB * scale,
  766. rotateC * scale,
  767. rotateD * scale,
  768. offsetCanvasX - rotateA * scale * centerX - rotateC * scale * centerY,
  769. offsetCanvasY - rotateB * scale * centerX - rotateD * scale * centerY
  770. ];
  771. this.width = width;
  772. this.height = height;
  773. this.fontScale = scale;
  774. }
  775. PageViewport.prototype = /** @lends PDFJS.PageViewport.prototype */ {
  776. /**
  777. * Clones viewport with additional properties.
  778. * @param args {Object} (optional) If specified, may contain the 'scale' or
  779. * 'rotation' properties to override the corresponding properties in
  780. * the cloned viewport.
  781. * @returns {PDFJS.PageViewport} Cloned viewport.
  782. */
  783. clone: function PageViewPort_clone(args) {
  784. args = args || {};
  785. var scale = 'scale' in args ? args.scale : this.scale;
  786. var rotation = 'rotation' in args ? args.rotation : this.rotation;
  787. return new PageViewport(this.viewBox.slice(), scale, rotation,
  788. this.offsetX, this.offsetY, args.dontFlip);
  789. },
  790. /**
  791. * Converts PDF point to the viewport coordinates. For examples, useful for
  792. * converting PDF location into canvas pixel coordinates.
  793. * @param x {number} X coordinate.
  794. * @param y {number} Y coordinate.
  795. * @returns {Object} Object that contains 'x' and 'y' properties of the
  796. * point in the viewport coordinate space.
  797. * @see {@link convertToPdfPoint}
  798. * @see {@link convertToViewportRectangle}
  799. */
  800. convertToViewportPoint: function PageViewport_convertToViewportPoint(x, y) {
  801. return Util.applyTransform([x, y], this.transform);
  802. },
  803. /**
  804. * Converts PDF rectangle to the viewport coordinates.
  805. * @param rect {Array} xMin, yMin, xMax and yMax coordinates.
  806. * @returns {Array} Contains corresponding coordinates of the rectangle
  807. * in the viewport coordinate space.
  808. * @see {@link convertToViewportPoint}
  809. */
  810. convertToViewportRectangle:
  811. function PageViewport_convertToViewportRectangle(rect) {
  812. var tl = Util.applyTransform([rect[0], rect[1]], this.transform);
  813. var br = Util.applyTransform([rect[2], rect[3]], this.transform);
  814. return [tl[0], tl[1], br[0], br[1]];
  815. },
  816. /**
  817. * Converts viewport coordinates to the PDF location. For examples, useful
  818. * for converting canvas pixel location into PDF one.
  819. * @param x {number} X coordinate.
  820. * @param y {number} Y coordinate.
  821. * @returns {Object} Object that contains 'x' and 'y' properties of the
  822. * point in the PDF coordinate space.
  823. * @see {@link convertToViewportPoint}
  824. */
  825. convertToPdfPoint: function PageViewport_convertToPdfPoint(x, y) {
  826. return Util.applyInverseTransform([x, y], this.transform);
  827. }
  828. };
  829. return PageViewport;
  830. })();
  831. var PDFStringTranslateTable = [
  832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  833. 0x2D8, 0x2C7, 0x2C6, 0x2D9, 0x2DD, 0x2DB, 0x2DA, 0x2DC, 0, 0, 0, 0, 0, 0, 0,
  834. 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,
  835. 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,
  836. 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,
  837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x2022, 0x2020, 0x2021, 0x2026, 0x2014,
  838. 0x2013, 0x192, 0x2044, 0x2039, 0x203A, 0x2212, 0x2030, 0x201E, 0x201C,
  839. 0x201D, 0x2018, 0x2019, 0x201A, 0x2122, 0xFB01, 0xFB02, 0x141, 0x152, 0x160,
  840. 0x178, 0x17D, 0x131, 0x142, 0x153, 0x161, 0x17E, 0, 0x20AC
  841. ];
  842. function stringToPDFString(str) {
  843. var i, n = str.length, strBuf = [];
  844. if (str[0] === '\xFE' && str[1] === '\xFF') {
  845. // UTF16BE BOM
  846. for (i = 2; i < n; i += 2) {
  847. strBuf.push(String.fromCharCode(
  848. (str.charCodeAt(i) << 8) | str.charCodeAt(i + 1)));
  849. }
  850. } else {
  851. for (i = 0; i < n; ++i) {
  852. var code = PDFStringTranslateTable[str.charCodeAt(i)];
  853. strBuf.push(code ? String.fromCharCode(code) : str.charAt(i));
  854. }
  855. }
  856. return strBuf.join('');
  857. }
  858. function stringToUTF8String(str) {
  859. return decodeURIComponent(escape(str));
  860. }
  861. function isEmptyObj(obj) {
  862. for (var key in obj) {
  863. return false;
  864. }
  865. return true;
  866. }
  867. function isBool(v) {
  868. return typeof v == 'boolean';
  869. }
  870. function isInt(v) {
  871. return typeof v === 'number' && ((v | 0) === v);
  872. }
  873. function isNum(v) {
  874. return typeof v === 'number';
  875. }
  876. function isString(v) {
  877. return typeof v === 'string';
  878. }
  879. function isNull(v) {
  880. return v === null;
  881. }
  882. function isName(v) {
  883. return v instanceof Name;
  884. }
  885. function isCmd(v, cmd) {
  886. return v instanceof Cmd && (cmd === undefined || v.cmd === cmd);
  887. }
  888. function isDict(v, type) {
  889. if (!(v instanceof Dict)) {
  890. return false;
  891. }
  892. if (!type) {
  893. return true;
  894. }
  895. var dictType = v.get('Type');
  896. return isName(dictType) && dictType.name === type;
  897. }
  898. function isArray(v) {
  899. return v instanceof Array;
  900. }
  901. function isStream(v) {
  902. return typeof v === 'object' && v !== null && v.getBytes !== undefined;
  903. }
  904. function isArrayBuffer(v) {
  905. return typeof v === 'object' && v !== null && v.byteLength !== undefined;
  906. }
  907. function isRef(v) {
  908. return v instanceof Ref;
  909. }
  910. /**
  911. * Promise Capability object.
  912. *
  913. * @typedef {Object} PromiseCapability
  914. * @property {Promise} promise - A promise object.
  915. * @property {function} resolve - Fullfills the promise.
  916. * @property {function} reject - Rejects the promise.
  917. */
  918. /**
  919. * Creates a promise capability object.
  920. * @alias PDFJS.createPromiseCapability
  921. *
  922. * @return {PromiseCapability} A capability object contains:
  923. * - a Promise, resolve and reject methods.
  924. */
  925. function createPromiseCapability() {
  926. var capability = {};
  927. capability.promise = new Promise(function (resolve, reject) {
  928. capability.resolve = resolve;
  929. capability.reject = reject;
  930. });
  931. return capability;
  932. }
  933. PDFJS.createPromiseCapability = createPromiseCapability;
  934. /**
  935. * Polyfill for Promises:
  936. * The following promise implementation tries to generally implement the
  937. * Promise/A+ spec. Some notable differences from other promise libaries are:
  938. * - There currently isn't a seperate deferred and promise object.
  939. * - Unhandled rejections eventually show an error if they aren't handled.
  940. *
  941. * Based off of the work in:
  942. * https://bugzilla.mozilla.org/show_bug.cgi?id=810490
  943. */
  944. (function PromiseClosure() {
  945. if (globalScope.Promise) {
  946. // Promises existing in the DOM/Worker, checking presence of all/resolve
  947. if (typeof globalScope.Promise.all !== 'function') {
  948. globalScope.Promise.all = function (iterable) {
  949. var count = 0, results = [], resolve, reject;
  950. var promise = new globalScope.Promise(function (resolve_, reject_) {
  951. resolve = resolve_;
  952. reject = reject_;
  953. });
  954. iterable.forEach(function (p, i) {
  955. count++;
  956. p.then(function (result) {
  957. results[i] = result;
  958. count--;
  959. if (count === 0) {
  960. resolve(results);
  961. }
  962. }, reject);
  963. });
  964. if (count === 0) {
  965. resolve(results);
  966. }
  967. return promise;
  968. };
  969. }
  970. if (typeof globalScope.Promise.resolve !== 'function') {
  971. globalScope.Promise.resolve = function (value) {
  972. return new globalScope.Promise(function (resolve) { resolve(value); });
  973. };
  974. }
  975. if (typeof globalScope.Promise.reject !== 'function') {
  976. globalScope.Promise.reject = function (reason) {
  977. return new globalScope.Promise(function (resolve, reject) {
  978. reject(reason);
  979. });
  980. };
  981. }
  982. if (typeof globalScope.Promise.prototype.catch !== 'function') {
  983. globalScope.Promise.prototype.catch = function (onReject) {
  984. return globalScope.Promise.prototype.then(undefined, onReject);
  985. };
  986. }
  987. return;
  988. }
  989. var STATUS_PENDING = 0;
  990. var STATUS_RESOLVED = 1;
  991. var STATUS_REJECTED = 2;
  992. // In an attempt to avoid silent exceptions, unhandled rejections are
  993. // tracked and if they aren't handled in a certain amount of time an
  994. // error is logged.
  995. var REJECTION_TIMEOUT = 500;
  996. var HandlerManager = {
  997. handlers: [],
  998. running: false,
  999. unhandledRejections: [],
  1000. pendingRejectionCheck: false,
  1001. scheduleHandlers: function scheduleHandlers(promise) {
  1002. if (promise._status == STATUS_PENDING) {
  1003. return;
  1004. }
  1005. this.handlers = this.handlers.concat(promise._handlers);
  1006. promise._handlers = [];
  1007. if (this.running) {
  1008. return;
  1009. }
  1010. this.running = true;
  1011. setTimeout(this.runHandlers.bind(this), 0);
  1012. },
  1013. runHandlers: function runHandlers() {
  1014. var RUN_TIMEOUT = 1; // ms
  1015. var timeoutAt = Date.now() + RUN_TIMEOUT;
  1016. while (this.handlers.length > 0) {
  1017. var handler = this.handlers.shift();
  1018. var nextStatus = handler.thisPromise._status;
  1019. var nextValue = handler.thisPromise._value;
  1020. try {
  1021. if (nextStatus === STATUS_RESOLVED) {
  1022. if (typeof(handler.onResolve) == 'function') {
  1023. nextValue = handler.onResolve(nextValue);
  1024. }
  1025. } else if (typeof(handler.onReject) === 'function') {
  1026. nextValue = handler.onReject(nextValue);
  1027. nextStatus = STATUS_RESOLVED;
  1028. if (handler.thisPromise._unhandledRejection) {
  1029. this.removeUnhandeledRejection(handler.thisPromise);
  1030. }
  1031. }
  1032. } catch (ex) {
  1033. nextStatus = STATUS_REJECTED;
  1034. nextValue = ex;
  1035. }
  1036. handler.nextPromise._updateStatus(nextStatus, nextValue);
  1037. if (Date.now() >= timeoutAt) {
  1038. break;
  1039. }
  1040. }
  1041. if (this.handlers.length > 0) {
  1042. setTimeout(this.runHandlers.bind(this), 0);
  1043. return;
  1044. }
  1045. this.running = false;
  1046. },
  1047. addUnhandledRejection: function addUnhandledRejection(promise) {
  1048. this.unhandledRejections.push({
  1049. promise: promise,
  1050. time: Date.now()
  1051. });
  1052. this.scheduleRejectionCheck();
  1053. },
  1054. removeUnhandeledRejection: function removeUnhandeledRejection(promise) {
  1055. promise._unhandledRejection = false;
  1056. for (var i = 0; i < this.unhandledRejections.length; i++) {
  1057. if (this.unhandledRejections[i].promise === promise) {
  1058. this.unhandledRejections.splice(i);
  1059. i--;
  1060. }
  1061. }
  1062. },
  1063. scheduleRejectionCheck: function scheduleRejectionCheck() {
  1064. if (this.pendingRejectionCheck) {
  1065. return;
  1066. }
  1067. this.pendingRejectionCheck = true;
  1068. setTimeout(function rejectionCheck() {
  1069. this.pendingRejectionCheck = false;
  1070. var now = Date.now();
  1071. for (var i = 0; i < this.unhandledRejections.length; i++) {
  1072. if (now - this.unhandledRejections[i].time > REJECTION_TIMEOUT) {
  1073. var unhandled = this.unhandledRejections[i].promise._value;
  1074. var msg = 'Unhandled rejection: ' + unhandled;
  1075. if (unhandled.stack) {
  1076. msg += '\n' + unhandled.stack;
  1077. }
  1078. warn(msg);
  1079. this.unhandledRejections.splice(i);
  1080. i--;
  1081. }
  1082. }
  1083. if (this.unhandledRejections.length) {
  1084. this.scheduleRejectionCheck();
  1085. }
  1086. }.bind(this), REJECTION_TIMEOUT);
  1087. }
  1088. };
  1089. function Promise(resolver) {
  1090. this._status = STATUS_PENDING;
  1091. this._handlers = [];
  1092. try {
  1093. resolver.call(this, this._resolve.bind(this), this._reject.bind(this));
  1094. } catch (e) {
  1095. this._reject(e);
  1096. }
  1097. }
  1098. /**
  1099. * Builds a promise that is resolved when all the passed in promises are
  1100. * resolved.
  1101. * @param {array} array of data and/or promises to wait for.
  1102. * @return {Promise} New dependant promise.
  1103. */
  1104. Promise.all = function Promise_all(promises) {
  1105. var resolveAll, rejectAll;
  1106. var deferred = new Promise(function (resolve, reject) {
  1107. resolveAll = resolve;
  1108. rejectAll = reject;
  1109. });
  1110. var unresolved = promises.length;
  1111. var results = [];
  1112. if (unresolved === 0) {
  1113. resolveAll(results);
  1114. return deferred;
  1115. }
  1116. function reject(reason) {
  1117. if (deferred._status === STATUS_REJECTED) {
  1118. return;
  1119. }
  1120. results = [];
  1121. rejectAll(reason);
  1122. }
  1123. for (var i = 0, ii = promises.length; i < ii; ++i) {
  1124. var promise = promises[i];
  1125. var resolve = (function(i) {
  1126. return function(value) {
  1127. if (deferred._status === STATUS_REJECTED) {
  1128. return;
  1129. }
  1130. results[i] = value;
  1131. unresolved--;
  1132. if (unresolved === 0) {
  1133. resolveAll(results);
  1134. }
  1135. };
  1136. })(i);
  1137. if (Promise.isPromise(promise)) {
  1138. promise.then(resolve, reject);
  1139. } else {
  1140. resolve(promise);
  1141. }
  1142. }
  1143. return deferred;
  1144. };
  1145. /**
  1146. * Checks if the value is likely a promise (has a 'then' function).
  1147. * @return {boolean} true if value is thenable
  1148. */
  1149. Promise.isPromise = function Promise_isPromise(value) {
  1150. return value && typeof value.then === 'function';
  1151. };
  1152. /**
  1153. * Creates resolved promise
  1154. * @param value resolve value
  1155. * @returns {Promise}
  1156. */
  1157. Promise.resolve = function Promise_resolve(value) {
  1158. return new Promise(function (resolve) { resolve(value); });
  1159. };
  1160. /**
  1161. * Creates rejected promise
  1162. * @param reason rejection value
  1163. * @returns {Promise}
  1164. */
  1165. Promise.reject = function Promise_reject(reason) {
  1166. return new Promise(function (resolve, reject) { reject(reason); });
  1167. };
  1168. Promise.prototype = {
  1169. _status: null,
  1170. _value: null,
  1171. _handlers: null,
  1172. _unhandledRejection: null,
  1173. _updateStatus: function Promise__updateStatus(status, value) {
  1174. if (this._status === STATUS_RESOLVED ||
  1175. this._status === STATUS_REJECTED) {
  1176. return;
  1177. }
  1178. if (status == STATUS_RESOLVED &&
  1179. Promise.isPromise(value)) {
  1180. value.then(this._updateStatus.bind(this, STATUS_RESOLVED),
  1181. this._updateStatus.bind(this, STATUS_REJECTED));
  1182. return;
  1183. }
  1184. this._status = status;
  1185. this._value = value;
  1186. if (status === STATUS_REJECTED && this._handlers.length === 0) {
  1187. this._unhandledRejection = true;
  1188. HandlerManager.addUnhandledRejection(this);
  1189. }
  1190. HandlerManager.scheduleHandlers(this);
  1191. },
  1192. _resolve: function Promise_resolve(value) {
  1193. this._updateStatus(STATUS_RESOLVED, value);
  1194. },
  1195. _reject: function Promise_reject(reason) {
  1196. this._updateStatus(STATUS_REJECTED, reason);
  1197. },
  1198. then: function Promise_then(onResolve, onReject) {
  1199. var nextPromise = new Promise(function (resolve, reject) {
  1200. this.resolve = resolve;
  1201. this.reject = reject;
  1202. });
  1203. this._handlers.push({
  1204. thisPromise: this,
  1205. onResolve: onResolve,
  1206. onReject: onReject,
  1207. nextPromise: nextPromise
  1208. });
  1209. HandlerManager.scheduleHandlers(this);
  1210. return nextPromise;
  1211. },
  1212. catch: function Promise_catch(onReject) {
  1213. return this.then(undefined, onReject);
  1214. }
  1215. };
  1216. globalScope.Promise = Promise;
  1217. })();
  1218. var StatTimer = (function StatTimerClosure() {
  1219. function rpad(str, pad, length) {
  1220. while (str.length < length) {
  1221. str += pad;
  1222. }
  1223. return str;
  1224. }
  1225. function StatTimer() {
  1226. this.started = {};
  1227. this.times = [];
  1228. this.enabled = true;
  1229. }
  1230. StatTimer.prototype = {
  1231. time: function StatTimer_time(name) {
  1232. if (!this.enabled) {
  1233. return;
  1234. }
  1235. if (name in this.started) {
  1236. warn('Timer is already running for ' + name);
  1237. }
  1238. this.started[name] = Date.now();
  1239. },
  1240. timeEnd: function StatTimer_timeEnd(name) {
  1241. if (!this.enabled) {
  1242. return;
  1243. }
  1244. if (!(name in this.started)) {
  1245. warn('Timer has not been started for ' + name);
  1246. }
  1247. this.times.push({
  1248. 'name': name,
  1249. 'start': this.started[name],
  1250. 'end': Date.now()
  1251. });
  1252. // Remove timer from started so it can be called again.
  1253. delete this.started[name];
  1254. },
  1255. toString: function StatTimer_toString() {
  1256. var i, ii;
  1257. var times = this.times;
  1258. var out = '';
  1259. // Find the longest name for padding purposes.
  1260. var longest = 0;
  1261. for (i = 0, ii = times.length; i < ii; ++i) {
  1262. var name = times[i]['name'];
  1263. if (name.length > longest) {
  1264. longest = name.length;
  1265. }
  1266. }
  1267. for (i = 0, ii = times.length; i < ii; ++i) {
  1268. var span = times[i];
  1269. var duration = span.end - span.start;
  1270. out += rpad(span['name'], ' ', longest) + ' ' + duration + 'ms\n';
  1271. }
  1272. return out;
  1273. }
  1274. };
  1275. return StatTimer;
  1276. })();
  1277. PDFJS.createBlob = function createBlob(data, contentType) {
  1278. if (typeof Blob !== 'undefined') {
  1279. return new Blob([data], { type: contentType });
  1280. }
  1281. // Blob builder is deprecated in FF14 and removed in FF18.
  1282. var bb = new MozBlobBuilder();
  1283. bb.append(data);
  1284. return bb.getBlob(contentType);
  1285. };
  1286. PDFJS.createObjectURL = (function createObjectURLClosure() {
  1287. // Blob/createObjectURL is not available, falling back to data schema.
  1288. var digits =
  1289. 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
  1290. return function createObjectURL(data, contentType) {
  1291. if (!PDFJS.disableCreateObjectURL &&
  1292. typeof URL !== 'undefined' && URL.createObjectURL) {
  1293. var blob = PDFJS.createBlob(data, contentType);
  1294. return URL.createObjectURL(blob);
  1295. }
  1296. var buffer = 'data:' + contentType + ';base64,';
  1297. for (var i = 0, ii = data.length; i < ii; i += 3) {
  1298. var b1 = data[i] & 0xFF;
  1299. var b2 = data[i + 1] & 0xFF;
  1300. var b3 = data[i + 2] & 0xFF;
  1301. var d1 = b1 >> 2, d2 = ((b1 & 3) << 4) | (b2 >> 4);
  1302. var d3 = i + 1 < ii ? ((b2 & 0xF) << 2) | (b3 >> 6) : 64;
  1303. var d4 = i + 2 < ii ? (b3 & 0x3F) : 64;
  1304. buffer += digits[d1] + digits[d2] + digits[d3] + digits[d4];
  1305. }
  1306. return buffer;
  1307. };
  1308. })();
  1309. function MessageHandler(name, comObj) {
  1310. this.name = name;
  1311. this.comObj = comObj;
  1312. this.callbackIndex = 1;
  1313. this.postMessageTransfers = true;
  1314. var callbacksCapabilities = this.callbacksCapabilities = {};
  1315. var ah = this.actionHandler = {};
  1316. ah['console_log'] = [function ahConsoleLog(data) {
  1317. console.log.apply(console, data);
  1318. }];
  1319. ah['console_error'] = [function ahConsoleError(data) {
  1320. console.error.apply(console, data);
  1321. }];
  1322. ah['_unsupported_feature'] = [function ah_unsupportedFeature(data) {
  1323. UnsupportedManager.notify(data);
  1324. }];
  1325. comObj.onmessage = function messageHandlerComObjOnMessage(event) {
  1326. var data = event.data;
  1327. if (data.isReply) {
  1328. var callbackId = data.callbackId;
  1329. if (data.callbackId in callbacksCapabilities) {
  1330. var callback = callbacksCapabilities[callbackId];
  1331. delete callbacksCapabilities[callbackId];
  1332. if ('error' in data) {
  1333. callback.reject(data.error);
  1334. } else {
  1335. callback.resolve(data.data);
  1336. }
  1337. } else {
  1338. error('Cannot resolve callback ' + callbackId);
  1339. }
  1340. } else if (data.action in ah) {
  1341. var action = ah[data.action];
  1342. if (data.callbackId) {
  1343. Promise.resolve().then(function () {
  1344. return action[0].call(action[1], data.data);
  1345. }).then(function (result) {
  1346. comObj.postMessage({
  1347. isReply: true,
  1348. callbackId: data.callbackId,
  1349. data: result
  1350. });
  1351. }, function (reason) {
  1352. comObj.postMessage({
  1353. isReply: true,
  1354. callbackId: data.callbackId,
  1355. error: reason
  1356. });
  1357. });
  1358. } else {
  1359. action[0].call(action[1], data.data);
  1360. }
  1361. } else {
  1362. error('Unknown action from worker: ' + data.action);
  1363. }
  1364. };
  1365. }
  1366. MessageHandler.prototype = {
  1367. on: function messageHandlerOn(actionName, handler, scope) {
  1368. var ah = this.actionHandler;
  1369. if (ah[actionName]) {
  1370. error('There is already an actionName called "' + actionName + '"');
  1371. }
  1372. ah[actionName] = [handler, scope];
  1373. },
  1374. /**
  1375. * Sends a message to the comObj to invoke the action with the supplied data.
  1376. * @param {String} actionName Action to call.
  1377. * @param {JSON} data JSON data to send.
  1378. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers
  1379. */
  1380. send: function messageHandlerSend(actionName, data, transfers) {
  1381. var message = {
  1382. action: actionName,
  1383. data: data
  1384. };
  1385. this.postMessage(message, transfers);
  1386. },
  1387. /**
  1388. * Sends a message to the comObj to invoke the action with the supplied data.
  1389. * Expects that other side will callback with the response.
  1390. * @param {String} actionName Action to call.
  1391. * @param {JSON} data JSON data to send.
  1392. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers.
  1393. * @returns {Promise} Promise to be resolved with response data.
  1394. */
  1395. sendWithPromise:
  1396. function messageHandlerSendWithPromise(actionName, data, transfers) {
  1397. var callbackId = this.callbackIndex++;
  1398. var message = {
  1399. action: actionName,
  1400. data: data,
  1401. callbackId: callbackId
  1402. };
  1403. var capability = createPromiseCapability();
  1404. this.callbacksCapabilities[callbackId] = capability;
  1405. try {
  1406. this.postMessage(message, transfers);
  1407. } catch (e) {
  1408. capability.reject(e);
  1409. }
  1410. return capability.promise;
  1411. },
  1412. /**
  1413. * Sends raw message to the comObj.
  1414. * @private
  1415. * @param message {Object} Raw message.
  1416. * @param transfers List of transfers/ArrayBuffers, or undefined.
  1417. */
  1418. postMessage: function (message, transfers) {
  1419. if (transfers && this.postMessageTransfers) {
  1420. this.comObj.postMessage(message, transfers);
  1421. } else {
  1422. this.comObj.postMessage(message);
  1423. }
  1424. }
  1425. };
  1426. function loadJpegStream(id, imageUrl, objs) {
  1427. var img = new Image();
  1428. img.onload = (function loadJpegStream_onloadClosure() {
  1429. objs.resolve(id, img);
  1430. });
  1431. img.onerror = (function loadJpegStream_onerrorClosure() {
  1432. objs.resolve(id, null);
  1433. warn('Error during JPEG image loading');
  1434. });
  1435. img.src = imageUrl;
  1436. }
  1437. var NetworkManager = (function NetworkManagerClosure() {
  1438. var OK_RESPONSE = 200;
  1439. var PARTIAL_CONTENT_RESPONSE = 206;
  1440. function NetworkManager(url, args) {
  1441. this.url = url;
  1442. args = args || {};
  1443. this.isHttp = /^https?:/i.test(url);
  1444. this.httpHeaders = (this.isHttp && args.httpHeaders) || {};
  1445. this.withCredentials = args.withCredentials || false;
  1446. this.getXhr = args.getXhr ||
  1447. function NetworkManager_getXhr() {
  1448. return new XMLHttpRequest();
  1449. };
  1450. this.currXhrId = 0;
  1451. this.pendingRequests = {};
  1452. this.loadedRequests = {};
  1453. }
  1454. function getArrayBuffer(xhr) {
  1455. var data = xhr.response;
  1456. if (typeof data !== 'string') {
  1457. return data;
  1458. }
  1459. var length = data.length;
  1460. var buffer = new Uint8Array(length);
  1461. for (var i = 0; i < length; i++) {
  1462. buffer[i] = data.charCodeAt(i) & 0xFF;
  1463. }
  1464. return buffer;
  1465. }
  1466. NetworkManager.prototype = {
  1467. requestRange: function NetworkManager_requestRange(begin, end, listeners) {
  1468. var args = {
  1469. begin: begin,
  1470. end: end
  1471. };
  1472. for (var prop in listeners) {
  1473. args[prop] = listeners[prop];
  1474. }
  1475. return this.request(args);
  1476. },
  1477. requestFull: function NetworkManager_requestRange(listeners) {
  1478. return this.request(listeners);
  1479. },
  1480. request: function NetworkManager_requestRange(args) {
  1481. var xhr = this.getXhr();
  1482. var xhrId = this.currXhrId++;
  1483. var pendingRequest = this.pendingRequests[xhrId] = {
  1484. xhr: xhr
  1485. };
  1486. xhr.open('GET', this.url);
  1487. xhr.withCredentials = this.withCredentials;
  1488. for (var property in this.httpHeaders) {
  1489. var value = this.httpHeaders[property];
  1490. if (typeof value === 'undefined') {
  1491. continue;
  1492. }
  1493. xhr.setRequestHeader(property, value);
  1494. }
  1495. if (this.isHttp && 'begin' in args && 'end' in args) {
  1496. var rangeStr = args.begin + '-' + (args.end - 1);
  1497. xhr.setRequestHeader('Range', 'bytes=' + rangeStr);
  1498. pendingRequest.expectedStatus = 206;
  1499. } else {
  1500. pendingRequest.expectedStatus = 200;
  1501. }
  1502. xhr.responseType = 'arraybuffer';
  1503. if (args.onProgress) {
  1504. xhr.onprogress = args.onProgress;
  1505. }
  1506. if (args.onError) {
  1507. xhr.onerror = function(evt) {
  1508. args.onError(xhr.status);
  1509. };
  1510. }
  1511. xhr.onreadystatechange = this.onStateChange.bind(this, xhrId);
  1512. pendingRequest.onHeadersReceived = args.onHeadersReceived;
  1513. pendingRequest.onDone = args.onDone;
  1514. pendingRequest.onError = args.onError;
  1515. xhr.send(null);
  1516. return xhrId;
  1517. },
  1518. onStateChange: function NetworkManager_onStateChange(xhrId, evt) {
  1519. var pendingRequest = this.pendingRequests[xhrId];
  1520. if (!pendingRequest) {
  1521. // Maybe abortRequest was called...
  1522. return;
  1523. }
  1524. var xhr = pendingRequest.xhr;
  1525. if (xhr.readyState >= 2 && pendingRequest.onHeadersReceived) {
  1526. pendingRequest.onHeadersReceived();
  1527. delete pendingRequest.onHeadersReceived;
  1528. }
  1529. if (xhr.readyState !== 4) {
  1530. return;
  1531. }
  1532. if (!(xhrId in this.pendingRequests)) {
  1533. // The XHR request might have been aborted in onHeadersReceived()
  1534. // callback, in which case we should abort request
  1535. return;
  1536. }
  1537. delete this.pendingRequests[xhrId];
  1538. // success status == 0 can be on ftp, file and other protocols
  1539. if (xhr.status === 0 && this.isHttp) {
  1540. if (pendingRequest.onError) {
  1541. pendingRequest.onError(xhr.status);
  1542. }
  1543. return;
  1544. }
  1545. var xhrStatus = xhr.status || OK_RESPONSE;
  1546. // From http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35.2:
  1547. // "A server MAY ignore the Range header". This means it's possible to
  1548. // get a 200 rather than a 206 response from a range request.
  1549. var ok_response_on_range_request =
  1550. xhrStatus === OK_RESPONSE &&
  1551. pendingRequest.expectedStatus === PARTIAL_CONTENT_RESPONSE;
  1552. if (!ok_response_on_range_request &&
  1553. xhrStatus !== pendingRequest.expectedStatus) {
  1554. if (pendingRequest.onError) {
  1555. pendingRequest.onError(xhr.status);
  1556. }
  1557. return;
  1558. }
  1559. this.loadedRequests[xhrId] = true;
  1560. var chunk = getArrayBuffer(xhr);
  1561. if (xhrStatus === PARTIAL_CONTENT_RESPONSE) {
  1562. var rangeHeader = xhr.getResponseHeader('Content-Range');
  1563. var matches = /bytes (\d+)-(\d+)\/(\d+)/.exec(rangeHeader);
  1564. var begin = parseInt(matches[1], 10);
  1565. pendingRequest.onDone({
  1566. begin: begin,
  1567. chunk: chunk
  1568. });
  1569. } else {
  1570. pendingRequest.onDone({
  1571. begin: 0,
  1572. chunk: chunk
  1573. });
  1574. }
  1575. },
  1576. hasPendingRequests: function NetworkManager_hasPendingRequests() {
  1577. for (var xhrId in this.pendingRequests) {
  1578. return true;
  1579. }
  1580. return false;
  1581. },
  1582. getRequestXhr: function NetworkManager_getXhr(xhrId) {
  1583. return this.pendingRequests[xhrId].xhr;
  1584. },
  1585. isPendingRequest: function NetworkManager_isPendingRequest(xhrId) {
  1586. return xhrId in this.pendingRequests;
  1587. },
  1588. isLoadedRequest: function NetworkManager_isLoadedRequest(xhrId) {
  1589. return xhrId in this.loadedRequests;
  1590. },
  1591. abortAllRequests: function NetworkManager_abortAllRequests() {
  1592. for (var xhrId in this.pendingRequests) {
  1593. this.abortRequest(xhrId | 0);
  1594. }
  1595. },
  1596. abortRequest: function NetworkManager_abortRequest(xhrId) {
  1597. var xhr = this.pendingRequests[xhrId].xhr;
  1598. delete this.pendingRequests[xhrId];
  1599. xhr.abort();
  1600. }
  1601. };
  1602. return NetworkManager;
  1603. })();
  1604. var ChunkedStream = (function ChunkedStreamClosure() {
  1605. function ChunkedStream(length, chunkSize, manager) {
  1606. this.bytes = new Uint8Array(length);
  1607. this.start = 0;
  1608. this.pos = 0;
  1609. this.end = length;
  1610. this.chunkSize = chunkSize;
  1611. this.loadedChunks = [];
  1612. this.numChunksLoaded = 0;
  1613. this.numChunks = Math.ceil(length / chunkSize);
  1614. this.manager = manager;
  1615. this.initialDataLength = 0;
  1616. this.lastSuccessfulEnsureByteChunk = -1; // a single-entry cache
  1617. }
  1618. // required methods for a stream. if a particular stream does not
  1619. // implement these, an error should be thrown
  1620. ChunkedStream.prototype = {
  1621. getMissingChunks: function ChunkedStream_getMissingChunks() {
  1622. var chunks = [];
  1623. for (var chunk = 0, n = this.numChunks; chunk < n; ++chunk) {
  1624. if (!(chunk in this.loadedChunks)) {
  1625. chunks.push(chunk);
  1626. }
  1627. }
  1628. return chunks;
  1629. },
  1630. getBaseStreams: function ChunkedStream_getBaseStreams() {
  1631. return [this];
  1632. },
  1633. allChunksLoaded: function ChunkedStream_allChunksLoaded() {
  1634. return this.numChunksLoaded === this.numChunks;
  1635. },
  1636. onReceiveData: function ChunkedStream_onReceiveData(begin, chunk) {
  1637. var end = begin + chunk.byteLength;
  1638. assert(begin % this.chunkSize === 0, 'Bad begin offset: ' + begin);
  1639. // Using this.length is inaccurate here since this.start can be moved
  1640. // See ChunkedStream.moveStart()
  1641. var length = this.bytes.length;
  1642. assert(end % this.chunkSize === 0 || end === length,
  1643. 'Bad end offset: ' + end);
  1644. this.bytes.set(new Uint8Array(chunk), begin);
  1645. var chunkSize = this.chunkSize;
  1646. var beginChunk = Math.floor(begin / chunkSize);
  1647. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  1648. var curChunk;
  1649. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  1650. if (!(curChunk in this.loadedChunks)) {
  1651. this.loadedChunks[curChunk] = true;
  1652. ++this.numChunksLoaded;
  1653. }
  1654. }
  1655. },
  1656. onReceiveInitialData: function ChunkedStream_onReceiveInitialData(data) {
  1657. this.bytes.set(data);
  1658. this.initialDataLength = data.length;
  1659. var endChunk = (this.end === data.length ?
  1660. this.numChunks : Math.floor(data.length / this.chunkSize));
  1661. for (var i = 0; i < endChunk; i++) {
  1662. this.loadedChunks[i] = true;
  1663. ++this.numChunksLoaded;
  1664. }
  1665. },
  1666. ensureByte: function ChunkedStream_ensureRange(pos) {
  1667. var chunk = Math.floor(pos / this.chunkSize);
  1668. if (chunk === this.lastSuccessfulEnsureByteChunk) {
  1669. return;
  1670. }
  1671. if (!(chunk in this.loadedChunks)) {
  1672. throw new MissingDataException(pos, pos + 1);
  1673. }
  1674. this.lastSuccessfulEnsureByteChunk = chunk;
  1675. },
  1676. ensureRange: function ChunkedStream_ensureRange(begin, end) {
  1677. if (begin >= end) {
  1678. return;
  1679. }
  1680. if (end <= this.initialDataLength) {
  1681. return;
  1682. }
  1683. var chunkSize = this.chunkSize;
  1684. var beginChunk = Math.floor(begin / chunkSize);
  1685. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  1686. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  1687. if (!(chunk in this.loadedChunks)) {
  1688. throw new MissingDataException(begin, end);
  1689. }
  1690. }
  1691. },
  1692. nextEmptyChunk: function ChunkedStream_nextEmptyChunk(beginChunk) {
  1693. var chunk, n;
  1694. for (chunk = beginChunk, n = this.numChunks; chunk < n; ++chunk) {
  1695. if (!(chunk in this.loadedChunks)) {
  1696. return chunk;
  1697. }
  1698. }
  1699. // Wrap around to beginning
  1700. for (chunk = 0; chunk < beginChunk; ++chunk) {
  1701. if (!(chunk in this.loadedChunks)) {
  1702. return chunk;
  1703. }
  1704. }
  1705. return null;
  1706. },
  1707. hasChunk: function ChunkedStream_hasChunk(chunk) {
  1708. return chunk in this.loadedChunks;
  1709. },
  1710. get length() {
  1711. return this.end - this.start;
  1712. },
  1713. get isEmpty() {
  1714. return this.length === 0;
  1715. },
  1716. getByte: function ChunkedStream_getByte() {
  1717. var pos = this.pos;
  1718. if (pos >= this.end) {
  1719. return -1;
  1720. }
  1721. var byte = this.bytes[pos];
  1722. if (byte === 0) {
  1723. // |byte| might be zero, because the corresponding chunk has not been
  1724. // loaded yet. In this case, this.ensureByte(pos) will throw an
  1725. // exception and nothing is returned.
  1726. this.ensureByte(pos);
  1727. }
  1728. this.pos++;
  1729. return byte;
  1730. },
  1731. getUint16: function ChunkedStream_getUint16() {
  1732. var b0 = this.getByte();
  1733. var b1 = this.getByte();
  1734. return (b0 << 8) + b1;
  1735. },
  1736. getInt32: function ChunkedStream_getInt32() {
  1737. var b0 = this.getByte();
  1738. var b1 = this.getByte();
  1739. var b2 = this.getByte();
  1740. var b3 = this.getByte();
  1741. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  1742. },
  1743. // returns subarray of original buffer
  1744. // should only be read
  1745. getBytes: function ChunkedStream_getBytes(length) {
  1746. var bytes = this.bytes;
  1747. var pos = this.pos;
  1748. var strEnd = this.end;
  1749. if (!length) {
  1750. this.ensureRange(pos, strEnd);
  1751. return bytes.subarray(pos, strEnd);
  1752. }
  1753. var end = pos + length;
  1754. if (end > strEnd) {
  1755. end = strEnd;
  1756. }
  1757. this.ensureRange(pos, end);
  1758. this.pos = end;
  1759. return bytes.subarray(pos, end);
  1760. },
  1761. peekBytes: function ChunkedStream_peekBytes(length) {
  1762. var bytes = this.getBytes(length);
  1763. this.pos -= bytes.length;
  1764. return bytes;
  1765. },
  1766. getByteRange: function ChunkedStream_getBytes(begin, end) {
  1767. this.ensureRange(begin, end);
  1768. return this.bytes.subarray(begin, end);
  1769. },
  1770. skip: function ChunkedStream_skip(n) {
  1771. if (!n) {
  1772. n = 1;
  1773. }
  1774. this.pos += n;
  1775. },
  1776. reset: function ChunkedStream_reset() {
  1777. this.pos = this.start;
  1778. },
  1779. moveStart: function ChunkedStream_moveStart() {
  1780. this.start = this.pos;
  1781. },
  1782. makeSubStream: function ChunkedStream_makeSubStream(start, length, dict) {
  1783. this.ensureRange(start, start + length);
  1784. function ChunkedStreamSubstream() {}
  1785. ChunkedStreamSubstream.prototype = Object.create(this);
  1786. ChunkedStreamSubstream.prototype.getMissingChunks = function() {
  1787. var chunkSize = this.chunkSize;
  1788. var beginChunk = Math.floor(this.start / chunkSize);
  1789. var endChunk = Math.floor((this.end - 1) / chunkSize) + 1;
  1790. var missingChunks = [];
  1791. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  1792. if (!(chunk in this.loadedChunks)) {
  1793. missingChunks.push(chunk);
  1794. }
  1795. }
  1796. return missingChunks;
  1797. };
  1798. var subStream = new ChunkedStreamSubstream();
  1799. subStream.pos = subStream.start = start;
  1800. subStream.end = start + length || this.end;
  1801. subStream.dict = dict;
  1802. return subStream;
  1803. },
  1804. isStream: true
  1805. };
  1806. return ChunkedStream;
  1807. })();
  1808. var ChunkedStreamManager = (function ChunkedStreamManagerClosure() {
  1809. function ChunkedStreamManager(length, chunkSize, url, args) {
  1810. this.stream = new ChunkedStream(length, chunkSize, this);
  1811. this.length = length;
  1812. this.chunkSize = chunkSize;
  1813. this.url = url;
  1814. this.disableAutoFetch = args.disableAutoFetch;
  1815. var msgHandler = this.msgHandler = args.msgHandler;
  1816. if (args.chunkedViewerLoading) {
  1817. msgHandler.on('OnDataRange', this.onReceiveData.bind(this));
  1818. msgHandler.on('OnDataProgress', this.onProgress.bind(this));
  1819. this.sendRequest = function ChunkedStreamManager_sendRequest(begin, end) {
  1820. msgHandler.send('RequestDataRange', { begin: begin, end: end });
  1821. };
  1822. } else {
  1823. var getXhr = function getXhr() {
  1824. return new XMLHttpRequest();
  1825. };
  1826. this.networkManager = new NetworkManager(this.url, {
  1827. getXhr: getXhr,
  1828. httpHeaders: args.httpHeaders,
  1829. withCredentials: args.withCredentials
  1830. });
  1831. this.sendRequest = function ChunkedStreamManager_sendRequest(begin, end) {
  1832. this.networkManager.requestRange(begin, end, {
  1833. onDone: this.onReceiveData.bind(this),
  1834. onProgress: this.onProgress.bind(this)
  1835. });
  1836. };
  1837. }
  1838. this.currRequestId = 0;
  1839. this.chunksNeededByRequest = {};
  1840. this.requestsByChunk = {};
  1841. this.callbacksByRequest = {};
  1842. this._loadedStreamCapability = createPromiseCapability();
  1843. if (args.initialData) {
  1844. this.setInitialData(args.initialData);
  1845. }
  1846. }
  1847. ChunkedStreamManager.prototype = {
  1848. setInitialData: function ChunkedStreamManager_setInitialData(data) {
  1849. this.stream.onReceiveInitialData(data);
  1850. if (this.stream.allChunksLoaded()) {
  1851. this._loadedStreamCapability.resolve(this.stream);
  1852. } else if (this.msgHandler) {
  1853. this.msgHandler.send('DocProgress', {
  1854. loaded: data.length,
  1855. total: this.length
  1856. });
  1857. }
  1858. },
  1859. onLoadedStream: function ChunkedStreamManager_getLoadedStream() {
  1860. return this._loadedStreamCapability.promise;
  1861. },
  1862. // Get all the chunks that are not yet loaded and groups them into
  1863. // contiguous ranges to load in as few requests as possible
  1864. requestAllChunks: function ChunkedStreamManager_requestAllChunks() {
  1865. var missingChunks = this.stream.getMissingChunks();
  1866. this.requestChunks(missingChunks);
  1867. return this._loadedStreamCapability.promise;
  1868. },
  1869. requestChunks: function ChunkedStreamManager_requestChunks(chunks,
  1870. callback) {
  1871. var requestId = this.currRequestId++;
  1872. var chunksNeeded;
  1873. var i, ii;
  1874. this.chunksNeededByRequest[requestId] = chunksNeeded = {};
  1875. for (i = 0, ii = chunks.length; i < ii; i++) {
  1876. if (!this.stream.hasChunk(chunks[i])) {
  1877. chunksNeeded[chunks[i]] = true;
  1878. }
  1879. }
  1880. if (isEmptyObj(chunksNeeded)) {
  1881. if (callback) {
  1882. callback();
  1883. }
  1884. return;
  1885. }
  1886. this.callbacksByRequest[requestId] = callback;
  1887. var chunksToRequest = [];
  1888. for (var chunk in chunksNeeded) {
  1889. chunk = chunk | 0;
  1890. if (!(chunk in this.requestsByChunk)) {
  1891. this.requestsByChunk[chunk] = [];
  1892. chunksToRequest.push(chunk);
  1893. }
  1894. this.requestsByChunk[chunk].push(requestId);
  1895. }
  1896. if (!chunksToRequest.length) {
  1897. return;
  1898. }
  1899. var groupedChunksToRequest = this.groupChunks(chunksToRequest);
  1900. for (i = 0; i < groupedChunksToRequest.length; ++i) {
  1901. var groupedChunk = groupedChunksToRequest[i];
  1902. var begin = groupedChunk.beginChunk * this.chunkSize;
  1903. var end = Math.min(groupedChunk.endChunk * this.chunkSize, this.length);
  1904. this.sendRequest(begin, end);
  1905. }
  1906. },
  1907. getStream: function ChunkedStreamManager_getStream() {
  1908. return this.stream;
  1909. },
  1910. // Loads any chunks in the requested range that are not yet loaded
  1911. requestRange: function ChunkedStreamManager_requestRange(
  1912. begin, end, callback) {
  1913. end = Math.min(end, this.length);
  1914. var beginChunk = this.getBeginChunk(begin);
  1915. var endChunk = this.getEndChunk(end);
  1916. var chunks = [];
  1917. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  1918. chunks.push(chunk);
  1919. }
  1920. this.requestChunks(chunks, callback);
  1921. },
  1922. requestRanges: function ChunkedStreamManager_requestRanges(ranges,
  1923. callback) {
  1924. ranges = ranges || [];
  1925. var chunksToRequest = [];
  1926. for (var i = 0; i < ranges.length; i++) {
  1927. var beginChunk = this.getBeginChunk(ranges[i].begin);
  1928. var endChunk = this.getEndChunk(ranges[i].end);
  1929. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  1930. if (chunksToRequest.indexOf(chunk) < 0) {
  1931. chunksToRequest.push(chunk);
  1932. }
  1933. }
  1934. }
  1935. chunksToRequest.sort(function(a, b) { return a - b; });
  1936. this.requestChunks(chunksToRequest, callback);
  1937. },
  1938. // Groups a sorted array of chunks into as few continguous larger
  1939. // chunks as possible
  1940. groupChunks: function ChunkedStreamManager_groupChunks(chunks) {
  1941. var groupedChunks = [];
  1942. var beginChunk = -1;
  1943. var prevChunk = -1;
  1944. for (var i = 0; i < chunks.length; ++i) {
  1945. var chunk = chunks[i];
  1946. if (beginChunk < 0) {
  1947. beginChunk = chunk;
  1948. }
  1949. if (prevChunk >= 0 && prevChunk + 1 !== chunk) {
  1950. groupedChunks.push({ beginChunk: beginChunk,
  1951. endChunk: prevChunk + 1 });
  1952. beginChunk = chunk;
  1953. }
  1954. if (i + 1 === chunks.length) {
  1955. groupedChunks.push({ beginChunk: beginChunk,
  1956. endChunk: chunk + 1 });
  1957. }
  1958. prevChunk = chunk;
  1959. }
  1960. return groupedChunks;
  1961. },
  1962. onProgress: function ChunkedStreamManager_onProgress(args) {
  1963. var bytesLoaded = (this.stream.numChunksLoaded * this.chunkSize +
  1964. args.loaded);
  1965. this.msgHandler.send('DocProgress', {
  1966. loaded: bytesLoaded,
  1967. total: this.length
  1968. });
  1969. },
  1970. onReceiveData: function ChunkedStreamManager_onReceiveData(args) {
  1971. var chunk = args.chunk;
  1972. var begin = args.begin;
  1973. var end = begin + chunk.byteLength;
  1974. var beginChunk = this.getBeginChunk(begin);
  1975. var endChunk = this.getEndChunk(end);
  1976. this.stream.onReceiveData(begin, chunk);
  1977. if (this.stream.allChunksLoaded()) {
  1978. this._loadedStreamCapability.resolve(this.stream);
  1979. }
  1980. var loadedRequests = [];
  1981. var i, requestId;
  1982. for (chunk = beginChunk; chunk < endChunk; ++chunk) {
  1983. // The server might return more chunks than requested
  1984. var requestIds = this.requestsByChunk[chunk] || [];
  1985. delete this.requestsByChunk[chunk];
  1986. for (i = 0; i < requestIds.length; ++i) {
  1987. requestId = requestIds[i];
  1988. var chunksNeeded = this.chunksNeededByRequest[requestId];
  1989. if (chunk in chunksNeeded) {
  1990. delete chunksNeeded[chunk];
  1991. }
  1992. if (!isEmptyObj(chunksNeeded)) {
  1993. continue;
  1994. }
  1995. loadedRequests.push(requestId);
  1996. }
  1997. }
  1998. // If there are no pending requests, automatically fetch the next
  1999. // unfetched chunk of the PDF
  2000. if (!this.disableAutoFetch && isEmptyObj(this.requestsByChunk)) {
  2001. var nextEmptyChunk;
  2002. if (this.stream.numChunksLoaded === 1) {
  2003. // This is a special optimization so that after fetching the first
  2004. // chunk, rather than fetching the second chunk, we fetch the last
  2005. // chunk.
  2006. var lastChunk = this.stream.numChunks - 1;
  2007. if (!this.stream.hasChunk(lastChunk)) {
  2008. nextEmptyChunk = lastChunk;
  2009. }
  2010. } else {
  2011. nextEmptyChunk = this.stream.nextEmptyChunk(endChunk);
  2012. }
  2013. if (isInt(nextEmptyChunk)) {
  2014. this.requestChunks([nextEmptyChunk]);
  2015. }
  2016. }
  2017. for (i = 0; i < loadedRequests.length; ++i) {
  2018. requestId = loadedRequests[i];
  2019. var callback = this.callbacksByRequest[requestId];
  2020. delete this.callbacksByRequest[requestId];
  2021. if (callback) {
  2022. callback();
  2023. }
  2024. }
  2025. this.msgHandler.send('DocProgress', {
  2026. loaded: this.stream.numChunksLoaded * this.chunkSize,
  2027. total: this.length
  2028. });
  2029. },
  2030. onError: function ChunkedStreamManager_onError(err) {
  2031. this._loadedStreamCapability.reject(err);
  2032. },
  2033. getBeginChunk: function ChunkedStreamManager_getBeginChunk(begin) {
  2034. var chunk = Math.floor(begin / this.chunkSize);
  2035. return chunk;
  2036. },
  2037. getEndChunk: function ChunkedStreamManager_getEndChunk(end) {
  2038. if (end % this.chunkSize === 0) {
  2039. return end / this.chunkSize;
  2040. }
  2041. // 0 -> 0
  2042. // 1 -> 1
  2043. // 99 -> 1
  2044. // 100 -> 1
  2045. // 101 -> 2
  2046. var chunk = Math.floor((end - 1) / this.chunkSize) + 1;
  2047. return chunk;
  2048. }
  2049. };
  2050. return ChunkedStreamManager;
  2051. })();
  2052. // The maximum number of bytes fetched per range request
  2053. var RANGE_CHUNK_SIZE = 65536;
  2054. // TODO(mack): Make use of PDFJS.Util.inherit() when it becomes available
  2055. var BasePdfManager = (function BasePdfManagerClosure() {
  2056. function BasePdfManager() {
  2057. throw new Error('Cannot initialize BaseManagerManager');
  2058. }
  2059. BasePdfManager.prototype = {
  2060. onLoadedStream: function BasePdfManager_onLoadedStream() {
  2061. throw new NotImplementedException();
  2062. },
  2063. ensureDoc: function BasePdfManager_ensureDoc(prop, args) {
  2064. return this.ensure(this.pdfDocument, prop, args);
  2065. },
  2066. ensureXRef: function BasePdfManager_ensureXRef(prop, args) {
  2067. return this.ensure(this.pdfDocument.xref, prop, args);
  2068. },
  2069. ensureCatalog: function BasePdfManager_ensureCatalog(prop, args) {
  2070. return this.ensure(this.pdfDocument.catalog, prop, args);
  2071. },
  2072. getPage: function BasePdfManager_pagePage(pageIndex) {
  2073. return this.pdfDocument.getPage(pageIndex);
  2074. },
  2075. cleanup: function BasePdfManager_cleanup() {
  2076. return this.pdfDocument.cleanup();
  2077. },
  2078. ensure: function BasePdfManager_ensure(obj, prop, args) {
  2079. return new NotImplementedException();
  2080. },
  2081. requestRange: function BasePdfManager_ensure(begin, end) {
  2082. return new NotImplementedException();
  2083. },
  2084. requestLoadedStream: function BasePdfManager_requestLoadedStream() {
  2085. return new NotImplementedException();
  2086. },
  2087. updatePassword: function BasePdfManager_updatePassword(password) {
  2088. this.pdfDocument.xref.password = this.password = password;
  2089. if (this._passwordChangedCapability) {
  2090. this._passwordChangedCapability.resolve();
  2091. }
  2092. },
  2093. passwordChanged: function BasePdfManager_passwordChanged() {
  2094. this._passwordChangedCapability = createPromiseCapability();
  2095. return this._passwordChangedCapability.promise;
  2096. },
  2097. terminate: function BasePdfManager_terminate() {
  2098. return new NotImplementedException();
  2099. }
  2100. };
  2101. return BasePdfManager;
  2102. })();
  2103. var LocalPdfManager = (function LocalPdfManagerClosure() {
  2104. function LocalPdfManager(data, password) {
  2105. var stream = new Stream(data);
  2106. this.pdfDocument = new PDFDocument(this, stream, password);
  2107. this._loadedStreamCapability = createPromiseCapability();
  2108. this._loadedStreamCapability.resolve(stream);
  2109. }
  2110. LocalPdfManager.prototype = Object.create(BasePdfManager.prototype);
  2111. LocalPdfManager.prototype.constructor = LocalPdfManager;
  2112. LocalPdfManager.prototype.ensure =
  2113. function LocalPdfManager_ensure(obj, prop, args) {
  2114. return new Promise(function (resolve, reject) {
  2115. try {
  2116. var value = obj[prop];
  2117. var result;
  2118. if (typeof value === 'function') {
  2119. result = value.apply(obj, args);
  2120. } else {
  2121. result = value;
  2122. }
  2123. resolve(result);
  2124. } catch (e) {
  2125. reject(e);
  2126. }
  2127. });
  2128. };
  2129. LocalPdfManager.prototype.requestRange =
  2130. function LocalPdfManager_requestRange(begin, end) {
  2131. return Promise.resolve();
  2132. };
  2133. LocalPdfManager.prototype.requestLoadedStream =
  2134. function LocalPdfManager_requestLoadedStream() {
  2135. };
  2136. LocalPdfManager.prototype.onLoadedStream =
  2137. function LocalPdfManager_getLoadedStream() {
  2138. return this._loadedStreamCapability.promise;
  2139. };
  2140. LocalPdfManager.prototype.terminate =
  2141. function LocalPdfManager_terminate() {
  2142. return;
  2143. };
  2144. return LocalPdfManager;
  2145. })();
  2146. var NetworkPdfManager = (function NetworkPdfManagerClosure() {
  2147. function NetworkPdfManager(args, msgHandler) {
  2148. this.msgHandler = msgHandler;
  2149. var params = {
  2150. msgHandler: msgHandler,
  2151. httpHeaders: args.httpHeaders,
  2152. withCredentials: args.withCredentials,
  2153. chunkedViewerLoading: args.chunkedViewerLoading,
  2154. disableAutoFetch: args.disableAutoFetch,
  2155. initialData: args.initialData
  2156. };
  2157. this.streamManager = new ChunkedStreamManager(args.length, RANGE_CHUNK_SIZE,
  2158. args.url, params);
  2159. this.pdfDocument = new PDFDocument(this, this.streamManager.getStream(),
  2160. args.password);
  2161. }
  2162. NetworkPdfManager.prototype = Object.create(BasePdfManager.prototype);
  2163. NetworkPdfManager.prototype.constructor = NetworkPdfManager;
  2164. NetworkPdfManager.prototype.ensure =
  2165. function NetworkPdfManager_ensure(obj, prop, args) {
  2166. var pdfManager = this;
  2167. return new Promise(function (resolve, reject) {
  2168. function ensureHelper() {
  2169. try {
  2170. var result;
  2171. var value = obj[prop];
  2172. if (typeof value === 'function') {
  2173. result = value.apply(obj, args);
  2174. } else {
  2175. result = value;
  2176. }
  2177. resolve(result);
  2178. } catch(e) {
  2179. if (!(e instanceof MissingDataException)) {
  2180. reject(e);
  2181. return;
  2182. }
  2183. pdfManager.streamManager.requestRange(e.begin, e.end, ensureHelper);
  2184. }
  2185. }
  2186. ensureHelper();
  2187. });
  2188. };
  2189. NetworkPdfManager.prototype.requestRange =
  2190. function NetworkPdfManager_requestRange(begin, end) {
  2191. return new Promise(function (resolve) {
  2192. this.streamManager.requestRange(begin, end, function() {
  2193. resolve();
  2194. });
  2195. }.bind(this));
  2196. };
  2197. NetworkPdfManager.prototype.requestLoadedStream =
  2198. function NetworkPdfManager_requestLoadedStream() {
  2199. this.streamManager.requestAllChunks();
  2200. };
  2201. NetworkPdfManager.prototype.onLoadedStream =
  2202. function NetworkPdfManager_getLoadedStream() {
  2203. return this.streamManager.onLoadedStream();
  2204. };
  2205. NetworkPdfManager.prototype.terminate =
  2206. function NetworkPdfManager_terminate() {
  2207. this.streamManager.networkManager.abortAllRequests();
  2208. };
  2209. return NetworkPdfManager;
  2210. })();
  2211. var Page = (function PageClosure() {
  2212. var LETTER_SIZE_MEDIABOX = [0, 0, 612, 792];
  2213. function Page(pdfManager, xref, pageIndex, pageDict, ref, fontCache) {
  2214. this.pdfManager = pdfManager;
  2215. this.pageIndex = pageIndex;
  2216. this.pageDict = pageDict;
  2217. this.xref = xref;
  2218. this.ref = ref;
  2219. this.fontCache = fontCache;
  2220. this.idCounters = {
  2221. obj: 0
  2222. };
  2223. this.resourcesPromise = null;
  2224. }
  2225. Page.prototype = {
  2226. getPageProp: function Page_getPageProp(key) {
  2227. return this.pageDict.get(key);
  2228. },
  2229. getInheritedPageProp: function Page_inheritPageProp(key) {
  2230. var dict = this.pageDict;
  2231. var value = dict.get(key);
  2232. while (value === undefined) {
  2233. dict = dict.get('Parent');
  2234. if (!dict) {
  2235. break;
  2236. }
  2237. value = dict.get(key);
  2238. }
  2239. return value;
  2240. },
  2241. get content() {
  2242. return this.getPageProp('Contents');
  2243. },
  2244. get resources() {
  2245. var value = this.getInheritedPageProp('Resources');
  2246. // For robustness: The spec states that a \Resources entry has to be
  2247. // present, but can be empty. Some document omit it still. In this case
  2248. // return an empty dictionary:
  2249. if (value === undefined) {
  2250. value = Dict.empty;
  2251. }
  2252. return shadow(this, 'resources', value);
  2253. },
  2254. get mediaBox() {
  2255. var obj = this.getInheritedPageProp('MediaBox');
  2256. // Reset invalid media box to letter size.
  2257. if (!isArray(obj) || obj.length !== 4) {
  2258. obj = LETTER_SIZE_MEDIABOX;
  2259. }
  2260. return shadow(this, 'mediaBox', obj);
  2261. },
  2262. get view() {
  2263. var mediaBox = this.mediaBox;
  2264. var cropBox = this.getInheritedPageProp('CropBox');
  2265. if (!isArray(cropBox) || cropBox.length !== 4) {
  2266. return shadow(this, 'view', mediaBox);
  2267. }
  2268. // From the spec, 6th ed., p.963:
  2269. // "The crop, bleed, trim, and art boxes should not ordinarily
  2270. // extend beyond the boundaries of the media box. If they do, they are
  2271. // effectively reduced to their intersection with the media box."
  2272. cropBox = Util.intersect(cropBox, mediaBox);
  2273. if (!cropBox) {
  2274. return shadow(this, 'view', mediaBox);
  2275. }
  2276. return shadow(this, 'view', cropBox);
  2277. },
  2278. get annotationRefs() {
  2279. return shadow(this, 'annotationRefs',
  2280. this.getInheritedPageProp('Annots'));
  2281. },
  2282. get rotate() {
  2283. var rotate = this.getInheritedPageProp('Rotate') || 0;
  2284. // Normalize rotation so it's a multiple of 90 and between 0 and 270
  2285. if (rotate % 90 !== 0) {
  2286. rotate = 0;
  2287. } else if (rotate >= 360) {
  2288. rotate = rotate % 360;
  2289. } else if (rotate < 0) {
  2290. // The spec doesn't cover negatives, assume its counterclockwise
  2291. // rotation. The following is the other implementation of modulo.
  2292. rotate = ((rotate % 360) + 360) % 360;
  2293. }
  2294. return shadow(this, 'rotate', rotate);
  2295. },
  2296. getContentStream: function Page_getContentStream() {
  2297. var content = this.content;
  2298. var stream;
  2299. if (isArray(content)) {
  2300. // fetching items
  2301. var xref = this.xref;
  2302. var i, n = content.length;
  2303. var streams = [];
  2304. for (i = 0; i < n; ++i) {
  2305. streams.push(xref.fetchIfRef(content[i]));
  2306. }
  2307. stream = new StreamsSequenceStream(streams);
  2308. } else if (isStream(content)) {
  2309. stream = content;
  2310. } else {
  2311. // replacing non-existent page content with empty one
  2312. stream = new NullStream();
  2313. }
  2314. return stream;
  2315. },
  2316. loadResources: function Page_loadResources(keys) {
  2317. if (!this.resourcesPromise) {
  2318. // TODO: add async getInheritedPageProp and remove this.
  2319. this.resourcesPromise = this.pdfManager.ensure(this, 'resources');
  2320. }
  2321. return this.resourcesPromise.then(function resourceSuccess() {
  2322. var objectLoader = new ObjectLoader(this.resources.map,
  2323. keys,
  2324. this.xref);
  2325. return objectLoader.load();
  2326. }.bind(this));
  2327. },
  2328. getOperatorList: function Page_getOperatorList(handler, intent) {
  2329. var self = this;
  2330. var pdfManager = this.pdfManager;
  2331. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  2332. []);
  2333. var resourcesPromise = this.loadResources([
  2334. 'ExtGState',
  2335. 'ColorSpace',
  2336. 'Pattern',
  2337. 'Shading',
  2338. 'XObject',
  2339. 'Font'
  2340. // ProcSet
  2341. // Properties
  2342. ]);
  2343. var partialEvaluator = new PartialEvaluator(pdfManager, this.xref,
  2344. handler, this.pageIndex,
  2345. 'p' + this.pageIndex + '_',
  2346. this.idCounters,
  2347. this.fontCache);
  2348. var dataPromises = Promise.all([contentStreamPromise, resourcesPromise]);
  2349. var pageListPromise = dataPromises.then(function(data) {
  2350. var contentStream = data[0];
  2351. var opList = new OperatorList(intent, handler, self.pageIndex);
  2352. handler.send('StartRenderPage', {
  2353. transparency: partialEvaluator.hasBlendModes(self.resources),
  2354. pageIndex: self.pageIndex,
  2355. intent: intent
  2356. });
  2357. return partialEvaluator.getOperatorList(contentStream, self.resources,
  2358. opList).then(function () {
  2359. return opList;
  2360. });
  2361. });
  2362. var annotationsPromise = pdfManager.ensure(this, 'annotations');
  2363. return Promise.all([pageListPromise, annotationsPromise]).then(
  2364. function(datas) {
  2365. var pageOpList = datas[0];
  2366. var annotations = datas[1];
  2367. if (annotations.length === 0) {
  2368. pageOpList.flush(true);
  2369. return pageOpList;
  2370. }
  2371. var annotationsReadyPromise = Annotation.appendToOperatorList(
  2372. annotations, pageOpList, pdfManager, partialEvaluator, intent);
  2373. return annotationsReadyPromise.then(function () {
  2374. pageOpList.flush(true);
  2375. return pageOpList;
  2376. });
  2377. });
  2378. },
  2379. extractTextContent: function Page_extractTextContent() {
  2380. var handler = {
  2381. on: function nullHandlerOn() {},
  2382. send: function nullHandlerSend() {}
  2383. };
  2384. var self = this;
  2385. var pdfManager = this.pdfManager;
  2386. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  2387. []);
  2388. var resourcesPromise = this.loadResources([
  2389. 'ExtGState',
  2390. 'XObject',
  2391. 'Font'
  2392. ]);
  2393. var dataPromises = Promise.all([contentStreamPromise,
  2394. resourcesPromise]);
  2395. return dataPromises.then(function(data) {
  2396. var contentStream = data[0];
  2397. var partialEvaluator = new PartialEvaluator(pdfManager, self.xref,
  2398. handler, self.pageIndex,
  2399. 'p' + self.pageIndex + '_',
  2400. self.idCounters,
  2401. self.fontCache);
  2402. return partialEvaluator.getTextContent(contentStream,
  2403. self.resources);
  2404. });
  2405. },
  2406. getAnnotationsData: function Page_getAnnotationsData() {
  2407. var annotations = this.annotations;
  2408. var annotationsData = [];
  2409. for (var i = 0, n = annotations.length; i < n; ++i) {
  2410. annotationsData.push(annotations[i].getData());
  2411. }
  2412. return annotationsData;
  2413. },
  2414. get annotations() {
  2415. var annotations = [];
  2416. var annotationRefs = (this.annotationRefs || []);
  2417. for (var i = 0, n = annotationRefs.length; i < n; ++i) {
  2418. var annotationRef = annotationRefs[i];
  2419. var annotation = Annotation.fromRef(this.xref, annotationRef);
  2420. if (annotation) {
  2421. annotations.push(annotation);
  2422. }
  2423. }
  2424. return shadow(this, 'annotations', annotations);
  2425. }
  2426. };
  2427. return Page;
  2428. })();
  2429. /**
  2430. * The `PDFDocument` holds all the data of the PDF file. Compared to the
  2431. * `PDFDoc`, this one doesn't have any job management code.
  2432. * Right now there exists one PDFDocument on the main thread + one object
  2433. * for each worker. If there is no worker support enabled, there are two
  2434. * `PDFDocument` objects on the main thread created.
  2435. */
  2436. var PDFDocument = (function PDFDocumentClosure() {
  2437. function PDFDocument(pdfManager, arg, password) {
  2438. if (isStream(arg)) {
  2439. init.call(this, pdfManager, arg, password);
  2440. } else if (isArrayBuffer(arg)) {
  2441. init.call(this, pdfManager, new Stream(arg), password);
  2442. } else {
  2443. error('PDFDocument: Unknown argument type');
  2444. }
  2445. }
  2446. function init(pdfManager, stream, password) {
  2447. assert(stream.length > 0, 'stream must have data');
  2448. this.pdfManager = pdfManager;
  2449. this.stream = stream;
  2450. var xref = new XRef(this.stream, password, pdfManager);
  2451. this.xref = xref;
  2452. }
  2453. function find(stream, needle, limit, backwards) {
  2454. var pos = stream.pos;
  2455. var end = stream.end;
  2456. var strBuf = [];
  2457. if (pos + limit > end) {
  2458. limit = end - pos;
  2459. }
  2460. for (var n = 0; n < limit; ++n) {
  2461. strBuf.push(String.fromCharCode(stream.getByte()));
  2462. }
  2463. var str = strBuf.join('');
  2464. stream.pos = pos;
  2465. var index = backwards ? str.lastIndexOf(needle) : str.indexOf(needle);
  2466. if (index == -1) {
  2467. return false; /* not found */
  2468. }
  2469. stream.pos += index;
  2470. return true; /* found */
  2471. }
  2472. var DocumentInfoValidators = {
  2473. get entries() {
  2474. // Lazily build this since all the validation functions below are not
  2475. // defined until after this file loads.
  2476. return shadow(this, 'entries', {
  2477. Title: isString,
  2478. Author: isString,
  2479. Subject: isString,
  2480. Keywords: isString,
  2481. Creator: isString,
  2482. Producer: isString,
  2483. CreationDate: isString,
  2484. ModDate: isString,
  2485. Trapped: isName
  2486. });
  2487. }
  2488. };
  2489. PDFDocument.prototype = {
  2490. parse: function PDFDocument_parse(recoveryMode) {
  2491. this.setup(recoveryMode);
  2492. try {
  2493. // checking if AcroForm is present
  2494. this.acroForm = this.catalog.catDict.get('AcroForm');
  2495. if (this.acroForm) {
  2496. this.xfa = this.acroForm.get('XFA');
  2497. var fields = this.acroForm.get('Fields');
  2498. if ((!fields || !isArray(fields) || fields.length === 0) &&
  2499. !this.xfa) {
  2500. // no fields and no XFA -- not a form (?)
  2501. this.acroForm = null;
  2502. }
  2503. }
  2504. } catch (ex) {
  2505. info('Something wrong with AcroForm entry');
  2506. this.acroForm = null;
  2507. }
  2508. },
  2509. get linearization() {
  2510. var linearization = null;
  2511. if (this.stream.length) {
  2512. try {
  2513. linearization = Linearization.create(this.stream);
  2514. } catch (err) {
  2515. if (err instanceof MissingDataException) {
  2516. throw err;
  2517. }
  2518. info(err);
  2519. }
  2520. }
  2521. // shadow the prototype getter with a data property
  2522. return shadow(this, 'linearization', linearization);
  2523. },
  2524. get startXRef() {
  2525. var stream = this.stream;
  2526. var startXRef = 0;
  2527. var linearization = this.linearization;
  2528. if (linearization) {
  2529. // Find end of first obj.
  2530. stream.reset();
  2531. if (find(stream, 'endobj', 1024)) {
  2532. startXRef = stream.pos + 6;
  2533. }
  2534. } else {
  2535. // Find startxref by jumping backward from the end of the file.
  2536. var step = 1024;
  2537. var found = false, pos = stream.end;
  2538. while (!found && pos > 0) {
  2539. pos -= step - 'startxref'.length;
  2540. if (pos < 0) {
  2541. pos = 0;
  2542. }
  2543. stream.pos = pos;
  2544. found = find(stream, 'startxref', step, true);
  2545. }
  2546. if (found) {
  2547. stream.skip(9);
  2548. var ch;
  2549. do {
  2550. ch = stream.getByte();
  2551. } while (Lexer.isSpace(ch));
  2552. var str = '';
  2553. while (ch >= 0x20 && ch <= 0x39) { // < '9'
  2554. str += String.fromCharCode(ch);
  2555. ch = stream.getByte();
  2556. }
  2557. startXRef = parseInt(str, 10);
  2558. if (isNaN(startXRef)) {
  2559. startXRef = 0;
  2560. }
  2561. }
  2562. }
  2563. // shadow the prototype getter with a data property
  2564. return shadow(this, 'startXRef', startXRef);
  2565. },
  2566. get mainXRefEntriesOffset() {
  2567. var mainXRefEntriesOffset = 0;
  2568. var linearization = this.linearization;
  2569. if (linearization) {
  2570. mainXRefEntriesOffset = linearization.mainXRefEntriesOffset;
  2571. }
  2572. // shadow the prototype getter with a data property
  2573. return shadow(this, 'mainXRefEntriesOffset', mainXRefEntriesOffset);
  2574. },
  2575. // Find the header, remove leading garbage and setup the stream
  2576. // starting from the header.
  2577. checkHeader: function PDFDocument_checkHeader() {
  2578. var stream = this.stream;
  2579. stream.reset();
  2580. if (find(stream, '%PDF-', 1024)) {
  2581. // Found the header, trim off any garbage before it.
  2582. stream.moveStart();
  2583. // Reading file format version
  2584. var MAX_VERSION_LENGTH = 12;
  2585. var version = '', ch;
  2586. while ((ch = stream.getByte()) > 0x20) { // SPACE
  2587. if (version.length >= MAX_VERSION_LENGTH) {
  2588. break;
  2589. }
  2590. version += String.fromCharCode(ch);
  2591. }
  2592. // removing "%PDF-"-prefix
  2593. this.pdfFormatVersion = version.substring(5);
  2594. return;
  2595. }
  2596. // May not be a PDF file, continue anyway.
  2597. },
  2598. parseStartXRef: function PDFDocument_parseStartXRef() {
  2599. var startXRef = this.startXRef;
  2600. this.xref.setStartXRef(startXRef);
  2601. },
  2602. setup: function PDFDocument_setup(recoveryMode) {
  2603. this.xref.parse(recoveryMode);
  2604. this.catalog = new Catalog(this.pdfManager, this.xref);
  2605. },
  2606. get numPages() {
  2607. var linearization = this.linearization;
  2608. var num = linearization ? linearization.numPages : this.catalog.numPages;
  2609. // shadow the prototype getter
  2610. return shadow(this, 'numPages', num);
  2611. },
  2612. get documentInfo() {
  2613. var docInfo = {
  2614. PDFFormatVersion: this.pdfFormatVersion,
  2615. IsAcroFormPresent: !!this.acroForm,
  2616. IsXFAPresent: !!this.xfa
  2617. };
  2618. var infoDict;
  2619. try {
  2620. infoDict = this.xref.trailer.get('Info');
  2621. } catch (err) {
  2622. info('The document information dictionary is invalid.');
  2623. }
  2624. if (infoDict) {
  2625. var validEntries = DocumentInfoValidators.entries;
  2626. // Only fill the document info with valid entries from the spec.
  2627. for (var key in validEntries) {
  2628. if (infoDict.has(key)) {
  2629. var value = infoDict.get(key);
  2630. // Make sure the value conforms to the spec.
  2631. if (validEntries[key](value)) {
  2632. docInfo[key] = (typeof value !== 'string' ?
  2633. value : stringToPDFString(value));
  2634. } else {
  2635. info('Bad value in document info for "' + key + '"');
  2636. }
  2637. }
  2638. }
  2639. }
  2640. return shadow(this, 'documentInfo', docInfo);
  2641. },
  2642. get fingerprint() {
  2643. var xref = this.xref, hash, fileID = '';
  2644. if (xref.trailer.has('ID')) {
  2645. hash = stringToBytes(xref.trailer.get('ID')[0]);
  2646. } else {
  2647. hash = calculateMD5(this.stream.bytes.subarray(0, 100), 0, 100);
  2648. }
  2649. for (var i = 0, n = hash.length; i < n; i++) {
  2650. fileID += hash[i].toString(16);
  2651. }
  2652. return shadow(this, 'fingerprint', fileID);
  2653. },
  2654. getPage: function PDFDocument_getPage(pageIndex) {
  2655. return this.catalog.getPage(pageIndex);
  2656. },
  2657. cleanup: function PDFDocument_cleanup() {
  2658. return this.catalog.cleanup();
  2659. }
  2660. };
  2661. return PDFDocument;
  2662. })();
  2663. var Name = (function NameClosure() {
  2664. function Name(name) {
  2665. this.name = name;
  2666. }
  2667. Name.prototype = {};
  2668. var nameCache = {};
  2669. Name.get = function Name_get(name) {
  2670. var nameValue = nameCache[name];
  2671. return (nameValue ? nameValue : (nameCache[name] = new Name(name)));
  2672. };
  2673. return Name;
  2674. })();
  2675. var Cmd = (function CmdClosure() {
  2676. function Cmd(cmd) {
  2677. this.cmd = cmd;
  2678. }
  2679. Cmd.prototype = {};
  2680. var cmdCache = {};
  2681. Cmd.get = function Cmd_get(cmd) {
  2682. var cmdValue = cmdCache[cmd];
  2683. return (cmdValue ? cmdValue : (cmdCache[cmd] = new Cmd(cmd)));
  2684. };
  2685. return Cmd;
  2686. })();
  2687. var Dict = (function DictClosure() {
  2688. var nonSerializable = function nonSerializableClosure() {
  2689. return nonSerializable; // creating closure on some variable
  2690. };
  2691. var GETALL_DICTIONARY_TYPES_WHITELIST = {
  2692. 'Background': true,
  2693. 'ExtGState': true,
  2694. 'Halftone': true,
  2695. 'Layout': true,
  2696. 'Mask': true,
  2697. 'Pagination': true,
  2698. 'Printing': true
  2699. };
  2700. function isRecursionAllowedFor(dict) {
  2701. if (!isName(dict.Type)) {
  2702. return true;
  2703. }
  2704. var dictType = dict.Type.name;
  2705. return GETALL_DICTIONARY_TYPES_WHITELIST[dictType] === true;
  2706. }
  2707. // xref is optional
  2708. function Dict(xref) {
  2709. // Map should only be used internally, use functions below to access.
  2710. this.map = Object.create(null);
  2711. this.xref = xref;
  2712. this.objId = null;
  2713. this.__nonSerializable__ = nonSerializable; // disable cloning of the Dict
  2714. }
  2715. Dict.prototype = {
  2716. assignXref: function Dict_assignXref(newXref) {
  2717. this.xref = newXref;
  2718. },
  2719. // automatically dereferences Ref objects
  2720. get: function Dict_get(key1, key2, key3) {
  2721. var value;
  2722. var xref = this.xref;
  2723. if (typeof (value = this.map[key1]) != 'undefined' || key1 in this.map ||
  2724. typeof key2 == 'undefined') {
  2725. return xref ? xref.fetchIfRef(value) : value;
  2726. }
  2727. if (typeof (value = this.map[key2]) != 'undefined' || key2 in this.map ||
  2728. typeof key3 == 'undefined') {
  2729. return xref ? xref.fetchIfRef(value) : value;
  2730. }
  2731. value = this.map[key3] || null;
  2732. return xref ? xref.fetchIfRef(value) : value;
  2733. },
  2734. // Same as get(), but returns a promise and uses fetchIfRefAsync().
  2735. getAsync: function Dict_getAsync(key1, key2, key3) {
  2736. var value;
  2737. var xref = this.xref;
  2738. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  2739. typeof key2 === 'undefined') {
  2740. if (xref) {
  2741. return xref.fetchIfRefAsync(value);
  2742. }
  2743. return Promise.resolve(value);
  2744. }
  2745. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  2746. typeof key3 === 'undefined') {
  2747. if (xref) {
  2748. return xref.fetchIfRefAsync(value);
  2749. }
  2750. return Promise.resolve(value);
  2751. }
  2752. value = this.map[key3] || null;
  2753. if (xref) {
  2754. return xref.fetchIfRefAsync(value);
  2755. }
  2756. return Promise.resolve(value);
  2757. },
  2758. // no dereferencing
  2759. getRaw: function Dict_getRaw(key) {
  2760. return this.map[key];
  2761. },
  2762. // creates new map and dereferences all Refs
  2763. getAll: function Dict_getAll() {
  2764. var all = Object.create(null);
  2765. var queue = null;
  2766. var key, obj;
  2767. for (key in this.map) {
  2768. obj = this.get(key);
  2769. if (obj instanceof Dict) {
  2770. if (isRecursionAllowedFor(obj)) {
  2771. (queue || (queue = [])).push({target: all, key: key, obj: obj});
  2772. } else {
  2773. all[key] = this.getRaw(key);
  2774. }
  2775. } else {
  2776. all[key] = obj;
  2777. }
  2778. }
  2779. if (!queue) {
  2780. return all;
  2781. }
  2782. // trying to take cyclic references into the account
  2783. var processed = Object.create(null);
  2784. while (queue.length > 0) {
  2785. var item = queue.shift();
  2786. var itemObj = item.obj;
  2787. var objId = itemObj.objId;
  2788. if (objId && objId in processed) {
  2789. item.target[item.key] = processed[objId];
  2790. continue;
  2791. }
  2792. var dereferenced = Object.create(null);
  2793. for (key in itemObj.map) {
  2794. obj = itemObj.get(key);
  2795. if (obj instanceof Dict) {
  2796. if (isRecursionAllowedFor(obj)) {
  2797. queue.push({target: dereferenced, key: key, obj: obj});
  2798. } else {
  2799. dereferenced[key] = itemObj.getRaw(key);
  2800. }
  2801. } else {
  2802. dereferenced[key] = obj;
  2803. }
  2804. }
  2805. if (objId) {
  2806. processed[objId] = dereferenced;
  2807. }
  2808. item.target[item.key] = dereferenced;
  2809. }
  2810. return all;
  2811. },
  2812. set: function Dict_set(key, value) {
  2813. this.map[key] = value;
  2814. },
  2815. has: function Dict_has(key) {
  2816. return key in this.map;
  2817. },
  2818. forEach: function Dict_forEach(callback) {
  2819. for (var key in this.map) {
  2820. callback(key, this.get(key));
  2821. }
  2822. }
  2823. };
  2824. Dict.empty = new Dict(null);
  2825. return Dict;
  2826. })();
  2827. var Ref = (function RefClosure() {
  2828. function Ref(num, gen) {
  2829. this.num = num;
  2830. this.gen = gen;
  2831. }
  2832. Ref.prototype = {
  2833. toString: function Ref_toString() {
  2834. // This function is hot, so we make the string as compact as possible.
  2835. // |this.gen| is almost always zero, so we treat that case specially.
  2836. var str = this.num + 'R';
  2837. if (this.gen !== 0) {
  2838. str += this.gen;
  2839. }
  2840. return str;
  2841. }
  2842. };
  2843. return Ref;
  2844. })();
  2845. // The reference is identified by number and generation.
  2846. // This structure stores only one instance of the reference.
  2847. var RefSet = (function RefSetClosure() {
  2848. function RefSet() {
  2849. this.dict = {};
  2850. }
  2851. RefSet.prototype = {
  2852. has: function RefSet_has(ref) {
  2853. return ref.toString() in this.dict;
  2854. },
  2855. put: function RefSet_put(ref) {
  2856. this.dict[ref.toString()] = true;
  2857. },
  2858. remove: function RefSet_remove(ref) {
  2859. delete this.dict[ref.toString()];
  2860. }
  2861. };
  2862. return RefSet;
  2863. })();
  2864. var RefSetCache = (function RefSetCacheClosure() {
  2865. function RefSetCache() {
  2866. this.dict = Object.create(null);
  2867. }
  2868. RefSetCache.prototype = {
  2869. get: function RefSetCache_get(ref) {
  2870. return this.dict[ref.toString()];
  2871. },
  2872. has: function RefSetCache_has(ref) {
  2873. return ref.toString() in this.dict;
  2874. },
  2875. put: function RefSetCache_put(ref, obj) {
  2876. this.dict[ref.toString()] = obj;
  2877. },
  2878. putAlias: function RefSetCache_putAlias(ref, aliasRef) {
  2879. this.dict[ref.toString()] = this.get(aliasRef);
  2880. },
  2881. forEach: function RefSetCache_forEach(fn, thisArg) {
  2882. for (var i in this.dict) {
  2883. fn.call(thisArg, this.dict[i]);
  2884. }
  2885. },
  2886. clear: function RefSetCache_clear() {
  2887. this.dict = Object.create(null);
  2888. }
  2889. };
  2890. return RefSetCache;
  2891. })();
  2892. var Catalog = (function CatalogClosure() {
  2893. function Catalog(pdfManager, xref) {
  2894. this.pdfManager = pdfManager;
  2895. this.xref = xref;
  2896. this.catDict = xref.getCatalogObj();
  2897. this.fontCache = new RefSetCache();
  2898. assert(isDict(this.catDict),
  2899. 'catalog object is not a dictionary');
  2900. this.pagePromises = [];
  2901. }
  2902. Catalog.prototype = {
  2903. get metadata() {
  2904. var streamRef = this.catDict.getRaw('Metadata');
  2905. if (!isRef(streamRef)) {
  2906. return shadow(this, 'metadata', null);
  2907. }
  2908. var encryptMetadata = (!this.xref.encrypt ? false :
  2909. this.xref.encrypt.encryptMetadata);
  2910. var stream = this.xref.fetch(streamRef, !encryptMetadata);
  2911. var metadata;
  2912. if (stream && isDict(stream.dict)) {
  2913. var type = stream.dict.get('Type');
  2914. var subtype = stream.dict.get('Subtype');
  2915. if (isName(type) && isName(subtype) &&
  2916. type.name === 'Metadata' && subtype.name === 'XML') {
  2917. // XXX: This should examine the charset the XML document defines,
  2918. // however since there are currently no real means to decode
  2919. // arbitrary charsets, let's just hope that the author of the PDF
  2920. // was reasonable enough to stick with the XML default charset,
  2921. // which is UTF-8.
  2922. try {
  2923. metadata = stringToUTF8String(bytesToString(stream.getBytes()));
  2924. } catch (e) {
  2925. info('Skipping invalid metadata.');
  2926. }
  2927. }
  2928. }
  2929. return shadow(this, 'metadata', metadata);
  2930. },
  2931. get toplevelPagesDict() {
  2932. var pagesObj = this.catDict.get('Pages');
  2933. assert(isDict(pagesObj), 'invalid top-level pages dictionary');
  2934. // shadow the prototype getter
  2935. return shadow(this, 'toplevelPagesDict', pagesObj);
  2936. },
  2937. get documentOutline() {
  2938. var obj = null;
  2939. try {
  2940. obj = this.readDocumentOutline();
  2941. } catch (ex) {
  2942. if (ex instanceof MissingDataException) {
  2943. throw ex;
  2944. }
  2945. warn('Unable to read document outline');
  2946. }
  2947. return shadow(this, 'documentOutline', obj);
  2948. },
  2949. readDocumentOutline: function Catalog_readDocumentOutline() {
  2950. var xref = this.xref;
  2951. var obj = this.catDict.get('Outlines');
  2952. var root = { items: [] };
  2953. if (isDict(obj)) {
  2954. obj = obj.getRaw('First');
  2955. var processed = new RefSet();
  2956. if (isRef(obj)) {
  2957. var queue = [{obj: obj, parent: root}];
  2958. // to avoid recursion keeping track of the items
  2959. // in the processed dictionary
  2960. processed.put(obj);
  2961. while (queue.length > 0) {
  2962. var i = queue.shift();
  2963. var outlineDict = xref.fetchIfRef(i.obj);
  2964. if (outlineDict === null) {
  2965. continue;
  2966. }
  2967. if (!outlineDict.has('Title')) {
  2968. error('Invalid outline item');
  2969. }
  2970. var dest = outlineDict.get('A');
  2971. if (dest) {
  2972. dest = dest.get('D');
  2973. } else if (outlineDict.has('Dest')) {
  2974. dest = outlineDict.getRaw('Dest');
  2975. if (isName(dest)) {
  2976. dest = dest.name;
  2977. }
  2978. }
  2979. var title = outlineDict.get('Title');
  2980. var outlineItem = {
  2981. dest: dest,
  2982. title: stringToPDFString(title),
  2983. color: outlineDict.get('C') || [0, 0, 0],
  2984. count: outlineDict.get('Count'),
  2985. bold: !!(outlineDict.get('F') & 2),
  2986. italic: !!(outlineDict.get('F') & 1),
  2987. items: []
  2988. };
  2989. i.parent.items.push(outlineItem);
  2990. obj = outlineDict.getRaw('First');
  2991. if (isRef(obj) && !processed.has(obj)) {
  2992. queue.push({obj: obj, parent: outlineItem});
  2993. processed.put(obj);
  2994. }
  2995. obj = outlineDict.getRaw('Next');
  2996. if (isRef(obj) && !processed.has(obj)) {
  2997. queue.push({obj: obj, parent: i.parent});
  2998. processed.put(obj);
  2999. }
  3000. }
  3001. }
  3002. }
  3003. return (root.items.length > 0 ? root.items : null);
  3004. },
  3005. get numPages() {
  3006. var obj = this.toplevelPagesDict.get('Count');
  3007. assert(
  3008. isInt(obj),
  3009. 'page count in top level pages object is not an integer'
  3010. );
  3011. // shadow the prototype getter
  3012. return shadow(this, 'num', obj);
  3013. },
  3014. get destinations() {
  3015. function fetchDestination(dest) {
  3016. return isDict(dest) ? dest.get('D') : dest;
  3017. }
  3018. var xref = this.xref;
  3019. var dests = {}, nameTreeRef, nameDictionaryRef;
  3020. var obj = this.catDict.get('Names');
  3021. if (obj && obj.has('Dests')) {
  3022. nameTreeRef = obj.getRaw('Dests');
  3023. } else if (this.catDict.has('Dests')) {
  3024. nameDictionaryRef = this.catDict.get('Dests');
  3025. }
  3026. if (nameDictionaryRef) {
  3027. // reading simple destination dictionary
  3028. obj = nameDictionaryRef;
  3029. obj.forEach(function catalogForEach(key, value) {
  3030. if (!value) {
  3031. return;
  3032. }
  3033. dests[key] = fetchDestination(value);
  3034. });
  3035. }
  3036. if (nameTreeRef) {
  3037. var nameTree = new NameTree(nameTreeRef, xref);
  3038. var names = nameTree.getAll();
  3039. for (var name in names) {
  3040. if (!names.hasOwnProperty(name)) {
  3041. continue;
  3042. }
  3043. dests[name] = fetchDestination(names[name]);
  3044. }
  3045. }
  3046. return shadow(this, 'destinations', dests);
  3047. },
  3048. get attachments() {
  3049. var xref = this.xref;
  3050. var attachments = null, nameTreeRef;
  3051. var obj = this.catDict.get('Names');
  3052. if (obj) {
  3053. nameTreeRef = obj.getRaw('EmbeddedFiles');
  3054. }
  3055. if (nameTreeRef) {
  3056. var nameTree = new NameTree(nameTreeRef, xref);
  3057. var names = nameTree.getAll();
  3058. for (var name in names) {
  3059. if (!names.hasOwnProperty(name)) {
  3060. continue;
  3061. }
  3062. var fs = new FileSpec(names[name], xref);
  3063. if (!attachments) {
  3064. attachments = {};
  3065. }
  3066. attachments[stringToPDFString(name)] = fs.serializable;
  3067. }
  3068. }
  3069. return shadow(this, 'attachments', attachments);
  3070. },
  3071. get javaScript() {
  3072. var xref = this.xref;
  3073. var obj = this.catDict.get('Names');
  3074. var javaScript = [];
  3075. if (obj && obj.has('JavaScript')) {
  3076. var nameTree = new NameTree(obj.getRaw('JavaScript'), xref);
  3077. var names = nameTree.getAll();
  3078. for (var name in names) {
  3079. if (!names.hasOwnProperty(name)) {
  3080. continue;
  3081. }
  3082. // We don't really use the JavaScript right now. This code is
  3083. // defensive so we don't cause errors on document load.
  3084. var jsDict = names[name];
  3085. if (!isDict(jsDict)) {
  3086. continue;
  3087. }
  3088. var type = jsDict.get('S');
  3089. if (!isName(type) || type.name !== 'JavaScript') {
  3090. continue;
  3091. }
  3092. var js = jsDict.get('JS');
  3093. if (!isString(js) && !isStream(js)) {
  3094. continue;
  3095. }
  3096. if (isStream(js)) {
  3097. js = bytesToString(js.getBytes());
  3098. }
  3099. javaScript.push(stringToPDFString(js));
  3100. }
  3101. }
  3102. // Append OpenAction actions to javaScript array
  3103. var openactionDict = this.catDict.get('OpenAction');
  3104. if (isDict(openactionDict)) {
  3105. var objType = openactionDict.get('Type');
  3106. var actionType = openactionDict.get('S');
  3107. var action = openactionDict.get('N');
  3108. var isPrintAction = (isName(objType) && objType.name === 'Action' &&
  3109. isName(actionType) && actionType.name === 'Named' &&
  3110. isName(action) && action.name === 'Print');
  3111. if (isPrintAction) {
  3112. javaScript.push('print(true);');
  3113. }
  3114. }
  3115. return shadow(this, 'javaScript', javaScript);
  3116. },
  3117. cleanup: function Catalog_cleanup() {
  3118. var promises = [];
  3119. this.fontCache.forEach(function (promise) {
  3120. promises.push(promise);
  3121. });
  3122. return Promise.all(promises).then(function (translatedFonts) {
  3123. for (var i = 0, ii = translatedFonts.length; i < ii; i++) {
  3124. var font = translatedFonts[i].dict;
  3125. delete font.translated;
  3126. }
  3127. this.fontCache.clear();
  3128. }.bind(this));
  3129. },
  3130. getPage: function Catalog_getPage(pageIndex) {
  3131. if (!(pageIndex in this.pagePromises)) {
  3132. this.pagePromises[pageIndex] = this.getPageDict(pageIndex).then(
  3133. function (a) {
  3134. var dict = a[0];
  3135. var ref = a[1];
  3136. return new Page(this.pdfManager, this.xref, pageIndex, dict, ref,
  3137. this.fontCache);
  3138. }.bind(this)
  3139. );
  3140. }
  3141. return this.pagePromises[pageIndex];
  3142. },
  3143. getPageDict: function Catalog_getPageDict(pageIndex) {
  3144. var capability = createPromiseCapability();
  3145. var nodesToVisit = [this.catDict.getRaw('Pages')];
  3146. var currentPageIndex = 0;
  3147. var xref = this.xref;
  3148. function next() {
  3149. while (nodesToVisit.length) {
  3150. var currentNode = nodesToVisit.pop();
  3151. if (isRef(currentNode)) {
  3152. xref.fetchAsync(currentNode).then(function (obj) {
  3153. if ((isDict(obj, 'Page') || (isDict(obj) && !obj.has('Kids')))) {
  3154. if (pageIndex === currentPageIndex) {
  3155. capability.resolve([obj, currentNode]);
  3156. } else {
  3157. currentPageIndex++;
  3158. next();
  3159. }
  3160. return;
  3161. }
  3162. nodesToVisit.push(obj);
  3163. next();
  3164. }.bind(this), capability.reject.bind(capability));
  3165. return;
  3166. }
  3167. // must be a child page dictionary
  3168. assert(
  3169. isDict(currentNode),
  3170. 'page dictionary kid reference points to wrong type of object'
  3171. );
  3172. var count = currentNode.get('Count');
  3173. // Skip nodes where the page can't be.
  3174. if (currentPageIndex + count <= pageIndex) {
  3175. currentPageIndex += count;
  3176. continue;
  3177. }
  3178. var kids = currentNode.get('Kids');
  3179. assert(isArray(kids), 'page dictionary kids object is not an array');
  3180. if (count === kids.length) {
  3181. // Nodes that don't have the page have been skipped and this is the
  3182. // bottom of the tree which means the page requested must be a
  3183. // descendant of this pages node. Ideally we would just resolve the
  3184. // promise with the page ref here, but there is the case where more
  3185. // pages nodes could link to single a page (see issue 3666 pdf). To
  3186. // handle this push it back on the queue so if it is a pages node it
  3187. // will be descended into.
  3188. nodesToVisit = [kids[pageIndex - currentPageIndex]];
  3189. currentPageIndex = pageIndex;
  3190. continue;
  3191. } else {
  3192. for (var last = kids.length - 1; last >= 0; last--) {
  3193. nodesToVisit.push(kids[last]);
  3194. }
  3195. }
  3196. }
  3197. capability.reject('Page index ' + pageIndex + ' not found.');
  3198. }
  3199. next();
  3200. return capability.promise;
  3201. },
  3202. getPageIndex: function Catalog_getPageIndex(ref) {
  3203. // The page tree nodes have the count of all the leaves below them. To get
  3204. // how many pages are before we just have to walk up the tree and keep
  3205. // adding the count of siblings to the left of the node.
  3206. var xref = this.xref;
  3207. function pagesBeforeRef(kidRef) {
  3208. var total = 0;
  3209. var parentRef;
  3210. return xref.fetchAsync(kidRef).then(function (node) {
  3211. if (!node) {
  3212. return null;
  3213. }
  3214. parentRef = node.getRaw('Parent');
  3215. return node.getAsync('Parent');
  3216. }).then(function (parent) {
  3217. if (!parent) {
  3218. return null;
  3219. }
  3220. return parent.getAsync('Kids');
  3221. }).then(function (kids) {
  3222. if (!kids) {
  3223. return null;
  3224. }
  3225. var kidPromises = [];
  3226. var found = false;
  3227. for (var i = 0; i < kids.length; i++) {
  3228. var kid = kids[i];
  3229. assert(isRef(kid), 'kids must be a ref');
  3230. if (kid.num == kidRef.num) {
  3231. found = true;
  3232. break;
  3233. }
  3234. kidPromises.push(xref.fetchAsync(kid).then(function (kid) {
  3235. if (kid.has('Count')) {
  3236. var count = kid.get('Count');
  3237. total += count;
  3238. } else { // page leaf node
  3239. total++;
  3240. }
  3241. }));
  3242. }
  3243. if (!found) {
  3244. error('kid ref not found in parents kids');
  3245. }
  3246. return Promise.all(kidPromises).then(function () {
  3247. return [total, parentRef];
  3248. });
  3249. });
  3250. }
  3251. var total = 0;
  3252. function next(ref) {
  3253. return pagesBeforeRef(ref).then(function (args) {
  3254. if (!args) {
  3255. return total;
  3256. }
  3257. var count = args[0];
  3258. var parentRef = args[1];
  3259. total += count;
  3260. return next(parentRef);
  3261. });
  3262. }
  3263. return next(ref);
  3264. }
  3265. };
  3266. return Catalog;
  3267. })();
  3268. var XRef = (function XRefClosure() {
  3269. function XRef(stream, password) {
  3270. this.stream = stream;
  3271. this.entries = [];
  3272. this.xrefstms = {};
  3273. // prepare the XRef cache
  3274. this.cache = [];
  3275. this.password = password;
  3276. this.stats = {
  3277. streamTypes: [],
  3278. fontTypes: []
  3279. };
  3280. }
  3281. XRef.prototype = {
  3282. setStartXRef: function XRef_setStartXRef(startXRef) {
  3283. // Store the starting positions of xref tables as we process them
  3284. // so we can recover from missing data errors
  3285. this.startXRefQueue = [startXRef];
  3286. },
  3287. parse: function XRef_parse(recoveryMode) {
  3288. var trailerDict;
  3289. if (!recoveryMode) {
  3290. trailerDict = this.readXRef();
  3291. } else {
  3292. warn('Indexing all PDF objects');
  3293. trailerDict = this.indexObjects();
  3294. }
  3295. trailerDict.assignXref(this);
  3296. this.trailer = trailerDict;
  3297. var encrypt = trailerDict.get('Encrypt');
  3298. if (encrypt) {
  3299. var ids = trailerDict.get('ID');
  3300. var fileId = (ids && ids.length) ? ids[0] : '';
  3301. this.encrypt = new CipherTransformFactory(encrypt, fileId,
  3302. this.password);
  3303. }
  3304. // get the root dictionary (catalog) object
  3305. if (!(this.root = trailerDict.get('Root'))) {
  3306. error('Invalid root reference');
  3307. }
  3308. },
  3309. processXRefTable: function XRef_processXRefTable(parser) {
  3310. if (!('tableState' in this)) {
  3311. // Stores state of the table as we process it so we can resume
  3312. // from middle of table in case of missing data error
  3313. this.tableState = {
  3314. entryNum: 0,
  3315. streamPos: parser.lexer.stream.pos,
  3316. parserBuf1: parser.buf1,
  3317. parserBuf2: parser.buf2
  3318. };
  3319. }
  3320. var obj = this.readXRefTable(parser);
  3321. // Sanity check
  3322. if (!isCmd(obj, 'trailer')) {
  3323. error('Invalid XRef table: could not find trailer dictionary');
  3324. }
  3325. // Read trailer dictionary, e.g.
  3326. // trailer
  3327. // << /Size 22
  3328. // /Root 20R
  3329. // /Info 10R
  3330. // /ID [ <81b14aafa313db63dbd6f981e49f94f4> ]
  3331. // >>
  3332. // The parser goes through the entire stream << ... >> and provides
  3333. // a getter interface for the key-value table
  3334. var dict = parser.getObj();
  3335. // The pdflib PDF generator can generate a nested trailer dictionary
  3336. if (!isDict(dict) && dict.dict) {
  3337. dict = dict.dict;
  3338. }
  3339. if (!isDict(dict)) {
  3340. error('Invalid XRef table: could not parse trailer dictionary');
  3341. }
  3342. delete this.tableState;
  3343. return dict;
  3344. },
  3345. readXRefTable: function XRef_readXRefTable(parser) {
  3346. // Example of cross-reference table:
  3347. // xref
  3348. // 0 1 <-- subsection header (first obj #, obj count)
  3349. // 0000000000 65535 f <-- actual object (offset, generation #, f/n)
  3350. // 23 2 <-- subsection header ... and so on ...
  3351. // 0000025518 00002 n
  3352. // 0000025635 00000 n
  3353. // trailer
  3354. // ...
  3355. var stream = parser.lexer.stream;
  3356. var tableState = this.tableState;
  3357. stream.pos = tableState.streamPos;
  3358. parser.buf1 = tableState.parserBuf1;
  3359. parser.buf2 = tableState.parserBuf2;
  3360. // Outer loop is over subsection headers
  3361. var obj;
  3362. while (true) {
  3363. if (!('firstEntryNum' in tableState) || !('entryCount' in tableState)) {
  3364. if (isCmd(obj = parser.getObj(), 'trailer')) {
  3365. break;
  3366. }
  3367. tableState.firstEntryNum = obj;
  3368. tableState.entryCount = parser.getObj();
  3369. }
  3370. var first = tableState.firstEntryNum;
  3371. var count = tableState.entryCount;
  3372. if (!isInt(first) || !isInt(count)) {
  3373. error('Invalid XRef table: wrong types in subsection header');
  3374. }
  3375. // Inner loop is over objects themselves
  3376. for (var i = tableState.entryNum; i < count; i++) {
  3377. tableState.streamPos = stream.pos;
  3378. tableState.entryNum = i;
  3379. tableState.parserBuf1 = parser.buf1;
  3380. tableState.parserBuf2 = parser.buf2;
  3381. var entry = {};
  3382. entry.offset = parser.getObj();
  3383. entry.gen = parser.getObj();
  3384. var type = parser.getObj();
  3385. if (isCmd(type, 'f')) {
  3386. entry.free = true;
  3387. } else if (isCmd(type, 'n')) {
  3388. entry.uncompressed = true;
  3389. }
  3390. // Validate entry obj
  3391. if (!isInt(entry.offset) || !isInt(entry.gen) ||
  3392. !(entry.free || entry.uncompressed)) {
  3393. console.log(entry.offset, entry.gen, entry.free,
  3394. entry.uncompressed);
  3395. error('Invalid entry in XRef subsection: ' + first + ', ' + count);
  3396. }
  3397. if (!this.entries[i + first]) {
  3398. this.entries[i + first] = entry;
  3399. }
  3400. }
  3401. tableState.entryNum = 0;
  3402. tableState.streamPos = stream.pos;
  3403. tableState.parserBuf1 = parser.buf1;
  3404. tableState.parserBuf2 = parser.buf2;
  3405. delete tableState.firstEntryNum;
  3406. delete tableState.entryCount;
  3407. }
  3408. // Per issue 3248: hp scanners generate bad XRef
  3409. if (first === 1 && this.entries[1] && this.entries[1].free) {
  3410. // shifting the entries
  3411. this.entries.shift();
  3412. }
  3413. // Sanity check: as per spec, first object must be free
  3414. if (this.entries[0] && !this.entries[0].free) {
  3415. error('Invalid XRef table: unexpected first object');
  3416. }
  3417. return obj;
  3418. },
  3419. processXRefStream: function XRef_processXRefStream(stream) {
  3420. if (!('streamState' in this)) {
  3421. // Stores state of the stream as we process it so we can resume
  3422. // from middle of stream in case of missing data error
  3423. var streamParameters = stream.dict;
  3424. var byteWidths = streamParameters.get('W');
  3425. var range = streamParameters.get('Index');
  3426. if (!range) {
  3427. range = [0, streamParameters.get('Size')];
  3428. }
  3429. this.streamState = {
  3430. entryRanges: range,
  3431. byteWidths: byteWidths,
  3432. entryNum: 0,
  3433. streamPos: stream.pos
  3434. };
  3435. }
  3436. this.readXRefStream(stream);
  3437. delete this.streamState;
  3438. return stream.dict;
  3439. },
  3440. readXRefStream: function XRef_readXRefStream(stream) {
  3441. var i, j;
  3442. var streamState = this.streamState;
  3443. stream.pos = streamState.streamPos;
  3444. var byteWidths = streamState.byteWidths;
  3445. var typeFieldWidth = byteWidths[0];
  3446. var offsetFieldWidth = byteWidths[1];
  3447. var generationFieldWidth = byteWidths[2];
  3448. var entryRanges = streamState.entryRanges;
  3449. while (entryRanges.length > 0) {
  3450. var first = entryRanges[0];
  3451. var n = entryRanges[1];
  3452. if (!isInt(first) || !isInt(n)) {
  3453. error('Invalid XRef range fields: ' + first + ', ' + n);
  3454. }
  3455. if (!isInt(typeFieldWidth) || !isInt(offsetFieldWidth) ||
  3456. !isInt(generationFieldWidth)) {
  3457. error('Invalid XRef entry fields length: ' + first + ', ' + n);
  3458. }
  3459. for (i = streamState.entryNum; i < n; ++i) {
  3460. streamState.entryNum = i;
  3461. streamState.streamPos = stream.pos;
  3462. var type = 0, offset = 0, generation = 0;
  3463. for (j = 0; j < typeFieldWidth; ++j) {
  3464. type = (type << 8) | stream.getByte();
  3465. }
  3466. // if type field is absent, its default value is 1
  3467. if (typeFieldWidth === 0) {
  3468. type = 1;
  3469. }
  3470. for (j = 0; j < offsetFieldWidth; ++j) {
  3471. offset = (offset << 8) | stream.getByte();
  3472. }
  3473. for (j = 0; j < generationFieldWidth; ++j) {
  3474. generation = (generation << 8) | stream.getByte();
  3475. }
  3476. var entry = {};
  3477. entry.offset = offset;
  3478. entry.gen = generation;
  3479. switch (type) {
  3480. case 0:
  3481. entry.free = true;
  3482. break;
  3483. case 1:
  3484. entry.uncompressed = true;
  3485. break;
  3486. case 2:
  3487. break;
  3488. default:
  3489. error('Invalid XRef entry type: ' + type);
  3490. }
  3491. if (!this.entries[first + i]) {
  3492. this.entries[first + i] = entry;
  3493. }
  3494. }
  3495. streamState.entryNum = 0;
  3496. streamState.streamPos = stream.pos;
  3497. entryRanges.splice(0, 2);
  3498. }
  3499. },
  3500. indexObjects: function XRef_indexObjects() {
  3501. // Simple scan through the PDF content to find objects,
  3502. // trailers and XRef streams.
  3503. function readToken(data, offset) {
  3504. var token = '', ch = data[offset];
  3505. while (ch !== 13 && ch !== 10) {
  3506. if (++offset >= data.length) {
  3507. break;
  3508. }
  3509. token += String.fromCharCode(ch);
  3510. ch = data[offset];
  3511. }
  3512. return token;
  3513. }
  3514. function skipUntil(data, offset, what) {
  3515. var length = what.length, dataLength = data.length;
  3516. var skipped = 0;
  3517. // finding byte sequence
  3518. while (offset < dataLength) {
  3519. var i = 0;
  3520. while (i < length && data[offset + i] == what[i]) {
  3521. ++i;
  3522. }
  3523. if (i >= length) {
  3524. break; // sequence found
  3525. }
  3526. offset++;
  3527. skipped++;
  3528. }
  3529. return skipped;
  3530. }
  3531. var trailerBytes = new Uint8Array([116, 114, 97, 105, 108, 101, 114]);
  3532. var startxrefBytes = new Uint8Array([115, 116, 97, 114, 116, 120, 114,
  3533. 101, 102]);
  3534. var endobjBytes = new Uint8Array([101, 110, 100, 111, 98, 106]);
  3535. var xrefBytes = new Uint8Array([47, 88, 82, 101, 102]);
  3536. var stream = this.stream;
  3537. stream.pos = 0;
  3538. var buffer = stream.getBytes();
  3539. var position = stream.start, length = buffer.length;
  3540. var trailers = [], xrefStms = [];
  3541. while (position < length) {
  3542. var ch = buffer[position];
  3543. if (ch === 32 || ch === 9 || ch === 13 || ch === 10) {
  3544. ++position;
  3545. continue;
  3546. }
  3547. if (ch === 37) { // %-comment
  3548. do {
  3549. ++position;
  3550. if (position >= length) {
  3551. break;
  3552. }
  3553. ch = buffer[position];
  3554. } while (ch !== 13 && ch !== 10);
  3555. continue;
  3556. }
  3557. var token = readToken(buffer, position);
  3558. var m;
  3559. if (token === 'xref') {
  3560. position += skipUntil(buffer, position, trailerBytes);
  3561. trailers.push(position);
  3562. position += skipUntil(buffer, position, startxrefBytes);
  3563. } else if ((m = /^(\d+)\s+(\d+)\s+obj\b/.exec(token))) {
  3564. this.entries[m[1]] = {
  3565. offset: position,
  3566. gen: m[2] | 0,
  3567. uncompressed: true
  3568. };
  3569. var contentLength = skipUntil(buffer, position, endobjBytes) + 7;
  3570. var content = buffer.subarray(position, position + contentLength);
  3571. // checking XRef stream suspect
  3572. // (it shall have '/XRef' and next char is not a letter)
  3573. var xrefTagOffset = skipUntil(content, 0, xrefBytes);
  3574. if (xrefTagOffset < contentLength &&
  3575. content[xrefTagOffset + 5] < 64) {
  3576. xrefStms.push(position);
  3577. this.xrefstms[position] = 1; // don't read it recursively
  3578. }
  3579. position += contentLength;
  3580. } else {
  3581. position += token.length + 1;
  3582. }
  3583. }
  3584. // reading XRef streams
  3585. var i, ii;
  3586. for (i = 0, ii = xrefStms.length; i < ii; ++i) {
  3587. this.startXRefQueue.push(xrefStms[i]);
  3588. this.readXRef(/* recoveryMode */ true);
  3589. }
  3590. // finding main trailer
  3591. var dict;
  3592. for (i = 0, ii = trailers.length; i < ii; ++i) {
  3593. stream.pos = trailers[i];
  3594. var parser = new Parser(new Lexer(stream), true, this);
  3595. var obj = parser.getObj();
  3596. if (!isCmd(obj, 'trailer')) {
  3597. continue;
  3598. }
  3599. // read the trailer dictionary
  3600. if (!isDict(dict = parser.getObj())) {
  3601. continue;
  3602. }
  3603. // taking the first one with 'ID'
  3604. if (dict.has('ID')) {
  3605. return dict;
  3606. }
  3607. }
  3608. // no tailer with 'ID', taking last one (if exists)
  3609. if (dict) {
  3610. return dict;
  3611. }
  3612. // nothing helps
  3613. // calling error() would reject worker with an UnknownErrorException.
  3614. throw new InvalidPDFException('Invalid PDF structure');
  3615. },
  3616. readXRef: function XRef_readXRef(recoveryMode) {
  3617. var stream = this.stream;
  3618. try {
  3619. while (this.startXRefQueue.length) {
  3620. var startXRef = this.startXRefQueue[0];
  3621. stream.pos = startXRef + stream.start;
  3622. var parser = new Parser(new Lexer(stream), true, this);
  3623. var obj = parser.getObj();
  3624. var dict;
  3625. // Get dictionary
  3626. if (isCmd(obj, 'xref')) {
  3627. // Parse end-of-file XRef
  3628. dict = this.processXRefTable(parser);
  3629. if (!this.topDict) {
  3630. this.topDict = dict;
  3631. }
  3632. // Recursively get other XRefs 'XRefStm', if any
  3633. obj = dict.get('XRefStm');
  3634. if (isInt(obj)) {
  3635. var pos = obj;
  3636. // ignore previously loaded xref streams
  3637. // (possible infinite recursion)
  3638. if (!(pos in this.xrefstms)) {
  3639. this.xrefstms[pos] = 1;
  3640. this.startXRefQueue.push(pos);
  3641. }
  3642. }
  3643. } else if (isInt(obj)) {
  3644. // Parse in-stream XRef
  3645. if (!isInt(parser.getObj()) ||
  3646. !isCmd(parser.getObj(), 'obj') ||
  3647. !isStream(obj = parser.getObj())) {
  3648. error('Invalid XRef stream');
  3649. }
  3650. dict = this.processXRefStream(obj);
  3651. if (!this.topDict) {
  3652. this.topDict = dict;
  3653. }
  3654. if (!dict) {
  3655. error('Failed to read XRef stream');
  3656. }
  3657. } else {
  3658. error('Invalid XRef stream header');
  3659. }
  3660. // Recursively get previous dictionary, if any
  3661. obj = dict.get('Prev');
  3662. if (isInt(obj)) {
  3663. this.startXRefQueue.push(obj);
  3664. } else if (isRef(obj)) {
  3665. // The spec says Prev must not be a reference, i.e. "/Prev NNN"
  3666. // This is a fallback for non-compliant PDFs, i.e. "/Prev NNN 0 R"
  3667. this.startXRefQueue.push(obj.num);
  3668. }
  3669. this.startXRefQueue.shift();
  3670. }
  3671. return this.topDict;
  3672. } catch (e) {
  3673. if (e instanceof MissingDataException) {
  3674. throw e;
  3675. }
  3676. info('(while reading XRef): ' + e);
  3677. }
  3678. if (recoveryMode) {
  3679. return;
  3680. }
  3681. throw new XRefParseException();
  3682. },
  3683. getEntry: function XRef_getEntry(i) {
  3684. var xrefEntry = this.entries[i];
  3685. if (xrefEntry && !xrefEntry.free && xrefEntry.offset) {
  3686. return xrefEntry;
  3687. }
  3688. return null;
  3689. },
  3690. fetchIfRef: function XRef_fetchIfRef(obj) {
  3691. if (!isRef(obj)) {
  3692. return obj;
  3693. }
  3694. return this.fetch(obj);
  3695. },
  3696. fetch: function XRef_fetch(ref, suppressEncryption) {
  3697. assert(isRef(ref), 'ref object is not a reference');
  3698. var num = ref.num;
  3699. if (num in this.cache) {
  3700. var cacheEntry = this.cache[num];
  3701. return cacheEntry;
  3702. }
  3703. var xrefEntry = this.getEntry(num);
  3704. // the referenced entry can be free
  3705. if (xrefEntry === null) {
  3706. return (this.cache[num] = null);
  3707. }
  3708. if (xrefEntry.uncompressed) {
  3709. xrefEntry = this.fetchUncompressed(ref, xrefEntry, suppressEncryption);
  3710. } else {
  3711. xrefEntry = this.fetchCompressed(xrefEntry, suppressEncryption);
  3712. }
  3713. if (isDict(xrefEntry)){
  3714. xrefEntry.objId = ref.toString();
  3715. } else if (isStream(xrefEntry)) {
  3716. xrefEntry.dict.objId = ref.toString();
  3717. }
  3718. return xrefEntry;
  3719. },
  3720. fetchUncompressed: function XRef_fetchUncompressed(ref, xrefEntry,
  3721. suppressEncryption) {
  3722. var gen = ref.gen;
  3723. var num = ref.num;
  3724. if (xrefEntry.gen !== gen) {
  3725. error('inconsistent generation in XRef');
  3726. }
  3727. var stream = this.stream.makeSubStream(xrefEntry.offset +
  3728. this.stream.start);
  3729. var parser = new Parser(new Lexer(stream), true, this);
  3730. var obj1 = parser.getObj();
  3731. var obj2 = parser.getObj();
  3732. var obj3 = parser.getObj();
  3733. if (!isInt(obj1) || parseInt(obj1, 10) !== num ||
  3734. !isInt(obj2) || parseInt(obj2, 10) !== gen ||
  3735. !isCmd(obj3)) {
  3736. error('bad XRef entry');
  3737. }
  3738. if (!isCmd(obj3, 'obj')) {
  3739. // some bad PDFs use "obj1234" and really mean 1234
  3740. if (obj3.cmd.indexOf('obj') === 0) {
  3741. num = parseInt(obj3.cmd.substring(3), 10);
  3742. if (!isNaN(num)) {
  3743. return num;
  3744. }
  3745. }
  3746. error('bad XRef entry');
  3747. }
  3748. if (this.encrypt && !suppressEncryption) {
  3749. xrefEntry = parser.getObj(this.encrypt.createCipherTransform(num, gen));
  3750. } else {
  3751. xrefEntry = parser.getObj();
  3752. }
  3753. if (!isStream(xrefEntry)) {
  3754. this.cache[num] = xrefEntry;
  3755. }
  3756. return xrefEntry;
  3757. },
  3758. fetchCompressed: function XRef_fetchCompressed(xrefEntry,
  3759. suppressEncryption) {
  3760. var tableOffset = xrefEntry.offset;
  3761. var stream = this.fetch(new Ref(tableOffset, 0));
  3762. if (!isStream(stream)) {
  3763. error('bad ObjStm stream');
  3764. }
  3765. var first = stream.dict.get('First');
  3766. var n = stream.dict.get('N');
  3767. if (!isInt(first) || !isInt(n)) {
  3768. error('invalid first and n parameters for ObjStm stream');
  3769. }
  3770. var parser = new Parser(new Lexer(stream), false, this);
  3771. parser.allowStreams = true;
  3772. var i, entries = [], num, nums = [];
  3773. // read the object numbers to populate cache
  3774. for (i = 0; i < n; ++i) {
  3775. num = parser.getObj();
  3776. if (!isInt(num)) {
  3777. error('invalid object number in the ObjStm stream: ' + num);
  3778. }
  3779. nums.push(num);
  3780. var offset = parser.getObj();
  3781. if (!isInt(offset)) {
  3782. error('invalid object offset in the ObjStm stream: ' + offset);
  3783. }
  3784. }
  3785. // read stream objects for cache
  3786. for (i = 0; i < n; ++i) {
  3787. entries.push(parser.getObj());
  3788. num = nums[i];
  3789. var entry = this.entries[num];
  3790. if (entry && entry.offset === tableOffset && entry.gen === i) {
  3791. this.cache[num] = entries[i];
  3792. }
  3793. }
  3794. xrefEntry = entries[xrefEntry.gen];
  3795. if (xrefEntry === undefined) {
  3796. error('bad XRef entry for compressed object');
  3797. }
  3798. return xrefEntry;
  3799. },
  3800. fetchIfRefAsync: function XRef_fetchIfRefAsync(obj) {
  3801. if (!isRef(obj)) {
  3802. return Promise.resolve(obj);
  3803. }
  3804. return this.fetchAsync(obj);
  3805. },
  3806. fetchAsync: function XRef_fetchAsync(ref, suppressEncryption) {
  3807. return new Promise(function (resolve, reject) {
  3808. var tryFetch = function () {
  3809. try {
  3810. resolve(this.fetch(ref, suppressEncryption));
  3811. } catch (e) {
  3812. if (e instanceof MissingDataException) {
  3813. this.stream.manager.requestRange(e.begin, e.end, tryFetch);
  3814. return;
  3815. }
  3816. reject(e);
  3817. }
  3818. }.bind(this);
  3819. tryFetch();
  3820. }.bind(this));
  3821. },
  3822. getCatalogObj: function XRef_getCatalogObj() {
  3823. return this.root;
  3824. }
  3825. };
  3826. return XRef;
  3827. })();
  3828. /**
  3829. * A NameTree is like a Dict but has some advantageous properties, see the
  3830. * spec (7.9.6) for more details.
  3831. * TODO: implement all the Dict functions and make this more efficent.
  3832. */
  3833. var NameTree = (function NameTreeClosure() {
  3834. function NameTree(root, xref) {
  3835. this.root = root;
  3836. this.xref = xref;
  3837. }
  3838. NameTree.prototype = {
  3839. getAll: function NameTree_getAll() {
  3840. var dict = {};
  3841. if (!this.root) {
  3842. return dict;
  3843. }
  3844. var xref = this.xref;
  3845. // reading name tree
  3846. var processed = new RefSet();
  3847. processed.put(this.root);
  3848. var queue = [this.root];
  3849. while (queue.length > 0) {
  3850. var i, n;
  3851. var obj = xref.fetchIfRef(queue.shift());
  3852. if (!isDict(obj)) {
  3853. continue;
  3854. }
  3855. if (obj.has('Kids')) {
  3856. var kids = obj.get('Kids');
  3857. for (i = 0, n = kids.length; i < n; i++) {
  3858. var kid = kids[i];
  3859. if (processed.has(kid)) {
  3860. error('invalid destinations');
  3861. }
  3862. queue.push(kid);
  3863. processed.put(kid);
  3864. }
  3865. continue;
  3866. }
  3867. var names = obj.get('Names');
  3868. if (names) {
  3869. for (i = 0, n = names.length; i < n; i += 2) {
  3870. dict[names[i]] = xref.fetchIfRef(names[i + 1]);
  3871. }
  3872. }
  3873. }
  3874. return dict;
  3875. }
  3876. };
  3877. return NameTree;
  3878. })();
  3879. /**
  3880. * "A PDF file can refer to the contents of another file by using a File
  3881. * Specification (PDF 1.1)", see the spec (7.11) for more details.
  3882. * NOTE: Only embedded files are supported (as part of the attachments support)
  3883. * TODO: support the 'URL' file system (with caching if !/V), portable
  3884. * collections attributes and related files (/RF)
  3885. */
  3886. var FileSpec = (function FileSpecClosure() {
  3887. function FileSpec(root, xref) {
  3888. if (!root || !isDict(root)) {
  3889. return;
  3890. }
  3891. this.xref = xref;
  3892. this.root = root;
  3893. if (root.has('FS')) {
  3894. this.fs = root.get('FS');
  3895. }
  3896. this.description = root.has('Desc') ?
  3897. stringToPDFString(root.get('Desc')) :
  3898. '';
  3899. if (root.has('RF')) {
  3900. warn('Related file specifications are not supported');
  3901. }
  3902. this.contentAvailable = true;
  3903. if (!root.has('EF')) {
  3904. this.contentAvailable = false;
  3905. warn('Non-embedded file specifications are not supported');
  3906. }
  3907. }
  3908. function pickPlatformItem(dict) {
  3909. // Look for the filename in this order:
  3910. // UF, F, Unix, Mac, DOS
  3911. if (dict.has('UF')) {
  3912. return dict.get('UF');
  3913. } else if (dict.has('F')) {
  3914. return dict.get('F');
  3915. } else if (dict.has('Unix')) {
  3916. return dict.get('Unix');
  3917. } else if (dict.has('Mac')) {
  3918. return dict.get('Mac');
  3919. } else if (dict.has('DOS')) {
  3920. return dict.get('DOS');
  3921. } else {
  3922. return null;
  3923. }
  3924. }
  3925. FileSpec.prototype = {
  3926. get filename() {
  3927. if (!this._filename && this.root) {
  3928. var filename = pickPlatformItem(this.root) || 'unnamed';
  3929. this._filename = stringToPDFString(filename).
  3930. replace(/\\\\/g, '\\').
  3931. replace(/\\\//g, '/').
  3932. replace(/\\/g, '/');
  3933. }
  3934. return this._filename;
  3935. },
  3936. get content() {
  3937. if (!this.contentAvailable) {
  3938. return null;
  3939. }
  3940. if (!this.contentRef && this.root) {
  3941. this.contentRef = pickPlatformItem(this.root.get('EF'));
  3942. }
  3943. var content = null;
  3944. if (this.contentRef) {
  3945. var xref = this.xref;
  3946. var fileObj = xref.fetchIfRef(this.contentRef);
  3947. if (fileObj && isStream(fileObj)) {
  3948. content = fileObj.getBytes();
  3949. } else {
  3950. warn('Embedded file specification points to non-existing/invalid ' +
  3951. 'content');
  3952. }
  3953. } else {
  3954. warn('Embedded file specification does not have a content');
  3955. }
  3956. return content;
  3957. },
  3958. get serializable() {
  3959. return {
  3960. filename: this.filename,
  3961. content: this.content
  3962. };
  3963. }
  3964. };
  3965. return FileSpec;
  3966. })();
  3967. /**
  3968. * A helper for loading missing data in object graphs. It traverses the graph
  3969. * depth first and queues up any objects that have missing data. Once it has
  3970. * has traversed as many objects that are available it attempts to bundle the
  3971. * missing data requests and then resume from the nodes that weren't ready.
  3972. *
  3973. * NOTE: It provides protection from circular references by keeping track of
  3974. * of loaded references. However, you must be careful not to load any graphs
  3975. * that have references to the catalog or other pages since that will cause the
  3976. * entire PDF document object graph to be traversed.
  3977. */
  3978. var ObjectLoader = (function() {
  3979. function mayHaveChildren(value) {
  3980. return isRef(value) || isDict(value) || isArray(value) || isStream(value);
  3981. }
  3982. function addChildren(node, nodesToVisit) {
  3983. var value;
  3984. if (isDict(node) || isStream(node)) {
  3985. var map;
  3986. if (isDict(node)) {
  3987. map = node.map;
  3988. } else {
  3989. map = node.dict.map;
  3990. }
  3991. for (var key in map) {
  3992. value = map[key];
  3993. if (mayHaveChildren(value)) {
  3994. nodesToVisit.push(value);
  3995. }
  3996. }
  3997. } else if (isArray(node)) {
  3998. for (var i = 0, ii = node.length; i < ii; i++) {
  3999. value = node[i];
  4000. if (mayHaveChildren(value)) {
  4001. nodesToVisit.push(value);
  4002. }
  4003. }
  4004. }
  4005. }
  4006. function ObjectLoader(obj, keys, xref) {
  4007. this.obj = obj;
  4008. this.keys = keys;
  4009. this.xref = xref;
  4010. this.refSet = null;
  4011. }
  4012. ObjectLoader.prototype = {
  4013. load: function ObjectLoader_load() {
  4014. var keys = this.keys;
  4015. this.capability = createPromiseCapability();
  4016. // Don't walk the graph if all the data is already loaded.
  4017. if (!(this.xref.stream instanceof ChunkedStream) ||
  4018. this.xref.stream.getMissingChunks().length === 0) {
  4019. this.capability.resolve();
  4020. return this.capability.promise;
  4021. }
  4022. this.refSet = new RefSet();
  4023. // Setup the initial nodes to visit.
  4024. var nodesToVisit = [];
  4025. for (var i = 0; i < keys.length; i++) {
  4026. nodesToVisit.push(this.obj[keys[i]]);
  4027. }
  4028. this.walk(nodesToVisit);
  4029. return this.capability.promise;
  4030. },
  4031. walk: function ObjectLoader_walk(nodesToVisit) {
  4032. var nodesToRevisit = [];
  4033. var pendingRequests = [];
  4034. // DFS walk of the object graph.
  4035. while (nodesToVisit.length) {
  4036. var currentNode = nodesToVisit.pop();
  4037. // Only references or chunked streams can cause missing data exceptions.
  4038. if (isRef(currentNode)) {
  4039. // Skip nodes that have already been visited.
  4040. if (this.refSet.has(currentNode)) {
  4041. continue;
  4042. }
  4043. try {
  4044. var ref = currentNode;
  4045. this.refSet.put(ref);
  4046. currentNode = this.xref.fetch(currentNode);
  4047. } catch (e) {
  4048. if (!(e instanceof MissingDataException)) {
  4049. throw e;
  4050. }
  4051. nodesToRevisit.push(currentNode);
  4052. pendingRequests.push({ begin: e.begin, end: e.end });
  4053. }
  4054. }
  4055. if (currentNode && currentNode.getBaseStreams) {
  4056. var baseStreams = currentNode.getBaseStreams();
  4057. var foundMissingData = false;
  4058. for (var i = 0; i < baseStreams.length; i++) {
  4059. var stream = baseStreams[i];
  4060. if (stream.getMissingChunks && stream.getMissingChunks().length) {
  4061. foundMissingData = true;
  4062. pendingRequests.push({
  4063. begin: stream.start,
  4064. end: stream.end
  4065. });
  4066. }
  4067. }
  4068. if (foundMissingData) {
  4069. nodesToRevisit.push(currentNode);
  4070. }
  4071. }
  4072. addChildren(currentNode, nodesToVisit);
  4073. }
  4074. if (pendingRequests.length) {
  4075. this.xref.stream.manager.requestRanges(pendingRequests,
  4076. function pendingRequestCallback() {
  4077. nodesToVisit = nodesToRevisit;
  4078. for (var i = 0; i < nodesToRevisit.length; i++) {
  4079. var node = nodesToRevisit[i];
  4080. // Remove any reference nodes from the currrent refset so they
  4081. // aren't skipped when we revist them.
  4082. if (isRef(node)) {
  4083. this.refSet.remove(node);
  4084. }
  4085. }
  4086. this.walk(nodesToVisit);
  4087. }.bind(this));
  4088. return;
  4089. }
  4090. // Everything is loaded.
  4091. this.refSet = null;
  4092. this.capability.resolve();
  4093. }
  4094. };
  4095. return ObjectLoader;
  4096. })();
  4097. var ISOAdobeCharset = [
  4098. '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar',
  4099. 'percent', 'ampersand', 'quoteright', 'parenleft', 'parenright',
  4100. 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash', 'zero',
  4101. 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  4102. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question',
  4103. 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
  4104. 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
  4105. 'bracketleft', 'backslash', 'bracketright', 'asciicircum', 'underscore',
  4106. 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
  4107. 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
  4108. 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
  4109. 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  4110. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  4111. 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
  4112. 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase',
  4113. 'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis',
  4114. 'perthousand', 'questiondown', 'grave', 'acute', 'circumflex', 'tilde',
  4115. 'macron', 'breve', 'dotaccent', 'dieresis', 'ring', 'cedilla',
  4116. 'hungarumlaut', 'ogonek', 'caron', 'emdash', 'AE', 'ordfeminine',
  4117. 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae', 'dotlessi', 'lslash',
  4118. 'oslash', 'oe', 'germandbls', 'onesuperior', 'logicalnot', 'mu',
  4119. 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn', 'onequarter',
  4120. 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters', 'twosuperior',
  4121. 'registered', 'minus', 'eth', 'multiply', 'threesuperior', 'copyright',
  4122. 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring', 'Atilde',
  4123. 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave', 'Iacute',
  4124. 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute', 'Ocircumflex',
  4125. 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute', 'Ucircumflex',
  4126. 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron', 'aacute',
  4127. 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde', 'ccedilla',
  4128. 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute', 'icircumflex',
  4129. 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex', 'odieresis',
  4130. 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex', 'udieresis',
  4131. 'ugrave', 'yacute', 'ydieresis', 'zcaron'
  4132. ];
  4133. var ExpertCharset = [
  4134. '.notdef', 'space', 'exclamsmall', 'Hungarumlautsmall', 'dollaroldstyle',
  4135. 'dollarsuperior', 'ampersandsmall', 'Acutesmall', 'parenleftsuperior',
  4136. 'parenrightsuperior', 'twodotenleader', 'onedotenleader', 'comma',
  4137. 'hyphen', 'period', 'fraction', 'zerooldstyle', 'oneoldstyle',
  4138. 'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle',
  4139. 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle',
  4140. 'colon', 'semicolon', 'commasuperior', 'threequartersemdash',
  4141. 'periodsuperior', 'questionsmall', 'asuperior', 'bsuperior',
  4142. 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',
  4143. 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  4144. 'tsuperior', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior',
  4145. 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall',
  4146. 'Asmall', 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall',
  4147. 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall',
  4148. 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall',
  4149. 'Vsmall', 'Wsmall', 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary',
  4150. 'onefitted', 'rupiah', 'Tildesmall', 'exclamdownsmall', 'centoldstyle',
  4151. 'Lslashsmall', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall',
  4152. 'Brevesmall', 'Caronsmall', 'Dotaccentsmall', 'Macronsmall',
  4153. 'figuredash', 'hypheninferior', 'Ogoneksmall', 'Ringsmall',
  4154. 'Cedillasmall', 'onequarter', 'onehalf', 'threequarters',
  4155. 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths',
  4156. 'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'onesuperior',
  4157. 'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',
  4158. 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',
  4159. 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior',
  4160. 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior',
  4161. 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior',
  4162. 'periodinferior', 'commainferior', 'Agravesmall', 'Aacutesmall',
  4163. 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall', 'Aringsmall',
  4164. 'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall',
  4165. 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall',
  4166. 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall',
  4167. 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall',
  4168. 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall',
  4169. 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall',
  4170. 'Ydieresissmall'
  4171. ];
  4172. var ExpertSubsetCharset = [
  4173. '.notdef', 'space', 'dollaroldstyle', 'dollarsuperior',
  4174. 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  4175. 'onedotenleader', 'comma', 'hyphen', 'period', 'fraction',
  4176. 'zerooldstyle', 'oneoldstyle', 'twooldstyle', 'threeoldstyle',
  4177. 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle',
  4178. 'eightoldstyle', 'nineoldstyle', 'colon', 'semicolon', 'commasuperior',
  4179. 'threequartersemdash', 'periodsuperior', 'asuperior', 'bsuperior',
  4180. 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',
  4181. 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  4182. 'tsuperior', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior',
  4183. 'parenrightinferior', 'hyphensuperior', 'colonmonetary', 'onefitted',
  4184. 'rupiah', 'centoldstyle', 'figuredash', 'hypheninferior', 'onequarter',
  4185. 'onehalf', 'threequarters', 'oneeighth', 'threeeighths', 'fiveeighths',
  4186. 'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'onesuperior',
  4187. 'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',
  4188. 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',
  4189. 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior',
  4190. 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior',
  4191. 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior',
  4192. 'periodinferior', 'commainferior'
  4193. ];
  4194. var DEFAULT_ICON_SIZE = 22; // px
  4195. var SUPPORTED_TYPES = ['Link', 'Text', 'Widget'];
  4196. var Annotation = (function AnnotationClosure() {
  4197. // 12.5.5: Algorithm: Appearance streams
  4198. function getTransformMatrix(rect, bbox, matrix) {
  4199. var bounds = Util.getAxialAlignedBoundingBox(bbox, matrix);
  4200. var minX = bounds[0];
  4201. var minY = bounds[1];
  4202. var maxX = bounds[2];
  4203. var maxY = bounds[3];
  4204. if (minX === maxX || minY === maxY) {
  4205. // From real-life file, bbox was [0, 0, 0, 0]. In this case,
  4206. // just apply the transform for rect
  4207. return [1, 0, 0, 1, rect[0], rect[1]];
  4208. }
  4209. var xRatio = (rect[2] - rect[0]) / (maxX - minX);
  4210. var yRatio = (rect[3] - rect[1]) / (maxY - minY);
  4211. return [
  4212. xRatio,
  4213. 0,
  4214. 0,
  4215. yRatio,
  4216. rect[0] - minX * xRatio,
  4217. rect[1] - minY * yRatio
  4218. ];
  4219. }
  4220. function getDefaultAppearance(dict) {
  4221. var appearanceState = dict.get('AP');
  4222. if (!isDict(appearanceState)) {
  4223. return;
  4224. }
  4225. var appearance;
  4226. var appearances = appearanceState.get('N');
  4227. if (isDict(appearances)) {
  4228. var as = dict.get('AS');
  4229. if (as && appearances.has(as.name)) {
  4230. appearance = appearances.get(as.name);
  4231. }
  4232. } else {
  4233. appearance = appearances;
  4234. }
  4235. return appearance;
  4236. }
  4237. function Annotation(params) {
  4238. var dict = params.dict;
  4239. var data = this.data = {};
  4240. data.subtype = dict.get('Subtype').name;
  4241. var rect = dict.get('Rect') || [0, 0, 0, 0];
  4242. data.rect = Util.normalizeRect(rect);
  4243. data.annotationFlags = dict.get('F');
  4244. var color = dict.get('C');
  4245. if (isArray(color) && color.length === 3) {
  4246. // TODO(mack): currently only supporting rgb; need support different
  4247. // colorspaces
  4248. data.color = color;
  4249. } else {
  4250. data.color = [0, 0, 0];
  4251. }
  4252. // Some types of annotations have border style dict which has more
  4253. // info than the border array
  4254. if (dict.has('BS')) {
  4255. var borderStyle = dict.get('BS');
  4256. data.borderWidth = borderStyle.has('W') ? borderStyle.get('W') : 1;
  4257. } else {
  4258. var borderArray = dict.get('Border') || [0, 0, 1];
  4259. data.borderWidth = borderArray[2] || 0;
  4260. // TODO: implement proper support for annotations with line dash patterns.
  4261. var dashArray = borderArray[3];
  4262. if (data.borderWidth > 0 && dashArray) {
  4263. if (!isArray(dashArray)) {
  4264. // Ignore the border if dashArray is not actually an array,
  4265. // this is consistent with the behaviour in Adobe Reader.
  4266. data.borderWidth = 0;
  4267. } else {
  4268. var dashArrayLength = dashArray.length;
  4269. if (dashArrayLength > 0) {
  4270. // According to the PDF specification: the elements in a dashArray
  4271. // shall be numbers that are nonnegative and not all equal to zero.
  4272. var isInvalid = false;
  4273. var numPositive = 0;
  4274. for (var i = 0; i < dashArrayLength; i++) {
  4275. var validNumber = (+dashArray[i] >= 0);
  4276. if (!validNumber) {
  4277. isInvalid = true;
  4278. break;
  4279. } else if (dashArray[i] > 0) {
  4280. numPositive++;
  4281. }
  4282. }
  4283. if (isInvalid || numPositive === 0) {
  4284. data.borderWidth = 0;
  4285. }
  4286. }
  4287. }
  4288. }
  4289. }
  4290. this.appearance = getDefaultAppearance(dict);
  4291. data.hasAppearance = !!this.appearance;
  4292. data.id = params.ref.num;
  4293. }
  4294. Annotation.prototype = {
  4295. getData: function Annotation_getData() {
  4296. return this.data;
  4297. },
  4298. isInvisible: function Annotation_isInvisible() {
  4299. var data = this.data;
  4300. if (data && SUPPORTED_TYPES.indexOf(data.subtype) !== -1) {
  4301. return false;
  4302. } else {
  4303. return !!(data &&
  4304. data.annotationFlags && // Default: not invisible
  4305. data.annotationFlags & 0x1); // Invisible
  4306. }
  4307. },
  4308. isViewable: function Annotation_isViewable() {
  4309. var data = this.data;
  4310. return !!(!this.isInvisible() &&
  4311. data &&
  4312. (!data.annotationFlags ||
  4313. !(data.annotationFlags & 0x22)) && // Hidden or NoView
  4314. data.rect); // rectangle is necessary
  4315. },
  4316. isPrintable: function Annotation_isPrintable() {
  4317. var data = this.data;
  4318. return !!(!this.isInvisible() &&
  4319. data &&
  4320. data.annotationFlags && // Default: not printable
  4321. data.annotationFlags & 0x4 && // Print
  4322. !(data.annotationFlags & 0x2) && // Hidden
  4323. data.rect); // rectangle is necessary
  4324. },
  4325. loadResources: function Annotation_loadResources(keys) {
  4326. return new Promise(function (resolve, reject) {
  4327. this.appearance.dict.getAsync('Resources').then(function (resources) {
  4328. if (!resources) {
  4329. resolve();
  4330. return;
  4331. }
  4332. var objectLoader = new ObjectLoader(resources.map,
  4333. keys,
  4334. resources.xref);
  4335. objectLoader.load().then(function() {
  4336. resolve(resources);
  4337. }, reject);
  4338. }, reject);
  4339. }.bind(this));
  4340. },
  4341. getOperatorList: function Annotation_getOperatorList(evaluator) {
  4342. if (!this.appearance) {
  4343. return Promise.resolve(new OperatorList());
  4344. }
  4345. var data = this.data;
  4346. var appearanceDict = this.appearance.dict;
  4347. var resourcesPromise = this.loadResources([
  4348. 'ExtGState',
  4349. 'ColorSpace',
  4350. 'Pattern',
  4351. 'Shading',
  4352. 'XObject',
  4353. 'Font'
  4354. // ProcSet
  4355. // Properties
  4356. ]);
  4357. var bbox = appearanceDict.get('BBox') || [0, 0, 1, 1];
  4358. var matrix = appearanceDict.get('Matrix') || [1, 0, 0, 1, 0 ,0];
  4359. var transform = getTransformMatrix(data.rect, bbox, matrix);
  4360. var self = this;
  4361. return resourcesPromise.then(function(resources) {
  4362. var opList = new OperatorList();
  4363. opList.addOp(OPS.beginAnnotation, [data.rect, transform, matrix]);
  4364. return evaluator.getOperatorList(self.appearance, resources, opList).
  4365. then(function () {
  4366. opList.addOp(OPS.endAnnotation, []);
  4367. self.appearance.reset();
  4368. return opList;
  4369. });
  4370. });
  4371. }
  4372. };
  4373. Annotation.getConstructor =
  4374. function Annotation_getConstructor(subtype, fieldType) {
  4375. if (!subtype) {
  4376. return;
  4377. }
  4378. // TODO(mack): Implement FreeText annotations
  4379. if (subtype === 'Link') {
  4380. return LinkAnnotation;
  4381. } else if (subtype === 'Text') {
  4382. return TextAnnotation;
  4383. } else if (subtype === 'Widget') {
  4384. if (!fieldType) {
  4385. return;
  4386. }
  4387. if (fieldType === 'Tx') {
  4388. return TextWidgetAnnotation;
  4389. } else {
  4390. return WidgetAnnotation;
  4391. }
  4392. } else {
  4393. return Annotation;
  4394. }
  4395. };
  4396. Annotation.fromRef = function Annotation_fromRef(xref, ref) {
  4397. var dict = xref.fetchIfRef(ref);
  4398. if (!isDict(dict)) {
  4399. return;
  4400. }
  4401. var subtype = dict.get('Subtype');
  4402. subtype = isName(subtype) ? subtype.name : '';
  4403. if (!subtype) {
  4404. return;
  4405. }
  4406. var fieldType = Util.getInheritableProperty(dict, 'FT');
  4407. fieldType = isName(fieldType) ? fieldType.name : '';
  4408. var Constructor = Annotation.getConstructor(subtype, fieldType);
  4409. if (!Constructor) {
  4410. return;
  4411. }
  4412. var params = {
  4413. dict: dict,
  4414. ref: ref,
  4415. };
  4416. var annotation = new Constructor(params);
  4417. if (annotation.isViewable() || annotation.isPrintable()) {
  4418. return annotation;
  4419. } else {
  4420. if (SUPPORTED_TYPES.indexOf(subtype) === -1) {
  4421. warn('unimplemented annotation type: ' + subtype);
  4422. }
  4423. }
  4424. };
  4425. Annotation.appendToOperatorList = function Annotation_appendToOperatorList(
  4426. annotations, opList, pdfManager, partialEvaluator, intent) {
  4427. function reject(e) {
  4428. annotationsReadyCapability.reject(e);
  4429. }
  4430. var annotationsReadyCapability = createPromiseCapability();
  4431. var annotationPromises = [];
  4432. for (var i = 0, n = annotations.length; i < n; ++i) {
  4433. if (intent === 'display' && annotations[i].isViewable() ||
  4434. intent === 'print' && annotations[i].isPrintable()) {
  4435. annotationPromises.push(
  4436. annotations[i].getOperatorList(partialEvaluator));
  4437. }
  4438. }
  4439. Promise.all(annotationPromises).then(function(datas) {
  4440. opList.addOp(OPS.beginAnnotations, []);
  4441. for (var i = 0, n = datas.length; i < n; ++i) {
  4442. var annotOpList = datas[i];
  4443. opList.addOpList(annotOpList);
  4444. }
  4445. opList.addOp(OPS.endAnnotations, []);
  4446. annotationsReadyCapability.resolve();
  4447. }, reject);
  4448. return annotationsReadyCapability.promise;
  4449. };
  4450. return Annotation;
  4451. })();
  4452. var WidgetAnnotation = (function WidgetAnnotationClosure() {
  4453. function WidgetAnnotation(params) {
  4454. Annotation.call(this, params);
  4455. var dict = params.dict;
  4456. var data = this.data;
  4457. data.fieldValue = stringToPDFString(
  4458. Util.getInheritableProperty(dict, 'V') || '');
  4459. data.alternativeText = stringToPDFString(dict.get('TU') || '');
  4460. data.defaultAppearance = Util.getInheritableProperty(dict, 'DA') || '';
  4461. var fieldType = Util.getInheritableProperty(dict, 'FT');
  4462. data.fieldType = isName(fieldType) ? fieldType.name : '';
  4463. data.fieldFlags = Util.getInheritableProperty(dict, 'Ff') || 0;
  4464. this.fieldResources = Util.getInheritableProperty(dict, 'DR') || Dict.empty;
  4465. // Building the full field name by collecting the field and
  4466. // its ancestors 'T' data and joining them using '.'.
  4467. var fieldName = [];
  4468. var namedItem = dict;
  4469. var ref = params.ref;
  4470. while (namedItem) {
  4471. var parent = namedItem.get('Parent');
  4472. var parentRef = namedItem.getRaw('Parent');
  4473. var name = namedItem.get('T');
  4474. if (name) {
  4475. fieldName.unshift(stringToPDFString(name));
  4476. } else {
  4477. // The field name is absent, that means more than one field
  4478. // with the same name may exist. Replacing the empty name
  4479. // with the '`' plus index in the parent's 'Kids' array.
  4480. // This is not in the PDF spec but necessary to id the
  4481. // the input controls.
  4482. var kids = parent.get('Kids');
  4483. var j, jj;
  4484. for (j = 0, jj = kids.length; j < jj; j++) {
  4485. var kidRef = kids[j];
  4486. if (kidRef.num == ref.num && kidRef.gen == ref.gen) {
  4487. break;
  4488. }
  4489. }
  4490. fieldName.unshift('`' + j);
  4491. }
  4492. namedItem = parent;
  4493. ref = parentRef;
  4494. }
  4495. data.fullName = fieldName.join('.');
  4496. }
  4497. var parent = Annotation.prototype;
  4498. Util.inherit(WidgetAnnotation, Annotation, {
  4499. isViewable: function WidgetAnnotation_isViewable() {
  4500. if (this.data.fieldType === 'Sig') {
  4501. warn('unimplemented annotation type: Widget signature');
  4502. return false;
  4503. }
  4504. return parent.isViewable.call(this);
  4505. }
  4506. });
  4507. return WidgetAnnotation;
  4508. })();
  4509. var TextWidgetAnnotation = (function TextWidgetAnnotationClosure() {
  4510. function TextWidgetAnnotation(params) {
  4511. WidgetAnnotation.call(this, params);
  4512. this.data.textAlignment = Util.getInheritableProperty(params.dict, 'Q');
  4513. this.data.annotationType = AnnotationType.WIDGET;
  4514. this.data.hasHtml = !this.data.hasAppearance && !!this.data.fieldValue;
  4515. }
  4516. Util.inherit(TextWidgetAnnotation, WidgetAnnotation, {
  4517. getOperatorList: function TextWidgetAnnotation_getOperatorList(evaluator) {
  4518. if (this.appearance) {
  4519. return Annotation.prototype.getOperatorList.call(this, evaluator);
  4520. }
  4521. var opList = new OperatorList();
  4522. var data = this.data;
  4523. // Even if there is an appearance stream, ignore it. This is the
  4524. // behaviour used by Adobe Reader.
  4525. if (!data.defaultAppearance) {
  4526. return Promise.resolve(opList);
  4527. }
  4528. var stream = new Stream(stringToBytes(data.defaultAppearance));
  4529. return evaluator.getOperatorList(stream, this.fieldResources, opList).
  4530. then(function () {
  4531. return opList;
  4532. });
  4533. }
  4534. });
  4535. return TextWidgetAnnotation;
  4536. })();
  4537. var InteractiveAnnotation = (function InteractiveAnnotationClosure() {
  4538. function InteractiveAnnotation(params) {
  4539. Annotation.call(this, params);
  4540. this.data.hasHtml = true;
  4541. }
  4542. Util.inherit(InteractiveAnnotation, Annotation, { });
  4543. return InteractiveAnnotation;
  4544. })();
  4545. var TextAnnotation = (function TextAnnotationClosure() {
  4546. function TextAnnotation(params) {
  4547. InteractiveAnnotation.call(this, params);
  4548. var dict = params.dict;
  4549. var data = this.data;
  4550. var content = dict.get('Contents');
  4551. var title = dict.get('T');
  4552. data.annotationType = AnnotationType.TEXT;
  4553. data.content = stringToPDFString(content || '');
  4554. data.title = stringToPDFString(title || '');
  4555. if (data.hasAppearance) {
  4556. data.name = 'NoIcon';
  4557. } else {
  4558. data.rect[1] = data.rect[3] - DEFAULT_ICON_SIZE;
  4559. data.rect[2] = data.rect[0] + DEFAULT_ICON_SIZE;
  4560. data.name = dict.has('Name') ? dict.get('Name').name : 'Note';
  4561. }
  4562. if (dict.has('C')) {
  4563. data.hasBgColor = true;
  4564. }
  4565. }
  4566. Util.inherit(TextAnnotation, InteractiveAnnotation, { });
  4567. return TextAnnotation;
  4568. })();
  4569. var LinkAnnotation = (function LinkAnnotationClosure() {
  4570. function LinkAnnotation(params) {
  4571. InteractiveAnnotation.call(this, params);
  4572. var dict = params.dict;
  4573. var data = this.data;
  4574. data.annotationType = AnnotationType.LINK;
  4575. var action = dict.get('A');
  4576. if (action) {
  4577. var linkType = action.get('S').name;
  4578. if (linkType === 'URI') {
  4579. var url = action.get('URI');
  4580. if (isName(url)) {
  4581. // Some bad PDFs do not put parentheses around relative URLs.
  4582. url = '/' + url.name;
  4583. } else if (url) {
  4584. url = addDefaultProtocolToUrl(url);
  4585. }
  4586. // TODO: pdf spec mentions urls can be relative to a Base
  4587. // entry in the dictionary.
  4588. if (!isValidUrl(url, false)) {
  4589. url = '';
  4590. }
  4591. data.url = url;
  4592. } else if (linkType === 'GoTo') {
  4593. data.dest = action.get('D');
  4594. } else if (linkType === 'GoToR') {
  4595. var urlDict = action.get('F');
  4596. if (isDict(urlDict)) {
  4597. // We assume that the 'url' is a Filspec dictionary
  4598. // and fetch the url without checking any further
  4599. url = urlDict.get('F') || '';
  4600. }
  4601. // TODO: pdf reference says that GoToR
  4602. // can also have 'NewWindow' attribute
  4603. if (!isValidUrl(url, false)) {
  4604. url = '';
  4605. }
  4606. data.url = url;
  4607. data.dest = action.get('D');
  4608. } else if (linkType === 'Named') {
  4609. data.action = action.get('N').name;
  4610. } else {
  4611. warn('unrecognized link type: ' + linkType);
  4612. }
  4613. } else if (dict.has('Dest')) {
  4614. // simple destination link
  4615. var dest = dict.get('Dest');
  4616. data.dest = isName(dest) ? dest.name : dest;
  4617. }
  4618. }
  4619. // Lets URLs beginning with 'www.' default to using the 'http://' protocol.
  4620. function addDefaultProtocolToUrl(url) {
  4621. if (url && url.indexOf('www.') === 0) {
  4622. return ('http://' + url);
  4623. }
  4624. return url;
  4625. }
  4626. Util.inherit(LinkAnnotation, InteractiveAnnotation, {
  4627. hasOperatorList: function LinkAnnotation_hasOperatorList() {
  4628. return false;
  4629. }
  4630. });
  4631. return LinkAnnotation;
  4632. })();
  4633. var PDFFunction = (function PDFFunctionClosure() {
  4634. var CONSTRUCT_SAMPLED = 0;
  4635. var CONSTRUCT_INTERPOLATED = 2;
  4636. var CONSTRUCT_STICHED = 3;
  4637. var CONSTRUCT_POSTSCRIPT = 4;
  4638. return {
  4639. getSampleArray: function PDFFunction_getSampleArray(size, outputSize, bps,
  4640. str) {
  4641. var i, ii;
  4642. var length = 1;
  4643. for (i = 0, ii = size.length; i < ii; i++) {
  4644. length *= size[i];
  4645. }
  4646. length *= outputSize;
  4647. var array = [];
  4648. var codeSize = 0;
  4649. var codeBuf = 0;
  4650. // 32 is a valid bps so shifting won't work
  4651. var sampleMul = 1.0 / (Math.pow(2.0, bps) - 1);
  4652. var strBytes = str.getBytes((length * bps + 7) / 8);
  4653. var strIdx = 0;
  4654. for (i = 0; i < length; i++) {
  4655. while (codeSize < bps) {
  4656. codeBuf <<= 8;
  4657. codeBuf |= strBytes[strIdx++];
  4658. codeSize += 8;
  4659. }
  4660. codeSize -= bps;
  4661. array.push((codeBuf >> codeSize) * sampleMul);
  4662. codeBuf &= (1 << codeSize) - 1;
  4663. }
  4664. return array;
  4665. },
  4666. getIR: function PDFFunction_getIR(xref, fn) {
  4667. var dict = fn.dict;
  4668. if (!dict) {
  4669. dict = fn;
  4670. }
  4671. var types = [this.constructSampled,
  4672. null,
  4673. this.constructInterpolated,
  4674. this.constructStiched,
  4675. this.constructPostScript];
  4676. var typeNum = dict.get('FunctionType');
  4677. var typeFn = types[typeNum];
  4678. if (!typeFn) {
  4679. error('Unknown type of function');
  4680. }
  4681. return typeFn.call(this, fn, dict, xref);
  4682. },
  4683. fromIR: function PDFFunction_fromIR(IR) {
  4684. var type = IR[0];
  4685. switch (type) {
  4686. case CONSTRUCT_SAMPLED:
  4687. return this.constructSampledFromIR(IR);
  4688. case CONSTRUCT_INTERPOLATED:
  4689. return this.constructInterpolatedFromIR(IR);
  4690. case CONSTRUCT_STICHED:
  4691. return this.constructStichedFromIR(IR);
  4692. //case CONSTRUCT_POSTSCRIPT:
  4693. default:
  4694. return this.constructPostScriptFromIR(IR);
  4695. }
  4696. },
  4697. parse: function PDFFunction_parse(xref, fn) {
  4698. var IR = this.getIR(xref, fn);
  4699. return this.fromIR(IR);
  4700. },
  4701. constructSampled: function PDFFunction_constructSampled(str, dict) {
  4702. function toMultiArray(arr) {
  4703. var inputLength = arr.length;
  4704. var out = [];
  4705. var index = 0;
  4706. for (var i = 0; i < inputLength; i += 2) {
  4707. out[index] = [arr[i], arr[i + 1]];
  4708. ++index;
  4709. }
  4710. return out;
  4711. }
  4712. var domain = dict.get('Domain');
  4713. var range = dict.get('Range');
  4714. if (!domain || !range) {
  4715. error('No domain or range');
  4716. }
  4717. var inputSize = domain.length / 2;
  4718. var outputSize = range.length / 2;
  4719. domain = toMultiArray(domain);
  4720. range = toMultiArray(range);
  4721. var size = dict.get('Size');
  4722. var bps = dict.get('BitsPerSample');
  4723. var order = dict.get('Order') || 1;
  4724. if (order !== 1) {
  4725. // No description how cubic spline interpolation works in PDF32000:2008
  4726. // As in poppler, ignoring order, linear interpolation may work as good
  4727. info('No support for cubic spline interpolation: ' + order);
  4728. }
  4729. var encode = dict.get('Encode');
  4730. if (!encode) {
  4731. encode = [];
  4732. for (var i = 0; i < inputSize; ++i) {
  4733. encode.push(0);
  4734. encode.push(size[i] - 1);
  4735. }
  4736. }
  4737. encode = toMultiArray(encode);
  4738. var decode = dict.get('Decode');
  4739. if (!decode) {
  4740. decode = range;
  4741. } else {
  4742. decode = toMultiArray(decode);
  4743. }
  4744. var samples = this.getSampleArray(size, outputSize, bps, str);
  4745. return [
  4746. CONSTRUCT_SAMPLED, inputSize, domain, encode, decode, samples, size,
  4747. outputSize, Math.pow(2, bps) - 1, range
  4748. ];
  4749. },
  4750. constructSampledFromIR: function PDFFunction_constructSampledFromIR(IR) {
  4751. // See chapter 3, page 109 of the PDF reference
  4752. function interpolate(x, xmin, xmax, ymin, ymax) {
  4753. return ymin + ((x - xmin) * ((ymax - ymin) / (xmax - xmin)));
  4754. }
  4755. return function constructSampledFromIRResult(args) {
  4756. // See chapter 3, page 110 of the PDF reference.
  4757. var m = IR[1];
  4758. var domain = IR[2];
  4759. var encode = IR[3];
  4760. var decode = IR[4];
  4761. var samples = IR[5];
  4762. var size = IR[6];
  4763. var n = IR[7];
  4764. //var mask = IR[8];
  4765. var range = IR[9];
  4766. if (m != args.length) {
  4767. error('Incorrect number of arguments: ' + m + ' != ' +
  4768. args.length);
  4769. }
  4770. var x = args;
  4771. // Building the cube vertices: its part and sample index
  4772. // http://rjwagner49.com/Mathematics/Interpolation.pdf
  4773. var cubeVertices = 1 << m;
  4774. var cubeN = new Float64Array(cubeVertices);
  4775. var cubeVertex = new Uint32Array(cubeVertices);
  4776. var i, j;
  4777. for (j = 0; j < cubeVertices; j++) {
  4778. cubeN[j] = 1;
  4779. }
  4780. var k = n, pos = 1;
  4781. // Map x_i to y_j for 0 <= i < m using the sampled function.
  4782. for (i = 0; i < m; ++i) {
  4783. // x_i' = min(max(x_i, Domain_2i), Domain_2i+1)
  4784. var domain_2i = domain[i][0];
  4785. var domain_2i_1 = domain[i][1];
  4786. var xi = Math.min(Math.max(x[i], domain_2i), domain_2i_1);
  4787. // e_i = Interpolate(x_i', Domain_2i, Domain_2i+1,
  4788. // Encode_2i, Encode_2i+1)
  4789. var e = interpolate(xi, domain_2i, domain_2i_1,
  4790. encode[i][0], encode[i][1]);
  4791. // e_i' = min(max(e_i, 0), Size_i - 1)
  4792. var size_i = size[i];
  4793. e = Math.min(Math.max(e, 0), size_i - 1);
  4794. // Adjusting the cube: N and vertex sample index
  4795. var e0 = e < size_i - 1 ? Math.floor(e) : e - 1; // e1 = e0 + 1;
  4796. var n0 = e0 + 1 - e; // (e1 - e) / (e1 - e0);
  4797. var n1 = e - e0; // (e - e0) / (e1 - e0);
  4798. var offset0 = e0 * k;
  4799. var offset1 = offset0 + k; // e1 * k
  4800. for (j = 0; j < cubeVertices; j++) {
  4801. if (j & pos) {
  4802. cubeN[j] *= n1;
  4803. cubeVertex[j] += offset1;
  4804. } else {
  4805. cubeN[j] *= n0;
  4806. cubeVertex[j] += offset0;
  4807. }
  4808. }
  4809. k *= size_i;
  4810. pos <<= 1;
  4811. }
  4812. var y = new Float64Array(n);
  4813. for (j = 0; j < n; ++j) {
  4814. // Sum all cube vertices' samples portions
  4815. var rj = 0;
  4816. for (i = 0; i < cubeVertices; i++) {
  4817. rj += samples[cubeVertex[i] + j] * cubeN[i];
  4818. }
  4819. // r_j' = Interpolate(r_j, 0, 2^BitsPerSample - 1,
  4820. // Decode_2j, Decode_2j+1)
  4821. rj = interpolate(rj, 0, 1, decode[j][0], decode[j][1]);
  4822. // y_j = min(max(r_j, range_2j), range_2j+1)
  4823. y[j] = Math.min(Math.max(rj, range[j][0]), range[j][1]);
  4824. }
  4825. return y;
  4826. };
  4827. },
  4828. constructInterpolated: function PDFFunction_constructInterpolated(str,
  4829. dict) {
  4830. var c0 = dict.get('C0') || [0];
  4831. var c1 = dict.get('C1') || [1];
  4832. var n = dict.get('N');
  4833. if (!isArray(c0) || !isArray(c1)) {
  4834. error('Illegal dictionary for interpolated function');
  4835. }
  4836. var length = c0.length;
  4837. var diff = [];
  4838. for (var i = 0; i < length; ++i) {
  4839. diff.push(c1[i] - c0[i]);
  4840. }
  4841. return [CONSTRUCT_INTERPOLATED, c0, diff, n];
  4842. },
  4843. constructInterpolatedFromIR:
  4844. function PDFFunction_constructInterpolatedFromIR(IR) {
  4845. var c0 = IR[1];
  4846. var diff = IR[2];
  4847. var n = IR[3];
  4848. var length = diff.length;
  4849. return function constructInterpolatedFromIRResult(args) {
  4850. var x = n == 1 ? args[0] : Math.pow(args[0], n);
  4851. var out = [];
  4852. for (var j = 0; j < length; ++j) {
  4853. out.push(c0[j] + (x * diff[j]));
  4854. }
  4855. return out;
  4856. };
  4857. },
  4858. constructStiched: function PDFFunction_constructStiched(fn, dict, xref) {
  4859. var domain = dict.get('Domain');
  4860. if (!domain) {
  4861. error('No domain');
  4862. }
  4863. var inputSize = domain.length / 2;
  4864. if (inputSize != 1) {
  4865. error('Bad domain for stiched function');
  4866. }
  4867. var fnRefs = dict.get('Functions');
  4868. var fns = [];
  4869. for (var i = 0, ii = fnRefs.length; i < ii; ++i) {
  4870. fns.push(PDFFunction.getIR(xref, xref.fetchIfRef(fnRefs[i])));
  4871. }
  4872. var bounds = dict.get('Bounds');
  4873. var encode = dict.get('Encode');
  4874. return [CONSTRUCT_STICHED, domain, bounds, encode, fns];
  4875. },
  4876. constructStichedFromIR: function PDFFunction_constructStichedFromIR(IR) {
  4877. var domain = IR[1];
  4878. var bounds = IR[2];
  4879. var encode = IR[3];
  4880. var fnsIR = IR[4];
  4881. var fns = [];
  4882. for (var i = 0, ii = fnsIR.length; i < ii; i++) {
  4883. fns.push(PDFFunction.fromIR(fnsIR[i]));
  4884. }
  4885. return function constructStichedFromIRResult(args) {
  4886. var clip = function constructStichedFromIRClip(v, min, max) {
  4887. if (v > max) {
  4888. v = max;
  4889. } else if (v < min) {
  4890. v = min;
  4891. }
  4892. return v;
  4893. };
  4894. // clip to domain
  4895. var v = clip(args[0], domain[0], domain[1]);
  4896. // calulate which bound the value is in
  4897. for (var i = 0, ii = bounds.length; i < ii; ++i) {
  4898. if (v < bounds[i]) {
  4899. break;
  4900. }
  4901. }
  4902. // encode value into domain of function
  4903. var dmin = domain[0];
  4904. if (i > 0) {
  4905. dmin = bounds[i - 1];
  4906. }
  4907. var dmax = domain[1];
  4908. if (i < bounds.length) {
  4909. dmax = bounds[i];
  4910. }
  4911. var rmin = encode[2 * i];
  4912. var rmax = encode[2 * i + 1];
  4913. var v2 = rmin + (v - dmin) * (rmax - rmin) / (dmax - dmin);
  4914. // call the appropriate function
  4915. return fns[i]([v2]);
  4916. };
  4917. },
  4918. constructPostScript: function PDFFunction_constructPostScript(fn, dict,
  4919. xref) {
  4920. var domain = dict.get('Domain');
  4921. var range = dict.get('Range');
  4922. if (!domain) {
  4923. error('No domain.');
  4924. }
  4925. if (!range) {
  4926. error('No range.');
  4927. }
  4928. var lexer = new PostScriptLexer(fn);
  4929. var parser = new PostScriptParser(lexer);
  4930. var code = parser.parse();
  4931. return [CONSTRUCT_POSTSCRIPT, domain, range, code];
  4932. },
  4933. constructPostScriptFromIR: function PDFFunction_constructPostScriptFromIR(
  4934. IR) {
  4935. var domain = IR[1];
  4936. var range = IR[2];
  4937. var code = IR[3];
  4938. var numOutputs = range.length >> 1;
  4939. var numInputs = domain.length >> 1;
  4940. var evaluator = new PostScriptEvaluator(code);
  4941. // Cache the values for a big speed up, the cache size is limited though
  4942. // since the number of possible values can be huge from a PS function.
  4943. var cache = {};
  4944. // The MAX_CACHE_SIZE is set to ~4x the maximum number of distinct values
  4945. // seen in our tests.
  4946. var MAX_CACHE_SIZE = 2048 * 4;
  4947. var cache_available = MAX_CACHE_SIZE;
  4948. return function constructPostScriptFromIRResult(args) {
  4949. var i, value;
  4950. var key = '';
  4951. var input = new Array(numInputs);
  4952. for (i = 0; i < numInputs; i++) {
  4953. value = args[i];
  4954. input[i] = value;
  4955. key += value + '_';
  4956. }
  4957. var cachedValue = cache[key];
  4958. if (cachedValue !== undefined) {
  4959. return cachedValue;
  4960. }
  4961. var output = new Array(numOutputs);
  4962. var stack = evaluator.execute(input);
  4963. var stackIndex = stack.length - numOutputs;
  4964. for (i = 0; i < numOutputs; i++) {
  4965. value = stack[stackIndex + i];
  4966. var bound = range[i * 2];
  4967. if (value < bound) {
  4968. value = bound;
  4969. } else {
  4970. bound = range[i * 2 +1];
  4971. if (value > bound) {
  4972. value = bound;
  4973. }
  4974. }
  4975. output[i] = value;
  4976. }
  4977. if (cache_available > 0) {
  4978. cache_available--;
  4979. cache[key] = output;
  4980. }
  4981. return output;
  4982. };
  4983. }
  4984. };
  4985. })();
  4986. function isPDFFunction(v) {
  4987. var fnDict;
  4988. if (typeof v != 'object') {
  4989. return false;
  4990. } else if (isDict(v)) {
  4991. fnDict = v;
  4992. } else if (isStream(v)) {
  4993. fnDict = v.dict;
  4994. } else {
  4995. return false;
  4996. }
  4997. return fnDict.has('FunctionType');
  4998. }
  4999. var PostScriptStack = (function PostScriptStackClosure() {
  5000. var MAX_STACK_SIZE = 100;
  5001. function PostScriptStack(initialStack) {
  5002. this.stack = initialStack || [];
  5003. }
  5004. PostScriptStack.prototype = {
  5005. push: function PostScriptStack_push(value) {
  5006. if (this.stack.length >= MAX_STACK_SIZE) {
  5007. error('PostScript function stack overflow.');
  5008. }
  5009. this.stack.push(value);
  5010. },
  5011. pop: function PostScriptStack_pop() {
  5012. if (this.stack.length <= 0) {
  5013. error('PostScript function stack underflow.');
  5014. }
  5015. return this.stack.pop();
  5016. },
  5017. copy: function PostScriptStack_copy(n) {
  5018. if (this.stack.length + n >= MAX_STACK_SIZE) {
  5019. error('PostScript function stack overflow.');
  5020. }
  5021. var stack = this.stack;
  5022. for (var i = stack.length - n, j = n - 1; j >= 0; j--, i++) {
  5023. stack.push(stack[i]);
  5024. }
  5025. },
  5026. index: function PostScriptStack_index(n) {
  5027. this.push(this.stack[this.stack.length - n - 1]);
  5028. },
  5029. // rotate the last n stack elements p times
  5030. roll: function PostScriptStack_roll(n, p) {
  5031. var stack = this.stack;
  5032. var l = stack.length - n;
  5033. var r = stack.length - 1, c = l + (p - Math.floor(p / n) * n), i, j, t;
  5034. for (i = l, j = r; i < j; i++, j--) {
  5035. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  5036. }
  5037. for (i = l, j = c - 1; i < j; i++, j--) {
  5038. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  5039. }
  5040. for (i = c, j = r; i < j; i++, j--) {
  5041. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  5042. }
  5043. }
  5044. };
  5045. return PostScriptStack;
  5046. })();
  5047. var PostScriptEvaluator = (function PostScriptEvaluatorClosure() {
  5048. function PostScriptEvaluator(operators) {
  5049. this.operators = operators;
  5050. }
  5051. PostScriptEvaluator.prototype = {
  5052. execute: function PostScriptEvaluator_execute(initialStack) {
  5053. var stack = new PostScriptStack(initialStack);
  5054. var counter = 0;
  5055. var operators = this.operators;
  5056. var length = operators.length;
  5057. var operator, a, b;
  5058. while (counter < length) {
  5059. operator = operators[counter++];
  5060. if (typeof operator == 'number') {
  5061. // Operator is really an operand and should be pushed to the stack.
  5062. stack.push(operator);
  5063. continue;
  5064. }
  5065. switch (operator) {
  5066. // non standard ps operators
  5067. case 'jz': // jump if false
  5068. b = stack.pop();
  5069. a = stack.pop();
  5070. if (!a) {
  5071. counter = b;
  5072. }
  5073. break;
  5074. case 'j': // jump
  5075. a = stack.pop();
  5076. counter = a;
  5077. break;
  5078. // all ps operators in alphabetical order (excluding if/ifelse)
  5079. case 'abs':
  5080. a = stack.pop();
  5081. stack.push(Math.abs(a));
  5082. break;
  5083. case 'add':
  5084. b = stack.pop();
  5085. a = stack.pop();
  5086. stack.push(a + b);
  5087. break;
  5088. case 'and':
  5089. b = stack.pop();
  5090. a = stack.pop();
  5091. if (isBool(a) && isBool(b)) {
  5092. stack.push(a && b);
  5093. } else {
  5094. stack.push(a & b);
  5095. }
  5096. break;
  5097. case 'atan':
  5098. a = stack.pop();
  5099. stack.push(Math.atan(a));
  5100. break;
  5101. case 'bitshift':
  5102. b = stack.pop();
  5103. a = stack.pop();
  5104. if (a > 0) {
  5105. stack.push(a << b);
  5106. } else {
  5107. stack.push(a >> b);
  5108. }
  5109. break;
  5110. case 'ceiling':
  5111. a = stack.pop();
  5112. stack.push(Math.ceil(a));
  5113. break;
  5114. case 'copy':
  5115. a = stack.pop();
  5116. stack.copy(a);
  5117. break;
  5118. case 'cos':
  5119. a = stack.pop();
  5120. stack.push(Math.cos(a));
  5121. break;
  5122. case 'cvi':
  5123. a = stack.pop() | 0;
  5124. stack.push(a);
  5125. break;
  5126. case 'cvr':
  5127. // noop
  5128. break;
  5129. case 'div':
  5130. b = stack.pop();
  5131. a = stack.pop();
  5132. stack.push(a / b);
  5133. break;
  5134. case 'dup':
  5135. stack.copy(1);
  5136. break;
  5137. case 'eq':
  5138. b = stack.pop();
  5139. a = stack.pop();
  5140. stack.push(a == b);
  5141. break;
  5142. case 'exch':
  5143. stack.roll(2, 1);
  5144. break;
  5145. case 'exp':
  5146. b = stack.pop();
  5147. a = stack.pop();
  5148. stack.push(Math.pow(a, b));
  5149. break;
  5150. case 'false':
  5151. stack.push(false);
  5152. break;
  5153. case 'floor':
  5154. a = stack.pop();
  5155. stack.push(Math.floor(a));
  5156. break;
  5157. case 'ge':
  5158. b = stack.pop();
  5159. a = stack.pop();
  5160. stack.push(a >= b);
  5161. break;
  5162. case 'gt':
  5163. b = stack.pop();
  5164. a = stack.pop();
  5165. stack.push(a > b);
  5166. break;
  5167. case 'idiv':
  5168. b = stack.pop();
  5169. a = stack.pop();
  5170. stack.push((a / b) | 0);
  5171. break;
  5172. case 'index':
  5173. a = stack.pop();
  5174. stack.index(a);
  5175. break;
  5176. case 'le':
  5177. b = stack.pop();
  5178. a = stack.pop();
  5179. stack.push(a <= b);
  5180. break;
  5181. case 'ln':
  5182. a = stack.pop();
  5183. stack.push(Math.log(a));
  5184. break;
  5185. case 'log':
  5186. a = stack.pop();
  5187. stack.push(Math.log(a) / Math.LN10);
  5188. break;
  5189. case 'lt':
  5190. b = stack.pop();
  5191. a = stack.pop();
  5192. stack.push(a < b);
  5193. break;
  5194. case 'mod':
  5195. b = stack.pop();
  5196. a = stack.pop();
  5197. stack.push(a % b);
  5198. break;
  5199. case 'mul':
  5200. b = stack.pop();
  5201. a = stack.pop();
  5202. stack.push(a * b);
  5203. break;
  5204. case 'ne':
  5205. b = stack.pop();
  5206. a = stack.pop();
  5207. stack.push(a != b);
  5208. break;
  5209. case 'neg':
  5210. a = stack.pop();
  5211. stack.push(-a);
  5212. break;
  5213. case 'not':
  5214. a = stack.pop();
  5215. if (isBool(a)) {
  5216. stack.push(!a);
  5217. } else {
  5218. stack.push(~a);
  5219. }
  5220. break;
  5221. case 'or':
  5222. b = stack.pop();
  5223. a = stack.pop();
  5224. if (isBool(a) && isBool(b)) {
  5225. stack.push(a || b);
  5226. } else {
  5227. stack.push(a | b);
  5228. }
  5229. break;
  5230. case 'pop':
  5231. stack.pop();
  5232. break;
  5233. case 'roll':
  5234. b = stack.pop();
  5235. a = stack.pop();
  5236. stack.roll(a, b);
  5237. break;
  5238. case 'round':
  5239. a = stack.pop();
  5240. stack.push(Math.round(a));
  5241. break;
  5242. case 'sin':
  5243. a = stack.pop();
  5244. stack.push(Math.sin(a));
  5245. break;
  5246. case 'sqrt':
  5247. a = stack.pop();
  5248. stack.push(Math.sqrt(a));
  5249. break;
  5250. case 'sub':
  5251. b = stack.pop();
  5252. a = stack.pop();
  5253. stack.push(a - b);
  5254. break;
  5255. case 'true':
  5256. stack.push(true);
  5257. break;
  5258. case 'truncate':
  5259. a = stack.pop();
  5260. a = a < 0 ? Math.ceil(a) : Math.floor(a);
  5261. stack.push(a);
  5262. break;
  5263. case 'xor':
  5264. b = stack.pop();
  5265. a = stack.pop();
  5266. if (isBool(a) && isBool(b)) {
  5267. stack.push(a != b);
  5268. } else {
  5269. stack.push(a ^ b);
  5270. }
  5271. break;
  5272. default:
  5273. error('Unknown operator ' + operator);
  5274. break;
  5275. }
  5276. }
  5277. return stack.stack;
  5278. }
  5279. };
  5280. return PostScriptEvaluator;
  5281. })();
  5282. var ColorSpace = (function ColorSpaceClosure() {
  5283. // Constructor should define this.numComps, this.defaultColor, this.name
  5284. function ColorSpace() {
  5285. error('should not call ColorSpace constructor');
  5286. }
  5287. ColorSpace.prototype = {
  5288. /**
  5289. * Converts the color value to the RGB color. The color components are
  5290. * located in the src array starting from the srcOffset. Returns the array
  5291. * of the rgb components, each value ranging from [0,255].
  5292. */
  5293. getRgb: function ColorSpace_getRgb(src, srcOffset) {
  5294. var rgb = new Uint8Array(3);
  5295. this.getRgbItem(src, srcOffset, rgb, 0);
  5296. return rgb;
  5297. },
  5298. /**
  5299. * Converts the color value to the RGB color, similar to the getRgb method.
  5300. * The result placed into the dest array starting from the destOffset.
  5301. */
  5302. getRgbItem: function ColorSpace_getRgbItem(src, srcOffset,
  5303. dest, destOffset) {
  5304. error('Should not call ColorSpace.getRgbItem');
  5305. },
  5306. /**
  5307. * Converts the specified number of the color values to the RGB colors.
  5308. * The colors are located in the src array starting from the srcOffset.
  5309. * The result is placed into the dest array starting from the destOffset.
  5310. * The src array items shall be in [0,2^bits) range, the dest array items
  5311. * will be in [0,255] range. alpha01 indicates how many alpha components
  5312. * there are in the dest array; it will be either 0 (RGB array) or 1 (RGBA
  5313. * array).
  5314. */
  5315. getRgbBuffer: function ColorSpace_getRgbBuffer(src, srcOffset, count,
  5316. dest, destOffset, bits,
  5317. alpha01) {
  5318. error('Should not call ColorSpace.getRgbBuffer');
  5319. },
  5320. /**
  5321. * Determines the number of bytes required to store the result of the
  5322. * conversion done by the getRgbBuffer method. As in getRgbBuffer,
  5323. * |alpha01| is either 0 (RGB output) or 1 (RGBA output).
  5324. */
  5325. getOutputLength: function ColorSpace_getOutputLength(inputLength,
  5326. alpha01) {
  5327. error('Should not call ColorSpace.getOutputLength');
  5328. },
  5329. /**
  5330. * Returns true if source data will be equal the result/output data.
  5331. */
  5332. isPassthrough: function ColorSpace_isPassthrough(bits) {
  5333. return false;
  5334. },
  5335. /**
  5336. * Fills in the RGB colors in the destination buffer. alpha01 indicates
  5337. * how many alpha components there are in the dest array; it will be either
  5338. * 0 (RGB array) or 1 (RGBA array).
  5339. */
  5340. fillRgb: function ColorSpace_fillRgb(dest, originalWidth,
  5341. originalHeight, width, height,
  5342. actualHeight, bpc, comps, alpha01) {
  5343. var count = originalWidth * originalHeight;
  5344. var rgbBuf = null;
  5345. var numComponentColors = 1 << bpc;
  5346. var needsResizing = originalHeight != height || originalWidth != width;
  5347. var i, ii;
  5348. if (this.isPassthrough(bpc)) {
  5349. rgbBuf = comps;
  5350. } else if (this.numComps === 1 && count > numComponentColors &&
  5351. this.name !== 'DeviceGray' && this.name !== 'DeviceRGB') {
  5352. // Optimization: create a color map when there is just one component and
  5353. // we are converting more colors than the size of the color map. We
  5354. // don't build the map if the colorspace is gray or rgb since those
  5355. // methods are faster than building a map. This mainly offers big speed
  5356. // ups for indexed and alternate colorspaces.
  5357. //
  5358. // TODO it may be worth while to cache the color map. While running
  5359. // testing I never hit a cache so I will leave that out for now (perhaps
  5360. // we are reparsing colorspaces too much?).
  5361. var allColors = bpc <= 8 ? new Uint8Array(numComponentColors) :
  5362. new Uint16Array(numComponentColors);
  5363. var key;
  5364. for (i = 0; i < numComponentColors; i++) {
  5365. allColors[i] = i;
  5366. }
  5367. var colorMap = new Uint8Array(numComponentColors * 3);
  5368. this.getRgbBuffer(allColors, 0, numComponentColors, colorMap, 0, bpc,
  5369. /* alpha01 = */ 0);
  5370. var destPos, rgbPos;
  5371. if (!needsResizing) {
  5372. // Fill in the RGB values directly into |dest|.
  5373. destPos = 0;
  5374. for (i = 0; i < count; ++i) {
  5375. key = comps[i] * 3;
  5376. dest[destPos++] = colorMap[key];
  5377. dest[destPos++] = colorMap[key + 1];
  5378. dest[destPos++] = colorMap[key + 2];
  5379. destPos += alpha01;
  5380. }
  5381. } else {
  5382. rgbBuf = new Uint8Array(count * 3);
  5383. rgbPos = 0;
  5384. for (i = 0; i < count; ++i) {
  5385. key = comps[i] * 3;
  5386. rgbBuf[rgbPos++] = colorMap[key];
  5387. rgbBuf[rgbPos++] = colorMap[key + 1];
  5388. rgbBuf[rgbPos++] = colorMap[key + 2];
  5389. }
  5390. }
  5391. } else {
  5392. if (!needsResizing) {
  5393. // Fill in the RGB values directly into |dest|.
  5394. this.getRgbBuffer(comps, 0, width * actualHeight, dest, 0, bpc,
  5395. alpha01);
  5396. } else {
  5397. rgbBuf = new Uint8Array(count * 3);
  5398. this.getRgbBuffer(comps, 0, count, rgbBuf, 0, bpc,
  5399. /* alpha01 = */ 0);
  5400. }
  5401. }
  5402. if (rgbBuf) {
  5403. if (needsResizing) {
  5404. PDFImage.resize(rgbBuf, bpc, 3, originalWidth, originalHeight, width,
  5405. height, dest, alpha01);
  5406. } else {
  5407. rgbPos = 0;
  5408. destPos = 0;
  5409. for (i = 0, ii = width * actualHeight; i < ii; i++) {
  5410. dest[destPos++] = rgbBuf[rgbPos++];
  5411. dest[destPos++] = rgbBuf[rgbPos++];
  5412. dest[destPos++] = rgbBuf[rgbPos++];
  5413. destPos += alpha01;
  5414. }
  5415. }
  5416. }
  5417. },
  5418. /**
  5419. * True if the colorspace has components in the default range of [0, 1].
  5420. * This should be true for all colorspaces except for lab color spaces
  5421. * which are [0,100], [-128, 127], [-128, 127].
  5422. */
  5423. usesZeroToOneRange: true
  5424. };
  5425. ColorSpace.parse = function ColorSpace_parse(cs, xref, res) {
  5426. var IR = ColorSpace.parseToIR(cs, xref, res);
  5427. if (IR instanceof AlternateCS) {
  5428. return IR;
  5429. }
  5430. return ColorSpace.fromIR(IR);
  5431. };
  5432. ColorSpace.fromIR = function ColorSpace_fromIR(IR) {
  5433. var name = isArray(IR) ? IR[0] : IR;
  5434. var whitePoint, blackPoint;
  5435. switch (name) {
  5436. case 'DeviceGrayCS':
  5437. return this.singletons.gray;
  5438. case 'DeviceRgbCS':
  5439. return this.singletons.rgb;
  5440. case 'DeviceCmykCS':
  5441. return this.singletons.cmyk;
  5442. case 'CalGrayCS':
  5443. whitePoint = IR[1].WhitePoint;
  5444. blackPoint = IR[1].BlackPoint;
  5445. var gamma = IR[1].Gamma;
  5446. return new CalGrayCS(whitePoint, blackPoint, gamma);
  5447. case 'PatternCS':
  5448. var basePatternCS = IR[1];
  5449. if (basePatternCS) {
  5450. basePatternCS = ColorSpace.fromIR(basePatternCS);
  5451. }
  5452. return new PatternCS(basePatternCS);
  5453. case 'IndexedCS':
  5454. var baseIndexedCS = IR[1];
  5455. var hiVal = IR[2];
  5456. var lookup = IR[3];
  5457. return new IndexedCS(ColorSpace.fromIR(baseIndexedCS), hiVal, lookup);
  5458. case 'AlternateCS':
  5459. var numComps = IR[1];
  5460. var alt = IR[2];
  5461. var tintFnIR = IR[3];
  5462. return new AlternateCS(numComps, ColorSpace.fromIR(alt),
  5463. PDFFunction.fromIR(tintFnIR));
  5464. case 'LabCS':
  5465. whitePoint = IR[1].WhitePoint;
  5466. blackPoint = IR[1].BlackPoint;
  5467. var range = IR[1].Range;
  5468. return new LabCS(whitePoint, blackPoint, range);
  5469. default:
  5470. error('Unkown name ' + name);
  5471. }
  5472. return null;
  5473. };
  5474. ColorSpace.parseToIR = function ColorSpace_parseToIR(cs, xref, res) {
  5475. if (isName(cs)) {
  5476. var colorSpaces = res.get('ColorSpace');
  5477. if (isDict(colorSpaces)) {
  5478. var refcs = colorSpaces.get(cs.name);
  5479. if (refcs) {
  5480. cs = refcs;
  5481. }
  5482. }
  5483. }
  5484. cs = xref.fetchIfRef(cs);
  5485. var mode;
  5486. if (isName(cs)) {
  5487. mode = cs.name;
  5488. this.mode = mode;
  5489. switch (mode) {
  5490. case 'DeviceGray':
  5491. case 'G':
  5492. return 'DeviceGrayCS';
  5493. case 'DeviceRGB':
  5494. case 'RGB':
  5495. return 'DeviceRgbCS';
  5496. case 'DeviceCMYK':
  5497. case 'CMYK':
  5498. return 'DeviceCmykCS';
  5499. case 'Pattern':
  5500. return ['PatternCS', null];
  5501. default:
  5502. error('unrecognized colorspace ' + mode);
  5503. }
  5504. } else if (isArray(cs)) {
  5505. mode = cs[0].name;
  5506. this.mode = mode;
  5507. var numComps, params;
  5508. switch (mode) {
  5509. case 'DeviceGray':
  5510. case 'G':
  5511. return 'DeviceGrayCS';
  5512. case 'DeviceRGB':
  5513. case 'RGB':
  5514. return 'DeviceRgbCS';
  5515. case 'DeviceCMYK':
  5516. case 'CMYK':
  5517. return 'DeviceCmykCS';
  5518. case 'CalGray':
  5519. params = cs[1].getAll();
  5520. return ['CalGrayCS', params];
  5521. case 'CalRGB':
  5522. return 'DeviceRgbCS';
  5523. case 'ICCBased':
  5524. var stream = xref.fetchIfRef(cs[1]);
  5525. var dict = stream.dict;
  5526. numComps = dict.get('N');
  5527. if (numComps == 1) {
  5528. return 'DeviceGrayCS';
  5529. } else if (numComps == 3) {
  5530. return 'DeviceRgbCS';
  5531. } else if (numComps == 4) {
  5532. return 'DeviceCmykCS';
  5533. }
  5534. break;
  5535. case 'Pattern':
  5536. var basePatternCS = cs[1];
  5537. if (basePatternCS) {
  5538. basePatternCS = ColorSpace.parseToIR(basePatternCS, xref, res);
  5539. }
  5540. return ['PatternCS', basePatternCS];
  5541. case 'Indexed':
  5542. case 'I':
  5543. var baseIndexedCS = ColorSpace.parseToIR(cs[1], xref, res);
  5544. var hiVal = cs[2] + 1;
  5545. var lookup = xref.fetchIfRef(cs[3]);
  5546. if (isStream(lookup)) {
  5547. lookup = lookup.getBytes();
  5548. }
  5549. return ['IndexedCS', baseIndexedCS, hiVal, lookup];
  5550. case 'Separation':
  5551. case 'DeviceN':
  5552. var name = cs[1];
  5553. numComps = 1;
  5554. if (isName(name)) {
  5555. numComps = 1;
  5556. } else if (isArray(name)) {
  5557. numComps = name.length;
  5558. }
  5559. var alt = ColorSpace.parseToIR(cs[2], xref, res);
  5560. var tintFnIR = PDFFunction.getIR(xref, xref.fetchIfRef(cs[3]));
  5561. return ['AlternateCS', numComps, alt, tintFnIR];
  5562. case 'Lab':
  5563. params = cs[1].getAll();
  5564. return ['LabCS', params];
  5565. default:
  5566. error('unimplemented color space object "' + mode + '"');
  5567. }
  5568. } else {
  5569. error('unrecognized color space object: "' + cs + '"');
  5570. }
  5571. return null;
  5572. };
  5573. /**
  5574. * Checks if a decode map matches the default decode map for a color space.
  5575. * This handles the general decode maps where there are two values per
  5576. * component. e.g. [0, 1, 0, 1, 0, 1] for a RGB color.
  5577. * This does not handle Lab, Indexed, or Pattern decode maps since they are
  5578. * slightly different.
  5579. * @param {Array} decode Decode map (usually from an image).
  5580. * @param {Number} n Number of components the color space has.
  5581. */
  5582. ColorSpace.isDefaultDecode = function ColorSpace_isDefaultDecode(decode, n) {
  5583. if (!decode) {
  5584. return true;
  5585. }
  5586. if (n * 2 !== decode.length) {
  5587. warn('The decode map is not the correct length');
  5588. return true;
  5589. }
  5590. for (var i = 0, ii = decode.length; i < ii; i += 2) {
  5591. if (decode[i] !== 0 || decode[i + 1] != 1) {
  5592. return false;
  5593. }
  5594. }
  5595. return true;
  5596. };
  5597. ColorSpace.singletons = {
  5598. get gray() {
  5599. return shadow(this, 'gray', new DeviceGrayCS());
  5600. },
  5601. get rgb() {
  5602. return shadow(this, 'rgb', new DeviceRgbCS());
  5603. },
  5604. get cmyk() {
  5605. return shadow(this, 'cmyk', new DeviceCmykCS());
  5606. }
  5607. };
  5608. return ColorSpace;
  5609. })();
  5610. /**
  5611. * Alternate color space handles both Separation and DeviceN color spaces. A
  5612. * Separation color space is actually just a DeviceN with one color component.
  5613. * Both color spaces use a tinting function to convert colors to a base color
  5614. * space.
  5615. */
  5616. var AlternateCS = (function AlternateCSClosure() {
  5617. function AlternateCS(numComps, base, tintFn) {
  5618. this.name = 'Alternate';
  5619. this.numComps = numComps;
  5620. this.defaultColor = new Float32Array(numComps);
  5621. for (var i = 0; i < numComps; ++i) {
  5622. this.defaultColor[i] = 1;
  5623. }
  5624. this.base = base;
  5625. this.tintFn = tintFn;
  5626. }
  5627. AlternateCS.prototype = {
  5628. getRgb: ColorSpace.prototype.getRgb,
  5629. getRgbItem: function AlternateCS_getRgbItem(src, srcOffset,
  5630. dest, destOffset) {
  5631. var baseNumComps = this.base.numComps;
  5632. var input = 'subarray' in src ?
  5633. src.subarray(srcOffset, srcOffset + this.numComps) :
  5634. Array.prototype.slice.call(src, srcOffset, srcOffset + this.numComps);
  5635. var tinted = this.tintFn(input);
  5636. this.base.getRgbItem(tinted, 0, dest, destOffset);
  5637. },
  5638. getRgbBuffer: function AlternateCS_getRgbBuffer(src, srcOffset, count,
  5639. dest, destOffset, bits,
  5640. alpha01) {
  5641. var tinted;
  5642. var tintFn = this.tintFn;
  5643. var base = this.base;
  5644. var scale = 1 / ((1 << bits) - 1);
  5645. var baseNumComps = base.numComps;
  5646. var usesZeroToOneRange = base.usesZeroToOneRange;
  5647. var isPassthrough = (base.isPassthrough(8) || !usesZeroToOneRange) &&
  5648. alpha01 === 0;
  5649. var pos = isPassthrough ? destOffset : 0;
  5650. var baseBuf = isPassthrough ? dest : new Uint8Array(baseNumComps * count);
  5651. var numComps = this.numComps;
  5652. var scaled = new Float32Array(numComps);
  5653. var i, j;
  5654. if (usesZeroToOneRange) {
  5655. for (i = 0; i < count; i++) {
  5656. for (j = 0; j < numComps; j++) {
  5657. scaled[j] = src[srcOffset++] * scale;
  5658. }
  5659. tinted = tintFn(scaled);
  5660. for (j = 0; j < baseNumComps; j++) {
  5661. baseBuf[pos++] = tinted[j] * 255;
  5662. }
  5663. }
  5664. } else {
  5665. for (i = 0; i < count; i++) {
  5666. for (j = 0; j < numComps; j++) {
  5667. scaled[j] = src[srcOffset++] * scale;
  5668. }
  5669. tinted = tintFn(scaled);
  5670. base.getRgbItem(tinted, 0, baseBuf, pos);
  5671. pos += baseNumComps;
  5672. }
  5673. }
  5674. if (!isPassthrough) {
  5675. base.getRgbBuffer(baseBuf, 0, count, dest, destOffset, 8, alpha01);
  5676. }
  5677. },
  5678. getOutputLength: function AlternateCS_getOutputLength(inputLength,
  5679. alpha01) {
  5680. return this.base.getOutputLength(inputLength *
  5681. this.base.numComps / this.numComps,
  5682. alpha01);
  5683. },
  5684. isPassthrough: ColorSpace.prototype.isPassthrough,
  5685. fillRgb: ColorSpace.prototype.fillRgb,
  5686. isDefaultDecode: function AlternateCS_isDefaultDecode(decodeMap) {
  5687. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  5688. },
  5689. usesZeroToOneRange: true
  5690. };
  5691. return AlternateCS;
  5692. })();
  5693. var PatternCS = (function PatternCSClosure() {
  5694. function PatternCS(baseCS) {
  5695. this.name = 'Pattern';
  5696. this.base = baseCS;
  5697. }
  5698. PatternCS.prototype = {};
  5699. return PatternCS;
  5700. })();
  5701. var IndexedCS = (function IndexedCSClosure() {
  5702. function IndexedCS(base, highVal, lookup) {
  5703. this.name = 'Indexed';
  5704. this.numComps = 1;
  5705. this.defaultColor = new Uint8Array([0]);
  5706. this.base = base;
  5707. this.highVal = highVal;
  5708. var baseNumComps = base.numComps;
  5709. var length = baseNumComps * highVal;
  5710. var lookupArray;
  5711. if (isStream(lookup)) {
  5712. lookupArray = new Uint8Array(length);
  5713. var bytes = lookup.getBytes(length);
  5714. lookupArray.set(bytes);
  5715. } else if (isString(lookup)) {
  5716. lookupArray = new Uint8Array(length);
  5717. for (var i = 0; i < length; ++i) {
  5718. lookupArray[i] = lookup.charCodeAt(i);
  5719. }
  5720. } else if (lookup instanceof Uint8Array || lookup instanceof Array) {
  5721. lookupArray = lookup;
  5722. } else {
  5723. error('Unrecognized lookup table: ' + lookup);
  5724. }
  5725. this.lookup = lookupArray;
  5726. }
  5727. IndexedCS.prototype = {
  5728. getRgb: ColorSpace.prototype.getRgb,
  5729. getRgbItem: function IndexedCS_getRgbItem(src, srcOffset,
  5730. dest, destOffset) {
  5731. var numComps = this.base.numComps;
  5732. var start = src[srcOffset] * numComps;
  5733. this.base.getRgbItem(this.lookup, start, dest, destOffset);
  5734. },
  5735. getRgbBuffer: function IndexedCS_getRgbBuffer(src, srcOffset, count,
  5736. dest, destOffset, bits,
  5737. alpha01) {
  5738. var base = this.base;
  5739. var numComps = base.numComps;
  5740. var outputDelta = base.getOutputLength(numComps, alpha01);
  5741. var lookup = this.lookup;
  5742. for (var i = 0; i < count; ++i) {
  5743. var lookupPos = src[srcOffset++] * numComps;
  5744. base.getRgbBuffer(lookup, lookupPos, 1, dest, destOffset, 8, alpha01);
  5745. destOffset += outputDelta;
  5746. }
  5747. },
  5748. getOutputLength: function IndexedCS_getOutputLength(inputLength, alpha01) {
  5749. return this.base.getOutputLength(inputLength * this.base.numComps,
  5750. alpha01);
  5751. },
  5752. isPassthrough: ColorSpace.prototype.isPassthrough,
  5753. fillRgb: ColorSpace.prototype.fillRgb,
  5754. isDefaultDecode: function IndexedCS_isDefaultDecode(decodeMap) {
  5755. // indexed color maps shouldn't be changed
  5756. return true;
  5757. },
  5758. usesZeroToOneRange: true
  5759. };
  5760. return IndexedCS;
  5761. })();
  5762. var DeviceGrayCS = (function DeviceGrayCSClosure() {
  5763. function DeviceGrayCS() {
  5764. this.name = 'DeviceGray';
  5765. this.numComps = 1;
  5766. this.defaultColor = new Float32Array([0]);
  5767. }
  5768. DeviceGrayCS.prototype = {
  5769. getRgb: ColorSpace.prototype.getRgb,
  5770. getRgbItem: function DeviceGrayCS_getRgbItem(src, srcOffset,
  5771. dest, destOffset) {
  5772. var c = (src[srcOffset] * 255) | 0;
  5773. c = c < 0 ? 0 : c > 255 ? 255 : c;
  5774. dest[destOffset] = dest[destOffset + 1] = dest[destOffset + 2] = c;
  5775. },
  5776. getRgbBuffer: function DeviceGrayCS_getRgbBuffer(src, srcOffset, count,
  5777. dest, destOffset, bits,
  5778. alpha01) {
  5779. var scale = 255 / ((1 << bits) - 1);
  5780. var j = srcOffset, q = destOffset;
  5781. for (var i = 0; i < count; ++i) {
  5782. var c = (scale * src[j++]) | 0;
  5783. dest[q++] = c;
  5784. dest[q++] = c;
  5785. dest[q++] = c;
  5786. q += alpha01;
  5787. }
  5788. },
  5789. getOutputLength: function DeviceGrayCS_getOutputLength(inputLength,
  5790. alpha01) {
  5791. return inputLength * (3 + alpha01);
  5792. },
  5793. isPassthrough: ColorSpace.prototype.isPassthrough,
  5794. fillRgb: ColorSpace.prototype.fillRgb,
  5795. isDefaultDecode: function DeviceGrayCS_isDefaultDecode(decodeMap) {
  5796. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  5797. },
  5798. usesZeroToOneRange: true
  5799. };
  5800. return DeviceGrayCS;
  5801. })();
  5802. var DeviceRgbCS = (function DeviceRgbCSClosure() {
  5803. function DeviceRgbCS() {
  5804. this.name = 'DeviceRGB';
  5805. this.numComps = 3;
  5806. this.defaultColor = new Float32Array([0, 0, 0]);
  5807. }
  5808. DeviceRgbCS.prototype = {
  5809. getRgb: ColorSpace.prototype.getRgb,
  5810. getRgbItem: function DeviceRgbCS_getRgbItem(src, srcOffset,
  5811. dest, destOffset) {
  5812. var r = (src[srcOffset] * 255) | 0;
  5813. var g = (src[srcOffset + 1] * 255) | 0;
  5814. var b = (src[srcOffset + 2] * 255) | 0;
  5815. dest[destOffset] = r < 0 ? 0 : r > 255 ? 255 : r;
  5816. dest[destOffset + 1] = g < 0 ? 0 : g > 255 ? 255 : g;
  5817. dest[destOffset + 2] = b < 0 ? 0 : b > 255 ? 255 : b;
  5818. },
  5819. getRgbBuffer: function DeviceRgbCS_getRgbBuffer(src, srcOffset, count,
  5820. dest, destOffset, bits,
  5821. alpha01) {
  5822. if (bits === 8 && alpha01 === 0) {
  5823. dest.set(src.subarray(srcOffset, srcOffset + count * 3), destOffset);
  5824. return;
  5825. }
  5826. var scale = 255 / ((1 << bits) - 1);
  5827. var j = srcOffset, q = destOffset;
  5828. for (var i = 0; i < count; ++i) {
  5829. dest[q++] = (scale * src[j++]) | 0;
  5830. dest[q++] = (scale * src[j++]) | 0;
  5831. dest[q++] = (scale * src[j++]) | 0;
  5832. q += alpha01;
  5833. }
  5834. },
  5835. getOutputLength: function DeviceRgbCS_getOutputLength(inputLength,
  5836. alpha01) {
  5837. return (inputLength * (3 + alpha01) / 3) | 0;
  5838. },
  5839. isPassthrough: function DeviceRgbCS_isPassthrough(bits) {
  5840. return bits == 8;
  5841. },
  5842. fillRgb: ColorSpace.prototype.fillRgb,
  5843. isDefaultDecode: function DeviceRgbCS_isDefaultDecode(decodeMap) {
  5844. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  5845. },
  5846. usesZeroToOneRange: true
  5847. };
  5848. return DeviceRgbCS;
  5849. })();
  5850. var DeviceCmykCS = (function DeviceCmykCSClosure() {
  5851. // The coefficients below was found using numerical analysis: the method of
  5852. // steepest descent for the sum((f_i - color_value_i)^2) for r/g/b colors,
  5853. // where color_value is the tabular value from the table of sampled RGB colors
  5854. // from CMYK US Web Coated (SWOP) colorspace, and f_i is the corresponding
  5855. // CMYK color conversion using the estimation below:
  5856. // f(A, B,.. N) = Acc+Bcm+Ccy+Dck+c+Fmm+Gmy+Hmk+Im+Jyy+Kyk+Ly+Mkk+Nk+255
  5857. function convertToRgb(src, srcOffset, srcScale, dest, destOffset) {
  5858. var c = src[srcOffset + 0] * srcScale;
  5859. var m = src[srcOffset + 1] * srcScale;
  5860. var y = src[srcOffset + 2] * srcScale;
  5861. var k = src[srcOffset + 3] * srcScale;
  5862. var r =
  5863. (c * (-4.387332384609988 * c + 54.48615194189176 * m +
  5864. 18.82290502165302 * y + 212.25662451639585 * k +
  5865. -285.2331026137004) +
  5866. m * (1.7149763477362134 * m - 5.6096736904047315 * y +
  5867. -17.873870861415444 * k - 5.497006427196366) +
  5868. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  5869. 17.5119270841813) +
  5870. k * (-21.86122147463605 * k - 189.48180835922747) + 255) | 0;
  5871. var g =
  5872. (c * (8.841041422036149 * c + 60.118027045597366 * m +
  5873. 6.871425592049007 * y + 31.159100130055922 * k +
  5874. -79.2970844816548) +
  5875. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  5876. 131.35250912493976 * k - 190.9453302588951) +
  5877. y * (4.444339102852739 * y + 9.8632861493405 * k - 24.86741582555878) +
  5878. k * (-20.737325471181034 * k - 187.80453709719578) + 255) | 0;
  5879. var b =
  5880. (c * (0.8842522430003296 * c + 8.078677503112928 * m +
  5881. 30.89978309703729 * y - 0.23883238689178934 * k +
  5882. -14.183576799673286) +
  5883. m * (10.49593273432072 * m + 63.02378494754052 * y +
  5884. 50.606957656360734 * k - 112.23884253719248) +
  5885. y * (0.03296041114873217 * y + 115.60384449646641 * k +
  5886. -193.58209356861505) +
  5887. k * (-22.33816807309886 * k - 180.12613974708367) + 255) | 0;
  5888. dest[destOffset] = r > 255 ? 255 : r < 0 ? 0 : r;
  5889. dest[destOffset + 1] = g > 255 ? 255 : g < 0 ? 0 : g;
  5890. dest[destOffset + 2] = b > 255 ? 255 : b < 0 ? 0 : b;
  5891. }
  5892. function DeviceCmykCS() {
  5893. this.name = 'DeviceCMYK';
  5894. this.numComps = 4;
  5895. this.defaultColor = new Float32Array([0, 0, 0, 1]);
  5896. }
  5897. DeviceCmykCS.prototype = {
  5898. getRgb: ColorSpace.prototype.getRgb,
  5899. getRgbItem: function DeviceCmykCS_getRgbItem(src, srcOffset,
  5900. dest, destOffset) {
  5901. convertToRgb(src, srcOffset, 1, dest, destOffset);
  5902. },
  5903. getRgbBuffer: function DeviceCmykCS_getRgbBuffer(src, srcOffset, count,
  5904. dest, destOffset, bits,
  5905. alpha01) {
  5906. var scale = 1 / ((1 << bits) - 1);
  5907. for (var i = 0; i < count; i++) {
  5908. convertToRgb(src, srcOffset, scale, dest, destOffset);
  5909. srcOffset += 4;
  5910. destOffset += 3 + alpha01;
  5911. }
  5912. },
  5913. getOutputLength: function DeviceCmykCS_getOutputLength(inputLength,
  5914. alpha01) {
  5915. return (inputLength / 4 * (3 + alpha01)) | 0;
  5916. },
  5917. isPassthrough: ColorSpace.prototype.isPassthrough,
  5918. fillRgb: ColorSpace.prototype.fillRgb,
  5919. isDefaultDecode: function DeviceCmykCS_isDefaultDecode(decodeMap) {
  5920. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  5921. },
  5922. usesZeroToOneRange: true
  5923. };
  5924. return DeviceCmykCS;
  5925. })();
  5926. //
  5927. // CalGrayCS: Based on "PDF Reference, Sixth Ed", p.245
  5928. //
  5929. var CalGrayCS = (function CalGrayCSClosure() {
  5930. function CalGrayCS(whitePoint, blackPoint, gamma) {
  5931. this.name = 'CalGray';
  5932. this.numComps = 1;
  5933. this.defaultColor = new Float32Array([0]);
  5934. if (!whitePoint) {
  5935. error('WhitePoint missing - required for color space CalGray');
  5936. }
  5937. blackPoint = blackPoint || [0, 0, 0];
  5938. gamma = gamma || 1;
  5939. // Translate arguments to spec variables.
  5940. this.XW = whitePoint[0];
  5941. this.YW = whitePoint[1];
  5942. this.ZW = whitePoint[2];
  5943. this.XB = blackPoint[0];
  5944. this.YB = blackPoint[1];
  5945. this.ZB = blackPoint[2];
  5946. this.G = gamma;
  5947. // Validate variables as per spec.
  5948. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  5949. error('Invalid WhitePoint components for ' + this.name +
  5950. ', no fallback available');
  5951. }
  5952. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  5953. info('Invalid BlackPoint for ' + this.name + ', falling back to default');
  5954. this.XB = this.YB = this.ZB = 0;
  5955. }
  5956. if (this.XB !== 0 || this.YB !== 0 || this.ZB !== 0) {
  5957. warn(this.name + ', BlackPoint: XB: ' + this.XB + ', YB: ' + this.YB +
  5958. ', ZB: ' + this.ZB + ', only default values are supported.');
  5959. }
  5960. if (this.G < 1) {
  5961. info('Invalid Gamma: ' + this.G + ' for ' + this.name +
  5962. ', falling back to default');
  5963. this.G = 1;
  5964. }
  5965. }
  5966. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  5967. // A represents a gray component of a calibrated gray space.
  5968. // A <---> AG in the spec
  5969. var A = src[srcOffset] * scale;
  5970. var AG = Math.pow(A, cs.G);
  5971. // Computes L as per spec. ( = cs.YW * AG )
  5972. // Except if other than default BlackPoint values are used.
  5973. var L = cs.YW * AG;
  5974. // http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html, Ch 4.
  5975. // Convert values to rgb range [0, 255].
  5976. var val = Math.max(295.8 * Math.pow(L, 0.333333333333333333) - 40.8, 0) | 0;
  5977. dest[destOffset] = val;
  5978. dest[destOffset + 1] = val;
  5979. dest[destOffset + 2] = val;
  5980. }
  5981. CalGrayCS.prototype = {
  5982. getRgb: ColorSpace.prototype.getRgb,
  5983. getRgbItem: function CalGrayCS_getRgbItem(src, srcOffset,
  5984. dest, destOffset) {
  5985. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  5986. },
  5987. getRgbBuffer: function CalGrayCS_getRgbBuffer(src, srcOffset, count,
  5988. dest, destOffset, bits,
  5989. alpha01) {
  5990. var scale = 1 / ((1 << bits) - 1);
  5991. for (var i = 0; i < count; ++i) {
  5992. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  5993. srcOffset += 1;
  5994. destOffset += 3 + alpha01;
  5995. }
  5996. },
  5997. getOutputLength: function CalGrayCS_getOutputLength(inputLength, alpha01) {
  5998. return inputLength * (3 + alpha01);
  5999. },
  6000. isPassthrough: ColorSpace.prototype.isPassthrough,
  6001. fillRgb: ColorSpace.prototype.fillRgb,
  6002. isDefaultDecode: function CalGrayCS_isDefaultDecode(decodeMap) {
  6003. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  6004. },
  6005. usesZeroToOneRange: true
  6006. };
  6007. return CalGrayCS;
  6008. })();
  6009. //
  6010. // LabCS: Based on "PDF Reference, Sixth Ed", p.250
  6011. //
  6012. var LabCS = (function LabCSClosure() {
  6013. function LabCS(whitePoint, blackPoint, range) {
  6014. this.name = 'Lab';
  6015. this.numComps = 3;
  6016. this.defaultColor = new Float32Array([0, 0, 0]);
  6017. if (!whitePoint) {
  6018. error('WhitePoint missing - required for color space Lab');
  6019. }
  6020. blackPoint = blackPoint || [0, 0, 0];
  6021. range = range || [-100, 100, -100, 100];
  6022. // Translate args to spec variables
  6023. this.XW = whitePoint[0];
  6024. this.YW = whitePoint[1];
  6025. this.ZW = whitePoint[2];
  6026. this.amin = range[0];
  6027. this.amax = range[1];
  6028. this.bmin = range[2];
  6029. this.bmax = range[3];
  6030. // These are here just for completeness - the spec doesn't offer any
  6031. // formulas that use BlackPoint in Lab
  6032. this.XB = blackPoint[0];
  6033. this.YB = blackPoint[1];
  6034. this.ZB = blackPoint[2];
  6035. // Validate vars as per spec
  6036. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  6037. error('Invalid WhitePoint components, no fallback available');
  6038. }
  6039. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  6040. info('Invalid BlackPoint, falling back to default');
  6041. this.XB = this.YB = this.ZB = 0;
  6042. }
  6043. if (this.amin > this.amax || this.bmin > this.bmax) {
  6044. info('Invalid Range, falling back to defaults');
  6045. this.amin = -100;
  6046. this.amax = 100;
  6047. this.bmin = -100;
  6048. this.bmax = 100;
  6049. }
  6050. }
  6051. // Function g(x) from spec
  6052. function fn_g(x) {
  6053. if (x >= 6 / 29) {
  6054. return x * x * x;
  6055. } else {
  6056. return (108 / 841) * (x - 4 / 29);
  6057. }
  6058. }
  6059. function decode(value, high1, low2, high2) {
  6060. return low2 + (value) * (high2 - low2) / (high1);
  6061. }
  6062. // If decoding is needed maxVal should be 2^bits per component - 1.
  6063. function convertToRgb(cs, src, srcOffset, maxVal, dest, destOffset) {
  6064. // XXX: Lab input is in the range of [0, 100], [amin, amax], [bmin, bmax]
  6065. // not the usual [0, 1]. If a command like setFillColor is used the src
  6066. // values will already be within the correct range. However, if we are
  6067. // converting an image we have to map the values to the correct range given
  6068. // above.
  6069. // Ls,as,bs <---> L*,a*,b* in the spec
  6070. var Ls = src[srcOffset];
  6071. var as = src[srcOffset + 1];
  6072. var bs = src[srcOffset + 2];
  6073. if (maxVal !== false) {
  6074. Ls = decode(Ls, maxVal, 0, 100);
  6075. as = decode(as, maxVal, cs.amin, cs.amax);
  6076. bs = decode(bs, maxVal, cs.bmin, cs.bmax);
  6077. }
  6078. // Adjust limits of 'as' and 'bs'
  6079. as = as > cs.amax ? cs.amax : as < cs.amin ? cs.amin : as;
  6080. bs = bs > cs.bmax ? cs.bmax : bs < cs.bmin ? cs.bmin : bs;
  6081. // Computes intermediate variables X,Y,Z as per spec
  6082. var M = (Ls + 16) / 116;
  6083. var L = M + (as / 500);
  6084. var N = M - (bs / 200);
  6085. var X = cs.XW * fn_g(L);
  6086. var Y = cs.YW * fn_g(M);
  6087. var Z = cs.ZW * fn_g(N);
  6088. var r, g, b;
  6089. // Using different conversions for D50 and D65 white points,
  6090. // per http://www.color.org/srgb.pdf
  6091. if (cs.ZW < 1) {
  6092. // Assuming D50 (X=0.9642, Y=1.00, Z=0.8249)
  6093. r = X * 3.1339 + Y * -1.6170 + Z * -0.4906;
  6094. g = X * -0.9785 + Y * 1.9160 + Z * 0.0333;
  6095. b = X * 0.0720 + Y * -0.2290 + Z * 1.4057;
  6096. } else {
  6097. // Assuming D65 (X=0.9505, Y=1.00, Z=1.0888)
  6098. r = X * 3.2406 + Y * -1.5372 + Z * -0.4986;
  6099. g = X * -0.9689 + Y * 1.8758 + Z * 0.0415;
  6100. b = X * 0.0557 + Y * -0.2040 + Z * 1.0570;
  6101. }
  6102. // clamp color values to [0,1] range then convert to [0,255] range.
  6103. dest[destOffset] = r <= 0 ? 0 : r >= 1 ? 255 : Math.sqrt(r) * 255 | 0;
  6104. dest[destOffset + 1] = g <= 0 ? 0 : g >= 1 ? 255 : Math.sqrt(g) * 255 | 0;
  6105. dest[destOffset + 2] = b <= 0 ? 0 : b >= 1 ? 255 : Math.sqrt(b) * 255 | 0;
  6106. }
  6107. LabCS.prototype = {
  6108. getRgb: ColorSpace.prototype.getRgb,
  6109. getRgbItem: function LabCS_getRgbItem(src, srcOffset, dest, destOffset) {
  6110. convertToRgb(this, src, srcOffset, false, dest, destOffset);
  6111. },
  6112. getRgbBuffer: function LabCS_getRgbBuffer(src, srcOffset, count,
  6113. dest, destOffset, bits,
  6114. alpha01) {
  6115. var maxVal = (1 << bits) - 1;
  6116. for (var i = 0; i < count; i++) {
  6117. convertToRgb(this, src, srcOffset, maxVal, dest, destOffset);
  6118. srcOffset += 3;
  6119. destOffset += 3 + alpha01;
  6120. }
  6121. },
  6122. getOutputLength: function LabCS_getOutputLength(inputLength, alpha01) {
  6123. return (inputLength * (3 + alpha01) / 3) | 0;
  6124. },
  6125. isPassthrough: ColorSpace.prototype.isPassthrough,
  6126. fillRgb: ColorSpace.prototype.fillRgb,
  6127. isDefaultDecode: function LabCS_isDefaultDecode(decodeMap) {
  6128. // XXX: Decoding is handled with the lab conversion because of the strange
  6129. // ranges that are used.
  6130. return true;
  6131. },
  6132. usesZeroToOneRange: false
  6133. };
  6134. return LabCS;
  6135. })();
  6136. var ARCFourCipher = (function ARCFourCipherClosure() {
  6137. function ARCFourCipher(key) {
  6138. this.a = 0;
  6139. this.b = 0;
  6140. var s = new Uint8Array(256);
  6141. var i, j = 0, tmp, keyLength = key.length;
  6142. for (i = 0; i < 256; ++i) {
  6143. s[i] = i;
  6144. }
  6145. for (i = 0; i < 256; ++i) {
  6146. tmp = s[i];
  6147. j = (j + tmp + key[i % keyLength]) & 0xFF;
  6148. s[i] = s[j];
  6149. s[j] = tmp;
  6150. }
  6151. this.s = s;
  6152. }
  6153. ARCFourCipher.prototype = {
  6154. encryptBlock: function ARCFourCipher_encryptBlock(data) {
  6155. var i, n = data.length, tmp, tmp2;
  6156. var a = this.a, b = this.b, s = this.s;
  6157. var output = new Uint8Array(n);
  6158. for (i = 0; i < n; ++i) {
  6159. a = (a + 1) & 0xFF;
  6160. tmp = s[a];
  6161. b = (b + tmp) & 0xFF;
  6162. tmp2 = s[b];
  6163. s[a] = tmp2;
  6164. s[b] = tmp;
  6165. output[i] = data[i] ^ s[(tmp + tmp2) & 0xFF];
  6166. }
  6167. this.a = a;
  6168. this.b = b;
  6169. return output;
  6170. }
  6171. };
  6172. ARCFourCipher.prototype.decryptBlock = ARCFourCipher.prototype.encryptBlock;
  6173. return ARCFourCipher;
  6174. })();
  6175. var calculateMD5 = (function calculateMD5Closure() {
  6176. var r = new Uint8Array([
  6177. 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22,
  6178. 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20,
  6179. 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23,
  6180. 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21]);
  6181. var k = new Int32Array([
  6182. -680876936, -389564586, 606105819, -1044525330, -176418897, 1200080426,
  6183. -1473231341, -45705983, 1770035416, -1958414417, -42063, -1990404162,
  6184. 1804603682, -40341101, -1502002290, 1236535329, -165796510, -1069501632,
  6185. 643717713, -373897302, -701558691, 38016083, -660478335, -405537848,
  6186. 568446438, -1019803690, -187363961, 1163531501, -1444681467, -51403784,
  6187. 1735328473, -1926607734, -378558, -2022574463, 1839030562, -35309556,
  6188. -1530992060, 1272893353, -155497632, -1094730640, 681279174, -358537222,
  6189. -722521979, 76029189, -640364487, -421815835, 530742520, -995338651,
  6190. -198630844, 1126891415, -1416354905, -57434055, 1700485571, -1894986606,
  6191. -1051523, -2054922799, 1873313359, -30611744, -1560198380, 1309151649,
  6192. -145523070, -1120210379, 718787259, -343485551]);
  6193. function hash(data, offset, length) {
  6194. var h0 = 1732584193, h1 = -271733879, h2 = -1732584194, h3 = 271733878;
  6195. // pre-processing
  6196. var paddedLength = (length + 72) & ~63; // data + 9 extra bytes
  6197. var padded = new Uint8Array(paddedLength);
  6198. var i, j, n;
  6199. for (i = 0; i < length; ++i) {
  6200. padded[i] = data[offset++];
  6201. }
  6202. padded[i++] = 0x80;
  6203. n = paddedLength - 8;
  6204. while (i < n) {
  6205. padded[i++] = 0;
  6206. }
  6207. padded[i++] = (length << 3) & 0xFF;
  6208. padded[i++] = (length >> 5) & 0xFF;
  6209. padded[i++] = (length >> 13) & 0xFF;
  6210. padded[i++] = (length >> 21) & 0xFF;
  6211. padded[i++] = (length >>> 29) & 0xFF;
  6212. padded[i++] = 0;
  6213. padded[i++] = 0;
  6214. padded[i++] = 0;
  6215. var w = new Int32Array(16);
  6216. for (i = 0; i < paddedLength;) {
  6217. for (j = 0; j < 16; ++j, i += 4) {
  6218. w[j] = (padded[i] | (padded[i + 1] << 8) |
  6219. (padded[i + 2] << 16) | (padded[i + 3] << 24));
  6220. }
  6221. var a = h0, b = h1, c = h2, d = h3, f, g;
  6222. for (j = 0; j < 64; ++j) {
  6223. if (j < 16) {
  6224. f = (b & c) | ((~b) & d);
  6225. g = j;
  6226. } else if (j < 32) {
  6227. f = (d & b) | ((~d) & c);
  6228. g = (5 * j + 1) & 15;
  6229. } else if (j < 48) {
  6230. f = b ^ c ^ d;
  6231. g = (3 * j + 5) & 15;
  6232. } else {
  6233. f = c ^ (b | (~d));
  6234. g = (7 * j) & 15;
  6235. }
  6236. var tmp = d, rotateArg = (a + f + k[j] + w[g]) | 0, rotate = r[j];
  6237. d = c;
  6238. c = b;
  6239. b = (b + ((rotateArg << rotate) | (rotateArg >>> (32 - rotate)))) | 0;
  6240. a = tmp;
  6241. }
  6242. h0 = (h0 + a) | 0;
  6243. h1 = (h1 + b) | 0;
  6244. h2 = (h2 + c) | 0;
  6245. h3 = (h3 + d) | 0;
  6246. }
  6247. return new Uint8Array([
  6248. h0 & 0xFF, (h0 >> 8) & 0xFF, (h0 >> 16) & 0xFF, (h0 >>> 24) & 0xFF,
  6249. h1 & 0xFF, (h1 >> 8) & 0xFF, (h1 >> 16) & 0xFF, (h1 >>> 24) & 0xFF,
  6250. h2 & 0xFF, (h2 >> 8) & 0xFF, (h2 >> 16) & 0xFF, (h2 >>> 24) & 0xFF,
  6251. h3 & 0xFF, (h3 >> 8) & 0xFF, (h3 >> 16) & 0xFF, (h3 >>> 24) & 0xFF
  6252. ]);
  6253. }
  6254. return hash;
  6255. })();
  6256. var Word64 = (function Word64Closure() {
  6257. function Word64(highInteger, lowInteger) {
  6258. this.high = highInteger | 0;
  6259. this.low = lowInteger | 0;
  6260. }
  6261. Word64.prototype = {
  6262. and: function Word64_and(word) {
  6263. this.high &= word.high;
  6264. this.low &= word.low;
  6265. },
  6266. xor: function Word64_xor(word) {
  6267. this.high ^= word.high;
  6268. this.low ^= word.low;
  6269. },
  6270. or: function Word64_or(word) {
  6271. this.high |= word.high;
  6272. this.low |= word.low;
  6273. },
  6274. shiftRight: function Word64_shiftRight(places) {
  6275. if (places >= 32) {
  6276. this.low = (this.high >>> (places - 32)) | 0;
  6277. this.high = 0;
  6278. } else {
  6279. this.low = (this.low >>> places) | (this.high << (32 - places));
  6280. this.high = (this.high >>> places) | 0;
  6281. }
  6282. },
  6283. shiftLeft: function Word64_shiftLeft(places) {
  6284. if (places >= 32) {
  6285. this.high = this.low << (places - 32);
  6286. this.low = 0;
  6287. } else {
  6288. this.high = (this.high << places) | (this.low >>> (32 - places));
  6289. this.low = this.low << places;
  6290. }
  6291. },
  6292. rotateRight: function Word64_rotateRight(places) {
  6293. var low, high;
  6294. if (places & 32) {
  6295. high = this.low;
  6296. low = this.high;
  6297. } else {
  6298. low = this.low;
  6299. high = this.high;
  6300. }
  6301. places &= 31;
  6302. this.low = (low >>> places) | (high << (32 - places));
  6303. this.high = (high >>> places) | (low << (32 - places));
  6304. },
  6305. not: function Word64_not() {
  6306. this.high = ~this.high;
  6307. this.low = ~this.low;
  6308. },
  6309. add: function Word64_add(word) {
  6310. var lowAdd = (this.low >>> 0) + (word.low >>> 0);
  6311. var highAdd = (this.high >>> 0) + (word.high >>> 0);
  6312. if (lowAdd > 0xFFFFFFFF) {
  6313. highAdd += 1;
  6314. }
  6315. this.low = lowAdd | 0;
  6316. this.high = highAdd | 0;
  6317. },
  6318. copyTo: function Word64_copyTo(bytes, offset) {
  6319. bytes[offset] = (this.high >>> 24) & 0xFF;
  6320. bytes[offset + 1] = (this.high >> 16) & 0xFF;
  6321. bytes[offset + 2] = (this.high >> 8) & 0xFF;
  6322. bytes[offset + 3] = this.high & 0xFF;
  6323. bytes[offset + 4] = (this.low >>> 24) & 0xFF;
  6324. bytes[offset + 5] = (this.low >> 16) & 0xFF;
  6325. bytes[offset + 6] = (this.low >> 8) & 0xFF;
  6326. bytes[offset + 7] = this.low & 0xFF;
  6327. },
  6328. assign: function Word64_assign(word) {
  6329. this.high = word.high;
  6330. this.low = word.low;
  6331. }
  6332. };
  6333. return Word64;
  6334. })();
  6335. var calculateSHA256 = (function calculateSHA256Closure() {
  6336. function rotr(x, n) {
  6337. return (x >>> n) | (x << 32 - n);
  6338. }
  6339. function ch(x, y, z) {
  6340. return (x & y) ^ (~x & z);
  6341. }
  6342. function maj(x, y, z) {
  6343. return (x & y) ^ (x & z) ^ (y & z);
  6344. }
  6345. function sigma(x) {
  6346. return rotr(x, 2) ^ rotr(x, 13) ^ rotr(x, 22);
  6347. }
  6348. function sigmaPrime(x) {
  6349. return rotr(x, 6) ^ rotr(x, 11) ^ rotr(x, 25);
  6350. }
  6351. function littleSigma(x) {
  6352. return rotr(x, 7) ^ rotr(x, 18) ^ x >>> 3;
  6353. }
  6354. function littleSigmaPrime(x) {
  6355. return rotr(x, 17) ^ rotr(x, 19) ^ x >>> 10;
  6356. }
  6357. var k = [0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
  6358. 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
  6359. 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
  6360. 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
  6361. 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
  6362. 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
  6363. 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
  6364. 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
  6365. 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
  6366. 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
  6367. 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
  6368. 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
  6369. 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
  6370. 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
  6371. 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
  6372. 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2];
  6373. function hash(data, offset, length) {
  6374. // initial hash values
  6375. var h0 = 0x6a09e667, h1 = 0xbb67ae85, h2 = 0x3c6ef372,
  6376. h3 = 0xa54ff53a, h4 = 0x510e527f, h5 = 0x9b05688c,
  6377. h6 = 0x1f83d9ab, h7 = 0x5be0cd19;
  6378. // pre-processing
  6379. var paddedLength = Math.ceil((length + 9) / 64) * 64;
  6380. var padded = new Uint8Array(paddedLength);
  6381. var i, j, n;
  6382. for (i = 0; i < length; ++i) {
  6383. padded[i] = data[offset++];
  6384. }
  6385. padded[i++] = 0x80;
  6386. n = paddedLength - 8;
  6387. while (i < n) {
  6388. padded[i++] = 0;
  6389. }
  6390. padded[i++] = 0;
  6391. padded[i++] = 0;
  6392. padded[i++] = 0;
  6393. padded[i++] = (length >>> 29) & 0xFF;
  6394. padded[i++] = (length >> 21) & 0xFF;
  6395. padded[i++] = (length >> 13) & 0xFF;
  6396. padded[i++] = (length >> 5) & 0xFF;
  6397. padded[i++] = (length << 3) & 0xFF;
  6398. var w = new Uint32Array(64);
  6399. // for each 512 bit block
  6400. for (i = 0; i < paddedLength;) {
  6401. for (j = 0; j < 16; ++j) {
  6402. w[j] = (padded[i] << 24 | (padded[i + 1] << 16) |
  6403. (padded[i + 2] << 8) | (padded[i + 3]));
  6404. i += 4;
  6405. }
  6406. for (j = 16; j < 64; ++j) {
  6407. w[j] = littleSigmaPrime(w[j - 2]) + w[j - 7] +
  6408. littleSigma(w[j - 15]) + w[j - 16] | 0;
  6409. }
  6410. var a = h0, b = h1, c = h2, d = h3, e = h4,
  6411. f = h5, g = h6, h = h7, t1, t2;
  6412. for (j = 0; j < 64; ++j) {
  6413. t1 = h + sigmaPrime(e) + ch(e, f, g) + k[j] + w[j];
  6414. t2 = sigma(a) + maj(a, b, c);
  6415. h = g;
  6416. g = f;
  6417. f = e;
  6418. e = (d + t1) | 0;
  6419. d = c;
  6420. c = b;
  6421. b = a;
  6422. a = (t1 + t2) | 0;
  6423. }
  6424. h0 = (h0 + a) | 0;
  6425. h1 = (h1 + b) | 0;
  6426. h2 = (h2 + c) | 0;
  6427. h3 = (h3 + d) | 0;
  6428. h4 = (h4 + e) | 0;
  6429. h5 = (h5 + f) | 0;
  6430. h6 = (h6 + g) | 0;
  6431. h7 = (h7 + h) | 0;
  6432. }
  6433. return new Uint8Array([
  6434. (h0 >> 24) & 0xFF, (h0 >> 16) & 0xFF, (h0 >> 8) & 0xFF, (h0) & 0xFF,
  6435. (h1 >> 24) & 0xFF, (h1 >> 16) & 0xFF, (h1 >> 8) & 0xFF, (h1) & 0xFF,
  6436. (h2 >> 24) & 0xFF, (h2 >> 16) & 0xFF, (h2 >> 8) & 0xFF, (h2) & 0xFF,
  6437. (h3 >> 24) & 0xFF, (h3 >> 16) & 0xFF, (h3 >> 8) & 0xFF, (h3) & 0xFF,
  6438. (h4 >> 24) & 0xFF, (h4 >> 16) & 0xFF, (h4 >> 8) & 0xFF, (h4) & 0xFF,
  6439. (h5 >> 24) & 0xFF, (h5 >> 16) & 0xFF, (h5 >> 8) & 0xFF, (h5) & 0xFF,
  6440. (h6 >> 24) & 0xFF, (h6 >> 16) & 0xFF, (h6 >> 8) & 0xFF, (h6) & 0xFF,
  6441. (h7 >> 24) & 0xFF, (h7 >> 16) & 0xFF, (h7 >> 8) & 0xFF, (h7) & 0xFF
  6442. ]);
  6443. }
  6444. return hash;
  6445. })();
  6446. var calculateSHA512 = (function calculateSHA512Closure() {
  6447. function ch(result, x, y, z, tmp) {
  6448. result.assign(x);
  6449. result.and(y);
  6450. tmp.assign(x);
  6451. tmp.not();
  6452. tmp.and(z);
  6453. result.xor(tmp);
  6454. }
  6455. function maj(result, x, y, z, tmp) {
  6456. result.assign(x);
  6457. result.and(y);
  6458. tmp.assign(x);
  6459. tmp.and(z);
  6460. result.xor(tmp);
  6461. tmp.assign(y);
  6462. tmp.and(z);
  6463. result.xor(tmp);
  6464. }
  6465. function sigma(result, x, tmp) {
  6466. result.assign(x);
  6467. result.rotateRight(28);
  6468. tmp.assign(x);
  6469. tmp.rotateRight(34);
  6470. result.xor(tmp);
  6471. tmp.assign(x);
  6472. tmp.rotateRight(39);
  6473. result.xor(tmp);
  6474. }
  6475. function sigmaPrime(result, x, tmp) {
  6476. result.assign(x);
  6477. result.rotateRight(14);
  6478. tmp.assign(x);
  6479. tmp.rotateRight(18);
  6480. result.xor(tmp);
  6481. tmp.assign(x);
  6482. tmp.rotateRight(41);
  6483. result.xor(tmp);
  6484. }
  6485. function littleSigma(result, x, tmp) {
  6486. result.assign(x);
  6487. result.rotateRight(1);
  6488. tmp.assign(x);
  6489. tmp.rotateRight(8);
  6490. result.xor(tmp);
  6491. tmp.assign(x);
  6492. tmp.shiftRight(7);
  6493. result.xor(tmp);
  6494. }
  6495. function littleSigmaPrime(result, x, tmp) {
  6496. result.assign(x);
  6497. result.rotateRight(19);
  6498. tmp.assign(x);
  6499. tmp.rotateRight(61);
  6500. result.xor(tmp);
  6501. tmp.assign(x);
  6502. tmp.shiftRight(6);
  6503. result.xor(tmp);
  6504. }
  6505. var k = [
  6506. new Word64(0x428a2f98, 0xd728ae22), new Word64(0x71374491, 0x23ef65cd),
  6507. new Word64(0xb5c0fbcf, 0xec4d3b2f), new Word64(0xe9b5dba5, 0x8189dbbc),
  6508. new Word64(0x3956c25b, 0xf348b538), new Word64(0x59f111f1, 0xb605d019),
  6509. new Word64(0x923f82a4, 0xaf194f9b), new Word64(0xab1c5ed5, 0xda6d8118),
  6510. new Word64(0xd807aa98, 0xa3030242), new Word64(0x12835b01, 0x45706fbe),
  6511. new Word64(0x243185be, 0x4ee4b28c), new Word64(0x550c7dc3, 0xd5ffb4e2),
  6512. new Word64(0x72be5d74, 0xf27b896f), new Word64(0x80deb1fe, 0x3b1696b1),
  6513. new Word64(0x9bdc06a7, 0x25c71235), new Word64(0xc19bf174, 0xcf692694),
  6514. new Word64(0xe49b69c1, 0x9ef14ad2), new Word64(0xefbe4786, 0x384f25e3),
  6515. new Word64(0x0fc19dc6, 0x8b8cd5b5), new Word64(0x240ca1cc, 0x77ac9c65),
  6516. new Word64(0x2de92c6f, 0x592b0275), new Word64(0x4a7484aa, 0x6ea6e483),
  6517. new Word64(0x5cb0a9dc, 0xbd41fbd4), new Word64(0x76f988da, 0x831153b5),
  6518. new Word64(0x983e5152, 0xee66dfab), new Word64(0xa831c66d, 0x2db43210),
  6519. new Word64(0xb00327c8, 0x98fb213f), new Word64(0xbf597fc7, 0xbeef0ee4),
  6520. new Word64(0xc6e00bf3, 0x3da88fc2), new Word64(0xd5a79147, 0x930aa725),
  6521. new Word64(0x06ca6351, 0xe003826f), new Word64(0x14292967, 0x0a0e6e70),
  6522. new Word64(0x27b70a85, 0x46d22ffc), new Word64(0x2e1b2138, 0x5c26c926),
  6523. new Word64(0x4d2c6dfc, 0x5ac42aed), new Word64(0x53380d13, 0x9d95b3df),
  6524. new Word64(0x650a7354, 0x8baf63de), new Word64(0x766a0abb, 0x3c77b2a8),
  6525. new Word64(0x81c2c92e, 0x47edaee6), new Word64(0x92722c85, 0x1482353b),
  6526. new Word64(0xa2bfe8a1, 0x4cf10364), new Word64(0xa81a664b, 0xbc423001),
  6527. new Word64(0xc24b8b70, 0xd0f89791), new Word64(0xc76c51a3, 0x0654be30),
  6528. new Word64(0xd192e819, 0xd6ef5218), new Word64(0xd6990624, 0x5565a910),
  6529. new Word64(0xf40e3585, 0x5771202a), new Word64(0x106aa070, 0x32bbd1b8),
  6530. new Word64(0x19a4c116, 0xb8d2d0c8), new Word64(0x1e376c08, 0x5141ab53),
  6531. new Word64(0x2748774c, 0xdf8eeb99), new Word64(0x34b0bcb5, 0xe19b48a8),
  6532. new Word64(0x391c0cb3, 0xc5c95a63), new Word64(0x4ed8aa4a, 0xe3418acb),
  6533. new Word64(0x5b9cca4f, 0x7763e373), new Word64(0x682e6ff3, 0xd6b2b8a3),
  6534. new Word64(0x748f82ee, 0x5defb2fc), new Word64(0x78a5636f, 0x43172f60),
  6535. new Word64(0x84c87814, 0xa1f0ab72), new Word64(0x8cc70208, 0x1a6439ec),
  6536. new Word64(0x90befffa, 0x23631e28), new Word64(0xa4506ceb, 0xde82bde9),
  6537. new Word64(0xbef9a3f7, 0xb2c67915), new Word64(0xc67178f2, 0xe372532b),
  6538. new Word64(0xca273ece, 0xea26619c), new Word64(0xd186b8c7, 0x21c0c207),
  6539. new Word64(0xeada7dd6, 0xcde0eb1e), new Word64(0xf57d4f7f, 0xee6ed178),
  6540. new Word64(0x06f067aa, 0x72176fba), new Word64(0x0a637dc5, 0xa2c898a6),
  6541. new Word64(0x113f9804, 0xbef90dae), new Word64(0x1b710b35, 0x131c471b),
  6542. new Word64(0x28db77f5, 0x23047d84), new Word64(0x32caab7b, 0x40c72493),
  6543. new Word64(0x3c9ebe0a, 0x15c9bebc), new Word64(0x431d67c4, 0x9c100d4c),
  6544. new Word64(0x4cc5d4be, 0xcb3e42b6), new Word64(0x597f299c, 0xfc657e2a),
  6545. new Word64(0x5fcb6fab, 0x3ad6faec), new Word64(0x6c44198c, 0x4a475817)];
  6546. function hash(data, offset, length, mode384) {
  6547. mode384 = !!mode384;
  6548. // initial hash values
  6549. var h0, h1, h2, h3, h4, h5, h6, h7;
  6550. if (!mode384) {
  6551. h0 = new Word64(0x6a09e667, 0xf3bcc908);
  6552. h1 = new Word64(0xbb67ae85, 0x84caa73b);
  6553. h2 = new Word64(0x3c6ef372, 0xfe94f82b);
  6554. h3 = new Word64(0xa54ff53a, 0x5f1d36f1);
  6555. h4 = new Word64(0x510e527f, 0xade682d1);
  6556. h5 = new Word64(0x9b05688c, 0x2b3e6c1f);
  6557. h6 = new Word64(0x1f83d9ab, 0xfb41bd6b);
  6558. h7 = new Word64(0x5be0cd19, 0x137e2179);
  6559. }
  6560. else {
  6561. // SHA384 is exactly the same
  6562. // except with different starting values and a trimmed result
  6563. h0 = new Word64(0xcbbb9d5d, 0xc1059ed8);
  6564. h1 = new Word64(0x629a292a, 0x367cd507);
  6565. h2 = new Word64(0x9159015a, 0x3070dd17);
  6566. h3 = new Word64(0x152fecd8, 0xf70e5939);
  6567. h4 = new Word64(0x67332667, 0xffc00b31);
  6568. h5 = new Word64(0x8eb44a87, 0x68581511);
  6569. h6 = new Word64(0xdb0c2e0d, 0x64f98fa7);
  6570. h7 = new Word64(0x47b5481d, 0xbefa4fa4);
  6571. }
  6572. // pre-processing
  6573. var paddedLength = Math.ceil((length + 17) / 128) * 128;
  6574. var padded = new Uint8Array(paddedLength);
  6575. var i, j, n;
  6576. for (i = 0; i < length; ++i) {
  6577. padded[i] = data[offset++];
  6578. }
  6579. padded[i++] = 0x80;
  6580. n = paddedLength - 16;
  6581. while (i < n) {
  6582. padded[i++] = 0;
  6583. }
  6584. padded[i++] = 0;
  6585. padded[i++] = 0;
  6586. padded[i++] = 0;
  6587. padded[i++] = 0;
  6588. padded[i++] = 0;
  6589. padded[i++] = 0;
  6590. padded[i++] = 0;
  6591. padded[i++] = 0;
  6592. padded[i++] = 0;
  6593. padded[i++] = 0;
  6594. padded[i++] = 0;
  6595. padded[i++] = (length >>> 29) & 0xFF;
  6596. padded[i++] = (length >> 21) & 0xFF;
  6597. padded[i++] = (length >> 13) & 0xFF;
  6598. padded[i++] = (length >> 5) & 0xFF;
  6599. padded[i++] = (length << 3) & 0xFF;
  6600. var w = new Array(80);
  6601. for (i = 0; i < 80; i++) {
  6602. w[i] = new Word64(0, 0);
  6603. }
  6604. var a = new Word64(0, 0), b = new Word64(0, 0), c = new Word64(0, 0);
  6605. var d = new Word64(0, 0), e = new Word64(0, 0), f = new Word64(0, 0);
  6606. var g = new Word64(0, 0), h = new Word64(0, 0);
  6607. var t1 = new Word64(0, 0), t2 = new Word64(0, 0);
  6608. var tmp1 = new Word64(0, 0), tmp2 = new Word64(0, 0), tmp3;
  6609. // for each 1024 bit block
  6610. for (i = 0; i < paddedLength;) {
  6611. for (j = 0; j < 16; ++j) {
  6612. w[j].high = (padded[i] << 24) | (padded[i + 1] << 16) |
  6613. (padded[i + 2] << 8) | (padded[i + 3]);
  6614. w[j].low = (padded[i + 4]) << 24 | (padded[i + 5]) << 16 |
  6615. (padded[i + 6]) << 8 | (padded[i + 7]);
  6616. i += 8;
  6617. }
  6618. for (j = 16; j < 80; ++j) {
  6619. tmp3 = w[j];
  6620. littleSigmaPrime(tmp3, w[j - 2], tmp2);
  6621. tmp3.add(w[j - 7]);
  6622. littleSigma(tmp1, w[j - 15], tmp2);
  6623. tmp3.add(tmp1);
  6624. tmp3.add(w[j - 16]);
  6625. }
  6626. a.assign(h0); b.assign(h1); c.assign(h2); d.assign(h3);
  6627. e.assign(h4); f.assign(h5); g.assign(h6); h.assign(h7);
  6628. for (j = 0; j < 80; ++j) {
  6629. t1.assign(h);
  6630. sigmaPrime(tmp1, e, tmp2);
  6631. t1.add(tmp1);
  6632. ch(tmp1, e, f, g, tmp2);
  6633. t1.add(tmp1);
  6634. t1.add(k[j]);
  6635. t1.add(w[j]);
  6636. sigma(t2, a, tmp2);
  6637. maj(tmp1, a, b, c, tmp2);
  6638. t2.add(tmp1);
  6639. tmp3 = h;
  6640. h = g;
  6641. g = f;
  6642. f = e;
  6643. d.add(t1);
  6644. e = d;
  6645. d = c;
  6646. c = b;
  6647. b = a;
  6648. tmp3.assign(t1);
  6649. tmp3.add(t2);
  6650. a = tmp3;
  6651. }
  6652. h0.add(a);
  6653. h1.add(b);
  6654. h2.add(c);
  6655. h3.add(d);
  6656. h4.add(e);
  6657. h5.add(f);
  6658. h6.add(g);
  6659. h7.add(h);
  6660. }
  6661. var result;
  6662. if (!mode384) {
  6663. result = new Uint8Array(64);
  6664. h0.copyTo(result,0);
  6665. h1.copyTo(result,8);
  6666. h2.copyTo(result,16);
  6667. h3.copyTo(result,24);
  6668. h4.copyTo(result,32);
  6669. h5.copyTo(result,40);
  6670. h6.copyTo(result,48);
  6671. h7.copyTo(result,56);
  6672. }
  6673. else {
  6674. result = new Uint8Array(48);
  6675. h0.copyTo(result,0);
  6676. h1.copyTo(result,8);
  6677. h2.copyTo(result,16);
  6678. h3.copyTo(result,24);
  6679. h4.copyTo(result,32);
  6680. h5.copyTo(result,40);
  6681. }
  6682. return result;
  6683. }
  6684. return hash;
  6685. })();
  6686. var calculateSHA384 = (function calculateSHA384Closure() {
  6687. function hash(data, offset, length) {
  6688. return calculateSHA512(data, offset, length, true);
  6689. }
  6690. return hash;
  6691. })();
  6692. var NullCipher = (function NullCipherClosure() {
  6693. function NullCipher() {
  6694. }
  6695. NullCipher.prototype = {
  6696. decryptBlock: function NullCipher_decryptBlock(data) {
  6697. return data;
  6698. }
  6699. };
  6700. return NullCipher;
  6701. })();
  6702. var AES128Cipher = (function AES128CipherClosure() {
  6703. var rcon = new Uint8Array([
  6704. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  6705. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  6706. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  6707. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  6708. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  6709. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  6710. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  6711. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  6712. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  6713. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  6714. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  6715. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  6716. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  6717. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  6718. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  6719. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  6720. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  6721. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  6722. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  6723. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  6724. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  6725. 0x74, 0xe8, 0xcb, 0x8d]);
  6726. var s = new Uint8Array([
  6727. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  6728. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  6729. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  6730. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  6731. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  6732. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  6733. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  6734. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  6735. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  6736. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  6737. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  6738. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  6739. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  6740. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  6741. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  6742. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  6743. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  6744. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  6745. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  6746. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  6747. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  6748. 0xb0, 0x54, 0xbb, 0x16]);
  6749. var inv_s = new Uint8Array([
  6750. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  6751. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  6752. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  6753. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  6754. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  6755. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  6756. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  6757. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  6758. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  6759. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  6760. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  6761. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  6762. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  6763. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  6764. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  6765. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  6766. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  6767. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  6768. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  6769. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  6770. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  6771. 0x55, 0x21, 0x0c, 0x7d]);
  6772. var mixCol = new Uint8Array(256);
  6773. for (var i = 0; i < 256; i++) {
  6774. if (i < 128) {
  6775. mixCol[i] = i << 1;
  6776. } else {
  6777. mixCol[i] = (i << 1) ^ 0x1b;
  6778. }
  6779. }
  6780. var mix = new Uint32Array([
  6781. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  6782. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  6783. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  6784. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  6785. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  6786. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  6787. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  6788. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  6789. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  6790. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  6791. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  6792. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  6793. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  6794. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  6795. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  6796. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  6797. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  6798. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  6799. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  6800. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  6801. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  6802. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  6803. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  6804. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  6805. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  6806. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  6807. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  6808. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  6809. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  6810. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  6811. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  6812. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  6813. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  6814. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  6815. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  6816. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  6817. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  6818. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  6819. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  6820. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  6821. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  6822. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  6823. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  6824. function expandKey128(cipherKey) {
  6825. var b = 176, result = new Uint8Array(b);
  6826. result.set(cipherKey);
  6827. for (var j = 16, i = 1; j < b; ++i) {
  6828. // RotWord
  6829. var t1 = result[j - 3], t2 = result[j - 2],
  6830. t3 = result[j - 1], t4 = result[j - 4];
  6831. // SubWord
  6832. t1 = s[t1];
  6833. t2 = s[t2];
  6834. t3 = s[t3];
  6835. t4 = s[t4];
  6836. // Rcon
  6837. t1 = t1 ^ rcon[i];
  6838. for (var n = 0; n < 4; ++n) {
  6839. result[j] = (t1 ^= result[j - 16]);
  6840. j++;
  6841. result[j] = (t2 ^= result[j - 16]);
  6842. j++;
  6843. result[j] = (t3 ^= result[j - 16]);
  6844. j++;
  6845. result[j] = (t4 ^= result[j - 16]);
  6846. j++;
  6847. }
  6848. }
  6849. return result;
  6850. }
  6851. function decrypt128(input, key) {
  6852. var state = new Uint8Array(16);
  6853. state.set(input);
  6854. var i, j, k;
  6855. var t, u, v;
  6856. // AddRoundKey
  6857. for (j = 0, k = 160; j < 16; ++j, ++k) {
  6858. state[j] ^= key[k];
  6859. }
  6860. for (i = 9; i >= 1; --i) {
  6861. // InvShiftRows
  6862. t = state[13];
  6863. state[13] = state[9];
  6864. state[9] = state[5];
  6865. state[5] = state[1];
  6866. state[1] = t;
  6867. t = state[14];
  6868. u = state[10];
  6869. state[14] = state[6];
  6870. state[10] = state[2];
  6871. state[6] = t;
  6872. state[2] = u;
  6873. t = state[15];
  6874. u = state[11];
  6875. v = state[7];
  6876. state[15] = state[3];
  6877. state[11] = t;
  6878. state[7] = u;
  6879. state[3] = v;
  6880. // InvSubBytes
  6881. for (j = 0; j < 16; ++j) {
  6882. state[j] = inv_s[state[j]];
  6883. }
  6884. // AddRoundKey
  6885. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  6886. state[j] ^= key[k];
  6887. }
  6888. // InvMixColumns
  6889. for (j = 0; j < 16; j += 4) {
  6890. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  6891. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  6892. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  6893. (s3 >>> 24) ^ (s3 << 8));
  6894. state[j] = (t >>> 24) & 0xFF;
  6895. state[j + 1] = (t >> 16) & 0xFF;
  6896. state[j + 2] = (t >> 8) & 0xFF;
  6897. state[j + 3] = t & 0xFF;
  6898. }
  6899. }
  6900. // InvShiftRows
  6901. t = state[13];
  6902. state[13] = state[9];
  6903. state[9] = state[5];
  6904. state[5] = state[1];
  6905. state[1] = t;
  6906. t = state[14];
  6907. u = state[10];
  6908. state[14] = state[6];
  6909. state[10] = state[2];
  6910. state[6] = t;
  6911. state[2] = u;
  6912. t = state[15];
  6913. u = state[11];
  6914. v = state[7];
  6915. state[15] = state[3];
  6916. state[11] = t;
  6917. state[7] = u;
  6918. state[3] = v;
  6919. for (j = 0; j < 16; ++j) {
  6920. // InvSubBytes
  6921. state[j] = inv_s[state[j]];
  6922. // AddRoundKey
  6923. state[j] ^= key[j];
  6924. }
  6925. return state;
  6926. }
  6927. function encrypt128(input, key) {
  6928. var t, u, v, k;
  6929. var state = new Uint8Array(16);
  6930. state.set(input);
  6931. for (j = 0; j < 16; ++j) {
  6932. // AddRoundKey
  6933. state[j] ^= key[j];
  6934. }
  6935. for (i = 1; i < 10; i++) {
  6936. //SubBytes
  6937. for (j = 0; j < 16; ++j) {
  6938. state[j] = s[state[j]];
  6939. }
  6940. //ShiftRows
  6941. v = state[1];
  6942. state[1] = state[5];
  6943. state[5] = state[9];
  6944. state[9] = state[13];
  6945. state[13] = v;
  6946. v = state[2];
  6947. u = state[6];
  6948. state[2] = state[10];
  6949. state[6] = state[14];
  6950. state[10] = v;
  6951. state[14] = u;
  6952. v = state[3];
  6953. u = state[7];
  6954. t = state[11];
  6955. state[3] = state[15];
  6956. state[7] = v;
  6957. state[11] = u;
  6958. state[15] = t;
  6959. //MixColumns
  6960. for (var j = 0; j < 16; j += 4) {
  6961. var s0 = state[j + 0], s1 = state[j + 1];
  6962. var s2 = state[j + 2], s3 = state[j + 3];
  6963. t = s0 ^ s1 ^ s2 ^ s3;
  6964. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  6965. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  6966. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  6967. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  6968. }
  6969. //AddRoundKey
  6970. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  6971. state[j] ^= key[k];
  6972. }
  6973. }
  6974. //SubBytes
  6975. for (j = 0; j < 16; ++j) {
  6976. state[j] = s[state[j]];
  6977. }
  6978. //ShiftRows
  6979. v = state[1];
  6980. state[1] = state[5];
  6981. state[5] = state[9];
  6982. state[9] = state[13];
  6983. state[13] = v;
  6984. v = state[2];
  6985. u = state[6];
  6986. state[2] = state[10];
  6987. state[6] = state[14];
  6988. state[10] = v;
  6989. state[14] = u;
  6990. v = state[3];
  6991. u = state[7];
  6992. t = state[11];
  6993. state[3] = state[15];
  6994. state[7] = v;
  6995. state[11] = u;
  6996. state[15] = t;
  6997. //AddRoundKey
  6998. for (j = 0, k = 160; j < 16; ++j, ++k) {
  6999. state[j] ^= key[k];
  7000. }
  7001. return state;
  7002. }
  7003. function AES128Cipher(key) {
  7004. this.key = expandKey128(key);
  7005. this.buffer = new Uint8Array(16);
  7006. this.bufferPosition = 0;
  7007. }
  7008. function decryptBlock2(data, finalize) {
  7009. var i, j, ii, sourceLength = data.length,
  7010. buffer = this.buffer, bufferLength = this.bufferPosition,
  7011. result = [], iv = this.iv;
  7012. for (i = 0; i < sourceLength; ++i) {
  7013. buffer[bufferLength] = data[i];
  7014. ++bufferLength;
  7015. if (bufferLength < 16) {
  7016. continue;
  7017. }
  7018. // buffer is full, decrypting
  7019. var plain = decrypt128(buffer, this.key);
  7020. // xor-ing the IV vector to get plain text
  7021. for (j = 0; j < 16; ++j) {
  7022. plain[j] ^= iv[j];
  7023. }
  7024. iv = buffer;
  7025. result.push(plain);
  7026. buffer = new Uint8Array(16);
  7027. bufferLength = 0;
  7028. }
  7029. // saving incomplete buffer
  7030. this.buffer = buffer;
  7031. this.bufferLength = bufferLength;
  7032. this.iv = iv;
  7033. if (result.length === 0) {
  7034. return new Uint8Array([]);
  7035. }
  7036. // combining plain text blocks into one
  7037. var outputLength = 16 * result.length;
  7038. if (finalize) {
  7039. // undo a padding that is described in RFC 2898
  7040. var lastBlock = result[result.length - 1];
  7041. outputLength -= lastBlock[15];
  7042. result[result.length - 1] = lastBlock.subarray(0, 16 - lastBlock[15]);
  7043. }
  7044. var output = new Uint8Array(outputLength);
  7045. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  7046. output.set(result[i], j);
  7047. }
  7048. return output;
  7049. }
  7050. AES128Cipher.prototype = {
  7051. decryptBlock: function AES128Cipher_decryptBlock(data, finalize) {
  7052. var i, sourceLength = data.length;
  7053. var buffer = this.buffer, bufferLength = this.bufferPosition;
  7054. // waiting for IV values -- they are at the start of the stream
  7055. for (i = 0; bufferLength < 16 && i < sourceLength; ++i, ++bufferLength) {
  7056. buffer[bufferLength] = data[i];
  7057. }
  7058. if (bufferLength < 16) {
  7059. // need more data
  7060. this.bufferLength = bufferLength;
  7061. return new Uint8Array([]);
  7062. }
  7063. this.iv = buffer;
  7064. this.buffer = new Uint8Array(16);
  7065. this.bufferLength = 0;
  7066. // starting decryption
  7067. this.decryptBlock = decryptBlock2;
  7068. return this.decryptBlock(data.subarray(16), finalize);
  7069. },
  7070. encrypt: function AES128Cipher_encrypt(data, iv) {
  7071. var i, j, ii, sourceLength = data.length,
  7072. buffer = this.buffer, bufferLength = this.bufferPosition,
  7073. result = [];
  7074. if (!iv) {
  7075. iv = new Uint8Array(16);
  7076. }
  7077. for (i = 0; i < sourceLength; ++i) {
  7078. buffer[bufferLength] = data[i];
  7079. ++bufferLength;
  7080. if (bufferLength < 16) {
  7081. continue;
  7082. }
  7083. for (j = 0; j < 16; ++j) {
  7084. buffer[j] ^= iv[j];
  7085. }
  7086. // buffer is full, encrypting
  7087. var cipher = encrypt128(buffer, this.key);
  7088. iv = cipher;
  7089. result.push(cipher);
  7090. buffer = new Uint8Array(16);
  7091. bufferLength = 0;
  7092. }
  7093. // saving incomplete buffer
  7094. this.buffer = buffer;
  7095. this.bufferLength = bufferLength;
  7096. this.iv = iv;
  7097. if (result.length === 0) {
  7098. return new Uint8Array([]);
  7099. }
  7100. // combining plain text blocks into one
  7101. var outputLength = 16 * result.length;
  7102. var output = new Uint8Array(outputLength);
  7103. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  7104. output.set(result[i], j);
  7105. }
  7106. return output;
  7107. }
  7108. };
  7109. return AES128Cipher;
  7110. })();
  7111. var AES256Cipher = (function AES256CipherClosure() {
  7112. var rcon = new Uint8Array([
  7113. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  7114. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  7115. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  7116. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  7117. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  7118. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  7119. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  7120. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  7121. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  7122. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  7123. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  7124. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  7125. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  7126. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  7127. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  7128. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  7129. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  7130. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  7131. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  7132. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  7133. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  7134. 0x74, 0xe8, 0xcb, 0x8d]);
  7135. var s = new Uint8Array([
  7136. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  7137. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  7138. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  7139. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  7140. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  7141. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  7142. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  7143. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  7144. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  7145. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  7146. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  7147. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  7148. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  7149. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  7150. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  7151. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  7152. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  7153. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  7154. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  7155. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  7156. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  7157. 0xb0, 0x54, 0xbb, 0x16]);
  7158. var inv_s = new Uint8Array([
  7159. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  7160. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  7161. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  7162. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  7163. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  7164. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  7165. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  7166. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  7167. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  7168. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  7169. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  7170. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  7171. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  7172. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  7173. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  7174. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  7175. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  7176. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  7177. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  7178. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  7179. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  7180. 0x55, 0x21, 0x0c, 0x7d]);
  7181. var mixCol = new Uint8Array(256);
  7182. for (var i = 0; i < 256; i++) {
  7183. if (i < 128) {
  7184. mixCol[i] = i << 1;
  7185. } else {
  7186. mixCol[i] = (i << 1) ^ 0x1b;
  7187. }
  7188. }
  7189. var mix = new Uint32Array([
  7190. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  7191. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  7192. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  7193. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  7194. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  7195. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  7196. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  7197. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  7198. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  7199. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  7200. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  7201. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  7202. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  7203. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  7204. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  7205. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  7206. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  7207. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  7208. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  7209. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  7210. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  7211. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  7212. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  7213. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  7214. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  7215. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  7216. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  7217. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  7218. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  7219. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  7220. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  7221. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  7222. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  7223. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  7224. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  7225. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  7226. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  7227. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  7228. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  7229. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  7230. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  7231. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  7232. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  7233. function expandKey256(cipherKey) {
  7234. var b = 240, result = new Uint8Array(b);
  7235. var r = 1;
  7236. result.set(cipherKey);
  7237. for (var j = 32, i = 1; j < b; ++i) {
  7238. if (j % 32 === 16) {
  7239. t1 = s[t1];
  7240. t2 = s[t2];
  7241. t3 = s[t3];
  7242. t4 = s[t4];
  7243. } else if (j % 32 === 0) {
  7244. // RotWord
  7245. var t1 = result[j - 3], t2 = result[j - 2],
  7246. t3 = result[j - 1], t4 = result[j - 4];
  7247. // SubWord
  7248. t1 = s[t1];
  7249. t2 = s[t2];
  7250. t3 = s[t3];
  7251. t4 = s[t4];
  7252. // Rcon
  7253. t1 = t1 ^ r;
  7254. if ((r <<= 1) >= 256) {
  7255. r = (r ^ 0x1b) & 0xFF;
  7256. }
  7257. }
  7258. for (var n = 0; n < 4; ++n) {
  7259. result[j] = (t1 ^= result[j - 32]);
  7260. j++;
  7261. result[j] = (t2 ^= result[j - 32]);
  7262. j++;
  7263. result[j] = (t3 ^= result[j - 32]);
  7264. j++;
  7265. result[j] = (t4 ^= result[j - 32]);
  7266. j++;
  7267. }
  7268. }
  7269. return result;
  7270. }
  7271. function decrypt256(input, key) {
  7272. var state = new Uint8Array(16);
  7273. state.set(input);
  7274. var i, j, k;
  7275. var t, u, v;
  7276. // AddRoundKey
  7277. for (j = 0, k = 224; j < 16; ++j, ++k) {
  7278. state[j] ^= key[k];
  7279. }
  7280. for (i = 13; i >= 1; --i) {
  7281. // InvShiftRows
  7282. t = state[13];
  7283. state[13] = state[9];
  7284. state[9] = state[5];
  7285. state[5] = state[1];
  7286. state[1] = t;
  7287. t = state[14];
  7288. u = state[10];
  7289. state[14] = state[6];
  7290. state[10] = state[2];
  7291. state[6] = t;
  7292. state[2] = u;
  7293. t = state[15];
  7294. u = state[11];
  7295. v = state[7];
  7296. state[15] = state[3];
  7297. state[11] = t;
  7298. state[7] = u;
  7299. state[3] = v;
  7300. // InvSubBytes
  7301. for (j = 0; j < 16; ++j) {
  7302. state[j] = inv_s[state[j]];
  7303. }
  7304. // AddRoundKey
  7305. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  7306. state[j] ^= key[k];
  7307. }
  7308. // InvMixColumns
  7309. for (j = 0; j < 16; j += 4) {
  7310. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  7311. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  7312. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  7313. (s3 >>> 24) ^ (s3 << 8));
  7314. state[j] = (t >>> 24) & 0xFF;
  7315. state[j + 1] = (t >> 16) & 0xFF;
  7316. state[j + 2] = (t >> 8) & 0xFF;
  7317. state[j + 3] = t & 0xFF;
  7318. }
  7319. }
  7320. // InvShiftRows
  7321. t = state[13];
  7322. state[13] = state[9];
  7323. state[9] = state[5];
  7324. state[5] = state[1];
  7325. state[1] = t;
  7326. t = state[14];
  7327. u = state[10];
  7328. state[14] = state[6];
  7329. state[10] = state[2];
  7330. state[6] = t;
  7331. state[2] = u;
  7332. t = state[15];
  7333. u = state[11];
  7334. v = state[7];
  7335. state[15] = state[3];
  7336. state[11] = t;
  7337. state[7] = u;
  7338. state[3] = v;
  7339. for (j = 0; j < 16; ++j) {
  7340. // InvSubBytes
  7341. state[j] = inv_s[state[j]];
  7342. // AddRoundKey
  7343. state[j] ^= key[j];
  7344. }
  7345. return state;
  7346. }
  7347. function encrypt256(input, key) {
  7348. var t, u, v, k;
  7349. var state = new Uint8Array(16);
  7350. state.set(input);
  7351. for (j = 0; j < 16; ++j) {
  7352. // AddRoundKey
  7353. state[j] ^= key[j];
  7354. }
  7355. for (i = 1; i < 14; i++) {
  7356. //SubBytes
  7357. for (j = 0; j < 16; ++j) {
  7358. state[j] = s[state[j]];
  7359. }
  7360. //ShiftRows
  7361. v = state[1];
  7362. state[1] = state[5];
  7363. state[5] = state[9];
  7364. state[9] = state[13];
  7365. state[13] = v;
  7366. v = state[2];
  7367. u = state[6];
  7368. state[2] = state[10];
  7369. state[6] = state[14];
  7370. state[10] = v;
  7371. state[14] = u;
  7372. v = state[3];
  7373. u = state[7];
  7374. t = state[11];
  7375. state[3] = state[15];
  7376. state[7] = v;
  7377. state[11] = u;
  7378. state[15] = t;
  7379. //MixColumns
  7380. for (var j = 0; j < 16; j += 4) {
  7381. var s0 = state[j + 0], s1 = state[j + 1];
  7382. var s2 = state[j + 2], s3 = state[j + 3];
  7383. t = s0 ^ s1 ^ s2 ^ s3;
  7384. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  7385. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  7386. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  7387. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  7388. }
  7389. //AddRoundKey
  7390. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  7391. state[j] ^= key[k];
  7392. }
  7393. }
  7394. //SubBytes
  7395. for (j = 0; j < 16; ++j) {
  7396. state[j] = s[state[j]];
  7397. }
  7398. //ShiftRows
  7399. v = state[1];
  7400. state[1] = state[5];
  7401. state[5] = state[9];
  7402. state[9] = state[13];
  7403. state[13] = v;
  7404. v = state[2];
  7405. u = state[6];
  7406. state[2] = state[10];
  7407. state[6] = state[14];
  7408. state[10] = v;
  7409. state[14] = u;
  7410. v = state[3];
  7411. u = state[7];
  7412. t = state[11];
  7413. state[3] = state[15];
  7414. state[7] = v;
  7415. state[11] = u;
  7416. state[15] = t;
  7417. //AddRoundKey
  7418. for (j = 0, k = 224; j < 16; ++j, ++k) {
  7419. state[j] ^= key[k];
  7420. }
  7421. return state;
  7422. }
  7423. function AES256Cipher(key) {
  7424. this.key = expandKey256(key);
  7425. this.buffer = new Uint8Array(16);
  7426. this.bufferPosition = 0;
  7427. }
  7428. function decryptBlock2(data, finalize) {
  7429. var i, j, ii, sourceLength = data.length,
  7430. buffer = this.buffer, bufferLength = this.bufferPosition,
  7431. result = [], iv = this.iv;
  7432. for (i = 0; i < sourceLength; ++i) {
  7433. buffer[bufferLength] = data[i];
  7434. ++bufferLength;
  7435. if (bufferLength < 16) {
  7436. continue;
  7437. }
  7438. // buffer is full, encrypting
  7439. var plain = decrypt256(buffer, this.key);
  7440. // xor-ing the IV vector to get plain text
  7441. for (j = 0; j < 16; ++j) {
  7442. plain[j] ^= iv[j];
  7443. }
  7444. iv = buffer;
  7445. result.push(plain);
  7446. buffer = new Uint8Array(16);
  7447. bufferLength = 0;
  7448. }
  7449. // saving incomplete buffer
  7450. this.buffer = buffer;
  7451. this.bufferLength = bufferLength;
  7452. this.iv = iv;
  7453. if (result.length === 0) {
  7454. return new Uint8Array([]);
  7455. }
  7456. // combining plain text blocks into one
  7457. var outputLength = 16 * result.length;
  7458. if (finalize) {
  7459. // undo a padding that is described in RFC 2898
  7460. var lastBlock = result[result.length - 1];
  7461. outputLength -= lastBlock[15];
  7462. result[result.length - 1] = lastBlock.subarray(0, 16 - lastBlock[15]);
  7463. }
  7464. var output = new Uint8Array(outputLength);
  7465. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  7466. output.set(result[i], j);
  7467. }
  7468. return output;
  7469. }
  7470. AES256Cipher.prototype = {
  7471. decryptBlock: function AES256Cipher_decryptBlock(data, finalize, iv) {
  7472. var i, sourceLength = data.length;
  7473. var buffer = this.buffer, bufferLength = this.bufferPosition;
  7474. // if not supplied an IV wait for IV values
  7475. // they are at the start of the stream
  7476. if (iv) {
  7477. this.iv = iv;
  7478. } else {
  7479. for (i = 0; bufferLength < 16 &&
  7480. i < sourceLength; ++i, ++bufferLength) {
  7481. buffer[bufferLength] = data[i];
  7482. }
  7483. if (bufferLength < 16) {
  7484. //need more data
  7485. this.bufferLength = bufferLength;
  7486. return new Uint8Array([]);
  7487. }
  7488. this.iv = buffer;
  7489. data = data.subarray(16);
  7490. }
  7491. this.buffer = new Uint8Array(16);
  7492. this.bufferLength = 0;
  7493. // starting decryption
  7494. this.decryptBlock = decryptBlock2;
  7495. return this.decryptBlock(data, finalize);
  7496. },
  7497. encrypt: function AES256Cipher_encrypt(data, iv) {
  7498. var i, j, ii, sourceLength = data.length,
  7499. buffer = this.buffer, bufferLength = this.bufferPosition,
  7500. result = [];
  7501. if (!iv) {
  7502. iv = new Uint8Array(16);
  7503. }
  7504. for (i = 0; i < sourceLength; ++i) {
  7505. buffer[bufferLength] = data[i];
  7506. ++bufferLength;
  7507. if (bufferLength < 16) {
  7508. continue;
  7509. }
  7510. for (j = 0; j < 16; ++j) {
  7511. buffer[j] ^= iv[j];
  7512. }
  7513. // buffer is full, encrypting
  7514. var cipher = encrypt256(buffer, this.key);
  7515. this.iv = cipher;
  7516. result.push(cipher);
  7517. buffer = new Uint8Array(16);
  7518. bufferLength = 0;
  7519. }
  7520. // saving incomplete buffer
  7521. this.buffer = buffer;
  7522. this.bufferLength = bufferLength;
  7523. this.iv = iv;
  7524. if (result.length === 0) {
  7525. return new Uint8Array([]);
  7526. }
  7527. // combining plain text blocks into one
  7528. var outputLength = 16 * result.length;
  7529. var output = new Uint8Array(outputLength);
  7530. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  7531. output.set(result[i], j);
  7532. }
  7533. return output;
  7534. }
  7535. };
  7536. return AES256Cipher;
  7537. })();
  7538. var PDF17 = (function PDF17Closure() {
  7539. function compareByteArrays(array1, array2) {
  7540. if (array1.length !== array2.length) {
  7541. return false;
  7542. }
  7543. for (var i = 0; i < array1.length; i++) {
  7544. if (array1[i] !== array2[i]) {
  7545. return false;
  7546. }
  7547. }
  7548. return true;
  7549. }
  7550. function PDF17() {
  7551. }
  7552. PDF17.prototype = {
  7553. checkOwnerPassword: function PDF17_checkOwnerPassword(password,
  7554. ownerValidationSalt,
  7555. userBytes,
  7556. ownerPassword) {
  7557. var hashData = new Uint8Array(password.length + 56);
  7558. hashData.set(password, 0);
  7559. hashData.set(ownerValidationSalt, password.length);
  7560. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  7561. var result = calculateSHA256(hashData, 0, hashData.length);
  7562. return compareByteArrays(result, ownerPassword);
  7563. },
  7564. checkUserPassword: function PDF17_checkUserPassword(password,
  7565. userValidationSalt,
  7566. userPassword) {
  7567. var hashData = new Uint8Array(password.length + 8);
  7568. hashData.set(password, 0);
  7569. hashData.set(userValidationSalt, password.length);
  7570. var result = calculateSHA256(hashData, 0, hashData.length);
  7571. return compareByteArrays(result, userPassword);
  7572. },
  7573. getOwnerKey: function PDF17_getOwnerKey(password, ownerKeySalt, userBytes,
  7574. ownerEncryption) {
  7575. var hashData = new Uint8Array(password.length + 56);
  7576. hashData.set(password, 0);
  7577. hashData.set(ownerKeySalt, password.length);
  7578. hashData.set(userBytes, password.length + ownerKeySalt.length);
  7579. var key = calculateSHA256(hashData, 0, hashData.length);
  7580. var cipher = new AES256Cipher(key);
  7581. return cipher.decryptBlock(ownerEncryption,
  7582. false,
  7583. new Uint8Array(16));
  7584. },
  7585. getUserKey: function PDF17_getUserKey(password, userKeySalt,
  7586. userEncryption) {
  7587. var hashData = new Uint8Array(password.length + 8);
  7588. hashData.set(password, 0);
  7589. hashData.set(userKeySalt, password.length);
  7590. //key is the decryption key for the UE string
  7591. var key = calculateSHA256(hashData, 0, hashData.length);
  7592. var cipher = new AES256Cipher(key);
  7593. return cipher.decryptBlock(userEncryption,
  7594. false,
  7595. new Uint8Array(16));
  7596. }
  7597. };
  7598. return PDF17;
  7599. })();
  7600. var PDF20 = (function PDF20Closure() {
  7601. function concatArrays(array1, array2) {
  7602. var t = new Uint8Array(array1.length + array2.length);
  7603. t.set(array1, 0);
  7604. t.set(array2, array1.length);
  7605. return t;
  7606. }
  7607. function calculatePDF20Hash(password, input, userBytes) {
  7608. //This refers to Algorithm 2.B as defined in ISO 32000-2
  7609. var k = calculateSHA256(input, 0, input.length).subarray(0, 32);
  7610. var e = [0];
  7611. var i = 0;
  7612. while (i < 64 || e[e.length - 1] > i - 32) {
  7613. var arrayLength = password.length + k.length + userBytes.length;
  7614. var k1 = new Uint8Array(arrayLength * 64);
  7615. var array = concatArrays(password, k);
  7616. array = concatArrays(array, userBytes);
  7617. for (var j = 0, pos = 0; j < 64; j++, pos += arrayLength) {
  7618. k1.set(array, pos);
  7619. }
  7620. //AES128 CBC NO PADDING with
  7621. //first 16 bytes of k as the key and the second 16 as the iv.
  7622. var cipher = new AES128Cipher(k.subarray(0, 16));
  7623. e = cipher.encrypt(k1, k.subarray(16, 32));
  7624. //Now we have to take the first 16 bytes of an unsigned
  7625. //big endian integer... and compute the remainder
  7626. //modulo 3.... That is a fairly large number and
  7627. //JavaScript isn't going to handle that well...
  7628. //So we're using a trick that allows us to perform
  7629. //modulo math byte by byte
  7630. var remainder = 0;
  7631. for (var z = 0; z < 16; z++) {
  7632. remainder *= (256 % 3);
  7633. remainder %= 3;
  7634. remainder += ((e[z] >>> 0) % 3);
  7635. remainder %= 3;
  7636. }
  7637. if (remainder === 0) {
  7638. k = calculateSHA256(e, 0, e.length);
  7639. }
  7640. else if (remainder === 1) {
  7641. k = calculateSHA384(e, 0, e.length);
  7642. }
  7643. else if (remainder === 2) {
  7644. k = calculateSHA512(e, 0, e.length);
  7645. }
  7646. i++;
  7647. }
  7648. return k.subarray(0, 32);
  7649. }
  7650. function PDF20() {
  7651. }
  7652. function compareByteArrays(array1, array2) {
  7653. if (array1.length !== array2.length) {
  7654. return false;
  7655. }
  7656. for (var i = 0; i < array1.length; i++) {
  7657. if (array1[i] !== array2[i]) {
  7658. return false;
  7659. }
  7660. }
  7661. return true;
  7662. }
  7663. PDF20.prototype = {
  7664. hash: function PDF20_hash(password, concatBytes, userBytes) {
  7665. return calculatePDF20Hash(password, concatBytes, userBytes);
  7666. },
  7667. checkOwnerPassword: function PDF20_checkOwnerPassword(password,
  7668. ownerValidationSalt,
  7669. userBytes,
  7670. ownerPassword) {
  7671. var hashData = new Uint8Array(password.length + 56);
  7672. hashData.set(password, 0);
  7673. hashData.set(ownerValidationSalt, password.length);
  7674. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  7675. var result = calculatePDF20Hash(password, hashData, userBytes);
  7676. return compareByteArrays(result, ownerPassword);
  7677. },
  7678. checkUserPassword: function PDF20_checkUserPassword(password,
  7679. userValidationSalt,
  7680. userPassword) {
  7681. var hashData = new Uint8Array(password.length + 8);
  7682. hashData.set(password, 0);
  7683. hashData.set(userValidationSalt, password.length);
  7684. var result = calculatePDF20Hash(password, hashData, []);
  7685. return compareByteArrays(result, userPassword);
  7686. },
  7687. getOwnerKey: function PDF20_getOwnerKey(password, ownerKeySalt, userBytes,
  7688. ownerEncryption) {
  7689. var hashData = new Uint8Array(password.length + 56);
  7690. hashData.set(password, 0);
  7691. hashData.set(ownerKeySalt, password.length);
  7692. hashData.set(userBytes, password.length + ownerKeySalt.length);
  7693. var key = calculatePDF20Hash(password, hashData, userBytes);
  7694. var cipher = new AES256Cipher(key);
  7695. return cipher.decryptBlock(ownerEncryption,
  7696. false,
  7697. new Uint8Array(16));
  7698. },
  7699. getUserKey: function PDF20_getUserKey(password, userKeySalt,
  7700. userEncryption) {
  7701. var hashData = new Uint8Array(password.length + 8);
  7702. hashData.set(password, 0);
  7703. hashData.set(userKeySalt, password.length);
  7704. //key is the decryption key for the UE string
  7705. var key = calculatePDF20Hash(password, hashData, []);
  7706. var cipher = new AES256Cipher(key);
  7707. return cipher.decryptBlock(userEncryption,
  7708. false,
  7709. new Uint8Array(16));
  7710. }
  7711. };
  7712. return PDF20;
  7713. })();
  7714. var CipherTransform = (function CipherTransformClosure() {
  7715. function CipherTransform(stringCipherConstructor, streamCipherConstructor) {
  7716. this.stringCipherConstructor = stringCipherConstructor;
  7717. this.streamCipherConstructor = streamCipherConstructor;
  7718. }
  7719. CipherTransform.prototype = {
  7720. createStream: function CipherTransform_createStream(stream, length) {
  7721. var cipher = new this.streamCipherConstructor();
  7722. return new DecryptStream(stream, length,
  7723. function cipherTransformDecryptStream(data, finalize) {
  7724. return cipher.decryptBlock(data, finalize);
  7725. }
  7726. );
  7727. },
  7728. decryptString: function CipherTransform_decryptString(s) {
  7729. var cipher = new this.stringCipherConstructor();
  7730. var data = stringToBytes(s);
  7731. data = cipher.decryptBlock(data, true);
  7732. return bytesToString(data);
  7733. }
  7734. };
  7735. return CipherTransform;
  7736. })();
  7737. var CipherTransformFactory = (function CipherTransformFactoryClosure() {
  7738. var defaultPasswordBytes = new Uint8Array([
  7739. 0x28, 0xBF, 0x4E, 0x5E, 0x4E, 0x75, 0x8A, 0x41,
  7740. 0x64, 0x00, 0x4E, 0x56, 0xFF, 0xFA, 0x01, 0x08,
  7741. 0x2E, 0x2E, 0x00, 0xB6, 0xD0, 0x68, 0x3E, 0x80,
  7742. 0x2F, 0x0C, 0xA9, 0xFE, 0x64, 0x53, 0x69, 0x7A]);
  7743. function createEncryptionKey20(revision, password, ownerPassword,
  7744. ownerValidationSalt, ownerKeySalt, uBytes,
  7745. userPassword, userValidationSalt, userKeySalt,
  7746. ownerEncryption, userEncryption, perms) {
  7747. if (password) {
  7748. var passwordLength = Math.min(127, password.length);
  7749. password = password.subarray(0, passwordLength);
  7750. } else {
  7751. password = [];
  7752. }
  7753. var pdfAlgorithm;
  7754. if (revision === 6) {
  7755. pdfAlgorithm = new PDF20();
  7756. } else {
  7757. pdfAlgorithm = new PDF17();
  7758. }
  7759. if (pdfAlgorithm) {
  7760. if (pdfAlgorithm.checkUserPassword(password, userValidationSalt,
  7761. userPassword)) {
  7762. return pdfAlgorithm.getUserKey(password, userKeySalt, userEncryption);
  7763. } else if (pdfAlgorithm.checkOwnerPassword(password, ownerValidationSalt,
  7764. uBytes,
  7765. ownerPassword)) {
  7766. return pdfAlgorithm.getOwnerKey(password, ownerKeySalt, uBytes,
  7767. ownerEncryption);
  7768. }
  7769. }
  7770. return null;
  7771. }
  7772. function prepareKeyData(fileId, password, ownerPassword, userPassword,
  7773. flags, revision, keyLength, encryptMetadata) {
  7774. var hashDataSize = 40 + ownerPassword.length + fileId.length;
  7775. var hashData = new Uint8Array(hashDataSize), i = 0, j, n;
  7776. if (password) {
  7777. n = Math.min(32, password.length);
  7778. for (; i < n; ++i) {
  7779. hashData[i] = password[i];
  7780. }
  7781. }
  7782. j = 0;
  7783. while (i < 32) {
  7784. hashData[i++] = defaultPasswordBytes[j++];
  7785. }
  7786. // as now the padded password in the hashData[0..i]
  7787. for (j = 0, n = ownerPassword.length; j < n; ++j) {
  7788. hashData[i++] = ownerPassword[j];
  7789. }
  7790. hashData[i++] = flags & 0xFF;
  7791. hashData[i++] = (flags >> 8) & 0xFF;
  7792. hashData[i++] = (flags >> 16) & 0xFF;
  7793. hashData[i++] = (flags >>> 24) & 0xFF;
  7794. for (j = 0, n = fileId.length; j < n; ++j) {
  7795. hashData[i++] = fileId[j];
  7796. }
  7797. if (revision >= 4 && !encryptMetadata) {
  7798. hashData[i++] = 0xFF;
  7799. hashData[i++] = 0xFF;
  7800. hashData[i++] = 0xFF;
  7801. hashData[i++] = 0xFF;
  7802. }
  7803. var hash = calculateMD5(hashData, 0, i);
  7804. var keyLengthInBytes = keyLength >> 3;
  7805. if (revision >= 3) {
  7806. for (j = 0; j < 50; ++j) {
  7807. hash = calculateMD5(hash, 0, keyLengthInBytes);
  7808. }
  7809. }
  7810. var encryptionKey = hash.subarray(0, keyLengthInBytes);
  7811. var cipher, checkData;
  7812. if (revision >= 3) {
  7813. for (i = 0; i < 32; ++i) {
  7814. hashData[i] = defaultPasswordBytes[i];
  7815. }
  7816. for (j = 0, n = fileId.length; j < n; ++j) {
  7817. hashData[i++] = fileId[j];
  7818. }
  7819. cipher = new ARCFourCipher(encryptionKey);
  7820. checkData = cipher.encryptBlock(calculateMD5(hashData, 0, i));
  7821. n = encryptionKey.length;
  7822. var derivedKey = new Uint8Array(n), k;
  7823. for (j = 1; j <= 19; ++j) {
  7824. for (k = 0; k < n; ++k) {
  7825. derivedKey[k] = encryptionKey[k] ^ j;
  7826. }
  7827. cipher = new ARCFourCipher(derivedKey);
  7828. checkData = cipher.encryptBlock(checkData);
  7829. }
  7830. for (j = 0, n = checkData.length; j < n; ++j) {
  7831. if (userPassword[j] !== checkData[j]) {
  7832. return null;
  7833. }
  7834. }
  7835. } else {
  7836. cipher = new ARCFourCipher(encryptionKey);
  7837. checkData = cipher.encryptBlock(defaultPasswordBytes);
  7838. for (j = 0, n = checkData.length; j < n; ++j) {
  7839. if (userPassword[j] !== checkData[j]) {
  7840. return null;
  7841. }
  7842. }
  7843. }
  7844. return encryptionKey;
  7845. }
  7846. function decodeUserPassword(password, ownerPassword, revision, keyLength) {
  7847. var hashData = new Uint8Array(32), i = 0, j, n;
  7848. n = Math.min(32, password.length);
  7849. for (; i < n; ++i) {
  7850. hashData[i] = password[i];
  7851. }
  7852. j = 0;
  7853. while (i < 32) {
  7854. hashData[i++] = defaultPasswordBytes[j++];
  7855. }
  7856. var hash = calculateMD5(hashData, 0, i);
  7857. var keyLengthInBytes = keyLength >> 3;
  7858. if (revision >= 3) {
  7859. for (j = 0; j < 50; ++j) {
  7860. hash = calculateMD5(hash, 0, hash.length);
  7861. }
  7862. }
  7863. var cipher, userPassword;
  7864. if (revision >= 3) {
  7865. userPassword = ownerPassword;
  7866. var derivedKey = new Uint8Array(keyLengthInBytes), k;
  7867. for (j = 19; j >= 0; j--) {
  7868. for (k = 0; k < keyLengthInBytes; ++k) {
  7869. derivedKey[k] = hash[k] ^ j;
  7870. }
  7871. cipher = new ARCFourCipher(derivedKey);
  7872. userPassword = cipher.encryptBlock(userPassword);
  7873. }
  7874. } else {
  7875. cipher = new ARCFourCipher(hash.subarray(0, keyLengthInBytes));
  7876. userPassword = cipher.encryptBlock(ownerPassword);
  7877. }
  7878. return userPassword;
  7879. }
  7880. var identityName = Name.get('Identity');
  7881. function CipherTransformFactory(dict, fileId, password) {
  7882. var filter = dict.get('Filter');
  7883. if (!isName(filter) || filter.name !== 'Standard') {
  7884. error('unknown encryption method');
  7885. }
  7886. this.dict = dict;
  7887. var algorithm = dict.get('V');
  7888. if (!isInt(algorithm) ||
  7889. (algorithm !== 1 && algorithm !== 2 && algorithm !== 4 &&
  7890. algorithm !== 5)) {
  7891. error('unsupported encryption algorithm');
  7892. }
  7893. this.algorithm = algorithm;
  7894. var keyLength = dict.get('Length') || 40;
  7895. if (!isInt(keyLength) ||
  7896. keyLength < 40 || (keyLength % 8) !== 0) {
  7897. error('invalid key length');
  7898. }
  7899. // prepare keys
  7900. var ownerPassword = stringToBytes(dict.get('O')).subarray(0, 32);
  7901. var userPassword = stringToBytes(dict.get('U')).subarray(0, 32);
  7902. var flags = dict.get('P');
  7903. var revision = dict.get('R');
  7904. // meaningful when V is 4 or 5
  7905. var encryptMetadata = ((algorithm === 4 || algorithm === 5) &&
  7906. dict.get('EncryptMetadata') !== false);
  7907. this.encryptMetadata = encryptMetadata;
  7908. var fileIdBytes = stringToBytes(fileId);
  7909. var passwordBytes;
  7910. if (password) {
  7911. passwordBytes = stringToBytes(password);
  7912. }
  7913. var encryptionKey;
  7914. if (algorithm !== 5) {
  7915. encryptionKey = prepareKeyData(fileIdBytes, passwordBytes,
  7916. ownerPassword, userPassword, flags,
  7917. revision, keyLength, encryptMetadata);
  7918. }
  7919. else {
  7920. var ownerValidationSalt = stringToBytes(dict.get('O')).subarray(32, 40);
  7921. var ownerKeySalt = stringToBytes(dict.get('O')).subarray(40, 48);
  7922. var uBytes = stringToBytes(dict.get('U')).subarray(0, 48);
  7923. var userValidationSalt = stringToBytes(dict.get('U')).subarray(32, 40);
  7924. var userKeySalt = stringToBytes(dict.get('U')).subarray(40, 48);
  7925. var ownerEncryption = stringToBytes(dict.get('OE'));
  7926. var userEncryption = stringToBytes(dict.get('UE'));
  7927. var perms = stringToBytes(dict.get('Perms'));
  7928. encryptionKey =
  7929. createEncryptionKey20(revision, passwordBytes,
  7930. ownerPassword, ownerValidationSalt,
  7931. ownerKeySalt, uBytes,
  7932. userPassword, userValidationSalt,
  7933. userKeySalt, ownerEncryption,
  7934. userEncryption, perms);
  7935. }
  7936. if (!encryptionKey && !password) {
  7937. throw new PasswordException('No password given',
  7938. PasswordResponses.NEED_PASSWORD);
  7939. } else if (!encryptionKey && password) {
  7940. // Attempting use the password as an owner password
  7941. var decodedPassword = decodeUserPassword(passwordBytes, ownerPassword,
  7942. revision, keyLength);
  7943. encryptionKey = prepareKeyData(fileIdBytes, decodedPassword,
  7944. ownerPassword, userPassword, flags,
  7945. revision, keyLength, encryptMetadata);
  7946. }
  7947. if (!encryptionKey) {
  7948. throw new PasswordException('Incorrect Password',
  7949. PasswordResponses.INCORRECT_PASSWORD);
  7950. }
  7951. this.encryptionKey = encryptionKey;
  7952. if (algorithm >= 4) {
  7953. this.cf = dict.get('CF');
  7954. this.stmf = dict.get('StmF') || identityName;
  7955. this.strf = dict.get('StrF') || identityName;
  7956. this.eff = dict.get('EFF') || this.strf;
  7957. }
  7958. }
  7959. function buildObjectKey(num, gen, encryptionKey, isAes) {
  7960. var key = new Uint8Array(encryptionKey.length + 9), i, n;
  7961. for (i = 0, n = encryptionKey.length; i < n; ++i) {
  7962. key[i] = encryptionKey[i];
  7963. }
  7964. key[i++] = num & 0xFF;
  7965. key[i++] = (num >> 8) & 0xFF;
  7966. key[i++] = (num >> 16) & 0xFF;
  7967. key[i++] = gen & 0xFF;
  7968. key[i++] = (gen >> 8) & 0xFF;
  7969. if (isAes) {
  7970. key[i++] = 0x73;
  7971. key[i++] = 0x41;
  7972. key[i++] = 0x6C;
  7973. key[i++] = 0x54;
  7974. }
  7975. var hash = calculateMD5(key, 0, i);
  7976. return hash.subarray(0, Math.min(encryptionKey.length + 5, 16));
  7977. }
  7978. function buildCipherConstructor(cf, name, num, gen, key) {
  7979. var cryptFilter = cf.get(name.name);
  7980. var cfm;
  7981. if (cryptFilter !== null && cryptFilter !== undefined) {
  7982. cfm = cryptFilter.get('CFM');
  7983. }
  7984. if (!cfm || cfm.name === 'None') {
  7985. return function cipherTransformFactoryBuildCipherConstructorNone() {
  7986. return new NullCipher();
  7987. };
  7988. }
  7989. if ('V2' === cfm.name) {
  7990. return function cipherTransformFactoryBuildCipherConstructorV2() {
  7991. return new ARCFourCipher(buildObjectKey(num, gen, key, false));
  7992. };
  7993. }
  7994. if ('AESV2' === cfm.name) {
  7995. return function cipherTransformFactoryBuildCipherConstructorAESV2() {
  7996. return new AES128Cipher(buildObjectKey(num, gen, key, true));
  7997. };
  7998. }
  7999. if ('AESV3' === cfm.name) {
  8000. return function cipherTransformFactoryBuildCipherConstructorAESV3() {
  8001. return new AES256Cipher(key);
  8002. };
  8003. }
  8004. error('Unknown crypto method');
  8005. }
  8006. CipherTransformFactory.prototype = {
  8007. createCipherTransform:
  8008. function CipherTransformFactory_createCipherTransform(num, gen) {
  8009. if (this.algorithm === 4 || this.algorithm === 5) {
  8010. return new CipherTransform(
  8011. buildCipherConstructor(this.cf, this.stmf,
  8012. num, gen, this.encryptionKey),
  8013. buildCipherConstructor(this.cf, this.strf,
  8014. num, gen, this.encryptionKey));
  8015. }
  8016. // algorithms 1 and 2
  8017. var key = buildObjectKey(num, gen, this.encryptionKey, false);
  8018. var cipherConstructor = function buildCipherCipherConstructor() {
  8019. return new ARCFourCipher(key);
  8020. };
  8021. return new CipherTransform(cipherConstructor, cipherConstructor);
  8022. }
  8023. };
  8024. return CipherTransformFactory;
  8025. })();
  8026. var PatternType = {
  8027. FUNCTION_BASED: 1,
  8028. AXIAL: 2,
  8029. RADIAL: 3,
  8030. FREE_FORM_MESH: 4,
  8031. LATTICE_FORM_MESH: 5,
  8032. COONS_PATCH_MESH: 6,
  8033. TENSOR_PATCH_MESH: 7
  8034. };
  8035. var Pattern = (function PatternClosure() {
  8036. // Constructor should define this.getPattern
  8037. function Pattern() {
  8038. error('should not call Pattern constructor');
  8039. }
  8040. Pattern.prototype = {
  8041. // Input: current Canvas context
  8042. // Output: the appropriate fillStyle or strokeStyle
  8043. getPattern: function Pattern_getPattern(ctx) {
  8044. error('Should not call Pattern.getStyle: ' + ctx);
  8045. }
  8046. };
  8047. Pattern.parseShading = function Pattern_parseShading(shading, matrix, xref,
  8048. res) {
  8049. var dict = isStream(shading) ? shading.dict : shading;
  8050. var type = dict.get('ShadingType');
  8051. switch (type) {
  8052. case PatternType.AXIAL:
  8053. case PatternType.RADIAL:
  8054. // Both radial and axial shadings are handled by RadialAxial shading.
  8055. return new Shadings.RadialAxial(dict, matrix, xref, res);
  8056. case PatternType.FREE_FORM_MESH:
  8057. case PatternType.LATTICE_FORM_MESH:
  8058. case PatternType.COONS_PATCH_MESH:
  8059. case PatternType.TENSOR_PATCH_MESH:
  8060. return new Shadings.Mesh(shading, matrix, xref, res);
  8061. default:
  8062. UnsupportedManager.notify(UNSUPPORTED_FEATURES.shadingPattern);
  8063. return new Shadings.Dummy();
  8064. }
  8065. };
  8066. return Pattern;
  8067. })();
  8068. var Shadings = {};
  8069. // A small number to offset the first/last color stops so we can insert ones to
  8070. // support extend. Number.MIN_VALUE appears to be too small and breaks the
  8071. // extend. 1e-7 works in FF but chrome seems to use an even smaller sized number
  8072. // internally so we have to go bigger.
  8073. Shadings.SMALL_NUMBER = 1e-2;
  8074. // Radial and axial shading have very similar implementations
  8075. // If needed, the implementations can be broken into two classes
  8076. Shadings.RadialAxial = (function RadialAxialClosure() {
  8077. function RadialAxial(dict, matrix, xref, res) {
  8078. this.matrix = matrix;
  8079. this.coordsArr = dict.get('Coords');
  8080. this.shadingType = dict.get('ShadingType');
  8081. this.type = 'Pattern';
  8082. var cs = dict.get('ColorSpace', 'CS');
  8083. cs = ColorSpace.parse(cs, xref, res);
  8084. this.cs = cs;
  8085. var t0 = 0.0, t1 = 1.0;
  8086. if (dict.has('Domain')) {
  8087. var domainArr = dict.get('Domain');
  8088. t0 = domainArr[0];
  8089. t1 = domainArr[1];
  8090. }
  8091. var extendStart = false, extendEnd = false;
  8092. if (dict.has('Extend')) {
  8093. var extendArr = dict.get('Extend');
  8094. extendStart = extendArr[0];
  8095. extendEnd = extendArr[1];
  8096. }
  8097. if (this.shadingType === PatternType.RADIAL &&
  8098. (!extendStart || !extendEnd)) {
  8099. // Radial gradient only currently works if either circle is fully within
  8100. // the other circle.
  8101. var x1 = this.coordsArr[0];
  8102. var y1 = this.coordsArr[1];
  8103. var r1 = this.coordsArr[2];
  8104. var x2 = this.coordsArr[3];
  8105. var y2 = this.coordsArr[4];
  8106. var r2 = this.coordsArr[5];
  8107. var distance = Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
  8108. if (r1 <= r2 + distance &&
  8109. r2 <= r1 + distance) {
  8110. warn('Unsupported radial gradient.');
  8111. }
  8112. }
  8113. this.extendStart = extendStart;
  8114. this.extendEnd = extendEnd;
  8115. var fnObj = dict.get('Function');
  8116. var fn;
  8117. if (isArray(fnObj)) {
  8118. var fnArray = [];
  8119. for (var j = 0, jj = fnObj.length; j < jj; j++) {
  8120. var obj = xref.fetchIfRef(fnObj[j]);
  8121. if (!isPDFFunction(obj)) {
  8122. error('Invalid function');
  8123. }
  8124. fnArray.push(PDFFunction.parse(xref, obj));
  8125. }
  8126. fn = function radialAxialColorFunction(arg) {
  8127. var out = [];
  8128. for (var i = 0, ii = fnArray.length; i < ii; i++) {
  8129. out.push(fnArray[i](arg)[0]);
  8130. }
  8131. return out;
  8132. };
  8133. } else {
  8134. if (!isPDFFunction(fnObj)) {
  8135. error('Invalid function');
  8136. }
  8137. fn = PDFFunction.parse(xref, fnObj);
  8138. }
  8139. // 10 samples seems good enough for now, but probably won't work
  8140. // if there are sharp color changes. Ideally, we would implement
  8141. // the spec faithfully and add lossless optimizations.
  8142. var diff = t1 - t0;
  8143. var step = diff / 10;
  8144. var colorStops = this.colorStops = [];
  8145. // Protect against bad domains so we don't end up in an infinte loop below.
  8146. if (t0 >= t1 || step <= 0) {
  8147. // Acrobat doesn't seem to handle these cases so we'll ignore for
  8148. // now.
  8149. info('Bad shading domain.');
  8150. return;
  8151. }
  8152. var rgbColor;
  8153. for (var i = t0; i <= t1; i += step) {
  8154. rgbColor = cs.getRgb(fn([i]), 0);
  8155. var cssColor = Util.makeCssRgb(rgbColor);
  8156. colorStops.push([(i - t0) / diff, cssColor]);
  8157. }
  8158. var background = 'transparent';
  8159. if (dict.has('Background')) {
  8160. rgbColor = cs.getRgb(dict.get('Background'), 0);
  8161. background = Util.makeCssRgb(rgbColor);
  8162. }
  8163. if (!extendStart) {
  8164. // Insert a color stop at the front and offset the first real color stop
  8165. // so it doesn't conflict with the one we insert.
  8166. colorStops.unshift([0, background]);
  8167. colorStops[1][0] += Shadings.SMALL_NUMBER;
  8168. }
  8169. if (!extendEnd) {
  8170. // Same idea as above in extendStart but for the end.
  8171. colorStops[colorStops.length - 1][0] -= Shadings.SMALL_NUMBER;
  8172. colorStops.push([1, background]);
  8173. }
  8174. this.colorStops = colorStops;
  8175. }
  8176. RadialAxial.prototype = {
  8177. getIR: function RadialAxial_getIR() {
  8178. var coordsArr = this.coordsArr;
  8179. var shadingType = this.shadingType;
  8180. var type, p0, p1, r0, r1;
  8181. if (shadingType == PatternType.AXIAL) {
  8182. p0 = [coordsArr[0], coordsArr[1]];
  8183. p1 = [coordsArr[2], coordsArr[3]];
  8184. r0 = null;
  8185. r1 = null;
  8186. type = 'axial';
  8187. } else if (shadingType == PatternType.RADIAL) {
  8188. p0 = [coordsArr[0], coordsArr[1]];
  8189. p1 = [coordsArr[3], coordsArr[4]];
  8190. r0 = coordsArr[2];
  8191. r1 = coordsArr[5];
  8192. type = 'radial';
  8193. } else {
  8194. error('getPattern type unknown: ' + shadingType);
  8195. }
  8196. var matrix = this.matrix;
  8197. if (matrix) {
  8198. p0 = Util.applyTransform(p0, matrix);
  8199. p1 = Util.applyTransform(p1, matrix);
  8200. }
  8201. return ['RadialAxial', type, this.colorStops, p0, p1, r0, r1];
  8202. }
  8203. };
  8204. return RadialAxial;
  8205. })();
  8206. // All mesh shading. For now, they will be presented as set of the triangles
  8207. // to be drawn on the canvas and rgb color for each vertex.
  8208. Shadings.Mesh = (function MeshClosure() {
  8209. function MeshStreamReader(stream, context) {
  8210. this.stream = stream;
  8211. this.context = context;
  8212. this.buffer = 0;
  8213. this.bufferLength = 0;
  8214. }
  8215. MeshStreamReader.prototype = {
  8216. get hasData() {
  8217. if (this.stream.end) {
  8218. return this.stream.pos < this.stream.end;
  8219. }
  8220. if (this.bufferLength > 0) {
  8221. return true;
  8222. }
  8223. var nextByte = this.stream.getByte();
  8224. if (nextByte < 0) {
  8225. return false;
  8226. }
  8227. this.buffer = nextByte;
  8228. this.bufferLength = 8;
  8229. return true;
  8230. },
  8231. readBits: function MeshStreamReader_readBits(n) {
  8232. var buffer = this.buffer;
  8233. var bufferLength = this.bufferLength;
  8234. if (n === 32) {
  8235. if (bufferLength === 0) {
  8236. return ((this.stream.getByte() << 24) |
  8237. (this.stream.getByte() << 16) | (this.stream.getByte() << 8) |
  8238. this.stream.getByte()) >>> 0;
  8239. }
  8240. buffer = (buffer << 24) | (this.stream.getByte() << 16) |
  8241. (this.stream.getByte() << 8) | this.stream.getByte();
  8242. var nextByte = this.stream.getByte();
  8243. this.buffer = nextByte & ((1 << bufferLength) - 1);
  8244. return ((buffer << (8 - bufferLength)) |
  8245. ((nextByte & 0xFF) >> bufferLength)) >>> 0;
  8246. }
  8247. if (n === 8 && bufferLength === 0) {
  8248. return this.stream.getByte();
  8249. }
  8250. while (bufferLength < n) {
  8251. buffer = (buffer << 8) | this.stream.getByte();
  8252. bufferLength += 8;
  8253. }
  8254. bufferLength -= n;
  8255. this.bufferLength = bufferLength;
  8256. this.buffer = buffer & ((1 << bufferLength) - 1);
  8257. return buffer >> bufferLength;
  8258. },
  8259. align: function MeshStreamReader_align() {
  8260. this.buffer = 0;
  8261. this.bufferLength = 0;
  8262. },
  8263. readFlag: function MeshStreamReader_readFlag() {
  8264. return this.readBits(this.context.bitsPerFlag);
  8265. },
  8266. readCoordinate: function MeshStreamReader_readCoordinate() {
  8267. var bitsPerCoordinate = this.context.bitsPerCoordinate;
  8268. var xi = this.readBits(bitsPerCoordinate);
  8269. var yi = this.readBits(bitsPerCoordinate);
  8270. var decode = this.context.decode;
  8271. var scale = bitsPerCoordinate < 32 ? 1 / ((1 << bitsPerCoordinate) - 1) :
  8272. 2.3283064365386963e-10; // 2 ^ -32
  8273. return [
  8274. xi * scale * (decode[1] - decode[0]) + decode[0],
  8275. yi * scale * (decode[3] - decode[2]) + decode[2]
  8276. ];
  8277. },
  8278. readComponents: function MeshStreamReader_readComponents() {
  8279. var numComps = this.context.numComps;
  8280. var bitsPerComponent = this.context.bitsPerComponent;
  8281. var scale = bitsPerComponent < 32 ? 1 / ((1 << bitsPerComponent) - 1) :
  8282. 2.3283064365386963e-10; // 2 ^ -32
  8283. var decode = this.context.decode;
  8284. var components = [];
  8285. for (var i = 0, j = 4; i < numComps; i++, j += 2) {
  8286. var ci = this.readBits(bitsPerComponent);
  8287. components.push(ci * scale * (decode[j + 1] - decode[j]) + decode[j]);
  8288. }
  8289. if (this.context.colorFn) {
  8290. components = this.context.colorFn(components);
  8291. }
  8292. return this.context.colorSpace.getRgb(components, 0);
  8293. }
  8294. };
  8295. function decodeType4Shading(mesh, reader) {
  8296. var coords = mesh.coords;
  8297. var colors = mesh.colors;
  8298. var operators = [];
  8299. var ps = []; // not maintaining cs since that will match ps
  8300. var verticesLeft = 0; // assuming we have all data to start a new triangle
  8301. while (reader.hasData) {
  8302. var f = reader.readFlag();
  8303. var coord = reader.readCoordinate();
  8304. var color = reader.readComponents();
  8305. if (verticesLeft === 0) { // ignoring flags if we started a triangle
  8306. assert(0 <= f && f <= 2, 'Unknown type4 flag');
  8307. switch (f) {
  8308. case 0:
  8309. verticesLeft = 3;
  8310. break;
  8311. case 1:
  8312. ps.push(ps[ps.length - 2], ps[ps.length - 1]);
  8313. verticesLeft = 1;
  8314. break;
  8315. case 2:
  8316. ps.push(ps[ps.length - 3], ps[ps.length - 1]);
  8317. verticesLeft = 1;
  8318. break;
  8319. }
  8320. operators.push(f);
  8321. }
  8322. ps.push(coords.length);
  8323. coords.push(coord);
  8324. colors.push(color);
  8325. verticesLeft--;
  8326. reader.align();
  8327. }
  8328. var psPacked = new Int32Array(ps);
  8329. mesh.figures.push({
  8330. type: 'triangles',
  8331. coords: psPacked,
  8332. colors: psPacked
  8333. });
  8334. }
  8335. function decodeType5Shading(mesh, reader, verticesPerRow) {
  8336. var coords = mesh.coords;
  8337. var colors = mesh.colors;
  8338. var ps = []; // not maintaining cs since that will match ps
  8339. while (reader.hasData) {
  8340. var coord = reader.readCoordinate();
  8341. var color = reader.readComponents();
  8342. ps.push(coords.length);
  8343. coords.push(coord);
  8344. colors.push(color);
  8345. }
  8346. var psPacked = new Int32Array(ps);
  8347. mesh.figures.push({
  8348. type: 'lattice',
  8349. coords: psPacked,
  8350. colors: psPacked,
  8351. verticesPerRow: verticesPerRow
  8352. });
  8353. }
  8354. var MIN_SPLIT_PATCH_CHUNKS_AMOUNT = 3;
  8355. var MAX_SPLIT_PATCH_CHUNKS_AMOUNT = 20;
  8356. var TRIANGLE_DENSITY = 20; // count of triangles per entire mesh bounds
  8357. var getB = (function getBClosure() {
  8358. function buildB(count) {
  8359. var lut = [];
  8360. for (var i = 0; i <= count; i++) {
  8361. var t = i / count, t_ = 1 - t;
  8362. lut.push(new Float32Array([t_ * t_ * t_, 3 * t * t_ * t_,
  8363. 3 * t * t * t_, t * t * t]));
  8364. }
  8365. return lut;
  8366. }
  8367. var cache = [];
  8368. return function getB(count) {
  8369. if (!cache[count]) {
  8370. cache[count] = buildB(count);
  8371. }
  8372. return cache[count];
  8373. };
  8374. })();
  8375. function buildFigureFromPatch(mesh, index) {
  8376. var figure = mesh.figures[index];
  8377. assert(figure.type === 'patch', 'Unexpected patch mesh figure');
  8378. var coords = mesh.coords, colors = mesh.colors;
  8379. var pi = figure.coords;
  8380. var ci = figure.colors;
  8381. var figureMinX = Math.min(coords[pi[0]][0], coords[pi[3]][0],
  8382. coords[pi[12]][0], coords[pi[15]][0]);
  8383. var figureMinY = Math.min(coords[pi[0]][1], coords[pi[3]][1],
  8384. coords[pi[12]][1], coords[pi[15]][1]);
  8385. var figureMaxX = Math.max(coords[pi[0]][0], coords[pi[3]][0],
  8386. coords[pi[12]][0], coords[pi[15]][0]);
  8387. var figureMaxY = Math.max(coords[pi[0]][1], coords[pi[3]][1],
  8388. coords[pi[12]][1], coords[pi[15]][1]);
  8389. var splitXBy = Math.ceil((figureMaxX - figureMinX) * TRIANGLE_DENSITY /
  8390. (mesh.bounds[2] - mesh.bounds[0]));
  8391. splitXBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  8392. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitXBy));
  8393. var splitYBy = Math.ceil((figureMaxY - figureMinY) * TRIANGLE_DENSITY /
  8394. (mesh.bounds[3] - mesh.bounds[1]));
  8395. splitYBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  8396. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitYBy));
  8397. var verticesPerRow = splitXBy + 1;
  8398. var figureCoords = new Int32Array((splitYBy + 1) * verticesPerRow);
  8399. var figureColors = new Int32Array((splitYBy + 1) * verticesPerRow);
  8400. var k = 0;
  8401. var cl = new Uint8Array(3), cr = new Uint8Array(3);
  8402. var c0 = colors[ci[0]], c1 = colors[ci[1]],
  8403. c2 = colors[ci[2]], c3 = colors[ci[3]];
  8404. var bRow = getB(splitYBy), bCol = getB(splitXBy);
  8405. for (var row = 0; row <= splitYBy; row++) {
  8406. cl[0] = ((c0[0] * (splitYBy - row) + c2[0] * row) / splitYBy) | 0;
  8407. cl[1] = ((c0[1] * (splitYBy - row) + c2[1] * row) / splitYBy) | 0;
  8408. cl[2] = ((c0[2] * (splitYBy - row) + c2[2] * row) / splitYBy) | 0;
  8409. cr[0] = ((c1[0] * (splitYBy - row) + c3[0] * row) / splitYBy) | 0;
  8410. cr[1] = ((c1[1] * (splitYBy - row) + c3[1] * row) / splitYBy) | 0;
  8411. cr[2] = ((c1[2] * (splitYBy - row) + c3[2] * row) / splitYBy) | 0;
  8412. for (var col = 0; col <= splitXBy; col++, k++) {
  8413. if ((row === 0 || row === splitYBy) &&
  8414. (col === 0 || col === splitXBy)) {
  8415. continue;
  8416. }
  8417. var x = 0, y = 0;
  8418. var q = 0;
  8419. for (var i = 0; i <= 3; i++) {
  8420. for (var j = 0; j <= 3; j++, q++) {
  8421. var m = bRow[row][i] * bCol[col][j];
  8422. x += coords[pi[q]][0] * m;
  8423. y += coords[pi[q]][1] * m;
  8424. }
  8425. }
  8426. figureCoords[k] = coords.length;
  8427. coords.push([x, y]);
  8428. figureColors[k] = colors.length;
  8429. var newColor = new Uint8Array(3);
  8430. newColor[0] = ((cl[0] * (splitXBy - col) + cr[0] * col) / splitXBy) | 0;
  8431. newColor[1] = ((cl[1] * (splitXBy - col) + cr[1] * col) / splitXBy) | 0;
  8432. newColor[2] = ((cl[2] * (splitXBy - col) + cr[2] * col) / splitXBy) | 0;
  8433. colors.push(newColor);
  8434. }
  8435. }
  8436. figureCoords[0] = pi[0];
  8437. figureColors[0] = ci[0];
  8438. figureCoords[splitXBy] = pi[3];
  8439. figureColors[splitXBy] = ci[1];
  8440. figureCoords[verticesPerRow * splitYBy] = pi[12];
  8441. figureColors[verticesPerRow * splitYBy] = ci[2];
  8442. figureCoords[verticesPerRow * splitYBy + splitXBy] = pi[15];
  8443. figureColors[verticesPerRow * splitYBy + splitXBy] = ci[3];
  8444. mesh.figures[index] = {
  8445. type: 'lattice',
  8446. coords: figureCoords,
  8447. colors: figureColors,
  8448. verticesPerRow: verticesPerRow
  8449. };
  8450. }
  8451. function decodeType6Shading(mesh, reader) {
  8452. // A special case of Type 7. The p11, p12, p21, p22 automatically filled
  8453. var coords = mesh.coords;
  8454. var colors = mesh.colors;
  8455. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  8456. var cs = new Int32Array(4); // c00, c30, c03, c33
  8457. while (reader.hasData) {
  8458. var f = reader.readFlag();
  8459. assert(0 <= f && f <= 3, 'Unknown type6 flag');
  8460. var i, ii;
  8461. var pi = coords.length;
  8462. for (i = 0, ii = (f !== 0 ? 8 : 12); i < ii; i++) {
  8463. coords.push(reader.readCoordinate());
  8464. }
  8465. var ci = colors.length;
  8466. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  8467. colors.push(reader.readComponents());
  8468. }
  8469. var tmp1, tmp2, tmp3, tmp4;
  8470. switch (f) {
  8471. case 0:
  8472. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  8473. ps[ 8] = pi + 2; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 7;
  8474. ps[ 4] = pi + 1; /* calculated below */ ps[ 7] = pi + 8;
  8475. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  8476. cs[2] = ci + 1; cs[3] = ci + 2;
  8477. cs[0] = ci; cs[1] = ci + 3;
  8478. break;
  8479. case 1:
  8480. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  8481. ps[12] = pi + 5; ps[13] = pi + 4; ps[14] = pi + 3; ps[15] = pi + 2;
  8482. ps[ 8] = pi + 6; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 1;
  8483. ps[ 4] = pi + 7; /* calculated below */ ps[ 7] = pi;
  8484. ps[ 0] = tmp1; ps[ 1] = tmp2; ps[ 2] = tmp3; ps[ 3] = tmp4;
  8485. tmp1 = cs[2]; tmp2 = cs[3];
  8486. cs[2] = ci + 1; cs[3] = ci;
  8487. cs[0] = tmp1; cs[1] = tmp2;
  8488. break;
  8489. case 2:
  8490. ps[12] = ps[15]; ps[13] = pi + 7; ps[14] = pi + 6; ps[15] = pi + 5;
  8491. ps[ 8] = ps[11]; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 4;
  8492. ps[ 4] = ps[7]; /* calculated below */ ps[ 7] = pi + 3;
  8493. ps[ 0] = ps[3]; ps[ 1] = pi; ps[ 2] = pi + 1; ps[ 3] = pi + 2;
  8494. cs[2] = cs[3]; cs[3] = ci + 1;
  8495. cs[0] = cs[1]; cs[1] = ci;
  8496. break;
  8497. case 3:
  8498. ps[12] = ps[0]; ps[13] = ps[1]; ps[14] = ps[2]; ps[15] = ps[3];
  8499. ps[ 8] = pi; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 7;
  8500. ps[ 4] = pi + 1; /* calculated below */ ps[ 7] = pi + 6;
  8501. ps[ 0] = pi + 2; ps[ 1] = pi + 3; ps[ 2] = pi + 4; ps[ 3] = pi + 5;
  8502. cs[2] = cs[0]; cs[3] = cs[1];
  8503. cs[0] = ci; cs[1] = ci + 1;
  8504. break;
  8505. }
  8506. // set p11, p12, p21, p22
  8507. ps[5] = coords.length;
  8508. coords.push([
  8509. (-4 * coords[ps[0]][0] - coords[ps[15]][0] +
  8510. 6 * (coords[ps[4]][0] + coords[ps[1]][0]) -
  8511. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  8512. 3 * (coords[ps[13]][0] + coords[ps[7]][0])) / 9,
  8513. (-4 * coords[ps[0]][1] - coords[ps[15]][1] +
  8514. 6 * (coords[ps[4]][1] + coords[ps[1]][1]) -
  8515. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  8516. 3 * (coords[ps[13]][1] + coords[ps[7]][1])) / 9
  8517. ]);
  8518. ps[6] = coords.length;
  8519. coords.push([
  8520. (-4 * coords[ps[3]][0] - coords[ps[12]][0] +
  8521. 6 * (coords[ps[2]][0] + coords[ps[7]][0]) -
  8522. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  8523. 3 * (coords[ps[4]][0] + coords[ps[14]][0])) / 9,
  8524. (-4 * coords[ps[3]][1] - coords[ps[12]][1] +
  8525. 6 * (coords[ps[2]][1] + coords[ps[7]][1]) -
  8526. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  8527. 3 * (coords[ps[4]][1] + coords[ps[14]][1])) / 9
  8528. ]);
  8529. ps[9] = coords.length;
  8530. coords.push([
  8531. (-4 * coords[ps[12]][0] - coords[ps[3]][0] +
  8532. 6 * (coords[ps[8]][0] + coords[ps[13]][0]) -
  8533. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  8534. 3 * (coords[ps[11]][0] + coords[ps[1]][0])) / 9,
  8535. (-4 * coords[ps[12]][1] - coords[ps[3]][1] +
  8536. 6 * (coords[ps[8]][1] + coords[ps[13]][1]) -
  8537. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  8538. 3 * (coords[ps[11]][1] + coords[ps[1]][1])) / 9
  8539. ]);
  8540. ps[10] = coords.length;
  8541. coords.push([
  8542. (-4 * coords[ps[15]][0] - coords[ps[0]][0] +
  8543. 6 * (coords[ps[11]][0] + coords[ps[14]][0]) -
  8544. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  8545. 3 * (coords[ps[2]][0] + coords[ps[8]][0])) / 9,
  8546. (-4 * coords[ps[15]][1] - coords[ps[0]][1] +
  8547. 6 * (coords[ps[11]][1] + coords[ps[14]][1]) -
  8548. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  8549. 3 * (coords[ps[2]][1] + coords[ps[8]][1])) / 9
  8550. ]);
  8551. mesh.figures.push({
  8552. type: 'patch',
  8553. coords: new Int32Array(ps), // making copies of ps and cs
  8554. colors: new Int32Array(cs)
  8555. });
  8556. }
  8557. }
  8558. function decodeType7Shading(mesh, reader) {
  8559. var coords = mesh.coords;
  8560. var colors = mesh.colors;
  8561. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  8562. var cs = new Int32Array(4); // c00, c30, c03, c33
  8563. while (reader.hasData) {
  8564. var f = reader.readFlag();
  8565. assert(0 <= f && f <= 3, 'Unknown type7 flag');
  8566. var i, ii;
  8567. var pi = coords.length;
  8568. for (i = 0, ii = (f !== 0 ? 12 : 16); i < ii; i++) {
  8569. coords.push(reader.readCoordinate());
  8570. }
  8571. var ci = colors.length;
  8572. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  8573. colors.push(reader.readComponents());
  8574. }
  8575. var tmp1, tmp2, tmp3, tmp4;
  8576. switch (f) {
  8577. case 0:
  8578. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  8579. ps[ 8] = pi + 2; ps[ 9] = pi + 13; ps[10] = pi + 14; ps[11] = pi + 7;
  8580. ps[ 4] = pi + 1; ps[ 5] = pi + 12; ps[ 6] = pi + 15; ps[ 7] = pi + 8;
  8581. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  8582. cs[2] = ci + 1; cs[3] = ci + 2;
  8583. cs[0] = ci; cs[1] = ci + 3;
  8584. break;
  8585. case 1:
  8586. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  8587. ps[12] = pi + 5; ps[13] = pi + 4; ps[14] = pi + 3; ps[15] = pi + 2;
  8588. ps[ 8] = pi + 6; ps[ 9] = pi + 11; ps[10] = pi + 10; ps[11] = pi + 1;
  8589. ps[ 4] = pi + 7; ps[ 5] = pi + 8; ps[ 6] = pi + 9; ps[ 7] = pi;
  8590. ps[ 0] = tmp1; ps[ 1] = tmp2; ps[ 2] = tmp3; ps[ 3] = tmp4;
  8591. tmp1 = cs[2]; tmp2 = cs[3];
  8592. cs[2] = ci + 1; cs[3] = ci;
  8593. cs[0] = tmp1; cs[1] = tmp2;
  8594. break;
  8595. case 2:
  8596. ps[12] = ps[15]; ps[13] = pi + 7; ps[14] = pi + 6; ps[15] = pi + 5;
  8597. ps[ 8] = ps[11]; ps[ 9] = pi + 8; ps[10] = pi + 11; ps[11] = pi + 4;
  8598. ps[ 4] = ps[7]; ps[ 5] = pi + 9; ps[ 6] = pi + 10; ps[ 7] = pi + 3;
  8599. ps[ 0] = ps[3]; ps[ 1] = pi; ps[ 2] = pi + 1; ps[ 3] = pi + 2;
  8600. cs[2] = cs[3]; cs[3] = ci + 1;
  8601. cs[0] = cs[1]; cs[1] = ci;
  8602. break;
  8603. case 3:
  8604. ps[12] = ps[0]; ps[13] = ps[1]; ps[14] = ps[2]; ps[15] = ps[3];
  8605. ps[ 8] = pi; ps[ 9] = pi + 9; ps[10] = pi + 8; ps[11] = pi + 7;
  8606. ps[ 4] = pi + 1; ps[ 5] = pi + 10; ps[ 6] = pi + 11; ps[ 7] = pi + 6;
  8607. ps[ 0] = pi + 2; ps[ 1] = pi + 3; ps[ 2] = pi + 4; ps[ 3] = pi + 5;
  8608. cs[2] = cs[0]; cs[3] = cs[1];
  8609. cs[0] = ci; cs[1] = ci + 1;
  8610. break;
  8611. }
  8612. mesh.figures.push({
  8613. type: 'patch',
  8614. coords: new Int32Array(ps), // making copies of ps and cs
  8615. colors: new Int32Array(cs)
  8616. });
  8617. }
  8618. }
  8619. function updateBounds(mesh) {
  8620. var minX = mesh.coords[0][0], minY = mesh.coords[0][1],
  8621. maxX = minX, maxY = minY;
  8622. for (var i = 1, ii = mesh.coords.length; i < ii; i++) {
  8623. var x = mesh.coords[i][0], y = mesh.coords[i][1];
  8624. minX = minX > x ? x : minX;
  8625. minY = minY > y ? y : minY;
  8626. maxX = maxX < x ? x : maxX;
  8627. maxY = maxY < y ? y : maxY;
  8628. }
  8629. mesh.bounds = [minX, minY, maxX, maxY];
  8630. }
  8631. function packData(mesh) {
  8632. var i, ii, j, jj;
  8633. var coords = mesh.coords;
  8634. var coordsPacked = new Float32Array(coords.length * 2);
  8635. for (i = 0, j = 0, ii = coords.length; i < ii; i++) {
  8636. var xy = coords[i];
  8637. coordsPacked[j++] = xy[0];
  8638. coordsPacked[j++] = xy[1];
  8639. }
  8640. mesh.coords = coordsPacked;
  8641. var colors = mesh.colors;
  8642. var colorsPacked = new Uint8Array(colors.length * 3);
  8643. for (i = 0, j = 0, ii = colors.length; i < ii; i++) {
  8644. var c = colors[i];
  8645. colorsPacked[j++] = c[0];
  8646. colorsPacked[j++] = c[1];
  8647. colorsPacked[j++] = c[2];
  8648. }
  8649. mesh.colors = colorsPacked;
  8650. var figures = mesh.figures;
  8651. for (i = 0, ii = figures.length; i < ii; i++) {
  8652. var figure = figures[i], ps = figure.coords, cs = figure.colors;
  8653. for (j = 0, jj = ps.length; j < jj; j++) {
  8654. ps[j] *= 2;
  8655. cs[j] *= 3;
  8656. }
  8657. }
  8658. }
  8659. function Mesh(stream, matrix, xref, res) {
  8660. assert(isStream(stream), 'Mesh data is not a stream');
  8661. var dict = stream.dict;
  8662. this.matrix = matrix;
  8663. this.shadingType = dict.get('ShadingType');
  8664. this.type = 'Pattern';
  8665. this.bbox = dict.get('BBox');
  8666. var cs = dict.get('ColorSpace', 'CS');
  8667. cs = ColorSpace.parse(cs, xref, res);
  8668. this.cs = cs;
  8669. this.background = dict.has('Background') ?
  8670. cs.getRgb(dict.get('Background'), 0) : null;
  8671. var fnObj = dict.get('Function');
  8672. var fn;
  8673. if (!fnObj) {
  8674. fn = null;
  8675. } else if (isArray(fnObj)) {
  8676. var fnArray = [];
  8677. for (var j = 0, jj = fnObj.length; j < jj; j++) {
  8678. var obj = xref.fetchIfRef(fnObj[j]);
  8679. if (!isPDFFunction(obj)) {
  8680. error('Invalid function');
  8681. }
  8682. fnArray.push(PDFFunction.parse(xref, obj));
  8683. }
  8684. fn = function radialAxialColorFunction(arg) {
  8685. var out = [];
  8686. for (var i = 0, ii = fnArray.length; i < ii; i++) {
  8687. out.push(fnArray[i](arg)[0]);
  8688. }
  8689. return out;
  8690. };
  8691. } else {
  8692. if (!isPDFFunction(fnObj)) {
  8693. error('Invalid function');
  8694. }
  8695. fn = PDFFunction.parse(xref, fnObj);
  8696. }
  8697. this.coords = [];
  8698. this.colors = [];
  8699. this.figures = [];
  8700. var decodeContext = {
  8701. bitsPerCoordinate: dict.get('BitsPerCoordinate'),
  8702. bitsPerComponent: dict.get('BitsPerComponent'),
  8703. bitsPerFlag: dict.get('BitsPerFlag'),
  8704. decode: dict.get('Decode'),
  8705. colorFn: fn,
  8706. colorSpace: cs,
  8707. numComps: fn ? 1 : cs.numComps
  8708. };
  8709. var reader = new MeshStreamReader(stream, decodeContext);
  8710. var patchMesh = false;
  8711. switch (this.shadingType) {
  8712. case PatternType.FREE_FORM_MESH:
  8713. decodeType4Shading(this, reader);
  8714. break;
  8715. case PatternType.LATTICE_FORM_MESH:
  8716. var verticesPerRow = dict.get('VerticesPerRow') | 0;
  8717. assert(verticesPerRow >= 2, 'Invalid VerticesPerRow');
  8718. decodeType5Shading(this, reader, verticesPerRow);
  8719. break;
  8720. case PatternType.COONS_PATCH_MESH:
  8721. decodeType6Shading(this, reader);
  8722. patchMesh = true;
  8723. break;
  8724. case PatternType.TENSOR_PATCH_MESH:
  8725. decodeType7Shading(this, reader);
  8726. patchMesh = true;
  8727. break;
  8728. default:
  8729. error('Unsupported mesh type.');
  8730. break;
  8731. }
  8732. if (patchMesh) {
  8733. // dirty bounds calculation for determining, how dense shall be triangles
  8734. updateBounds(this);
  8735. for (var i = 0, ii = this.figures.length; i < ii; i++) {
  8736. buildFigureFromPatch(this, i);
  8737. }
  8738. }
  8739. // calculate bounds
  8740. updateBounds(this);
  8741. packData(this);
  8742. }
  8743. Mesh.prototype = {
  8744. getIR: function Mesh_getIR() {
  8745. return ['Mesh', this.shadingType, this.coords, this.colors, this.figures,
  8746. this.bounds, this.matrix, this.bbox, this.background];
  8747. }
  8748. };
  8749. return Mesh;
  8750. })();
  8751. Shadings.Dummy = (function DummyClosure() {
  8752. function Dummy() {
  8753. this.type = 'Pattern';
  8754. }
  8755. Dummy.prototype = {
  8756. getIR: function Dummy_getIR() {
  8757. return ['Dummy'];
  8758. }
  8759. };
  8760. return Dummy;
  8761. })();
  8762. function getTilingPatternIR(operatorList, dict, args) {
  8763. var matrix = dict.get('Matrix');
  8764. var bbox = dict.get('BBox');
  8765. var xstep = dict.get('XStep');
  8766. var ystep = dict.get('YStep');
  8767. var paintType = dict.get('PaintType');
  8768. var tilingType = dict.get('TilingType');
  8769. return [
  8770. 'TilingPattern', args, operatorList, matrix, bbox, xstep, ystep,
  8771. paintType, tilingType
  8772. ];
  8773. }
  8774. var PartialEvaluator = (function PartialEvaluatorClosure() {
  8775. function PartialEvaluator(pdfManager, xref, handler, pageIndex,
  8776. uniquePrefix, idCounters, fontCache) {
  8777. this.pdfManager = pdfManager;
  8778. this.xref = xref;
  8779. this.handler = handler;
  8780. this.pageIndex = pageIndex;
  8781. this.uniquePrefix = uniquePrefix;
  8782. this.idCounters = idCounters;
  8783. this.fontCache = fontCache;
  8784. }
  8785. // Trying to minimize Date.now() usage and check every 100 time
  8786. var TIME_SLOT_DURATION_MS = 20;
  8787. var CHECK_TIME_EVERY = 100;
  8788. function TimeSlotManager() {
  8789. this.reset();
  8790. }
  8791. TimeSlotManager.prototype = {
  8792. check: function TimeSlotManager_check() {
  8793. if (++this.checked < CHECK_TIME_EVERY) {
  8794. return false;
  8795. }
  8796. this.checked = 0;
  8797. return this.endTime <= Date.now();
  8798. },
  8799. reset: function TimeSlotManager_reset() {
  8800. this.endTime = Date.now() + TIME_SLOT_DURATION_MS;
  8801. this.checked = 0;
  8802. }
  8803. };
  8804. var deferred = Promise.resolve();
  8805. var TILING_PATTERN = 1, SHADING_PATTERN = 2;
  8806. PartialEvaluator.prototype = {
  8807. hasBlendModes: function PartialEvaluator_hasBlendModes(resources) {
  8808. if (!isDict(resources)) {
  8809. return false;
  8810. }
  8811. var processed = Object.create(null);
  8812. if (resources.objId) {
  8813. processed[resources.objId] = true;
  8814. }
  8815. var nodes = [resources];
  8816. while (nodes.length) {
  8817. var key;
  8818. var node = nodes.shift();
  8819. // First check the current resources for blend modes.
  8820. var graphicStates = node.get('ExtGState');
  8821. if (isDict(graphicStates)) {
  8822. graphicStates = graphicStates.getAll();
  8823. for (key in graphicStates) {
  8824. var graphicState = graphicStates[key];
  8825. var bm = graphicState['BM'];
  8826. if (isName(bm) && bm.name !== 'Normal') {
  8827. return true;
  8828. }
  8829. }
  8830. }
  8831. // Descend into the XObjects to look for more resources and blend modes.
  8832. var xObjects = node.get('XObject');
  8833. if (!isDict(xObjects)) {
  8834. continue;
  8835. }
  8836. xObjects = xObjects.getAll();
  8837. for (key in xObjects) {
  8838. var xObject = xObjects[key];
  8839. if (!isStream(xObject)) {
  8840. continue;
  8841. }
  8842. if (xObject.dict.objId) {
  8843. if (processed[xObject.dict.objId]) {
  8844. // stream has objId and is processed already
  8845. continue;
  8846. }
  8847. processed[xObject.dict.objId] = true;
  8848. }
  8849. var xResources = xObject.dict.get('Resources');
  8850. // Checking objId to detect an infinite loop.
  8851. if (isDict(xResources) &&
  8852. (!xResources.objId || !processed[xResources.objId])) {
  8853. nodes.push(xResources);
  8854. if (xResources.objId) {
  8855. processed[xResources.objId] = true;
  8856. }
  8857. }
  8858. }
  8859. }
  8860. return false;
  8861. },
  8862. buildFormXObject: function PartialEvaluator_buildFormXObject(resources,
  8863. xobj, smask,
  8864. operatorList,
  8865. initialState) {
  8866. var matrix = xobj.dict.get('Matrix');
  8867. var bbox = xobj.dict.get('BBox');
  8868. var group = xobj.dict.get('Group');
  8869. if (group) {
  8870. var groupOptions = {
  8871. matrix: matrix,
  8872. bbox: bbox,
  8873. smask: smask,
  8874. isolated: false,
  8875. knockout: false
  8876. };
  8877. var groupSubtype = group.get('S');
  8878. var colorSpace;
  8879. if (isName(groupSubtype) && groupSubtype.name === 'Transparency') {
  8880. groupOptions.isolated = (group.get('I') || false);
  8881. groupOptions.knockout = (group.get('K') || false);
  8882. colorSpace = (group.has('CS') ?
  8883. ColorSpace.parse(group.get('CS'), this.xref, resources) : null);
  8884. }
  8885. if (smask && smask.backdrop) {
  8886. colorSpace = colorSpace || ColorSpace.singletons.rgb;
  8887. smask.backdrop = colorSpace.getRgb(smask.backdrop, 0);
  8888. }
  8889. operatorList.addOp(OPS.beginGroup, [groupOptions]);
  8890. }
  8891. operatorList.addOp(OPS.paintFormXObjectBegin, [matrix, bbox]);
  8892. return this.getOperatorList(xobj,
  8893. (xobj.dict.get('Resources') || resources), operatorList, initialState).
  8894. then(function () {
  8895. operatorList.addOp(OPS.paintFormXObjectEnd, []);
  8896. if (group) {
  8897. operatorList.addOp(OPS.endGroup, [groupOptions]);
  8898. }
  8899. });
  8900. },
  8901. buildPaintImageXObject:
  8902. function PartialEvaluator_buildPaintImageXObject(resources, image,
  8903. inline, operatorList,
  8904. cacheKey, cache) {
  8905. var self = this;
  8906. var dict = image.dict;
  8907. var w = dict.get('Width', 'W');
  8908. var h = dict.get('Height', 'H');
  8909. if (!(w && isNum(w)) || !(h && isNum(h))) {
  8910. warn('Image dimensions are missing, or not numbers.');
  8911. return;
  8912. }
  8913. if (PDFJS.maxImageSize !== -1 && w * h > PDFJS.maxImageSize) {
  8914. warn('Image exceeded maximum allowed size and was removed.');
  8915. return;
  8916. }
  8917. var imageMask = (dict.get('ImageMask', 'IM') || false);
  8918. var imgData, args;
  8919. if (imageMask) {
  8920. // This depends on a tmpCanvas being filled with the
  8921. // current fillStyle, such that processing the pixel
  8922. // data can't be done here. Instead of creating a
  8923. // complete PDFImage, only read the information needed
  8924. // for later.
  8925. var width = dict.get('Width', 'W');
  8926. var height = dict.get('Height', 'H');
  8927. var bitStrideLength = (width + 7) >> 3;
  8928. var imgArray = image.getBytes(bitStrideLength * height);
  8929. var decode = dict.get('Decode', 'D');
  8930. var inverseDecode = (!!decode && decode[0] > 0);
  8931. imgData = PDFImage.createMask(imgArray, width, height,
  8932. image instanceof DecodeStream,
  8933. inverseDecode);
  8934. imgData.cached = true;
  8935. args = [imgData];
  8936. operatorList.addOp(OPS.paintImageMaskXObject, args);
  8937. if (cacheKey) {
  8938. cache.key = cacheKey;
  8939. cache.fn = OPS.paintImageMaskXObject;
  8940. cache.args = args;
  8941. }
  8942. return;
  8943. }
  8944. var softMask = (dict.get('SMask', 'SM') || false);
  8945. var mask = (dict.get('Mask') || false);
  8946. var SMALL_IMAGE_DIMENSIONS = 200;
  8947. // Inlining small images into the queue as RGB data
  8948. if (inline && !softMask && !mask && !(image instanceof JpegStream) &&
  8949. (w + h) < SMALL_IMAGE_DIMENSIONS) {
  8950. var imageObj = new PDFImage(this.xref, resources, image,
  8951. inline, null, null);
  8952. // We force the use of RGBA_32BPP images here, because we can't handle
  8953. // any other kind.
  8954. imgData = imageObj.createImageData(/* forceRGBA = */ true);
  8955. operatorList.addOp(OPS.paintInlineImageXObject, [imgData]);
  8956. return;
  8957. }
  8958. // If there is no imageMask, create the PDFImage and a lot
  8959. // of image processing can be done here.
  8960. var uniquePrefix = (this.uniquePrefix || '');
  8961. var objId = 'img_' + uniquePrefix + (++this.idCounters.obj);
  8962. operatorList.addDependency(objId);
  8963. args = [objId, w, h];
  8964. if (!softMask && !mask && image instanceof JpegStream &&
  8965. image.isNativelySupported(this.xref, resources)) {
  8966. // These JPEGs don't need any more processing so we can just send it.
  8967. operatorList.addOp(OPS.paintJpegXObject, args);
  8968. this.handler.send('obj',
  8969. [objId, this.pageIndex, 'JpegStream', image.getIR()]);
  8970. return;
  8971. }
  8972. PDFImage.buildImage(self.handler, self.xref, resources, image, inline).
  8973. then(function(imageObj) {
  8974. var imgData = imageObj.createImageData(/* forceRGBA = */ false);
  8975. self.handler.send('obj', [objId, self.pageIndex, 'Image', imgData],
  8976. [imgData.data.buffer]);
  8977. }).then(null, function (reason) {
  8978. warn('Unable to decode image: ' + reason);
  8979. self.handler.send('obj', [objId, self.pageIndex, 'Image', null]);
  8980. });
  8981. operatorList.addOp(OPS.paintImageXObject, args);
  8982. if (cacheKey) {
  8983. cache.key = cacheKey;
  8984. cache.fn = OPS.paintImageXObject;
  8985. cache.args = args;
  8986. }
  8987. },
  8988. handleSMask: function PartialEvaluator_handleSmask(smask, resources,
  8989. operatorList,
  8990. stateManager) {
  8991. var smaskContent = smask.get('G');
  8992. var smaskOptions = {
  8993. subtype: smask.get('S').name,
  8994. backdrop: smask.get('BC')
  8995. };
  8996. return this.buildFormXObject(resources, smaskContent, smaskOptions,
  8997. operatorList, stateManager.state.clone());
  8998. },
  8999. handleTilingType:
  9000. function PartialEvaluator_handleTilingType(fn, args, resources,
  9001. pattern, patternDict,
  9002. operatorList) {
  9003. // Create an IR of the pattern code.
  9004. var tilingOpList = new OperatorList();
  9005. return this.getOperatorList(pattern,
  9006. (patternDict.get('Resources') || resources), tilingOpList).
  9007. then(function () {
  9008. // Add the dependencies to the parent operator list so they are
  9009. // resolved before sub operator list is executed synchronously.
  9010. operatorList.addDependencies(tilingOpList.dependencies);
  9011. operatorList.addOp(fn, getTilingPatternIR({
  9012. fnArray: tilingOpList.fnArray,
  9013. argsArray: tilingOpList.argsArray
  9014. }, patternDict, args));
  9015. });
  9016. },
  9017. handleSetFont:
  9018. function PartialEvaluator_handleSetFont(resources, fontArgs, fontRef,
  9019. operatorList, state) {
  9020. // TODO(mack): Not needed?
  9021. var fontName;
  9022. if (fontArgs) {
  9023. fontArgs = fontArgs.slice();
  9024. fontName = fontArgs[0].name;
  9025. }
  9026. var self = this;
  9027. return this.loadFont(fontName, fontRef, this.xref, resources).then(
  9028. function (translated) {
  9029. if (!translated.font.isType3Font) {
  9030. return translated;
  9031. }
  9032. return translated.loadType3Data(self, resources, operatorList).then(
  9033. function () {
  9034. return translated;
  9035. });
  9036. }).then(function (translated) {
  9037. state.font = translated.font;
  9038. translated.send(self.handler);
  9039. return translated.loadedName;
  9040. });
  9041. },
  9042. handleText: function PartialEvaluator_handleText(chars, state) {
  9043. var font = state.font;
  9044. var glyphs = font.charsToGlyphs(chars);
  9045. var isAddToPathSet = !!(state.textRenderingMode &
  9046. TextRenderingMode.ADD_TO_PATH_FLAG);
  9047. if (font.data && (isAddToPathSet || PDFJS.disableFontFace)) {
  9048. var buildPath = function (fontChar) {
  9049. if (!font.renderer.hasBuiltPath(fontChar)) {
  9050. var path = font.renderer.getPathJs(fontChar);
  9051. this.handler.send('commonobj', [
  9052. font.loadedName + '_path_' + fontChar,
  9053. 'FontPath',
  9054. path
  9055. ]);
  9056. }
  9057. }.bind(this);
  9058. for (var i = 0, ii = glyphs.length; i < ii; i++) {
  9059. var glyph = glyphs[i];
  9060. if (glyph === null) {
  9061. continue;
  9062. }
  9063. buildPath(glyph.fontChar);
  9064. // If the glyph has an accent we need to build a path for its
  9065. // fontChar too, otherwise CanvasGraphics_paintChar will fail.
  9066. var accent = glyph.accent;
  9067. if (accent && accent.fontChar) {
  9068. buildPath(accent.fontChar);
  9069. }
  9070. }
  9071. }
  9072. return glyphs;
  9073. },
  9074. setGState: function PartialEvaluator_setGState(resources, gState,
  9075. operatorList, xref,
  9076. stateManager) {
  9077. // TODO(mack): This should be rewritten so that this function returns
  9078. // what should be added to the queue during each iteration
  9079. function setGStateForKey(gStateObj, key, value) {
  9080. switch (key) {
  9081. case 'Type':
  9082. break;
  9083. case 'LW':
  9084. case 'LC':
  9085. case 'LJ':
  9086. case 'ML':
  9087. case 'D':
  9088. case 'RI':
  9089. case 'FL':
  9090. case 'CA':
  9091. case 'ca':
  9092. gStateObj.push([key, value]);
  9093. break;
  9094. case 'Font':
  9095. promise = promise.then(function () {
  9096. return self.handleSetFont(resources, null, value[0],
  9097. operatorList, stateManager.state).
  9098. then(function (loadedName) {
  9099. operatorList.addDependency(loadedName);
  9100. gStateObj.push([key, [loadedName, value[1]]]);
  9101. });
  9102. });
  9103. break;
  9104. case 'BM':
  9105. gStateObj.push([key, value]);
  9106. break;
  9107. case 'SMask':
  9108. if (isName(value) && value.name === 'None') {
  9109. gStateObj.push([key, false]);
  9110. break;
  9111. }
  9112. var dict = xref.fetchIfRef(value);
  9113. if (isDict(dict)) {
  9114. promise = promise.then(function () {
  9115. return self.handleSMask(dict, resources, operatorList,
  9116. stateManager);
  9117. });
  9118. gStateObj.push([key, true]);
  9119. } else {
  9120. warn('Unsupported SMask type');
  9121. }
  9122. break;
  9123. // Only generate info log messages for the following since
  9124. // they are unlikey to have a big impact on the rendering.
  9125. case 'OP':
  9126. case 'op':
  9127. case 'OPM':
  9128. case 'BG':
  9129. case 'BG2':
  9130. case 'UCR':
  9131. case 'UCR2':
  9132. case 'TR':
  9133. case 'TR2':
  9134. case 'HT':
  9135. case 'SM':
  9136. case 'SA':
  9137. case 'AIS':
  9138. case 'TK':
  9139. // TODO implement these operators.
  9140. info('graphic state operator ' + key);
  9141. break;
  9142. default:
  9143. info('Unknown graphic state operator ' + key);
  9144. break;
  9145. }
  9146. }
  9147. // This array holds the converted/processed state data.
  9148. var gStateObj = [];
  9149. var gStateMap = gState.map;
  9150. var self = this;
  9151. var promise = Promise.resolve();
  9152. for (var key in gStateMap) {
  9153. var value = gStateMap[key];
  9154. setGStateForKey(gStateObj, key, value);
  9155. }
  9156. return promise.then(function () {
  9157. operatorList.addOp(OPS.setGState, [gStateObj]);
  9158. });
  9159. },
  9160. loadFont: function PartialEvaluator_loadFont(fontName, font, xref,
  9161. resources) {
  9162. function errorFont() {
  9163. return Promise.resolve(new TranslatedFont('g_font_error',
  9164. new ErrorFont('Font ' + fontName + ' is not available'), font));
  9165. }
  9166. var fontRef;
  9167. if (font) { // Loading by ref.
  9168. assert(isRef(font));
  9169. fontRef = font;
  9170. } else { // Loading by name.
  9171. var fontRes = resources.get('Font');
  9172. if (fontRes) {
  9173. fontRef = fontRes.getRaw(fontName);
  9174. } else {
  9175. warn('fontRes not available');
  9176. return errorFont();
  9177. }
  9178. }
  9179. if (!fontRef) {
  9180. warn('fontRef not available');
  9181. return errorFont();
  9182. }
  9183. if (this.fontCache.has(fontRef)) {
  9184. return this.fontCache.get(fontRef);
  9185. }
  9186. font = xref.fetchIfRef(fontRef);
  9187. if (!isDict(font)) {
  9188. return errorFont();
  9189. }
  9190. // We are holding font.translated references just for fontRef that are not
  9191. // dictionaries (Dict). See explanation below.
  9192. if (font.translated) {
  9193. return font.translated;
  9194. }
  9195. var fontCapability = createPromiseCapability();
  9196. var preEvaluatedFont = this.preEvaluateFont(font, xref);
  9197. var descriptor = preEvaluatedFont.descriptor;
  9198. var fontID = fontRef.num + '_' + fontRef.gen;
  9199. if (isDict(descriptor)) {
  9200. if (!descriptor.fontAliases) {
  9201. descriptor.fontAliases = Object.create(null);
  9202. }
  9203. var fontAliases = descriptor.fontAliases;
  9204. var hash = preEvaluatedFont.hash;
  9205. if (fontAliases[hash]) {
  9206. var aliasFontRef = fontAliases[hash].aliasRef;
  9207. if (aliasFontRef && this.fontCache.has(aliasFontRef)) {
  9208. this.fontCache.putAlias(fontRef, aliasFontRef);
  9209. return this.fontCache.get(fontRef);
  9210. }
  9211. }
  9212. if (!fontAliases[hash]) {
  9213. fontAliases[hash] = {
  9214. fontID: Font.getFontID()
  9215. };
  9216. }
  9217. fontAliases[hash].aliasRef = fontRef;
  9218. fontID = fontAliases[hash].fontID;
  9219. }
  9220. // Workaround for bad PDF generators that don't reference fonts
  9221. // properly, i.e. by not using an object identifier.
  9222. // Check if the fontRef is a Dict (as opposed to a standard object),
  9223. // in which case we don't cache the font and instead reference it by
  9224. // fontName in font.loadedName below.
  9225. var fontRefIsDict = isDict(fontRef);
  9226. if (!fontRefIsDict) {
  9227. this.fontCache.put(fontRef, fontCapability.promise);
  9228. }
  9229. // Keep track of each font we translated so the caller can
  9230. // load them asynchronously before calling display on a page.
  9231. font.loadedName = 'g_font_' + (fontRefIsDict ?
  9232. fontName.replace(/\W/g, '') : fontID);
  9233. font.translated = fontCapability.promise;
  9234. // TODO move promises into translate font
  9235. var translatedPromise;
  9236. try {
  9237. translatedPromise = Promise.resolve(
  9238. this.translateFont(preEvaluatedFont, xref));
  9239. } catch (e) {
  9240. translatedPromise = Promise.reject(e);
  9241. }
  9242. translatedPromise.then(function (translatedFont) {
  9243. if (translatedFont.fontType !== undefined) {
  9244. var xrefFontStats = xref.stats.fontTypes;
  9245. xrefFontStats[translatedFont.fontType] = true;
  9246. }
  9247. fontCapability.resolve(new TranslatedFont(font.loadedName,
  9248. translatedFont, font));
  9249. }, function (reason) {
  9250. // TODO fontCapability.reject?
  9251. UnsupportedManager.notify(UNSUPPORTED_FEATURES.font);
  9252. try {
  9253. // error, but it's still nice to have font type reported
  9254. var descriptor = preEvaluatedFont.descriptor;
  9255. var fontFile3 = descriptor && descriptor.get('FontFile3');
  9256. var subtype = fontFile3 && fontFile3.get('Subtype');
  9257. var fontType = getFontType(preEvaluatedFont.type,
  9258. subtype && subtype.name);
  9259. var xrefFontStats = xref.stats.fontTypes;
  9260. xrefFontStats[fontType] = true;
  9261. } catch (ex) { }
  9262. fontCapability.resolve(new TranslatedFont(font.loadedName,
  9263. new ErrorFont(reason instanceof Error ? reason.message : reason),
  9264. font));
  9265. });
  9266. return fontCapability.promise;
  9267. },
  9268. buildPath: function PartialEvaluator_buildPath(operatorList, fn, args) {
  9269. var lastIndex = operatorList.length - 1;
  9270. if (lastIndex < 0 ||
  9271. operatorList.fnArray[lastIndex] !== OPS.constructPath) {
  9272. operatorList.addOp(OPS.constructPath, [[fn], args]);
  9273. } else {
  9274. var opArgs = operatorList.argsArray[lastIndex];
  9275. opArgs[0].push(fn);
  9276. Array.prototype.push.apply(opArgs[1], args);
  9277. }
  9278. },
  9279. handleColorN: function PartialEvaluator_handleColorN(operatorList, fn, args,
  9280. cs, patterns, resources, xref) {
  9281. // compile tiling patterns
  9282. var patternName = args[args.length - 1];
  9283. // SCN/scn applies patterns along with normal colors
  9284. var pattern;
  9285. if (isName(patternName) &&
  9286. (pattern = patterns.get(patternName.name))) {
  9287. var dict = (isStream(pattern) ? pattern.dict : pattern);
  9288. var typeNum = dict.get('PatternType');
  9289. if (typeNum === TILING_PATTERN) {
  9290. var color = cs.base ? cs.base.getRgb(args, 0) : null;
  9291. return this.handleTilingType(fn, color, resources, pattern,
  9292. dict, operatorList);
  9293. } else if (typeNum === SHADING_PATTERN) {
  9294. var shading = dict.get('Shading');
  9295. var matrix = dict.get('Matrix');
  9296. pattern = Pattern.parseShading(shading, matrix, xref, resources);
  9297. operatorList.addOp(fn, pattern.getIR());
  9298. return Promise.resolve();
  9299. } else {
  9300. return Promise.reject('Unknown PatternType: ' + typeNum);
  9301. }
  9302. }
  9303. // TODO shall we fail here?
  9304. operatorList.addOp(fn, args);
  9305. return Promise.resolve();
  9306. },
  9307. getOperatorList: function PartialEvaluator_getOperatorList(stream,
  9308. resources,
  9309. operatorList,
  9310. initialState) {
  9311. var self = this;
  9312. var xref = this.xref;
  9313. var imageCache = {};
  9314. assert(operatorList);
  9315. resources = (resources || Dict.empty);
  9316. var xobjs = (resources.get('XObject') || Dict.empty);
  9317. var patterns = (resources.get('Pattern') || Dict.empty);
  9318. var stateManager = new StateManager(initialState || new EvalState());
  9319. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  9320. var timeSlotManager = new TimeSlotManager();
  9321. return new Promise(function next(resolve, reject) {
  9322. timeSlotManager.reset();
  9323. var stop, operation = {}, i, ii, cs;
  9324. while (!(stop = timeSlotManager.check()) &&
  9325. preprocessor.read(operation)) {
  9326. var args = operation.args;
  9327. var fn = operation.fn;
  9328. switch (fn | 0) {
  9329. case OPS.paintXObject:
  9330. if (args[0].code) {
  9331. break;
  9332. }
  9333. // eagerly compile XForm objects
  9334. var name = args[0].name;
  9335. if (imageCache.key === name) {
  9336. operatorList.addOp(imageCache.fn, imageCache.args);
  9337. args = null;
  9338. continue;
  9339. }
  9340. var xobj = xobjs.get(name);
  9341. if (xobj) {
  9342. assert(isStream(xobj), 'XObject should be a stream');
  9343. var type = xobj.dict.get('Subtype');
  9344. assert(isName(type),
  9345. 'XObject should have a Name subtype');
  9346. if (type.name === 'Form') {
  9347. stateManager.save();
  9348. return self.buildFormXObject(resources, xobj, null,
  9349. operatorList,
  9350. stateManager.state.clone()).
  9351. then(function () {
  9352. stateManager.restore();
  9353. next(resolve, reject);
  9354. }, reject);
  9355. } else if (type.name === 'Image') {
  9356. self.buildPaintImageXObject(resources, xobj, false,
  9357. operatorList, name, imageCache);
  9358. args = null;
  9359. continue;
  9360. } else if (type.name === 'PS') {
  9361. // PostScript XObjects are unused when viewing documents.
  9362. // See section 4.7.1 of Adobe's PDF reference.
  9363. info('Ignored XObject subtype PS');
  9364. continue;
  9365. } else {
  9366. error('Unhandled XObject subtype ' + type.name);
  9367. }
  9368. }
  9369. break;
  9370. case OPS.setFont:
  9371. var fontSize = args[1];
  9372. // eagerly collect all fonts
  9373. return self.handleSetFont(resources, args, null,
  9374. operatorList, stateManager.state).
  9375. then(function (loadedName) {
  9376. operatorList.addDependency(loadedName);
  9377. operatorList.addOp(OPS.setFont, [loadedName, fontSize]);
  9378. next(resolve, reject);
  9379. }, reject);
  9380. case OPS.endInlineImage:
  9381. var cacheKey = args[0].cacheKey;
  9382. if (cacheKey && imageCache.key === cacheKey) {
  9383. operatorList.addOp(imageCache.fn, imageCache.args);
  9384. args = null;
  9385. continue;
  9386. }
  9387. self.buildPaintImageXObject(resources, args[0], true,
  9388. operatorList, cacheKey, imageCache);
  9389. args = null;
  9390. continue;
  9391. case OPS.showText:
  9392. args[0] = self.handleText(args[0], stateManager.state);
  9393. break;
  9394. case OPS.showSpacedText:
  9395. var arr = args[0];
  9396. var combinedGlyphs = [];
  9397. var arrLength = arr.length;
  9398. for (i = 0; i < arrLength; ++i) {
  9399. var arrItem = arr[i];
  9400. if (isString(arrItem)) {
  9401. Array.prototype.push.apply(combinedGlyphs,
  9402. self.handleText(arrItem, stateManager.state));
  9403. } else if (isNum(arrItem)) {
  9404. combinedGlyphs.push(arrItem);
  9405. }
  9406. }
  9407. args[0] = combinedGlyphs;
  9408. fn = OPS.showText;
  9409. break;
  9410. case OPS.nextLineShowText:
  9411. operatorList.addOp(OPS.nextLine);
  9412. args[0] = self.handleText(args[0], stateManager.state);
  9413. fn = OPS.showText;
  9414. break;
  9415. case OPS.nextLineSetSpacingShowText:
  9416. operatorList.addOp(OPS.nextLine);
  9417. operatorList.addOp(OPS.setWordSpacing, [args.shift()]);
  9418. operatorList.addOp(OPS.setCharSpacing, [args.shift()]);
  9419. args[0] = self.handleText(args[0], stateManager.state);
  9420. fn = OPS.showText;
  9421. break;
  9422. case OPS.setTextRenderingMode:
  9423. stateManager.state.textRenderingMode = args[0];
  9424. break;
  9425. case OPS.setFillColorSpace:
  9426. stateManager.state.fillColorSpace =
  9427. ColorSpace.parse(args[0], xref, resources);
  9428. continue;
  9429. case OPS.setStrokeColorSpace:
  9430. stateManager.state.strokeColorSpace =
  9431. ColorSpace.parse(args[0], xref, resources);
  9432. continue;
  9433. case OPS.setFillColor:
  9434. cs = stateManager.state.fillColorSpace;
  9435. args = cs.getRgb(args, 0);
  9436. fn = OPS.setFillRGBColor;
  9437. break;
  9438. case OPS.setStrokeColor:
  9439. cs = stateManager.state.strokeColorSpace;
  9440. args = cs.getRgb(args, 0);
  9441. fn = OPS.setStrokeRGBColor;
  9442. break;
  9443. case OPS.setFillGray:
  9444. stateManager.state.fillColorSpace = ColorSpace.singletons.gray;
  9445. args = ColorSpace.singletons.gray.getRgb(args, 0);
  9446. fn = OPS.setFillRGBColor;
  9447. break;
  9448. case OPS.setStrokeGray:
  9449. stateManager.state.strokeColorSpace = ColorSpace.singletons.gray;
  9450. args = ColorSpace.singletons.gray.getRgb(args, 0);
  9451. fn = OPS.setStrokeRGBColor;
  9452. break;
  9453. case OPS.setFillCMYKColor:
  9454. stateManager.state.fillColorSpace = ColorSpace.singletons.cmyk;
  9455. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  9456. fn = OPS.setFillRGBColor;
  9457. break;
  9458. case OPS.setStrokeCMYKColor:
  9459. stateManager.state.strokeColorSpace = ColorSpace.singletons.cmyk;
  9460. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  9461. fn = OPS.setStrokeRGBColor;
  9462. break;
  9463. case OPS.setFillRGBColor:
  9464. stateManager.state.fillColorSpace = ColorSpace.singletons.rgb;
  9465. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  9466. break;
  9467. case OPS.setStrokeRGBColor:
  9468. stateManager.state.strokeColorSpace = ColorSpace.singletons.rgb;
  9469. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  9470. break;
  9471. case OPS.setFillColorN:
  9472. cs = stateManager.state.fillColorSpace;
  9473. if (cs.name === 'Pattern') {
  9474. return self.handleColorN(operatorList, OPS.setFillColorN,
  9475. args, cs, patterns, resources, xref).then(function() {
  9476. next(resolve, reject);
  9477. }, reject);
  9478. }
  9479. args = cs.getRgb(args, 0);
  9480. fn = OPS.setFillRGBColor;
  9481. break;
  9482. case OPS.setStrokeColorN:
  9483. cs = stateManager.state.strokeColorSpace;
  9484. if (cs.name === 'Pattern') {
  9485. return self.handleColorN(operatorList, OPS.setStrokeColorN,
  9486. args, cs, patterns, resources, xref).then(function() {
  9487. next(resolve, reject);
  9488. }, reject);
  9489. }
  9490. args = cs.getRgb(args, 0);
  9491. fn = OPS.setStrokeRGBColor;
  9492. break;
  9493. case OPS.shadingFill:
  9494. var shadingRes = resources.get('Shading');
  9495. if (!shadingRes) {
  9496. error('No shading resource found');
  9497. }
  9498. var shading = shadingRes.get(args[0].name);
  9499. if (!shading) {
  9500. error('No shading object found');
  9501. }
  9502. var shadingFill = Pattern.parseShading(shading, null, xref,
  9503. resources);
  9504. var patternIR = shadingFill.getIR();
  9505. args = [patternIR];
  9506. fn = OPS.shadingFill;
  9507. break;
  9508. case OPS.setGState:
  9509. var dictName = args[0];
  9510. var extGState = resources.get('ExtGState');
  9511. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  9512. break;
  9513. }
  9514. var gState = extGState.get(dictName.name);
  9515. return self.setGState(resources, gState, operatorList, xref,
  9516. stateManager).then(function() {
  9517. next(resolve, reject);
  9518. }, reject);
  9519. case OPS.moveTo:
  9520. case OPS.lineTo:
  9521. case OPS.curveTo:
  9522. case OPS.curveTo2:
  9523. case OPS.curveTo3:
  9524. case OPS.closePath:
  9525. self.buildPath(operatorList, fn, args);
  9526. continue;
  9527. case OPS.rectangle:
  9528. self.buildPath(operatorList, fn, args);
  9529. continue;
  9530. }
  9531. operatorList.addOp(fn, args);
  9532. }
  9533. if (stop) {
  9534. deferred.then(function () {
  9535. next(resolve, reject);
  9536. });
  9537. return;
  9538. }
  9539. // Some PDFs don't close all restores inside object/form.
  9540. // Closing those for them.
  9541. for (i = 0, ii = preprocessor.savedStatesDepth; i < ii; i++) {
  9542. operatorList.addOp(OPS.restore, []);
  9543. }
  9544. resolve();
  9545. });
  9546. },
  9547. getTextContent: function PartialEvaluator_getTextContent(stream, resources,
  9548. stateManager) {
  9549. stateManager = (stateManager || new StateManager(new TextState()));
  9550. var textContent = {
  9551. items: [],
  9552. styles: Object.create(null)
  9553. };
  9554. var bidiTexts = textContent.items;
  9555. var SPACE_FACTOR = 0.35;
  9556. var MULTI_SPACE_FACTOR = 1.5;
  9557. var self = this;
  9558. var xref = this.xref;
  9559. resources = (xref.fetchIfRef(resources) || Dict.empty);
  9560. // The xobj is parsed iff it's needed, e.g. if there is a `DO` cmd.
  9561. var xobjs = null;
  9562. var xobjsCache = {};
  9563. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  9564. var textState;
  9565. function newTextChunk() {
  9566. var font = textState.font;
  9567. if (!(font.loadedName in textContent.styles)) {
  9568. textContent.styles[font.loadedName] = {
  9569. fontFamily: font.fallbackName,
  9570. ascent: font.ascent,
  9571. descent: font.descent,
  9572. vertical: font.vertical
  9573. };
  9574. }
  9575. return {
  9576. // |str| is initially an array which we push individual chars to, and
  9577. // then runBidi() overwrites it with the final string.
  9578. str: [],
  9579. dir: null,
  9580. width: 0,
  9581. height: 0,
  9582. transform: null,
  9583. fontName: font.loadedName
  9584. };
  9585. }
  9586. function runBidi(textChunk) {
  9587. var str = textChunk.str.join('');
  9588. var bidiResult = PDFJS.bidi(str, -1, textState.font.vertical);
  9589. textChunk.str = bidiResult.str;
  9590. textChunk.dir = bidiResult.dir;
  9591. return textChunk;
  9592. }
  9593. function handleSetFont(fontName, fontRef) {
  9594. return self.loadFont(fontName, fontRef, xref, resources).
  9595. then(function (translated) {
  9596. textState.font = translated.font;
  9597. textState.fontMatrix = translated.font.fontMatrix ||
  9598. FONT_IDENTITY_MATRIX;
  9599. });
  9600. }
  9601. function buildTextGeometry(chars, textChunk) {
  9602. var font = textState.font;
  9603. textChunk = textChunk || newTextChunk();
  9604. if (!textChunk.transform) {
  9605. // 9.4.4 Text Space Details
  9606. var tsm = [textState.fontSize * textState.textHScale, 0,
  9607. 0, textState.fontSize,
  9608. 0, textState.textRise];
  9609. var trm = textChunk.transform = Util.transform(textState.ctm,
  9610. Util.transform(textState.textMatrix, tsm));
  9611. if (!font.vertical) {
  9612. textChunk.height = Math.sqrt(trm[2] * trm[2] + trm[3] * trm[3]);
  9613. } else {
  9614. textChunk.width = Math.sqrt(trm[0] * trm[0] + trm[1] * trm[1]);
  9615. }
  9616. }
  9617. var width = 0;
  9618. var height = 0;
  9619. var glyphs = font.charsToGlyphs(chars);
  9620. var defaultVMetrics = font.defaultVMetrics;
  9621. for (var i = 0; i < glyphs.length; i++) {
  9622. var glyph = glyphs[i];
  9623. if (!glyph) { // Previous glyph was a space.
  9624. width += textState.wordSpacing * textState.textHScale;
  9625. continue;
  9626. }
  9627. var vMetricX = null;
  9628. var vMetricY = null;
  9629. var glyphWidth = null;
  9630. if (font.vertical) {
  9631. if (glyph.vmetric) {
  9632. glyphWidth = glyph.vmetric[0];
  9633. vMetricX = glyph.vmetric[1];
  9634. vMetricY = glyph.vmetric[2];
  9635. } else {
  9636. glyphWidth = glyph.width;
  9637. vMetricX = glyph.width * 0.5;
  9638. vMetricY = defaultVMetrics[2];
  9639. }
  9640. } else {
  9641. glyphWidth = glyph.width;
  9642. }
  9643. var glyphUnicode = glyph.unicode;
  9644. if (NormalizedUnicodes[glyphUnicode] !== undefined) {
  9645. glyphUnicode = NormalizedUnicodes[glyphUnicode];
  9646. }
  9647. glyphUnicode = reverseIfRtl(glyphUnicode);
  9648. // The following will calculate the x and y of the individual glyphs.
  9649. // if (font.vertical) {
  9650. // tsm[4] -= vMetricX * Math.abs(textState.fontSize) *
  9651. // textState.fontMatrix[0];
  9652. // tsm[5] -= vMetricY * textState.fontSize *
  9653. // textState.fontMatrix[0];
  9654. // }
  9655. // var trm = Util.transform(textState.textMatrix, tsm);
  9656. // var pt = Util.applyTransform([trm[4], trm[5]], textState.ctm);
  9657. // var x = pt[0];
  9658. // var y = pt[1];
  9659. var tx = 0;
  9660. var ty = 0;
  9661. if (!font.vertical) {
  9662. var w0 = glyphWidth * textState.fontMatrix[0];
  9663. tx = (w0 * textState.fontSize + textState.charSpacing) *
  9664. textState.textHScale;
  9665. width += tx;
  9666. } else {
  9667. var w1 = glyphWidth * textState.fontMatrix[0];
  9668. ty = w1 * textState.fontSize + textState.charSpacing;
  9669. height += ty;
  9670. }
  9671. textState.translateTextMatrix(tx, ty);
  9672. textChunk.str.push(glyphUnicode);
  9673. }
  9674. var a = textState.textLineMatrix[0];
  9675. var b = textState.textLineMatrix[1];
  9676. var scaleLineX = Math.sqrt(a * a + b * b);
  9677. a = textState.ctm[0];
  9678. b = textState.ctm[1];
  9679. var scaleCtmX = Math.sqrt(a * a + b * b);
  9680. if (!font.vertical) {
  9681. textChunk.width += width * scaleCtmX * scaleLineX;
  9682. } else {
  9683. textChunk.height += Math.abs(height * scaleCtmX * scaleLineX);
  9684. }
  9685. return textChunk;
  9686. }
  9687. var timeSlotManager = new TimeSlotManager();
  9688. return new Promise(function next(resolve, reject) {
  9689. timeSlotManager.reset();
  9690. var stop, operation = {};
  9691. while (!(stop = timeSlotManager.check()) &&
  9692. (preprocessor.read(operation))) {
  9693. textState = stateManager.state;
  9694. var fn = operation.fn;
  9695. var args = operation.args;
  9696. switch (fn | 0) {
  9697. case OPS.setFont:
  9698. textState.fontSize = args[1];
  9699. return handleSetFont(args[0].name).then(function() {
  9700. next(resolve, reject);
  9701. }, reject);
  9702. case OPS.setTextRise:
  9703. textState.textRise = args[0];
  9704. break;
  9705. case OPS.setHScale:
  9706. textState.textHScale = args[0] / 100;
  9707. break;
  9708. case OPS.setLeading:
  9709. textState.leading = args[0];
  9710. break;
  9711. case OPS.moveText:
  9712. textState.translateTextLineMatrix(args[0], args[1]);
  9713. textState.textMatrix = textState.textLineMatrix.slice();
  9714. break;
  9715. case OPS.setLeadingMoveText:
  9716. textState.leading = -args[1];
  9717. textState.translateTextLineMatrix(args[0], args[1]);
  9718. textState.textMatrix = textState.textLineMatrix.slice();
  9719. break;
  9720. case OPS.nextLine:
  9721. textState.carriageReturn();
  9722. break;
  9723. case OPS.setTextMatrix:
  9724. textState.setTextMatrix(args[0], args[1], args[2], args[3],
  9725. args[4], args[5]);
  9726. textState.setTextLineMatrix(args[0], args[1], args[2], args[3],
  9727. args[4], args[5]);
  9728. break;
  9729. case OPS.setCharSpacing:
  9730. textState.charSpacing = args[0];
  9731. break;
  9732. case OPS.setWordSpacing:
  9733. textState.wordSpacing = args[0];
  9734. break;
  9735. case OPS.beginText:
  9736. textState.textMatrix = IDENTITY_MATRIX.slice();
  9737. textState.textLineMatrix = IDENTITY_MATRIX.slice();
  9738. break;
  9739. case OPS.showSpacedText:
  9740. var items = args[0];
  9741. var textChunk = newTextChunk();
  9742. var offset;
  9743. for (var j = 0, jj = items.length; j < jj; j++) {
  9744. if (typeof items[j] === 'string') {
  9745. buildTextGeometry(items[j], textChunk);
  9746. } else {
  9747. var val = items[j] / 1000;
  9748. if (!textState.font.vertical) {
  9749. offset = -val * textState.fontSize * textState.textHScale *
  9750. textState.textMatrix[0];
  9751. textState.translateTextMatrix(offset, 0);
  9752. textChunk.width += offset;
  9753. } else {
  9754. offset = -val * textState.fontSize *
  9755. textState.textMatrix[3];
  9756. textState.translateTextMatrix(0, offset);
  9757. textChunk.height += offset;
  9758. }
  9759. if (items[j] < 0 && textState.font.spaceWidth > 0) {
  9760. var fakeSpaces = -items[j] / textState.font.spaceWidth;
  9761. if (fakeSpaces > MULTI_SPACE_FACTOR) {
  9762. fakeSpaces = Math.round(fakeSpaces);
  9763. while (fakeSpaces--) {
  9764. textChunk.str.push(' ');
  9765. }
  9766. } else if (fakeSpaces > SPACE_FACTOR) {
  9767. textChunk.str.push(' ');
  9768. }
  9769. }
  9770. }
  9771. }
  9772. bidiTexts.push(runBidi(textChunk));
  9773. break;
  9774. case OPS.showText:
  9775. bidiTexts.push(runBidi(buildTextGeometry(args[0])));
  9776. break;
  9777. case OPS.nextLineShowText:
  9778. textState.carriageReturn();
  9779. bidiTexts.push(runBidi(buildTextGeometry(args[0])));
  9780. break;
  9781. case OPS.nextLineSetSpacingShowText:
  9782. textState.wordSpacing = args[0];
  9783. textState.charSpacing = args[1];
  9784. textState.carriageReturn();
  9785. bidiTexts.push(runBidi(buildTextGeometry(args[2])));
  9786. break;
  9787. case OPS.paintXObject:
  9788. if (args[0].code) {
  9789. break;
  9790. }
  9791. if (!xobjs) {
  9792. xobjs = (resources.get('XObject') || Dict.empty);
  9793. }
  9794. var name = args[0].name;
  9795. if (xobjsCache.key === name) {
  9796. if (xobjsCache.texts) {
  9797. Util.appendToArray(bidiTexts, xobjsCache.texts.items);
  9798. Util.extendObj(textContent.styles, xobjsCache.texts.styles);
  9799. }
  9800. break;
  9801. }
  9802. var xobj = xobjs.get(name);
  9803. if (!xobj) {
  9804. break;
  9805. }
  9806. assert(isStream(xobj), 'XObject should be a stream');
  9807. var type = xobj.dict.get('Subtype');
  9808. assert(isName(type),
  9809. 'XObject should have a Name subtype');
  9810. if ('Form' !== type.name) {
  9811. xobjsCache.key = name;
  9812. xobjsCache.texts = null;
  9813. break;
  9814. }
  9815. stateManager.save();
  9816. var matrix = xobj.dict.get('Matrix');
  9817. if (isArray(matrix) && matrix.length === 6) {
  9818. stateManager.transform(matrix);
  9819. }
  9820. return self.getTextContent(xobj,
  9821. xobj.dict.get('Resources') || resources, stateManager).
  9822. then(function (formTextContent) {
  9823. Util.appendToArray(bidiTexts, formTextContent.items);
  9824. Util.extendObj(textContent.styles, formTextContent.styles);
  9825. stateManager.restore();
  9826. xobjsCache.key = name;
  9827. xobjsCache.texts = formTextContent;
  9828. next(resolve, reject);
  9829. }, reject);
  9830. case OPS.setGState:
  9831. var dictName = args[0];
  9832. var extGState = resources.get('ExtGState');
  9833. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  9834. break;
  9835. }
  9836. var gsStateMap = extGState.get(dictName.name);
  9837. var gsStateFont = null;
  9838. for (var key in gsStateMap) {
  9839. if (key === 'Font') {
  9840. assert(!gsStateFont);
  9841. gsStateFont = gsStateMap[key];
  9842. }
  9843. }
  9844. if (gsStateFont) {
  9845. textState.fontSize = gsStateFont[1];
  9846. return handleSetFont(gsStateFont[0]).then(function() {
  9847. next(resolve, reject);
  9848. }, reject);
  9849. }
  9850. break;
  9851. } // switch
  9852. } // while
  9853. if (stop) {
  9854. deferred.then(function () {
  9855. next(resolve, reject);
  9856. });
  9857. return;
  9858. }
  9859. resolve(textContent);
  9860. });
  9861. },
  9862. extractDataStructures: function
  9863. partialEvaluatorExtractDataStructures(dict, baseDict,
  9864. xref, properties) {
  9865. // 9.10.2
  9866. var toUnicode = (dict.get('ToUnicode') || baseDict.get('ToUnicode'));
  9867. if (toUnicode) {
  9868. properties.toUnicode = this.readToUnicode(toUnicode);
  9869. }
  9870. if (properties.composite) {
  9871. // CIDSystemInfo helps to match CID to glyphs
  9872. var cidSystemInfo = dict.get('CIDSystemInfo');
  9873. if (isDict(cidSystemInfo)) {
  9874. properties.cidSystemInfo = {
  9875. registry: cidSystemInfo.get('Registry'),
  9876. ordering: cidSystemInfo.get('Ordering'),
  9877. supplement: cidSystemInfo.get('Supplement')
  9878. };
  9879. }
  9880. var cidToGidMap = dict.get('CIDToGIDMap');
  9881. if (isStream(cidToGidMap)) {
  9882. properties.cidToGidMap = this.readCidToGidMap(cidToGidMap);
  9883. }
  9884. }
  9885. // Based on 9.6.6 of the spec the encoding can come from multiple places
  9886. // and depends on the font type. The base encoding and differences are
  9887. // read here, but the encoding that is actually used is chosen during
  9888. // glyph mapping in the font.
  9889. // TODO: Loading the built in encoding in the font would allow the
  9890. // differences to be merged in here not require us to hold on to it.
  9891. var differences = [];
  9892. var baseEncodingName = null;
  9893. var encoding;
  9894. if (dict.has('Encoding')) {
  9895. encoding = dict.get('Encoding');
  9896. if (isDict(encoding)) {
  9897. baseEncodingName = encoding.get('BaseEncoding');
  9898. baseEncodingName = (isName(baseEncodingName) ?
  9899. baseEncodingName.name : null);
  9900. // Load the differences between the base and original
  9901. if (encoding.has('Differences')) {
  9902. var diffEncoding = encoding.get('Differences');
  9903. var index = 0;
  9904. for (var j = 0, jj = diffEncoding.length; j < jj; j++) {
  9905. var data = diffEncoding[j];
  9906. if (isNum(data)) {
  9907. index = data;
  9908. } else {
  9909. differences[index++] = data.name;
  9910. }
  9911. }
  9912. }
  9913. } else if (isName(encoding)) {
  9914. baseEncodingName = encoding.name;
  9915. } else {
  9916. error('Encoding is not a Name nor a Dict');
  9917. }
  9918. // According to table 114 if the encoding is a named encoding it must be
  9919. // one of these predefined encodings.
  9920. if ((baseEncodingName !== 'MacRomanEncoding' &&
  9921. baseEncodingName !== 'MacExpertEncoding' &&
  9922. baseEncodingName !== 'WinAnsiEncoding')) {
  9923. baseEncodingName = null;
  9924. }
  9925. }
  9926. if (baseEncodingName) {
  9927. properties.defaultEncoding = Encodings[baseEncodingName].slice();
  9928. } else {
  9929. encoding = (properties.type === 'TrueType' ?
  9930. Encodings.WinAnsiEncoding : Encodings.StandardEncoding);
  9931. // The Symbolic attribute can be misused for regular fonts
  9932. // Heuristic: we have to check if the font is a standard one also
  9933. if (!!(properties.flags & FontFlags.Symbolic)) {
  9934. encoding = (!properties.file && /Symbol/i.test(properties.name) ?
  9935. Encodings.SymbolSetEncoding :
  9936. Encodings.MacRomanEncoding);
  9937. }
  9938. properties.defaultEncoding = encoding;
  9939. }
  9940. properties.differences = differences;
  9941. properties.baseEncodingName = baseEncodingName;
  9942. properties.dict = dict;
  9943. },
  9944. readToUnicode: function PartialEvaluator_readToUnicode(toUnicode) {
  9945. var cmapObj = toUnicode;
  9946. if (isName(cmapObj)) {
  9947. return CMapFactory.create(cmapObj,
  9948. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null).getMap();
  9949. } else if (isStream(cmapObj)) {
  9950. var cmap = CMapFactory.create(cmapObj,
  9951. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null).getMap();
  9952. // Convert UTF-16BE
  9953. // NOTE: cmap can be a sparse array, so use forEach instead of for(;;)
  9954. // to iterate over all keys.
  9955. cmap.forEach(function(token, i) {
  9956. var str = [];
  9957. for (var k = 0; k < token.length; k += 2) {
  9958. var w1 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  9959. if ((w1 & 0xF800) !== 0xD800) { // w1 < 0xD800 || w1 > 0xDFFF
  9960. str.push(w1);
  9961. continue;
  9962. }
  9963. k += 2;
  9964. var w2 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  9965. str.push(((w1 & 0x3ff) << 10) + (w2 & 0x3ff) + 0x10000);
  9966. }
  9967. cmap[i] = String.fromCharCode.apply(String, str);
  9968. });
  9969. return cmap;
  9970. }
  9971. return null;
  9972. },
  9973. readCidToGidMap: function PartialEvaluator_readCidToGidMap(cidToGidStream) {
  9974. // Extract the encoding from the CIDToGIDMap
  9975. var glyphsData = cidToGidStream.getBytes();
  9976. // Set encoding 0 to later verify the font has an encoding
  9977. var result = [];
  9978. for (var j = 0, jj = glyphsData.length; j < jj; j++) {
  9979. var glyphID = (glyphsData[j++] << 8) | glyphsData[j];
  9980. if (glyphID === 0) {
  9981. continue;
  9982. }
  9983. var code = j >> 1;
  9984. result[code] = glyphID;
  9985. }
  9986. return result;
  9987. },
  9988. extractWidths: function PartialEvaluator_extractWidths(dict, xref,
  9989. descriptor,
  9990. properties) {
  9991. var glyphsWidths = [];
  9992. var defaultWidth = 0;
  9993. var glyphsVMetrics = [];
  9994. var defaultVMetrics;
  9995. var i, ii, j, jj, start, code, widths;
  9996. if (properties.composite) {
  9997. defaultWidth = dict.get('DW') || 1000;
  9998. widths = dict.get('W');
  9999. if (widths) {
  10000. for (i = 0, ii = widths.length; i < ii; i++) {
  10001. start = widths[i++];
  10002. code = xref.fetchIfRef(widths[i]);
  10003. if (isArray(code)) {
  10004. for (j = 0, jj = code.length; j < jj; j++) {
  10005. glyphsWidths[start++] = code[j];
  10006. }
  10007. } else {
  10008. var width = widths[++i];
  10009. for (j = start; j <= code; j++) {
  10010. glyphsWidths[j] = width;
  10011. }
  10012. }
  10013. }
  10014. }
  10015. if (properties.vertical) {
  10016. var vmetrics = (dict.get('DW2') || [880, -1000]);
  10017. defaultVMetrics = [vmetrics[1], defaultWidth * 0.5, vmetrics[0]];
  10018. vmetrics = dict.get('W2');
  10019. if (vmetrics) {
  10020. for (i = 0, ii = vmetrics.length; i < ii; i++) {
  10021. start = vmetrics[i++];
  10022. code = xref.fetchIfRef(vmetrics[i]);
  10023. if (isArray(code)) {
  10024. for (j = 0, jj = code.length; j < jj; j++) {
  10025. glyphsVMetrics[start++] = [code[j++], code[j++], code[j]];
  10026. }
  10027. } else {
  10028. var vmetric = [vmetrics[++i], vmetrics[++i], vmetrics[++i]];
  10029. for (j = start; j <= code; j++) {
  10030. glyphsVMetrics[j] = vmetric;
  10031. }
  10032. }
  10033. }
  10034. }
  10035. }
  10036. } else {
  10037. var firstChar = properties.firstChar;
  10038. widths = dict.get('Widths');
  10039. if (widths) {
  10040. j = firstChar;
  10041. for (i = 0, ii = widths.length; i < ii; i++) {
  10042. glyphsWidths[j++] = widths[i];
  10043. }
  10044. defaultWidth = (parseFloat(descriptor.get('MissingWidth')) || 0);
  10045. } else {
  10046. // Trying get the BaseFont metrics (see comment above).
  10047. var baseFontName = dict.get('BaseFont');
  10048. if (isName(baseFontName)) {
  10049. var metrics = this.getBaseFontMetrics(baseFontName.name);
  10050. glyphsWidths = this.buildCharCodeToWidth(metrics.widths,
  10051. properties);
  10052. defaultWidth = metrics.defaultWidth;
  10053. }
  10054. }
  10055. }
  10056. // Heuristic: detection of monospace font by checking all non-zero widths
  10057. var isMonospace = true;
  10058. var firstWidth = defaultWidth;
  10059. for (var glyph in glyphsWidths) {
  10060. var glyphWidth = glyphsWidths[glyph];
  10061. if (!glyphWidth) {
  10062. continue;
  10063. }
  10064. if (!firstWidth) {
  10065. firstWidth = glyphWidth;
  10066. continue;
  10067. }
  10068. if (firstWidth != glyphWidth) {
  10069. isMonospace = false;
  10070. break;
  10071. }
  10072. }
  10073. if (isMonospace) {
  10074. properties.flags |= FontFlags.FixedPitch;
  10075. }
  10076. properties.defaultWidth = defaultWidth;
  10077. properties.widths = glyphsWidths;
  10078. properties.defaultVMetrics = defaultVMetrics;
  10079. properties.vmetrics = glyphsVMetrics;
  10080. },
  10081. isSerifFont: function PartialEvaluator_isSerifFont(baseFontName) {
  10082. // Simulating descriptor flags attribute
  10083. var fontNameWoStyle = baseFontName.split('-')[0];
  10084. return (fontNameWoStyle in serifFonts) ||
  10085. (fontNameWoStyle.search(/serif/gi) !== -1);
  10086. },
  10087. getBaseFontMetrics: function PartialEvaluator_getBaseFontMetrics(name) {
  10088. var defaultWidth = 0;
  10089. var widths = [];
  10090. var monospace = false;
  10091. var lookupName = (stdFontMap[name] || name);
  10092. if (!(lookupName in Metrics)) {
  10093. // Use default fonts for looking up font metrics if the passed
  10094. // font is not a base font
  10095. if (this.isSerifFont(name)) {
  10096. lookupName = 'Times-Roman';
  10097. } else {
  10098. lookupName = 'Helvetica';
  10099. }
  10100. }
  10101. var glyphWidths = Metrics[lookupName];
  10102. if (isNum(glyphWidths)) {
  10103. defaultWidth = glyphWidths;
  10104. monospace = true;
  10105. } else {
  10106. widths = glyphWidths;
  10107. }
  10108. return {
  10109. defaultWidth: defaultWidth,
  10110. monospace: monospace,
  10111. widths: widths
  10112. };
  10113. },
  10114. buildCharCodeToWidth:
  10115. function PartialEvaluator_bulildCharCodeToWidth(widthsByGlyphName,
  10116. properties) {
  10117. var widths = Object.create(null);
  10118. var differences = properties.differences;
  10119. var encoding = properties.defaultEncoding;
  10120. for (var charCode = 0; charCode < 256; charCode++) {
  10121. if (charCode in differences &&
  10122. widthsByGlyphName[differences[charCode]]) {
  10123. widths[charCode] = widthsByGlyphName[differences[charCode]];
  10124. continue;
  10125. }
  10126. if (charCode in encoding && widthsByGlyphName[encoding[charCode]]) {
  10127. widths[charCode] = widthsByGlyphName[encoding[charCode]];
  10128. continue;
  10129. }
  10130. }
  10131. return widths;
  10132. },
  10133. preEvaluateFont: function PartialEvaluator_preEvaluateFont(dict, xref) {
  10134. var baseDict = dict;
  10135. var type = dict.get('Subtype');
  10136. assert(isName(type), 'invalid font Subtype');
  10137. var composite = false;
  10138. var uint8array;
  10139. if (type.name === 'Type0') {
  10140. // If font is a composite
  10141. // - get the descendant font
  10142. // - set the type according to the descendant font
  10143. // - get the FontDescriptor from the descendant font
  10144. var df = dict.get('DescendantFonts');
  10145. if (!df) {
  10146. error('Descendant fonts are not specified');
  10147. }
  10148. dict = (isArray(df) ? xref.fetchIfRef(df[0]) : df);
  10149. type = dict.get('Subtype');
  10150. assert(isName(type), 'invalid font Subtype');
  10151. composite = true;
  10152. }
  10153. var descriptor = dict.get('FontDescriptor');
  10154. if (descriptor) {
  10155. var hash = new MurmurHash3_64();
  10156. var encoding = baseDict.getRaw('Encoding');
  10157. if (isName(encoding)) {
  10158. hash.update(encoding.name);
  10159. } else if (isRef(encoding)) {
  10160. hash.update(encoding.num + '_' + encoding.gen);
  10161. }
  10162. var toUnicode = dict.get('ToUnicode') || baseDict.get('ToUnicode');
  10163. if (isStream(toUnicode)) {
  10164. var stream = toUnicode.str || toUnicode;
  10165. uint8array = stream.buffer ?
  10166. new Uint8Array(stream.buffer.buffer, 0, stream.bufferLength) :
  10167. new Uint8Array(stream.bytes.buffer,
  10168. stream.start, stream.end - stream.start);
  10169. hash.update(uint8array);
  10170. } else if (isName(toUnicode)) {
  10171. hash.update(toUnicode.name);
  10172. }
  10173. var widths = dict.get('Widths') || baseDict.get('Widths');
  10174. if (widths) {
  10175. uint8array = new Uint8Array(new Uint32Array(widths).buffer);
  10176. hash.update(uint8array);
  10177. }
  10178. }
  10179. return {
  10180. descriptor: descriptor,
  10181. dict: dict,
  10182. baseDict: baseDict,
  10183. composite: composite,
  10184. type: type.name,
  10185. hash: hash ? hash.hexdigest() : ''
  10186. };
  10187. },
  10188. translateFont: function PartialEvaluator_translateFont(preEvaluatedFont,
  10189. xref) {
  10190. var baseDict = preEvaluatedFont.baseDict;
  10191. var dict = preEvaluatedFont.dict;
  10192. var composite = preEvaluatedFont.composite;
  10193. var descriptor = preEvaluatedFont.descriptor;
  10194. var type = preEvaluatedFont.type;
  10195. var maxCharIndex = (composite ? 0xFFFF : 0xFF);
  10196. var properties;
  10197. if (!descriptor) {
  10198. if (type === 'Type3') {
  10199. // FontDescriptor is only required for Type3 fonts when the document
  10200. // is a tagged pdf. Create a barbebones one to get by.
  10201. descriptor = new Dict(null);
  10202. descriptor.set('FontName', Name.get(type));
  10203. } else {
  10204. // Before PDF 1.5 if the font was one of the base 14 fonts, having a
  10205. // FontDescriptor was not required.
  10206. // This case is here for compatibility.
  10207. var baseFontName = dict.get('BaseFont');
  10208. if (!isName(baseFontName)) {
  10209. error('Base font is not specified');
  10210. }
  10211. // Using base font name as a font name.
  10212. baseFontName = baseFontName.name.replace(/[,_]/g, '-');
  10213. var metrics = this.getBaseFontMetrics(baseFontName);
  10214. // Simulating descriptor flags attribute
  10215. var fontNameWoStyle = baseFontName.split('-')[0];
  10216. var flags =
  10217. (this.isSerifFont(fontNameWoStyle) ? FontFlags.Serif : 0) |
  10218. (metrics.monospace ? FontFlags.FixedPitch : 0) |
  10219. (symbolsFonts[fontNameWoStyle] ? FontFlags.Symbolic :
  10220. FontFlags.Nonsymbolic);
  10221. properties = {
  10222. type: type,
  10223. name: baseFontName,
  10224. widths: metrics.widths,
  10225. defaultWidth: metrics.defaultWidth,
  10226. flags: flags,
  10227. firstChar: 0,
  10228. lastChar: maxCharIndex
  10229. };
  10230. this.extractDataStructures(dict, dict, xref, properties);
  10231. properties.widths = this.buildCharCodeToWidth(metrics.widths,
  10232. properties);
  10233. return new Font(baseFontName, null, properties);
  10234. }
  10235. }
  10236. // According to the spec if 'FontDescriptor' is declared, 'FirstChar',
  10237. // 'LastChar' and 'Widths' should exist too, but some PDF encoders seem
  10238. // to ignore this rule when a variant of a standart font is used.
  10239. // TODO Fill the width array depending on which of the base font this is
  10240. // a variant.
  10241. var firstChar = (dict.get('FirstChar') || 0);
  10242. var lastChar = (dict.get('LastChar') || maxCharIndex);
  10243. var fontName = descriptor.get('FontName');
  10244. var baseFont = dict.get('BaseFont');
  10245. // Some bad PDFs have a string as the font name.
  10246. if (isString(fontName)) {
  10247. fontName = Name.get(fontName);
  10248. }
  10249. if (isString(baseFont)) {
  10250. baseFont = Name.get(baseFont);
  10251. }
  10252. if (type !== 'Type3') {
  10253. var fontNameStr = fontName && fontName.name;
  10254. var baseFontStr = baseFont && baseFont.name;
  10255. if (fontNameStr !== baseFontStr) {
  10256. info('The FontDescriptor\'s FontName is "' + fontNameStr +
  10257. '" but should be the same as the Font\'s BaseFont "' +
  10258. baseFontStr + '"');
  10259. // Workaround for cases where e.g. fontNameStr = 'Arial' and
  10260. // baseFontStr = 'Arial,Bold' (needed when no font file is embedded).
  10261. if (fontNameStr && baseFontStr &&
  10262. baseFontStr.indexOf(fontNameStr) === 0) {
  10263. fontName = baseFont;
  10264. }
  10265. }
  10266. }
  10267. fontName = (fontName || baseFont);
  10268. assert(isName(fontName), 'invalid font name');
  10269. var fontFile = descriptor.get('FontFile', 'FontFile2', 'FontFile3');
  10270. if (fontFile) {
  10271. if (fontFile.dict) {
  10272. var subtype = fontFile.dict.get('Subtype');
  10273. if (subtype) {
  10274. subtype = subtype.name;
  10275. }
  10276. var length1 = fontFile.dict.get('Length1');
  10277. var length2 = fontFile.dict.get('Length2');
  10278. }
  10279. }
  10280. properties = {
  10281. type: type,
  10282. name: fontName.name,
  10283. subtype: subtype,
  10284. file: fontFile,
  10285. length1: length1,
  10286. length2: length2,
  10287. loadedName: baseDict.loadedName,
  10288. composite: composite,
  10289. wideChars: composite,
  10290. fixedPitch: false,
  10291. fontMatrix: (dict.get('FontMatrix') || FONT_IDENTITY_MATRIX),
  10292. firstChar: firstChar || 0,
  10293. lastChar: (lastChar || maxCharIndex),
  10294. bbox: descriptor.get('FontBBox'),
  10295. ascent: descriptor.get('Ascent'),
  10296. descent: descriptor.get('Descent'),
  10297. xHeight: descriptor.get('XHeight'),
  10298. capHeight: descriptor.get('CapHeight'),
  10299. flags: descriptor.get('Flags'),
  10300. italicAngle: descriptor.get('ItalicAngle'),
  10301. coded: false
  10302. };
  10303. if (composite) {
  10304. var cidEncoding = baseDict.get('Encoding');
  10305. if (isName(cidEncoding)) {
  10306. properties.cidEncoding = cidEncoding.name;
  10307. }
  10308. properties.cMap = CMapFactory.create(cidEncoding,
  10309. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  10310. properties.vertical = properties.cMap.vertical;
  10311. }
  10312. this.extractDataStructures(dict, baseDict, xref, properties);
  10313. this.extractWidths(dict, xref, descriptor, properties);
  10314. if (type === 'Type3') {
  10315. properties.isType3Font = true;
  10316. }
  10317. return new Font(fontName.name, fontFile, properties);
  10318. }
  10319. };
  10320. return PartialEvaluator;
  10321. })();
  10322. var TranslatedFont = (function TranslatedFontClosure() {
  10323. function TranslatedFont(loadedName, font, dict) {
  10324. this.loadedName = loadedName;
  10325. this.font = font;
  10326. this.dict = dict;
  10327. this.type3Loaded = null;
  10328. this.sent = false;
  10329. }
  10330. TranslatedFont.prototype = {
  10331. send: function (handler) {
  10332. if (this.sent) {
  10333. return;
  10334. }
  10335. var fontData = this.font.exportData();
  10336. handler.send('commonobj', [
  10337. this.loadedName,
  10338. 'Font',
  10339. fontData
  10340. ]);
  10341. this.sent = true;
  10342. },
  10343. loadType3Data: function (evaluator, resources, parentOperatorList) {
  10344. assert(this.font.isType3Font);
  10345. if (this.type3Loaded) {
  10346. return this.type3Loaded;
  10347. }
  10348. var translatedFont = this.font;
  10349. var loadCharProcsPromise = Promise.resolve();
  10350. var charProcs = this.dict.get('CharProcs').getAll();
  10351. var fontResources = this.dict.get('Resources') || resources;
  10352. var charProcKeys = Object.keys(charProcs);
  10353. var charProcOperatorList = {};
  10354. for (var i = 0, n = charProcKeys.length; i < n; ++i) {
  10355. loadCharProcsPromise = loadCharProcsPromise.then(function (key) {
  10356. var glyphStream = charProcs[key];
  10357. var operatorList = new OperatorList();
  10358. return evaluator.getOperatorList(glyphStream, fontResources,
  10359. operatorList).then(function () {
  10360. charProcOperatorList[key] = operatorList.getIR();
  10361. // Add the dependencies to the parent operator list so they are
  10362. // resolved before sub operator list is executed synchronously.
  10363. parentOperatorList.addDependencies(operatorList.dependencies);
  10364. }, function (reason) {
  10365. warn('Type3 font resource \"' + key + '\" is not available');
  10366. var operatorList = new OperatorList();
  10367. charProcOperatorList[key] = operatorList.getIR();
  10368. });
  10369. }.bind(this, charProcKeys[i]));
  10370. }
  10371. this.type3Loaded = loadCharProcsPromise.then(function () {
  10372. translatedFont.charProcOperatorList = charProcOperatorList;
  10373. });
  10374. return this.type3Loaded;
  10375. }
  10376. };
  10377. return TranslatedFont;
  10378. })();
  10379. var OperatorList = (function OperatorListClosure() {
  10380. var CHUNK_SIZE = 1000;
  10381. var CHUNK_SIZE_ABOUT = CHUNK_SIZE - 5; // close to chunk size
  10382. function getTransfers(queue) {
  10383. var transfers = [];
  10384. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  10385. for (var i = 0, ii = queue.length; i < ii; i++) {
  10386. switch (fnArray[i]) {
  10387. case OPS.paintInlineImageXObject:
  10388. case OPS.paintInlineImageXObjectGroup:
  10389. case OPS.paintImageMaskXObject:
  10390. var arg = argsArray[i][0]; // first param in imgData
  10391. if (!arg.cached) {
  10392. transfers.push(arg.data.buffer);
  10393. }
  10394. break;
  10395. }
  10396. }
  10397. return transfers;
  10398. }
  10399. function OperatorList(intent, messageHandler, pageIndex) {
  10400. this.messageHandler = messageHandler;
  10401. this.fnArray = [];
  10402. this.argsArray = [];
  10403. this.dependencies = {};
  10404. this.pageIndex = pageIndex;
  10405. this.intent = intent;
  10406. }
  10407. OperatorList.prototype = {
  10408. get length() {
  10409. return this.argsArray.length;
  10410. },
  10411. addOp: function(fn, args) {
  10412. this.fnArray.push(fn);
  10413. this.argsArray.push(args);
  10414. if (this.messageHandler) {
  10415. if (this.fnArray.length >= CHUNK_SIZE) {
  10416. this.flush();
  10417. } else if (this.fnArray.length >= CHUNK_SIZE_ABOUT &&
  10418. (fn === OPS.restore || fn === OPS.endText)) {
  10419. // heuristic to flush on boundary of restore or endText
  10420. this.flush();
  10421. }
  10422. }
  10423. },
  10424. addDependency: function(dependency) {
  10425. if (dependency in this.dependencies) {
  10426. return;
  10427. }
  10428. this.dependencies[dependency] = true;
  10429. this.addOp(OPS.dependency, [dependency]);
  10430. },
  10431. addDependencies: function(dependencies) {
  10432. for (var key in dependencies) {
  10433. this.addDependency(key);
  10434. }
  10435. },
  10436. addOpList: function(opList) {
  10437. Util.extendObj(this.dependencies, opList.dependencies);
  10438. for (var i = 0, ii = opList.length; i < ii; i++) {
  10439. this.addOp(opList.fnArray[i], opList.argsArray[i]);
  10440. }
  10441. },
  10442. getIR: function() {
  10443. return {
  10444. fnArray: this.fnArray,
  10445. argsArray: this.argsArray,
  10446. length: this.length
  10447. };
  10448. },
  10449. flush: function(lastChunk) {
  10450. new QueueOptimizer().optimize(this);
  10451. var transfers = getTransfers(this);
  10452. this.messageHandler.send('RenderPageChunk', {
  10453. operatorList: {
  10454. fnArray: this.fnArray,
  10455. argsArray: this.argsArray,
  10456. lastChunk: lastChunk,
  10457. length: this.length
  10458. },
  10459. pageIndex: this.pageIndex,
  10460. intent: this.intent
  10461. }, transfers);
  10462. this.dependencies = {};
  10463. this.fnArray.length = 0;
  10464. this.argsArray.length = 0;
  10465. }
  10466. };
  10467. return OperatorList;
  10468. })();
  10469. var StateManager = (function StateManagerClosure() {
  10470. function StateManager(initialState) {
  10471. this.state = initialState;
  10472. this.stateStack = [];
  10473. }
  10474. StateManager.prototype = {
  10475. save: function () {
  10476. var old = this.state;
  10477. this.stateStack.push(this.state);
  10478. this.state = old.clone();
  10479. },
  10480. restore: function () {
  10481. var prev = this.stateStack.pop();
  10482. if (prev) {
  10483. this.state = prev;
  10484. }
  10485. },
  10486. transform: function (args) {
  10487. this.state.ctm = Util.transform(this.state.ctm, args);
  10488. }
  10489. };
  10490. return StateManager;
  10491. })();
  10492. var TextState = (function TextStateClosure() {
  10493. function TextState() {
  10494. this.ctm = new Float32Array(IDENTITY_MATRIX);
  10495. this.fontSize = 0;
  10496. this.font = null;
  10497. this.fontMatrix = FONT_IDENTITY_MATRIX;
  10498. this.textMatrix = IDENTITY_MATRIX.slice();
  10499. this.textLineMatrix = IDENTITY_MATRIX.slice();
  10500. this.charSpacing = 0;
  10501. this.wordSpacing = 0;
  10502. this.leading = 0;
  10503. this.textHScale = 1;
  10504. this.textRise = 0;
  10505. }
  10506. TextState.prototype = {
  10507. setTextMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  10508. var m = this.textMatrix;
  10509. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  10510. },
  10511. setTextLineMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  10512. var m = this.textLineMatrix;
  10513. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  10514. },
  10515. translateTextMatrix: function TextState_translateTextMatrix(x, y) {
  10516. var m = this.textMatrix;
  10517. m[4] = m[0] * x + m[2] * y + m[4];
  10518. m[5] = m[1] * x + m[3] * y + m[5];
  10519. },
  10520. translateTextLineMatrix: function TextState_translateTextMatrix(x, y) {
  10521. var m = this.textLineMatrix;
  10522. m[4] = m[0] * x + m[2] * y + m[4];
  10523. m[5] = m[1] * x + m[3] * y + m[5];
  10524. },
  10525. calcRenderMatrix: function TextState_calcRendeMatrix(ctm) {
  10526. // 9.4.4 Text Space Details
  10527. var tsm = [this.fontSize * this.textHScale, 0,
  10528. 0, this.fontSize,
  10529. 0, this.textRise];
  10530. return Util.transform(ctm, Util.transform(this.textMatrix, tsm));
  10531. },
  10532. carriageReturn: function TextState_carriageReturn() {
  10533. this.translateTextLineMatrix(0, -this.leading);
  10534. this.textMatrix = this.textLineMatrix.slice();
  10535. },
  10536. clone: function TextState_clone() {
  10537. var clone = Object.create(this);
  10538. clone.textMatrix = this.textMatrix.slice();
  10539. clone.textLineMatrix = this.textLineMatrix.slice();
  10540. clone.fontMatrix = this.fontMatrix.slice();
  10541. return clone;
  10542. }
  10543. };
  10544. return TextState;
  10545. })();
  10546. var EvalState = (function EvalStateClosure() {
  10547. function EvalState() {
  10548. this.ctm = new Float32Array(IDENTITY_MATRIX);
  10549. this.font = null;
  10550. this.textRenderingMode = TextRenderingMode.FILL;
  10551. this.fillColorSpace = ColorSpace.singletons.gray;
  10552. this.strokeColorSpace = ColorSpace.singletons.gray;
  10553. }
  10554. EvalState.prototype = {
  10555. clone: function CanvasExtraState_clone() {
  10556. return Object.create(this);
  10557. },
  10558. };
  10559. return EvalState;
  10560. })();
  10561. var EvaluatorPreprocessor = (function EvaluatorPreprocessorClosure() {
  10562. // Specifies properties for each command
  10563. //
  10564. // If variableArgs === true: [0, `numArgs`] expected
  10565. // If variableArgs === false: exactly `numArgs` expected
  10566. var OP_MAP = {
  10567. // Graphic state
  10568. w: { id: OPS.setLineWidth, numArgs: 1, variableArgs: false },
  10569. J: { id: OPS.setLineCap, numArgs: 1, variableArgs: false },
  10570. j: { id: OPS.setLineJoin, numArgs: 1, variableArgs: false },
  10571. M: { id: OPS.setMiterLimit, numArgs: 1, variableArgs: false },
  10572. d: { id: OPS.setDash, numArgs: 2, variableArgs: false },
  10573. ri: { id: OPS.setRenderingIntent, numArgs: 1, variableArgs: false },
  10574. i: { id: OPS.setFlatness, numArgs: 1, variableArgs: false },
  10575. gs: { id: OPS.setGState, numArgs: 1, variableArgs: false },
  10576. q: { id: OPS.save, numArgs: 0, variableArgs: false },
  10577. Q: { id: OPS.restore, numArgs: 0, variableArgs: false },
  10578. cm: { id: OPS.transform, numArgs: 6, variableArgs: false },
  10579. // Path
  10580. m: { id: OPS.moveTo, numArgs: 2, variableArgs: false },
  10581. l: { id: OPS.lineTo, numArgs: 2, variableArgs: false },
  10582. c: { id: OPS.curveTo, numArgs: 6, variableArgs: false },
  10583. v: { id: OPS.curveTo2, numArgs: 4, variableArgs: false },
  10584. y: { id: OPS.curveTo3, numArgs: 4, variableArgs: false },
  10585. h: { id: OPS.closePath, numArgs: 0, variableArgs: false },
  10586. re: { id: OPS.rectangle, numArgs: 4, variableArgs: false },
  10587. S: { id: OPS.stroke, numArgs: 0, variableArgs: false },
  10588. s: { id: OPS.closeStroke, numArgs: 0, variableArgs: false },
  10589. f: { id: OPS.fill, numArgs: 0, variableArgs: false },
  10590. F: { id: OPS.fill, numArgs: 0, variableArgs: false },
  10591. 'f*': { id: OPS.eoFill, numArgs: 0, variableArgs: false },
  10592. B: { id: OPS.fillStroke, numArgs: 0, variableArgs: false },
  10593. 'B*': { id: OPS.eoFillStroke, numArgs: 0, variableArgs: false },
  10594. b: { id: OPS.closeFillStroke, numArgs: 0, variableArgs: false },
  10595. 'b*': { id: OPS.closeEOFillStroke, numArgs: 0, variableArgs: false },
  10596. n: { id: OPS.endPath, numArgs: 0, variableArgs: false },
  10597. // Clipping
  10598. W: { id: OPS.clip, numArgs: 0, variableArgs: false },
  10599. 'W*': { id: OPS.eoClip, numArgs: 0, variableArgs: false },
  10600. // Text
  10601. BT: { id: OPS.beginText, numArgs: 0, variableArgs: false },
  10602. ET: { id: OPS.endText, numArgs: 0, variableArgs: false },
  10603. Tc: { id: OPS.setCharSpacing, numArgs: 1, variableArgs: false },
  10604. Tw: { id: OPS.setWordSpacing, numArgs: 1, variableArgs: false },
  10605. Tz: { id: OPS.setHScale, numArgs: 1, variableArgs: false },
  10606. TL: { id: OPS.setLeading, numArgs: 1, variableArgs: false },
  10607. Tf: { id: OPS.setFont, numArgs: 2, variableArgs: false },
  10608. Tr: { id: OPS.setTextRenderingMode, numArgs: 1, variableArgs: false },
  10609. Ts: { id: OPS.setTextRise, numArgs: 1, variableArgs: false },
  10610. Td: { id: OPS.moveText, numArgs: 2, variableArgs: false },
  10611. TD: { id: OPS.setLeadingMoveText, numArgs: 2, variableArgs: false },
  10612. Tm: { id: OPS.setTextMatrix, numArgs: 6, variableArgs: false },
  10613. 'T*': { id: OPS.nextLine, numArgs: 0, variableArgs: false },
  10614. Tj: { id: OPS.showText, numArgs: 1, variableArgs: false },
  10615. TJ: { id: OPS.showSpacedText, numArgs: 1, variableArgs: false },
  10616. '\'': { id: OPS.nextLineShowText, numArgs: 1, variableArgs: false },
  10617. '"': { id: OPS.nextLineSetSpacingShowText, numArgs: 3,
  10618. variableArgs: false },
  10619. // Type3 fonts
  10620. d0: { id: OPS.setCharWidth, numArgs: 2, variableArgs: false },
  10621. d1: { id: OPS.setCharWidthAndBounds, numArgs: 6, variableArgs: false },
  10622. // Color
  10623. CS: { id: OPS.setStrokeColorSpace, numArgs: 1, variableArgs: false },
  10624. cs: { id: OPS.setFillColorSpace, numArgs: 1, variableArgs: false },
  10625. SC: { id: OPS.setStrokeColor, numArgs: 4, variableArgs: true },
  10626. SCN: { id: OPS.setStrokeColorN, numArgs: 33, variableArgs: true },
  10627. sc: { id: OPS.setFillColor, numArgs: 4, variableArgs: true },
  10628. scn: { id: OPS.setFillColorN, numArgs: 33, variableArgs: true },
  10629. G: { id: OPS.setStrokeGray, numArgs: 1, variableArgs: false },
  10630. g: { id: OPS.setFillGray, numArgs: 1, variableArgs: false },
  10631. RG: { id: OPS.setStrokeRGBColor, numArgs: 3, variableArgs: false },
  10632. rg: { id: OPS.setFillRGBColor, numArgs: 3, variableArgs: false },
  10633. K: { id: OPS.setStrokeCMYKColor, numArgs: 4, variableArgs: false },
  10634. k: { id: OPS.setFillCMYKColor, numArgs: 4, variableArgs: false },
  10635. // Shading
  10636. sh: { id: OPS.shadingFill, numArgs: 1, variableArgs: false },
  10637. // Images
  10638. BI: { id: OPS.beginInlineImage, numArgs: 0, variableArgs: false },
  10639. ID: { id: OPS.beginImageData, numArgs: 0, variableArgs: false },
  10640. EI: { id: OPS.endInlineImage, numArgs: 1, variableArgs: false },
  10641. // XObjects
  10642. Do: { id: OPS.paintXObject, numArgs: 1, variableArgs: false },
  10643. MP: { id: OPS.markPoint, numArgs: 1, variableArgs: false },
  10644. DP: { id: OPS.markPointProps, numArgs: 2, variableArgs: false },
  10645. BMC: { id: OPS.beginMarkedContent, numArgs: 1, variableArgs: false },
  10646. BDC: { id: OPS.beginMarkedContentProps, numArgs: 2,
  10647. variableArgs: false },
  10648. EMC: { id: OPS.endMarkedContent, numArgs: 0, variableArgs: false },
  10649. // Compatibility
  10650. BX: { id: OPS.beginCompat, numArgs: 0, variableArgs: false },
  10651. EX: { id: OPS.endCompat, numArgs: 0, variableArgs: false },
  10652. // (reserved partial commands for the lexer)
  10653. BM: null,
  10654. BD: null,
  10655. 'true': null,
  10656. fa: null,
  10657. fal: null,
  10658. fals: null,
  10659. 'false': null,
  10660. nu: null,
  10661. nul: null,
  10662. 'null': null
  10663. };
  10664. function EvaluatorPreprocessor(stream, xref, stateManager) {
  10665. // TODO(mduan): pass array of knownCommands rather than OP_MAP
  10666. // dictionary
  10667. this.parser = new Parser(new Lexer(stream, OP_MAP), false, xref);
  10668. this.stateManager = stateManager;
  10669. this.nonProcessedArgs = [];
  10670. }
  10671. EvaluatorPreprocessor.prototype = {
  10672. get savedStatesDepth() {
  10673. return this.stateManager.stateStack.length;
  10674. },
  10675. read: function EvaluatorPreprocessor_read(operation) {
  10676. // We use an array to represent args, except we use |null| to represent
  10677. // no args because it's more compact than an empty array.
  10678. var args = null;
  10679. while (true) {
  10680. var obj = this.parser.getObj();
  10681. if (isCmd(obj)) {
  10682. var cmd = obj.cmd;
  10683. // Check that the command is valid
  10684. var opSpec = OP_MAP[cmd];
  10685. if (!opSpec) {
  10686. warn('Unknown command "' + cmd + '"');
  10687. continue;
  10688. }
  10689. var fn = opSpec.id;
  10690. var numArgs = opSpec.numArgs;
  10691. if (!opSpec.variableArgs) {
  10692. // Postscript commands can be nested, e.g. /F2 /GS2 gs 5.711 Tf
  10693. var argsLength = args !== null ? args.length : 0;
  10694. if (argsLength !== numArgs) {
  10695. var nonProcessedArgs = this.nonProcessedArgs;
  10696. while (argsLength > numArgs) {
  10697. nonProcessedArgs.push(args.shift());
  10698. argsLength--;
  10699. }
  10700. while (argsLength < numArgs && nonProcessedArgs.length !== 0) {
  10701. if (!args) {
  10702. args = [];
  10703. }
  10704. args.unshift(nonProcessedArgs.pop());
  10705. argsLength++;
  10706. }
  10707. }
  10708. if (argsLength < numArgs) {
  10709. // If we receive too few args, it's not possible to possible
  10710. // to execute the command, so skip the command
  10711. info('Command ' + fn + ': because expected ' +
  10712. numArgs + ' args, but received ' + argsLength +
  10713. ' args; skipping');
  10714. args = null;
  10715. continue;
  10716. }
  10717. } else if (argsLength > numArgs) {
  10718. info('Command ' + fn + ': expected [0,' + numArgs +
  10719. '] args, but received ' + argsLength + ' args');
  10720. }
  10721. // TODO figure out how to type-check vararg functions
  10722. this.preprocessCommand(fn, args);
  10723. operation.fn = fn;
  10724. operation.args = args;
  10725. return true;
  10726. } else {
  10727. if (isEOF(obj)) {
  10728. return false; // no more commands
  10729. }
  10730. // argument
  10731. if (obj !== null) {
  10732. if (!args) {
  10733. args = [];
  10734. }
  10735. args.push((obj instanceof Dict ? obj.getAll() : obj));
  10736. assert(args.length <= 33, 'Too many arguments');
  10737. }
  10738. }
  10739. }
  10740. },
  10741. preprocessCommand:
  10742. function EvaluatorPreprocessor_preprocessCommand(fn, args) {
  10743. switch (fn | 0) {
  10744. case OPS.save:
  10745. this.stateManager.save();
  10746. break;
  10747. case OPS.restore:
  10748. this.stateManager.restore();
  10749. break;
  10750. case OPS.transform:
  10751. this.stateManager.transform(args);
  10752. break;
  10753. }
  10754. }
  10755. };
  10756. return EvaluatorPreprocessor;
  10757. })();
  10758. var QueueOptimizer = (function QueueOptimizerClosure() {
  10759. function addState(parentState, pattern, fn) {
  10760. var state = parentState;
  10761. for (var i = 0, ii = pattern.length - 1; i < ii; i++) {
  10762. var item = pattern[i];
  10763. state = (state[item] || (state[item] = []));
  10764. }
  10765. state[pattern[pattern.length - 1]] = fn;
  10766. }
  10767. function handlePaintSolidColorImageMask(index, count, fnArray, argsArray) {
  10768. // Handles special case of mainly LaTeX documents which
  10769. // use image masks to draw lines with the current fill style.
  10770. // 'count' groups of (save, transform, paintImageMaskXObject, restore)+
  10771. // have been found at index.
  10772. for (var i = 0; i < count; i++) {
  10773. var arg = argsArray[index + 4 * i + 2];
  10774. var imageMask = arg.length === 1 && arg[0];
  10775. if (imageMask && imageMask.width === 1 && imageMask.height === 1 &&
  10776. (!imageMask.data.length || (imageMask.data.length === 1 &&
  10777. imageMask.data[0] === 0))) {
  10778. fnArray[index + 4 * i + 2] = OPS.paintSolidColorImageMask;
  10779. continue;
  10780. }
  10781. break;
  10782. }
  10783. return count - i;
  10784. }
  10785. var InitialState = [];
  10786. addState(InitialState,
  10787. [OPS.save, OPS.transform, OPS.paintInlineImageXObject, OPS.restore],
  10788. function foundInlineImageGroup(context) {
  10789. // grouping paintInlineImageXObject's into paintInlineImageXObjectGroup
  10790. // searching for (save, transform, paintInlineImageXObject, restore)+
  10791. var MIN_IMAGES_IN_INLINE_IMAGES_BLOCK = 10;
  10792. var MAX_IMAGES_IN_INLINE_IMAGES_BLOCK = 200;
  10793. var MAX_WIDTH = 1000;
  10794. var IMAGE_PADDING = 1;
  10795. var fnArray = context.fnArray, argsArray = context.argsArray;
  10796. var j = context.currentOperation - 3, i = j + 4;
  10797. var ii = fnArray.length;
  10798. for (; i < ii && fnArray[i - 4] === fnArray[i]; i++) {}
  10799. var count = Math.min((i - j) >> 2, MAX_IMAGES_IN_INLINE_IMAGES_BLOCK);
  10800. if (count < MIN_IMAGES_IN_INLINE_IMAGES_BLOCK) {
  10801. context.currentOperation = i - 1;
  10802. return;
  10803. }
  10804. // assuming that heights of those image is too small (~1 pixel)
  10805. // packing as much as possible by lines
  10806. var maxX = 0;
  10807. var map = [], maxLineHeight = 0;
  10808. var currentX = IMAGE_PADDING, currentY = IMAGE_PADDING;
  10809. var q;
  10810. for (q = 0; q < count; q++) {
  10811. var transform = argsArray[j + (q << 2) + 1];
  10812. var img = argsArray[j + (q << 2) + 2][0];
  10813. if (currentX + img.width > MAX_WIDTH) {
  10814. // starting new line
  10815. maxX = Math.max(maxX, currentX);
  10816. currentY += maxLineHeight + 2 * IMAGE_PADDING;
  10817. currentX = 0;
  10818. maxLineHeight = 0;
  10819. }
  10820. map.push({
  10821. transform: transform,
  10822. x: currentX, y: currentY,
  10823. w: img.width, h: img.height
  10824. });
  10825. currentX += img.width + 2 * IMAGE_PADDING;
  10826. maxLineHeight = Math.max(maxLineHeight, img.height);
  10827. }
  10828. var imgWidth = Math.max(maxX, currentX) + IMAGE_PADDING;
  10829. var imgHeight = currentY + maxLineHeight + IMAGE_PADDING;
  10830. var imgData = new Uint8Array(imgWidth * imgHeight * 4);
  10831. var imgRowSize = imgWidth << 2;
  10832. for (q = 0; q < count; q++) {
  10833. var data = argsArray[j + (q << 2) + 2][0].data;
  10834. // copy image by lines and extends pixels into padding
  10835. var rowSize = map[q].w << 2;
  10836. var dataOffset = 0;
  10837. var offset = (map[q].x + map[q].y * imgWidth) << 2;
  10838. imgData.set(data.subarray(0, rowSize), offset - imgRowSize);
  10839. for (var k = 0, kk = map[q].h; k < kk; k++) {
  10840. imgData.set(data.subarray(dataOffset, dataOffset + rowSize), offset);
  10841. dataOffset += rowSize;
  10842. offset += imgRowSize;
  10843. }
  10844. imgData.set(data.subarray(dataOffset - rowSize, dataOffset), offset);
  10845. while (offset >= 0) {
  10846. data[offset - 4] = data[offset];
  10847. data[offset - 3] = data[offset + 1];
  10848. data[offset - 2] = data[offset + 2];
  10849. data[offset - 1] = data[offset + 3];
  10850. data[offset + rowSize] = data[offset + rowSize - 4];
  10851. data[offset + rowSize + 1] = data[offset + rowSize - 3];
  10852. data[offset + rowSize + 2] = data[offset + rowSize - 2];
  10853. data[offset + rowSize + 3] = data[offset + rowSize - 1];
  10854. offset -= imgRowSize;
  10855. }
  10856. }
  10857. // replacing queue items
  10858. fnArray.splice(j, count * 4, OPS.paintInlineImageXObjectGroup);
  10859. argsArray.splice(j, count * 4,
  10860. [{ width: imgWidth, height: imgHeight, kind: ImageKind.RGBA_32BPP,
  10861. data: imgData }, map]);
  10862. context.currentOperation = j;
  10863. });
  10864. addState(InitialState,
  10865. [OPS.save, OPS.transform, OPS.paintImageMaskXObject, OPS.restore],
  10866. function foundImageMaskGroup(context) {
  10867. // grouping paintImageMaskXObject's into paintImageMaskXObjectGroup
  10868. // searching for (save, transform, paintImageMaskXObject, restore)+
  10869. var MIN_IMAGES_IN_MASKS_BLOCK = 10;
  10870. var MAX_IMAGES_IN_MASKS_BLOCK = 100;
  10871. var MAX_SAME_IMAGES_IN_MASKS_BLOCK = 1000;
  10872. var fnArray = context.fnArray, argsArray = context.argsArray;
  10873. var j = context.currentOperation - 3, i = j + 4;
  10874. var ii = fnArray.length, q;
  10875. for (; i < ii && fnArray[i - 4] === fnArray[i]; i++) {}
  10876. var count = (i - j) >> 2;
  10877. count = handlePaintSolidColorImageMask(j, count, fnArray, argsArray);
  10878. if (count < MIN_IMAGES_IN_MASKS_BLOCK) {
  10879. context.currentOperation = i - 1;
  10880. return;
  10881. }
  10882. var isSameImage = false;
  10883. var transformArgs;
  10884. if (argsArray[j + 1][1] === 0 && argsArray[j + 1][2] === 0) {
  10885. i = j + 4;
  10886. isSameImage = true;
  10887. for (q = 1; q < count; q++, i += 4) {
  10888. var prevTransformArgs = argsArray[i - 3];
  10889. transformArgs = argsArray[i + 1];
  10890. if (argsArray[i - 2][0] !== argsArray[i + 2][0] ||
  10891. prevTransformArgs[0] !== transformArgs[0] ||
  10892. prevTransformArgs[1] !== transformArgs[1] ||
  10893. prevTransformArgs[2] !== transformArgs[2] ||
  10894. prevTransformArgs[3] !== transformArgs[3]) {
  10895. if (q < MIN_IMAGES_IN_MASKS_BLOCK) {
  10896. isSameImage = false;
  10897. } else {
  10898. count = q;
  10899. }
  10900. break; // different image or transform
  10901. }
  10902. }
  10903. }
  10904. if (isSameImage) {
  10905. count = Math.min(count, MAX_SAME_IMAGES_IN_MASKS_BLOCK);
  10906. var positions = new Float32Array(count * 2);
  10907. i = j + 1;
  10908. for (q = 0; q < count; q++) {
  10909. transformArgs = argsArray[i];
  10910. positions[(q << 1)] = transformArgs[4];
  10911. positions[(q << 1) + 1] = transformArgs[5];
  10912. i += 4;
  10913. }
  10914. // replacing queue items
  10915. fnArray.splice(j, count * 4, OPS.paintImageMaskXObjectRepeat);
  10916. argsArray.splice(j, count * 4, [argsArray[j + 2][0],
  10917. argsArray[j + 1][0], argsArray[j + 1][3], positions]);
  10918. context.currentOperation = j;
  10919. } else {
  10920. count = Math.min(count, MAX_IMAGES_IN_MASKS_BLOCK);
  10921. var images = [];
  10922. for (q = 0; q < count; q++) {
  10923. transformArgs = argsArray[j + (q << 2) + 1];
  10924. var maskParams = argsArray[j + (q << 2) + 2][0];
  10925. images.push({ data: maskParams.data, width: maskParams.width,
  10926. height: maskParams.height,
  10927. transform: transformArgs });
  10928. }
  10929. // replacing queue items
  10930. fnArray.splice(j, count * 4, OPS.paintImageMaskXObjectGroup);
  10931. argsArray.splice(j, count * 4, [images]);
  10932. context.currentOperation = j;
  10933. }
  10934. });
  10935. addState(InitialState,
  10936. [OPS.save, OPS.transform, OPS.paintImageXObject, OPS.restore],
  10937. function (context) {
  10938. var MIN_IMAGES_IN_BLOCK = 3;
  10939. var MAX_IMAGES_IN_BLOCK = 1000;
  10940. var fnArray = context.fnArray, argsArray = context.argsArray;
  10941. var j = context.currentOperation - 3, i = j + 4;
  10942. if (argsArray[j + 1][1] !== 0 || argsArray[j + 1][2] !== 0) {
  10943. return;
  10944. }
  10945. var ii = fnArray.length;
  10946. var transformArgs;
  10947. for (; i + 3 < ii && fnArray[i - 4] === fnArray[i]; i += 4) {
  10948. if (fnArray[i - 3] !== fnArray[i + 1] ||
  10949. fnArray[i - 2] !== fnArray[i + 2] ||
  10950. fnArray[i - 1] !== fnArray[i + 3]) {
  10951. break;
  10952. }
  10953. if (argsArray[i - 2][0] !== argsArray[i + 2][0]) {
  10954. break; // different image
  10955. }
  10956. var prevTransformArgs = argsArray[i - 3];
  10957. transformArgs = argsArray[i + 1];
  10958. if (prevTransformArgs[0] !== transformArgs[0] ||
  10959. prevTransformArgs[1] !== transformArgs[1] ||
  10960. prevTransformArgs[2] !== transformArgs[2] ||
  10961. prevTransformArgs[3] !== transformArgs[3]) {
  10962. break; // different transform
  10963. }
  10964. }
  10965. var count = Math.min((i - j) >> 2, MAX_IMAGES_IN_BLOCK);
  10966. if (count < MIN_IMAGES_IN_BLOCK) {
  10967. context.currentOperation = i - 1;
  10968. return;
  10969. }
  10970. var positions = new Float32Array(count * 2);
  10971. i = j + 1;
  10972. for (var q = 0; q < count; q++) {
  10973. transformArgs = argsArray[i];
  10974. positions[(q << 1)] = transformArgs[4];
  10975. positions[(q << 1) + 1] = transformArgs[5];
  10976. i += 4;
  10977. }
  10978. var args = [argsArray[j + 2][0], argsArray[j + 1][0],
  10979. argsArray[j + 1][3], positions];
  10980. // replacing queue items
  10981. fnArray.splice(j, count * 4, OPS.paintImageXObjectRepeat);
  10982. argsArray.splice(j, count * 4, args);
  10983. context.currentOperation = j;
  10984. });
  10985. addState(InitialState,
  10986. [OPS.beginText, OPS.setFont, OPS.setTextMatrix, OPS.showText, OPS.endText],
  10987. function (context) {
  10988. // moving single chars with same font into beginText/endText groups
  10989. // searching for (beginText, setFont, setTextMatrix, showText, endText)+
  10990. var MIN_CHARS_IN_BLOCK = 3;
  10991. var MAX_CHARS_IN_BLOCK = 1000;
  10992. var fnArray = context.fnArray, argsArray = context.argsArray;
  10993. var j = context.currentOperation - 4, i = j + 5;
  10994. var ii = fnArray.length;
  10995. for (; i < ii && fnArray[i - 5] === fnArray[i]; i++) {
  10996. if (fnArray[i] === OPS.setFont) {
  10997. if (argsArray[i - 5][0] !== argsArray[i][0] ||
  10998. argsArray[i - 5][1] !== argsArray[i][1]) {
  10999. break;
  11000. }
  11001. }
  11002. }
  11003. var count = Math.min(((i - j) / 5) | 0, MAX_CHARS_IN_BLOCK);
  11004. if (count < MIN_CHARS_IN_BLOCK) {
  11005. context.currentOperation = i - 1;
  11006. return;
  11007. }
  11008. if (j >= 4 && fnArray[j - 4] === fnArray[j + 1] &&
  11009. fnArray[j - 3] === fnArray[j + 2] &&
  11010. fnArray[j - 2] === fnArray[j + 3] &&
  11011. fnArray[j - 1] === fnArray[j + 4] &&
  11012. argsArray[j - 4][0] === argsArray[j + 1][0] &&
  11013. argsArray[j - 4][1] === argsArray[j + 1][1]) {
  11014. // extending one block ahead (very first block might have 'dependency')
  11015. count++;
  11016. j -= 5;
  11017. }
  11018. var k = j + 7;
  11019. i = j + 4;
  11020. for (var q = 1; q < count; q++) {
  11021. fnArray[i] = fnArray[k];
  11022. argsArray[i] = argsArray[k];
  11023. fnArray[i + 1] = fnArray[k + 1];
  11024. argsArray[i + 1] = argsArray[k + 1];
  11025. i += 2;
  11026. k += 5;
  11027. }
  11028. var removed = (count - 1) * 3;
  11029. fnArray.splice(i, removed);
  11030. argsArray.splice(i, removed);
  11031. context.currentOperation = i;
  11032. });
  11033. function QueueOptimizer() {}
  11034. QueueOptimizer.prototype = {
  11035. optimize: function QueueOptimizer_optimize(queue) {
  11036. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  11037. var context = {
  11038. currentOperation: 0,
  11039. fnArray: fnArray,
  11040. argsArray: argsArray
  11041. };
  11042. var i, ii = argsArray.length;
  11043. var state;
  11044. for (i = 0; i < ii; i++) {
  11045. state = (state || InitialState)[fnArray[i]];
  11046. if (typeof state === 'function') { // we found some handler
  11047. context.currentOperation = i;
  11048. state = state(context);
  11049. i = context.currentOperation;
  11050. ii = context.fnArray.length;
  11051. }
  11052. }
  11053. }
  11054. };
  11055. return QueueOptimizer;
  11056. })();
  11057. var BUILT_IN_CMAPS = [
  11058. // << Start unicode maps.
  11059. 'Adobe-GB1-UCS2',
  11060. 'Adobe-CNS1-UCS2',
  11061. 'Adobe-Japan1-UCS2',
  11062. 'Adobe-Korea1-UCS2',
  11063. // >> End unicode maps.
  11064. '78-EUC-H',
  11065. '78-EUC-V',
  11066. '78-H',
  11067. '78-RKSJ-H',
  11068. '78-RKSJ-V',
  11069. '78-V',
  11070. '78ms-RKSJ-H',
  11071. '78ms-RKSJ-V',
  11072. '83pv-RKSJ-H',
  11073. '90ms-RKSJ-H',
  11074. '90ms-RKSJ-V',
  11075. '90msp-RKSJ-H',
  11076. '90msp-RKSJ-V',
  11077. '90pv-RKSJ-H',
  11078. '90pv-RKSJ-V',
  11079. 'Add-H',
  11080. 'Add-RKSJ-H',
  11081. 'Add-RKSJ-V',
  11082. 'Add-V',
  11083. 'Adobe-CNS1-0',
  11084. 'Adobe-CNS1-1',
  11085. 'Adobe-CNS1-2',
  11086. 'Adobe-CNS1-3',
  11087. 'Adobe-CNS1-4',
  11088. 'Adobe-CNS1-5',
  11089. 'Adobe-CNS1-6',
  11090. 'Adobe-GB1-0',
  11091. 'Adobe-GB1-1',
  11092. 'Adobe-GB1-2',
  11093. 'Adobe-GB1-3',
  11094. 'Adobe-GB1-4',
  11095. 'Adobe-GB1-5',
  11096. 'Adobe-Japan1-0',
  11097. 'Adobe-Japan1-1',
  11098. 'Adobe-Japan1-2',
  11099. 'Adobe-Japan1-3',
  11100. 'Adobe-Japan1-4',
  11101. 'Adobe-Japan1-5',
  11102. 'Adobe-Japan1-6',
  11103. 'Adobe-Korea1-0',
  11104. 'Adobe-Korea1-1',
  11105. 'Adobe-Korea1-2',
  11106. 'B5-H',
  11107. 'B5-V',
  11108. 'B5pc-H',
  11109. 'B5pc-V',
  11110. 'CNS-EUC-H',
  11111. 'CNS-EUC-V',
  11112. 'CNS1-H',
  11113. 'CNS1-V',
  11114. 'CNS2-H',
  11115. 'CNS2-V',
  11116. 'ETHK-B5-H',
  11117. 'ETHK-B5-V',
  11118. 'ETen-B5-H',
  11119. 'ETen-B5-V',
  11120. 'ETenms-B5-H',
  11121. 'ETenms-B5-V',
  11122. 'EUC-H',
  11123. 'EUC-V',
  11124. 'Ext-H',
  11125. 'Ext-RKSJ-H',
  11126. 'Ext-RKSJ-V',
  11127. 'Ext-V',
  11128. 'GB-EUC-H',
  11129. 'GB-EUC-V',
  11130. 'GB-H',
  11131. 'GB-V',
  11132. 'GBK-EUC-H',
  11133. 'GBK-EUC-V',
  11134. 'GBK2K-H',
  11135. 'GBK2K-V',
  11136. 'GBKp-EUC-H',
  11137. 'GBKp-EUC-V',
  11138. 'GBT-EUC-H',
  11139. 'GBT-EUC-V',
  11140. 'GBT-H',
  11141. 'GBT-V',
  11142. 'GBTpc-EUC-H',
  11143. 'GBTpc-EUC-V',
  11144. 'GBpc-EUC-H',
  11145. 'GBpc-EUC-V',
  11146. 'H',
  11147. 'HKdla-B5-H',
  11148. 'HKdla-B5-V',
  11149. 'HKdlb-B5-H',
  11150. 'HKdlb-B5-V',
  11151. 'HKgccs-B5-H',
  11152. 'HKgccs-B5-V',
  11153. 'HKm314-B5-H',
  11154. 'HKm314-B5-V',
  11155. 'HKm471-B5-H',
  11156. 'HKm471-B5-V',
  11157. 'HKscs-B5-H',
  11158. 'HKscs-B5-V',
  11159. 'Hankaku',
  11160. 'Hiragana',
  11161. 'KSC-EUC-H',
  11162. 'KSC-EUC-V',
  11163. 'KSC-H',
  11164. 'KSC-Johab-H',
  11165. 'KSC-Johab-V',
  11166. 'KSC-V',
  11167. 'KSCms-UHC-H',
  11168. 'KSCms-UHC-HW-H',
  11169. 'KSCms-UHC-HW-V',
  11170. 'KSCms-UHC-V',
  11171. 'KSCpc-EUC-H',
  11172. 'KSCpc-EUC-V',
  11173. 'Katakana',
  11174. 'NWP-H',
  11175. 'NWP-V',
  11176. 'RKSJ-H',
  11177. 'RKSJ-V',
  11178. 'Roman',
  11179. 'UniCNS-UCS2-H',
  11180. 'UniCNS-UCS2-V',
  11181. 'UniCNS-UTF16-H',
  11182. 'UniCNS-UTF16-V',
  11183. 'UniCNS-UTF32-H',
  11184. 'UniCNS-UTF32-V',
  11185. 'UniCNS-UTF8-H',
  11186. 'UniCNS-UTF8-V',
  11187. 'UniGB-UCS2-H',
  11188. 'UniGB-UCS2-V',
  11189. 'UniGB-UTF16-H',
  11190. 'UniGB-UTF16-V',
  11191. 'UniGB-UTF32-H',
  11192. 'UniGB-UTF32-V',
  11193. 'UniGB-UTF8-H',
  11194. 'UniGB-UTF8-V',
  11195. 'UniJIS-UCS2-H',
  11196. 'UniJIS-UCS2-HW-H',
  11197. 'UniJIS-UCS2-HW-V',
  11198. 'UniJIS-UCS2-V',
  11199. 'UniJIS-UTF16-H',
  11200. 'UniJIS-UTF16-V',
  11201. 'UniJIS-UTF32-H',
  11202. 'UniJIS-UTF32-V',
  11203. 'UniJIS-UTF8-H',
  11204. 'UniJIS-UTF8-V',
  11205. 'UniJIS2004-UTF16-H',
  11206. 'UniJIS2004-UTF16-V',
  11207. 'UniJIS2004-UTF32-H',
  11208. 'UniJIS2004-UTF32-V',
  11209. 'UniJIS2004-UTF8-H',
  11210. 'UniJIS2004-UTF8-V',
  11211. 'UniJISPro-UCS2-HW-V',
  11212. 'UniJISPro-UCS2-V',
  11213. 'UniJISPro-UTF8-V',
  11214. 'UniJISX0213-UTF32-H',
  11215. 'UniJISX0213-UTF32-V',
  11216. 'UniJISX02132004-UTF32-H',
  11217. 'UniJISX02132004-UTF32-V',
  11218. 'UniKS-UCS2-H',
  11219. 'UniKS-UCS2-V',
  11220. 'UniKS-UTF16-H',
  11221. 'UniKS-UTF16-V',
  11222. 'UniKS-UTF32-H',
  11223. 'UniKS-UTF32-V',
  11224. 'UniKS-UTF8-H',
  11225. 'UniKS-UTF8-V',
  11226. 'V',
  11227. 'WP-Symbol'];
  11228. // CMap, not to be confused with TrueType's cmap.
  11229. var CMap = (function CMapClosure() {
  11230. function CMap(builtInCMap) {
  11231. // Codespace ranges are stored as follows:
  11232. // [[1BytePairs], [2BytePairs], [3BytePairs], [4BytePairs]]
  11233. // where nBytePairs are ranges e.g. [low1, high1, low2, high2, ...]
  11234. this.codespaceRanges = [[], [], [], []];
  11235. this.numCodespaceRanges = 0;
  11236. this._map = [];
  11237. this.vertical = false;
  11238. this.useCMap = null;
  11239. this.builtInCMap = builtInCMap;
  11240. }
  11241. CMap.prototype = {
  11242. addCodespaceRange: function(n, low, high) {
  11243. this.codespaceRanges[n - 1].push(low, high);
  11244. this.numCodespaceRanges++;
  11245. },
  11246. mapRange: function(low, high, dstLow) {
  11247. var lastByte = dstLow.length - 1;
  11248. while (low <= high) {
  11249. this._map[low] = dstLow;
  11250. // Only the last byte has to be incremented.
  11251. dstLow = dstLow.substr(0, lastByte) +
  11252. String.fromCharCode(dstLow.charCodeAt(lastByte) + 1);
  11253. ++low;
  11254. }
  11255. },
  11256. mapRangeToArray: function(low, high, array) {
  11257. var i = 0, ii = array.length;
  11258. while (low <= high && i < ii) {
  11259. this._map[low] = array[i++];
  11260. ++low;
  11261. }
  11262. },
  11263. mapOne: function(src, dst) {
  11264. this._map[src] = dst;
  11265. },
  11266. lookup: function(code) {
  11267. return this._map[code];
  11268. },
  11269. contains: function(code) {
  11270. return this._map[code] !== undefined;
  11271. },
  11272. forEach: function(callback) {
  11273. // Most maps have fewer than 65536 entries, and for those we use normal
  11274. // array iteration. But really sparse tables are possible -- e.g. with
  11275. // indices in the *billions*. For such tables we use for..in, which isn't
  11276. // ideal because it stringifies the indices for all present elements, but
  11277. // it does avoid iterating over every undefined entry.
  11278. var map = this._map;
  11279. var length = map.length;
  11280. var i;
  11281. if (length <= 0x10000) {
  11282. for (i = 0; i < length; i++) {
  11283. if (map[i] !== undefined) {
  11284. callback(i, map[i]);
  11285. }
  11286. }
  11287. } else {
  11288. for (i in this._map) {
  11289. callback(i, map[i]);
  11290. }
  11291. }
  11292. },
  11293. charCodeOf: function(value) {
  11294. return this._map.indexOf(value);
  11295. },
  11296. getMap: function() {
  11297. return this._map;
  11298. },
  11299. readCharCode: function(str, offset) {
  11300. var c = 0;
  11301. var codespaceRanges = this.codespaceRanges;
  11302. var codespaceRangesLen = this.codespaceRanges.length;
  11303. // 9.7.6.2 CMap Mapping
  11304. // The code length is at most 4.
  11305. for (var n = 0; n < codespaceRangesLen; n++) {
  11306. c = ((c << 8) | str.charCodeAt(offset + n)) >>> 0;
  11307. // Check each codespace range to see if it falls within.
  11308. var codespaceRange = codespaceRanges[n];
  11309. for (var k = 0, kk = codespaceRange.length; k < kk;) {
  11310. var low = codespaceRange[k++];
  11311. var high = codespaceRange[k++];
  11312. if (c >= low && c <= high) {
  11313. return [c, n + 1];
  11314. }
  11315. }
  11316. }
  11317. return [0, 1];
  11318. }
  11319. };
  11320. return CMap;
  11321. })();
  11322. var IdentityCMap = (function IdentityCMapClosure() {
  11323. function IdentityCMap(vertical, n) {
  11324. CMap.call(this);
  11325. this.vertical = vertical;
  11326. this.addCodespaceRange(n, 0, 0xffff);
  11327. this.mapRange(0, 0xffff, '\u0000');
  11328. }
  11329. Util.inherit(IdentityCMap, CMap, {});
  11330. return IdentityCMap;
  11331. })();
  11332. var BinaryCMapReader = (function BinaryCMapReaderClosure() {
  11333. function fetchBinaryData(url) {
  11334. var nonBinaryRequest = PDFJS.disableWorker;
  11335. var request = new XMLHttpRequest();
  11336. request.open('GET', url, false);
  11337. if (!nonBinaryRequest) {
  11338. try {
  11339. request.responseType = 'arraybuffer';
  11340. nonBinaryRequest = request.responseType !== 'arraybuffer';
  11341. } catch (e) {
  11342. nonBinaryRequest = true;
  11343. }
  11344. }
  11345. if (nonBinaryRequest && request.overrideMimeType) {
  11346. request.overrideMimeType('text/plain; charset=x-user-defined');
  11347. }
  11348. request.send(null);
  11349. if (request.status === 0 && /^https?:/i.test(url)) {
  11350. error('Unable to get binary cMap at: ' + url);
  11351. }
  11352. if (nonBinaryRequest) {
  11353. var data = Array.prototype.map.call(request.responseText, function (ch) {
  11354. return ch.charCodeAt(0) & 255;
  11355. });
  11356. return new Uint8Array(data);
  11357. }
  11358. return new Uint8Array(request.response);
  11359. }
  11360. function hexToInt(a, size) {
  11361. var n = 0;
  11362. for (var i = 0; i <= size; i++) {
  11363. n = (n << 8) | a[i];
  11364. }
  11365. return n >>> 0;
  11366. }
  11367. function hexToStr(a, size) {
  11368. return String.fromCharCode.apply(null, a.subarray(0, size + 1));
  11369. }
  11370. function addHex(a, b, size) {
  11371. var c = 0;
  11372. for (var i = size; i >= 0; i--) {
  11373. c += a[i] + b[i];
  11374. a[i] = c & 255;
  11375. c >>= 8;
  11376. }
  11377. }
  11378. function incHex(a, size) {
  11379. var c = 1;
  11380. for (var i = size; i >= 0 && c > 0; i--) {
  11381. c += a[i];
  11382. a[i] = c & 255;
  11383. c >>= 8;
  11384. }
  11385. }
  11386. var MAX_NUM_SIZE = 16;
  11387. var MAX_ENCODED_NUM_SIZE = 19; // ceil(MAX_NUM_SIZE * 7 / 8)
  11388. function BinaryCMapStream(data) {
  11389. this.buffer = data;
  11390. this.pos = 0;
  11391. this.end = data.length;
  11392. this.tmpBuf = new Uint8Array(MAX_ENCODED_NUM_SIZE);
  11393. }
  11394. BinaryCMapStream.prototype = {
  11395. readByte: function () {
  11396. if (this.pos >= this.end) {
  11397. return -1;
  11398. }
  11399. return this.buffer[this.pos++];
  11400. },
  11401. readNumber: function () {
  11402. var n = 0;
  11403. var last;
  11404. do {
  11405. var b = this.readByte();
  11406. if (b < 0) {
  11407. error('unexpected EOF in bcmap');
  11408. }
  11409. last = !(b & 0x80);
  11410. n = (n << 7) | (b & 0x7F);
  11411. } while (!last);
  11412. return n;
  11413. },
  11414. readSigned: function () {
  11415. var n = this.readNumber();
  11416. return (n & 1) ? ~(n >>> 1) : n >>> 1;
  11417. },
  11418. readHex: function (num, size) {
  11419. num.set(this.buffer.subarray(this.pos,
  11420. this.pos + size + 1));
  11421. this.pos += size + 1;
  11422. },
  11423. readHexNumber: function (num, size) {
  11424. var last;
  11425. var stack = this.tmpBuf, sp = 0;
  11426. do {
  11427. var b = this.readByte();
  11428. if (b < 0) {
  11429. error('unexpected EOF in bcmap');
  11430. }
  11431. last = !(b & 0x80);
  11432. stack[sp++] = b & 0x7F;
  11433. } while (!last);
  11434. var i = size, buffer = 0, bufferSize = 0;
  11435. while (i >= 0) {
  11436. while (bufferSize < 8 && stack.length > 0) {
  11437. buffer = (stack[--sp] << bufferSize) | buffer;
  11438. bufferSize += 7;
  11439. }
  11440. num[i] = buffer & 255;
  11441. i--;
  11442. buffer >>= 8;
  11443. bufferSize -= 8;
  11444. }
  11445. },
  11446. readHexSigned: function (num, size) {
  11447. this.readHexNumber(num, size);
  11448. var sign = num[size] & 1 ? 255 : 0;
  11449. var c = 0;
  11450. for (var i = 0; i <= size; i++) {
  11451. c = ((c & 1) << 8) | num[i];
  11452. num[i] = (c >> 1) ^ sign;
  11453. }
  11454. },
  11455. readString: function () {
  11456. var len = this.readNumber();
  11457. var s = '';
  11458. for (var i = 0; i < len; i++) {
  11459. s += String.fromCharCode(this.readNumber());
  11460. }
  11461. return s;
  11462. }
  11463. };
  11464. function processBinaryCMap(url, cMap, extend) {
  11465. var data = fetchBinaryData(url);
  11466. var stream = new BinaryCMapStream(data);
  11467. var header = stream.readByte();
  11468. cMap.vertical = !!(header & 1);
  11469. var useCMap = null;
  11470. var start = new Uint8Array(MAX_NUM_SIZE);
  11471. var end = new Uint8Array(MAX_NUM_SIZE);
  11472. var char = new Uint8Array(MAX_NUM_SIZE);
  11473. var charCode = new Uint8Array(MAX_NUM_SIZE);
  11474. var tmp = new Uint8Array(MAX_NUM_SIZE);
  11475. var code;
  11476. var b;
  11477. while ((b = stream.readByte()) >= 0) {
  11478. var type = b >> 5;
  11479. if (type === 7) { // metadata, e.g. comment or usecmap
  11480. switch (b & 0x1F) {
  11481. case 0:
  11482. stream.readString(); // skipping comment
  11483. break;
  11484. case 1:
  11485. useCMap = stream.readString();
  11486. break;
  11487. }
  11488. continue;
  11489. }
  11490. var sequence = !!(b & 0x10);
  11491. var dataSize = b & 15;
  11492. assert(dataSize + 1 <= MAX_NUM_SIZE);
  11493. var ucs2DataSize = 1;
  11494. var subitemsCount = stream.readNumber();
  11495. var i;
  11496. switch (type) {
  11497. case 0: // codespacerange
  11498. stream.readHex(start, dataSize);
  11499. stream.readHexNumber(end, dataSize);
  11500. addHex(end, start, dataSize);
  11501. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  11502. hexToInt(end, dataSize));
  11503. for (i = 1; i < subitemsCount; i++) {
  11504. incHex(end, dataSize);
  11505. stream.readHexNumber(start, dataSize);
  11506. addHex(start, end, dataSize);
  11507. stream.readHexNumber(end, dataSize);
  11508. addHex(end, start, dataSize);
  11509. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  11510. hexToInt(end, dataSize));
  11511. }
  11512. break;
  11513. case 1: // notdefrange
  11514. stream.readHex(start, dataSize);
  11515. stream.readHexNumber(end, dataSize);
  11516. addHex(end, start, dataSize);
  11517. code = stream.readNumber();
  11518. // undefined range, skipping
  11519. for (i = 1; i < subitemsCount; i++) {
  11520. incHex(end, dataSize);
  11521. stream.readHexNumber(start, dataSize);
  11522. addHex(start, end, dataSize);
  11523. stream.readHexNumber(end, dataSize);
  11524. addHex(end, start, dataSize);
  11525. code = stream.readNumber();
  11526. // nop
  11527. }
  11528. break;
  11529. case 2: // cidchar
  11530. stream.readHex(char, dataSize);
  11531. code = stream.readNumber();
  11532. cMap.mapOne(hexToInt(char, dataSize), String.fromCharCode(code));
  11533. for (i = 1; i < subitemsCount; i++) {
  11534. incHex(char, dataSize);
  11535. if (!sequence) {
  11536. stream.readHexNumber(tmp, dataSize);
  11537. addHex(char, tmp, dataSize);
  11538. }
  11539. code = stream.readSigned() + (code + 1);
  11540. cMap.mapOne(hexToInt(char, dataSize), String.fromCharCode(code));
  11541. }
  11542. break;
  11543. case 3: // cidrange
  11544. stream.readHex(start, dataSize);
  11545. stream.readHexNumber(end, dataSize);
  11546. addHex(end, start, dataSize);
  11547. code = stream.readNumber();
  11548. cMap.mapRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  11549. String.fromCharCode(code));
  11550. for (i = 1; i < subitemsCount; i++) {
  11551. incHex(end, dataSize);
  11552. if (!sequence) {
  11553. stream.readHexNumber(start, dataSize);
  11554. addHex(start, end, dataSize);
  11555. } else {
  11556. start.set(end);
  11557. }
  11558. stream.readHexNumber(end, dataSize);
  11559. addHex(end, start, dataSize);
  11560. code = stream.readNumber();
  11561. cMap.mapRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  11562. String.fromCharCode(code));
  11563. }
  11564. break;
  11565. case 4: // bfchar
  11566. stream.readHex(char, ucs2DataSize);
  11567. stream.readHex(charCode, dataSize);
  11568. cMap.mapOne(hexToInt(char, ucs2DataSize),
  11569. hexToStr(charCode, dataSize));
  11570. for (i = 1; i < subitemsCount; i++) {
  11571. incHex(char, ucs2DataSize);
  11572. if (!sequence) {
  11573. stream.readHexNumber(tmp, ucs2DataSize);
  11574. addHex(char, tmp, ucs2DataSize);
  11575. }
  11576. incHex(charCode, dataSize);
  11577. stream.readHexSigned(tmp, dataSize);
  11578. addHex(charCode, tmp, dataSize);
  11579. cMap.mapOne(hexToInt(char, ucs2DataSize),
  11580. hexToStr(charCode, dataSize));
  11581. }
  11582. break;
  11583. case 5: // bfrange
  11584. stream.readHex(start, ucs2DataSize);
  11585. stream.readHexNumber(end, ucs2DataSize);
  11586. addHex(end, start, ucs2DataSize);
  11587. stream.readHex(charCode, dataSize);
  11588. cMap.mapRange(hexToInt(start, ucs2DataSize),
  11589. hexToInt(end, ucs2DataSize),
  11590. hexToStr(charCode, dataSize));
  11591. for (i = 1; i < subitemsCount; i++) {
  11592. incHex(end, ucs2DataSize);
  11593. if (!sequence) {
  11594. stream.readHexNumber(start, ucs2DataSize);
  11595. addHex(start, end, ucs2DataSize);
  11596. } else {
  11597. start.set(end);
  11598. }
  11599. stream.readHexNumber(end, ucs2DataSize);
  11600. addHex(end, start, ucs2DataSize);
  11601. stream.readHex(charCode, dataSize);
  11602. cMap.mapRange(hexToInt(start, ucs2DataSize),
  11603. hexToInt(end, ucs2DataSize),
  11604. hexToStr(charCode, dataSize));
  11605. }
  11606. break;
  11607. default:
  11608. error('Unknown type: ' + type);
  11609. break;
  11610. }
  11611. }
  11612. if (useCMap) {
  11613. extend(useCMap);
  11614. }
  11615. return cMap;
  11616. }
  11617. function BinaryCMapReader() {}
  11618. BinaryCMapReader.prototype = {
  11619. read: processBinaryCMap
  11620. };
  11621. return BinaryCMapReader;
  11622. })();
  11623. var CMapFactory = (function CMapFactoryClosure() {
  11624. function strToInt(str) {
  11625. var a = 0;
  11626. for (var i = 0; i < str.length; i++) {
  11627. a = (a << 8) | str.charCodeAt(i);
  11628. }
  11629. return a >>> 0;
  11630. }
  11631. function expectString(obj) {
  11632. if (!isString(obj)) {
  11633. error('Malformed CMap: expected string.');
  11634. }
  11635. }
  11636. function expectInt(obj) {
  11637. if (!isInt(obj)) {
  11638. error('Malformed CMap: expected int.');
  11639. }
  11640. }
  11641. function parseBfChar(cMap, lexer) {
  11642. while (true) {
  11643. var obj = lexer.getObj();
  11644. if (isEOF(obj)) {
  11645. break;
  11646. }
  11647. if (isCmd(obj, 'endbfchar')) {
  11648. return;
  11649. }
  11650. expectString(obj);
  11651. var src = strToInt(obj);
  11652. obj = lexer.getObj();
  11653. // TODO are /dstName used?
  11654. expectString(obj);
  11655. var dst = obj;
  11656. cMap.mapOne(src, dst);
  11657. }
  11658. }
  11659. function parseBfRange(cMap, lexer) {
  11660. while (true) {
  11661. var obj = lexer.getObj();
  11662. if (isEOF(obj)) {
  11663. break;
  11664. }
  11665. if (isCmd(obj, 'endbfrange')) {
  11666. return;
  11667. }
  11668. expectString(obj);
  11669. var low = strToInt(obj);
  11670. obj = lexer.getObj();
  11671. expectString(obj);
  11672. var high = strToInt(obj);
  11673. obj = lexer.getObj();
  11674. if (isInt(obj) || isString(obj)) {
  11675. var dstLow = isInt(obj) ? String.fromCharCode(obj) : obj;
  11676. cMap.mapRange(low, high, dstLow);
  11677. } else if (isCmd(obj, '[')) {
  11678. obj = lexer.getObj();
  11679. var array = [];
  11680. while (!isCmd(obj, ']') && !isEOF(obj)) {
  11681. array.push(obj);
  11682. obj = lexer.getObj();
  11683. }
  11684. cMap.mapRangeToArray(low, high, array);
  11685. } else {
  11686. break;
  11687. }
  11688. }
  11689. error('Invalid bf range.');
  11690. }
  11691. function parseCidChar(cMap, lexer) {
  11692. while (true) {
  11693. var obj = lexer.getObj();
  11694. if (isEOF(obj)) {
  11695. break;
  11696. }
  11697. if (isCmd(obj, 'endcidchar')) {
  11698. return;
  11699. }
  11700. expectString(obj);
  11701. var src = strToInt(obj);
  11702. obj = lexer.getObj();
  11703. expectInt(obj);
  11704. var dst = String.fromCharCode(obj);
  11705. cMap.mapOne(src, dst);
  11706. }
  11707. }
  11708. function parseCidRange(cMap, lexer) {
  11709. while (true) {
  11710. var obj = lexer.getObj();
  11711. if (isEOF(obj)) {
  11712. break;
  11713. }
  11714. if (isCmd(obj, 'endcidrange')) {
  11715. return;
  11716. }
  11717. expectString(obj);
  11718. var low = strToInt(obj);
  11719. obj = lexer.getObj();
  11720. expectString(obj);
  11721. var high = strToInt(obj);
  11722. obj = lexer.getObj();
  11723. expectInt(obj);
  11724. var dstLow = String.fromCharCode(obj);
  11725. cMap.mapRange(low, high, dstLow);
  11726. }
  11727. }
  11728. function parseCodespaceRange(cMap, lexer) {
  11729. while (true) {
  11730. var obj = lexer.getObj();
  11731. if (isEOF(obj)) {
  11732. break;
  11733. }
  11734. if (isCmd(obj, 'endcodespacerange')) {
  11735. return;
  11736. }
  11737. if (!isString(obj)) {
  11738. break;
  11739. }
  11740. var low = strToInt(obj);
  11741. obj = lexer.getObj();
  11742. if (!isString(obj)) {
  11743. break;
  11744. }
  11745. var high = strToInt(obj);
  11746. cMap.addCodespaceRange(obj.length, low, high);
  11747. }
  11748. error('Invalid codespace range.');
  11749. }
  11750. function parseWMode(cMap, lexer) {
  11751. var obj = lexer.getObj();
  11752. if (isInt(obj)) {
  11753. cMap.vertical = !!obj;
  11754. }
  11755. }
  11756. function parseCMap(cMap, lexer, builtInCMapParams, useCMap) {
  11757. var previous;
  11758. var embededUseCMap;
  11759. objLoop: while (true) {
  11760. var obj = lexer.getObj();
  11761. if (isEOF(obj)) {
  11762. break;
  11763. } else if (isName(obj)) {
  11764. if (obj.name === 'WMode') {
  11765. parseWMode(cMap, lexer);
  11766. }
  11767. previous = obj;
  11768. } else if (isCmd(obj)) {
  11769. switch (obj.cmd) {
  11770. case 'endcmap':
  11771. break objLoop;
  11772. case 'usecmap':
  11773. if (isName(previous)) {
  11774. embededUseCMap = previous.name;
  11775. }
  11776. break;
  11777. case 'begincodespacerange':
  11778. parseCodespaceRange(cMap, lexer);
  11779. break;
  11780. case 'beginbfchar':
  11781. parseBfChar(cMap, lexer);
  11782. break;
  11783. case 'begincidchar':
  11784. parseCidChar(cMap, lexer);
  11785. break;
  11786. case 'beginbfrange':
  11787. parseBfRange(cMap, lexer);
  11788. break;
  11789. case 'begincidrange':
  11790. parseCidRange(cMap, lexer);
  11791. break;
  11792. }
  11793. }
  11794. }
  11795. if (!useCMap && embededUseCMap) {
  11796. // Load the usecmap definition from the file only if there wasn't one
  11797. // specified.
  11798. useCMap = embededUseCMap;
  11799. }
  11800. if (useCMap) {
  11801. extendCMap(cMap, builtInCMapParams, useCMap);
  11802. }
  11803. }
  11804. function extendCMap(cMap, builtInCMapParams, useCMap) {
  11805. cMap.useCMap = createBuiltInCMap(useCMap, builtInCMapParams);
  11806. // If there aren't any code space ranges defined clone all the parent ones
  11807. // into this cMap.
  11808. if (cMap.numCodespaceRanges === 0) {
  11809. var useCodespaceRanges = cMap.useCMap.codespaceRanges;
  11810. for (var i = 0; i < useCodespaceRanges.length; i++) {
  11811. cMap.codespaceRanges[i] = useCodespaceRanges[i].slice();
  11812. }
  11813. cMap.numCodespaceRanges = cMap.useCMap.numCodespaceRanges;
  11814. }
  11815. // Merge the map into the current one, making sure not to override
  11816. // any previously defined entries.
  11817. cMap.useCMap.forEach(function(key, value) {
  11818. if (!cMap.contains(key)) {
  11819. cMap.mapOne(key, cMap.useCMap.lookup(key));
  11820. }
  11821. });
  11822. }
  11823. function parseBinaryCMap(name, builtInCMapParams) {
  11824. var url = builtInCMapParams.url + name + '.bcmap';
  11825. var cMap = new CMap(true);
  11826. new BinaryCMapReader().read(url, cMap, function (useCMap) {
  11827. extendCMap(cMap, builtInCMapParams, useCMap);
  11828. });
  11829. return cMap;
  11830. }
  11831. function createBuiltInCMap(name, builtInCMapParams) {
  11832. if (name === 'Identity-H') {
  11833. return new IdentityCMap(false, 2);
  11834. } else if (name === 'Identity-V') {
  11835. return new IdentityCMap(true, 2);
  11836. }
  11837. if (BUILT_IN_CMAPS.indexOf(name) === -1) {
  11838. error('Unknown cMap name: ' + name);
  11839. }
  11840. assert(builtInCMapParams, 'built-in cMap parameters are not provided');
  11841. if (builtInCMapParams.packed) {
  11842. return parseBinaryCMap(name, builtInCMapParams);
  11843. }
  11844. var request = new XMLHttpRequest();
  11845. var url = builtInCMapParams.url + name;
  11846. request.open('GET', url, false);
  11847. request.send(null);
  11848. if (request.status === 0 && /^https?:/i.test(url)) {
  11849. error('Unable to get cMap at: ' + url);
  11850. }
  11851. var cMap = new CMap(true);
  11852. var lexer = new Lexer(new StringStream(request.responseText));
  11853. parseCMap(cMap, lexer, builtInCMapParams, null);
  11854. return cMap;
  11855. }
  11856. return {
  11857. create: function (encoding, builtInCMapParams, useCMap) {
  11858. if (isName(encoding)) {
  11859. return createBuiltInCMap(encoding.name, builtInCMapParams);
  11860. } else if (isStream(encoding)) {
  11861. var cMap = new CMap();
  11862. var lexer = new Lexer(encoding);
  11863. try {
  11864. parseCMap(cMap, lexer, builtInCMapParams, useCMap);
  11865. } catch (e) {
  11866. warn('Invalid CMap data. ' + e);
  11867. }
  11868. return cMap;
  11869. }
  11870. error('Encoding required.');
  11871. }
  11872. };
  11873. })();
  11874. // Unicode Private Use Area
  11875. var PRIVATE_USE_OFFSET_START = 0xE000;
  11876. var PRIVATE_USE_OFFSET_END = 0xF8FF;
  11877. var SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = false;
  11878. // PDF Glyph Space Units are one Thousandth of a TextSpace Unit
  11879. // except for Type 3 fonts
  11880. var PDF_GLYPH_SPACE_UNITS = 1000;
  11881. // Hinting is currently disabled due to unknown problems on windows
  11882. // in tracemonkey and various other pdfs with type1 fonts.
  11883. var HINTING_ENABLED = false;
  11884. // Accented charactars are not displayed properly on windows, using this flag
  11885. // to control analysis of seac charstrings.
  11886. var SEAC_ANALYSIS_ENABLED = false;
  11887. var FontFlags = {
  11888. FixedPitch: 1,
  11889. Serif: 2,
  11890. Symbolic: 4,
  11891. Script: 8,
  11892. Nonsymbolic: 32,
  11893. Italic: 64,
  11894. AllCap: 65536,
  11895. SmallCap: 131072,
  11896. ForceBold: 262144
  11897. };
  11898. var Encodings = {
  11899. ExpertEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  11900. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  11901. 'space', 'exclamsmall', 'Hungarumlautsmall', '', 'dollaroldstyle',
  11902. 'dollarsuperior', 'ampersandsmall', 'Acutesmall', 'parenleftsuperior',
  11903. 'parenrightsuperior', 'twodotenleader', 'onedotenleader', 'comma',
  11904. 'hyphen', 'period', 'fraction', 'zerooldstyle', 'oneoldstyle',
  11905. 'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle',
  11906. 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'colon',
  11907. 'semicolon', 'commasuperior', 'threequartersemdash', 'periodsuperior',
  11908. 'questionsmall', '', 'asuperior', 'bsuperior', 'centsuperior', 'dsuperior',
  11909. 'esuperior', '', '', 'isuperior', '', '', 'lsuperior', 'msuperior',
  11910. 'nsuperior', 'osuperior', '', '', 'rsuperior', 'ssuperior', 'tsuperior',
  11911. '', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior', '',
  11912. 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall',
  11913. 'Asmall', 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall',
  11914. 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall',
  11915. 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall',
  11916. 'Vsmall', 'Wsmall', 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary',
  11917. 'onefitted', 'rupiah', 'Tildesmall', '', '', '', '', '', '', '', '', '',
  11918. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  11919. '', '', '', '', '', '', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall',
  11920. '', '', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall',
  11921. 'Caronsmall', '', 'Dotaccentsmall', '', '', 'Macronsmall', '', '',
  11922. 'figuredash', 'hypheninferior', '', '', 'Ogoneksmall', 'Ringsmall',
  11923. 'Cedillasmall', '', '', '', 'onequarter', 'onehalf', 'threequarters',
  11924. 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths',
  11925. 'seveneighths', 'onethird', 'twothirds', '', '', 'zerosuperior',
  11926. 'onesuperior', 'twosuperior', 'threesuperior', 'foursuperior',
  11927. 'fivesuperior', 'sixsuperior', 'sevensuperior', 'eightsuperior',
  11928. 'ninesuperior', 'zeroinferior', 'oneinferior', 'twoinferior',
  11929. 'threeinferior', 'fourinferior', 'fiveinferior', 'sixinferior',
  11930. 'seveninferior', 'eightinferior', 'nineinferior', 'centinferior',
  11931. 'dollarinferior', 'periodinferior', 'commainferior', 'Agravesmall',
  11932. 'Aacutesmall', 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall',
  11933. 'Aringsmall', 'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall',
  11934. 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall',
  11935. 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall',
  11936. 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall',
  11937. 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall',
  11938. 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall',
  11939. 'Ydieresissmall'],
  11940. MacExpertEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  11941. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  11942. 'space', 'exclamsmall', 'Hungarumlautsmall', 'centoldstyle',
  11943. 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall', 'Acutesmall',
  11944. 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  11945. 'onedotenleader', 'comma', 'hyphen', 'period', 'fraction', 'zerooldstyle',
  11946. 'oneoldstyle', 'twooldstyle', 'threeoldstyle', 'fouroldstyle',
  11947. 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle',
  11948. 'nineoldstyle', 'colon', 'semicolon', '', 'threequartersemdash', '',
  11949. 'questionsmall', '', '', '', '', 'Ethsmall', '', '', 'onequarter',
  11950. 'onehalf', 'threequarters', 'oneeighth', 'threeeighths', 'fiveeighths',
  11951. 'seveneighths', 'onethird', 'twothirds', '', '', '', '', '', '', 'ff',
  11952. 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior', '', 'parenrightinferior',
  11953. 'Circumflexsmall', 'hypheninferior', 'Gravesmall', 'Asmall', 'Bsmall',
  11954. 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall',
  11955. 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall',
  11956. 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
  11957. 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah',
  11958. 'Tildesmall', '', '', 'asuperior', 'centsuperior', '', '', '', '',
  11959. 'Aacutesmall', 'Agravesmall', 'Acircumflexsmall', 'Adieresissmall',
  11960. 'Atildesmall', 'Aringsmall', 'Ccedillasmall', 'Eacutesmall', 'Egravesmall',
  11961. 'Ecircumflexsmall', 'Edieresissmall', 'Iacutesmall', 'Igravesmall',
  11962. 'Icircumflexsmall', 'Idieresissmall', 'Ntildesmall', 'Oacutesmall',
  11963. 'Ogravesmall', 'Ocircumflexsmall', 'Odieresissmall', 'Otildesmall',
  11964. 'Uacutesmall', 'Ugravesmall', 'Ucircumflexsmall', 'Udieresissmall', '',
  11965. 'eightsuperior', 'fourinferior', 'threeinferior', 'sixinferior',
  11966. 'eightinferior', 'seveninferior', 'Scaronsmall', '', 'centinferior',
  11967. 'twoinferior', '', 'Dieresissmall', '', 'Caronsmall', 'osuperior',
  11968. 'fiveinferior', '', 'commainferior', 'periodinferior', 'Yacutesmall', '',
  11969. 'dollarinferior', '', 'Thornsmall', '', 'nineinferior', 'zeroinferior',
  11970. 'Zcaronsmall', 'AEsmall', 'Oslashsmall', 'questiondownsmall',
  11971. 'oneinferior', 'Lslashsmall', '', '', '', '', '', '', 'Cedillasmall', '',
  11972. '', '', '', '', 'OEsmall', 'figuredash', 'hyphensuperior', '', '', '', '',
  11973. 'exclamdownsmall', '', 'Ydieresissmall', '', 'onesuperior', 'twosuperior',
  11974. 'threesuperior', 'foursuperior', 'fivesuperior', 'sixsuperior',
  11975. 'sevensuperior', 'ninesuperior', 'zerosuperior', '', 'esuperior',
  11976. 'rsuperior', 'tsuperior', '', '', 'isuperior', 'ssuperior', 'dsuperior',
  11977. '', '', '', '', '', 'lsuperior', 'Ogoneksmall', 'Brevesmall',
  11978. 'Macronsmall', 'bsuperior', 'nsuperior', 'msuperior', 'commasuperior',
  11979. 'periodsuperior', 'Dotaccentsmall', 'Ringsmall'],
  11980. MacRomanEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  11981. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  11982. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  11983. 'ampersand', 'quotesingle', 'parenleft', 'parenright', 'asterisk', 'plus',
  11984. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  11985. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  11986. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  11987. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  11988. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  11989. 'asciicircum', 'underscore', 'grave', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
  11990. 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
  11991. 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', '',
  11992. 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde', 'Odieresis',
  11993. 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis', 'atilde',
  11994. 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  11995. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute',
  11996. 'ograve', 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave',
  11997. 'ucircumflex', 'udieresis', 'dagger', 'degree', 'cent', 'sterling',
  11998. 'section', 'bullet', 'paragraph', 'germandbls', 'registered', 'copyright',
  11999. 'trademark', 'acute', 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity',
  12000. 'plusminus', 'lessequal', 'greaterequal', 'yen', 'mu', 'partialdiff',
  12001. 'summation', 'product', 'pi', 'integral', 'ordfeminine', 'ordmasculine',
  12002. 'Omega', 'ae', 'oslash', 'questiondown', 'exclamdown', 'logicalnot',
  12003. 'radical', 'florin', 'approxequal', 'Delta', 'guillemotleft',
  12004. 'guillemotright', 'ellipsis', 'space', 'Agrave', 'Atilde', 'Otilde', 'OE',
  12005. 'oe', 'endash', 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft',
  12006. 'quoteright', 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction',
  12007. 'currency', 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl',
  12008. 'periodcentered', 'quotesinglbase', 'quotedblbase', 'perthousand',
  12009. 'Acircumflex', 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute',
  12010. 'Icircumflex', 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple',
  12011. 'Ograve', 'Uacute', 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex',
  12012. 'tilde', 'macron', 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut',
  12013. 'ogonek', 'caron'],
  12014. StandardEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12015. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12016. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  12017. 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus',
  12018. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  12019. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  12020. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  12021. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  12022. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  12023. 'asciicircum', 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f',
  12024. 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u',
  12025. 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde',
  12026. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12027. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', 'exclamdown',
  12028. 'cent', 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  12029. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  12030. 'guilsinglright', 'fi', 'fl', '', 'endash', 'dagger', 'daggerdbl',
  12031. 'periodcentered', '', 'paragraph', 'bullet', 'quotesinglbase',
  12032. 'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis',
  12033. 'perthousand', '', 'questiondown', '', 'grave', 'acute', 'circumflex',
  12034. 'tilde', 'macron', 'breve', 'dotaccent', 'dieresis', '', 'ring', 'cedilla',
  12035. '', 'hungarumlaut', 'ogonek', 'caron', 'emdash', '', '', '', '', '', '',
  12036. '', '', '', '', '', '', '', '', '', '', 'AE', '', 'ordfeminine', '', '',
  12037. '', '', 'Lslash', 'Oslash', 'OE', 'ordmasculine', '', '', '', '', '', 'ae',
  12038. '', '', '', 'dotlessi', '', '', 'lslash', 'oslash', 'oe', 'germandbls'],
  12039. WinAnsiEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12040. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12041. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  12042. 'ampersand', 'quotesingle', 'parenleft', 'parenright', 'asterisk', 'plus',
  12043. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  12044. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  12045. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  12046. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  12047. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  12048. 'asciicircum', 'underscore', 'grave', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
  12049. 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
  12050. 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde',
  12051. 'bullet', 'Euro', 'bullet', 'quotesinglbase', 'florin', 'quotedblbase',
  12052. 'ellipsis', 'dagger', 'daggerdbl', 'circumflex', 'perthousand', 'Scaron',
  12053. 'guilsinglleft', 'OE', 'bullet', 'Zcaron', 'bullet', 'bullet', 'quoteleft',
  12054. 'quoteright', 'quotedblleft', 'quotedblright', 'bullet', 'endash',
  12055. 'emdash', 'tilde', 'trademark', 'scaron', 'guilsinglright', 'oe', 'bullet',
  12056. 'zcaron', 'Ydieresis', 'space', 'exclamdown', 'cent', 'sterling',
  12057. 'currency', 'yen', 'brokenbar', 'section', 'dieresis', 'copyright',
  12058. 'ordfeminine', 'guillemotleft', 'logicalnot', 'hyphen', 'registered',
  12059. 'macron', 'degree', 'plusminus', 'twosuperior', 'threesuperior', 'acute',
  12060. 'mu', 'paragraph', 'periodcentered', 'cedilla', 'onesuperior',
  12061. 'ordmasculine', 'guillemotright', 'onequarter', 'onehalf', 'threequarters',
  12062. 'questiondown', 'Agrave', 'Aacute', 'Acircumflex', 'Atilde', 'Adieresis',
  12063. 'Aring', 'AE', 'Ccedilla', 'Egrave', 'Eacute', 'Ecircumflex', 'Edieresis',
  12064. 'Igrave', 'Iacute', 'Icircumflex', 'Idieresis', 'Eth', 'Ntilde', 'Ograve',
  12065. 'Oacute', 'Ocircumflex', 'Otilde', 'Odieresis', 'multiply', 'Oslash',
  12066. 'Ugrave', 'Uacute', 'Ucircumflex', 'Udieresis', 'Yacute', 'Thorn',
  12067. 'germandbls', 'agrave', 'aacute', 'acircumflex', 'atilde', 'adieresis',
  12068. 'aring', 'ae', 'ccedilla', 'egrave', 'eacute', 'ecircumflex', 'edieresis',
  12069. 'igrave', 'iacute', 'icircumflex', 'idieresis', 'eth', 'ntilde', 'ograve',
  12070. 'oacute', 'ocircumflex', 'otilde', 'odieresis', 'divide', 'oslash',
  12071. 'ugrave', 'uacute', 'ucircumflex', 'udieresis', 'yacute', 'thorn',
  12072. 'ydieresis'],
  12073. SymbolSetEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12074. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12075. 'space', 'exclam', 'universal', 'numbersign', 'existential', 'percent',
  12076. 'ampersand', 'suchthat', 'parenleft', 'parenright', 'asteriskmath', 'plus',
  12077. 'comma', 'minus', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
  12078. 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',
  12079. 'equal', 'greater', 'question', 'congruent', 'Alpha', 'Beta', 'Chi',
  12080. 'Delta', 'Epsilon', 'Phi', 'Gamma', 'Eta', 'Iota', 'theta1', 'Kappa',
  12081. 'Lambda', 'Mu', 'Nu', 'Omicron', 'Pi', 'Theta', 'Rho', 'Sigma', 'Tau',
  12082. 'Upsilon', 'sigma1', 'Omega', 'Xi', 'Psi', 'Zeta', 'bracketleft',
  12083. 'therefore', 'bracketright', 'perpendicular', 'underscore', 'radicalex',
  12084. 'alpha', 'beta', 'chi', 'delta', 'epsilon', 'phi', 'gamma', 'eta', 'iota',
  12085. 'phi1', 'kappa', 'lambda', 'mu', 'nu', 'omicron', 'pi', 'theta', 'rho',
  12086. 'sigma', 'tau', 'upsilon', 'omega1', 'omega', 'xi', 'psi', 'zeta',
  12087. 'braceleft', 'bar', 'braceright', 'similar', '', '', '', '', '', '', '',
  12088. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12089. '', '', '', '', '', '', '', 'Euro', 'Upsilon1', 'minute', 'lessequal',
  12090. 'fraction', 'infinity', 'florin', 'club', 'diamond', 'heart', 'spade',
  12091. 'arrowboth', 'arrowleft', 'arrowup', 'arrowright', 'arrowdown', 'degree',
  12092. 'plusminus', 'second', 'greaterequal', 'multiply', 'proportional',
  12093. 'partialdiff', 'bullet', 'divide', 'notequal', 'equivalence',
  12094. 'approxequal', 'ellipsis', 'arrowvertex', 'arrowhorizex', 'carriagereturn',
  12095. 'aleph', 'Ifraktur', 'Rfraktur', 'weierstrass', 'circlemultiply',
  12096. 'circleplus', 'emptyset', 'intersection', 'union', 'propersuperset',
  12097. 'reflexsuperset', 'notsubset', 'propersubset', 'reflexsubset', 'element',
  12098. 'notelement', 'angle', 'gradient', 'registerserif', 'copyrightserif',
  12099. 'trademarkserif', 'product', 'radical', 'dotmath', 'logicalnot',
  12100. 'logicaland', 'logicalor', 'arrowdblboth', 'arrowdblleft', 'arrowdblup',
  12101. 'arrowdblright', 'arrowdbldown', 'lozenge', 'angleleft', 'registersans',
  12102. 'copyrightsans', 'trademarksans', 'summation', 'parenlefttp',
  12103. 'parenleftex', 'parenleftbt', 'bracketlefttp', 'bracketleftex',
  12104. 'bracketleftbt', 'bracelefttp', 'braceleftmid', 'braceleftbt', 'braceex',
  12105. '', 'angleright', 'integral', 'integraltp', 'integralex', 'integralbt',
  12106. 'parenrighttp', 'parenrightex', 'parenrightbt', 'bracketrighttp',
  12107. 'bracketrightex', 'bracketrightbt', 'bracerighttp', 'bracerightmid',
  12108. 'bracerightbt'],
  12109. zapfDingbatsEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12110. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12111. 'space', 'a1', 'a2', 'a202', 'a3', 'a4', 'a5', 'a119', 'a118', 'a117',
  12112. 'a11', 'a12', 'a13', 'a14', 'a15', 'a16', 'a105', 'a17', 'a18', 'a19',
  12113. 'a20', 'a21', 'a22', 'a23', 'a24', 'a25', 'a26', 'a27', 'a28', 'a6', 'a7',
  12114. 'a8', 'a9', 'a10', 'a29', 'a30', 'a31', 'a32', 'a33', 'a34', 'a35', 'a36',
  12115. 'a37', 'a38', 'a39', 'a40', 'a41', 'a42', 'a43', 'a44', 'a45', 'a46',
  12116. 'a47', 'a48', 'a49', 'a50', 'a51', 'a52', 'a53', 'a54', 'a55', 'a56',
  12117. 'a57', 'a58', 'a59', 'a60', 'a61', 'a62', 'a63', 'a64', 'a65', 'a66',
  12118. 'a67', 'a68', 'a69', 'a70', 'a71', 'a72', 'a73', 'a74', 'a203', 'a75',
  12119. 'a204', 'a76', 'a77', 'a78', 'a79', 'a81', 'a82', 'a83', 'a84', 'a97',
  12120. 'a98', 'a99', 'a100', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12121. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  12122. '', '', 'a101', 'a102', 'a103', 'a104', 'a106', 'a107', 'a108', 'a112',
  12123. 'a111', 'a110', 'a109', 'a120', 'a121', 'a122', 'a123', 'a124', 'a125',
  12124. 'a126', 'a127', 'a128', 'a129', 'a130', 'a131', 'a132', 'a133', 'a134',
  12125. 'a135', 'a136', 'a137', 'a138', 'a139', 'a140', 'a141', 'a142', 'a143',
  12126. 'a144', 'a145', 'a146', 'a147', 'a148', 'a149', 'a150', 'a151', 'a152',
  12127. 'a153', 'a154', 'a155', 'a156', 'a157', 'a158', 'a159', 'a160', 'a161',
  12128. 'a163', 'a164', 'a196', 'a165', 'a192', 'a166', 'a167', 'a168', 'a169',
  12129. 'a170', 'a171', 'a172', 'a173', 'a162', 'a174', 'a175', 'a176', 'a177',
  12130. 'a178', 'a179', 'a193', 'a180', 'a199', 'a181', 'a200', 'a182', '', 'a201',
  12131. 'a183', 'a184', 'a197', 'a185', 'a194', 'a198', 'a186', 'a195', 'a187',
  12132. 'a188', 'a189', 'a190', 'a191']
  12133. };
  12134. /**
  12135. * Hold a map of decoded fonts and of the standard fourteen Type1
  12136. * fonts and their acronyms.
  12137. */
  12138. var stdFontMap = {
  12139. 'ArialNarrow': 'Helvetica',
  12140. 'ArialNarrow-Bold': 'Helvetica-Bold',
  12141. 'ArialNarrow-BoldItalic': 'Helvetica-BoldOblique',
  12142. 'ArialNarrow-Italic': 'Helvetica-Oblique',
  12143. 'ArialBlack': 'Helvetica',
  12144. 'ArialBlack-Bold': 'Helvetica-Bold',
  12145. 'ArialBlack-BoldItalic': 'Helvetica-BoldOblique',
  12146. 'ArialBlack-Italic': 'Helvetica-Oblique',
  12147. 'Arial': 'Helvetica',
  12148. 'Arial-Bold': 'Helvetica-Bold',
  12149. 'Arial-BoldItalic': 'Helvetica-BoldOblique',
  12150. 'Arial-Italic': 'Helvetica-Oblique',
  12151. 'Arial-BoldItalicMT': 'Helvetica-BoldOblique',
  12152. 'Arial-BoldMT': 'Helvetica-Bold',
  12153. 'Arial-ItalicMT': 'Helvetica-Oblique',
  12154. 'ArialMT': 'Helvetica',
  12155. 'Courier-Bold': 'Courier-Bold',
  12156. 'Courier-BoldItalic': 'Courier-BoldOblique',
  12157. 'Courier-Italic': 'Courier-Oblique',
  12158. 'CourierNew': 'Courier',
  12159. 'CourierNew-Bold': 'Courier-Bold',
  12160. 'CourierNew-BoldItalic': 'Courier-BoldOblique',
  12161. 'CourierNew-Italic': 'Courier-Oblique',
  12162. 'CourierNewPS-BoldItalicMT': 'Courier-BoldOblique',
  12163. 'CourierNewPS-BoldMT': 'Courier-Bold',
  12164. 'CourierNewPS-ItalicMT': 'Courier-Oblique',
  12165. 'CourierNewPSMT': 'Courier',
  12166. 'Helvetica-Bold': 'Helvetica-Bold',
  12167. 'Helvetica-BoldItalic': 'Helvetica-BoldOblique',
  12168. 'Helvetica-Italic': 'Helvetica-Oblique',
  12169. 'Symbol-Bold': 'Symbol',
  12170. 'Symbol-BoldItalic': 'Symbol',
  12171. 'Symbol-Italic': 'Symbol',
  12172. 'TimesNewRoman': 'Times-Roman',
  12173. 'TimesNewRoman-Bold': 'Times-Bold',
  12174. 'TimesNewRoman-BoldItalic': 'Times-BoldItalic',
  12175. 'TimesNewRoman-Italic': 'Times-Italic',
  12176. 'TimesNewRomanPS': 'Times-Roman',
  12177. 'TimesNewRomanPS-Bold': 'Times-Bold',
  12178. 'TimesNewRomanPS-BoldItalic': 'Times-BoldItalic',
  12179. 'TimesNewRomanPS-BoldItalicMT': 'Times-BoldItalic',
  12180. 'TimesNewRomanPS-BoldMT': 'Times-Bold',
  12181. 'TimesNewRomanPS-Italic': 'Times-Italic',
  12182. 'TimesNewRomanPS-ItalicMT': 'Times-Italic',
  12183. 'TimesNewRomanPSMT': 'Times-Roman',
  12184. 'TimesNewRomanPSMT-Bold': 'Times-Bold',
  12185. 'TimesNewRomanPSMT-BoldItalic': 'Times-BoldItalic',
  12186. 'TimesNewRomanPSMT-Italic': 'Times-Italic'
  12187. };
  12188. /**
  12189. * Holds the map of the non-standard fonts that might be included as a standard
  12190. * fonts without glyph data.
  12191. */
  12192. var nonStdFontMap = {
  12193. 'ComicSansMS': 'Comic Sans MS',
  12194. 'ComicSansMS-Bold': 'Comic Sans MS-Bold',
  12195. 'ComicSansMS-BoldItalic': 'Comic Sans MS-BoldItalic',
  12196. 'ComicSansMS-Italic': 'Comic Sans MS-Italic',
  12197. 'LucidaConsole': 'Courier',
  12198. 'LucidaConsole-Bold': 'Courier-Bold',
  12199. 'LucidaConsole-BoldItalic': 'Courier-BoldOblique',
  12200. 'LucidaConsole-Italic': 'Courier-Oblique',
  12201. 'MS-Gothic': 'MS Gothic',
  12202. 'MS-Gothic-Bold': 'MS Gothic-Bold',
  12203. 'MS-Gothic-BoldItalic': 'MS Gothic-BoldItalic',
  12204. 'MS-Gothic-Italic': 'MS Gothic-Italic',
  12205. 'MS-Mincho': 'MS Mincho',
  12206. 'MS-Mincho-Bold': 'MS Mincho-Bold',
  12207. 'MS-Mincho-BoldItalic': 'MS Mincho-BoldItalic',
  12208. 'MS-Mincho-Italic': 'MS Mincho-Italic',
  12209. 'MS-PGothic': 'MS PGothic',
  12210. 'MS-PGothic-Bold': 'MS PGothic-Bold',
  12211. 'MS-PGothic-BoldItalic': 'MS PGothic-BoldItalic',
  12212. 'MS-PGothic-Italic': 'MS PGothic-Italic',
  12213. 'MS-PMincho': 'MS PMincho',
  12214. 'MS-PMincho-Bold': 'MS PMincho-Bold',
  12215. 'MS-PMincho-BoldItalic': 'MS PMincho-BoldItalic',
  12216. 'MS-PMincho-Italic': 'MS PMincho-Italic'
  12217. };
  12218. var serifFonts = {
  12219. 'Adobe Jenson': true, 'Adobe Text': true, 'Albertus': true,
  12220. 'Aldus': true, 'Alexandria': true, 'Algerian': true,
  12221. 'American Typewriter': true, 'Antiqua': true, 'Apex': true,
  12222. 'Arno': true, 'Aster': true, 'Aurora': true,
  12223. 'Baskerville': true, 'Bell': true, 'Bembo': true,
  12224. 'Bembo Schoolbook': true, 'Benguiat': true, 'Berkeley Old Style': true,
  12225. 'Bernhard Modern': true, 'Berthold City': true, 'Bodoni': true,
  12226. 'Bauer Bodoni': true, 'Book Antiqua': true, 'Bookman': true,
  12227. 'Bordeaux Roman': true, 'Californian FB': true, 'Calisto': true,
  12228. 'Calvert': true, 'Capitals': true, 'Cambria': true,
  12229. 'Cartier': true, 'Caslon': true, 'Catull': true,
  12230. 'Centaur': true, 'Century Old Style': true, 'Century Schoolbook': true,
  12231. 'Chaparral': true, 'Charis SIL': true, 'Cheltenham': true,
  12232. 'Cholla Slab': true, 'Clarendon': true, 'Clearface': true,
  12233. 'Cochin': true, 'Colonna': true, 'Computer Modern': true,
  12234. 'Concrete Roman': true, 'Constantia': true, 'Cooper Black': true,
  12235. 'Corona': true, 'Ecotype': true, 'Egyptienne': true,
  12236. 'Elephant': true, 'Excelsior': true, 'Fairfield': true,
  12237. 'FF Scala': true, 'Folkard': true, 'Footlight': true,
  12238. 'FreeSerif': true, 'Friz Quadrata': true, 'Garamond': true,
  12239. 'Gentium': true, 'Georgia': true, 'Gloucester': true,
  12240. 'Goudy Old Style': true, 'Goudy Schoolbook': true, 'Goudy Pro Font': true,
  12241. 'Granjon': true, 'Guardian Egyptian': true, 'Heather': true,
  12242. 'Hercules': true, 'High Tower Text': true, 'Hiroshige': true,
  12243. 'Hoefler Text': true, 'Humana Serif': true, 'Imprint': true,
  12244. 'Ionic No. 5': true, 'Janson': true, 'Joanna': true,
  12245. 'Korinna': true, 'Lexicon': true, 'Liberation Serif': true,
  12246. 'Linux Libertine': true, 'Literaturnaya': true, 'Lucida': true,
  12247. 'Lucida Bright': true, 'Melior': true, 'Memphis': true,
  12248. 'Miller': true, 'Minion': true, 'Modern': true,
  12249. 'Mona Lisa': true, 'Mrs Eaves': true, 'MS Serif': true,
  12250. 'Museo Slab': true, 'New York': true, 'Nimbus Roman': true,
  12251. 'NPS Rawlinson Roadway': true, 'Palatino': true, 'Perpetua': true,
  12252. 'Plantin': true, 'Plantin Schoolbook': true, 'Playbill': true,
  12253. 'Poor Richard': true, 'Rawlinson Roadway': true, 'Renault': true,
  12254. 'Requiem': true, 'Rockwell': true, 'Roman': true,
  12255. 'Rotis Serif': true, 'Sabon': true, 'Scala': true,
  12256. 'Seagull': true, 'Sistina': true, 'Souvenir': true,
  12257. 'STIX': true, 'Stone Informal': true, 'Stone Serif': true,
  12258. 'Sylfaen': true, 'Times': true, 'Trajan': true,
  12259. 'Trinité': true, 'Trump Mediaeval': true, 'Utopia': true,
  12260. 'Vale Type': true, 'Bitstream Vera': true, 'Vera Serif': true,
  12261. 'Versailles': true, 'Wanted': true, 'Weiss': true,
  12262. 'Wide Latin': true, 'Windsor': true, 'XITS': true
  12263. };
  12264. var symbolsFonts = {
  12265. 'Dingbats': true, 'Symbol': true, 'ZapfDingbats': true
  12266. };
  12267. // Glyph map for well-known standard fonts. Sometimes Ghostscript uses CID fonts
  12268. // but does not embed the CID to GID mapping. The mapping is incomplete for all
  12269. // glyphs, but common for some set of the standard fonts.
  12270. var GlyphMapForStandardFonts = {
  12271. '2': 10, '3': 32, '4': 33, '5': 34, '6': 35, '7': 36, '8': 37, '9': 38,
  12272. '10': 39, '11': 40, '12': 41, '13': 42, '14': 43, '15': 44, '16': 45,
  12273. '17': 46, '18': 47, '19': 48, '20': 49, '21': 50, '22': 51, '23': 52,
  12274. '24': 53, '25': 54, '26': 55, '27': 56, '28': 57, '29': 58, '30': 894,
  12275. '31': 60, '32': 61, '33': 62, '34': 63, '35': 64, '36': 65, '37': 66,
  12276. '38': 67, '39': 68, '40': 69, '41': 70, '42': 71, '43': 72, '44': 73,
  12277. '45': 74, '46': 75, '47': 76, '48': 77, '49': 78, '50': 79, '51': 80,
  12278. '52': 81, '53': 82, '54': 83, '55': 84, '56': 85, '57': 86, '58': 87,
  12279. '59': 88, '60': 89, '61': 90, '62': 91, '63': 92, '64': 93, '65': 94,
  12280. '66': 95, '67': 96, '68': 97, '69': 98, '70': 99, '71': 100, '72': 101,
  12281. '73': 102, '74': 103, '75': 104, '76': 105, '77': 106, '78': 107, '79': 108,
  12282. '80': 109, '81': 110, '82': 111, '83': 112, '84': 113, '85': 114, '86': 115,
  12283. '87': 116, '88': 117, '89': 118, '90': 119, '91': 120, '92': 121, '93': 122,
  12284. '94': 123, '95': 124, '96': 125, '97': 126, '98': 196, '99': 197, '100': 199,
  12285. '101': 201, '102': 209, '103': 214, '104': 220, '105': 225, '106': 224,
  12286. '107': 226, '108': 228, '109': 227, '110': 229, '111': 231, '112': 233,
  12287. '113': 232, '114': 234, '115': 235, '116': 237, '117': 236, '118': 238,
  12288. '119': 239, '120': 241, '121': 243, '122': 242, '123': 244, '124': 246,
  12289. '125': 245, '126': 250, '127': 249, '128': 251, '129': 252, '130': 8224,
  12290. '131': 176, '132': 162, '133': 163, '134': 167, '135': 8226, '136': 182,
  12291. '137': 223, '138': 174, '139': 169, '140': 8482, '141': 180, '142': 168,
  12292. '143': 8800, '144': 198, '145': 216, '146': 8734, '147': 177, '148': 8804,
  12293. '149': 8805, '150': 165, '151': 181, '152': 8706, '153': 8721, '154': 8719,
  12294. '156': 8747, '157': 170, '158': 186, '159': 8486, '160': 230, '161': 248,
  12295. '162': 191, '163': 161, '164': 172, '165': 8730, '166': 402, '167': 8776,
  12296. '168': 8710, '169': 171, '170': 187, '171': 8230, '210': 218, '223': 711,
  12297. '227': 353, '229': 382, '234': 253, '253': 268, '254': 269, '258': 258,
  12298. '268': 283, '269': 313, '278': 328, '284': 345, '292': 367, '305': 963,
  12299. '306': 964, '307': 966, '308': 8215, '309': 8252, '310': 8319, '311': 8359,
  12300. '312': 8592, '313': 8593, '337': 9552, '493': 1039, '494': 1040, '705': 1524,
  12301. '706': 8362, '710': 64288, '711': 64298, '759': 1617, '761': 1776,
  12302. '763': 1778, '775': 1652, '777': 1764, '778': 1780, '779': 1781, '780': 1782,
  12303. '782': 771, '783': 64726, '786': 8363, '788': 8532, '790': 768, '791': 769,
  12304. '792': 768, '795': 803, '797': 64336, '798': 64337, '799': 64342,
  12305. '800': 64343, '801': 64344, '802': 64345, '803': 64362, '804': 64363,
  12306. '805': 64364, '2424': 7821, '2425': 7822, '2426': 7823, '2427': 7824,
  12307. '2428': 7825, '2429': 7826, '2430': 7827, '2433': 7682, '2678': 8045,
  12308. '2679': 8046, '2830': 1552, '2838': 686, '2840': 751, '2842': 753,
  12309. '2843': 754, '2844': 755, '2846': 757, '2856': 767, '2857': 848, '2858': 849,
  12310. '2862': 853, '2863': 854, '2864': 855, '2865': 861, '2866': 862, '2906': 7460,
  12311. '2908': 7462, '2909': 7463, '2910': 7464, '2912': 7466, '2913': 7467,
  12312. '2914': 7468, '2916': 7470, '2917': 7471, '2918': 7472, '2920': 7474,
  12313. '2921': 7475, '2922': 7476, '2924': 7478, '2925': 7479, '2926': 7480,
  12314. '2928': 7482, '2929': 7483, '2930': 7484, '2932': 7486, '2933': 7487,
  12315. '2934': 7488, '2936': 7490, '2937': 7491, '2938': 7492, '2940': 7494,
  12316. '2941': 7495, '2942': 7496, '2944': 7498, '2946': 7500, '2948': 7502,
  12317. '2950': 7504, '2951': 7505, '2952': 7506, '2954': 7508, '2955': 7509,
  12318. '2956': 7510, '2958': 7512, '2959': 7513, '2960': 7514, '2962': 7516,
  12319. '2963': 7517, '2964': 7518, '2966': 7520, '2967': 7521, '2968': 7522,
  12320. '2970': 7524, '2971': 7525, '2972': 7526, '2974': 7528, '2975': 7529,
  12321. '2976': 7530, '2978': 1537, '2979': 1538, '2980': 1539, '2982': 1549,
  12322. '2983': 1551, '2984': 1552, '2986': 1554, '2987': 1555, '2988': 1556,
  12323. '2990': 1623, '2991': 1624, '2995': 1775, '2999': 1791, '3002': 64290,
  12324. '3003': 64291, '3004': 64292, '3006': 64294, '3007': 64295, '3008': 64296,
  12325. '3011': 1900, '3014': 8223, '3015': 8244, '3017': 7532, '3018': 7533,
  12326. '3019': 7534, '3075': 7590, '3076': 7591, '3079': 7594, '3080': 7595,
  12327. '3083': 7598, '3084': 7599, '3087': 7602, '3088': 7603, '3091': 7606,
  12328. '3092': 7607, '3095': 7610, '3096': 7611, '3099': 7614, '3100': 7615,
  12329. '3103': 7618, '3104': 7619, '3107': 8337, '3108': 8338, '3116': 1884,
  12330. '3119': 1885, '3120': 1885, '3123': 1886, '3124': 1886, '3127': 1887,
  12331. '3128': 1887, '3131': 1888, '3132': 1888, '3135': 1889, '3136': 1889,
  12332. '3139': 1890, '3140': 1890, '3143': 1891, '3144': 1891, '3147': 1892,
  12333. '3148': 1892, '3153': 580, '3154': 581, '3157': 584, '3158': 585, '3161': 588,
  12334. '3162': 589, '3165': 891, '3166': 892, '3169': 1274, '3170': 1275,
  12335. '3173': 1278, '3174': 1279, '3181': 7622, '3182': 7623, '3282': 11799,
  12336. '3316': 578, '3379': 42785, '3393': 1159, '3416': 8377
  12337. };
  12338. // Some characters, e.g. copyrightserif, mapped to the private use area and
  12339. // might not be displayed using standard fonts. Mapping/hacking well-known chars
  12340. // to the similar equivalents in the normal characters range.
  12341. function mapSpecialUnicodeValues(code) {
  12342. if (code >= 0xFFF0 && code <= 0xFFFF) { // Specials unicode block.
  12343. return 0;
  12344. }
  12345. switch (code) {
  12346. case 0xF8E9: // copyrightsans
  12347. case 0xF6D9: // copyrightserif
  12348. return 0x00A9; // copyright
  12349. case 0xF8E8: // registersans
  12350. case 0xF6DA: // registerserif
  12351. return 0x00AE; // registered
  12352. case 0xF8EA: // trademarksans
  12353. case 0xF6DB: // trademarkserif
  12354. return 0x2122; // trademark
  12355. default:
  12356. return code;
  12357. }
  12358. }
  12359. var UnicodeRanges = [
  12360. { 'begin': 0x0000, 'end': 0x007F }, // Basic Latin
  12361. { 'begin': 0x0080, 'end': 0x00FF }, // Latin-1 Supplement
  12362. { 'begin': 0x0100, 'end': 0x017F }, // Latin Extended-A
  12363. { 'begin': 0x0180, 'end': 0x024F }, // Latin Extended-B
  12364. { 'begin': 0x0250, 'end': 0x02AF }, // IPA Extensions
  12365. { 'begin': 0x02B0, 'end': 0x02FF }, // Spacing Modifier Letters
  12366. { 'begin': 0x0300, 'end': 0x036F }, // Combining Diacritical Marks
  12367. { 'begin': 0x0370, 'end': 0x03FF }, // Greek and Coptic
  12368. { 'begin': 0x2C80, 'end': 0x2CFF }, // Coptic
  12369. { 'begin': 0x0400, 'end': 0x04FF }, // Cyrillic
  12370. { 'begin': 0x0530, 'end': 0x058F }, // Armenian
  12371. { 'begin': 0x0590, 'end': 0x05FF }, // Hebrew
  12372. { 'begin': 0xA500, 'end': 0xA63F }, // Vai
  12373. { 'begin': 0x0600, 'end': 0x06FF }, // Arabic
  12374. { 'begin': 0x07C0, 'end': 0x07FF }, // NKo
  12375. { 'begin': 0x0900, 'end': 0x097F }, // Devanagari
  12376. { 'begin': 0x0980, 'end': 0x09FF }, // Bengali
  12377. { 'begin': 0x0A00, 'end': 0x0A7F }, // Gurmukhi
  12378. { 'begin': 0x0A80, 'end': 0x0AFF }, // Gujarati
  12379. { 'begin': 0x0B00, 'end': 0x0B7F }, // Oriya
  12380. { 'begin': 0x0B80, 'end': 0x0BFF }, // Tamil
  12381. { 'begin': 0x0C00, 'end': 0x0C7F }, // Telugu
  12382. { 'begin': 0x0C80, 'end': 0x0CFF }, // Kannada
  12383. { 'begin': 0x0D00, 'end': 0x0D7F }, // Malayalam
  12384. { 'begin': 0x0E00, 'end': 0x0E7F }, // Thai
  12385. { 'begin': 0x0E80, 'end': 0x0EFF }, // Lao
  12386. { 'begin': 0x10A0, 'end': 0x10FF }, // Georgian
  12387. { 'begin': 0x1B00, 'end': 0x1B7F }, // Balinese
  12388. { 'begin': 0x1100, 'end': 0x11FF }, // Hangul Jamo
  12389. { 'begin': 0x1E00, 'end': 0x1EFF }, // Latin Extended Additional
  12390. { 'begin': 0x1F00, 'end': 0x1FFF }, // Greek Extended
  12391. { 'begin': 0x2000, 'end': 0x206F }, // General Punctuation
  12392. { 'begin': 0x2070, 'end': 0x209F }, // Superscripts And Subscripts
  12393. { 'begin': 0x20A0, 'end': 0x20CF }, // Currency Symbol
  12394. { 'begin': 0x20D0, 'end': 0x20FF }, // Combining Diacritical Marks For Symbols
  12395. { 'begin': 0x2100, 'end': 0x214F }, // Letterlike Symbols
  12396. { 'begin': 0x2150, 'end': 0x218F }, // Number Forms
  12397. { 'begin': 0x2190, 'end': 0x21FF }, // Arrows
  12398. { 'begin': 0x2200, 'end': 0x22FF }, // Mathematical Operators
  12399. { 'begin': 0x2300, 'end': 0x23FF }, // Miscellaneous Technical
  12400. { 'begin': 0x2400, 'end': 0x243F }, // Control Pictures
  12401. { 'begin': 0x2440, 'end': 0x245F }, // Optical Character Recognition
  12402. { 'begin': 0x2460, 'end': 0x24FF }, // Enclosed Alphanumerics
  12403. { 'begin': 0x2500, 'end': 0x257F }, // Box Drawing
  12404. { 'begin': 0x2580, 'end': 0x259F }, // Block Elements
  12405. { 'begin': 0x25A0, 'end': 0x25FF }, // Geometric Shapes
  12406. { 'begin': 0x2600, 'end': 0x26FF }, // Miscellaneous Symbols
  12407. { 'begin': 0x2700, 'end': 0x27BF }, // Dingbats
  12408. { 'begin': 0x3000, 'end': 0x303F }, // CJK Symbols And Punctuation
  12409. { 'begin': 0x3040, 'end': 0x309F }, // Hiragana
  12410. { 'begin': 0x30A0, 'end': 0x30FF }, // Katakana
  12411. { 'begin': 0x3100, 'end': 0x312F }, // Bopomofo
  12412. { 'begin': 0x3130, 'end': 0x318F }, // Hangul Compatibility Jamo
  12413. { 'begin': 0xA840, 'end': 0xA87F }, // Phags-pa
  12414. { 'begin': 0x3200, 'end': 0x32FF }, // Enclosed CJK Letters And Months
  12415. { 'begin': 0x3300, 'end': 0x33FF }, // CJK Compatibility
  12416. { 'begin': 0xAC00, 'end': 0xD7AF }, // Hangul Syllables
  12417. { 'begin': 0xD800, 'end': 0xDFFF }, // Non-Plane 0 *
  12418. { 'begin': 0x10900, 'end': 0x1091F }, // Phoenicia
  12419. { 'begin': 0x4E00, 'end': 0x9FFF }, // CJK Unified Ideographs
  12420. { 'begin': 0xE000, 'end': 0xF8FF }, // Private Use Area (plane 0)
  12421. { 'begin': 0x31C0, 'end': 0x31EF }, // CJK Strokes
  12422. { 'begin': 0xFB00, 'end': 0xFB4F }, // Alphabetic Presentation Forms
  12423. { 'begin': 0xFB50, 'end': 0xFDFF }, // Arabic Presentation Forms-A
  12424. { 'begin': 0xFE20, 'end': 0xFE2F }, // Combining Half Marks
  12425. { 'begin': 0xFE10, 'end': 0xFE1F }, // Vertical Forms
  12426. { 'begin': 0xFE50, 'end': 0xFE6F }, // Small Form Variants
  12427. { 'begin': 0xFE70, 'end': 0xFEFF }, // Arabic Presentation Forms-B
  12428. { 'begin': 0xFF00, 'end': 0xFFEF }, // Halfwidth And Fullwidth Forms
  12429. { 'begin': 0xFFF0, 'end': 0xFFFF }, // Specials
  12430. { 'begin': 0x0F00, 'end': 0x0FFF }, // Tibetan
  12431. { 'begin': 0x0700, 'end': 0x074F }, // Syriac
  12432. { 'begin': 0x0780, 'end': 0x07BF }, // Thaana
  12433. { 'begin': 0x0D80, 'end': 0x0DFF }, // Sinhala
  12434. { 'begin': 0x1000, 'end': 0x109F }, // Myanmar
  12435. { 'begin': 0x1200, 'end': 0x137F }, // Ethiopic
  12436. { 'begin': 0x13A0, 'end': 0x13FF }, // Cherokee
  12437. { 'begin': 0x1400, 'end': 0x167F }, // Unified Canadian Aboriginal Syllabics
  12438. { 'begin': 0x1680, 'end': 0x169F }, // Ogham
  12439. { 'begin': 0x16A0, 'end': 0x16FF }, // Runic
  12440. { 'begin': 0x1780, 'end': 0x17FF }, // Khmer
  12441. { 'begin': 0x1800, 'end': 0x18AF }, // Mongolian
  12442. { 'begin': 0x2800, 'end': 0x28FF }, // Braille Patterns
  12443. { 'begin': 0xA000, 'end': 0xA48F }, // Yi Syllables
  12444. { 'begin': 0x1700, 'end': 0x171F }, // Tagalog
  12445. { 'begin': 0x10300, 'end': 0x1032F }, // Old Italic
  12446. { 'begin': 0x10330, 'end': 0x1034F }, // Gothic
  12447. { 'begin': 0x10400, 'end': 0x1044F }, // Deseret
  12448. { 'begin': 0x1D000, 'end': 0x1D0FF }, // Byzantine Musical Symbols
  12449. { 'begin': 0x1D400, 'end': 0x1D7FF }, // Mathematical Alphanumeric Symbols
  12450. { 'begin': 0xFF000, 'end': 0xFFFFD }, // Private Use (plane 15)
  12451. { 'begin': 0xFE00, 'end': 0xFE0F }, // Variation Selectors
  12452. { 'begin': 0xE0000, 'end': 0xE007F }, // Tags
  12453. { 'begin': 0x1900, 'end': 0x194F }, // Limbu
  12454. { 'begin': 0x1950, 'end': 0x197F }, // Tai Le
  12455. { 'begin': 0x1980, 'end': 0x19DF }, // New Tai Lue
  12456. { 'begin': 0x1A00, 'end': 0x1A1F }, // Buginese
  12457. { 'begin': 0x2C00, 'end': 0x2C5F }, // Glagolitic
  12458. { 'begin': 0x2D30, 'end': 0x2D7F }, // Tifinagh
  12459. { 'begin': 0x4DC0, 'end': 0x4DFF }, // Yijing Hexagram Symbols
  12460. { 'begin': 0xA800, 'end': 0xA82F }, // Syloti Nagri
  12461. { 'begin': 0x10000, 'end': 0x1007F }, // Linear B Syllabary
  12462. { 'begin': 0x10140, 'end': 0x1018F }, // Ancient Greek Numbers
  12463. { 'begin': 0x10380, 'end': 0x1039F }, // Ugaritic
  12464. { 'begin': 0x103A0, 'end': 0x103DF }, // Old Persian
  12465. { 'begin': 0x10450, 'end': 0x1047F }, // Shavian
  12466. { 'begin': 0x10480, 'end': 0x104AF }, // Osmanya
  12467. { 'begin': 0x10800, 'end': 0x1083F }, // Cypriot Syllabary
  12468. { 'begin': 0x10A00, 'end': 0x10A5F }, // Kharoshthi
  12469. { 'begin': 0x1D300, 'end': 0x1D35F }, // Tai Xuan Jing Symbols
  12470. { 'begin': 0x12000, 'end': 0x123FF }, // Cuneiform
  12471. { 'begin': 0x1D360, 'end': 0x1D37F }, // Counting Rod Numerals
  12472. { 'begin': 0x1B80, 'end': 0x1BBF }, // Sundanese
  12473. { 'begin': 0x1C00, 'end': 0x1C4F }, // Lepcha
  12474. { 'begin': 0x1C50, 'end': 0x1C7F }, // Ol Chiki
  12475. { 'begin': 0xA880, 'end': 0xA8DF }, // Saurashtra
  12476. { 'begin': 0xA900, 'end': 0xA92F }, // Kayah Li
  12477. { 'begin': 0xA930, 'end': 0xA95F }, // Rejang
  12478. { 'begin': 0xAA00, 'end': 0xAA5F }, // Cham
  12479. { 'begin': 0x10190, 'end': 0x101CF }, // Ancient Symbols
  12480. { 'begin': 0x101D0, 'end': 0x101FF }, // Phaistos Disc
  12481. { 'begin': 0x102A0, 'end': 0x102DF }, // Carian
  12482. { 'begin': 0x1F030, 'end': 0x1F09F } // Domino Tiles
  12483. ];
  12484. var MacStandardGlyphOrdering = [
  12485. '.notdef', '.null', 'nonmarkingreturn', 'space', 'exclam', 'quotedbl',
  12486. 'numbersign', 'dollar', 'percent', 'ampersand', 'quotesingle', 'parenleft',
  12487. 'parenright', 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash',
  12488. 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  12489. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question', 'at',
  12490. 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
  12491. 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'bracketleft',
  12492. 'backslash', 'bracketright', 'asciicircum', 'underscore', 'grave', 'a', 'b',
  12493. 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q',
  12494. 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright',
  12495. 'asciitilde', 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde',
  12496. 'Odieresis', 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis',
  12497. 'atilde', 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  12498. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute', 'ograve',
  12499. 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave', 'ucircumflex',
  12500. 'udieresis', 'dagger', 'degree', 'cent', 'sterling', 'section', 'bullet',
  12501. 'paragraph', 'germandbls', 'registered', 'copyright', 'trademark', 'acute',
  12502. 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity', 'plusminus', 'lessequal',
  12503. 'greaterequal', 'yen', 'mu', 'partialdiff', 'summation', 'product', 'pi',
  12504. 'integral', 'ordfeminine', 'ordmasculine', 'Omega', 'ae', 'oslash',
  12505. 'questiondown', 'exclamdown', 'logicalnot', 'radical', 'florin',
  12506. 'approxequal', 'Delta', 'guillemotleft', 'guillemotright', 'ellipsis',
  12507. 'nonbreakingspace', 'Agrave', 'Atilde', 'Otilde', 'OE', 'oe', 'endash',
  12508. 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft', 'quoteright',
  12509. 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction', 'currency',
  12510. 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl', 'periodcentered',
  12511. 'quotesinglbase', 'quotedblbase', 'perthousand', 'Acircumflex',
  12512. 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute', 'Icircumflex',
  12513. 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple', 'Ograve', 'Uacute',
  12514. 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex', 'tilde', 'macron',
  12515. 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron',
  12516. 'Lslash', 'lslash', 'Scaron', 'scaron', 'Zcaron', 'zcaron', 'brokenbar',
  12517. 'Eth', 'eth', 'Yacute', 'yacute', 'Thorn', 'thorn', 'minus', 'multiply',
  12518. 'onesuperior', 'twosuperior', 'threesuperior', 'onehalf', 'onequarter',
  12519. 'threequarters', 'franc', 'Gbreve', 'gbreve', 'Idotaccent', 'Scedilla',
  12520. 'scedilla', 'Cacute', 'cacute', 'Ccaron', 'ccaron', 'dcroat'];
  12521. function getUnicodeRangeFor(value) {
  12522. for (var i = 0, ii = UnicodeRanges.length; i < ii; i++) {
  12523. var range = UnicodeRanges[i];
  12524. if (value >= range.begin && value < range.end) {
  12525. return i;
  12526. }
  12527. }
  12528. return -1;
  12529. }
  12530. function isRTLRangeFor(value) {
  12531. var range = UnicodeRanges[13];
  12532. if (value >= range.begin && value < range.end) {
  12533. return true;
  12534. }
  12535. range = UnicodeRanges[11];
  12536. if (value >= range.begin && value < range.end) {
  12537. return true;
  12538. }
  12539. return false;
  12540. }
  12541. // The normalization table is obtained by filtering the Unicode characters
  12542. // database with <compat> entries.
  12543. var NormalizedUnicodes = {
  12544. '\u00A8': '\u0020\u0308',
  12545. '\u00AF': '\u0020\u0304',
  12546. '\u00B4': '\u0020\u0301',
  12547. '\u00B5': '\u03BC',
  12548. '\u00B8': '\u0020\u0327',
  12549. '\u0132': '\u0049\u004A',
  12550. '\u0133': '\u0069\u006A',
  12551. '\u013F': '\u004C\u00B7',
  12552. '\u0140': '\u006C\u00B7',
  12553. '\u0149': '\u02BC\u006E',
  12554. '\u017F': '\u0073',
  12555. '\u01C4': '\u0044\u017D',
  12556. '\u01C5': '\u0044\u017E',
  12557. '\u01C6': '\u0064\u017E',
  12558. '\u01C7': '\u004C\u004A',
  12559. '\u01C8': '\u004C\u006A',
  12560. '\u01C9': '\u006C\u006A',
  12561. '\u01CA': '\u004E\u004A',
  12562. '\u01CB': '\u004E\u006A',
  12563. '\u01CC': '\u006E\u006A',
  12564. '\u01F1': '\u0044\u005A',
  12565. '\u01F2': '\u0044\u007A',
  12566. '\u01F3': '\u0064\u007A',
  12567. '\u02D8': '\u0020\u0306',
  12568. '\u02D9': '\u0020\u0307',
  12569. '\u02DA': '\u0020\u030A',
  12570. '\u02DB': '\u0020\u0328',
  12571. '\u02DC': '\u0020\u0303',
  12572. '\u02DD': '\u0020\u030B',
  12573. '\u037A': '\u0020\u0345',
  12574. '\u0384': '\u0020\u0301',
  12575. '\u03D0': '\u03B2',
  12576. '\u03D1': '\u03B8',
  12577. '\u03D2': '\u03A5',
  12578. '\u03D5': '\u03C6',
  12579. '\u03D6': '\u03C0',
  12580. '\u03F0': '\u03BA',
  12581. '\u03F1': '\u03C1',
  12582. '\u03F2': '\u03C2',
  12583. '\u03F4': '\u0398',
  12584. '\u03F5': '\u03B5',
  12585. '\u03F9': '\u03A3',
  12586. '\u0587': '\u0565\u0582',
  12587. '\u0675': '\u0627\u0674',
  12588. '\u0676': '\u0648\u0674',
  12589. '\u0677': '\u06C7\u0674',
  12590. '\u0678': '\u064A\u0674',
  12591. '\u0E33': '\u0E4D\u0E32',
  12592. '\u0EB3': '\u0ECD\u0EB2',
  12593. '\u0EDC': '\u0EAB\u0E99',
  12594. '\u0EDD': '\u0EAB\u0EA1',
  12595. '\u0F77': '\u0FB2\u0F81',
  12596. '\u0F79': '\u0FB3\u0F81',
  12597. '\u1E9A': '\u0061\u02BE',
  12598. '\u1FBD': '\u0020\u0313',
  12599. '\u1FBF': '\u0020\u0313',
  12600. '\u1FC0': '\u0020\u0342',
  12601. '\u1FFE': '\u0020\u0314',
  12602. '\u2002': '\u0020',
  12603. '\u2003': '\u0020',
  12604. '\u2004': '\u0020',
  12605. '\u2005': '\u0020',
  12606. '\u2006': '\u0020',
  12607. '\u2008': '\u0020',
  12608. '\u2009': '\u0020',
  12609. '\u200A': '\u0020',
  12610. '\u2017': '\u0020\u0333',
  12611. '\u2024': '\u002E',
  12612. '\u2025': '\u002E\u002E',
  12613. '\u2026': '\u002E\u002E\u002E',
  12614. '\u2033': '\u2032\u2032',
  12615. '\u2034': '\u2032\u2032\u2032',
  12616. '\u2036': '\u2035\u2035',
  12617. '\u2037': '\u2035\u2035\u2035',
  12618. '\u203C': '\u0021\u0021',
  12619. '\u203E': '\u0020\u0305',
  12620. '\u2047': '\u003F\u003F',
  12621. '\u2048': '\u003F\u0021',
  12622. '\u2049': '\u0021\u003F',
  12623. '\u2057': '\u2032\u2032\u2032\u2032',
  12624. '\u205F': '\u0020',
  12625. '\u20A8': '\u0052\u0073',
  12626. '\u2100': '\u0061\u002F\u0063',
  12627. '\u2101': '\u0061\u002F\u0073',
  12628. '\u2103': '\u00B0\u0043',
  12629. '\u2105': '\u0063\u002F\u006F',
  12630. '\u2106': '\u0063\u002F\u0075',
  12631. '\u2107': '\u0190',
  12632. '\u2109': '\u00B0\u0046',
  12633. '\u2116': '\u004E\u006F',
  12634. '\u2121': '\u0054\u0045\u004C',
  12635. '\u2135': '\u05D0',
  12636. '\u2136': '\u05D1',
  12637. '\u2137': '\u05D2',
  12638. '\u2138': '\u05D3',
  12639. '\u213B': '\u0046\u0041\u0058',
  12640. '\u2160': '\u0049',
  12641. '\u2161': '\u0049\u0049',
  12642. '\u2162': '\u0049\u0049\u0049',
  12643. '\u2163': '\u0049\u0056',
  12644. '\u2164': '\u0056',
  12645. '\u2165': '\u0056\u0049',
  12646. '\u2166': '\u0056\u0049\u0049',
  12647. '\u2167': '\u0056\u0049\u0049\u0049',
  12648. '\u2168': '\u0049\u0058',
  12649. '\u2169': '\u0058',
  12650. '\u216A': '\u0058\u0049',
  12651. '\u216B': '\u0058\u0049\u0049',
  12652. '\u216C': '\u004C',
  12653. '\u216D': '\u0043',
  12654. '\u216E': '\u0044',
  12655. '\u216F': '\u004D',
  12656. '\u2170': '\u0069',
  12657. '\u2171': '\u0069\u0069',
  12658. '\u2172': '\u0069\u0069\u0069',
  12659. '\u2173': '\u0069\u0076',
  12660. '\u2174': '\u0076',
  12661. '\u2175': '\u0076\u0069',
  12662. '\u2176': '\u0076\u0069\u0069',
  12663. '\u2177': '\u0076\u0069\u0069\u0069',
  12664. '\u2178': '\u0069\u0078',
  12665. '\u2179': '\u0078',
  12666. '\u217A': '\u0078\u0069',
  12667. '\u217B': '\u0078\u0069\u0069',
  12668. '\u217C': '\u006C',
  12669. '\u217D': '\u0063',
  12670. '\u217E': '\u0064',
  12671. '\u217F': '\u006D',
  12672. '\u222C': '\u222B\u222B',
  12673. '\u222D': '\u222B\u222B\u222B',
  12674. '\u222F': '\u222E\u222E',
  12675. '\u2230': '\u222E\u222E\u222E',
  12676. '\u2474': '\u0028\u0031\u0029',
  12677. '\u2475': '\u0028\u0032\u0029',
  12678. '\u2476': '\u0028\u0033\u0029',
  12679. '\u2477': '\u0028\u0034\u0029',
  12680. '\u2478': '\u0028\u0035\u0029',
  12681. '\u2479': '\u0028\u0036\u0029',
  12682. '\u247A': '\u0028\u0037\u0029',
  12683. '\u247B': '\u0028\u0038\u0029',
  12684. '\u247C': '\u0028\u0039\u0029',
  12685. '\u247D': '\u0028\u0031\u0030\u0029',
  12686. '\u247E': '\u0028\u0031\u0031\u0029',
  12687. '\u247F': '\u0028\u0031\u0032\u0029',
  12688. '\u2480': '\u0028\u0031\u0033\u0029',
  12689. '\u2481': '\u0028\u0031\u0034\u0029',
  12690. '\u2482': '\u0028\u0031\u0035\u0029',
  12691. '\u2483': '\u0028\u0031\u0036\u0029',
  12692. '\u2484': '\u0028\u0031\u0037\u0029',
  12693. '\u2485': '\u0028\u0031\u0038\u0029',
  12694. '\u2486': '\u0028\u0031\u0039\u0029',
  12695. '\u2487': '\u0028\u0032\u0030\u0029',
  12696. '\u2488': '\u0031\u002E',
  12697. '\u2489': '\u0032\u002E',
  12698. '\u248A': '\u0033\u002E',
  12699. '\u248B': '\u0034\u002E',
  12700. '\u248C': '\u0035\u002E',
  12701. '\u248D': '\u0036\u002E',
  12702. '\u248E': '\u0037\u002E',
  12703. '\u248F': '\u0038\u002E',
  12704. '\u2490': '\u0039\u002E',
  12705. '\u2491': '\u0031\u0030\u002E',
  12706. '\u2492': '\u0031\u0031\u002E',
  12707. '\u2493': '\u0031\u0032\u002E',
  12708. '\u2494': '\u0031\u0033\u002E',
  12709. '\u2495': '\u0031\u0034\u002E',
  12710. '\u2496': '\u0031\u0035\u002E',
  12711. '\u2497': '\u0031\u0036\u002E',
  12712. '\u2498': '\u0031\u0037\u002E',
  12713. '\u2499': '\u0031\u0038\u002E',
  12714. '\u249A': '\u0031\u0039\u002E',
  12715. '\u249B': '\u0032\u0030\u002E',
  12716. '\u249C': '\u0028\u0061\u0029',
  12717. '\u249D': '\u0028\u0062\u0029',
  12718. '\u249E': '\u0028\u0063\u0029',
  12719. '\u249F': '\u0028\u0064\u0029',
  12720. '\u24A0': '\u0028\u0065\u0029',
  12721. '\u24A1': '\u0028\u0066\u0029',
  12722. '\u24A2': '\u0028\u0067\u0029',
  12723. '\u24A3': '\u0028\u0068\u0029',
  12724. '\u24A4': '\u0028\u0069\u0029',
  12725. '\u24A5': '\u0028\u006A\u0029',
  12726. '\u24A6': '\u0028\u006B\u0029',
  12727. '\u24A7': '\u0028\u006C\u0029',
  12728. '\u24A8': '\u0028\u006D\u0029',
  12729. '\u24A9': '\u0028\u006E\u0029',
  12730. '\u24AA': '\u0028\u006F\u0029',
  12731. '\u24AB': '\u0028\u0070\u0029',
  12732. '\u24AC': '\u0028\u0071\u0029',
  12733. '\u24AD': '\u0028\u0072\u0029',
  12734. '\u24AE': '\u0028\u0073\u0029',
  12735. '\u24AF': '\u0028\u0074\u0029',
  12736. '\u24B0': '\u0028\u0075\u0029',
  12737. '\u24B1': '\u0028\u0076\u0029',
  12738. '\u24B2': '\u0028\u0077\u0029',
  12739. '\u24B3': '\u0028\u0078\u0029',
  12740. '\u24B4': '\u0028\u0079\u0029',
  12741. '\u24B5': '\u0028\u007A\u0029',
  12742. '\u2A0C': '\u222B\u222B\u222B\u222B',
  12743. '\u2A74': '\u003A\u003A\u003D',
  12744. '\u2A75': '\u003D\u003D',
  12745. '\u2A76': '\u003D\u003D\u003D',
  12746. '\u2E9F': '\u6BCD',
  12747. '\u2EF3': '\u9F9F',
  12748. '\u2F00': '\u4E00',
  12749. '\u2F01': '\u4E28',
  12750. '\u2F02': '\u4E36',
  12751. '\u2F03': '\u4E3F',
  12752. '\u2F04': '\u4E59',
  12753. '\u2F05': '\u4E85',
  12754. '\u2F06': '\u4E8C',
  12755. '\u2F07': '\u4EA0',
  12756. '\u2F08': '\u4EBA',
  12757. '\u2F09': '\u513F',
  12758. '\u2F0A': '\u5165',
  12759. '\u2F0B': '\u516B',
  12760. '\u2F0C': '\u5182',
  12761. '\u2F0D': '\u5196',
  12762. '\u2F0E': '\u51AB',
  12763. '\u2F0F': '\u51E0',
  12764. '\u2F10': '\u51F5',
  12765. '\u2F11': '\u5200',
  12766. '\u2F12': '\u529B',
  12767. '\u2F13': '\u52F9',
  12768. '\u2F14': '\u5315',
  12769. '\u2F15': '\u531A',
  12770. '\u2F16': '\u5338',
  12771. '\u2F17': '\u5341',
  12772. '\u2F18': '\u535C',
  12773. '\u2F19': '\u5369',
  12774. '\u2F1A': '\u5382',
  12775. '\u2F1B': '\u53B6',
  12776. '\u2F1C': '\u53C8',
  12777. '\u2F1D': '\u53E3',
  12778. '\u2F1E': '\u56D7',
  12779. '\u2F1F': '\u571F',
  12780. '\u2F20': '\u58EB',
  12781. '\u2F21': '\u5902',
  12782. '\u2F22': '\u590A',
  12783. '\u2F23': '\u5915',
  12784. '\u2F24': '\u5927',
  12785. '\u2F25': '\u5973',
  12786. '\u2F26': '\u5B50',
  12787. '\u2F27': '\u5B80',
  12788. '\u2F28': '\u5BF8',
  12789. '\u2F29': '\u5C0F',
  12790. '\u2F2A': '\u5C22',
  12791. '\u2F2B': '\u5C38',
  12792. '\u2F2C': '\u5C6E',
  12793. '\u2F2D': '\u5C71',
  12794. '\u2F2E': '\u5DDB',
  12795. '\u2F2F': '\u5DE5',
  12796. '\u2F30': '\u5DF1',
  12797. '\u2F31': '\u5DFE',
  12798. '\u2F32': '\u5E72',
  12799. '\u2F33': '\u5E7A',
  12800. '\u2F34': '\u5E7F',
  12801. '\u2F35': '\u5EF4',
  12802. '\u2F36': '\u5EFE',
  12803. '\u2F37': '\u5F0B',
  12804. '\u2F38': '\u5F13',
  12805. '\u2F39': '\u5F50',
  12806. '\u2F3A': '\u5F61',
  12807. '\u2F3B': '\u5F73',
  12808. '\u2F3C': '\u5FC3',
  12809. '\u2F3D': '\u6208',
  12810. '\u2F3E': '\u6236',
  12811. '\u2F3F': '\u624B',
  12812. '\u2F40': '\u652F',
  12813. '\u2F41': '\u6534',
  12814. '\u2F42': '\u6587',
  12815. '\u2F43': '\u6597',
  12816. '\u2F44': '\u65A4',
  12817. '\u2F45': '\u65B9',
  12818. '\u2F46': '\u65E0',
  12819. '\u2F47': '\u65E5',
  12820. '\u2F48': '\u66F0',
  12821. '\u2F49': '\u6708',
  12822. '\u2F4A': '\u6728',
  12823. '\u2F4B': '\u6B20',
  12824. '\u2F4C': '\u6B62',
  12825. '\u2F4D': '\u6B79',
  12826. '\u2F4E': '\u6BB3',
  12827. '\u2F4F': '\u6BCB',
  12828. '\u2F50': '\u6BD4',
  12829. '\u2F51': '\u6BDB',
  12830. '\u2F52': '\u6C0F',
  12831. '\u2F53': '\u6C14',
  12832. '\u2F54': '\u6C34',
  12833. '\u2F55': '\u706B',
  12834. '\u2F56': '\u722A',
  12835. '\u2F57': '\u7236',
  12836. '\u2F58': '\u723B',
  12837. '\u2F59': '\u723F',
  12838. '\u2F5A': '\u7247',
  12839. '\u2F5B': '\u7259',
  12840. '\u2F5C': '\u725B',
  12841. '\u2F5D': '\u72AC',
  12842. '\u2F5E': '\u7384',
  12843. '\u2F5F': '\u7389',
  12844. '\u2F60': '\u74DC',
  12845. '\u2F61': '\u74E6',
  12846. '\u2F62': '\u7518',
  12847. '\u2F63': '\u751F',
  12848. '\u2F64': '\u7528',
  12849. '\u2F65': '\u7530',
  12850. '\u2F66': '\u758B',
  12851. '\u2F67': '\u7592',
  12852. '\u2F68': '\u7676',
  12853. '\u2F69': '\u767D',
  12854. '\u2F6A': '\u76AE',
  12855. '\u2F6B': '\u76BF',
  12856. '\u2F6C': '\u76EE',
  12857. '\u2F6D': '\u77DB',
  12858. '\u2F6E': '\u77E2',
  12859. '\u2F6F': '\u77F3',
  12860. '\u2F70': '\u793A',
  12861. '\u2F71': '\u79B8',
  12862. '\u2F72': '\u79BE',
  12863. '\u2F73': '\u7A74',
  12864. '\u2F74': '\u7ACB',
  12865. '\u2F75': '\u7AF9',
  12866. '\u2F76': '\u7C73',
  12867. '\u2F77': '\u7CF8',
  12868. '\u2F78': '\u7F36',
  12869. '\u2F79': '\u7F51',
  12870. '\u2F7A': '\u7F8A',
  12871. '\u2F7B': '\u7FBD',
  12872. '\u2F7C': '\u8001',
  12873. '\u2F7D': '\u800C',
  12874. '\u2F7E': '\u8012',
  12875. '\u2F7F': '\u8033',
  12876. '\u2F80': '\u807F',
  12877. '\u2F81': '\u8089',
  12878. '\u2F82': '\u81E3',
  12879. '\u2F83': '\u81EA',
  12880. '\u2F84': '\u81F3',
  12881. '\u2F85': '\u81FC',
  12882. '\u2F86': '\u820C',
  12883. '\u2F87': '\u821B',
  12884. '\u2F88': '\u821F',
  12885. '\u2F89': '\u826E',
  12886. '\u2F8A': '\u8272',
  12887. '\u2F8B': '\u8278',
  12888. '\u2F8C': '\u864D',
  12889. '\u2F8D': '\u866B',
  12890. '\u2F8E': '\u8840',
  12891. '\u2F8F': '\u884C',
  12892. '\u2F90': '\u8863',
  12893. '\u2F91': '\u897E',
  12894. '\u2F92': '\u898B',
  12895. '\u2F93': '\u89D2',
  12896. '\u2F94': '\u8A00',
  12897. '\u2F95': '\u8C37',
  12898. '\u2F96': '\u8C46',
  12899. '\u2F97': '\u8C55',
  12900. '\u2F98': '\u8C78',
  12901. '\u2F99': '\u8C9D',
  12902. '\u2F9A': '\u8D64',
  12903. '\u2F9B': '\u8D70',
  12904. '\u2F9C': '\u8DB3',
  12905. '\u2F9D': '\u8EAB',
  12906. '\u2F9E': '\u8ECA',
  12907. '\u2F9F': '\u8F9B',
  12908. '\u2FA0': '\u8FB0',
  12909. '\u2FA1': '\u8FB5',
  12910. '\u2FA2': '\u9091',
  12911. '\u2FA3': '\u9149',
  12912. '\u2FA4': '\u91C6',
  12913. '\u2FA5': '\u91CC',
  12914. '\u2FA6': '\u91D1',
  12915. '\u2FA7': '\u9577',
  12916. '\u2FA8': '\u9580',
  12917. '\u2FA9': '\u961C',
  12918. '\u2FAA': '\u96B6',
  12919. '\u2FAB': '\u96B9',
  12920. '\u2FAC': '\u96E8',
  12921. '\u2FAD': '\u9751',
  12922. '\u2FAE': '\u975E',
  12923. '\u2FAF': '\u9762',
  12924. '\u2FB0': '\u9769',
  12925. '\u2FB1': '\u97CB',
  12926. '\u2FB2': '\u97ED',
  12927. '\u2FB3': '\u97F3',
  12928. '\u2FB4': '\u9801',
  12929. '\u2FB5': '\u98A8',
  12930. '\u2FB6': '\u98DB',
  12931. '\u2FB7': '\u98DF',
  12932. '\u2FB8': '\u9996',
  12933. '\u2FB9': '\u9999',
  12934. '\u2FBA': '\u99AC',
  12935. '\u2FBB': '\u9AA8',
  12936. '\u2FBC': '\u9AD8',
  12937. '\u2FBD': '\u9ADF',
  12938. '\u2FBE': '\u9B25',
  12939. '\u2FBF': '\u9B2F',
  12940. '\u2FC0': '\u9B32',
  12941. '\u2FC1': '\u9B3C',
  12942. '\u2FC2': '\u9B5A',
  12943. '\u2FC3': '\u9CE5',
  12944. '\u2FC4': '\u9E75',
  12945. '\u2FC5': '\u9E7F',
  12946. '\u2FC6': '\u9EA5',
  12947. '\u2FC7': '\u9EBB',
  12948. '\u2FC8': '\u9EC3',
  12949. '\u2FC9': '\u9ECD',
  12950. '\u2FCA': '\u9ED1',
  12951. '\u2FCB': '\u9EF9',
  12952. '\u2FCC': '\u9EFD',
  12953. '\u2FCD': '\u9F0E',
  12954. '\u2FCE': '\u9F13',
  12955. '\u2FCF': '\u9F20',
  12956. '\u2FD0': '\u9F3B',
  12957. '\u2FD1': '\u9F4A',
  12958. '\u2FD2': '\u9F52',
  12959. '\u2FD3': '\u9F8D',
  12960. '\u2FD4': '\u9F9C',
  12961. '\u2FD5': '\u9FA0',
  12962. '\u3036': '\u3012',
  12963. '\u3038': '\u5341',
  12964. '\u3039': '\u5344',
  12965. '\u303A': '\u5345',
  12966. '\u309B': '\u0020\u3099',
  12967. '\u309C': '\u0020\u309A',
  12968. '\u3131': '\u1100',
  12969. '\u3132': '\u1101',
  12970. '\u3133': '\u11AA',
  12971. '\u3134': '\u1102',
  12972. '\u3135': '\u11AC',
  12973. '\u3136': '\u11AD',
  12974. '\u3137': '\u1103',
  12975. '\u3138': '\u1104',
  12976. '\u3139': '\u1105',
  12977. '\u313A': '\u11B0',
  12978. '\u313B': '\u11B1',
  12979. '\u313C': '\u11B2',
  12980. '\u313D': '\u11B3',
  12981. '\u313E': '\u11B4',
  12982. '\u313F': '\u11B5',
  12983. '\u3140': '\u111A',
  12984. '\u3141': '\u1106',
  12985. '\u3142': '\u1107',
  12986. '\u3143': '\u1108',
  12987. '\u3144': '\u1121',
  12988. '\u3145': '\u1109',
  12989. '\u3146': '\u110A',
  12990. '\u3147': '\u110B',
  12991. '\u3148': '\u110C',
  12992. '\u3149': '\u110D',
  12993. '\u314A': '\u110E',
  12994. '\u314B': '\u110F',
  12995. '\u314C': '\u1110',
  12996. '\u314D': '\u1111',
  12997. '\u314E': '\u1112',
  12998. '\u314F': '\u1161',
  12999. '\u3150': '\u1162',
  13000. '\u3151': '\u1163',
  13001. '\u3152': '\u1164',
  13002. '\u3153': '\u1165',
  13003. '\u3154': '\u1166',
  13004. '\u3155': '\u1167',
  13005. '\u3156': '\u1168',
  13006. '\u3157': '\u1169',
  13007. '\u3158': '\u116A',
  13008. '\u3159': '\u116B',
  13009. '\u315A': '\u116C',
  13010. '\u315B': '\u116D',
  13011. '\u315C': '\u116E',
  13012. '\u315D': '\u116F',
  13013. '\u315E': '\u1170',
  13014. '\u315F': '\u1171',
  13015. '\u3160': '\u1172',
  13016. '\u3161': '\u1173',
  13017. '\u3162': '\u1174',
  13018. '\u3163': '\u1175',
  13019. '\u3164': '\u1160',
  13020. '\u3165': '\u1114',
  13021. '\u3166': '\u1115',
  13022. '\u3167': '\u11C7',
  13023. '\u3168': '\u11C8',
  13024. '\u3169': '\u11CC',
  13025. '\u316A': '\u11CE',
  13026. '\u316B': '\u11D3',
  13027. '\u316C': '\u11D7',
  13028. '\u316D': '\u11D9',
  13029. '\u316E': '\u111C',
  13030. '\u316F': '\u11DD',
  13031. '\u3170': '\u11DF',
  13032. '\u3171': '\u111D',
  13033. '\u3172': '\u111E',
  13034. '\u3173': '\u1120',
  13035. '\u3174': '\u1122',
  13036. '\u3175': '\u1123',
  13037. '\u3176': '\u1127',
  13038. '\u3177': '\u1129',
  13039. '\u3178': '\u112B',
  13040. '\u3179': '\u112C',
  13041. '\u317A': '\u112D',
  13042. '\u317B': '\u112E',
  13043. '\u317C': '\u112F',
  13044. '\u317D': '\u1132',
  13045. '\u317E': '\u1136',
  13046. '\u317F': '\u1140',
  13047. '\u3180': '\u1147',
  13048. '\u3181': '\u114C',
  13049. '\u3182': '\u11F1',
  13050. '\u3183': '\u11F2',
  13051. '\u3184': '\u1157',
  13052. '\u3185': '\u1158',
  13053. '\u3186': '\u1159',
  13054. '\u3187': '\u1184',
  13055. '\u3188': '\u1185',
  13056. '\u3189': '\u1188',
  13057. '\u318A': '\u1191',
  13058. '\u318B': '\u1192',
  13059. '\u318C': '\u1194',
  13060. '\u318D': '\u119E',
  13061. '\u318E': '\u11A1',
  13062. '\u3200': '\u0028\u1100\u0029',
  13063. '\u3201': '\u0028\u1102\u0029',
  13064. '\u3202': '\u0028\u1103\u0029',
  13065. '\u3203': '\u0028\u1105\u0029',
  13066. '\u3204': '\u0028\u1106\u0029',
  13067. '\u3205': '\u0028\u1107\u0029',
  13068. '\u3206': '\u0028\u1109\u0029',
  13069. '\u3207': '\u0028\u110B\u0029',
  13070. '\u3208': '\u0028\u110C\u0029',
  13071. '\u3209': '\u0028\u110E\u0029',
  13072. '\u320A': '\u0028\u110F\u0029',
  13073. '\u320B': '\u0028\u1110\u0029',
  13074. '\u320C': '\u0028\u1111\u0029',
  13075. '\u320D': '\u0028\u1112\u0029',
  13076. '\u320E': '\u0028\u1100\u1161\u0029',
  13077. '\u320F': '\u0028\u1102\u1161\u0029',
  13078. '\u3210': '\u0028\u1103\u1161\u0029',
  13079. '\u3211': '\u0028\u1105\u1161\u0029',
  13080. '\u3212': '\u0028\u1106\u1161\u0029',
  13081. '\u3213': '\u0028\u1107\u1161\u0029',
  13082. '\u3214': '\u0028\u1109\u1161\u0029',
  13083. '\u3215': '\u0028\u110B\u1161\u0029',
  13084. '\u3216': '\u0028\u110C\u1161\u0029',
  13085. '\u3217': '\u0028\u110E\u1161\u0029',
  13086. '\u3218': '\u0028\u110F\u1161\u0029',
  13087. '\u3219': '\u0028\u1110\u1161\u0029',
  13088. '\u321A': '\u0028\u1111\u1161\u0029',
  13089. '\u321B': '\u0028\u1112\u1161\u0029',
  13090. '\u321C': '\u0028\u110C\u116E\u0029',
  13091. '\u321D': '\u0028\u110B\u1169\u110C\u1165\u11AB\u0029',
  13092. '\u321E': '\u0028\u110B\u1169\u1112\u116E\u0029',
  13093. '\u3220': '\u0028\u4E00\u0029',
  13094. '\u3221': '\u0028\u4E8C\u0029',
  13095. '\u3222': '\u0028\u4E09\u0029',
  13096. '\u3223': '\u0028\u56DB\u0029',
  13097. '\u3224': '\u0028\u4E94\u0029',
  13098. '\u3225': '\u0028\u516D\u0029',
  13099. '\u3226': '\u0028\u4E03\u0029',
  13100. '\u3227': '\u0028\u516B\u0029',
  13101. '\u3228': '\u0028\u4E5D\u0029',
  13102. '\u3229': '\u0028\u5341\u0029',
  13103. '\u322A': '\u0028\u6708\u0029',
  13104. '\u322B': '\u0028\u706B\u0029',
  13105. '\u322C': '\u0028\u6C34\u0029',
  13106. '\u322D': '\u0028\u6728\u0029',
  13107. '\u322E': '\u0028\u91D1\u0029',
  13108. '\u322F': '\u0028\u571F\u0029',
  13109. '\u3230': '\u0028\u65E5\u0029',
  13110. '\u3231': '\u0028\u682A\u0029',
  13111. '\u3232': '\u0028\u6709\u0029',
  13112. '\u3233': '\u0028\u793E\u0029',
  13113. '\u3234': '\u0028\u540D\u0029',
  13114. '\u3235': '\u0028\u7279\u0029',
  13115. '\u3236': '\u0028\u8CA1\u0029',
  13116. '\u3237': '\u0028\u795D\u0029',
  13117. '\u3238': '\u0028\u52B4\u0029',
  13118. '\u3239': '\u0028\u4EE3\u0029',
  13119. '\u323A': '\u0028\u547C\u0029',
  13120. '\u323B': '\u0028\u5B66\u0029',
  13121. '\u323C': '\u0028\u76E3\u0029',
  13122. '\u323D': '\u0028\u4F01\u0029',
  13123. '\u323E': '\u0028\u8CC7\u0029',
  13124. '\u323F': '\u0028\u5354\u0029',
  13125. '\u3240': '\u0028\u796D\u0029',
  13126. '\u3241': '\u0028\u4F11\u0029',
  13127. '\u3242': '\u0028\u81EA\u0029',
  13128. '\u3243': '\u0028\u81F3\u0029',
  13129. '\u32C0': '\u0031\u6708',
  13130. '\u32C1': '\u0032\u6708',
  13131. '\u32C2': '\u0033\u6708',
  13132. '\u32C3': '\u0034\u6708',
  13133. '\u32C4': '\u0035\u6708',
  13134. '\u32C5': '\u0036\u6708',
  13135. '\u32C6': '\u0037\u6708',
  13136. '\u32C7': '\u0038\u6708',
  13137. '\u32C8': '\u0039\u6708',
  13138. '\u32C9': '\u0031\u0030\u6708',
  13139. '\u32CA': '\u0031\u0031\u6708',
  13140. '\u32CB': '\u0031\u0032\u6708',
  13141. '\u3358': '\u0030\u70B9',
  13142. '\u3359': '\u0031\u70B9',
  13143. '\u335A': '\u0032\u70B9',
  13144. '\u335B': '\u0033\u70B9',
  13145. '\u335C': '\u0034\u70B9',
  13146. '\u335D': '\u0035\u70B9',
  13147. '\u335E': '\u0036\u70B9',
  13148. '\u335F': '\u0037\u70B9',
  13149. '\u3360': '\u0038\u70B9',
  13150. '\u3361': '\u0039\u70B9',
  13151. '\u3362': '\u0031\u0030\u70B9',
  13152. '\u3363': '\u0031\u0031\u70B9',
  13153. '\u3364': '\u0031\u0032\u70B9',
  13154. '\u3365': '\u0031\u0033\u70B9',
  13155. '\u3366': '\u0031\u0034\u70B9',
  13156. '\u3367': '\u0031\u0035\u70B9',
  13157. '\u3368': '\u0031\u0036\u70B9',
  13158. '\u3369': '\u0031\u0037\u70B9',
  13159. '\u336A': '\u0031\u0038\u70B9',
  13160. '\u336B': '\u0031\u0039\u70B9',
  13161. '\u336C': '\u0032\u0030\u70B9',
  13162. '\u336D': '\u0032\u0031\u70B9',
  13163. '\u336E': '\u0032\u0032\u70B9',
  13164. '\u336F': '\u0032\u0033\u70B9',
  13165. '\u3370': '\u0032\u0034\u70B9',
  13166. '\u33E0': '\u0031\u65E5',
  13167. '\u33E1': '\u0032\u65E5',
  13168. '\u33E2': '\u0033\u65E5',
  13169. '\u33E3': '\u0034\u65E5',
  13170. '\u33E4': '\u0035\u65E5',
  13171. '\u33E5': '\u0036\u65E5',
  13172. '\u33E6': '\u0037\u65E5',
  13173. '\u33E7': '\u0038\u65E5',
  13174. '\u33E8': '\u0039\u65E5',
  13175. '\u33E9': '\u0031\u0030\u65E5',
  13176. '\u33EA': '\u0031\u0031\u65E5',
  13177. '\u33EB': '\u0031\u0032\u65E5',
  13178. '\u33EC': '\u0031\u0033\u65E5',
  13179. '\u33ED': '\u0031\u0034\u65E5',
  13180. '\u33EE': '\u0031\u0035\u65E5',
  13181. '\u33EF': '\u0031\u0036\u65E5',
  13182. '\u33F0': '\u0031\u0037\u65E5',
  13183. '\u33F1': '\u0031\u0038\u65E5',
  13184. '\u33F2': '\u0031\u0039\u65E5',
  13185. '\u33F3': '\u0032\u0030\u65E5',
  13186. '\u33F4': '\u0032\u0031\u65E5',
  13187. '\u33F5': '\u0032\u0032\u65E5',
  13188. '\u33F6': '\u0032\u0033\u65E5',
  13189. '\u33F7': '\u0032\u0034\u65E5',
  13190. '\u33F8': '\u0032\u0035\u65E5',
  13191. '\u33F9': '\u0032\u0036\u65E5',
  13192. '\u33FA': '\u0032\u0037\u65E5',
  13193. '\u33FB': '\u0032\u0038\u65E5',
  13194. '\u33FC': '\u0032\u0039\u65E5',
  13195. '\u33FD': '\u0033\u0030\u65E5',
  13196. '\u33FE': '\u0033\u0031\u65E5',
  13197. '\uFB00': '\u0066\u0066',
  13198. '\uFB01': '\u0066\u0069',
  13199. '\uFB02': '\u0066\u006C',
  13200. '\uFB03': '\u0066\u0066\u0069',
  13201. '\uFB04': '\u0066\u0066\u006C',
  13202. '\uFB05': '\u017F\u0074',
  13203. '\uFB06': '\u0073\u0074',
  13204. '\uFB13': '\u0574\u0576',
  13205. '\uFB14': '\u0574\u0565',
  13206. '\uFB15': '\u0574\u056B',
  13207. '\uFB16': '\u057E\u0576',
  13208. '\uFB17': '\u0574\u056D',
  13209. '\uFB4F': '\u05D0\u05DC',
  13210. '\uFB50': '\u0671',
  13211. '\uFB51': '\u0671',
  13212. '\uFB52': '\u067B',
  13213. '\uFB53': '\u067B',
  13214. '\uFB54': '\u067B',
  13215. '\uFB55': '\u067B',
  13216. '\uFB56': '\u067E',
  13217. '\uFB57': '\u067E',
  13218. '\uFB58': '\u067E',
  13219. '\uFB59': '\u067E',
  13220. '\uFB5A': '\u0680',
  13221. '\uFB5B': '\u0680',
  13222. '\uFB5C': '\u0680',
  13223. '\uFB5D': '\u0680',
  13224. '\uFB5E': '\u067A',
  13225. '\uFB5F': '\u067A',
  13226. '\uFB60': '\u067A',
  13227. '\uFB61': '\u067A',
  13228. '\uFB62': '\u067F',
  13229. '\uFB63': '\u067F',
  13230. '\uFB64': '\u067F',
  13231. '\uFB65': '\u067F',
  13232. '\uFB66': '\u0679',
  13233. '\uFB67': '\u0679',
  13234. '\uFB68': '\u0679',
  13235. '\uFB69': '\u0679',
  13236. '\uFB6A': '\u06A4',
  13237. '\uFB6B': '\u06A4',
  13238. '\uFB6C': '\u06A4',
  13239. '\uFB6D': '\u06A4',
  13240. '\uFB6E': '\u06A6',
  13241. '\uFB6F': '\u06A6',
  13242. '\uFB70': '\u06A6',
  13243. '\uFB71': '\u06A6',
  13244. '\uFB72': '\u0684',
  13245. '\uFB73': '\u0684',
  13246. '\uFB74': '\u0684',
  13247. '\uFB75': '\u0684',
  13248. '\uFB76': '\u0683',
  13249. '\uFB77': '\u0683',
  13250. '\uFB78': '\u0683',
  13251. '\uFB79': '\u0683',
  13252. '\uFB7A': '\u0686',
  13253. '\uFB7B': '\u0686',
  13254. '\uFB7C': '\u0686',
  13255. '\uFB7D': '\u0686',
  13256. '\uFB7E': '\u0687',
  13257. '\uFB7F': '\u0687',
  13258. '\uFB80': '\u0687',
  13259. '\uFB81': '\u0687',
  13260. '\uFB82': '\u068D',
  13261. '\uFB83': '\u068D',
  13262. '\uFB84': '\u068C',
  13263. '\uFB85': '\u068C',
  13264. '\uFB86': '\u068E',
  13265. '\uFB87': '\u068E',
  13266. '\uFB88': '\u0688',
  13267. '\uFB89': '\u0688',
  13268. '\uFB8A': '\u0698',
  13269. '\uFB8B': '\u0698',
  13270. '\uFB8C': '\u0691',
  13271. '\uFB8D': '\u0691',
  13272. '\uFB8E': '\u06A9',
  13273. '\uFB8F': '\u06A9',
  13274. '\uFB90': '\u06A9',
  13275. '\uFB91': '\u06A9',
  13276. '\uFB92': '\u06AF',
  13277. '\uFB93': '\u06AF',
  13278. '\uFB94': '\u06AF',
  13279. '\uFB95': '\u06AF',
  13280. '\uFB96': '\u06B3',
  13281. '\uFB97': '\u06B3',
  13282. '\uFB98': '\u06B3',
  13283. '\uFB99': '\u06B3',
  13284. '\uFB9A': '\u06B1',
  13285. '\uFB9B': '\u06B1',
  13286. '\uFB9C': '\u06B1',
  13287. '\uFB9D': '\u06B1',
  13288. '\uFB9E': '\u06BA',
  13289. '\uFB9F': '\u06BA',
  13290. '\uFBA0': '\u06BB',
  13291. '\uFBA1': '\u06BB',
  13292. '\uFBA2': '\u06BB',
  13293. '\uFBA3': '\u06BB',
  13294. '\uFBA4': '\u06C0',
  13295. '\uFBA5': '\u06C0',
  13296. '\uFBA6': '\u06C1',
  13297. '\uFBA7': '\u06C1',
  13298. '\uFBA8': '\u06C1',
  13299. '\uFBA9': '\u06C1',
  13300. '\uFBAA': '\u06BE',
  13301. '\uFBAB': '\u06BE',
  13302. '\uFBAC': '\u06BE',
  13303. '\uFBAD': '\u06BE',
  13304. '\uFBAE': '\u06D2',
  13305. '\uFBAF': '\u06D2',
  13306. '\uFBB0': '\u06D3',
  13307. '\uFBB1': '\u06D3',
  13308. '\uFBD3': '\u06AD',
  13309. '\uFBD4': '\u06AD',
  13310. '\uFBD5': '\u06AD',
  13311. '\uFBD6': '\u06AD',
  13312. '\uFBD7': '\u06C7',
  13313. '\uFBD8': '\u06C7',
  13314. '\uFBD9': '\u06C6',
  13315. '\uFBDA': '\u06C6',
  13316. '\uFBDB': '\u06C8',
  13317. '\uFBDC': '\u06C8',
  13318. '\uFBDD': '\u0677',
  13319. '\uFBDE': '\u06CB',
  13320. '\uFBDF': '\u06CB',
  13321. '\uFBE0': '\u06C5',
  13322. '\uFBE1': '\u06C5',
  13323. '\uFBE2': '\u06C9',
  13324. '\uFBE3': '\u06C9',
  13325. '\uFBE4': '\u06D0',
  13326. '\uFBE5': '\u06D0',
  13327. '\uFBE6': '\u06D0',
  13328. '\uFBE7': '\u06D0',
  13329. '\uFBE8': '\u0649',
  13330. '\uFBE9': '\u0649',
  13331. '\uFBEA': '\u0626\u0627',
  13332. '\uFBEB': '\u0626\u0627',
  13333. '\uFBEC': '\u0626\u06D5',
  13334. '\uFBED': '\u0626\u06D5',
  13335. '\uFBEE': '\u0626\u0648',
  13336. '\uFBEF': '\u0626\u0648',
  13337. '\uFBF0': '\u0626\u06C7',
  13338. '\uFBF1': '\u0626\u06C7',
  13339. '\uFBF2': '\u0626\u06C6',
  13340. '\uFBF3': '\u0626\u06C6',
  13341. '\uFBF4': '\u0626\u06C8',
  13342. '\uFBF5': '\u0626\u06C8',
  13343. '\uFBF6': '\u0626\u06D0',
  13344. '\uFBF7': '\u0626\u06D0',
  13345. '\uFBF8': '\u0626\u06D0',
  13346. '\uFBF9': '\u0626\u0649',
  13347. '\uFBFA': '\u0626\u0649',
  13348. '\uFBFB': '\u0626\u0649',
  13349. '\uFBFC': '\u06CC',
  13350. '\uFBFD': '\u06CC',
  13351. '\uFBFE': '\u06CC',
  13352. '\uFBFF': '\u06CC',
  13353. '\uFC00': '\u0626\u062C',
  13354. '\uFC01': '\u0626\u062D',
  13355. '\uFC02': '\u0626\u0645',
  13356. '\uFC03': '\u0626\u0649',
  13357. '\uFC04': '\u0626\u064A',
  13358. '\uFC05': '\u0628\u062C',
  13359. '\uFC06': '\u0628\u062D',
  13360. '\uFC07': '\u0628\u062E',
  13361. '\uFC08': '\u0628\u0645',
  13362. '\uFC09': '\u0628\u0649',
  13363. '\uFC0A': '\u0628\u064A',
  13364. '\uFC0B': '\u062A\u062C',
  13365. '\uFC0C': '\u062A\u062D',
  13366. '\uFC0D': '\u062A\u062E',
  13367. '\uFC0E': '\u062A\u0645',
  13368. '\uFC0F': '\u062A\u0649',
  13369. '\uFC10': '\u062A\u064A',
  13370. '\uFC11': '\u062B\u062C',
  13371. '\uFC12': '\u062B\u0645',
  13372. '\uFC13': '\u062B\u0649',
  13373. '\uFC14': '\u062B\u064A',
  13374. '\uFC15': '\u062C\u062D',
  13375. '\uFC16': '\u062C\u0645',
  13376. '\uFC17': '\u062D\u062C',
  13377. '\uFC18': '\u062D\u0645',
  13378. '\uFC19': '\u062E\u062C',
  13379. '\uFC1A': '\u062E\u062D',
  13380. '\uFC1B': '\u062E\u0645',
  13381. '\uFC1C': '\u0633\u062C',
  13382. '\uFC1D': '\u0633\u062D',
  13383. '\uFC1E': '\u0633\u062E',
  13384. '\uFC1F': '\u0633\u0645',
  13385. '\uFC20': '\u0635\u062D',
  13386. '\uFC21': '\u0635\u0645',
  13387. '\uFC22': '\u0636\u062C',
  13388. '\uFC23': '\u0636\u062D',
  13389. '\uFC24': '\u0636\u062E',
  13390. '\uFC25': '\u0636\u0645',
  13391. '\uFC26': '\u0637\u062D',
  13392. '\uFC27': '\u0637\u0645',
  13393. '\uFC28': '\u0638\u0645',
  13394. '\uFC29': '\u0639\u062C',
  13395. '\uFC2A': '\u0639\u0645',
  13396. '\uFC2B': '\u063A\u062C',
  13397. '\uFC2C': '\u063A\u0645',
  13398. '\uFC2D': '\u0641\u062C',
  13399. '\uFC2E': '\u0641\u062D',
  13400. '\uFC2F': '\u0641\u062E',
  13401. '\uFC30': '\u0641\u0645',
  13402. '\uFC31': '\u0641\u0649',
  13403. '\uFC32': '\u0641\u064A',
  13404. '\uFC33': '\u0642\u062D',
  13405. '\uFC34': '\u0642\u0645',
  13406. '\uFC35': '\u0642\u0649',
  13407. '\uFC36': '\u0642\u064A',
  13408. '\uFC37': '\u0643\u0627',
  13409. '\uFC38': '\u0643\u062C',
  13410. '\uFC39': '\u0643\u062D',
  13411. '\uFC3A': '\u0643\u062E',
  13412. '\uFC3B': '\u0643\u0644',
  13413. '\uFC3C': '\u0643\u0645',
  13414. '\uFC3D': '\u0643\u0649',
  13415. '\uFC3E': '\u0643\u064A',
  13416. '\uFC3F': '\u0644\u062C',
  13417. '\uFC40': '\u0644\u062D',
  13418. '\uFC41': '\u0644\u062E',
  13419. '\uFC42': '\u0644\u0645',
  13420. '\uFC43': '\u0644\u0649',
  13421. '\uFC44': '\u0644\u064A',
  13422. '\uFC45': '\u0645\u062C',
  13423. '\uFC46': '\u0645\u062D',
  13424. '\uFC47': '\u0645\u062E',
  13425. '\uFC48': '\u0645\u0645',
  13426. '\uFC49': '\u0645\u0649',
  13427. '\uFC4A': '\u0645\u064A',
  13428. '\uFC4B': '\u0646\u062C',
  13429. '\uFC4C': '\u0646\u062D',
  13430. '\uFC4D': '\u0646\u062E',
  13431. '\uFC4E': '\u0646\u0645',
  13432. '\uFC4F': '\u0646\u0649',
  13433. '\uFC50': '\u0646\u064A',
  13434. '\uFC51': '\u0647\u062C',
  13435. '\uFC52': '\u0647\u0645',
  13436. '\uFC53': '\u0647\u0649',
  13437. '\uFC54': '\u0647\u064A',
  13438. '\uFC55': '\u064A\u062C',
  13439. '\uFC56': '\u064A\u062D',
  13440. '\uFC57': '\u064A\u062E',
  13441. '\uFC58': '\u064A\u0645',
  13442. '\uFC59': '\u064A\u0649',
  13443. '\uFC5A': '\u064A\u064A',
  13444. '\uFC5B': '\u0630\u0670',
  13445. '\uFC5C': '\u0631\u0670',
  13446. '\uFC5D': '\u0649\u0670',
  13447. '\uFC5E': '\u0020\u064C\u0651',
  13448. '\uFC5F': '\u0020\u064D\u0651',
  13449. '\uFC60': '\u0020\u064E\u0651',
  13450. '\uFC61': '\u0020\u064F\u0651',
  13451. '\uFC62': '\u0020\u0650\u0651',
  13452. '\uFC63': '\u0020\u0651\u0670',
  13453. '\uFC64': '\u0626\u0631',
  13454. '\uFC65': '\u0626\u0632',
  13455. '\uFC66': '\u0626\u0645',
  13456. '\uFC67': '\u0626\u0646',
  13457. '\uFC68': '\u0626\u0649',
  13458. '\uFC69': '\u0626\u064A',
  13459. '\uFC6A': '\u0628\u0631',
  13460. '\uFC6B': '\u0628\u0632',
  13461. '\uFC6C': '\u0628\u0645',
  13462. '\uFC6D': '\u0628\u0646',
  13463. '\uFC6E': '\u0628\u0649',
  13464. '\uFC6F': '\u0628\u064A',
  13465. '\uFC70': '\u062A\u0631',
  13466. '\uFC71': '\u062A\u0632',
  13467. '\uFC72': '\u062A\u0645',
  13468. '\uFC73': '\u062A\u0646',
  13469. '\uFC74': '\u062A\u0649',
  13470. '\uFC75': '\u062A\u064A',
  13471. '\uFC76': '\u062B\u0631',
  13472. '\uFC77': '\u062B\u0632',
  13473. '\uFC78': '\u062B\u0645',
  13474. '\uFC79': '\u062B\u0646',
  13475. '\uFC7A': '\u062B\u0649',
  13476. '\uFC7B': '\u062B\u064A',
  13477. '\uFC7C': '\u0641\u0649',
  13478. '\uFC7D': '\u0641\u064A',
  13479. '\uFC7E': '\u0642\u0649',
  13480. '\uFC7F': '\u0642\u064A',
  13481. '\uFC80': '\u0643\u0627',
  13482. '\uFC81': '\u0643\u0644',
  13483. '\uFC82': '\u0643\u0645',
  13484. '\uFC83': '\u0643\u0649',
  13485. '\uFC84': '\u0643\u064A',
  13486. '\uFC85': '\u0644\u0645',
  13487. '\uFC86': '\u0644\u0649',
  13488. '\uFC87': '\u0644\u064A',
  13489. '\uFC88': '\u0645\u0627',
  13490. '\uFC89': '\u0645\u0645',
  13491. '\uFC8A': '\u0646\u0631',
  13492. '\uFC8B': '\u0646\u0632',
  13493. '\uFC8C': '\u0646\u0645',
  13494. '\uFC8D': '\u0646\u0646',
  13495. '\uFC8E': '\u0646\u0649',
  13496. '\uFC8F': '\u0646\u064A',
  13497. '\uFC90': '\u0649\u0670',
  13498. '\uFC91': '\u064A\u0631',
  13499. '\uFC92': '\u064A\u0632',
  13500. '\uFC93': '\u064A\u0645',
  13501. '\uFC94': '\u064A\u0646',
  13502. '\uFC95': '\u064A\u0649',
  13503. '\uFC96': '\u064A\u064A',
  13504. '\uFC97': '\u0626\u062C',
  13505. '\uFC98': '\u0626\u062D',
  13506. '\uFC99': '\u0626\u062E',
  13507. '\uFC9A': '\u0626\u0645',
  13508. '\uFC9B': '\u0626\u0647',
  13509. '\uFC9C': '\u0628\u062C',
  13510. '\uFC9D': '\u0628\u062D',
  13511. '\uFC9E': '\u0628\u062E',
  13512. '\uFC9F': '\u0628\u0645',
  13513. '\uFCA0': '\u0628\u0647',
  13514. '\uFCA1': '\u062A\u062C',
  13515. '\uFCA2': '\u062A\u062D',
  13516. '\uFCA3': '\u062A\u062E',
  13517. '\uFCA4': '\u062A\u0645',
  13518. '\uFCA5': '\u062A\u0647',
  13519. '\uFCA6': '\u062B\u0645',
  13520. '\uFCA7': '\u062C\u062D',
  13521. '\uFCA8': '\u062C\u0645',
  13522. '\uFCA9': '\u062D\u062C',
  13523. '\uFCAA': '\u062D\u0645',
  13524. '\uFCAB': '\u062E\u062C',
  13525. '\uFCAC': '\u062E\u0645',
  13526. '\uFCAD': '\u0633\u062C',
  13527. '\uFCAE': '\u0633\u062D',
  13528. '\uFCAF': '\u0633\u062E',
  13529. '\uFCB0': '\u0633\u0645',
  13530. '\uFCB1': '\u0635\u062D',
  13531. '\uFCB2': '\u0635\u062E',
  13532. '\uFCB3': '\u0635\u0645',
  13533. '\uFCB4': '\u0636\u062C',
  13534. '\uFCB5': '\u0636\u062D',
  13535. '\uFCB6': '\u0636\u062E',
  13536. '\uFCB7': '\u0636\u0645',
  13537. '\uFCB8': '\u0637\u062D',
  13538. '\uFCB9': '\u0638\u0645',
  13539. '\uFCBA': '\u0639\u062C',
  13540. '\uFCBB': '\u0639\u0645',
  13541. '\uFCBC': '\u063A\u062C',
  13542. '\uFCBD': '\u063A\u0645',
  13543. '\uFCBE': '\u0641\u062C',
  13544. '\uFCBF': '\u0641\u062D',
  13545. '\uFCC0': '\u0641\u062E',
  13546. '\uFCC1': '\u0641\u0645',
  13547. '\uFCC2': '\u0642\u062D',
  13548. '\uFCC3': '\u0642\u0645',
  13549. '\uFCC4': '\u0643\u062C',
  13550. '\uFCC5': '\u0643\u062D',
  13551. '\uFCC6': '\u0643\u062E',
  13552. '\uFCC7': '\u0643\u0644',
  13553. '\uFCC8': '\u0643\u0645',
  13554. '\uFCC9': '\u0644\u062C',
  13555. '\uFCCA': '\u0644\u062D',
  13556. '\uFCCB': '\u0644\u062E',
  13557. '\uFCCC': '\u0644\u0645',
  13558. '\uFCCD': '\u0644\u0647',
  13559. '\uFCCE': '\u0645\u062C',
  13560. '\uFCCF': '\u0645\u062D',
  13561. '\uFCD0': '\u0645\u062E',
  13562. '\uFCD1': '\u0645\u0645',
  13563. '\uFCD2': '\u0646\u062C',
  13564. '\uFCD3': '\u0646\u062D',
  13565. '\uFCD4': '\u0646\u062E',
  13566. '\uFCD5': '\u0646\u0645',
  13567. '\uFCD6': '\u0646\u0647',
  13568. '\uFCD7': '\u0647\u062C',
  13569. '\uFCD8': '\u0647\u0645',
  13570. '\uFCD9': '\u0647\u0670',
  13571. '\uFCDA': '\u064A\u062C',
  13572. '\uFCDB': '\u064A\u062D',
  13573. '\uFCDC': '\u064A\u062E',
  13574. '\uFCDD': '\u064A\u0645',
  13575. '\uFCDE': '\u064A\u0647',
  13576. '\uFCDF': '\u0626\u0645',
  13577. '\uFCE0': '\u0626\u0647',
  13578. '\uFCE1': '\u0628\u0645',
  13579. '\uFCE2': '\u0628\u0647',
  13580. '\uFCE3': '\u062A\u0645',
  13581. '\uFCE4': '\u062A\u0647',
  13582. '\uFCE5': '\u062B\u0645',
  13583. '\uFCE6': '\u062B\u0647',
  13584. '\uFCE7': '\u0633\u0645',
  13585. '\uFCE8': '\u0633\u0647',
  13586. '\uFCE9': '\u0634\u0645',
  13587. '\uFCEA': '\u0634\u0647',
  13588. '\uFCEB': '\u0643\u0644',
  13589. '\uFCEC': '\u0643\u0645',
  13590. '\uFCED': '\u0644\u0645',
  13591. '\uFCEE': '\u0646\u0645',
  13592. '\uFCEF': '\u0646\u0647',
  13593. '\uFCF0': '\u064A\u0645',
  13594. '\uFCF1': '\u064A\u0647',
  13595. '\uFCF2': '\u0640\u064E\u0651',
  13596. '\uFCF3': '\u0640\u064F\u0651',
  13597. '\uFCF4': '\u0640\u0650\u0651',
  13598. '\uFCF5': '\u0637\u0649',
  13599. '\uFCF6': '\u0637\u064A',
  13600. '\uFCF7': '\u0639\u0649',
  13601. '\uFCF8': '\u0639\u064A',
  13602. '\uFCF9': '\u063A\u0649',
  13603. '\uFCFA': '\u063A\u064A',
  13604. '\uFCFB': '\u0633\u0649',
  13605. '\uFCFC': '\u0633\u064A',
  13606. '\uFCFD': '\u0634\u0649',
  13607. '\uFCFE': '\u0634\u064A',
  13608. '\uFCFF': '\u062D\u0649',
  13609. '\uFD00': '\u062D\u064A',
  13610. '\uFD01': '\u062C\u0649',
  13611. '\uFD02': '\u062C\u064A',
  13612. '\uFD03': '\u062E\u0649',
  13613. '\uFD04': '\u062E\u064A',
  13614. '\uFD05': '\u0635\u0649',
  13615. '\uFD06': '\u0635\u064A',
  13616. '\uFD07': '\u0636\u0649',
  13617. '\uFD08': '\u0636\u064A',
  13618. '\uFD09': '\u0634\u062C',
  13619. '\uFD0A': '\u0634\u062D',
  13620. '\uFD0B': '\u0634\u062E',
  13621. '\uFD0C': '\u0634\u0645',
  13622. '\uFD0D': '\u0634\u0631',
  13623. '\uFD0E': '\u0633\u0631',
  13624. '\uFD0F': '\u0635\u0631',
  13625. '\uFD10': '\u0636\u0631',
  13626. '\uFD11': '\u0637\u0649',
  13627. '\uFD12': '\u0637\u064A',
  13628. '\uFD13': '\u0639\u0649',
  13629. '\uFD14': '\u0639\u064A',
  13630. '\uFD15': '\u063A\u0649',
  13631. '\uFD16': '\u063A\u064A',
  13632. '\uFD17': '\u0633\u0649',
  13633. '\uFD18': '\u0633\u064A',
  13634. '\uFD19': '\u0634\u0649',
  13635. '\uFD1A': '\u0634\u064A',
  13636. '\uFD1B': '\u062D\u0649',
  13637. '\uFD1C': '\u062D\u064A',
  13638. '\uFD1D': '\u062C\u0649',
  13639. '\uFD1E': '\u062C\u064A',
  13640. '\uFD1F': '\u062E\u0649',
  13641. '\uFD20': '\u062E\u064A',
  13642. '\uFD21': '\u0635\u0649',
  13643. '\uFD22': '\u0635\u064A',
  13644. '\uFD23': '\u0636\u0649',
  13645. '\uFD24': '\u0636\u064A',
  13646. '\uFD25': '\u0634\u062C',
  13647. '\uFD26': '\u0634\u062D',
  13648. '\uFD27': '\u0634\u062E',
  13649. '\uFD28': '\u0634\u0645',
  13650. '\uFD29': '\u0634\u0631',
  13651. '\uFD2A': '\u0633\u0631',
  13652. '\uFD2B': '\u0635\u0631',
  13653. '\uFD2C': '\u0636\u0631',
  13654. '\uFD2D': '\u0634\u062C',
  13655. '\uFD2E': '\u0634\u062D',
  13656. '\uFD2F': '\u0634\u062E',
  13657. '\uFD30': '\u0634\u0645',
  13658. '\uFD31': '\u0633\u0647',
  13659. '\uFD32': '\u0634\u0647',
  13660. '\uFD33': '\u0637\u0645',
  13661. '\uFD34': '\u0633\u062C',
  13662. '\uFD35': '\u0633\u062D',
  13663. '\uFD36': '\u0633\u062E',
  13664. '\uFD37': '\u0634\u062C',
  13665. '\uFD38': '\u0634\u062D',
  13666. '\uFD39': '\u0634\u062E',
  13667. '\uFD3A': '\u0637\u0645',
  13668. '\uFD3B': '\u0638\u0645',
  13669. '\uFD3C': '\u0627\u064B',
  13670. '\uFD3D': '\u0627\u064B',
  13671. '\uFD50': '\u062A\u062C\u0645',
  13672. '\uFD51': '\u062A\u062D\u062C',
  13673. '\uFD52': '\u062A\u062D\u062C',
  13674. '\uFD53': '\u062A\u062D\u0645',
  13675. '\uFD54': '\u062A\u062E\u0645',
  13676. '\uFD55': '\u062A\u0645\u062C',
  13677. '\uFD56': '\u062A\u0645\u062D',
  13678. '\uFD57': '\u062A\u0645\u062E',
  13679. '\uFD58': '\u062C\u0645\u062D',
  13680. '\uFD59': '\u062C\u0645\u062D',
  13681. '\uFD5A': '\u062D\u0645\u064A',
  13682. '\uFD5B': '\u062D\u0645\u0649',
  13683. '\uFD5C': '\u0633\u062D\u062C',
  13684. '\uFD5D': '\u0633\u062C\u062D',
  13685. '\uFD5E': '\u0633\u062C\u0649',
  13686. '\uFD5F': '\u0633\u0645\u062D',
  13687. '\uFD60': '\u0633\u0645\u062D',
  13688. '\uFD61': '\u0633\u0645\u062C',
  13689. '\uFD62': '\u0633\u0645\u0645',
  13690. '\uFD63': '\u0633\u0645\u0645',
  13691. '\uFD64': '\u0635\u062D\u062D',
  13692. '\uFD65': '\u0635\u062D\u062D',
  13693. '\uFD66': '\u0635\u0645\u0645',
  13694. '\uFD67': '\u0634\u062D\u0645',
  13695. '\uFD68': '\u0634\u062D\u0645',
  13696. '\uFD69': '\u0634\u062C\u064A',
  13697. '\uFD6A': '\u0634\u0645\u062E',
  13698. '\uFD6B': '\u0634\u0645\u062E',
  13699. '\uFD6C': '\u0634\u0645\u0645',
  13700. '\uFD6D': '\u0634\u0645\u0645',
  13701. '\uFD6E': '\u0636\u062D\u0649',
  13702. '\uFD6F': '\u0636\u062E\u0645',
  13703. '\uFD70': '\u0636\u062E\u0645',
  13704. '\uFD71': '\u0637\u0645\u062D',
  13705. '\uFD72': '\u0637\u0645\u062D',
  13706. '\uFD73': '\u0637\u0645\u0645',
  13707. '\uFD74': '\u0637\u0645\u064A',
  13708. '\uFD75': '\u0639\u062C\u0645',
  13709. '\uFD76': '\u0639\u0645\u0645',
  13710. '\uFD77': '\u0639\u0645\u0645',
  13711. '\uFD78': '\u0639\u0645\u0649',
  13712. '\uFD79': '\u063A\u0645\u0645',
  13713. '\uFD7A': '\u063A\u0645\u064A',
  13714. '\uFD7B': '\u063A\u0645\u0649',
  13715. '\uFD7C': '\u0641\u062E\u0645',
  13716. '\uFD7D': '\u0641\u062E\u0645',
  13717. '\uFD7E': '\u0642\u0645\u062D',
  13718. '\uFD7F': '\u0642\u0645\u0645',
  13719. '\uFD80': '\u0644\u062D\u0645',
  13720. '\uFD81': '\u0644\u062D\u064A',
  13721. '\uFD82': '\u0644\u062D\u0649',
  13722. '\uFD83': '\u0644\u062C\u062C',
  13723. '\uFD84': '\u0644\u062C\u062C',
  13724. '\uFD85': '\u0644\u062E\u0645',
  13725. '\uFD86': '\u0644\u062E\u0645',
  13726. '\uFD87': '\u0644\u0645\u062D',
  13727. '\uFD88': '\u0644\u0645\u062D',
  13728. '\uFD89': '\u0645\u062D\u062C',
  13729. '\uFD8A': '\u0645\u062D\u0645',
  13730. '\uFD8B': '\u0645\u062D\u064A',
  13731. '\uFD8C': '\u0645\u062C\u062D',
  13732. '\uFD8D': '\u0645\u062C\u0645',
  13733. '\uFD8E': '\u0645\u062E\u062C',
  13734. '\uFD8F': '\u0645\u062E\u0645',
  13735. '\uFD92': '\u0645\u062C\u062E',
  13736. '\uFD93': '\u0647\u0645\u062C',
  13737. '\uFD94': '\u0647\u0645\u0645',
  13738. '\uFD95': '\u0646\u062D\u0645',
  13739. '\uFD96': '\u0646\u062D\u0649',
  13740. '\uFD97': '\u0646\u062C\u0645',
  13741. '\uFD98': '\u0646\u062C\u0645',
  13742. '\uFD99': '\u0646\u062C\u0649',
  13743. '\uFD9A': '\u0646\u0645\u064A',
  13744. '\uFD9B': '\u0646\u0645\u0649',
  13745. '\uFD9C': '\u064A\u0645\u0645',
  13746. '\uFD9D': '\u064A\u0645\u0645',
  13747. '\uFD9E': '\u0628\u062E\u064A',
  13748. '\uFD9F': '\u062A\u062C\u064A',
  13749. '\uFDA0': '\u062A\u062C\u0649',
  13750. '\uFDA1': '\u062A\u062E\u064A',
  13751. '\uFDA2': '\u062A\u062E\u0649',
  13752. '\uFDA3': '\u062A\u0645\u064A',
  13753. '\uFDA4': '\u062A\u0645\u0649',
  13754. '\uFDA5': '\u062C\u0645\u064A',
  13755. '\uFDA6': '\u062C\u062D\u0649',
  13756. '\uFDA7': '\u062C\u0645\u0649',
  13757. '\uFDA8': '\u0633\u062E\u0649',
  13758. '\uFDA9': '\u0635\u062D\u064A',
  13759. '\uFDAA': '\u0634\u062D\u064A',
  13760. '\uFDAB': '\u0636\u062D\u064A',
  13761. '\uFDAC': '\u0644\u062C\u064A',
  13762. '\uFDAD': '\u0644\u0645\u064A',
  13763. '\uFDAE': '\u064A\u062D\u064A',
  13764. '\uFDAF': '\u064A\u062C\u064A',
  13765. '\uFDB0': '\u064A\u0645\u064A',
  13766. '\uFDB1': '\u0645\u0645\u064A',
  13767. '\uFDB2': '\u0642\u0645\u064A',
  13768. '\uFDB3': '\u0646\u062D\u064A',
  13769. '\uFDB4': '\u0642\u0645\u062D',
  13770. '\uFDB5': '\u0644\u062D\u0645',
  13771. '\uFDB6': '\u0639\u0645\u064A',
  13772. '\uFDB7': '\u0643\u0645\u064A',
  13773. '\uFDB8': '\u0646\u062C\u062D',
  13774. '\uFDB9': '\u0645\u062E\u064A',
  13775. '\uFDBA': '\u0644\u062C\u0645',
  13776. '\uFDBB': '\u0643\u0645\u0645',
  13777. '\uFDBC': '\u0644\u062C\u0645',
  13778. '\uFDBD': '\u0646\u062C\u062D',
  13779. '\uFDBE': '\u062C\u062D\u064A',
  13780. '\uFDBF': '\u062D\u062C\u064A',
  13781. '\uFDC0': '\u0645\u062C\u064A',
  13782. '\uFDC1': '\u0641\u0645\u064A',
  13783. '\uFDC2': '\u0628\u062D\u064A',
  13784. '\uFDC3': '\u0643\u0645\u0645',
  13785. '\uFDC4': '\u0639\u062C\u0645',
  13786. '\uFDC5': '\u0635\u0645\u0645',
  13787. '\uFDC6': '\u0633\u062E\u064A',
  13788. '\uFDC7': '\u0646\u062C\u064A',
  13789. '\uFE49': '\u203E',
  13790. '\uFE4A': '\u203E',
  13791. '\uFE4B': '\u203E',
  13792. '\uFE4C': '\u203E',
  13793. '\uFE4D': '\u005F',
  13794. '\uFE4E': '\u005F',
  13795. '\uFE4F': '\u005F',
  13796. '\uFE80': '\u0621',
  13797. '\uFE81': '\u0622',
  13798. '\uFE82': '\u0622',
  13799. '\uFE83': '\u0623',
  13800. '\uFE84': '\u0623',
  13801. '\uFE85': '\u0624',
  13802. '\uFE86': '\u0624',
  13803. '\uFE87': '\u0625',
  13804. '\uFE88': '\u0625',
  13805. '\uFE89': '\u0626',
  13806. '\uFE8A': '\u0626',
  13807. '\uFE8B': '\u0626',
  13808. '\uFE8C': '\u0626',
  13809. '\uFE8D': '\u0627',
  13810. '\uFE8E': '\u0627',
  13811. '\uFE8F': '\u0628',
  13812. '\uFE90': '\u0628',
  13813. '\uFE91': '\u0628',
  13814. '\uFE92': '\u0628',
  13815. '\uFE93': '\u0629',
  13816. '\uFE94': '\u0629',
  13817. '\uFE95': '\u062A',
  13818. '\uFE96': '\u062A',
  13819. '\uFE97': '\u062A',
  13820. '\uFE98': '\u062A',
  13821. '\uFE99': '\u062B',
  13822. '\uFE9A': '\u062B',
  13823. '\uFE9B': '\u062B',
  13824. '\uFE9C': '\u062B',
  13825. '\uFE9D': '\u062C',
  13826. '\uFE9E': '\u062C',
  13827. '\uFE9F': '\u062C',
  13828. '\uFEA0': '\u062C',
  13829. '\uFEA1': '\u062D',
  13830. '\uFEA2': '\u062D',
  13831. '\uFEA3': '\u062D',
  13832. '\uFEA4': '\u062D',
  13833. '\uFEA5': '\u062E',
  13834. '\uFEA6': '\u062E',
  13835. '\uFEA7': '\u062E',
  13836. '\uFEA8': '\u062E',
  13837. '\uFEA9': '\u062F',
  13838. '\uFEAA': '\u062F',
  13839. '\uFEAB': '\u0630',
  13840. '\uFEAC': '\u0630',
  13841. '\uFEAD': '\u0631',
  13842. '\uFEAE': '\u0631',
  13843. '\uFEAF': '\u0632',
  13844. '\uFEB0': '\u0632',
  13845. '\uFEB1': '\u0633',
  13846. '\uFEB2': '\u0633',
  13847. '\uFEB3': '\u0633',
  13848. '\uFEB4': '\u0633',
  13849. '\uFEB5': '\u0634',
  13850. '\uFEB6': '\u0634',
  13851. '\uFEB7': '\u0634',
  13852. '\uFEB8': '\u0634',
  13853. '\uFEB9': '\u0635',
  13854. '\uFEBA': '\u0635',
  13855. '\uFEBB': '\u0635',
  13856. '\uFEBC': '\u0635',
  13857. '\uFEBD': '\u0636',
  13858. '\uFEBE': '\u0636',
  13859. '\uFEBF': '\u0636',
  13860. '\uFEC0': '\u0636',
  13861. '\uFEC1': '\u0637',
  13862. '\uFEC2': '\u0637',
  13863. '\uFEC3': '\u0637',
  13864. '\uFEC4': '\u0637',
  13865. '\uFEC5': '\u0638',
  13866. '\uFEC6': '\u0638',
  13867. '\uFEC7': '\u0638',
  13868. '\uFEC8': '\u0638',
  13869. '\uFEC9': '\u0639',
  13870. '\uFECA': '\u0639',
  13871. '\uFECB': '\u0639',
  13872. '\uFECC': '\u0639',
  13873. '\uFECD': '\u063A',
  13874. '\uFECE': '\u063A',
  13875. '\uFECF': '\u063A',
  13876. '\uFED0': '\u063A',
  13877. '\uFED1': '\u0641',
  13878. '\uFED2': '\u0641',
  13879. '\uFED3': '\u0641',
  13880. '\uFED4': '\u0641',
  13881. '\uFED5': '\u0642',
  13882. '\uFED6': '\u0642',
  13883. '\uFED7': '\u0642',
  13884. '\uFED8': '\u0642',
  13885. '\uFED9': '\u0643',
  13886. '\uFEDA': '\u0643',
  13887. '\uFEDB': '\u0643',
  13888. '\uFEDC': '\u0643',
  13889. '\uFEDD': '\u0644',
  13890. '\uFEDE': '\u0644',
  13891. '\uFEDF': '\u0644',
  13892. '\uFEE0': '\u0644',
  13893. '\uFEE1': '\u0645',
  13894. '\uFEE2': '\u0645',
  13895. '\uFEE3': '\u0645',
  13896. '\uFEE4': '\u0645',
  13897. '\uFEE5': '\u0646',
  13898. '\uFEE6': '\u0646',
  13899. '\uFEE7': '\u0646',
  13900. '\uFEE8': '\u0646',
  13901. '\uFEE9': '\u0647',
  13902. '\uFEEA': '\u0647',
  13903. '\uFEEB': '\u0647',
  13904. '\uFEEC': '\u0647',
  13905. '\uFEED': '\u0648',
  13906. '\uFEEE': '\u0648',
  13907. '\uFEEF': '\u0649',
  13908. '\uFEF0': '\u0649',
  13909. '\uFEF1': '\u064A',
  13910. '\uFEF2': '\u064A',
  13911. '\uFEF3': '\u064A',
  13912. '\uFEF4': '\u064A',
  13913. '\uFEF5': '\u0644\u0622',
  13914. '\uFEF6': '\u0644\u0622',
  13915. '\uFEF7': '\u0644\u0623',
  13916. '\uFEF8': '\u0644\u0623',
  13917. '\uFEF9': '\u0644\u0625',
  13918. '\uFEFA': '\u0644\u0625',
  13919. '\uFEFB': '\u0644\u0627',
  13920. '\uFEFC': '\u0644\u0627'
  13921. };
  13922. function reverseIfRtl(chars) {
  13923. var charsLength = chars.length;
  13924. //reverse an arabic ligature
  13925. if (charsLength <= 1 || !isRTLRangeFor(chars.charCodeAt(0))) {
  13926. return chars;
  13927. }
  13928. var s = '';
  13929. for (var ii = charsLength - 1; ii >= 0; ii--) {
  13930. s += chars[ii];
  13931. }
  13932. return s;
  13933. }
  13934. function adjustWidths(properties) {
  13935. if (properties.fontMatrix[0] === FONT_IDENTITY_MATRIX[0]) {
  13936. return;
  13937. }
  13938. // adjusting width to fontMatrix scale
  13939. var scale = 0.001 / properties.fontMatrix[0];
  13940. var glyphsWidths = properties.widths;
  13941. for (var glyph in glyphsWidths) {
  13942. glyphsWidths[glyph] *= scale;
  13943. }
  13944. properties.defaultWidth *= scale;
  13945. }
  13946. function getFontType(type, subtype) {
  13947. switch (type) {
  13948. case 'Type1':
  13949. return subtype === 'Type1C' ? FontType.TYPE1C : FontType.TYPE1;
  13950. case 'CIDFontType0':
  13951. return subtype === 'CIDFontType0C' ? FontType.CIDFONTTYPE0C :
  13952. FontType.CIDFONTTYPE0;
  13953. case 'OpenType':
  13954. return FontType.OPENTYPE;
  13955. case 'TrueType':
  13956. return FontType.TRUETYPE;
  13957. case 'CIDFontType2':
  13958. return FontType.CIDFONTTYPE2;
  13959. case 'MMType1':
  13960. return FontType.MMTYPE1;
  13961. case 'Type0':
  13962. return FontType.TYPE0;
  13963. default:
  13964. return FontType.UNKNOWN;
  13965. }
  13966. }
  13967. var Glyph = (function GlyphClosure() {
  13968. function Glyph(fontChar, unicode, accent, width, vmetric, operatorListId) {
  13969. this.fontChar = fontChar;
  13970. this.unicode = unicode;
  13971. this.accent = accent;
  13972. this.width = width;
  13973. this.vmetric = vmetric;
  13974. this.operatorListId = operatorListId;
  13975. }
  13976. Glyph.prototype.matchesForCache =
  13977. function(fontChar, unicode, accent, width, vmetric, operatorListId) {
  13978. return this.fontChar === fontChar &&
  13979. this.unicode === unicode &&
  13980. this.accent === accent &&
  13981. this.width === width &&
  13982. this.vmetric === vmetric &&
  13983. this.operatorListId === operatorListId;
  13984. };
  13985. return Glyph;
  13986. })();
  13987. /**
  13988. * 'Font' is the class the outside world should use, it encapsulate all the font
  13989. * decoding logics whatever type it is (assuming the font type is supported).
  13990. *
  13991. * For example to read a Type1 font and to attach it to the document:
  13992. * var type1Font = new Font("MyFontName", binaryFile, propertiesObject);
  13993. * type1Font.bind();
  13994. */
  13995. var Font = (function FontClosure() {
  13996. function Font(name, file, properties) {
  13997. var charCode, glyphName;
  13998. this.name = name;
  13999. this.loadedName = properties.loadedName;
  14000. this.isType3Font = properties.isType3Font;
  14001. this.sizes = [];
  14002. this.glyphCache = {};
  14003. var names = name.split('+');
  14004. names = names.length > 1 ? names[1] : names[0];
  14005. names = names.split(/[-,_]/g)[0];
  14006. this.isSerifFont = !!(properties.flags & FontFlags.Serif);
  14007. this.isSymbolicFont = !!(properties.flags & FontFlags.Symbolic);
  14008. this.isMonospace = !!(properties.flags & FontFlags.FixedPitch);
  14009. var type = properties.type;
  14010. var subtype = properties.subtype;
  14011. this.type = type;
  14012. this.fallbackName = (this.isMonospace ? 'monospace' :
  14013. (this.isSerifFont ? 'serif' : 'sans-serif'));
  14014. this.differences = properties.differences;
  14015. this.widths = properties.widths;
  14016. this.defaultWidth = properties.defaultWidth;
  14017. this.composite = properties.composite;
  14018. this.wideChars = properties.wideChars;
  14019. this.cMap = properties.cMap;
  14020. this.ascent = properties.ascent / PDF_GLYPH_SPACE_UNITS;
  14021. this.descent = properties.descent / PDF_GLYPH_SPACE_UNITS;
  14022. this.fontMatrix = properties.fontMatrix;
  14023. var unicode = this.buildToUnicode(properties);
  14024. this.toUnicode = properties.toUnicode = unicode.toUnicode;
  14025. this.isIdentityUnicode = properties.isIdentityUnicode = unicode.isIdentity;
  14026. this.toFontChar = [];
  14027. if (properties.type == 'Type3') {
  14028. for (charCode = 0; charCode < 256; charCode++) {
  14029. this.toFontChar[charCode] = (this.differences[charCode] ||
  14030. properties.defaultEncoding[charCode]);
  14031. }
  14032. this.fontType = FontType.TYPE3;
  14033. return;
  14034. }
  14035. this.cidEncoding = properties.cidEncoding;
  14036. this.vertical = properties.vertical;
  14037. if (this.vertical) {
  14038. this.vmetrics = properties.vmetrics;
  14039. this.defaultVMetrics = properties.defaultVMetrics;
  14040. }
  14041. if (!file || file.isEmpty) {
  14042. if (file) {
  14043. // Some bad PDF generators will include empty font files,
  14044. // attempting to recover by assuming that no file exists.
  14045. warn('Font file is empty in "' + name + '" (' + this.loadedName + ')');
  14046. }
  14047. this.missingFile = true;
  14048. // The file data is not specified. Trying to fix the font name
  14049. // to be used with the canvas.font.
  14050. var fontName = name.replace(/[,_]/g, '-');
  14051. var isStandardFont = fontName in stdFontMap;
  14052. fontName = stdFontMap[fontName] || nonStdFontMap[fontName] || fontName;
  14053. this.bold = (fontName.search(/bold/gi) != -1);
  14054. this.italic = ((fontName.search(/oblique/gi) != -1) ||
  14055. (fontName.search(/italic/gi) != -1));
  14056. // Use 'name' instead of 'fontName' here because the original
  14057. // name ArialBlack for example will be replaced by Helvetica.
  14058. this.black = (name.search(/Black/g) != -1);
  14059. // if at least one width is present, remeasure all chars when exists
  14060. this.remeasure = Object.keys(this.widths).length > 0;
  14061. if (isStandardFont && type === 'CIDFontType2' &&
  14062. properties.cidEncoding.indexOf('Identity-') === 0) {
  14063. // Standard fonts might be embedded as CID font without glyph mapping.
  14064. // Building one based on GlyphMapForStandardFonts.
  14065. var map = [];
  14066. for (var code in GlyphMapForStandardFonts) {
  14067. map[+code] = GlyphMapForStandardFonts[code];
  14068. }
  14069. this.toFontChar = map;
  14070. this.toUnicode = map;
  14071. } else if (/Symbol/i.test(fontName)) {
  14072. var symbols = Encodings.SymbolSetEncoding;
  14073. for (charCode in symbols) {
  14074. var fontChar = GlyphsUnicode[symbols[charCode]];
  14075. if (!fontChar) {
  14076. continue;
  14077. }
  14078. this.toFontChar[charCode] = fontChar;
  14079. }
  14080. } else if (isStandardFont) {
  14081. this.toFontChar = [];
  14082. for (charCode in properties.defaultEncoding) {
  14083. glyphName = (properties.differences[charCode] ||
  14084. properties.defaultEncoding[charCode]);
  14085. this.toFontChar[charCode] = GlyphsUnicode[glyphName];
  14086. }
  14087. } else {
  14088. var unicodeCharCode, notCidFont = (type.indexOf('CIDFontType') === -1);
  14089. for (charCode in this.toUnicode) {
  14090. unicodeCharCode = this.toUnicode[charCode].charCodeAt(0);
  14091. if (notCidFont) {
  14092. glyphName = (properties.differences[charCode] ||
  14093. properties.defaultEncoding[charCode]);
  14094. unicodeCharCode = (GlyphsUnicode[glyphName] || unicodeCharCode);
  14095. }
  14096. this.toFontChar[charCode] = unicodeCharCode;
  14097. }
  14098. }
  14099. this.loadedName = fontName.split('-')[0];
  14100. this.loading = false;
  14101. this.fontType = getFontType(type, subtype);
  14102. return;
  14103. }
  14104. // Some fonts might use wrong font types for Type1C or CIDFontType0C
  14105. if (subtype == 'Type1C' && (type != 'Type1' && type != 'MMType1')) {
  14106. // Some TrueType fonts by mistake claim Type1C
  14107. if (isTrueTypeFile(file)) {
  14108. subtype = 'TrueType';
  14109. } else {
  14110. type = 'Type1';
  14111. }
  14112. }
  14113. if (subtype == 'CIDFontType0C' && type != 'CIDFontType0') {
  14114. type = 'CIDFontType0';
  14115. }
  14116. // XXX: Temporarily change the type for open type so we trigger a warning.
  14117. // This should be removed when we add support for open type.
  14118. if (subtype === 'OpenType') {
  14119. type = 'OpenType';
  14120. }
  14121. var data;
  14122. switch (type) {
  14123. case 'Type1':
  14124. case 'CIDFontType0':
  14125. this.mimetype = 'font/opentype';
  14126. var cff = (subtype === 'Type1C' || subtype === 'CIDFontType0C') ?
  14127. new CFFFont(file, properties) : new Type1Font(name, file, properties);
  14128. adjustWidths(properties);
  14129. // Wrap the CFF data inside an OTF font file
  14130. data = this.convert(name, cff, properties);
  14131. break;
  14132. case 'OpenType':
  14133. case 'TrueType':
  14134. case 'CIDFontType2':
  14135. this.mimetype = 'font/opentype';
  14136. // Repair the TrueType file. It is can be damaged in the point of
  14137. // view of the sanitizer
  14138. data = this.checkAndRepair(name, file, properties);
  14139. if (this.isOpenType) {
  14140. type = 'OpenType';
  14141. }
  14142. break;
  14143. default:
  14144. error('Font ' + type + ' is not supported');
  14145. break;
  14146. }
  14147. this.data = data;
  14148. this.fontType = getFontType(type, subtype);
  14149. // Transfer some properties again that could change during font conversion
  14150. this.fontMatrix = properties.fontMatrix;
  14151. this.widths = properties.widths;
  14152. this.defaultWidth = properties.defaultWidth;
  14153. this.encoding = properties.baseEncoding;
  14154. this.seacMap = properties.seacMap;
  14155. this.loading = true;
  14156. }
  14157. Font.getFontID = (function () {
  14158. var ID = 1;
  14159. return function Font_getFontID() {
  14160. return String(ID++);
  14161. };
  14162. })();
  14163. function int16(b0, b1) {
  14164. return (b0 << 8) + b1;
  14165. }
  14166. function int32(b0, b1, b2, b3) {
  14167. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  14168. }
  14169. function getMaxPower2(number) {
  14170. var maxPower = 0;
  14171. var value = number;
  14172. while (value >= 2) {
  14173. value /= 2;
  14174. maxPower++;
  14175. }
  14176. value = 2;
  14177. for (var i = 1; i < maxPower; i++) {
  14178. value *= 2;
  14179. }
  14180. return value;
  14181. }
  14182. function string16(value) {
  14183. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  14184. }
  14185. function safeString16(value) {
  14186. // clamp value to the 16-bit int range
  14187. value = (value > 0x7FFF ? 0x7FFF : (value < -0x8000 ? -0x8000 : value));
  14188. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  14189. }
  14190. function createOpenTypeHeader(sfnt, file, numTables) {
  14191. // Windows hates the Mac TrueType sfnt version number
  14192. if (sfnt == 'true') {
  14193. sfnt = string32(0x00010000);
  14194. }
  14195. // sfnt version (4 bytes)
  14196. var header = sfnt;
  14197. // numTables (2 bytes)
  14198. header += string16(numTables);
  14199. // searchRange (2 bytes)
  14200. var tablesMaxPower2 = getMaxPower2(numTables);
  14201. var searchRange = tablesMaxPower2 * 16;
  14202. header += string16(searchRange);
  14203. // entrySelector (2 bytes)
  14204. header += string16(Math.log(tablesMaxPower2) / Math.log(2));
  14205. // rangeShift (2 bytes)
  14206. header += string16(numTables * 16 - searchRange);
  14207. file.file += header;
  14208. file.virtualOffset += header.length;
  14209. }
  14210. function createTableEntry(file, tag, data) {
  14211. // offset
  14212. var offset = file.virtualOffset;
  14213. // length
  14214. var length = data.length;
  14215. // Per spec tables must be 4-bytes align so add padding as needed
  14216. while (data.length & 3) {
  14217. data.push(0x00);
  14218. }
  14219. while (file.virtualOffset & 3) {
  14220. file.virtualOffset++;
  14221. }
  14222. // checksum
  14223. var checksum = 0, n = data.length;
  14224. for (var i = 0; i < n; i += 4) {
  14225. checksum = (checksum + int32(data[i], data[i + 1], data[i + 2],
  14226. data[i + 3])) | 0;
  14227. }
  14228. var tableEntry = (tag + string32(checksum) +
  14229. string32(offset) + string32(length));
  14230. file.file += tableEntry;
  14231. file.virtualOffset += data.length;
  14232. }
  14233. function isTrueTypeFile(file) {
  14234. var header = file.peekBytes(4);
  14235. return readUint32(header, 0) === 0x00010000;
  14236. }
  14237. /**
  14238. * Rebuilds the char code to glyph ID map by trying to replace the char codes
  14239. * with their unicode value. It also moves char codes that are in known
  14240. * problematic locations.
  14241. * @return {Object} Two properties:
  14242. * 'toFontChar' - maps original char codes(the value that will be read
  14243. * from commands such as show text) to the char codes that will be used in the
  14244. * font that we build
  14245. * 'charCodeToGlyphId' - maps the new font char codes to glyph ids
  14246. */
  14247. function adjustMapping(charCodeToGlyphId, properties) {
  14248. var toUnicode = properties.toUnicode;
  14249. var isSymbolic = !!(properties.flags & FontFlags.Symbolic);
  14250. var isIdentityUnicode = properties.isIdentityUnicode;
  14251. var isCidFontType2 = (properties.type === 'CIDFontType2');
  14252. var newMap = Object.create(null);
  14253. var toFontChar = [];
  14254. var usedFontCharCodes = [];
  14255. var nextAvailableFontCharCode = PRIVATE_USE_OFFSET_START;
  14256. for (var originalCharCode in charCodeToGlyphId) {
  14257. originalCharCode |= 0;
  14258. var glyphId = charCodeToGlyphId[originalCharCode];
  14259. var fontCharCode = originalCharCode;
  14260. // First try to map the value to a unicode position if a non identity map
  14261. // was created.
  14262. if (!isIdentityUnicode) {
  14263. if (toUnicode[originalCharCode] !== undefined) {
  14264. var unicode = toUnicode[fontCharCode];
  14265. // TODO: Try to map ligatures to the correct spot.
  14266. if (unicode.length === 1) {
  14267. fontCharCode = unicode.charCodeAt(0);
  14268. }
  14269. } else if (isCidFontType2) {
  14270. // For CIDFontType2, move characters not present in toUnicode
  14271. // to the private use area (fixes bug 1028735 and issue 4881).
  14272. fontCharCode = nextAvailableFontCharCode;
  14273. }
  14274. }
  14275. // Try to move control characters, special characters and already mapped
  14276. // characters to the private use area since they will not be drawn by
  14277. // canvas if left in their current position. Also, move characters if the
  14278. // font was symbolic and there is only an identity unicode map since the
  14279. // characters probably aren't in the correct position (fixes an issue
  14280. // with firefox and thuluthfont).
  14281. if ((usedFontCharCodes[fontCharCode] !== undefined ||
  14282. fontCharCode <= 0x1f || // Control chars
  14283. fontCharCode === 0x7F || // Control char
  14284. fontCharCode === 0xAD || // Soft hyphen
  14285. (fontCharCode >= 0x80 && fontCharCode <= 0x9F) || // Control chars
  14286. // Prevent drawing characters in the specials unicode block.
  14287. (fontCharCode >= 0xFFF0 && fontCharCode <= 0xFFFF) ||
  14288. (isSymbolic && isIdentityUnicode)) &&
  14289. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END) { // Room left.
  14290. // Loop to try and find a free spot in the private use area.
  14291. do {
  14292. fontCharCode = nextAvailableFontCharCode++;
  14293. if (SKIP_PRIVATE_USE_RANGE_F000_TO_F01F && fontCharCode === 0xF000) {
  14294. fontCharCode = 0xF020;
  14295. nextAvailableFontCharCode = fontCharCode + 1;
  14296. }
  14297. } while (usedFontCharCodes[fontCharCode] !== undefined &&
  14298. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END);
  14299. }
  14300. newMap[fontCharCode] = glyphId;
  14301. toFontChar[originalCharCode] = fontCharCode;
  14302. usedFontCharCodes[fontCharCode] = true;
  14303. }
  14304. return {
  14305. toFontChar: toFontChar,
  14306. charCodeToGlyphId: newMap,
  14307. nextAvailableFontCharCode: nextAvailableFontCharCode
  14308. };
  14309. }
  14310. function getRanges(glyphs) {
  14311. // Array.sort() sorts by characters, not numerically, so convert to an
  14312. // array of characters.
  14313. var codes = [];
  14314. for (var charCode in glyphs) {
  14315. codes.push({ fontCharCode: charCode | 0, glyphId: glyphs[charCode] });
  14316. }
  14317. codes.sort(function fontGetRangesSort(a, b) {
  14318. return a.fontCharCode - b.fontCharCode;
  14319. });
  14320. // Split the sorted codes into ranges.
  14321. var ranges = [];
  14322. var length = codes.length;
  14323. for (var n = 0; n < length; ) {
  14324. var start = codes[n].fontCharCode;
  14325. var codeIndices = [codes[n].glyphId];
  14326. ++n;
  14327. var end = start;
  14328. while (n < length && end + 1 == codes[n].fontCharCode) {
  14329. codeIndices.push(codes[n].glyphId);
  14330. ++end;
  14331. ++n;
  14332. if (end === 0xFFFF) {
  14333. break;
  14334. }
  14335. }
  14336. ranges.push([start, end, codeIndices]);
  14337. }
  14338. return ranges;
  14339. }
  14340. function createCmapTable(glyphs) {
  14341. var ranges = getRanges(glyphs);
  14342. var numTables = ranges[ranges.length - 1][1] > 0xFFFF ? 2 : 1;
  14343. var cmap = '\x00\x00' + // version
  14344. string16(numTables) + // numTables
  14345. '\x00\x03' + // platformID
  14346. '\x00\x01' + // encodingID
  14347. string32(4 + numTables * 8); // start of the table record
  14348. var i, ii, j, jj;
  14349. for (i = ranges.length - 1; i >= 0; --i) {
  14350. if (ranges[i][0] <= 0xFFFF) { break; }
  14351. }
  14352. var bmpLength = i + 1;
  14353. if (ranges[i][0] < 0xFFFF && ranges[i][1] === 0xFFFF) {
  14354. ranges[i][1] = 0xFFFE;
  14355. }
  14356. var trailingRangesCount = ranges[i][1] < 0xFFFF ? 1 : 0;
  14357. var segCount = bmpLength + trailingRangesCount;
  14358. var segCount2 = segCount * 2;
  14359. var searchRange = getMaxPower2(segCount) * 2;
  14360. var searchEntry = Math.log(segCount) / Math.log(2);
  14361. var rangeShift = 2 * segCount - searchRange;
  14362. // Fill up the 4 parallel arrays describing the segments.
  14363. var startCount = '';
  14364. var endCount = '';
  14365. var idDeltas = '';
  14366. var idRangeOffsets = '';
  14367. var glyphsIds = '';
  14368. var bias = 0;
  14369. var range, start, end, codes;
  14370. for (i = 0, ii = bmpLength; i < ii; i++) {
  14371. range = ranges[i];
  14372. start = range[0];
  14373. end = range[1];
  14374. startCount += string16(start);
  14375. endCount += string16(end);
  14376. codes = range[2];
  14377. var contiguous = true;
  14378. for (j = 1, jj = codes.length; j < jj; ++j) {
  14379. if (codes[j] !== codes[j - 1] + 1) {
  14380. contiguous = false;
  14381. break;
  14382. }
  14383. }
  14384. if (!contiguous) {
  14385. var offset = (segCount - i) * 2 + bias * 2;
  14386. bias += (end - start + 1);
  14387. idDeltas += string16(0);
  14388. idRangeOffsets += string16(offset);
  14389. for (j = 0, jj = codes.length; j < jj; ++j) {
  14390. glyphsIds += string16(codes[j]);
  14391. }
  14392. } else {
  14393. var startCode = codes[0];
  14394. idDeltas += string16((startCode - start) & 0xFFFF);
  14395. idRangeOffsets += string16(0);
  14396. }
  14397. }
  14398. if (trailingRangesCount > 0) {
  14399. endCount += '\xFF\xFF';
  14400. startCount += '\xFF\xFF';
  14401. idDeltas += '\x00\x01';
  14402. idRangeOffsets += '\x00\x00';
  14403. }
  14404. var format314 = '\x00\x00' + // language
  14405. string16(segCount2) +
  14406. string16(searchRange) +
  14407. string16(searchEntry) +
  14408. string16(rangeShift) +
  14409. endCount + '\x00\x00' + startCount +
  14410. idDeltas + idRangeOffsets + glyphsIds;
  14411. var format31012 = '';
  14412. var header31012 = '';
  14413. if (numTables > 1) {
  14414. cmap += '\x00\x03' + // platformID
  14415. '\x00\x0A' + // encodingID
  14416. string32(4 + numTables * 8 +
  14417. 4 + format314.length); // start of the table record
  14418. format31012 = '';
  14419. for (i = 0, ii = ranges.length; i < ii; i++) {
  14420. range = ranges[i];
  14421. start = range[0];
  14422. codes = range[2];
  14423. var code = codes[0];
  14424. for (j = 1, jj = codes.length; j < jj; ++j) {
  14425. if (codes[j] !== codes[j - 1] + 1) {
  14426. end = range[0] + j - 1;
  14427. format31012 += string32(start) + // startCharCode
  14428. string32(end) + // endCharCode
  14429. string32(code); // startGlyphID
  14430. start = end + 1;
  14431. code = codes[j];
  14432. }
  14433. }
  14434. format31012 += string32(start) + // startCharCode
  14435. string32(range[1]) + // endCharCode
  14436. string32(code); // startGlyphID
  14437. }
  14438. header31012 = '\x00\x0C' + // format
  14439. '\x00\x00' + // reserved
  14440. string32(format31012.length + 16) + // length
  14441. '\x00\x00\x00\x00' + // language
  14442. string32(format31012.length / 12); // nGroups
  14443. }
  14444. return stringToArray(cmap +
  14445. '\x00\x04' + // format
  14446. string16(format314.length + 4) + // length
  14447. format314 + header31012 + format31012);
  14448. }
  14449. function validateOS2Table(os2) {
  14450. var stream = new Stream(os2.data);
  14451. var version = stream.getUint16();
  14452. // TODO verify all OS/2 tables fields, but currently we validate only those
  14453. // that give us issues
  14454. stream.getBytes(60); // skipping type, misc sizes, panose, unicode ranges
  14455. var selection = stream.getUint16();
  14456. if (version < 4 && (selection & 0x0300)) {
  14457. return false;
  14458. }
  14459. var firstChar = stream.getUint16();
  14460. var lastChar = stream.getUint16();
  14461. if (firstChar > lastChar) {
  14462. return false;
  14463. }
  14464. stream.getBytes(6); // skipping sTypoAscender/Descender/LineGap
  14465. var usWinAscent = stream.getUint16();
  14466. if (usWinAscent === 0) { // makes font unreadable by windows
  14467. return false;
  14468. }
  14469. // OS/2 appears to be valid, resetting some fields
  14470. os2.data[8] = os2.data[9] = 0; // IE rejects fonts if fsType != 0
  14471. return true;
  14472. }
  14473. function createOS2Table(properties, charstrings, override) {
  14474. override = override || {
  14475. unitsPerEm: 0,
  14476. yMax: 0,
  14477. yMin: 0,
  14478. ascent: 0,
  14479. descent: 0
  14480. };
  14481. var ulUnicodeRange1 = 0;
  14482. var ulUnicodeRange2 = 0;
  14483. var ulUnicodeRange3 = 0;
  14484. var ulUnicodeRange4 = 0;
  14485. var firstCharIndex = null;
  14486. var lastCharIndex = 0;
  14487. if (charstrings) {
  14488. for (var code in charstrings) {
  14489. code |= 0;
  14490. if (firstCharIndex > code || !firstCharIndex) {
  14491. firstCharIndex = code;
  14492. }
  14493. if (lastCharIndex < code) {
  14494. lastCharIndex = code;
  14495. }
  14496. var position = getUnicodeRangeFor(code);
  14497. if (position < 32) {
  14498. ulUnicodeRange1 |= 1 << position;
  14499. } else if (position < 64) {
  14500. ulUnicodeRange2 |= 1 << position - 32;
  14501. } else if (position < 96) {
  14502. ulUnicodeRange3 |= 1 << position - 64;
  14503. } else if (position < 123) {
  14504. ulUnicodeRange4 |= 1 << position - 96;
  14505. } else {
  14506. error('Unicode ranges Bits > 123 are reserved for internal usage');
  14507. }
  14508. }
  14509. } else {
  14510. // TODO
  14511. firstCharIndex = 0;
  14512. lastCharIndex = 255;
  14513. }
  14514. var bbox = properties.bbox || [0, 0, 0, 0];
  14515. var unitsPerEm = (override.unitsPerEm ||
  14516. 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0]);
  14517. // if the font units differ to the PDF glyph space units
  14518. // then scale up the values
  14519. var scale = (properties.ascentScaled ? 1.0 :
  14520. unitsPerEm / PDF_GLYPH_SPACE_UNITS);
  14521. var typoAscent = (override.ascent ||
  14522. Math.round(scale * (properties.ascent || bbox[3])));
  14523. var typoDescent = (override.descent ||
  14524. Math.round(scale * (properties.descent || bbox[1])));
  14525. if (typoDescent > 0 && properties.descent > 0 && bbox[1] < 0) {
  14526. typoDescent = -typoDescent; // fixing incorrect descent
  14527. }
  14528. var winAscent = override.yMax || typoAscent;
  14529. var winDescent = -override.yMin || -typoDescent;
  14530. return '\x00\x03' + // version
  14531. '\x02\x24' + // xAvgCharWidth
  14532. '\x01\xF4' + // usWeightClass
  14533. '\x00\x05' + // usWidthClass
  14534. '\x00\x00' + // fstype (0 to let the font loads via font-face on IE)
  14535. '\x02\x8A' + // ySubscriptXSize
  14536. '\x02\xBB' + // ySubscriptYSize
  14537. '\x00\x00' + // ySubscriptXOffset
  14538. '\x00\x8C' + // ySubscriptYOffset
  14539. '\x02\x8A' + // ySuperScriptXSize
  14540. '\x02\xBB' + // ySuperScriptYSize
  14541. '\x00\x00' + // ySuperScriptXOffset
  14542. '\x01\xDF' + // ySuperScriptYOffset
  14543. '\x00\x31' + // yStrikeOutSize
  14544. '\x01\x02' + // yStrikeOutPosition
  14545. '\x00\x00' + // sFamilyClass
  14546. '\x00\x00\x06' +
  14547. String.fromCharCode(properties.fixedPitch ? 0x09 : 0x00) +
  14548. '\x00\x00\x00\x00\x00\x00' + // Panose
  14549. string32(ulUnicodeRange1) + // ulUnicodeRange1 (Bits 0-31)
  14550. string32(ulUnicodeRange2) + // ulUnicodeRange2 (Bits 32-63)
  14551. string32(ulUnicodeRange3) + // ulUnicodeRange3 (Bits 64-95)
  14552. string32(ulUnicodeRange4) + // ulUnicodeRange4 (Bits 96-127)
  14553. '\x2A\x32\x31\x2A' + // achVendID
  14554. string16(properties.italicAngle ? 1 : 0) + // fsSelection
  14555. string16(firstCharIndex ||
  14556. properties.firstChar) + // usFirstCharIndex
  14557. string16(lastCharIndex || properties.lastChar) + // usLastCharIndex
  14558. string16(typoAscent) + // sTypoAscender
  14559. string16(typoDescent) + // sTypoDescender
  14560. '\x00\x64' + // sTypoLineGap (7%-10% of the unitsPerEM value)
  14561. string16(winAscent) + // usWinAscent
  14562. string16(winDescent) + // usWinDescent
  14563. '\x00\x00\x00\x00' + // ulCodePageRange1 (Bits 0-31)
  14564. '\x00\x00\x00\x00' + // ulCodePageRange2 (Bits 32-63)
  14565. string16(properties.xHeight) + // sxHeight
  14566. string16(properties.capHeight) + // sCapHeight
  14567. string16(0) + // usDefaultChar
  14568. string16(firstCharIndex || properties.firstChar) + // usBreakChar
  14569. '\x00\x03'; // usMaxContext
  14570. }
  14571. function createPostTable(properties) {
  14572. var angle = Math.floor(properties.italicAngle * (Math.pow(2, 16)));
  14573. return ('\x00\x03\x00\x00' + // Version number
  14574. string32(angle) + // italicAngle
  14575. '\x00\x00' + // underlinePosition
  14576. '\x00\x00' + // underlineThickness
  14577. string32(properties.fixedPitch) + // isFixedPitch
  14578. '\x00\x00\x00\x00' + // minMemType42
  14579. '\x00\x00\x00\x00' + // maxMemType42
  14580. '\x00\x00\x00\x00' + // minMemType1
  14581. '\x00\x00\x00\x00'); // maxMemType1
  14582. }
  14583. function createNameTable(name, proto) {
  14584. if (!proto) {
  14585. proto = [[], []]; // no strings and unicode strings
  14586. }
  14587. var strings = [
  14588. proto[0][0] || 'Original licence', // 0.Copyright
  14589. proto[0][1] || name, // 1.Font family
  14590. proto[0][2] || 'Unknown', // 2.Font subfamily (font weight)
  14591. proto[0][3] || 'uniqueID', // 3.Unique ID
  14592. proto[0][4] || name, // 4.Full font name
  14593. proto[0][5] || 'Version 0.11', // 5.Version
  14594. proto[0][6] || '', // 6.Postscript name
  14595. proto[0][7] || 'Unknown', // 7.Trademark
  14596. proto[0][8] || 'Unknown', // 8.Manufacturer
  14597. proto[0][9] || 'Unknown' // 9.Designer
  14598. ];
  14599. // Mac want 1-byte per character strings while Windows want
  14600. // 2-bytes per character, so duplicate the names table
  14601. var stringsUnicode = [];
  14602. var i, ii, j, jj, str;
  14603. for (i = 0, ii = strings.length; i < ii; i++) {
  14604. str = proto[1][i] || strings[i];
  14605. var strBufUnicode = [];
  14606. for (j = 0, jj = str.length; j < jj; j++) {
  14607. strBufUnicode.push(string16(str.charCodeAt(j)));
  14608. }
  14609. stringsUnicode.push(strBufUnicode.join(''));
  14610. }
  14611. var names = [strings, stringsUnicode];
  14612. var platforms = ['\x00\x01', '\x00\x03'];
  14613. var encodings = ['\x00\x00', '\x00\x01'];
  14614. var languages = ['\x00\x00', '\x04\x09'];
  14615. var namesRecordCount = strings.length * platforms.length;
  14616. var nameTable =
  14617. '\x00\x00' + // format
  14618. string16(namesRecordCount) + // Number of names Record
  14619. string16(namesRecordCount * 12 + 6); // Storage
  14620. // Build the name records field
  14621. var strOffset = 0;
  14622. for (i = 0, ii = platforms.length; i < ii; i++) {
  14623. var strs = names[i];
  14624. for (j = 0, jj = strs.length; j < jj; j++) {
  14625. str = strs[j];
  14626. var nameRecord =
  14627. platforms[i] + // platform ID
  14628. encodings[i] + // encoding ID
  14629. languages[i] + // language ID
  14630. string16(j) + // name ID
  14631. string16(str.length) +
  14632. string16(strOffset);
  14633. nameTable += nameRecord;
  14634. strOffset += str.length;
  14635. }
  14636. }
  14637. nameTable += strings.join('') + stringsUnicode.join('');
  14638. return nameTable;
  14639. }
  14640. Font.prototype = {
  14641. name: null,
  14642. font: null,
  14643. mimetype: null,
  14644. encoding: null,
  14645. get renderer() {
  14646. var renderer = FontRendererFactory.create(this);
  14647. return shadow(this, 'renderer', renderer);
  14648. },
  14649. exportData: function Font_exportData() {
  14650. var data = {};
  14651. for (var i in this) {
  14652. if (this.hasOwnProperty(i)) {
  14653. data[i] = this[i];
  14654. }
  14655. }
  14656. return data;
  14657. },
  14658. checkAndRepair: function Font_checkAndRepair(name, font, properties) {
  14659. function readTableEntry(file) {
  14660. var tag = bytesToString(file.getBytes(4));
  14661. var checksum = file.getInt32();
  14662. var offset = file.getInt32() >>> 0;
  14663. var length = file.getInt32() >>> 0;
  14664. // Read the table associated data
  14665. var previousPosition = file.pos;
  14666. file.pos = file.start ? file.start : 0;
  14667. file.skip(offset);
  14668. var data = file.getBytes(length);
  14669. file.pos = previousPosition;
  14670. if (tag == 'head') {
  14671. // clearing checksum adjustment
  14672. data[8] = data[9] = data[10] = data[11] = 0;
  14673. data[17] |= 0x20; //Set font optimized for cleartype flag
  14674. }
  14675. return {
  14676. tag: tag,
  14677. checksum: checksum,
  14678. length: length,
  14679. offset: offset,
  14680. data: data
  14681. };
  14682. }
  14683. function readOpenTypeHeader(ttf) {
  14684. return {
  14685. version: bytesToString(ttf.getBytes(4)),
  14686. numTables: ttf.getUint16(),
  14687. searchRange: ttf.getUint16(),
  14688. entrySelector: ttf.getUint16(),
  14689. rangeShift: ttf.getUint16()
  14690. };
  14691. }
  14692. /**
  14693. * Read the appropriate subtable from the cmap according to 9.6.6.4 from
  14694. * PDF spec
  14695. */
  14696. function readCmapTable(cmap, font, isSymbolicFont) {
  14697. var segment;
  14698. var start = (font.start ? font.start : 0) + cmap.offset;
  14699. font.pos = start;
  14700. var version = font.getUint16();
  14701. var numTables = font.getUint16();
  14702. var potentialTable;
  14703. var canBreak = false;
  14704. // There's an order of preference in terms of which cmap subtable to
  14705. // use:
  14706. // - non-symbolic fonts the preference is a 3,1 table then a 1,0 table
  14707. // - symbolic fonts the preference is a 3,0 table then a 1,0 table
  14708. // The following takes advantage of the fact that the tables are sorted
  14709. // to work.
  14710. for (var i = 0; i < numTables; i++) {
  14711. var platformId = font.getUint16();
  14712. var encodingId = font.getUint16();
  14713. var offset = font.getInt32() >>> 0;
  14714. var useTable = false;
  14715. if (platformId == 1 && encodingId === 0) {
  14716. useTable = true;
  14717. // Continue the loop since there still may be a higher priority
  14718. // table.
  14719. } else if (!isSymbolicFont && platformId === 3 && encodingId === 1) {
  14720. useTable = true;
  14721. canBreak = true;
  14722. } else if (isSymbolicFont && platformId === 3 && encodingId === 0) {
  14723. useTable = true;
  14724. canBreak = true;
  14725. }
  14726. if (useTable) {
  14727. potentialTable = {
  14728. platformId: platformId,
  14729. encodingId: encodingId,
  14730. offset: offset
  14731. };
  14732. }
  14733. if (canBreak) {
  14734. break;
  14735. }
  14736. }
  14737. if (!potentialTable) {
  14738. warn('Could not find a preferred cmap table.');
  14739. return {
  14740. platformId: -1,
  14741. encodingId: -1,
  14742. mappings: [],
  14743. hasShortCmap: false
  14744. };
  14745. }
  14746. font.pos = start + potentialTable.offset;
  14747. var format = font.getUint16();
  14748. var length = font.getUint16();
  14749. var language = font.getUint16();
  14750. var hasShortCmap = false;
  14751. var mappings = [];
  14752. var j, glyphId;
  14753. // TODO(mack): refactor this cmap subtable reading logic out
  14754. if (format === 0) {
  14755. for (j = 0; j < 256; j++) {
  14756. var index = font.getByte();
  14757. if (!index) {
  14758. continue;
  14759. }
  14760. mappings.push({
  14761. charCode: j,
  14762. glyphId: index
  14763. });
  14764. }
  14765. hasShortCmap = true;
  14766. } else if (format === 4) {
  14767. // re-creating the table in format 4 since the encoding
  14768. // might be changed
  14769. var segCount = (font.getUint16() >> 1);
  14770. font.getBytes(6); // skipping range fields
  14771. var segIndex, segments = [];
  14772. for (segIndex = 0; segIndex < segCount; segIndex++) {
  14773. segments.push({ end: font.getUint16() });
  14774. }
  14775. font.getUint16();
  14776. for (segIndex = 0; segIndex < segCount; segIndex++) {
  14777. segments[segIndex].start = font.getUint16();
  14778. }
  14779. for (segIndex = 0; segIndex < segCount; segIndex++) {
  14780. segments[segIndex].delta = font.getUint16();
  14781. }
  14782. var offsetsCount = 0;
  14783. for (segIndex = 0; segIndex < segCount; segIndex++) {
  14784. segment = segments[segIndex];
  14785. var rangeOffset = font.getUint16();
  14786. if (!rangeOffset) {
  14787. segment.offsetIndex = -1;
  14788. continue;
  14789. }
  14790. var offsetIndex = (rangeOffset >> 1) - (segCount - segIndex);
  14791. segment.offsetIndex = offsetIndex;
  14792. offsetsCount = Math.max(offsetsCount, offsetIndex +
  14793. segment.end - segment.start + 1);
  14794. }
  14795. var offsets = [];
  14796. for (j = 0; j < offsetsCount; j++) {
  14797. offsets.push(font.getUint16());
  14798. }
  14799. for (segIndex = 0; segIndex < segCount; segIndex++) {
  14800. segment = segments[segIndex];
  14801. start = segment.start;
  14802. var end = segment.end;
  14803. var delta = segment.delta;
  14804. offsetIndex = segment.offsetIndex;
  14805. for (j = start; j <= end; j++) {
  14806. if (j == 0xFFFF) {
  14807. continue;
  14808. }
  14809. glyphId = (offsetIndex < 0 ?
  14810. j : offsets[offsetIndex + j - start]);
  14811. glyphId = (glyphId + delta) & 0xFFFF;
  14812. if (glyphId === 0) {
  14813. continue;
  14814. }
  14815. mappings.push({
  14816. charCode: j,
  14817. glyphId: glyphId
  14818. });
  14819. }
  14820. }
  14821. } else if (format == 6) {
  14822. // Format 6 is a 2-bytes dense mapping, which means the font data
  14823. // lives glue together even if they are pretty far in the unicode
  14824. // table. (This looks weird, so I can have missed something), this
  14825. // works on Linux but seems to fails on Mac so let's rewrite the
  14826. // cmap table to a 3-1-4 style
  14827. var firstCode = font.getUint16();
  14828. var entryCount = font.getUint16();
  14829. for (j = 0; j < entryCount; j++) {
  14830. glyphId = font.getUint16();
  14831. var charCode = firstCode + j;
  14832. mappings.push({
  14833. charCode: charCode,
  14834. glyphId: glyphId
  14835. });
  14836. }
  14837. } else {
  14838. error('cmap table has unsupported format: ' + format);
  14839. }
  14840. // removing duplicate entries
  14841. mappings.sort(function (a, b) {
  14842. return a.charCode - b.charCode;
  14843. });
  14844. for (i = 1; i < mappings.length; i++) {
  14845. if (mappings[i - 1].charCode === mappings[i].charCode) {
  14846. mappings.splice(i, 1);
  14847. i--;
  14848. }
  14849. }
  14850. return {
  14851. platformId: potentialTable.platformId,
  14852. encodingId: potentialTable.encodingId,
  14853. mappings: mappings,
  14854. hasShortCmap: hasShortCmap
  14855. };
  14856. }
  14857. function sanitizeMetrics(font, header, metrics, numGlyphs) {
  14858. if (!header) {
  14859. if (metrics) {
  14860. metrics.data = null;
  14861. }
  14862. return;
  14863. }
  14864. font.pos = (font.start ? font.start : 0) + header.offset;
  14865. font.pos += header.length - 2;
  14866. var numOfMetrics = font.getUint16();
  14867. if (numOfMetrics > numGlyphs) {
  14868. info('The numOfMetrics (' + numOfMetrics + ') should not be ' +
  14869. 'greater than the numGlyphs (' + numGlyphs + ')');
  14870. // Reduce numOfMetrics if it is greater than numGlyphs
  14871. numOfMetrics = numGlyphs;
  14872. header.data[34] = (numOfMetrics & 0xff00) >> 8;
  14873. header.data[35] = numOfMetrics & 0x00ff;
  14874. }
  14875. var numOfSidebearings = numGlyphs - numOfMetrics;
  14876. var numMissing = numOfSidebearings -
  14877. ((metrics.length - numOfMetrics * 4) >> 1);
  14878. var i, ii;
  14879. if (numMissing > 0) {
  14880. font.pos = (font.start ? font.start : 0) + metrics.offset;
  14881. var entries = '';
  14882. for (i = 0, ii = metrics.length; i < ii; i++) {
  14883. entries += String.fromCharCode(font.getByte());
  14884. }
  14885. for (i = 0; i < numMissing; i++) {
  14886. entries += '\x00\x00';
  14887. }
  14888. metrics.data = stringToArray(entries);
  14889. }
  14890. }
  14891. function sanitizeGlyph(source, sourceStart, sourceEnd, dest, destStart,
  14892. hintsValid) {
  14893. if (sourceEnd - sourceStart <= 12) {
  14894. // glyph with data less than 12 is invalid one
  14895. return 0;
  14896. }
  14897. var glyf = source.subarray(sourceStart, sourceEnd);
  14898. var contoursCount = (glyf[0] << 8) | glyf[1];
  14899. if (contoursCount & 0x8000) {
  14900. // complex glyph, writing as is
  14901. dest.set(glyf, destStart);
  14902. return glyf.length;
  14903. }
  14904. var i, j = 10, flagsCount = 0;
  14905. for (i = 0; i < contoursCount; i++) {
  14906. var endPoint = (glyf[j] << 8) | glyf[j + 1];
  14907. flagsCount = endPoint + 1;
  14908. j += 2;
  14909. }
  14910. // skipping instructions
  14911. var instructionsStart = j;
  14912. var instructionsLength = (glyf[j] << 8) | glyf[j + 1];
  14913. j += 2 + instructionsLength;
  14914. var instructionsEnd = j;
  14915. // validating flags
  14916. var coordinatesLength = 0;
  14917. for (i = 0; i < flagsCount; i++) {
  14918. var flag = glyf[j++];
  14919. if (flag & 0xC0) {
  14920. // reserved flags must be zero, cleaning up
  14921. glyf[j - 1] = flag & 0x3F;
  14922. }
  14923. var xyLength = ((flag & 2) ? 1 : (flag & 16) ? 0 : 2) +
  14924. ((flag & 4) ? 1 : (flag & 32) ? 0 : 2);
  14925. coordinatesLength += xyLength;
  14926. if (flag & 8) {
  14927. var repeat = glyf[j++];
  14928. i += repeat;
  14929. coordinatesLength += repeat * xyLength;
  14930. }
  14931. }
  14932. // glyph without coordinates will be rejected
  14933. if (coordinatesLength === 0) {
  14934. return 0;
  14935. }
  14936. var glyphDataLength = j + coordinatesLength;
  14937. if (glyphDataLength > glyf.length) {
  14938. // not enough data for coordinates
  14939. return 0;
  14940. }
  14941. if (!hintsValid && instructionsLength > 0) {
  14942. dest.set(glyf.subarray(0, instructionsStart), destStart);
  14943. dest.set([0, 0], destStart + instructionsStart);
  14944. dest.set(glyf.subarray(instructionsEnd, glyphDataLength),
  14945. destStart + instructionsStart + 2);
  14946. glyphDataLength -= instructionsLength;
  14947. if (glyf.length - glyphDataLength > 3) {
  14948. glyphDataLength = (glyphDataLength + 3) & ~3;
  14949. }
  14950. return glyphDataLength;
  14951. }
  14952. if (glyf.length - glyphDataLength > 3) {
  14953. // truncating and aligning to 4 bytes the long glyph data
  14954. glyphDataLength = (glyphDataLength + 3) & ~3;
  14955. dest.set(glyf.subarray(0, glyphDataLength), destStart);
  14956. return glyphDataLength;
  14957. }
  14958. // glyph data is fine
  14959. dest.set(glyf, destStart);
  14960. return glyf.length;
  14961. }
  14962. function sanitizeHead(head, numGlyphs, locaLength) {
  14963. var data = head.data;
  14964. // Validate version:
  14965. // Should always be 0x00010000
  14966. var version = int32(data[0], data[1], data[2], data[3]);
  14967. if (version >> 16 !== 1) {
  14968. info('Attempting to fix invalid version in head table: ' + version);
  14969. data[0] = 0;
  14970. data[1] = 1;
  14971. data[2] = 0;
  14972. data[3] = 0;
  14973. }
  14974. var indexToLocFormat = int16(data[50], data[51]);
  14975. if (indexToLocFormat < 0 || indexToLocFormat > 1) {
  14976. info('Attempting to fix invalid indexToLocFormat in head table: ' +
  14977. indexToLocFormat);
  14978. // The value of indexToLocFormat should be 0 if the loca table
  14979. // consists of short offsets, and should be 1 if the loca table
  14980. // consists of long offsets.
  14981. //
  14982. // The number of entries in the loca table should be numGlyphs + 1.
  14983. //
  14984. // Using this information, we can work backwards to deduce if the
  14985. // size of each offset in the loca table, and thus figure out the
  14986. // appropriate value for indexToLocFormat.
  14987. var numGlyphsPlusOne = numGlyphs + 1;
  14988. if (locaLength === numGlyphsPlusOne << 1) {
  14989. // 0x0000 indicates the loca table consists of short offsets
  14990. data[50] = 0;
  14991. data[51] = 0;
  14992. } else if (locaLength === numGlyphsPlusOne << 2) {
  14993. // 0x0001 indicates the loca table consists of long offsets
  14994. data[50] = 0;
  14995. data[51] = 1;
  14996. } else {
  14997. warn('Could not fix indexToLocFormat: ' + indexToLocFormat);
  14998. }
  14999. }
  15000. }
  15001. function sanitizeGlyphLocations(loca, glyf, numGlyphs,
  15002. isGlyphLocationsLong, hintsValid,
  15003. dupFirstEntry) {
  15004. var itemSize, itemDecode, itemEncode;
  15005. if (isGlyphLocationsLong) {
  15006. itemSize = 4;
  15007. itemDecode = function fontItemDecodeLong(data, offset) {
  15008. return (data[offset] << 24) | (data[offset + 1] << 16) |
  15009. (data[offset + 2] << 8) | data[offset + 3];
  15010. };
  15011. itemEncode = function fontItemEncodeLong(data, offset, value) {
  15012. data[offset] = (value >>> 24) & 0xFF;
  15013. data[offset + 1] = (value >> 16) & 0xFF;
  15014. data[offset + 2] = (value >> 8) & 0xFF;
  15015. data[offset + 3] = value & 0xFF;
  15016. };
  15017. } else {
  15018. itemSize = 2;
  15019. itemDecode = function fontItemDecode(data, offset) {
  15020. return (data[offset] << 9) | (data[offset + 1] << 1);
  15021. };
  15022. itemEncode = function fontItemEncode(data, offset, value) {
  15023. data[offset] = (value >> 9) & 0xFF;
  15024. data[offset + 1] = (value >> 1) & 0xFF;
  15025. };
  15026. }
  15027. var locaData = loca.data;
  15028. var locaDataSize = itemSize * (1 + numGlyphs);
  15029. // is loca.data too short or long?
  15030. if (locaData.length !== locaDataSize) {
  15031. locaData = new Uint8Array(locaDataSize);
  15032. locaData.set(loca.data.subarray(0, locaDataSize));
  15033. loca.data = locaData;
  15034. }
  15035. // removing the invalid glyphs
  15036. var oldGlyfData = glyf.data;
  15037. var oldGlyfDataLength = oldGlyfData.length;
  15038. var newGlyfData = new Uint8Array(oldGlyfDataLength);
  15039. var startOffset = itemDecode(locaData, 0);
  15040. var writeOffset = 0;
  15041. itemEncode(locaData, 0, writeOffset);
  15042. var i, j;
  15043. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  15044. var endOffset = itemDecode(locaData, j);
  15045. if (endOffset > oldGlyfDataLength &&
  15046. ((oldGlyfDataLength + 3) & ~3) === endOffset) {
  15047. // Aspose breaks fonts by aligning the glyphs to the qword, but not
  15048. // the glyf table size, which makes last glyph out of range.
  15049. endOffset = oldGlyfDataLength;
  15050. }
  15051. if (endOffset > oldGlyfDataLength) {
  15052. // glyph end offset points outside glyf data, rejecting the glyph
  15053. itemEncode(locaData, j, writeOffset);
  15054. startOffset = endOffset;
  15055. continue;
  15056. }
  15057. var newLength = sanitizeGlyph(oldGlyfData, startOffset, endOffset,
  15058. newGlyfData, writeOffset, hintsValid);
  15059. writeOffset += newLength;
  15060. itemEncode(locaData, j, writeOffset);
  15061. startOffset = endOffset;
  15062. }
  15063. if (writeOffset === 0) {
  15064. // glyf table cannot be empty -- redoing the glyf and loca tables
  15065. // to have single glyph with one point
  15066. var simpleGlyph = new Uint8Array(
  15067. [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 49, 0]);
  15068. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  15069. itemEncode(locaData, j, simpleGlyph.length);
  15070. }
  15071. glyf.data = simpleGlyph;
  15072. return;
  15073. }
  15074. if (dupFirstEntry) {
  15075. var firstEntryLength = itemDecode(locaData, itemSize);
  15076. if (newGlyfData.length > firstEntryLength + writeOffset) {
  15077. glyf.data = newGlyfData.subarray(0, firstEntryLength + writeOffset);
  15078. } else {
  15079. glyf.data = new Uint8Array(firstEntryLength + writeOffset);
  15080. glyf.data.set(newGlyfData.subarray(0, writeOffset));
  15081. }
  15082. glyf.data.set(newGlyfData.subarray(0, firstEntryLength), writeOffset);
  15083. itemEncode(loca.data, locaData.length - itemSize,
  15084. writeOffset + firstEntryLength);
  15085. } else {
  15086. glyf.data = newGlyfData.subarray(0, writeOffset);
  15087. }
  15088. }
  15089. function readPostScriptTable(post, properties, maxpNumGlyphs) {
  15090. var start = (font.start ? font.start : 0) + post.offset;
  15091. font.pos = start;
  15092. var length = post.length, end = start + length;
  15093. var version = font.getInt32();
  15094. // skip rest to the tables
  15095. font.getBytes(28);
  15096. var glyphNames;
  15097. var valid = true;
  15098. var i;
  15099. switch (version) {
  15100. case 0x00010000:
  15101. glyphNames = MacStandardGlyphOrdering;
  15102. break;
  15103. case 0x00020000:
  15104. var numGlyphs = font.getUint16();
  15105. if (numGlyphs != maxpNumGlyphs) {
  15106. valid = false;
  15107. break;
  15108. }
  15109. var glyphNameIndexes = [];
  15110. for (i = 0; i < numGlyphs; ++i) {
  15111. var index = font.getUint16();
  15112. if (index >= 32768) {
  15113. valid = false;
  15114. break;
  15115. }
  15116. glyphNameIndexes.push(index);
  15117. }
  15118. if (!valid) {
  15119. break;
  15120. }
  15121. var customNames = [];
  15122. var strBuf = [];
  15123. while (font.pos < end) {
  15124. var stringLength = font.getByte();
  15125. strBuf.length = stringLength;
  15126. for (i = 0; i < stringLength; ++i) {
  15127. strBuf[i] = String.fromCharCode(font.getByte());
  15128. }
  15129. customNames.push(strBuf.join(''));
  15130. }
  15131. glyphNames = [];
  15132. for (i = 0; i < numGlyphs; ++i) {
  15133. var j = glyphNameIndexes[i];
  15134. if (j < 258) {
  15135. glyphNames.push(MacStandardGlyphOrdering[j]);
  15136. continue;
  15137. }
  15138. glyphNames.push(customNames[j - 258]);
  15139. }
  15140. break;
  15141. case 0x00030000:
  15142. break;
  15143. default:
  15144. warn('Unknown/unsupported post table version ' + version);
  15145. valid = false;
  15146. break;
  15147. }
  15148. properties.glyphNames = glyphNames;
  15149. return valid;
  15150. }
  15151. function readNameTable(nameTable) {
  15152. var start = (font.start ? font.start : 0) + nameTable.offset;
  15153. font.pos = start;
  15154. var names = [[], []];
  15155. var length = nameTable.length, end = start + length;
  15156. var format = font.getUint16();
  15157. var FORMAT_0_HEADER_LENGTH = 6;
  15158. if (format !== 0 || length < FORMAT_0_HEADER_LENGTH) {
  15159. // unsupported name table format or table "too" small
  15160. return names;
  15161. }
  15162. var numRecords = font.getUint16();
  15163. var stringsStart = font.getUint16();
  15164. var records = [];
  15165. var NAME_RECORD_LENGTH = 12;
  15166. var i, ii;
  15167. for (i = 0; i < numRecords &&
  15168. font.pos + NAME_RECORD_LENGTH <= end; i++) {
  15169. var r = {
  15170. platform: font.getUint16(),
  15171. encoding: font.getUint16(),
  15172. language: font.getUint16(),
  15173. name: font.getUint16(),
  15174. length: font.getUint16(),
  15175. offset: font.getUint16()
  15176. };
  15177. // using only Macintosh and Windows platform/encoding names
  15178. if ((r.platform == 1 && r.encoding === 0 && r.language === 0) ||
  15179. (r.platform == 3 && r.encoding == 1 && r.language == 0x409)) {
  15180. records.push(r);
  15181. }
  15182. }
  15183. for (i = 0, ii = records.length; i < ii; i++) {
  15184. var record = records[i];
  15185. var pos = start + stringsStart + record.offset;
  15186. if (pos + record.length > end) {
  15187. continue; // outside of name table, ignoring
  15188. }
  15189. font.pos = pos;
  15190. var nameIndex = record.name;
  15191. if (record.encoding) {
  15192. // unicode
  15193. var str = '';
  15194. for (var j = 0, jj = record.length; j < jj; j += 2) {
  15195. str += String.fromCharCode(font.getUint16());
  15196. }
  15197. names[1][nameIndex] = str;
  15198. } else {
  15199. names[0][nameIndex] = bytesToString(font.getBytes(record.length));
  15200. }
  15201. }
  15202. return names;
  15203. }
  15204. var TTOpsStackDeltas = [
  15205. 0, 0, 0, 0, 0, 0, 0, 0, -2, -2, -2, -2, 0, 0, -2, -5,
  15206. -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, -1, -1,
  15207. 1, -1, -999, 0, 1, 0, -1, -2, 0, -1, -2, -1, -1, 0, -1, -1,
  15208. 0, 0, -999, -999, -1, -1, -1, -1, -2, -999, -2, -2, -999, 0, -2, -2,
  15209. 0, 0, -2, 0, -2, 0, 0, 0, -2, -1, -1, 1, 1, 0, 0, -1,
  15210. -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, 0, -999, -1, -1,
  15211. -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  15212. -2, -999, -999, -999, -999, -999, -1, -1, -2, -2, 0, 0, 0, 0, -1, -1,
  15213. -999, -2, -2, 0, 0, -1, -2, -2, 0, 0, 0, -1, -1, -1, -2];
  15214. // 0xC0-DF == -1 and 0xE0-FF == -2
  15215. function sanitizeTTProgram(table, ttContext) {
  15216. var data = table.data;
  15217. var i = 0, j, n, b, funcId, pc, lastEndf = 0, lastDeff = 0;
  15218. var stack = [];
  15219. var callstack = [];
  15220. var functionsCalled = [];
  15221. var tooComplexToFollowFunctions =
  15222. ttContext.tooComplexToFollowFunctions;
  15223. var inFDEF = false, ifLevel = 0, inELSE = 0;
  15224. for (var ii = data.length; i < ii;) {
  15225. var op = data[i++];
  15226. // The TrueType instruction set docs can be found at
  15227. // https://developer.apple.com/fonts/TTRefMan/RM05/Chap5.html
  15228. if (op === 0x40) { // NPUSHB - pushes n bytes
  15229. n = data[i++];
  15230. if (inFDEF || inELSE) {
  15231. i += n;
  15232. } else {
  15233. for (j = 0; j < n; j++) {
  15234. stack.push(data[i++]);
  15235. }
  15236. }
  15237. } else if (op === 0x41) { // NPUSHW - pushes n words
  15238. n = data[i++];
  15239. if (inFDEF || inELSE) {
  15240. i += n * 2;
  15241. } else {
  15242. for (j = 0; j < n; j++) {
  15243. b = data[i++];
  15244. stack.push((b << 8) | data[i++]);
  15245. }
  15246. }
  15247. } else if ((op & 0xF8) === 0xB0) { // PUSHB - pushes bytes
  15248. n = op - 0xB0 + 1;
  15249. if (inFDEF || inELSE) {
  15250. i += n;
  15251. } else {
  15252. for (j = 0; j < n; j++) {
  15253. stack.push(data[i++]);
  15254. }
  15255. }
  15256. } else if ((op & 0xF8) === 0xB8) { // PUSHW - pushes words
  15257. n = op - 0xB8 + 1;
  15258. if (inFDEF || inELSE) {
  15259. i += n * 2;
  15260. } else {
  15261. for (j = 0; j < n; j++) {
  15262. b = data[i++];
  15263. stack.push((b << 8) | data[i++]);
  15264. }
  15265. }
  15266. } else if (op === 0x2B && !tooComplexToFollowFunctions) { // CALL
  15267. if (!inFDEF && !inELSE) {
  15268. // collecting inforamtion about which functions are used
  15269. funcId = stack[stack.length - 1];
  15270. ttContext.functionsUsed[funcId] = true;
  15271. if (funcId in ttContext.functionsStackDeltas) {
  15272. stack.length += ttContext.functionsStackDeltas[funcId];
  15273. } else if (funcId in ttContext.functionsDefined &&
  15274. functionsCalled.indexOf(funcId) < 0) {
  15275. callstack.push({data: data, i: i, stackTop: stack.length - 1});
  15276. functionsCalled.push(funcId);
  15277. pc = ttContext.functionsDefined[funcId];
  15278. if (!pc) {
  15279. warn('TT: CALL non-existent function');
  15280. ttContext.hintsValid = false;
  15281. return;
  15282. }
  15283. data = pc.data;
  15284. i = pc.i;
  15285. }
  15286. }
  15287. } else if (op === 0x2C && !tooComplexToFollowFunctions) { // FDEF
  15288. if (inFDEF || inELSE) {
  15289. warn('TT: nested FDEFs not allowed');
  15290. tooComplexToFollowFunctions = true;
  15291. }
  15292. inFDEF = true;
  15293. // collecting inforamtion about which functions are defined
  15294. lastDeff = i;
  15295. funcId = stack.pop();
  15296. ttContext.functionsDefined[funcId] = {data: data, i: i};
  15297. } else if (op === 0x2D) { // ENDF - end of function
  15298. if (inFDEF) {
  15299. inFDEF = false;
  15300. lastEndf = i;
  15301. } else {
  15302. pc = callstack.pop();
  15303. if (!pc) {
  15304. warn('TT: ENDF bad stack');
  15305. ttContext.hintsValid = false;
  15306. return;
  15307. }
  15308. funcId = functionsCalled.pop();
  15309. data = pc.data;
  15310. i = pc.i;
  15311. ttContext.functionsStackDeltas[funcId] =
  15312. stack.length - pc.stackTop;
  15313. }
  15314. } else if (op === 0x89) { // IDEF - instruction definition
  15315. if (inFDEF || inELSE) {
  15316. warn('TT: nested IDEFs not allowed');
  15317. tooComplexToFollowFunctions = true;
  15318. }
  15319. inFDEF = true;
  15320. // recording it as a function to track ENDF
  15321. lastDeff = i;
  15322. } else if (op === 0x58) { // IF
  15323. ++ifLevel;
  15324. } else if (op === 0x1B) { // ELSE
  15325. inELSE = ifLevel;
  15326. } else if (op === 0x59) { // EIF
  15327. if (inELSE === ifLevel) {
  15328. inELSE = 0;
  15329. }
  15330. --ifLevel;
  15331. } else if (op === 0x1C) { // JMPR
  15332. if (!inFDEF && !inELSE) {
  15333. var offset = stack[stack.length - 1];
  15334. // only jumping forward to prevent infinite loop
  15335. if (offset > 0) {
  15336. i += offset - 1;
  15337. }
  15338. }
  15339. }
  15340. // Adjusting stack not extactly, but just enough to get function id
  15341. if (!inFDEF && !inELSE) {
  15342. var stackDelta = op <= 0x8E ? TTOpsStackDeltas[op] :
  15343. op >= 0xC0 && op <= 0xDF ? -1 : op >= 0xE0 ? -2 : 0;
  15344. if (op >= 0x71 && op <= 0x75) {
  15345. n = stack.pop();
  15346. if (n === n) {
  15347. stackDelta = -n * 2;
  15348. }
  15349. }
  15350. while (stackDelta < 0 && stack.length > 0) {
  15351. stack.pop();
  15352. stackDelta++;
  15353. }
  15354. while (stackDelta > 0) {
  15355. stack.push(NaN); // pushing any number into stack
  15356. stackDelta--;
  15357. }
  15358. }
  15359. }
  15360. ttContext.tooComplexToFollowFunctions = tooComplexToFollowFunctions;
  15361. var content = [data];
  15362. if (i > data.length) {
  15363. content.push(new Uint8Array(i - data.length));
  15364. }
  15365. if (lastDeff > lastEndf) {
  15366. warn('TT: complementing a missing function tail');
  15367. // new function definition started, but not finished
  15368. // complete function by [CLEAR, ENDF]
  15369. content.push(new Uint8Array([0x22, 0x2D]));
  15370. }
  15371. foldTTTable(table, content);
  15372. }
  15373. function checkInvalidFunctions(ttContext, maxFunctionDefs) {
  15374. if (ttContext.tooComplexToFollowFunctions) {
  15375. return;
  15376. }
  15377. if (ttContext.functionsDefined.length > maxFunctionDefs) {
  15378. warn('TT: more functions defined than expected');
  15379. ttContext.hintsValid = false;
  15380. return;
  15381. }
  15382. for (var j = 0, jj = ttContext.functionsUsed.length; j < jj; j++) {
  15383. if (j > maxFunctionDefs) {
  15384. warn('TT: invalid function id: ' + j);
  15385. ttContext.hintsValid = false;
  15386. return;
  15387. }
  15388. if (ttContext.functionsUsed[j] && !ttContext.functionsDefined[j]) {
  15389. warn('TT: undefined function: ' + j);
  15390. ttContext.hintsValid = false;
  15391. return;
  15392. }
  15393. }
  15394. }
  15395. function foldTTTable(table, content) {
  15396. if (content.length > 1) {
  15397. // concatenating the content items
  15398. var newLength = 0;
  15399. var j, jj;
  15400. for (j = 0, jj = content.length; j < jj; j++) {
  15401. newLength += content[j].length;
  15402. }
  15403. newLength = (newLength + 3) & ~3;
  15404. var result = new Uint8Array(newLength);
  15405. var pos = 0;
  15406. for (j = 0, jj = content.length; j < jj; j++) {
  15407. result.set(content[j], pos);
  15408. pos += content[j].length;
  15409. }
  15410. table.data = result;
  15411. table.length = newLength;
  15412. }
  15413. }
  15414. function sanitizeTTPrograms(fpgm, prep, cvt) {
  15415. var ttContext = {
  15416. functionsDefined: [],
  15417. functionsUsed: [],
  15418. functionsStackDeltas: [],
  15419. tooComplexToFollowFunctions: false,
  15420. hintsValid: true
  15421. };
  15422. if (fpgm) {
  15423. sanitizeTTProgram(fpgm, ttContext);
  15424. }
  15425. if (prep) {
  15426. sanitizeTTProgram(prep, ttContext);
  15427. }
  15428. if (fpgm) {
  15429. checkInvalidFunctions(ttContext, maxFunctionDefs);
  15430. }
  15431. if (cvt && (cvt.length & 1)) {
  15432. var cvtData = new Uint8Array(cvt.length + 1);
  15433. cvtData.set(cvt.data);
  15434. cvt.data = cvtData;
  15435. }
  15436. return ttContext.hintsValid;
  15437. }
  15438. // The following steps modify the original font data, making copy
  15439. font = new Stream(new Uint8Array(font.getBytes()));
  15440. var VALID_TABLES = ['OS/2', 'cmap', 'head', 'hhea', 'hmtx', 'maxp',
  15441. 'name', 'post', 'loca', 'glyf', 'fpgm', 'prep', 'cvt ', 'CFF '];
  15442. var header = readOpenTypeHeader(font);
  15443. var numTables = header.numTables;
  15444. var cff, cffFile;
  15445. var tables = { 'OS/2': null, cmap: null, head: null, hhea: null,
  15446. hmtx: null, maxp: null, name: null, post: null };
  15447. var table, tableData;
  15448. for (var i = 0; i < numTables; i++) {
  15449. table = readTableEntry(font);
  15450. if (VALID_TABLES.indexOf(table.tag) < 0) {
  15451. continue; // skipping table if it's not a required or optional table
  15452. }
  15453. if (table.length === 0) {
  15454. continue; // skipping empty tables
  15455. }
  15456. tables[table.tag] = table;
  15457. }
  15458. var isTrueType = !tables['CFF '];
  15459. if (!isTrueType) {
  15460. // OpenType font
  15461. if (!tables.head || !tables.hhea || !tables.maxp || !tables.post) {
  15462. // no major tables: throwing everything at CFFFont
  15463. cffFile = new Stream(tables['CFF '].data);
  15464. cff = new CFFFont(cffFile, properties);
  15465. return this.convert(name, cff, properties);
  15466. }
  15467. delete tables.glyf;
  15468. delete tables.loca;
  15469. delete tables.fpgm;
  15470. delete tables.prep;
  15471. delete tables['cvt '];
  15472. this.isOpenType = true;
  15473. } else {
  15474. if (!tables.glyf || !tables.loca) {
  15475. error('Required "glyf" or "loca" tables are not found');
  15476. }
  15477. this.isOpenType = false;
  15478. }
  15479. if (!tables.maxp) {
  15480. error('Required "maxp" table is not found');
  15481. }
  15482. font.pos = (font.start || 0) + tables.maxp.offset;
  15483. var version = font.getInt32();
  15484. var numGlyphs = font.getUint16();
  15485. var maxFunctionDefs = 0;
  15486. if (version >= 0x00010000 && tables.maxp.length >= 22) {
  15487. // maxZones can be invalid
  15488. font.pos += 8;
  15489. var maxZones = font.getUint16();
  15490. if (maxZones > 2) { // reset to 2 if font has invalid maxZones
  15491. tables.maxp.data[14] = 0;
  15492. tables.maxp.data[15] = 2;
  15493. }
  15494. font.pos += 4;
  15495. maxFunctionDefs = font.getUint16();
  15496. }
  15497. var dupFirstEntry = false;
  15498. if (properties.type == 'CIDFontType2' && properties.toUnicode &&
  15499. properties.toUnicode[0] > '\u0000') {
  15500. // oracle's defect (see 3427), duplicating first entry
  15501. dupFirstEntry = true;
  15502. numGlyphs++;
  15503. tables.maxp.data[4] = numGlyphs >> 8;
  15504. tables.maxp.data[5] = numGlyphs & 255;
  15505. }
  15506. var hintsValid = sanitizeTTPrograms(tables.fpgm, tables.prep,
  15507. tables['cvt '], maxFunctionDefs);
  15508. if (!hintsValid) {
  15509. delete tables.fpgm;
  15510. delete tables.prep;
  15511. delete tables['cvt '];
  15512. }
  15513. // Tables needs to be written by ascendant alphabetic order
  15514. var tablesNames = Object.keys(tables);
  15515. tablesNames.sort();
  15516. numTables = tablesNames.length;
  15517. // header and new offsets. Table entry information is appended to the
  15518. // end of file. The virtualOffset represents where to put the actual
  15519. // data of a particular table;
  15520. var ttf = {
  15521. file: '',
  15522. virtualOffset: numTables * (4 * 4)
  15523. };
  15524. // The new numbers of tables will be the last one plus the num
  15525. // of missing tables
  15526. createOpenTypeHeader(header.version, ttf, numTables);
  15527. // Ensure the hmtx table contains the advance width and
  15528. // sidebearings information for numGlyphs in the maxp table
  15529. sanitizeMetrics(font, tables.hhea, tables.hmtx, numGlyphs);
  15530. if (!tables.head) {
  15531. error('Required "head" table is not found');
  15532. }
  15533. sanitizeHead(tables.head, numGlyphs, isTrueType ? tables.loca.length : 0);
  15534. if (isTrueType) {
  15535. var isGlyphLocationsLong = int16(tables.head.data[50],
  15536. tables.head.data[51]);
  15537. sanitizeGlyphLocations(tables.loca, tables.glyf, numGlyphs,
  15538. isGlyphLocationsLong, hintsValid, dupFirstEntry);
  15539. }
  15540. if (!tables.hhea) {
  15541. error('Required "hhea" table is not found');
  15542. }
  15543. // Sanitizer reduces the glyph advanceWidth to the maxAdvanceWidth
  15544. // Sometimes it's 0. That needs to be fixed
  15545. if (tables.hhea.data[10] === 0 && tables.hhea.data[11] === 0) {
  15546. tables.hhea.data[10] = 0xFF;
  15547. tables.hhea.data[11] = 0xFF;
  15548. }
  15549. // The 'post' table has glyphs names.
  15550. if (tables.post) {
  15551. var valid = readPostScriptTable(tables.post, properties, numGlyphs);
  15552. if (!valid) {
  15553. tables.post = null;
  15554. }
  15555. }
  15556. var charCodeToGlyphId = [], charCode;
  15557. if (properties.type === 'CIDFontType2') {
  15558. var cidToGidMap = properties.cidToGidMap || [];
  15559. var cidToGidMapLength = cidToGidMap.length;
  15560. properties.cMap.forEach(function(charCode, cid) {
  15561. assert(cid.length === 1, 'Max size of CID is 65,535');
  15562. cid = cid.charCodeAt(0);
  15563. var glyphId = -1;
  15564. if (cidToGidMapLength === 0) {
  15565. glyphId = charCode;
  15566. } else if (cidToGidMap[cid] !== undefined) {
  15567. glyphId = cidToGidMap[cid];
  15568. }
  15569. if (glyphId >= 0 && glyphId < numGlyphs) {
  15570. charCodeToGlyphId[charCode] = glyphId;
  15571. }
  15572. });
  15573. if (dupFirstEntry) {
  15574. charCodeToGlyphId[0] = numGlyphs - 1;
  15575. }
  15576. } else {
  15577. // Most of the following logic in this code branch is based on the
  15578. // 9.6.6.4 of the PDF spec.
  15579. var cmapTable = readCmapTable(tables.cmap, font, this.isSymbolicFont);
  15580. var cmapPlatformId = cmapTable.platformId;
  15581. var cmapEncodingId = cmapTable.encodingId;
  15582. var cmapMappings = cmapTable.mappings;
  15583. var cmapMappingsLength = cmapMappings.length;
  15584. var hasEncoding = properties.differences.length ||
  15585. !!properties.baseEncodingName;
  15586. // The spec seems to imply that if the font is symbolic the encoding
  15587. // should be ignored, this doesn't appear to work for 'preistabelle.pdf'
  15588. // where the the font is symbolic and it has an encoding.
  15589. if (hasEncoding &&
  15590. (cmapPlatformId === 3 && cmapEncodingId === 1 ||
  15591. cmapPlatformId === 1 && cmapEncodingId === 0)) {
  15592. var baseEncoding = [];
  15593. if (properties.baseEncodingName === 'MacRomanEncoding' ||
  15594. properties.baseEncodingName === 'WinAnsiEncoding') {
  15595. baseEncoding = Encodings[properties.baseEncodingName];
  15596. }
  15597. for (charCode = 0; charCode < 256; charCode++) {
  15598. var glyphName;
  15599. if (this.differences && charCode in this.differences) {
  15600. glyphName = this.differences[charCode];
  15601. } else if (charCode in baseEncoding &&
  15602. baseEncoding[charCode] !== '') {
  15603. glyphName = baseEncoding[charCode];
  15604. } else {
  15605. glyphName = Encodings.StandardEncoding[charCode];
  15606. }
  15607. if (!glyphName) {
  15608. continue;
  15609. }
  15610. var unicodeOrCharCode;
  15611. if (cmapPlatformId === 3 && cmapEncodingId === 1) {
  15612. unicodeOrCharCode = GlyphsUnicode[glyphName];
  15613. } else if (cmapPlatformId === 1 && cmapEncodingId === 0) {
  15614. // TODO: the encoding needs to be updated with mac os table.
  15615. unicodeOrCharCode = Encodings.MacRomanEncoding.indexOf(glyphName);
  15616. }
  15617. var found = false;
  15618. for (i = 0; i < cmapMappingsLength; ++i) {
  15619. if (cmapMappings[i].charCode === unicodeOrCharCode) {
  15620. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  15621. found = true;
  15622. break;
  15623. }
  15624. }
  15625. if (!found && properties.glyphNames) {
  15626. // Try to map using the post table. There are currently no known
  15627. // pdfs that this fixes.
  15628. var glyphId = properties.glyphNames.indexOf(glyphName);
  15629. if (glyphId > 0) {
  15630. charCodeToGlyphId[charCode] = glyphId;
  15631. }
  15632. }
  15633. }
  15634. } else {
  15635. // For (3, 0) cmap tables:
  15636. // The charcode key being stored in charCodeToGlyphId is the lower
  15637. // byte of the two-byte charcodes of the cmap table since according to
  15638. // the spec: 'each byte from the string shall be prepended with the
  15639. // high byte of the range [of charcodes in the cmap table], to form
  15640. // a two-byte character, which shall be used to select the
  15641. // associated glyph description from the subtable'.
  15642. //
  15643. // For (1, 0) cmap tables:
  15644. // 'single bytes from the string shall be used to look up the
  15645. // associated glyph descriptions from the subtable'. This means
  15646. // charcodes in the cmap will be single bytes, so no-op since
  15647. // glyph.charCode & 0xFF === glyph.charCode
  15648. for (i = 0; i < cmapMappingsLength; ++i) {
  15649. charCode = cmapMappings[i].charCode & 0xFF;
  15650. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  15651. }
  15652. }
  15653. }
  15654. if (charCodeToGlyphId.length === 0) {
  15655. // defines at least one glyph
  15656. charCodeToGlyphId[0] = 0;
  15657. }
  15658. // Converting glyphs and ids into font's cmap table
  15659. var newMapping = adjustMapping(charCodeToGlyphId, properties);
  15660. this.toFontChar = newMapping.toFontChar;
  15661. tables.cmap = {
  15662. tag: 'cmap',
  15663. data: createCmapTable(newMapping.charCodeToGlyphId)
  15664. };
  15665. if (!tables['OS/2'] || !validateOS2Table(tables['OS/2'])) {
  15666. // extract some more font properties from the OpenType head and
  15667. // hhea tables; yMin and descent value are always negative
  15668. var override = {
  15669. unitsPerEm: int16(tables.head.data[18], tables.head.data[19]),
  15670. yMax: int16(tables.head.data[42], tables.head.data[43]),
  15671. yMin: int16(tables.head.data[38], tables.head.data[39]) - 0x10000,
  15672. ascent: int16(tables.hhea.data[4], tables.hhea.data[5]),
  15673. descent: int16(tables.hhea.data[6], tables.hhea.data[7]) - 0x10000
  15674. };
  15675. tables['OS/2'] = {
  15676. tag: 'OS/2',
  15677. data: stringToArray(createOS2Table(properties,
  15678. newMapping.charCodeToGlyphId,
  15679. override))
  15680. };
  15681. }
  15682. // Rewrite the 'post' table if needed
  15683. if (!tables.post) {
  15684. tables.post = {
  15685. tag: 'post',
  15686. data: stringToArray(createPostTable(properties))
  15687. };
  15688. }
  15689. if (!isTrueType) {
  15690. try {
  15691. // Trying to repair CFF file
  15692. cffFile = new Stream(tables['CFF '].data);
  15693. var parser = new CFFParser(cffFile, properties);
  15694. cff = parser.parse();
  15695. var compiler = new CFFCompiler(cff);
  15696. tables['CFF '].data = compiler.compile();
  15697. } catch (e) {
  15698. warn('Failed to compile font ' + properties.loadedName);
  15699. }
  15700. }
  15701. // Re-creating 'name' table
  15702. if (!tables.name) {
  15703. tables.name = {
  15704. tag: 'name',
  15705. data: stringToArray(createNameTable(this.name))
  15706. };
  15707. } else {
  15708. // ... using existing 'name' table as prototype
  15709. var namePrototype = readNameTable(tables.name);
  15710. tables.name.data = stringToArray(createNameTable(name, namePrototype));
  15711. }
  15712. // rewrite the tables but tweak offsets
  15713. for (i = 0; i < numTables; i++) {
  15714. table = tables[tablesNames[i]];
  15715. var data = [];
  15716. tableData = table.data;
  15717. for (var j = 0, jj = tableData.length; j < jj; j++) {
  15718. data.push(tableData[j]);
  15719. }
  15720. createTableEntry(ttf, table.tag, data);
  15721. }
  15722. // Add the table datas
  15723. for (i = 0; i < numTables; i++) {
  15724. table = tables[tablesNames[i]];
  15725. tableData = table.data;
  15726. ttf.file += bytesToString(new Uint8Array(tableData));
  15727. // 4-byte aligned data
  15728. while (ttf.file.length & 3) {
  15729. ttf.file += String.fromCharCode(0);
  15730. }
  15731. }
  15732. return stringToArray(ttf.file);
  15733. },
  15734. convert: function Font_convert(fontName, font, properties) {
  15735. // The offsets object holds at the same time a representation of where
  15736. // to write the table entry information about a table and another offset
  15737. // representing the offset where to draw the actual data of a particular
  15738. // table
  15739. var otf = {
  15740. file: '',
  15741. virtualOffset: 9 * (4 * 4)
  15742. };
  15743. createOpenTypeHeader('\x4F\x54\x54\x4F', otf, 9);
  15744. // TODO: Check the charstring widths to determine this.
  15745. properties.fixedPitch = false;
  15746. var mapping = font.getGlyphMapping(properties);
  15747. var newMapping = adjustMapping(mapping, properties);
  15748. this.toFontChar = newMapping.toFontChar;
  15749. var numGlyphs = font.numGlyphs;
  15750. function getCharCodes(charCodeToGlyphId, glyphId) {
  15751. var charCodes = null;
  15752. for (var charCode in charCodeToGlyphId) {
  15753. if (glyphId === charCodeToGlyphId[charCode]) {
  15754. if (!charCodes) {
  15755. charCodes = [];
  15756. }
  15757. charCodes.push(charCode | 0);
  15758. }
  15759. }
  15760. return charCodes;
  15761. }
  15762. function createCharCode(charCodeToGlyphId, glyphId) {
  15763. for (var charCode in charCodeToGlyphId) {
  15764. if (glyphId === charCodeToGlyphId[charCode]) {
  15765. return charCode | 0;
  15766. }
  15767. }
  15768. newMapping.charCodeToGlyphId[newMapping.nextAvailableFontCharCode] =
  15769. glyphId;
  15770. return newMapping.nextAvailableFontCharCode++;
  15771. }
  15772. var seacs = font.seacs;
  15773. if (SEAC_ANALYSIS_ENABLED && seacs && seacs.length) {
  15774. var matrix = properties.fontMatrix || FONT_IDENTITY_MATRIX;
  15775. var charset = font.getCharset();
  15776. var seacMap = Object.create(null);
  15777. for (var glyphId in seacs) {
  15778. glyphId |= 0;
  15779. var seac = seacs[glyphId];
  15780. var baseGlyphName = Encodings.StandardEncoding[seac[2]];
  15781. var accentGlyphName = Encodings.StandardEncoding[seac[3]];
  15782. var baseGlyphId = charset.indexOf(baseGlyphName);
  15783. var accentGlyphId = charset.indexOf(accentGlyphName);
  15784. if (baseGlyphId < 0 || accentGlyphId < 0) {
  15785. continue;
  15786. }
  15787. var accentOffset = {
  15788. x: seac[0] * matrix[0] + seac[1] * matrix[2] + matrix[4],
  15789. y: seac[0] * matrix[1] + seac[1] * matrix[3] + matrix[5]
  15790. };
  15791. var charCodes = getCharCodes(mapping, glyphId);
  15792. if (!charCodes) {
  15793. // There's no point in mapping it if the char code was never mapped
  15794. // to begin with.
  15795. continue;
  15796. }
  15797. for (var i = 0, ii = charCodes.length; i < ii; i++) {
  15798. var charCode = charCodes[i];
  15799. // Find a fontCharCode that maps to the base and accent glyphs.
  15800. // If one doesn't exists, create it.
  15801. var charCodeToGlyphId = newMapping.charCodeToGlyphId;
  15802. var baseFontCharCode = createCharCode(charCodeToGlyphId,
  15803. baseGlyphId);
  15804. var accentFontCharCode = createCharCode(charCodeToGlyphId,
  15805. accentGlyphId);
  15806. seacMap[charCode] = {
  15807. baseFontCharCode: baseFontCharCode,
  15808. accentFontCharCode: accentFontCharCode,
  15809. accentOffset: accentOffset
  15810. };
  15811. }
  15812. }
  15813. properties.seacMap = seacMap;
  15814. }
  15815. var unitsPerEm = 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0];
  15816. var fields = {
  15817. // PostScript Font Program
  15818. 'CFF ': font.data,
  15819. // OS/2 and Windows Specific metrics
  15820. 'OS/2': stringToArray(createOS2Table(properties,
  15821. newMapping.charCodeToGlyphId)),
  15822. // Character to glyphs mapping
  15823. 'cmap': createCmapTable(newMapping.charCodeToGlyphId),
  15824. // Font header
  15825. 'head': (function fontFieldsHead() {
  15826. return stringToArray(
  15827. '\x00\x01\x00\x00' + // Version number
  15828. '\x00\x00\x10\x00' + // fontRevision
  15829. '\x00\x00\x00\x00' + // checksumAdjustement
  15830. '\x5F\x0F\x3C\xF5' + // magicNumber
  15831. '\x00\x00' + // Flags
  15832. safeString16(unitsPerEm) + // unitsPerEM
  15833. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // creation date
  15834. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // modifification date
  15835. '\x00\x00' + // xMin
  15836. safeString16(properties.descent) + // yMin
  15837. '\x0F\xFF' + // xMax
  15838. safeString16(properties.ascent) + // yMax
  15839. string16(properties.italicAngle ? 2 : 0) + // macStyle
  15840. '\x00\x11' + // lowestRecPPEM
  15841. '\x00\x00' + // fontDirectionHint
  15842. '\x00\x00' + // indexToLocFormat
  15843. '\x00\x00'); // glyphDataFormat
  15844. })(),
  15845. // Horizontal header
  15846. 'hhea': (function fontFieldsHhea() {
  15847. return stringToArray(
  15848. '\x00\x01\x00\x00' + // Version number
  15849. safeString16(properties.ascent) + // Typographic Ascent
  15850. safeString16(properties.descent) + // Typographic Descent
  15851. '\x00\x00' + // Line Gap
  15852. '\xFF\xFF' + // advanceWidthMax
  15853. '\x00\x00' + // minLeftSidebearing
  15854. '\x00\x00' + // minRightSidebearing
  15855. '\x00\x00' + // xMaxExtent
  15856. safeString16(properties.capHeight) + // caretSlopeRise
  15857. safeString16(Math.tan(properties.italicAngle) *
  15858. properties.xHeight) + // caretSlopeRun
  15859. '\x00\x00' + // caretOffset
  15860. '\x00\x00' + // -reserved-
  15861. '\x00\x00' + // -reserved-
  15862. '\x00\x00' + // -reserved-
  15863. '\x00\x00' + // -reserved-
  15864. '\x00\x00' + // metricDataFormat
  15865. string16(numGlyphs)); // Number of HMetrics
  15866. })(),
  15867. // Horizontal metrics
  15868. 'hmtx': (function fontFieldsHmtx() {
  15869. var charstrings = font.charstrings;
  15870. var hmtx = '\x00\x00\x00\x00'; // Fake .notdef
  15871. for (var i = 1, ii = numGlyphs; i < ii; i++) {
  15872. // TODO: For CFF fonts the width should technically match th x in
  15873. // the glyph, but it doesn't seem to matter.
  15874. var charstring = charstrings ? charstrings[i - 1] : {};
  15875. var width = 'width' in charstring ? charstring.width : 0;
  15876. hmtx += string16(width) + string16(0);
  15877. }
  15878. return stringToArray(hmtx);
  15879. })(),
  15880. // Maximum profile
  15881. 'maxp': (function fontFieldsMaxp() {
  15882. return stringToArray(
  15883. '\x00\x00\x50\x00' + // Version number
  15884. string16(numGlyphs)); // Num of glyphs
  15885. })(),
  15886. // Naming tables
  15887. 'name': stringToArray(createNameTable(fontName)),
  15888. // PostScript informations
  15889. 'post': stringToArray(createPostTable(properties))
  15890. };
  15891. var field;
  15892. for (field in fields) {
  15893. createTableEntry(otf, field, fields[field]);
  15894. }
  15895. for (field in fields) {
  15896. var table = fields[field];
  15897. otf.file += bytesToString(new Uint8Array(table));
  15898. }
  15899. return stringToArray(otf.file);
  15900. },
  15901. /**
  15902. * Builds a char code to unicode map based on section 9.10 of the spec.
  15903. * @param {Object} properties Font properties object.
  15904. * @return {Object} Has two properties: 'toUnicode' which maps char codes to
  15905. * unicode (string) values and 'isIdentity' which is true if an identity map
  15906. * is used.
  15907. */
  15908. buildToUnicode: function Font_buildToUnicode(properties) {
  15909. var map = {
  15910. isIdentity: false,
  15911. toUnicode: null
  15912. };
  15913. // Section 9.10.2 Mapping Character Codes to Unicode Values
  15914. if (properties.toUnicode && properties.toUnicode.length !== 0) {
  15915. map.toUnicode = properties.toUnicode;
  15916. return map;
  15917. }
  15918. // According to the spec if the font is a simple font we should only map
  15919. // to unicode if the base encoding is MacRoman, MacExpert, or WinAnsi or
  15920. // the differences array only contains adobe standard or symbol set names,
  15921. // in pratice it seems better to always try to create a toUnicode
  15922. // map based of the default encoding.
  15923. var toUnicode, charcode;
  15924. if (!properties.composite /* is simple font */) {
  15925. toUnicode = [];
  15926. var encoding = properties.defaultEncoding.slice();
  15927. // Merge in the differences array.
  15928. var differences = properties.differences;
  15929. for (charcode in differences) {
  15930. encoding[charcode] = differences[charcode];
  15931. }
  15932. for (charcode in encoding) {
  15933. // a) Map the character code to a character name.
  15934. var glyphName = encoding[charcode];
  15935. // b) Look up the character name in the Adobe Glyph List (see the
  15936. // Bibliography) to obtain the corresponding Unicode value.
  15937. if (glyphName === '' || !(glyphName in GlyphsUnicode)) {
  15938. // (undocumented) c) Few heuristics to recognize unknown glyphs
  15939. // NOTE: Adobe Reader does not do this step, but OSX Preview does
  15940. var code;
  15941. // Gxx glyph
  15942. if (glyphName.length === 3 &&
  15943. glyphName[0] === 'G' &&
  15944. (code = parseInt(glyphName.substr(1), 16))) {
  15945. toUnicode[charcode] = String.fromCharCode(code);
  15946. }
  15947. // g00xx glyph
  15948. if (glyphName.length === 5 &&
  15949. glyphName[0] === 'g' &&
  15950. (code = parseInt(glyphName.substr(1), 16))) {
  15951. toUnicode[charcode] = String.fromCharCode(code);
  15952. }
  15953. // Cddd glyph
  15954. if (glyphName.length >= 3 &&
  15955. glyphName[0] === 'C' &&
  15956. (code = +glyphName.substr(1))) {
  15957. toUnicode[charcode] = String.fromCharCode(code);
  15958. }
  15959. continue;
  15960. }
  15961. toUnicode[charcode] = String.fromCharCode(GlyphsUnicode[glyphName]);
  15962. }
  15963. map.toUnicode = toUnicode;
  15964. return map;
  15965. }
  15966. // If the font is a composite font that uses one of the predefined CMaps
  15967. // listed in Table 118 (except Identity–H and Identity–V) or whose
  15968. // descendant CIDFont uses the Adobe-GB1, Adobe-CNS1, Adobe-Japan1, or
  15969. // Adobe-Korea1 character collection:
  15970. if (properties.composite && (
  15971. (properties.cMap.builtInCMap &&
  15972. !(properties.cMap instanceof IdentityCMap)) ||
  15973. (properties.cidSystemInfo.registry === 'Adobe' &&
  15974. (properties.cidSystemInfo.ordering === 'GB1' ||
  15975. properties.cidSystemInfo.ordering === 'CNS1' ||
  15976. properties.cidSystemInfo.ordering === 'Japan1' ||
  15977. properties.cidSystemInfo.ordering === 'Korea1')))) {
  15978. // Then:
  15979. // a) Map the character code to a character identifier (CID) according
  15980. // to the font’s CMap.
  15981. // b) Obtain the registry and ordering of the character collection used
  15982. // by the font’s CMap (for example, Adobe and Japan1) from its
  15983. // CIDSystemInfo dictionary.
  15984. var registry = properties.cidSystemInfo.registry;
  15985. var ordering = properties.cidSystemInfo.ordering;
  15986. // c) Construct a second CMap name by concatenating the registry and
  15987. // ordering obtained in step (b) in the format registry–ordering–UCS2
  15988. // (for example, Adobe–Japan1–UCS2).
  15989. var ucs2CMapName = new Name(registry + '-' + ordering + '-UCS2');
  15990. // d) Obtain the CMap with the name constructed in step (c) (available
  15991. // from the ASN Web site; see the Bibliography).
  15992. var ucs2CMap = CMapFactory.create(ucs2CMapName,
  15993. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  15994. var cMap = properties.cMap;
  15995. toUnicode = [];
  15996. cMap.forEach(function(charcode, cid) {
  15997. assert(cid.length === 1, 'Max size of CID is 65,535');
  15998. // e) Map the CID obtained in step (a) according to the CMap obtained
  15999. // in step (d), producing a Unicode value.
  16000. var ucs2 = ucs2CMap.lookup(cid.charCodeAt(0));
  16001. if (ucs2) {
  16002. toUnicode[charcode] =
  16003. String.fromCharCode((ucs2.charCodeAt(0) << 8) +
  16004. ucs2.charCodeAt(1));
  16005. }
  16006. });
  16007. map.toUnicode = toUnicode;
  16008. return map;
  16009. }
  16010. // The viewer's choice, just use an identity map.
  16011. toUnicode = [];
  16012. var firstChar = properties.firstChar, lastChar = properties.lastChar;
  16013. for (var i = firstChar; i <= lastChar; i++) {
  16014. toUnicode[i] = String.fromCharCode(i);
  16015. }
  16016. map.isIdentity = true;
  16017. map.toUnicode = toUnicode;
  16018. return map;
  16019. },
  16020. get spaceWidth() {
  16021. if ('_shadowWidth' in this) {
  16022. return this._shadowWidth;
  16023. }
  16024. // trying to estimate space character width
  16025. var possibleSpaceReplacements = ['space', 'minus', 'one', 'i'];
  16026. var width;
  16027. for (var i = 0, ii = possibleSpaceReplacements.length; i < ii; i++) {
  16028. var glyphName = possibleSpaceReplacements[i];
  16029. // if possible, getting width by glyph name
  16030. if (glyphName in this.widths) {
  16031. width = this.widths[glyphName];
  16032. break;
  16033. }
  16034. var glyphUnicode = GlyphsUnicode[glyphName];
  16035. // finding the charcode via unicodeToCID map
  16036. var charcode = 0;
  16037. if (this.composite) {
  16038. if (this.cMap.contains(glyphUnicode)) {
  16039. charcode = this.cMap.lookup(glyphUnicode).charCodeAt(0);
  16040. }
  16041. }
  16042. // ... via toUnicode map
  16043. if (!charcode && 'toUnicode' in this) {
  16044. charcode = this.toUnicode.indexOf(glyphUnicode);
  16045. }
  16046. // setting it to unicode if negative or undefined
  16047. if (charcode <= 0) {
  16048. charcode = glyphUnicode;
  16049. }
  16050. // trying to get width via charcode
  16051. width = this.widths[charcode];
  16052. if (width) {
  16053. break; // the non-zero width found
  16054. }
  16055. }
  16056. width = width || this.defaultWidth;
  16057. // Do not shadow the property here. See discussion:
  16058. // https://github.com/mozilla/pdf.js/pull/2127#discussion_r1662280
  16059. this._shadowWidth = width;
  16060. return width;
  16061. },
  16062. charToGlyph: function Font_charToGlyph(charcode) {
  16063. var fontCharCode, width, operatorListId;
  16064. var widthCode = charcode;
  16065. if (this.cMap && this.cMap.contains(charcode)) {
  16066. widthCode = this.cMap.lookup(charcode).charCodeAt(0);
  16067. }
  16068. width = this.widths[widthCode];
  16069. width = isNum(width) ? width : this.defaultWidth;
  16070. var vmetric = this.vmetrics && this.vmetrics[widthCode];
  16071. var unicode = this.toUnicode[charcode] || charcode;
  16072. if (typeof unicode === 'number') {
  16073. unicode = String.fromCharCode(unicode);
  16074. }
  16075. // First try the toFontChar map, if it's not there then try falling
  16076. // back to the char code.
  16077. fontCharCode = this.toFontChar[charcode] || charcode;
  16078. if (this.missingFile) {
  16079. fontCharCode = mapSpecialUnicodeValues(fontCharCode);
  16080. }
  16081. if (this.isType3Font) {
  16082. // Font char code in this case is actually a glyph name.
  16083. operatorListId = fontCharCode;
  16084. }
  16085. var accent = null;
  16086. if (this.seacMap && this.seacMap[charcode]) {
  16087. var seac = this.seacMap[charcode];
  16088. fontCharCode = seac.baseFontCharCode;
  16089. accent = {
  16090. fontChar: String.fromCharCode(seac.accentFontCharCode),
  16091. offset: seac.accentOffset
  16092. };
  16093. }
  16094. var fontChar = String.fromCharCode(fontCharCode);
  16095. var glyph = this.glyphCache[charcode];
  16096. if (!glyph ||
  16097. !glyph.matchesForCache(fontChar, unicode, accent, width, vmetric,
  16098. operatorListId)) {
  16099. glyph = new Glyph(fontChar, unicode, accent, width, vmetric,
  16100. operatorListId);
  16101. this.glyphCache[charcode] = glyph;
  16102. }
  16103. return glyph;
  16104. },
  16105. charsToGlyphs: function Font_charsToGlyphs(chars) {
  16106. var charsCache = this.charsCache;
  16107. var glyphs, glyph, charcode;
  16108. // if we translated this string before, just grab it from the cache
  16109. if (charsCache) {
  16110. glyphs = charsCache[chars];
  16111. if (glyphs) {
  16112. return glyphs;
  16113. }
  16114. }
  16115. // lazily create the translation cache
  16116. if (!charsCache) {
  16117. charsCache = this.charsCache = Object.create(null);
  16118. }
  16119. glyphs = [];
  16120. var charsCacheKey = chars;
  16121. var i = 0, ii;
  16122. if (this.cMap) {
  16123. // composite fonts have multi-byte strings convert the string from
  16124. // single-byte to multi-byte
  16125. while (i < chars.length) {
  16126. var c = this.cMap.readCharCode(chars, i);
  16127. charcode = c[0];
  16128. var length = c[1];
  16129. i += length;
  16130. glyph = this.charToGlyph(charcode);
  16131. glyphs.push(glyph);
  16132. // placing null after each word break charcode (ASCII SPACE)
  16133. // Ignore occurences of 0x20 in multiple-byte codes.
  16134. if (length === 1 && chars.charCodeAt(i - 1) === 0x20) {
  16135. glyphs.push(null);
  16136. }
  16137. }
  16138. } else {
  16139. for (i = 0, ii = chars.length; i < ii; ++i) {
  16140. charcode = chars.charCodeAt(i);
  16141. glyph = this.charToGlyph(charcode);
  16142. glyphs.push(glyph);
  16143. if (charcode == 0x20) {
  16144. glyphs.push(null);
  16145. }
  16146. }
  16147. }
  16148. // Enter the translated string into the cache
  16149. return (charsCache[charsCacheKey] = glyphs);
  16150. }
  16151. };
  16152. return Font;
  16153. })();
  16154. var ErrorFont = (function ErrorFontClosure() {
  16155. function ErrorFont(error) {
  16156. this.error = error;
  16157. this.loadedName = 'g_font_error';
  16158. this.loading = false;
  16159. }
  16160. ErrorFont.prototype = {
  16161. charsToGlyphs: function ErrorFont_charsToGlyphs() {
  16162. return [];
  16163. },
  16164. exportData: function ErrorFont_exportData() {
  16165. return {error: this.error};
  16166. }
  16167. };
  16168. return ErrorFont;
  16169. })();
  16170. /**
  16171. * Shared logic for building a char code to glyph id mapping for Type1 and
  16172. * simple CFF fonts. See section 9.6.6.2 of the spec.
  16173. * @param {Object} properties Font properties object.
  16174. * @param {Object} builtInEncoding The encoding contained within the actual font
  16175. * data.
  16176. * @param {Array} Array of glyph names where the index is the glyph ID.
  16177. * @returns {Object} A char code to glyph ID map.
  16178. */
  16179. function type1FontGlyphMapping(properties, builtInEncoding, glyphNames) {
  16180. var charCodeToGlyphId = Object.create(null);
  16181. var glyphId, charCode, baseEncoding;
  16182. if (properties.baseEncodingName) {
  16183. // If a valid base encoding name was used, the mapping is initialized with
  16184. // that.
  16185. baseEncoding = Encodings[properties.baseEncodingName];
  16186. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  16187. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  16188. if (glyphId >= 0) {
  16189. charCodeToGlyphId[charCode] = glyphId;
  16190. }
  16191. }
  16192. } else if (!!(properties.flags & FontFlags.Symbolic)) {
  16193. // For a symbolic font the encoding should be the fonts built-in
  16194. // encoding.
  16195. for (charCode in builtInEncoding) {
  16196. charCodeToGlyphId[charCode] = builtInEncoding[charCode];
  16197. }
  16198. } else {
  16199. // For non-symbolic fonts that don't have a base encoding the standard
  16200. // encoding should be used.
  16201. baseEncoding = Encodings.StandardEncoding;
  16202. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  16203. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  16204. if (glyphId >= 0) {
  16205. charCodeToGlyphId[charCode] = glyphId;
  16206. }
  16207. }
  16208. }
  16209. // Lastly, merge in the differences.
  16210. var differences = properties.differences;
  16211. if (differences) {
  16212. for (charCode in differences) {
  16213. var glyphName = differences[charCode];
  16214. glyphId = glyphNames.indexOf(glyphName);
  16215. if (glyphId >= 0) {
  16216. charCodeToGlyphId[charCode] = glyphId;
  16217. }
  16218. }
  16219. }
  16220. return charCodeToGlyphId;
  16221. }
  16222. /*
  16223. * CharStrings are encoded following the the CharString Encoding sequence
  16224. * describe in Chapter 6 of the "Adobe Type1 Font Format" specification.
  16225. * The value in a byte indicates a command, a number, or subsequent bytes
  16226. * that are to be interpreted in a special way.
  16227. *
  16228. * CharString Number Encoding:
  16229. * A CharString byte containing the values from 32 through 255 inclusive
  16230. * indicate an integer. These values are decoded in four ranges.
  16231. *
  16232. * 1. A CharString byte containing a value, v, between 32 and 246 inclusive,
  16233. * indicate the integer v - 139. Thus, the integer values from -107 through
  16234. * 107 inclusive may be encoded in single byte.
  16235. *
  16236. * 2. A CharString byte containing a value, v, between 247 and 250 inclusive,
  16237. * indicates an integer involving the next byte, w, according to the formula:
  16238. * [(v - 247) x 256] + w + 108
  16239. *
  16240. * 3. A CharString byte containing a value, v, between 251 and 254 inclusive,
  16241. * indicates an integer involving the next byte, w, according to the formula:
  16242. * -[(v - 251) * 256] - w - 108
  16243. *
  16244. * 4. A CharString containing the value 255 indicates that the next 4 bytes
  16245. * are a two complement signed integer. The first of these bytes contains the
  16246. * highest order bits, the second byte contains the next higher order bits
  16247. * and the fourth byte contain the lowest order bits.
  16248. *
  16249. *
  16250. * CharString Command Encoding:
  16251. * CharStrings commands are encoded in 1 or 2 bytes.
  16252. *
  16253. * Single byte commands are encoded in 1 byte that contains a value between
  16254. * 0 and 31 inclusive.
  16255. * If a command byte contains the value 12, then the value in the next byte
  16256. * indicates a command. This "escape" mechanism allows many extra commands
  16257. * to be encoded and this encoding technique helps to minimize the length of
  16258. * the charStrings.
  16259. */
  16260. var Type1CharString = (function Type1CharStringClosure() {
  16261. var COMMAND_MAP = {
  16262. 'hstem': [1],
  16263. 'vstem': [3],
  16264. 'vmoveto': [4],
  16265. 'rlineto': [5],
  16266. 'hlineto': [6],
  16267. 'vlineto': [7],
  16268. 'rrcurveto': [8],
  16269. 'callsubr': [10],
  16270. 'flex': [12, 35],
  16271. 'drop' : [12, 18],
  16272. 'endchar': [14],
  16273. 'rmoveto': [21],
  16274. 'hmoveto': [22],
  16275. 'vhcurveto': [30],
  16276. 'hvcurveto': [31]
  16277. };
  16278. function Type1CharString() {
  16279. this.width = 0;
  16280. this.lsb = 0;
  16281. this.flexing = false;
  16282. this.output = [];
  16283. this.stack = [];
  16284. }
  16285. Type1CharString.prototype = {
  16286. convert: function Type1CharString_convert(encoded, subrs) {
  16287. var count = encoded.length;
  16288. var error = false;
  16289. var wx, sbx, subrNumber;
  16290. for (var i = 0; i < count; i++) {
  16291. var value = encoded[i];
  16292. if (value < 32) {
  16293. if (value === 12) {
  16294. value = (value << 8) + encoded[++i];
  16295. }
  16296. switch (value) {
  16297. case 1: // hstem
  16298. if (!HINTING_ENABLED) {
  16299. this.stack = [];
  16300. break;
  16301. }
  16302. error = this.executeCommand(2, COMMAND_MAP.hstem);
  16303. break;
  16304. case 3: // vstem
  16305. if (!HINTING_ENABLED) {
  16306. this.stack = [];
  16307. break;
  16308. }
  16309. error = this.executeCommand(2, COMMAND_MAP.vstem);
  16310. break;
  16311. case 4: // vmoveto
  16312. if (this.flexing) {
  16313. if (this.stack.length < 1) {
  16314. error = true;
  16315. break;
  16316. }
  16317. // Add the dx for flex and but also swap the values so they are
  16318. // the right order.
  16319. var dy = this.stack.pop();
  16320. this.stack.push(0, dy);
  16321. break;
  16322. }
  16323. error = this.executeCommand(1, COMMAND_MAP.vmoveto);
  16324. break;
  16325. case 5: // rlineto
  16326. error = this.executeCommand(2, COMMAND_MAP.rlineto);
  16327. break;
  16328. case 6: // hlineto
  16329. error = this.executeCommand(1, COMMAND_MAP.hlineto);
  16330. break;
  16331. case 7: // vlineto
  16332. error = this.executeCommand(1, COMMAND_MAP.vlineto);
  16333. break;
  16334. case 8: // rrcurveto
  16335. error = this.executeCommand(6, COMMAND_MAP.rrcurveto);
  16336. break;
  16337. case 9: // closepath
  16338. // closepath is a Type1 command that does not take argument and is
  16339. // useless in Type2 and it can simply be ignored.
  16340. this.stack = [];
  16341. break;
  16342. case 10: // callsubr
  16343. if (this.stack.length < 1) {
  16344. error = true;
  16345. break;
  16346. }
  16347. subrNumber = this.stack.pop();
  16348. error = this.convert(subrs[subrNumber], subrs);
  16349. break;
  16350. case 11: // return
  16351. return error;
  16352. case 13: // hsbw
  16353. if (this.stack.length < 2) {
  16354. error = true;
  16355. break;
  16356. }
  16357. // To convert to type2 we have to move the width value to the
  16358. // first part of the charstring and then use hmoveto with lsb.
  16359. wx = this.stack.pop();
  16360. sbx = this.stack.pop();
  16361. this.lsb = sbx;
  16362. this.width = wx;
  16363. this.stack.push(sbx);
  16364. error = this.executeCommand(1, COMMAND_MAP.hmoveto);
  16365. break;
  16366. case 14: // endchar
  16367. this.output.push(COMMAND_MAP.endchar[0]);
  16368. break;
  16369. case 21: // rmoveto
  16370. if (this.flexing) {
  16371. break;
  16372. }
  16373. error = this.executeCommand(2, COMMAND_MAP.rmoveto);
  16374. break;
  16375. case 22: // hmoveto
  16376. if (this.flexing) {
  16377. // Add the dy for flex.
  16378. this.stack.push(0);
  16379. break;
  16380. }
  16381. error = this.executeCommand(1, COMMAND_MAP.hmoveto);
  16382. break;
  16383. case 30: // vhcurveto
  16384. error = this.executeCommand(4, COMMAND_MAP.vhcurveto);
  16385. break;
  16386. case 31: // hvcurveto
  16387. error = this.executeCommand(4, COMMAND_MAP.hvcurveto);
  16388. break;
  16389. case (12 << 8) + 0: // dotsection
  16390. // dotsection is a Type1 command to specify some hinting feature
  16391. // for dots that do not take a parameter and it can safely be
  16392. // ignored for Type2.
  16393. this.stack = [];
  16394. break;
  16395. case (12 << 8) + 1: // vstem3
  16396. if (!HINTING_ENABLED) {
  16397. this.stack = [];
  16398. break;
  16399. }
  16400. // [vh]stem3 are Type1 only and Type2 supports [vh]stem with
  16401. // multiple parameters, so instead of returning [vh]stem3 take a
  16402. // shortcut and return [vhstem] instead.
  16403. error = this.executeCommand(2, COMMAND_MAP.vstem);
  16404. break;
  16405. case (12 << 8) + 2: // hstem3
  16406. if (!HINTING_ENABLED) {
  16407. this.stack = [];
  16408. break;
  16409. }
  16410. // See vstem3.
  16411. error = this.executeCommand(2, COMMAND_MAP.hstem);
  16412. break;
  16413. case (12 << 8) + 6: // seac
  16414. // seac is like type 2's special endchar but it doesn't use the
  16415. // first argument asb, so remove it.
  16416. if (SEAC_ANALYSIS_ENABLED) {
  16417. this.seac = this.stack.splice(-4, 4);
  16418. error = this.executeCommand(0, COMMAND_MAP.endchar);
  16419. } else {
  16420. error = this.executeCommand(4, COMMAND_MAP.endchar);
  16421. }
  16422. break;
  16423. case (12 << 8) + 7: // sbw
  16424. if (this.stack.length < 4) {
  16425. error = true;
  16426. break;
  16427. }
  16428. // To convert to type2 we have to move the width value to the
  16429. // first part of the charstring and then use rmoveto with
  16430. // (dx, dy). The height argument will not be used for vmtx and
  16431. // vhea tables reconstruction -- ignoring it.
  16432. var wy = this.stack.pop();
  16433. wx = this.stack.pop();
  16434. var sby = this.stack.pop();
  16435. sbx = this.stack.pop();
  16436. this.lsb = sbx;
  16437. this.width = wx;
  16438. this.stack.push(sbx, sby);
  16439. error = this.executeCommand(2, COMMAND_MAP.rmoveto);
  16440. break;
  16441. case (12 << 8) + 12: // div
  16442. if (this.stack.length < 2) {
  16443. error = true;
  16444. break;
  16445. }
  16446. var num2 = this.stack.pop();
  16447. var num1 = this.stack.pop();
  16448. this.stack.push(num1 / num2);
  16449. break;
  16450. case (12 << 8) + 16: // callothersubr
  16451. if (this.stack.length < 2) {
  16452. error = true;
  16453. break;
  16454. }
  16455. subrNumber = this.stack.pop();
  16456. var numArgs = this.stack.pop();
  16457. if (subrNumber === 0 && numArgs === 3) {
  16458. var flexArgs = this.stack.splice(this.stack.length - 17, 17);
  16459. this.stack.push(
  16460. flexArgs[2] + flexArgs[0], // bcp1x + rpx
  16461. flexArgs[3] + flexArgs[1], // bcp1y + rpy
  16462. flexArgs[4], // bcp2x
  16463. flexArgs[5], // bcp2y
  16464. flexArgs[6], // p2x
  16465. flexArgs[7], // p2y
  16466. flexArgs[8], // bcp3x
  16467. flexArgs[9], // bcp3y
  16468. flexArgs[10], // bcp4x
  16469. flexArgs[11], // bcp4y
  16470. flexArgs[12], // p3x
  16471. flexArgs[13], // p3y
  16472. flexArgs[14] // flexDepth
  16473. // 15 = finalx unused by flex
  16474. // 16 = finaly unused by flex
  16475. );
  16476. error = this.executeCommand(13, COMMAND_MAP.flex, true);
  16477. this.flexing = false;
  16478. this.stack.push(flexArgs[15], flexArgs[16]);
  16479. } else if (subrNumber === 1 && numArgs === 0) {
  16480. this.flexing = true;
  16481. }
  16482. break;
  16483. case (12 << 8) + 17: // pop
  16484. // Ignore this since it is only used with othersubr.
  16485. break;
  16486. case (12 << 8) + 33: // setcurrentpoint
  16487. // Ignore for now.
  16488. this.stack = [];
  16489. break;
  16490. default:
  16491. warn('Unknown type 1 charstring command of "' + value + '"');
  16492. break;
  16493. }
  16494. if (error) {
  16495. break;
  16496. }
  16497. continue;
  16498. } else if (value <= 246) {
  16499. value = value - 139;
  16500. } else if (value <= 250) {
  16501. value = ((value - 247) * 256) + encoded[++i] + 108;
  16502. } else if (value <= 254) {
  16503. value = -((value - 251) * 256) - encoded[++i] - 108;
  16504. } else {
  16505. value = (encoded[++i] & 0xff) << 24 | (encoded[++i] & 0xff) << 16 |
  16506. (encoded[++i] & 0xff) << 8 | (encoded[++i] & 0xff) << 0;
  16507. }
  16508. this.stack.push(value);
  16509. }
  16510. return error;
  16511. },
  16512. executeCommand: function(howManyArgs, command, keepStack) {
  16513. var stackLength = this.stack.length;
  16514. if (howManyArgs > stackLength) {
  16515. return true;
  16516. }
  16517. var start = stackLength - howManyArgs;
  16518. for (var i = start; i < stackLength; i++) {
  16519. var value = this.stack[i];
  16520. if (value === (value | 0)) { // int
  16521. this.output.push(28, (value >> 8) & 0xff, value & 0xff);
  16522. } else { // fixed point
  16523. value = (65536 * value) | 0;
  16524. this.output.push(255,
  16525. (value >> 24) & 0xFF,
  16526. (value >> 16) & 0xFF,
  16527. (value >> 8) & 0xFF,
  16528. value & 0xFF);
  16529. }
  16530. }
  16531. this.output.push.apply(this.output, command);
  16532. if (keepStack) {
  16533. this.stack.splice(start, howManyArgs);
  16534. } else {
  16535. this.stack.length = 0;
  16536. }
  16537. return false;
  16538. }
  16539. };
  16540. return Type1CharString;
  16541. })();
  16542. /*
  16543. * Type1Parser encapsulate the needed code for parsing a Type1 font
  16544. * program. Some of its logic depends on the Type2 charstrings
  16545. * structure.
  16546. * Note: this doesn't really parse the font since that would require evaluation
  16547. * of PostScript, but it is possible in most cases to extract what we need
  16548. * without a full parse.
  16549. */
  16550. var Type1Parser = (function Type1ParserClosure() {
  16551. /*
  16552. * Decrypt a Sequence of Ciphertext Bytes to Produce the Original Sequence
  16553. * of Plaintext Bytes. The function took a key as a parameter which can be
  16554. * for decrypting the eexec block of for decoding charStrings.
  16555. */
  16556. var EEXEC_ENCRYPT_KEY = 55665;
  16557. var CHAR_STRS_ENCRYPT_KEY = 4330;
  16558. function isHexDigit(code) {
  16559. return code >= 48 && code <= 57 || // '0'-'9'
  16560. code >= 65 && code <= 70 || // 'A'-'F'
  16561. code >= 97 && code <= 102; // 'a'-'f'
  16562. }
  16563. function decrypt(data, key, discardNumber) {
  16564. var r = key | 0, c1 = 52845, c2 = 22719;
  16565. var count = data.length;
  16566. var decrypted = new Uint8Array(count);
  16567. for (var i = 0; i < count; i++) {
  16568. var value = data[i];
  16569. decrypted[i] = value ^ (r >> 8);
  16570. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  16571. }
  16572. return Array.prototype.slice.call(decrypted, discardNumber);
  16573. }
  16574. function decryptAscii(data, key, discardNumber) {
  16575. var r = key | 0, c1 = 52845, c2 = 22719;
  16576. var count = data.length, maybeLength = count >>> 1;
  16577. var decrypted = new Uint8Array(maybeLength);
  16578. var i, j;
  16579. for (i = 0, j = 0; i < count; i++) {
  16580. var digit1 = data[i];
  16581. if (!isHexDigit(digit1)) {
  16582. continue;
  16583. }
  16584. i++;
  16585. var digit2;
  16586. while (i < count && !isHexDigit(digit2 = data[i])) {
  16587. i++;
  16588. }
  16589. if (i < count) {
  16590. var value = parseInt(String.fromCharCode(digit1, digit2), 16);
  16591. decrypted[j++] = value ^ (r >> 8);
  16592. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  16593. }
  16594. }
  16595. return Array.prototype.slice.call(decrypted, discardNumber, j);
  16596. }
  16597. function isSpecial(c) {
  16598. return c === 0x2F || // '/'
  16599. c === 0x5B || c === 0x5D || // '[', ']'
  16600. c === 0x7B || c === 0x7D || // '{', '}'
  16601. c === 0x28 || c === 0x29; // '(', ')'
  16602. }
  16603. function Type1Parser(stream, encrypted) {
  16604. if (encrypted) {
  16605. var data = stream.getBytes();
  16606. var isBinary = !(isHexDigit(data[0]) && isHexDigit(data[1]) &&
  16607. isHexDigit(data[2]) && isHexDigit(data[3]));
  16608. stream = new Stream(isBinary ? decrypt(data, EEXEC_ENCRYPT_KEY, 4) :
  16609. decryptAscii(data, EEXEC_ENCRYPT_KEY, 4));
  16610. }
  16611. this.stream = stream;
  16612. this.nextChar();
  16613. }
  16614. Type1Parser.prototype = {
  16615. readNumberArray: function Type1Parser_readNumberArray() {
  16616. this.getToken(); // read '[' or '{' (arrays can start with either)
  16617. var array = [];
  16618. while (true) {
  16619. var token = this.getToken();
  16620. if (token === null || token === ']' || token === '}') {
  16621. break;
  16622. }
  16623. array.push(parseFloat(token || 0));
  16624. }
  16625. return array;
  16626. },
  16627. readNumber: function Type1Parser_readNumber() {
  16628. var token = this.getToken();
  16629. return parseFloat(token || 0);
  16630. },
  16631. readInt: function Type1Parser_readInt() {
  16632. // Use '| 0' to prevent setting a double into length such as the double
  16633. // does not flow into the loop variable.
  16634. var token = this.getToken();
  16635. return parseInt(token || 0, 10) | 0;
  16636. },
  16637. readBoolean: function Type1Parser_readBoolean() {
  16638. var token = this.getToken();
  16639. // Use 1 and 0 since that's what type2 charstrings use.
  16640. return token === 'true' ? 1 : 0;
  16641. },
  16642. nextChar : function Type1_nextChar() {
  16643. return (this.currentChar = this.stream.getByte());
  16644. },
  16645. getToken: function Type1Parser_getToken() {
  16646. // Eat whitespace and comments.
  16647. var comment = false;
  16648. var ch = this.currentChar;
  16649. while (true) {
  16650. if (ch === -1) {
  16651. return null;
  16652. }
  16653. if (comment) {
  16654. if (ch === 0x0A || ch === 0x0D) {
  16655. comment = false;
  16656. }
  16657. } else if (ch === 0x25) { // '%'
  16658. comment = true;
  16659. } else if (!Lexer.isSpace(ch)) {
  16660. break;
  16661. }
  16662. ch = this.nextChar();
  16663. }
  16664. if (isSpecial(ch)) {
  16665. this.nextChar();
  16666. return String.fromCharCode(ch);
  16667. }
  16668. var token = '';
  16669. do {
  16670. token += String.fromCharCode(ch);
  16671. ch = this.nextChar();
  16672. } while (ch >= 0 && !Lexer.isSpace(ch) && !isSpecial(ch));
  16673. return token;
  16674. },
  16675. /*
  16676. * Returns an object containing a Subrs array and a CharStrings
  16677. * array extracted from and eexec encrypted block of data
  16678. */
  16679. extractFontProgram: function Type1Parser_extractFontProgram() {
  16680. var stream = this.stream;
  16681. var subrs = [], charstrings = [];
  16682. var program = {
  16683. subrs: [],
  16684. charstrings: [],
  16685. properties: {
  16686. 'privateData': {
  16687. 'lenIV': 4
  16688. }
  16689. }
  16690. };
  16691. var token, length, data, lenIV, encoded;
  16692. while ((token = this.getToken()) !== null) {
  16693. if (token !== '/') {
  16694. continue;
  16695. }
  16696. token = this.getToken();
  16697. switch (token) {
  16698. case 'CharStrings':
  16699. // The number immediately following CharStrings must be greater or
  16700. // equal to the number of CharStrings.
  16701. this.getToken();
  16702. this.getToken(); // read in 'dict'
  16703. this.getToken(); // read in 'dup'
  16704. this.getToken(); // read in 'begin'
  16705. while(true) {
  16706. token = this.getToken();
  16707. if (token === null || token === 'end') {
  16708. break;
  16709. }
  16710. if (token !== '/') {
  16711. continue;
  16712. }
  16713. var glyph = this.getToken();
  16714. length = this.readInt();
  16715. this.getToken(); // read in 'RD' or '-|'
  16716. data = stream.makeSubStream(stream.pos, length);
  16717. lenIV = program.properties.privateData['lenIV'];
  16718. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  16719. // Skip past the required space and binary data.
  16720. stream.skip(length);
  16721. this.nextChar();
  16722. token = this.getToken(); // read in 'ND' or '|-'
  16723. if (token === 'noaccess') {
  16724. this.getToken(); // read in 'def'
  16725. }
  16726. charstrings.push({
  16727. glyph: glyph,
  16728. encoded: encoded
  16729. });
  16730. }
  16731. break;
  16732. case 'Subrs':
  16733. var num = this.readInt();
  16734. this.getToken(); // read in 'array'
  16735. while ((token = this.getToken()) === 'dup') {
  16736. var index = this.readInt();
  16737. length = this.readInt();
  16738. this.getToken(); // read in 'RD' or '-|'
  16739. data = stream.makeSubStream(stream.pos, length);
  16740. lenIV = program.properties.privateData['lenIV'];
  16741. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  16742. // Skip past the required space and binary data.
  16743. stream.skip(length);
  16744. this.nextChar();
  16745. token = this.getToken(); // read in 'NP' or '|'
  16746. if (token === 'noaccess') {
  16747. this.getToken(); // read in 'put'
  16748. }
  16749. subrs[index] = encoded;
  16750. }
  16751. break;
  16752. case 'BlueValues':
  16753. case 'OtherBlues':
  16754. case 'FamilyBlues':
  16755. case 'FamilyOtherBlues':
  16756. var blueArray = this.readNumberArray();
  16757. // *Blue* values may contain invalid data: disables reading of
  16758. // those values when hinting is disabled.
  16759. if (blueArray.length > 0 && (blueArray.length % 2) === 0 &&
  16760. HINTING_ENABLED) {
  16761. program.properties.privateData[token] = blueArray;
  16762. }
  16763. break;
  16764. case 'StemSnapH':
  16765. case 'StemSnapV':
  16766. program.properties.privateData[token] = this.readNumberArray();
  16767. break;
  16768. case 'StdHW':
  16769. case 'StdVW':
  16770. program.properties.privateData[token] =
  16771. this.readNumberArray()[0];
  16772. break;
  16773. case 'BlueShift':
  16774. case 'lenIV':
  16775. case 'BlueFuzz':
  16776. case 'BlueScale':
  16777. case 'LanguageGroup':
  16778. case 'ExpansionFactor':
  16779. program.properties.privateData[token] = this.readNumber();
  16780. break;
  16781. case 'ForceBold':
  16782. program.properties.privateData[token] = this.readBoolean();
  16783. break;
  16784. }
  16785. }
  16786. for (var i = 0; i < charstrings.length; i++) {
  16787. glyph = charstrings[i].glyph;
  16788. encoded = charstrings[i].encoded;
  16789. var charString = new Type1CharString();
  16790. var error = charString.convert(encoded, subrs);
  16791. var output = charString.output;
  16792. if (error) {
  16793. // It seems when FreeType encounters an error while evaluating a glyph
  16794. // that it completely ignores the glyph so we'll mimic that behaviour
  16795. // here and put an endchar to make the validator happy.
  16796. output = [14];
  16797. }
  16798. program.charstrings.push({
  16799. glyphName: glyph,
  16800. charstring: output,
  16801. width: charString.width,
  16802. lsb: charString.lsb,
  16803. seac: charString.seac
  16804. });
  16805. }
  16806. return program;
  16807. },
  16808. extractFontHeader: function Type1Parser_extractFontHeader(properties) {
  16809. var token;
  16810. while ((token = this.getToken()) !== null) {
  16811. if (token !== '/') {
  16812. continue;
  16813. }
  16814. token = this.getToken();
  16815. switch (token) {
  16816. case 'FontMatrix':
  16817. var matrix = this.readNumberArray();
  16818. properties.fontMatrix = matrix;
  16819. break;
  16820. case 'Encoding':
  16821. var encodingArg = this.getToken();
  16822. var encoding;
  16823. if (!/^\d+$/.test(encodingArg)) {
  16824. // encoding name is specified
  16825. encoding = Encodings[encodingArg];
  16826. } else {
  16827. encoding = [];
  16828. var size = parseInt(encodingArg, 10) | 0;
  16829. this.getToken(); // read in 'array'
  16830. for (var j = 0; j < size; j++) {
  16831. token = this.getToken();
  16832. // skipping till first dup or def (e.g. ignoring for statement)
  16833. while (token !== 'dup' && token !== 'def') {
  16834. token = this.getToken();
  16835. if (token === null) {
  16836. return; // invalid header
  16837. }
  16838. }
  16839. if (token === 'def') {
  16840. break; // read all array data
  16841. }
  16842. var index = this.readInt();
  16843. this.getToken(); // read in '/'
  16844. var glyph = this.getToken();
  16845. encoding[index] = glyph;
  16846. this.getToken(); // read the in 'put'
  16847. }
  16848. }
  16849. properties.builtInEncoding = encoding;
  16850. break;
  16851. case 'FontBBox':
  16852. var fontBBox = this.readNumberArray();
  16853. // adjusting ascent/descent
  16854. properties.ascent = fontBBox[3];
  16855. properties.descent = fontBBox[1];
  16856. properties.ascentScaled = true;
  16857. break;
  16858. }
  16859. }
  16860. }
  16861. };
  16862. return Type1Parser;
  16863. })();
  16864. /**
  16865. * The CFF class takes a Type1 file and wrap it into a
  16866. * 'Compact Font Format' which itself embed Type2 charstrings.
  16867. */
  16868. var CFFStandardStrings = [
  16869. '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  16870. 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus',
  16871. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
  16872. 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',
  16873. 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
  16874. 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
  16875. 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright', 'asciicircum',
  16876. 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
  16877. 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
  16878. 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
  16879. 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  16880. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  16881. 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
  16882. 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase', 'quotedblbase',
  16883. 'quotedblright', 'guillemotright', 'ellipsis', 'perthousand', 'questiondown',
  16884. 'grave', 'acute', 'circumflex', 'tilde', 'macron', 'breve', 'dotaccent',
  16885. 'dieresis', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron', 'emdash',
  16886. 'AE', 'ordfeminine', 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae',
  16887. 'dotlessi', 'lslash', 'oslash', 'oe', 'germandbls', 'onesuperior',
  16888. 'logicalnot', 'mu', 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn',
  16889. 'onequarter', 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters',
  16890. 'twosuperior', 'registered', 'minus', 'eth', 'multiply', 'threesuperior',
  16891. 'copyright', 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring',
  16892. 'Atilde', 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave',
  16893. 'Iacute', 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute',
  16894. 'Ocircumflex', 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute',
  16895. 'Ucircumflex', 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron',
  16896. 'aacute', 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde',
  16897. 'ccedilla', 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute',
  16898. 'icircumflex', 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex',
  16899. 'odieresis', 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex',
  16900. 'udieresis', 'ugrave', 'yacute', 'ydieresis', 'zcaron', 'exclamsmall',
  16901. 'Hungarumlautsmall', 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall',
  16902. 'Acutesmall', 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  16903. 'onedotenleader', 'zerooldstyle', 'oneoldstyle', 'twooldstyle',
  16904. 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle',
  16905. 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'commasuperior',
  16906. 'threequartersemdash', 'periodsuperior', 'questionsmall', 'asuperior',
  16907. 'bsuperior', 'centsuperior', 'dsuperior', 'esuperior', 'isuperior',
  16908. 'lsuperior', 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  16909. 'tsuperior', 'ff', 'ffi', 'ffl', 'parenleftinferior', 'parenrightinferior',
  16910. 'Circumflexsmall', 'hyphensuperior', 'Gravesmall', 'Asmall', 'Bsmall',
  16911. 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall',
  16912. 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall',
  16913. 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
  16914. 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah',
  16915. 'Tildesmall', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall',
  16916. 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall', 'Caronsmall',
  16917. 'Dotaccentsmall', 'Macronsmall', 'figuredash', 'hypheninferior',
  16918. 'Ogoneksmall', 'Ringsmall', 'Cedillasmall', 'questiondownsmall', 'oneeighth',
  16919. 'threeeighths', 'fiveeighths', 'seveneighths', 'onethird', 'twothirds',
  16920. 'zerosuperior', 'foursuperior', 'fivesuperior', 'sixsuperior',
  16921. 'sevensuperior', 'eightsuperior', 'ninesuperior', 'zeroinferior',
  16922. 'oneinferior', 'twoinferior', 'threeinferior', 'fourinferior',
  16923. 'fiveinferior', 'sixinferior', 'seveninferior', 'eightinferior',
  16924. 'nineinferior', 'centinferior', 'dollarinferior', 'periodinferior',
  16925. 'commainferior', 'Agravesmall', 'Aacutesmall', 'Acircumflexsmall',
  16926. 'Atildesmall', 'Adieresissmall', 'Aringsmall', 'AEsmall', 'Ccedillasmall',
  16927. 'Egravesmall', 'Eacutesmall', 'Ecircumflexsmall', 'Edieresissmall',
  16928. 'Igravesmall', 'Iacutesmall', 'Icircumflexsmall', 'Idieresissmall',
  16929. 'Ethsmall', 'Ntildesmall', 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall',
  16930. 'Otildesmall', 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall',
  16931. 'Uacutesmall', 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall',
  16932. 'Thornsmall', 'Ydieresissmall', '001.000', '001.001', '001.002', '001.003',
  16933. 'Black', 'Bold', 'Book', 'Light', 'Medium', 'Regular', 'Roman', 'Semibold'
  16934. ];
  16935. // Type1Font is also a CIDFontType0.
  16936. var Type1Font = function Type1Font(name, file, properties) {
  16937. // Some bad generators embed pfb file as is, we have to strip 6-byte headers.
  16938. // Also, length1 and length2 might be off by 6 bytes as well.
  16939. // http://www.math.ubc.ca/~cass/piscript/type1.pdf
  16940. var PFB_HEADER_SIZE = 6;
  16941. var headerBlockLength = properties.length1;
  16942. var eexecBlockLength = properties.length2;
  16943. var pfbHeader = file.peekBytes(PFB_HEADER_SIZE);
  16944. var pfbHeaderPresent = pfbHeader[0] == 0x80 && pfbHeader[1] == 0x01;
  16945. if (pfbHeaderPresent) {
  16946. file.skip(PFB_HEADER_SIZE);
  16947. headerBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  16948. (pfbHeader[3] << 8) | pfbHeader[2];
  16949. }
  16950. // Get the data block containing glyphs and subrs informations
  16951. var headerBlock = new Stream(file.getBytes(headerBlockLength));
  16952. var headerBlockParser = new Type1Parser(headerBlock);
  16953. headerBlockParser.extractFontHeader(properties);
  16954. if (pfbHeaderPresent) {
  16955. pfbHeader = file.getBytes(PFB_HEADER_SIZE);
  16956. eexecBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  16957. (pfbHeader[3] << 8) | pfbHeader[2];
  16958. }
  16959. // Decrypt the data blocks and retrieve it's content
  16960. var eexecBlock = new Stream(file.getBytes(eexecBlockLength));
  16961. var eexecBlockParser = new Type1Parser(eexecBlock, true);
  16962. var data = eexecBlockParser.extractFontProgram();
  16963. for (var info in data.properties) {
  16964. properties[info] = data.properties[info];
  16965. }
  16966. var charstrings = data.charstrings;
  16967. var type2Charstrings = this.getType2Charstrings(charstrings);
  16968. var subrs = this.getType2Subrs(data.subrs);
  16969. this.charstrings = charstrings;
  16970. this.data = this.wrap(name, type2Charstrings, this.charstrings,
  16971. subrs, properties);
  16972. this.seacs = this.getSeacs(data.charstrings);
  16973. };
  16974. Type1Font.prototype = {
  16975. get numGlyphs() {
  16976. return this.charstrings.length + 1;
  16977. },
  16978. getCharset: function Type1Font_getCharset() {
  16979. var charset = ['.notdef'];
  16980. var charstrings = this.charstrings;
  16981. for (var glyphId = 0; glyphId < charstrings.length; glyphId++) {
  16982. charset.push(charstrings[glyphId].glyphName);
  16983. }
  16984. return charset;
  16985. },
  16986. getGlyphMapping: function Type1Font_getGlyphMapping(properties) {
  16987. var charstrings = this.charstrings;
  16988. var glyphNames = ['.notdef'], glyphId;
  16989. for (glyphId = 0; glyphId < charstrings.length; glyphId++) {
  16990. glyphNames.push(charstrings[glyphId].glyphName);
  16991. }
  16992. var encoding = properties.builtInEncoding;
  16993. if (encoding) {
  16994. var builtInEncoding = {};
  16995. for (var charCode in encoding) {
  16996. glyphId = glyphNames.indexOf(encoding[charCode]);
  16997. if (glyphId >= 0) {
  16998. builtInEncoding[charCode] = glyphId;
  16999. }
  17000. }
  17001. }
  17002. return type1FontGlyphMapping(properties, builtInEncoding, glyphNames);
  17003. },
  17004. getSeacs: function Type1Font_getSeacs(charstrings) {
  17005. var i, ii;
  17006. var seacMap = [];
  17007. for (i = 0, ii = charstrings.length; i < ii; i++) {
  17008. var charstring = charstrings[i];
  17009. if (charstring.seac) {
  17010. // Offset by 1 for .notdef
  17011. seacMap[i + 1] = charstring.seac;
  17012. }
  17013. }
  17014. return seacMap;
  17015. },
  17016. getType2Charstrings: function Type1Font_getType2Charstrings(
  17017. type1Charstrings) {
  17018. var type2Charstrings = [];
  17019. for (var i = 0, ii = type1Charstrings.length; i < ii; i++) {
  17020. type2Charstrings.push(type1Charstrings[i].charstring);
  17021. }
  17022. return type2Charstrings;
  17023. },
  17024. getType2Subrs: function Type1Font_getType2Subrs(type1Subrs) {
  17025. var bias = 0;
  17026. var count = type1Subrs.length;
  17027. if (count < 1133) {
  17028. bias = 107;
  17029. } else if (count < 33769) {
  17030. bias = 1131;
  17031. } else {
  17032. bias = 32768;
  17033. }
  17034. // Add a bunch of empty subrs to deal with the Type2 bias
  17035. var type2Subrs = [];
  17036. var i;
  17037. for (i = 0; i < bias; i++) {
  17038. type2Subrs.push([0x0B]);
  17039. }
  17040. for (i = 0; i < count; i++) {
  17041. type2Subrs.push(type1Subrs[i]);
  17042. }
  17043. return type2Subrs;
  17044. },
  17045. wrap: function Type1Font_wrap(name, glyphs, charstrings, subrs, properties) {
  17046. var cff = new CFF();
  17047. cff.header = new CFFHeader(1, 0, 4, 4);
  17048. cff.names = [name];
  17049. var topDict = new CFFTopDict();
  17050. // CFF strings IDs 0...390 are predefined names, so refering
  17051. // to entries in our own String INDEX starts at SID 391.
  17052. topDict.setByName('version', 391);
  17053. topDict.setByName('Notice', 392);
  17054. topDict.setByName('FullName', 393);
  17055. topDict.setByName('FamilyName', 394);
  17056. topDict.setByName('Weight', 395);
  17057. topDict.setByName('Encoding', null); // placeholder
  17058. topDict.setByName('FontMatrix', properties.fontMatrix);
  17059. topDict.setByName('FontBBox', properties.bbox);
  17060. topDict.setByName('charset', null); // placeholder
  17061. topDict.setByName('CharStrings', null); // placeholder
  17062. topDict.setByName('Private', null); // placeholder
  17063. cff.topDict = topDict;
  17064. var strings = new CFFStrings();
  17065. strings.add('Version 0.11'); // Version
  17066. strings.add('See original notice'); // Notice
  17067. strings.add(name); // FullName
  17068. strings.add(name); // FamilyName
  17069. strings.add('Medium'); // Weight
  17070. cff.strings = strings;
  17071. cff.globalSubrIndex = new CFFIndex();
  17072. var count = glyphs.length;
  17073. var charsetArray = [0];
  17074. var i, ii;
  17075. for (i = 0; i < count; i++) {
  17076. var index = CFFStandardStrings.indexOf(charstrings[i].glyphName);
  17077. // TODO: Insert the string and correctly map it. Previously it was
  17078. // thought mapping names that aren't in the standard strings to .notdef
  17079. // was fine, however in issue818 when mapping them all to .notdef the
  17080. // adieresis glyph no longer worked.
  17081. if (index == -1) {
  17082. index = 0;
  17083. }
  17084. charsetArray.push((index >> 8) & 0xff, index & 0xff);
  17085. }
  17086. cff.charset = new CFFCharset(false, 0, [], charsetArray);
  17087. var charStringsIndex = new CFFIndex();
  17088. charStringsIndex.add([0x8B, 0x0E]); // .notdef
  17089. for (i = 0; i < count; i++) {
  17090. charStringsIndex.add(glyphs[i]);
  17091. }
  17092. cff.charStrings = charStringsIndex;
  17093. var privateDict = new CFFPrivateDict();
  17094. privateDict.setByName('Subrs', null); // placeholder
  17095. var fields = [
  17096. 'BlueValues',
  17097. 'OtherBlues',
  17098. 'FamilyBlues',
  17099. 'FamilyOtherBlues',
  17100. 'StemSnapH',
  17101. 'StemSnapV',
  17102. 'BlueShift',
  17103. 'BlueFuzz',
  17104. 'BlueScale',
  17105. 'LanguageGroup',
  17106. 'ExpansionFactor',
  17107. 'ForceBold',
  17108. 'StdHW',
  17109. 'StdVW'
  17110. ];
  17111. for (i = 0, ii = fields.length; i < ii; i++) {
  17112. var field = fields[i];
  17113. if (!properties.privateData.hasOwnProperty(field)) {
  17114. continue;
  17115. }
  17116. var value = properties.privateData[field];
  17117. if (isArray(value)) {
  17118. // All of the private dictionary array data in CFF must be stored as
  17119. // "delta-encoded" numbers.
  17120. for (var j = value.length - 1; j > 0; j--) {
  17121. value[j] -= value[j - 1]; // ... difference from previous value
  17122. }
  17123. }
  17124. privateDict.setByName(field, value);
  17125. }
  17126. cff.topDict.privateDict = privateDict;
  17127. var subrIndex = new CFFIndex();
  17128. for (i = 0, ii = subrs.length; i < ii; i++) {
  17129. subrIndex.add(subrs[i]);
  17130. }
  17131. privateDict.subrsIndex = subrIndex;
  17132. var compiler = new CFFCompiler(cff);
  17133. return compiler.compile();
  17134. }
  17135. };
  17136. var CFFFont = (function CFFFontClosure() {
  17137. function CFFFont(file, properties) {
  17138. this.properties = properties;
  17139. var parser = new CFFParser(file, properties);
  17140. this.cff = parser.parse();
  17141. var compiler = new CFFCompiler(this.cff);
  17142. this.seacs = this.cff.seacs;
  17143. try {
  17144. this.data = compiler.compile();
  17145. } catch (e) {
  17146. warn('Failed to compile font ' + properties.loadedName);
  17147. // There may have just been an issue with the compiler, set the data
  17148. // anyway and hope the font loaded.
  17149. this.data = file;
  17150. }
  17151. }
  17152. CFFFont.prototype = {
  17153. get numGlyphs() {
  17154. return this.cff.charStrings.count;
  17155. },
  17156. getCharset: function CFFFont_getCharset() {
  17157. return this.cff.charset.charset;
  17158. },
  17159. getGlyphMapping: function CFFFont_getGlyphMapping() {
  17160. var cff = this.cff;
  17161. var properties = this.properties;
  17162. var charsets = cff.charset.charset;
  17163. var charCodeToGlyphId;
  17164. var glyphId;
  17165. if (properties.composite) {
  17166. charCodeToGlyphId = Object.create(null);
  17167. if (cff.isCIDFont) {
  17168. // If the font is actually a CID font then we should use the charset
  17169. // to map CIDs to GIDs.
  17170. for (glyphId = 0; glyphId < charsets.length; glyphId++) {
  17171. var cidString = String.fromCharCode(charsets[glyphId]);
  17172. var charCode = properties.cMap.charCodeOf(cidString);
  17173. charCodeToGlyphId[charCode] = glyphId;
  17174. }
  17175. } else {
  17176. // If it is NOT actually a CID font then CIDs should be mapped
  17177. // directly to GIDs.
  17178. for (glyphId = 0; glyphId < cff.charStrings.count; glyphId++) {
  17179. charCodeToGlyphId[glyphId] = glyphId;
  17180. }
  17181. }
  17182. return charCodeToGlyphId;
  17183. }
  17184. var encoding = cff.encoding ? cff.encoding.encoding : null;
  17185. charCodeToGlyphId = type1FontGlyphMapping(properties, encoding, charsets);
  17186. return charCodeToGlyphId;
  17187. }
  17188. };
  17189. return CFFFont;
  17190. })();
  17191. var CFFParser = (function CFFParserClosure() {
  17192. var CharstringValidationData = [
  17193. null,
  17194. { id: 'hstem', min: 2, resetStack: true, stem: true },
  17195. null,
  17196. { id: 'vstem', min: 2, resetStack: true, stem: true },
  17197. { id: 'vmoveto', min: 1, resetStack: true },
  17198. { id: 'rlineto', min: 2, resetStack: true },
  17199. { id: 'hlineto', min: 1, resetStack: true },
  17200. { id: 'vlineto', min: 1, resetStack: true },
  17201. { id: 'rrcurveto', min: 6, resetStack: true },
  17202. null,
  17203. { id: 'callsubr', min: 1, undefStack: true },
  17204. { id: 'return', min: 0, undefStack: true },
  17205. null, // 12
  17206. null,
  17207. null, // endchar
  17208. null,
  17209. null,
  17210. null,
  17211. { id: 'hstemhm', min: 2, resetStack: true, stem: true },
  17212. null, // hintmask
  17213. null, // cntrmask
  17214. { id: 'rmoveto', min: 2, resetStack: true },
  17215. { id: 'hmoveto', min: 1, resetStack: true },
  17216. { id: 'vstemhm', min: 2, resetStack: true, stem: true },
  17217. { id: 'rcurveline', min: 8, resetStack: true },
  17218. { id: 'rlinecurve', min: 8, resetStack: true },
  17219. { id: 'vvcurveto', min: 4, resetStack: true },
  17220. { id: 'hhcurveto', min: 4, resetStack: true },
  17221. null, // shortint
  17222. { id: 'callgsubr', min: 1, undefStack: true },
  17223. { id: 'vhcurveto', min: 4, resetStack: true },
  17224. { id: 'hvcurveto', min: 4, resetStack: true }
  17225. ];
  17226. var CharstringValidationData12 = [
  17227. null,
  17228. null,
  17229. null,
  17230. { id: 'and', min: 2, stackDelta: -1 },
  17231. { id: 'or', min: 2, stackDelta: -1 },
  17232. { id: 'not', min: 1, stackDelta: 0 },
  17233. null,
  17234. null,
  17235. null,
  17236. { id: 'abs', min: 1, stackDelta: 0 },
  17237. { id: 'add', min: 2, stackDelta: -1,
  17238. stackFn: function stack_div(stack, index) {
  17239. stack[index - 2] = stack[index - 2] + stack[index - 1];
  17240. }
  17241. },
  17242. { id: 'sub', min: 2, stackDelta: -1,
  17243. stackFn: function stack_div(stack, index) {
  17244. stack[index - 2] = stack[index - 2] - stack[index - 1];
  17245. }
  17246. },
  17247. { id: 'div', min: 2, stackDelta: -1,
  17248. stackFn: function stack_div(stack, index) {
  17249. stack[index - 2] = stack[index - 2] / stack[index - 1];
  17250. }
  17251. },
  17252. null,
  17253. { id: 'neg', min: 1, stackDelta: 0,
  17254. stackFn: function stack_div(stack, index) {
  17255. stack[index - 1] = -stack[index - 1];
  17256. }
  17257. },
  17258. { id: 'eq', min: 2, stackDelta: -1 },
  17259. null,
  17260. null,
  17261. { id: 'drop', min: 1, stackDelta: -1 },
  17262. null,
  17263. { id: 'put', min: 2, stackDelta: -2 },
  17264. { id: 'get', min: 1, stackDelta: 0 },
  17265. { id: 'ifelse', min: 4, stackDelta: -3 },
  17266. { id: 'random', min: 0, stackDelta: 1 },
  17267. { id: 'mul', min: 2, stackDelta: -1,
  17268. stackFn: function stack_div(stack, index) {
  17269. stack[index - 2] = stack[index - 2] * stack[index - 1];
  17270. }
  17271. },
  17272. null,
  17273. { id: 'sqrt', min: 1, stackDelta: 0 },
  17274. { id: 'dup', min: 1, stackDelta: 1 },
  17275. { id: 'exch', min: 2, stackDelta: 0 },
  17276. { id: 'index', min: 2, stackDelta: 0 },
  17277. { id: 'roll', min: 3, stackDelta: -2 },
  17278. null,
  17279. null,
  17280. null,
  17281. { id: 'hflex', min: 7, resetStack: true },
  17282. { id: 'flex', min: 13, resetStack: true },
  17283. { id: 'hflex1', min: 9, resetStack: true },
  17284. { id: 'flex1', min: 11, resetStack: true }
  17285. ];
  17286. function CFFParser(file, properties) {
  17287. this.bytes = file.getBytes();
  17288. this.properties = properties;
  17289. }
  17290. CFFParser.prototype = {
  17291. parse: function CFFParser_parse() {
  17292. var properties = this.properties;
  17293. var cff = new CFF();
  17294. this.cff = cff;
  17295. // The first five sections must be in order, all the others are reached
  17296. // via offsets contained in one of the below.
  17297. var header = this.parseHeader();
  17298. var nameIndex = this.parseIndex(header.endPos);
  17299. var topDictIndex = this.parseIndex(nameIndex.endPos);
  17300. var stringIndex = this.parseIndex(topDictIndex.endPos);
  17301. var globalSubrIndex = this.parseIndex(stringIndex.endPos);
  17302. var topDictParsed = this.parseDict(topDictIndex.obj.get(0));
  17303. var topDict = this.createDict(CFFTopDict, topDictParsed, cff.strings);
  17304. cff.header = header.obj;
  17305. cff.names = this.parseNameIndex(nameIndex.obj);
  17306. cff.strings = this.parseStringIndex(stringIndex.obj);
  17307. cff.topDict = topDict;
  17308. cff.globalSubrIndex = globalSubrIndex.obj;
  17309. this.parsePrivateDict(cff.topDict);
  17310. cff.isCIDFont = topDict.hasName('ROS');
  17311. var charStringOffset = topDict.getByName('CharStrings');
  17312. var charStringsAndSeacs = this.parseCharStrings(charStringOffset);
  17313. cff.charStrings = charStringsAndSeacs.charStrings;
  17314. cff.seacs = charStringsAndSeacs.seacs;
  17315. var fontMatrix = topDict.getByName('FontMatrix');
  17316. if (fontMatrix) {
  17317. properties.fontMatrix = fontMatrix;
  17318. }
  17319. var fontBBox = topDict.getByName('FontBBox');
  17320. if (fontBBox) {
  17321. // adjusting ascent/descent
  17322. properties.ascent = fontBBox[3];
  17323. properties.descent = fontBBox[1];
  17324. properties.ascentScaled = true;
  17325. }
  17326. var charset, encoding;
  17327. if (cff.isCIDFont) {
  17328. var fdArrayIndex = this.parseIndex(topDict.getByName('FDArray')).obj;
  17329. for (var i = 0, ii = fdArrayIndex.count; i < ii; ++i) {
  17330. var dictRaw = fdArrayIndex.get(i);
  17331. var fontDict = this.createDict(CFFTopDict, this.parseDict(dictRaw),
  17332. cff.strings);
  17333. this.parsePrivateDict(fontDict);
  17334. cff.fdArray.push(fontDict);
  17335. }
  17336. // cid fonts don't have an encoding
  17337. encoding = null;
  17338. charset = this.parseCharsets(topDict.getByName('charset'),
  17339. cff.charStrings.count, cff.strings, true);
  17340. cff.fdSelect = this.parseFDSelect(topDict.getByName('FDSelect'),
  17341. cff.charStrings.count);
  17342. } else {
  17343. charset = this.parseCharsets(topDict.getByName('charset'),
  17344. cff.charStrings.count, cff.strings, false);
  17345. encoding = this.parseEncoding(topDict.getByName('Encoding'),
  17346. properties,
  17347. cff.strings, charset.charset);
  17348. }
  17349. cff.charset = charset;
  17350. cff.encoding = encoding;
  17351. return cff;
  17352. },
  17353. parseHeader: function CFFParser_parseHeader() {
  17354. var bytes = this.bytes;
  17355. var bytesLength = bytes.length;
  17356. var offset = 0;
  17357. // Prevent an infinite loop, by checking that the offset is within the
  17358. // bounds of the bytes array. Necessary in empty, or invalid, font files.
  17359. while (offset < bytesLength && bytes[offset] !== 1) {
  17360. ++offset;
  17361. }
  17362. if (offset >= bytesLength) {
  17363. error('Invalid CFF header');
  17364. } else if (offset !== 0) {
  17365. info('cff data is shifted');
  17366. bytes = bytes.subarray(offset);
  17367. this.bytes = bytes;
  17368. }
  17369. var major = bytes[0];
  17370. var minor = bytes[1];
  17371. var hdrSize = bytes[2];
  17372. var offSize = bytes[3];
  17373. var header = new CFFHeader(major, minor, hdrSize, offSize);
  17374. return { obj: header, endPos: hdrSize };
  17375. },
  17376. parseDict: function CFFParser_parseDict(dict) {
  17377. var pos = 0;
  17378. function parseOperand() {
  17379. var value = dict[pos++];
  17380. if (value === 30) {
  17381. return parseFloatOperand(pos);
  17382. } else if (value === 28) {
  17383. value = dict[pos++];
  17384. value = ((value << 24) | (dict[pos++] << 16)) >> 16;
  17385. return value;
  17386. } else if (value === 29) {
  17387. value = dict[pos++];
  17388. value = (value << 8) | dict[pos++];
  17389. value = (value << 8) | dict[pos++];
  17390. value = (value << 8) | dict[pos++];
  17391. return value;
  17392. } else if (value >= 32 && value <= 246) {
  17393. return value - 139;
  17394. } else if (value >= 247 && value <= 250) {
  17395. return ((value - 247) * 256) + dict[pos++] + 108;
  17396. } else if (value >= 251 && value <= 254) {
  17397. return -((value - 251) * 256) - dict[pos++] - 108;
  17398. } else {
  17399. error('255 is not a valid DICT command');
  17400. }
  17401. return -1;
  17402. }
  17403. function parseFloatOperand() {
  17404. var str = '';
  17405. var eof = 15;
  17406. var lookup = ['0', '1', '2', '3', '4', '5', '6', '7', '8',
  17407. '9', '.', 'E', 'E-', null, '-'];
  17408. var length = dict.length;
  17409. while (pos < length) {
  17410. var b = dict[pos++];
  17411. var b1 = b >> 4;
  17412. var b2 = b & 15;
  17413. if (b1 == eof) {
  17414. break;
  17415. }
  17416. str += lookup[b1];
  17417. if (b2 == eof) {
  17418. break;
  17419. }
  17420. str += lookup[b2];
  17421. }
  17422. return parseFloat(str);
  17423. }
  17424. var operands = [];
  17425. var entries = [];
  17426. pos = 0;
  17427. var end = dict.length;
  17428. while (pos < end) {
  17429. var b = dict[pos];
  17430. if (b <= 21) {
  17431. if (b === 12) {
  17432. b = (b << 8) | dict[++pos];
  17433. }
  17434. entries.push([b, operands]);
  17435. operands = [];
  17436. ++pos;
  17437. } else {
  17438. operands.push(parseOperand());
  17439. }
  17440. }
  17441. return entries;
  17442. },
  17443. parseIndex: function CFFParser_parseIndex(pos) {
  17444. var cffIndex = new CFFIndex();
  17445. var bytes = this.bytes;
  17446. var count = (bytes[pos++] << 8) | bytes[pos++];
  17447. var offsets = [];
  17448. var end = pos;
  17449. var i, ii;
  17450. if (count !== 0) {
  17451. var offsetSize = bytes[pos++];
  17452. // add 1 for offset to determine size of last object
  17453. var startPos = pos + ((count + 1) * offsetSize) - 1;
  17454. for (i = 0, ii = count + 1; i < ii; ++i) {
  17455. var offset = 0;
  17456. for (var j = 0; j < offsetSize; ++j) {
  17457. offset <<= 8;
  17458. offset += bytes[pos++];
  17459. }
  17460. offsets.push(startPos + offset);
  17461. }
  17462. end = offsets[count];
  17463. }
  17464. for (i = 0, ii = offsets.length - 1; i < ii; ++i) {
  17465. var offsetStart = offsets[i];
  17466. var offsetEnd = offsets[i + 1];
  17467. cffIndex.add(bytes.subarray(offsetStart, offsetEnd));
  17468. }
  17469. return {obj: cffIndex, endPos: end};
  17470. },
  17471. parseNameIndex: function CFFParser_parseNameIndex(index) {
  17472. var names = [];
  17473. for (var i = 0, ii = index.count; i < ii; ++i) {
  17474. var name = index.get(i);
  17475. // OTS doesn't allow names to be over 127 characters.
  17476. var length = Math.min(name.length, 127);
  17477. var data = [];
  17478. // OTS also only permits certain characters in the name.
  17479. for (var j = 0; j < length; ++j) {
  17480. var c = name[j];
  17481. if (j === 0 && c === 0) {
  17482. data[j] = c;
  17483. continue;
  17484. }
  17485. if ((c < 33 || c > 126) || c === 91 /* [ */ || c === 93 /* ] */ ||
  17486. c === 40 /* ( */ || c === 41 /* ) */ || c === 123 /* { */ ||
  17487. c === 125 /* } */ || c === 60 /* < */ || c === 62 /* > */ ||
  17488. c === 47 /* / */ || c === 37 /* % */ || c === 35 /* # */) {
  17489. data[j] = 95;
  17490. continue;
  17491. }
  17492. data[j] = c;
  17493. }
  17494. names.push(bytesToString(data));
  17495. }
  17496. return names;
  17497. },
  17498. parseStringIndex: function CFFParser_parseStringIndex(index) {
  17499. var strings = new CFFStrings();
  17500. for (var i = 0, ii = index.count; i < ii; ++i) {
  17501. var data = index.get(i);
  17502. strings.add(bytesToString(data));
  17503. }
  17504. return strings;
  17505. },
  17506. createDict: function CFFParser_createDict(Type, dict, strings) {
  17507. var cffDict = new Type(strings);
  17508. for (var i = 0, ii = dict.length; i < ii; ++i) {
  17509. var pair = dict[i];
  17510. var key = pair[0];
  17511. var value = pair[1];
  17512. cffDict.setByKey(key, value);
  17513. }
  17514. return cffDict;
  17515. },
  17516. parseCharStrings: function CFFParser_parseCharStrings(charStringOffset) {
  17517. var charStrings = this.parseIndex(charStringOffset).obj;
  17518. var seacs = [];
  17519. var count = charStrings.count;
  17520. for (var i = 0; i < count; i++) {
  17521. var charstring = charStrings.get(i);
  17522. var stackSize = 0;
  17523. var stack = [];
  17524. var undefStack = true;
  17525. var hints = 0;
  17526. var valid = true;
  17527. var data = charstring;
  17528. var length = data.length;
  17529. for (var j = 0; j < length;) {
  17530. var value = data[j++];
  17531. var validationCommand = null;
  17532. if (value == 12) {
  17533. var q = data[j++];
  17534. if (q === 0) {
  17535. // The CFF specification state that the 'dotsection' command
  17536. // (12, 0) is deprecated and treated as a no-op, but all Type2
  17537. // charstrings processors should support them. Unfortunately
  17538. // the font sanitizer don't. As a workaround the sequence (12, 0)
  17539. // is replaced by a useless (0, hmoveto).
  17540. data[j - 2] = 139;
  17541. data[j - 1] = 22;
  17542. stackSize = 0;
  17543. } else {
  17544. validationCommand = CharstringValidationData12[q];
  17545. }
  17546. } else if (value === 28) { // number (16 bit)
  17547. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16)) >> 16;
  17548. j += 2;
  17549. stackSize++;
  17550. } else if (value == 14) {
  17551. if (stackSize >= 4) {
  17552. stackSize -= 4;
  17553. if (SEAC_ANALYSIS_ENABLED) {
  17554. seacs[i] = stack.slice(stackSize, stackSize + 4);
  17555. valid = false;
  17556. }
  17557. }
  17558. } else if (value >= 32 && value <= 246) { // number
  17559. stack[stackSize] = value - 139;
  17560. stackSize++;
  17561. } else if (value >= 247 && value <= 254) { // number (+1 bytes)
  17562. stack[stackSize] = (value < 251 ?
  17563. ((value - 247) << 8) + data[j] + 108 :
  17564. -((value - 251) << 8) - data[j] - 108);
  17565. j++;
  17566. stackSize++;
  17567. } else if (value == 255) { // number (32 bit)
  17568. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16) |
  17569. (data[j + 2] << 8) | data[j + 3]) / 65536;
  17570. j += 4;
  17571. stackSize++;
  17572. } else if (value == 19 || value == 20) {
  17573. hints += stackSize >> 1;
  17574. j += (hints + 7) >> 3; // skipping right amount of hints flag data
  17575. stackSize = 0;
  17576. } else {
  17577. validationCommand = CharstringValidationData[value];
  17578. }
  17579. if (validationCommand) {
  17580. if (validationCommand.stem) {
  17581. hints += stackSize >> 1;
  17582. }
  17583. if ('min' in validationCommand) {
  17584. if (!undefStack && stackSize < validationCommand.min) {
  17585. warn('Not enough parameters for ' + validationCommand.id +
  17586. '; actual: ' + stackSize +
  17587. ', expected: ' + validationCommand.min);
  17588. valid = false;
  17589. break;
  17590. }
  17591. }
  17592. if ('stackDelta' in validationCommand) {
  17593. if ('stackFn' in validationCommand) {
  17594. validationCommand.stackFn(stack, stackSize);
  17595. }
  17596. stackSize += validationCommand.stackDelta;
  17597. } else if (validationCommand.resetStack) {
  17598. stackSize = 0;
  17599. undefStack = false;
  17600. } else if (validationCommand.undefStack) {
  17601. stackSize = 0;
  17602. undefStack = true;
  17603. }
  17604. }
  17605. }
  17606. if (!valid) {
  17607. // resetting invalid charstring to single 'endchar'
  17608. charStrings.set(i, new Uint8Array([14]));
  17609. }
  17610. }
  17611. return { charStrings: charStrings, seacs: seacs };
  17612. },
  17613. emptyPrivateDictionary:
  17614. function CFFParser_emptyPrivateDictionary(parentDict) {
  17615. var privateDict = this.createDict(CFFPrivateDict, [],
  17616. parentDict.strings);
  17617. parentDict.setByKey(18, [0, 0]);
  17618. parentDict.privateDict = privateDict;
  17619. },
  17620. parsePrivateDict: function CFFParser_parsePrivateDict(parentDict) {
  17621. // no private dict, do nothing
  17622. if (!parentDict.hasName('Private')) {
  17623. this.emptyPrivateDictionary(parentDict);
  17624. return;
  17625. }
  17626. var privateOffset = parentDict.getByName('Private');
  17627. // make sure the params are formatted correctly
  17628. if (!isArray(privateOffset) || privateOffset.length !== 2) {
  17629. parentDict.removeByName('Private');
  17630. return;
  17631. }
  17632. var size = privateOffset[0];
  17633. var offset = privateOffset[1];
  17634. // remove empty dicts or ones that refer to invalid location
  17635. if (size === 0 || offset >= this.bytes.length) {
  17636. this.emptyPrivateDictionary(parentDict);
  17637. return;
  17638. }
  17639. var privateDictEnd = offset + size;
  17640. var dictData = this.bytes.subarray(offset, privateDictEnd);
  17641. var dict = this.parseDict(dictData);
  17642. var privateDict = this.createDict(CFFPrivateDict, dict,
  17643. parentDict.strings);
  17644. parentDict.privateDict = privateDict;
  17645. // Parse the Subrs index also since it's relative to the private dict.
  17646. if (!privateDict.getByName('Subrs')) {
  17647. return;
  17648. }
  17649. var subrsOffset = privateDict.getByName('Subrs');
  17650. var relativeOffset = offset + subrsOffset;
  17651. // Validate the offset.
  17652. if (subrsOffset === 0 || relativeOffset >= this.bytes.length) {
  17653. this.emptyPrivateDictionary(parentDict);
  17654. return;
  17655. }
  17656. var subrsIndex = this.parseIndex(relativeOffset);
  17657. privateDict.subrsIndex = subrsIndex.obj;
  17658. },
  17659. parseCharsets: function CFFParser_parseCharsets(pos, length, strings, cid) {
  17660. if (pos === 0) {
  17661. return new CFFCharset(true, CFFCharsetPredefinedTypes.ISO_ADOBE,
  17662. ISOAdobeCharset);
  17663. } else if (pos == 1) {
  17664. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT,
  17665. ExpertCharset);
  17666. } else if (pos == 2) {
  17667. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT_SUBSET,
  17668. ExpertSubsetCharset);
  17669. }
  17670. var bytes = this.bytes;
  17671. var start = pos;
  17672. var format = bytes[pos++];
  17673. var charset = ['.notdef'];
  17674. var id, count, i;
  17675. // subtract 1 for the .notdef glyph
  17676. length -= 1;
  17677. switch (format) {
  17678. case 0:
  17679. for (i = 0; i < length; i++) {
  17680. id = (bytes[pos++] << 8) | bytes[pos++];
  17681. charset.push(cid ? id : strings.get(id));
  17682. }
  17683. break;
  17684. case 1:
  17685. while (charset.length <= length) {
  17686. id = (bytes[pos++] << 8) | bytes[pos++];
  17687. count = bytes[pos++];
  17688. for (i = 0; i <= count; i++) {
  17689. charset.push(cid ? id++ : strings.get(id++));
  17690. }
  17691. }
  17692. break;
  17693. case 2:
  17694. while (charset.length <= length) {
  17695. id = (bytes[pos++] << 8) | bytes[pos++];
  17696. count = (bytes[pos++] << 8) | bytes[pos++];
  17697. for (i = 0; i <= count; i++) {
  17698. charset.push(cid ? id++ : strings.get(id++));
  17699. }
  17700. }
  17701. break;
  17702. default:
  17703. error('Unknown charset format');
  17704. }
  17705. // Raw won't be needed if we actually compile the charset.
  17706. var end = pos;
  17707. var raw = bytes.subarray(start, end);
  17708. return new CFFCharset(false, format, charset, raw);
  17709. },
  17710. parseEncoding: function CFFParser_parseEncoding(pos,
  17711. properties,
  17712. strings,
  17713. charset) {
  17714. var encoding = {};
  17715. var bytes = this.bytes;
  17716. var predefined = false;
  17717. var hasSupplement = false;
  17718. var format, i, ii;
  17719. var raw = null;
  17720. function readSupplement() {
  17721. var supplementsCount = bytes[pos++];
  17722. for (i = 0; i < supplementsCount; i++) {
  17723. var code = bytes[pos++];
  17724. var sid = (bytes[pos++] << 8) + (bytes[pos++] & 0xff);
  17725. encoding[code] = charset.indexOf(strings.get(sid));
  17726. }
  17727. }
  17728. if (pos === 0 || pos == 1) {
  17729. predefined = true;
  17730. format = pos;
  17731. var baseEncoding = pos ? Encodings.ExpertEncoding :
  17732. Encodings.StandardEncoding;
  17733. for (i = 0, ii = charset.length; i < ii; i++) {
  17734. var index = baseEncoding.indexOf(charset[i]);
  17735. if (index != -1) {
  17736. encoding[index] = i;
  17737. }
  17738. }
  17739. } else {
  17740. var dataStart = pos;
  17741. format = bytes[pos++];
  17742. switch (format & 0x7f) {
  17743. case 0:
  17744. var glyphsCount = bytes[pos++];
  17745. for (i = 1; i <= glyphsCount; i++) {
  17746. encoding[bytes[pos++]] = i;
  17747. }
  17748. break;
  17749. case 1:
  17750. var rangesCount = bytes[pos++];
  17751. var gid = 1;
  17752. for (i = 0; i < rangesCount; i++) {
  17753. var start = bytes[pos++];
  17754. var left = bytes[pos++];
  17755. for (var j = start; j <= start + left; j++) {
  17756. encoding[j] = gid++;
  17757. }
  17758. }
  17759. break;
  17760. default:
  17761. error('Unknow encoding format: ' + format + ' in CFF');
  17762. break;
  17763. }
  17764. var dataEnd = pos;
  17765. if (format & 0x80) {
  17766. // The font sanitizer does not support CFF encoding with a
  17767. // supplement, since the encoding is not really used to map
  17768. // between gid to glyph, let's overwrite what is declared in
  17769. // the top dictionary to let the sanitizer think the font use
  17770. // StandardEncoding, that's a lie but that's ok.
  17771. bytes[dataStart] &= 0x7f;
  17772. readSupplement();
  17773. hasSupplement = true;
  17774. }
  17775. raw = bytes.subarray(dataStart, dataEnd);
  17776. }
  17777. format = format & 0x7f;
  17778. return new CFFEncoding(predefined, format, encoding, raw);
  17779. },
  17780. parseFDSelect: function CFFParser_parseFDSelect(pos, length) {
  17781. var start = pos;
  17782. var bytes = this.bytes;
  17783. var format = bytes[pos++];
  17784. var fdSelect = [];
  17785. var i;
  17786. switch (format) {
  17787. case 0:
  17788. for (i = 0; i < length; ++i) {
  17789. var id = bytes[pos++];
  17790. fdSelect.push(id);
  17791. }
  17792. break;
  17793. case 3:
  17794. var rangesCount = (bytes[pos++] << 8) | bytes[pos++];
  17795. for (i = 0; i < rangesCount; ++i) {
  17796. var first = (bytes[pos++] << 8) | bytes[pos++];
  17797. var fdIndex = bytes[pos++];
  17798. var next = (bytes[pos] << 8) | bytes[pos + 1];
  17799. for (var j = first; j < next; ++j) {
  17800. fdSelect.push(fdIndex);
  17801. }
  17802. }
  17803. // Advance past the sentinel(next).
  17804. pos += 2;
  17805. break;
  17806. default:
  17807. error('Unknown fdselect format ' + format);
  17808. break;
  17809. }
  17810. var end = pos;
  17811. return new CFFFDSelect(fdSelect, bytes.subarray(start, end));
  17812. }
  17813. };
  17814. return CFFParser;
  17815. })();
  17816. // Compact Font Format
  17817. var CFF = (function CFFClosure() {
  17818. function CFF() {
  17819. this.header = null;
  17820. this.names = [];
  17821. this.topDict = null;
  17822. this.strings = new CFFStrings();
  17823. this.globalSubrIndex = null;
  17824. // The following could really be per font, but since we only have one font
  17825. // store them here.
  17826. this.encoding = null;
  17827. this.charset = null;
  17828. this.charStrings = null;
  17829. this.fdArray = [];
  17830. this.fdSelect = null;
  17831. this.isCIDFont = false;
  17832. }
  17833. return CFF;
  17834. })();
  17835. var CFFHeader = (function CFFHeaderClosure() {
  17836. function CFFHeader(major, minor, hdrSize, offSize) {
  17837. this.major = major;
  17838. this.minor = minor;
  17839. this.hdrSize = hdrSize;
  17840. this.offSize = offSize;
  17841. }
  17842. return CFFHeader;
  17843. })();
  17844. var CFFStrings = (function CFFStringsClosure() {
  17845. function CFFStrings() {
  17846. this.strings = [];
  17847. }
  17848. CFFStrings.prototype = {
  17849. get: function CFFStrings_get(index) {
  17850. if (index >= 0 && index <= 390) {
  17851. return CFFStandardStrings[index];
  17852. }
  17853. if (index - 391 <= this.strings.length) {
  17854. return this.strings[index - 391];
  17855. }
  17856. return CFFStandardStrings[0];
  17857. },
  17858. add: function CFFStrings_add(value) {
  17859. this.strings.push(value);
  17860. },
  17861. get count() {
  17862. return this.strings.length;
  17863. }
  17864. };
  17865. return CFFStrings;
  17866. })();
  17867. var CFFIndex = (function CFFIndexClosure() {
  17868. function CFFIndex() {
  17869. this.objects = [];
  17870. this.length = 0;
  17871. }
  17872. CFFIndex.prototype = {
  17873. add: function CFFIndex_add(data) {
  17874. this.length += data.length;
  17875. this.objects.push(data);
  17876. },
  17877. set: function CFFIndex_set(index, data) {
  17878. this.length += data.length - this.objects[index].length;
  17879. this.objects[index] = data;
  17880. },
  17881. get: function CFFIndex_get(index) {
  17882. return this.objects[index];
  17883. },
  17884. get count() {
  17885. return this.objects.length;
  17886. }
  17887. };
  17888. return CFFIndex;
  17889. })();
  17890. var CFFDict = (function CFFDictClosure() {
  17891. function CFFDict(tables, strings) {
  17892. this.keyToNameMap = tables.keyToNameMap;
  17893. this.nameToKeyMap = tables.nameToKeyMap;
  17894. this.defaults = tables.defaults;
  17895. this.types = tables.types;
  17896. this.opcodes = tables.opcodes;
  17897. this.order = tables.order;
  17898. this.strings = strings;
  17899. this.values = {};
  17900. }
  17901. CFFDict.prototype = {
  17902. // value should always be an array
  17903. setByKey: function CFFDict_setByKey(key, value) {
  17904. if (!(key in this.keyToNameMap)) {
  17905. return false;
  17906. }
  17907. // ignore empty values
  17908. if (value.length === 0) {
  17909. return true;
  17910. }
  17911. var type = this.types[key];
  17912. // remove the array wrapping these types of values
  17913. if (type === 'num' || type === 'sid' || type === 'offset') {
  17914. value = value[0];
  17915. }
  17916. this.values[key] = value;
  17917. return true;
  17918. },
  17919. setByName: function CFFDict_setByName(name, value) {
  17920. if (!(name in this.nameToKeyMap)) {
  17921. error('Invalid dictionary name "' + name + '"');
  17922. }
  17923. this.values[this.nameToKeyMap[name]] = value;
  17924. },
  17925. hasName: function CFFDict_hasName(name) {
  17926. return this.nameToKeyMap[name] in this.values;
  17927. },
  17928. getByName: function CFFDict_getByName(name) {
  17929. if (!(name in this.nameToKeyMap)) {
  17930. error('Invalid dictionary name "' + name + '"');
  17931. }
  17932. var key = this.nameToKeyMap[name];
  17933. if (!(key in this.values)) {
  17934. return this.defaults[key];
  17935. }
  17936. return this.values[key];
  17937. },
  17938. removeByName: function CFFDict_removeByName(name) {
  17939. delete this.values[this.nameToKeyMap[name]];
  17940. }
  17941. };
  17942. CFFDict.createTables = function CFFDict_createTables(layout) {
  17943. var tables = {
  17944. keyToNameMap: {},
  17945. nameToKeyMap: {},
  17946. defaults: {},
  17947. types: {},
  17948. opcodes: {},
  17949. order: []
  17950. };
  17951. for (var i = 0, ii = layout.length; i < ii; ++i) {
  17952. var entry = layout[i];
  17953. var key = isArray(entry[0]) ? (entry[0][0] << 8) + entry[0][1] : entry[0];
  17954. tables.keyToNameMap[key] = entry[1];
  17955. tables.nameToKeyMap[entry[1]] = key;
  17956. tables.types[key] = entry[2];
  17957. tables.defaults[key] = entry[3];
  17958. tables.opcodes[key] = isArray(entry[0]) ? entry[0] : [entry[0]];
  17959. tables.order.push(key);
  17960. }
  17961. return tables;
  17962. };
  17963. return CFFDict;
  17964. })();
  17965. var CFFTopDict = (function CFFTopDictClosure() {
  17966. var layout = [
  17967. [[12, 30], 'ROS', ['sid', 'sid', 'num'], null],
  17968. [[12, 20], 'SyntheticBase', 'num', null],
  17969. [0, 'version', 'sid', null],
  17970. [1, 'Notice', 'sid', null],
  17971. [[12, 0], 'Copyright', 'sid', null],
  17972. [2, 'FullName', 'sid', null],
  17973. [3, 'FamilyName', 'sid', null],
  17974. [4, 'Weight', 'sid', null],
  17975. [[12, 1], 'isFixedPitch', 'num', 0],
  17976. [[12, 2], 'ItalicAngle', 'num', 0],
  17977. [[12, 3], 'UnderlinePosition', 'num', -100],
  17978. [[12, 4], 'UnderlineThickness', 'num', 50],
  17979. [[12, 5], 'PaintType', 'num', 0],
  17980. [[12, 6], 'CharstringType', 'num', 2],
  17981. [[12, 7], 'FontMatrix', ['num', 'num', 'num', 'num', 'num', 'num'],
  17982. [0.001, 0, 0, 0.001, 0, 0]],
  17983. [13, 'UniqueID', 'num', null],
  17984. [5, 'FontBBox', ['num', 'num', 'num', 'num'], [0, 0, 0, 0]],
  17985. [[12, 8], 'StrokeWidth', 'num', 0],
  17986. [14, 'XUID', 'array', null],
  17987. [15, 'charset', 'offset', 0],
  17988. [16, 'Encoding', 'offset', 0],
  17989. [17, 'CharStrings', 'offset', 0],
  17990. [18, 'Private', ['offset', 'offset'], null],
  17991. [[12, 21], 'PostScript', 'sid', null],
  17992. [[12, 22], 'BaseFontName', 'sid', null],
  17993. [[12, 23], 'BaseFontBlend', 'delta', null],
  17994. [[12, 31], 'CIDFontVersion', 'num', 0],
  17995. [[12, 32], 'CIDFontRevision', 'num', 0],
  17996. [[12, 33], 'CIDFontType', 'num', 0],
  17997. [[12, 34], 'CIDCount', 'num', 8720],
  17998. [[12, 35], 'UIDBase', 'num', null],
  17999. // XXX: CID Fonts on DirectWrite 6.1 only seem to work if FDSelect comes
  18000. // before FDArray.
  18001. [[12, 37], 'FDSelect', 'offset', null],
  18002. [[12, 36], 'FDArray', 'offset', null],
  18003. [[12, 38], 'FontName', 'sid', null]
  18004. ];
  18005. var tables = null;
  18006. function CFFTopDict(strings) {
  18007. if (tables === null) {
  18008. tables = CFFDict.createTables(layout);
  18009. }
  18010. CFFDict.call(this, tables, strings);
  18011. this.privateDict = null;
  18012. }
  18013. CFFTopDict.prototype = Object.create(CFFDict.prototype);
  18014. return CFFTopDict;
  18015. })();
  18016. var CFFPrivateDict = (function CFFPrivateDictClosure() {
  18017. var layout = [
  18018. [6, 'BlueValues', 'delta', null],
  18019. [7, 'OtherBlues', 'delta', null],
  18020. [8, 'FamilyBlues', 'delta', null],
  18021. [9, 'FamilyOtherBlues', 'delta', null],
  18022. [[12, 9], 'BlueScale', 'num', 0.039625],
  18023. [[12, 10], 'BlueShift', 'num', 7],
  18024. [[12, 11], 'BlueFuzz', 'num', 1],
  18025. [10, 'StdHW', 'num', null],
  18026. [11, 'StdVW', 'num', null],
  18027. [[12, 12], 'StemSnapH', 'delta', null],
  18028. [[12, 13], 'StemSnapV', 'delta', null],
  18029. [[12, 14], 'ForceBold', 'num', 0],
  18030. [[12, 17], 'LanguageGroup', 'num', 0],
  18031. [[12, 18], 'ExpansionFactor', 'num', 0.06],
  18032. [[12, 19], 'initialRandomSeed', 'num', 0],
  18033. [20, 'defaultWidthX', 'num', 0],
  18034. [21, 'nominalWidthX', 'num', 0],
  18035. [19, 'Subrs', 'offset', null]
  18036. ];
  18037. var tables = null;
  18038. function CFFPrivateDict(strings) {
  18039. if (tables === null) {
  18040. tables = CFFDict.createTables(layout);
  18041. }
  18042. CFFDict.call(this, tables, strings);
  18043. this.subrsIndex = null;
  18044. }
  18045. CFFPrivateDict.prototype = Object.create(CFFDict.prototype);
  18046. return CFFPrivateDict;
  18047. })();
  18048. var CFFCharsetPredefinedTypes = {
  18049. ISO_ADOBE: 0,
  18050. EXPERT: 1,
  18051. EXPERT_SUBSET: 2
  18052. };
  18053. var CFFCharset = (function CFFCharsetClosure() {
  18054. function CFFCharset(predefined, format, charset, raw) {
  18055. this.predefined = predefined;
  18056. this.format = format;
  18057. this.charset = charset;
  18058. this.raw = raw;
  18059. }
  18060. return CFFCharset;
  18061. })();
  18062. var CFFEncoding = (function CFFEncodingClosure() {
  18063. function CFFEncoding(predefined, format, encoding, raw) {
  18064. this.predefined = predefined;
  18065. this.format = format;
  18066. this.encoding = encoding;
  18067. this.raw = raw;
  18068. }
  18069. return CFFEncoding;
  18070. })();
  18071. var CFFFDSelect = (function CFFFDSelectClosure() {
  18072. function CFFFDSelect(fdSelect, raw) {
  18073. this.fdSelect = fdSelect;
  18074. this.raw = raw;
  18075. }
  18076. return CFFFDSelect;
  18077. })();
  18078. // Helper class to keep track of where an offset is within the data and helps
  18079. // filling in that offset once it's known.
  18080. var CFFOffsetTracker = (function CFFOffsetTrackerClosure() {
  18081. function CFFOffsetTracker() {
  18082. this.offsets = {};
  18083. }
  18084. CFFOffsetTracker.prototype = {
  18085. isTracking: function CFFOffsetTracker_isTracking(key) {
  18086. return key in this.offsets;
  18087. },
  18088. track: function CFFOffsetTracker_track(key, location) {
  18089. if (key in this.offsets) {
  18090. error('Already tracking location of ' + key);
  18091. }
  18092. this.offsets[key] = location;
  18093. },
  18094. offset: function CFFOffsetTracker_offset(value) {
  18095. for (var key in this.offsets) {
  18096. this.offsets[key] += value;
  18097. }
  18098. },
  18099. setEntryLocation: function CFFOffsetTracker_setEntryLocation(key,
  18100. values,
  18101. output) {
  18102. if (!(key in this.offsets)) {
  18103. error('Not tracking location of ' + key);
  18104. }
  18105. var data = output.data;
  18106. var dataOffset = this.offsets[key];
  18107. var size = 5;
  18108. for (var i = 0, ii = values.length; i < ii; ++i) {
  18109. var offset0 = i * size + dataOffset;
  18110. var offset1 = offset0 + 1;
  18111. var offset2 = offset0 + 2;
  18112. var offset3 = offset0 + 3;
  18113. var offset4 = offset0 + 4;
  18114. // It's easy to screw up offsets so perform this sanity check.
  18115. if (data[offset0] !== 0x1d || data[offset1] !== 0 ||
  18116. data[offset2] !== 0 || data[offset3] !== 0 || data[offset4] !== 0) {
  18117. error('writing to an offset that is not empty');
  18118. }
  18119. var value = values[i];
  18120. data[offset0] = 0x1d;
  18121. data[offset1] = (value >> 24) & 0xFF;
  18122. data[offset2] = (value >> 16) & 0xFF;
  18123. data[offset3] = (value >> 8) & 0xFF;
  18124. data[offset4] = value & 0xFF;
  18125. }
  18126. }
  18127. };
  18128. return CFFOffsetTracker;
  18129. })();
  18130. // Takes a CFF and converts it to the binary representation.
  18131. var CFFCompiler = (function CFFCompilerClosure() {
  18132. function CFFCompiler(cff) {
  18133. this.cff = cff;
  18134. }
  18135. CFFCompiler.prototype = {
  18136. compile: function CFFCompiler_compile() {
  18137. var cff = this.cff;
  18138. var output = {
  18139. data: [],
  18140. length: 0,
  18141. add: function CFFCompiler_add(data) {
  18142. this.data = this.data.concat(data);
  18143. this.length = this.data.length;
  18144. }
  18145. };
  18146. // Compile the five entries that must be in order.
  18147. var header = this.compileHeader(cff.header);
  18148. output.add(header);
  18149. var nameIndex = this.compileNameIndex(cff.names);
  18150. output.add(nameIndex);
  18151. if (cff.isCIDFont) {
  18152. // The spec is unclear on how font matrices should relate to each other
  18153. // when there is one in the main top dict and the sub top dicts.
  18154. // Windows handles this differently than linux and osx so we have to
  18155. // normalize to work on all.
  18156. // Rules based off of some mailing list discussions:
  18157. // - If main font has a matrix and subfont doesn't, use the main matrix.
  18158. // - If no main font matrix and there is a subfont matrix, use the
  18159. // subfont matrix.
  18160. // - If both have matrices, concat together.
  18161. // - If neither have matrices, use default.
  18162. // To make this work on all platforms we move the top matrix into each
  18163. // sub top dict and concat if necessary.
  18164. if (cff.topDict.hasName('FontMatrix')) {
  18165. var base = cff.topDict.getByName('FontMatrix');
  18166. cff.topDict.removeByName('FontMatrix');
  18167. for (var i = 0, ii = cff.fdArray.length; i < ii; i++) {
  18168. var subDict = cff.fdArray[i];
  18169. var matrix = base.slice(0);
  18170. if (subDict.hasName('FontMatrix')) {
  18171. matrix = Util.transform(matrix, subDict.getByName('FontMatrix'));
  18172. }
  18173. subDict.setByName('FontMatrix', matrix);
  18174. }
  18175. }
  18176. }
  18177. var compiled = this.compileTopDicts([cff.topDict],
  18178. output.length,
  18179. cff.isCIDFont);
  18180. output.add(compiled.output);
  18181. var topDictTracker = compiled.trackers[0];
  18182. var stringIndex = this.compileStringIndex(cff.strings.strings);
  18183. output.add(stringIndex);
  18184. var globalSubrIndex = this.compileIndex(cff.globalSubrIndex);
  18185. output.add(globalSubrIndex);
  18186. // Now start on the other entries that have no specfic order.
  18187. if (cff.encoding && cff.topDict.hasName('Encoding')) {
  18188. if (cff.encoding.predefined) {
  18189. topDictTracker.setEntryLocation('Encoding', [cff.encoding.format],
  18190. output);
  18191. } else {
  18192. var encoding = this.compileEncoding(cff.encoding);
  18193. topDictTracker.setEntryLocation('Encoding', [output.length], output);
  18194. output.add(encoding);
  18195. }
  18196. }
  18197. if (cff.charset && cff.topDict.hasName('charset')) {
  18198. if (cff.charset.predefined) {
  18199. topDictTracker.setEntryLocation('charset', [cff.charset.format],
  18200. output);
  18201. } else {
  18202. var charset = this.compileCharset(cff.charset);
  18203. topDictTracker.setEntryLocation('charset', [output.length], output);
  18204. output.add(charset);
  18205. }
  18206. }
  18207. var charStrings = this.compileCharStrings(cff.charStrings);
  18208. topDictTracker.setEntryLocation('CharStrings', [output.length], output);
  18209. output.add(charStrings);
  18210. if (cff.isCIDFont) {
  18211. // For some reason FDSelect must be in front of FDArray on windows. OSX
  18212. // and linux don't seem to care.
  18213. topDictTracker.setEntryLocation('FDSelect', [output.length], output);
  18214. var fdSelect = this.compileFDSelect(cff.fdSelect.raw);
  18215. output.add(fdSelect);
  18216. // It is unclear if the sub font dictionary can have CID related
  18217. // dictionary keys, but the sanitizer doesn't like them so remove them.
  18218. compiled = this.compileTopDicts(cff.fdArray, output.length, true);
  18219. topDictTracker.setEntryLocation('FDArray', [output.length], output);
  18220. output.add(compiled.output);
  18221. var fontDictTrackers = compiled.trackers;
  18222. this.compilePrivateDicts(cff.fdArray, fontDictTrackers, output);
  18223. }
  18224. this.compilePrivateDicts([cff.topDict], [topDictTracker], output);
  18225. // If the font data ends with INDEX whose object data is zero-length,
  18226. // the sanitizer will bail out. Add a dummy byte to avoid that.
  18227. output.add([0]);
  18228. return output.data;
  18229. },
  18230. encodeNumber: function CFFCompiler_encodeNumber(value) {
  18231. if (parseFloat(value) == parseInt(value, 10) && !isNaN(value)) { // isInt
  18232. return this.encodeInteger(value);
  18233. } else {
  18234. return this.encodeFloat(value);
  18235. }
  18236. },
  18237. encodeFloat: function CFFCompiler_encodeFloat(num) {
  18238. var value = num.toString();
  18239. // rounding inaccurate doubles
  18240. var m = /\.(\d*?)(?:9{5,20}|0{5,20})\d{0,2}(?:e(.+)|$)/.exec(value);
  18241. if (m) {
  18242. var epsilon = parseFloat('1e' + ((m[2] ? +m[2] : 0) + m[1].length));
  18243. value = (Math.round(num * epsilon) / epsilon).toString();
  18244. }
  18245. var nibbles = '';
  18246. var i, ii;
  18247. for (i = 0, ii = value.length; i < ii; ++i) {
  18248. var a = value[i];
  18249. if (a === 'e') {
  18250. nibbles += value[++i] === '-' ? 'c' : 'b';
  18251. } else if (a === '.') {
  18252. nibbles += 'a';
  18253. } else if (a === '-') {
  18254. nibbles += 'e';
  18255. } else {
  18256. nibbles += a;
  18257. }
  18258. }
  18259. nibbles += (nibbles.length & 1) ? 'f' : 'ff';
  18260. var out = [30];
  18261. for (i = 0, ii = nibbles.length; i < ii; i += 2) {
  18262. out.push(parseInt(nibbles.substr(i, 2), 16));
  18263. }
  18264. return out;
  18265. },
  18266. encodeInteger: function CFFCompiler_encodeInteger(value) {
  18267. var code;
  18268. if (value >= -107 && value <= 107) {
  18269. code = [value + 139];
  18270. } else if (value >= 108 && value <= 1131) {
  18271. value = [value - 108];
  18272. code = [(value >> 8) + 247, value & 0xFF];
  18273. } else if (value >= -1131 && value <= -108) {
  18274. value = -value - 108;
  18275. code = [(value >> 8) + 251, value & 0xFF];
  18276. } else if (value >= -32768 && value <= 32767) {
  18277. code = [0x1c, (value >> 8) & 0xFF, value & 0xFF];
  18278. } else {
  18279. code = [0x1d,
  18280. (value >> 24) & 0xFF,
  18281. (value >> 16) & 0xFF,
  18282. (value >> 8) & 0xFF,
  18283. value & 0xFF];
  18284. }
  18285. return code;
  18286. },
  18287. compileHeader: function CFFCompiler_compileHeader(header) {
  18288. return [
  18289. header.major,
  18290. header.minor,
  18291. header.hdrSize,
  18292. header.offSize
  18293. ];
  18294. },
  18295. compileNameIndex: function CFFCompiler_compileNameIndex(names) {
  18296. var nameIndex = new CFFIndex();
  18297. for (var i = 0, ii = names.length; i < ii; ++i) {
  18298. nameIndex.add(stringToArray(names[i]));
  18299. }
  18300. return this.compileIndex(nameIndex);
  18301. },
  18302. compileTopDicts: function CFFCompiler_compileTopDicts(dicts,
  18303. length,
  18304. removeCidKeys) {
  18305. var fontDictTrackers = [];
  18306. var fdArrayIndex = new CFFIndex();
  18307. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  18308. var fontDict = dicts[i];
  18309. if (removeCidKeys) {
  18310. fontDict.removeByName('CIDFontVersion');
  18311. fontDict.removeByName('CIDFontRevision');
  18312. fontDict.removeByName('CIDFontType');
  18313. fontDict.removeByName('CIDCount');
  18314. fontDict.removeByName('UIDBase');
  18315. }
  18316. var fontDictTracker = new CFFOffsetTracker();
  18317. var fontDictData = this.compileDict(fontDict, fontDictTracker);
  18318. fontDictTrackers.push(fontDictTracker);
  18319. fdArrayIndex.add(fontDictData);
  18320. fontDictTracker.offset(length);
  18321. }
  18322. fdArrayIndex = this.compileIndex(fdArrayIndex, fontDictTrackers);
  18323. return {
  18324. trackers: fontDictTrackers,
  18325. output: fdArrayIndex
  18326. };
  18327. },
  18328. compilePrivateDicts: function CFFCompiler_compilePrivateDicts(dicts,
  18329. trackers,
  18330. output) {
  18331. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  18332. var fontDict = dicts[i];
  18333. assert(fontDict.privateDict && fontDict.hasName('Private'),
  18334. 'There must be an private dictionary.');
  18335. var privateDict = fontDict.privateDict;
  18336. var privateDictTracker = new CFFOffsetTracker();
  18337. var privateDictData = this.compileDict(privateDict, privateDictTracker);
  18338. var outputLength = output.length;
  18339. privateDictTracker.offset(outputLength);
  18340. if (!privateDictData.length) {
  18341. // The private dictionary was empty, set the output length to zero to
  18342. // ensure the offset length isn't out of bounds in the eyes of the
  18343. // sanitizer.
  18344. outputLength = 0;
  18345. }
  18346. trackers[i].setEntryLocation('Private',
  18347. [privateDictData.length, outputLength],
  18348. output);
  18349. output.add(privateDictData);
  18350. if (privateDict.subrsIndex && privateDict.hasName('Subrs')) {
  18351. var subrs = this.compileIndex(privateDict.subrsIndex);
  18352. privateDictTracker.setEntryLocation('Subrs', [privateDictData.length],
  18353. output);
  18354. output.add(subrs);
  18355. }
  18356. }
  18357. },
  18358. compileDict: function CFFCompiler_compileDict(dict, offsetTracker) {
  18359. var out = [];
  18360. // The dictionary keys must be in a certain order.
  18361. var order = dict.order;
  18362. for (var i = 0; i < order.length; ++i) {
  18363. var key = order[i];
  18364. if (!(key in dict.values)) {
  18365. continue;
  18366. }
  18367. var values = dict.values[key];
  18368. var types = dict.types[key];
  18369. if (!isArray(types)) {
  18370. types = [types];
  18371. }
  18372. if (!isArray(values)) {
  18373. values = [values];
  18374. }
  18375. // Remove any empty dict values.
  18376. if (values.length === 0) {
  18377. continue;
  18378. }
  18379. for (var j = 0, jj = types.length; j < jj; ++j) {
  18380. var type = types[j];
  18381. var value = values[j];
  18382. switch (type) {
  18383. case 'num':
  18384. case 'sid':
  18385. out = out.concat(this.encodeNumber(value));
  18386. break;
  18387. case 'offset':
  18388. // For offsets we just insert a 32bit integer so we don't have to
  18389. // deal with figuring out the length of the offset when it gets
  18390. // replaced later on by the compiler.
  18391. var name = dict.keyToNameMap[key];
  18392. // Some offsets have the offset and the length, so just record the
  18393. // position of the first one.
  18394. if (!offsetTracker.isTracking(name)) {
  18395. offsetTracker.track(name, out.length);
  18396. }
  18397. out = out.concat([0x1d, 0, 0, 0, 0]);
  18398. break;
  18399. case 'array':
  18400. case 'delta':
  18401. out = out.concat(this.encodeNumber(value));
  18402. for (var k = 1, kk = values.length; k < kk; ++k) {
  18403. out = out.concat(this.encodeNumber(values[k]));
  18404. }
  18405. break;
  18406. default:
  18407. error('Unknown data type of ' + type);
  18408. break;
  18409. }
  18410. }
  18411. out = out.concat(dict.opcodes[key]);
  18412. }
  18413. return out;
  18414. },
  18415. compileStringIndex: function CFFCompiler_compileStringIndex(strings) {
  18416. var stringIndex = new CFFIndex();
  18417. for (var i = 0, ii = strings.length; i < ii; ++i) {
  18418. stringIndex.add(stringToArray(strings[i]));
  18419. }
  18420. return this.compileIndex(stringIndex);
  18421. },
  18422. compileGlobalSubrIndex: function CFFCompiler_compileGlobalSubrIndex() {
  18423. var globalSubrIndex = this.cff.globalSubrIndex;
  18424. this.out.writeByteArray(this.compileIndex(globalSubrIndex));
  18425. },
  18426. compileCharStrings: function CFFCompiler_compileCharStrings(charStrings) {
  18427. return this.compileIndex(charStrings);
  18428. },
  18429. compileCharset: function CFFCompiler_compileCharset(charset) {
  18430. return this.compileTypedArray(charset.raw);
  18431. },
  18432. compileEncoding: function CFFCompiler_compileEncoding(encoding) {
  18433. return this.compileTypedArray(encoding.raw);
  18434. },
  18435. compileFDSelect: function CFFCompiler_compileFDSelect(fdSelect) {
  18436. return this.compileTypedArray(fdSelect);
  18437. },
  18438. compileTypedArray: function CFFCompiler_compileTypedArray(data) {
  18439. var out = [];
  18440. for (var i = 0, ii = data.length; i < ii; ++i) {
  18441. out[i] = data[i];
  18442. }
  18443. return out;
  18444. },
  18445. compileIndex: function CFFCompiler_compileIndex(index, trackers) {
  18446. trackers = trackers || [];
  18447. var objects = index.objects;
  18448. // First 2 bytes contains the number of objects contained into this index
  18449. var count = objects.length;
  18450. // If there is no object, just create an index. This technically
  18451. // should just be [0, 0] but OTS has an issue with that.
  18452. if (count === 0) {
  18453. return [0, 0, 0];
  18454. }
  18455. var data = [(count >> 8) & 0xFF, count & 0xff];
  18456. var lastOffset = 1, i;
  18457. for (i = 0; i < count; ++i) {
  18458. lastOffset += objects[i].length;
  18459. }
  18460. var offsetSize;
  18461. if (lastOffset < 0x100) {
  18462. offsetSize = 1;
  18463. } else if (lastOffset < 0x10000) {
  18464. offsetSize = 2;
  18465. } else if (lastOffset < 0x1000000) {
  18466. offsetSize = 3;
  18467. } else {
  18468. offsetSize = 4;
  18469. }
  18470. // Next byte contains the offset size use to reference object in the file
  18471. data.push(offsetSize);
  18472. // Add another offset after this one because we need a new offset
  18473. var relativeOffset = 1;
  18474. for (i = 0; i < count + 1; i++) {
  18475. if (offsetSize === 1) {
  18476. data.push(relativeOffset & 0xFF);
  18477. } else if (offsetSize === 2) {
  18478. data.push((relativeOffset >> 8) & 0xFF,
  18479. relativeOffset & 0xFF);
  18480. } else if (offsetSize === 3) {
  18481. data.push((relativeOffset >> 16) & 0xFF,
  18482. (relativeOffset >> 8) & 0xFF,
  18483. relativeOffset & 0xFF);
  18484. } else {
  18485. data.push((relativeOffset >>> 24) & 0xFF,
  18486. (relativeOffset >> 16) & 0xFF,
  18487. (relativeOffset >> 8) & 0xFF,
  18488. relativeOffset & 0xFF);
  18489. }
  18490. if (objects[i]) {
  18491. relativeOffset += objects[i].length;
  18492. }
  18493. }
  18494. for (i = 0; i < count; i++) {
  18495. // Notify the tracker where the object will be offset in the data.
  18496. if (trackers[i]) {
  18497. trackers[i].offset(data.length);
  18498. }
  18499. for (var j = 0, jj = objects[i].length; j < jj; j++) {
  18500. data.push(objects[i][j]);
  18501. }
  18502. }
  18503. return data;
  18504. }
  18505. };
  18506. return CFFCompiler;
  18507. })();
  18508. // Workaround for seac on Windows.
  18509. (function checkSeacSupport() {
  18510. if (/Windows/.test(navigator.userAgent)) {
  18511. SEAC_ANALYSIS_ENABLED = true;
  18512. }
  18513. })();
  18514. // Workaround for Private Use Area characters in Chrome on Windows
  18515. // http://code.google.com/p/chromium/issues/detail?id=122465
  18516. // https://github.com/mozilla/pdf.js/issues/1689
  18517. (function checkChromeWindows() {
  18518. if (/Windows.*Chrome/.test(navigator.userAgent)) {
  18519. SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = true;
  18520. }
  18521. })();
  18522. var FontRendererFactory = (function FontRendererFactoryClosure() {
  18523. function getLong(data, offset) {
  18524. return (data[offset] << 24) | (data[offset + 1] << 16) |
  18525. (data[offset + 2] << 8) | data[offset + 3];
  18526. }
  18527. function getUshort(data, offset) {
  18528. return (data[offset] << 8) | data[offset + 1];
  18529. }
  18530. function parseCmap(data, start, end) {
  18531. var offset = (getUshort(data, start + 2) === 1 ?
  18532. getLong(data, start + 8) : getLong(data, start + 16));
  18533. var format = getUshort(data, start + offset);
  18534. var length, ranges, p, i;
  18535. if (format === 4) {
  18536. length = getUshort(data, start + offset + 2);
  18537. var segCount = getUshort(data, start + offset + 6) >> 1;
  18538. p = start + offset + 14;
  18539. ranges = [];
  18540. for (i = 0; i < segCount; i++, p += 2) {
  18541. ranges[i] = {end: getUshort(data, p)};
  18542. }
  18543. p += 2;
  18544. for (i = 0; i < segCount; i++, p += 2) {
  18545. ranges[i].start = getUshort(data, p);
  18546. }
  18547. for (i = 0; i < segCount; i++, p += 2) {
  18548. ranges[i].idDelta = getUshort(data, p);
  18549. }
  18550. for (i = 0; i < segCount; i++, p += 2) {
  18551. var idOffset = getUshort(data, p);
  18552. if (idOffset === 0) {
  18553. continue;
  18554. }
  18555. ranges[i].ids = [];
  18556. for (var j = 0, jj = ranges[i].end - ranges[i].start + 1; j < jj; j++) {
  18557. ranges[i].ids[j] = getUshort(data, p + idOffset);
  18558. idOffset += 2;
  18559. }
  18560. }
  18561. return ranges;
  18562. } else if (format === 12) {
  18563. length = getLong(data, start + offset + 4);
  18564. var groups = getLong(data, start + offset + 12);
  18565. p = start + offset + 16;
  18566. ranges = [];
  18567. for (i = 0; i < groups; i++) {
  18568. ranges.push({
  18569. start: getLong(data, p),
  18570. end: getLong(data, p + 4),
  18571. idDelta: getLong(data, p + 8) - getLong(data, p)
  18572. });
  18573. p += 12;
  18574. }
  18575. return ranges;
  18576. }
  18577. error('not supported cmap: ' + format);
  18578. }
  18579. function parseCff(data, start, end) {
  18580. var properties = {};
  18581. var parser = new CFFParser(new Stream(data, start, end - start),
  18582. properties);
  18583. var cff = parser.parse();
  18584. return {
  18585. glyphs: cff.charStrings.objects,
  18586. subrs: (cff.topDict.privateDict && cff.topDict.privateDict.subrsIndex &&
  18587. cff.topDict.privateDict.subrsIndex.objects),
  18588. gsubrs: cff.globalSubrIndex && cff.globalSubrIndex.objects
  18589. };
  18590. }
  18591. function parseGlyfTable(glyf, loca, isGlyphLocationsLong) {
  18592. var itemSize, itemDecode;
  18593. if (isGlyphLocationsLong) {
  18594. itemSize = 4;
  18595. itemDecode = function fontItemDecodeLong(data, offset) {
  18596. return (data[offset] << 24) | (data[offset + 1] << 16) |
  18597. (data[offset + 2] << 8) | data[offset + 3];
  18598. };
  18599. } else {
  18600. itemSize = 2;
  18601. itemDecode = function fontItemDecode(data, offset) {
  18602. return (data[offset] << 9) | (data[offset + 1] << 1);
  18603. };
  18604. }
  18605. var glyphs = [];
  18606. var startOffset = itemDecode(loca, 0);
  18607. for (var j = itemSize; j < loca.length; j += itemSize) {
  18608. var endOffset = itemDecode(loca, j);
  18609. glyphs.push(glyf.subarray(startOffset, endOffset));
  18610. startOffset = endOffset;
  18611. }
  18612. return glyphs;
  18613. }
  18614. function lookupCmap(ranges, unicode) {
  18615. var code = unicode.charCodeAt(0);
  18616. var l = 0, r = ranges.length - 1;
  18617. while (l < r) {
  18618. var c = (l + r + 1) >> 1;
  18619. if (code < ranges[c].start) {
  18620. r = c - 1;
  18621. } else {
  18622. l = c;
  18623. }
  18624. }
  18625. if (ranges[l].start <= code && code <= ranges[l].end) {
  18626. return (ranges[l].idDelta + (ranges[l].ids ?
  18627. ranges[l].ids[code - ranges[l].start] : code)) & 0xFFFF;
  18628. }
  18629. return 0;
  18630. }
  18631. function compileGlyf(code, js, font) {
  18632. function moveTo(x, y) {
  18633. js.push('c.moveTo(' + x + ',' + y + ');');
  18634. }
  18635. function lineTo(x, y) {
  18636. js.push('c.lineTo(' + x + ',' + y + ');');
  18637. }
  18638. function quadraticCurveTo(xa, ya, x, y) {
  18639. js.push('c.quadraticCurveTo(' + xa + ',' + ya + ',' +
  18640. x + ',' + y + ');');
  18641. }
  18642. var i = 0;
  18643. var numberOfContours = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  18644. var flags;
  18645. var x = 0, y = 0;
  18646. i += 10;
  18647. if (numberOfContours < 0) {
  18648. // composite glyph
  18649. do {
  18650. flags = (code[i] << 8) | code[i + 1];
  18651. var glyphIndex = (code[i + 2] << 8) | code[i + 3];
  18652. i += 4;
  18653. var arg1, arg2;
  18654. if ((flags & 0x01)) {
  18655. arg1 = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  18656. arg2 = ((code[i + 2] << 24) | (code[i + 3] << 16)) >> 16;
  18657. i += 4;
  18658. } else {
  18659. arg1 = code[i++]; arg2 = code[i++];
  18660. }
  18661. if ((flags & 0x02)) {
  18662. x = arg1;
  18663. y = arg2;
  18664. } else {
  18665. x = 0; y = 0; // TODO "they are points" ?
  18666. }
  18667. var scaleX = 1, scaleY = 1, scale01 = 0, scale10 = 0;
  18668. if ((flags & 0x08)) {
  18669. scaleX =
  18670. scaleY = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  18671. i += 2;
  18672. } else if ((flags & 0x40)) {
  18673. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  18674. scaleY = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  18675. i += 4;
  18676. } else if ((flags & 0x80)) {
  18677. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  18678. scale01 = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  18679. scale10 = ((code[i + 4] << 24) | (code[i + 5] << 16)) / 1073741824;
  18680. scaleY = ((code[i + 6] << 24) | (code[i + 7] << 16)) / 1073741824;
  18681. i += 8;
  18682. }
  18683. var subglyph = font.glyphs[glyphIndex];
  18684. if (subglyph) {
  18685. js.push('c.save();');
  18686. js.push('c.transform(' + scaleX + ',' + scale01 + ',' +
  18687. scale10 + ',' + scaleY + ',' + x + ',' + y + ');');
  18688. compileGlyf(subglyph, js, font);
  18689. js.push('c.restore();');
  18690. }
  18691. } while ((flags & 0x20));
  18692. } else {
  18693. // simple glyph
  18694. var endPtsOfContours = [];
  18695. var j, jj;
  18696. for (j = 0; j < numberOfContours; j++) {
  18697. endPtsOfContours.push((code[i] << 8) | code[i + 1]);
  18698. i += 2;
  18699. }
  18700. var instructionLength = (code[i] << 8) | code[i + 1];
  18701. i += 2 + instructionLength; // skipping the instructions
  18702. var numberOfPoints = endPtsOfContours[endPtsOfContours.length - 1] + 1;
  18703. var points = [];
  18704. while (points.length < numberOfPoints) {
  18705. flags = code[i++];
  18706. var repeat = 1;
  18707. if ((flags & 0x08)) {
  18708. repeat += code[i++];
  18709. }
  18710. while (repeat-- > 0) {
  18711. points.push({flags: flags});
  18712. }
  18713. }
  18714. for (j = 0; j < numberOfPoints; j++) {
  18715. switch (points[j].flags & 0x12) {
  18716. case 0x00:
  18717. x += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  18718. i += 2;
  18719. break;
  18720. case 0x02:
  18721. x -= code[i++];
  18722. break;
  18723. case 0x12:
  18724. x += code[i++];
  18725. break;
  18726. }
  18727. points[j].x = x;
  18728. }
  18729. for (j = 0; j < numberOfPoints; j++) {
  18730. switch (points[j].flags & 0x24) {
  18731. case 0x00:
  18732. y += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  18733. i += 2;
  18734. break;
  18735. case 0x04:
  18736. y -= code[i++];
  18737. break;
  18738. case 0x24:
  18739. y += code[i++];
  18740. break;
  18741. }
  18742. points[j].y = y;
  18743. }
  18744. var startPoint = 0;
  18745. for (i = 0; i < numberOfContours; i++) {
  18746. var endPoint = endPtsOfContours[i];
  18747. // contours might have implicit points, which is located in the middle
  18748. // between two neighboring off-curve points
  18749. var contour = points.slice(startPoint, endPoint + 1);
  18750. if ((contour[0].flags & 1)) {
  18751. contour.push(contour[0]); // using start point at the contour end
  18752. } else if ((contour[contour.length - 1].flags & 1)) {
  18753. // first is off-curve point, trying to use one from the end
  18754. contour.unshift(contour[contour.length - 1]);
  18755. } else {
  18756. // start and end are off-curve points, creating implicit one
  18757. var p = {
  18758. flags: 1,
  18759. x: (contour[0].x + contour[contour.length - 1].x) / 2,
  18760. y: (contour[0].y + contour[contour.length - 1].y) / 2
  18761. };
  18762. contour.unshift(p);
  18763. contour.push(p);
  18764. }
  18765. moveTo(contour[0].x, contour[0].y);
  18766. for (j = 1, jj = contour.length; j < jj; j++) {
  18767. if ((contour[j].flags & 1)) {
  18768. lineTo(contour[j].x, contour[j].y);
  18769. } else if ((contour[j + 1].flags & 1)){
  18770. quadraticCurveTo(contour[j].x, contour[j].y,
  18771. contour[j + 1].x, contour[j + 1].y);
  18772. j++;
  18773. } else {
  18774. quadraticCurveTo(contour[j].x, contour[j].y,
  18775. (contour[j].x + contour[j + 1].x) / 2,
  18776. (contour[j].y + contour[j + 1].y) / 2);
  18777. }
  18778. }
  18779. startPoint = endPoint + 1;
  18780. }
  18781. }
  18782. }
  18783. function compileCharString(code, js, font) {
  18784. var stack = [];
  18785. var x = 0, y = 0;
  18786. var stems = 0;
  18787. function moveTo(x, y) {
  18788. js.push('c.moveTo(' + x + ',' + y + ');');
  18789. }
  18790. function lineTo(x, y) {
  18791. js.push('c.lineTo(' + x + ',' + y + ');');
  18792. }
  18793. function bezierCurveTo(x1, y1, x2, y2, x, y) {
  18794. js.push('c.bezierCurveTo(' + x1 + ',' + y1 + ',' + x2 + ',' + y2 + ',' +
  18795. x + ',' + y + ');');
  18796. }
  18797. function parse(code) {
  18798. var i = 0;
  18799. while (i < code.length) {
  18800. var stackClean = false;
  18801. var v = code[i++];
  18802. var xa, xb, ya, yb, y1, y2, y3, n, subrCode;
  18803. switch (v) {
  18804. case 1: // hstem
  18805. stems += stack.length >> 1;
  18806. stackClean = true;
  18807. break;
  18808. case 3: // vstem
  18809. stems += stack.length >> 1;
  18810. stackClean = true;
  18811. break;
  18812. case 4: // vmoveto
  18813. y += stack.pop();
  18814. moveTo(x, y);
  18815. stackClean = true;
  18816. break;
  18817. case 5: // rlineto
  18818. while (stack.length > 0) {
  18819. x += stack.shift();
  18820. y += stack.shift();
  18821. lineTo(x, y);
  18822. }
  18823. break;
  18824. case 6: // hlineto
  18825. while (stack.length > 0) {
  18826. x += stack.shift();
  18827. lineTo(x, y);
  18828. if (stack.length === 0) {
  18829. break;
  18830. }
  18831. y += stack.shift();
  18832. lineTo(x, y);
  18833. }
  18834. break;
  18835. case 7: // vlineto
  18836. while (stack.length > 0) {
  18837. y += stack.shift();
  18838. lineTo(x, y);
  18839. if (stack.length === 0) {
  18840. break;
  18841. }
  18842. x += stack.shift();
  18843. lineTo(x, y);
  18844. }
  18845. break;
  18846. case 8: // rrcurveto
  18847. while (stack.length > 0) {
  18848. xa = x + stack.shift(); ya = y + stack.shift();
  18849. xb = xa + stack.shift(); yb = ya + stack.shift();
  18850. x = xb + stack.shift(); y = yb + stack.shift();
  18851. bezierCurveTo(xa, ya, xb, yb, x, y);
  18852. }
  18853. break;
  18854. case 10: // callsubr
  18855. n = stack.pop() + font.subrsBias;
  18856. subrCode = font.subrs[n];
  18857. if (subrCode) {
  18858. parse(subrCode);
  18859. }
  18860. break;
  18861. case 11: // return
  18862. return;
  18863. case 12:
  18864. v = code[i++];
  18865. switch (v) {
  18866. case 34: // flex
  18867. xa = x + stack.shift();
  18868. xb = xa + stack.shift(); y1 = y + stack.shift();
  18869. x = xb + stack.shift();
  18870. bezierCurveTo(xa, y, xb, y1, x, y1);
  18871. xa = x + stack.shift();
  18872. xb = xa + stack.shift();
  18873. x = xb + stack.shift();
  18874. bezierCurveTo(xa, y1, xb, y, x, y);
  18875. break;
  18876. case 35: // flex
  18877. xa = x + stack.shift(); ya = y + stack.shift();
  18878. xb = xa + stack.shift(); yb = ya + stack.shift();
  18879. x = xb + stack.shift(); y = yb + stack.shift();
  18880. bezierCurveTo(xa, ya, xb, yb, x, y);
  18881. xa = x + stack.shift(); ya = y + stack.shift();
  18882. xb = xa + stack.shift(); yb = ya + stack.shift();
  18883. x = xb + stack.shift(); y = yb + stack.shift();
  18884. bezierCurveTo(xa, ya, xb, yb, x, y);
  18885. stack.pop(); // fd
  18886. break;
  18887. case 36: // hflex1
  18888. xa = x + stack.shift(); y1 = y + stack.shift();
  18889. xb = xa + stack.shift(); y2 = y1 + stack.shift();
  18890. x = xb + stack.shift();
  18891. bezierCurveTo(xa, y1, xb, y2, x, y2);
  18892. xa = x + stack.shift();
  18893. xb = xa + stack.shift(); y3 = y2 + stack.shift();
  18894. x = xb + stack.shift();
  18895. bezierCurveTo(xa, y2, xb, y3, x, y);
  18896. break;
  18897. case 37: // flex1
  18898. var x0 = x, y0 = y;
  18899. xa = x + stack.shift(); ya = y + stack.shift();
  18900. xb = xa + stack.shift(); yb = ya + stack.shift();
  18901. x = xb + stack.shift(); y = yb + stack.shift();
  18902. bezierCurveTo(xa, ya, xb, yb, x, y);
  18903. xa = x + stack.shift(); ya = y + stack.shift();
  18904. xb = xa + stack.shift(); yb = ya + stack.shift();
  18905. x = xb; y = yb;
  18906. if (Math.abs(x - x0) > Math.abs(y - y0)) {
  18907. x += stack.shift();
  18908. } else {
  18909. y += stack.shift();
  18910. }
  18911. bezierCurveTo(xa, ya, xb, yb, x, y);
  18912. break;
  18913. default:
  18914. error('unknown operator: 12 ' + v);
  18915. }
  18916. break;
  18917. case 14: // endchar
  18918. if (stack.length >= 4) {
  18919. var achar = stack.pop();
  18920. var bchar = stack.pop();
  18921. y = stack.pop();
  18922. x = stack.pop();
  18923. js.push('c.save();');
  18924. js.push('c.translate('+ x + ',' + y + ');');
  18925. var gid = lookupCmap(font.cmap, String.fromCharCode(
  18926. font.glyphNameMap[Encodings.StandardEncoding[achar]]));
  18927. compileCharString(font.glyphs[gid], js, font);
  18928. js.push('c.restore();');
  18929. gid = lookupCmap(font.cmap, String.fromCharCode(
  18930. font.glyphNameMap[Encodings.StandardEncoding[bchar]]));
  18931. compileCharString(font.glyphs[gid], js, font);
  18932. }
  18933. return;
  18934. case 18: // hstemhm
  18935. stems += stack.length >> 1;
  18936. stackClean = true;
  18937. break;
  18938. case 19: // hintmask
  18939. stems += stack.length >> 1;
  18940. i += (stems + 7) >> 3;
  18941. stackClean = true;
  18942. break;
  18943. case 20: // cntrmask
  18944. stems += stack.length >> 1;
  18945. i += (stems + 7) >> 3;
  18946. stackClean = true;
  18947. break;
  18948. case 21: // rmoveto
  18949. y += stack.pop();
  18950. x += stack.pop();
  18951. moveTo(x, y);
  18952. stackClean = true;
  18953. break;
  18954. case 22: // hmoveto
  18955. x += stack.pop();
  18956. moveTo(x, y);
  18957. stackClean = true;
  18958. break;
  18959. case 23: // vstemhm
  18960. stems += stack.length >> 1;
  18961. stackClean = true;
  18962. break;
  18963. case 24: // rcurveline
  18964. while (stack.length > 2) {
  18965. xa = x + stack.shift(); ya = y + stack.shift();
  18966. xb = xa + stack.shift(); yb = ya + stack.shift();
  18967. x = xb + stack.shift(); y = yb + stack.shift();
  18968. bezierCurveTo(xa, ya, xb, yb, x, y);
  18969. }
  18970. x += stack.shift();
  18971. y += stack.shift();
  18972. lineTo(x, y);
  18973. break;
  18974. case 25: // rlinecurve
  18975. while (stack.length > 6) {
  18976. x += stack.shift();
  18977. y += stack.shift();
  18978. lineTo(x, y);
  18979. }
  18980. xa = x + stack.shift(); ya = y + stack.shift();
  18981. xb = xa + stack.shift(); yb = ya + stack.shift();
  18982. x = xb + stack.shift(); y = yb + stack.shift();
  18983. bezierCurveTo(xa, ya, xb, yb, x, y);
  18984. break;
  18985. case 26: // vvcurveto
  18986. if (stack.length % 2) {
  18987. x += stack.shift();
  18988. }
  18989. while (stack.length > 0) {
  18990. xa = x; ya = y + stack.shift();
  18991. xb = xa + stack.shift(); yb = ya + stack.shift();
  18992. x = xb; y = yb + stack.shift();
  18993. bezierCurveTo(xa, ya, xb, yb, x, y);
  18994. }
  18995. break;
  18996. case 27: // hhcurveto
  18997. if (stack.length % 2) {
  18998. y += stack.shift();
  18999. }
  19000. while (stack.length > 0) {
  19001. xa = x + stack.shift(); ya = y;
  19002. xb = xa + stack.shift(); yb = ya + stack.shift();
  19003. x = xb + stack.shift(); y = yb;
  19004. bezierCurveTo(xa, ya, xb, yb, x, y);
  19005. }
  19006. break;
  19007. case 28:
  19008. stack.push(((code[i] << 24) | (code[i + 1] << 16)) >> 16);
  19009. i += 2;
  19010. break;
  19011. case 29: // callgsubr
  19012. n = stack.pop() + font.gsubrsBias;
  19013. subrCode = font.gsubrs[n];
  19014. if (subrCode) {
  19015. parse(subrCode);
  19016. }
  19017. break;
  19018. case 30: // vhcurveto
  19019. while (stack.length > 0) {
  19020. xa = x; ya = y + stack.shift();
  19021. xb = xa + stack.shift(); yb = ya + stack.shift();
  19022. x = xb + stack.shift();
  19023. y = yb + (stack.length === 1 ? stack.shift() : 0);
  19024. bezierCurveTo(xa, ya, xb, yb, x, y);
  19025. if (stack.length === 0) {
  19026. break;
  19027. }
  19028. xa = x + stack.shift(); ya = y;
  19029. xb = xa + stack.shift(); yb = ya + stack.shift();
  19030. y = yb + stack.shift();
  19031. x = xb + (stack.length === 1 ? stack.shift() : 0);
  19032. bezierCurveTo(xa, ya, xb, yb, x, y);
  19033. }
  19034. break;
  19035. case 31: // hvcurveto
  19036. while (stack.length > 0) {
  19037. xa = x + stack.shift(); ya = y;
  19038. xb = xa + stack.shift(); yb = ya + stack.shift();
  19039. y = yb + stack.shift();
  19040. x = xb + (stack.length === 1 ? stack.shift() : 0);
  19041. bezierCurveTo(xa, ya, xb, yb, x, y);
  19042. if (stack.length === 0) {
  19043. break;
  19044. }
  19045. xa = x; ya = y + stack.shift();
  19046. xb = xa + stack.shift(); yb = ya + stack.shift();
  19047. x = xb + stack.shift();
  19048. y = yb + (stack.length === 1 ? stack.shift() : 0);
  19049. bezierCurveTo(xa, ya, xb, yb, x, y);
  19050. }
  19051. break;
  19052. default:
  19053. if (v < 32) {
  19054. error('unknown operator: ' + v);
  19055. }
  19056. if (v < 247) {
  19057. stack.push(v - 139);
  19058. } else if (v < 251) {
  19059. stack.push((v - 247) * 256 + code[i++] + 108);
  19060. } else if (v < 255) {
  19061. stack.push(-(v - 251) * 256 - code[i++] - 108);
  19062. } else {
  19063. stack.push(((code[i] << 24) | (code[i + 1] << 16) |
  19064. (code[i + 2] << 8) | code[i + 3]) / 65536);
  19065. i += 4;
  19066. }
  19067. break;
  19068. }
  19069. if (stackClean) {
  19070. stack.length = 0;
  19071. }
  19072. }
  19073. }
  19074. parse(code);
  19075. }
  19076. var noop = '';
  19077. function CompiledFont(fontMatrix) {
  19078. this.compiledGlyphs = {};
  19079. this.fontMatrix = fontMatrix;
  19080. }
  19081. CompiledFont.prototype = {
  19082. getPathJs: function (unicode) {
  19083. var gid = lookupCmap(this.cmap, unicode);
  19084. var fn = this.compiledGlyphs[gid];
  19085. if (!fn) {
  19086. this.compiledGlyphs[gid] = fn = this.compileGlyph(this.glyphs[gid]);
  19087. }
  19088. return fn;
  19089. },
  19090. compileGlyph: function (code) {
  19091. if (!code || code.length === 0 || code[0] === 14) {
  19092. return noop;
  19093. }
  19094. var js = [];
  19095. js.push('c.save();');
  19096. js.push('c.transform(' + this.fontMatrix.join(',') + ');');
  19097. js.push('c.scale(size, -size);');
  19098. this.compileGlyphImpl(code, js);
  19099. js.push('c.restore();');
  19100. return js.join('\n');
  19101. },
  19102. compileGlyphImpl: function () {
  19103. error('Children classes should implement this.');
  19104. },
  19105. hasBuiltPath: function (unicode) {
  19106. var gid = lookupCmap(this.cmap, unicode);
  19107. return gid in this.compiledGlyphs;
  19108. }
  19109. };
  19110. function TrueTypeCompiled(glyphs, cmap, fontMatrix) {
  19111. fontMatrix = fontMatrix || [0.000488, 0, 0, 0.000488, 0, 0];
  19112. CompiledFont.call(this, fontMatrix);
  19113. this.glyphs = glyphs;
  19114. this.cmap = cmap;
  19115. this.compiledGlyphs = [];
  19116. }
  19117. Util.inherit(TrueTypeCompiled, CompiledFont, {
  19118. compileGlyphImpl: function (code, js) {
  19119. compileGlyf(code, js, this);
  19120. }
  19121. });
  19122. function Type2Compiled(cffInfo, cmap, fontMatrix, glyphNameMap) {
  19123. fontMatrix = fontMatrix || [0.001, 0, 0, 0.001, 0, 0];
  19124. CompiledFont.call(this, fontMatrix);
  19125. this.glyphs = cffInfo.glyphs;
  19126. this.gsubrs = cffInfo.gsubrs || [];
  19127. this.subrs = cffInfo.subrs || [];
  19128. this.cmap = cmap;
  19129. this.glyphNameMap = glyphNameMap || GlyphsUnicode;
  19130. this.compiledGlyphs = [];
  19131. this.gsubrsBias = (this.gsubrs.length < 1240 ?
  19132. 107 : (this.gsubrs.length < 33900 ? 1131 : 32768));
  19133. this.subrsBias = (this.subrs.length < 1240 ?
  19134. 107 : (this.subrs.length < 33900 ? 1131 : 32768));
  19135. }
  19136. Util.inherit(Type2Compiled, CompiledFont, {
  19137. compileGlyphImpl: function (code, js) {
  19138. compileCharString(code, js, this);
  19139. }
  19140. });
  19141. return {
  19142. create: function FontRendererFactory_create(font) {
  19143. var data = new Uint8Array(font.data);
  19144. var cmap, glyf, loca, cff, indexToLocFormat, unitsPerEm;
  19145. var numTables = getUshort(data, 4);
  19146. for (var i = 0, p = 12; i < numTables; i++, p += 16) {
  19147. var tag = bytesToString(data.subarray(p, p + 4));
  19148. var offset = getLong(data, p + 8);
  19149. var length = getLong(data, p + 12);
  19150. switch (tag) {
  19151. case 'cmap':
  19152. cmap = parseCmap(data, offset, offset + length);
  19153. break;
  19154. case 'glyf':
  19155. glyf = data.subarray(offset, offset + length);
  19156. break;
  19157. case 'loca':
  19158. loca = data.subarray(offset, offset + length);
  19159. break;
  19160. case 'head':
  19161. unitsPerEm = getUshort(data, offset + 18);
  19162. indexToLocFormat = getUshort(data, offset + 50);
  19163. break;
  19164. case 'CFF ':
  19165. cff = parseCff(data, offset, offset + length);
  19166. break;
  19167. }
  19168. }
  19169. if (glyf) {
  19170. var fontMatrix = (!unitsPerEm ? font.fontMatrix :
  19171. [1 / unitsPerEm, 0, 0, 1 / unitsPerEm, 0, 0]);
  19172. return new TrueTypeCompiled(
  19173. parseGlyfTable(glyf, loca, indexToLocFormat), cmap, fontMatrix);
  19174. } else {
  19175. return new Type2Compiled(cff, cmap, font.fontMatrix, font.glyphNameMap);
  19176. }
  19177. }
  19178. };
  19179. })();
  19180. var GlyphsUnicode = {
  19181. A: 0x0041,
  19182. AE: 0x00C6,
  19183. AEacute: 0x01FC,
  19184. AEmacron: 0x01E2,
  19185. AEsmall: 0xF7E6,
  19186. Aacute: 0x00C1,
  19187. Aacutesmall: 0xF7E1,
  19188. Abreve: 0x0102,
  19189. Abreveacute: 0x1EAE,
  19190. Abrevecyrillic: 0x04D0,
  19191. Abrevedotbelow: 0x1EB6,
  19192. Abrevegrave: 0x1EB0,
  19193. Abrevehookabove: 0x1EB2,
  19194. Abrevetilde: 0x1EB4,
  19195. Acaron: 0x01CD,
  19196. Acircle: 0x24B6,
  19197. Acircumflex: 0x00C2,
  19198. Acircumflexacute: 0x1EA4,
  19199. Acircumflexdotbelow: 0x1EAC,
  19200. Acircumflexgrave: 0x1EA6,
  19201. Acircumflexhookabove: 0x1EA8,
  19202. Acircumflexsmall: 0xF7E2,
  19203. Acircumflextilde: 0x1EAA,
  19204. Acute: 0xF6C9,
  19205. Acutesmall: 0xF7B4,
  19206. Acyrillic: 0x0410,
  19207. Adblgrave: 0x0200,
  19208. Adieresis: 0x00C4,
  19209. Adieresiscyrillic: 0x04D2,
  19210. Adieresismacron: 0x01DE,
  19211. Adieresissmall: 0xF7E4,
  19212. Adotbelow: 0x1EA0,
  19213. Adotmacron: 0x01E0,
  19214. Agrave: 0x00C0,
  19215. Agravesmall: 0xF7E0,
  19216. Ahookabove: 0x1EA2,
  19217. Aiecyrillic: 0x04D4,
  19218. Ainvertedbreve: 0x0202,
  19219. Alpha: 0x0391,
  19220. Alphatonos: 0x0386,
  19221. Amacron: 0x0100,
  19222. Amonospace: 0xFF21,
  19223. Aogonek: 0x0104,
  19224. Aring: 0x00C5,
  19225. Aringacute: 0x01FA,
  19226. Aringbelow: 0x1E00,
  19227. Aringsmall: 0xF7E5,
  19228. Asmall: 0xF761,
  19229. Atilde: 0x00C3,
  19230. Atildesmall: 0xF7E3,
  19231. Aybarmenian: 0x0531,
  19232. B: 0x0042,
  19233. Bcircle: 0x24B7,
  19234. Bdotaccent: 0x1E02,
  19235. Bdotbelow: 0x1E04,
  19236. Becyrillic: 0x0411,
  19237. Benarmenian: 0x0532,
  19238. Beta: 0x0392,
  19239. Bhook: 0x0181,
  19240. Blinebelow: 0x1E06,
  19241. Bmonospace: 0xFF22,
  19242. Brevesmall: 0xF6F4,
  19243. Bsmall: 0xF762,
  19244. Btopbar: 0x0182,
  19245. C: 0x0043,
  19246. Caarmenian: 0x053E,
  19247. Cacute: 0x0106,
  19248. Caron: 0xF6CA,
  19249. Caronsmall: 0xF6F5,
  19250. Ccaron: 0x010C,
  19251. Ccedilla: 0x00C7,
  19252. Ccedillaacute: 0x1E08,
  19253. Ccedillasmall: 0xF7E7,
  19254. Ccircle: 0x24B8,
  19255. Ccircumflex: 0x0108,
  19256. Cdot: 0x010A,
  19257. Cdotaccent: 0x010A,
  19258. Cedillasmall: 0xF7B8,
  19259. Chaarmenian: 0x0549,
  19260. Cheabkhasiancyrillic: 0x04BC,
  19261. Checyrillic: 0x0427,
  19262. Chedescenderabkhasiancyrillic: 0x04BE,
  19263. Chedescendercyrillic: 0x04B6,
  19264. Chedieresiscyrillic: 0x04F4,
  19265. Cheharmenian: 0x0543,
  19266. Chekhakassiancyrillic: 0x04CB,
  19267. Cheverticalstrokecyrillic: 0x04B8,
  19268. Chi: 0x03A7,
  19269. Chook: 0x0187,
  19270. Circumflexsmall: 0xF6F6,
  19271. Cmonospace: 0xFF23,
  19272. Coarmenian: 0x0551,
  19273. Csmall: 0xF763,
  19274. D: 0x0044,
  19275. DZ: 0x01F1,
  19276. DZcaron: 0x01C4,
  19277. Daarmenian: 0x0534,
  19278. Dafrican: 0x0189,
  19279. Dcaron: 0x010E,
  19280. Dcedilla: 0x1E10,
  19281. Dcircle: 0x24B9,
  19282. Dcircumflexbelow: 0x1E12,
  19283. Dcroat: 0x0110,
  19284. Ddotaccent: 0x1E0A,
  19285. Ddotbelow: 0x1E0C,
  19286. Decyrillic: 0x0414,
  19287. Deicoptic: 0x03EE,
  19288. Delta: 0x2206,
  19289. Deltagreek: 0x0394,
  19290. Dhook: 0x018A,
  19291. Dieresis: 0xF6CB,
  19292. DieresisAcute: 0xF6CC,
  19293. DieresisGrave: 0xF6CD,
  19294. Dieresissmall: 0xF7A8,
  19295. Digammagreek: 0x03DC,
  19296. Djecyrillic: 0x0402,
  19297. Dlinebelow: 0x1E0E,
  19298. Dmonospace: 0xFF24,
  19299. Dotaccentsmall: 0xF6F7,
  19300. Dslash: 0x0110,
  19301. Dsmall: 0xF764,
  19302. Dtopbar: 0x018B,
  19303. Dz: 0x01F2,
  19304. Dzcaron: 0x01C5,
  19305. Dzeabkhasiancyrillic: 0x04E0,
  19306. Dzecyrillic: 0x0405,
  19307. Dzhecyrillic: 0x040F,
  19308. E: 0x0045,
  19309. Eacute: 0x00C9,
  19310. Eacutesmall: 0xF7E9,
  19311. Ebreve: 0x0114,
  19312. Ecaron: 0x011A,
  19313. Ecedillabreve: 0x1E1C,
  19314. Echarmenian: 0x0535,
  19315. Ecircle: 0x24BA,
  19316. Ecircumflex: 0x00CA,
  19317. Ecircumflexacute: 0x1EBE,
  19318. Ecircumflexbelow: 0x1E18,
  19319. Ecircumflexdotbelow: 0x1EC6,
  19320. Ecircumflexgrave: 0x1EC0,
  19321. Ecircumflexhookabove: 0x1EC2,
  19322. Ecircumflexsmall: 0xF7EA,
  19323. Ecircumflextilde: 0x1EC4,
  19324. Ecyrillic: 0x0404,
  19325. Edblgrave: 0x0204,
  19326. Edieresis: 0x00CB,
  19327. Edieresissmall: 0xF7EB,
  19328. Edot: 0x0116,
  19329. Edotaccent: 0x0116,
  19330. Edotbelow: 0x1EB8,
  19331. Efcyrillic: 0x0424,
  19332. Egrave: 0x00C8,
  19333. Egravesmall: 0xF7E8,
  19334. Eharmenian: 0x0537,
  19335. Ehookabove: 0x1EBA,
  19336. Eightroman: 0x2167,
  19337. Einvertedbreve: 0x0206,
  19338. Eiotifiedcyrillic: 0x0464,
  19339. Elcyrillic: 0x041B,
  19340. Elevenroman: 0x216A,
  19341. Emacron: 0x0112,
  19342. Emacronacute: 0x1E16,
  19343. Emacrongrave: 0x1E14,
  19344. Emcyrillic: 0x041C,
  19345. Emonospace: 0xFF25,
  19346. Encyrillic: 0x041D,
  19347. Endescendercyrillic: 0x04A2,
  19348. Eng: 0x014A,
  19349. Enghecyrillic: 0x04A4,
  19350. Enhookcyrillic: 0x04C7,
  19351. Eogonek: 0x0118,
  19352. Eopen: 0x0190,
  19353. Epsilon: 0x0395,
  19354. Epsilontonos: 0x0388,
  19355. Ercyrillic: 0x0420,
  19356. Ereversed: 0x018E,
  19357. Ereversedcyrillic: 0x042D,
  19358. Escyrillic: 0x0421,
  19359. Esdescendercyrillic: 0x04AA,
  19360. Esh: 0x01A9,
  19361. Esmall: 0xF765,
  19362. Eta: 0x0397,
  19363. Etarmenian: 0x0538,
  19364. Etatonos: 0x0389,
  19365. Eth: 0x00D0,
  19366. Ethsmall: 0xF7F0,
  19367. Etilde: 0x1EBC,
  19368. Etildebelow: 0x1E1A,
  19369. Euro: 0x20AC,
  19370. Ezh: 0x01B7,
  19371. Ezhcaron: 0x01EE,
  19372. Ezhreversed: 0x01B8,
  19373. F: 0x0046,
  19374. Fcircle: 0x24BB,
  19375. Fdotaccent: 0x1E1E,
  19376. Feharmenian: 0x0556,
  19377. Feicoptic: 0x03E4,
  19378. Fhook: 0x0191,
  19379. Fitacyrillic: 0x0472,
  19380. Fiveroman: 0x2164,
  19381. Fmonospace: 0xFF26,
  19382. Fourroman: 0x2163,
  19383. Fsmall: 0xF766,
  19384. G: 0x0047,
  19385. GBsquare: 0x3387,
  19386. Gacute: 0x01F4,
  19387. Gamma: 0x0393,
  19388. Gammaafrican: 0x0194,
  19389. Gangiacoptic: 0x03EA,
  19390. Gbreve: 0x011E,
  19391. Gcaron: 0x01E6,
  19392. Gcedilla: 0x0122,
  19393. Gcircle: 0x24BC,
  19394. Gcircumflex: 0x011C,
  19395. Gcommaaccent: 0x0122,
  19396. Gdot: 0x0120,
  19397. Gdotaccent: 0x0120,
  19398. Gecyrillic: 0x0413,
  19399. Ghadarmenian: 0x0542,
  19400. Ghemiddlehookcyrillic: 0x0494,
  19401. Ghestrokecyrillic: 0x0492,
  19402. Gheupturncyrillic: 0x0490,
  19403. Ghook: 0x0193,
  19404. Gimarmenian: 0x0533,
  19405. Gjecyrillic: 0x0403,
  19406. Gmacron: 0x1E20,
  19407. Gmonospace: 0xFF27,
  19408. Grave: 0xF6CE,
  19409. Gravesmall: 0xF760,
  19410. Gsmall: 0xF767,
  19411. Gsmallhook: 0x029B,
  19412. Gstroke: 0x01E4,
  19413. H: 0x0048,
  19414. H18533: 0x25CF,
  19415. H18543: 0x25AA,
  19416. H18551: 0x25AB,
  19417. H22073: 0x25A1,
  19418. HPsquare: 0x33CB,
  19419. Haabkhasiancyrillic: 0x04A8,
  19420. Hadescendercyrillic: 0x04B2,
  19421. Hardsigncyrillic: 0x042A,
  19422. Hbar: 0x0126,
  19423. Hbrevebelow: 0x1E2A,
  19424. Hcedilla: 0x1E28,
  19425. Hcircle: 0x24BD,
  19426. Hcircumflex: 0x0124,
  19427. Hdieresis: 0x1E26,
  19428. Hdotaccent: 0x1E22,
  19429. Hdotbelow: 0x1E24,
  19430. Hmonospace: 0xFF28,
  19431. Hoarmenian: 0x0540,
  19432. Horicoptic: 0x03E8,
  19433. Hsmall: 0xF768,
  19434. Hungarumlaut: 0xF6CF,
  19435. Hungarumlautsmall: 0xF6F8,
  19436. Hzsquare: 0x3390,
  19437. I: 0x0049,
  19438. IAcyrillic: 0x042F,
  19439. IJ: 0x0132,
  19440. IUcyrillic: 0x042E,
  19441. Iacute: 0x00CD,
  19442. Iacutesmall: 0xF7ED,
  19443. Ibreve: 0x012C,
  19444. Icaron: 0x01CF,
  19445. Icircle: 0x24BE,
  19446. Icircumflex: 0x00CE,
  19447. Icircumflexsmall: 0xF7EE,
  19448. Icyrillic: 0x0406,
  19449. Idblgrave: 0x0208,
  19450. Idieresis: 0x00CF,
  19451. Idieresisacute: 0x1E2E,
  19452. Idieresiscyrillic: 0x04E4,
  19453. Idieresissmall: 0xF7EF,
  19454. Idot: 0x0130,
  19455. Idotaccent: 0x0130,
  19456. Idotbelow: 0x1ECA,
  19457. Iebrevecyrillic: 0x04D6,
  19458. Iecyrillic: 0x0415,
  19459. Ifraktur: 0x2111,
  19460. Igrave: 0x00CC,
  19461. Igravesmall: 0xF7EC,
  19462. Ihookabove: 0x1EC8,
  19463. Iicyrillic: 0x0418,
  19464. Iinvertedbreve: 0x020A,
  19465. Iishortcyrillic: 0x0419,
  19466. Imacron: 0x012A,
  19467. Imacroncyrillic: 0x04E2,
  19468. Imonospace: 0xFF29,
  19469. Iniarmenian: 0x053B,
  19470. Iocyrillic: 0x0401,
  19471. Iogonek: 0x012E,
  19472. Iota: 0x0399,
  19473. Iotaafrican: 0x0196,
  19474. Iotadieresis: 0x03AA,
  19475. Iotatonos: 0x038A,
  19476. Ismall: 0xF769,
  19477. Istroke: 0x0197,
  19478. Itilde: 0x0128,
  19479. Itildebelow: 0x1E2C,
  19480. Izhitsacyrillic: 0x0474,
  19481. Izhitsadblgravecyrillic: 0x0476,
  19482. J: 0x004A,
  19483. Jaarmenian: 0x0541,
  19484. Jcircle: 0x24BF,
  19485. Jcircumflex: 0x0134,
  19486. Jecyrillic: 0x0408,
  19487. Jheharmenian: 0x054B,
  19488. Jmonospace: 0xFF2A,
  19489. Jsmall: 0xF76A,
  19490. K: 0x004B,
  19491. KBsquare: 0x3385,
  19492. KKsquare: 0x33CD,
  19493. Kabashkircyrillic: 0x04A0,
  19494. Kacute: 0x1E30,
  19495. Kacyrillic: 0x041A,
  19496. Kadescendercyrillic: 0x049A,
  19497. Kahookcyrillic: 0x04C3,
  19498. Kappa: 0x039A,
  19499. Kastrokecyrillic: 0x049E,
  19500. Kaverticalstrokecyrillic: 0x049C,
  19501. Kcaron: 0x01E8,
  19502. Kcedilla: 0x0136,
  19503. Kcircle: 0x24C0,
  19504. Kcommaaccent: 0x0136,
  19505. Kdotbelow: 0x1E32,
  19506. Keharmenian: 0x0554,
  19507. Kenarmenian: 0x053F,
  19508. Khacyrillic: 0x0425,
  19509. Kheicoptic: 0x03E6,
  19510. Khook: 0x0198,
  19511. Kjecyrillic: 0x040C,
  19512. Klinebelow: 0x1E34,
  19513. Kmonospace: 0xFF2B,
  19514. Koppacyrillic: 0x0480,
  19515. Koppagreek: 0x03DE,
  19516. Ksicyrillic: 0x046E,
  19517. Ksmall: 0xF76B,
  19518. L: 0x004C,
  19519. LJ: 0x01C7,
  19520. LL: 0xF6BF,
  19521. Lacute: 0x0139,
  19522. Lambda: 0x039B,
  19523. Lcaron: 0x013D,
  19524. Lcedilla: 0x013B,
  19525. Lcircle: 0x24C1,
  19526. Lcircumflexbelow: 0x1E3C,
  19527. Lcommaaccent: 0x013B,
  19528. Ldot: 0x013F,
  19529. Ldotaccent: 0x013F,
  19530. Ldotbelow: 0x1E36,
  19531. Ldotbelowmacron: 0x1E38,
  19532. Liwnarmenian: 0x053C,
  19533. Lj: 0x01C8,
  19534. Ljecyrillic: 0x0409,
  19535. Llinebelow: 0x1E3A,
  19536. Lmonospace: 0xFF2C,
  19537. Lslash: 0x0141,
  19538. Lslashsmall: 0xF6F9,
  19539. Lsmall: 0xF76C,
  19540. M: 0x004D,
  19541. MBsquare: 0x3386,
  19542. Macron: 0xF6D0,
  19543. Macronsmall: 0xF7AF,
  19544. Macute: 0x1E3E,
  19545. Mcircle: 0x24C2,
  19546. Mdotaccent: 0x1E40,
  19547. Mdotbelow: 0x1E42,
  19548. Menarmenian: 0x0544,
  19549. Mmonospace: 0xFF2D,
  19550. Msmall: 0xF76D,
  19551. Mturned: 0x019C,
  19552. Mu: 0x039C,
  19553. N: 0x004E,
  19554. NJ: 0x01CA,
  19555. Nacute: 0x0143,
  19556. Ncaron: 0x0147,
  19557. Ncedilla: 0x0145,
  19558. Ncircle: 0x24C3,
  19559. Ncircumflexbelow: 0x1E4A,
  19560. Ncommaaccent: 0x0145,
  19561. Ndotaccent: 0x1E44,
  19562. Ndotbelow: 0x1E46,
  19563. Nhookleft: 0x019D,
  19564. Nineroman: 0x2168,
  19565. Nj: 0x01CB,
  19566. Njecyrillic: 0x040A,
  19567. Nlinebelow: 0x1E48,
  19568. Nmonospace: 0xFF2E,
  19569. Nowarmenian: 0x0546,
  19570. Nsmall: 0xF76E,
  19571. Ntilde: 0x00D1,
  19572. Ntildesmall: 0xF7F1,
  19573. Nu: 0x039D,
  19574. O: 0x004F,
  19575. OE: 0x0152,
  19576. OEsmall: 0xF6FA,
  19577. Oacute: 0x00D3,
  19578. Oacutesmall: 0xF7F3,
  19579. Obarredcyrillic: 0x04E8,
  19580. Obarreddieresiscyrillic: 0x04EA,
  19581. Obreve: 0x014E,
  19582. Ocaron: 0x01D1,
  19583. Ocenteredtilde: 0x019F,
  19584. Ocircle: 0x24C4,
  19585. Ocircumflex: 0x00D4,
  19586. Ocircumflexacute: 0x1ED0,
  19587. Ocircumflexdotbelow: 0x1ED8,
  19588. Ocircumflexgrave: 0x1ED2,
  19589. Ocircumflexhookabove: 0x1ED4,
  19590. Ocircumflexsmall: 0xF7F4,
  19591. Ocircumflextilde: 0x1ED6,
  19592. Ocyrillic: 0x041E,
  19593. Odblacute: 0x0150,
  19594. Odblgrave: 0x020C,
  19595. Odieresis: 0x00D6,
  19596. Odieresiscyrillic: 0x04E6,
  19597. Odieresissmall: 0xF7F6,
  19598. Odotbelow: 0x1ECC,
  19599. Ogoneksmall: 0xF6FB,
  19600. Ograve: 0x00D2,
  19601. Ogravesmall: 0xF7F2,
  19602. Oharmenian: 0x0555,
  19603. Ohm: 0x2126,
  19604. Ohookabove: 0x1ECE,
  19605. Ohorn: 0x01A0,
  19606. Ohornacute: 0x1EDA,
  19607. Ohorndotbelow: 0x1EE2,
  19608. Ohorngrave: 0x1EDC,
  19609. Ohornhookabove: 0x1EDE,
  19610. Ohorntilde: 0x1EE0,
  19611. Ohungarumlaut: 0x0150,
  19612. Oi: 0x01A2,
  19613. Oinvertedbreve: 0x020E,
  19614. Omacron: 0x014C,
  19615. Omacronacute: 0x1E52,
  19616. Omacrongrave: 0x1E50,
  19617. Omega: 0x2126,
  19618. Omegacyrillic: 0x0460,
  19619. Omegagreek: 0x03A9,
  19620. Omegaroundcyrillic: 0x047A,
  19621. Omegatitlocyrillic: 0x047C,
  19622. Omegatonos: 0x038F,
  19623. Omicron: 0x039F,
  19624. Omicrontonos: 0x038C,
  19625. Omonospace: 0xFF2F,
  19626. Oneroman: 0x2160,
  19627. Oogonek: 0x01EA,
  19628. Oogonekmacron: 0x01EC,
  19629. Oopen: 0x0186,
  19630. Oslash: 0x00D8,
  19631. Oslashacute: 0x01FE,
  19632. Oslashsmall: 0xF7F8,
  19633. Osmall: 0xF76F,
  19634. Ostrokeacute: 0x01FE,
  19635. Otcyrillic: 0x047E,
  19636. Otilde: 0x00D5,
  19637. Otildeacute: 0x1E4C,
  19638. Otildedieresis: 0x1E4E,
  19639. Otildesmall: 0xF7F5,
  19640. P: 0x0050,
  19641. Pacute: 0x1E54,
  19642. Pcircle: 0x24C5,
  19643. Pdotaccent: 0x1E56,
  19644. Pecyrillic: 0x041F,
  19645. Peharmenian: 0x054A,
  19646. Pemiddlehookcyrillic: 0x04A6,
  19647. Phi: 0x03A6,
  19648. Phook: 0x01A4,
  19649. Pi: 0x03A0,
  19650. Piwrarmenian: 0x0553,
  19651. Pmonospace: 0xFF30,
  19652. Psi: 0x03A8,
  19653. Psicyrillic: 0x0470,
  19654. Psmall: 0xF770,
  19655. Q: 0x0051,
  19656. Qcircle: 0x24C6,
  19657. Qmonospace: 0xFF31,
  19658. Qsmall: 0xF771,
  19659. R: 0x0052,
  19660. Raarmenian: 0x054C,
  19661. Racute: 0x0154,
  19662. Rcaron: 0x0158,
  19663. Rcedilla: 0x0156,
  19664. Rcircle: 0x24C7,
  19665. Rcommaaccent: 0x0156,
  19666. Rdblgrave: 0x0210,
  19667. Rdotaccent: 0x1E58,
  19668. Rdotbelow: 0x1E5A,
  19669. Rdotbelowmacron: 0x1E5C,
  19670. Reharmenian: 0x0550,
  19671. Rfraktur: 0x211C,
  19672. Rho: 0x03A1,
  19673. Ringsmall: 0xF6FC,
  19674. Rinvertedbreve: 0x0212,
  19675. Rlinebelow: 0x1E5E,
  19676. Rmonospace: 0xFF32,
  19677. Rsmall: 0xF772,
  19678. Rsmallinverted: 0x0281,
  19679. Rsmallinvertedsuperior: 0x02B6,
  19680. S: 0x0053,
  19681. SF010000: 0x250C,
  19682. SF020000: 0x2514,
  19683. SF030000: 0x2510,
  19684. SF040000: 0x2518,
  19685. SF050000: 0x253C,
  19686. SF060000: 0x252C,
  19687. SF070000: 0x2534,
  19688. SF080000: 0x251C,
  19689. SF090000: 0x2524,
  19690. SF100000: 0x2500,
  19691. SF110000: 0x2502,
  19692. SF190000: 0x2561,
  19693. SF200000: 0x2562,
  19694. SF210000: 0x2556,
  19695. SF220000: 0x2555,
  19696. SF230000: 0x2563,
  19697. SF240000: 0x2551,
  19698. SF250000: 0x2557,
  19699. SF260000: 0x255D,
  19700. SF270000: 0x255C,
  19701. SF280000: 0x255B,
  19702. SF360000: 0x255E,
  19703. SF370000: 0x255F,
  19704. SF380000: 0x255A,
  19705. SF390000: 0x2554,
  19706. SF400000: 0x2569,
  19707. SF410000: 0x2566,
  19708. SF420000: 0x2560,
  19709. SF430000: 0x2550,
  19710. SF440000: 0x256C,
  19711. SF450000: 0x2567,
  19712. SF460000: 0x2568,
  19713. SF470000: 0x2564,
  19714. SF480000: 0x2565,
  19715. SF490000: 0x2559,
  19716. SF500000: 0x2558,
  19717. SF510000: 0x2552,
  19718. SF520000: 0x2553,
  19719. SF530000: 0x256B,
  19720. SF540000: 0x256A,
  19721. Sacute: 0x015A,
  19722. Sacutedotaccent: 0x1E64,
  19723. Sampigreek: 0x03E0,
  19724. Scaron: 0x0160,
  19725. Scarondotaccent: 0x1E66,
  19726. Scaronsmall: 0xF6FD,
  19727. Scedilla: 0x015E,
  19728. Schwa: 0x018F,
  19729. Schwacyrillic: 0x04D8,
  19730. Schwadieresiscyrillic: 0x04DA,
  19731. Scircle: 0x24C8,
  19732. Scircumflex: 0x015C,
  19733. Scommaaccent: 0x0218,
  19734. Sdotaccent: 0x1E60,
  19735. Sdotbelow: 0x1E62,
  19736. Sdotbelowdotaccent: 0x1E68,
  19737. Seharmenian: 0x054D,
  19738. Sevenroman: 0x2166,
  19739. Shaarmenian: 0x0547,
  19740. Shacyrillic: 0x0428,
  19741. Shchacyrillic: 0x0429,
  19742. Sheicoptic: 0x03E2,
  19743. Shhacyrillic: 0x04BA,
  19744. Shimacoptic: 0x03EC,
  19745. Sigma: 0x03A3,
  19746. Sixroman: 0x2165,
  19747. Smonospace: 0xFF33,
  19748. Softsigncyrillic: 0x042C,
  19749. Ssmall: 0xF773,
  19750. Stigmagreek: 0x03DA,
  19751. T: 0x0054,
  19752. Tau: 0x03A4,
  19753. Tbar: 0x0166,
  19754. Tcaron: 0x0164,
  19755. Tcedilla: 0x0162,
  19756. Tcircle: 0x24C9,
  19757. Tcircumflexbelow: 0x1E70,
  19758. Tcommaaccent: 0x0162,
  19759. Tdotaccent: 0x1E6A,
  19760. Tdotbelow: 0x1E6C,
  19761. Tecyrillic: 0x0422,
  19762. Tedescendercyrillic: 0x04AC,
  19763. Tenroman: 0x2169,
  19764. Tetsecyrillic: 0x04B4,
  19765. Theta: 0x0398,
  19766. Thook: 0x01AC,
  19767. Thorn: 0x00DE,
  19768. Thornsmall: 0xF7FE,
  19769. Threeroman: 0x2162,
  19770. Tildesmall: 0xF6FE,
  19771. Tiwnarmenian: 0x054F,
  19772. Tlinebelow: 0x1E6E,
  19773. Tmonospace: 0xFF34,
  19774. Toarmenian: 0x0539,
  19775. Tonefive: 0x01BC,
  19776. Tonesix: 0x0184,
  19777. Tonetwo: 0x01A7,
  19778. Tretroflexhook: 0x01AE,
  19779. Tsecyrillic: 0x0426,
  19780. Tshecyrillic: 0x040B,
  19781. Tsmall: 0xF774,
  19782. Twelveroman: 0x216B,
  19783. Tworoman: 0x2161,
  19784. U: 0x0055,
  19785. Uacute: 0x00DA,
  19786. Uacutesmall: 0xF7FA,
  19787. Ubreve: 0x016C,
  19788. Ucaron: 0x01D3,
  19789. Ucircle: 0x24CA,
  19790. Ucircumflex: 0x00DB,
  19791. Ucircumflexbelow: 0x1E76,
  19792. Ucircumflexsmall: 0xF7FB,
  19793. Ucyrillic: 0x0423,
  19794. Udblacute: 0x0170,
  19795. Udblgrave: 0x0214,
  19796. Udieresis: 0x00DC,
  19797. Udieresisacute: 0x01D7,
  19798. Udieresisbelow: 0x1E72,
  19799. Udieresiscaron: 0x01D9,
  19800. Udieresiscyrillic: 0x04F0,
  19801. Udieresisgrave: 0x01DB,
  19802. Udieresismacron: 0x01D5,
  19803. Udieresissmall: 0xF7FC,
  19804. Udotbelow: 0x1EE4,
  19805. Ugrave: 0x00D9,
  19806. Ugravesmall: 0xF7F9,
  19807. Uhookabove: 0x1EE6,
  19808. Uhorn: 0x01AF,
  19809. Uhornacute: 0x1EE8,
  19810. Uhorndotbelow: 0x1EF0,
  19811. Uhorngrave: 0x1EEA,
  19812. Uhornhookabove: 0x1EEC,
  19813. Uhorntilde: 0x1EEE,
  19814. Uhungarumlaut: 0x0170,
  19815. Uhungarumlautcyrillic: 0x04F2,
  19816. Uinvertedbreve: 0x0216,
  19817. Ukcyrillic: 0x0478,
  19818. Umacron: 0x016A,
  19819. Umacroncyrillic: 0x04EE,
  19820. Umacrondieresis: 0x1E7A,
  19821. Umonospace: 0xFF35,
  19822. Uogonek: 0x0172,
  19823. Upsilon: 0x03A5,
  19824. Upsilon1: 0x03D2,
  19825. Upsilonacutehooksymbolgreek: 0x03D3,
  19826. Upsilonafrican: 0x01B1,
  19827. Upsilondieresis: 0x03AB,
  19828. Upsilondieresishooksymbolgreek: 0x03D4,
  19829. Upsilonhooksymbol: 0x03D2,
  19830. Upsilontonos: 0x038E,
  19831. Uring: 0x016E,
  19832. Ushortcyrillic: 0x040E,
  19833. Usmall: 0xF775,
  19834. Ustraightcyrillic: 0x04AE,
  19835. Ustraightstrokecyrillic: 0x04B0,
  19836. Utilde: 0x0168,
  19837. Utildeacute: 0x1E78,
  19838. Utildebelow: 0x1E74,
  19839. V: 0x0056,
  19840. Vcircle: 0x24CB,
  19841. Vdotbelow: 0x1E7E,
  19842. Vecyrillic: 0x0412,
  19843. Vewarmenian: 0x054E,
  19844. Vhook: 0x01B2,
  19845. Vmonospace: 0xFF36,
  19846. Voarmenian: 0x0548,
  19847. Vsmall: 0xF776,
  19848. Vtilde: 0x1E7C,
  19849. W: 0x0057,
  19850. Wacute: 0x1E82,
  19851. Wcircle: 0x24CC,
  19852. Wcircumflex: 0x0174,
  19853. Wdieresis: 0x1E84,
  19854. Wdotaccent: 0x1E86,
  19855. Wdotbelow: 0x1E88,
  19856. Wgrave: 0x1E80,
  19857. Wmonospace: 0xFF37,
  19858. Wsmall: 0xF777,
  19859. X: 0x0058,
  19860. Xcircle: 0x24CD,
  19861. Xdieresis: 0x1E8C,
  19862. Xdotaccent: 0x1E8A,
  19863. Xeharmenian: 0x053D,
  19864. Xi: 0x039E,
  19865. Xmonospace: 0xFF38,
  19866. Xsmall: 0xF778,
  19867. Y: 0x0059,
  19868. Yacute: 0x00DD,
  19869. Yacutesmall: 0xF7FD,
  19870. Yatcyrillic: 0x0462,
  19871. Ycircle: 0x24CE,
  19872. Ycircumflex: 0x0176,
  19873. Ydieresis: 0x0178,
  19874. Ydieresissmall: 0xF7FF,
  19875. Ydotaccent: 0x1E8E,
  19876. Ydotbelow: 0x1EF4,
  19877. Yericyrillic: 0x042B,
  19878. Yerudieresiscyrillic: 0x04F8,
  19879. Ygrave: 0x1EF2,
  19880. Yhook: 0x01B3,
  19881. Yhookabove: 0x1EF6,
  19882. Yiarmenian: 0x0545,
  19883. Yicyrillic: 0x0407,
  19884. Yiwnarmenian: 0x0552,
  19885. Ymonospace: 0xFF39,
  19886. Ysmall: 0xF779,
  19887. Ytilde: 0x1EF8,
  19888. Yusbigcyrillic: 0x046A,
  19889. Yusbigiotifiedcyrillic: 0x046C,
  19890. Yuslittlecyrillic: 0x0466,
  19891. Yuslittleiotifiedcyrillic: 0x0468,
  19892. Z: 0x005A,
  19893. Zaarmenian: 0x0536,
  19894. Zacute: 0x0179,
  19895. Zcaron: 0x017D,
  19896. Zcaronsmall: 0xF6FF,
  19897. Zcircle: 0x24CF,
  19898. Zcircumflex: 0x1E90,
  19899. Zdot: 0x017B,
  19900. Zdotaccent: 0x017B,
  19901. Zdotbelow: 0x1E92,
  19902. Zecyrillic: 0x0417,
  19903. Zedescendercyrillic: 0x0498,
  19904. Zedieresiscyrillic: 0x04DE,
  19905. Zeta: 0x0396,
  19906. Zhearmenian: 0x053A,
  19907. Zhebrevecyrillic: 0x04C1,
  19908. Zhecyrillic: 0x0416,
  19909. Zhedescendercyrillic: 0x0496,
  19910. Zhedieresiscyrillic: 0x04DC,
  19911. Zlinebelow: 0x1E94,
  19912. Zmonospace: 0xFF3A,
  19913. Zsmall: 0xF77A,
  19914. Zstroke: 0x01B5,
  19915. a: 0x0061,
  19916. aabengali: 0x0986,
  19917. aacute: 0x00E1,
  19918. aadeva: 0x0906,
  19919. aagujarati: 0x0A86,
  19920. aagurmukhi: 0x0A06,
  19921. aamatragurmukhi: 0x0A3E,
  19922. aarusquare: 0x3303,
  19923. aavowelsignbengali: 0x09BE,
  19924. aavowelsigndeva: 0x093E,
  19925. aavowelsigngujarati: 0x0ABE,
  19926. abbreviationmarkarmenian: 0x055F,
  19927. abbreviationsigndeva: 0x0970,
  19928. abengali: 0x0985,
  19929. abopomofo: 0x311A,
  19930. abreve: 0x0103,
  19931. abreveacute: 0x1EAF,
  19932. abrevecyrillic: 0x04D1,
  19933. abrevedotbelow: 0x1EB7,
  19934. abrevegrave: 0x1EB1,
  19935. abrevehookabove: 0x1EB3,
  19936. abrevetilde: 0x1EB5,
  19937. acaron: 0x01CE,
  19938. acircle: 0x24D0,
  19939. acircumflex: 0x00E2,
  19940. acircumflexacute: 0x1EA5,
  19941. acircumflexdotbelow: 0x1EAD,
  19942. acircumflexgrave: 0x1EA7,
  19943. acircumflexhookabove: 0x1EA9,
  19944. acircumflextilde: 0x1EAB,
  19945. acute: 0x00B4,
  19946. acutebelowcmb: 0x0317,
  19947. acutecmb: 0x0301,
  19948. acutecomb: 0x0301,
  19949. acutedeva: 0x0954,
  19950. acutelowmod: 0x02CF,
  19951. acutetonecmb: 0x0341,
  19952. acyrillic: 0x0430,
  19953. adblgrave: 0x0201,
  19954. addakgurmukhi: 0x0A71,
  19955. adeva: 0x0905,
  19956. adieresis: 0x00E4,
  19957. adieresiscyrillic: 0x04D3,
  19958. adieresismacron: 0x01DF,
  19959. adotbelow: 0x1EA1,
  19960. adotmacron: 0x01E1,
  19961. ae: 0x00E6,
  19962. aeacute: 0x01FD,
  19963. aekorean: 0x3150,
  19964. aemacron: 0x01E3,
  19965. afii00208: 0x2015,
  19966. afii08941: 0x20A4,
  19967. afii10017: 0x0410,
  19968. afii10018: 0x0411,
  19969. afii10019: 0x0412,
  19970. afii10020: 0x0413,
  19971. afii10021: 0x0414,
  19972. afii10022: 0x0415,
  19973. afii10023: 0x0401,
  19974. afii10024: 0x0416,
  19975. afii10025: 0x0417,
  19976. afii10026: 0x0418,
  19977. afii10027: 0x0419,
  19978. afii10028: 0x041A,
  19979. afii10029: 0x041B,
  19980. afii10030: 0x041C,
  19981. afii10031: 0x041D,
  19982. afii10032: 0x041E,
  19983. afii10033: 0x041F,
  19984. afii10034: 0x0420,
  19985. afii10035: 0x0421,
  19986. afii10036: 0x0422,
  19987. afii10037: 0x0423,
  19988. afii10038: 0x0424,
  19989. afii10039: 0x0425,
  19990. afii10040: 0x0426,
  19991. afii10041: 0x0427,
  19992. afii10042: 0x0428,
  19993. afii10043: 0x0429,
  19994. afii10044: 0x042A,
  19995. afii10045: 0x042B,
  19996. afii10046: 0x042C,
  19997. afii10047: 0x042D,
  19998. afii10048: 0x042E,
  19999. afii10049: 0x042F,
  20000. afii10050: 0x0490,
  20001. afii10051: 0x0402,
  20002. afii10052: 0x0403,
  20003. afii10053: 0x0404,
  20004. afii10054: 0x0405,
  20005. afii10055: 0x0406,
  20006. afii10056: 0x0407,
  20007. afii10057: 0x0408,
  20008. afii10058: 0x0409,
  20009. afii10059: 0x040A,
  20010. afii10060: 0x040B,
  20011. afii10061: 0x040C,
  20012. afii10062: 0x040E,
  20013. afii10063: 0xF6C4,
  20014. afii10064: 0xF6C5,
  20015. afii10065: 0x0430,
  20016. afii10066: 0x0431,
  20017. afii10067: 0x0432,
  20018. afii10068: 0x0433,
  20019. afii10069: 0x0434,
  20020. afii10070: 0x0435,
  20021. afii10071: 0x0451,
  20022. afii10072: 0x0436,
  20023. afii10073: 0x0437,
  20024. afii10074: 0x0438,
  20025. afii10075: 0x0439,
  20026. afii10076: 0x043A,
  20027. afii10077: 0x043B,
  20028. afii10078: 0x043C,
  20029. afii10079: 0x043D,
  20030. afii10080: 0x043E,
  20031. afii10081: 0x043F,
  20032. afii10082: 0x0440,
  20033. afii10083: 0x0441,
  20034. afii10084: 0x0442,
  20035. afii10085: 0x0443,
  20036. afii10086: 0x0444,
  20037. afii10087: 0x0445,
  20038. afii10088: 0x0446,
  20039. afii10089: 0x0447,
  20040. afii10090: 0x0448,
  20041. afii10091: 0x0449,
  20042. afii10092: 0x044A,
  20043. afii10093: 0x044B,
  20044. afii10094: 0x044C,
  20045. afii10095: 0x044D,
  20046. afii10096: 0x044E,
  20047. afii10097: 0x044F,
  20048. afii10098: 0x0491,
  20049. afii10099: 0x0452,
  20050. afii10100: 0x0453,
  20051. afii10101: 0x0454,
  20052. afii10102: 0x0455,
  20053. afii10103: 0x0456,
  20054. afii10104: 0x0457,
  20055. afii10105: 0x0458,
  20056. afii10106: 0x0459,
  20057. afii10107: 0x045A,
  20058. afii10108: 0x045B,
  20059. afii10109: 0x045C,
  20060. afii10110: 0x045E,
  20061. afii10145: 0x040F,
  20062. afii10146: 0x0462,
  20063. afii10147: 0x0472,
  20064. afii10148: 0x0474,
  20065. afii10192: 0xF6C6,
  20066. afii10193: 0x045F,
  20067. afii10194: 0x0463,
  20068. afii10195: 0x0473,
  20069. afii10196: 0x0475,
  20070. afii10831: 0xF6C7,
  20071. afii10832: 0xF6C8,
  20072. afii10846: 0x04D9,
  20073. afii299: 0x200E,
  20074. afii300: 0x200F,
  20075. afii301: 0x200D,
  20076. afii57381: 0x066A,
  20077. afii57388: 0x060C,
  20078. afii57392: 0x0660,
  20079. afii57393: 0x0661,
  20080. afii57394: 0x0662,
  20081. afii57395: 0x0663,
  20082. afii57396: 0x0664,
  20083. afii57397: 0x0665,
  20084. afii57398: 0x0666,
  20085. afii57399: 0x0667,
  20086. afii57400: 0x0668,
  20087. afii57401: 0x0669,
  20088. afii57403: 0x061B,
  20089. afii57407: 0x061F,
  20090. afii57409: 0x0621,
  20091. afii57410: 0x0622,
  20092. afii57411: 0x0623,
  20093. afii57412: 0x0624,
  20094. afii57413: 0x0625,
  20095. afii57414: 0x0626,
  20096. afii57415: 0x0627,
  20097. afii57416: 0x0628,
  20098. afii57417: 0x0629,
  20099. afii57418: 0x062A,
  20100. afii57419: 0x062B,
  20101. afii57420: 0x062C,
  20102. afii57421: 0x062D,
  20103. afii57422: 0x062E,
  20104. afii57423: 0x062F,
  20105. afii57424: 0x0630,
  20106. afii57425: 0x0631,
  20107. afii57426: 0x0632,
  20108. afii57427: 0x0633,
  20109. afii57428: 0x0634,
  20110. afii57429: 0x0635,
  20111. afii57430: 0x0636,
  20112. afii57431: 0x0637,
  20113. afii57432: 0x0638,
  20114. afii57433: 0x0639,
  20115. afii57434: 0x063A,
  20116. afii57440: 0x0640,
  20117. afii57441: 0x0641,
  20118. afii57442: 0x0642,
  20119. afii57443: 0x0643,
  20120. afii57444: 0x0644,
  20121. afii57445: 0x0645,
  20122. afii57446: 0x0646,
  20123. afii57448: 0x0648,
  20124. afii57449: 0x0649,
  20125. afii57450: 0x064A,
  20126. afii57451: 0x064B,
  20127. afii57452: 0x064C,
  20128. afii57453: 0x064D,
  20129. afii57454: 0x064E,
  20130. afii57455: 0x064F,
  20131. afii57456: 0x0650,
  20132. afii57457: 0x0651,
  20133. afii57458: 0x0652,
  20134. afii57470: 0x0647,
  20135. afii57505: 0x06A4,
  20136. afii57506: 0x067E,
  20137. afii57507: 0x0686,
  20138. afii57508: 0x0698,
  20139. afii57509: 0x06AF,
  20140. afii57511: 0x0679,
  20141. afii57512: 0x0688,
  20142. afii57513: 0x0691,
  20143. afii57514: 0x06BA,
  20144. afii57519: 0x06D2,
  20145. afii57534: 0x06D5,
  20146. afii57636: 0x20AA,
  20147. afii57645: 0x05BE,
  20148. afii57658: 0x05C3,
  20149. afii57664: 0x05D0,
  20150. afii57665: 0x05D1,
  20151. afii57666: 0x05D2,
  20152. afii57667: 0x05D3,
  20153. afii57668: 0x05D4,
  20154. afii57669: 0x05D5,
  20155. afii57670: 0x05D6,
  20156. afii57671: 0x05D7,
  20157. afii57672: 0x05D8,
  20158. afii57673: 0x05D9,
  20159. afii57674: 0x05DA,
  20160. afii57675: 0x05DB,
  20161. afii57676: 0x05DC,
  20162. afii57677: 0x05DD,
  20163. afii57678: 0x05DE,
  20164. afii57679: 0x05DF,
  20165. afii57680: 0x05E0,
  20166. afii57681: 0x05E1,
  20167. afii57682: 0x05E2,
  20168. afii57683: 0x05E3,
  20169. afii57684: 0x05E4,
  20170. afii57685: 0x05E5,
  20171. afii57686: 0x05E6,
  20172. afii57687: 0x05E7,
  20173. afii57688: 0x05E8,
  20174. afii57689: 0x05E9,
  20175. afii57690: 0x05EA,
  20176. afii57694: 0xFB2A,
  20177. afii57695: 0xFB2B,
  20178. afii57700: 0xFB4B,
  20179. afii57705: 0xFB1F,
  20180. afii57716: 0x05F0,
  20181. afii57717: 0x05F1,
  20182. afii57718: 0x05F2,
  20183. afii57723: 0xFB35,
  20184. afii57793: 0x05B4,
  20185. afii57794: 0x05B5,
  20186. afii57795: 0x05B6,
  20187. afii57796: 0x05BB,
  20188. afii57797: 0x05B8,
  20189. afii57798: 0x05B7,
  20190. afii57799: 0x05B0,
  20191. afii57800: 0x05B2,
  20192. afii57801: 0x05B1,
  20193. afii57802: 0x05B3,
  20194. afii57803: 0x05C2,
  20195. afii57804: 0x05C1,
  20196. afii57806: 0x05B9,
  20197. afii57807: 0x05BC,
  20198. afii57839: 0x05BD,
  20199. afii57841: 0x05BF,
  20200. afii57842: 0x05C0,
  20201. afii57929: 0x02BC,
  20202. afii61248: 0x2105,
  20203. afii61289: 0x2113,
  20204. afii61352: 0x2116,
  20205. afii61573: 0x202C,
  20206. afii61574: 0x202D,
  20207. afii61575: 0x202E,
  20208. afii61664: 0x200C,
  20209. afii63167: 0x066D,
  20210. afii64937: 0x02BD,
  20211. agrave: 0x00E0,
  20212. agujarati: 0x0A85,
  20213. agurmukhi: 0x0A05,
  20214. ahiragana: 0x3042,
  20215. ahookabove: 0x1EA3,
  20216. aibengali: 0x0990,
  20217. aibopomofo: 0x311E,
  20218. aideva: 0x0910,
  20219. aiecyrillic: 0x04D5,
  20220. aigujarati: 0x0A90,
  20221. aigurmukhi: 0x0A10,
  20222. aimatragurmukhi: 0x0A48,
  20223. ainarabic: 0x0639,
  20224. ainfinalarabic: 0xFECA,
  20225. aininitialarabic: 0xFECB,
  20226. ainmedialarabic: 0xFECC,
  20227. ainvertedbreve: 0x0203,
  20228. aivowelsignbengali: 0x09C8,
  20229. aivowelsigndeva: 0x0948,
  20230. aivowelsigngujarati: 0x0AC8,
  20231. akatakana: 0x30A2,
  20232. akatakanahalfwidth: 0xFF71,
  20233. akorean: 0x314F,
  20234. alef: 0x05D0,
  20235. alefarabic: 0x0627,
  20236. alefdageshhebrew: 0xFB30,
  20237. aleffinalarabic: 0xFE8E,
  20238. alefhamzaabovearabic: 0x0623,
  20239. alefhamzaabovefinalarabic: 0xFE84,
  20240. alefhamzabelowarabic: 0x0625,
  20241. alefhamzabelowfinalarabic: 0xFE88,
  20242. alefhebrew: 0x05D0,
  20243. aleflamedhebrew: 0xFB4F,
  20244. alefmaddaabovearabic: 0x0622,
  20245. alefmaddaabovefinalarabic: 0xFE82,
  20246. alefmaksuraarabic: 0x0649,
  20247. alefmaksurafinalarabic: 0xFEF0,
  20248. alefmaksurainitialarabic: 0xFEF3,
  20249. alefmaksuramedialarabic: 0xFEF4,
  20250. alefpatahhebrew: 0xFB2E,
  20251. alefqamatshebrew: 0xFB2F,
  20252. aleph: 0x2135,
  20253. allequal: 0x224C,
  20254. alpha: 0x03B1,
  20255. alphatonos: 0x03AC,
  20256. amacron: 0x0101,
  20257. amonospace: 0xFF41,
  20258. ampersand: 0x0026,
  20259. ampersandmonospace: 0xFF06,
  20260. ampersandsmall: 0xF726,
  20261. amsquare: 0x33C2,
  20262. anbopomofo: 0x3122,
  20263. angbopomofo: 0x3124,
  20264. angbracketleft: 0x3008, // This glyph is missing from Adobe's original list.
  20265. angbracketright: 0x3009, // This glyph is missing from Adobe's original list.
  20266. angkhankhuthai: 0x0E5A,
  20267. angle: 0x2220,
  20268. anglebracketleft: 0x3008,
  20269. anglebracketleftvertical: 0xFE3F,
  20270. anglebracketright: 0x3009,
  20271. anglebracketrightvertical: 0xFE40,
  20272. angleleft: 0x2329,
  20273. angleright: 0x232A,
  20274. angstrom: 0x212B,
  20275. anoteleia: 0x0387,
  20276. anudattadeva: 0x0952,
  20277. anusvarabengali: 0x0982,
  20278. anusvaradeva: 0x0902,
  20279. anusvaragujarati: 0x0A82,
  20280. aogonek: 0x0105,
  20281. apaatosquare: 0x3300,
  20282. aparen: 0x249C,
  20283. apostrophearmenian: 0x055A,
  20284. apostrophemod: 0x02BC,
  20285. apple: 0xF8FF,
  20286. approaches: 0x2250,
  20287. approxequal: 0x2248,
  20288. approxequalorimage: 0x2252,
  20289. approximatelyequal: 0x2245,
  20290. araeaekorean: 0x318E,
  20291. araeakorean: 0x318D,
  20292. arc: 0x2312,
  20293. arighthalfring: 0x1E9A,
  20294. aring: 0x00E5,
  20295. aringacute: 0x01FB,
  20296. aringbelow: 0x1E01,
  20297. arrowboth: 0x2194,
  20298. arrowdashdown: 0x21E3,
  20299. arrowdashleft: 0x21E0,
  20300. arrowdashright: 0x21E2,
  20301. arrowdashup: 0x21E1,
  20302. arrowdblboth: 0x21D4,
  20303. arrowdbldown: 0x21D3,
  20304. arrowdblleft: 0x21D0,
  20305. arrowdblright: 0x21D2,
  20306. arrowdblup: 0x21D1,
  20307. arrowdown: 0x2193,
  20308. arrowdownleft: 0x2199,
  20309. arrowdownright: 0x2198,
  20310. arrowdownwhite: 0x21E9,
  20311. arrowheaddownmod: 0x02C5,
  20312. arrowheadleftmod: 0x02C2,
  20313. arrowheadrightmod: 0x02C3,
  20314. arrowheadupmod: 0x02C4,
  20315. arrowhorizex: 0xF8E7,
  20316. arrowleft: 0x2190,
  20317. arrowleftdbl: 0x21D0,
  20318. arrowleftdblstroke: 0x21CD,
  20319. arrowleftoverright: 0x21C6,
  20320. arrowleftwhite: 0x21E6,
  20321. arrowright: 0x2192,
  20322. arrowrightdblstroke: 0x21CF,
  20323. arrowrightheavy: 0x279E,
  20324. arrowrightoverleft: 0x21C4,
  20325. arrowrightwhite: 0x21E8,
  20326. arrowtableft: 0x21E4,
  20327. arrowtabright: 0x21E5,
  20328. arrowup: 0x2191,
  20329. arrowupdn: 0x2195,
  20330. arrowupdnbse: 0x21A8,
  20331. arrowupdownbase: 0x21A8,
  20332. arrowupleft: 0x2196,
  20333. arrowupleftofdown: 0x21C5,
  20334. arrowupright: 0x2197,
  20335. arrowupwhite: 0x21E7,
  20336. arrowvertex: 0xF8E6,
  20337. asciicircum: 0x005E,
  20338. asciicircummonospace: 0xFF3E,
  20339. asciitilde: 0x007E,
  20340. asciitildemonospace: 0xFF5E,
  20341. ascript: 0x0251,
  20342. ascriptturned: 0x0252,
  20343. asmallhiragana: 0x3041,
  20344. asmallkatakana: 0x30A1,
  20345. asmallkatakanahalfwidth: 0xFF67,
  20346. asterisk: 0x002A,
  20347. asteriskaltonearabic: 0x066D,
  20348. asteriskarabic: 0x066D,
  20349. asteriskmath: 0x2217,
  20350. asteriskmonospace: 0xFF0A,
  20351. asterisksmall: 0xFE61,
  20352. asterism: 0x2042,
  20353. asuperior: 0xF6E9,
  20354. asymptoticallyequal: 0x2243,
  20355. at: 0x0040,
  20356. atilde: 0x00E3,
  20357. atmonospace: 0xFF20,
  20358. atsmall: 0xFE6B,
  20359. aturned: 0x0250,
  20360. aubengali: 0x0994,
  20361. aubopomofo: 0x3120,
  20362. audeva: 0x0914,
  20363. augujarati: 0x0A94,
  20364. augurmukhi: 0x0A14,
  20365. aulengthmarkbengali: 0x09D7,
  20366. aumatragurmukhi: 0x0A4C,
  20367. auvowelsignbengali: 0x09CC,
  20368. auvowelsigndeva: 0x094C,
  20369. auvowelsigngujarati: 0x0ACC,
  20370. avagrahadeva: 0x093D,
  20371. aybarmenian: 0x0561,
  20372. ayin: 0x05E2,
  20373. ayinaltonehebrew: 0xFB20,
  20374. ayinhebrew: 0x05E2,
  20375. b: 0x0062,
  20376. babengali: 0x09AC,
  20377. backslash: 0x005C,
  20378. backslashmonospace: 0xFF3C,
  20379. badeva: 0x092C,
  20380. bagujarati: 0x0AAC,
  20381. bagurmukhi: 0x0A2C,
  20382. bahiragana: 0x3070,
  20383. bahtthai: 0x0E3F,
  20384. bakatakana: 0x30D0,
  20385. bar: 0x007C,
  20386. barmonospace: 0xFF5C,
  20387. bbopomofo: 0x3105,
  20388. bcircle: 0x24D1,
  20389. bdotaccent: 0x1E03,
  20390. bdotbelow: 0x1E05,
  20391. beamedsixteenthnotes: 0x266C,
  20392. because: 0x2235,
  20393. becyrillic: 0x0431,
  20394. beharabic: 0x0628,
  20395. behfinalarabic: 0xFE90,
  20396. behinitialarabic: 0xFE91,
  20397. behiragana: 0x3079,
  20398. behmedialarabic: 0xFE92,
  20399. behmeeminitialarabic: 0xFC9F,
  20400. behmeemisolatedarabic: 0xFC08,
  20401. behnoonfinalarabic: 0xFC6D,
  20402. bekatakana: 0x30D9,
  20403. benarmenian: 0x0562,
  20404. bet: 0x05D1,
  20405. beta: 0x03B2,
  20406. betasymbolgreek: 0x03D0,
  20407. betdagesh: 0xFB31,
  20408. betdageshhebrew: 0xFB31,
  20409. bethebrew: 0x05D1,
  20410. betrafehebrew: 0xFB4C,
  20411. bhabengali: 0x09AD,
  20412. bhadeva: 0x092D,
  20413. bhagujarati: 0x0AAD,
  20414. bhagurmukhi: 0x0A2D,
  20415. bhook: 0x0253,
  20416. bihiragana: 0x3073,
  20417. bikatakana: 0x30D3,
  20418. bilabialclick: 0x0298,
  20419. bindigurmukhi: 0x0A02,
  20420. birusquare: 0x3331,
  20421. blackcircle: 0x25CF,
  20422. blackdiamond: 0x25C6,
  20423. blackdownpointingtriangle: 0x25BC,
  20424. blackleftpointingpointer: 0x25C4,
  20425. blackleftpointingtriangle: 0x25C0,
  20426. blacklenticularbracketleft: 0x3010,
  20427. blacklenticularbracketleftvertical: 0xFE3B,
  20428. blacklenticularbracketright: 0x3011,
  20429. blacklenticularbracketrightvertical: 0xFE3C,
  20430. blacklowerlefttriangle: 0x25E3,
  20431. blacklowerrighttriangle: 0x25E2,
  20432. blackrectangle: 0x25AC,
  20433. blackrightpointingpointer: 0x25BA,
  20434. blackrightpointingtriangle: 0x25B6,
  20435. blacksmallsquare: 0x25AA,
  20436. blacksmilingface: 0x263B,
  20437. blacksquare: 0x25A0,
  20438. blackstar: 0x2605,
  20439. blackupperlefttriangle: 0x25E4,
  20440. blackupperrighttriangle: 0x25E5,
  20441. blackuppointingsmalltriangle: 0x25B4,
  20442. blackuppointingtriangle: 0x25B2,
  20443. blank: 0x2423,
  20444. blinebelow: 0x1E07,
  20445. block: 0x2588,
  20446. bmonospace: 0xFF42,
  20447. bobaimaithai: 0x0E1A,
  20448. bohiragana: 0x307C,
  20449. bokatakana: 0x30DC,
  20450. bparen: 0x249D,
  20451. bqsquare: 0x33C3,
  20452. braceex: 0xF8F4,
  20453. braceleft: 0x007B,
  20454. braceleftbt: 0xF8F3,
  20455. braceleftmid: 0xF8F2,
  20456. braceleftmonospace: 0xFF5B,
  20457. braceleftsmall: 0xFE5B,
  20458. bracelefttp: 0xF8F1,
  20459. braceleftvertical: 0xFE37,
  20460. braceright: 0x007D,
  20461. bracerightbt: 0xF8FE,
  20462. bracerightmid: 0xF8FD,
  20463. bracerightmonospace: 0xFF5D,
  20464. bracerightsmall: 0xFE5C,
  20465. bracerighttp: 0xF8FC,
  20466. bracerightvertical: 0xFE38,
  20467. bracketleft: 0x005B,
  20468. bracketleftbt: 0xF8F0,
  20469. bracketleftex: 0xF8EF,
  20470. bracketleftmonospace: 0xFF3B,
  20471. bracketlefttp: 0xF8EE,
  20472. bracketright: 0x005D,
  20473. bracketrightbt: 0xF8FB,
  20474. bracketrightex: 0xF8FA,
  20475. bracketrightmonospace: 0xFF3D,
  20476. bracketrighttp: 0xF8F9,
  20477. breve: 0x02D8,
  20478. brevebelowcmb: 0x032E,
  20479. brevecmb: 0x0306,
  20480. breveinvertedbelowcmb: 0x032F,
  20481. breveinvertedcmb: 0x0311,
  20482. breveinverteddoublecmb: 0x0361,
  20483. bridgebelowcmb: 0x032A,
  20484. bridgeinvertedbelowcmb: 0x033A,
  20485. brokenbar: 0x00A6,
  20486. bstroke: 0x0180,
  20487. bsuperior: 0xF6EA,
  20488. btopbar: 0x0183,
  20489. buhiragana: 0x3076,
  20490. bukatakana: 0x30D6,
  20491. bullet: 0x2022,
  20492. bulletinverse: 0x25D8,
  20493. bulletoperator: 0x2219,
  20494. bullseye: 0x25CE,
  20495. c: 0x0063,
  20496. caarmenian: 0x056E,
  20497. cabengali: 0x099A,
  20498. cacute: 0x0107,
  20499. cadeva: 0x091A,
  20500. cagujarati: 0x0A9A,
  20501. cagurmukhi: 0x0A1A,
  20502. calsquare: 0x3388,
  20503. candrabindubengali: 0x0981,
  20504. candrabinducmb: 0x0310,
  20505. candrabindudeva: 0x0901,
  20506. candrabindugujarati: 0x0A81,
  20507. capslock: 0x21EA,
  20508. careof: 0x2105,
  20509. caron: 0x02C7,
  20510. caronbelowcmb: 0x032C,
  20511. caroncmb: 0x030C,
  20512. carriagereturn: 0x21B5,
  20513. cbopomofo: 0x3118,
  20514. ccaron: 0x010D,
  20515. ccedilla: 0x00E7,
  20516. ccedillaacute: 0x1E09,
  20517. ccircle: 0x24D2,
  20518. ccircumflex: 0x0109,
  20519. ccurl: 0x0255,
  20520. cdot: 0x010B,
  20521. cdotaccent: 0x010B,
  20522. cdsquare: 0x33C5,
  20523. cedilla: 0x00B8,
  20524. cedillacmb: 0x0327,
  20525. cent: 0x00A2,
  20526. centigrade: 0x2103,
  20527. centinferior: 0xF6DF,
  20528. centmonospace: 0xFFE0,
  20529. centoldstyle: 0xF7A2,
  20530. centsuperior: 0xF6E0,
  20531. chaarmenian: 0x0579,
  20532. chabengali: 0x099B,
  20533. chadeva: 0x091B,
  20534. chagujarati: 0x0A9B,
  20535. chagurmukhi: 0x0A1B,
  20536. chbopomofo: 0x3114,
  20537. cheabkhasiancyrillic: 0x04BD,
  20538. checkmark: 0x2713,
  20539. checyrillic: 0x0447,
  20540. chedescenderabkhasiancyrillic: 0x04BF,
  20541. chedescendercyrillic: 0x04B7,
  20542. chedieresiscyrillic: 0x04F5,
  20543. cheharmenian: 0x0573,
  20544. chekhakassiancyrillic: 0x04CC,
  20545. cheverticalstrokecyrillic: 0x04B9,
  20546. chi: 0x03C7,
  20547. chieuchacirclekorean: 0x3277,
  20548. chieuchaparenkorean: 0x3217,
  20549. chieuchcirclekorean: 0x3269,
  20550. chieuchkorean: 0x314A,
  20551. chieuchparenkorean: 0x3209,
  20552. chochangthai: 0x0E0A,
  20553. chochanthai: 0x0E08,
  20554. chochingthai: 0x0E09,
  20555. chochoethai: 0x0E0C,
  20556. chook: 0x0188,
  20557. cieucacirclekorean: 0x3276,
  20558. cieucaparenkorean: 0x3216,
  20559. cieuccirclekorean: 0x3268,
  20560. cieuckorean: 0x3148,
  20561. cieucparenkorean: 0x3208,
  20562. cieucuparenkorean: 0x321C,
  20563. circle: 0x25CB,
  20564. circlecopyrt: 0x00A9, // This glyph is missing from Adobe's original list.
  20565. circlemultiply: 0x2297,
  20566. circleot: 0x2299,
  20567. circleplus: 0x2295,
  20568. circlepostalmark: 0x3036,
  20569. circlewithlefthalfblack: 0x25D0,
  20570. circlewithrighthalfblack: 0x25D1,
  20571. circumflex: 0x02C6,
  20572. circumflexbelowcmb: 0x032D,
  20573. circumflexcmb: 0x0302,
  20574. clear: 0x2327,
  20575. clickalveolar: 0x01C2,
  20576. clickdental: 0x01C0,
  20577. clicklateral: 0x01C1,
  20578. clickretroflex: 0x01C3,
  20579. club: 0x2663,
  20580. clubsuitblack: 0x2663,
  20581. clubsuitwhite: 0x2667,
  20582. cmcubedsquare: 0x33A4,
  20583. cmonospace: 0xFF43,
  20584. cmsquaredsquare: 0x33A0,
  20585. coarmenian: 0x0581,
  20586. colon: 0x003A,
  20587. colonmonetary: 0x20A1,
  20588. colonmonospace: 0xFF1A,
  20589. colonsign: 0x20A1,
  20590. colonsmall: 0xFE55,
  20591. colontriangularhalfmod: 0x02D1,
  20592. colontriangularmod: 0x02D0,
  20593. comma: 0x002C,
  20594. commaabovecmb: 0x0313,
  20595. commaaboverightcmb: 0x0315,
  20596. commaaccent: 0xF6C3,
  20597. commaarabic: 0x060C,
  20598. commaarmenian: 0x055D,
  20599. commainferior: 0xF6E1,
  20600. commamonospace: 0xFF0C,
  20601. commareversedabovecmb: 0x0314,
  20602. commareversedmod: 0x02BD,
  20603. commasmall: 0xFE50,
  20604. commasuperior: 0xF6E2,
  20605. commaturnedabovecmb: 0x0312,
  20606. commaturnedmod: 0x02BB,
  20607. compass: 0x263C,
  20608. congruent: 0x2245,
  20609. contourintegral: 0x222E,
  20610. control: 0x2303,
  20611. controlACK: 0x0006,
  20612. controlBEL: 0x0007,
  20613. controlBS: 0x0008,
  20614. controlCAN: 0x0018,
  20615. controlCR: 0x000D,
  20616. controlDC1: 0x0011,
  20617. controlDC2: 0x0012,
  20618. controlDC3: 0x0013,
  20619. controlDC4: 0x0014,
  20620. controlDEL: 0x007F,
  20621. controlDLE: 0x0010,
  20622. controlEM: 0x0019,
  20623. controlENQ: 0x0005,
  20624. controlEOT: 0x0004,
  20625. controlESC: 0x001B,
  20626. controlETB: 0x0017,
  20627. controlETX: 0x0003,
  20628. controlFF: 0x000C,
  20629. controlFS: 0x001C,
  20630. controlGS: 0x001D,
  20631. controlHT: 0x0009,
  20632. controlLF: 0x000A,
  20633. controlNAK: 0x0015,
  20634. controlRS: 0x001E,
  20635. controlSI: 0x000F,
  20636. controlSO: 0x000E,
  20637. controlSOT: 0x0002,
  20638. controlSTX: 0x0001,
  20639. controlSUB: 0x001A,
  20640. controlSYN: 0x0016,
  20641. controlUS: 0x001F,
  20642. controlVT: 0x000B,
  20643. copyright: 0x00A9,
  20644. copyrightsans: 0xF8E9,
  20645. copyrightserif: 0xF6D9,
  20646. cornerbracketleft: 0x300C,
  20647. cornerbracketlefthalfwidth: 0xFF62,
  20648. cornerbracketleftvertical: 0xFE41,
  20649. cornerbracketright: 0x300D,
  20650. cornerbracketrighthalfwidth: 0xFF63,
  20651. cornerbracketrightvertical: 0xFE42,
  20652. corporationsquare: 0x337F,
  20653. cosquare: 0x33C7,
  20654. coverkgsquare: 0x33C6,
  20655. cparen: 0x249E,
  20656. cruzeiro: 0x20A2,
  20657. cstretched: 0x0297,
  20658. curlyand: 0x22CF,
  20659. curlyor: 0x22CE,
  20660. currency: 0x00A4,
  20661. cyrBreve: 0xF6D1,
  20662. cyrFlex: 0xF6D2,
  20663. cyrbreve: 0xF6D4,
  20664. cyrflex: 0xF6D5,
  20665. d: 0x0064,
  20666. daarmenian: 0x0564,
  20667. dabengali: 0x09A6,
  20668. dadarabic: 0x0636,
  20669. dadeva: 0x0926,
  20670. dadfinalarabic: 0xFEBE,
  20671. dadinitialarabic: 0xFEBF,
  20672. dadmedialarabic: 0xFEC0,
  20673. dagesh: 0x05BC,
  20674. dageshhebrew: 0x05BC,
  20675. dagger: 0x2020,
  20676. daggerdbl: 0x2021,
  20677. dagujarati: 0x0AA6,
  20678. dagurmukhi: 0x0A26,
  20679. dahiragana: 0x3060,
  20680. dakatakana: 0x30C0,
  20681. dalarabic: 0x062F,
  20682. dalet: 0x05D3,
  20683. daletdagesh: 0xFB33,
  20684. daletdageshhebrew: 0xFB33,
  20685. dalethebrew: 0x05D3,
  20686. dalfinalarabic: 0xFEAA,
  20687. dammaarabic: 0x064F,
  20688. dammalowarabic: 0x064F,
  20689. dammatanaltonearabic: 0x064C,
  20690. dammatanarabic: 0x064C,
  20691. danda: 0x0964,
  20692. dargahebrew: 0x05A7,
  20693. dargalefthebrew: 0x05A7,
  20694. dasiapneumatacyrilliccmb: 0x0485,
  20695. dblGrave: 0xF6D3,
  20696. dblanglebracketleft: 0x300A,
  20697. dblanglebracketleftvertical: 0xFE3D,
  20698. dblanglebracketright: 0x300B,
  20699. dblanglebracketrightvertical: 0xFE3E,
  20700. dblarchinvertedbelowcmb: 0x032B,
  20701. dblarrowleft: 0x21D4,
  20702. dblarrowright: 0x21D2,
  20703. dbldanda: 0x0965,
  20704. dblgrave: 0xF6D6,
  20705. dblgravecmb: 0x030F,
  20706. dblintegral: 0x222C,
  20707. dbllowline: 0x2017,
  20708. dbllowlinecmb: 0x0333,
  20709. dbloverlinecmb: 0x033F,
  20710. dblprimemod: 0x02BA,
  20711. dblverticalbar: 0x2016,
  20712. dblverticallineabovecmb: 0x030E,
  20713. dbopomofo: 0x3109,
  20714. dbsquare: 0x33C8,
  20715. dcaron: 0x010F,
  20716. dcedilla: 0x1E11,
  20717. dcircle: 0x24D3,
  20718. dcircumflexbelow: 0x1E13,
  20719. dcroat: 0x0111,
  20720. ddabengali: 0x09A1,
  20721. ddadeva: 0x0921,
  20722. ddagujarati: 0x0AA1,
  20723. ddagurmukhi: 0x0A21,
  20724. ddalarabic: 0x0688,
  20725. ddalfinalarabic: 0xFB89,
  20726. dddhadeva: 0x095C,
  20727. ddhabengali: 0x09A2,
  20728. ddhadeva: 0x0922,
  20729. ddhagujarati: 0x0AA2,
  20730. ddhagurmukhi: 0x0A22,
  20731. ddotaccent: 0x1E0B,
  20732. ddotbelow: 0x1E0D,
  20733. decimalseparatorarabic: 0x066B,
  20734. decimalseparatorpersian: 0x066B,
  20735. decyrillic: 0x0434,
  20736. degree: 0x00B0,
  20737. dehihebrew: 0x05AD,
  20738. dehiragana: 0x3067,
  20739. deicoptic: 0x03EF,
  20740. dekatakana: 0x30C7,
  20741. deleteleft: 0x232B,
  20742. deleteright: 0x2326,
  20743. delta: 0x03B4,
  20744. deltaturned: 0x018D,
  20745. denominatorminusonenumeratorbengali: 0x09F8,
  20746. dezh: 0x02A4,
  20747. dhabengali: 0x09A7,
  20748. dhadeva: 0x0927,
  20749. dhagujarati: 0x0AA7,
  20750. dhagurmukhi: 0x0A27,
  20751. dhook: 0x0257,
  20752. dialytikatonos: 0x0385,
  20753. dialytikatonoscmb: 0x0344,
  20754. diamond: 0x2666,
  20755. diamondsuitwhite: 0x2662,
  20756. dieresis: 0x00A8,
  20757. dieresisacute: 0xF6D7,
  20758. dieresisbelowcmb: 0x0324,
  20759. dieresiscmb: 0x0308,
  20760. dieresisgrave: 0xF6D8,
  20761. dieresistonos: 0x0385,
  20762. dihiragana: 0x3062,
  20763. dikatakana: 0x30C2,
  20764. dittomark: 0x3003,
  20765. divide: 0x00F7,
  20766. divides: 0x2223,
  20767. divisionslash: 0x2215,
  20768. djecyrillic: 0x0452,
  20769. dkshade: 0x2593,
  20770. dlinebelow: 0x1E0F,
  20771. dlsquare: 0x3397,
  20772. dmacron: 0x0111,
  20773. dmonospace: 0xFF44,
  20774. dnblock: 0x2584,
  20775. dochadathai: 0x0E0E,
  20776. dodekthai: 0x0E14,
  20777. dohiragana: 0x3069,
  20778. dokatakana: 0x30C9,
  20779. dollar: 0x0024,
  20780. dollarinferior: 0xF6E3,
  20781. dollarmonospace: 0xFF04,
  20782. dollaroldstyle: 0xF724,
  20783. dollarsmall: 0xFE69,
  20784. dollarsuperior: 0xF6E4,
  20785. dong: 0x20AB,
  20786. dorusquare: 0x3326,
  20787. dotaccent: 0x02D9,
  20788. dotaccentcmb: 0x0307,
  20789. dotbelowcmb: 0x0323,
  20790. dotbelowcomb: 0x0323,
  20791. dotkatakana: 0x30FB,
  20792. dotlessi: 0x0131,
  20793. dotlessj: 0xF6BE,
  20794. dotlessjstrokehook: 0x0284,
  20795. dotmath: 0x22C5,
  20796. dottedcircle: 0x25CC,
  20797. doubleyodpatah: 0xFB1F,
  20798. doubleyodpatahhebrew: 0xFB1F,
  20799. downtackbelowcmb: 0x031E,
  20800. downtackmod: 0x02D5,
  20801. dparen: 0x249F,
  20802. dsuperior: 0xF6EB,
  20803. dtail: 0x0256,
  20804. dtopbar: 0x018C,
  20805. duhiragana: 0x3065,
  20806. dukatakana: 0x30C5,
  20807. dz: 0x01F3,
  20808. dzaltone: 0x02A3,
  20809. dzcaron: 0x01C6,
  20810. dzcurl: 0x02A5,
  20811. dzeabkhasiancyrillic: 0x04E1,
  20812. dzecyrillic: 0x0455,
  20813. dzhecyrillic: 0x045F,
  20814. e: 0x0065,
  20815. eacute: 0x00E9,
  20816. earth: 0x2641,
  20817. ebengali: 0x098F,
  20818. ebopomofo: 0x311C,
  20819. ebreve: 0x0115,
  20820. ecandradeva: 0x090D,
  20821. ecandragujarati: 0x0A8D,
  20822. ecandravowelsigndeva: 0x0945,
  20823. ecandravowelsigngujarati: 0x0AC5,
  20824. ecaron: 0x011B,
  20825. ecedillabreve: 0x1E1D,
  20826. echarmenian: 0x0565,
  20827. echyiwnarmenian: 0x0587,
  20828. ecircle: 0x24D4,
  20829. ecircumflex: 0x00EA,
  20830. ecircumflexacute: 0x1EBF,
  20831. ecircumflexbelow: 0x1E19,
  20832. ecircumflexdotbelow: 0x1EC7,
  20833. ecircumflexgrave: 0x1EC1,
  20834. ecircumflexhookabove: 0x1EC3,
  20835. ecircumflextilde: 0x1EC5,
  20836. ecyrillic: 0x0454,
  20837. edblgrave: 0x0205,
  20838. edeva: 0x090F,
  20839. edieresis: 0x00EB,
  20840. edot: 0x0117,
  20841. edotaccent: 0x0117,
  20842. edotbelow: 0x1EB9,
  20843. eegurmukhi: 0x0A0F,
  20844. eematragurmukhi: 0x0A47,
  20845. efcyrillic: 0x0444,
  20846. egrave: 0x00E8,
  20847. egujarati: 0x0A8F,
  20848. eharmenian: 0x0567,
  20849. ehbopomofo: 0x311D,
  20850. ehiragana: 0x3048,
  20851. ehookabove: 0x1EBB,
  20852. eibopomofo: 0x311F,
  20853. eight: 0x0038,
  20854. eightarabic: 0x0668,
  20855. eightbengali: 0x09EE,
  20856. eightcircle: 0x2467,
  20857. eightcircleinversesansserif: 0x2791,
  20858. eightdeva: 0x096E,
  20859. eighteencircle: 0x2471,
  20860. eighteenparen: 0x2485,
  20861. eighteenperiod: 0x2499,
  20862. eightgujarati: 0x0AEE,
  20863. eightgurmukhi: 0x0A6E,
  20864. eighthackarabic: 0x0668,
  20865. eighthangzhou: 0x3028,
  20866. eighthnotebeamed: 0x266B,
  20867. eightideographicparen: 0x3227,
  20868. eightinferior: 0x2088,
  20869. eightmonospace: 0xFF18,
  20870. eightoldstyle: 0xF738,
  20871. eightparen: 0x247B,
  20872. eightperiod: 0x248F,
  20873. eightpersian: 0x06F8,
  20874. eightroman: 0x2177,
  20875. eightsuperior: 0x2078,
  20876. eightthai: 0x0E58,
  20877. einvertedbreve: 0x0207,
  20878. eiotifiedcyrillic: 0x0465,
  20879. ekatakana: 0x30A8,
  20880. ekatakanahalfwidth: 0xFF74,
  20881. ekonkargurmukhi: 0x0A74,
  20882. ekorean: 0x3154,
  20883. elcyrillic: 0x043B,
  20884. element: 0x2208,
  20885. elevencircle: 0x246A,
  20886. elevenparen: 0x247E,
  20887. elevenperiod: 0x2492,
  20888. elevenroman: 0x217A,
  20889. ellipsis: 0x2026,
  20890. ellipsisvertical: 0x22EE,
  20891. emacron: 0x0113,
  20892. emacronacute: 0x1E17,
  20893. emacrongrave: 0x1E15,
  20894. emcyrillic: 0x043C,
  20895. emdash: 0x2014,
  20896. emdashvertical: 0xFE31,
  20897. emonospace: 0xFF45,
  20898. emphasismarkarmenian: 0x055B,
  20899. emptyset: 0x2205,
  20900. enbopomofo: 0x3123,
  20901. encyrillic: 0x043D,
  20902. endash: 0x2013,
  20903. endashvertical: 0xFE32,
  20904. endescendercyrillic: 0x04A3,
  20905. eng: 0x014B,
  20906. engbopomofo: 0x3125,
  20907. enghecyrillic: 0x04A5,
  20908. enhookcyrillic: 0x04C8,
  20909. enspace: 0x2002,
  20910. eogonek: 0x0119,
  20911. eokorean: 0x3153,
  20912. eopen: 0x025B,
  20913. eopenclosed: 0x029A,
  20914. eopenreversed: 0x025C,
  20915. eopenreversedclosed: 0x025E,
  20916. eopenreversedhook: 0x025D,
  20917. eparen: 0x24A0,
  20918. epsilon: 0x03B5,
  20919. epsilontonos: 0x03AD,
  20920. equal: 0x003D,
  20921. equalmonospace: 0xFF1D,
  20922. equalsmall: 0xFE66,
  20923. equalsuperior: 0x207C,
  20924. equivalence: 0x2261,
  20925. erbopomofo: 0x3126,
  20926. ercyrillic: 0x0440,
  20927. ereversed: 0x0258,
  20928. ereversedcyrillic: 0x044D,
  20929. escyrillic: 0x0441,
  20930. esdescendercyrillic: 0x04AB,
  20931. esh: 0x0283,
  20932. eshcurl: 0x0286,
  20933. eshortdeva: 0x090E,
  20934. eshortvowelsigndeva: 0x0946,
  20935. eshreversedloop: 0x01AA,
  20936. eshsquatreversed: 0x0285,
  20937. esmallhiragana: 0x3047,
  20938. esmallkatakana: 0x30A7,
  20939. esmallkatakanahalfwidth: 0xFF6A,
  20940. estimated: 0x212E,
  20941. esuperior: 0xF6EC,
  20942. eta: 0x03B7,
  20943. etarmenian: 0x0568,
  20944. etatonos: 0x03AE,
  20945. eth: 0x00F0,
  20946. etilde: 0x1EBD,
  20947. etildebelow: 0x1E1B,
  20948. etnahtafoukhhebrew: 0x0591,
  20949. etnahtafoukhlefthebrew: 0x0591,
  20950. etnahtahebrew: 0x0591,
  20951. etnahtalefthebrew: 0x0591,
  20952. eturned: 0x01DD,
  20953. eukorean: 0x3161,
  20954. euro: 0x20AC,
  20955. evowelsignbengali: 0x09C7,
  20956. evowelsigndeva: 0x0947,
  20957. evowelsigngujarati: 0x0AC7,
  20958. exclam: 0x0021,
  20959. exclamarmenian: 0x055C,
  20960. exclamdbl: 0x203C,
  20961. exclamdown: 0x00A1,
  20962. exclamdownsmall: 0xF7A1,
  20963. exclammonospace: 0xFF01,
  20964. exclamsmall: 0xF721,
  20965. existential: 0x2203,
  20966. ezh: 0x0292,
  20967. ezhcaron: 0x01EF,
  20968. ezhcurl: 0x0293,
  20969. ezhreversed: 0x01B9,
  20970. ezhtail: 0x01BA,
  20971. f: 0x0066,
  20972. fadeva: 0x095E,
  20973. fagurmukhi: 0x0A5E,
  20974. fahrenheit: 0x2109,
  20975. fathaarabic: 0x064E,
  20976. fathalowarabic: 0x064E,
  20977. fathatanarabic: 0x064B,
  20978. fbopomofo: 0x3108,
  20979. fcircle: 0x24D5,
  20980. fdotaccent: 0x1E1F,
  20981. feharabic: 0x0641,
  20982. feharmenian: 0x0586,
  20983. fehfinalarabic: 0xFED2,
  20984. fehinitialarabic: 0xFED3,
  20985. fehmedialarabic: 0xFED4,
  20986. feicoptic: 0x03E5,
  20987. female: 0x2640,
  20988. ff: 0xFB00,
  20989. ffi: 0xFB03,
  20990. ffl: 0xFB04,
  20991. fi: 0xFB01,
  20992. fifteencircle: 0x246E,
  20993. fifteenparen: 0x2482,
  20994. fifteenperiod: 0x2496,
  20995. figuredash: 0x2012,
  20996. filledbox: 0x25A0,
  20997. filledrect: 0x25AC,
  20998. finalkaf: 0x05DA,
  20999. finalkafdagesh: 0xFB3A,
  21000. finalkafdageshhebrew: 0xFB3A,
  21001. finalkafhebrew: 0x05DA,
  21002. finalmem: 0x05DD,
  21003. finalmemhebrew: 0x05DD,
  21004. finalnun: 0x05DF,
  21005. finalnunhebrew: 0x05DF,
  21006. finalpe: 0x05E3,
  21007. finalpehebrew: 0x05E3,
  21008. finaltsadi: 0x05E5,
  21009. finaltsadihebrew: 0x05E5,
  21010. firsttonechinese: 0x02C9,
  21011. fisheye: 0x25C9,
  21012. fitacyrillic: 0x0473,
  21013. five: 0x0035,
  21014. fivearabic: 0x0665,
  21015. fivebengali: 0x09EB,
  21016. fivecircle: 0x2464,
  21017. fivecircleinversesansserif: 0x278E,
  21018. fivedeva: 0x096B,
  21019. fiveeighths: 0x215D,
  21020. fivegujarati: 0x0AEB,
  21021. fivegurmukhi: 0x0A6B,
  21022. fivehackarabic: 0x0665,
  21023. fivehangzhou: 0x3025,
  21024. fiveideographicparen: 0x3224,
  21025. fiveinferior: 0x2085,
  21026. fivemonospace: 0xFF15,
  21027. fiveoldstyle: 0xF735,
  21028. fiveparen: 0x2478,
  21029. fiveperiod: 0x248C,
  21030. fivepersian: 0x06F5,
  21031. fiveroman: 0x2174,
  21032. fivesuperior: 0x2075,
  21033. fivethai: 0x0E55,
  21034. fl: 0xFB02,
  21035. florin: 0x0192,
  21036. fmonospace: 0xFF46,
  21037. fmsquare: 0x3399,
  21038. fofanthai: 0x0E1F,
  21039. fofathai: 0x0E1D,
  21040. fongmanthai: 0x0E4F,
  21041. forall: 0x2200,
  21042. four: 0x0034,
  21043. fourarabic: 0x0664,
  21044. fourbengali: 0x09EA,
  21045. fourcircle: 0x2463,
  21046. fourcircleinversesansserif: 0x278D,
  21047. fourdeva: 0x096A,
  21048. fourgujarati: 0x0AEA,
  21049. fourgurmukhi: 0x0A6A,
  21050. fourhackarabic: 0x0664,
  21051. fourhangzhou: 0x3024,
  21052. fourideographicparen: 0x3223,
  21053. fourinferior: 0x2084,
  21054. fourmonospace: 0xFF14,
  21055. fournumeratorbengali: 0x09F7,
  21056. fouroldstyle: 0xF734,
  21057. fourparen: 0x2477,
  21058. fourperiod: 0x248B,
  21059. fourpersian: 0x06F4,
  21060. fourroman: 0x2173,
  21061. foursuperior: 0x2074,
  21062. fourteencircle: 0x246D,
  21063. fourteenparen: 0x2481,
  21064. fourteenperiod: 0x2495,
  21065. fourthai: 0x0E54,
  21066. fourthtonechinese: 0x02CB,
  21067. fparen: 0x24A1,
  21068. fraction: 0x2044,
  21069. franc: 0x20A3,
  21070. g: 0x0067,
  21071. gabengali: 0x0997,
  21072. gacute: 0x01F5,
  21073. gadeva: 0x0917,
  21074. gafarabic: 0x06AF,
  21075. gaffinalarabic: 0xFB93,
  21076. gafinitialarabic: 0xFB94,
  21077. gafmedialarabic: 0xFB95,
  21078. gagujarati: 0x0A97,
  21079. gagurmukhi: 0x0A17,
  21080. gahiragana: 0x304C,
  21081. gakatakana: 0x30AC,
  21082. gamma: 0x03B3,
  21083. gammalatinsmall: 0x0263,
  21084. gammasuperior: 0x02E0,
  21085. gangiacoptic: 0x03EB,
  21086. gbopomofo: 0x310D,
  21087. gbreve: 0x011F,
  21088. gcaron: 0x01E7,
  21089. gcedilla: 0x0123,
  21090. gcircle: 0x24D6,
  21091. gcircumflex: 0x011D,
  21092. gcommaaccent: 0x0123,
  21093. gdot: 0x0121,
  21094. gdotaccent: 0x0121,
  21095. gecyrillic: 0x0433,
  21096. gehiragana: 0x3052,
  21097. gekatakana: 0x30B2,
  21098. geometricallyequal: 0x2251,
  21099. gereshaccenthebrew: 0x059C,
  21100. gereshhebrew: 0x05F3,
  21101. gereshmuqdamhebrew: 0x059D,
  21102. germandbls: 0x00DF,
  21103. gershayimaccenthebrew: 0x059E,
  21104. gershayimhebrew: 0x05F4,
  21105. getamark: 0x3013,
  21106. ghabengali: 0x0998,
  21107. ghadarmenian: 0x0572,
  21108. ghadeva: 0x0918,
  21109. ghagujarati: 0x0A98,
  21110. ghagurmukhi: 0x0A18,
  21111. ghainarabic: 0x063A,
  21112. ghainfinalarabic: 0xFECE,
  21113. ghaininitialarabic: 0xFECF,
  21114. ghainmedialarabic: 0xFED0,
  21115. ghemiddlehookcyrillic: 0x0495,
  21116. ghestrokecyrillic: 0x0493,
  21117. gheupturncyrillic: 0x0491,
  21118. ghhadeva: 0x095A,
  21119. ghhagurmukhi: 0x0A5A,
  21120. ghook: 0x0260,
  21121. ghzsquare: 0x3393,
  21122. gihiragana: 0x304E,
  21123. gikatakana: 0x30AE,
  21124. gimarmenian: 0x0563,
  21125. gimel: 0x05D2,
  21126. gimeldagesh: 0xFB32,
  21127. gimeldageshhebrew: 0xFB32,
  21128. gimelhebrew: 0x05D2,
  21129. gjecyrillic: 0x0453,
  21130. glottalinvertedstroke: 0x01BE,
  21131. glottalstop: 0x0294,
  21132. glottalstopinverted: 0x0296,
  21133. glottalstopmod: 0x02C0,
  21134. glottalstopreversed: 0x0295,
  21135. glottalstopreversedmod: 0x02C1,
  21136. glottalstopreversedsuperior: 0x02E4,
  21137. glottalstopstroke: 0x02A1,
  21138. glottalstopstrokereversed: 0x02A2,
  21139. gmacron: 0x1E21,
  21140. gmonospace: 0xFF47,
  21141. gohiragana: 0x3054,
  21142. gokatakana: 0x30B4,
  21143. gparen: 0x24A2,
  21144. gpasquare: 0x33AC,
  21145. gradient: 0x2207,
  21146. grave: 0x0060,
  21147. gravebelowcmb: 0x0316,
  21148. gravecmb: 0x0300,
  21149. gravecomb: 0x0300,
  21150. gravedeva: 0x0953,
  21151. gravelowmod: 0x02CE,
  21152. gravemonospace: 0xFF40,
  21153. gravetonecmb: 0x0340,
  21154. greater: 0x003E,
  21155. greaterequal: 0x2265,
  21156. greaterequalorless: 0x22DB,
  21157. greatermonospace: 0xFF1E,
  21158. greaterorequivalent: 0x2273,
  21159. greaterorless: 0x2277,
  21160. greateroverequal: 0x2267,
  21161. greatersmall: 0xFE65,
  21162. gscript: 0x0261,
  21163. gstroke: 0x01E5,
  21164. guhiragana: 0x3050,
  21165. guillemotleft: 0x00AB,
  21166. guillemotright: 0x00BB,
  21167. guilsinglleft: 0x2039,
  21168. guilsinglright: 0x203A,
  21169. gukatakana: 0x30B0,
  21170. guramusquare: 0x3318,
  21171. gysquare: 0x33C9,
  21172. h: 0x0068,
  21173. haabkhasiancyrillic: 0x04A9,
  21174. haaltonearabic: 0x06C1,
  21175. habengali: 0x09B9,
  21176. hadescendercyrillic: 0x04B3,
  21177. hadeva: 0x0939,
  21178. hagujarati: 0x0AB9,
  21179. hagurmukhi: 0x0A39,
  21180. haharabic: 0x062D,
  21181. hahfinalarabic: 0xFEA2,
  21182. hahinitialarabic: 0xFEA3,
  21183. hahiragana: 0x306F,
  21184. hahmedialarabic: 0xFEA4,
  21185. haitusquare: 0x332A,
  21186. hakatakana: 0x30CF,
  21187. hakatakanahalfwidth: 0xFF8A,
  21188. halantgurmukhi: 0x0A4D,
  21189. hamzaarabic: 0x0621,
  21190. hamzalowarabic: 0x0621,
  21191. hangulfiller: 0x3164,
  21192. hardsigncyrillic: 0x044A,
  21193. harpoonleftbarbup: 0x21BC,
  21194. harpoonrightbarbup: 0x21C0,
  21195. hasquare: 0x33CA,
  21196. hatafpatah: 0x05B2,
  21197. hatafpatah16: 0x05B2,
  21198. hatafpatah23: 0x05B2,
  21199. hatafpatah2f: 0x05B2,
  21200. hatafpatahhebrew: 0x05B2,
  21201. hatafpatahnarrowhebrew: 0x05B2,
  21202. hatafpatahquarterhebrew: 0x05B2,
  21203. hatafpatahwidehebrew: 0x05B2,
  21204. hatafqamats: 0x05B3,
  21205. hatafqamats1b: 0x05B3,
  21206. hatafqamats28: 0x05B3,
  21207. hatafqamats34: 0x05B3,
  21208. hatafqamatshebrew: 0x05B3,
  21209. hatafqamatsnarrowhebrew: 0x05B3,
  21210. hatafqamatsquarterhebrew: 0x05B3,
  21211. hatafqamatswidehebrew: 0x05B3,
  21212. hatafsegol: 0x05B1,
  21213. hatafsegol17: 0x05B1,
  21214. hatafsegol24: 0x05B1,
  21215. hatafsegol30: 0x05B1,
  21216. hatafsegolhebrew: 0x05B1,
  21217. hatafsegolnarrowhebrew: 0x05B1,
  21218. hatafsegolquarterhebrew: 0x05B1,
  21219. hatafsegolwidehebrew: 0x05B1,
  21220. hbar: 0x0127,
  21221. hbopomofo: 0x310F,
  21222. hbrevebelow: 0x1E2B,
  21223. hcedilla: 0x1E29,
  21224. hcircle: 0x24D7,
  21225. hcircumflex: 0x0125,
  21226. hdieresis: 0x1E27,
  21227. hdotaccent: 0x1E23,
  21228. hdotbelow: 0x1E25,
  21229. he: 0x05D4,
  21230. heart: 0x2665,
  21231. heartsuitblack: 0x2665,
  21232. heartsuitwhite: 0x2661,
  21233. hedagesh: 0xFB34,
  21234. hedageshhebrew: 0xFB34,
  21235. hehaltonearabic: 0x06C1,
  21236. heharabic: 0x0647,
  21237. hehebrew: 0x05D4,
  21238. hehfinalaltonearabic: 0xFBA7,
  21239. hehfinalalttwoarabic: 0xFEEA,
  21240. hehfinalarabic: 0xFEEA,
  21241. hehhamzaabovefinalarabic: 0xFBA5,
  21242. hehhamzaaboveisolatedarabic: 0xFBA4,
  21243. hehinitialaltonearabic: 0xFBA8,
  21244. hehinitialarabic: 0xFEEB,
  21245. hehiragana: 0x3078,
  21246. hehmedialaltonearabic: 0xFBA9,
  21247. hehmedialarabic: 0xFEEC,
  21248. heiseierasquare: 0x337B,
  21249. hekatakana: 0x30D8,
  21250. hekatakanahalfwidth: 0xFF8D,
  21251. hekutaarusquare: 0x3336,
  21252. henghook: 0x0267,
  21253. herutusquare: 0x3339,
  21254. het: 0x05D7,
  21255. hethebrew: 0x05D7,
  21256. hhook: 0x0266,
  21257. hhooksuperior: 0x02B1,
  21258. hieuhacirclekorean: 0x327B,
  21259. hieuhaparenkorean: 0x321B,
  21260. hieuhcirclekorean: 0x326D,
  21261. hieuhkorean: 0x314E,
  21262. hieuhparenkorean: 0x320D,
  21263. hihiragana: 0x3072,
  21264. hikatakana: 0x30D2,
  21265. hikatakanahalfwidth: 0xFF8B,
  21266. hiriq: 0x05B4,
  21267. hiriq14: 0x05B4,
  21268. hiriq21: 0x05B4,
  21269. hiriq2d: 0x05B4,
  21270. hiriqhebrew: 0x05B4,
  21271. hiriqnarrowhebrew: 0x05B4,
  21272. hiriqquarterhebrew: 0x05B4,
  21273. hiriqwidehebrew: 0x05B4,
  21274. hlinebelow: 0x1E96,
  21275. hmonospace: 0xFF48,
  21276. hoarmenian: 0x0570,
  21277. hohipthai: 0x0E2B,
  21278. hohiragana: 0x307B,
  21279. hokatakana: 0x30DB,
  21280. hokatakanahalfwidth: 0xFF8E,
  21281. holam: 0x05B9,
  21282. holam19: 0x05B9,
  21283. holam26: 0x05B9,
  21284. holam32: 0x05B9,
  21285. holamhebrew: 0x05B9,
  21286. holamnarrowhebrew: 0x05B9,
  21287. holamquarterhebrew: 0x05B9,
  21288. holamwidehebrew: 0x05B9,
  21289. honokhukthai: 0x0E2E,
  21290. hookabovecomb: 0x0309,
  21291. hookcmb: 0x0309,
  21292. hookpalatalizedbelowcmb: 0x0321,
  21293. hookretroflexbelowcmb: 0x0322,
  21294. hoonsquare: 0x3342,
  21295. horicoptic: 0x03E9,
  21296. horizontalbar: 0x2015,
  21297. horncmb: 0x031B,
  21298. hotsprings: 0x2668,
  21299. house: 0x2302,
  21300. hparen: 0x24A3,
  21301. hsuperior: 0x02B0,
  21302. hturned: 0x0265,
  21303. huhiragana: 0x3075,
  21304. huiitosquare: 0x3333,
  21305. hukatakana: 0x30D5,
  21306. hukatakanahalfwidth: 0xFF8C,
  21307. hungarumlaut: 0x02DD,
  21308. hungarumlautcmb: 0x030B,
  21309. hv: 0x0195,
  21310. hyphen: 0x002D,
  21311. hypheninferior: 0xF6E5,
  21312. hyphenmonospace: 0xFF0D,
  21313. hyphensmall: 0xFE63,
  21314. hyphensuperior: 0xF6E6,
  21315. hyphentwo: 0x2010,
  21316. i: 0x0069,
  21317. iacute: 0x00ED,
  21318. iacyrillic: 0x044F,
  21319. ibengali: 0x0987,
  21320. ibopomofo: 0x3127,
  21321. ibreve: 0x012D,
  21322. icaron: 0x01D0,
  21323. icircle: 0x24D8,
  21324. icircumflex: 0x00EE,
  21325. icyrillic: 0x0456,
  21326. idblgrave: 0x0209,
  21327. ideographearthcircle: 0x328F,
  21328. ideographfirecircle: 0x328B,
  21329. ideographicallianceparen: 0x323F,
  21330. ideographiccallparen: 0x323A,
  21331. ideographiccentrecircle: 0x32A5,
  21332. ideographicclose: 0x3006,
  21333. ideographiccomma: 0x3001,
  21334. ideographiccommaleft: 0xFF64,
  21335. ideographiccongratulationparen: 0x3237,
  21336. ideographiccorrectcircle: 0x32A3,
  21337. ideographicearthparen: 0x322F,
  21338. ideographicenterpriseparen: 0x323D,
  21339. ideographicexcellentcircle: 0x329D,
  21340. ideographicfestivalparen: 0x3240,
  21341. ideographicfinancialcircle: 0x3296,
  21342. ideographicfinancialparen: 0x3236,
  21343. ideographicfireparen: 0x322B,
  21344. ideographichaveparen: 0x3232,
  21345. ideographichighcircle: 0x32A4,
  21346. ideographiciterationmark: 0x3005,
  21347. ideographiclaborcircle: 0x3298,
  21348. ideographiclaborparen: 0x3238,
  21349. ideographicleftcircle: 0x32A7,
  21350. ideographiclowcircle: 0x32A6,
  21351. ideographicmedicinecircle: 0x32A9,
  21352. ideographicmetalparen: 0x322E,
  21353. ideographicmoonparen: 0x322A,
  21354. ideographicnameparen: 0x3234,
  21355. ideographicperiod: 0x3002,
  21356. ideographicprintcircle: 0x329E,
  21357. ideographicreachparen: 0x3243,
  21358. ideographicrepresentparen: 0x3239,
  21359. ideographicresourceparen: 0x323E,
  21360. ideographicrightcircle: 0x32A8,
  21361. ideographicsecretcircle: 0x3299,
  21362. ideographicselfparen: 0x3242,
  21363. ideographicsocietyparen: 0x3233,
  21364. ideographicspace: 0x3000,
  21365. ideographicspecialparen: 0x3235,
  21366. ideographicstockparen: 0x3231,
  21367. ideographicstudyparen: 0x323B,
  21368. ideographicsunparen: 0x3230,
  21369. ideographicsuperviseparen: 0x323C,
  21370. ideographicwaterparen: 0x322C,
  21371. ideographicwoodparen: 0x322D,
  21372. ideographiczero: 0x3007,
  21373. ideographmetalcircle: 0x328E,
  21374. ideographmooncircle: 0x328A,
  21375. ideographnamecircle: 0x3294,
  21376. ideographsuncircle: 0x3290,
  21377. ideographwatercircle: 0x328C,
  21378. ideographwoodcircle: 0x328D,
  21379. ideva: 0x0907,
  21380. idieresis: 0x00EF,
  21381. idieresisacute: 0x1E2F,
  21382. idieresiscyrillic: 0x04E5,
  21383. idotbelow: 0x1ECB,
  21384. iebrevecyrillic: 0x04D7,
  21385. iecyrillic: 0x0435,
  21386. ieungacirclekorean: 0x3275,
  21387. ieungaparenkorean: 0x3215,
  21388. ieungcirclekorean: 0x3267,
  21389. ieungkorean: 0x3147,
  21390. ieungparenkorean: 0x3207,
  21391. igrave: 0x00EC,
  21392. igujarati: 0x0A87,
  21393. igurmukhi: 0x0A07,
  21394. ihiragana: 0x3044,
  21395. ihookabove: 0x1EC9,
  21396. iibengali: 0x0988,
  21397. iicyrillic: 0x0438,
  21398. iideva: 0x0908,
  21399. iigujarati: 0x0A88,
  21400. iigurmukhi: 0x0A08,
  21401. iimatragurmukhi: 0x0A40,
  21402. iinvertedbreve: 0x020B,
  21403. iishortcyrillic: 0x0439,
  21404. iivowelsignbengali: 0x09C0,
  21405. iivowelsigndeva: 0x0940,
  21406. iivowelsigngujarati: 0x0AC0,
  21407. ij: 0x0133,
  21408. ikatakana: 0x30A4,
  21409. ikatakanahalfwidth: 0xFF72,
  21410. ikorean: 0x3163,
  21411. ilde: 0x02DC,
  21412. iluyhebrew: 0x05AC,
  21413. imacron: 0x012B,
  21414. imacroncyrillic: 0x04E3,
  21415. imageorapproximatelyequal: 0x2253,
  21416. imatragurmukhi: 0x0A3F,
  21417. imonospace: 0xFF49,
  21418. increment: 0x2206,
  21419. infinity: 0x221E,
  21420. iniarmenian: 0x056B,
  21421. integral: 0x222B,
  21422. integralbottom: 0x2321,
  21423. integralbt: 0x2321,
  21424. integralex: 0xF8F5,
  21425. integraltop: 0x2320,
  21426. integraltp: 0x2320,
  21427. intersection: 0x2229,
  21428. intisquare: 0x3305,
  21429. invbullet: 0x25D8,
  21430. invcircle: 0x25D9,
  21431. invsmileface: 0x263B,
  21432. iocyrillic: 0x0451,
  21433. iogonek: 0x012F,
  21434. iota: 0x03B9,
  21435. iotadieresis: 0x03CA,
  21436. iotadieresistonos: 0x0390,
  21437. iotalatin: 0x0269,
  21438. iotatonos: 0x03AF,
  21439. iparen: 0x24A4,
  21440. irigurmukhi: 0x0A72,
  21441. ismallhiragana: 0x3043,
  21442. ismallkatakana: 0x30A3,
  21443. ismallkatakanahalfwidth: 0xFF68,
  21444. issharbengali: 0x09FA,
  21445. istroke: 0x0268,
  21446. isuperior: 0xF6ED,
  21447. iterationhiragana: 0x309D,
  21448. iterationkatakana: 0x30FD,
  21449. itilde: 0x0129,
  21450. itildebelow: 0x1E2D,
  21451. iubopomofo: 0x3129,
  21452. iucyrillic: 0x044E,
  21453. ivowelsignbengali: 0x09BF,
  21454. ivowelsigndeva: 0x093F,
  21455. ivowelsigngujarati: 0x0ABF,
  21456. izhitsacyrillic: 0x0475,
  21457. izhitsadblgravecyrillic: 0x0477,
  21458. j: 0x006A,
  21459. jaarmenian: 0x0571,
  21460. jabengali: 0x099C,
  21461. jadeva: 0x091C,
  21462. jagujarati: 0x0A9C,
  21463. jagurmukhi: 0x0A1C,
  21464. jbopomofo: 0x3110,
  21465. jcaron: 0x01F0,
  21466. jcircle: 0x24D9,
  21467. jcircumflex: 0x0135,
  21468. jcrossedtail: 0x029D,
  21469. jdotlessstroke: 0x025F,
  21470. jecyrillic: 0x0458,
  21471. jeemarabic: 0x062C,
  21472. jeemfinalarabic: 0xFE9E,
  21473. jeeminitialarabic: 0xFE9F,
  21474. jeemmedialarabic: 0xFEA0,
  21475. jeharabic: 0x0698,
  21476. jehfinalarabic: 0xFB8B,
  21477. jhabengali: 0x099D,
  21478. jhadeva: 0x091D,
  21479. jhagujarati: 0x0A9D,
  21480. jhagurmukhi: 0x0A1D,
  21481. jheharmenian: 0x057B,
  21482. jis: 0x3004,
  21483. jmonospace: 0xFF4A,
  21484. jparen: 0x24A5,
  21485. jsuperior: 0x02B2,
  21486. k: 0x006B,
  21487. kabashkircyrillic: 0x04A1,
  21488. kabengali: 0x0995,
  21489. kacute: 0x1E31,
  21490. kacyrillic: 0x043A,
  21491. kadescendercyrillic: 0x049B,
  21492. kadeva: 0x0915,
  21493. kaf: 0x05DB,
  21494. kafarabic: 0x0643,
  21495. kafdagesh: 0xFB3B,
  21496. kafdageshhebrew: 0xFB3B,
  21497. kaffinalarabic: 0xFEDA,
  21498. kafhebrew: 0x05DB,
  21499. kafinitialarabic: 0xFEDB,
  21500. kafmedialarabic: 0xFEDC,
  21501. kafrafehebrew: 0xFB4D,
  21502. kagujarati: 0x0A95,
  21503. kagurmukhi: 0x0A15,
  21504. kahiragana: 0x304B,
  21505. kahookcyrillic: 0x04C4,
  21506. kakatakana: 0x30AB,
  21507. kakatakanahalfwidth: 0xFF76,
  21508. kappa: 0x03BA,
  21509. kappasymbolgreek: 0x03F0,
  21510. kapyeounmieumkorean: 0x3171,
  21511. kapyeounphieuphkorean: 0x3184,
  21512. kapyeounpieupkorean: 0x3178,
  21513. kapyeounssangpieupkorean: 0x3179,
  21514. karoriisquare: 0x330D,
  21515. kashidaautoarabic: 0x0640,
  21516. kashidaautonosidebearingarabic: 0x0640,
  21517. kasmallkatakana: 0x30F5,
  21518. kasquare: 0x3384,
  21519. kasraarabic: 0x0650,
  21520. kasratanarabic: 0x064D,
  21521. kastrokecyrillic: 0x049F,
  21522. katahiraprolongmarkhalfwidth: 0xFF70,
  21523. kaverticalstrokecyrillic: 0x049D,
  21524. kbopomofo: 0x310E,
  21525. kcalsquare: 0x3389,
  21526. kcaron: 0x01E9,
  21527. kcedilla: 0x0137,
  21528. kcircle: 0x24DA,
  21529. kcommaaccent: 0x0137,
  21530. kdotbelow: 0x1E33,
  21531. keharmenian: 0x0584,
  21532. kehiragana: 0x3051,
  21533. kekatakana: 0x30B1,
  21534. kekatakanahalfwidth: 0xFF79,
  21535. kenarmenian: 0x056F,
  21536. kesmallkatakana: 0x30F6,
  21537. kgreenlandic: 0x0138,
  21538. khabengali: 0x0996,
  21539. khacyrillic: 0x0445,
  21540. khadeva: 0x0916,
  21541. khagujarati: 0x0A96,
  21542. khagurmukhi: 0x0A16,
  21543. khaharabic: 0x062E,
  21544. khahfinalarabic: 0xFEA6,
  21545. khahinitialarabic: 0xFEA7,
  21546. khahmedialarabic: 0xFEA8,
  21547. kheicoptic: 0x03E7,
  21548. khhadeva: 0x0959,
  21549. khhagurmukhi: 0x0A59,
  21550. khieukhacirclekorean: 0x3278,
  21551. khieukhaparenkorean: 0x3218,
  21552. khieukhcirclekorean: 0x326A,
  21553. khieukhkorean: 0x314B,
  21554. khieukhparenkorean: 0x320A,
  21555. khokhaithai: 0x0E02,
  21556. khokhonthai: 0x0E05,
  21557. khokhuatthai: 0x0E03,
  21558. khokhwaithai: 0x0E04,
  21559. khomutthai: 0x0E5B,
  21560. khook: 0x0199,
  21561. khorakhangthai: 0x0E06,
  21562. khzsquare: 0x3391,
  21563. kihiragana: 0x304D,
  21564. kikatakana: 0x30AD,
  21565. kikatakanahalfwidth: 0xFF77,
  21566. kiroguramusquare: 0x3315,
  21567. kiromeetorusquare: 0x3316,
  21568. kirosquare: 0x3314,
  21569. kiyeokacirclekorean: 0x326E,
  21570. kiyeokaparenkorean: 0x320E,
  21571. kiyeokcirclekorean: 0x3260,
  21572. kiyeokkorean: 0x3131,
  21573. kiyeokparenkorean: 0x3200,
  21574. kiyeoksioskorean: 0x3133,
  21575. kjecyrillic: 0x045C,
  21576. klinebelow: 0x1E35,
  21577. klsquare: 0x3398,
  21578. kmcubedsquare: 0x33A6,
  21579. kmonospace: 0xFF4B,
  21580. kmsquaredsquare: 0x33A2,
  21581. kohiragana: 0x3053,
  21582. kohmsquare: 0x33C0,
  21583. kokaithai: 0x0E01,
  21584. kokatakana: 0x30B3,
  21585. kokatakanahalfwidth: 0xFF7A,
  21586. kooposquare: 0x331E,
  21587. koppacyrillic: 0x0481,
  21588. koreanstandardsymbol: 0x327F,
  21589. koroniscmb: 0x0343,
  21590. kparen: 0x24A6,
  21591. kpasquare: 0x33AA,
  21592. ksicyrillic: 0x046F,
  21593. ktsquare: 0x33CF,
  21594. kturned: 0x029E,
  21595. kuhiragana: 0x304F,
  21596. kukatakana: 0x30AF,
  21597. kukatakanahalfwidth: 0xFF78,
  21598. kvsquare: 0x33B8,
  21599. kwsquare: 0x33BE,
  21600. l: 0x006C,
  21601. labengali: 0x09B2,
  21602. lacute: 0x013A,
  21603. ladeva: 0x0932,
  21604. lagujarati: 0x0AB2,
  21605. lagurmukhi: 0x0A32,
  21606. lakkhangyaothai: 0x0E45,
  21607. lamaleffinalarabic: 0xFEFC,
  21608. lamalefhamzaabovefinalarabic: 0xFEF8,
  21609. lamalefhamzaaboveisolatedarabic: 0xFEF7,
  21610. lamalefhamzabelowfinalarabic: 0xFEFA,
  21611. lamalefhamzabelowisolatedarabic: 0xFEF9,
  21612. lamalefisolatedarabic: 0xFEFB,
  21613. lamalefmaddaabovefinalarabic: 0xFEF6,
  21614. lamalefmaddaaboveisolatedarabic: 0xFEF5,
  21615. lamarabic: 0x0644,
  21616. lambda: 0x03BB,
  21617. lambdastroke: 0x019B,
  21618. lamed: 0x05DC,
  21619. lameddagesh: 0xFB3C,
  21620. lameddageshhebrew: 0xFB3C,
  21621. lamedhebrew: 0x05DC,
  21622. lamfinalarabic: 0xFEDE,
  21623. lamhahinitialarabic: 0xFCCA,
  21624. laminitialarabic: 0xFEDF,
  21625. lamjeeminitialarabic: 0xFCC9,
  21626. lamkhahinitialarabic: 0xFCCB,
  21627. lamlamhehisolatedarabic: 0xFDF2,
  21628. lammedialarabic: 0xFEE0,
  21629. lammeemhahinitialarabic: 0xFD88,
  21630. lammeeminitialarabic: 0xFCCC,
  21631. largecircle: 0x25EF,
  21632. lbar: 0x019A,
  21633. lbelt: 0x026C,
  21634. lbopomofo: 0x310C,
  21635. lcaron: 0x013E,
  21636. lcedilla: 0x013C,
  21637. lcircle: 0x24DB,
  21638. lcircumflexbelow: 0x1E3D,
  21639. lcommaaccent: 0x013C,
  21640. ldot: 0x0140,
  21641. ldotaccent: 0x0140,
  21642. ldotbelow: 0x1E37,
  21643. ldotbelowmacron: 0x1E39,
  21644. leftangleabovecmb: 0x031A,
  21645. lefttackbelowcmb: 0x0318,
  21646. less: 0x003C,
  21647. lessequal: 0x2264,
  21648. lessequalorgreater: 0x22DA,
  21649. lessmonospace: 0xFF1C,
  21650. lessorequivalent: 0x2272,
  21651. lessorgreater: 0x2276,
  21652. lessoverequal: 0x2266,
  21653. lesssmall: 0xFE64,
  21654. lezh: 0x026E,
  21655. lfblock: 0x258C,
  21656. lhookretroflex: 0x026D,
  21657. lira: 0x20A4,
  21658. liwnarmenian: 0x056C,
  21659. lj: 0x01C9,
  21660. ljecyrillic: 0x0459,
  21661. ll: 0xF6C0,
  21662. lladeva: 0x0933,
  21663. llagujarati: 0x0AB3,
  21664. llinebelow: 0x1E3B,
  21665. llladeva: 0x0934,
  21666. llvocalicbengali: 0x09E1,
  21667. llvocalicdeva: 0x0961,
  21668. llvocalicvowelsignbengali: 0x09E3,
  21669. llvocalicvowelsigndeva: 0x0963,
  21670. lmiddletilde: 0x026B,
  21671. lmonospace: 0xFF4C,
  21672. lmsquare: 0x33D0,
  21673. lochulathai: 0x0E2C,
  21674. logicaland: 0x2227,
  21675. logicalnot: 0x00AC,
  21676. logicalnotreversed: 0x2310,
  21677. logicalor: 0x2228,
  21678. lolingthai: 0x0E25,
  21679. longs: 0x017F,
  21680. lowlinecenterline: 0xFE4E,
  21681. lowlinecmb: 0x0332,
  21682. lowlinedashed: 0xFE4D,
  21683. lozenge: 0x25CA,
  21684. lparen: 0x24A7,
  21685. lslash: 0x0142,
  21686. lsquare: 0x2113,
  21687. lsuperior: 0xF6EE,
  21688. ltshade: 0x2591,
  21689. luthai: 0x0E26,
  21690. lvocalicbengali: 0x098C,
  21691. lvocalicdeva: 0x090C,
  21692. lvocalicvowelsignbengali: 0x09E2,
  21693. lvocalicvowelsigndeva: 0x0962,
  21694. lxsquare: 0x33D3,
  21695. m: 0x006D,
  21696. mabengali: 0x09AE,
  21697. macron: 0x00AF,
  21698. macronbelowcmb: 0x0331,
  21699. macroncmb: 0x0304,
  21700. macronlowmod: 0x02CD,
  21701. macronmonospace: 0xFFE3,
  21702. macute: 0x1E3F,
  21703. madeva: 0x092E,
  21704. magujarati: 0x0AAE,
  21705. magurmukhi: 0x0A2E,
  21706. mahapakhhebrew: 0x05A4,
  21707. mahapakhlefthebrew: 0x05A4,
  21708. mahiragana: 0x307E,
  21709. maichattawalowleftthai: 0xF895,
  21710. maichattawalowrightthai: 0xF894,
  21711. maichattawathai: 0x0E4B,
  21712. maichattawaupperleftthai: 0xF893,
  21713. maieklowleftthai: 0xF88C,
  21714. maieklowrightthai: 0xF88B,
  21715. maiekthai: 0x0E48,
  21716. maiekupperleftthai: 0xF88A,
  21717. maihanakatleftthai: 0xF884,
  21718. maihanakatthai: 0x0E31,
  21719. maitaikhuleftthai: 0xF889,
  21720. maitaikhuthai: 0x0E47,
  21721. maitholowleftthai: 0xF88F,
  21722. maitholowrightthai: 0xF88E,
  21723. maithothai: 0x0E49,
  21724. maithoupperleftthai: 0xF88D,
  21725. maitrilowleftthai: 0xF892,
  21726. maitrilowrightthai: 0xF891,
  21727. maitrithai: 0x0E4A,
  21728. maitriupperleftthai: 0xF890,
  21729. maiyamokthai: 0x0E46,
  21730. makatakana: 0x30DE,
  21731. makatakanahalfwidth: 0xFF8F,
  21732. male: 0x2642,
  21733. mansyonsquare: 0x3347,
  21734. maqafhebrew: 0x05BE,
  21735. mars: 0x2642,
  21736. masoracirclehebrew: 0x05AF,
  21737. masquare: 0x3383,
  21738. mbopomofo: 0x3107,
  21739. mbsquare: 0x33D4,
  21740. mcircle: 0x24DC,
  21741. mcubedsquare: 0x33A5,
  21742. mdotaccent: 0x1E41,
  21743. mdotbelow: 0x1E43,
  21744. meemarabic: 0x0645,
  21745. meemfinalarabic: 0xFEE2,
  21746. meeminitialarabic: 0xFEE3,
  21747. meemmedialarabic: 0xFEE4,
  21748. meemmeeminitialarabic: 0xFCD1,
  21749. meemmeemisolatedarabic: 0xFC48,
  21750. meetorusquare: 0x334D,
  21751. mehiragana: 0x3081,
  21752. meizierasquare: 0x337E,
  21753. mekatakana: 0x30E1,
  21754. mekatakanahalfwidth: 0xFF92,
  21755. mem: 0x05DE,
  21756. memdagesh: 0xFB3E,
  21757. memdageshhebrew: 0xFB3E,
  21758. memhebrew: 0x05DE,
  21759. menarmenian: 0x0574,
  21760. merkhahebrew: 0x05A5,
  21761. merkhakefulahebrew: 0x05A6,
  21762. merkhakefulalefthebrew: 0x05A6,
  21763. merkhalefthebrew: 0x05A5,
  21764. mhook: 0x0271,
  21765. mhzsquare: 0x3392,
  21766. middledotkatakanahalfwidth: 0xFF65,
  21767. middot: 0x00B7,
  21768. mieumacirclekorean: 0x3272,
  21769. mieumaparenkorean: 0x3212,
  21770. mieumcirclekorean: 0x3264,
  21771. mieumkorean: 0x3141,
  21772. mieumpansioskorean: 0x3170,
  21773. mieumparenkorean: 0x3204,
  21774. mieumpieupkorean: 0x316E,
  21775. mieumsioskorean: 0x316F,
  21776. mihiragana: 0x307F,
  21777. mikatakana: 0x30DF,
  21778. mikatakanahalfwidth: 0xFF90,
  21779. minus: 0x2212,
  21780. minusbelowcmb: 0x0320,
  21781. minuscircle: 0x2296,
  21782. minusmod: 0x02D7,
  21783. minusplus: 0x2213,
  21784. minute: 0x2032,
  21785. miribaarusquare: 0x334A,
  21786. mirisquare: 0x3349,
  21787. mlonglegturned: 0x0270,
  21788. mlsquare: 0x3396,
  21789. mmcubedsquare: 0x33A3,
  21790. mmonospace: 0xFF4D,
  21791. mmsquaredsquare: 0x339F,
  21792. mohiragana: 0x3082,
  21793. mohmsquare: 0x33C1,
  21794. mokatakana: 0x30E2,
  21795. mokatakanahalfwidth: 0xFF93,
  21796. molsquare: 0x33D6,
  21797. momathai: 0x0E21,
  21798. moverssquare: 0x33A7,
  21799. moverssquaredsquare: 0x33A8,
  21800. mparen: 0x24A8,
  21801. mpasquare: 0x33AB,
  21802. mssquare: 0x33B3,
  21803. msuperior: 0xF6EF,
  21804. mturned: 0x026F,
  21805. mu: 0x00B5,
  21806. mu1: 0x00B5,
  21807. muasquare: 0x3382,
  21808. muchgreater: 0x226B,
  21809. muchless: 0x226A,
  21810. mufsquare: 0x338C,
  21811. mugreek: 0x03BC,
  21812. mugsquare: 0x338D,
  21813. muhiragana: 0x3080,
  21814. mukatakana: 0x30E0,
  21815. mukatakanahalfwidth: 0xFF91,
  21816. mulsquare: 0x3395,
  21817. multiply: 0x00D7,
  21818. mumsquare: 0x339B,
  21819. munahhebrew: 0x05A3,
  21820. munahlefthebrew: 0x05A3,
  21821. musicalnote: 0x266A,
  21822. musicalnotedbl: 0x266B,
  21823. musicflatsign: 0x266D,
  21824. musicsharpsign: 0x266F,
  21825. mussquare: 0x33B2,
  21826. muvsquare: 0x33B6,
  21827. muwsquare: 0x33BC,
  21828. mvmegasquare: 0x33B9,
  21829. mvsquare: 0x33B7,
  21830. mwmegasquare: 0x33BF,
  21831. mwsquare: 0x33BD,
  21832. n: 0x006E,
  21833. nabengali: 0x09A8,
  21834. nabla: 0x2207,
  21835. nacute: 0x0144,
  21836. nadeva: 0x0928,
  21837. nagujarati: 0x0AA8,
  21838. nagurmukhi: 0x0A28,
  21839. nahiragana: 0x306A,
  21840. nakatakana: 0x30CA,
  21841. nakatakanahalfwidth: 0xFF85,
  21842. napostrophe: 0x0149,
  21843. nasquare: 0x3381,
  21844. nbopomofo: 0x310B,
  21845. nbspace: 0x00A0,
  21846. ncaron: 0x0148,
  21847. ncedilla: 0x0146,
  21848. ncircle: 0x24DD,
  21849. ncircumflexbelow: 0x1E4B,
  21850. ncommaaccent: 0x0146,
  21851. ndotaccent: 0x1E45,
  21852. ndotbelow: 0x1E47,
  21853. nehiragana: 0x306D,
  21854. nekatakana: 0x30CD,
  21855. nekatakanahalfwidth: 0xFF88,
  21856. newsheqelsign: 0x20AA,
  21857. nfsquare: 0x338B,
  21858. ngabengali: 0x0999,
  21859. ngadeva: 0x0919,
  21860. ngagujarati: 0x0A99,
  21861. ngagurmukhi: 0x0A19,
  21862. ngonguthai: 0x0E07,
  21863. nhiragana: 0x3093,
  21864. nhookleft: 0x0272,
  21865. nhookretroflex: 0x0273,
  21866. nieunacirclekorean: 0x326F,
  21867. nieunaparenkorean: 0x320F,
  21868. nieuncieuckorean: 0x3135,
  21869. nieuncirclekorean: 0x3261,
  21870. nieunhieuhkorean: 0x3136,
  21871. nieunkorean: 0x3134,
  21872. nieunpansioskorean: 0x3168,
  21873. nieunparenkorean: 0x3201,
  21874. nieunsioskorean: 0x3167,
  21875. nieuntikeutkorean: 0x3166,
  21876. nihiragana: 0x306B,
  21877. nikatakana: 0x30CB,
  21878. nikatakanahalfwidth: 0xFF86,
  21879. nikhahitleftthai: 0xF899,
  21880. nikhahitthai: 0x0E4D,
  21881. nine: 0x0039,
  21882. ninearabic: 0x0669,
  21883. ninebengali: 0x09EF,
  21884. ninecircle: 0x2468,
  21885. ninecircleinversesansserif: 0x2792,
  21886. ninedeva: 0x096F,
  21887. ninegujarati: 0x0AEF,
  21888. ninegurmukhi: 0x0A6F,
  21889. ninehackarabic: 0x0669,
  21890. ninehangzhou: 0x3029,
  21891. nineideographicparen: 0x3228,
  21892. nineinferior: 0x2089,
  21893. ninemonospace: 0xFF19,
  21894. nineoldstyle: 0xF739,
  21895. nineparen: 0x247C,
  21896. nineperiod: 0x2490,
  21897. ninepersian: 0x06F9,
  21898. nineroman: 0x2178,
  21899. ninesuperior: 0x2079,
  21900. nineteencircle: 0x2472,
  21901. nineteenparen: 0x2486,
  21902. nineteenperiod: 0x249A,
  21903. ninethai: 0x0E59,
  21904. nj: 0x01CC,
  21905. njecyrillic: 0x045A,
  21906. nkatakana: 0x30F3,
  21907. nkatakanahalfwidth: 0xFF9D,
  21908. nlegrightlong: 0x019E,
  21909. nlinebelow: 0x1E49,
  21910. nmonospace: 0xFF4E,
  21911. nmsquare: 0x339A,
  21912. nnabengali: 0x09A3,
  21913. nnadeva: 0x0923,
  21914. nnagujarati: 0x0AA3,
  21915. nnagurmukhi: 0x0A23,
  21916. nnnadeva: 0x0929,
  21917. nohiragana: 0x306E,
  21918. nokatakana: 0x30CE,
  21919. nokatakanahalfwidth: 0xFF89,
  21920. nonbreakingspace: 0x00A0,
  21921. nonenthai: 0x0E13,
  21922. nonuthai: 0x0E19,
  21923. noonarabic: 0x0646,
  21924. noonfinalarabic: 0xFEE6,
  21925. noonghunnaarabic: 0x06BA,
  21926. noonghunnafinalarabic: 0xFB9F,
  21927. nooninitialarabic: 0xFEE7,
  21928. noonjeeminitialarabic: 0xFCD2,
  21929. noonjeemisolatedarabic: 0xFC4B,
  21930. noonmedialarabic: 0xFEE8,
  21931. noonmeeminitialarabic: 0xFCD5,
  21932. noonmeemisolatedarabic: 0xFC4E,
  21933. noonnoonfinalarabic: 0xFC8D,
  21934. notcontains: 0x220C,
  21935. notelement: 0x2209,
  21936. notelementof: 0x2209,
  21937. notequal: 0x2260,
  21938. notgreater: 0x226F,
  21939. notgreaternorequal: 0x2271,
  21940. notgreaternorless: 0x2279,
  21941. notidentical: 0x2262,
  21942. notless: 0x226E,
  21943. notlessnorequal: 0x2270,
  21944. notparallel: 0x2226,
  21945. notprecedes: 0x2280,
  21946. notsubset: 0x2284,
  21947. notsucceeds: 0x2281,
  21948. notsuperset: 0x2285,
  21949. nowarmenian: 0x0576,
  21950. nparen: 0x24A9,
  21951. nssquare: 0x33B1,
  21952. nsuperior: 0x207F,
  21953. ntilde: 0x00F1,
  21954. nu: 0x03BD,
  21955. nuhiragana: 0x306C,
  21956. nukatakana: 0x30CC,
  21957. nukatakanahalfwidth: 0xFF87,
  21958. nuktabengali: 0x09BC,
  21959. nuktadeva: 0x093C,
  21960. nuktagujarati: 0x0ABC,
  21961. nuktagurmukhi: 0x0A3C,
  21962. numbersign: 0x0023,
  21963. numbersignmonospace: 0xFF03,
  21964. numbersignsmall: 0xFE5F,
  21965. numeralsigngreek: 0x0374,
  21966. numeralsignlowergreek: 0x0375,
  21967. numero: 0x2116,
  21968. nun: 0x05E0,
  21969. nundagesh: 0xFB40,
  21970. nundageshhebrew: 0xFB40,
  21971. nunhebrew: 0x05E0,
  21972. nvsquare: 0x33B5,
  21973. nwsquare: 0x33BB,
  21974. nyabengali: 0x099E,
  21975. nyadeva: 0x091E,
  21976. nyagujarati: 0x0A9E,
  21977. nyagurmukhi: 0x0A1E,
  21978. o: 0x006F,
  21979. oacute: 0x00F3,
  21980. oangthai: 0x0E2D,
  21981. obarred: 0x0275,
  21982. obarredcyrillic: 0x04E9,
  21983. obarreddieresiscyrillic: 0x04EB,
  21984. obengali: 0x0993,
  21985. obopomofo: 0x311B,
  21986. obreve: 0x014F,
  21987. ocandradeva: 0x0911,
  21988. ocandragujarati: 0x0A91,
  21989. ocandravowelsigndeva: 0x0949,
  21990. ocandravowelsigngujarati: 0x0AC9,
  21991. ocaron: 0x01D2,
  21992. ocircle: 0x24DE,
  21993. ocircumflex: 0x00F4,
  21994. ocircumflexacute: 0x1ED1,
  21995. ocircumflexdotbelow: 0x1ED9,
  21996. ocircumflexgrave: 0x1ED3,
  21997. ocircumflexhookabove: 0x1ED5,
  21998. ocircumflextilde: 0x1ED7,
  21999. ocyrillic: 0x043E,
  22000. odblacute: 0x0151,
  22001. odblgrave: 0x020D,
  22002. odeva: 0x0913,
  22003. odieresis: 0x00F6,
  22004. odieresiscyrillic: 0x04E7,
  22005. odotbelow: 0x1ECD,
  22006. oe: 0x0153,
  22007. oekorean: 0x315A,
  22008. ogonek: 0x02DB,
  22009. ogonekcmb: 0x0328,
  22010. ograve: 0x00F2,
  22011. ogujarati: 0x0A93,
  22012. oharmenian: 0x0585,
  22013. ohiragana: 0x304A,
  22014. ohookabove: 0x1ECF,
  22015. ohorn: 0x01A1,
  22016. ohornacute: 0x1EDB,
  22017. ohorndotbelow: 0x1EE3,
  22018. ohorngrave: 0x1EDD,
  22019. ohornhookabove: 0x1EDF,
  22020. ohorntilde: 0x1EE1,
  22021. ohungarumlaut: 0x0151,
  22022. oi: 0x01A3,
  22023. oinvertedbreve: 0x020F,
  22024. okatakana: 0x30AA,
  22025. okatakanahalfwidth: 0xFF75,
  22026. okorean: 0x3157,
  22027. olehebrew: 0x05AB,
  22028. omacron: 0x014D,
  22029. omacronacute: 0x1E53,
  22030. omacrongrave: 0x1E51,
  22031. omdeva: 0x0950,
  22032. omega: 0x03C9,
  22033. omega1: 0x03D6,
  22034. omegacyrillic: 0x0461,
  22035. omegalatinclosed: 0x0277,
  22036. omegaroundcyrillic: 0x047B,
  22037. omegatitlocyrillic: 0x047D,
  22038. omegatonos: 0x03CE,
  22039. omgujarati: 0x0AD0,
  22040. omicron: 0x03BF,
  22041. omicrontonos: 0x03CC,
  22042. omonospace: 0xFF4F,
  22043. one: 0x0031,
  22044. onearabic: 0x0661,
  22045. onebengali: 0x09E7,
  22046. onecircle: 0x2460,
  22047. onecircleinversesansserif: 0x278A,
  22048. onedeva: 0x0967,
  22049. onedotenleader: 0x2024,
  22050. oneeighth: 0x215B,
  22051. onefitted: 0xF6DC,
  22052. onegujarati: 0x0AE7,
  22053. onegurmukhi: 0x0A67,
  22054. onehackarabic: 0x0661,
  22055. onehalf: 0x00BD,
  22056. onehangzhou: 0x3021,
  22057. oneideographicparen: 0x3220,
  22058. oneinferior: 0x2081,
  22059. onemonospace: 0xFF11,
  22060. onenumeratorbengali: 0x09F4,
  22061. oneoldstyle: 0xF731,
  22062. oneparen: 0x2474,
  22063. oneperiod: 0x2488,
  22064. onepersian: 0x06F1,
  22065. onequarter: 0x00BC,
  22066. oneroman: 0x2170,
  22067. onesuperior: 0x00B9,
  22068. onethai: 0x0E51,
  22069. onethird: 0x2153,
  22070. oogonek: 0x01EB,
  22071. oogonekmacron: 0x01ED,
  22072. oogurmukhi: 0x0A13,
  22073. oomatragurmukhi: 0x0A4B,
  22074. oopen: 0x0254,
  22075. oparen: 0x24AA,
  22076. openbullet: 0x25E6,
  22077. option: 0x2325,
  22078. ordfeminine: 0x00AA,
  22079. ordmasculine: 0x00BA,
  22080. orthogonal: 0x221F,
  22081. oshortdeva: 0x0912,
  22082. oshortvowelsigndeva: 0x094A,
  22083. oslash: 0x00F8,
  22084. oslashacute: 0x01FF,
  22085. osmallhiragana: 0x3049,
  22086. osmallkatakana: 0x30A9,
  22087. osmallkatakanahalfwidth: 0xFF6B,
  22088. ostrokeacute: 0x01FF,
  22089. osuperior: 0xF6F0,
  22090. otcyrillic: 0x047F,
  22091. otilde: 0x00F5,
  22092. otildeacute: 0x1E4D,
  22093. otildedieresis: 0x1E4F,
  22094. oubopomofo: 0x3121,
  22095. overline: 0x203E,
  22096. overlinecenterline: 0xFE4A,
  22097. overlinecmb: 0x0305,
  22098. overlinedashed: 0xFE49,
  22099. overlinedblwavy: 0xFE4C,
  22100. overlinewavy: 0xFE4B,
  22101. overscore: 0x00AF,
  22102. ovowelsignbengali: 0x09CB,
  22103. ovowelsigndeva: 0x094B,
  22104. ovowelsigngujarati: 0x0ACB,
  22105. p: 0x0070,
  22106. paampssquare: 0x3380,
  22107. paasentosquare: 0x332B,
  22108. pabengali: 0x09AA,
  22109. pacute: 0x1E55,
  22110. padeva: 0x092A,
  22111. pagedown: 0x21DF,
  22112. pageup: 0x21DE,
  22113. pagujarati: 0x0AAA,
  22114. pagurmukhi: 0x0A2A,
  22115. pahiragana: 0x3071,
  22116. paiyannoithai: 0x0E2F,
  22117. pakatakana: 0x30D1,
  22118. palatalizationcyrilliccmb: 0x0484,
  22119. palochkacyrillic: 0x04C0,
  22120. pansioskorean: 0x317F,
  22121. paragraph: 0x00B6,
  22122. parallel: 0x2225,
  22123. parenleft: 0x0028,
  22124. parenleftaltonearabic: 0xFD3E,
  22125. parenleftbt: 0xF8ED,
  22126. parenleftex: 0xF8EC,
  22127. parenleftinferior: 0x208D,
  22128. parenleftmonospace: 0xFF08,
  22129. parenleftsmall: 0xFE59,
  22130. parenleftsuperior: 0x207D,
  22131. parenlefttp: 0xF8EB,
  22132. parenleftvertical: 0xFE35,
  22133. parenright: 0x0029,
  22134. parenrightaltonearabic: 0xFD3F,
  22135. parenrightbt: 0xF8F8,
  22136. parenrightex: 0xF8F7,
  22137. parenrightinferior: 0x208E,
  22138. parenrightmonospace: 0xFF09,
  22139. parenrightsmall: 0xFE5A,
  22140. parenrightsuperior: 0x207E,
  22141. parenrighttp: 0xF8F6,
  22142. parenrightvertical: 0xFE36,
  22143. partialdiff: 0x2202,
  22144. paseqhebrew: 0x05C0,
  22145. pashtahebrew: 0x0599,
  22146. pasquare: 0x33A9,
  22147. patah: 0x05B7,
  22148. patah11: 0x05B7,
  22149. patah1d: 0x05B7,
  22150. patah2a: 0x05B7,
  22151. patahhebrew: 0x05B7,
  22152. patahnarrowhebrew: 0x05B7,
  22153. patahquarterhebrew: 0x05B7,
  22154. patahwidehebrew: 0x05B7,
  22155. pazerhebrew: 0x05A1,
  22156. pbopomofo: 0x3106,
  22157. pcircle: 0x24DF,
  22158. pdotaccent: 0x1E57,
  22159. pe: 0x05E4,
  22160. pecyrillic: 0x043F,
  22161. pedagesh: 0xFB44,
  22162. pedageshhebrew: 0xFB44,
  22163. peezisquare: 0x333B,
  22164. pefinaldageshhebrew: 0xFB43,
  22165. peharabic: 0x067E,
  22166. peharmenian: 0x057A,
  22167. pehebrew: 0x05E4,
  22168. pehfinalarabic: 0xFB57,
  22169. pehinitialarabic: 0xFB58,
  22170. pehiragana: 0x307A,
  22171. pehmedialarabic: 0xFB59,
  22172. pekatakana: 0x30DA,
  22173. pemiddlehookcyrillic: 0x04A7,
  22174. perafehebrew: 0xFB4E,
  22175. percent: 0x0025,
  22176. percentarabic: 0x066A,
  22177. percentmonospace: 0xFF05,
  22178. percentsmall: 0xFE6A,
  22179. period: 0x002E,
  22180. periodarmenian: 0x0589,
  22181. periodcentered: 0x00B7,
  22182. periodhalfwidth: 0xFF61,
  22183. periodinferior: 0xF6E7,
  22184. periodmonospace: 0xFF0E,
  22185. periodsmall: 0xFE52,
  22186. periodsuperior: 0xF6E8,
  22187. perispomenigreekcmb: 0x0342,
  22188. perpendicular: 0x22A5,
  22189. perthousand: 0x2030,
  22190. peseta: 0x20A7,
  22191. pfsquare: 0x338A,
  22192. phabengali: 0x09AB,
  22193. phadeva: 0x092B,
  22194. phagujarati: 0x0AAB,
  22195. phagurmukhi: 0x0A2B,
  22196. phi: 0x03C6,
  22197. phi1: 0x03D5,
  22198. phieuphacirclekorean: 0x327A,
  22199. phieuphaparenkorean: 0x321A,
  22200. phieuphcirclekorean: 0x326C,
  22201. phieuphkorean: 0x314D,
  22202. phieuphparenkorean: 0x320C,
  22203. philatin: 0x0278,
  22204. phinthuthai: 0x0E3A,
  22205. phisymbolgreek: 0x03D5,
  22206. phook: 0x01A5,
  22207. phophanthai: 0x0E1E,
  22208. phophungthai: 0x0E1C,
  22209. phosamphaothai: 0x0E20,
  22210. pi: 0x03C0,
  22211. pieupacirclekorean: 0x3273,
  22212. pieupaparenkorean: 0x3213,
  22213. pieupcieuckorean: 0x3176,
  22214. pieupcirclekorean: 0x3265,
  22215. pieupkiyeokkorean: 0x3172,
  22216. pieupkorean: 0x3142,
  22217. pieupparenkorean: 0x3205,
  22218. pieupsioskiyeokkorean: 0x3174,
  22219. pieupsioskorean: 0x3144,
  22220. pieupsiostikeutkorean: 0x3175,
  22221. pieupthieuthkorean: 0x3177,
  22222. pieuptikeutkorean: 0x3173,
  22223. pihiragana: 0x3074,
  22224. pikatakana: 0x30D4,
  22225. pisymbolgreek: 0x03D6,
  22226. piwrarmenian: 0x0583,
  22227. plus: 0x002B,
  22228. plusbelowcmb: 0x031F,
  22229. pluscircle: 0x2295,
  22230. plusminus: 0x00B1,
  22231. plusmod: 0x02D6,
  22232. plusmonospace: 0xFF0B,
  22233. plussmall: 0xFE62,
  22234. plussuperior: 0x207A,
  22235. pmonospace: 0xFF50,
  22236. pmsquare: 0x33D8,
  22237. pohiragana: 0x307D,
  22238. pointingindexdownwhite: 0x261F,
  22239. pointingindexleftwhite: 0x261C,
  22240. pointingindexrightwhite: 0x261E,
  22241. pointingindexupwhite: 0x261D,
  22242. pokatakana: 0x30DD,
  22243. poplathai: 0x0E1B,
  22244. postalmark: 0x3012,
  22245. postalmarkface: 0x3020,
  22246. pparen: 0x24AB,
  22247. precedes: 0x227A,
  22248. prescription: 0x211E,
  22249. primemod: 0x02B9,
  22250. primereversed: 0x2035,
  22251. product: 0x220F,
  22252. projective: 0x2305,
  22253. prolongedkana: 0x30FC,
  22254. propellor: 0x2318,
  22255. propersubset: 0x2282,
  22256. propersuperset: 0x2283,
  22257. proportion: 0x2237,
  22258. proportional: 0x221D,
  22259. psi: 0x03C8,
  22260. psicyrillic: 0x0471,
  22261. psilipneumatacyrilliccmb: 0x0486,
  22262. pssquare: 0x33B0,
  22263. puhiragana: 0x3077,
  22264. pukatakana: 0x30D7,
  22265. pvsquare: 0x33B4,
  22266. pwsquare: 0x33BA,
  22267. q: 0x0071,
  22268. qadeva: 0x0958,
  22269. qadmahebrew: 0x05A8,
  22270. qafarabic: 0x0642,
  22271. qaffinalarabic: 0xFED6,
  22272. qafinitialarabic: 0xFED7,
  22273. qafmedialarabic: 0xFED8,
  22274. qamats: 0x05B8,
  22275. qamats10: 0x05B8,
  22276. qamats1a: 0x05B8,
  22277. qamats1c: 0x05B8,
  22278. qamats27: 0x05B8,
  22279. qamats29: 0x05B8,
  22280. qamats33: 0x05B8,
  22281. qamatsde: 0x05B8,
  22282. qamatshebrew: 0x05B8,
  22283. qamatsnarrowhebrew: 0x05B8,
  22284. qamatsqatanhebrew: 0x05B8,
  22285. qamatsqatannarrowhebrew: 0x05B8,
  22286. qamatsqatanquarterhebrew: 0x05B8,
  22287. qamatsqatanwidehebrew: 0x05B8,
  22288. qamatsquarterhebrew: 0x05B8,
  22289. qamatswidehebrew: 0x05B8,
  22290. qarneyparahebrew: 0x059F,
  22291. qbopomofo: 0x3111,
  22292. qcircle: 0x24E0,
  22293. qhook: 0x02A0,
  22294. qmonospace: 0xFF51,
  22295. qof: 0x05E7,
  22296. qofdagesh: 0xFB47,
  22297. qofdageshhebrew: 0xFB47,
  22298. qofhebrew: 0x05E7,
  22299. qparen: 0x24AC,
  22300. quarternote: 0x2669,
  22301. qubuts: 0x05BB,
  22302. qubuts18: 0x05BB,
  22303. qubuts25: 0x05BB,
  22304. qubuts31: 0x05BB,
  22305. qubutshebrew: 0x05BB,
  22306. qubutsnarrowhebrew: 0x05BB,
  22307. qubutsquarterhebrew: 0x05BB,
  22308. qubutswidehebrew: 0x05BB,
  22309. question: 0x003F,
  22310. questionarabic: 0x061F,
  22311. questionarmenian: 0x055E,
  22312. questiondown: 0x00BF,
  22313. questiondownsmall: 0xF7BF,
  22314. questiongreek: 0x037E,
  22315. questionmonospace: 0xFF1F,
  22316. questionsmall: 0xF73F,
  22317. quotedbl: 0x0022,
  22318. quotedblbase: 0x201E,
  22319. quotedblleft: 0x201C,
  22320. quotedblmonospace: 0xFF02,
  22321. quotedblprime: 0x301E,
  22322. quotedblprimereversed: 0x301D,
  22323. quotedblright: 0x201D,
  22324. quoteleft: 0x2018,
  22325. quoteleftreversed: 0x201B,
  22326. quotereversed: 0x201B,
  22327. quoteright: 0x2019,
  22328. quoterightn: 0x0149,
  22329. quotesinglbase: 0x201A,
  22330. quotesingle: 0x0027,
  22331. quotesinglemonospace: 0xFF07,
  22332. r: 0x0072,
  22333. raarmenian: 0x057C,
  22334. rabengali: 0x09B0,
  22335. racute: 0x0155,
  22336. radeva: 0x0930,
  22337. radical: 0x221A,
  22338. radicalex: 0xF8E5,
  22339. radoverssquare: 0x33AE,
  22340. radoverssquaredsquare: 0x33AF,
  22341. radsquare: 0x33AD,
  22342. rafe: 0x05BF,
  22343. rafehebrew: 0x05BF,
  22344. ragujarati: 0x0AB0,
  22345. ragurmukhi: 0x0A30,
  22346. rahiragana: 0x3089,
  22347. rakatakana: 0x30E9,
  22348. rakatakanahalfwidth: 0xFF97,
  22349. ralowerdiagonalbengali: 0x09F1,
  22350. ramiddlediagonalbengali: 0x09F0,
  22351. ramshorn: 0x0264,
  22352. ratio: 0x2236,
  22353. rbopomofo: 0x3116,
  22354. rcaron: 0x0159,
  22355. rcedilla: 0x0157,
  22356. rcircle: 0x24E1,
  22357. rcommaaccent: 0x0157,
  22358. rdblgrave: 0x0211,
  22359. rdotaccent: 0x1E59,
  22360. rdotbelow: 0x1E5B,
  22361. rdotbelowmacron: 0x1E5D,
  22362. referencemark: 0x203B,
  22363. reflexsubset: 0x2286,
  22364. reflexsuperset: 0x2287,
  22365. registered: 0x00AE,
  22366. registersans: 0xF8E8,
  22367. registerserif: 0xF6DA,
  22368. reharabic: 0x0631,
  22369. reharmenian: 0x0580,
  22370. rehfinalarabic: 0xFEAE,
  22371. rehiragana: 0x308C,
  22372. rekatakana: 0x30EC,
  22373. rekatakanahalfwidth: 0xFF9A,
  22374. resh: 0x05E8,
  22375. reshdageshhebrew: 0xFB48,
  22376. reshhebrew: 0x05E8,
  22377. reversedtilde: 0x223D,
  22378. reviahebrew: 0x0597,
  22379. reviamugrashhebrew: 0x0597,
  22380. revlogicalnot: 0x2310,
  22381. rfishhook: 0x027E,
  22382. rfishhookreversed: 0x027F,
  22383. rhabengali: 0x09DD,
  22384. rhadeva: 0x095D,
  22385. rho: 0x03C1,
  22386. rhook: 0x027D,
  22387. rhookturned: 0x027B,
  22388. rhookturnedsuperior: 0x02B5,
  22389. rhosymbolgreek: 0x03F1,
  22390. rhotichookmod: 0x02DE,
  22391. rieulacirclekorean: 0x3271,
  22392. rieulaparenkorean: 0x3211,
  22393. rieulcirclekorean: 0x3263,
  22394. rieulhieuhkorean: 0x3140,
  22395. rieulkiyeokkorean: 0x313A,
  22396. rieulkiyeoksioskorean: 0x3169,
  22397. rieulkorean: 0x3139,
  22398. rieulmieumkorean: 0x313B,
  22399. rieulpansioskorean: 0x316C,
  22400. rieulparenkorean: 0x3203,
  22401. rieulphieuphkorean: 0x313F,
  22402. rieulpieupkorean: 0x313C,
  22403. rieulpieupsioskorean: 0x316B,
  22404. rieulsioskorean: 0x313D,
  22405. rieulthieuthkorean: 0x313E,
  22406. rieultikeutkorean: 0x316A,
  22407. rieulyeorinhieuhkorean: 0x316D,
  22408. rightangle: 0x221F,
  22409. righttackbelowcmb: 0x0319,
  22410. righttriangle: 0x22BF,
  22411. rihiragana: 0x308A,
  22412. rikatakana: 0x30EA,
  22413. rikatakanahalfwidth: 0xFF98,
  22414. ring: 0x02DA,
  22415. ringbelowcmb: 0x0325,
  22416. ringcmb: 0x030A,
  22417. ringhalfleft: 0x02BF,
  22418. ringhalfleftarmenian: 0x0559,
  22419. ringhalfleftbelowcmb: 0x031C,
  22420. ringhalfleftcentered: 0x02D3,
  22421. ringhalfright: 0x02BE,
  22422. ringhalfrightbelowcmb: 0x0339,
  22423. ringhalfrightcentered: 0x02D2,
  22424. rinvertedbreve: 0x0213,
  22425. rittorusquare: 0x3351,
  22426. rlinebelow: 0x1E5F,
  22427. rlongleg: 0x027C,
  22428. rlonglegturned: 0x027A,
  22429. rmonospace: 0xFF52,
  22430. rohiragana: 0x308D,
  22431. rokatakana: 0x30ED,
  22432. rokatakanahalfwidth: 0xFF9B,
  22433. roruathai: 0x0E23,
  22434. rparen: 0x24AD,
  22435. rrabengali: 0x09DC,
  22436. rradeva: 0x0931,
  22437. rragurmukhi: 0x0A5C,
  22438. rreharabic: 0x0691,
  22439. rrehfinalarabic: 0xFB8D,
  22440. rrvocalicbengali: 0x09E0,
  22441. rrvocalicdeva: 0x0960,
  22442. rrvocalicgujarati: 0x0AE0,
  22443. rrvocalicvowelsignbengali: 0x09C4,
  22444. rrvocalicvowelsigndeva: 0x0944,
  22445. rrvocalicvowelsigngujarati: 0x0AC4,
  22446. rsuperior: 0xF6F1,
  22447. rtblock: 0x2590,
  22448. rturned: 0x0279,
  22449. rturnedsuperior: 0x02B4,
  22450. ruhiragana: 0x308B,
  22451. rukatakana: 0x30EB,
  22452. rukatakanahalfwidth: 0xFF99,
  22453. rupeemarkbengali: 0x09F2,
  22454. rupeesignbengali: 0x09F3,
  22455. rupiah: 0xF6DD,
  22456. ruthai: 0x0E24,
  22457. rvocalicbengali: 0x098B,
  22458. rvocalicdeva: 0x090B,
  22459. rvocalicgujarati: 0x0A8B,
  22460. rvocalicvowelsignbengali: 0x09C3,
  22461. rvocalicvowelsigndeva: 0x0943,
  22462. rvocalicvowelsigngujarati: 0x0AC3,
  22463. s: 0x0073,
  22464. sabengali: 0x09B8,
  22465. sacute: 0x015B,
  22466. sacutedotaccent: 0x1E65,
  22467. sadarabic: 0x0635,
  22468. sadeva: 0x0938,
  22469. sadfinalarabic: 0xFEBA,
  22470. sadinitialarabic: 0xFEBB,
  22471. sadmedialarabic: 0xFEBC,
  22472. sagujarati: 0x0AB8,
  22473. sagurmukhi: 0x0A38,
  22474. sahiragana: 0x3055,
  22475. sakatakana: 0x30B5,
  22476. sakatakanahalfwidth: 0xFF7B,
  22477. sallallahoualayhewasallamarabic: 0xFDFA,
  22478. samekh: 0x05E1,
  22479. samekhdagesh: 0xFB41,
  22480. samekhdageshhebrew: 0xFB41,
  22481. samekhhebrew: 0x05E1,
  22482. saraaathai: 0x0E32,
  22483. saraaethai: 0x0E41,
  22484. saraaimaimalaithai: 0x0E44,
  22485. saraaimaimuanthai: 0x0E43,
  22486. saraamthai: 0x0E33,
  22487. saraathai: 0x0E30,
  22488. saraethai: 0x0E40,
  22489. saraiileftthai: 0xF886,
  22490. saraiithai: 0x0E35,
  22491. saraileftthai: 0xF885,
  22492. saraithai: 0x0E34,
  22493. saraothai: 0x0E42,
  22494. saraueeleftthai: 0xF888,
  22495. saraueethai: 0x0E37,
  22496. saraueleftthai: 0xF887,
  22497. sarauethai: 0x0E36,
  22498. sarauthai: 0x0E38,
  22499. sarauuthai: 0x0E39,
  22500. sbopomofo: 0x3119,
  22501. scaron: 0x0161,
  22502. scarondotaccent: 0x1E67,
  22503. scedilla: 0x015F,
  22504. schwa: 0x0259,
  22505. schwacyrillic: 0x04D9,
  22506. schwadieresiscyrillic: 0x04DB,
  22507. schwahook: 0x025A,
  22508. scircle: 0x24E2,
  22509. scircumflex: 0x015D,
  22510. scommaaccent: 0x0219,
  22511. sdotaccent: 0x1E61,
  22512. sdotbelow: 0x1E63,
  22513. sdotbelowdotaccent: 0x1E69,
  22514. seagullbelowcmb: 0x033C,
  22515. second: 0x2033,
  22516. secondtonechinese: 0x02CA,
  22517. section: 0x00A7,
  22518. seenarabic: 0x0633,
  22519. seenfinalarabic: 0xFEB2,
  22520. seeninitialarabic: 0xFEB3,
  22521. seenmedialarabic: 0xFEB4,
  22522. segol: 0x05B6,
  22523. segol13: 0x05B6,
  22524. segol1f: 0x05B6,
  22525. segol2c: 0x05B6,
  22526. segolhebrew: 0x05B6,
  22527. segolnarrowhebrew: 0x05B6,
  22528. segolquarterhebrew: 0x05B6,
  22529. segoltahebrew: 0x0592,
  22530. segolwidehebrew: 0x05B6,
  22531. seharmenian: 0x057D,
  22532. sehiragana: 0x305B,
  22533. sekatakana: 0x30BB,
  22534. sekatakanahalfwidth: 0xFF7E,
  22535. semicolon: 0x003B,
  22536. semicolonarabic: 0x061B,
  22537. semicolonmonospace: 0xFF1B,
  22538. semicolonsmall: 0xFE54,
  22539. semivoicedmarkkana: 0x309C,
  22540. semivoicedmarkkanahalfwidth: 0xFF9F,
  22541. sentisquare: 0x3322,
  22542. sentosquare: 0x3323,
  22543. seven: 0x0037,
  22544. sevenarabic: 0x0667,
  22545. sevenbengali: 0x09ED,
  22546. sevencircle: 0x2466,
  22547. sevencircleinversesansserif: 0x2790,
  22548. sevendeva: 0x096D,
  22549. seveneighths: 0x215E,
  22550. sevengujarati: 0x0AED,
  22551. sevengurmukhi: 0x0A6D,
  22552. sevenhackarabic: 0x0667,
  22553. sevenhangzhou: 0x3027,
  22554. sevenideographicparen: 0x3226,
  22555. seveninferior: 0x2087,
  22556. sevenmonospace: 0xFF17,
  22557. sevenoldstyle: 0xF737,
  22558. sevenparen: 0x247A,
  22559. sevenperiod: 0x248E,
  22560. sevenpersian: 0x06F7,
  22561. sevenroman: 0x2176,
  22562. sevensuperior: 0x2077,
  22563. seventeencircle: 0x2470,
  22564. seventeenparen: 0x2484,
  22565. seventeenperiod: 0x2498,
  22566. seventhai: 0x0E57,
  22567. sfthyphen: 0x00AD,
  22568. shaarmenian: 0x0577,
  22569. shabengali: 0x09B6,
  22570. shacyrillic: 0x0448,
  22571. shaddaarabic: 0x0651,
  22572. shaddadammaarabic: 0xFC61,
  22573. shaddadammatanarabic: 0xFC5E,
  22574. shaddafathaarabic: 0xFC60,
  22575. shaddakasraarabic: 0xFC62,
  22576. shaddakasratanarabic: 0xFC5F,
  22577. shade: 0x2592,
  22578. shadedark: 0x2593,
  22579. shadelight: 0x2591,
  22580. shademedium: 0x2592,
  22581. shadeva: 0x0936,
  22582. shagujarati: 0x0AB6,
  22583. shagurmukhi: 0x0A36,
  22584. shalshelethebrew: 0x0593,
  22585. shbopomofo: 0x3115,
  22586. shchacyrillic: 0x0449,
  22587. sheenarabic: 0x0634,
  22588. sheenfinalarabic: 0xFEB6,
  22589. sheeninitialarabic: 0xFEB7,
  22590. sheenmedialarabic: 0xFEB8,
  22591. sheicoptic: 0x03E3,
  22592. sheqel: 0x20AA,
  22593. sheqelhebrew: 0x20AA,
  22594. sheva: 0x05B0,
  22595. sheva115: 0x05B0,
  22596. sheva15: 0x05B0,
  22597. sheva22: 0x05B0,
  22598. sheva2e: 0x05B0,
  22599. shevahebrew: 0x05B0,
  22600. shevanarrowhebrew: 0x05B0,
  22601. shevaquarterhebrew: 0x05B0,
  22602. shevawidehebrew: 0x05B0,
  22603. shhacyrillic: 0x04BB,
  22604. shimacoptic: 0x03ED,
  22605. shin: 0x05E9,
  22606. shindagesh: 0xFB49,
  22607. shindageshhebrew: 0xFB49,
  22608. shindageshshindot: 0xFB2C,
  22609. shindageshshindothebrew: 0xFB2C,
  22610. shindageshsindot: 0xFB2D,
  22611. shindageshsindothebrew: 0xFB2D,
  22612. shindothebrew: 0x05C1,
  22613. shinhebrew: 0x05E9,
  22614. shinshindot: 0xFB2A,
  22615. shinshindothebrew: 0xFB2A,
  22616. shinsindot: 0xFB2B,
  22617. shinsindothebrew: 0xFB2B,
  22618. shook: 0x0282,
  22619. sigma: 0x03C3,
  22620. sigma1: 0x03C2,
  22621. sigmafinal: 0x03C2,
  22622. sigmalunatesymbolgreek: 0x03F2,
  22623. sihiragana: 0x3057,
  22624. sikatakana: 0x30B7,
  22625. sikatakanahalfwidth: 0xFF7C,
  22626. siluqhebrew: 0x05BD,
  22627. siluqlefthebrew: 0x05BD,
  22628. similar: 0x223C,
  22629. sindothebrew: 0x05C2,
  22630. siosacirclekorean: 0x3274,
  22631. siosaparenkorean: 0x3214,
  22632. sioscieuckorean: 0x317E,
  22633. sioscirclekorean: 0x3266,
  22634. sioskiyeokkorean: 0x317A,
  22635. sioskorean: 0x3145,
  22636. siosnieunkorean: 0x317B,
  22637. siosparenkorean: 0x3206,
  22638. siospieupkorean: 0x317D,
  22639. siostikeutkorean: 0x317C,
  22640. six: 0x0036,
  22641. sixarabic: 0x0666,
  22642. sixbengali: 0x09EC,
  22643. sixcircle: 0x2465,
  22644. sixcircleinversesansserif: 0x278F,
  22645. sixdeva: 0x096C,
  22646. sixgujarati: 0x0AEC,
  22647. sixgurmukhi: 0x0A6C,
  22648. sixhackarabic: 0x0666,
  22649. sixhangzhou: 0x3026,
  22650. sixideographicparen: 0x3225,
  22651. sixinferior: 0x2086,
  22652. sixmonospace: 0xFF16,
  22653. sixoldstyle: 0xF736,
  22654. sixparen: 0x2479,
  22655. sixperiod: 0x248D,
  22656. sixpersian: 0x06F6,
  22657. sixroman: 0x2175,
  22658. sixsuperior: 0x2076,
  22659. sixteencircle: 0x246F,
  22660. sixteencurrencydenominatorbengali: 0x09F9,
  22661. sixteenparen: 0x2483,
  22662. sixteenperiod: 0x2497,
  22663. sixthai: 0x0E56,
  22664. slash: 0x002F,
  22665. slashmonospace: 0xFF0F,
  22666. slong: 0x017F,
  22667. slongdotaccent: 0x1E9B,
  22668. smileface: 0x263A,
  22669. smonospace: 0xFF53,
  22670. sofpasuqhebrew: 0x05C3,
  22671. softhyphen: 0x00AD,
  22672. softsigncyrillic: 0x044C,
  22673. sohiragana: 0x305D,
  22674. sokatakana: 0x30BD,
  22675. sokatakanahalfwidth: 0xFF7F,
  22676. soliduslongoverlaycmb: 0x0338,
  22677. solidusshortoverlaycmb: 0x0337,
  22678. sorusithai: 0x0E29,
  22679. sosalathai: 0x0E28,
  22680. sosothai: 0x0E0B,
  22681. sosuathai: 0x0E2A,
  22682. space: 0x0020,
  22683. spacehackarabic: 0x0020,
  22684. spade: 0x2660,
  22685. spadesuitblack: 0x2660,
  22686. spadesuitwhite: 0x2664,
  22687. sparen: 0x24AE,
  22688. squarebelowcmb: 0x033B,
  22689. squarecc: 0x33C4,
  22690. squarecm: 0x339D,
  22691. squarediagonalcrosshatchfill: 0x25A9,
  22692. squarehorizontalfill: 0x25A4,
  22693. squarekg: 0x338F,
  22694. squarekm: 0x339E,
  22695. squarekmcapital: 0x33CE,
  22696. squareln: 0x33D1,
  22697. squarelog: 0x33D2,
  22698. squaremg: 0x338E,
  22699. squaremil: 0x33D5,
  22700. squaremm: 0x339C,
  22701. squaremsquared: 0x33A1,
  22702. squareorthogonalcrosshatchfill: 0x25A6,
  22703. squareupperlefttolowerrightfill: 0x25A7,
  22704. squareupperrighttolowerleftfill: 0x25A8,
  22705. squareverticalfill: 0x25A5,
  22706. squarewhitewithsmallblack: 0x25A3,
  22707. srsquare: 0x33DB,
  22708. ssabengali: 0x09B7,
  22709. ssadeva: 0x0937,
  22710. ssagujarati: 0x0AB7,
  22711. ssangcieuckorean: 0x3149,
  22712. ssanghieuhkorean: 0x3185,
  22713. ssangieungkorean: 0x3180,
  22714. ssangkiyeokkorean: 0x3132,
  22715. ssangnieunkorean: 0x3165,
  22716. ssangpieupkorean: 0x3143,
  22717. ssangsioskorean: 0x3146,
  22718. ssangtikeutkorean: 0x3138,
  22719. ssuperior: 0xF6F2,
  22720. sterling: 0x00A3,
  22721. sterlingmonospace: 0xFFE1,
  22722. strokelongoverlaycmb: 0x0336,
  22723. strokeshortoverlaycmb: 0x0335,
  22724. subset: 0x2282,
  22725. subsetnotequal: 0x228A,
  22726. subsetorequal: 0x2286,
  22727. succeeds: 0x227B,
  22728. suchthat: 0x220B,
  22729. suhiragana: 0x3059,
  22730. sukatakana: 0x30B9,
  22731. sukatakanahalfwidth: 0xFF7D,
  22732. sukunarabic: 0x0652,
  22733. summation: 0x2211,
  22734. sun: 0x263C,
  22735. superset: 0x2283,
  22736. supersetnotequal: 0x228B,
  22737. supersetorequal: 0x2287,
  22738. svsquare: 0x33DC,
  22739. syouwaerasquare: 0x337C,
  22740. t: 0x0074,
  22741. tabengali: 0x09A4,
  22742. tackdown: 0x22A4,
  22743. tackleft: 0x22A3,
  22744. tadeva: 0x0924,
  22745. tagujarati: 0x0AA4,
  22746. tagurmukhi: 0x0A24,
  22747. taharabic: 0x0637,
  22748. tahfinalarabic: 0xFEC2,
  22749. tahinitialarabic: 0xFEC3,
  22750. tahiragana: 0x305F,
  22751. tahmedialarabic: 0xFEC4,
  22752. taisyouerasquare: 0x337D,
  22753. takatakana: 0x30BF,
  22754. takatakanahalfwidth: 0xFF80,
  22755. tatweelarabic: 0x0640,
  22756. tau: 0x03C4,
  22757. tav: 0x05EA,
  22758. tavdages: 0xFB4A,
  22759. tavdagesh: 0xFB4A,
  22760. tavdageshhebrew: 0xFB4A,
  22761. tavhebrew: 0x05EA,
  22762. tbar: 0x0167,
  22763. tbopomofo: 0x310A,
  22764. tcaron: 0x0165,
  22765. tccurl: 0x02A8,
  22766. tcedilla: 0x0163,
  22767. tcheharabic: 0x0686,
  22768. tchehfinalarabic: 0xFB7B,
  22769. tchehinitialarabic: 0xFB7C,
  22770. tchehmedialarabic: 0xFB7D,
  22771. tcircle: 0x24E3,
  22772. tcircumflexbelow: 0x1E71,
  22773. tcommaaccent: 0x0163,
  22774. tdieresis: 0x1E97,
  22775. tdotaccent: 0x1E6B,
  22776. tdotbelow: 0x1E6D,
  22777. tecyrillic: 0x0442,
  22778. tedescendercyrillic: 0x04AD,
  22779. teharabic: 0x062A,
  22780. tehfinalarabic: 0xFE96,
  22781. tehhahinitialarabic: 0xFCA2,
  22782. tehhahisolatedarabic: 0xFC0C,
  22783. tehinitialarabic: 0xFE97,
  22784. tehiragana: 0x3066,
  22785. tehjeeminitialarabic: 0xFCA1,
  22786. tehjeemisolatedarabic: 0xFC0B,
  22787. tehmarbutaarabic: 0x0629,
  22788. tehmarbutafinalarabic: 0xFE94,
  22789. tehmedialarabic: 0xFE98,
  22790. tehmeeminitialarabic: 0xFCA4,
  22791. tehmeemisolatedarabic: 0xFC0E,
  22792. tehnoonfinalarabic: 0xFC73,
  22793. tekatakana: 0x30C6,
  22794. tekatakanahalfwidth: 0xFF83,
  22795. telephone: 0x2121,
  22796. telephoneblack: 0x260E,
  22797. telishagedolahebrew: 0x05A0,
  22798. telishaqetanahebrew: 0x05A9,
  22799. tencircle: 0x2469,
  22800. tenideographicparen: 0x3229,
  22801. tenparen: 0x247D,
  22802. tenperiod: 0x2491,
  22803. tenroman: 0x2179,
  22804. tesh: 0x02A7,
  22805. tet: 0x05D8,
  22806. tetdagesh: 0xFB38,
  22807. tetdageshhebrew: 0xFB38,
  22808. tethebrew: 0x05D8,
  22809. tetsecyrillic: 0x04B5,
  22810. tevirhebrew: 0x059B,
  22811. tevirlefthebrew: 0x059B,
  22812. thabengali: 0x09A5,
  22813. thadeva: 0x0925,
  22814. thagujarati: 0x0AA5,
  22815. thagurmukhi: 0x0A25,
  22816. thalarabic: 0x0630,
  22817. thalfinalarabic: 0xFEAC,
  22818. thanthakhatlowleftthai: 0xF898,
  22819. thanthakhatlowrightthai: 0xF897,
  22820. thanthakhatthai: 0x0E4C,
  22821. thanthakhatupperleftthai: 0xF896,
  22822. theharabic: 0x062B,
  22823. thehfinalarabic: 0xFE9A,
  22824. thehinitialarabic: 0xFE9B,
  22825. thehmedialarabic: 0xFE9C,
  22826. thereexists: 0x2203,
  22827. therefore: 0x2234,
  22828. theta: 0x03B8,
  22829. theta1: 0x03D1,
  22830. thetasymbolgreek: 0x03D1,
  22831. thieuthacirclekorean: 0x3279,
  22832. thieuthaparenkorean: 0x3219,
  22833. thieuthcirclekorean: 0x326B,
  22834. thieuthkorean: 0x314C,
  22835. thieuthparenkorean: 0x320B,
  22836. thirteencircle: 0x246C,
  22837. thirteenparen: 0x2480,
  22838. thirteenperiod: 0x2494,
  22839. thonangmonthothai: 0x0E11,
  22840. thook: 0x01AD,
  22841. thophuthaothai: 0x0E12,
  22842. thorn: 0x00FE,
  22843. thothahanthai: 0x0E17,
  22844. thothanthai: 0x0E10,
  22845. thothongthai: 0x0E18,
  22846. thothungthai: 0x0E16,
  22847. thousandcyrillic: 0x0482,
  22848. thousandsseparatorarabic: 0x066C,
  22849. thousandsseparatorpersian: 0x066C,
  22850. three: 0x0033,
  22851. threearabic: 0x0663,
  22852. threebengali: 0x09E9,
  22853. threecircle: 0x2462,
  22854. threecircleinversesansserif: 0x278C,
  22855. threedeva: 0x0969,
  22856. threeeighths: 0x215C,
  22857. threegujarati: 0x0AE9,
  22858. threegurmukhi: 0x0A69,
  22859. threehackarabic: 0x0663,
  22860. threehangzhou: 0x3023,
  22861. threeideographicparen: 0x3222,
  22862. threeinferior: 0x2083,
  22863. threemonospace: 0xFF13,
  22864. threenumeratorbengali: 0x09F6,
  22865. threeoldstyle: 0xF733,
  22866. threeparen: 0x2476,
  22867. threeperiod: 0x248A,
  22868. threepersian: 0x06F3,
  22869. threequarters: 0x00BE,
  22870. threequartersemdash: 0xF6DE,
  22871. threeroman: 0x2172,
  22872. threesuperior: 0x00B3,
  22873. threethai: 0x0E53,
  22874. thzsquare: 0x3394,
  22875. tihiragana: 0x3061,
  22876. tikatakana: 0x30C1,
  22877. tikatakanahalfwidth: 0xFF81,
  22878. tikeutacirclekorean: 0x3270,
  22879. tikeutaparenkorean: 0x3210,
  22880. tikeutcirclekorean: 0x3262,
  22881. tikeutkorean: 0x3137,
  22882. tikeutparenkorean: 0x3202,
  22883. tilde: 0x02DC,
  22884. tildebelowcmb: 0x0330,
  22885. tildecmb: 0x0303,
  22886. tildecomb: 0x0303,
  22887. tildedoublecmb: 0x0360,
  22888. tildeoperator: 0x223C,
  22889. tildeoverlaycmb: 0x0334,
  22890. tildeverticalcmb: 0x033E,
  22891. timescircle: 0x2297,
  22892. tipehahebrew: 0x0596,
  22893. tipehalefthebrew: 0x0596,
  22894. tippigurmukhi: 0x0A70,
  22895. titlocyrilliccmb: 0x0483,
  22896. tiwnarmenian: 0x057F,
  22897. tlinebelow: 0x1E6F,
  22898. tmonospace: 0xFF54,
  22899. toarmenian: 0x0569,
  22900. tohiragana: 0x3068,
  22901. tokatakana: 0x30C8,
  22902. tokatakanahalfwidth: 0xFF84,
  22903. tonebarextrahighmod: 0x02E5,
  22904. tonebarextralowmod: 0x02E9,
  22905. tonebarhighmod: 0x02E6,
  22906. tonebarlowmod: 0x02E8,
  22907. tonebarmidmod: 0x02E7,
  22908. tonefive: 0x01BD,
  22909. tonesix: 0x0185,
  22910. tonetwo: 0x01A8,
  22911. tonos: 0x0384,
  22912. tonsquare: 0x3327,
  22913. topatakthai: 0x0E0F,
  22914. tortoiseshellbracketleft: 0x3014,
  22915. tortoiseshellbracketleftsmall: 0xFE5D,
  22916. tortoiseshellbracketleftvertical: 0xFE39,
  22917. tortoiseshellbracketright: 0x3015,
  22918. tortoiseshellbracketrightsmall: 0xFE5E,
  22919. tortoiseshellbracketrightvertical: 0xFE3A,
  22920. totaothai: 0x0E15,
  22921. tpalatalhook: 0x01AB,
  22922. tparen: 0x24AF,
  22923. trademark: 0x2122,
  22924. trademarksans: 0xF8EA,
  22925. trademarkserif: 0xF6DB,
  22926. tretroflexhook: 0x0288,
  22927. triagdn: 0x25BC,
  22928. triaglf: 0x25C4,
  22929. triagrt: 0x25BA,
  22930. triagup: 0x25B2,
  22931. ts: 0x02A6,
  22932. tsadi: 0x05E6,
  22933. tsadidagesh: 0xFB46,
  22934. tsadidageshhebrew: 0xFB46,
  22935. tsadihebrew: 0x05E6,
  22936. tsecyrillic: 0x0446,
  22937. tsere: 0x05B5,
  22938. tsere12: 0x05B5,
  22939. tsere1e: 0x05B5,
  22940. tsere2b: 0x05B5,
  22941. tserehebrew: 0x05B5,
  22942. tserenarrowhebrew: 0x05B5,
  22943. tserequarterhebrew: 0x05B5,
  22944. tserewidehebrew: 0x05B5,
  22945. tshecyrillic: 0x045B,
  22946. tsuperior: 0xF6F3,
  22947. ttabengali: 0x099F,
  22948. ttadeva: 0x091F,
  22949. ttagujarati: 0x0A9F,
  22950. ttagurmukhi: 0x0A1F,
  22951. tteharabic: 0x0679,
  22952. ttehfinalarabic: 0xFB67,
  22953. ttehinitialarabic: 0xFB68,
  22954. ttehmedialarabic: 0xFB69,
  22955. tthabengali: 0x09A0,
  22956. tthadeva: 0x0920,
  22957. tthagujarati: 0x0AA0,
  22958. tthagurmukhi: 0x0A20,
  22959. tturned: 0x0287,
  22960. tuhiragana: 0x3064,
  22961. tukatakana: 0x30C4,
  22962. tukatakanahalfwidth: 0xFF82,
  22963. tusmallhiragana: 0x3063,
  22964. tusmallkatakana: 0x30C3,
  22965. tusmallkatakanahalfwidth: 0xFF6F,
  22966. twelvecircle: 0x246B,
  22967. twelveparen: 0x247F,
  22968. twelveperiod: 0x2493,
  22969. twelveroman: 0x217B,
  22970. twentycircle: 0x2473,
  22971. twentyhangzhou: 0x5344,
  22972. twentyparen: 0x2487,
  22973. twentyperiod: 0x249B,
  22974. two: 0x0032,
  22975. twoarabic: 0x0662,
  22976. twobengali: 0x09E8,
  22977. twocircle: 0x2461,
  22978. twocircleinversesansserif: 0x278B,
  22979. twodeva: 0x0968,
  22980. twodotenleader: 0x2025,
  22981. twodotleader: 0x2025,
  22982. twodotleadervertical: 0xFE30,
  22983. twogujarati: 0x0AE8,
  22984. twogurmukhi: 0x0A68,
  22985. twohackarabic: 0x0662,
  22986. twohangzhou: 0x3022,
  22987. twoideographicparen: 0x3221,
  22988. twoinferior: 0x2082,
  22989. twomonospace: 0xFF12,
  22990. twonumeratorbengali: 0x09F5,
  22991. twooldstyle: 0xF732,
  22992. twoparen: 0x2475,
  22993. twoperiod: 0x2489,
  22994. twopersian: 0x06F2,
  22995. tworoman: 0x2171,
  22996. twostroke: 0x01BB,
  22997. twosuperior: 0x00B2,
  22998. twothai: 0x0E52,
  22999. twothirds: 0x2154,
  23000. u: 0x0075,
  23001. uacute: 0x00FA,
  23002. ubar: 0x0289,
  23003. ubengali: 0x0989,
  23004. ubopomofo: 0x3128,
  23005. ubreve: 0x016D,
  23006. ucaron: 0x01D4,
  23007. ucircle: 0x24E4,
  23008. ucircumflex: 0x00FB,
  23009. ucircumflexbelow: 0x1E77,
  23010. ucyrillic: 0x0443,
  23011. udattadeva: 0x0951,
  23012. udblacute: 0x0171,
  23013. udblgrave: 0x0215,
  23014. udeva: 0x0909,
  23015. udieresis: 0x00FC,
  23016. udieresisacute: 0x01D8,
  23017. udieresisbelow: 0x1E73,
  23018. udieresiscaron: 0x01DA,
  23019. udieresiscyrillic: 0x04F1,
  23020. udieresisgrave: 0x01DC,
  23021. udieresismacron: 0x01D6,
  23022. udotbelow: 0x1EE5,
  23023. ugrave: 0x00F9,
  23024. ugujarati: 0x0A89,
  23025. ugurmukhi: 0x0A09,
  23026. uhiragana: 0x3046,
  23027. uhookabove: 0x1EE7,
  23028. uhorn: 0x01B0,
  23029. uhornacute: 0x1EE9,
  23030. uhorndotbelow: 0x1EF1,
  23031. uhorngrave: 0x1EEB,
  23032. uhornhookabove: 0x1EED,
  23033. uhorntilde: 0x1EEF,
  23034. uhungarumlaut: 0x0171,
  23035. uhungarumlautcyrillic: 0x04F3,
  23036. uinvertedbreve: 0x0217,
  23037. ukatakana: 0x30A6,
  23038. ukatakanahalfwidth: 0xFF73,
  23039. ukcyrillic: 0x0479,
  23040. ukorean: 0x315C,
  23041. umacron: 0x016B,
  23042. umacroncyrillic: 0x04EF,
  23043. umacrondieresis: 0x1E7B,
  23044. umatragurmukhi: 0x0A41,
  23045. umonospace: 0xFF55,
  23046. underscore: 0x005F,
  23047. underscoredbl: 0x2017,
  23048. underscoremonospace: 0xFF3F,
  23049. underscorevertical: 0xFE33,
  23050. underscorewavy: 0xFE4F,
  23051. union: 0x222A,
  23052. universal: 0x2200,
  23053. uogonek: 0x0173,
  23054. uparen: 0x24B0,
  23055. upblock: 0x2580,
  23056. upperdothebrew: 0x05C4,
  23057. upsilon: 0x03C5,
  23058. upsilondieresis: 0x03CB,
  23059. upsilondieresistonos: 0x03B0,
  23060. upsilonlatin: 0x028A,
  23061. upsilontonos: 0x03CD,
  23062. uptackbelowcmb: 0x031D,
  23063. uptackmod: 0x02D4,
  23064. uragurmukhi: 0x0A73,
  23065. uring: 0x016F,
  23066. ushortcyrillic: 0x045E,
  23067. usmallhiragana: 0x3045,
  23068. usmallkatakana: 0x30A5,
  23069. usmallkatakanahalfwidth: 0xFF69,
  23070. ustraightcyrillic: 0x04AF,
  23071. ustraightstrokecyrillic: 0x04B1,
  23072. utilde: 0x0169,
  23073. utildeacute: 0x1E79,
  23074. utildebelow: 0x1E75,
  23075. uubengali: 0x098A,
  23076. uudeva: 0x090A,
  23077. uugujarati: 0x0A8A,
  23078. uugurmukhi: 0x0A0A,
  23079. uumatragurmukhi: 0x0A42,
  23080. uuvowelsignbengali: 0x09C2,
  23081. uuvowelsigndeva: 0x0942,
  23082. uuvowelsigngujarati: 0x0AC2,
  23083. uvowelsignbengali: 0x09C1,
  23084. uvowelsigndeva: 0x0941,
  23085. uvowelsigngujarati: 0x0AC1,
  23086. v: 0x0076,
  23087. vadeva: 0x0935,
  23088. vagujarati: 0x0AB5,
  23089. vagurmukhi: 0x0A35,
  23090. vakatakana: 0x30F7,
  23091. vav: 0x05D5,
  23092. vavdagesh: 0xFB35,
  23093. vavdagesh65: 0xFB35,
  23094. vavdageshhebrew: 0xFB35,
  23095. vavhebrew: 0x05D5,
  23096. vavholam: 0xFB4B,
  23097. vavholamhebrew: 0xFB4B,
  23098. vavvavhebrew: 0x05F0,
  23099. vavyodhebrew: 0x05F1,
  23100. vcircle: 0x24E5,
  23101. vdotbelow: 0x1E7F,
  23102. vecyrillic: 0x0432,
  23103. veharabic: 0x06A4,
  23104. vehfinalarabic: 0xFB6B,
  23105. vehinitialarabic: 0xFB6C,
  23106. vehmedialarabic: 0xFB6D,
  23107. vekatakana: 0x30F9,
  23108. venus: 0x2640,
  23109. verticalbar: 0x007C,
  23110. verticallineabovecmb: 0x030D,
  23111. verticallinebelowcmb: 0x0329,
  23112. verticallinelowmod: 0x02CC,
  23113. verticallinemod: 0x02C8,
  23114. vewarmenian: 0x057E,
  23115. vhook: 0x028B,
  23116. vikatakana: 0x30F8,
  23117. viramabengali: 0x09CD,
  23118. viramadeva: 0x094D,
  23119. viramagujarati: 0x0ACD,
  23120. visargabengali: 0x0983,
  23121. visargadeva: 0x0903,
  23122. visargagujarati: 0x0A83,
  23123. vmonospace: 0xFF56,
  23124. voarmenian: 0x0578,
  23125. voicediterationhiragana: 0x309E,
  23126. voicediterationkatakana: 0x30FE,
  23127. voicedmarkkana: 0x309B,
  23128. voicedmarkkanahalfwidth: 0xFF9E,
  23129. vokatakana: 0x30FA,
  23130. vparen: 0x24B1,
  23131. vtilde: 0x1E7D,
  23132. vturned: 0x028C,
  23133. vuhiragana: 0x3094,
  23134. vukatakana: 0x30F4,
  23135. w: 0x0077,
  23136. wacute: 0x1E83,
  23137. waekorean: 0x3159,
  23138. wahiragana: 0x308F,
  23139. wakatakana: 0x30EF,
  23140. wakatakanahalfwidth: 0xFF9C,
  23141. wakorean: 0x3158,
  23142. wasmallhiragana: 0x308E,
  23143. wasmallkatakana: 0x30EE,
  23144. wattosquare: 0x3357,
  23145. wavedash: 0x301C,
  23146. wavyunderscorevertical: 0xFE34,
  23147. wawarabic: 0x0648,
  23148. wawfinalarabic: 0xFEEE,
  23149. wawhamzaabovearabic: 0x0624,
  23150. wawhamzaabovefinalarabic: 0xFE86,
  23151. wbsquare: 0x33DD,
  23152. wcircle: 0x24E6,
  23153. wcircumflex: 0x0175,
  23154. wdieresis: 0x1E85,
  23155. wdotaccent: 0x1E87,
  23156. wdotbelow: 0x1E89,
  23157. wehiragana: 0x3091,
  23158. weierstrass: 0x2118,
  23159. wekatakana: 0x30F1,
  23160. wekorean: 0x315E,
  23161. weokorean: 0x315D,
  23162. wgrave: 0x1E81,
  23163. whitebullet: 0x25E6,
  23164. whitecircle: 0x25CB,
  23165. whitecircleinverse: 0x25D9,
  23166. whitecornerbracketleft: 0x300E,
  23167. whitecornerbracketleftvertical: 0xFE43,
  23168. whitecornerbracketright: 0x300F,
  23169. whitecornerbracketrightvertical: 0xFE44,
  23170. whitediamond: 0x25C7,
  23171. whitediamondcontainingblacksmalldiamond: 0x25C8,
  23172. whitedownpointingsmalltriangle: 0x25BF,
  23173. whitedownpointingtriangle: 0x25BD,
  23174. whiteleftpointingsmalltriangle: 0x25C3,
  23175. whiteleftpointingtriangle: 0x25C1,
  23176. whitelenticularbracketleft: 0x3016,
  23177. whitelenticularbracketright: 0x3017,
  23178. whiterightpointingsmalltriangle: 0x25B9,
  23179. whiterightpointingtriangle: 0x25B7,
  23180. whitesmallsquare: 0x25AB,
  23181. whitesmilingface: 0x263A,
  23182. whitesquare: 0x25A1,
  23183. whitestar: 0x2606,
  23184. whitetelephone: 0x260F,
  23185. whitetortoiseshellbracketleft: 0x3018,
  23186. whitetortoiseshellbracketright: 0x3019,
  23187. whiteuppointingsmalltriangle: 0x25B5,
  23188. whiteuppointingtriangle: 0x25B3,
  23189. wihiragana: 0x3090,
  23190. wikatakana: 0x30F0,
  23191. wikorean: 0x315F,
  23192. wmonospace: 0xFF57,
  23193. wohiragana: 0x3092,
  23194. wokatakana: 0x30F2,
  23195. wokatakanahalfwidth: 0xFF66,
  23196. won: 0x20A9,
  23197. wonmonospace: 0xFFE6,
  23198. wowaenthai: 0x0E27,
  23199. wparen: 0x24B2,
  23200. wring: 0x1E98,
  23201. wsuperior: 0x02B7,
  23202. wturned: 0x028D,
  23203. wynn: 0x01BF,
  23204. x: 0x0078,
  23205. xabovecmb: 0x033D,
  23206. xbopomofo: 0x3112,
  23207. xcircle: 0x24E7,
  23208. xdieresis: 0x1E8D,
  23209. xdotaccent: 0x1E8B,
  23210. xeharmenian: 0x056D,
  23211. xi: 0x03BE,
  23212. xmonospace: 0xFF58,
  23213. xparen: 0x24B3,
  23214. xsuperior: 0x02E3,
  23215. y: 0x0079,
  23216. yaadosquare: 0x334E,
  23217. yabengali: 0x09AF,
  23218. yacute: 0x00FD,
  23219. yadeva: 0x092F,
  23220. yaekorean: 0x3152,
  23221. yagujarati: 0x0AAF,
  23222. yagurmukhi: 0x0A2F,
  23223. yahiragana: 0x3084,
  23224. yakatakana: 0x30E4,
  23225. yakatakanahalfwidth: 0xFF94,
  23226. yakorean: 0x3151,
  23227. yamakkanthai: 0x0E4E,
  23228. yasmallhiragana: 0x3083,
  23229. yasmallkatakana: 0x30E3,
  23230. yasmallkatakanahalfwidth: 0xFF6C,
  23231. yatcyrillic: 0x0463,
  23232. ycircle: 0x24E8,
  23233. ycircumflex: 0x0177,
  23234. ydieresis: 0x00FF,
  23235. ydotaccent: 0x1E8F,
  23236. ydotbelow: 0x1EF5,
  23237. yeharabic: 0x064A,
  23238. yehbarreearabic: 0x06D2,
  23239. yehbarreefinalarabic: 0xFBAF,
  23240. yehfinalarabic: 0xFEF2,
  23241. yehhamzaabovearabic: 0x0626,
  23242. yehhamzaabovefinalarabic: 0xFE8A,
  23243. yehhamzaaboveinitialarabic: 0xFE8B,
  23244. yehhamzaabovemedialarabic: 0xFE8C,
  23245. yehinitialarabic: 0xFEF3,
  23246. yehmedialarabic: 0xFEF4,
  23247. yehmeeminitialarabic: 0xFCDD,
  23248. yehmeemisolatedarabic: 0xFC58,
  23249. yehnoonfinalarabic: 0xFC94,
  23250. yehthreedotsbelowarabic: 0x06D1,
  23251. yekorean: 0x3156,
  23252. yen: 0x00A5,
  23253. yenmonospace: 0xFFE5,
  23254. yeokorean: 0x3155,
  23255. yeorinhieuhkorean: 0x3186,
  23256. yerahbenyomohebrew: 0x05AA,
  23257. yerahbenyomolefthebrew: 0x05AA,
  23258. yericyrillic: 0x044B,
  23259. yerudieresiscyrillic: 0x04F9,
  23260. yesieungkorean: 0x3181,
  23261. yesieungpansioskorean: 0x3183,
  23262. yesieungsioskorean: 0x3182,
  23263. yetivhebrew: 0x059A,
  23264. ygrave: 0x1EF3,
  23265. yhook: 0x01B4,
  23266. yhookabove: 0x1EF7,
  23267. yiarmenian: 0x0575,
  23268. yicyrillic: 0x0457,
  23269. yikorean: 0x3162,
  23270. yinyang: 0x262F,
  23271. yiwnarmenian: 0x0582,
  23272. ymonospace: 0xFF59,
  23273. yod: 0x05D9,
  23274. yoddagesh: 0xFB39,
  23275. yoddageshhebrew: 0xFB39,
  23276. yodhebrew: 0x05D9,
  23277. yodyodhebrew: 0x05F2,
  23278. yodyodpatahhebrew: 0xFB1F,
  23279. yohiragana: 0x3088,
  23280. yoikorean: 0x3189,
  23281. yokatakana: 0x30E8,
  23282. yokatakanahalfwidth: 0xFF96,
  23283. yokorean: 0x315B,
  23284. yosmallhiragana: 0x3087,
  23285. yosmallkatakana: 0x30E7,
  23286. yosmallkatakanahalfwidth: 0xFF6E,
  23287. yotgreek: 0x03F3,
  23288. yoyaekorean: 0x3188,
  23289. yoyakorean: 0x3187,
  23290. yoyakthai: 0x0E22,
  23291. yoyingthai: 0x0E0D,
  23292. yparen: 0x24B4,
  23293. ypogegrammeni: 0x037A,
  23294. ypogegrammenigreekcmb: 0x0345,
  23295. yr: 0x01A6,
  23296. yring: 0x1E99,
  23297. ysuperior: 0x02B8,
  23298. ytilde: 0x1EF9,
  23299. yturned: 0x028E,
  23300. yuhiragana: 0x3086,
  23301. yuikorean: 0x318C,
  23302. yukatakana: 0x30E6,
  23303. yukatakanahalfwidth: 0xFF95,
  23304. yukorean: 0x3160,
  23305. yusbigcyrillic: 0x046B,
  23306. yusbigiotifiedcyrillic: 0x046D,
  23307. yuslittlecyrillic: 0x0467,
  23308. yuslittleiotifiedcyrillic: 0x0469,
  23309. yusmallhiragana: 0x3085,
  23310. yusmallkatakana: 0x30E5,
  23311. yusmallkatakanahalfwidth: 0xFF6D,
  23312. yuyekorean: 0x318B,
  23313. yuyeokorean: 0x318A,
  23314. yyabengali: 0x09DF,
  23315. yyadeva: 0x095F,
  23316. z: 0x007A,
  23317. zaarmenian: 0x0566,
  23318. zacute: 0x017A,
  23319. zadeva: 0x095B,
  23320. zagurmukhi: 0x0A5B,
  23321. zaharabic: 0x0638,
  23322. zahfinalarabic: 0xFEC6,
  23323. zahinitialarabic: 0xFEC7,
  23324. zahiragana: 0x3056,
  23325. zahmedialarabic: 0xFEC8,
  23326. zainarabic: 0x0632,
  23327. zainfinalarabic: 0xFEB0,
  23328. zakatakana: 0x30B6,
  23329. zaqefgadolhebrew: 0x0595,
  23330. zaqefqatanhebrew: 0x0594,
  23331. zarqahebrew: 0x0598,
  23332. zayin: 0x05D6,
  23333. zayindagesh: 0xFB36,
  23334. zayindageshhebrew: 0xFB36,
  23335. zayinhebrew: 0x05D6,
  23336. zbopomofo: 0x3117,
  23337. zcaron: 0x017E,
  23338. zcircle: 0x24E9,
  23339. zcircumflex: 0x1E91,
  23340. zcurl: 0x0291,
  23341. zdot: 0x017C,
  23342. zdotaccent: 0x017C,
  23343. zdotbelow: 0x1E93,
  23344. zecyrillic: 0x0437,
  23345. zedescendercyrillic: 0x0499,
  23346. zedieresiscyrillic: 0x04DF,
  23347. zehiragana: 0x305C,
  23348. zekatakana: 0x30BC,
  23349. zero: 0x0030,
  23350. zeroarabic: 0x0660,
  23351. zerobengali: 0x09E6,
  23352. zerodeva: 0x0966,
  23353. zerogujarati: 0x0AE6,
  23354. zerogurmukhi: 0x0A66,
  23355. zerohackarabic: 0x0660,
  23356. zeroinferior: 0x2080,
  23357. zeromonospace: 0xFF10,
  23358. zerooldstyle: 0xF730,
  23359. zeropersian: 0x06F0,
  23360. zerosuperior: 0x2070,
  23361. zerothai: 0x0E50,
  23362. zerowidthjoiner: 0xFEFF,
  23363. zerowidthnonjoiner: 0x200C,
  23364. zerowidthspace: 0x200B,
  23365. zeta: 0x03B6,
  23366. zhbopomofo: 0x3113,
  23367. zhearmenian: 0x056A,
  23368. zhebrevecyrillic: 0x04C2,
  23369. zhecyrillic: 0x0436,
  23370. zhedescendercyrillic: 0x0497,
  23371. zhedieresiscyrillic: 0x04DD,
  23372. zihiragana: 0x3058,
  23373. zikatakana: 0x30B8,
  23374. zinorhebrew: 0x05AE,
  23375. zlinebelow: 0x1E95,
  23376. zmonospace: 0xFF5A,
  23377. zohiragana: 0x305E,
  23378. zokatakana: 0x30BE,
  23379. zparen: 0x24B5,
  23380. zretroflexhook: 0x0290,
  23381. zstroke: 0x01B6,
  23382. zuhiragana: 0x305A,
  23383. zukatakana: 0x30BA,
  23384. '.notdef': 0x0000
  23385. };
  23386. var PDFImage = (function PDFImageClosure() {
  23387. /**
  23388. * Decode the image in the main thread if it supported. Resovles the promise
  23389. * when the image data is ready.
  23390. */
  23391. function handleImageData(handler, xref, res, image) {
  23392. if (image instanceof JpegStream && image.isNativelyDecodable(xref, res)) {
  23393. // For natively supported jpegs send them to the main thread for decoding.
  23394. var dict = image.dict;
  23395. var colorSpace = dict.get('ColorSpace', 'CS');
  23396. colorSpace = ColorSpace.parse(colorSpace, xref, res);
  23397. var numComps = colorSpace.numComps;
  23398. var decodePromise = handler.sendWithPromise('JpegDecode',
  23399. [image.getIR(), numComps]);
  23400. return decodePromise.then(function (message) {
  23401. var data = message.data;
  23402. return new Stream(data, 0, data.length, image.dict);
  23403. });
  23404. } else {
  23405. return Promise.resolve(image);
  23406. }
  23407. }
  23408. /**
  23409. * Decode and clamp a value. The formula is different from the spec because we
  23410. * don't decode to float range [0,1], we decode it in the [0,max] range.
  23411. */
  23412. function decodeAndClamp(value, addend, coefficient, max) {
  23413. value = addend + value * coefficient;
  23414. // Clamp the value to the range
  23415. return (value < 0 ? 0 : (value > max ? max : value));
  23416. }
  23417. function PDFImage(xref, res, image, inline, smask, mask, isMask) {
  23418. this.image = image;
  23419. var dict = image.dict;
  23420. if (dict.has('Filter')) {
  23421. var filter = dict.get('Filter').name;
  23422. if (filter === 'JPXDecode') {
  23423. var jpxImage = new JpxImage();
  23424. jpxImage.parseImageProperties(image.stream);
  23425. image.stream.reset();
  23426. image.bitsPerComponent = jpxImage.bitsPerComponent;
  23427. image.numComps = jpxImage.componentsCount;
  23428. } else if (filter === 'JBIG2Decode') {
  23429. image.bitsPerComponent = 1;
  23430. image.numComps = 1;
  23431. }
  23432. }
  23433. // TODO cache rendered images?
  23434. this.width = dict.get('Width', 'W');
  23435. this.height = dict.get('Height', 'H');
  23436. if (this.width < 1 || this.height < 1) {
  23437. error('Invalid image width: ' + this.width + ' or height: ' +
  23438. this.height);
  23439. }
  23440. this.interpolate = dict.get('Interpolate', 'I') || false;
  23441. this.imageMask = dict.get('ImageMask', 'IM') || false;
  23442. this.matte = dict.get('Matte') || false;
  23443. var bitsPerComponent = image.bitsPerComponent;
  23444. if (!bitsPerComponent) {
  23445. bitsPerComponent = dict.get('BitsPerComponent', 'BPC');
  23446. if (!bitsPerComponent) {
  23447. if (this.imageMask) {
  23448. bitsPerComponent = 1;
  23449. } else {
  23450. error('Bits per component missing in image: ' + this.imageMask);
  23451. }
  23452. }
  23453. }
  23454. this.bpc = bitsPerComponent;
  23455. if (!this.imageMask) {
  23456. var colorSpace = dict.get('ColorSpace', 'CS');
  23457. if (!colorSpace) {
  23458. info('JPX images (which do not require color spaces)');
  23459. switch (image.numComps) {
  23460. case 1:
  23461. colorSpace = Name.get('DeviceGray');
  23462. break;
  23463. case 3:
  23464. colorSpace = Name.get('DeviceRGB');
  23465. break;
  23466. case 4:
  23467. colorSpace = Name.get('DeviceCMYK');
  23468. break;
  23469. default:
  23470. error('JPX images with ' + this.numComps +
  23471. ' color components not supported.');
  23472. }
  23473. }
  23474. this.colorSpace = ColorSpace.parse(colorSpace, xref, res);
  23475. this.numComps = this.colorSpace.numComps;
  23476. }
  23477. this.decode = dict.get('Decode', 'D');
  23478. this.needsDecode = false;
  23479. if (this.decode &&
  23480. ((this.colorSpace && !this.colorSpace.isDefaultDecode(this.decode)) ||
  23481. (isMask && !ColorSpace.isDefaultDecode(this.decode, 1)))) {
  23482. this.needsDecode = true;
  23483. // Do some preprocessing to avoid more math.
  23484. var max = (1 << bitsPerComponent) - 1;
  23485. this.decodeCoefficients = [];
  23486. this.decodeAddends = [];
  23487. for (var i = 0, j = 0; i < this.decode.length; i += 2, ++j) {
  23488. var dmin = this.decode[i];
  23489. var dmax = this.decode[i + 1];
  23490. this.decodeCoefficients[j] = dmax - dmin;
  23491. this.decodeAddends[j] = max * dmin;
  23492. }
  23493. }
  23494. if (smask) {
  23495. this.smask = new PDFImage(xref, res, smask, false);
  23496. } else if (mask) {
  23497. if (isStream(mask)) {
  23498. this.mask = new PDFImage(xref, res, mask, false, null, null, true);
  23499. } else {
  23500. // Color key mask (just an array).
  23501. this.mask = mask;
  23502. }
  23503. }
  23504. }
  23505. /**
  23506. * Handles processing of image data and returns the Promise that is resolved
  23507. * with a PDFImage when the image is ready to be used.
  23508. */
  23509. PDFImage.buildImage = function PDFImage_buildImage(handler, xref,
  23510. res, image, inline) {
  23511. var imagePromise = handleImageData(handler, xref, res, image);
  23512. var smaskPromise;
  23513. var maskPromise;
  23514. var smask = image.dict.get('SMask');
  23515. var mask = image.dict.get('Mask');
  23516. if (smask) {
  23517. smaskPromise = handleImageData(handler, xref, res, smask);
  23518. maskPromise = Promise.resolve(null);
  23519. } else {
  23520. smaskPromise = Promise.resolve(null);
  23521. if (mask) {
  23522. if (isStream(mask)) {
  23523. maskPromise = handleImageData(handler, xref, res, mask);
  23524. } else if (isArray(mask)) {
  23525. maskPromise = Promise.resolve(mask);
  23526. } else {
  23527. warn('Unsupported mask format.');
  23528. maskPromise = Promise.resolve(null);
  23529. }
  23530. } else {
  23531. maskPromise = Promise.resolve(null);
  23532. }
  23533. }
  23534. return Promise.all([imagePromise, smaskPromise, maskPromise]).then(
  23535. function(results) {
  23536. var imageData = results[0];
  23537. var smaskData = results[1];
  23538. var maskData = results[2];
  23539. return new PDFImage(xref, res, imageData, inline, smaskData, maskData);
  23540. });
  23541. };
  23542. /**
  23543. * Resize an image using the nearest neighbor algorithm. Currently only
  23544. * supports one and three component images.
  23545. * @param {TypedArray} pixels The original image with one component.
  23546. * @param {Number} bpc Number of bits per component.
  23547. * @param {Number} components Number of color components, 1 or 3 is supported.
  23548. * @param {Number} w1 Original width.
  23549. * @param {Number} h1 Original height.
  23550. * @param {Number} w2 New width.
  23551. * @param {Number} h2 New height.
  23552. * @param {TypedArray} dest (Optional) The destination buffer.
  23553. * @param {Number} alpha01 (Optional) Size reserved for the alpha channel.
  23554. * @return {TypedArray} Resized image data.
  23555. */
  23556. PDFImage.resize = function PDFImage_resize(pixels, bpc, components,
  23557. w1, h1, w2, h2, dest, alpha01) {
  23558. if (components !== 1 && components !== 3) {
  23559. error('Unsupported component count for resizing.');
  23560. }
  23561. var length = w2 * h2 * components;
  23562. var temp = dest ? dest : (bpc <= 8 ? new Uint8Array(length) :
  23563. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  23564. var xRatio = w1 / w2;
  23565. var yRatio = h1 / h2;
  23566. var i, j, py, newIndex = 0, oldIndex;
  23567. var xScaled = new Uint16Array(w2);
  23568. var w1Scanline = w1 * components;
  23569. if (alpha01 !== 1) {
  23570. alpha01 = 0;
  23571. }
  23572. for (j = 0; j < w2; j++) {
  23573. xScaled[j] = Math.floor(j * xRatio) * components;
  23574. }
  23575. if (components === 1) {
  23576. for (i = 0; i < h2; i++) {
  23577. py = Math.floor(i * yRatio) * w1Scanline;
  23578. for (j = 0; j < w2; j++) {
  23579. oldIndex = py + xScaled[j];
  23580. temp[newIndex++] = pixels[oldIndex];
  23581. }
  23582. }
  23583. } else if (components === 3) {
  23584. for (i = 0; i < h2; i++) {
  23585. py = Math.floor(i * yRatio) * w1Scanline;
  23586. for (j = 0; j < w2; j++) {
  23587. oldIndex = py + xScaled[j];
  23588. temp[newIndex++] = pixels[oldIndex++];
  23589. temp[newIndex++] = pixels[oldIndex++];
  23590. temp[newIndex++] = pixels[oldIndex++];
  23591. newIndex += alpha01;
  23592. }
  23593. }
  23594. }
  23595. return temp;
  23596. };
  23597. PDFImage.createMask =
  23598. function PDFImage_createMask(imgArray, width, height,
  23599. imageIsFromDecodeStream, inverseDecode) {
  23600. // |imgArray| might not contain full data for every pixel of the mask, so
  23601. // we need to distinguish between |computedLength| and |actualLength|.
  23602. // In particular, if inverseDecode is true, then the array we return must
  23603. // have a length of |computedLength|.
  23604. var computedLength = ((width + 7) >> 3) * height;
  23605. var actualLength = imgArray.byteLength;
  23606. var haveFullData = computedLength == actualLength;
  23607. var data, i;
  23608. if (imageIsFromDecodeStream && (!inverseDecode || haveFullData)) {
  23609. // imgArray came from a DecodeStream and its data is in an appropriate
  23610. // form, so we can just transfer it.
  23611. data = imgArray;
  23612. } else if (!inverseDecode) {
  23613. data = new Uint8Array(actualLength);
  23614. data.set(imgArray);
  23615. } else {
  23616. data = new Uint8Array(computedLength);
  23617. data.set(imgArray);
  23618. for (i = actualLength; i < computedLength; i++) {
  23619. data[i] = 0xff;
  23620. }
  23621. }
  23622. // If necessary, invert the original mask data (but not any extra we might
  23623. // have added above). It's safe to modify the array -- whether it's the
  23624. // original or a copy, we're about to transfer it anyway, so nothing else
  23625. // in this thread can be relying on its contents.
  23626. if (inverseDecode) {
  23627. for (i = 0; i < actualLength; i++) {
  23628. data[i] = ~data[i];
  23629. }
  23630. }
  23631. return {data: data, width: width, height: height};
  23632. };
  23633. PDFImage.prototype = {
  23634. get drawWidth() {
  23635. return Math.max(this.width,
  23636. this.smask && this.smask.width || 0,
  23637. this.mask && this.mask.width || 0);
  23638. },
  23639. get drawHeight() {
  23640. return Math.max(this.height,
  23641. this.smask && this.smask.height || 0,
  23642. this.mask && this.mask.height || 0);
  23643. },
  23644. decodeBuffer: function PDFImage_decodeBuffer(buffer) {
  23645. var bpc = this.bpc;
  23646. var numComps = this.numComps;
  23647. var decodeAddends = this.decodeAddends;
  23648. var decodeCoefficients = this.decodeCoefficients;
  23649. var max = (1 << bpc) - 1;
  23650. var i, ii;
  23651. if (bpc === 1) {
  23652. // If the buffer needed decode that means it just needs to be inverted.
  23653. for (i = 0, ii = buffer.length; i < ii; i++) {
  23654. buffer[i] = +!(buffer[i]);
  23655. }
  23656. return;
  23657. }
  23658. var index = 0;
  23659. for (i = 0, ii = this.width * this.height; i < ii; i++) {
  23660. for (var j = 0; j < numComps; j++) {
  23661. buffer[index] = decodeAndClamp(buffer[index], decodeAddends[j],
  23662. decodeCoefficients[j], max);
  23663. index++;
  23664. }
  23665. }
  23666. },
  23667. getComponents: function PDFImage_getComponents(buffer) {
  23668. var bpc = this.bpc;
  23669. // This image doesn't require any extra work.
  23670. if (bpc === 8) {
  23671. return buffer;
  23672. }
  23673. var width = this.width;
  23674. var height = this.height;
  23675. var numComps = this.numComps;
  23676. var length = width * height * numComps;
  23677. var bufferPos = 0;
  23678. var output = (bpc <= 8 ? new Uint8Array(length) :
  23679. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  23680. var rowComps = width * numComps;
  23681. var max = (1 << bpc) - 1;
  23682. var i = 0, ii, buf;
  23683. if (bpc === 1) {
  23684. // Optimization for reading 1 bpc images.
  23685. var mask, loop1End, loop2End;
  23686. for (var j = 0; j < height; j++) {
  23687. loop1End = i + (rowComps & ~7);
  23688. loop2End = i + rowComps;
  23689. // unroll loop for all full bytes
  23690. while (i < loop1End) {
  23691. buf = buffer[bufferPos++];
  23692. output[i] = (buf >> 7) & 1;
  23693. output[i + 1] = (buf >> 6) & 1;
  23694. output[i + 2] = (buf >> 5) & 1;
  23695. output[i + 3] = (buf >> 4) & 1;
  23696. output[i + 4] = (buf >> 3) & 1;
  23697. output[i + 5] = (buf >> 2) & 1;
  23698. output[i + 6] = (buf >> 1) & 1;
  23699. output[i + 7] = buf & 1;
  23700. i += 8;
  23701. }
  23702. // handle remaing bits
  23703. if (i < loop2End) {
  23704. buf = buffer[bufferPos++];
  23705. mask = 128;
  23706. while (i < loop2End) {
  23707. output[i++] = +!!(buf & mask);
  23708. mask >>= 1;
  23709. }
  23710. }
  23711. }
  23712. } else {
  23713. // The general case that handles all other bpc values.
  23714. var bits = 0;
  23715. buf = 0;
  23716. for (i = 0, ii = length; i < ii; ++i) {
  23717. if (i % rowComps === 0) {
  23718. buf = 0;
  23719. bits = 0;
  23720. }
  23721. while (bits < bpc) {
  23722. buf = (buf << 8) | buffer[bufferPos++];
  23723. bits += 8;
  23724. }
  23725. var remainingBits = bits - bpc;
  23726. var value = buf >> remainingBits;
  23727. output[i] = (value < 0 ? 0 : (value > max ? max : value));
  23728. buf = buf & ((1 << remainingBits) - 1);
  23729. bits = remainingBits;
  23730. }
  23731. }
  23732. return output;
  23733. },
  23734. fillOpacity: function PDFImage_fillOpacity(rgbaBuf, width, height,
  23735. actualHeight, image) {
  23736. var smask = this.smask;
  23737. var mask = this.mask;
  23738. var alphaBuf, sw, sh, i, ii, j;
  23739. if (smask) {
  23740. sw = smask.width;
  23741. sh = smask.height;
  23742. alphaBuf = new Uint8Array(sw * sh);
  23743. smask.fillGrayBuffer(alphaBuf);
  23744. if (sw != width || sh != height) {
  23745. alphaBuf = PDFImage.resize(alphaBuf, smask.bpc, 1, sw, sh, width,
  23746. height);
  23747. }
  23748. } else if (mask) {
  23749. if (mask instanceof PDFImage) {
  23750. sw = mask.width;
  23751. sh = mask.height;
  23752. alphaBuf = new Uint8Array(sw * sh);
  23753. mask.numComps = 1;
  23754. mask.fillGrayBuffer(alphaBuf);
  23755. // Need to invert values in rgbaBuf
  23756. for (i = 0, ii = sw * sh; i < ii; ++i) {
  23757. alphaBuf[i] = 255 - alphaBuf[i];
  23758. }
  23759. if (sw != width || sh != height) {
  23760. alphaBuf = PDFImage.resize(alphaBuf, mask.bpc, 1, sw, sh, width,
  23761. height);
  23762. }
  23763. } else if (isArray(mask)) {
  23764. // Color key mask: if any of the compontents are outside the range
  23765. // then they should be painted.
  23766. alphaBuf = new Uint8Array(width * height);
  23767. var numComps = this.numComps;
  23768. for (i = 0, ii = width * height; i < ii; ++i) {
  23769. var opacity = 0;
  23770. var imageOffset = i * numComps;
  23771. for (j = 0; j < numComps; ++j) {
  23772. var color = image[imageOffset + j];
  23773. var maskOffset = j * 2;
  23774. if (color < mask[maskOffset] || color > mask[maskOffset + 1]) {
  23775. opacity = 255;
  23776. break;
  23777. }
  23778. }
  23779. alphaBuf[i] = opacity;
  23780. }
  23781. } else {
  23782. error('Unknown mask format.');
  23783. }
  23784. }
  23785. if (alphaBuf) {
  23786. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  23787. rgbaBuf[j] = alphaBuf[i];
  23788. }
  23789. } else {
  23790. // No mask.
  23791. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  23792. rgbaBuf[j] = 255;
  23793. }
  23794. }
  23795. },
  23796. undoPreblend: function PDFImage_undoPreblend(buffer, width, height) {
  23797. var matte = this.smask && this.smask.matte;
  23798. if (!matte) {
  23799. return;
  23800. }
  23801. var matteRgb = this.colorSpace.getRgb(matte, 0);
  23802. var matteR = matteRgb[0];
  23803. var matteG = matteRgb[1];
  23804. var matteB = matteRgb[2];
  23805. var length = width * height * 4;
  23806. var r, g, b;
  23807. for (var i = 0; i < length; i += 4) {
  23808. var alpha = buffer[i + 3];
  23809. if (alpha === 0) {
  23810. // according formula we have to get Infinity in all components
  23811. // making it white (typical paper color) should be okay
  23812. buffer[i] = 255;
  23813. buffer[i + 1] = 255;
  23814. buffer[i + 2] = 255;
  23815. continue;
  23816. }
  23817. var k = 255 / alpha;
  23818. r = (buffer[i] - matteR) * k + matteR;
  23819. g = (buffer[i + 1] - matteG) * k + matteG;
  23820. b = (buffer[i + 2] - matteB) * k + matteB;
  23821. buffer[i] = r <= 0 ? 0 : r >= 255 ? 255 : r | 0;
  23822. buffer[i + 1] = g <= 0 ? 0 : g >= 255 ? 255 : g | 0;
  23823. buffer[i + 2] = b <= 0 ? 0 : b >= 255 ? 255 : b | 0;
  23824. }
  23825. },
  23826. createImageData: function PDFImage_createImageData(forceRGBA) {
  23827. var drawWidth = this.drawWidth;
  23828. var drawHeight = this.drawHeight;
  23829. var imgData = { // other fields are filled in below
  23830. width: drawWidth,
  23831. height: drawHeight
  23832. };
  23833. var numComps = this.numComps;
  23834. var originalWidth = this.width;
  23835. var originalHeight = this.height;
  23836. var bpc = this.bpc;
  23837. // Rows start at byte boundary.
  23838. var rowBytes = (originalWidth * numComps * bpc + 7) >> 3;
  23839. var imgArray;
  23840. if (!forceRGBA) {
  23841. // If it is a 1-bit-per-pixel grayscale (i.e. black-and-white) image
  23842. // without any complications, we pass a same-sized copy to the main
  23843. // thread rather than expanding by 32x to RGBA form. This saves *lots*
  23844. // of memory for many scanned documents. It's also much faster.
  23845. //
  23846. // Similarly, if it is a 24-bit-per pixel RGB image without any
  23847. // complications, we avoid expanding by 1.333x to RGBA form.
  23848. var kind;
  23849. if (this.colorSpace.name === 'DeviceGray' && bpc === 1) {
  23850. kind = ImageKind.GRAYSCALE_1BPP;
  23851. } else if (this.colorSpace.name === 'DeviceRGB' && bpc === 8) {
  23852. kind = ImageKind.RGB_24BPP;
  23853. }
  23854. if (kind && !this.smask && !this.mask && !this.needsDecode &&
  23855. drawWidth === originalWidth && drawHeight === originalHeight) {
  23856. imgData.kind = kind;
  23857. imgArray = this.getImageBytes(originalHeight * rowBytes);
  23858. // If imgArray came from a DecodeStream, we're safe to transfer it
  23859. // (and thus neuter it) because it will constitute the entire
  23860. // DecodeStream's data. But if it came from a Stream, we need to
  23861. // copy it because it'll only be a portion of the Stream's data, and
  23862. // the rest will be read later on.
  23863. if (this.image instanceof DecodeStream) {
  23864. imgData.data = imgArray;
  23865. } else {
  23866. var newArray = new Uint8Array(imgArray.length);
  23867. newArray.set(imgArray);
  23868. imgData.data = newArray;
  23869. }
  23870. return imgData;
  23871. }
  23872. if (this.image instanceof JpegStream && !this.smask && !this.mask) {
  23873. imgData.kind = ImageKind.RGB_24BPP;
  23874. imgData.data = this.getImageBytes(originalHeight * rowBytes,
  23875. drawWidth, drawHeight, true);
  23876. return imgData;
  23877. }
  23878. }
  23879. imgArray = this.getImageBytes(originalHeight * rowBytes);
  23880. // imgArray can be incomplete (e.g. after CCITT fax encoding).
  23881. var actualHeight = 0 | (imgArray.length / rowBytes *
  23882. drawHeight / originalHeight);
  23883. var comps = this.getComponents(imgArray);
  23884. // If opacity data is present, use RGBA_32BPP form. Otherwise, use the
  23885. // more compact RGB_24BPP form if allowable.
  23886. var alpha01, maybeUndoPreblend;
  23887. if (!forceRGBA && !this.smask && !this.mask) {
  23888. imgData.kind = ImageKind.RGB_24BPP;
  23889. imgData.data = new Uint8Array(drawWidth * drawHeight * 3);
  23890. alpha01 = 0;
  23891. maybeUndoPreblend = false;
  23892. } else {
  23893. imgData.kind = ImageKind.RGBA_32BPP;
  23894. imgData.data = new Uint8Array(drawWidth * drawHeight * 4);
  23895. alpha01 = 1;
  23896. maybeUndoPreblend = true;
  23897. // Color key masking (opacity) must be performed before decoding.
  23898. this.fillOpacity(imgData.data, drawWidth, drawHeight, actualHeight,
  23899. comps);
  23900. }
  23901. if (this.needsDecode) {
  23902. this.decodeBuffer(comps);
  23903. }
  23904. this.colorSpace.fillRgb(imgData.data, originalWidth, originalHeight,
  23905. drawWidth, drawHeight, actualHeight, bpc, comps,
  23906. alpha01);
  23907. if (maybeUndoPreblend) {
  23908. this.undoPreblend(imgData.data, drawWidth, actualHeight);
  23909. }
  23910. return imgData;
  23911. },
  23912. fillGrayBuffer: function PDFImage_fillGrayBuffer(buffer) {
  23913. var numComps = this.numComps;
  23914. if (numComps != 1) {
  23915. error('Reading gray scale from a color image: ' + numComps);
  23916. }
  23917. var width = this.width;
  23918. var height = this.height;
  23919. var bpc = this.bpc;
  23920. // rows start at byte boundary
  23921. var rowBytes = (width * numComps * bpc + 7) >> 3;
  23922. var imgArray = this.getImageBytes(height * rowBytes);
  23923. var comps = this.getComponents(imgArray);
  23924. var i, length;
  23925. if (bpc === 1) {
  23926. // inline decoding (= inversion) for 1 bpc images
  23927. length = width * height;
  23928. if (this.needsDecode) {
  23929. // invert and scale to {0, 255}
  23930. for (i = 0; i < length; ++i) {
  23931. buffer[i] = (comps[i] - 1) & 255;
  23932. }
  23933. } else {
  23934. // scale to {0, 255}
  23935. for (i = 0; i < length; ++i) {
  23936. buffer[i] = (-comps[i]) & 255;
  23937. }
  23938. }
  23939. return;
  23940. }
  23941. if (this.needsDecode) {
  23942. this.decodeBuffer(comps);
  23943. }
  23944. length = width * height;
  23945. // we aren't using a colorspace so we need to scale the value
  23946. var scale = 255 / ((1 << bpc) - 1);
  23947. for (i = 0; i < length; ++i) {
  23948. buffer[i] = (scale * comps[i]) | 0;
  23949. }
  23950. },
  23951. getImageBytes: function PDFImage_getImageBytes(length,
  23952. drawWidth, drawHeight,
  23953. forceRGB) {
  23954. this.image.reset();
  23955. this.image.drawWidth = drawWidth || this.width;
  23956. this.image.drawHeight = drawHeight || this.height;
  23957. this.image.forceRGB = !!forceRGB;
  23958. return this.image.getBytes(length);
  23959. }
  23960. };
  23961. return PDFImage;
  23962. })();
  23963. // The Metrics object contains glyph widths (in glyph space units).
  23964. // As per PDF spec, for most fonts (Type 3 being an exception) a glyph
  23965. // space unit corresponds to 1/1000th of text space unit.
  23966. var Metrics = {
  23967. 'Courier': 600,
  23968. 'Courier-Bold': 600,
  23969. 'Courier-BoldOblique': 600,
  23970. 'Courier-Oblique': 600,
  23971. 'Helvetica' : {
  23972. 'space': 278,
  23973. 'exclam': 278,
  23974. 'quotedbl': 355,
  23975. 'numbersign': 556,
  23976. 'dollar': 556,
  23977. 'percent': 889,
  23978. 'ampersand': 667,
  23979. 'quoteright': 222,
  23980. 'parenleft': 333,
  23981. 'parenright': 333,
  23982. 'asterisk': 389,
  23983. 'plus': 584,
  23984. 'comma': 278,
  23985. 'hyphen': 333,
  23986. 'period': 278,
  23987. 'slash': 278,
  23988. 'zero': 556,
  23989. 'one': 556,
  23990. 'two': 556,
  23991. 'three': 556,
  23992. 'four': 556,
  23993. 'five': 556,
  23994. 'six': 556,
  23995. 'seven': 556,
  23996. 'eight': 556,
  23997. 'nine': 556,
  23998. 'colon': 278,
  23999. 'semicolon': 278,
  24000. 'less': 584,
  24001. 'equal': 584,
  24002. 'greater': 584,
  24003. 'question': 556,
  24004. 'at': 1015,
  24005. 'A': 667,
  24006. 'B': 667,
  24007. 'C': 722,
  24008. 'D': 722,
  24009. 'E': 667,
  24010. 'F': 611,
  24011. 'G': 778,
  24012. 'H': 722,
  24013. 'I': 278,
  24014. 'J': 500,
  24015. 'K': 667,
  24016. 'L': 556,
  24017. 'M': 833,
  24018. 'N': 722,
  24019. 'O': 778,
  24020. 'P': 667,
  24021. 'Q': 778,
  24022. 'R': 722,
  24023. 'S': 667,
  24024. 'T': 611,
  24025. 'U': 722,
  24026. 'V': 667,
  24027. 'W': 944,
  24028. 'X': 667,
  24029. 'Y': 667,
  24030. 'Z': 611,
  24031. 'bracketleft': 278,
  24032. 'backslash': 278,
  24033. 'bracketright': 278,
  24034. 'asciicircum': 469,
  24035. 'underscore': 556,
  24036. 'quoteleft': 222,
  24037. 'a': 556,
  24038. 'b': 556,
  24039. 'c': 500,
  24040. 'd': 556,
  24041. 'e': 556,
  24042. 'f': 278,
  24043. 'g': 556,
  24044. 'h': 556,
  24045. 'i': 222,
  24046. 'j': 222,
  24047. 'k': 500,
  24048. 'l': 222,
  24049. 'm': 833,
  24050. 'n': 556,
  24051. 'o': 556,
  24052. 'p': 556,
  24053. 'q': 556,
  24054. 'r': 333,
  24055. 's': 500,
  24056. 't': 278,
  24057. 'u': 556,
  24058. 'v': 500,
  24059. 'w': 722,
  24060. 'x': 500,
  24061. 'y': 500,
  24062. 'z': 500,
  24063. 'braceleft': 334,
  24064. 'bar': 260,
  24065. 'braceright': 334,
  24066. 'asciitilde': 584,
  24067. 'exclamdown': 333,
  24068. 'cent': 556,
  24069. 'sterling': 556,
  24070. 'fraction': 167,
  24071. 'yen': 556,
  24072. 'florin': 556,
  24073. 'section': 556,
  24074. 'currency': 556,
  24075. 'quotesingle': 191,
  24076. 'quotedblleft': 333,
  24077. 'guillemotleft': 556,
  24078. 'guilsinglleft': 333,
  24079. 'guilsinglright': 333,
  24080. 'fi': 500,
  24081. 'fl': 500,
  24082. 'endash': 556,
  24083. 'dagger': 556,
  24084. 'daggerdbl': 556,
  24085. 'periodcentered': 278,
  24086. 'paragraph': 537,
  24087. 'bullet': 350,
  24088. 'quotesinglbase': 222,
  24089. 'quotedblbase': 333,
  24090. 'quotedblright': 333,
  24091. 'guillemotright': 556,
  24092. 'ellipsis': 1000,
  24093. 'perthousand': 1000,
  24094. 'questiondown': 611,
  24095. 'grave': 333,
  24096. 'acute': 333,
  24097. 'circumflex': 333,
  24098. 'tilde': 333,
  24099. 'macron': 333,
  24100. 'breve': 333,
  24101. 'dotaccent': 333,
  24102. 'dieresis': 333,
  24103. 'ring': 333,
  24104. 'cedilla': 333,
  24105. 'hungarumlaut': 333,
  24106. 'ogonek': 333,
  24107. 'caron': 333,
  24108. 'emdash': 1000,
  24109. 'AE': 1000,
  24110. 'ordfeminine': 370,
  24111. 'Lslash': 556,
  24112. 'Oslash': 778,
  24113. 'OE': 1000,
  24114. 'ordmasculine': 365,
  24115. 'ae': 889,
  24116. 'dotlessi': 278,
  24117. 'lslash': 222,
  24118. 'oslash': 611,
  24119. 'oe': 944,
  24120. 'germandbls': 611,
  24121. 'Idieresis': 278,
  24122. 'eacute': 556,
  24123. 'abreve': 556,
  24124. 'uhungarumlaut': 556,
  24125. 'ecaron': 556,
  24126. 'Ydieresis': 667,
  24127. 'divide': 584,
  24128. 'Yacute': 667,
  24129. 'Acircumflex': 667,
  24130. 'aacute': 556,
  24131. 'Ucircumflex': 722,
  24132. 'yacute': 500,
  24133. 'scommaaccent': 500,
  24134. 'ecircumflex': 556,
  24135. 'Uring': 722,
  24136. 'Udieresis': 722,
  24137. 'aogonek': 556,
  24138. 'Uacute': 722,
  24139. 'uogonek': 556,
  24140. 'Edieresis': 667,
  24141. 'Dcroat': 722,
  24142. 'commaaccent': 250,
  24143. 'copyright': 737,
  24144. 'Emacron': 667,
  24145. 'ccaron': 500,
  24146. 'aring': 556,
  24147. 'Ncommaaccent': 722,
  24148. 'lacute': 222,
  24149. 'agrave': 556,
  24150. 'Tcommaaccent': 611,
  24151. 'Cacute': 722,
  24152. 'atilde': 556,
  24153. 'Edotaccent': 667,
  24154. 'scaron': 500,
  24155. 'scedilla': 500,
  24156. 'iacute': 278,
  24157. 'lozenge': 471,
  24158. 'Rcaron': 722,
  24159. 'Gcommaaccent': 778,
  24160. 'ucircumflex': 556,
  24161. 'acircumflex': 556,
  24162. 'Amacron': 667,
  24163. 'rcaron': 333,
  24164. 'ccedilla': 500,
  24165. 'Zdotaccent': 611,
  24166. 'Thorn': 667,
  24167. 'Omacron': 778,
  24168. 'Racute': 722,
  24169. 'Sacute': 667,
  24170. 'dcaron': 643,
  24171. 'Umacron': 722,
  24172. 'uring': 556,
  24173. 'threesuperior': 333,
  24174. 'Ograve': 778,
  24175. 'Agrave': 667,
  24176. 'Abreve': 667,
  24177. 'multiply': 584,
  24178. 'uacute': 556,
  24179. 'Tcaron': 611,
  24180. 'partialdiff': 476,
  24181. 'ydieresis': 500,
  24182. 'Nacute': 722,
  24183. 'icircumflex': 278,
  24184. 'Ecircumflex': 667,
  24185. 'adieresis': 556,
  24186. 'edieresis': 556,
  24187. 'cacute': 500,
  24188. 'nacute': 556,
  24189. 'umacron': 556,
  24190. 'Ncaron': 722,
  24191. 'Iacute': 278,
  24192. 'plusminus': 584,
  24193. 'brokenbar': 260,
  24194. 'registered': 737,
  24195. 'Gbreve': 778,
  24196. 'Idotaccent': 278,
  24197. 'summation': 600,
  24198. 'Egrave': 667,
  24199. 'racute': 333,
  24200. 'omacron': 556,
  24201. 'Zacute': 611,
  24202. 'Zcaron': 611,
  24203. 'greaterequal': 549,
  24204. 'Eth': 722,
  24205. 'Ccedilla': 722,
  24206. 'lcommaaccent': 222,
  24207. 'tcaron': 317,
  24208. 'eogonek': 556,
  24209. 'Uogonek': 722,
  24210. 'Aacute': 667,
  24211. 'Adieresis': 667,
  24212. 'egrave': 556,
  24213. 'zacute': 500,
  24214. 'iogonek': 222,
  24215. 'Oacute': 778,
  24216. 'oacute': 556,
  24217. 'amacron': 556,
  24218. 'sacute': 500,
  24219. 'idieresis': 278,
  24220. 'Ocircumflex': 778,
  24221. 'Ugrave': 722,
  24222. 'Delta': 612,
  24223. 'thorn': 556,
  24224. 'twosuperior': 333,
  24225. 'Odieresis': 778,
  24226. 'mu': 556,
  24227. 'igrave': 278,
  24228. 'ohungarumlaut': 556,
  24229. 'Eogonek': 667,
  24230. 'dcroat': 556,
  24231. 'threequarters': 834,
  24232. 'Scedilla': 667,
  24233. 'lcaron': 299,
  24234. 'Kcommaaccent': 667,
  24235. 'Lacute': 556,
  24236. 'trademark': 1000,
  24237. 'edotaccent': 556,
  24238. 'Igrave': 278,
  24239. 'Imacron': 278,
  24240. 'Lcaron': 556,
  24241. 'onehalf': 834,
  24242. 'lessequal': 549,
  24243. 'ocircumflex': 556,
  24244. 'ntilde': 556,
  24245. 'Uhungarumlaut': 722,
  24246. 'Eacute': 667,
  24247. 'emacron': 556,
  24248. 'gbreve': 556,
  24249. 'onequarter': 834,
  24250. 'Scaron': 667,
  24251. 'Scommaaccent': 667,
  24252. 'Ohungarumlaut': 778,
  24253. 'degree': 400,
  24254. 'ograve': 556,
  24255. 'Ccaron': 722,
  24256. 'ugrave': 556,
  24257. 'radical': 453,
  24258. 'Dcaron': 722,
  24259. 'rcommaaccent': 333,
  24260. 'Ntilde': 722,
  24261. 'otilde': 556,
  24262. 'Rcommaaccent': 722,
  24263. 'Lcommaaccent': 556,
  24264. 'Atilde': 667,
  24265. 'Aogonek': 667,
  24266. 'Aring': 667,
  24267. 'Otilde': 778,
  24268. 'zdotaccent': 500,
  24269. 'Ecaron': 667,
  24270. 'Iogonek': 278,
  24271. 'kcommaaccent': 500,
  24272. 'minus': 584,
  24273. 'Icircumflex': 278,
  24274. 'ncaron': 556,
  24275. 'tcommaaccent': 278,
  24276. 'logicalnot': 584,
  24277. 'odieresis': 556,
  24278. 'udieresis': 556,
  24279. 'notequal': 549,
  24280. 'gcommaaccent': 556,
  24281. 'eth': 556,
  24282. 'zcaron': 500,
  24283. 'ncommaaccent': 556,
  24284. 'onesuperior': 333,
  24285. 'imacron': 278,
  24286. 'Euro': 556
  24287. },
  24288. 'Helvetica-Bold': {
  24289. 'space': 278,
  24290. 'exclam': 333,
  24291. 'quotedbl': 474,
  24292. 'numbersign': 556,
  24293. 'dollar': 556,
  24294. 'percent': 889,
  24295. 'ampersand': 722,
  24296. 'quoteright': 278,
  24297. 'parenleft': 333,
  24298. 'parenright': 333,
  24299. 'asterisk': 389,
  24300. 'plus': 584,
  24301. 'comma': 278,
  24302. 'hyphen': 333,
  24303. 'period': 278,
  24304. 'slash': 278,
  24305. 'zero': 556,
  24306. 'one': 556,
  24307. 'two': 556,
  24308. 'three': 556,
  24309. 'four': 556,
  24310. 'five': 556,
  24311. 'six': 556,
  24312. 'seven': 556,
  24313. 'eight': 556,
  24314. 'nine': 556,
  24315. 'colon': 333,
  24316. 'semicolon': 333,
  24317. 'less': 584,
  24318. 'equal': 584,
  24319. 'greater': 584,
  24320. 'question': 611,
  24321. 'at': 975,
  24322. 'A': 722,
  24323. 'B': 722,
  24324. 'C': 722,
  24325. 'D': 722,
  24326. 'E': 667,
  24327. 'F': 611,
  24328. 'G': 778,
  24329. 'H': 722,
  24330. 'I': 278,
  24331. 'J': 556,
  24332. 'K': 722,
  24333. 'L': 611,
  24334. 'M': 833,
  24335. 'N': 722,
  24336. 'O': 778,
  24337. 'P': 667,
  24338. 'Q': 778,
  24339. 'R': 722,
  24340. 'S': 667,
  24341. 'T': 611,
  24342. 'U': 722,
  24343. 'V': 667,
  24344. 'W': 944,
  24345. 'X': 667,
  24346. 'Y': 667,
  24347. 'Z': 611,
  24348. 'bracketleft': 333,
  24349. 'backslash': 278,
  24350. 'bracketright': 333,
  24351. 'asciicircum': 584,
  24352. 'underscore': 556,
  24353. 'quoteleft': 278,
  24354. 'a': 556,
  24355. 'b': 611,
  24356. 'c': 556,
  24357. 'd': 611,
  24358. 'e': 556,
  24359. 'f': 333,
  24360. 'g': 611,
  24361. 'h': 611,
  24362. 'i': 278,
  24363. 'j': 278,
  24364. 'k': 556,
  24365. 'l': 278,
  24366. 'm': 889,
  24367. 'n': 611,
  24368. 'o': 611,
  24369. 'p': 611,
  24370. 'q': 611,
  24371. 'r': 389,
  24372. 's': 556,
  24373. 't': 333,
  24374. 'u': 611,
  24375. 'v': 556,
  24376. 'w': 778,
  24377. 'x': 556,
  24378. 'y': 556,
  24379. 'z': 500,
  24380. 'braceleft': 389,
  24381. 'bar': 280,
  24382. 'braceright': 389,
  24383. 'asciitilde': 584,
  24384. 'exclamdown': 333,
  24385. 'cent': 556,
  24386. 'sterling': 556,
  24387. 'fraction': 167,
  24388. 'yen': 556,
  24389. 'florin': 556,
  24390. 'section': 556,
  24391. 'currency': 556,
  24392. 'quotesingle': 238,
  24393. 'quotedblleft': 500,
  24394. 'guillemotleft': 556,
  24395. 'guilsinglleft': 333,
  24396. 'guilsinglright': 333,
  24397. 'fi': 611,
  24398. 'fl': 611,
  24399. 'endash': 556,
  24400. 'dagger': 556,
  24401. 'daggerdbl': 556,
  24402. 'periodcentered': 278,
  24403. 'paragraph': 556,
  24404. 'bullet': 350,
  24405. 'quotesinglbase': 278,
  24406. 'quotedblbase': 500,
  24407. 'quotedblright': 500,
  24408. 'guillemotright': 556,
  24409. 'ellipsis': 1000,
  24410. 'perthousand': 1000,
  24411. 'questiondown': 611,
  24412. 'grave': 333,
  24413. 'acute': 333,
  24414. 'circumflex': 333,
  24415. 'tilde': 333,
  24416. 'macron': 333,
  24417. 'breve': 333,
  24418. 'dotaccent': 333,
  24419. 'dieresis': 333,
  24420. 'ring': 333,
  24421. 'cedilla': 333,
  24422. 'hungarumlaut': 333,
  24423. 'ogonek': 333,
  24424. 'caron': 333,
  24425. 'emdash': 1000,
  24426. 'AE': 1000,
  24427. 'ordfeminine': 370,
  24428. 'Lslash': 611,
  24429. 'Oslash': 778,
  24430. 'OE': 1000,
  24431. 'ordmasculine': 365,
  24432. 'ae': 889,
  24433. 'dotlessi': 278,
  24434. 'lslash': 278,
  24435. 'oslash': 611,
  24436. 'oe': 944,
  24437. 'germandbls': 611,
  24438. 'Idieresis': 278,
  24439. 'eacute': 556,
  24440. 'abreve': 556,
  24441. 'uhungarumlaut': 611,
  24442. 'ecaron': 556,
  24443. 'Ydieresis': 667,
  24444. 'divide': 584,
  24445. 'Yacute': 667,
  24446. 'Acircumflex': 722,
  24447. 'aacute': 556,
  24448. 'Ucircumflex': 722,
  24449. 'yacute': 556,
  24450. 'scommaaccent': 556,
  24451. 'ecircumflex': 556,
  24452. 'Uring': 722,
  24453. 'Udieresis': 722,
  24454. 'aogonek': 556,
  24455. 'Uacute': 722,
  24456. 'uogonek': 611,
  24457. 'Edieresis': 667,
  24458. 'Dcroat': 722,
  24459. 'commaaccent': 250,
  24460. 'copyright': 737,
  24461. 'Emacron': 667,
  24462. 'ccaron': 556,
  24463. 'aring': 556,
  24464. 'Ncommaaccent': 722,
  24465. 'lacute': 278,
  24466. 'agrave': 556,
  24467. 'Tcommaaccent': 611,
  24468. 'Cacute': 722,
  24469. 'atilde': 556,
  24470. 'Edotaccent': 667,
  24471. 'scaron': 556,
  24472. 'scedilla': 556,
  24473. 'iacute': 278,
  24474. 'lozenge': 494,
  24475. 'Rcaron': 722,
  24476. 'Gcommaaccent': 778,
  24477. 'ucircumflex': 611,
  24478. 'acircumflex': 556,
  24479. 'Amacron': 722,
  24480. 'rcaron': 389,
  24481. 'ccedilla': 556,
  24482. 'Zdotaccent': 611,
  24483. 'Thorn': 667,
  24484. 'Omacron': 778,
  24485. 'Racute': 722,
  24486. 'Sacute': 667,
  24487. 'dcaron': 743,
  24488. 'Umacron': 722,
  24489. 'uring': 611,
  24490. 'threesuperior': 333,
  24491. 'Ograve': 778,
  24492. 'Agrave': 722,
  24493. 'Abreve': 722,
  24494. 'multiply': 584,
  24495. 'uacute': 611,
  24496. 'Tcaron': 611,
  24497. 'partialdiff': 494,
  24498. 'ydieresis': 556,
  24499. 'Nacute': 722,
  24500. 'icircumflex': 278,
  24501. 'Ecircumflex': 667,
  24502. 'adieresis': 556,
  24503. 'edieresis': 556,
  24504. 'cacute': 556,
  24505. 'nacute': 611,
  24506. 'umacron': 611,
  24507. 'Ncaron': 722,
  24508. 'Iacute': 278,
  24509. 'plusminus': 584,
  24510. 'brokenbar': 280,
  24511. 'registered': 737,
  24512. 'Gbreve': 778,
  24513. 'Idotaccent': 278,
  24514. 'summation': 600,
  24515. 'Egrave': 667,
  24516. 'racute': 389,
  24517. 'omacron': 611,
  24518. 'Zacute': 611,
  24519. 'Zcaron': 611,
  24520. 'greaterequal': 549,
  24521. 'Eth': 722,
  24522. 'Ccedilla': 722,
  24523. 'lcommaaccent': 278,
  24524. 'tcaron': 389,
  24525. 'eogonek': 556,
  24526. 'Uogonek': 722,
  24527. 'Aacute': 722,
  24528. 'Adieresis': 722,
  24529. 'egrave': 556,
  24530. 'zacute': 500,
  24531. 'iogonek': 278,
  24532. 'Oacute': 778,
  24533. 'oacute': 611,
  24534. 'amacron': 556,
  24535. 'sacute': 556,
  24536. 'idieresis': 278,
  24537. 'Ocircumflex': 778,
  24538. 'Ugrave': 722,
  24539. 'Delta': 612,
  24540. 'thorn': 611,
  24541. 'twosuperior': 333,
  24542. 'Odieresis': 778,
  24543. 'mu': 611,
  24544. 'igrave': 278,
  24545. 'ohungarumlaut': 611,
  24546. 'Eogonek': 667,
  24547. 'dcroat': 611,
  24548. 'threequarters': 834,
  24549. 'Scedilla': 667,
  24550. 'lcaron': 400,
  24551. 'Kcommaaccent': 722,
  24552. 'Lacute': 611,
  24553. 'trademark': 1000,
  24554. 'edotaccent': 556,
  24555. 'Igrave': 278,
  24556. 'Imacron': 278,
  24557. 'Lcaron': 611,
  24558. 'onehalf': 834,
  24559. 'lessequal': 549,
  24560. 'ocircumflex': 611,
  24561. 'ntilde': 611,
  24562. 'Uhungarumlaut': 722,
  24563. 'Eacute': 667,
  24564. 'emacron': 556,
  24565. 'gbreve': 611,
  24566. 'onequarter': 834,
  24567. 'Scaron': 667,
  24568. 'Scommaaccent': 667,
  24569. 'Ohungarumlaut': 778,
  24570. 'degree': 400,
  24571. 'ograve': 611,
  24572. 'Ccaron': 722,
  24573. 'ugrave': 611,
  24574. 'radical': 549,
  24575. 'Dcaron': 722,
  24576. 'rcommaaccent': 389,
  24577. 'Ntilde': 722,
  24578. 'otilde': 611,
  24579. 'Rcommaaccent': 722,
  24580. 'Lcommaaccent': 611,
  24581. 'Atilde': 722,
  24582. 'Aogonek': 722,
  24583. 'Aring': 722,
  24584. 'Otilde': 778,
  24585. 'zdotaccent': 500,
  24586. 'Ecaron': 667,
  24587. 'Iogonek': 278,
  24588. 'kcommaaccent': 556,
  24589. 'minus': 584,
  24590. 'Icircumflex': 278,
  24591. 'ncaron': 611,
  24592. 'tcommaaccent': 333,
  24593. 'logicalnot': 584,
  24594. 'odieresis': 611,
  24595. 'udieresis': 611,
  24596. 'notequal': 549,
  24597. 'gcommaaccent': 611,
  24598. 'eth': 611,
  24599. 'zcaron': 500,
  24600. 'ncommaaccent': 611,
  24601. 'onesuperior': 333,
  24602. 'imacron': 278,
  24603. 'Euro': 556
  24604. },
  24605. 'Helvetica-BoldOblique': {
  24606. 'space': 278,
  24607. 'exclam': 333,
  24608. 'quotedbl': 474,
  24609. 'numbersign': 556,
  24610. 'dollar': 556,
  24611. 'percent': 889,
  24612. 'ampersand': 722,
  24613. 'quoteright': 278,
  24614. 'parenleft': 333,
  24615. 'parenright': 333,
  24616. 'asterisk': 389,
  24617. 'plus': 584,
  24618. 'comma': 278,
  24619. 'hyphen': 333,
  24620. 'period': 278,
  24621. 'slash': 278,
  24622. 'zero': 556,
  24623. 'one': 556,
  24624. 'two': 556,
  24625. 'three': 556,
  24626. 'four': 556,
  24627. 'five': 556,
  24628. 'six': 556,
  24629. 'seven': 556,
  24630. 'eight': 556,
  24631. 'nine': 556,
  24632. 'colon': 333,
  24633. 'semicolon': 333,
  24634. 'less': 584,
  24635. 'equal': 584,
  24636. 'greater': 584,
  24637. 'question': 611,
  24638. 'at': 975,
  24639. 'A': 722,
  24640. 'B': 722,
  24641. 'C': 722,
  24642. 'D': 722,
  24643. 'E': 667,
  24644. 'F': 611,
  24645. 'G': 778,
  24646. 'H': 722,
  24647. 'I': 278,
  24648. 'J': 556,
  24649. 'K': 722,
  24650. 'L': 611,
  24651. 'M': 833,
  24652. 'N': 722,
  24653. 'O': 778,
  24654. 'P': 667,
  24655. 'Q': 778,
  24656. 'R': 722,
  24657. 'S': 667,
  24658. 'T': 611,
  24659. 'U': 722,
  24660. 'V': 667,
  24661. 'W': 944,
  24662. 'X': 667,
  24663. 'Y': 667,
  24664. 'Z': 611,
  24665. 'bracketleft': 333,
  24666. 'backslash': 278,
  24667. 'bracketright': 333,
  24668. 'asciicircum': 584,
  24669. 'underscore': 556,
  24670. 'quoteleft': 278,
  24671. 'a': 556,
  24672. 'b': 611,
  24673. 'c': 556,
  24674. 'd': 611,
  24675. 'e': 556,
  24676. 'f': 333,
  24677. 'g': 611,
  24678. 'h': 611,
  24679. 'i': 278,
  24680. 'j': 278,
  24681. 'k': 556,
  24682. 'l': 278,
  24683. 'm': 889,
  24684. 'n': 611,
  24685. 'o': 611,
  24686. 'p': 611,
  24687. 'q': 611,
  24688. 'r': 389,
  24689. 's': 556,
  24690. 't': 333,
  24691. 'u': 611,
  24692. 'v': 556,
  24693. 'w': 778,
  24694. 'x': 556,
  24695. 'y': 556,
  24696. 'z': 500,
  24697. 'braceleft': 389,
  24698. 'bar': 280,
  24699. 'braceright': 389,
  24700. 'asciitilde': 584,
  24701. 'exclamdown': 333,
  24702. 'cent': 556,
  24703. 'sterling': 556,
  24704. 'fraction': 167,
  24705. 'yen': 556,
  24706. 'florin': 556,
  24707. 'section': 556,
  24708. 'currency': 556,
  24709. 'quotesingle': 238,
  24710. 'quotedblleft': 500,
  24711. 'guillemotleft': 556,
  24712. 'guilsinglleft': 333,
  24713. 'guilsinglright': 333,
  24714. 'fi': 611,
  24715. 'fl': 611,
  24716. 'endash': 556,
  24717. 'dagger': 556,
  24718. 'daggerdbl': 556,
  24719. 'periodcentered': 278,
  24720. 'paragraph': 556,
  24721. 'bullet': 350,
  24722. 'quotesinglbase': 278,
  24723. 'quotedblbase': 500,
  24724. 'quotedblright': 500,
  24725. 'guillemotright': 556,
  24726. 'ellipsis': 1000,
  24727. 'perthousand': 1000,
  24728. 'questiondown': 611,
  24729. 'grave': 333,
  24730. 'acute': 333,
  24731. 'circumflex': 333,
  24732. 'tilde': 333,
  24733. 'macron': 333,
  24734. 'breve': 333,
  24735. 'dotaccent': 333,
  24736. 'dieresis': 333,
  24737. 'ring': 333,
  24738. 'cedilla': 333,
  24739. 'hungarumlaut': 333,
  24740. 'ogonek': 333,
  24741. 'caron': 333,
  24742. 'emdash': 1000,
  24743. 'AE': 1000,
  24744. 'ordfeminine': 370,
  24745. 'Lslash': 611,
  24746. 'Oslash': 778,
  24747. 'OE': 1000,
  24748. 'ordmasculine': 365,
  24749. 'ae': 889,
  24750. 'dotlessi': 278,
  24751. 'lslash': 278,
  24752. 'oslash': 611,
  24753. 'oe': 944,
  24754. 'germandbls': 611,
  24755. 'Idieresis': 278,
  24756. 'eacute': 556,
  24757. 'abreve': 556,
  24758. 'uhungarumlaut': 611,
  24759. 'ecaron': 556,
  24760. 'Ydieresis': 667,
  24761. 'divide': 584,
  24762. 'Yacute': 667,
  24763. 'Acircumflex': 722,
  24764. 'aacute': 556,
  24765. 'Ucircumflex': 722,
  24766. 'yacute': 556,
  24767. 'scommaaccent': 556,
  24768. 'ecircumflex': 556,
  24769. 'Uring': 722,
  24770. 'Udieresis': 722,
  24771. 'aogonek': 556,
  24772. 'Uacute': 722,
  24773. 'uogonek': 611,
  24774. 'Edieresis': 667,
  24775. 'Dcroat': 722,
  24776. 'commaaccent': 250,
  24777. 'copyright': 737,
  24778. 'Emacron': 667,
  24779. 'ccaron': 556,
  24780. 'aring': 556,
  24781. 'Ncommaaccent': 722,
  24782. 'lacute': 278,
  24783. 'agrave': 556,
  24784. 'Tcommaaccent': 611,
  24785. 'Cacute': 722,
  24786. 'atilde': 556,
  24787. 'Edotaccent': 667,
  24788. 'scaron': 556,
  24789. 'scedilla': 556,
  24790. 'iacute': 278,
  24791. 'lozenge': 494,
  24792. 'Rcaron': 722,
  24793. 'Gcommaaccent': 778,
  24794. 'ucircumflex': 611,
  24795. 'acircumflex': 556,
  24796. 'Amacron': 722,
  24797. 'rcaron': 389,
  24798. 'ccedilla': 556,
  24799. 'Zdotaccent': 611,
  24800. 'Thorn': 667,
  24801. 'Omacron': 778,
  24802. 'Racute': 722,
  24803. 'Sacute': 667,
  24804. 'dcaron': 743,
  24805. 'Umacron': 722,
  24806. 'uring': 611,
  24807. 'threesuperior': 333,
  24808. 'Ograve': 778,
  24809. 'Agrave': 722,
  24810. 'Abreve': 722,
  24811. 'multiply': 584,
  24812. 'uacute': 611,
  24813. 'Tcaron': 611,
  24814. 'partialdiff': 494,
  24815. 'ydieresis': 556,
  24816. 'Nacute': 722,
  24817. 'icircumflex': 278,
  24818. 'Ecircumflex': 667,
  24819. 'adieresis': 556,
  24820. 'edieresis': 556,
  24821. 'cacute': 556,
  24822. 'nacute': 611,
  24823. 'umacron': 611,
  24824. 'Ncaron': 722,
  24825. 'Iacute': 278,
  24826. 'plusminus': 584,
  24827. 'brokenbar': 280,
  24828. 'registered': 737,
  24829. 'Gbreve': 778,
  24830. 'Idotaccent': 278,
  24831. 'summation': 600,
  24832. 'Egrave': 667,
  24833. 'racute': 389,
  24834. 'omacron': 611,
  24835. 'Zacute': 611,
  24836. 'Zcaron': 611,
  24837. 'greaterequal': 549,
  24838. 'Eth': 722,
  24839. 'Ccedilla': 722,
  24840. 'lcommaaccent': 278,
  24841. 'tcaron': 389,
  24842. 'eogonek': 556,
  24843. 'Uogonek': 722,
  24844. 'Aacute': 722,
  24845. 'Adieresis': 722,
  24846. 'egrave': 556,
  24847. 'zacute': 500,
  24848. 'iogonek': 278,
  24849. 'Oacute': 778,
  24850. 'oacute': 611,
  24851. 'amacron': 556,
  24852. 'sacute': 556,
  24853. 'idieresis': 278,
  24854. 'Ocircumflex': 778,
  24855. 'Ugrave': 722,
  24856. 'Delta': 612,
  24857. 'thorn': 611,
  24858. 'twosuperior': 333,
  24859. 'Odieresis': 778,
  24860. 'mu': 611,
  24861. 'igrave': 278,
  24862. 'ohungarumlaut': 611,
  24863. 'Eogonek': 667,
  24864. 'dcroat': 611,
  24865. 'threequarters': 834,
  24866. 'Scedilla': 667,
  24867. 'lcaron': 400,
  24868. 'Kcommaaccent': 722,
  24869. 'Lacute': 611,
  24870. 'trademark': 1000,
  24871. 'edotaccent': 556,
  24872. 'Igrave': 278,
  24873. 'Imacron': 278,
  24874. 'Lcaron': 611,
  24875. 'onehalf': 834,
  24876. 'lessequal': 549,
  24877. 'ocircumflex': 611,
  24878. 'ntilde': 611,
  24879. 'Uhungarumlaut': 722,
  24880. 'Eacute': 667,
  24881. 'emacron': 556,
  24882. 'gbreve': 611,
  24883. 'onequarter': 834,
  24884. 'Scaron': 667,
  24885. 'Scommaaccent': 667,
  24886. 'Ohungarumlaut': 778,
  24887. 'degree': 400,
  24888. 'ograve': 611,
  24889. 'Ccaron': 722,
  24890. 'ugrave': 611,
  24891. 'radical': 549,
  24892. 'Dcaron': 722,
  24893. 'rcommaaccent': 389,
  24894. 'Ntilde': 722,
  24895. 'otilde': 611,
  24896. 'Rcommaaccent': 722,
  24897. 'Lcommaaccent': 611,
  24898. 'Atilde': 722,
  24899. 'Aogonek': 722,
  24900. 'Aring': 722,
  24901. 'Otilde': 778,
  24902. 'zdotaccent': 500,
  24903. 'Ecaron': 667,
  24904. 'Iogonek': 278,
  24905. 'kcommaaccent': 556,
  24906. 'minus': 584,
  24907. 'Icircumflex': 278,
  24908. 'ncaron': 611,
  24909. 'tcommaaccent': 333,
  24910. 'logicalnot': 584,
  24911. 'odieresis': 611,
  24912. 'udieresis': 611,
  24913. 'notequal': 549,
  24914. 'gcommaaccent': 611,
  24915. 'eth': 611,
  24916. 'zcaron': 500,
  24917. 'ncommaaccent': 611,
  24918. 'onesuperior': 333,
  24919. 'imacron': 278,
  24920. 'Euro': 556
  24921. },
  24922. 'Helvetica-Oblique' : {
  24923. 'space': 278,
  24924. 'exclam': 278,
  24925. 'quotedbl': 355,
  24926. 'numbersign': 556,
  24927. 'dollar': 556,
  24928. 'percent': 889,
  24929. 'ampersand': 667,
  24930. 'quoteright': 222,
  24931. 'parenleft': 333,
  24932. 'parenright': 333,
  24933. 'asterisk': 389,
  24934. 'plus': 584,
  24935. 'comma': 278,
  24936. 'hyphen': 333,
  24937. 'period': 278,
  24938. 'slash': 278,
  24939. 'zero': 556,
  24940. 'one': 556,
  24941. 'two': 556,
  24942. 'three': 556,
  24943. 'four': 556,
  24944. 'five': 556,
  24945. 'six': 556,
  24946. 'seven': 556,
  24947. 'eight': 556,
  24948. 'nine': 556,
  24949. 'colon': 278,
  24950. 'semicolon': 278,
  24951. 'less': 584,
  24952. 'equal': 584,
  24953. 'greater': 584,
  24954. 'question': 556,
  24955. 'at': 1015,
  24956. 'A': 667,
  24957. 'B': 667,
  24958. 'C': 722,
  24959. 'D': 722,
  24960. 'E': 667,
  24961. 'F': 611,
  24962. 'G': 778,
  24963. 'H': 722,
  24964. 'I': 278,
  24965. 'J': 500,
  24966. 'K': 667,
  24967. 'L': 556,
  24968. 'M': 833,
  24969. 'N': 722,
  24970. 'O': 778,
  24971. 'P': 667,
  24972. 'Q': 778,
  24973. 'R': 722,
  24974. 'S': 667,
  24975. 'T': 611,
  24976. 'U': 722,
  24977. 'V': 667,
  24978. 'W': 944,
  24979. 'X': 667,
  24980. 'Y': 667,
  24981. 'Z': 611,
  24982. 'bracketleft': 278,
  24983. 'backslash': 278,
  24984. 'bracketright': 278,
  24985. 'asciicircum': 469,
  24986. 'underscore': 556,
  24987. 'quoteleft': 222,
  24988. 'a': 556,
  24989. 'b': 556,
  24990. 'c': 500,
  24991. 'd': 556,
  24992. 'e': 556,
  24993. 'f': 278,
  24994. 'g': 556,
  24995. 'h': 556,
  24996. 'i': 222,
  24997. 'j': 222,
  24998. 'k': 500,
  24999. 'l': 222,
  25000. 'm': 833,
  25001. 'n': 556,
  25002. 'o': 556,
  25003. 'p': 556,
  25004. 'q': 556,
  25005. 'r': 333,
  25006. 's': 500,
  25007. 't': 278,
  25008. 'u': 556,
  25009. 'v': 500,
  25010. 'w': 722,
  25011. 'x': 500,
  25012. 'y': 500,
  25013. 'z': 500,
  25014. 'braceleft': 334,
  25015. 'bar': 260,
  25016. 'braceright': 334,
  25017. 'asciitilde': 584,
  25018. 'exclamdown': 333,
  25019. 'cent': 556,
  25020. 'sterling': 556,
  25021. 'fraction': 167,
  25022. 'yen': 556,
  25023. 'florin': 556,
  25024. 'section': 556,
  25025. 'currency': 556,
  25026. 'quotesingle': 191,
  25027. 'quotedblleft': 333,
  25028. 'guillemotleft': 556,
  25029. 'guilsinglleft': 333,
  25030. 'guilsinglright': 333,
  25031. 'fi': 500,
  25032. 'fl': 500,
  25033. 'endash': 556,
  25034. 'dagger': 556,
  25035. 'daggerdbl': 556,
  25036. 'periodcentered': 278,
  25037. 'paragraph': 537,
  25038. 'bullet': 350,
  25039. 'quotesinglbase': 222,
  25040. 'quotedblbase': 333,
  25041. 'quotedblright': 333,
  25042. 'guillemotright': 556,
  25043. 'ellipsis': 1000,
  25044. 'perthousand': 1000,
  25045. 'questiondown': 611,
  25046. 'grave': 333,
  25047. 'acute': 333,
  25048. 'circumflex': 333,
  25049. 'tilde': 333,
  25050. 'macron': 333,
  25051. 'breve': 333,
  25052. 'dotaccent': 333,
  25053. 'dieresis': 333,
  25054. 'ring': 333,
  25055. 'cedilla': 333,
  25056. 'hungarumlaut': 333,
  25057. 'ogonek': 333,
  25058. 'caron': 333,
  25059. 'emdash': 1000,
  25060. 'AE': 1000,
  25061. 'ordfeminine': 370,
  25062. 'Lslash': 556,
  25063. 'Oslash': 778,
  25064. 'OE': 1000,
  25065. 'ordmasculine': 365,
  25066. 'ae': 889,
  25067. 'dotlessi': 278,
  25068. 'lslash': 222,
  25069. 'oslash': 611,
  25070. 'oe': 944,
  25071. 'germandbls': 611,
  25072. 'Idieresis': 278,
  25073. 'eacute': 556,
  25074. 'abreve': 556,
  25075. 'uhungarumlaut': 556,
  25076. 'ecaron': 556,
  25077. 'Ydieresis': 667,
  25078. 'divide': 584,
  25079. 'Yacute': 667,
  25080. 'Acircumflex': 667,
  25081. 'aacute': 556,
  25082. 'Ucircumflex': 722,
  25083. 'yacute': 500,
  25084. 'scommaaccent': 500,
  25085. 'ecircumflex': 556,
  25086. 'Uring': 722,
  25087. 'Udieresis': 722,
  25088. 'aogonek': 556,
  25089. 'Uacute': 722,
  25090. 'uogonek': 556,
  25091. 'Edieresis': 667,
  25092. 'Dcroat': 722,
  25093. 'commaaccent': 250,
  25094. 'copyright': 737,
  25095. 'Emacron': 667,
  25096. 'ccaron': 500,
  25097. 'aring': 556,
  25098. 'Ncommaaccent': 722,
  25099. 'lacute': 222,
  25100. 'agrave': 556,
  25101. 'Tcommaaccent': 611,
  25102. 'Cacute': 722,
  25103. 'atilde': 556,
  25104. 'Edotaccent': 667,
  25105. 'scaron': 500,
  25106. 'scedilla': 500,
  25107. 'iacute': 278,
  25108. 'lozenge': 471,
  25109. 'Rcaron': 722,
  25110. 'Gcommaaccent': 778,
  25111. 'ucircumflex': 556,
  25112. 'acircumflex': 556,
  25113. 'Amacron': 667,
  25114. 'rcaron': 333,
  25115. 'ccedilla': 500,
  25116. 'Zdotaccent': 611,
  25117. 'Thorn': 667,
  25118. 'Omacron': 778,
  25119. 'Racute': 722,
  25120. 'Sacute': 667,
  25121. 'dcaron': 643,
  25122. 'Umacron': 722,
  25123. 'uring': 556,
  25124. 'threesuperior': 333,
  25125. 'Ograve': 778,
  25126. 'Agrave': 667,
  25127. 'Abreve': 667,
  25128. 'multiply': 584,
  25129. 'uacute': 556,
  25130. 'Tcaron': 611,
  25131. 'partialdiff': 476,
  25132. 'ydieresis': 500,
  25133. 'Nacute': 722,
  25134. 'icircumflex': 278,
  25135. 'Ecircumflex': 667,
  25136. 'adieresis': 556,
  25137. 'edieresis': 556,
  25138. 'cacute': 500,
  25139. 'nacute': 556,
  25140. 'umacron': 556,
  25141. 'Ncaron': 722,
  25142. 'Iacute': 278,
  25143. 'plusminus': 584,
  25144. 'brokenbar': 260,
  25145. 'registered': 737,
  25146. 'Gbreve': 778,
  25147. 'Idotaccent': 278,
  25148. 'summation': 600,
  25149. 'Egrave': 667,
  25150. 'racute': 333,
  25151. 'omacron': 556,
  25152. 'Zacute': 611,
  25153. 'Zcaron': 611,
  25154. 'greaterequal': 549,
  25155. 'Eth': 722,
  25156. 'Ccedilla': 722,
  25157. 'lcommaaccent': 222,
  25158. 'tcaron': 317,
  25159. 'eogonek': 556,
  25160. 'Uogonek': 722,
  25161. 'Aacute': 667,
  25162. 'Adieresis': 667,
  25163. 'egrave': 556,
  25164. 'zacute': 500,
  25165. 'iogonek': 222,
  25166. 'Oacute': 778,
  25167. 'oacute': 556,
  25168. 'amacron': 556,
  25169. 'sacute': 500,
  25170. 'idieresis': 278,
  25171. 'Ocircumflex': 778,
  25172. 'Ugrave': 722,
  25173. 'Delta': 612,
  25174. 'thorn': 556,
  25175. 'twosuperior': 333,
  25176. 'Odieresis': 778,
  25177. 'mu': 556,
  25178. 'igrave': 278,
  25179. 'ohungarumlaut': 556,
  25180. 'Eogonek': 667,
  25181. 'dcroat': 556,
  25182. 'threequarters': 834,
  25183. 'Scedilla': 667,
  25184. 'lcaron': 299,
  25185. 'Kcommaaccent': 667,
  25186. 'Lacute': 556,
  25187. 'trademark': 1000,
  25188. 'edotaccent': 556,
  25189. 'Igrave': 278,
  25190. 'Imacron': 278,
  25191. 'Lcaron': 556,
  25192. 'onehalf': 834,
  25193. 'lessequal': 549,
  25194. 'ocircumflex': 556,
  25195. 'ntilde': 556,
  25196. 'Uhungarumlaut': 722,
  25197. 'Eacute': 667,
  25198. 'emacron': 556,
  25199. 'gbreve': 556,
  25200. 'onequarter': 834,
  25201. 'Scaron': 667,
  25202. 'Scommaaccent': 667,
  25203. 'Ohungarumlaut': 778,
  25204. 'degree': 400,
  25205. 'ograve': 556,
  25206. 'Ccaron': 722,
  25207. 'ugrave': 556,
  25208. 'radical': 453,
  25209. 'Dcaron': 722,
  25210. 'rcommaaccent': 333,
  25211. 'Ntilde': 722,
  25212. 'otilde': 556,
  25213. 'Rcommaaccent': 722,
  25214. 'Lcommaaccent': 556,
  25215. 'Atilde': 667,
  25216. 'Aogonek': 667,
  25217. 'Aring': 667,
  25218. 'Otilde': 778,
  25219. 'zdotaccent': 500,
  25220. 'Ecaron': 667,
  25221. 'Iogonek': 278,
  25222. 'kcommaaccent': 500,
  25223. 'minus': 584,
  25224. 'Icircumflex': 278,
  25225. 'ncaron': 556,
  25226. 'tcommaaccent': 278,
  25227. 'logicalnot': 584,
  25228. 'odieresis': 556,
  25229. 'udieresis': 556,
  25230. 'notequal': 549,
  25231. 'gcommaaccent': 556,
  25232. 'eth': 556,
  25233. 'zcaron': 500,
  25234. 'ncommaaccent': 556,
  25235. 'onesuperior': 333,
  25236. 'imacron': 278,
  25237. 'Euro': 556
  25238. },
  25239. 'Symbol': {
  25240. 'space': 250,
  25241. 'exclam': 333,
  25242. 'universal': 713,
  25243. 'numbersign': 500,
  25244. 'existential': 549,
  25245. 'percent': 833,
  25246. 'ampersand': 778,
  25247. 'suchthat': 439,
  25248. 'parenleft': 333,
  25249. 'parenright': 333,
  25250. 'asteriskmath': 500,
  25251. 'plus': 549,
  25252. 'comma': 250,
  25253. 'minus': 549,
  25254. 'period': 250,
  25255. 'slash': 278,
  25256. 'zero': 500,
  25257. 'one': 500,
  25258. 'two': 500,
  25259. 'three': 500,
  25260. 'four': 500,
  25261. 'five': 500,
  25262. 'six': 500,
  25263. 'seven': 500,
  25264. 'eight': 500,
  25265. 'nine': 500,
  25266. 'colon': 278,
  25267. 'semicolon': 278,
  25268. 'less': 549,
  25269. 'equal': 549,
  25270. 'greater': 549,
  25271. 'question': 444,
  25272. 'congruent': 549,
  25273. 'Alpha': 722,
  25274. 'Beta': 667,
  25275. 'Chi': 722,
  25276. 'Delta': 612,
  25277. 'Epsilon': 611,
  25278. 'Phi': 763,
  25279. 'Gamma': 603,
  25280. 'Eta': 722,
  25281. 'Iota': 333,
  25282. 'theta1': 631,
  25283. 'Kappa': 722,
  25284. 'Lambda': 686,
  25285. 'Mu': 889,
  25286. 'Nu': 722,
  25287. 'Omicron': 722,
  25288. 'Pi': 768,
  25289. 'Theta': 741,
  25290. 'Rho': 556,
  25291. 'Sigma': 592,
  25292. 'Tau': 611,
  25293. 'Upsilon': 690,
  25294. 'sigma1': 439,
  25295. 'Omega': 768,
  25296. 'Xi': 645,
  25297. 'Psi': 795,
  25298. 'Zeta': 611,
  25299. 'bracketleft': 333,
  25300. 'therefore': 863,
  25301. 'bracketright': 333,
  25302. 'perpendicular': 658,
  25303. 'underscore': 500,
  25304. 'radicalex': 500,
  25305. 'alpha': 631,
  25306. 'beta': 549,
  25307. 'chi': 549,
  25308. 'delta': 494,
  25309. 'epsilon': 439,
  25310. 'phi': 521,
  25311. 'gamma': 411,
  25312. 'eta': 603,
  25313. 'iota': 329,
  25314. 'phi1': 603,
  25315. 'kappa': 549,
  25316. 'lambda': 549,
  25317. 'mu': 576,
  25318. 'nu': 521,
  25319. 'omicron': 549,
  25320. 'pi': 549,
  25321. 'theta': 521,
  25322. 'rho': 549,
  25323. 'sigma': 603,
  25324. 'tau': 439,
  25325. 'upsilon': 576,
  25326. 'omega1': 713,
  25327. 'omega': 686,
  25328. 'xi': 493,
  25329. 'psi': 686,
  25330. 'zeta': 494,
  25331. 'braceleft': 480,
  25332. 'bar': 200,
  25333. 'braceright': 480,
  25334. 'similar': 549,
  25335. 'Euro': 750,
  25336. 'Upsilon1': 620,
  25337. 'minute': 247,
  25338. 'lessequal': 549,
  25339. 'fraction': 167,
  25340. 'infinity': 713,
  25341. 'florin': 500,
  25342. 'club': 753,
  25343. 'diamond': 753,
  25344. 'heart': 753,
  25345. 'spade': 753,
  25346. 'arrowboth': 1042,
  25347. 'arrowleft': 987,
  25348. 'arrowup': 603,
  25349. 'arrowright': 987,
  25350. 'arrowdown': 603,
  25351. 'degree': 400,
  25352. 'plusminus': 549,
  25353. 'second': 411,
  25354. 'greaterequal': 549,
  25355. 'multiply': 549,
  25356. 'proportional': 713,
  25357. 'partialdiff': 494,
  25358. 'bullet': 460,
  25359. 'divide': 549,
  25360. 'notequal': 549,
  25361. 'equivalence': 549,
  25362. 'approxequal': 549,
  25363. 'ellipsis': 1000,
  25364. 'arrowvertex': 603,
  25365. 'arrowhorizex': 1000,
  25366. 'carriagereturn': 658,
  25367. 'aleph': 823,
  25368. 'Ifraktur': 686,
  25369. 'Rfraktur': 795,
  25370. 'weierstrass': 987,
  25371. 'circlemultiply': 768,
  25372. 'circleplus': 768,
  25373. 'emptyset': 823,
  25374. 'intersection': 768,
  25375. 'union': 768,
  25376. 'propersuperset': 713,
  25377. 'reflexsuperset': 713,
  25378. 'notsubset': 713,
  25379. 'propersubset': 713,
  25380. 'reflexsubset': 713,
  25381. 'element': 713,
  25382. 'notelement': 713,
  25383. 'angle': 768,
  25384. 'gradient': 713,
  25385. 'registerserif': 790,
  25386. 'copyrightserif': 790,
  25387. 'trademarkserif': 890,
  25388. 'product': 823,
  25389. 'radical': 549,
  25390. 'dotmath': 250,
  25391. 'logicalnot': 713,
  25392. 'logicaland': 603,
  25393. 'logicalor': 603,
  25394. 'arrowdblboth': 1042,
  25395. 'arrowdblleft': 987,
  25396. 'arrowdblup': 603,
  25397. 'arrowdblright': 987,
  25398. 'arrowdbldown': 603,
  25399. 'lozenge': 494,
  25400. 'angleleft': 329,
  25401. 'registersans': 790,
  25402. 'copyrightsans': 790,
  25403. 'trademarksans': 786,
  25404. 'summation': 713,
  25405. 'parenlefttp': 384,
  25406. 'parenleftex': 384,
  25407. 'parenleftbt': 384,
  25408. 'bracketlefttp': 384,
  25409. 'bracketleftex': 384,
  25410. 'bracketleftbt': 384,
  25411. 'bracelefttp': 494,
  25412. 'braceleftmid': 494,
  25413. 'braceleftbt': 494,
  25414. 'braceex': 494,
  25415. 'angleright': 329,
  25416. 'integral': 274,
  25417. 'integraltp': 686,
  25418. 'integralex': 686,
  25419. 'integralbt': 686,
  25420. 'parenrighttp': 384,
  25421. 'parenrightex': 384,
  25422. 'parenrightbt': 384,
  25423. 'bracketrighttp': 384,
  25424. 'bracketrightex': 384,
  25425. 'bracketrightbt': 384,
  25426. 'bracerighttp': 494,
  25427. 'bracerightmid': 494,
  25428. 'bracerightbt': 494,
  25429. 'apple': 790
  25430. },
  25431. 'Times-Roman': {
  25432. 'space': 250,
  25433. 'exclam': 333,
  25434. 'quotedbl': 408,
  25435. 'numbersign': 500,
  25436. 'dollar': 500,
  25437. 'percent': 833,
  25438. 'ampersand': 778,
  25439. 'quoteright': 333,
  25440. 'parenleft': 333,
  25441. 'parenright': 333,
  25442. 'asterisk': 500,
  25443. 'plus': 564,
  25444. 'comma': 250,
  25445. 'hyphen': 333,
  25446. 'period': 250,
  25447. 'slash': 278,
  25448. 'zero': 500,
  25449. 'one': 500,
  25450. 'two': 500,
  25451. 'three': 500,
  25452. 'four': 500,
  25453. 'five': 500,
  25454. 'six': 500,
  25455. 'seven': 500,
  25456. 'eight': 500,
  25457. 'nine': 500,
  25458. 'colon': 278,
  25459. 'semicolon': 278,
  25460. 'less': 564,
  25461. 'equal': 564,
  25462. 'greater': 564,
  25463. 'question': 444,
  25464. 'at': 921,
  25465. 'A': 722,
  25466. 'B': 667,
  25467. 'C': 667,
  25468. 'D': 722,
  25469. 'E': 611,
  25470. 'F': 556,
  25471. 'G': 722,
  25472. 'H': 722,
  25473. 'I': 333,
  25474. 'J': 389,
  25475. 'K': 722,
  25476. 'L': 611,
  25477. 'M': 889,
  25478. 'N': 722,
  25479. 'O': 722,
  25480. 'P': 556,
  25481. 'Q': 722,
  25482. 'R': 667,
  25483. 'S': 556,
  25484. 'T': 611,
  25485. 'U': 722,
  25486. 'V': 722,
  25487. 'W': 944,
  25488. 'X': 722,
  25489. 'Y': 722,
  25490. 'Z': 611,
  25491. 'bracketleft': 333,
  25492. 'backslash': 278,
  25493. 'bracketright': 333,
  25494. 'asciicircum': 469,
  25495. 'underscore': 500,
  25496. 'quoteleft': 333,
  25497. 'a': 444,
  25498. 'b': 500,
  25499. 'c': 444,
  25500. 'd': 500,
  25501. 'e': 444,
  25502. 'f': 333,
  25503. 'g': 500,
  25504. 'h': 500,
  25505. 'i': 278,
  25506. 'j': 278,
  25507. 'k': 500,
  25508. 'l': 278,
  25509. 'm': 778,
  25510. 'n': 500,
  25511. 'o': 500,
  25512. 'p': 500,
  25513. 'q': 500,
  25514. 'r': 333,
  25515. 's': 389,
  25516. 't': 278,
  25517. 'u': 500,
  25518. 'v': 500,
  25519. 'w': 722,
  25520. 'x': 500,
  25521. 'y': 500,
  25522. 'z': 444,
  25523. 'braceleft': 480,
  25524. 'bar': 200,
  25525. 'braceright': 480,
  25526. 'asciitilde': 541,
  25527. 'exclamdown': 333,
  25528. 'cent': 500,
  25529. 'sterling': 500,
  25530. 'fraction': 167,
  25531. 'yen': 500,
  25532. 'florin': 500,
  25533. 'section': 500,
  25534. 'currency': 500,
  25535. 'quotesingle': 180,
  25536. 'quotedblleft': 444,
  25537. 'guillemotleft': 500,
  25538. 'guilsinglleft': 333,
  25539. 'guilsinglright': 333,
  25540. 'fi': 556,
  25541. 'fl': 556,
  25542. 'endash': 500,
  25543. 'dagger': 500,
  25544. 'daggerdbl': 500,
  25545. 'periodcentered': 250,
  25546. 'paragraph': 453,
  25547. 'bullet': 350,
  25548. 'quotesinglbase': 333,
  25549. 'quotedblbase': 444,
  25550. 'quotedblright': 444,
  25551. 'guillemotright': 500,
  25552. 'ellipsis': 1000,
  25553. 'perthousand': 1000,
  25554. 'questiondown': 444,
  25555. 'grave': 333,
  25556. 'acute': 333,
  25557. 'circumflex': 333,
  25558. 'tilde': 333,
  25559. 'macron': 333,
  25560. 'breve': 333,
  25561. 'dotaccent': 333,
  25562. 'dieresis': 333,
  25563. 'ring': 333,
  25564. 'cedilla': 333,
  25565. 'hungarumlaut': 333,
  25566. 'ogonek': 333,
  25567. 'caron': 333,
  25568. 'emdash': 1000,
  25569. 'AE': 889,
  25570. 'ordfeminine': 276,
  25571. 'Lslash': 611,
  25572. 'Oslash': 722,
  25573. 'OE': 889,
  25574. 'ordmasculine': 310,
  25575. 'ae': 667,
  25576. 'dotlessi': 278,
  25577. 'lslash': 278,
  25578. 'oslash': 500,
  25579. 'oe': 722,
  25580. 'germandbls': 500,
  25581. 'Idieresis': 333,
  25582. 'eacute': 444,
  25583. 'abreve': 444,
  25584. 'uhungarumlaut': 500,
  25585. 'ecaron': 444,
  25586. 'Ydieresis': 722,
  25587. 'divide': 564,
  25588. 'Yacute': 722,
  25589. 'Acircumflex': 722,
  25590. 'aacute': 444,
  25591. 'Ucircumflex': 722,
  25592. 'yacute': 500,
  25593. 'scommaaccent': 389,
  25594. 'ecircumflex': 444,
  25595. 'Uring': 722,
  25596. 'Udieresis': 722,
  25597. 'aogonek': 444,
  25598. 'Uacute': 722,
  25599. 'uogonek': 500,
  25600. 'Edieresis': 611,
  25601. 'Dcroat': 722,
  25602. 'commaaccent': 250,
  25603. 'copyright': 760,
  25604. 'Emacron': 611,
  25605. 'ccaron': 444,
  25606. 'aring': 444,
  25607. 'Ncommaaccent': 722,
  25608. 'lacute': 278,
  25609. 'agrave': 444,
  25610. 'Tcommaaccent': 611,
  25611. 'Cacute': 667,
  25612. 'atilde': 444,
  25613. 'Edotaccent': 611,
  25614. 'scaron': 389,
  25615. 'scedilla': 389,
  25616. 'iacute': 278,
  25617. 'lozenge': 471,
  25618. 'Rcaron': 667,
  25619. 'Gcommaaccent': 722,
  25620. 'ucircumflex': 500,
  25621. 'acircumflex': 444,
  25622. 'Amacron': 722,
  25623. 'rcaron': 333,
  25624. 'ccedilla': 444,
  25625. 'Zdotaccent': 611,
  25626. 'Thorn': 556,
  25627. 'Omacron': 722,
  25628. 'Racute': 667,
  25629. 'Sacute': 556,
  25630. 'dcaron': 588,
  25631. 'Umacron': 722,
  25632. 'uring': 500,
  25633. 'threesuperior': 300,
  25634. 'Ograve': 722,
  25635. 'Agrave': 722,
  25636. 'Abreve': 722,
  25637. 'multiply': 564,
  25638. 'uacute': 500,
  25639. 'Tcaron': 611,
  25640. 'partialdiff': 476,
  25641. 'ydieresis': 500,
  25642. 'Nacute': 722,
  25643. 'icircumflex': 278,
  25644. 'Ecircumflex': 611,
  25645. 'adieresis': 444,
  25646. 'edieresis': 444,
  25647. 'cacute': 444,
  25648. 'nacute': 500,
  25649. 'umacron': 500,
  25650. 'Ncaron': 722,
  25651. 'Iacute': 333,
  25652. 'plusminus': 564,
  25653. 'brokenbar': 200,
  25654. 'registered': 760,
  25655. 'Gbreve': 722,
  25656. 'Idotaccent': 333,
  25657. 'summation': 600,
  25658. 'Egrave': 611,
  25659. 'racute': 333,
  25660. 'omacron': 500,
  25661. 'Zacute': 611,
  25662. 'Zcaron': 611,
  25663. 'greaterequal': 549,
  25664. 'Eth': 722,
  25665. 'Ccedilla': 667,
  25666. 'lcommaaccent': 278,
  25667. 'tcaron': 326,
  25668. 'eogonek': 444,
  25669. 'Uogonek': 722,
  25670. 'Aacute': 722,
  25671. 'Adieresis': 722,
  25672. 'egrave': 444,
  25673. 'zacute': 444,
  25674. 'iogonek': 278,
  25675. 'Oacute': 722,
  25676. 'oacute': 500,
  25677. 'amacron': 444,
  25678. 'sacute': 389,
  25679. 'idieresis': 278,
  25680. 'Ocircumflex': 722,
  25681. 'Ugrave': 722,
  25682. 'Delta': 612,
  25683. 'thorn': 500,
  25684. 'twosuperior': 300,
  25685. 'Odieresis': 722,
  25686. 'mu': 500,
  25687. 'igrave': 278,
  25688. 'ohungarumlaut': 500,
  25689. 'Eogonek': 611,
  25690. 'dcroat': 500,
  25691. 'threequarters': 750,
  25692. 'Scedilla': 556,
  25693. 'lcaron': 344,
  25694. 'Kcommaaccent': 722,
  25695. 'Lacute': 611,
  25696. 'trademark': 980,
  25697. 'edotaccent': 444,
  25698. 'Igrave': 333,
  25699. 'Imacron': 333,
  25700. 'Lcaron': 611,
  25701. 'onehalf': 750,
  25702. 'lessequal': 549,
  25703. 'ocircumflex': 500,
  25704. 'ntilde': 500,
  25705. 'Uhungarumlaut': 722,
  25706. 'Eacute': 611,
  25707. 'emacron': 444,
  25708. 'gbreve': 500,
  25709. 'onequarter': 750,
  25710. 'Scaron': 556,
  25711. 'Scommaaccent': 556,
  25712. 'Ohungarumlaut': 722,
  25713. 'degree': 400,
  25714. 'ograve': 500,
  25715. 'Ccaron': 667,
  25716. 'ugrave': 500,
  25717. 'radical': 453,
  25718. 'Dcaron': 722,
  25719. 'rcommaaccent': 333,
  25720. 'Ntilde': 722,
  25721. 'otilde': 500,
  25722. 'Rcommaaccent': 667,
  25723. 'Lcommaaccent': 611,
  25724. 'Atilde': 722,
  25725. 'Aogonek': 722,
  25726. 'Aring': 722,
  25727. 'Otilde': 722,
  25728. 'zdotaccent': 444,
  25729. 'Ecaron': 611,
  25730. 'Iogonek': 333,
  25731. 'kcommaaccent': 500,
  25732. 'minus': 564,
  25733. 'Icircumflex': 333,
  25734. 'ncaron': 500,
  25735. 'tcommaaccent': 278,
  25736. 'logicalnot': 564,
  25737. 'odieresis': 500,
  25738. 'udieresis': 500,
  25739. 'notequal': 549,
  25740. 'gcommaaccent': 500,
  25741. 'eth': 500,
  25742. 'zcaron': 444,
  25743. 'ncommaaccent': 500,
  25744. 'onesuperior': 300,
  25745. 'imacron': 278,
  25746. 'Euro': 500
  25747. },
  25748. 'Times-Bold': {
  25749. 'space': 250,
  25750. 'exclam': 333,
  25751. 'quotedbl': 555,
  25752. 'numbersign': 500,
  25753. 'dollar': 500,
  25754. 'percent': 1000,
  25755. 'ampersand': 833,
  25756. 'quoteright': 333,
  25757. 'parenleft': 333,
  25758. 'parenright': 333,
  25759. 'asterisk': 500,
  25760. 'plus': 570,
  25761. 'comma': 250,
  25762. 'hyphen': 333,
  25763. 'period': 250,
  25764. 'slash': 278,
  25765. 'zero': 500,
  25766. 'one': 500,
  25767. 'two': 500,
  25768. 'three': 500,
  25769. 'four': 500,
  25770. 'five': 500,
  25771. 'six': 500,
  25772. 'seven': 500,
  25773. 'eight': 500,
  25774. 'nine': 500,
  25775. 'colon': 333,
  25776. 'semicolon': 333,
  25777. 'less': 570,
  25778. 'equal': 570,
  25779. 'greater': 570,
  25780. 'question': 500,
  25781. 'at': 930,
  25782. 'A': 722,
  25783. 'B': 667,
  25784. 'C': 722,
  25785. 'D': 722,
  25786. 'E': 667,
  25787. 'F': 611,
  25788. 'G': 778,
  25789. 'H': 778,
  25790. 'I': 389,
  25791. 'J': 500,
  25792. 'K': 778,
  25793. 'L': 667,
  25794. 'M': 944,
  25795. 'N': 722,
  25796. 'O': 778,
  25797. 'P': 611,
  25798. 'Q': 778,
  25799. 'R': 722,
  25800. 'S': 556,
  25801. 'T': 667,
  25802. 'U': 722,
  25803. 'V': 722,
  25804. 'W': 1000,
  25805. 'X': 722,
  25806. 'Y': 722,
  25807. 'Z': 667,
  25808. 'bracketleft': 333,
  25809. 'backslash': 278,
  25810. 'bracketright': 333,
  25811. 'asciicircum': 581,
  25812. 'underscore': 500,
  25813. 'quoteleft': 333,
  25814. 'a': 500,
  25815. 'b': 556,
  25816. 'c': 444,
  25817. 'd': 556,
  25818. 'e': 444,
  25819. 'f': 333,
  25820. 'g': 500,
  25821. 'h': 556,
  25822. 'i': 278,
  25823. 'j': 333,
  25824. 'k': 556,
  25825. 'l': 278,
  25826. 'm': 833,
  25827. 'n': 556,
  25828. 'o': 500,
  25829. 'p': 556,
  25830. 'q': 556,
  25831. 'r': 444,
  25832. 's': 389,
  25833. 't': 333,
  25834. 'u': 556,
  25835. 'v': 500,
  25836. 'w': 722,
  25837. 'x': 500,
  25838. 'y': 500,
  25839. 'z': 444,
  25840. 'braceleft': 394,
  25841. 'bar': 220,
  25842. 'braceright': 394,
  25843. 'asciitilde': 520,
  25844. 'exclamdown': 333,
  25845. 'cent': 500,
  25846. 'sterling': 500,
  25847. 'fraction': 167,
  25848. 'yen': 500,
  25849. 'florin': 500,
  25850. 'section': 500,
  25851. 'currency': 500,
  25852. 'quotesingle': 278,
  25853. 'quotedblleft': 500,
  25854. 'guillemotleft': 500,
  25855. 'guilsinglleft': 333,
  25856. 'guilsinglright': 333,
  25857. 'fi': 556,
  25858. 'fl': 556,
  25859. 'endash': 500,
  25860. 'dagger': 500,
  25861. 'daggerdbl': 500,
  25862. 'periodcentered': 250,
  25863. 'paragraph': 540,
  25864. 'bullet': 350,
  25865. 'quotesinglbase': 333,
  25866. 'quotedblbase': 500,
  25867. 'quotedblright': 500,
  25868. 'guillemotright': 500,
  25869. 'ellipsis': 1000,
  25870. 'perthousand': 1000,
  25871. 'questiondown': 500,
  25872. 'grave': 333,
  25873. 'acute': 333,
  25874. 'circumflex': 333,
  25875. 'tilde': 333,
  25876. 'macron': 333,
  25877. 'breve': 333,
  25878. 'dotaccent': 333,
  25879. 'dieresis': 333,
  25880. 'ring': 333,
  25881. 'cedilla': 333,
  25882. 'hungarumlaut': 333,
  25883. 'ogonek': 333,
  25884. 'caron': 333,
  25885. 'emdash': 1000,
  25886. 'AE': 1000,
  25887. 'ordfeminine': 300,
  25888. 'Lslash': 667,
  25889. 'Oslash': 778,
  25890. 'OE': 1000,
  25891. 'ordmasculine': 330,
  25892. 'ae': 722,
  25893. 'dotlessi': 278,
  25894. 'lslash': 278,
  25895. 'oslash': 500,
  25896. 'oe': 722,
  25897. 'germandbls': 556,
  25898. 'Idieresis': 389,
  25899. 'eacute': 444,
  25900. 'abreve': 500,
  25901. 'uhungarumlaut': 556,
  25902. 'ecaron': 444,
  25903. 'Ydieresis': 722,
  25904. 'divide': 570,
  25905. 'Yacute': 722,
  25906. 'Acircumflex': 722,
  25907. 'aacute': 500,
  25908. 'Ucircumflex': 722,
  25909. 'yacute': 500,
  25910. 'scommaaccent': 389,
  25911. 'ecircumflex': 444,
  25912. 'Uring': 722,
  25913. 'Udieresis': 722,
  25914. 'aogonek': 500,
  25915. 'Uacute': 722,
  25916. 'uogonek': 556,
  25917. 'Edieresis': 667,
  25918. 'Dcroat': 722,
  25919. 'commaaccent': 250,
  25920. 'copyright': 747,
  25921. 'Emacron': 667,
  25922. 'ccaron': 444,
  25923. 'aring': 500,
  25924. 'Ncommaaccent': 722,
  25925. 'lacute': 278,
  25926. 'agrave': 500,
  25927. 'Tcommaaccent': 667,
  25928. 'Cacute': 722,
  25929. 'atilde': 500,
  25930. 'Edotaccent': 667,
  25931. 'scaron': 389,
  25932. 'scedilla': 389,
  25933. 'iacute': 278,
  25934. 'lozenge': 494,
  25935. 'Rcaron': 722,
  25936. 'Gcommaaccent': 778,
  25937. 'ucircumflex': 556,
  25938. 'acircumflex': 500,
  25939. 'Amacron': 722,
  25940. 'rcaron': 444,
  25941. 'ccedilla': 444,
  25942. 'Zdotaccent': 667,
  25943. 'Thorn': 611,
  25944. 'Omacron': 778,
  25945. 'Racute': 722,
  25946. 'Sacute': 556,
  25947. 'dcaron': 672,
  25948. 'Umacron': 722,
  25949. 'uring': 556,
  25950. 'threesuperior': 300,
  25951. 'Ograve': 778,
  25952. 'Agrave': 722,
  25953. 'Abreve': 722,
  25954. 'multiply': 570,
  25955. 'uacute': 556,
  25956. 'Tcaron': 667,
  25957. 'partialdiff': 494,
  25958. 'ydieresis': 500,
  25959. 'Nacute': 722,
  25960. 'icircumflex': 278,
  25961. 'Ecircumflex': 667,
  25962. 'adieresis': 500,
  25963. 'edieresis': 444,
  25964. 'cacute': 444,
  25965. 'nacute': 556,
  25966. 'umacron': 556,
  25967. 'Ncaron': 722,
  25968. 'Iacute': 389,
  25969. 'plusminus': 570,
  25970. 'brokenbar': 220,
  25971. 'registered': 747,
  25972. 'Gbreve': 778,
  25973. 'Idotaccent': 389,
  25974. 'summation': 600,
  25975. 'Egrave': 667,
  25976. 'racute': 444,
  25977. 'omacron': 500,
  25978. 'Zacute': 667,
  25979. 'Zcaron': 667,
  25980. 'greaterequal': 549,
  25981. 'Eth': 722,
  25982. 'Ccedilla': 722,
  25983. 'lcommaaccent': 278,
  25984. 'tcaron': 416,
  25985. 'eogonek': 444,
  25986. 'Uogonek': 722,
  25987. 'Aacute': 722,
  25988. 'Adieresis': 722,
  25989. 'egrave': 444,
  25990. 'zacute': 444,
  25991. 'iogonek': 278,
  25992. 'Oacute': 778,
  25993. 'oacute': 500,
  25994. 'amacron': 500,
  25995. 'sacute': 389,
  25996. 'idieresis': 278,
  25997. 'Ocircumflex': 778,
  25998. 'Ugrave': 722,
  25999. 'Delta': 612,
  26000. 'thorn': 556,
  26001. 'twosuperior': 300,
  26002. 'Odieresis': 778,
  26003. 'mu': 556,
  26004. 'igrave': 278,
  26005. 'ohungarumlaut': 500,
  26006. 'Eogonek': 667,
  26007. 'dcroat': 556,
  26008. 'threequarters': 750,
  26009. 'Scedilla': 556,
  26010. 'lcaron': 394,
  26011. 'Kcommaaccent': 778,
  26012. 'Lacute': 667,
  26013. 'trademark': 1000,
  26014. 'edotaccent': 444,
  26015. 'Igrave': 389,
  26016. 'Imacron': 389,
  26017. 'Lcaron': 667,
  26018. 'onehalf': 750,
  26019. 'lessequal': 549,
  26020. 'ocircumflex': 500,
  26021. 'ntilde': 556,
  26022. 'Uhungarumlaut': 722,
  26023. 'Eacute': 667,
  26024. 'emacron': 444,
  26025. 'gbreve': 500,
  26026. 'onequarter': 750,
  26027. 'Scaron': 556,
  26028. 'Scommaaccent': 556,
  26029. 'Ohungarumlaut': 778,
  26030. 'degree': 400,
  26031. 'ograve': 500,
  26032. 'Ccaron': 722,
  26033. 'ugrave': 556,
  26034. 'radical': 549,
  26035. 'Dcaron': 722,
  26036. 'rcommaaccent': 444,
  26037. 'Ntilde': 722,
  26038. 'otilde': 500,
  26039. 'Rcommaaccent': 722,
  26040. 'Lcommaaccent': 667,
  26041. 'Atilde': 722,
  26042. 'Aogonek': 722,
  26043. 'Aring': 722,
  26044. 'Otilde': 778,
  26045. 'zdotaccent': 444,
  26046. 'Ecaron': 667,
  26047. 'Iogonek': 389,
  26048. 'kcommaaccent': 556,
  26049. 'minus': 570,
  26050. 'Icircumflex': 389,
  26051. 'ncaron': 556,
  26052. 'tcommaaccent': 333,
  26053. 'logicalnot': 570,
  26054. 'odieresis': 500,
  26055. 'udieresis': 556,
  26056. 'notequal': 549,
  26057. 'gcommaaccent': 500,
  26058. 'eth': 500,
  26059. 'zcaron': 444,
  26060. 'ncommaaccent': 556,
  26061. 'onesuperior': 300,
  26062. 'imacron': 278,
  26063. 'Euro': 500
  26064. },
  26065. 'Times-BoldItalic': {
  26066. 'space': 250,
  26067. 'exclam': 389,
  26068. 'quotedbl': 555,
  26069. 'numbersign': 500,
  26070. 'dollar': 500,
  26071. 'percent': 833,
  26072. 'ampersand': 778,
  26073. 'quoteright': 333,
  26074. 'parenleft': 333,
  26075. 'parenright': 333,
  26076. 'asterisk': 500,
  26077. 'plus': 570,
  26078. 'comma': 250,
  26079. 'hyphen': 333,
  26080. 'period': 250,
  26081. 'slash': 278,
  26082. 'zero': 500,
  26083. 'one': 500,
  26084. 'two': 500,
  26085. 'three': 500,
  26086. 'four': 500,
  26087. 'five': 500,
  26088. 'six': 500,
  26089. 'seven': 500,
  26090. 'eight': 500,
  26091. 'nine': 500,
  26092. 'colon': 333,
  26093. 'semicolon': 333,
  26094. 'less': 570,
  26095. 'equal': 570,
  26096. 'greater': 570,
  26097. 'question': 500,
  26098. 'at': 832,
  26099. 'A': 667,
  26100. 'B': 667,
  26101. 'C': 667,
  26102. 'D': 722,
  26103. 'E': 667,
  26104. 'F': 667,
  26105. 'G': 722,
  26106. 'H': 778,
  26107. 'I': 389,
  26108. 'J': 500,
  26109. 'K': 667,
  26110. 'L': 611,
  26111. 'M': 889,
  26112. 'N': 722,
  26113. 'O': 722,
  26114. 'P': 611,
  26115. 'Q': 722,
  26116. 'R': 667,
  26117. 'S': 556,
  26118. 'T': 611,
  26119. 'U': 722,
  26120. 'V': 667,
  26121. 'W': 889,
  26122. 'X': 667,
  26123. 'Y': 611,
  26124. 'Z': 611,
  26125. 'bracketleft': 333,
  26126. 'backslash': 278,
  26127. 'bracketright': 333,
  26128. 'asciicircum': 570,
  26129. 'underscore': 500,
  26130. 'quoteleft': 333,
  26131. 'a': 500,
  26132. 'b': 500,
  26133. 'c': 444,
  26134. 'd': 500,
  26135. 'e': 444,
  26136. 'f': 333,
  26137. 'g': 500,
  26138. 'h': 556,
  26139. 'i': 278,
  26140. 'j': 278,
  26141. 'k': 500,
  26142. 'l': 278,
  26143. 'm': 778,
  26144. 'n': 556,
  26145. 'o': 500,
  26146. 'p': 500,
  26147. 'q': 500,
  26148. 'r': 389,
  26149. 's': 389,
  26150. 't': 278,
  26151. 'u': 556,
  26152. 'v': 444,
  26153. 'w': 667,
  26154. 'x': 500,
  26155. 'y': 444,
  26156. 'z': 389,
  26157. 'braceleft': 348,
  26158. 'bar': 220,
  26159. 'braceright': 348,
  26160. 'asciitilde': 570,
  26161. 'exclamdown': 389,
  26162. 'cent': 500,
  26163. 'sterling': 500,
  26164. 'fraction': 167,
  26165. 'yen': 500,
  26166. 'florin': 500,
  26167. 'section': 500,
  26168. 'currency': 500,
  26169. 'quotesingle': 278,
  26170. 'quotedblleft': 500,
  26171. 'guillemotleft': 500,
  26172. 'guilsinglleft': 333,
  26173. 'guilsinglright': 333,
  26174. 'fi': 556,
  26175. 'fl': 556,
  26176. 'endash': 500,
  26177. 'dagger': 500,
  26178. 'daggerdbl': 500,
  26179. 'periodcentered': 250,
  26180. 'paragraph': 500,
  26181. 'bullet': 350,
  26182. 'quotesinglbase': 333,
  26183. 'quotedblbase': 500,
  26184. 'quotedblright': 500,
  26185. 'guillemotright': 500,
  26186. 'ellipsis': 1000,
  26187. 'perthousand': 1000,
  26188. 'questiondown': 500,
  26189. 'grave': 333,
  26190. 'acute': 333,
  26191. 'circumflex': 333,
  26192. 'tilde': 333,
  26193. 'macron': 333,
  26194. 'breve': 333,
  26195. 'dotaccent': 333,
  26196. 'dieresis': 333,
  26197. 'ring': 333,
  26198. 'cedilla': 333,
  26199. 'hungarumlaut': 333,
  26200. 'ogonek': 333,
  26201. 'caron': 333,
  26202. 'emdash': 1000,
  26203. 'AE': 944,
  26204. 'ordfeminine': 266,
  26205. 'Lslash': 611,
  26206. 'Oslash': 722,
  26207. 'OE': 944,
  26208. 'ordmasculine': 300,
  26209. 'ae': 722,
  26210. 'dotlessi': 278,
  26211. 'lslash': 278,
  26212. 'oslash': 500,
  26213. 'oe': 722,
  26214. 'germandbls': 500,
  26215. 'Idieresis': 389,
  26216. 'eacute': 444,
  26217. 'abreve': 500,
  26218. 'uhungarumlaut': 556,
  26219. 'ecaron': 444,
  26220. 'Ydieresis': 611,
  26221. 'divide': 570,
  26222. 'Yacute': 611,
  26223. 'Acircumflex': 667,
  26224. 'aacute': 500,
  26225. 'Ucircumflex': 722,
  26226. 'yacute': 444,
  26227. 'scommaaccent': 389,
  26228. 'ecircumflex': 444,
  26229. 'Uring': 722,
  26230. 'Udieresis': 722,
  26231. 'aogonek': 500,
  26232. 'Uacute': 722,
  26233. 'uogonek': 556,
  26234. 'Edieresis': 667,
  26235. 'Dcroat': 722,
  26236. 'commaaccent': 250,
  26237. 'copyright': 747,
  26238. 'Emacron': 667,
  26239. 'ccaron': 444,
  26240. 'aring': 500,
  26241. 'Ncommaaccent': 722,
  26242. 'lacute': 278,
  26243. 'agrave': 500,
  26244. 'Tcommaaccent': 611,
  26245. 'Cacute': 667,
  26246. 'atilde': 500,
  26247. 'Edotaccent': 667,
  26248. 'scaron': 389,
  26249. 'scedilla': 389,
  26250. 'iacute': 278,
  26251. 'lozenge': 494,
  26252. 'Rcaron': 667,
  26253. 'Gcommaaccent': 722,
  26254. 'ucircumflex': 556,
  26255. 'acircumflex': 500,
  26256. 'Amacron': 667,
  26257. 'rcaron': 389,
  26258. 'ccedilla': 444,
  26259. 'Zdotaccent': 611,
  26260. 'Thorn': 611,
  26261. 'Omacron': 722,
  26262. 'Racute': 667,
  26263. 'Sacute': 556,
  26264. 'dcaron': 608,
  26265. 'Umacron': 722,
  26266. 'uring': 556,
  26267. 'threesuperior': 300,
  26268. 'Ograve': 722,
  26269. 'Agrave': 667,
  26270. 'Abreve': 667,
  26271. 'multiply': 570,
  26272. 'uacute': 556,
  26273. 'Tcaron': 611,
  26274. 'partialdiff': 494,
  26275. 'ydieresis': 444,
  26276. 'Nacute': 722,
  26277. 'icircumflex': 278,
  26278. 'Ecircumflex': 667,
  26279. 'adieresis': 500,
  26280. 'edieresis': 444,
  26281. 'cacute': 444,
  26282. 'nacute': 556,
  26283. 'umacron': 556,
  26284. 'Ncaron': 722,
  26285. 'Iacute': 389,
  26286. 'plusminus': 570,
  26287. 'brokenbar': 220,
  26288. 'registered': 747,
  26289. 'Gbreve': 722,
  26290. 'Idotaccent': 389,
  26291. 'summation': 600,
  26292. 'Egrave': 667,
  26293. 'racute': 389,
  26294. 'omacron': 500,
  26295. 'Zacute': 611,
  26296. 'Zcaron': 611,
  26297. 'greaterequal': 549,
  26298. 'Eth': 722,
  26299. 'Ccedilla': 667,
  26300. 'lcommaaccent': 278,
  26301. 'tcaron': 366,
  26302. 'eogonek': 444,
  26303. 'Uogonek': 722,
  26304. 'Aacute': 667,
  26305. 'Adieresis': 667,
  26306. 'egrave': 444,
  26307. 'zacute': 389,
  26308. 'iogonek': 278,
  26309. 'Oacute': 722,
  26310. 'oacute': 500,
  26311. 'amacron': 500,
  26312. 'sacute': 389,
  26313. 'idieresis': 278,
  26314. 'Ocircumflex': 722,
  26315. 'Ugrave': 722,
  26316. 'Delta': 612,
  26317. 'thorn': 500,
  26318. 'twosuperior': 300,
  26319. 'Odieresis': 722,
  26320. 'mu': 576,
  26321. 'igrave': 278,
  26322. 'ohungarumlaut': 500,
  26323. 'Eogonek': 667,
  26324. 'dcroat': 500,
  26325. 'threequarters': 750,
  26326. 'Scedilla': 556,
  26327. 'lcaron': 382,
  26328. 'Kcommaaccent': 667,
  26329. 'Lacute': 611,
  26330. 'trademark': 1000,
  26331. 'edotaccent': 444,
  26332. 'Igrave': 389,
  26333. 'Imacron': 389,
  26334. 'Lcaron': 611,
  26335. 'onehalf': 750,
  26336. 'lessequal': 549,
  26337. 'ocircumflex': 500,
  26338. 'ntilde': 556,
  26339. 'Uhungarumlaut': 722,
  26340. 'Eacute': 667,
  26341. 'emacron': 444,
  26342. 'gbreve': 500,
  26343. 'onequarter': 750,
  26344. 'Scaron': 556,
  26345. 'Scommaaccent': 556,
  26346. 'Ohungarumlaut': 722,
  26347. 'degree': 400,
  26348. 'ograve': 500,
  26349. 'Ccaron': 667,
  26350. 'ugrave': 556,
  26351. 'radical': 549,
  26352. 'Dcaron': 722,
  26353. 'rcommaaccent': 389,
  26354. 'Ntilde': 722,
  26355. 'otilde': 500,
  26356. 'Rcommaaccent': 667,
  26357. 'Lcommaaccent': 611,
  26358. 'Atilde': 667,
  26359. 'Aogonek': 667,
  26360. 'Aring': 667,
  26361. 'Otilde': 722,
  26362. 'zdotaccent': 389,
  26363. 'Ecaron': 667,
  26364. 'Iogonek': 389,
  26365. 'kcommaaccent': 500,
  26366. 'minus': 606,
  26367. 'Icircumflex': 389,
  26368. 'ncaron': 556,
  26369. 'tcommaaccent': 278,
  26370. 'logicalnot': 606,
  26371. 'odieresis': 500,
  26372. 'udieresis': 556,
  26373. 'notequal': 549,
  26374. 'gcommaaccent': 500,
  26375. 'eth': 500,
  26376. 'zcaron': 389,
  26377. 'ncommaaccent': 556,
  26378. 'onesuperior': 300,
  26379. 'imacron': 278,
  26380. 'Euro': 500
  26381. },
  26382. 'Times-Italic': {
  26383. 'space': 250,
  26384. 'exclam': 333,
  26385. 'quotedbl': 420,
  26386. 'numbersign': 500,
  26387. 'dollar': 500,
  26388. 'percent': 833,
  26389. 'ampersand': 778,
  26390. 'quoteright': 333,
  26391. 'parenleft': 333,
  26392. 'parenright': 333,
  26393. 'asterisk': 500,
  26394. 'plus': 675,
  26395. 'comma': 250,
  26396. 'hyphen': 333,
  26397. 'period': 250,
  26398. 'slash': 278,
  26399. 'zero': 500,
  26400. 'one': 500,
  26401. 'two': 500,
  26402. 'three': 500,
  26403. 'four': 500,
  26404. 'five': 500,
  26405. 'six': 500,
  26406. 'seven': 500,
  26407. 'eight': 500,
  26408. 'nine': 500,
  26409. 'colon': 333,
  26410. 'semicolon': 333,
  26411. 'less': 675,
  26412. 'equal': 675,
  26413. 'greater': 675,
  26414. 'question': 500,
  26415. 'at': 920,
  26416. 'A': 611,
  26417. 'B': 611,
  26418. 'C': 667,
  26419. 'D': 722,
  26420. 'E': 611,
  26421. 'F': 611,
  26422. 'G': 722,
  26423. 'H': 722,
  26424. 'I': 333,
  26425. 'J': 444,
  26426. 'K': 667,
  26427. 'L': 556,
  26428. 'M': 833,
  26429. 'N': 667,
  26430. 'O': 722,
  26431. 'P': 611,
  26432. 'Q': 722,
  26433. 'R': 611,
  26434. 'S': 500,
  26435. 'T': 556,
  26436. 'U': 722,
  26437. 'V': 611,
  26438. 'W': 833,
  26439. 'X': 611,
  26440. 'Y': 556,
  26441. 'Z': 556,
  26442. 'bracketleft': 389,
  26443. 'backslash': 278,
  26444. 'bracketright': 389,
  26445. 'asciicircum': 422,
  26446. 'underscore': 500,
  26447. 'quoteleft': 333,
  26448. 'a': 500,
  26449. 'b': 500,
  26450. 'c': 444,
  26451. 'd': 500,
  26452. 'e': 444,
  26453. 'f': 278,
  26454. 'g': 500,
  26455. 'h': 500,
  26456. 'i': 278,
  26457. 'j': 278,
  26458. 'k': 444,
  26459. 'l': 278,
  26460. 'm': 722,
  26461. 'n': 500,
  26462. 'o': 500,
  26463. 'p': 500,
  26464. 'q': 500,
  26465. 'r': 389,
  26466. 's': 389,
  26467. 't': 278,
  26468. 'u': 500,
  26469. 'v': 444,
  26470. 'w': 667,
  26471. 'x': 444,
  26472. 'y': 444,
  26473. 'z': 389,
  26474. 'braceleft': 400,
  26475. 'bar': 275,
  26476. 'braceright': 400,
  26477. 'asciitilde': 541,
  26478. 'exclamdown': 389,
  26479. 'cent': 500,
  26480. 'sterling': 500,
  26481. 'fraction': 167,
  26482. 'yen': 500,
  26483. 'florin': 500,
  26484. 'section': 500,
  26485. 'currency': 500,
  26486. 'quotesingle': 214,
  26487. 'quotedblleft': 556,
  26488. 'guillemotleft': 500,
  26489. 'guilsinglleft': 333,
  26490. 'guilsinglright': 333,
  26491. 'fi': 500,
  26492. 'fl': 500,
  26493. 'endash': 500,
  26494. 'dagger': 500,
  26495. 'daggerdbl': 500,
  26496. 'periodcentered': 250,
  26497. 'paragraph': 523,
  26498. 'bullet': 350,
  26499. 'quotesinglbase': 333,
  26500. 'quotedblbase': 556,
  26501. 'quotedblright': 556,
  26502. 'guillemotright': 500,
  26503. 'ellipsis': 889,
  26504. 'perthousand': 1000,
  26505. 'questiondown': 500,
  26506. 'grave': 333,
  26507. 'acute': 333,
  26508. 'circumflex': 333,
  26509. 'tilde': 333,
  26510. 'macron': 333,
  26511. 'breve': 333,
  26512. 'dotaccent': 333,
  26513. 'dieresis': 333,
  26514. 'ring': 333,
  26515. 'cedilla': 333,
  26516. 'hungarumlaut': 333,
  26517. 'ogonek': 333,
  26518. 'caron': 333,
  26519. 'emdash': 889,
  26520. 'AE': 889,
  26521. 'ordfeminine': 276,
  26522. 'Lslash': 556,
  26523. 'Oslash': 722,
  26524. 'OE': 944,
  26525. 'ordmasculine': 310,
  26526. 'ae': 667,
  26527. 'dotlessi': 278,
  26528. 'lslash': 278,
  26529. 'oslash': 500,
  26530. 'oe': 667,
  26531. 'germandbls': 500,
  26532. 'Idieresis': 333,
  26533. 'eacute': 444,
  26534. 'abreve': 500,
  26535. 'uhungarumlaut': 500,
  26536. 'ecaron': 444,
  26537. 'Ydieresis': 556,
  26538. 'divide': 675,
  26539. 'Yacute': 556,
  26540. 'Acircumflex': 611,
  26541. 'aacute': 500,
  26542. 'Ucircumflex': 722,
  26543. 'yacute': 444,
  26544. 'scommaaccent': 389,
  26545. 'ecircumflex': 444,
  26546. 'Uring': 722,
  26547. 'Udieresis': 722,
  26548. 'aogonek': 500,
  26549. 'Uacute': 722,
  26550. 'uogonek': 500,
  26551. 'Edieresis': 611,
  26552. 'Dcroat': 722,
  26553. 'commaaccent': 250,
  26554. 'copyright': 760,
  26555. 'Emacron': 611,
  26556. 'ccaron': 444,
  26557. 'aring': 500,
  26558. 'Ncommaaccent': 667,
  26559. 'lacute': 278,
  26560. 'agrave': 500,
  26561. 'Tcommaaccent': 556,
  26562. 'Cacute': 667,
  26563. 'atilde': 500,
  26564. 'Edotaccent': 611,
  26565. 'scaron': 389,
  26566. 'scedilla': 389,
  26567. 'iacute': 278,
  26568. 'lozenge': 471,
  26569. 'Rcaron': 611,
  26570. 'Gcommaaccent': 722,
  26571. 'ucircumflex': 500,
  26572. 'acircumflex': 500,
  26573. 'Amacron': 611,
  26574. 'rcaron': 389,
  26575. 'ccedilla': 444,
  26576. 'Zdotaccent': 556,
  26577. 'Thorn': 611,
  26578. 'Omacron': 722,
  26579. 'Racute': 611,
  26580. 'Sacute': 500,
  26581. 'dcaron': 544,
  26582. 'Umacron': 722,
  26583. 'uring': 500,
  26584. 'threesuperior': 300,
  26585. 'Ograve': 722,
  26586. 'Agrave': 611,
  26587. 'Abreve': 611,
  26588. 'multiply': 675,
  26589. 'uacute': 500,
  26590. 'Tcaron': 556,
  26591. 'partialdiff': 476,
  26592. 'ydieresis': 444,
  26593. 'Nacute': 667,
  26594. 'icircumflex': 278,
  26595. 'Ecircumflex': 611,
  26596. 'adieresis': 500,
  26597. 'edieresis': 444,
  26598. 'cacute': 444,
  26599. 'nacute': 500,
  26600. 'umacron': 500,
  26601. 'Ncaron': 667,
  26602. 'Iacute': 333,
  26603. 'plusminus': 675,
  26604. 'brokenbar': 275,
  26605. 'registered': 760,
  26606. 'Gbreve': 722,
  26607. 'Idotaccent': 333,
  26608. 'summation': 600,
  26609. 'Egrave': 611,
  26610. 'racute': 389,
  26611. 'omacron': 500,
  26612. 'Zacute': 556,
  26613. 'Zcaron': 556,
  26614. 'greaterequal': 549,
  26615. 'Eth': 722,
  26616. 'Ccedilla': 667,
  26617. 'lcommaaccent': 278,
  26618. 'tcaron': 300,
  26619. 'eogonek': 444,
  26620. 'Uogonek': 722,
  26621. 'Aacute': 611,
  26622. 'Adieresis': 611,
  26623. 'egrave': 444,
  26624. 'zacute': 389,
  26625. 'iogonek': 278,
  26626. 'Oacute': 722,
  26627. 'oacute': 500,
  26628. 'amacron': 500,
  26629. 'sacute': 389,
  26630. 'idieresis': 278,
  26631. 'Ocircumflex': 722,
  26632. 'Ugrave': 722,
  26633. 'Delta': 612,
  26634. 'thorn': 500,
  26635. 'twosuperior': 300,
  26636. 'Odieresis': 722,
  26637. 'mu': 500,
  26638. 'igrave': 278,
  26639. 'ohungarumlaut': 500,
  26640. 'Eogonek': 611,
  26641. 'dcroat': 500,
  26642. 'threequarters': 750,
  26643. 'Scedilla': 500,
  26644. 'lcaron': 300,
  26645. 'Kcommaaccent': 667,
  26646. 'Lacute': 556,
  26647. 'trademark': 980,
  26648. 'edotaccent': 444,
  26649. 'Igrave': 333,
  26650. 'Imacron': 333,
  26651. 'Lcaron': 611,
  26652. 'onehalf': 750,
  26653. 'lessequal': 549,
  26654. 'ocircumflex': 500,
  26655. 'ntilde': 500,
  26656. 'Uhungarumlaut': 722,
  26657. 'Eacute': 611,
  26658. 'emacron': 444,
  26659. 'gbreve': 500,
  26660. 'onequarter': 750,
  26661. 'Scaron': 500,
  26662. 'Scommaaccent': 500,
  26663. 'Ohungarumlaut': 722,
  26664. 'degree': 400,
  26665. 'ograve': 500,
  26666. 'Ccaron': 667,
  26667. 'ugrave': 500,
  26668. 'radical': 453,
  26669. 'Dcaron': 722,
  26670. 'rcommaaccent': 389,
  26671. 'Ntilde': 667,
  26672. 'otilde': 500,
  26673. 'Rcommaaccent': 611,
  26674. 'Lcommaaccent': 556,
  26675. 'Atilde': 611,
  26676. 'Aogonek': 611,
  26677. 'Aring': 611,
  26678. 'Otilde': 722,
  26679. 'zdotaccent': 389,
  26680. 'Ecaron': 611,
  26681. 'Iogonek': 333,
  26682. 'kcommaaccent': 444,
  26683. 'minus': 675,
  26684. 'Icircumflex': 333,
  26685. 'ncaron': 500,
  26686. 'tcommaaccent': 278,
  26687. 'logicalnot': 675,
  26688. 'odieresis': 500,
  26689. 'udieresis': 500,
  26690. 'notequal': 549,
  26691. 'gcommaaccent': 500,
  26692. 'eth': 500,
  26693. 'zcaron': 389,
  26694. 'ncommaaccent': 500,
  26695. 'onesuperior': 300,
  26696. 'imacron': 278,
  26697. 'Euro': 500
  26698. },
  26699. 'ZapfDingbats': {
  26700. 'space': 278,
  26701. 'a1': 974,
  26702. 'a2': 961,
  26703. 'a202': 974,
  26704. 'a3': 980,
  26705. 'a4': 719,
  26706. 'a5': 789,
  26707. 'a119': 790,
  26708. 'a118': 791,
  26709. 'a117': 690,
  26710. 'a11': 960,
  26711. 'a12': 939,
  26712. 'a13': 549,
  26713. 'a14': 855,
  26714. 'a15': 911,
  26715. 'a16': 933,
  26716. 'a105': 911,
  26717. 'a17': 945,
  26718. 'a18': 974,
  26719. 'a19': 755,
  26720. 'a20': 846,
  26721. 'a21': 762,
  26722. 'a22': 761,
  26723. 'a23': 571,
  26724. 'a24': 677,
  26725. 'a25': 763,
  26726. 'a26': 760,
  26727. 'a27': 759,
  26728. 'a28': 754,
  26729. 'a6': 494,
  26730. 'a7': 552,
  26731. 'a8': 537,
  26732. 'a9': 577,
  26733. 'a10': 692,
  26734. 'a29': 786,
  26735. 'a30': 788,
  26736. 'a31': 788,
  26737. 'a32': 790,
  26738. 'a33': 793,
  26739. 'a34': 794,
  26740. 'a35': 816,
  26741. 'a36': 823,
  26742. 'a37': 789,
  26743. 'a38': 841,
  26744. 'a39': 823,
  26745. 'a40': 833,
  26746. 'a41': 816,
  26747. 'a42': 831,
  26748. 'a43': 923,
  26749. 'a44': 744,
  26750. 'a45': 723,
  26751. 'a46': 749,
  26752. 'a47': 790,
  26753. 'a48': 792,
  26754. 'a49': 695,
  26755. 'a50': 776,
  26756. 'a51': 768,
  26757. 'a52': 792,
  26758. 'a53': 759,
  26759. 'a54': 707,
  26760. 'a55': 708,
  26761. 'a56': 682,
  26762. 'a57': 701,
  26763. 'a58': 826,
  26764. 'a59': 815,
  26765. 'a60': 789,
  26766. 'a61': 789,
  26767. 'a62': 707,
  26768. 'a63': 687,
  26769. 'a64': 696,
  26770. 'a65': 689,
  26771. 'a66': 786,
  26772. 'a67': 787,
  26773. 'a68': 713,
  26774. 'a69': 791,
  26775. 'a70': 785,
  26776. 'a71': 791,
  26777. 'a72': 873,
  26778. 'a73': 761,
  26779. 'a74': 762,
  26780. 'a203': 762,
  26781. 'a75': 759,
  26782. 'a204': 759,
  26783. 'a76': 892,
  26784. 'a77': 892,
  26785. 'a78': 788,
  26786. 'a79': 784,
  26787. 'a81': 438,
  26788. 'a82': 138,
  26789. 'a83': 277,
  26790. 'a84': 415,
  26791. 'a97': 392,
  26792. 'a98': 392,
  26793. 'a99': 668,
  26794. 'a100': 668,
  26795. 'a89': 390,
  26796. 'a90': 390,
  26797. 'a93': 317,
  26798. 'a94': 317,
  26799. 'a91': 276,
  26800. 'a92': 276,
  26801. 'a205': 509,
  26802. 'a85': 509,
  26803. 'a206': 410,
  26804. 'a86': 410,
  26805. 'a87': 234,
  26806. 'a88': 234,
  26807. 'a95': 334,
  26808. 'a96': 334,
  26809. 'a101': 732,
  26810. 'a102': 544,
  26811. 'a103': 544,
  26812. 'a104': 910,
  26813. 'a106': 667,
  26814. 'a107': 760,
  26815. 'a108': 760,
  26816. 'a112': 776,
  26817. 'a111': 595,
  26818. 'a110': 694,
  26819. 'a109': 626,
  26820. 'a120': 788,
  26821. 'a121': 788,
  26822. 'a122': 788,
  26823. 'a123': 788,
  26824. 'a124': 788,
  26825. 'a125': 788,
  26826. 'a126': 788,
  26827. 'a127': 788,
  26828. 'a128': 788,
  26829. 'a129': 788,
  26830. 'a130': 788,
  26831. 'a131': 788,
  26832. 'a132': 788,
  26833. 'a133': 788,
  26834. 'a134': 788,
  26835. 'a135': 788,
  26836. 'a136': 788,
  26837. 'a137': 788,
  26838. 'a138': 788,
  26839. 'a139': 788,
  26840. 'a140': 788,
  26841. 'a141': 788,
  26842. 'a142': 788,
  26843. 'a143': 788,
  26844. 'a144': 788,
  26845. 'a145': 788,
  26846. 'a146': 788,
  26847. 'a147': 788,
  26848. 'a148': 788,
  26849. 'a149': 788,
  26850. 'a150': 788,
  26851. 'a151': 788,
  26852. 'a152': 788,
  26853. 'a153': 788,
  26854. 'a154': 788,
  26855. 'a155': 788,
  26856. 'a156': 788,
  26857. 'a157': 788,
  26858. 'a158': 788,
  26859. 'a159': 788,
  26860. 'a160': 894,
  26861. 'a161': 838,
  26862. 'a163': 1016,
  26863. 'a164': 458,
  26864. 'a196': 748,
  26865. 'a165': 924,
  26866. 'a192': 748,
  26867. 'a166': 918,
  26868. 'a167': 927,
  26869. 'a168': 928,
  26870. 'a169': 928,
  26871. 'a170': 834,
  26872. 'a171': 873,
  26873. 'a172': 828,
  26874. 'a173': 924,
  26875. 'a162': 924,
  26876. 'a174': 917,
  26877. 'a175': 930,
  26878. 'a176': 931,
  26879. 'a177': 463,
  26880. 'a178': 883,
  26881. 'a179': 836,
  26882. 'a193': 836,
  26883. 'a180': 867,
  26884. 'a199': 867,
  26885. 'a181': 696,
  26886. 'a200': 696,
  26887. 'a182': 874,
  26888. 'a201': 874,
  26889. 'a183': 760,
  26890. 'a184': 946,
  26891. 'a197': 771,
  26892. 'a185': 865,
  26893. 'a194': 771,
  26894. 'a198': 888,
  26895. 'a186': 967,
  26896. 'a195': 888,
  26897. 'a187': 831,
  26898. 'a188': 873,
  26899. 'a189': 927,
  26900. 'a190': 970,
  26901. 'a191': 918
  26902. }
  26903. };
  26904. var EOF = {};
  26905. function isEOF(v) {
  26906. return (v === EOF);
  26907. }
  26908. var Parser = (function ParserClosure() {
  26909. function Parser(lexer, allowStreams, xref) {
  26910. this.lexer = lexer;
  26911. this.allowStreams = allowStreams;
  26912. this.xref = xref;
  26913. this.imageCache = {
  26914. length: 0,
  26915. adler32: 0,
  26916. stream: null
  26917. };
  26918. this.refill();
  26919. }
  26920. Parser.prototype = {
  26921. refill: function Parser_refill() {
  26922. this.buf1 = this.lexer.getObj();
  26923. this.buf2 = this.lexer.getObj();
  26924. },
  26925. shift: function Parser_shift() {
  26926. if (isCmd(this.buf2, 'ID')) {
  26927. this.buf1 = this.buf2;
  26928. this.buf2 = null;
  26929. } else {
  26930. this.buf1 = this.buf2;
  26931. this.buf2 = this.lexer.getObj();
  26932. }
  26933. },
  26934. getObj: function Parser_getObj(cipherTransform) {
  26935. var buf1 = this.buf1;
  26936. this.shift();
  26937. if (buf1 instanceof Cmd) {
  26938. switch (buf1.cmd) {
  26939. case 'BI': // inline image
  26940. return this.makeInlineImage(cipherTransform);
  26941. case '[': // array
  26942. var array = [];
  26943. while (!isCmd(this.buf1, ']') && !isEOF(this.buf1)) {
  26944. array.push(this.getObj(cipherTransform));
  26945. }
  26946. if (isEOF(this.buf1)) {
  26947. error('End of file inside array');
  26948. }
  26949. this.shift();
  26950. return array;
  26951. case '<<': // dictionary or stream
  26952. var dict = new Dict(this.xref);
  26953. while (!isCmd(this.buf1, '>>') && !isEOF(this.buf1)) {
  26954. if (!isName(this.buf1)) {
  26955. info('Malformed dictionary: key must be a name object');
  26956. this.shift();
  26957. continue;
  26958. }
  26959. var key = this.buf1.name;
  26960. this.shift();
  26961. if (isEOF(this.buf1)) {
  26962. break;
  26963. }
  26964. dict.set(key, this.getObj(cipherTransform));
  26965. }
  26966. if (isEOF(this.buf1)) {
  26967. error('End of file inside dictionary');
  26968. }
  26969. // Stream objects are not allowed inside content streams or
  26970. // object streams.
  26971. if (isCmd(this.buf2, 'stream')) {
  26972. return (this.allowStreams ?
  26973. this.makeStream(dict, cipherTransform) : dict);
  26974. }
  26975. this.shift();
  26976. return dict;
  26977. default: // simple object
  26978. return buf1;
  26979. }
  26980. }
  26981. if (isInt(buf1)) { // indirect reference or integer
  26982. var num = buf1;
  26983. if (isInt(this.buf1) && isCmd(this.buf2, 'R')) {
  26984. var ref = new Ref(num, this.buf1);
  26985. this.shift();
  26986. this.shift();
  26987. return ref;
  26988. }
  26989. return num;
  26990. }
  26991. if (isString(buf1)) { // string
  26992. var str = buf1;
  26993. if (cipherTransform) {
  26994. str = cipherTransform.decryptString(str);
  26995. }
  26996. return str;
  26997. }
  26998. // simple object
  26999. return buf1;
  27000. },
  27001. makeInlineImage: function Parser_makeInlineImage(cipherTransform) {
  27002. var lexer = this.lexer;
  27003. var stream = lexer.stream;
  27004. // parse dictionary
  27005. var dict = new Dict(null);
  27006. while (!isCmd(this.buf1, 'ID') && !isEOF(this.buf1)) {
  27007. if (!isName(this.buf1)) {
  27008. error('Dictionary key must be a name object');
  27009. }
  27010. var key = this.buf1.name;
  27011. this.shift();
  27012. if (isEOF(this.buf1)) {
  27013. break;
  27014. }
  27015. dict.set(key, this.getObj(cipherTransform));
  27016. }
  27017. // parse image stream
  27018. var startPos = stream.pos;
  27019. // searching for the /EI\s/
  27020. var state = 0, ch, i, ii;
  27021. while (state != 4 && (ch = stream.getByte()) !== -1) {
  27022. switch (ch | 0) {
  27023. case 0x20:
  27024. case 0x0D:
  27025. case 0x0A:
  27026. // let's check next five bytes to be ASCII... just be sure
  27027. var followingBytes = stream.peekBytes(5);
  27028. for (i = 0, ii = followingBytes.length; i < ii; i++) {
  27029. ch = followingBytes[i];
  27030. if (ch !== 0x0A && ch !== 0x0D && (ch < 0x20 || ch > 0x7F)) {
  27031. // not a LF, CR, SPACE or any visible ASCII character
  27032. state = 0;
  27033. break; // some binary stuff found, resetting the state
  27034. }
  27035. }
  27036. state = (state === 3 ? 4 : 0);
  27037. break;
  27038. case 0x45:
  27039. state = 2;
  27040. break;
  27041. case 0x49:
  27042. state = (state === 2 ? 3 : 0);
  27043. break;
  27044. default:
  27045. state = 0;
  27046. break;
  27047. }
  27048. }
  27049. var length = (stream.pos - 4) - startPos;
  27050. var imageStream = stream.makeSubStream(startPos, length, dict);
  27051. // trying to cache repeat images, first we are trying to "warm up" caching
  27052. // using length, then comparing adler32
  27053. var MAX_LENGTH_TO_CACHE = 1000;
  27054. var cacheImage = false, adler32;
  27055. if (length < MAX_LENGTH_TO_CACHE && this.imageCache.length === length) {
  27056. var imageBytes = imageStream.getBytes();
  27057. imageStream.reset();
  27058. var a = 1;
  27059. var b = 0;
  27060. for (i = 0, ii = imageBytes.length; i < ii; ++i) {
  27061. a = (a + (imageBytes[i] & 0xff)) % 65521;
  27062. b = (b + a) % 65521;
  27063. }
  27064. adler32 = (b << 16) | a;
  27065. if (this.imageCache.stream && this.imageCache.adler32 === adler32) {
  27066. this.buf2 = Cmd.get('EI');
  27067. this.shift();
  27068. this.imageCache.stream.reset();
  27069. return this.imageCache.stream;
  27070. }
  27071. cacheImage = true;
  27072. }
  27073. if (!cacheImage && !this.imageCache.stream) {
  27074. this.imageCache.length = length;
  27075. this.imageCache.stream = null;
  27076. }
  27077. if (cipherTransform) {
  27078. imageStream = cipherTransform.createStream(imageStream, length);
  27079. }
  27080. imageStream = this.filter(imageStream, dict, length);
  27081. imageStream.dict = dict;
  27082. if (cacheImage) {
  27083. imageStream.cacheKey = 'inline_' + length + '_' + adler32;
  27084. this.imageCache.adler32 = adler32;
  27085. this.imageCache.stream = imageStream;
  27086. }
  27087. this.buf2 = Cmd.get('EI');
  27088. this.shift();
  27089. return imageStream;
  27090. },
  27091. fetchIfRef: function Parser_fetchIfRef(obj) {
  27092. // not relying on the xref.fetchIfRef -- xref might not be set
  27093. return (isRef(obj) ? this.xref.fetch(obj) : obj);
  27094. },
  27095. makeStream: function Parser_makeStream(dict, cipherTransform) {
  27096. var lexer = this.lexer;
  27097. var stream = lexer.stream;
  27098. // get stream start position
  27099. lexer.skipToNextLine();
  27100. var pos = stream.pos - 1;
  27101. // get length
  27102. var length = this.fetchIfRef(dict.get('Length'));
  27103. if (!isInt(length)) {
  27104. info('Bad ' + length + ' attribute in stream');
  27105. length = 0;
  27106. }
  27107. // skip over the stream data
  27108. stream.pos = pos + length;
  27109. lexer.nextChar();
  27110. this.shift(); // '>>'
  27111. this.shift(); // 'stream'
  27112. if (!isCmd(this.buf1, 'endstream')) {
  27113. // bad stream length, scanning for endstream
  27114. stream.pos = pos;
  27115. var SCAN_BLOCK_SIZE = 2048;
  27116. var ENDSTREAM_SIGNATURE_LENGTH = 9;
  27117. var ENDSTREAM_SIGNATURE = [0x65, 0x6E, 0x64, 0x73, 0x74, 0x72, 0x65,
  27118. 0x61, 0x6D];
  27119. var skipped = 0, found = false, i, j;
  27120. while (stream.pos < stream.end) {
  27121. var scanBytes = stream.peekBytes(SCAN_BLOCK_SIZE);
  27122. var scanLength = scanBytes.length - ENDSTREAM_SIGNATURE_LENGTH;
  27123. if (scanLength <= 0) {
  27124. break;
  27125. }
  27126. found = false;
  27127. for (i = 0, j = 0; i < scanLength; i++) {
  27128. var b = scanBytes[i];
  27129. if (b !== ENDSTREAM_SIGNATURE[j]) {
  27130. i -= j;
  27131. j = 0;
  27132. } else {
  27133. j++;
  27134. if (j >= ENDSTREAM_SIGNATURE_LENGTH) {
  27135. i++;
  27136. found = true;
  27137. break;
  27138. }
  27139. }
  27140. }
  27141. if (found) {
  27142. skipped += i - ENDSTREAM_SIGNATURE_LENGTH;
  27143. stream.pos += i - ENDSTREAM_SIGNATURE_LENGTH;
  27144. break;
  27145. }
  27146. skipped += scanLength;
  27147. stream.pos += scanLength;
  27148. }
  27149. if (!found) {
  27150. error('Missing endstream');
  27151. }
  27152. length = skipped;
  27153. lexer.nextChar();
  27154. this.shift();
  27155. this.shift();
  27156. }
  27157. this.shift(); // 'endstream'
  27158. stream = stream.makeSubStream(pos, length, dict);
  27159. if (cipherTransform) {
  27160. stream = cipherTransform.createStream(stream, length);
  27161. }
  27162. stream = this.filter(stream, dict, length);
  27163. stream.dict = dict;
  27164. return stream;
  27165. },
  27166. filter: function Parser_filter(stream, dict, length) {
  27167. var filter = this.fetchIfRef(dict.get('Filter', 'F'));
  27168. var params = this.fetchIfRef(dict.get('DecodeParms', 'DP'));
  27169. if (isName(filter)) {
  27170. return this.makeFilter(stream, filter.name, length, params);
  27171. }
  27172. var maybeLength = length;
  27173. if (isArray(filter)) {
  27174. var filterArray = filter;
  27175. var paramsArray = params;
  27176. for (var i = 0, ii = filterArray.length; i < ii; ++i) {
  27177. filter = filterArray[i];
  27178. if (!isName(filter)) {
  27179. error('Bad filter name: ' + filter);
  27180. }
  27181. params = null;
  27182. if (isArray(paramsArray) && (i in paramsArray)) {
  27183. params = paramsArray[i];
  27184. }
  27185. stream = this.makeFilter(stream, filter.name, maybeLength, params);
  27186. // after the first stream the length variable is invalid
  27187. maybeLength = null;
  27188. }
  27189. }
  27190. return stream;
  27191. },
  27192. makeFilter: function Parser_makeFilter(stream, name, maybeLength, params) {
  27193. if (stream.dict.get('Length') === 0) {
  27194. return new NullStream(stream);
  27195. }
  27196. try {
  27197. var xrefStreamStats = this.xref.stats.streamTypes;
  27198. if (name == 'FlateDecode' || name == 'Fl') {
  27199. xrefStreamStats[StreamType.FLATE] = true;
  27200. if (params) {
  27201. return new PredictorStream(new FlateStream(stream, maybeLength),
  27202. maybeLength, params);
  27203. }
  27204. return new FlateStream(stream, maybeLength);
  27205. }
  27206. if (name == 'LZWDecode' || name == 'LZW') {
  27207. xrefStreamStats[StreamType.LZW] = true;
  27208. var earlyChange = 1;
  27209. if (params) {
  27210. if (params.has('EarlyChange')) {
  27211. earlyChange = params.get('EarlyChange');
  27212. }
  27213. return new PredictorStream(
  27214. new LZWStream(stream, maybeLength, earlyChange),
  27215. maybeLength, params);
  27216. }
  27217. return new LZWStream(stream, maybeLength, earlyChange);
  27218. }
  27219. if (name == 'DCTDecode' || name == 'DCT') {
  27220. xrefStreamStats[StreamType.DCT] = true;
  27221. return new JpegStream(stream, maybeLength, stream.dict, this.xref);
  27222. }
  27223. if (name == 'JPXDecode' || name == 'JPX') {
  27224. xrefStreamStats[StreamType.JPX] = true;
  27225. return new JpxStream(stream, maybeLength, stream.dict);
  27226. }
  27227. if (name == 'ASCII85Decode' || name == 'A85') {
  27228. xrefStreamStats[StreamType.A85] = true;
  27229. return new Ascii85Stream(stream, maybeLength);
  27230. }
  27231. if (name == 'ASCIIHexDecode' || name == 'AHx') {
  27232. xrefStreamStats[StreamType.AHX] = true;
  27233. return new AsciiHexStream(stream, maybeLength);
  27234. }
  27235. if (name == 'CCITTFaxDecode' || name == 'CCF') {
  27236. xrefStreamStats[StreamType.CCF] = true;
  27237. return new CCITTFaxStream(stream, maybeLength, params);
  27238. }
  27239. if (name == 'RunLengthDecode' || name == 'RL') {
  27240. xrefStreamStats[StreamType.RL] = true;
  27241. return new RunLengthStream(stream, maybeLength);
  27242. }
  27243. if (name == 'JBIG2Decode') {
  27244. xrefStreamStats[StreamType.JBIG] = true;
  27245. return new Jbig2Stream(stream, maybeLength, stream.dict);
  27246. }
  27247. warn('filter "' + name + '" not supported yet');
  27248. return stream;
  27249. } catch (ex) {
  27250. if (ex instanceof MissingDataException) {
  27251. throw ex;
  27252. }
  27253. warn('Invalid stream: \"' + ex + '\"');
  27254. return new NullStream(stream);
  27255. }
  27256. }
  27257. };
  27258. return Parser;
  27259. })();
  27260. var Lexer = (function LexerClosure() {
  27261. function Lexer(stream, knownCommands) {
  27262. this.stream = stream;
  27263. this.nextChar();
  27264. // While lexing, we build up many strings one char at a time. Using += for
  27265. // this can result in lots of garbage strings. It's better to build an
  27266. // array of single-char strings and then join() them together at the end.
  27267. // And reusing a single array (i.e. |this.strBuf|) over and over for this
  27268. // purpose uses less memory than using a new array for each string.
  27269. this.strBuf = [];
  27270. // The PDFs might have "glued" commands with other commands, operands or
  27271. // literals, e.g. "q1". The knownCommands is a dictionary of the valid
  27272. // commands and their prefixes. The prefixes are built the following way:
  27273. // if there a command that is a prefix of the other valid command or
  27274. // literal (e.g. 'f' and 'false') the following prefixes must be included,
  27275. // 'fa', 'fal', 'fals'. The prefixes are not needed, if the command has no
  27276. // other commands or literals as a prefix. The knowCommands is optional.
  27277. this.knownCommands = knownCommands;
  27278. }
  27279. Lexer.isSpace = function Lexer_isSpace(ch) {
  27280. // Space is one of the following characters: SPACE, TAB, CR or LF.
  27281. return (ch === 0x20 || ch === 0x09 || ch === 0x0D || ch === 0x0A);
  27282. };
  27283. // A '1' in this array means the character is white space. A '1' or
  27284. // '2' means the character ends a name or command.
  27285. var specialChars = [
  27286. 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, // 0x
  27287. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 1x
  27288. 1, 0, 0, 0, 0, 2, 0, 0, 2, 2, 0, 0, 0, 0, 0, 2, // 2x
  27289. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, // 3x
  27290. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 4x
  27291. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 5x
  27292. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 6x
  27293. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 7x
  27294. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 8x
  27295. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 9x
  27296. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ax
  27297. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // bx
  27298. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // cx
  27299. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // dx
  27300. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ex
  27301. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 // fx
  27302. ];
  27303. function toHexDigit(ch) {
  27304. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  27305. return ch & 0x0F;
  27306. }
  27307. if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  27308. // 'A'-'F', 'a'-'f'
  27309. return (ch & 0x0F) + 9;
  27310. }
  27311. return -1;
  27312. }
  27313. Lexer.prototype = {
  27314. nextChar: function Lexer_nextChar() {
  27315. return (this.currentChar = this.stream.getByte());
  27316. },
  27317. peekChar: function Lexer_peekChar() {
  27318. return this.stream.peekBytes(1)[0];
  27319. },
  27320. getNumber: function Lexer_getNumber() {
  27321. var ch = this.currentChar;
  27322. var eNotation = false;
  27323. var divideBy = 0; // different from 0 if it's a floating point value
  27324. var sign = 1;
  27325. if (ch === 0x2D) { // '-'
  27326. sign = -1;
  27327. ch = this.nextChar();
  27328. } else if (ch === 0x2B) { // '+'
  27329. ch = this.nextChar();
  27330. }
  27331. if (ch === 0x2E) { // '.'
  27332. divideBy = 10;
  27333. ch = this.nextChar();
  27334. }
  27335. if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  27336. error('Invalid number: ' + String.fromCharCode(ch));
  27337. return 0;
  27338. }
  27339. var baseValue = ch - 0x30; // '0'
  27340. var powerValue = 0;
  27341. var powerValueSign = 1;
  27342. while ((ch = this.nextChar()) >= 0) {
  27343. if (0x30 <= ch && ch <= 0x39) { // '0' - '9'
  27344. var currentDigit = ch - 0x30; // '0'
  27345. if (eNotation) { // We are after an 'e' or 'E'
  27346. powerValue = powerValue * 10 + currentDigit;
  27347. } else {
  27348. if (divideBy !== 0) { // We are after a point
  27349. divideBy *= 10;
  27350. }
  27351. baseValue = baseValue * 10 + currentDigit;
  27352. }
  27353. } else if (ch === 0x2E) { // '.'
  27354. if (divideBy === 0) {
  27355. divideBy = 1;
  27356. } else {
  27357. // A number can have only one '.'
  27358. break;
  27359. }
  27360. } else if (ch === 0x2D) { // '-'
  27361. // ignore minus signs in the middle of numbers to match
  27362. // Adobe's behavior
  27363. warn('Badly formated number');
  27364. } else if (ch === 0x45 || ch === 0x65) { // 'E', 'e'
  27365. // 'E' can be either a scientific notation or the beginning of a new
  27366. // operator
  27367. ch = this.peekChar();
  27368. if (ch === 0x2B || ch === 0x2D) { // '+', '-'
  27369. powerValueSign = (ch === 0x2D) ? -1 : 1;
  27370. this.nextChar(); // Consume the sign character
  27371. } else if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  27372. // The 'E' must be the beginning of a new operator
  27373. break;
  27374. }
  27375. eNotation = true;
  27376. } else {
  27377. // the last character doesn't belong to us
  27378. break;
  27379. }
  27380. }
  27381. if (divideBy !== 0) {
  27382. baseValue /= divideBy;
  27383. }
  27384. if (eNotation) {
  27385. baseValue *= Math.pow(10, powerValueSign * powerValue);
  27386. }
  27387. return sign * baseValue;
  27388. },
  27389. getString: function Lexer_getString() {
  27390. var numParen = 1;
  27391. var done = false;
  27392. var strBuf = this.strBuf;
  27393. strBuf.length = 0;
  27394. var ch = this.nextChar();
  27395. while (true) {
  27396. var charBuffered = false;
  27397. switch (ch | 0) {
  27398. case -1:
  27399. warn('Unterminated string');
  27400. done = true;
  27401. break;
  27402. case 0x28: // '('
  27403. ++numParen;
  27404. strBuf.push('(');
  27405. break;
  27406. case 0x29: // ')'
  27407. if (--numParen === 0) {
  27408. this.nextChar(); // consume strings ')'
  27409. done = true;
  27410. } else {
  27411. strBuf.push(')');
  27412. }
  27413. break;
  27414. case 0x5C: // '\\'
  27415. ch = this.nextChar();
  27416. switch (ch) {
  27417. case -1:
  27418. warn('Unterminated string');
  27419. done = true;
  27420. break;
  27421. case 0x6E: // 'n'
  27422. strBuf.push('\n');
  27423. break;
  27424. case 0x72: // 'r'
  27425. strBuf.push('\r');
  27426. break;
  27427. case 0x74: // 't'
  27428. strBuf.push('\t');
  27429. break;
  27430. case 0x62: // 'b'
  27431. strBuf.push('\b');
  27432. break;
  27433. case 0x66: // 'f'
  27434. strBuf.push('\f');
  27435. break;
  27436. case 0x5C: // '\'
  27437. case 0x28: // '('
  27438. case 0x29: // ')'
  27439. strBuf.push(String.fromCharCode(ch));
  27440. break;
  27441. case 0x30: case 0x31: case 0x32: case 0x33: // '0'-'3'
  27442. case 0x34: case 0x35: case 0x36: case 0x37: // '4'-'7'
  27443. var x = ch & 0x0F;
  27444. ch = this.nextChar();
  27445. charBuffered = true;
  27446. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  27447. x = (x << 3) + (ch & 0x0F);
  27448. ch = this.nextChar();
  27449. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  27450. charBuffered = false;
  27451. x = (x << 3) + (ch & 0x0F);
  27452. }
  27453. }
  27454. strBuf.push(String.fromCharCode(x));
  27455. break;
  27456. case 0x0D: // CR
  27457. if (this.peekChar() === 0x0A) { // LF
  27458. this.nextChar();
  27459. }
  27460. break;
  27461. case 0x0A: // LF
  27462. break;
  27463. default:
  27464. strBuf.push(String.fromCharCode(ch));
  27465. break;
  27466. }
  27467. break;
  27468. default:
  27469. strBuf.push(String.fromCharCode(ch));
  27470. break;
  27471. }
  27472. if (done) {
  27473. break;
  27474. }
  27475. if (!charBuffered) {
  27476. ch = this.nextChar();
  27477. }
  27478. }
  27479. return strBuf.join('');
  27480. },
  27481. getName: function Lexer_getName() {
  27482. var ch;
  27483. var strBuf = this.strBuf;
  27484. strBuf.length = 0;
  27485. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  27486. if (ch === 0x23) { // '#'
  27487. ch = this.nextChar();
  27488. var x = toHexDigit(ch);
  27489. if (x != -1) {
  27490. var x2 = toHexDigit(this.nextChar());
  27491. if (x2 === -1) {
  27492. error('Illegal digit in hex char in name: ' + x2);
  27493. }
  27494. strBuf.push(String.fromCharCode((x << 4) | x2));
  27495. } else {
  27496. strBuf.push('#', String.fromCharCode(ch));
  27497. }
  27498. } else {
  27499. strBuf.push(String.fromCharCode(ch));
  27500. }
  27501. }
  27502. if (strBuf.length > 128) {
  27503. error('Warning: name token is longer than allowed by the spec: ' +
  27504. strBuf.length);
  27505. }
  27506. return Name.get(strBuf.join(''));
  27507. },
  27508. getHexString: function Lexer_getHexString() {
  27509. var strBuf = this.strBuf;
  27510. strBuf.length = 0;
  27511. var ch = this.currentChar;
  27512. var isFirstHex = true;
  27513. var firstDigit;
  27514. var secondDigit;
  27515. while (true) {
  27516. if (ch < 0) {
  27517. warn('Unterminated hex string');
  27518. break;
  27519. } else if (ch === 0x3E) { // '>'
  27520. this.nextChar();
  27521. break;
  27522. } else if (specialChars[ch] === 1) {
  27523. ch = this.nextChar();
  27524. continue;
  27525. } else {
  27526. if (isFirstHex) {
  27527. firstDigit = toHexDigit(ch);
  27528. if (firstDigit === -1) {
  27529. warn('Ignoring invalid character "' + ch + '" in hex string');
  27530. ch = this.nextChar();
  27531. continue;
  27532. }
  27533. } else {
  27534. secondDigit = toHexDigit(ch);
  27535. if (secondDigit === -1) {
  27536. warn('Ignoring invalid character "' + ch + '" in hex string');
  27537. ch = this.nextChar();
  27538. continue;
  27539. }
  27540. strBuf.push(String.fromCharCode((firstDigit << 4) | secondDigit));
  27541. }
  27542. isFirstHex = !isFirstHex;
  27543. ch = this.nextChar();
  27544. }
  27545. }
  27546. return strBuf.join('');
  27547. },
  27548. getObj: function Lexer_getObj() {
  27549. // skip whitespace and comments
  27550. var comment = false;
  27551. var ch = this.currentChar;
  27552. while (true) {
  27553. if (ch < 0) {
  27554. return EOF;
  27555. }
  27556. if (comment) {
  27557. if (ch === 0x0A || ch === 0x0D) { // LF, CR
  27558. comment = false;
  27559. }
  27560. } else if (ch === 0x25) { // '%'
  27561. comment = true;
  27562. } else if (specialChars[ch] !== 1) {
  27563. break;
  27564. }
  27565. ch = this.nextChar();
  27566. }
  27567. // start reading token
  27568. switch (ch | 0) {
  27569. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  27570. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  27571. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  27572. return this.getNumber();
  27573. case 0x28: // '('
  27574. return this.getString();
  27575. case 0x2F: // '/'
  27576. return this.getName();
  27577. // array punctuation
  27578. case 0x5B: // '['
  27579. this.nextChar();
  27580. return Cmd.get('[');
  27581. case 0x5D: // ']'
  27582. this.nextChar();
  27583. return Cmd.get(']');
  27584. // hex string or dict punctuation
  27585. case 0x3C: // '<'
  27586. ch = this.nextChar();
  27587. if (ch === 0x3C) {
  27588. // dict punctuation
  27589. this.nextChar();
  27590. return Cmd.get('<<');
  27591. }
  27592. return this.getHexString();
  27593. // dict punctuation
  27594. case 0x3E: // '>'
  27595. ch = this.nextChar();
  27596. if (ch === 0x3E) {
  27597. this.nextChar();
  27598. return Cmd.get('>>');
  27599. }
  27600. return Cmd.get('>');
  27601. case 0x7B: // '{'
  27602. this.nextChar();
  27603. return Cmd.get('{');
  27604. case 0x7D: // '}'
  27605. this.nextChar();
  27606. return Cmd.get('}');
  27607. case 0x29: // ')'
  27608. error('Illegal character: ' + ch);
  27609. break;
  27610. }
  27611. // command
  27612. var str = String.fromCharCode(ch);
  27613. var knownCommands = this.knownCommands;
  27614. var knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  27615. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  27616. // stop if known command is found and next character does not make
  27617. // the str a command
  27618. var possibleCommand = str + String.fromCharCode(ch);
  27619. if (knownCommandFound && knownCommands[possibleCommand] === undefined) {
  27620. break;
  27621. }
  27622. if (str.length === 128) {
  27623. error('Command token too long: ' + str.length);
  27624. }
  27625. str = possibleCommand;
  27626. knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  27627. }
  27628. if (str === 'true') {
  27629. return true;
  27630. }
  27631. if (str === 'false') {
  27632. return false;
  27633. }
  27634. if (str === 'null') {
  27635. return null;
  27636. }
  27637. return Cmd.get(str);
  27638. },
  27639. skipToNextLine: function Lexer_skipToNextLine() {
  27640. var ch = this.currentChar;
  27641. while (ch >= 0) {
  27642. if (ch === 0x0D) { // CR
  27643. ch = this.nextChar();
  27644. if (ch === 0x0A) { // LF
  27645. this.nextChar();
  27646. }
  27647. break;
  27648. } else if (ch === 0x0A) { // LF
  27649. this.nextChar();
  27650. break;
  27651. }
  27652. ch = this.nextChar();
  27653. }
  27654. }
  27655. };
  27656. return Lexer;
  27657. })();
  27658. var Linearization = {
  27659. create: function LinearizationCreate(stream) {
  27660. function getInt(name, allowZeroValue) {
  27661. var obj = linDict.get(name);
  27662. if (isInt(obj) && (allowZeroValue ? obj >= 0 : obj > 0)) {
  27663. return obj;
  27664. }
  27665. throw new Error('The "' + name + '" parameter in the linearization ' +
  27666. 'dictionary is invalid.');
  27667. }
  27668. function getHints() {
  27669. var hints = linDict.get('H'), hintsLength, item;
  27670. if (isArray(hints) &&
  27671. ((hintsLength = hints.length) === 2 || hintsLength === 4)) {
  27672. for (var index = 0; index < hintsLength; index++) {
  27673. if (!(isInt(item = hints[index]) && item > 0)) {
  27674. throw new Error('Hint (' + index +
  27675. ') in the linearization dictionary is invalid.');
  27676. }
  27677. }
  27678. return hints;
  27679. }
  27680. throw new Error('Hint array in the linearization dictionary is invalid.');
  27681. }
  27682. var parser = new Parser(new Lexer(stream), false, null);
  27683. var obj1 = parser.getObj();
  27684. var obj2 = parser.getObj();
  27685. var obj3 = parser.getObj();
  27686. var linDict = parser.getObj();
  27687. var obj, length;
  27688. if (!(isInt(obj1) && isInt(obj2) && isCmd(obj3, 'obj') && isDict(linDict) &&
  27689. isNum(obj = linDict.get('Linearized')) && obj > 0)) {
  27690. return null; // No valid linearization dictionary found.
  27691. } else if ((length = getInt('L')) !== stream.length) {
  27692. throw new Error('The "L" parameter in the linearization dictionary ' +
  27693. 'does not equal the stream length.');
  27694. }
  27695. return {
  27696. length: length,
  27697. hints: getHints(),
  27698. objectNumberFirst: getInt('O'),
  27699. endFirst: getInt('E'),
  27700. numPages: getInt('N'),
  27701. mainXRefEntriesOffset: getInt('T'),
  27702. pageFirst: (linDict.has('P') ? getInt('P', true) : 0)
  27703. };
  27704. }
  27705. };
  27706. var PostScriptParser = (function PostScriptParserClosure() {
  27707. function PostScriptParser(lexer) {
  27708. this.lexer = lexer;
  27709. this.operators = [];
  27710. this.token = null;
  27711. this.prev = null;
  27712. }
  27713. PostScriptParser.prototype = {
  27714. nextToken: function PostScriptParser_nextToken() {
  27715. this.prev = this.token;
  27716. this.token = this.lexer.getToken();
  27717. },
  27718. accept: function PostScriptParser_accept(type) {
  27719. if (this.token.type == type) {
  27720. this.nextToken();
  27721. return true;
  27722. }
  27723. return false;
  27724. },
  27725. expect: function PostScriptParser_expect(type) {
  27726. if (this.accept(type)) {
  27727. return true;
  27728. }
  27729. error('Unexpected symbol: found ' + this.token.type + ' expected ' +
  27730. type + '.');
  27731. },
  27732. parse: function PostScriptParser_parse() {
  27733. this.nextToken();
  27734. this.expect(PostScriptTokenTypes.LBRACE);
  27735. this.parseBlock();
  27736. this.expect(PostScriptTokenTypes.RBRACE);
  27737. return this.operators;
  27738. },
  27739. parseBlock: function PostScriptParser_parseBlock() {
  27740. while (true) {
  27741. if (this.accept(PostScriptTokenTypes.NUMBER)) {
  27742. this.operators.push(this.prev.value);
  27743. } else if (this.accept(PostScriptTokenTypes.OPERATOR)) {
  27744. this.operators.push(this.prev.value);
  27745. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  27746. this.parseCondition();
  27747. } else {
  27748. return;
  27749. }
  27750. }
  27751. },
  27752. parseCondition: function PostScriptParser_parseCondition() {
  27753. // Add two place holders that will be updated later
  27754. var conditionLocation = this.operators.length;
  27755. this.operators.push(null, null);
  27756. this.parseBlock();
  27757. this.expect(PostScriptTokenTypes.RBRACE);
  27758. if (this.accept(PostScriptTokenTypes.IF)) {
  27759. // The true block is right after the 'if' so it just falls through on
  27760. // true else it jumps and skips the true block.
  27761. this.operators[conditionLocation] = this.operators.length;
  27762. this.operators[conditionLocation + 1] = 'jz';
  27763. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  27764. var jumpLocation = this.operators.length;
  27765. this.operators.push(null, null);
  27766. var endOfTrue = this.operators.length;
  27767. this.parseBlock();
  27768. this.expect(PostScriptTokenTypes.RBRACE);
  27769. this.expect(PostScriptTokenTypes.IFELSE);
  27770. // The jump is added at the end of the true block to skip the false
  27771. // block.
  27772. this.operators[jumpLocation] = this.operators.length;
  27773. this.operators[jumpLocation + 1] = 'j';
  27774. this.operators[conditionLocation] = endOfTrue;
  27775. this.operators[conditionLocation + 1] = 'jz';
  27776. } else {
  27777. error('PS Function: error parsing conditional.');
  27778. }
  27779. }
  27780. };
  27781. return PostScriptParser;
  27782. })();
  27783. var PostScriptTokenTypes = {
  27784. LBRACE: 0,
  27785. RBRACE: 1,
  27786. NUMBER: 2,
  27787. OPERATOR: 3,
  27788. IF: 4,
  27789. IFELSE: 5
  27790. };
  27791. var PostScriptToken = (function PostScriptTokenClosure() {
  27792. function PostScriptToken(type, value) {
  27793. this.type = type;
  27794. this.value = value;
  27795. }
  27796. var opCache = {};
  27797. PostScriptToken.getOperator = function PostScriptToken_getOperator(op) {
  27798. var opValue = opCache[op];
  27799. if (opValue) {
  27800. return opValue;
  27801. }
  27802. return opCache[op] = new PostScriptToken(PostScriptTokenTypes.OPERATOR, op);
  27803. };
  27804. PostScriptToken.LBRACE = new PostScriptToken(PostScriptTokenTypes.LBRACE,
  27805. '{');
  27806. PostScriptToken.RBRACE = new PostScriptToken(PostScriptTokenTypes.RBRACE,
  27807. '}');
  27808. PostScriptToken.IF = new PostScriptToken(PostScriptTokenTypes.IF, 'IF');
  27809. PostScriptToken.IFELSE = new PostScriptToken(PostScriptTokenTypes.IFELSE,
  27810. 'IFELSE');
  27811. return PostScriptToken;
  27812. })();
  27813. var PostScriptLexer = (function PostScriptLexerClosure() {
  27814. function PostScriptLexer(stream) {
  27815. this.stream = stream;
  27816. this.nextChar();
  27817. this.strBuf = [];
  27818. }
  27819. PostScriptLexer.prototype = {
  27820. nextChar: function PostScriptLexer_nextChar() {
  27821. return (this.currentChar = this.stream.getByte());
  27822. },
  27823. getToken: function PostScriptLexer_getToken() {
  27824. var comment = false;
  27825. var ch = this.currentChar;
  27826. // skip comments
  27827. while (true) {
  27828. if (ch < 0) {
  27829. return EOF;
  27830. }
  27831. if (comment) {
  27832. if (ch === 0x0A || ch === 0x0D) {
  27833. comment = false;
  27834. }
  27835. } else if (ch == 0x25) { // '%'
  27836. comment = true;
  27837. } else if (!Lexer.isSpace(ch)) {
  27838. break;
  27839. }
  27840. ch = this.nextChar();
  27841. }
  27842. switch (ch | 0) {
  27843. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  27844. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  27845. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  27846. return new PostScriptToken(PostScriptTokenTypes.NUMBER,
  27847. this.getNumber());
  27848. case 0x7B: // '{'
  27849. this.nextChar();
  27850. return PostScriptToken.LBRACE;
  27851. case 0x7D: // '}'
  27852. this.nextChar();
  27853. return PostScriptToken.RBRACE;
  27854. }
  27855. // operator
  27856. var strBuf = this.strBuf;
  27857. strBuf.length = 0;
  27858. strBuf[0] = String.fromCharCode(ch);
  27859. while ((ch = this.nextChar()) >= 0 && // and 'A'-'Z', 'a'-'z'
  27860. ((ch >= 0x41 && ch <= 0x5A) || (ch >= 0x61 && ch <= 0x7A))) {
  27861. strBuf.push(String.fromCharCode(ch));
  27862. }
  27863. var str = strBuf.join('');
  27864. switch (str.toLowerCase()) {
  27865. case 'if':
  27866. return PostScriptToken.IF;
  27867. case 'ifelse':
  27868. return PostScriptToken.IFELSE;
  27869. default:
  27870. return PostScriptToken.getOperator(str);
  27871. }
  27872. },
  27873. getNumber: function PostScriptLexer_getNumber() {
  27874. var ch = this.currentChar;
  27875. var strBuf = this.strBuf;
  27876. strBuf.length = 0;
  27877. strBuf[0] = String.fromCharCode(ch);
  27878. while ((ch = this.nextChar()) >= 0) {
  27879. if ((ch >= 0x30 && ch <= 0x39) || // '0'-'9'
  27880. ch === 0x2D || ch === 0x2E) { // '-', '.'
  27881. strBuf.push(String.fromCharCode(ch));
  27882. } else {
  27883. break;
  27884. }
  27885. }
  27886. var value = parseFloat(strBuf.join(''));
  27887. if (isNaN(value)) {
  27888. error('Invalid floating point number: ' + value);
  27889. }
  27890. return value;
  27891. }
  27892. };
  27893. return PostScriptLexer;
  27894. })();
  27895. var Stream = (function StreamClosure() {
  27896. function Stream(arrayBuffer, start, length, dict) {
  27897. this.bytes = (arrayBuffer instanceof Uint8Array ?
  27898. arrayBuffer : new Uint8Array(arrayBuffer));
  27899. this.start = start || 0;
  27900. this.pos = this.start;
  27901. this.end = (start + length) || this.bytes.length;
  27902. this.dict = dict;
  27903. }
  27904. // required methods for a stream. if a particular stream does not
  27905. // implement these, an error should be thrown
  27906. Stream.prototype = {
  27907. get length() {
  27908. return this.end - this.start;
  27909. },
  27910. get isEmpty() {
  27911. return this.length === 0;
  27912. },
  27913. getByte: function Stream_getByte() {
  27914. if (this.pos >= this.end) {
  27915. return -1;
  27916. }
  27917. return this.bytes[this.pos++];
  27918. },
  27919. getUint16: function Stream_getUint16() {
  27920. var b0 = this.getByte();
  27921. var b1 = this.getByte();
  27922. return (b0 << 8) + b1;
  27923. },
  27924. getInt32: function Stream_getInt32() {
  27925. var b0 = this.getByte();
  27926. var b1 = this.getByte();
  27927. var b2 = this.getByte();
  27928. var b3 = this.getByte();
  27929. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  27930. },
  27931. // returns subarray of original buffer
  27932. // should only be read
  27933. getBytes: function Stream_getBytes(length) {
  27934. var bytes = this.bytes;
  27935. var pos = this.pos;
  27936. var strEnd = this.end;
  27937. if (!length) {
  27938. return bytes.subarray(pos, strEnd);
  27939. }
  27940. var end = pos + length;
  27941. if (end > strEnd) {
  27942. end = strEnd;
  27943. }
  27944. this.pos = end;
  27945. return bytes.subarray(pos, end);
  27946. },
  27947. peekBytes: function Stream_peekBytes(length) {
  27948. var bytes = this.getBytes(length);
  27949. this.pos -= bytes.length;
  27950. return bytes;
  27951. },
  27952. skip: function Stream_skip(n) {
  27953. if (!n) {
  27954. n = 1;
  27955. }
  27956. this.pos += n;
  27957. },
  27958. reset: function Stream_reset() {
  27959. this.pos = this.start;
  27960. },
  27961. moveStart: function Stream_moveStart() {
  27962. this.start = this.pos;
  27963. },
  27964. makeSubStream: function Stream_makeSubStream(start, length, dict) {
  27965. return new Stream(this.bytes.buffer, start, length, dict);
  27966. },
  27967. isStream: true
  27968. };
  27969. return Stream;
  27970. })();
  27971. var StringStream = (function StringStreamClosure() {
  27972. function StringStream(str) {
  27973. var length = str.length;
  27974. var bytes = new Uint8Array(length);
  27975. for (var n = 0; n < length; ++n) {
  27976. bytes[n] = str.charCodeAt(n);
  27977. }
  27978. Stream.call(this, bytes);
  27979. }
  27980. StringStream.prototype = Stream.prototype;
  27981. return StringStream;
  27982. })();
  27983. // super class for the decoding streams
  27984. var DecodeStream = (function DecodeStreamClosure() {
  27985. // Lots of DecodeStreams are created whose buffers are never used. For these
  27986. // we share a single empty buffer. This is (a) space-efficient and (b) avoids
  27987. // having special cases that would be required if we used |null| for an empty
  27988. // buffer.
  27989. var emptyBuffer = new Uint8Array(0);
  27990. function DecodeStream(maybeMinBufferLength) {
  27991. this.pos = 0;
  27992. this.bufferLength = 0;
  27993. this.eof = false;
  27994. this.buffer = emptyBuffer;
  27995. this.minBufferLength = 512;
  27996. if (maybeMinBufferLength) {
  27997. // Compute the first power of two that is as big as maybeMinBufferLength.
  27998. while (this.minBufferLength < maybeMinBufferLength) {
  27999. this.minBufferLength *= 2;
  28000. }
  28001. }
  28002. }
  28003. DecodeStream.prototype = {
  28004. get isEmpty() {
  28005. while (!this.eof && this.bufferLength === 0) {
  28006. this.readBlock();
  28007. }
  28008. return this.bufferLength === 0;
  28009. },
  28010. ensureBuffer: function DecodeStream_ensureBuffer(requested) {
  28011. var buffer = this.buffer;
  28012. if (requested <= buffer.byteLength) {
  28013. return buffer;
  28014. }
  28015. var size = this.minBufferLength;
  28016. while (size < requested) {
  28017. size *= 2;
  28018. }
  28019. var buffer2 = new Uint8Array(size);
  28020. buffer2.set(buffer);
  28021. return (this.buffer = buffer2);
  28022. },
  28023. getByte: function DecodeStream_getByte() {
  28024. var pos = this.pos;
  28025. while (this.bufferLength <= pos) {
  28026. if (this.eof) {
  28027. return -1;
  28028. }
  28029. this.readBlock();
  28030. }
  28031. return this.buffer[this.pos++];
  28032. },
  28033. getUint16: function DecodeStream_getUint16() {
  28034. var b0 = this.getByte();
  28035. var b1 = this.getByte();
  28036. return (b0 << 8) + b1;
  28037. },
  28038. getInt32: function DecodeStream_getInt32() {
  28039. var b0 = this.getByte();
  28040. var b1 = this.getByte();
  28041. var b2 = this.getByte();
  28042. var b3 = this.getByte();
  28043. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  28044. },
  28045. getBytes: function DecodeStream_getBytes(length) {
  28046. var end, pos = this.pos;
  28047. if (length) {
  28048. this.ensureBuffer(pos + length);
  28049. end = pos + length;
  28050. while (!this.eof && this.bufferLength < end) {
  28051. this.readBlock();
  28052. }
  28053. var bufEnd = this.bufferLength;
  28054. if (end > bufEnd) {
  28055. end = bufEnd;
  28056. }
  28057. } else {
  28058. while (!this.eof) {
  28059. this.readBlock();
  28060. }
  28061. end = this.bufferLength;
  28062. }
  28063. this.pos = end;
  28064. return this.buffer.subarray(pos, end);
  28065. },
  28066. peekBytes: function DecodeStream_peekBytes(length) {
  28067. var bytes = this.getBytes(length);
  28068. this.pos -= bytes.length;
  28069. return bytes;
  28070. },
  28071. makeSubStream: function DecodeStream_makeSubStream(start, length, dict) {
  28072. var end = start + length;
  28073. while (this.bufferLength <= end && !this.eof) {
  28074. this.readBlock();
  28075. }
  28076. return new Stream(this.buffer, start, length, dict);
  28077. },
  28078. skip: function DecodeStream_skip(n) {
  28079. if (!n) {
  28080. n = 1;
  28081. }
  28082. this.pos += n;
  28083. },
  28084. reset: function DecodeStream_reset() {
  28085. this.pos = 0;
  28086. },
  28087. getBaseStreams: function DecodeStream_getBaseStreams() {
  28088. if (this.str && this.str.getBaseStreams) {
  28089. return this.str.getBaseStreams();
  28090. }
  28091. return [];
  28092. }
  28093. };
  28094. return DecodeStream;
  28095. })();
  28096. var StreamsSequenceStream = (function StreamsSequenceStreamClosure() {
  28097. function StreamsSequenceStream(streams) {
  28098. this.streams = streams;
  28099. DecodeStream.call(this, /* maybeLength = */ null);
  28100. }
  28101. StreamsSequenceStream.prototype = Object.create(DecodeStream.prototype);
  28102. StreamsSequenceStream.prototype.readBlock =
  28103. function streamSequenceStreamReadBlock() {
  28104. var streams = this.streams;
  28105. if (streams.length === 0) {
  28106. this.eof = true;
  28107. return;
  28108. }
  28109. var stream = streams.shift();
  28110. var chunk = stream.getBytes();
  28111. var bufferLength = this.bufferLength;
  28112. var newLength = bufferLength + chunk.length;
  28113. var buffer = this.ensureBuffer(newLength);
  28114. buffer.set(chunk, bufferLength);
  28115. this.bufferLength = newLength;
  28116. };
  28117. StreamsSequenceStream.prototype.getBaseStreams =
  28118. function StreamsSequenceStream_getBaseStreams() {
  28119. var baseStreams = [];
  28120. for (var i = 0, ii = this.streams.length; i < ii; i++) {
  28121. var stream = this.streams[i];
  28122. if (stream.getBaseStreams) {
  28123. Util.appendToArray(baseStreams, stream.getBaseStreams());
  28124. }
  28125. }
  28126. return baseStreams;
  28127. };
  28128. return StreamsSequenceStream;
  28129. })();
  28130. var FlateStream = (function FlateStreamClosure() {
  28131. var codeLenCodeMap = new Uint32Array([
  28132. 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
  28133. ]);
  28134. var lengthDecode = new Uint32Array([
  28135. 0x00003, 0x00004, 0x00005, 0x00006, 0x00007, 0x00008, 0x00009, 0x0000a,
  28136. 0x1000b, 0x1000d, 0x1000f, 0x10011, 0x20013, 0x20017, 0x2001b, 0x2001f,
  28137. 0x30023, 0x3002b, 0x30033, 0x3003b, 0x40043, 0x40053, 0x40063, 0x40073,
  28138. 0x50083, 0x500a3, 0x500c3, 0x500e3, 0x00102, 0x00102, 0x00102
  28139. ]);
  28140. var distDecode = new Uint32Array([
  28141. 0x00001, 0x00002, 0x00003, 0x00004, 0x10005, 0x10007, 0x20009, 0x2000d,
  28142. 0x30011, 0x30019, 0x40021, 0x40031, 0x50041, 0x50061, 0x60081, 0x600c1,
  28143. 0x70101, 0x70181, 0x80201, 0x80301, 0x90401, 0x90601, 0xa0801, 0xa0c01,
  28144. 0xb1001, 0xb1801, 0xc2001, 0xc3001, 0xd4001, 0xd6001
  28145. ]);
  28146. var fixedLitCodeTab = [new Uint32Array([
  28147. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c0,
  28148. 0x70108, 0x80060, 0x80020, 0x900a0, 0x80000, 0x80080, 0x80040, 0x900e0,
  28149. 0x70104, 0x80058, 0x80018, 0x90090, 0x70114, 0x80078, 0x80038, 0x900d0,
  28150. 0x7010c, 0x80068, 0x80028, 0x900b0, 0x80008, 0x80088, 0x80048, 0x900f0,
  28151. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c8,
  28152. 0x7010a, 0x80064, 0x80024, 0x900a8, 0x80004, 0x80084, 0x80044, 0x900e8,
  28153. 0x70106, 0x8005c, 0x8001c, 0x90098, 0x70116, 0x8007c, 0x8003c, 0x900d8,
  28154. 0x7010e, 0x8006c, 0x8002c, 0x900b8, 0x8000c, 0x8008c, 0x8004c, 0x900f8,
  28155. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c4,
  28156. 0x70109, 0x80062, 0x80022, 0x900a4, 0x80002, 0x80082, 0x80042, 0x900e4,
  28157. 0x70105, 0x8005a, 0x8001a, 0x90094, 0x70115, 0x8007a, 0x8003a, 0x900d4,
  28158. 0x7010d, 0x8006a, 0x8002a, 0x900b4, 0x8000a, 0x8008a, 0x8004a, 0x900f4,
  28159. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cc,
  28160. 0x7010b, 0x80066, 0x80026, 0x900ac, 0x80006, 0x80086, 0x80046, 0x900ec,
  28161. 0x70107, 0x8005e, 0x8001e, 0x9009c, 0x70117, 0x8007e, 0x8003e, 0x900dc,
  28162. 0x7010f, 0x8006e, 0x8002e, 0x900bc, 0x8000e, 0x8008e, 0x8004e, 0x900fc,
  28163. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c2,
  28164. 0x70108, 0x80061, 0x80021, 0x900a2, 0x80001, 0x80081, 0x80041, 0x900e2,
  28165. 0x70104, 0x80059, 0x80019, 0x90092, 0x70114, 0x80079, 0x80039, 0x900d2,
  28166. 0x7010c, 0x80069, 0x80029, 0x900b2, 0x80009, 0x80089, 0x80049, 0x900f2,
  28167. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900ca,
  28168. 0x7010a, 0x80065, 0x80025, 0x900aa, 0x80005, 0x80085, 0x80045, 0x900ea,
  28169. 0x70106, 0x8005d, 0x8001d, 0x9009a, 0x70116, 0x8007d, 0x8003d, 0x900da,
  28170. 0x7010e, 0x8006d, 0x8002d, 0x900ba, 0x8000d, 0x8008d, 0x8004d, 0x900fa,
  28171. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c6,
  28172. 0x70109, 0x80063, 0x80023, 0x900a6, 0x80003, 0x80083, 0x80043, 0x900e6,
  28173. 0x70105, 0x8005b, 0x8001b, 0x90096, 0x70115, 0x8007b, 0x8003b, 0x900d6,
  28174. 0x7010d, 0x8006b, 0x8002b, 0x900b6, 0x8000b, 0x8008b, 0x8004b, 0x900f6,
  28175. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900ce,
  28176. 0x7010b, 0x80067, 0x80027, 0x900ae, 0x80007, 0x80087, 0x80047, 0x900ee,
  28177. 0x70107, 0x8005f, 0x8001f, 0x9009e, 0x70117, 0x8007f, 0x8003f, 0x900de,
  28178. 0x7010f, 0x8006f, 0x8002f, 0x900be, 0x8000f, 0x8008f, 0x8004f, 0x900fe,
  28179. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c1,
  28180. 0x70108, 0x80060, 0x80020, 0x900a1, 0x80000, 0x80080, 0x80040, 0x900e1,
  28181. 0x70104, 0x80058, 0x80018, 0x90091, 0x70114, 0x80078, 0x80038, 0x900d1,
  28182. 0x7010c, 0x80068, 0x80028, 0x900b1, 0x80008, 0x80088, 0x80048, 0x900f1,
  28183. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c9,
  28184. 0x7010a, 0x80064, 0x80024, 0x900a9, 0x80004, 0x80084, 0x80044, 0x900e9,
  28185. 0x70106, 0x8005c, 0x8001c, 0x90099, 0x70116, 0x8007c, 0x8003c, 0x900d9,
  28186. 0x7010e, 0x8006c, 0x8002c, 0x900b9, 0x8000c, 0x8008c, 0x8004c, 0x900f9,
  28187. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c5,
  28188. 0x70109, 0x80062, 0x80022, 0x900a5, 0x80002, 0x80082, 0x80042, 0x900e5,
  28189. 0x70105, 0x8005a, 0x8001a, 0x90095, 0x70115, 0x8007a, 0x8003a, 0x900d5,
  28190. 0x7010d, 0x8006a, 0x8002a, 0x900b5, 0x8000a, 0x8008a, 0x8004a, 0x900f5,
  28191. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cd,
  28192. 0x7010b, 0x80066, 0x80026, 0x900ad, 0x80006, 0x80086, 0x80046, 0x900ed,
  28193. 0x70107, 0x8005e, 0x8001e, 0x9009d, 0x70117, 0x8007e, 0x8003e, 0x900dd,
  28194. 0x7010f, 0x8006e, 0x8002e, 0x900bd, 0x8000e, 0x8008e, 0x8004e, 0x900fd,
  28195. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c3,
  28196. 0x70108, 0x80061, 0x80021, 0x900a3, 0x80001, 0x80081, 0x80041, 0x900e3,
  28197. 0x70104, 0x80059, 0x80019, 0x90093, 0x70114, 0x80079, 0x80039, 0x900d3,
  28198. 0x7010c, 0x80069, 0x80029, 0x900b3, 0x80009, 0x80089, 0x80049, 0x900f3,
  28199. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900cb,
  28200. 0x7010a, 0x80065, 0x80025, 0x900ab, 0x80005, 0x80085, 0x80045, 0x900eb,
  28201. 0x70106, 0x8005d, 0x8001d, 0x9009b, 0x70116, 0x8007d, 0x8003d, 0x900db,
  28202. 0x7010e, 0x8006d, 0x8002d, 0x900bb, 0x8000d, 0x8008d, 0x8004d, 0x900fb,
  28203. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c7,
  28204. 0x70109, 0x80063, 0x80023, 0x900a7, 0x80003, 0x80083, 0x80043, 0x900e7,
  28205. 0x70105, 0x8005b, 0x8001b, 0x90097, 0x70115, 0x8007b, 0x8003b, 0x900d7,
  28206. 0x7010d, 0x8006b, 0x8002b, 0x900b7, 0x8000b, 0x8008b, 0x8004b, 0x900f7,
  28207. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900cf,
  28208. 0x7010b, 0x80067, 0x80027, 0x900af, 0x80007, 0x80087, 0x80047, 0x900ef,
  28209. 0x70107, 0x8005f, 0x8001f, 0x9009f, 0x70117, 0x8007f, 0x8003f, 0x900df,
  28210. 0x7010f, 0x8006f, 0x8002f, 0x900bf, 0x8000f, 0x8008f, 0x8004f, 0x900ff
  28211. ]), 9];
  28212. var fixedDistCodeTab = [new Uint32Array([
  28213. 0x50000, 0x50010, 0x50008, 0x50018, 0x50004, 0x50014, 0x5000c, 0x5001c,
  28214. 0x50002, 0x50012, 0x5000a, 0x5001a, 0x50006, 0x50016, 0x5000e, 0x00000,
  28215. 0x50001, 0x50011, 0x50009, 0x50019, 0x50005, 0x50015, 0x5000d, 0x5001d,
  28216. 0x50003, 0x50013, 0x5000b, 0x5001b, 0x50007, 0x50017, 0x5000f, 0x00000
  28217. ]), 5];
  28218. function FlateStream(str, maybeLength) {
  28219. this.str = str;
  28220. this.dict = str.dict;
  28221. var cmf = str.getByte();
  28222. var flg = str.getByte();
  28223. if (cmf == -1 || flg == -1) {
  28224. error('Invalid header in flate stream: ' + cmf + ', ' + flg);
  28225. }
  28226. if ((cmf & 0x0f) != 0x08) {
  28227. error('Unknown compression method in flate stream: ' + cmf + ', ' + flg);
  28228. }
  28229. if ((((cmf << 8) + flg) % 31) !== 0) {
  28230. error('Bad FCHECK in flate stream: ' + cmf + ', ' + flg);
  28231. }
  28232. if (flg & 0x20) {
  28233. error('FDICT bit set in flate stream: ' + cmf + ', ' + flg);
  28234. }
  28235. this.codeSize = 0;
  28236. this.codeBuf = 0;
  28237. DecodeStream.call(this, maybeLength);
  28238. }
  28239. FlateStream.prototype = Object.create(DecodeStream.prototype);
  28240. FlateStream.prototype.getBits = function FlateStream_getBits(bits) {
  28241. var str = this.str;
  28242. var codeSize = this.codeSize;
  28243. var codeBuf = this.codeBuf;
  28244. var b;
  28245. while (codeSize < bits) {
  28246. if ((b = str.getByte()) === -1) {
  28247. error('Bad encoding in flate stream');
  28248. }
  28249. codeBuf |= b << codeSize;
  28250. codeSize += 8;
  28251. }
  28252. b = codeBuf & ((1 << bits) - 1);
  28253. this.codeBuf = codeBuf >> bits;
  28254. this.codeSize = codeSize -= bits;
  28255. return b;
  28256. };
  28257. FlateStream.prototype.getCode = function FlateStream_getCode(table) {
  28258. var str = this.str;
  28259. var codes = table[0];
  28260. var maxLen = table[1];
  28261. var codeSize = this.codeSize;
  28262. var codeBuf = this.codeBuf;
  28263. var b;
  28264. while (codeSize < maxLen) {
  28265. if ((b = str.getByte()) === -1) {
  28266. // premature end of stream. code might however still be valid.
  28267. // codeSize < codeLen check below guards against incomplete codeVal.
  28268. break;
  28269. }
  28270. codeBuf |= (b << codeSize);
  28271. codeSize += 8;
  28272. }
  28273. var code = codes[codeBuf & ((1 << maxLen) - 1)];
  28274. var codeLen = code >> 16;
  28275. var codeVal = code & 0xffff;
  28276. if (codeLen < 1 || codeSize < codeLen) {
  28277. error('Bad encoding in flate stream');
  28278. }
  28279. this.codeBuf = (codeBuf >> codeLen);
  28280. this.codeSize = (codeSize - codeLen);
  28281. return codeVal;
  28282. };
  28283. FlateStream.prototype.generateHuffmanTable =
  28284. function flateStreamGenerateHuffmanTable(lengths) {
  28285. var n = lengths.length;
  28286. // find max code length
  28287. var maxLen = 0;
  28288. var i;
  28289. for (i = 0; i < n; ++i) {
  28290. if (lengths[i] > maxLen) {
  28291. maxLen = lengths[i];
  28292. }
  28293. }
  28294. // build the table
  28295. var size = 1 << maxLen;
  28296. var codes = new Uint32Array(size);
  28297. for (var len = 1, code = 0, skip = 2;
  28298. len <= maxLen;
  28299. ++len, code <<= 1, skip <<= 1) {
  28300. for (var val = 0; val < n; ++val) {
  28301. if (lengths[val] == len) {
  28302. // bit-reverse the code
  28303. var code2 = 0;
  28304. var t = code;
  28305. for (i = 0; i < len; ++i) {
  28306. code2 = (code2 << 1) | (t & 1);
  28307. t >>= 1;
  28308. }
  28309. // fill the table entries
  28310. for (i = code2; i < size; i += skip) {
  28311. codes[i] = (len << 16) | val;
  28312. }
  28313. ++code;
  28314. }
  28315. }
  28316. }
  28317. return [codes, maxLen];
  28318. };
  28319. FlateStream.prototype.readBlock = function FlateStream_readBlock() {
  28320. var buffer, len;
  28321. var str = this.str;
  28322. // read block header
  28323. var hdr = this.getBits(3);
  28324. if (hdr & 1) {
  28325. this.eof = true;
  28326. }
  28327. hdr >>= 1;
  28328. if (hdr === 0) { // uncompressed block
  28329. var b;
  28330. if ((b = str.getByte()) === -1) {
  28331. error('Bad block header in flate stream');
  28332. }
  28333. var blockLen = b;
  28334. if ((b = str.getByte()) === -1) {
  28335. error('Bad block header in flate stream');
  28336. }
  28337. blockLen |= (b << 8);
  28338. if ((b = str.getByte()) === -1) {
  28339. error('Bad block header in flate stream');
  28340. }
  28341. var check = b;
  28342. if ((b = str.getByte()) === -1) {
  28343. error('Bad block header in flate stream');
  28344. }
  28345. check |= (b << 8);
  28346. if (check != (~blockLen & 0xffff) &&
  28347. (blockLen !== 0 || check !== 0)) {
  28348. // Ignoring error for bad "empty" block (see issue 1277)
  28349. error('Bad uncompressed block length in flate stream');
  28350. }
  28351. this.codeBuf = 0;
  28352. this.codeSize = 0;
  28353. var bufferLength = this.bufferLength;
  28354. buffer = this.ensureBuffer(bufferLength + blockLen);
  28355. var end = bufferLength + blockLen;
  28356. this.bufferLength = end;
  28357. if (blockLen === 0) {
  28358. if (str.peekBytes(1).length === 0) {
  28359. this.eof = true;
  28360. }
  28361. } else {
  28362. for (var n = bufferLength; n < end; ++n) {
  28363. if ((b = str.getByte()) === -1) {
  28364. this.eof = true;
  28365. break;
  28366. }
  28367. buffer[n] = b;
  28368. }
  28369. }
  28370. return;
  28371. }
  28372. var litCodeTable;
  28373. var distCodeTable;
  28374. if (hdr == 1) { // compressed block, fixed codes
  28375. litCodeTable = fixedLitCodeTab;
  28376. distCodeTable = fixedDistCodeTab;
  28377. } else if (hdr == 2) { // compressed block, dynamic codes
  28378. var numLitCodes = this.getBits(5) + 257;
  28379. var numDistCodes = this.getBits(5) + 1;
  28380. var numCodeLenCodes = this.getBits(4) + 4;
  28381. // build the code lengths code table
  28382. var codeLenCodeLengths = new Uint8Array(codeLenCodeMap.length);
  28383. var i;
  28384. for (i = 0; i < numCodeLenCodes; ++i) {
  28385. codeLenCodeLengths[codeLenCodeMap[i]] = this.getBits(3);
  28386. }
  28387. var codeLenCodeTab = this.generateHuffmanTable(codeLenCodeLengths);
  28388. // build the literal and distance code tables
  28389. len = 0;
  28390. i = 0;
  28391. var codes = numLitCodes + numDistCodes;
  28392. var codeLengths = new Uint8Array(codes);
  28393. var bitsLength, bitsOffset, what;
  28394. while (i < codes) {
  28395. var code = this.getCode(codeLenCodeTab);
  28396. if (code == 16) {
  28397. bitsLength = 2; bitsOffset = 3; what = len;
  28398. } else if (code == 17) {
  28399. bitsLength = 3; bitsOffset = 3; what = (len = 0);
  28400. } else if (code == 18) {
  28401. bitsLength = 7; bitsOffset = 11; what = (len = 0);
  28402. } else {
  28403. codeLengths[i++] = len = code;
  28404. continue;
  28405. }
  28406. var repeatLength = this.getBits(bitsLength) + bitsOffset;
  28407. while (repeatLength-- > 0) {
  28408. codeLengths[i++] = what;
  28409. }
  28410. }
  28411. litCodeTable =
  28412. this.generateHuffmanTable(codeLengths.subarray(0, numLitCodes));
  28413. distCodeTable =
  28414. this.generateHuffmanTable(codeLengths.subarray(numLitCodes, codes));
  28415. } else {
  28416. error('Unknown block type in flate stream');
  28417. }
  28418. buffer = this.buffer;
  28419. var limit = buffer ? buffer.length : 0;
  28420. var pos = this.bufferLength;
  28421. while (true) {
  28422. var code1 = this.getCode(litCodeTable);
  28423. if (code1 < 256) {
  28424. if (pos + 1 >= limit) {
  28425. buffer = this.ensureBuffer(pos + 1);
  28426. limit = buffer.length;
  28427. }
  28428. buffer[pos++] = code1;
  28429. continue;
  28430. }
  28431. if (code1 == 256) {
  28432. this.bufferLength = pos;
  28433. return;
  28434. }
  28435. code1 -= 257;
  28436. code1 = lengthDecode[code1];
  28437. var code2 = code1 >> 16;
  28438. if (code2 > 0) {
  28439. code2 = this.getBits(code2);
  28440. }
  28441. len = (code1 & 0xffff) + code2;
  28442. code1 = this.getCode(distCodeTable);
  28443. code1 = distDecode[code1];
  28444. code2 = code1 >> 16;
  28445. if (code2 > 0) {
  28446. code2 = this.getBits(code2);
  28447. }
  28448. var dist = (code1 & 0xffff) + code2;
  28449. if (pos + len >= limit) {
  28450. buffer = this.ensureBuffer(pos + len);
  28451. limit = buffer.length;
  28452. }
  28453. for (var k = 0; k < len; ++k, ++pos) {
  28454. buffer[pos] = buffer[pos - dist];
  28455. }
  28456. }
  28457. };
  28458. return FlateStream;
  28459. })();
  28460. var PredictorStream = (function PredictorStreamClosure() {
  28461. function PredictorStream(str, maybeLength, params) {
  28462. var predictor = this.predictor = params.get('Predictor') || 1;
  28463. if (predictor <= 1) {
  28464. return str; // no prediction
  28465. }
  28466. if (predictor !== 2 && (predictor < 10 || predictor > 15)) {
  28467. error('Unsupported predictor: ' + predictor);
  28468. }
  28469. if (predictor === 2) {
  28470. this.readBlock = this.readBlockTiff;
  28471. } else {
  28472. this.readBlock = this.readBlockPng;
  28473. }
  28474. this.str = str;
  28475. this.dict = str.dict;
  28476. var colors = this.colors = params.get('Colors') || 1;
  28477. var bits = this.bits = params.get('BitsPerComponent') || 8;
  28478. var columns = this.columns = params.get('Columns') || 1;
  28479. this.pixBytes = (colors * bits + 7) >> 3;
  28480. this.rowBytes = (columns * colors * bits + 7) >> 3;
  28481. DecodeStream.call(this, maybeLength);
  28482. return this;
  28483. }
  28484. PredictorStream.prototype = Object.create(DecodeStream.prototype);
  28485. PredictorStream.prototype.readBlockTiff =
  28486. function predictorStreamReadBlockTiff() {
  28487. var rowBytes = this.rowBytes;
  28488. var bufferLength = this.bufferLength;
  28489. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  28490. var bits = this.bits;
  28491. var colors = this.colors;
  28492. var rawBytes = this.str.getBytes(rowBytes);
  28493. this.eof = !rawBytes.length;
  28494. if (this.eof) {
  28495. return;
  28496. }
  28497. var inbuf = 0, outbuf = 0;
  28498. var inbits = 0, outbits = 0;
  28499. var pos = bufferLength;
  28500. var i;
  28501. if (bits === 1) {
  28502. for (i = 0; i < rowBytes; ++i) {
  28503. var c = rawBytes[i];
  28504. inbuf = (inbuf << 8) | c;
  28505. // bitwise addition is exclusive or
  28506. // first shift inbuf and then add
  28507. buffer[pos++] = (c ^ (inbuf >> colors)) & 0xFF;
  28508. // truncate inbuf (assumes colors < 16)
  28509. inbuf &= 0xFFFF;
  28510. }
  28511. } else if (bits === 8) {
  28512. for (i = 0; i < colors; ++i) {
  28513. buffer[pos++] = rawBytes[i];
  28514. }
  28515. for (; i < rowBytes; ++i) {
  28516. buffer[pos] = buffer[pos - colors] + rawBytes[i];
  28517. pos++;
  28518. }
  28519. } else {
  28520. var compArray = new Uint8Array(colors + 1);
  28521. var bitMask = (1 << bits) - 1;
  28522. var j = 0, k = bufferLength;
  28523. var columns = this.columns;
  28524. for (i = 0; i < columns; ++i) {
  28525. for (var kk = 0; kk < colors; ++kk) {
  28526. if (inbits < bits) {
  28527. inbuf = (inbuf << 8) | (rawBytes[j++] & 0xFF);
  28528. inbits += 8;
  28529. }
  28530. compArray[kk] = (compArray[kk] +
  28531. (inbuf >> (inbits - bits))) & bitMask;
  28532. inbits -= bits;
  28533. outbuf = (outbuf << bits) | compArray[kk];
  28534. outbits += bits;
  28535. if (outbits >= 8) {
  28536. buffer[k++] = (outbuf >> (outbits - 8)) & 0xFF;
  28537. outbits -= 8;
  28538. }
  28539. }
  28540. }
  28541. if (outbits > 0) {
  28542. buffer[k++] = (outbuf << (8 - outbits)) +
  28543. (inbuf & ((1 << (8 - outbits)) - 1));
  28544. }
  28545. }
  28546. this.bufferLength += rowBytes;
  28547. };
  28548. PredictorStream.prototype.readBlockPng =
  28549. function predictorStreamReadBlockPng() {
  28550. var rowBytes = this.rowBytes;
  28551. var pixBytes = this.pixBytes;
  28552. var predictor = this.str.getByte();
  28553. var rawBytes = this.str.getBytes(rowBytes);
  28554. this.eof = !rawBytes.length;
  28555. if (this.eof) {
  28556. return;
  28557. }
  28558. var bufferLength = this.bufferLength;
  28559. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  28560. var prevRow = buffer.subarray(bufferLength - rowBytes, bufferLength);
  28561. if (prevRow.length === 0) {
  28562. prevRow = new Uint8Array(rowBytes);
  28563. }
  28564. var i, j = bufferLength, up, c;
  28565. switch (predictor) {
  28566. case 0:
  28567. for (i = 0; i < rowBytes; ++i) {
  28568. buffer[j++] = rawBytes[i];
  28569. }
  28570. break;
  28571. case 1:
  28572. for (i = 0; i < pixBytes; ++i) {
  28573. buffer[j++] = rawBytes[i];
  28574. }
  28575. for (; i < rowBytes; ++i) {
  28576. buffer[j] = (buffer[j - pixBytes] + rawBytes[i]) & 0xFF;
  28577. j++;
  28578. }
  28579. break;
  28580. case 2:
  28581. for (i = 0; i < rowBytes; ++i) {
  28582. buffer[j++] = (prevRow[i] + rawBytes[i]) & 0xFF;
  28583. }
  28584. break;
  28585. case 3:
  28586. for (i = 0; i < pixBytes; ++i) {
  28587. buffer[j++] = (prevRow[i] >> 1) + rawBytes[i];
  28588. }
  28589. for (; i < rowBytes; ++i) {
  28590. buffer[j] = (((prevRow[i] + buffer[j - pixBytes]) >> 1) +
  28591. rawBytes[i]) & 0xFF;
  28592. j++;
  28593. }
  28594. break;
  28595. case 4:
  28596. // we need to save the up left pixels values. the simplest way
  28597. // is to create a new buffer
  28598. for (i = 0; i < pixBytes; ++i) {
  28599. up = prevRow[i];
  28600. c = rawBytes[i];
  28601. buffer[j++] = up + c;
  28602. }
  28603. for (; i < rowBytes; ++i) {
  28604. up = prevRow[i];
  28605. var upLeft = prevRow[i - pixBytes];
  28606. var left = buffer[j - pixBytes];
  28607. var p = left + up - upLeft;
  28608. var pa = p - left;
  28609. if (pa < 0) {
  28610. pa = -pa;
  28611. }
  28612. var pb = p - up;
  28613. if (pb < 0) {
  28614. pb = -pb;
  28615. }
  28616. var pc = p - upLeft;
  28617. if (pc < 0) {
  28618. pc = -pc;
  28619. }
  28620. c = rawBytes[i];
  28621. if (pa <= pb && pa <= pc) {
  28622. buffer[j++] = left + c;
  28623. } else if (pb <= pc) {
  28624. buffer[j++] = up + c;
  28625. } else {
  28626. buffer[j++] = upLeft + c;
  28627. }
  28628. }
  28629. break;
  28630. default:
  28631. error('Unsupported predictor: ' + predictor);
  28632. }
  28633. this.bufferLength += rowBytes;
  28634. };
  28635. return PredictorStream;
  28636. })();
  28637. /**
  28638. * Depending on the type of JPEG a JpegStream is handled in different ways. For
  28639. * JPEG's that are supported natively such as DeviceGray and DeviceRGB the image
  28640. * data is stored and then loaded by the browser. For unsupported JPEG's we use
  28641. * a library to decode these images and the stream behaves like all the other
  28642. * DecodeStreams.
  28643. */
  28644. var JpegStream = (function JpegStreamClosure() {
  28645. function JpegStream(stream, maybeLength, dict, xref) {
  28646. // TODO: per poppler, some images may have 'junk' before that
  28647. // need to be removed
  28648. this.stream = stream;
  28649. this.maybeLength = maybeLength;
  28650. this.dict = dict;
  28651. DecodeStream.call(this, maybeLength);
  28652. }
  28653. JpegStream.prototype = Object.create(DecodeStream.prototype);
  28654. Object.defineProperty(JpegStream.prototype, 'bytes', {
  28655. get: function JpegStream_bytes() {
  28656. // If this.maybeLength is null, we'll get the entire stream.
  28657. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  28658. },
  28659. configurable: true
  28660. });
  28661. JpegStream.prototype.ensureBuffer = function JpegStream_ensureBuffer(req) {
  28662. if (this.bufferLength) {
  28663. return;
  28664. }
  28665. try {
  28666. var jpegImage = new JpegImage();
  28667. // checking if values needs to be transformed before conversion
  28668. if (this.dict && isArray(this.dict.get('Decode'))) {
  28669. var decodeArr = this.dict.get('Decode');
  28670. var bitsPerComponent = this.dict.get('BitsPerComponent') || 8;
  28671. var decodeArrLength = decodeArr.length;
  28672. var transform = new Int32Array(decodeArrLength);
  28673. var transformNeeded = false;
  28674. var maxValue = (1 << bitsPerComponent) - 1;
  28675. for (var i = 0; i < decodeArrLength; i += 2) {
  28676. transform[i] = ((decodeArr[i + 1] - decodeArr[i]) * 256) | 0;
  28677. transform[i + 1] = (decodeArr[i] * maxValue) | 0;
  28678. if (transform[i] !== 256 || transform[i + 1] !== 0) {
  28679. transformNeeded = true;
  28680. }
  28681. }
  28682. if (transformNeeded) {
  28683. jpegImage.decodeTransform = transform;
  28684. }
  28685. }
  28686. jpegImage.parse(this.bytes);
  28687. var data = jpegImage.getData(this.drawWidth, this.drawHeight,
  28688. this.forceRGB);
  28689. this.buffer = data;
  28690. this.bufferLength = data.length;
  28691. this.eof = true;
  28692. } catch (e) {
  28693. error('JPEG error: ' + e);
  28694. }
  28695. };
  28696. JpegStream.prototype.getBytes = function JpegStream_getBytes(length) {
  28697. this.ensureBuffer();
  28698. return this.buffer;
  28699. };
  28700. JpegStream.prototype.getIR = function JpegStream_getIR() {
  28701. return PDFJS.createObjectURL(this.bytes, 'image/jpeg');
  28702. };
  28703. /**
  28704. * Checks if the image can be decoded and displayed by the browser without any
  28705. * further processing such as color space conversions.
  28706. */
  28707. JpegStream.prototype.isNativelySupported =
  28708. function JpegStream_isNativelySupported(xref, res) {
  28709. var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
  28710. return cs.name === 'DeviceGray' || cs.name === 'DeviceRGB';
  28711. };
  28712. /**
  28713. * Checks if the image can be decoded by the browser.
  28714. */
  28715. JpegStream.prototype.isNativelyDecodable =
  28716. function JpegStream_isNativelyDecodable(xref, res) {
  28717. var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
  28718. var numComps = cs.numComps;
  28719. return numComps == 1 || numComps == 3;
  28720. };
  28721. return JpegStream;
  28722. })();
  28723. /**
  28724. * For JPEG 2000's we use a library to decode these images and
  28725. * the stream behaves like all the other DecodeStreams.
  28726. */
  28727. var JpxStream = (function JpxStreamClosure() {
  28728. function JpxStream(stream, maybeLength, dict) {
  28729. this.stream = stream;
  28730. this.maybeLength = maybeLength;
  28731. this.dict = dict;
  28732. DecodeStream.call(this, maybeLength);
  28733. }
  28734. JpxStream.prototype = Object.create(DecodeStream.prototype);
  28735. Object.defineProperty(JpxStream.prototype, 'bytes', {
  28736. get: function JpxStream_bytes() {
  28737. // If this.maybeLength is null, we'll get the entire stream.
  28738. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  28739. },
  28740. configurable: true
  28741. });
  28742. JpxStream.prototype.ensureBuffer = function JpxStream_ensureBuffer(req) {
  28743. if (this.bufferLength) {
  28744. return;
  28745. }
  28746. var jpxImage = new JpxImage();
  28747. jpxImage.parse(this.bytes);
  28748. var width = jpxImage.width;
  28749. var height = jpxImage.height;
  28750. var componentsCount = jpxImage.componentsCount;
  28751. var tileCount = jpxImage.tiles.length;
  28752. if (tileCount === 1) {
  28753. this.buffer = jpxImage.tiles[0].items;
  28754. } else {
  28755. var data = new Uint8Array(width * height * componentsCount);
  28756. for (var k = 0; k < tileCount; k++) {
  28757. var tileComponents = jpxImage.tiles[k];
  28758. var tileWidth = tileComponents.width;
  28759. var tileHeight = tileComponents.height;
  28760. var tileLeft = tileComponents.left;
  28761. var tileTop = tileComponents.top;
  28762. var src = tileComponents.items;
  28763. var srcPosition = 0;
  28764. var dataPosition = (width * tileTop + tileLeft) * componentsCount;
  28765. var imgRowSize = width * componentsCount;
  28766. var tileRowSize = tileWidth * componentsCount;
  28767. for (var j = 0; j < tileHeight; j++) {
  28768. var rowBytes = src.subarray(srcPosition, srcPosition + tileRowSize);
  28769. data.set(rowBytes, dataPosition);
  28770. srcPosition += tileRowSize;
  28771. dataPosition += imgRowSize;
  28772. }
  28773. }
  28774. this.buffer = data;
  28775. }
  28776. this.bufferLength = this.buffer.length;
  28777. this.eof = true;
  28778. };
  28779. return JpxStream;
  28780. })();
  28781. /**
  28782. * For JBIG2's we use a library to decode these images and
  28783. * the stream behaves like all the other DecodeStreams.
  28784. */
  28785. var Jbig2Stream = (function Jbig2StreamClosure() {
  28786. function Jbig2Stream(stream, maybeLength, dict) {
  28787. this.stream = stream;
  28788. this.maybeLength = maybeLength;
  28789. this.dict = dict;
  28790. DecodeStream.call(this, maybeLength);
  28791. }
  28792. Jbig2Stream.prototype = Object.create(DecodeStream.prototype);
  28793. Object.defineProperty(Jbig2Stream.prototype, 'bytes', {
  28794. get: function Jbig2Stream_bytes() {
  28795. // If this.maybeLength is null, we'll get the entire stream.
  28796. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  28797. },
  28798. configurable: true
  28799. });
  28800. Jbig2Stream.prototype.ensureBuffer = function Jbig2Stream_ensureBuffer(req) {
  28801. if (this.bufferLength) {
  28802. return;
  28803. }
  28804. var jbig2Image = new Jbig2Image();
  28805. var chunks = [], decodeParams = this.dict.get('DecodeParms');
  28806. // According to the PDF specification, DecodeParms can be either
  28807. // a dictionary, or an array whose elements are dictionaries.
  28808. if (isArray(decodeParams)) {
  28809. if (decodeParams.length > 1) {
  28810. warn('JBIG2 - \'DecodeParms\' array with multiple elements ' +
  28811. 'not supported.');
  28812. }
  28813. decodeParams = decodeParams[0];
  28814. }
  28815. if (decodeParams && decodeParams.has('JBIG2Globals')) {
  28816. var globalsStream = decodeParams.get('JBIG2Globals');
  28817. var globals = globalsStream.getBytes();
  28818. chunks.push({data: globals, start: 0, end: globals.length});
  28819. }
  28820. chunks.push({data: this.bytes, start: 0, end: this.bytes.length});
  28821. var data = jbig2Image.parseChunks(chunks);
  28822. var dataLength = data.length;
  28823. // JBIG2 had black as 1 and white as 0, inverting the colors
  28824. for (var i = 0; i < dataLength; i++) {
  28825. data[i] ^= 0xFF;
  28826. }
  28827. this.buffer = data;
  28828. this.bufferLength = dataLength;
  28829. this.eof = true;
  28830. };
  28831. return Jbig2Stream;
  28832. })();
  28833. var DecryptStream = (function DecryptStreamClosure() {
  28834. function DecryptStream(str, maybeLength, decrypt) {
  28835. this.str = str;
  28836. this.dict = str.dict;
  28837. this.decrypt = decrypt;
  28838. this.nextChunk = null;
  28839. this.initialized = false;
  28840. DecodeStream.call(this, maybeLength);
  28841. }
  28842. var chunkSize = 512;
  28843. DecryptStream.prototype = Object.create(DecodeStream.prototype);
  28844. DecryptStream.prototype.readBlock = function DecryptStream_readBlock() {
  28845. var chunk;
  28846. if (this.initialized) {
  28847. chunk = this.nextChunk;
  28848. } else {
  28849. chunk = this.str.getBytes(chunkSize);
  28850. this.initialized = true;
  28851. }
  28852. if (!chunk || chunk.length === 0) {
  28853. this.eof = true;
  28854. return;
  28855. }
  28856. this.nextChunk = this.str.getBytes(chunkSize);
  28857. var hasMoreData = this.nextChunk && this.nextChunk.length > 0;
  28858. var decrypt = this.decrypt;
  28859. chunk = decrypt(chunk, !hasMoreData);
  28860. var bufferLength = this.bufferLength;
  28861. var i, n = chunk.length;
  28862. var buffer = this.ensureBuffer(bufferLength + n);
  28863. for (i = 0; i < n; i++) {
  28864. buffer[bufferLength++] = chunk[i];
  28865. }
  28866. this.bufferLength = bufferLength;
  28867. };
  28868. return DecryptStream;
  28869. })();
  28870. var Ascii85Stream = (function Ascii85StreamClosure() {
  28871. function Ascii85Stream(str, maybeLength) {
  28872. this.str = str;
  28873. this.dict = str.dict;
  28874. this.input = new Uint8Array(5);
  28875. // Most streams increase in size when decoded, but Ascii85 streams
  28876. // typically shrink by ~20%.
  28877. if (maybeLength) {
  28878. maybeLength = 0.8 * maybeLength;
  28879. }
  28880. DecodeStream.call(this, maybeLength);
  28881. }
  28882. Ascii85Stream.prototype = Object.create(DecodeStream.prototype);
  28883. Ascii85Stream.prototype.readBlock = function Ascii85Stream_readBlock() {
  28884. var TILDA_CHAR = 0x7E; // '~'
  28885. var Z_LOWER_CHAR = 0x7A; // 'z'
  28886. var EOF = -1;
  28887. var str = this.str;
  28888. var c = str.getByte();
  28889. while (Lexer.isSpace(c)) {
  28890. c = str.getByte();
  28891. }
  28892. if (c === EOF || c === TILDA_CHAR) {
  28893. this.eof = true;
  28894. return;
  28895. }
  28896. var bufferLength = this.bufferLength, buffer;
  28897. var i;
  28898. // special code for z
  28899. if (c == Z_LOWER_CHAR) {
  28900. buffer = this.ensureBuffer(bufferLength + 4);
  28901. for (i = 0; i < 4; ++i) {
  28902. buffer[bufferLength + i] = 0;
  28903. }
  28904. this.bufferLength += 4;
  28905. } else {
  28906. var input = this.input;
  28907. input[0] = c;
  28908. for (i = 1; i < 5; ++i) {
  28909. c = str.getByte();
  28910. while (Lexer.isSpace(c)) {
  28911. c = str.getByte();
  28912. }
  28913. input[i] = c;
  28914. if (c === EOF || c == TILDA_CHAR) {
  28915. break;
  28916. }
  28917. }
  28918. buffer = this.ensureBuffer(bufferLength + i - 1);
  28919. this.bufferLength += i - 1;
  28920. // partial ending;
  28921. if (i < 5) {
  28922. for (; i < 5; ++i) {
  28923. input[i] = 0x21 + 84;
  28924. }
  28925. this.eof = true;
  28926. }
  28927. var t = 0;
  28928. for (i = 0; i < 5; ++i) {
  28929. t = t * 85 + (input[i] - 0x21);
  28930. }
  28931. for (i = 3; i >= 0; --i) {
  28932. buffer[bufferLength + i] = t & 0xFF;
  28933. t >>= 8;
  28934. }
  28935. }
  28936. };
  28937. return Ascii85Stream;
  28938. })();
  28939. var AsciiHexStream = (function AsciiHexStreamClosure() {
  28940. function AsciiHexStream(str, maybeLength) {
  28941. this.str = str;
  28942. this.dict = str.dict;
  28943. this.firstDigit = -1;
  28944. // Most streams increase in size when decoded, but AsciiHex streams shrink
  28945. // by 50%.
  28946. if (maybeLength) {
  28947. maybeLength = 0.5 * maybeLength;
  28948. }
  28949. DecodeStream.call(this, maybeLength);
  28950. }
  28951. AsciiHexStream.prototype = Object.create(DecodeStream.prototype);
  28952. AsciiHexStream.prototype.readBlock = function AsciiHexStream_readBlock() {
  28953. var UPSTREAM_BLOCK_SIZE = 8000;
  28954. var bytes = this.str.getBytes(UPSTREAM_BLOCK_SIZE);
  28955. if (!bytes.length) {
  28956. this.eof = true;
  28957. return;
  28958. }
  28959. var maxDecodeLength = (bytes.length + 1) >> 1;
  28960. var buffer = this.ensureBuffer(this.bufferLength + maxDecodeLength);
  28961. var bufferLength = this.bufferLength;
  28962. var firstDigit = this.firstDigit;
  28963. for (var i = 0, ii = bytes.length; i < ii; i++) {
  28964. var ch = bytes[i], digit;
  28965. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  28966. digit = ch & 0x0F;
  28967. } else if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  28968. // 'A'-'Z', 'a'-'z'
  28969. digit = (ch & 0x0F) + 9;
  28970. } else if (ch === 0x3E) { // '>'
  28971. this.eof = true;
  28972. break;
  28973. } else { // probably whitespace
  28974. continue; // ignoring
  28975. }
  28976. if (firstDigit < 0) {
  28977. firstDigit = digit;
  28978. } else {
  28979. buffer[bufferLength++] = (firstDigit << 4) | digit;
  28980. firstDigit = -1;
  28981. }
  28982. }
  28983. if (firstDigit >= 0 && this.eof) {
  28984. // incomplete byte
  28985. buffer[bufferLength++] = (firstDigit << 4);
  28986. firstDigit = -1;
  28987. }
  28988. this.firstDigit = firstDigit;
  28989. this.bufferLength = bufferLength;
  28990. };
  28991. return AsciiHexStream;
  28992. })();
  28993. var RunLengthStream = (function RunLengthStreamClosure() {
  28994. function RunLengthStream(str, maybeLength) {
  28995. this.str = str;
  28996. this.dict = str.dict;
  28997. DecodeStream.call(this, maybeLength);
  28998. }
  28999. RunLengthStream.prototype = Object.create(DecodeStream.prototype);
  29000. RunLengthStream.prototype.readBlock = function RunLengthStream_readBlock() {
  29001. // The repeatHeader has following format. The first byte defines type of run
  29002. // and amount of bytes to repeat/copy: n = 0 through 127 - copy next n bytes
  29003. // (in addition to the second byte from the header), n = 129 through 255 -
  29004. // duplicate the second byte from the header (257 - n) times, n = 128 - end.
  29005. var repeatHeader = this.str.getBytes(2);
  29006. if (!repeatHeader || repeatHeader.length < 2 || repeatHeader[0] == 128) {
  29007. this.eof = true;
  29008. return;
  29009. }
  29010. var buffer;
  29011. var bufferLength = this.bufferLength;
  29012. var n = repeatHeader[0];
  29013. if (n < 128) {
  29014. // copy n bytes
  29015. buffer = this.ensureBuffer(bufferLength + n + 1);
  29016. buffer[bufferLength++] = repeatHeader[1];
  29017. if (n > 0) {
  29018. var source = this.str.getBytes(n);
  29019. buffer.set(source, bufferLength);
  29020. bufferLength += n;
  29021. }
  29022. } else {
  29023. n = 257 - n;
  29024. var b = repeatHeader[1];
  29025. buffer = this.ensureBuffer(bufferLength + n + 1);
  29026. for (var i = 0; i < n; i++) {
  29027. buffer[bufferLength++] = b;
  29028. }
  29029. }
  29030. this.bufferLength = bufferLength;
  29031. };
  29032. return RunLengthStream;
  29033. })();
  29034. var CCITTFaxStream = (function CCITTFaxStreamClosure() {
  29035. var ccittEOL = -2;
  29036. var twoDimPass = 0;
  29037. var twoDimHoriz = 1;
  29038. var twoDimVert0 = 2;
  29039. var twoDimVertR1 = 3;
  29040. var twoDimVertL1 = 4;
  29041. var twoDimVertR2 = 5;
  29042. var twoDimVertL2 = 6;
  29043. var twoDimVertR3 = 7;
  29044. var twoDimVertL3 = 8;
  29045. var twoDimTable = [
  29046. [-1, -1], [-1, -1], // 000000x
  29047. [7, twoDimVertL3], // 0000010
  29048. [7, twoDimVertR3], // 0000011
  29049. [6, twoDimVertL2], [6, twoDimVertL2], // 000010x
  29050. [6, twoDimVertR2], [6, twoDimVertR2], // 000011x
  29051. [4, twoDimPass], [4, twoDimPass], // 0001xxx
  29052. [4, twoDimPass], [4, twoDimPass],
  29053. [4, twoDimPass], [4, twoDimPass],
  29054. [4, twoDimPass], [4, twoDimPass],
  29055. [3, twoDimHoriz], [3, twoDimHoriz], // 001xxxx
  29056. [3, twoDimHoriz], [3, twoDimHoriz],
  29057. [3, twoDimHoriz], [3, twoDimHoriz],
  29058. [3, twoDimHoriz], [3, twoDimHoriz],
  29059. [3, twoDimHoriz], [3, twoDimHoriz],
  29060. [3, twoDimHoriz], [3, twoDimHoriz],
  29061. [3, twoDimHoriz], [3, twoDimHoriz],
  29062. [3, twoDimHoriz], [3, twoDimHoriz],
  29063. [3, twoDimVertL1], [3, twoDimVertL1], // 010xxxx
  29064. [3, twoDimVertL1], [3, twoDimVertL1],
  29065. [3, twoDimVertL1], [3, twoDimVertL1],
  29066. [3, twoDimVertL1], [3, twoDimVertL1],
  29067. [3, twoDimVertL1], [3, twoDimVertL1],
  29068. [3, twoDimVertL1], [3, twoDimVertL1],
  29069. [3, twoDimVertL1], [3, twoDimVertL1],
  29070. [3, twoDimVertL1], [3, twoDimVertL1],
  29071. [3, twoDimVertR1], [3, twoDimVertR1], // 011xxxx
  29072. [3, twoDimVertR1], [3, twoDimVertR1],
  29073. [3, twoDimVertR1], [3, twoDimVertR1],
  29074. [3, twoDimVertR1], [3, twoDimVertR1],
  29075. [3, twoDimVertR1], [3, twoDimVertR1],
  29076. [3, twoDimVertR1], [3, twoDimVertR1],
  29077. [3, twoDimVertR1], [3, twoDimVertR1],
  29078. [3, twoDimVertR1], [3, twoDimVertR1],
  29079. [1, twoDimVert0], [1, twoDimVert0], // 1xxxxxx
  29080. [1, twoDimVert0], [1, twoDimVert0],
  29081. [1, twoDimVert0], [1, twoDimVert0],
  29082. [1, twoDimVert0], [1, twoDimVert0],
  29083. [1, twoDimVert0], [1, twoDimVert0],
  29084. [1, twoDimVert0], [1, twoDimVert0],
  29085. [1, twoDimVert0], [1, twoDimVert0],
  29086. [1, twoDimVert0], [1, twoDimVert0],
  29087. [1, twoDimVert0], [1, twoDimVert0],
  29088. [1, twoDimVert0], [1, twoDimVert0],
  29089. [1, twoDimVert0], [1, twoDimVert0],
  29090. [1, twoDimVert0], [1, twoDimVert0],
  29091. [1, twoDimVert0], [1, twoDimVert0],
  29092. [1, twoDimVert0], [1, twoDimVert0],
  29093. [1, twoDimVert0], [1, twoDimVert0],
  29094. [1, twoDimVert0], [1, twoDimVert0],
  29095. [1, twoDimVert0], [1, twoDimVert0],
  29096. [1, twoDimVert0], [1, twoDimVert0],
  29097. [1, twoDimVert0], [1, twoDimVert0],
  29098. [1, twoDimVert0], [1, twoDimVert0],
  29099. [1, twoDimVert0], [1, twoDimVert0],
  29100. [1, twoDimVert0], [1, twoDimVert0],
  29101. [1, twoDimVert0], [1, twoDimVert0],
  29102. [1, twoDimVert0], [1, twoDimVert0],
  29103. [1, twoDimVert0], [1, twoDimVert0],
  29104. [1, twoDimVert0], [1, twoDimVert0],
  29105. [1, twoDimVert0], [1, twoDimVert0],
  29106. [1, twoDimVert0], [1, twoDimVert0],
  29107. [1, twoDimVert0], [1, twoDimVert0],
  29108. [1, twoDimVert0], [1, twoDimVert0],
  29109. [1, twoDimVert0], [1, twoDimVert0],
  29110. [1, twoDimVert0], [1, twoDimVert0]
  29111. ];
  29112. var whiteTable1 = [
  29113. [-1, -1], // 00000
  29114. [12, ccittEOL], // 00001
  29115. [-1, -1], [-1, -1], // 0001x
  29116. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 001xx
  29117. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 010xx
  29118. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 011xx
  29119. [11, 1792], [11, 1792], // 1000x
  29120. [12, 1984], // 10010
  29121. [12, 2048], // 10011
  29122. [12, 2112], // 10100
  29123. [12, 2176], // 10101
  29124. [12, 2240], // 10110
  29125. [12, 2304], // 10111
  29126. [11, 1856], [11, 1856], // 1100x
  29127. [11, 1920], [11, 1920], // 1101x
  29128. [12, 2368], // 11100
  29129. [12, 2432], // 11101
  29130. [12, 2496], // 11110
  29131. [12, 2560] // 11111
  29132. ];
  29133. var whiteTable2 = [
  29134. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000000xx
  29135. [8, 29], [8, 29], // 00000010x
  29136. [8, 30], [8, 30], // 00000011x
  29137. [8, 45], [8, 45], // 00000100x
  29138. [8, 46], [8, 46], // 00000101x
  29139. [7, 22], [7, 22], [7, 22], [7, 22], // 0000011xx
  29140. [7, 23], [7, 23], [7, 23], [7, 23], // 0000100xx
  29141. [8, 47], [8, 47], // 00001010x
  29142. [8, 48], [8, 48], // 00001011x
  29143. [6, 13], [6, 13], [6, 13], [6, 13], // 000011xxx
  29144. [6, 13], [6, 13], [6, 13], [6, 13],
  29145. [7, 20], [7, 20], [7, 20], [7, 20], // 0001000xx
  29146. [8, 33], [8, 33], // 00010010x
  29147. [8, 34], [8, 34], // 00010011x
  29148. [8, 35], [8, 35], // 00010100x
  29149. [8, 36], [8, 36], // 00010101x
  29150. [8, 37], [8, 37], // 00010110x
  29151. [8, 38], [8, 38], // 00010111x
  29152. [7, 19], [7, 19], [7, 19], [7, 19], // 0001100xx
  29153. [8, 31], [8, 31], // 00011010x
  29154. [8, 32], [8, 32], // 00011011x
  29155. [6, 1], [6, 1], [6, 1], [6, 1], // 000111xxx
  29156. [6, 1], [6, 1], [6, 1], [6, 1],
  29157. [6, 12], [6, 12], [6, 12], [6, 12], // 001000xxx
  29158. [6, 12], [6, 12], [6, 12], [6, 12],
  29159. [8, 53], [8, 53], // 00100100x
  29160. [8, 54], [8, 54], // 00100101x
  29161. [7, 26], [7, 26], [7, 26], [7, 26], // 0010011xx
  29162. [8, 39], [8, 39], // 00101000x
  29163. [8, 40], [8, 40], // 00101001x
  29164. [8, 41], [8, 41], // 00101010x
  29165. [8, 42], [8, 42], // 00101011x
  29166. [8, 43], [8, 43], // 00101100x
  29167. [8, 44], [8, 44], // 00101101x
  29168. [7, 21], [7, 21], [7, 21], [7, 21], // 0010111xx
  29169. [7, 28], [7, 28], [7, 28], [7, 28], // 0011000xx
  29170. [8, 61], [8, 61], // 00110010x
  29171. [8, 62], [8, 62], // 00110011x
  29172. [8, 63], [8, 63], // 00110100x
  29173. [8, 0], [8, 0], // 00110101x
  29174. [8, 320], [8, 320], // 00110110x
  29175. [8, 384], [8, 384], // 00110111x
  29176. [5, 10], [5, 10], [5, 10], [5, 10], // 00111xxxx
  29177. [5, 10], [5, 10], [5, 10], [5, 10],
  29178. [5, 10], [5, 10], [5, 10], [5, 10],
  29179. [5, 10], [5, 10], [5, 10], [5, 10],
  29180. [5, 11], [5, 11], [5, 11], [5, 11], // 01000xxxx
  29181. [5, 11], [5, 11], [5, 11], [5, 11],
  29182. [5, 11], [5, 11], [5, 11], [5, 11],
  29183. [5, 11], [5, 11], [5, 11], [5, 11],
  29184. [7, 27], [7, 27], [7, 27], [7, 27], // 0100100xx
  29185. [8, 59], [8, 59], // 01001010x
  29186. [8, 60], [8, 60], // 01001011x
  29187. [9, 1472], // 010011000
  29188. [9, 1536], // 010011001
  29189. [9, 1600], // 010011010
  29190. [9, 1728], // 010011011
  29191. [7, 18], [7, 18], [7, 18], [7, 18], // 0100111xx
  29192. [7, 24], [7, 24], [7, 24], [7, 24], // 0101000xx
  29193. [8, 49], [8, 49], // 01010010x
  29194. [8, 50], [8, 50], // 01010011x
  29195. [8, 51], [8, 51], // 01010100x
  29196. [8, 52], [8, 52], // 01010101x
  29197. [7, 25], [7, 25], [7, 25], [7, 25], // 0101011xx
  29198. [8, 55], [8, 55], // 01011000x
  29199. [8, 56], [8, 56], // 01011001x
  29200. [8, 57], [8, 57], // 01011010x
  29201. [8, 58], [8, 58], // 01011011x
  29202. [6, 192], [6, 192], [6, 192], [6, 192], // 010111xxx
  29203. [6, 192], [6, 192], [6, 192], [6, 192],
  29204. [6, 1664], [6, 1664], [6, 1664], [6, 1664], // 011000xxx
  29205. [6, 1664], [6, 1664], [6, 1664], [6, 1664],
  29206. [8, 448], [8, 448], // 01100100x
  29207. [8, 512], [8, 512], // 01100101x
  29208. [9, 704], // 011001100
  29209. [9, 768], // 011001101
  29210. [8, 640], [8, 640], // 01100111x
  29211. [8, 576], [8, 576], // 01101000x
  29212. [9, 832], // 011010010
  29213. [9, 896], // 011010011
  29214. [9, 960], // 011010100
  29215. [9, 1024], // 011010101
  29216. [9, 1088], // 011010110
  29217. [9, 1152], // 011010111
  29218. [9, 1216], // 011011000
  29219. [9, 1280], // 011011001
  29220. [9, 1344], // 011011010
  29221. [9, 1408], // 011011011
  29222. [7, 256], [7, 256], [7, 256], [7, 256], // 0110111xx
  29223. [4, 2], [4, 2], [4, 2], [4, 2], // 0111xxxxx
  29224. [4, 2], [4, 2], [4, 2], [4, 2],
  29225. [4, 2], [4, 2], [4, 2], [4, 2],
  29226. [4, 2], [4, 2], [4, 2], [4, 2],
  29227. [4, 2], [4, 2], [4, 2], [4, 2],
  29228. [4, 2], [4, 2], [4, 2], [4, 2],
  29229. [4, 2], [4, 2], [4, 2], [4, 2],
  29230. [4, 2], [4, 2], [4, 2], [4, 2],
  29231. [4, 3], [4, 3], [4, 3], [4, 3], // 1000xxxxx
  29232. [4, 3], [4, 3], [4, 3], [4, 3],
  29233. [4, 3], [4, 3], [4, 3], [4, 3],
  29234. [4, 3], [4, 3], [4, 3], [4, 3],
  29235. [4, 3], [4, 3], [4, 3], [4, 3],
  29236. [4, 3], [4, 3], [4, 3], [4, 3],
  29237. [4, 3], [4, 3], [4, 3], [4, 3],
  29238. [4, 3], [4, 3], [4, 3], [4, 3],
  29239. [5, 128], [5, 128], [5, 128], [5, 128], // 10010xxxx
  29240. [5, 128], [5, 128], [5, 128], [5, 128],
  29241. [5, 128], [5, 128], [5, 128], [5, 128],
  29242. [5, 128], [5, 128], [5, 128], [5, 128],
  29243. [5, 8], [5, 8], [5, 8], [5, 8], // 10011xxxx
  29244. [5, 8], [5, 8], [5, 8], [5, 8],
  29245. [5, 8], [5, 8], [5, 8], [5, 8],
  29246. [5, 8], [5, 8], [5, 8], [5, 8],
  29247. [5, 9], [5, 9], [5, 9], [5, 9], // 10100xxxx
  29248. [5, 9], [5, 9], [5, 9], [5, 9],
  29249. [5, 9], [5, 9], [5, 9], [5, 9],
  29250. [5, 9], [5, 9], [5, 9], [5, 9],
  29251. [6, 16], [6, 16], [6, 16], [6, 16], // 101010xxx
  29252. [6, 16], [6, 16], [6, 16], [6, 16],
  29253. [6, 17], [6, 17], [6, 17], [6, 17], // 101011xxx
  29254. [6, 17], [6, 17], [6, 17], [6, 17],
  29255. [4, 4], [4, 4], [4, 4], [4, 4], // 1011xxxxx
  29256. [4, 4], [4, 4], [4, 4], [4, 4],
  29257. [4, 4], [4, 4], [4, 4], [4, 4],
  29258. [4, 4], [4, 4], [4, 4], [4, 4],
  29259. [4, 4], [4, 4], [4, 4], [4, 4],
  29260. [4, 4], [4, 4], [4, 4], [4, 4],
  29261. [4, 4], [4, 4], [4, 4], [4, 4],
  29262. [4, 4], [4, 4], [4, 4], [4, 4],
  29263. [4, 5], [4, 5], [4, 5], [4, 5], // 1100xxxxx
  29264. [4, 5], [4, 5], [4, 5], [4, 5],
  29265. [4, 5], [4, 5], [4, 5], [4, 5],
  29266. [4, 5], [4, 5], [4, 5], [4, 5],
  29267. [4, 5], [4, 5], [4, 5], [4, 5],
  29268. [4, 5], [4, 5], [4, 5], [4, 5],
  29269. [4, 5], [4, 5], [4, 5], [4, 5],
  29270. [4, 5], [4, 5], [4, 5], [4, 5],
  29271. [6, 14], [6, 14], [6, 14], [6, 14], // 110100xxx
  29272. [6, 14], [6, 14], [6, 14], [6, 14],
  29273. [6, 15], [6, 15], [6, 15], [6, 15], // 110101xxx
  29274. [6, 15], [6, 15], [6, 15], [6, 15],
  29275. [5, 64], [5, 64], [5, 64], [5, 64], // 11011xxxx
  29276. [5, 64], [5, 64], [5, 64], [5, 64],
  29277. [5, 64], [5, 64], [5, 64], [5, 64],
  29278. [5, 64], [5, 64], [5, 64], [5, 64],
  29279. [4, 6], [4, 6], [4, 6], [4, 6], // 1110xxxxx
  29280. [4, 6], [4, 6], [4, 6], [4, 6],
  29281. [4, 6], [4, 6], [4, 6], [4, 6],
  29282. [4, 6], [4, 6], [4, 6], [4, 6],
  29283. [4, 6], [4, 6], [4, 6], [4, 6],
  29284. [4, 6], [4, 6], [4, 6], [4, 6],
  29285. [4, 6], [4, 6], [4, 6], [4, 6],
  29286. [4, 6], [4, 6], [4, 6], [4, 6],
  29287. [4, 7], [4, 7], [4, 7], [4, 7], // 1111xxxxx
  29288. [4, 7], [4, 7], [4, 7], [4, 7],
  29289. [4, 7], [4, 7], [4, 7], [4, 7],
  29290. [4, 7], [4, 7], [4, 7], [4, 7],
  29291. [4, 7], [4, 7], [4, 7], [4, 7],
  29292. [4, 7], [4, 7], [4, 7], [4, 7],
  29293. [4, 7], [4, 7], [4, 7], [4, 7],
  29294. [4, 7], [4, 7], [4, 7], [4, 7]
  29295. ];
  29296. var blackTable1 = [
  29297. [-1, -1], [-1, -1], // 000000000000x
  29298. [12, ccittEOL], [12, ccittEOL], // 000000000001x
  29299. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000001xx
  29300. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000010xx
  29301. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000011xx
  29302. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000100xx
  29303. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000101xx
  29304. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000110xx
  29305. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000111xx
  29306. [11, 1792], [11, 1792], [11, 1792], [11, 1792], // 00000001000xx
  29307. [12, 1984], [12, 1984], // 000000010010x
  29308. [12, 2048], [12, 2048], // 000000010011x
  29309. [12, 2112], [12, 2112], // 000000010100x
  29310. [12, 2176], [12, 2176], // 000000010101x
  29311. [12, 2240], [12, 2240], // 000000010110x
  29312. [12, 2304], [12, 2304], // 000000010111x
  29313. [11, 1856], [11, 1856], [11, 1856], [11, 1856], // 00000001100xx
  29314. [11, 1920], [11, 1920], [11, 1920], [11, 1920], // 00000001101xx
  29315. [12, 2368], [12, 2368], // 000000011100x
  29316. [12, 2432], [12, 2432], // 000000011101x
  29317. [12, 2496], [12, 2496], // 000000011110x
  29318. [12, 2560], [12, 2560], // 000000011111x
  29319. [10, 18], [10, 18], [10, 18], [10, 18], // 0000001000xxx
  29320. [10, 18], [10, 18], [10, 18], [10, 18],
  29321. [12, 52], [12, 52], // 000000100100x
  29322. [13, 640], // 0000001001010
  29323. [13, 704], // 0000001001011
  29324. [13, 768], // 0000001001100
  29325. [13, 832], // 0000001001101
  29326. [12, 55], [12, 55], // 000000100111x
  29327. [12, 56], [12, 56], // 000000101000x
  29328. [13, 1280], // 0000001010010
  29329. [13, 1344], // 0000001010011
  29330. [13, 1408], // 0000001010100
  29331. [13, 1472], // 0000001010101
  29332. [12, 59], [12, 59], // 000000101011x
  29333. [12, 60], [12, 60], // 000000101100x
  29334. [13, 1536], // 0000001011010
  29335. [13, 1600], // 0000001011011
  29336. [11, 24], [11, 24], [11, 24], [11, 24], // 00000010111xx
  29337. [11, 25], [11, 25], [11, 25], [11, 25], // 00000011000xx
  29338. [13, 1664], // 0000001100100
  29339. [13, 1728], // 0000001100101
  29340. [12, 320], [12, 320], // 000000110011x
  29341. [12, 384], [12, 384], // 000000110100x
  29342. [12, 448], [12, 448], // 000000110101x
  29343. [13, 512], // 0000001101100
  29344. [13, 576], // 0000001101101
  29345. [12, 53], [12, 53], // 000000110111x
  29346. [12, 54], [12, 54], // 000000111000x
  29347. [13, 896], // 0000001110010
  29348. [13, 960], // 0000001110011
  29349. [13, 1024], // 0000001110100
  29350. [13, 1088], // 0000001110101
  29351. [13, 1152], // 0000001110110
  29352. [13, 1216], // 0000001110111
  29353. [10, 64], [10, 64], [10, 64], [10, 64], // 0000001111xxx
  29354. [10, 64], [10, 64], [10, 64], [10, 64]
  29355. ];
  29356. var blackTable2 = [
  29357. [8, 13], [8, 13], [8, 13], [8, 13], // 00000100xxxx
  29358. [8, 13], [8, 13], [8, 13], [8, 13],
  29359. [8, 13], [8, 13], [8, 13], [8, 13],
  29360. [8, 13], [8, 13], [8, 13], [8, 13],
  29361. [11, 23], [11, 23], // 00000101000x
  29362. [12, 50], // 000001010010
  29363. [12, 51], // 000001010011
  29364. [12, 44], // 000001010100
  29365. [12, 45], // 000001010101
  29366. [12, 46], // 000001010110
  29367. [12, 47], // 000001010111
  29368. [12, 57], // 000001011000
  29369. [12, 58], // 000001011001
  29370. [12, 61], // 000001011010
  29371. [12, 256], // 000001011011
  29372. [10, 16], [10, 16], [10, 16], [10, 16], // 0000010111xx
  29373. [10, 17], [10, 17], [10, 17], [10, 17], // 0000011000xx
  29374. [12, 48], // 000001100100
  29375. [12, 49], // 000001100101
  29376. [12, 62], // 000001100110
  29377. [12, 63], // 000001100111
  29378. [12, 30], // 000001101000
  29379. [12, 31], // 000001101001
  29380. [12, 32], // 000001101010
  29381. [12, 33], // 000001101011
  29382. [12, 40], // 000001101100
  29383. [12, 41], // 000001101101
  29384. [11, 22], [11, 22], // 00000110111x
  29385. [8, 14], [8, 14], [8, 14], [8, 14], // 00000111xxxx
  29386. [8, 14], [8, 14], [8, 14], [8, 14],
  29387. [8, 14], [8, 14], [8, 14], [8, 14],
  29388. [8, 14], [8, 14], [8, 14], [8, 14],
  29389. [7, 10], [7, 10], [7, 10], [7, 10], // 0000100xxxxx
  29390. [7, 10], [7, 10], [7, 10], [7, 10],
  29391. [7, 10], [7, 10], [7, 10], [7, 10],
  29392. [7, 10], [7, 10], [7, 10], [7, 10],
  29393. [7, 10], [7, 10], [7, 10], [7, 10],
  29394. [7, 10], [7, 10], [7, 10], [7, 10],
  29395. [7, 10], [7, 10], [7, 10], [7, 10],
  29396. [7, 10], [7, 10], [7, 10], [7, 10],
  29397. [7, 11], [7, 11], [7, 11], [7, 11], // 0000101xxxxx
  29398. [7, 11], [7, 11], [7, 11], [7, 11],
  29399. [7, 11], [7, 11], [7, 11], [7, 11],
  29400. [7, 11], [7, 11], [7, 11], [7, 11],
  29401. [7, 11], [7, 11], [7, 11], [7, 11],
  29402. [7, 11], [7, 11], [7, 11], [7, 11],
  29403. [7, 11], [7, 11], [7, 11], [7, 11],
  29404. [7, 11], [7, 11], [7, 11], [7, 11],
  29405. [9, 15], [9, 15], [9, 15], [9, 15], // 000011000xxx
  29406. [9, 15], [9, 15], [9, 15], [9, 15],
  29407. [12, 128], // 000011001000
  29408. [12, 192], // 000011001001
  29409. [12, 26], // 000011001010
  29410. [12, 27], // 000011001011
  29411. [12, 28], // 000011001100
  29412. [12, 29], // 000011001101
  29413. [11, 19], [11, 19], // 00001100111x
  29414. [11, 20], [11, 20], // 00001101000x
  29415. [12, 34], // 000011010010
  29416. [12, 35], // 000011010011
  29417. [12, 36], // 000011010100
  29418. [12, 37], // 000011010101
  29419. [12, 38], // 000011010110
  29420. [12, 39], // 000011010111
  29421. [11, 21], [11, 21], // 00001101100x
  29422. [12, 42], // 000011011010
  29423. [12, 43], // 000011011011
  29424. [10, 0], [10, 0], [10, 0], [10, 0], // 0000110111xx
  29425. [7, 12], [7, 12], [7, 12], [7, 12], // 0000111xxxxx
  29426. [7, 12], [7, 12], [7, 12], [7, 12],
  29427. [7, 12], [7, 12], [7, 12], [7, 12],
  29428. [7, 12], [7, 12], [7, 12], [7, 12],
  29429. [7, 12], [7, 12], [7, 12], [7, 12],
  29430. [7, 12], [7, 12], [7, 12], [7, 12],
  29431. [7, 12], [7, 12], [7, 12], [7, 12],
  29432. [7, 12], [7, 12], [7, 12], [7, 12]
  29433. ];
  29434. var blackTable3 = [
  29435. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000xx
  29436. [6, 9], // 000100
  29437. [6, 8], // 000101
  29438. [5, 7], [5, 7], // 00011x
  29439. [4, 6], [4, 6], [4, 6], [4, 6], // 0010xx
  29440. [4, 5], [4, 5], [4, 5], [4, 5], // 0011xx
  29441. [3, 1], [3, 1], [3, 1], [3, 1], // 010xxx
  29442. [3, 1], [3, 1], [3, 1], [3, 1],
  29443. [3, 4], [3, 4], [3, 4], [3, 4], // 011xxx
  29444. [3, 4], [3, 4], [3, 4], [3, 4],
  29445. [2, 3], [2, 3], [2, 3], [2, 3], // 10xxxx
  29446. [2, 3], [2, 3], [2, 3], [2, 3],
  29447. [2, 3], [2, 3], [2, 3], [2, 3],
  29448. [2, 3], [2, 3], [2, 3], [2, 3],
  29449. [2, 2], [2, 2], [2, 2], [2, 2], // 11xxxx
  29450. [2, 2], [2, 2], [2, 2], [2, 2],
  29451. [2, 2], [2, 2], [2, 2], [2, 2],
  29452. [2, 2], [2, 2], [2, 2], [2, 2]
  29453. ];
  29454. function CCITTFaxStream(str, maybeLength, params) {
  29455. this.str = str;
  29456. this.dict = str.dict;
  29457. params = params || Dict.empty;
  29458. this.encoding = params.get('K') || 0;
  29459. this.eoline = params.get('EndOfLine') || false;
  29460. this.byteAlign = params.get('EncodedByteAlign') || false;
  29461. this.columns = params.get('Columns') || 1728;
  29462. this.rows = params.get('Rows') || 0;
  29463. var eoblock = params.get('EndOfBlock');
  29464. if (eoblock === null || eoblock === undefined) {
  29465. eoblock = true;
  29466. }
  29467. this.eoblock = eoblock;
  29468. this.black = params.get('BlackIs1') || false;
  29469. this.codingLine = new Uint32Array(this.columns + 1);
  29470. this.refLine = new Uint32Array(this.columns + 2);
  29471. this.codingLine[0] = this.columns;
  29472. this.codingPos = 0;
  29473. this.row = 0;
  29474. this.nextLine2D = this.encoding < 0;
  29475. this.inputBits = 0;
  29476. this.inputBuf = 0;
  29477. this.outputBits = 0;
  29478. var code1;
  29479. while ((code1 = this.lookBits(12)) === 0) {
  29480. this.eatBits(1);
  29481. }
  29482. if (code1 == 1) {
  29483. this.eatBits(12);
  29484. }
  29485. if (this.encoding > 0) {
  29486. this.nextLine2D = !this.lookBits(1);
  29487. this.eatBits(1);
  29488. }
  29489. DecodeStream.call(this, maybeLength);
  29490. }
  29491. CCITTFaxStream.prototype = Object.create(DecodeStream.prototype);
  29492. CCITTFaxStream.prototype.readBlock = function CCITTFaxStream_readBlock() {
  29493. while (!this.eof) {
  29494. var c = this.lookChar();
  29495. this.ensureBuffer(this.bufferLength + 1);
  29496. this.buffer[this.bufferLength++] = c;
  29497. }
  29498. };
  29499. CCITTFaxStream.prototype.addPixels =
  29500. function ccittFaxStreamAddPixels(a1, blackPixels) {
  29501. var codingLine = this.codingLine;
  29502. var codingPos = this.codingPos;
  29503. if (a1 > codingLine[codingPos]) {
  29504. if (a1 > this.columns) {
  29505. info('row is wrong length');
  29506. this.err = true;
  29507. a1 = this.columns;
  29508. }
  29509. if ((codingPos & 1) ^ blackPixels) {
  29510. ++codingPos;
  29511. }
  29512. codingLine[codingPos] = a1;
  29513. }
  29514. this.codingPos = codingPos;
  29515. };
  29516. CCITTFaxStream.prototype.addPixelsNeg =
  29517. function ccittFaxStreamAddPixelsNeg(a1, blackPixels) {
  29518. var codingLine = this.codingLine;
  29519. var codingPos = this.codingPos;
  29520. if (a1 > codingLine[codingPos]) {
  29521. if (a1 > this.columns) {
  29522. info('row is wrong length');
  29523. this.err = true;
  29524. a1 = this.columns;
  29525. }
  29526. if ((codingPos & 1) ^ blackPixels) {
  29527. ++codingPos;
  29528. }
  29529. codingLine[codingPos] = a1;
  29530. } else if (a1 < codingLine[codingPos]) {
  29531. if (a1 < 0) {
  29532. info('invalid code');
  29533. this.err = true;
  29534. a1 = 0;
  29535. }
  29536. while (codingPos > 0 && a1 < codingLine[codingPos - 1]) {
  29537. --codingPos;
  29538. }
  29539. codingLine[codingPos] = a1;
  29540. }
  29541. this.codingPos = codingPos;
  29542. };
  29543. CCITTFaxStream.prototype.lookChar = function CCITTFaxStream_lookChar() {
  29544. var refLine = this.refLine;
  29545. var codingLine = this.codingLine;
  29546. var columns = this.columns;
  29547. var refPos, blackPixels, bits, i;
  29548. if (this.outputBits === 0) {
  29549. if (this.eof) {
  29550. return null;
  29551. }
  29552. this.err = false;
  29553. var code1, code2, code3;
  29554. if (this.nextLine2D) {
  29555. for (i = 0; codingLine[i] < columns; ++i) {
  29556. refLine[i] = codingLine[i];
  29557. }
  29558. refLine[i++] = columns;
  29559. refLine[i] = columns;
  29560. codingLine[0] = 0;
  29561. this.codingPos = 0;
  29562. refPos = 0;
  29563. blackPixels = 0;
  29564. while (codingLine[this.codingPos] < columns) {
  29565. code1 = this.getTwoDimCode();
  29566. switch (code1) {
  29567. case twoDimPass:
  29568. this.addPixels(refLine[refPos + 1], blackPixels);
  29569. if (refLine[refPos + 1] < columns) {
  29570. refPos += 2;
  29571. }
  29572. break;
  29573. case twoDimHoriz:
  29574. code1 = code2 = 0;
  29575. if (blackPixels) {
  29576. do {
  29577. code1 += (code3 = this.getBlackCode());
  29578. } while (code3 >= 64);
  29579. do {
  29580. code2 += (code3 = this.getWhiteCode());
  29581. } while (code3 >= 64);
  29582. } else {
  29583. do {
  29584. code1 += (code3 = this.getWhiteCode());
  29585. } while (code3 >= 64);
  29586. do {
  29587. code2 += (code3 = this.getBlackCode());
  29588. } while (code3 >= 64);
  29589. }
  29590. this.addPixels(codingLine[this.codingPos] +
  29591. code1, blackPixels);
  29592. if (codingLine[this.codingPos] < columns) {
  29593. this.addPixels(codingLine[this.codingPos] + code2,
  29594. blackPixels ^ 1);
  29595. }
  29596. while (refLine[refPos] <= codingLine[this.codingPos] &&
  29597. refLine[refPos] < columns) {
  29598. refPos += 2;
  29599. }
  29600. break;
  29601. case twoDimVertR3:
  29602. this.addPixels(refLine[refPos] + 3, blackPixels);
  29603. blackPixels ^= 1;
  29604. if (codingLine[this.codingPos] < columns) {
  29605. ++refPos;
  29606. while (refLine[refPos] <= codingLine[this.codingPos] &&
  29607. refLine[refPos] < columns) {
  29608. refPos += 2;
  29609. }
  29610. }
  29611. break;
  29612. case twoDimVertR2:
  29613. this.addPixels(refLine[refPos] + 2, blackPixels);
  29614. blackPixels ^= 1;
  29615. if (codingLine[this.codingPos] < columns) {
  29616. ++refPos;
  29617. while (refLine[refPos] <= codingLine[this.codingPos] &&
  29618. refLine[refPos] < columns) {
  29619. refPos += 2;
  29620. }
  29621. }
  29622. break;
  29623. case twoDimVertR1:
  29624. this.addPixels(refLine[refPos] + 1, blackPixels);
  29625. blackPixels ^= 1;
  29626. if (codingLine[this.codingPos] < columns) {
  29627. ++refPos;
  29628. while (refLine[refPos] <= codingLine[this.codingPos] &&
  29629. refLine[refPos] < columns) {
  29630. refPos += 2;
  29631. }
  29632. }
  29633. break;
  29634. case twoDimVert0:
  29635. this.addPixels(refLine[refPos], blackPixels);
  29636. blackPixels ^= 1;
  29637. if (codingLine[this.codingPos] < columns) {
  29638. ++refPos;
  29639. while (refLine[refPos] <= codingLine[this.codingPos] &&
  29640. refLine[refPos] < columns) {
  29641. refPos += 2;
  29642. }
  29643. }
  29644. break;
  29645. case twoDimVertL3:
  29646. this.addPixelsNeg(refLine[refPos] - 3, blackPixels);
  29647. blackPixels ^= 1;
  29648. if (codingLine[this.codingPos] < columns) {
  29649. if (refPos > 0) {
  29650. --refPos;
  29651. } else {
  29652. ++refPos;
  29653. }
  29654. while (refLine[refPos] <= codingLine[this.codingPos] &&
  29655. refLine[refPos] < columns) {
  29656. refPos += 2;
  29657. }
  29658. }
  29659. break;
  29660. case twoDimVertL2:
  29661. this.addPixelsNeg(refLine[refPos] - 2, blackPixels);
  29662. blackPixels ^= 1;
  29663. if (codingLine[this.codingPos] < columns) {
  29664. if (refPos > 0) {
  29665. --refPos;
  29666. } else {
  29667. ++refPos;
  29668. }
  29669. while (refLine[refPos] <= codingLine[this.codingPos] &&
  29670. refLine[refPos] < columns) {
  29671. refPos += 2;
  29672. }
  29673. }
  29674. break;
  29675. case twoDimVertL1:
  29676. this.addPixelsNeg(refLine[refPos] - 1, blackPixels);
  29677. blackPixels ^= 1;
  29678. if (codingLine[this.codingPos] < columns) {
  29679. if (refPos > 0) {
  29680. --refPos;
  29681. } else {
  29682. ++refPos;
  29683. }
  29684. while (refLine[refPos] <= codingLine[this.codingPos] &&
  29685. refLine[refPos] < columns) {
  29686. refPos += 2;
  29687. }
  29688. }
  29689. break;
  29690. case EOF:
  29691. this.addPixels(columns, 0);
  29692. this.eof = true;
  29693. break;
  29694. default:
  29695. info('bad 2d code');
  29696. this.addPixels(columns, 0);
  29697. this.err = true;
  29698. }
  29699. }
  29700. } else {
  29701. codingLine[0] = 0;
  29702. this.codingPos = 0;
  29703. blackPixels = 0;
  29704. while (codingLine[this.codingPos] < columns) {
  29705. code1 = 0;
  29706. if (blackPixels) {
  29707. do {
  29708. code1 += (code3 = this.getBlackCode());
  29709. } while (code3 >= 64);
  29710. } else {
  29711. do {
  29712. code1 += (code3 = this.getWhiteCode());
  29713. } while (code3 >= 64);
  29714. }
  29715. this.addPixels(codingLine[this.codingPos] + code1, blackPixels);
  29716. blackPixels ^= 1;
  29717. }
  29718. }
  29719. if (this.byteAlign) {
  29720. this.inputBits &= ~7;
  29721. }
  29722. var gotEOL = false;
  29723. if (!this.eoblock && this.row == this.rows - 1) {
  29724. this.eof = true;
  29725. } else {
  29726. code1 = this.lookBits(12);
  29727. while (code1 === 0) {
  29728. this.eatBits(1);
  29729. code1 = this.lookBits(12);
  29730. }
  29731. if (code1 == 1) {
  29732. this.eatBits(12);
  29733. gotEOL = true;
  29734. } else if (code1 == EOF) {
  29735. this.eof = true;
  29736. }
  29737. }
  29738. if (!this.eof && this.encoding > 0) {
  29739. this.nextLine2D = !this.lookBits(1);
  29740. this.eatBits(1);
  29741. }
  29742. if (this.eoblock && gotEOL) {
  29743. code1 = this.lookBits(12);
  29744. if (code1 == 1) {
  29745. this.eatBits(12);
  29746. if (this.encoding > 0) {
  29747. this.lookBits(1);
  29748. this.eatBits(1);
  29749. }
  29750. if (this.encoding >= 0) {
  29751. for (i = 0; i < 4; ++i) {
  29752. code1 = this.lookBits(12);
  29753. if (code1 != 1) {
  29754. info('bad rtc code: ' + code1);
  29755. }
  29756. this.eatBits(12);
  29757. if (this.encoding > 0) {
  29758. this.lookBits(1);
  29759. this.eatBits(1);
  29760. }
  29761. }
  29762. }
  29763. this.eof = true;
  29764. }
  29765. } else if (this.err && this.eoline) {
  29766. while (true) {
  29767. code1 = this.lookBits(13);
  29768. if (code1 == EOF) {
  29769. this.eof = true;
  29770. return null;
  29771. }
  29772. if ((code1 >> 1) == 1) {
  29773. break;
  29774. }
  29775. this.eatBits(1);
  29776. }
  29777. this.eatBits(12);
  29778. if (this.encoding > 0) {
  29779. this.eatBits(1);
  29780. this.nextLine2D = !(code1 & 1);
  29781. }
  29782. }
  29783. if (codingLine[0] > 0) {
  29784. this.outputBits = codingLine[this.codingPos = 0];
  29785. } else {
  29786. this.outputBits = codingLine[this.codingPos = 1];
  29787. }
  29788. this.row++;
  29789. }
  29790. var c;
  29791. if (this.outputBits >= 8) {
  29792. c = (this.codingPos & 1) ? 0 : 0xFF;
  29793. this.outputBits -= 8;
  29794. if (this.outputBits === 0 && codingLine[this.codingPos] < columns) {
  29795. this.codingPos++;
  29796. this.outputBits = (codingLine[this.codingPos] -
  29797. codingLine[this.codingPos - 1]);
  29798. }
  29799. } else {
  29800. bits = 8;
  29801. c = 0;
  29802. do {
  29803. if (this.outputBits > bits) {
  29804. c <<= bits;
  29805. if (!(this.codingPos & 1)) {
  29806. c |= 0xFF >> (8 - bits);
  29807. }
  29808. this.outputBits -= bits;
  29809. bits = 0;
  29810. } else {
  29811. c <<= this.outputBits;
  29812. if (!(this.codingPos & 1)) {
  29813. c |= 0xFF >> (8 - this.outputBits);
  29814. }
  29815. bits -= this.outputBits;
  29816. this.outputBits = 0;
  29817. if (codingLine[this.codingPos] < columns) {
  29818. this.codingPos++;
  29819. this.outputBits = (codingLine[this.codingPos] -
  29820. codingLine[this.codingPos - 1]);
  29821. } else if (bits > 0) {
  29822. c <<= bits;
  29823. bits = 0;
  29824. }
  29825. }
  29826. } while (bits);
  29827. }
  29828. if (this.black) {
  29829. c ^= 0xFF;
  29830. }
  29831. return c;
  29832. };
  29833. // This functions returns the code found from the table.
  29834. // The start and end parameters set the boundaries for searching the table.
  29835. // The limit parameter is optional. Function returns an array with three
  29836. // values. The first array element indicates whether a valid code is being
  29837. // returned. The second array element is the actual code. The third array
  29838. // element indicates whether EOF was reached.
  29839. CCITTFaxStream.prototype.findTableCode =
  29840. function ccittFaxStreamFindTableCode(start, end, table, limit) {
  29841. var limitValue = limit || 0;
  29842. for (var i = start; i <= end; ++i) {
  29843. var code = this.lookBits(i);
  29844. if (code == EOF) {
  29845. return [true, 1, false];
  29846. }
  29847. if (i < end) {
  29848. code <<= end - i;
  29849. }
  29850. if (!limitValue || code >= limitValue) {
  29851. var p = table[code - limitValue];
  29852. if (p[0] == i) {
  29853. this.eatBits(i);
  29854. return [true, p[1], true];
  29855. }
  29856. }
  29857. }
  29858. return [false, 0, false];
  29859. };
  29860. CCITTFaxStream.prototype.getTwoDimCode =
  29861. function ccittFaxStreamGetTwoDimCode() {
  29862. var code = 0;
  29863. var p;
  29864. if (this.eoblock) {
  29865. code = this.lookBits(7);
  29866. p = twoDimTable[code];
  29867. if (p && p[0] > 0) {
  29868. this.eatBits(p[0]);
  29869. return p[1];
  29870. }
  29871. } else {
  29872. var result = this.findTableCode(1, 7, twoDimTable);
  29873. if (result[0] && result[2]) {
  29874. return result[1];
  29875. }
  29876. }
  29877. info('Bad two dim code');
  29878. return EOF;
  29879. };
  29880. CCITTFaxStream.prototype.getWhiteCode =
  29881. function ccittFaxStreamGetWhiteCode() {
  29882. var code = 0;
  29883. var p;
  29884. if (this.eoblock) {
  29885. code = this.lookBits(12);
  29886. if (code == EOF) {
  29887. return 1;
  29888. }
  29889. if ((code >> 5) === 0) {
  29890. p = whiteTable1[code];
  29891. } else {
  29892. p = whiteTable2[code >> 3];
  29893. }
  29894. if (p[0] > 0) {
  29895. this.eatBits(p[0]);
  29896. return p[1];
  29897. }
  29898. } else {
  29899. var result = this.findTableCode(1, 9, whiteTable2);
  29900. if (result[0]) {
  29901. return result[1];
  29902. }
  29903. result = this.findTableCode(11, 12, whiteTable1);
  29904. if (result[0]) {
  29905. return result[1];
  29906. }
  29907. }
  29908. info('bad white code');
  29909. this.eatBits(1);
  29910. return 1;
  29911. };
  29912. CCITTFaxStream.prototype.getBlackCode =
  29913. function ccittFaxStreamGetBlackCode() {
  29914. var code, p;
  29915. if (this.eoblock) {
  29916. code = this.lookBits(13);
  29917. if (code == EOF) {
  29918. return 1;
  29919. }
  29920. if ((code >> 7) === 0) {
  29921. p = blackTable1[code];
  29922. } else if ((code >> 9) === 0 && (code >> 7) !== 0) {
  29923. p = blackTable2[(code >> 1) - 64];
  29924. } else {
  29925. p = blackTable3[code >> 7];
  29926. }
  29927. if (p[0] > 0) {
  29928. this.eatBits(p[0]);
  29929. return p[1];
  29930. }
  29931. } else {
  29932. var result = this.findTableCode(2, 6, blackTable3);
  29933. if (result[0]) {
  29934. return result[1];
  29935. }
  29936. result = this.findTableCode(7, 12, blackTable2, 64);
  29937. if (result[0]) {
  29938. return result[1];
  29939. }
  29940. result = this.findTableCode(10, 13, blackTable1);
  29941. if (result[0]) {
  29942. return result[1];
  29943. }
  29944. }
  29945. info('bad black code');
  29946. this.eatBits(1);
  29947. return 1;
  29948. };
  29949. CCITTFaxStream.prototype.lookBits = function CCITTFaxStream_lookBits(n) {
  29950. var c;
  29951. while (this.inputBits < n) {
  29952. if ((c = this.str.getByte()) === -1) {
  29953. if (this.inputBits === 0) {
  29954. return EOF;
  29955. }
  29956. return ((this.inputBuf << (n - this.inputBits)) &
  29957. (0xFFFF >> (16 - n)));
  29958. }
  29959. this.inputBuf = (this.inputBuf << 8) + c;
  29960. this.inputBits += 8;
  29961. }
  29962. return (this.inputBuf >> (this.inputBits - n)) & (0xFFFF >> (16 - n));
  29963. };
  29964. CCITTFaxStream.prototype.eatBits = function CCITTFaxStream_eatBits(n) {
  29965. if ((this.inputBits -= n) < 0) {
  29966. this.inputBits = 0;
  29967. }
  29968. };
  29969. return CCITTFaxStream;
  29970. })();
  29971. var LZWStream = (function LZWStreamClosure() {
  29972. function LZWStream(str, maybeLength, earlyChange) {
  29973. this.str = str;
  29974. this.dict = str.dict;
  29975. this.cachedData = 0;
  29976. this.bitsCached = 0;
  29977. var maxLzwDictionarySize = 4096;
  29978. var lzwState = {
  29979. earlyChange: earlyChange,
  29980. codeLength: 9,
  29981. nextCode: 258,
  29982. dictionaryValues: new Uint8Array(maxLzwDictionarySize),
  29983. dictionaryLengths: new Uint16Array(maxLzwDictionarySize),
  29984. dictionaryPrevCodes: new Uint16Array(maxLzwDictionarySize),
  29985. currentSequence: new Uint8Array(maxLzwDictionarySize),
  29986. currentSequenceLength: 0
  29987. };
  29988. for (var i = 0; i < 256; ++i) {
  29989. lzwState.dictionaryValues[i] = i;
  29990. lzwState.dictionaryLengths[i] = 1;
  29991. }
  29992. this.lzwState = lzwState;
  29993. DecodeStream.call(this, maybeLength);
  29994. }
  29995. LZWStream.prototype = Object.create(DecodeStream.prototype);
  29996. LZWStream.prototype.readBits = function LZWStream_readBits(n) {
  29997. var bitsCached = this.bitsCached;
  29998. var cachedData = this.cachedData;
  29999. while (bitsCached < n) {
  30000. var c = this.str.getByte();
  30001. if (c === -1) {
  30002. this.eof = true;
  30003. return null;
  30004. }
  30005. cachedData = (cachedData << 8) | c;
  30006. bitsCached += 8;
  30007. }
  30008. this.bitsCached = (bitsCached -= n);
  30009. this.cachedData = cachedData;
  30010. this.lastCode = null;
  30011. return (cachedData >>> bitsCached) & ((1 << n) - 1);
  30012. };
  30013. LZWStream.prototype.readBlock = function LZWStream_readBlock() {
  30014. var blockSize = 512;
  30015. var estimatedDecodedSize = blockSize * 2, decodedSizeDelta = blockSize;
  30016. var i, j, q;
  30017. var lzwState = this.lzwState;
  30018. if (!lzwState) {
  30019. return; // eof was found
  30020. }
  30021. var earlyChange = lzwState.earlyChange;
  30022. var nextCode = lzwState.nextCode;
  30023. var dictionaryValues = lzwState.dictionaryValues;
  30024. var dictionaryLengths = lzwState.dictionaryLengths;
  30025. var dictionaryPrevCodes = lzwState.dictionaryPrevCodes;
  30026. var codeLength = lzwState.codeLength;
  30027. var prevCode = lzwState.prevCode;
  30028. var currentSequence = lzwState.currentSequence;
  30029. var currentSequenceLength = lzwState.currentSequenceLength;
  30030. var decodedLength = 0;
  30031. var currentBufferLength = this.bufferLength;
  30032. var buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  30033. for (i = 0; i < blockSize; i++) {
  30034. var code = this.readBits(codeLength);
  30035. var hasPrev = currentSequenceLength > 0;
  30036. if (code < 256) {
  30037. currentSequence[0] = code;
  30038. currentSequenceLength = 1;
  30039. } else if (code >= 258) {
  30040. if (code < nextCode) {
  30041. currentSequenceLength = dictionaryLengths[code];
  30042. for (j = currentSequenceLength - 1, q = code; j >= 0; j--) {
  30043. currentSequence[j] = dictionaryValues[q];
  30044. q = dictionaryPrevCodes[q];
  30045. }
  30046. } else {
  30047. currentSequence[currentSequenceLength++] = currentSequence[0];
  30048. }
  30049. } else if (code == 256) {
  30050. codeLength = 9;
  30051. nextCode = 258;
  30052. currentSequenceLength = 0;
  30053. continue;
  30054. } else {
  30055. this.eof = true;
  30056. delete this.lzwState;
  30057. break;
  30058. }
  30059. if (hasPrev) {
  30060. dictionaryPrevCodes[nextCode] = prevCode;
  30061. dictionaryLengths[nextCode] = dictionaryLengths[prevCode] + 1;
  30062. dictionaryValues[nextCode] = currentSequence[0];
  30063. nextCode++;
  30064. codeLength = (nextCode + earlyChange) & (nextCode + earlyChange - 1) ?
  30065. codeLength : Math.min(Math.log(nextCode + earlyChange) /
  30066. 0.6931471805599453 + 1, 12) | 0;
  30067. }
  30068. prevCode = code;
  30069. decodedLength += currentSequenceLength;
  30070. if (estimatedDecodedSize < decodedLength) {
  30071. do {
  30072. estimatedDecodedSize += decodedSizeDelta;
  30073. } while (estimatedDecodedSize < decodedLength);
  30074. buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  30075. }
  30076. for (j = 0; j < currentSequenceLength; j++) {
  30077. buffer[currentBufferLength++] = currentSequence[j];
  30078. }
  30079. }
  30080. lzwState.nextCode = nextCode;
  30081. lzwState.codeLength = codeLength;
  30082. lzwState.prevCode = prevCode;
  30083. lzwState.currentSequenceLength = currentSequenceLength;
  30084. this.bufferLength = currentBufferLength;
  30085. };
  30086. return LZWStream;
  30087. })();
  30088. var NullStream = (function NullStreamClosure() {
  30089. function NullStream() {
  30090. Stream.call(this, new Uint8Array(0));
  30091. }
  30092. NullStream.prototype = Stream.prototype;
  30093. return NullStream;
  30094. })();
  30095. var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
  30096. setup: function wphSetup(handler) {
  30097. var pdfManager;
  30098. function loadDocument(recoveryMode) {
  30099. var loadDocumentCapability = createPromiseCapability();
  30100. var parseSuccess = function parseSuccess() {
  30101. var numPagesPromise = pdfManager.ensureDoc('numPages');
  30102. var fingerprintPromise = pdfManager.ensureDoc('fingerprint');
  30103. var encryptedPromise = pdfManager.ensureXRef('encrypt');
  30104. Promise.all([numPagesPromise, fingerprintPromise,
  30105. encryptedPromise]).then(function onDocReady(results) {
  30106. var doc = {
  30107. numPages: results[0],
  30108. fingerprint: results[1],
  30109. encrypted: !!results[2],
  30110. };
  30111. loadDocumentCapability.resolve(doc);
  30112. },
  30113. parseFailure);
  30114. };
  30115. var parseFailure = function parseFailure(e) {
  30116. loadDocumentCapability.reject(e);
  30117. };
  30118. pdfManager.ensureDoc('checkHeader', []).then(function() {
  30119. pdfManager.ensureDoc('parseStartXRef', []).then(function() {
  30120. pdfManager.ensureDoc('parse', [recoveryMode]).then(
  30121. parseSuccess, parseFailure);
  30122. }, parseFailure);
  30123. }, parseFailure);
  30124. return loadDocumentCapability.promise;
  30125. }
  30126. function getPdfManager(data) {
  30127. var pdfManagerCapability = createPromiseCapability();
  30128. var source = data.source;
  30129. var disableRange = data.disableRange;
  30130. if (source.data) {
  30131. try {
  30132. pdfManager = new LocalPdfManager(source.data, source.password);
  30133. pdfManagerCapability.resolve();
  30134. } catch (ex) {
  30135. pdfManagerCapability.reject(ex);
  30136. }
  30137. return pdfManagerCapability.promise;
  30138. } else if (source.chunkedViewerLoading) {
  30139. try {
  30140. pdfManager = new NetworkPdfManager(source, handler);
  30141. pdfManagerCapability.resolve();
  30142. } catch (ex) {
  30143. pdfManagerCapability.reject(ex);
  30144. }
  30145. return pdfManagerCapability.promise;
  30146. }
  30147. var networkManager = new NetworkManager(source.url, {
  30148. httpHeaders: source.httpHeaders,
  30149. withCredentials: source.withCredentials
  30150. });
  30151. var fullRequestXhrId = networkManager.requestFull({
  30152. onHeadersReceived: function onHeadersReceived() {
  30153. if (disableRange) {
  30154. return;
  30155. }
  30156. var fullRequestXhr = networkManager.getRequestXhr(fullRequestXhrId);
  30157. if (fullRequestXhr.getResponseHeader('Accept-Ranges') !== 'bytes') {
  30158. return;
  30159. }
  30160. var contentEncoding =
  30161. fullRequestXhr.getResponseHeader('Content-Encoding') || 'identity';
  30162. if (contentEncoding !== 'identity') {
  30163. return;
  30164. }
  30165. var length = fullRequestXhr.getResponseHeader('Content-Length');
  30166. length = parseInt(length, 10);
  30167. if (!isInt(length)) {
  30168. return;
  30169. }
  30170. source.length = length;
  30171. if (length <= 2 * RANGE_CHUNK_SIZE) {
  30172. // The file size is smaller than the size of two chunks, so it does
  30173. // not make any sense to abort the request and retry with a range
  30174. // request.
  30175. return;
  30176. }
  30177. // NOTE: by cancelling the full request, and then issuing range
  30178. // requests, there will be an issue for sites where you can only
  30179. // request the pdf once. However, if this is the case, then the
  30180. // server should not be returning that it can support range requests.
  30181. networkManager.abortRequest(fullRequestXhrId);
  30182. try {
  30183. pdfManager = new NetworkPdfManager(source, handler);
  30184. pdfManagerCapability.resolve(pdfManager);
  30185. } catch (ex) {
  30186. pdfManagerCapability.reject(ex);
  30187. }
  30188. },
  30189. onDone: function onDone(args) {
  30190. // the data is array, instantiating directly from it
  30191. try {
  30192. pdfManager = new LocalPdfManager(args.chunk, source.password);
  30193. pdfManagerCapability.resolve();
  30194. } catch (ex) {
  30195. pdfManagerCapability.reject(ex);
  30196. }
  30197. },
  30198. onError: function onError(status) {
  30199. if (status == 404) {
  30200. var exception = new MissingPDFException('Missing PDF "' +
  30201. source.url + '".');
  30202. handler.send('MissingPDF', { exception: exception });
  30203. } else {
  30204. handler.send('DocError', 'Unexpected server response (' +
  30205. status + ') while retrieving PDF "' +
  30206. source.url + '".');
  30207. }
  30208. },
  30209. onProgress: function onProgress(evt) {
  30210. handler.send('DocProgress', {
  30211. loaded: evt.loaded,
  30212. total: evt.lengthComputable ? evt.total : source.length
  30213. });
  30214. }
  30215. });
  30216. return pdfManagerCapability.promise;
  30217. }
  30218. handler.on('test', function wphSetupTest(data) {
  30219. // check if Uint8Array can be sent to worker
  30220. if (!(data instanceof Uint8Array)) {
  30221. handler.send('test', false);
  30222. return;
  30223. }
  30224. // making sure postMessage transfers are working
  30225. var supportTransfers = data[0] === 255;
  30226. handler.postMessageTransfers = supportTransfers;
  30227. // check if the response property is supported by xhr
  30228. var xhr = new XMLHttpRequest();
  30229. var responseExists = 'response' in xhr;
  30230. // check if the property is actually implemented
  30231. try {
  30232. var dummy = xhr.responseType;
  30233. } catch (e) {
  30234. responseExists = false;
  30235. }
  30236. if (!responseExists) {
  30237. handler.send('test', false);
  30238. return;
  30239. }
  30240. handler.send('test', {
  30241. supportTypedArray: true,
  30242. supportTransfers: supportTransfers
  30243. });
  30244. });
  30245. handler.on('GetDocRequest', function wphSetupDoc(data) {
  30246. var onSuccess = function(doc) {
  30247. handler.send('GetDoc', { pdfInfo: doc });
  30248. };
  30249. var onFailure = function(e) {
  30250. if (e instanceof PasswordException) {
  30251. if (e.code === PasswordResponses.NEED_PASSWORD) {
  30252. handler.send('NeedPassword', {
  30253. exception: e
  30254. });
  30255. } else if (e.code === PasswordResponses.INCORRECT_PASSWORD) {
  30256. handler.send('IncorrectPassword', {
  30257. exception: e
  30258. });
  30259. }
  30260. } else if (e instanceof InvalidPDFException) {
  30261. handler.send('InvalidPDF', {
  30262. exception: e
  30263. });
  30264. } else if (e instanceof MissingPDFException) {
  30265. handler.send('MissingPDF', {
  30266. exception: e
  30267. });
  30268. } else {
  30269. handler.send('UnknownError', {
  30270. exception: new UnknownErrorException(e.message, e.toString())
  30271. });
  30272. }
  30273. };
  30274. PDFJS.maxImageSize = data.maxImageSize === undefined ?
  30275. -1 : data.maxImageSize;
  30276. PDFJS.disableFontFace = data.disableFontFace;
  30277. PDFJS.disableCreateObjectURL = data.disableCreateObjectURL;
  30278. PDFJS.verbosity = data.verbosity;
  30279. PDFJS.cMapUrl = data.cMapUrl === undefined ?
  30280. null : data.cMapUrl;
  30281. PDFJS.cMapPacked = data.cMapPacked === true;
  30282. getPdfManager(data).then(function () {
  30283. pdfManager.onLoadedStream().then(function(stream) {
  30284. handler.send('DataLoaded', { length: stream.bytes.byteLength });
  30285. });
  30286. }).then(function pdfManagerReady() {
  30287. loadDocument(false).then(onSuccess, function loadFailure(ex) {
  30288. // Try again with recoveryMode == true
  30289. if (!(ex instanceof XRefParseException)) {
  30290. if (ex instanceof PasswordException) {
  30291. // after password exception prepare to receive a new password
  30292. // to repeat loading
  30293. pdfManager.passwordChanged().then(pdfManagerReady);
  30294. }
  30295. onFailure(ex);
  30296. return;
  30297. }
  30298. pdfManager.requestLoadedStream();
  30299. pdfManager.onLoadedStream().then(function() {
  30300. loadDocument(true).then(onSuccess, onFailure);
  30301. });
  30302. }, onFailure);
  30303. }, onFailure);
  30304. });
  30305. handler.on('GetPage', function wphSetupGetPage(data) {
  30306. return pdfManager.getPage(data.pageIndex).then(function(page) {
  30307. var rotatePromise = pdfManager.ensure(page, 'rotate');
  30308. var refPromise = pdfManager.ensure(page, 'ref');
  30309. var viewPromise = pdfManager.ensure(page, 'view');
  30310. return Promise.all([rotatePromise, refPromise, viewPromise]).then(
  30311. function(results) {
  30312. return {
  30313. rotate: results[0],
  30314. ref: results[1],
  30315. view: results[2]
  30316. };
  30317. });
  30318. });
  30319. });
  30320. handler.on('GetPageIndex', function wphSetupGetPageIndex(data) {
  30321. var ref = new Ref(data.ref.num, data.ref.gen);
  30322. var catalog = pdfManager.pdfDocument.catalog;
  30323. return catalog.getPageIndex(ref);
  30324. });
  30325. handler.on('GetDestinations',
  30326. function wphSetupGetDestinations(data) {
  30327. return pdfManager.ensureCatalog('destinations');
  30328. }
  30329. );
  30330. handler.on('GetAttachments',
  30331. function wphSetupGetAttachments(data) {
  30332. return pdfManager.ensureCatalog('attachments');
  30333. }
  30334. );
  30335. handler.on('GetJavaScript',
  30336. function wphSetupGetJavaScript(data) {
  30337. return pdfManager.ensureCatalog('javaScript');
  30338. }
  30339. );
  30340. handler.on('GetOutline',
  30341. function wphSetupGetOutline(data) {
  30342. return pdfManager.ensureCatalog('documentOutline');
  30343. }
  30344. );
  30345. handler.on('GetMetadata',
  30346. function wphSetupGetMetadata(data) {
  30347. return Promise.all([pdfManager.ensureDoc('documentInfo'),
  30348. pdfManager.ensureCatalog('metadata')]);
  30349. }
  30350. );
  30351. handler.on('GetData', function wphSetupGetData(data) {
  30352. pdfManager.requestLoadedStream();
  30353. return pdfManager.onLoadedStream().then(function(stream) {
  30354. return stream.bytes;
  30355. });
  30356. });
  30357. handler.on('GetStats',
  30358. function wphSetupGetStats(data) {
  30359. return pdfManager.pdfDocument.xref.stats;
  30360. }
  30361. );
  30362. handler.on('UpdatePassword', function wphSetupUpdatePassword(data) {
  30363. pdfManager.updatePassword(data);
  30364. });
  30365. handler.on('GetAnnotations', function wphSetupGetAnnotations(data) {
  30366. return pdfManager.getPage(data.pageIndex).then(function(page) {
  30367. return pdfManager.ensure(page, 'getAnnotationsData', []);
  30368. });
  30369. });
  30370. handler.on('RenderPageRequest', function wphSetupRenderPage(data) {
  30371. pdfManager.getPage(data.pageIndex).then(function(page) {
  30372. var pageNum = data.pageIndex + 1;
  30373. var start = Date.now();
  30374. // Pre compile the pdf page and fetch the fonts/images.
  30375. page.getOperatorList(handler, data.intent).then(function(operatorList) {
  30376. info('page=' + pageNum + ' - getOperatorList: time=' +
  30377. (Date.now() - start) + 'ms, len=' + operatorList.fnArray.length);
  30378. }, function(e) {
  30379. var minimumStackMessage =
  30380. 'worker.js: while trying to getPage() and getOperatorList()';
  30381. var wrappedException;
  30382. // Turn the error into an obj that can be serialized
  30383. if (typeof e === 'string') {
  30384. wrappedException = {
  30385. message: e,
  30386. stack: minimumStackMessage
  30387. };
  30388. } else if (typeof e === 'object') {
  30389. wrappedException = {
  30390. message: e.message || e.toString(),
  30391. stack: e.stack || minimumStackMessage
  30392. };
  30393. } else {
  30394. wrappedException = {
  30395. message: 'Unknown exception type: ' + (typeof e),
  30396. stack: minimumStackMessage
  30397. };
  30398. }
  30399. handler.send('PageError', {
  30400. pageNum: pageNum,
  30401. error: wrappedException,
  30402. intent: data.intent
  30403. });
  30404. });
  30405. });
  30406. }, this);
  30407. handler.on('GetTextContent', function wphExtractText(data) {
  30408. return pdfManager.getPage(data.pageIndex).then(function(page) {
  30409. var pageNum = data.pageIndex + 1;
  30410. var start = Date.now();
  30411. return page.extractTextContent().then(function(textContent) {
  30412. info('text indexing: page=' + pageNum + ' - time=' +
  30413. (Date.now() - start) + 'ms');
  30414. return textContent;
  30415. });
  30416. });
  30417. });
  30418. handler.on('Cleanup', function wphCleanup(data) {
  30419. return pdfManager.cleanup();
  30420. });
  30421. handler.on('Terminate', function wphTerminate(data) {
  30422. pdfManager.terminate();
  30423. });
  30424. }
  30425. };
  30426. var consoleTimer = {};
  30427. var workerConsole = {
  30428. log: function log() {
  30429. var args = Array.prototype.slice.call(arguments);
  30430. globalScope.postMessage({
  30431. action: 'console_log',
  30432. data: args
  30433. });
  30434. },
  30435. error: function error() {
  30436. var args = Array.prototype.slice.call(arguments);
  30437. globalScope.postMessage({
  30438. action: 'console_error',
  30439. data: args
  30440. });
  30441. throw 'pdf.js execution error';
  30442. },
  30443. time: function time(name) {
  30444. consoleTimer[name] = Date.now();
  30445. },
  30446. timeEnd: function timeEnd(name) {
  30447. var time = consoleTimer[name];
  30448. if (!time) {
  30449. error('Unknown timer name ' + name);
  30450. }
  30451. this.log('Timer:', name, Date.now() - time);
  30452. }
  30453. };
  30454. // Worker thread?
  30455. if (typeof window === 'undefined') {
  30456. if (!('console' in globalScope)) {
  30457. globalScope.console = workerConsole;
  30458. }
  30459. // Listen for unsupported features so we can pass them on to the main thread.
  30460. PDFJS.UnsupportedManager.listen(function (msg) {
  30461. globalScope.postMessage({
  30462. action: '_unsupported_feature',
  30463. data: msg
  30464. });
  30465. });
  30466. var handler = new MessageHandler('worker_processor', this);
  30467. WorkerMessageHandler.setup(handler);
  30468. }
  30469. /* This class implements the QM Coder decoding as defined in
  30470. * JPEG 2000 Part I Final Committee Draft Version 1.0
  30471. * Annex C.3 Arithmetic decoding procedure
  30472. * available at http://www.jpeg.org/public/fcd15444-1.pdf
  30473. *
  30474. * The arithmetic decoder is used in conjunction with context models to decode
  30475. * JPEG2000 and JBIG2 streams.
  30476. */
  30477. var ArithmeticDecoder = (function ArithmeticDecoderClosure() {
  30478. // Table C-2
  30479. var QeTable = [
  30480. {qe: 0x5601, nmps: 1, nlps: 1, switchFlag: 1},
  30481. {qe: 0x3401, nmps: 2, nlps: 6, switchFlag: 0},
  30482. {qe: 0x1801, nmps: 3, nlps: 9, switchFlag: 0},
  30483. {qe: 0x0AC1, nmps: 4, nlps: 12, switchFlag: 0},
  30484. {qe: 0x0521, nmps: 5, nlps: 29, switchFlag: 0},
  30485. {qe: 0x0221, nmps: 38, nlps: 33, switchFlag: 0},
  30486. {qe: 0x5601, nmps: 7, nlps: 6, switchFlag: 1},
  30487. {qe: 0x5401, nmps: 8, nlps: 14, switchFlag: 0},
  30488. {qe: 0x4801, nmps: 9, nlps: 14, switchFlag: 0},
  30489. {qe: 0x3801, nmps: 10, nlps: 14, switchFlag: 0},
  30490. {qe: 0x3001, nmps: 11, nlps: 17, switchFlag: 0},
  30491. {qe: 0x2401, nmps: 12, nlps: 18, switchFlag: 0},
  30492. {qe: 0x1C01, nmps: 13, nlps: 20, switchFlag: 0},
  30493. {qe: 0x1601, nmps: 29, nlps: 21, switchFlag: 0},
  30494. {qe: 0x5601, nmps: 15, nlps: 14, switchFlag: 1},
  30495. {qe: 0x5401, nmps: 16, nlps: 14, switchFlag: 0},
  30496. {qe: 0x5101, nmps: 17, nlps: 15, switchFlag: 0},
  30497. {qe: 0x4801, nmps: 18, nlps: 16, switchFlag: 0},
  30498. {qe: 0x3801, nmps: 19, nlps: 17, switchFlag: 0},
  30499. {qe: 0x3401, nmps: 20, nlps: 18, switchFlag: 0},
  30500. {qe: 0x3001, nmps: 21, nlps: 19, switchFlag: 0},
  30501. {qe: 0x2801, nmps: 22, nlps: 19, switchFlag: 0},
  30502. {qe: 0x2401, nmps: 23, nlps: 20, switchFlag: 0},
  30503. {qe: 0x2201, nmps: 24, nlps: 21, switchFlag: 0},
  30504. {qe: 0x1C01, nmps: 25, nlps: 22, switchFlag: 0},
  30505. {qe: 0x1801, nmps: 26, nlps: 23, switchFlag: 0},
  30506. {qe: 0x1601, nmps: 27, nlps: 24, switchFlag: 0},
  30507. {qe: 0x1401, nmps: 28, nlps: 25, switchFlag: 0},
  30508. {qe: 0x1201, nmps: 29, nlps: 26, switchFlag: 0},
  30509. {qe: 0x1101, nmps: 30, nlps: 27, switchFlag: 0},
  30510. {qe: 0x0AC1, nmps: 31, nlps: 28, switchFlag: 0},
  30511. {qe: 0x09C1, nmps: 32, nlps: 29, switchFlag: 0},
  30512. {qe: 0x08A1, nmps: 33, nlps: 30, switchFlag: 0},
  30513. {qe: 0x0521, nmps: 34, nlps: 31, switchFlag: 0},
  30514. {qe: 0x0441, nmps: 35, nlps: 32, switchFlag: 0},
  30515. {qe: 0x02A1, nmps: 36, nlps: 33, switchFlag: 0},
  30516. {qe: 0x0221, nmps: 37, nlps: 34, switchFlag: 0},
  30517. {qe: 0x0141, nmps: 38, nlps: 35, switchFlag: 0},
  30518. {qe: 0x0111, nmps: 39, nlps: 36, switchFlag: 0},
  30519. {qe: 0x0085, nmps: 40, nlps: 37, switchFlag: 0},
  30520. {qe: 0x0049, nmps: 41, nlps: 38, switchFlag: 0},
  30521. {qe: 0x0025, nmps: 42, nlps: 39, switchFlag: 0},
  30522. {qe: 0x0015, nmps: 43, nlps: 40, switchFlag: 0},
  30523. {qe: 0x0009, nmps: 44, nlps: 41, switchFlag: 0},
  30524. {qe: 0x0005, nmps: 45, nlps: 42, switchFlag: 0},
  30525. {qe: 0x0001, nmps: 45, nlps: 43, switchFlag: 0},
  30526. {qe: 0x5601, nmps: 46, nlps: 46, switchFlag: 0}
  30527. ];
  30528. // C.3.5 Initialisation of the decoder (INITDEC)
  30529. function ArithmeticDecoder(data, start, end) {
  30530. this.data = data;
  30531. this.bp = start;
  30532. this.dataEnd = end;
  30533. this.chigh = data[start];
  30534. this.clow = 0;
  30535. this.byteIn();
  30536. this.chigh = ((this.chigh << 7) & 0xFFFF) | ((this.clow >> 9) & 0x7F);
  30537. this.clow = (this.clow << 7) & 0xFFFF;
  30538. this.ct -= 7;
  30539. this.a = 0x8000;
  30540. }
  30541. ArithmeticDecoder.prototype = {
  30542. // C.3.4 Compressed data input (BYTEIN)
  30543. byteIn: function ArithmeticDecoder_byteIn() {
  30544. var data = this.data;
  30545. var bp = this.bp;
  30546. if (data[bp] == 0xFF) {
  30547. var b1 = data[bp + 1];
  30548. if (b1 > 0x8F) {
  30549. this.clow += 0xFF00;
  30550. this.ct = 8;
  30551. } else {
  30552. bp++;
  30553. this.clow += (data[bp] << 9);
  30554. this.ct = 7;
  30555. this.bp = bp;
  30556. }
  30557. } else {
  30558. bp++;
  30559. this.clow += bp < this.dataEnd ? (data[bp] << 8) : 0xFF00;
  30560. this.ct = 8;
  30561. this.bp = bp;
  30562. }
  30563. if (this.clow > 0xFFFF) {
  30564. this.chigh += (this.clow >> 16);
  30565. this.clow &= 0xFFFF;
  30566. }
  30567. },
  30568. // C.3.2 Decoding a decision (DECODE)
  30569. readBit: function ArithmeticDecoder_readBit(contexts, pos) {
  30570. // contexts are packed into 1 byte:
  30571. // highest 7 bits carry cx.index, lowest bit carries cx.mps
  30572. var cx_index = contexts[pos] >> 1, cx_mps = contexts[pos] & 1;
  30573. var qeTableIcx = QeTable[cx_index];
  30574. var qeIcx = qeTableIcx.qe;
  30575. var d;
  30576. var a = this.a - qeIcx;
  30577. if (this.chigh < qeIcx) {
  30578. // exchangeLps
  30579. if (a < qeIcx) {
  30580. a = qeIcx;
  30581. d = cx_mps;
  30582. cx_index = qeTableIcx.nmps;
  30583. } else {
  30584. a = qeIcx;
  30585. d = 1 ^ cx_mps;
  30586. if (qeTableIcx.switchFlag === 1) {
  30587. cx_mps = d;
  30588. }
  30589. cx_index = qeTableIcx.nlps;
  30590. }
  30591. } else {
  30592. this.chigh -= qeIcx;
  30593. if ((a & 0x8000) !== 0) {
  30594. this.a = a;
  30595. return cx_mps;
  30596. }
  30597. // exchangeMps
  30598. if (a < qeIcx) {
  30599. d = 1 ^ cx_mps;
  30600. if (qeTableIcx.switchFlag === 1) {
  30601. cx_mps = d;
  30602. }
  30603. cx_index = qeTableIcx.nlps;
  30604. } else {
  30605. d = cx_mps;
  30606. cx_index = qeTableIcx.nmps;
  30607. }
  30608. }
  30609. // C.3.3 renormD;
  30610. do {
  30611. if (this.ct === 0) {
  30612. this.byteIn();
  30613. }
  30614. a <<= 1;
  30615. this.chigh = ((this.chigh << 1) & 0xFFFF) | ((this.clow >> 15) & 1);
  30616. this.clow = (this.clow << 1) & 0xFFFF;
  30617. this.ct--;
  30618. } while ((a & 0x8000) === 0);
  30619. this.a = a;
  30620. contexts[pos] = cx_index << 1 | cx_mps;
  30621. return d;
  30622. }
  30623. };
  30624. return ArithmeticDecoder;
  30625. })();
  30626. var JpegImage = (function jpegImage() {
  30627. var dctZigZag = new Uint8Array([
  30628. 0,
  30629. 1, 8,
  30630. 16, 9, 2,
  30631. 3, 10, 17, 24,
  30632. 32, 25, 18, 11, 4,
  30633. 5, 12, 19, 26, 33, 40,
  30634. 48, 41, 34, 27, 20, 13, 6,
  30635. 7, 14, 21, 28, 35, 42, 49, 56,
  30636. 57, 50, 43, 36, 29, 22, 15,
  30637. 23, 30, 37, 44, 51, 58,
  30638. 59, 52, 45, 38, 31,
  30639. 39, 46, 53, 60,
  30640. 61, 54, 47,
  30641. 55, 62,
  30642. 63
  30643. ]);
  30644. var dctCos1 = 4017; // cos(pi/16)
  30645. var dctSin1 = 799; // sin(pi/16)
  30646. var dctCos3 = 3406; // cos(3*pi/16)
  30647. var dctSin3 = 2276; // sin(3*pi/16)
  30648. var dctCos6 = 1567; // cos(6*pi/16)
  30649. var dctSin6 = 3784; // sin(6*pi/16)
  30650. var dctSqrt2 = 5793; // sqrt(2)
  30651. var dctSqrt1d2 = 2896; // sqrt(2) / 2
  30652. function constructor() {
  30653. }
  30654. function buildHuffmanTable(codeLengths, values) {
  30655. var k = 0, code = [], i, j, length = 16;
  30656. while (length > 0 && !codeLengths[length - 1]) {
  30657. length--;
  30658. }
  30659. code.push({children: [], index: 0});
  30660. var p = code[0], q;
  30661. for (i = 0; i < length; i++) {
  30662. for (j = 0; j < codeLengths[i]; j++) {
  30663. p = code.pop();
  30664. p.children[p.index] = values[k];
  30665. while (p.index > 0) {
  30666. p = code.pop();
  30667. }
  30668. p.index++;
  30669. code.push(p);
  30670. while (code.length <= i) {
  30671. code.push(q = {children: [], index: 0});
  30672. p.children[p.index] = q.children;
  30673. p = q;
  30674. }
  30675. k++;
  30676. }
  30677. if (i + 1 < length) {
  30678. // p here points to last code
  30679. code.push(q = {children: [], index: 0});
  30680. p.children[p.index] = q.children;
  30681. p = q;
  30682. }
  30683. }
  30684. return code[0].children;
  30685. }
  30686. function getBlockBufferOffset(component, row, col) {
  30687. return 64 * ((component.blocksPerLine + 1) * row + col);
  30688. }
  30689. function decodeScan(data, offset, frame, components, resetInterval,
  30690. spectralStart, spectralEnd, successivePrev, successive) {
  30691. var precision = frame.precision;
  30692. var samplesPerLine = frame.samplesPerLine;
  30693. var scanLines = frame.scanLines;
  30694. var mcusPerLine = frame.mcusPerLine;
  30695. var progressive = frame.progressive;
  30696. var maxH = frame.maxH, maxV = frame.maxV;
  30697. var startOffset = offset, bitsData = 0, bitsCount = 0;
  30698. function readBit() {
  30699. if (bitsCount > 0) {
  30700. bitsCount--;
  30701. return (bitsData >> bitsCount) & 1;
  30702. }
  30703. bitsData = data[offset++];
  30704. if (bitsData == 0xFF) {
  30705. var nextByte = data[offset++];
  30706. if (nextByte) {
  30707. throw 'unexpected marker: ' +
  30708. ((bitsData << 8) | nextByte).toString(16);
  30709. }
  30710. // unstuff 0
  30711. }
  30712. bitsCount = 7;
  30713. return bitsData >>> 7;
  30714. }
  30715. function decodeHuffman(tree) {
  30716. var node = tree;
  30717. var bit;
  30718. while ((bit = readBit()) !== null) {
  30719. node = node[bit];
  30720. if (typeof node === 'number') {
  30721. return node;
  30722. }
  30723. if (typeof node !== 'object') {
  30724. throw 'invalid huffman sequence';
  30725. }
  30726. }
  30727. return null;
  30728. }
  30729. function receive(length) {
  30730. var n = 0;
  30731. while (length > 0) {
  30732. var bit = readBit();
  30733. if (bit === null) {
  30734. return;
  30735. }
  30736. n = (n << 1) | bit;
  30737. length--;
  30738. }
  30739. return n;
  30740. }
  30741. function receiveAndExtend(length) {
  30742. if (length === 1) {
  30743. return readBit() === 1 ? 1 : -1;
  30744. }
  30745. var n = receive(length);
  30746. if (n >= 1 << (length - 1)) {
  30747. return n;
  30748. }
  30749. return n + (-1 << length) + 1;
  30750. }
  30751. function decodeBaseline(component, offset) {
  30752. var t = decodeHuffman(component.huffmanTableDC);
  30753. var diff = t === 0 ? 0 : receiveAndExtend(t);
  30754. component.blockData[offset] = (component.pred += diff);
  30755. var k = 1;
  30756. while (k < 64) {
  30757. var rs = decodeHuffman(component.huffmanTableAC);
  30758. var s = rs & 15, r = rs >> 4;
  30759. if (s === 0) {
  30760. if (r < 15) {
  30761. break;
  30762. }
  30763. k += 16;
  30764. continue;
  30765. }
  30766. k += r;
  30767. var z = dctZigZag[k];
  30768. component.blockData[offset + z] = receiveAndExtend(s);
  30769. k++;
  30770. }
  30771. }
  30772. function decodeDCFirst(component, offset) {
  30773. var t = decodeHuffman(component.huffmanTableDC);
  30774. var diff = t === 0 ? 0 : (receiveAndExtend(t) << successive);
  30775. component.blockData[offset] = (component.pred += diff);
  30776. }
  30777. function decodeDCSuccessive(component, offset) {
  30778. component.blockData[offset] |= readBit() << successive;
  30779. }
  30780. var eobrun = 0;
  30781. function decodeACFirst(component, offset) {
  30782. if (eobrun > 0) {
  30783. eobrun--;
  30784. return;
  30785. }
  30786. var k = spectralStart, e = spectralEnd;
  30787. while (k <= e) {
  30788. var rs = decodeHuffman(component.huffmanTableAC);
  30789. var s = rs & 15, r = rs >> 4;
  30790. if (s === 0) {
  30791. if (r < 15) {
  30792. eobrun = receive(r) + (1 << r) - 1;
  30793. break;
  30794. }
  30795. k += 16;
  30796. continue;
  30797. }
  30798. k += r;
  30799. var z = dctZigZag[k];
  30800. component.blockData[offset + z] =
  30801. receiveAndExtend(s) * (1 << successive);
  30802. k++;
  30803. }
  30804. }
  30805. var successiveACState = 0, successiveACNextValue;
  30806. function decodeACSuccessive(component, offset) {
  30807. var k = spectralStart;
  30808. var e = spectralEnd;
  30809. var r = 0;
  30810. var s;
  30811. var rs;
  30812. while (k <= e) {
  30813. var z = dctZigZag[k];
  30814. switch (successiveACState) {
  30815. case 0: // initial state
  30816. rs = decodeHuffman(component.huffmanTableAC);
  30817. s = rs & 15;
  30818. r = rs >> 4;
  30819. if (s === 0) {
  30820. if (r < 15) {
  30821. eobrun = receive(r) + (1 << r);
  30822. successiveACState = 4;
  30823. } else {
  30824. r = 16;
  30825. successiveACState = 1;
  30826. }
  30827. } else {
  30828. if (s !== 1) {
  30829. throw 'invalid ACn encoding';
  30830. }
  30831. successiveACNextValue = receiveAndExtend(s);
  30832. successiveACState = r ? 2 : 3;
  30833. }
  30834. continue;
  30835. case 1: // skipping r zero items
  30836. case 2:
  30837. if (component.blockData[offset + z]) {
  30838. component.blockData[offset + z] += (readBit() << successive);
  30839. } else {
  30840. r--;
  30841. if (r === 0) {
  30842. successiveACState = successiveACState == 2 ? 3 : 0;
  30843. }
  30844. }
  30845. break;
  30846. case 3: // set value for a zero item
  30847. if (component.blockData[offset + z]) {
  30848. component.blockData[offset + z] += (readBit() << successive);
  30849. } else {
  30850. component.blockData[offset + z] =
  30851. successiveACNextValue << successive;
  30852. successiveACState = 0;
  30853. }
  30854. break;
  30855. case 4: // eob
  30856. if (component.blockData[offset + z]) {
  30857. component.blockData[offset + z] += (readBit() << successive);
  30858. }
  30859. break;
  30860. }
  30861. k++;
  30862. }
  30863. if (successiveACState === 4) {
  30864. eobrun--;
  30865. if (eobrun === 0) {
  30866. successiveACState = 0;
  30867. }
  30868. }
  30869. }
  30870. function decodeMcu(component, decode, mcu, row, col) {
  30871. var mcuRow = (mcu / mcusPerLine) | 0;
  30872. var mcuCol = mcu % mcusPerLine;
  30873. var blockRow = mcuRow * component.v + row;
  30874. var blockCol = mcuCol * component.h + col;
  30875. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  30876. decode(component, offset);
  30877. }
  30878. function decodeBlock(component, decode, mcu) {
  30879. var blockRow = (mcu / component.blocksPerLine) | 0;
  30880. var blockCol = mcu % component.blocksPerLine;
  30881. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  30882. decode(component, offset);
  30883. }
  30884. var componentsLength = components.length;
  30885. var component, i, j, k, n;
  30886. var decodeFn;
  30887. if (progressive) {
  30888. if (spectralStart === 0) {
  30889. decodeFn = successivePrev === 0 ? decodeDCFirst : decodeDCSuccessive;
  30890. } else {
  30891. decodeFn = successivePrev === 0 ? decodeACFirst : decodeACSuccessive;
  30892. }
  30893. } else {
  30894. decodeFn = decodeBaseline;
  30895. }
  30896. var mcu = 0, marker;
  30897. var mcuExpected;
  30898. if (componentsLength == 1) {
  30899. mcuExpected = components[0].blocksPerLine * components[0].blocksPerColumn;
  30900. } else {
  30901. mcuExpected = mcusPerLine * frame.mcusPerColumn;
  30902. }
  30903. if (!resetInterval) {
  30904. resetInterval = mcuExpected;
  30905. }
  30906. var h, v;
  30907. while (mcu < mcuExpected) {
  30908. // reset interval stuff
  30909. for (i = 0; i < componentsLength; i++) {
  30910. components[i].pred = 0;
  30911. }
  30912. eobrun = 0;
  30913. if (componentsLength == 1) {
  30914. component = components[0];
  30915. for (n = 0; n < resetInterval; n++) {
  30916. decodeBlock(component, decodeFn, mcu);
  30917. mcu++;
  30918. }
  30919. } else {
  30920. for (n = 0; n < resetInterval; n++) {
  30921. for (i = 0; i < componentsLength; i++) {
  30922. component = components[i];
  30923. h = component.h;
  30924. v = component.v;
  30925. for (j = 0; j < v; j++) {
  30926. for (k = 0; k < h; k++) {
  30927. decodeMcu(component, decodeFn, mcu, j, k);
  30928. }
  30929. }
  30930. }
  30931. mcu++;
  30932. }
  30933. }
  30934. // find marker
  30935. bitsCount = 0;
  30936. marker = (data[offset] << 8) | data[offset + 1];
  30937. if (marker <= 0xFF00) {
  30938. throw 'marker was not found';
  30939. }
  30940. if (marker >= 0xFFD0 && marker <= 0xFFD7) { // RSTx
  30941. offset += 2;
  30942. } else {
  30943. break;
  30944. }
  30945. }
  30946. return offset - startOffset;
  30947. }
  30948. // A port of poppler's IDCT method which in turn is taken from:
  30949. // Christoph Loeffler, Adriaan Ligtenberg, George S. Moschytz,
  30950. // 'Practical Fast 1-D DCT Algorithms with 11 Multiplications',
  30951. // IEEE Intl. Conf. on Acoustics, Speech & Signal Processing, 1989,
  30952. // 988-991.
  30953. function quantizeAndInverse(component, blockBufferOffset, p) {
  30954. var qt = component.quantizationTable, blockData = component.blockData;
  30955. var v0, v1, v2, v3, v4, v5, v6, v7;
  30956. var p0, p1, p2, p3, p4, p5, p6, p7;
  30957. var t;
  30958. // inverse DCT on rows
  30959. for (var row = 0; row < 64; row += 8) {
  30960. // gather block data
  30961. p0 = blockData[blockBufferOffset + row];
  30962. p1 = blockData[blockBufferOffset + row + 1];
  30963. p2 = blockData[blockBufferOffset + row + 2];
  30964. p3 = blockData[blockBufferOffset + row + 3];
  30965. p4 = blockData[blockBufferOffset + row + 4];
  30966. p5 = blockData[blockBufferOffset + row + 5];
  30967. p6 = blockData[blockBufferOffset + row + 6];
  30968. p7 = blockData[blockBufferOffset + row + 7];
  30969. // dequant p0
  30970. p0 *= qt[row];
  30971. // check for all-zero AC coefficients
  30972. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  30973. t = (dctSqrt2 * p0 + 512) >> 10;
  30974. p[row] = t;
  30975. p[row + 1] = t;
  30976. p[row + 2] = t;
  30977. p[row + 3] = t;
  30978. p[row + 4] = t;
  30979. p[row + 5] = t;
  30980. p[row + 6] = t;
  30981. p[row + 7] = t;
  30982. continue;
  30983. }
  30984. // dequant p1 ... p7
  30985. p1 *= qt[row + 1];
  30986. p2 *= qt[row + 2];
  30987. p3 *= qt[row + 3];
  30988. p4 *= qt[row + 4];
  30989. p5 *= qt[row + 5];
  30990. p6 *= qt[row + 6];
  30991. p7 *= qt[row + 7];
  30992. // stage 4
  30993. v0 = (dctSqrt2 * p0 + 128) >> 8;
  30994. v1 = (dctSqrt2 * p4 + 128) >> 8;
  30995. v2 = p2;
  30996. v3 = p6;
  30997. v4 = (dctSqrt1d2 * (p1 - p7) + 128) >> 8;
  30998. v7 = (dctSqrt1d2 * (p1 + p7) + 128) >> 8;
  30999. v5 = p3 << 4;
  31000. v6 = p5 << 4;
  31001. // stage 3
  31002. v0 = (v0 + v1 + 1) >> 1;
  31003. v1 = v0 - v1;
  31004. t = (v2 * dctSin6 + v3 * dctCos6 + 128) >> 8;
  31005. v2 = (v2 * dctCos6 - v3 * dctSin6 + 128) >> 8;
  31006. v3 = t;
  31007. v4 = (v4 + v6 + 1) >> 1;
  31008. v6 = v4 - v6;
  31009. v7 = (v7 + v5 + 1) >> 1;
  31010. v5 = v7 - v5;
  31011. // stage 2
  31012. v0 = (v0 + v3 + 1) >> 1;
  31013. v3 = v0 - v3;
  31014. v1 = (v1 + v2 + 1) >> 1;
  31015. v2 = v1 - v2;
  31016. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  31017. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  31018. v7 = t;
  31019. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  31020. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  31021. v6 = t;
  31022. // stage 1
  31023. p[row] = v0 + v7;
  31024. p[row + 7] = v0 - v7;
  31025. p[row + 1] = v1 + v6;
  31026. p[row + 6] = v1 - v6;
  31027. p[row + 2] = v2 + v5;
  31028. p[row + 5] = v2 - v5;
  31029. p[row + 3] = v3 + v4;
  31030. p[row + 4] = v3 - v4;
  31031. }
  31032. // inverse DCT on columns
  31033. for (var col = 0; col < 8; ++col) {
  31034. p0 = p[col];
  31035. p1 = p[col + 8];
  31036. p2 = p[col + 16];
  31037. p3 = p[col + 24];
  31038. p4 = p[col + 32];
  31039. p5 = p[col + 40];
  31040. p6 = p[col + 48];
  31041. p7 = p[col + 56];
  31042. // check for all-zero AC coefficients
  31043. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  31044. t = (dctSqrt2 * p0 + 8192) >> 14;
  31045. // convert to 8 bit
  31046. t = (t < -2040) ? 0 : (t >= 2024) ? 255 : (t + 2056) >> 4;
  31047. blockData[blockBufferOffset + col] = t;
  31048. blockData[blockBufferOffset + col + 8] = t;
  31049. blockData[blockBufferOffset + col + 16] = t;
  31050. blockData[blockBufferOffset + col + 24] = t;
  31051. blockData[blockBufferOffset + col + 32] = t;
  31052. blockData[blockBufferOffset + col + 40] = t;
  31053. blockData[blockBufferOffset + col + 48] = t;
  31054. blockData[blockBufferOffset + col + 56] = t;
  31055. continue;
  31056. }
  31057. // stage 4
  31058. v0 = (dctSqrt2 * p0 + 2048) >> 12;
  31059. v1 = (dctSqrt2 * p4 + 2048) >> 12;
  31060. v2 = p2;
  31061. v3 = p6;
  31062. v4 = (dctSqrt1d2 * (p1 - p7) + 2048) >> 12;
  31063. v7 = (dctSqrt1d2 * (p1 + p7) + 2048) >> 12;
  31064. v5 = p3;
  31065. v6 = p5;
  31066. // stage 3
  31067. // Shift v0 by 128.5 << 5 here, so we don't need to shift p0...p7 when
  31068. // converting to UInt8 range later.
  31069. v0 = ((v0 + v1 + 1) >> 1) + 4112;
  31070. v1 = v0 - v1;
  31071. t = (v2 * dctSin6 + v3 * dctCos6 + 2048) >> 12;
  31072. v2 = (v2 * dctCos6 - v3 * dctSin6 + 2048) >> 12;
  31073. v3 = t;
  31074. v4 = (v4 + v6 + 1) >> 1;
  31075. v6 = v4 - v6;
  31076. v7 = (v7 + v5 + 1) >> 1;
  31077. v5 = v7 - v5;
  31078. // stage 2
  31079. v0 = (v0 + v3 + 1) >> 1;
  31080. v3 = v0 - v3;
  31081. v1 = (v1 + v2 + 1) >> 1;
  31082. v2 = v1 - v2;
  31083. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  31084. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  31085. v7 = t;
  31086. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  31087. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  31088. v6 = t;
  31089. // stage 1
  31090. p0 = v0 + v7;
  31091. p7 = v0 - v7;
  31092. p1 = v1 + v6;
  31093. p6 = v1 - v6;
  31094. p2 = v2 + v5;
  31095. p5 = v2 - v5;
  31096. p3 = v3 + v4;
  31097. p4 = v3 - v4;
  31098. // convert to 8-bit integers
  31099. p0 = (p0 < 16) ? 0 : (p0 >= 4080) ? 255 : p0 >> 4;
  31100. p1 = (p1 < 16) ? 0 : (p1 >= 4080) ? 255 : p1 >> 4;
  31101. p2 = (p2 < 16) ? 0 : (p2 >= 4080) ? 255 : p2 >> 4;
  31102. p3 = (p3 < 16) ? 0 : (p3 >= 4080) ? 255 : p3 >> 4;
  31103. p4 = (p4 < 16) ? 0 : (p4 >= 4080) ? 255 : p4 >> 4;
  31104. p5 = (p5 < 16) ? 0 : (p5 >= 4080) ? 255 : p5 >> 4;
  31105. p6 = (p6 < 16) ? 0 : (p6 >= 4080) ? 255 : p6 >> 4;
  31106. p7 = (p7 < 16) ? 0 : (p7 >= 4080) ? 255 : p7 >> 4;
  31107. // store block data
  31108. blockData[blockBufferOffset + col] = p0;
  31109. blockData[blockBufferOffset + col + 8] = p1;
  31110. blockData[blockBufferOffset + col + 16] = p2;
  31111. blockData[blockBufferOffset + col + 24] = p3;
  31112. blockData[blockBufferOffset + col + 32] = p4;
  31113. blockData[blockBufferOffset + col + 40] = p5;
  31114. blockData[blockBufferOffset + col + 48] = p6;
  31115. blockData[blockBufferOffset + col + 56] = p7;
  31116. }
  31117. }
  31118. function buildComponentData(frame, component) {
  31119. var blocksPerLine = component.blocksPerLine;
  31120. var blocksPerColumn = component.blocksPerColumn;
  31121. var computationBuffer = new Int16Array(64);
  31122. for (var blockRow = 0; blockRow < blocksPerColumn; blockRow++) {
  31123. for (var blockCol = 0; blockCol < blocksPerLine; blockCol++) {
  31124. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  31125. quantizeAndInverse(component, offset, computationBuffer);
  31126. }
  31127. }
  31128. return component.blockData;
  31129. }
  31130. function clamp0to255(a) {
  31131. return a <= 0 ? 0 : a >= 255 ? 255 : a;
  31132. }
  31133. constructor.prototype = {
  31134. parse: function parse(data) {
  31135. function readUint16() {
  31136. var value = (data[offset] << 8) | data[offset + 1];
  31137. offset += 2;
  31138. return value;
  31139. }
  31140. function readDataBlock() {
  31141. var length = readUint16();
  31142. var array = data.subarray(offset, offset + length - 2);
  31143. offset += array.length;
  31144. return array;
  31145. }
  31146. function prepareComponents(frame) {
  31147. var mcusPerLine = Math.ceil(frame.samplesPerLine / 8 / frame.maxH);
  31148. var mcusPerColumn = Math.ceil(frame.scanLines / 8 / frame.maxV);
  31149. for (var i = 0; i < frame.components.length; i++) {
  31150. component = frame.components[i];
  31151. var blocksPerLine = Math.ceil(Math.ceil(frame.samplesPerLine / 8) *
  31152. component.h / frame.maxH);
  31153. var blocksPerColumn = Math.ceil(Math.ceil(frame.scanLines / 8) *
  31154. component.v / frame.maxV);
  31155. var blocksPerLineForMcu = mcusPerLine * component.h;
  31156. var blocksPerColumnForMcu = mcusPerColumn * component.v;
  31157. var blocksBufferSize = 64 * blocksPerColumnForMcu *
  31158. (blocksPerLineForMcu + 1);
  31159. component.blockData = new Int16Array(blocksBufferSize);
  31160. component.blocksPerLine = blocksPerLine;
  31161. component.blocksPerColumn = blocksPerColumn;
  31162. }
  31163. frame.mcusPerLine = mcusPerLine;
  31164. frame.mcusPerColumn = mcusPerColumn;
  31165. }
  31166. var offset = 0, length = data.length;
  31167. var jfif = null;
  31168. var adobe = null;
  31169. var pixels = null;
  31170. var frame, resetInterval;
  31171. var quantizationTables = [];
  31172. var huffmanTablesAC = [], huffmanTablesDC = [];
  31173. var fileMarker = readUint16();
  31174. if (fileMarker != 0xFFD8) { // SOI (Start of Image)
  31175. throw 'SOI not found';
  31176. }
  31177. fileMarker = readUint16();
  31178. while (fileMarker != 0xFFD9) { // EOI (End of image)
  31179. var i, j, l;
  31180. switch(fileMarker) {
  31181. case 0xFFE0: // APP0 (Application Specific)
  31182. case 0xFFE1: // APP1
  31183. case 0xFFE2: // APP2
  31184. case 0xFFE3: // APP3
  31185. case 0xFFE4: // APP4
  31186. case 0xFFE5: // APP5
  31187. case 0xFFE6: // APP6
  31188. case 0xFFE7: // APP7
  31189. case 0xFFE8: // APP8
  31190. case 0xFFE9: // APP9
  31191. case 0xFFEA: // APP10
  31192. case 0xFFEB: // APP11
  31193. case 0xFFEC: // APP12
  31194. case 0xFFED: // APP13
  31195. case 0xFFEE: // APP14
  31196. case 0xFFEF: // APP15
  31197. case 0xFFFE: // COM (Comment)
  31198. var appData = readDataBlock();
  31199. if (fileMarker === 0xFFE0) {
  31200. if (appData[0] === 0x4A && appData[1] === 0x46 &&
  31201. appData[2] === 0x49 && appData[3] === 0x46 &&
  31202. appData[4] === 0) { // 'JFIF\x00'
  31203. jfif = {
  31204. version: { major: appData[5], minor: appData[6] },
  31205. densityUnits: appData[7],
  31206. xDensity: (appData[8] << 8) | appData[9],
  31207. yDensity: (appData[10] << 8) | appData[11],
  31208. thumbWidth: appData[12],
  31209. thumbHeight: appData[13],
  31210. thumbData: appData.subarray(14, 14 +
  31211. 3 * appData[12] * appData[13])
  31212. };
  31213. }
  31214. }
  31215. // TODO APP1 - Exif
  31216. if (fileMarker === 0xFFEE) {
  31217. if (appData[0] === 0x41 && appData[1] === 0x64 &&
  31218. appData[2] === 0x6F && appData[3] === 0x62 &&
  31219. appData[4] === 0x65 && appData[5] === 0) { // 'Adobe\x00'
  31220. adobe = {
  31221. version: appData[6],
  31222. flags0: (appData[7] << 8) | appData[8],
  31223. flags1: (appData[9] << 8) | appData[10],
  31224. transformCode: appData[11]
  31225. };
  31226. }
  31227. }
  31228. break;
  31229. case 0xFFDB: // DQT (Define Quantization Tables)
  31230. var quantizationTablesLength = readUint16();
  31231. var quantizationTablesEnd = quantizationTablesLength + offset - 2;
  31232. var z;
  31233. while (offset < quantizationTablesEnd) {
  31234. var quantizationTableSpec = data[offset++];
  31235. var tableData = new Uint16Array(64);
  31236. if ((quantizationTableSpec >> 4) === 0) { // 8 bit values
  31237. for (j = 0; j < 64; j++) {
  31238. z = dctZigZag[j];
  31239. tableData[z] = data[offset++];
  31240. }
  31241. } else if ((quantizationTableSpec >> 4) === 1) { //16 bit
  31242. for (j = 0; j < 64; j++) {
  31243. z = dctZigZag[j];
  31244. tableData[z] = readUint16();
  31245. }
  31246. } else {
  31247. throw 'DQT: invalid table spec';
  31248. }
  31249. quantizationTables[quantizationTableSpec & 15] = tableData;
  31250. }
  31251. break;
  31252. case 0xFFC0: // SOF0 (Start of Frame, Baseline DCT)
  31253. case 0xFFC1: // SOF1 (Start of Frame, Extended DCT)
  31254. case 0xFFC2: // SOF2 (Start of Frame, Progressive DCT)
  31255. if (frame) {
  31256. throw 'Only single frame JPEGs supported';
  31257. }
  31258. readUint16(); // skip data length
  31259. frame = {};
  31260. frame.extended = (fileMarker === 0xFFC1);
  31261. frame.progressive = (fileMarker === 0xFFC2);
  31262. frame.precision = data[offset++];
  31263. frame.scanLines = readUint16();
  31264. frame.samplesPerLine = readUint16();
  31265. frame.components = [];
  31266. frame.componentIds = {};
  31267. var componentsCount = data[offset++], componentId;
  31268. var maxH = 0, maxV = 0;
  31269. for (i = 0; i < componentsCount; i++) {
  31270. componentId = data[offset];
  31271. var h = data[offset + 1] >> 4;
  31272. var v = data[offset + 1] & 15;
  31273. if (maxH < h) {
  31274. maxH = h;
  31275. }
  31276. if (maxV < v) {
  31277. maxV = v;
  31278. }
  31279. var qId = data[offset + 2];
  31280. l = frame.components.push({
  31281. h: h,
  31282. v: v,
  31283. quantizationTable: quantizationTables[qId]
  31284. });
  31285. frame.componentIds[componentId] = l - 1;
  31286. offset += 3;
  31287. }
  31288. frame.maxH = maxH;
  31289. frame.maxV = maxV;
  31290. prepareComponents(frame);
  31291. break;
  31292. case 0xFFC4: // DHT (Define Huffman Tables)
  31293. var huffmanLength = readUint16();
  31294. for (i = 2; i < huffmanLength;) {
  31295. var huffmanTableSpec = data[offset++];
  31296. var codeLengths = new Uint8Array(16);
  31297. var codeLengthSum = 0;
  31298. for (j = 0; j < 16; j++, offset++) {
  31299. codeLengthSum += (codeLengths[j] = data[offset]);
  31300. }
  31301. var huffmanValues = new Uint8Array(codeLengthSum);
  31302. for (j = 0; j < codeLengthSum; j++, offset++) {
  31303. huffmanValues[j] = data[offset];
  31304. }
  31305. i += 17 + codeLengthSum;
  31306. ((huffmanTableSpec >> 4) === 0 ?
  31307. huffmanTablesDC : huffmanTablesAC)[huffmanTableSpec & 15] =
  31308. buildHuffmanTable(codeLengths, huffmanValues);
  31309. }
  31310. break;
  31311. case 0xFFDD: // DRI (Define Restart Interval)
  31312. readUint16(); // skip data length
  31313. resetInterval = readUint16();
  31314. break;
  31315. case 0xFFDA: // SOS (Start of Scan)
  31316. var scanLength = readUint16();
  31317. var selectorsCount = data[offset++];
  31318. var components = [], component;
  31319. for (i = 0; i < selectorsCount; i++) {
  31320. var componentIndex = frame.componentIds[data[offset++]];
  31321. component = frame.components[componentIndex];
  31322. var tableSpec = data[offset++];
  31323. component.huffmanTableDC = huffmanTablesDC[tableSpec >> 4];
  31324. component.huffmanTableAC = huffmanTablesAC[tableSpec & 15];
  31325. components.push(component);
  31326. }
  31327. var spectralStart = data[offset++];
  31328. var spectralEnd = data[offset++];
  31329. var successiveApproximation = data[offset++];
  31330. var processed = decodeScan(data, offset,
  31331. frame, components, resetInterval,
  31332. spectralStart, spectralEnd,
  31333. successiveApproximation >> 4, successiveApproximation & 15);
  31334. offset += processed;
  31335. break;
  31336. default:
  31337. if (data[offset - 3] == 0xFF &&
  31338. data[offset - 2] >= 0xC0 && data[offset - 2] <= 0xFE) {
  31339. // could be incorrect encoding -- last 0xFF byte of the previous
  31340. // block was eaten by the encoder
  31341. offset -= 3;
  31342. break;
  31343. }
  31344. throw 'unknown JPEG marker ' + fileMarker.toString(16);
  31345. }
  31346. fileMarker = readUint16();
  31347. }
  31348. this.width = frame.samplesPerLine;
  31349. this.height = frame.scanLines;
  31350. this.jfif = jfif;
  31351. this.adobe = adobe;
  31352. this.components = [];
  31353. for (i = 0; i < frame.components.length; i++) {
  31354. component = frame.components[i];
  31355. this.components.push({
  31356. output: buildComponentData(frame, component),
  31357. scaleX: component.h / frame.maxH,
  31358. scaleY: component.v / frame.maxV,
  31359. blocksPerLine: component.blocksPerLine,
  31360. blocksPerColumn: component.blocksPerColumn
  31361. });
  31362. }
  31363. this.numComponents = this.components.length;
  31364. },
  31365. _getLinearizedBlockData: function getLinearizedBlockData(width, height) {
  31366. var scaleX = this.width / width, scaleY = this.height / height;
  31367. var component, componentScaleX, componentScaleY, blocksPerScanline;
  31368. var x, y, i, j, k;
  31369. var index;
  31370. var offset = 0;
  31371. var output;
  31372. var numComponents = this.components.length;
  31373. var dataLength = width * height * numComponents;
  31374. var data = new Uint8Array(dataLength);
  31375. var xScaleBlockOffset = new Uint32Array(width);
  31376. var mask3LSB = 0xfffffff8; // used to clear the 3 LSBs
  31377. for (i = 0; i < numComponents; i++) {
  31378. component = this.components[i];
  31379. componentScaleX = component.scaleX * scaleX;
  31380. componentScaleY = component.scaleY * scaleY;
  31381. offset = i;
  31382. output = component.output;
  31383. blocksPerScanline = (component.blocksPerLine + 1) << 3;
  31384. // precalculate the xScaleBlockOffset
  31385. for (x = 0; x < width; x++) {
  31386. j = 0 | (x * componentScaleX);
  31387. xScaleBlockOffset[x] = ((j & mask3LSB) << 3) | (j & 7);
  31388. }
  31389. // linearize the blocks of the component
  31390. for (y = 0; y < height; y++) {
  31391. j = 0 | (y * componentScaleY);
  31392. index = blocksPerScanline * (j & mask3LSB) | ((j & 7) << 3);
  31393. for (x = 0; x < width; x++) {
  31394. data[offset] = output[index + xScaleBlockOffset[x]];
  31395. offset += numComponents;
  31396. }
  31397. }
  31398. }
  31399. // decodeTransform will contains pairs of multiplier (-256..256) and
  31400. // additive
  31401. var transform = this.decodeTransform;
  31402. if (transform) {
  31403. for (i = 0; i < dataLength;) {
  31404. for (j = 0, k = 0; j < numComponents; j++, i++, k += 2) {
  31405. data[i] = ((data[i] * transform[k]) >> 8) + transform[k + 1];
  31406. }
  31407. }
  31408. }
  31409. return data;
  31410. },
  31411. _isColorConversionNeeded: function isColorConversionNeeded() {
  31412. if (this.adobe && this.adobe.transformCode) {
  31413. // The adobe transform marker overrides any previous setting
  31414. return true;
  31415. } else if (this.numComponents == 3) {
  31416. return true;
  31417. } else {
  31418. return false;
  31419. }
  31420. },
  31421. _convertYccToRgb: function convertYccToRgb(data) {
  31422. var Y, Cb, Cr;
  31423. for (var i = 0, length = data.length; i < length; i += 3) {
  31424. Y = data[i ];
  31425. Cb = data[i + 1];
  31426. Cr = data[i + 2];
  31427. data[i ] = clamp0to255(Y - 179.456 + 1.402 * Cr);
  31428. data[i + 1] = clamp0to255(Y + 135.459 - 0.344 * Cb - 0.714 * Cr);
  31429. data[i + 2] = clamp0to255(Y - 226.816 + 1.772 * Cb);
  31430. }
  31431. return data;
  31432. },
  31433. _convertYcckToRgb: function convertYcckToRgb(data) {
  31434. var Y, Cb, Cr, k, CbCb, CbCr, CbY, Cbk, CrCr, Crk, CrY, YY, Yk, kk;
  31435. var offset = 0;
  31436. for (var i = 0, length = data.length; i < length; i += 4) {
  31437. Y = data[i];
  31438. Cb = data[i + 1];
  31439. Cr = data[i + 2];
  31440. k = data[i + 3];
  31441. CbCb = Cb * Cb;
  31442. CbCr = Cb * Cr;
  31443. CbY = Cb * Y;
  31444. Cbk = Cb * k;
  31445. CrCr = Cr * Cr;
  31446. Crk = Cr * k;
  31447. CrY = Cr * Y;
  31448. YY = Y * Y;
  31449. Yk = Y * k;
  31450. kk = k * k;
  31451. var r = - 122.67195406894 -
  31452. 6.60635669420364e-5 * CbCb + 0.000437130475926232 * CbCr -
  31453. 5.4080610064599e-5* CbY + 0.00048449797120281* Cbk -
  31454. 0.154362151871126 * Cb - 0.000957964378445773 * CrCr +
  31455. 0.000817076911346625 * CrY - 0.00477271405408747 * Crk +
  31456. 1.53380253221734 * Cr + 0.000961250184130688 * YY -
  31457. 0.00266257332283933 * Yk + 0.48357088451265 * Y -
  31458. 0.000336197177618394 * kk + 0.484791561490776 * k;
  31459. var g = 107.268039397724 +
  31460. 2.19927104525741e-5 * CbCb - 0.000640992018297945 * CbCr +
  31461. 0.000659397001245577* CbY + 0.000426105652938837* Cbk -
  31462. 0.176491792462875 * Cb - 0.000778269941513683 * CrCr +
  31463. 0.00130872261408275 * CrY + 0.000770482631801132 * Crk -
  31464. 0.151051492775562 * Cr + 0.00126935368114843 * YY -
  31465. 0.00265090189010898 * Yk + 0.25802910206845 * Y -
  31466. 0.000318913117588328 * kk - 0.213742400323665 * k;
  31467. var b = - 20.810012546947 -
  31468. 0.000570115196973677 * CbCb - 2.63409051004589e-5 * CbCr +
  31469. 0.0020741088115012* CbY - 0.00288260236853442* Cbk +
  31470. 0.814272968359295 * Cb - 1.53496057440975e-5 * CrCr -
  31471. 0.000132689043961446 * CrY + 0.000560833691242812 * Crk -
  31472. 0.195152027534049 * Cr + 0.00174418132927582 * YY -
  31473. 0.00255243321439347 * Yk + 0.116935020465145 * Y -
  31474. 0.000343531996510555 * kk + 0.24165260232407 * k;
  31475. data[offset++] = clamp0to255(r);
  31476. data[offset++] = clamp0to255(g);
  31477. data[offset++] = clamp0to255(b);
  31478. }
  31479. return data;
  31480. },
  31481. _convertYcckToCmyk: function convertYcckToCmyk(data) {
  31482. var Y, Cb, Cr;
  31483. for (var i = 0, length = data.length; i < length; i += 4) {
  31484. Y = data[i];
  31485. Cb = data[i + 1];
  31486. Cr = data[i + 2];
  31487. data[i ] = clamp0to255(434.456 - Y - 1.402 * Cr);
  31488. data[i + 1] = clamp0to255(119.541 - Y + 0.344 * Cb + 0.714 * Cr);
  31489. data[i + 2] = clamp0to255(481.816 - Y - 1.772 * Cb);
  31490. // K in data[i + 3] is unchanged
  31491. }
  31492. return data;
  31493. },
  31494. _convertCmykToRgb: function convertCmykToRgb(data) {
  31495. var c, m, y, k;
  31496. var offset = 0;
  31497. var min = -255 * 255 * 255;
  31498. var scale = 1 / 255 / 255;
  31499. for (var i = 0, length = data.length; i < length; i += 4) {
  31500. c = data[i];
  31501. m = data[i + 1];
  31502. y = data[i + 2];
  31503. k = data[i + 3];
  31504. var r =
  31505. c * (-4.387332384609988 * c + 54.48615194189176 * m +
  31506. 18.82290502165302 * y + 212.25662451639585 * k -
  31507. 72734.4411664936) +
  31508. m * (1.7149763477362134 * m - 5.6096736904047315 * y -
  31509. 17.873870861415444 * k - 1401.7366389350734) +
  31510. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  31511. 4465.541406466231) -
  31512. k * (21.86122147463605 * k + 48317.86113160301);
  31513. var g =
  31514. c * (8.841041422036149 * c + 60.118027045597366 * m +
  31515. 6.871425592049007 * y + 31.159100130055922 * k -
  31516. 20220.756542821975) +
  31517. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  31518. 131.35250912493976 * k - 48691.05921601825) +
  31519. y * (4.444339102852739 * y + 9.8632861493405 * k -
  31520. 6341.191035517494) -
  31521. k * (20.737325471181034 * k + 47890.15695978492);
  31522. var b =
  31523. c * (0.8842522430003296 * c + 8.078677503112928 * m +
  31524. 30.89978309703729 * y - 0.23883238689178934 * k -
  31525. 3616.812083916688) +
  31526. m * (10.49593273432072 * m + 63.02378494754052 * y +
  31527. 50.606957656360734 * k - 28620.90484698408) +
  31528. y * (0.03296041114873217 * y + 115.60384449646641 * k -
  31529. 49363.43385999684) -
  31530. k * (22.33816807309886 * k + 45932.16563550634);
  31531. data[offset++] = r >= 0 ? 255 : r <= min ? 0 : 255 + r * scale | 0;
  31532. data[offset++] = g >= 0 ? 255 : g <= min ? 0 : 255 + g * scale | 0;
  31533. data[offset++] = b >= 0 ? 255 : b <= min ? 0 : 255 + b * scale | 0;
  31534. }
  31535. return data;
  31536. },
  31537. getData: function getData(width, height, forceRGBoutput) {
  31538. if (this.numComponents > 4) {
  31539. throw 'Unsupported color mode';
  31540. }
  31541. // type of data: Uint8Array(width * height * numComponents)
  31542. var data = this._getLinearizedBlockData(width, height);
  31543. if (this.numComponents === 3) {
  31544. return this._convertYccToRgb(data);
  31545. } else if (this.numComponents === 4) {
  31546. if (this._isColorConversionNeeded()) {
  31547. if (forceRGBoutput) {
  31548. return this._convertYcckToRgb(data);
  31549. } else {
  31550. return this._convertYcckToCmyk(data);
  31551. }
  31552. } else if (forceRGBoutput) {
  31553. return this._convertCmykToRgb(data);
  31554. }
  31555. }
  31556. return data;
  31557. }
  31558. };
  31559. return constructor;
  31560. })();
  31561. var JpxImage = (function JpxImageClosure() {
  31562. // Table E.1
  31563. var SubbandsGainLog2 = {
  31564. 'LL': 0,
  31565. 'LH': 1,
  31566. 'HL': 1,
  31567. 'HH': 2
  31568. };
  31569. function JpxImage() {
  31570. this.failOnCorruptedImage = false;
  31571. }
  31572. JpxImage.prototype = {
  31573. parse: function JpxImage_parse(data) {
  31574. var head = readUint16(data, 0);
  31575. // No box header, immediate start of codestream (SOC)
  31576. if (head === 0xFF4F) {
  31577. this.parseCodestream(data, 0, data.length);
  31578. return;
  31579. }
  31580. var position = 0, length = data.length;
  31581. while (position < length) {
  31582. var headerSize = 8;
  31583. var lbox = readUint32(data, position);
  31584. var tbox = readUint32(data, position + 4);
  31585. position += headerSize;
  31586. if (lbox === 1) {
  31587. // XLBox: read UInt64 according to spec.
  31588. // JavaScript's int precision of 53 bit should be sufficient here.
  31589. lbox = readUint32(data, position) * 4294967296 +
  31590. readUint32(data, position + 4);
  31591. position += 8;
  31592. headerSize += 8;
  31593. }
  31594. if (lbox === 0) {
  31595. lbox = length - position + headerSize;
  31596. }
  31597. if (lbox < headerSize) {
  31598. throw new Error('JPX Error: Invalid box field size');
  31599. }
  31600. var dataLength = lbox - headerSize;
  31601. var jumpDataLength = true;
  31602. switch (tbox) {
  31603. case 0x6A501A1A: // 'jP\032\032'
  31604. // TODO
  31605. break;
  31606. case 0x6A703268: // 'jp2h'
  31607. jumpDataLength = false; // parsing child boxes
  31608. break;
  31609. case 0x636F6C72: // 'colr'
  31610. // TODO
  31611. break;
  31612. case 0x6A703263: // 'jp2c'
  31613. this.parseCodestream(data, position, position + dataLength);
  31614. break;
  31615. }
  31616. if (jumpDataLength) {
  31617. position += dataLength;
  31618. }
  31619. }
  31620. },
  31621. parseImageProperties: function JpxImage_parseImageProperties(stream) {
  31622. var newByte = stream.getByte();
  31623. while (newByte >= 0) {
  31624. var oldByte = newByte;
  31625. newByte = stream.getByte();
  31626. var code = (oldByte << 8) | newByte;
  31627. // Image and tile size (SIZ)
  31628. if (code == 0xFF51) {
  31629. stream.skip(4);
  31630. var Xsiz = stream.getInt32() >>> 0; // Byte 4
  31631. var Ysiz = stream.getInt32() >>> 0; // Byte 8
  31632. var XOsiz = stream.getInt32() >>> 0; // Byte 12
  31633. var YOsiz = stream.getInt32() >>> 0; // Byte 16
  31634. stream.skip(16);
  31635. var Csiz = stream.getUint16(); // Byte 36
  31636. this.width = Xsiz - XOsiz;
  31637. this.height = Ysiz - YOsiz;
  31638. this.componentsCount = Csiz;
  31639. // Results are always returned as Uint8Arrays
  31640. this.bitsPerComponent = 8;
  31641. return;
  31642. }
  31643. }
  31644. throw new Error('JPX Error: No size marker found in JPX stream');
  31645. },
  31646. parseCodestream: function JpxImage_parseCodestream(data, start, end) {
  31647. var context = {};
  31648. try {
  31649. var doNotRecover = false;
  31650. var position = start;
  31651. while (position + 1 < end) {
  31652. var code = readUint16(data, position);
  31653. position += 2;
  31654. var length = 0, j, sqcd, spqcds, spqcdSize, scalarExpounded, tile;
  31655. switch (code) {
  31656. case 0xFF4F: // Start of codestream (SOC)
  31657. context.mainHeader = true;
  31658. break;
  31659. case 0xFFD9: // End of codestream (EOC)
  31660. break;
  31661. case 0xFF51: // Image and tile size (SIZ)
  31662. length = readUint16(data, position);
  31663. var siz = {};
  31664. siz.Xsiz = readUint32(data, position + 4);
  31665. siz.Ysiz = readUint32(data, position + 8);
  31666. siz.XOsiz = readUint32(data, position + 12);
  31667. siz.YOsiz = readUint32(data, position + 16);
  31668. siz.XTsiz = readUint32(data, position + 20);
  31669. siz.YTsiz = readUint32(data, position + 24);
  31670. siz.XTOsiz = readUint32(data, position + 28);
  31671. siz.YTOsiz = readUint32(data, position + 32);
  31672. var componentsCount = readUint16(data, position + 36);
  31673. siz.Csiz = componentsCount;
  31674. var components = [];
  31675. j = position + 38;
  31676. for (var i = 0; i < componentsCount; i++) {
  31677. var component = {
  31678. precision: (data[j] & 0x7F) + 1,
  31679. isSigned: !!(data[j] & 0x80),
  31680. XRsiz: data[j + 1],
  31681. YRsiz: data[j + 1]
  31682. };
  31683. calculateComponentDimensions(component, siz);
  31684. components.push(component);
  31685. }
  31686. context.SIZ = siz;
  31687. context.components = components;
  31688. calculateTileGrids(context, components);
  31689. context.QCC = [];
  31690. context.COC = [];
  31691. break;
  31692. case 0xFF55: // Tile-part lengths, main header (TLM)
  31693. var Ltlm = readUint16(data, position); // Marker segment length
  31694. // Skip tile length markers
  31695. position += Ltlm;
  31696. break;
  31697. case 0xFF5C: // Quantization default (QCD)
  31698. length = readUint16(data, position);
  31699. var qcd = {};
  31700. j = position + 2;
  31701. sqcd = data[j++];
  31702. switch (sqcd & 0x1F) {
  31703. case 0:
  31704. spqcdSize = 8;
  31705. scalarExpounded = true;
  31706. break;
  31707. case 1:
  31708. spqcdSize = 16;
  31709. scalarExpounded = false;
  31710. break;
  31711. case 2:
  31712. spqcdSize = 16;
  31713. scalarExpounded = true;
  31714. break;
  31715. default:
  31716. throw new Error('JPX Error: Invalid SQcd value ' + sqcd);
  31717. }
  31718. qcd.noQuantization = (spqcdSize == 8);
  31719. qcd.scalarExpounded = scalarExpounded;
  31720. qcd.guardBits = sqcd >> 5;
  31721. spqcds = [];
  31722. while (j < length + position) {
  31723. var spqcd = {};
  31724. if (spqcdSize == 8) {
  31725. spqcd.epsilon = data[j++] >> 3;
  31726. spqcd.mu = 0;
  31727. } else {
  31728. spqcd.epsilon = data[j] >> 3;
  31729. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  31730. j += 2;
  31731. }
  31732. spqcds.push(spqcd);
  31733. }
  31734. qcd.SPqcds = spqcds;
  31735. if (context.mainHeader) {
  31736. context.QCD = qcd;
  31737. } else {
  31738. context.currentTile.QCD = qcd;
  31739. context.currentTile.QCC = [];
  31740. }
  31741. break;
  31742. case 0xFF5D: // Quantization component (QCC)
  31743. length = readUint16(data, position);
  31744. var qcc = {};
  31745. j = position + 2;
  31746. var cqcc;
  31747. if (context.SIZ.Csiz < 257) {
  31748. cqcc = data[j++];
  31749. } else {
  31750. cqcc = readUint16(data, j);
  31751. j += 2;
  31752. }
  31753. sqcd = data[j++];
  31754. switch (sqcd & 0x1F) {
  31755. case 0:
  31756. spqcdSize = 8;
  31757. scalarExpounded = true;
  31758. break;
  31759. case 1:
  31760. spqcdSize = 16;
  31761. scalarExpounded = false;
  31762. break;
  31763. case 2:
  31764. spqcdSize = 16;
  31765. scalarExpounded = true;
  31766. break;
  31767. default:
  31768. throw new Error('JPX Error: Invalid SQcd value ' + sqcd);
  31769. }
  31770. qcc.noQuantization = (spqcdSize == 8);
  31771. qcc.scalarExpounded = scalarExpounded;
  31772. qcc.guardBits = sqcd >> 5;
  31773. spqcds = [];
  31774. while (j < (length + position)) {
  31775. spqcd = {};
  31776. if (spqcdSize == 8) {
  31777. spqcd.epsilon = data[j++] >> 3;
  31778. spqcd.mu = 0;
  31779. } else {
  31780. spqcd.epsilon = data[j] >> 3;
  31781. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  31782. j += 2;
  31783. }
  31784. spqcds.push(spqcd);
  31785. }
  31786. qcc.SPqcds = spqcds;
  31787. if (context.mainHeader) {
  31788. context.QCC[cqcc] = qcc;
  31789. } else {
  31790. context.currentTile.QCC[cqcc] = qcc;
  31791. }
  31792. break;
  31793. case 0xFF52: // Coding style default (COD)
  31794. length = readUint16(data, position);
  31795. var cod = {};
  31796. j = position + 2;
  31797. var scod = data[j++];
  31798. cod.entropyCoderWithCustomPrecincts = !!(scod & 1);
  31799. cod.sopMarkerUsed = !!(scod & 2);
  31800. cod.ephMarkerUsed = !!(scod & 4);
  31801. cod.progressionOrder = data[j++];
  31802. cod.layersCount = readUint16(data, j);
  31803. j += 2;
  31804. cod.multipleComponentTransform = data[j++];
  31805. cod.decompositionLevelsCount = data[j++];
  31806. cod.xcb = (data[j++] & 0xF) + 2;
  31807. cod.ycb = (data[j++] & 0xF) + 2;
  31808. var blockStyle = data[j++];
  31809. cod.selectiveArithmeticCodingBypass = !!(blockStyle & 1);
  31810. cod.resetContextProbabilities = !!(blockStyle & 2);
  31811. cod.terminationOnEachCodingPass = !!(blockStyle & 4);
  31812. cod.verticalyStripe = !!(blockStyle & 8);
  31813. cod.predictableTermination = !!(blockStyle & 16);
  31814. cod.segmentationSymbolUsed = !!(blockStyle & 32);
  31815. cod.reversibleTransformation = data[j++];
  31816. if (cod.entropyCoderWithCustomPrecincts) {
  31817. var precinctsSizes = [];
  31818. while (j < length + position) {
  31819. var precinctsSize = data[j++];
  31820. precinctsSizes.push({
  31821. PPx: precinctsSize & 0xF,
  31822. PPy: precinctsSize >> 4
  31823. });
  31824. }
  31825. cod.precinctsSizes = precinctsSizes;
  31826. }
  31827. var unsupported = [];
  31828. if (cod.sopMarkerUsed) {
  31829. unsupported.push('sopMarkerUsed');
  31830. }
  31831. if (cod.ephMarkerUsed) {
  31832. unsupported.push('ephMarkerUsed');
  31833. }
  31834. if (cod.selectiveArithmeticCodingBypass) {
  31835. unsupported.push('selectiveArithmeticCodingBypass');
  31836. }
  31837. if (cod.resetContextProbabilities) {
  31838. unsupported.push('resetContextProbabilities');
  31839. }
  31840. if (cod.terminationOnEachCodingPass) {
  31841. unsupported.push('terminationOnEachCodingPass');
  31842. }
  31843. if (cod.verticalyStripe) {
  31844. unsupported.push('verticalyStripe');
  31845. }
  31846. if (cod.predictableTermination) {
  31847. unsupported.push('predictableTermination');
  31848. }
  31849. if (unsupported.length > 0) {
  31850. doNotRecover = true;
  31851. throw new Error('JPX Error: Unsupported COD options (' +
  31852. unsupported.join(', ') + ')');
  31853. }
  31854. if (context.mainHeader) {
  31855. context.COD = cod;
  31856. } else {
  31857. context.currentTile.COD = cod;
  31858. context.currentTile.COC = [];
  31859. }
  31860. break;
  31861. case 0xFF90: // Start of tile-part (SOT)
  31862. length = readUint16(data, position);
  31863. tile = {};
  31864. tile.index = readUint16(data, position + 2);
  31865. tile.length = readUint32(data, position + 4);
  31866. tile.dataEnd = tile.length + position - 2;
  31867. tile.partIndex = data[position + 8];
  31868. tile.partsCount = data[position + 9];
  31869. context.mainHeader = false;
  31870. if (tile.partIndex === 0) {
  31871. // reset component specific settings
  31872. tile.COD = context.COD;
  31873. tile.COC = context.COC.slice(0); // clone of the global COC
  31874. tile.QCD = context.QCD;
  31875. tile.QCC = context.QCC.slice(0); // clone of the global COC
  31876. }
  31877. context.currentTile = tile;
  31878. break;
  31879. case 0xFF93: // Start of data (SOD)
  31880. tile = context.currentTile;
  31881. if (tile.partIndex === 0) {
  31882. initializeTile(context, tile.index);
  31883. buildPackets(context);
  31884. }
  31885. // moving to the end of the data
  31886. length = tile.dataEnd - position;
  31887. parseTilePackets(context, data, position, length);
  31888. break;
  31889. case 0xFF64: // Comment (COM)
  31890. length = readUint16(data, position);
  31891. // skipping content
  31892. break;
  31893. case 0xFF53: // Coding style component (COC)
  31894. throw new Error('JPX Error: Codestream code 0xFF53 (COC) is ' +
  31895. 'not implemented');
  31896. default:
  31897. throw new Error('JPX Error: Unknown codestream code: ' +
  31898. code.toString(16));
  31899. }
  31900. position += length;
  31901. }
  31902. } catch (e) {
  31903. if (doNotRecover || this.failOnCorruptedImage) {
  31904. throw e;
  31905. } else {
  31906. warn('Trying to recover from ' + e.message);
  31907. }
  31908. }
  31909. this.tiles = transformComponents(context);
  31910. this.width = context.SIZ.Xsiz - context.SIZ.XOsiz;
  31911. this.height = context.SIZ.Ysiz - context.SIZ.YOsiz;
  31912. this.componentsCount = context.SIZ.Csiz;
  31913. }
  31914. };
  31915. function calculateComponentDimensions(component, siz) {
  31916. // Section B.2 Component mapping
  31917. component.x0 = Math.ceil(siz.XOsiz / component.XRsiz);
  31918. component.x1 = Math.ceil(siz.Xsiz / component.XRsiz);
  31919. component.y0 = Math.ceil(siz.YOsiz / component.YRsiz);
  31920. component.y1 = Math.ceil(siz.Ysiz / component.YRsiz);
  31921. component.width = component.x1 - component.x0;
  31922. component.height = component.y1 - component.y0;
  31923. }
  31924. function calculateTileGrids(context, components) {
  31925. var siz = context.SIZ;
  31926. // Section B.3 Division into tile and tile-components
  31927. var tile, tiles = [];
  31928. var numXtiles = Math.ceil((siz.Xsiz - siz.XTOsiz) / siz.XTsiz);
  31929. var numYtiles = Math.ceil((siz.Ysiz - siz.YTOsiz) / siz.YTsiz);
  31930. for (var q = 0; q < numYtiles; q++) {
  31931. for (var p = 0; p < numXtiles; p++) {
  31932. tile = {};
  31933. tile.tx0 = Math.max(siz.XTOsiz + p * siz.XTsiz, siz.XOsiz);
  31934. tile.ty0 = Math.max(siz.YTOsiz + q * siz.YTsiz, siz.YOsiz);
  31935. tile.tx1 = Math.min(siz.XTOsiz + (p + 1) * siz.XTsiz, siz.Xsiz);
  31936. tile.ty1 = Math.min(siz.YTOsiz + (q + 1) * siz.YTsiz, siz.Ysiz);
  31937. tile.width = tile.tx1 - tile.tx0;
  31938. tile.height = tile.ty1 - tile.ty0;
  31939. tile.components = [];
  31940. tiles.push(tile);
  31941. }
  31942. }
  31943. context.tiles = tiles;
  31944. var componentsCount = siz.Csiz;
  31945. for (var i = 0, ii = componentsCount; i < ii; i++) {
  31946. var component = components[i];
  31947. for (var j = 0, jj = tiles.length; j < jj; j++) {
  31948. var tileComponent = {};
  31949. tile = tiles[j];
  31950. tileComponent.tcx0 = Math.ceil(tile.tx0 / component.XRsiz);
  31951. tileComponent.tcy0 = Math.ceil(tile.ty0 / component.YRsiz);
  31952. tileComponent.tcx1 = Math.ceil(tile.tx1 / component.XRsiz);
  31953. tileComponent.tcy1 = Math.ceil(tile.ty1 / component.YRsiz);
  31954. tileComponent.width = tileComponent.tcx1 - tileComponent.tcx0;
  31955. tileComponent.height = tileComponent.tcy1 - tileComponent.tcy0;
  31956. tile.components[i] = tileComponent;
  31957. }
  31958. }
  31959. }
  31960. function getBlocksDimensions(context, component, r) {
  31961. var codOrCoc = component.codingStyleParameters;
  31962. var result = {};
  31963. if (!codOrCoc.entropyCoderWithCustomPrecincts) {
  31964. result.PPx = 15;
  31965. result.PPy = 15;
  31966. } else {
  31967. result.PPx = codOrCoc.precinctsSizes[r].PPx;
  31968. result.PPy = codOrCoc.precinctsSizes[r].PPy;
  31969. }
  31970. // calculate codeblock size as described in section B.7
  31971. result.xcb_ = (r > 0 ? Math.min(codOrCoc.xcb, result.PPx - 1) :
  31972. Math.min(codOrCoc.xcb, result.PPx));
  31973. result.ycb_ = (r > 0 ? Math.min(codOrCoc.ycb, result.PPy - 1) :
  31974. Math.min(codOrCoc.ycb, result.PPy));
  31975. return result;
  31976. }
  31977. function buildPrecincts(context, resolution, dimensions) {
  31978. // Section B.6 Division resolution to precincts
  31979. var precinctWidth = 1 << dimensions.PPx;
  31980. var precinctHeight = 1 << dimensions.PPy;
  31981. var numprecinctswide = (resolution.trx1 > resolution.trx0 ?
  31982. Math.ceil(resolution.trx1 / precinctWidth) -
  31983. Math.floor(resolution.trx0 / precinctWidth) : 0);
  31984. var numprecinctshigh = (resolution.try1 > resolution.try0 ?
  31985. Math.ceil(resolution.try1 / precinctHeight) -
  31986. Math.floor(resolution.try0 / precinctHeight) : 0);
  31987. var numprecincts = numprecinctswide * numprecinctshigh;
  31988. var precinctXOffset = Math.floor(resolution.trx0 / precinctWidth) *
  31989. precinctWidth;
  31990. var precinctYOffset = Math.floor(resolution.try0 / precinctHeight) *
  31991. precinctHeight;
  31992. resolution.precinctParameters = {
  31993. precinctXOffset: precinctXOffset,
  31994. precinctYOffset: precinctYOffset,
  31995. precinctWidth: precinctWidth,
  31996. precinctHeight: precinctHeight,
  31997. numprecinctswide: numprecinctswide,
  31998. numprecinctshigh: numprecinctshigh,
  31999. numprecincts: numprecincts
  32000. };
  32001. }
  32002. function buildCodeblocks(context, subband, dimensions) {
  32003. // Section B.7 Division sub-band into code-blocks
  32004. var xcb_ = dimensions.xcb_;
  32005. var ycb_ = dimensions.ycb_;
  32006. var codeblockWidth = 1 << xcb_;
  32007. var codeblockHeight = 1 << ycb_;
  32008. var cbx0 = subband.tbx0 >> xcb_;
  32009. var cby0 = subband.tby0 >> ycb_;
  32010. var cbx1 = (subband.tbx1 + codeblockWidth - 1) >> xcb_;
  32011. var cby1 = (subband.tby1 + codeblockHeight - 1) >> ycb_;
  32012. var precinctParameters = subband.resolution.precinctParameters;
  32013. var codeblocks = [];
  32014. var precincts = [];
  32015. var i, j, codeblock, precinctNumber;
  32016. for (j = cby0; j < cby1; j++) {
  32017. for (i = cbx0; i < cbx1; i++) {
  32018. codeblock = {
  32019. cbx: i,
  32020. cby: j,
  32021. tbx0: codeblockWidth * i,
  32022. tby0: codeblockHeight * j,
  32023. tbx1: codeblockWidth * (i + 1),
  32024. tby1: codeblockHeight * (j + 1)
  32025. };
  32026. // calculate precinct number
  32027. var pi = Math.floor((codeblock.tbx0 -
  32028. precinctParameters.precinctXOffset) /
  32029. precinctParameters.precinctWidth);
  32030. var pj = Math.floor((codeblock.tby0 -
  32031. precinctParameters.precinctYOffset) /
  32032. precinctParameters.precinctHeight);
  32033. precinctNumber = pj + pi * precinctParameters.numprecinctswide;
  32034. codeblock.tbx0_ = Math.max(subband.tbx0, codeblock.tbx0);
  32035. codeblock.tby0_ = Math.max(subband.tby0, codeblock.tby0);
  32036. codeblock.tbx1_ = Math.min(subband.tbx1, codeblock.tbx1);
  32037. codeblock.tby1_ = Math.min(subband.tby1, codeblock.tby1);
  32038. codeblock.precinctNumber = precinctNumber;
  32039. codeblock.subbandType = subband.type;
  32040. codeblock.Lblock = 3;
  32041. codeblocks.push(codeblock);
  32042. // building precinct for the sub-band
  32043. var precinct = precincts[precinctNumber];
  32044. if (precinct !== undefined) {
  32045. if (i < precinct.cbxMin) {
  32046. precinct.cbxMin = i;
  32047. } else if (i > precinct.cbxMax) {
  32048. precinct.cbxMax = i;
  32049. }
  32050. if (j < precinct.cbyMin) {
  32051. precinct.cbxMin = j;
  32052. } else if (j > precinct.cbyMax) {
  32053. precinct.cbyMax = j;
  32054. }
  32055. } else {
  32056. precincts[precinctNumber] = precinct = {
  32057. cbxMin: i,
  32058. cbyMin: j,
  32059. cbxMax: i,
  32060. cbyMax: j
  32061. };
  32062. }
  32063. codeblock.precinct = precinct;
  32064. }
  32065. }
  32066. subband.codeblockParameters = {
  32067. codeblockWidth: xcb_,
  32068. codeblockHeight: ycb_,
  32069. numcodeblockwide: cbx1 - cbx0 + 1,
  32070. numcodeblockhigh: cby1 - cby1 + 1
  32071. };
  32072. subband.codeblocks = codeblocks;
  32073. subband.precincts = precincts;
  32074. }
  32075. function createPacket(resolution, precinctNumber, layerNumber) {
  32076. var precinctCodeblocks = [];
  32077. // Section B.10.8 Order of info in packet
  32078. var subbands = resolution.subbands;
  32079. // sub-bands already ordered in 'LL', 'HL', 'LH', and 'HH' sequence
  32080. for (var i = 0, ii = subbands.length; i < ii; i++) {
  32081. var subband = subbands[i];
  32082. var codeblocks = subband.codeblocks;
  32083. for (var j = 0, jj = codeblocks.length; j < jj; j++) {
  32084. var codeblock = codeblocks[j];
  32085. if (codeblock.precinctNumber != precinctNumber) {
  32086. continue;
  32087. }
  32088. precinctCodeblocks.push(codeblock);
  32089. }
  32090. }
  32091. return {
  32092. layerNumber: layerNumber,
  32093. codeblocks: precinctCodeblocks
  32094. };
  32095. }
  32096. function LayerResolutionComponentPositionIterator(context) {
  32097. var siz = context.SIZ;
  32098. var tileIndex = context.currentTile.index;
  32099. var tile = context.tiles[tileIndex];
  32100. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  32101. var componentsCount = siz.Csiz;
  32102. var maxDecompositionLevelsCount = 0;
  32103. for (var q = 0; q < componentsCount; q++) {
  32104. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  32105. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  32106. }
  32107. var l = 0, r = 0, i = 0, k = 0;
  32108. this.nextPacket = function JpxImage_nextPacket() {
  32109. // Section B.12.1.1 Layer-resolution-component-position
  32110. for (; l < layersCount; l++) {
  32111. for (; r <= maxDecompositionLevelsCount; r++) {
  32112. for (; i < componentsCount; i++) {
  32113. var component = tile.components[i];
  32114. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  32115. continue;
  32116. }
  32117. var resolution = component.resolutions[r];
  32118. var numprecincts = resolution.precinctParameters.numprecincts;
  32119. for (; k < numprecincts;) {
  32120. var packet = createPacket(resolution, k, l);
  32121. k++;
  32122. return packet;
  32123. }
  32124. k = 0;
  32125. }
  32126. i = 0;
  32127. }
  32128. r = 0;
  32129. }
  32130. throw new Error('JPX Error: Out of packets');
  32131. };
  32132. }
  32133. function ResolutionLayerComponentPositionIterator(context) {
  32134. var siz = context.SIZ;
  32135. var tileIndex = context.currentTile.index;
  32136. var tile = context.tiles[tileIndex];
  32137. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  32138. var componentsCount = siz.Csiz;
  32139. var maxDecompositionLevelsCount = 0;
  32140. for (var q = 0; q < componentsCount; q++) {
  32141. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  32142. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  32143. }
  32144. var r = 0, l = 0, i = 0, k = 0;
  32145. this.nextPacket = function JpxImage_nextPacket() {
  32146. // Section B.12.1.2 Resolution-layer-component-position
  32147. for (; r <= maxDecompositionLevelsCount; r++) {
  32148. for (; l < layersCount; l++) {
  32149. for (; i < componentsCount; i++) {
  32150. var component = tile.components[i];
  32151. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  32152. continue;
  32153. }
  32154. var resolution = component.resolutions[r];
  32155. var numprecincts = resolution.precinctParameters.numprecincts;
  32156. for (; k < numprecincts;) {
  32157. var packet = createPacket(resolution, k, l);
  32158. k++;
  32159. return packet;
  32160. }
  32161. k = 0;
  32162. }
  32163. i = 0;
  32164. }
  32165. l = 0;
  32166. }
  32167. throw new Error('JPX Error: Out of packets');
  32168. };
  32169. }
  32170. function buildPackets(context) {
  32171. var siz = context.SIZ;
  32172. var tileIndex = context.currentTile.index;
  32173. var tile = context.tiles[tileIndex];
  32174. var componentsCount = siz.Csiz;
  32175. // Creating resolutions and sub-bands for each component
  32176. for (var c = 0; c < componentsCount; c++) {
  32177. var component = tile.components[c];
  32178. var decompositionLevelsCount =
  32179. component.codingStyleParameters.decompositionLevelsCount;
  32180. // Section B.5 Resolution levels and sub-bands
  32181. var resolutions = [];
  32182. var subbands = [];
  32183. for (var r = 0; r <= decompositionLevelsCount; r++) {
  32184. var blocksDimensions = getBlocksDimensions(context, component, r);
  32185. var resolution = {};
  32186. var scale = 1 << (decompositionLevelsCount - r);
  32187. resolution.trx0 = Math.ceil(component.tcx0 / scale);
  32188. resolution.try0 = Math.ceil(component.tcy0 / scale);
  32189. resolution.trx1 = Math.ceil(component.tcx1 / scale);
  32190. resolution.try1 = Math.ceil(component.tcy1 / scale);
  32191. buildPrecincts(context, resolution, blocksDimensions);
  32192. resolutions.push(resolution);
  32193. var subband;
  32194. if (r === 0) {
  32195. // one sub-band (LL) with last decomposition
  32196. subband = {};
  32197. subband.type = 'LL';
  32198. subband.tbx0 = Math.ceil(component.tcx0 / scale);
  32199. subband.tby0 = Math.ceil(component.tcy0 / scale);
  32200. subband.tbx1 = Math.ceil(component.tcx1 / scale);
  32201. subband.tby1 = Math.ceil(component.tcy1 / scale);
  32202. subband.resolution = resolution;
  32203. buildCodeblocks(context, subband, blocksDimensions);
  32204. subbands.push(subband);
  32205. resolution.subbands = [subband];
  32206. } else {
  32207. var bscale = 1 << (decompositionLevelsCount - r + 1);
  32208. var resolutionSubbands = [];
  32209. // three sub-bands (HL, LH and HH) with rest of decompositions
  32210. subband = {};
  32211. subband.type = 'HL';
  32212. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  32213. subband.tby0 = Math.ceil(component.tcy0 / bscale);
  32214. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  32215. subband.tby1 = Math.ceil(component.tcy1 / bscale);
  32216. subband.resolution = resolution;
  32217. buildCodeblocks(context, subband, blocksDimensions);
  32218. subbands.push(subband);
  32219. resolutionSubbands.push(subband);
  32220. subband = {};
  32221. subband.type = 'LH';
  32222. subband.tbx0 = Math.ceil(component.tcx0 / bscale);
  32223. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  32224. subband.tbx1 = Math.ceil(component.tcx1 / bscale);
  32225. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  32226. subband.resolution = resolution;
  32227. buildCodeblocks(context, subband, blocksDimensions);
  32228. subbands.push(subband);
  32229. resolutionSubbands.push(subband);
  32230. subband = {};
  32231. subband.type = 'HH';
  32232. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  32233. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  32234. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  32235. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  32236. subband.resolution = resolution;
  32237. buildCodeblocks(context, subband, blocksDimensions);
  32238. subbands.push(subband);
  32239. resolutionSubbands.push(subband);
  32240. resolution.subbands = resolutionSubbands;
  32241. }
  32242. }
  32243. component.resolutions = resolutions;
  32244. component.subbands = subbands;
  32245. }
  32246. // Generate the packets sequence
  32247. var progressionOrder = tile.codingStyleDefaultParameters.progressionOrder;
  32248. switch (progressionOrder) {
  32249. case 0:
  32250. tile.packetsIterator =
  32251. new LayerResolutionComponentPositionIterator(context);
  32252. break;
  32253. case 1:
  32254. tile.packetsIterator =
  32255. new ResolutionLayerComponentPositionIterator(context);
  32256. break;
  32257. default:
  32258. throw new Error('JPX Error: Unsupported progression order ' +
  32259. progressionOrder);
  32260. }
  32261. }
  32262. function parseTilePackets(context, data, offset, dataLength) {
  32263. var position = 0;
  32264. var buffer, bufferSize = 0, skipNextBit = false;
  32265. function readBits(count) {
  32266. while (bufferSize < count) {
  32267. var b = data[offset + position];
  32268. position++;
  32269. if (skipNextBit) {
  32270. buffer = (buffer << 7) | b;
  32271. bufferSize += 7;
  32272. skipNextBit = false;
  32273. } else {
  32274. buffer = (buffer << 8) | b;
  32275. bufferSize += 8;
  32276. }
  32277. if (b == 0xFF) {
  32278. skipNextBit = true;
  32279. }
  32280. }
  32281. bufferSize -= count;
  32282. return (buffer >>> bufferSize) & ((1 << count) - 1);
  32283. }
  32284. function alignToByte() {
  32285. bufferSize = 0;
  32286. if (skipNextBit) {
  32287. position++;
  32288. skipNextBit = false;
  32289. }
  32290. }
  32291. function readCodingpasses() {
  32292. if (readBits(1) === 0) {
  32293. return 1;
  32294. }
  32295. if (readBits(1) === 0) {
  32296. return 2;
  32297. }
  32298. var value = readBits(2);
  32299. if (value < 3) {
  32300. return value + 3;
  32301. }
  32302. value = readBits(5);
  32303. if (value < 31) {
  32304. return value + 6;
  32305. }
  32306. value = readBits(7);
  32307. return value + 37;
  32308. }
  32309. var tileIndex = context.currentTile.index;
  32310. var tile = context.tiles[tileIndex];
  32311. var packetsIterator = tile.packetsIterator;
  32312. while (position < dataLength) {
  32313. var packet = packetsIterator.nextPacket();
  32314. if (!readBits(1)) {
  32315. alignToByte();
  32316. continue;
  32317. }
  32318. var layerNumber = packet.layerNumber;
  32319. var queue = [], codeblock;
  32320. for (var i = 0, ii = packet.codeblocks.length; i < ii; i++) {
  32321. codeblock = packet.codeblocks[i];
  32322. var precinct = codeblock.precinct;
  32323. var codeblockColumn = codeblock.cbx - precinct.cbxMin;
  32324. var codeblockRow = codeblock.cby - precinct.cbyMin;
  32325. var codeblockIncluded = false;
  32326. var firstTimeInclusion = false;
  32327. var valueReady;
  32328. if ('included' in codeblock) {
  32329. codeblockIncluded = !!readBits(1);
  32330. } else {
  32331. // reading inclusion tree
  32332. precinct = codeblock.precinct;
  32333. var inclusionTree, zeroBitPlanesTree;
  32334. if ('inclusionTree' in precinct) {
  32335. inclusionTree = precinct.inclusionTree;
  32336. } else {
  32337. // building inclusion and zero bit-planes trees
  32338. var width = precinct.cbxMax - precinct.cbxMin + 1;
  32339. var height = precinct.cbyMax - precinct.cbyMin + 1;
  32340. inclusionTree = new InclusionTree(width, height, layerNumber);
  32341. zeroBitPlanesTree = new TagTree(width, height);
  32342. precinct.inclusionTree = inclusionTree;
  32343. precinct.zeroBitPlanesTree = zeroBitPlanesTree;
  32344. }
  32345. if (inclusionTree.reset(codeblockColumn, codeblockRow, layerNumber)) {
  32346. while (true) {
  32347. if (readBits(1)) {
  32348. valueReady = !inclusionTree.nextLevel();
  32349. if (valueReady) {
  32350. codeblock.included = true;
  32351. codeblockIncluded = firstTimeInclusion = true;
  32352. break;
  32353. }
  32354. } else {
  32355. inclusionTree.incrementValue(layerNumber);
  32356. break;
  32357. }
  32358. }
  32359. }
  32360. }
  32361. if (!codeblockIncluded) {
  32362. continue;
  32363. }
  32364. if (firstTimeInclusion) {
  32365. zeroBitPlanesTree = precinct.zeroBitPlanesTree;
  32366. zeroBitPlanesTree.reset(codeblockColumn, codeblockRow);
  32367. while (true) {
  32368. if (readBits(1)) {
  32369. valueReady = !zeroBitPlanesTree.nextLevel();
  32370. if (valueReady) {
  32371. break;
  32372. }
  32373. } else {
  32374. zeroBitPlanesTree.incrementValue();
  32375. }
  32376. }
  32377. codeblock.zeroBitPlanes = zeroBitPlanesTree.value;
  32378. }
  32379. var codingpasses = readCodingpasses();
  32380. while (readBits(1)) {
  32381. codeblock.Lblock++;
  32382. }
  32383. var codingpassesLog2 = log2(codingpasses);
  32384. // rounding down log2
  32385. var bits = ((codingpasses < (1 << codingpassesLog2)) ?
  32386. codingpassesLog2 - 1 : codingpassesLog2) + codeblock.Lblock;
  32387. var codedDataLength = readBits(bits);
  32388. queue.push({
  32389. codeblock: codeblock,
  32390. codingpasses: codingpasses,
  32391. dataLength: codedDataLength
  32392. });
  32393. }
  32394. alignToByte();
  32395. while (queue.length > 0) {
  32396. var packetItem = queue.shift();
  32397. codeblock = packetItem.codeblock;
  32398. if (!('data' in codeblock)) {
  32399. codeblock.data = [];
  32400. }
  32401. codeblock.data.push({
  32402. data: data,
  32403. start: offset + position,
  32404. end: offset + position + packetItem.dataLength,
  32405. codingpasses: packetItem.codingpasses
  32406. });
  32407. position += packetItem.dataLength;
  32408. }
  32409. }
  32410. return position;
  32411. }
  32412. function copyCoefficients(coefficients, levelWidth, levelHeight, subband,
  32413. delta, mb, reversible, segmentationSymbolUsed) {
  32414. var x0 = subband.tbx0;
  32415. var y0 = subband.tby0;
  32416. var width = subband.tbx1 - subband.tbx0;
  32417. var codeblocks = subband.codeblocks;
  32418. var right = subband.type.charAt(0) === 'H' ? 1 : 0;
  32419. var bottom = subband.type.charAt(1) === 'H' ? levelWidth : 0;
  32420. for (var i = 0, ii = codeblocks.length; i < ii; ++i) {
  32421. var codeblock = codeblocks[i];
  32422. var blockWidth = codeblock.tbx1_ - codeblock.tbx0_;
  32423. var blockHeight = codeblock.tby1_ - codeblock.tby0_;
  32424. if (blockWidth === 0 || blockHeight === 0) {
  32425. continue;
  32426. }
  32427. if (!('data' in codeblock)) {
  32428. continue;
  32429. }
  32430. var bitModel, currentCodingpassType;
  32431. bitModel = new BitModel(blockWidth, blockHeight, codeblock.subbandType,
  32432. codeblock.zeroBitPlanes, mb);
  32433. currentCodingpassType = 2; // first bit plane starts from cleanup
  32434. // collect data
  32435. var data = codeblock.data, totalLength = 0, codingpasses = 0;
  32436. var j, jj, dataItem;
  32437. for (j = 0, jj = data.length; j < jj; j++) {
  32438. dataItem = data[j];
  32439. totalLength += dataItem.end - dataItem.start;
  32440. codingpasses += dataItem.codingpasses;
  32441. }
  32442. var encodedData = new Uint8Array(totalLength);
  32443. var position = 0;
  32444. for (j = 0, jj = data.length; j < jj; j++) {
  32445. dataItem = data[j];
  32446. var chunk = dataItem.data.subarray(dataItem.start, dataItem.end);
  32447. encodedData.set(chunk, position);
  32448. position += chunk.length;
  32449. }
  32450. // decoding the item
  32451. var decoder = new ArithmeticDecoder(encodedData, 0, totalLength);
  32452. bitModel.setDecoder(decoder);
  32453. for (j = 0; j < codingpasses; j++) {
  32454. switch (currentCodingpassType) {
  32455. case 0:
  32456. bitModel.runSignificancePropogationPass();
  32457. break;
  32458. case 1:
  32459. bitModel.runMagnitudeRefinementPass();
  32460. break;
  32461. case 2:
  32462. bitModel.runCleanupPass();
  32463. if (segmentationSymbolUsed) {
  32464. bitModel.checkSegmentationSymbol();
  32465. }
  32466. break;
  32467. }
  32468. currentCodingpassType = (currentCodingpassType + 1) % 3;
  32469. }
  32470. var offset = (codeblock.tbx0_ - x0) + (codeblock.tby0_ - y0) * width;
  32471. var sign = bitModel.coefficentsSign;
  32472. var magnitude = bitModel.coefficentsMagnitude;
  32473. var bitsDecoded = bitModel.bitsDecoded;
  32474. var magnitudeCorrection = reversible ? 0 : 0.5;
  32475. var k, n, nb;
  32476. position = 0;
  32477. // Do the interleaving of Section F.3.3 here, so we do not need
  32478. // to copy later. LL level is not interleaved, just copied.
  32479. var interleave = (subband.type !== 'LL');
  32480. for (j = 0; j < blockHeight; j++) {
  32481. var row = (offset / width) | 0; // row in the non-interleaved subband
  32482. var levelOffset = 2 * row * (levelWidth - width) + right + bottom;
  32483. for (k = 0; k < blockWidth; k++) {
  32484. n = magnitude[position];
  32485. if (n !== 0) {
  32486. n = (n + magnitudeCorrection) * delta;
  32487. if (sign[position] !== 0) {
  32488. n = -n;
  32489. }
  32490. nb = bitsDecoded[position];
  32491. var pos = interleave ? (levelOffset + (offset << 1)) : offset;
  32492. if (reversible && (nb >= mb)) {
  32493. coefficients[pos] = n;
  32494. } else {
  32495. coefficients[pos] = n * (1 << (mb - nb));
  32496. }
  32497. }
  32498. offset++;
  32499. position++;
  32500. }
  32501. offset += width - blockWidth;
  32502. }
  32503. }
  32504. }
  32505. function transformTile(context, tile, c) {
  32506. var component = tile.components[c];
  32507. var codingStyleParameters = component.codingStyleParameters;
  32508. var quantizationParameters = component.quantizationParameters;
  32509. var decompositionLevelsCount =
  32510. codingStyleParameters.decompositionLevelsCount;
  32511. var spqcds = quantizationParameters.SPqcds;
  32512. var scalarExpounded = quantizationParameters.scalarExpounded;
  32513. var guardBits = quantizationParameters.guardBits;
  32514. var segmentationSymbolUsed = codingStyleParameters.segmentationSymbolUsed;
  32515. var precision = context.components[c].precision;
  32516. var reversible = codingStyleParameters.reversibleTransformation;
  32517. var transform = (reversible ? new ReversibleTransform() :
  32518. new IrreversibleTransform());
  32519. var subbandCoefficients = [];
  32520. var b = 0;
  32521. for (var i = 0; i <= decompositionLevelsCount; i++) {
  32522. var resolution = component.resolutions[i];
  32523. var width = resolution.trx1 - resolution.trx0;
  32524. var height = resolution.try1 - resolution.try0;
  32525. // Allocate space for the whole sublevel.
  32526. var coefficients = new Float32Array(width * height);
  32527. for (var j = 0, jj = resolution.subbands.length; j < jj; j++) {
  32528. var mu, epsilon;
  32529. if (!scalarExpounded) {
  32530. // formula E-5
  32531. mu = spqcds[0].mu;
  32532. epsilon = spqcds[0].epsilon + (i > 0 ? 1 - i : 0);
  32533. } else {
  32534. mu = spqcds[b].mu;
  32535. epsilon = spqcds[b].epsilon;
  32536. b++;
  32537. }
  32538. var subband = resolution.subbands[j];
  32539. var gainLog2 = SubbandsGainLog2[subband.type];
  32540. // calulate quantization coefficient (Section E.1.1.1)
  32541. var delta = (reversible ? 1 :
  32542. Math.pow(2, precision + gainLog2 - epsilon) * (1 + mu / 2048));
  32543. var mb = (guardBits + epsilon - 1);
  32544. // In the first resolution level, copyCoefficients will fill the
  32545. // whole array with coefficients. In the succeding passes,
  32546. // copyCoefficients will consecutively fill in the values that belong
  32547. // to the interleaved positions of the HL, LH, and HH coefficients.
  32548. // The LL coefficients will then be interleaved in Transform.iterate().
  32549. copyCoefficients(coefficients, width, height, subband, delta, mb,
  32550. reversible, segmentationSymbolUsed);
  32551. }
  32552. subbandCoefficients.push({
  32553. width: width,
  32554. height: height,
  32555. items: coefficients
  32556. });
  32557. }
  32558. var result = transform.calculate(subbandCoefficients,
  32559. component.tcx0, component.tcy0);
  32560. return {
  32561. left: component.tcx0,
  32562. top: component.tcy0,
  32563. width: result.width,
  32564. height: result.height,
  32565. items: result.items
  32566. };
  32567. }
  32568. function transformComponents(context) {
  32569. var siz = context.SIZ;
  32570. var components = context.components;
  32571. var componentsCount = siz.Csiz;
  32572. var resultImages = [];
  32573. for (var i = 0, ii = context.tiles.length; i < ii; i++) {
  32574. var tile = context.tiles[i];
  32575. var transformedTiles = [];
  32576. var c;
  32577. for (c = 0; c < componentsCount; c++) {
  32578. transformedTiles[c] = transformTile(context, tile, c);
  32579. }
  32580. var tile0 = transformedTiles[0];
  32581. var out = new Uint8Array(tile0.items.length * componentsCount);
  32582. var result = {
  32583. left: tile0.left,
  32584. top: tile0.top,
  32585. width: tile0.width,
  32586. height: tile0.height,
  32587. items: out
  32588. };
  32589. // Section G.2.2 Inverse multi component transform
  32590. var shift, offset, max, min, maxK;
  32591. var pos = 0, j, jj, y0, y1, y2, r, g, b, k, val;
  32592. if (tile.codingStyleDefaultParameters.multipleComponentTransform) {
  32593. var fourComponents = componentsCount === 4;
  32594. var y0items = transformedTiles[0].items;
  32595. var y1items = transformedTiles[1].items;
  32596. var y2items = transformedTiles[2].items;
  32597. var y3items = fourComponents ? transformedTiles[3].items : null;
  32598. // HACK: The multiple component transform formulas below assume that
  32599. // all components have the same precision. With this in mind, we
  32600. // compute shift and offset only once.
  32601. shift = components[0].precision - 8;
  32602. offset = (128 << shift) + 0.5;
  32603. max = 255 * (1 << shift);
  32604. maxK = max * 0.5;
  32605. min = -maxK;
  32606. var component0 = tile.components[0];
  32607. var alpha01 = componentsCount - 3;
  32608. jj = y0items.length;
  32609. if (!component0.codingStyleParameters.reversibleTransformation) {
  32610. // inverse irreversible multiple component transform
  32611. for (j = 0; j < jj; j++, pos += alpha01) {
  32612. y0 = y0items[j] + offset;
  32613. y1 = y1items[j];
  32614. y2 = y2items[j];
  32615. r = y0 + 1.402 * y2;
  32616. g = y0 - 0.34413 * y1 - 0.71414 * y2;
  32617. b = y0 + 1.772 * y1;
  32618. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  32619. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  32620. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  32621. }
  32622. } else {
  32623. // inverse reversible multiple component transform
  32624. for (j = 0; j < jj; j++, pos += alpha01) {
  32625. y0 = y0items[j] + offset;
  32626. y1 = y1items[j];
  32627. y2 = y2items[j];
  32628. g = y0 - ((y2 + y1) >> 2);
  32629. r = g + y2;
  32630. b = g + y1;
  32631. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  32632. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  32633. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  32634. }
  32635. }
  32636. if (fourComponents) {
  32637. for (j = 0, pos = 3; j < jj; j++, pos += 4) {
  32638. k = y3items[j];
  32639. out[pos] = k <= min ? 0 : k >= maxK ? 255 : (k + offset) >> shift;
  32640. }
  32641. }
  32642. } else { // no multi-component transform
  32643. for (c = 0; c < componentsCount; c++) {
  32644. var items = transformedTiles[c].items;
  32645. shift = components[c].precision - 8;
  32646. offset = (128 << shift) + 0.5;
  32647. max = (127.5 * (1 << shift));
  32648. min = -max;
  32649. for (pos = c, j = 0, jj = items.length; j < jj; j++) {
  32650. val = items[j];
  32651. out[pos] = val <= min ? 0 :
  32652. val >= max ? 255 : (val + offset) >> shift;
  32653. pos += componentsCount;
  32654. }
  32655. }
  32656. }
  32657. resultImages.push(result);
  32658. }
  32659. return resultImages;
  32660. }
  32661. function initializeTile(context, tileIndex) {
  32662. var siz = context.SIZ;
  32663. var componentsCount = siz.Csiz;
  32664. var tile = context.tiles[tileIndex];
  32665. for (var c = 0; c < componentsCount; c++) {
  32666. var component = tile.components[c];
  32667. var qcdOrQcc = (c in context.currentTile.QCC ?
  32668. context.currentTile.QCC[c] : context.currentTile.QCD);
  32669. component.quantizationParameters = qcdOrQcc;
  32670. var codOrCoc = (c in context.currentTile.COC ?
  32671. context.currentTile.COC[c] : context.currentTile.COD);
  32672. component.codingStyleParameters = codOrCoc;
  32673. }
  32674. tile.codingStyleDefaultParameters = context.currentTile.COD;
  32675. }
  32676. // Section B.10.2 Tag trees
  32677. var TagTree = (function TagTreeClosure() {
  32678. function TagTree(width, height) {
  32679. var levelsLength = log2(Math.max(width, height)) + 1;
  32680. this.levels = [];
  32681. for (var i = 0; i < levelsLength; i++) {
  32682. var level = {
  32683. width: width,
  32684. height: height,
  32685. items: []
  32686. };
  32687. this.levels.push(level);
  32688. width = Math.ceil(width / 2);
  32689. height = Math.ceil(height / 2);
  32690. }
  32691. }
  32692. TagTree.prototype = {
  32693. reset: function TagTree_reset(i, j) {
  32694. var currentLevel = 0, value = 0, level;
  32695. while (currentLevel < this.levels.length) {
  32696. level = this.levels[currentLevel];
  32697. var index = i + j * level.width;
  32698. if (index in level.items) {
  32699. value = level.items[index];
  32700. break;
  32701. }
  32702. level.index = index;
  32703. i >>= 1;
  32704. j >>= 1;
  32705. currentLevel++;
  32706. }
  32707. currentLevel--;
  32708. level = this.levels[currentLevel];
  32709. level.items[level.index] = value;
  32710. this.currentLevel = currentLevel;
  32711. delete this.value;
  32712. },
  32713. incrementValue: function TagTree_incrementValue() {
  32714. var level = this.levels[this.currentLevel];
  32715. level.items[level.index]++;
  32716. },
  32717. nextLevel: function TagTree_nextLevel() {
  32718. var currentLevel = this.currentLevel;
  32719. var level = this.levels[currentLevel];
  32720. var value = level.items[level.index];
  32721. currentLevel--;
  32722. if (currentLevel < 0) {
  32723. this.value = value;
  32724. return false;
  32725. }
  32726. this.currentLevel = currentLevel;
  32727. level = this.levels[currentLevel];
  32728. level.items[level.index] = value;
  32729. return true;
  32730. }
  32731. };
  32732. return TagTree;
  32733. })();
  32734. var InclusionTree = (function InclusionTreeClosure() {
  32735. function InclusionTree(width, height, defaultValue) {
  32736. var levelsLength = log2(Math.max(width, height)) + 1;
  32737. this.levels = [];
  32738. for (var i = 0; i < levelsLength; i++) {
  32739. var items = new Uint8Array(width * height);
  32740. for (var j = 0, jj = items.length; j < jj; j++) {
  32741. items[j] = defaultValue;
  32742. }
  32743. var level = {
  32744. width: width,
  32745. height: height,
  32746. items: items
  32747. };
  32748. this.levels.push(level);
  32749. width = Math.ceil(width / 2);
  32750. height = Math.ceil(height / 2);
  32751. }
  32752. }
  32753. InclusionTree.prototype = {
  32754. reset: function InclusionTree_reset(i, j, stopValue) {
  32755. var currentLevel = 0;
  32756. while (currentLevel < this.levels.length) {
  32757. var level = this.levels[currentLevel];
  32758. var index = i + j * level.width;
  32759. level.index = index;
  32760. var value = level.items[index];
  32761. if (value == 0xFF) {
  32762. break;
  32763. }
  32764. if (value > stopValue) {
  32765. this.currentLevel = currentLevel;
  32766. // already know about this one, propagating the value to top levels
  32767. this.propagateValues();
  32768. return false;
  32769. }
  32770. i >>= 1;
  32771. j >>= 1;
  32772. currentLevel++;
  32773. }
  32774. this.currentLevel = currentLevel - 1;
  32775. return true;
  32776. },
  32777. incrementValue: function InclusionTree_incrementValue(stopValue) {
  32778. var level = this.levels[this.currentLevel];
  32779. level.items[level.index] = stopValue + 1;
  32780. this.propagateValues();
  32781. },
  32782. propagateValues: function InclusionTree_propagateValues() {
  32783. var levelIndex = this.currentLevel;
  32784. var level = this.levels[levelIndex];
  32785. var currentValue = level.items[level.index];
  32786. while (--levelIndex >= 0) {
  32787. level = this.levels[levelIndex];
  32788. level.items[level.index] = currentValue;
  32789. }
  32790. },
  32791. nextLevel: function InclusionTree_nextLevel() {
  32792. var currentLevel = this.currentLevel;
  32793. var level = this.levels[currentLevel];
  32794. var value = level.items[level.index];
  32795. level.items[level.index] = 0xFF;
  32796. currentLevel--;
  32797. if (currentLevel < 0) {
  32798. return false;
  32799. }
  32800. this.currentLevel = currentLevel;
  32801. level = this.levels[currentLevel];
  32802. level.items[level.index] = value;
  32803. return true;
  32804. }
  32805. };
  32806. return InclusionTree;
  32807. })();
  32808. // Section D. Coefficient bit modeling
  32809. var BitModel = (function BitModelClosure() {
  32810. var UNIFORM_CONTEXT = 17;
  32811. var RUNLENGTH_CONTEXT = 18;
  32812. // Table D-1
  32813. // The index is binary presentation: 0dddvvhh, ddd - sum of Di (0..4),
  32814. // vv - sum of Vi (0..2), and hh - sum of Hi (0..2)
  32815. var LLAndLHContextsLabel = new Uint8Array([
  32816. 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,
  32817. 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,
  32818. 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
  32819. ]);
  32820. var HLContextLabel = new Uint8Array([
  32821. 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,
  32822. 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,
  32823. 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
  32824. ]);
  32825. var HHContextLabel = new Uint8Array([
  32826. 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,
  32827. 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,
  32828. 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
  32829. ]);
  32830. function BitModel(width, height, subband, zeroBitPlanes, mb) {
  32831. this.width = width;
  32832. this.height = height;
  32833. this.contextLabelTable = (subband == 'HH' ? HHContextLabel :
  32834. (subband == 'HL' ? HLContextLabel : LLAndLHContextsLabel));
  32835. var coefficientCount = width * height;
  32836. // coefficients outside the encoding region treated as insignificant
  32837. // add border state cells for significanceState
  32838. this.neighborsSignificance = new Uint8Array(coefficientCount);
  32839. this.coefficentsSign = new Uint8Array(coefficientCount);
  32840. this.coefficentsMagnitude = mb > 14 ? new Uint32Array(coefficientCount) :
  32841. mb > 6 ? new Uint16Array(coefficientCount) :
  32842. new Uint8Array(coefficientCount);
  32843. this.processingFlags = new Uint8Array(coefficientCount);
  32844. var bitsDecoded = new Uint8Array(coefficientCount);
  32845. if (zeroBitPlanes !== 0) {
  32846. for (var i = 0; i < coefficientCount; i++) {
  32847. bitsDecoded[i] = zeroBitPlanes;
  32848. }
  32849. }
  32850. this.bitsDecoded = bitsDecoded;
  32851. this.reset();
  32852. }
  32853. BitModel.prototype = {
  32854. setDecoder: function BitModel_setDecoder(decoder) {
  32855. this.decoder = decoder;
  32856. },
  32857. reset: function BitModel_reset() {
  32858. // We have 17 contexts that are accessed via context labels,
  32859. // plus the uniform and runlength context.
  32860. this.contexts = new Int8Array(19);
  32861. // Contexts are packed into 1 byte:
  32862. // highest 7 bits carry the index, lowest bit carries mps
  32863. this.contexts[0] = (4 << 1) | 0;
  32864. this.contexts[UNIFORM_CONTEXT] = (46 << 1) | 0;
  32865. this.contexts[RUNLENGTH_CONTEXT] = (3 << 1) | 0;
  32866. },
  32867. setNeighborsSignificance:
  32868. function BitModel_setNeighborsSignificance(row, column, index) {
  32869. var neighborsSignificance = this.neighborsSignificance;
  32870. var width = this.width, height = this.height;
  32871. var left = (column > 0);
  32872. var right = (column + 1 < width);
  32873. var i;
  32874. if (row > 0) {
  32875. i = index - width;
  32876. if (left) {
  32877. neighborsSignificance[i - 1] += 0x10;
  32878. }
  32879. if (right) {
  32880. neighborsSignificance[i + 1] += 0x10;
  32881. }
  32882. neighborsSignificance[i] += 0x04;
  32883. }
  32884. if (row + 1 < height) {
  32885. i = index + width;
  32886. if (left) {
  32887. neighborsSignificance[i - 1] += 0x10;
  32888. }
  32889. if (right) {
  32890. neighborsSignificance[i + 1] += 0x10;
  32891. }
  32892. neighborsSignificance[i] += 0x04;
  32893. }
  32894. if (left) {
  32895. neighborsSignificance[index - 1] += 0x01;
  32896. }
  32897. if (right) {
  32898. neighborsSignificance[index + 1] += 0x01;
  32899. }
  32900. neighborsSignificance[index] |= 0x80;
  32901. },
  32902. runSignificancePropogationPass:
  32903. function BitModel_runSignificancePropogationPass() {
  32904. var decoder = this.decoder;
  32905. var width = this.width, height = this.height;
  32906. var coefficentsMagnitude = this.coefficentsMagnitude;
  32907. var coefficentsSign = this.coefficentsSign;
  32908. var neighborsSignificance = this.neighborsSignificance;
  32909. var processingFlags = this.processingFlags;
  32910. var contexts = this.contexts;
  32911. var labels = this.contextLabelTable;
  32912. var bitsDecoded = this.bitsDecoded;
  32913. var processedInverseMask = ~1;
  32914. var processedMask = 1;
  32915. var firstMagnitudeBitMask = 2;
  32916. for (var i0 = 0; i0 < height; i0 += 4) {
  32917. for (var j = 0; j < width; j++) {
  32918. var index = i0 * width + j;
  32919. for (var i1 = 0; i1 < 4; i1++, index += width) {
  32920. var i = i0 + i1;
  32921. if (i >= height) {
  32922. break;
  32923. }
  32924. // clear processed flag first
  32925. processingFlags[index] &= processedInverseMask;
  32926. if (coefficentsMagnitude[index] ||
  32927. !neighborsSignificance[index]) {
  32928. continue;
  32929. }
  32930. var contextLabel = labels[neighborsSignificance[index]];
  32931. var decision = decoder.readBit(contexts, contextLabel);
  32932. if (decision) {
  32933. var sign = this.decodeSignBit(i, j, index);
  32934. coefficentsSign[index] = sign;
  32935. coefficentsMagnitude[index] = 1;
  32936. this.setNeighborsSignificance(i, j, index);
  32937. processingFlags[index] |= firstMagnitudeBitMask;
  32938. }
  32939. bitsDecoded[index]++;
  32940. processingFlags[index] |= processedMask;
  32941. }
  32942. }
  32943. }
  32944. },
  32945. decodeSignBit: function BitModel_decodeSignBit(row, column, index) {
  32946. var width = this.width, height = this.height;
  32947. var coefficentsMagnitude = this.coefficentsMagnitude;
  32948. var coefficentsSign = this.coefficentsSign;
  32949. var contribution, sign0, sign1, significance1;
  32950. var contextLabel, decoded;
  32951. // calculate horizontal contribution
  32952. significance1 = (column > 0 && coefficentsMagnitude[index - 1] !== 0);
  32953. if (column + 1 < width && coefficentsMagnitude[index + 1] !== 0) {
  32954. sign1 = coefficentsSign[index + 1];
  32955. if (significance1) {
  32956. sign0 = coefficentsSign[index - 1];
  32957. contribution = 1 - sign1 - sign0;
  32958. } else {
  32959. contribution = 1 - sign1 - sign1;
  32960. }
  32961. } else if (significance1) {
  32962. sign0 = coefficentsSign[index - 1];
  32963. contribution = 1 - sign0 - sign0;
  32964. } else {
  32965. contribution = 0;
  32966. }
  32967. var horizontalContribution = 3 * contribution;
  32968. // calculate vertical contribution and combine with the horizontal
  32969. significance1 = (row > 0 && coefficentsMagnitude[index - width] !== 0);
  32970. if (row + 1 < height && coefficentsMagnitude[index + width] !== 0) {
  32971. sign1 = coefficentsSign[index + width];
  32972. if (significance1) {
  32973. sign0 = coefficentsSign[index - width];
  32974. contribution = 1 - sign1 - sign0 + horizontalContribution;
  32975. } else {
  32976. contribution = 1 - sign1 - sign1 + horizontalContribution;
  32977. }
  32978. } else if (significance1) {
  32979. sign0 = coefficentsSign[index - width];
  32980. contribution = 1 - sign0 - sign0 + horizontalContribution;
  32981. } else {
  32982. contribution = horizontalContribution;
  32983. }
  32984. if (contribution >= 0) {
  32985. contextLabel = 9 + contribution;
  32986. decoded = this.decoder.readBit(this.contexts, contextLabel);
  32987. } else {
  32988. contextLabel = 9 - contribution;
  32989. decoded = this.decoder.readBit(this.contexts, contextLabel) ^ 1;
  32990. }
  32991. return decoded;
  32992. },
  32993. runMagnitudeRefinementPass:
  32994. function BitModel_runMagnitudeRefinementPass() {
  32995. var decoder = this.decoder;
  32996. var width = this.width, height = this.height;
  32997. var coefficentsMagnitude = this.coefficentsMagnitude;
  32998. var neighborsSignificance = this.neighborsSignificance;
  32999. var contexts = this.contexts;
  33000. var bitsDecoded = this.bitsDecoded;
  33001. var processingFlags = this.processingFlags;
  33002. var processedMask = 1;
  33003. var firstMagnitudeBitMask = 2;
  33004. var length = width * height;
  33005. var width4 = width * 4;
  33006. for (var index0 = 0, indexNext; index0 < length; index0 = indexNext) {
  33007. indexNext = Math.min(length, index0 + width4);
  33008. for (var j = 0; j < width; j++) {
  33009. for (var index = index0 + j; index < indexNext; index += width) {
  33010. // significant but not those that have just become
  33011. if (!coefficentsMagnitude[index] ||
  33012. (processingFlags[index] & processedMask) !== 0) {
  33013. continue;
  33014. }
  33015. var contextLabel = 16;
  33016. if ((processingFlags[index] & firstMagnitudeBitMask) !== 0) {
  33017. processingFlags[index] ^= firstMagnitudeBitMask;
  33018. // first refinement
  33019. var significance = neighborsSignificance[index] & 127;
  33020. contextLabel = significance === 0 ? 15 : 14;
  33021. }
  33022. var bit = decoder.readBit(contexts, contextLabel);
  33023. coefficentsMagnitude[index] =
  33024. (coefficentsMagnitude[index] << 1) | bit;
  33025. bitsDecoded[index]++;
  33026. processingFlags[index] |= processedMask;
  33027. }
  33028. }
  33029. }
  33030. },
  33031. runCleanupPass: function BitModel_runCleanupPass() {
  33032. var decoder = this.decoder;
  33033. var width = this.width, height = this.height;
  33034. var neighborsSignificance = this.neighborsSignificance;
  33035. var coefficentsMagnitude = this.coefficentsMagnitude;
  33036. var coefficentsSign = this.coefficentsSign;
  33037. var contexts = this.contexts;
  33038. var labels = this.contextLabelTable;
  33039. var bitsDecoded = this.bitsDecoded;
  33040. var processingFlags = this.processingFlags;
  33041. var processedMask = 1;
  33042. var firstMagnitudeBitMask = 2;
  33043. var oneRowDown = width;
  33044. var twoRowsDown = width * 2;
  33045. var threeRowsDown = width * 3;
  33046. var iNext;
  33047. for (var i0 = 0; i0 < height; i0 = iNext) {
  33048. iNext = Math.min(i0 + 4, height);
  33049. var indexBase = i0 * width;
  33050. var checkAllEmpty = i0 + 3 < height;
  33051. for (var j = 0; j < width; j++) {
  33052. var index0 = indexBase + j;
  33053. // using the property: labels[neighborsSignificance[index]] == 0
  33054. // when neighborsSignificance[index] == 0
  33055. var allEmpty = (checkAllEmpty &&
  33056. processingFlags[index0] === 0 &&
  33057. processingFlags[index0 + oneRowDown] === 0 &&
  33058. processingFlags[index0 + twoRowsDown] === 0 &&
  33059. processingFlags[index0 + threeRowsDown] === 0 &&
  33060. neighborsSignificance[index0] === 0 &&
  33061. neighborsSignificance[index0 + oneRowDown] === 0 &&
  33062. neighborsSignificance[index0 + twoRowsDown] === 0 &&
  33063. neighborsSignificance[index0 + threeRowsDown] === 0);
  33064. var i1 = 0, index = index0;
  33065. var i = i0, sign;
  33066. if (allEmpty) {
  33067. var hasSignificantCoefficent =
  33068. decoder.readBit(contexts, RUNLENGTH_CONTEXT);
  33069. if (!hasSignificantCoefficent) {
  33070. bitsDecoded[index0]++;
  33071. bitsDecoded[index0 + oneRowDown]++;
  33072. bitsDecoded[index0 + twoRowsDown]++;
  33073. bitsDecoded[index0 + threeRowsDown]++;
  33074. continue; // next column
  33075. }
  33076. i1 = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  33077. decoder.readBit(contexts, UNIFORM_CONTEXT);
  33078. if (i1 !== 0) {
  33079. i = i0 + i1;
  33080. index += i1 * width;
  33081. }
  33082. sign = this.decodeSignBit(i, j, index);
  33083. coefficentsSign[index] = sign;
  33084. coefficentsMagnitude[index] = 1;
  33085. this.setNeighborsSignificance(i, j, index);
  33086. processingFlags[index] |= firstMagnitudeBitMask;
  33087. index = index0;
  33088. for (var i2 = i0; i2 <= i; i2++, index += width) {
  33089. bitsDecoded[index]++;
  33090. }
  33091. i1++;
  33092. }
  33093. for (i = i0 + i1; i < iNext; i++, index += width) {
  33094. if (coefficentsMagnitude[index] ||
  33095. (processingFlags[index] & processedMask) !== 0) {
  33096. continue;
  33097. }
  33098. var contextLabel = labels[neighborsSignificance[index]];
  33099. var decision = decoder.readBit(contexts, contextLabel);
  33100. if (decision === 1) {
  33101. sign = this.decodeSignBit(i, j, index);
  33102. coefficentsSign[index] = sign;
  33103. coefficentsMagnitude[index] = 1;
  33104. this.setNeighborsSignificance(i, j, index);
  33105. processingFlags[index] |= firstMagnitudeBitMask;
  33106. }
  33107. bitsDecoded[index]++;
  33108. }
  33109. }
  33110. }
  33111. },
  33112. checkSegmentationSymbol: function BitModel_checkSegmentationSymbol() {
  33113. var decoder = this.decoder;
  33114. var contexts = this.contexts;
  33115. var symbol = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 3) |
  33116. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 2) |
  33117. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  33118. decoder.readBit(contexts, UNIFORM_CONTEXT);
  33119. if (symbol != 0xA) {
  33120. throw new Error('JPX Error: Invalid segmentation symbol');
  33121. }
  33122. }
  33123. };
  33124. return BitModel;
  33125. })();
  33126. // Section F, Discrete wavelet transformation
  33127. var Transform = (function TransformClosure() {
  33128. function Transform() {}
  33129. Transform.prototype.calculate =
  33130. function transformCalculate(subbands, u0, v0) {
  33131. var ll = subbands[0];
  33132. for (var i = 1, ii = subbands.length; i < ii; i++) {
  33133. ll = this.iterate(ll, subbands[i], u0, v0);
  33134. }
  33135. return ll;
  33136. };
  33137. Transform.prototype.extend = function extend(buffer, offset, size) {
  33138. // Section F.3.7 extending... using max extension of 4
  33139. var i1 = offset - 1, j1 = offset + 1;
  33140. var i2 = offset + size - 2, j2 = offset + size;
  33141. buffer[i1--] = buffer[j1++];
  33142. buffer[j2++] = buffer[i2--];
  33143. buffer[i1--] = buffer[j1++];
  33144. buffer[j2++] = buffer[i2--];
  33145. buffer[i1--] = buffer[j1++];
  33146. buffer[j2++] = buffer[i2--];
  33147. buffer[i1] = buffer[j1];
  33148. buffer[j2] = buffer[i2];
  33149. };
  33150. Transform.prototype.iterate = function Transform_iterate(ll, hl_lh_hh,
  33151. u0, v0) {
  33152. var llWidth = ll.width, llHeight = ll.height, llItems = ll.items;
  33153. var width = hl_lh_hh.width;
  33154. var height = hl_lh_hh.height;
  33155. var items = hl_lh_hh.items;
  33156. var i, j, k, l, u, v;
  33157. // Interleave LL according to Section F.3.3
  33158. for (k = 0, i = 0; i < llHeight; i++) {
  33159. l = i * 2 * width;
  33160. for (j = 0; j < llWidth; j++, k++, l += 2) {
  33161. items[l] = llItems[k];
  33162. }
  33163. }
  33164. // The LL band is not needed anymore.
  33165. llItems = ll.items = null;
  33166. var bufferPadding = 4;
  33167. var rowBuffer = new Float32Array(width + 2 * bufferPadding);
  33168. // Section F.3.4 HOR_SR
  33169. if (width === 1) {
  33170. // if width = 1, when u0 even keep items as is, when odd divide by 2
  33171. if ((u0 & 1) !== 0) {
  33172. for (v = 0, k = 0; v < height; v++, k += width) {
  33173. items[k] *= 0.5;
  33174. }
  33175. }
  33176. } else {
  33177. for (v = 0, k = 0; v < height; v++, k += width) {
  33178. rowBuffer.set(items.subarray(k, k + width), bufferPadding);
  33179. this.extend(rowBuffer, bufferPadding, width);
  33180. this.filter(rowBuffer, bufferPadding, width);
  33181. items.set(
  33182. rowBuffer.subarray(bufferPadding, bufferPadding + width),
  33183. k);
  33184. }
  33185. }
  33186. // Accesses to the items array can take long, because it may not fit into
  33187. // CPU cache and has to be fetched from main memory. Since subsequent
  33188. // accesses to the items array are not local when reading columns, we
  33189. // have a cache miss every time. To reduce cache misses, get up to
  33190. // 'numBuffers' items at a time and store them into the individual
  33191. // buffers. The colBuffers should be small enough to fit into CPU cache.
  33192. var numBuffers = 16;
  33193. var colBuffers = [];
  33194. for (i = 0; i < numBuffers; i++) {
  33195. colBuffers.push(new Float32Array(height + 2 * bufferPadding));
  33196. }
  33197. var b, currentBuffer = 0;
  33198. ll = bufferPadding + height;
  33199. // Section F.3.5 VER_SR
  33200. if (height === 1) {
  33201. // if height = 1, when v0 even keep items as is, when odd divide by 2
  33202. if ((v0 & 1) !== 0) {
  33203. for (u = 0; u < width; u++) {
  33204. items[u] *= 0.5;
  33205. }
  33206. }
  33207. } else {
  33208. for (u = 0; u < width; u++) {
  33209. // if we ran out of buffers, copy several image columns at once
  33210. if (currentBuffer === 0) {
  33211. numBuffers = Math.min(width - u, numBuffers);
  33212. for (k = u, l = bufferPadding; l < ll; k += width, l++) {
  33213. for (b = 0; b < numBuffers; b++) {
  33214. colBuffers[b][l] = items[k + b];
  33215. }
  33216. }
  33217. currentBuffer = numBuffers;
  33218. }
  33219. currentBuffer--;
  33220. var buffer = colBuffers[currentBuffer];
  33221. this.extend(buffer, bufferPadding, height);
  33222. this.filter(buffer, bufferPadding, height);
  33223. // If this is last buffer in this group of buffers, flush all buffers.
  33224. if (currentBuffer === 0) {
  33225. k = u - numBuffers + 1;
  33226. for (l = bufferPadding; l < ll; k += width, l++) {
  33227. for (b = 0; b < numBuffers; b++) {
  33228. items[k + b] = colBuffers[b][l];
  33229. }
  33230. }
  33231. }
  33232. }
  33233. }
  33234. return {
  33235. width: width,
  33236. height: height,
  33237. items: items
  33238. };
  33239. };
  33240. return Transform;
  33241. })();
  33242. // Section 3.8.2 Irreversible 9-7 filter
  33243. var IrreversibleTransform = (function IrreversibleTransformClosure() {
  33244. function IrreversibleTransform() {
  33245. Transform.call(this);
  33246. }
  33247. IrreversibleTransform.prototype = Object.create(Transform.prototype);
  33248. IrreversibleTransform.prototype.filter =
  33249. function irreversibleTransformFilter(x, offset, length) {
  33250. var len = length >> 1;
  33251. offset = offset | 0;
  33252. var j, n, current, next;
  33253. var alpha = -1.586134342059924;
  33254. var beta = -0.052980118572961;
  33255. var gamma = 0.882911075530934;
  33256. var delta = 0.443506852043971;
  33257. var K = 1.230174104914001;
  33258. var K_ = 1 / K;
  33259. // step 1 is combined with step 3
  33260. // step 2
  33261. j = offset - 3;
  33262. for (n = len + 4; n--; j += 2) {
  33263. x[j] *= K_;
  33264. }
  33265. // step 1 & 3
  33266. j = offset - 2;
  33267. current = delta * x[j -1];
  33268. for (n = len + 3; n--; j += 2) {
  33269. next = delta * x[j + 1];
  33270. x[j] = K * x[j] - current - next;
  33271. if (n--) {
  33272. j += 2;
  33273. current = delta * x[j + 1];
  33274. x[j] = K * x[j] - current - next;
  33275. } else {
  33276. break;
  33277. }
  33278. }
  33279. // step 4
  33280. j = offset - 1;
  33281. current = gamma * x[j - 1];
  33282. for (n = len + 2; n--; j += 2) {
  33283. next = gamma * x[j + 1];
  33284. x[j] -= current + next;
  33285. if (n--) {
  33286. j += 2;
  33287. current = gamma * x[j + 1];
  33288. x[j] -= current + next;
  33289. } else {
  33290. break;
  33291. }
  33292. }
  33293. // step 5
  33294. j = offset;
  33295. current = beta * x[j - 1];
  33296. for (n = len + 1; n--; j += 2) {
  33297. next = beta * x[j + 1];
  33298. x[j] -= current + next;
  33299. if (n--) {
  33300. j += 2;
  33301. current = beta * x[j + 1];
  33302. x[j] -= current + next;
  33303. } else {
  33304. break;
  33305. }
  33306. }
  33307. // step 6
  33308. if (len !== 0) {
  33309. j = offset + 1;
  33310. current = alpha * x[j - 1];
  33311. for (n = len; n--; j += 2) {
  33312. next = alpha * x[j + 1];
  33313. x[j] -= current + next;
  33314. if (n--) {
  33315. j += 2;
  33316. current = alpha * x[j + 1];
  33317. x[j] -= current + next;
  33318. } else {
  33319. break;
  33320. }
  33321. }
  33322. }
  33323. };
  33324. return IrreversibleTransform;
  33325. })();
  33326. // Section 3.8.1 Reversible 5-3 filter
  33327. var ReversibleTransform = (function ReversibleTransformClosure() {
  33328. function ReversibleTransform() {
  33329. Transform.call(this);
  33330. }
  33331. ReversibleTransform.prototype = Object.create(Transform.prototype);
  33332. ReversibleTransform.prototype.filter =
  33333. function reversibleTransformFilter(x, offset, length) {
  33334. var len = length >> 1;
  33335. offset = offset | 0;
  33336. var j, n;
  33337. for (j = offset, n = len + 1; n--; j += 2) {
  33338. x[j] -= (x[j - 1] + x[j + 1] + 2) >> 2;
  33339. }
  33340. for (j = offset + 1, n = len; n--; j += 2) {
  33341. x[j] += (x[j - 1] + x[j + 1]) >> 1;
  33342. }
  33343. };
  33344. return ReversibleTransform;
  33345. })();
  33346. return JpxImage;
  33347. })();
  33348. var Jbig2Image = (function Jbig2ImageClosure() {
  33349. // Utility data structures
  33350. function ContextCache() {}
  33351. ContextCache.prototype = {
  33352. getContexts: function(id) {
  33353. if (id in this) {
  33354. return this[id];
  33355. }
  33356. return (this[id] = new Int8Array(1 << 16));
  33357. }
  33358. };
  33359. function DecodingContext(data, start, end) {
  33360. this.data = data;
  33361. this.start = start;
  33362. this.end = end;
  33363. }
  33364. DecodingContext.prototype = {
  33365. get decoder() {
  33366. var decoder = new ArithmeticDecoder(this.data, this.start, this.end);
  33367. return shadow(this, 'decoder', decoder);
  33368. },
  33369. get contextCache() {
  33370. var cache = new ContextCache();
  33371. return shadow(this, 'contextCache', cache);
  33372. }
  33373. };
  33374. // Annex A. Arithmetic Integer Decoding Procedure
  33375. // A.2 Procedure for decoding values
  33376. function decodeInteger(contextCache, procedure, decoder) {
  33377. var contexts = contextCache.getContexts(procedure);
  33378. var prev = 1;
  33379. function readBits(length) {
  33380. var v = 0;
  33381. for (var i = 0; i < length; i++) {
  33382. var bit = decoder.readBit(contexts, prev);
  33383. prev = (prev < 256 ? (prev << 1) | bit :
  33384. (((prev << 1) | bit) & 511) | 256);
  33385. v = (v << 1) | bit;
  33386. }
  33387. return v >>> 0;
  33388. }
  33389. var sign = readBits(1);
  33390. var value = readBits(1) ?
  33391. (readBits(1) ?
  33392. (readBits(1) ?
  33393. (readBits(1) ?
  33394. (readBits(1) ?
  33395. (readBits(32) + 4436) :
  33396. readBits(12) + 340) :
  33397. readBits(8) + 84) :
  33398. readBits(6) + 20) :
  33399. readBits(4) + 4) :
  33400. readBits(2);
  33401. return (sign === 0 ? value : (value > 0 ? -value : null));
  33402. }
  33403. // A.3 The IAID decoding procedure
  33404. function decodeIAID(contextCache, decoder, codeLength) {
  33405. var contexts = contextCache.getContexts('IAID');
  33406. var prev = 1;
  33407. for (var i = 0; i < codeLength; i++) {
  33408. var bit = decoder.readBit(contexts, prev);
  33409. prev = (prev << 1) | bit;
  33410. }
  33411. if (codeLength < 31) {
  33412. return prev & ((1 << codeLength) - 1);
  33413. }
  33414. return prev & 0x7FFFFFFF;
  33415. }
  33416. // 7.3 Segment types
  33417. var SegmentTypes = [
  33418. 'SymbolDictionary', null, null, null, 'IntermediateTextRegion', null,
  33419. 'ImmediateTextRegion', 'ImmediateLosslessTextRegion', null, null, null,
  33420. null, null, null, null, null, 'patternDictionary', null, null, null,
  33421. 'IntermediateHalftoneRegion', null, 'ImmediateHalftoneRegion',
  33422. 'ImmediateLosslessHalftoneRegion', null, null, null, null, null, null, null,
  33423. null, null, null, null, null, 'IntermediateGenericRegion', null,
  33424. 'ImmediateGenericRegion', 'ImmediateLosslessGenericRegion',
  33425. 'IntermediateGenericRefinementRegion', null,
  33426. 'ImmediateGenericRefinementRegion',
  33427. 'ImmediateLosslessGenericRefinementRegion', null, null, null, null,
  33428. 'PageInformation', 'EndOfPage', 'EndOfStripe', 'EndOfFile', 'Profiles',
  33429. 'Tables', null, null, null, null, null, null, null, null,
  33430. 'Extension'
  33431. ];
  33432. var CodingTemplates = [
  33433. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  33434. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: 2, y: -1},
  33435. {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  33436. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: 2, y: -2},
  33437. {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1},
  33438. {x: 2, y: -1}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  33439. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  33440. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -2, y: 0},
  33441. {x: -1, y: 0}],
  33442. [{x: -3, y: -1}, {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1},
  33443. {x: 1, y: -1}, {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}]
  33444. ];
  33445. var RefinementTemplates = [
  33446. {
  33447. coding: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  33448. reference: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}, {x: 0, y: 0},
  33449. {x: 1, y: 0}, {x: -1, y: 1}, {x: 0, y: 1}, {x: 1, y: 1}]
  33450. },
  33451. {
  33452. coding: [{x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  33453. reference: [{x: 0, y: -1}, {x: -1, y: 0}, {x: 0, y: 0}, {x: 1, y: 0},
  33454. {x: 0, y: 1}, {x: 1, y: 1}]
  33455. }
  33456. ];
  33457. // See 6.2.5.7 Decoding the bitmap.
  33458. var ReusedContexts = [
  33459. 0x9B25, // 10011 0110010 0101
  33460. 0x0795, // 0011 110010 101
  33461. 0x00E5, // 001 11001 01
  33462. 0x0195 // 011001 0101
  33463. ];
  33464. var RefinementReusedContexts = [
  33465. 0x0020, // '000' + '0' (coding) + '00010000' + '0' (reference)
  33466. 0x0008 // '0000' + '001000'
  33467. ];
  33468. // 6.2 Generic Region Decoding Procedure
  33469. function decodeBitmap(mmr, width, height, templateIndex, prediction, skip, at,
  33470. decodingContext) {
  33471. if (mmr) {
  33472. error('JBIG2 error: MMR encoding is not supported');
  33473. }
  33474. var useskip = !!skip;
  33475. var template = CodingTemplates[templateIndex].concat(at);
  33476. // Sorting is non-standard, and it is not required. But sorting increases
  33477. // the number of template bits that can be reused from the previous
  33478. // contextLabel in the main loop.
  33479. template.sort(function (a, b) {
  33480. return (a.y - b.y) || (a.x - b.x);
  33481. });
  33482. var templateLength = template.length;
  33483. var templateX = new Int8Array(templateLength);
  33484. var templateY = new Int8Array(templateLength);
  33485. var changingTemplateEntries = [];
  33486. var reuseMask = 0, minX = 0, maxX = 0, minY = 0;
  33487. var c, k;
  33488. for (k = 0; k < templateLength; k++) {
  33489. templateX[k] = template[k].x;
  33490. templateY[k] = template[k].y;
  33491. minX = Math.min(minX, template[k].x);
  33492. maxX = Math.max(maxX, template[k].x);
  33493. minY = Math.min(minY, template[k].y);
  33494. // Check if the template pixel appears in two consecutive context labels,
  33495. // so it can be reused. Otherwise, we add it to the list of changing
  33496. // template entries.
  33497. if (k < templateLength - 1 &&
  33498. template[k].y === template[k + 1].y &&
  33499. template[k].x === template[k + 1].x - 1) {
  33500. reuseMask |= 1 << (templateLength - 1 - k);
  33501. } else {
  33502. changingTemplateEntries.push(k);
  33503. }
  33504. }
  33505. var changingEntriesLength = changingTemplateEntries.length;
  33506. var changingTemplateX = new Int8Array(changingEntriesLength);
  33507. var changingTemplateY = new Int8Array(changingEntriesLength);
  33508. var changingTemplateBit = new Uint16Array(changingEntriesLength);
  33509. for (c = 0; c < changingEntriesLength; c++) {
  33510. k = changingTemplateEntries[c];
  33511. changingTemplateX[c] = template[k].x;
  33512. changingTemplateY[c] = template[k].y;
  33513. changingTemplateBit[c] = 1 << (templateLength - 1 - k);
  33514. }
  33515. // Get the safe bounding box edges from the width, height, minX, maxX, minY
  33516. var sbb_left = -minX;
  33517. var sbb_top = -minY;
  33518. var sbb_right = width - maxX;
  33519. var pseudoPixelContext = ReusedContexts[templateIndex];
  33520. var row = new Uint8Array(width);
  33521. var bitmap = [];
  33522. var decoder = decodingContext.decoder;
  33523. var contexts = decodingContext.contextCache.getContexts('GB');
  33524. var ltp = 0, j, i0, j0, contextLabel = 0, bit, shift;
  33525. for (var i = 0; i < height; i++) {
  33526. if (prediction) {
  33527. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  33528. ltp ^= sltp;
  33529. if (ltp) {
  33530. bitmap.push(row); // duplicate previous row
  33531. continue;
  33532. }
  33533. }
  33534. row = new Uint8Array(row);
  33535. bitmap.push(row);
  33536. for (j = 0; j < width; j++) {
  33537. if (useskip && skip[i][j]) {
  33538. row[j] = 0;
  33539. continue;
  33540. }
  33541. // Are we in the middle of a scanline, so we can reuse contextLabel
  33542. // bits?
  33543. if (j >= sbb_left && j < sbb_right && i >= sbb_top) {
  33544. // If yes, we can just shift the bits that are reusable and only
  33545. // fetch the remaining ones.
  33546. contextLabel = (contextLabel << 1) & reuseMask;
  33547. for (k = 0; k < changingEntriesLength; k++) {
  33548. i0 = i + changingTemplateY[k];
  33549. j0 = j + changingTemplateX[k];
  33550. bit = bitmap[i0][j0];
  33551. if (bit) {
  33552. bit = changingTemplateBit[k];
  33553. contextLabel |= bit;
  33554. }
  33555. }
  33556. } else {
  33557. // compute the contextLabel from scratch
  33558. contextLabel = 0;
  33559. shift = templateLength - 1;
  33560. for (k = 0; k < templateLength; k++, shift--) {
  33561. j0 = j + templateX[k];
  33562. if (j0 >= 0 && j0 < width) {
  33563. i0 = i + templateY[k];
  33564. if (i0 >= 0) {
  33565. bit = bitmap[i0][j0];
  33566. if (bit) {
  33567. contextLabel |= bit << shift;
  33568. }
  33569. }
  33570. }
  33571. }
  33572. }
  33573. var pixel = decoder.readBit(contexts, contextLabel);
  33574. row[j] = pixel;
  33575. }
  33576. }
  33577. return bitmap;
  33578. }
  33579. // 6.3.2 Generic Refinement Region Decoding Procedure
  33580. function decodeRefinement(width, height, templateIndex, referenceBitmap,
  33581. offsetX, offsetY, prediction, at,
  33582. decodingContext) {
  33583. var codingTemplate = RefinementTemplates[templateIndex].coding;
  33584. if (templateIndex === 0) {
  33585. codingTemplate = codingTemplate.concat([at[0]]);
  33586. }
  33587. var codingTemplateLength = codingTemplate.length;
  33588. var codingTemplateX = new Int32Array(codingTemplateLength);
  33589. var codingTemplateY = new Int32Array(codingTemplateLength);
  33590. var k;
  33591. for (k = 0; k < codingTemplateLength; k++) {
  33592. codingTemplateX[k] = codingTemplate[k].x;
  33593. codingTemplateY[k] = codingTemplate[k].y;
  33594. }
  33595. var referenceTemplate = RefinementTemplates[templateIndex].reference;
  33596. if (templateIndex === 0) {
  33597. referenceTemplate = referenceTemplate.concat([at[1]]);
  33598. }
  33599. var referenceTemplateLength = referenceTemplate.length;
  33600. var referenceTemplateX = new Int32Array(referenceTemplateLength);
  33601. var referenceTemplateY = new Int32Array(referenceTemplateLength);
  33602. for (k = 0; k < referenceTemplateLength; k++) {
  33603. referenceTemplateX[k] = referenceTemplate[k].x;
  33604. referenceTemplateY[k] = referenceTemplate[k].y;
  33605. }
  33606. var referenceWidth = referenceBitmap[0].length;
  33607. var referenceHeight = referenceBitmap.length;
  33608. var pseudoPixelContext = RefinementReusedContexts[templateIndex];
  33609. var bitmap = [];
  33610. var decoder = decodingContext.decoder;
  33611. var contexts = decodingContext.contextCache.getContexts('GR');
  33612. var ltp = 0;
  33613. for (var i = 0; i < height; i++) {
  33614. if (prediction) {
  33615. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  33616. ltp ^= sltp;
  33617. if (ltp) {
  33618. error('JBIG2 error: prediction is not supported');
  33619. }
  33620. }
  33621. var row = new Uint8Array(width);
  33622. bitmap.push(row);
  33623. for (var j = 0; j < width; j++) {
  33624. var i0, j0;
  33625. var contextLabel = 0;
  33626. for (k = 0; k < codingTemplateLength; k++) {
  33627. i0 = i + codingTemplateY[k];
  33628. j0 = j + codingTemplateX[k];
  33629. if (i0 < 0 || j0 < 0 || j0 >= width) {
  33630. contextLabel <<= 1; // out of bound pixel
  33631. } else {
  33632. contextLabel = (contextLabel << 1) | bitmap[i0][j0];
  33633. }
  33634. }
  33635. for (k = 0; k < referenceTemplateLength; k++) {
  33636. i0 = i + referenceTemplateY[k] + offsetY;
  33637. j0 = j + referenceTemplateX[k] + offsetX;
  33638. if (i0 < 0 || i0 >= referenceHeight || j0 < 0 ||
  33639. j0 >= referenceWidth) {
  33640. contextLabel <<= 1; // out of bound pixel
  33641. } else {
  33642. contextLabel = (contextLabel << 1) | referenceBitmap[i0][j0];
  33643. }
  33644. }
  33645. var pixel = decoder.readBit(contexts, contextLabel);
  33646. row[j] = pixel;
  33647. }
  33648. }
  33649. return bitmap;
  33650. }
  33651. // 6.5.5 Decoding the symbol dictionary
  33652. function decodeSymbolDictionary(huffman, refinement, symbols,
  33653. numberOfNewSymbols, numberOfExportedSymbols,
  33654. huffmanTables, templateIndex, at,
  33655. refinementTemplateIndex, refinementAt,
  33656. decodingContext) {
  33657. if (huffman) {
  33658. error('JBIG2 error: huffman is not supported');
  33659. }
  33660. var newSymbols = [];
  33661. var currentHeight = 0;
  33662. var symbolCodeLength = log2(symbols.length + numberOfNewSymbols);
  33663. var decoder = decodingContext.decoder;
  33664. var contextCache = decodingContext.contextCache;
  33665. while (newSymbols.length < numberOfNewSymbols) {
  33666. var deltaHeight = decodeInteger(contextCache, 'IADH', decoder); // 6.5.6
  33667. currentHeight += deltaHeight;
  33668. var currentWidth = 0;
  33669. var totalWidth = 0;
  33670. while (true) {
  33671. var deltaWidth = decodeInteger(contextCache, 'IADW', decoder); // 6.5.7
  33672. if (deltaWidth === null) {
  33673. break; // OOB
  33674. }
  33675. currentWidth += deltaWidth;
  33676. totalWidth += currentWidth;
  33677. var bitmap;
  33678. if (refinement) {
  33679. // 6.5.8.2 Refinement/aggregate-coded symbol bitmap
  33680. var numberOfInstances = decodeInteger(contextCache, 'IAAI', decoder);
  33681. if (numberOfInstances > 1) {
  33682. bitmap = decodeTextRegion(huffman, refinement,
  33683. currentWidth, currentHeight, 0,
  33684. numberOfInstances, 1, //strip size
  33685. symbols.concat(newSymbols),
  33686. symbolCodeLength,
  33687. 0, //transposed
  33688. 0, //ds offset
  33689. 1, //top left 7.4.3.1.1
  33690. 0, //OR operator
  33691. huffmanTables,
  33692. refinementTemplateIndex, refinementAt,
  33693. decodingContext);
  33694. } else {
  33695. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  33696. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  33697. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  33698. var symbol = (symbolId < symbols.length ? symbols[symbolId] :
  33699. newSymbols[symbolId - symbols.length]);
  33700. bitmap = decodeRefinement(currentWidth, currentHeight,
  33701. refinementTemplateIndex, symbol, rdx, rdy, false, refinementAt,
  33702. decodingContext);
  33703. }
  33704. } else {
  33705. // 6.5.8.1 Direct-coded symbol bitmap
  33706. bitmap = decodeBitmap(false, currentWidth, currentHeight,
  33707. templateIndex, false, null, at, decodingContext);
  33708. }
  33709. newSymbols.push(bitmap);
  33710. }
  33711. }
  33712. // 6.5.10 Exported symbols
  33713. var exportedSymbols = [];
  33714. var flags = [], currentFlag = false;
  33715. var totalSymbolsLength = symbols.length + numberOfNewSymbols;
  33716. while (flags.length < totalSymbolsLength) {
  33717. var runLength = decodeInteger(contextCache, 'IAEX', decoder);
  33718. while (runLength--) {
  33719. flags.push(currentFlag);
  33720. }
  33721. currentFlag = !currentFlag;
  33722. }
  33723. for (var i = 0, ii = symbols.length; i < ii; i++) {
  33724. if (flags[i]) {
  33725. exportedSymbols.push(symbols[i]);
  33726. }
  33727. }
  33728. for (var j = 0; j < numberOfNewSymbols; i++, j++) {
  33729. if (flags[i]) {
  33730. exportedSymbols.push(newSymbols[j]);
  33731. }
  33732. }
  33733. return exportedSymbols;
  33734. }
  33735. function decodeTextRegion(huffman, refinement, width, height,
  33736. defaultPixelValue, numberOfSymbolInstances,
  33737. stripSize, inputSymbols, symbolCodeLength,
  33738. transposed, dsOffset, referenceCorner,
  33739. combinationOperator, huffmanTables,
  33740. refinementTemplateIndex, refinementAt,
  33741. decodingContext) {
  33742. if (huffman) {
  33743. error('JBIG2 error: huffman is not supported');
  33744. }
  33745. // Prepare bitmap
  33746. var bitmap = [];
  33747. var i, row;
  33748. for (i = 0; i < height; i++) {
  33749. row = new Uint8Array(width);
  33750. if (defaultPixelValue) {
  33751. for (var j = 0; j < width; j++) {
  33752. row[j] = defaultPixelValue;
  33753. }
  33754. }
  33755. bitmap.push(row);
  33756. }
  33757. var decoder = decodingContext.decoder;
  33758. var contextCache = decodingContext.contextCache;
  33759. var stripT = -decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  33760. var firstS = 0;
  33761. i = 0;
  33762. while (i < numberOfSymbolInstances) {
  33763. var deltaT = decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  33764. stripT += deltaT;
  33765. var deltaFirstS = decodeInteger(contextCache, 'IAFS', decoder); // 6.4.7
  33766. firstS += deltaFirstS;
  33767. var currentS = firstS;
  33768. do {
  33769. var currentT = (stripSize == 1 ? 0 :
  33770. decodeInteger(contextCache, 'IAIT', decoder)); // 6.4.9
  33771. var t = stripSize * stripT + currentT;
  33772. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  33773. var applyRefinement = (refinement &&
  33774. decodeInteger(contextCache, 'IARI', decoder));
  33775. var symbolBitmap = inputSymbols[symbolId];
  33776. var symbolWidth = symbolBitmap[0].length;
  33777. var symbolHeight = symbolBitmap.length;
  33778. if (applyRefinement) {
  33779. var rdw = decodeInteger(contextCache, 'IARDW', decoder); // 6.4.11.1
  33780. var rdh = decodeInteger(contextCache, 'IARDH', decoder); // 6.4.11.2
  33781. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  33782. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  33783. symbolWidth += rdw;
  33784. symbolHeight += rdh;
  33785. symbolBitmap = decodeRefinement(symbolWidth, symbolHeight,
  33786. refinementTemplateIndex, symbolBitmap, (rdw >> 1) + rdx,
  33787. (rdh >> 1) + rdy, false, refinementAt,
  33788. decodingContext);
  33789. }
  33790. var offsetT = t - ((referenceCorner & 1) ? 0 : symbolHeight);
  33791. var offsetS = currentS - ((referenceCorner & 2) ? symbolWidth : 0);
  33792. var s2, t2, symbolRow;
  33793. if (transposed) {
  33794. // Place Symbol Bitmap from T1,S1
  33795. for (s2 = 0; s2 < symbolHeight; s2++) {
  33796. row = bitmap[offsetS + s2];
  33797. if (!row) {
  33798. continue;
  33799. }
  33800. symbolRow = symbolBitmap[s2];
  33801. // To ignore Parts of Symbol bitmap which goes
  33802. // outside bitmap region
  33803. var maxWidth = Math.min(width - offsetT, symbolWidth);
  33804. switch (combinationOperator) {
  33805. case 0: // OR
  33806. for (t2 = 0; t2 < maxWidth; t2++) {
  33807. row[offsetT + t2] |= symbolRow[t2];
  33808. }
  33809. break;
  33810. case 2: // XOR
  33811. for (t2 = 0; t2 < maxWidth; t2++) {
  33812. row[offsetT + t2] ^= symbolRow[t2];
  33813. }
  33814. break;
  33815. default:
  33816. error('JBIG2 error: operator ' + combinationOperator +
  33817. ' is not supported');
  33818. }
  33819. }
  33820. currentS += symbolHeight - 1;
  33821. } else {
  33822. for (t2 = 0; t2 < symbolHeight; t2++) {
  33823. row = bitmap[offsetT + t2];
  33824. if (!row) {
  33825. continue;
  33826. }
  33827. symbolRow = symbolBitmap[t2];
  33828. switch (combinationOperator) {
  33829. case 0: // OR
  33830. for (s2 = 0; s2 < symbolWidth; s2++) {
  33831. row[offsetS + s2] |= symbolRow[s2];
  33832. }
  33833. break;
  33834. case 2: // XOR
  33835. for (s2 = 0; s2 < symbolWidth; s2++) {
  33836. row[offsetS + s2] ^= symbolRow[s2];
  33837. }
  33838. break;
  33839. default:
  33840. error('JBIG2 error: operator ' + combinationOperator +
  33841. ' is not supported');
  33842. }
  33843. }
  33844. currentS += symbolWidth - 1;
  33845. }
  33846. i++;
  33847. var deltaS = decodeInteger(contextCache, 'IADS', decoder); // 6.4.8
  33848. if (deltaS === null) {
  33849. break; // OOB
  33850. }
  33851. currentS += deltaS + dsOffset;
  33852. } while (true);
  33853. }
  33854. return bitmap;
  33855. }
  33856. function readSegmentHeader(data, start) {
  33857. var segmentHeader = {};
  33858. segmentHeader.number = readUint32(data, start);
  33859. var flags = data[start + 4];
  33860. var segmentType = flags & 0x3F;
  33861. if (!SegmentTypes[segmentType]) {
  33862. error('JBIG2 error: invalid segment type: ' + segmentType);
  33863. }
  33864. segmentHeader.type = segmentType;
  33865. segmentHeader.typeName = SegmentTypes[segmentType];
  33866. segmentHeader.deferredNonRetain = !!(flags & 0x80);
  33867. var pageAssociationFieldSize = !!(flags & 0x40);
  33868. var referredFlags = data[start + 5];
  33869. var referredToCount = (referredFlags >> 5) & 7;
  33870. var retainBits = [referredFlags & 31];
  33871. var position = start + 6;
  33872. if (referredFlags == 7) {
  33873. referredToCount = readUint32(data, position - 1) & 0x1FFFFFFF;
  33874. position += 3;
  33875. var bytes = (referredToCount + 7) >> 3;
  33876. retainBits[0] = data[position++];
  33877. while (--bytes > 0) {
  33878. retainBits.push(data[position++]);
  33879. }
  33880. } else if (referredFlags == 5 || referredFlags == 6) {
  33881. error('JBIG2 error: invalid referred-to flags');
  33882. }
  33883. segmentHeader.retainBits = retainBits;
  33884. var referredToSegmentNumberSize = (segmentHeader.number <= 256 ? 1 :
  33885. (segmentHeader.number <= 65536 ? 2 : 4));
  33886. var referredTo = [];
  33887. var i, ii;
  33888. for (i = 0; i < referredToCount; i++) {
  33889. var number = (referredToSegmentNumberSize == 1 ? data[position] :
  33890. (referredToSegmentNumberSize == 2 ? readUint16(data, position) :
  33891. readUint32(data, position)));
  33892. referredTo.push(number);
  33893. position += referredToSegmentNumberSize;
  33894. }
  33895. segmentHeader.referredTo = referredTo;
  33896. if (!pageAssociationFieldSize) {
  33897. segmentHeader.pageAssociation = data[position++];
  33898. } else {
  33899. segmentHeader.pageAssociation = readUint32(data, position);
  33900. position += 4;
  33901. }
  33902. segmentHeader.length = readUint32(data, position);
  33903. position += 4;
  33904. if (segmentHeader.length == 0xFFFFFFFF) {
  33905. // 7.2.7 Segment data length, unknown segment length
  33906. if (segmentType === 38) { // ImmediateGenericRegion
  33907. var genericRegionInfo = readRegionSegmentInformation(data, position);
  33908. var genericRegionSegmentFlags = data[position +
  33909. RegionSegmentInformationFieldLength];
  33910. var genericRegionMmr = !!(genericRegionSegmentFlags & 1);
  33911. // searching for the segment end
  33912. var searchPatternLength = 6;
  33913. var searchPattern = new Uint8Array(searchPatternLength);
  33914. if (!genericRegionMmr) {
  33915. searchPattern[0] = 0xFF;
  33916. searchPattern[1] = 0xAC;
  33917. }
  33918. searchPattern[2] = (genericRegionInfo.height >>> 24) & 0xFF;
  33919. searchPattern[3] = (genericRegionInfo.height >> 16) & 0xFF;
  33920. searchPattern[4] = (genericRegionInfo.height >> 8) & 0xFF;
  33921. searchPattern[5] = genericRegionInfo.height & 0xFF;
  33922. for (i = position, ii = data.length; i < ii; i++) {
  33923. var j = 0;
  33924. while (j < searchPatternLength && searchPattern[j] === data[i + j]) {
  33925. j++;
  33926. }
  33927. if (j == searchPatternLength) {
  33928. segmentHeader.length = i + searchPatternLength;
  33929. break;
  33930. }
  33931. }
  33932. if (segmentHeader.length == 0xFFFFFFFF) {
  33933. error('JBIG2 error: segment end was not found');
  33934. }
  33935. } else {
  33936. error('JBIG2 error: invalid unknown segment length');
  33937. }
  33938. }
  33939. segmentHeader.headerEnd = position;
  33940. return segmentHeader;
  33941. }
  33942. function readSegments(header, data, start, end) {
  33943. var segments = [];
  33944. var position = start;
  33945. while (position < end) {
  33946. var segmentHeader = readSegmentHeader(data, position);
  33947. position = segmentHeader.headerEnd;
  33948. var segment = {
  33949. header: segmentHeader,
  33950. data: data
  33951. };
  33952. if (!header.randomAccess) {
  33953. segment.start = position;
  33954. position += segmentHeader.length;
  33955. segment.end = position;
  33956. }
  33957. segments.push(segment);
  33958. if (segmentHeader.type == 51) {
  33959. break; // end of file is found
  33960. }
  33961. }
  33962. if (header.randomAccess) {
  33963. for (var i = 0, ii = segments.length; i < ii; i++) {
  33964. segments[i].start = position;
  33965. position += segments[i].header.length;
  33966. segments[i].end = position;
  33967. }
  33968. }
  33969. return segments;
  33970. }
  33971. // 7.4.1 Region segment information field
  33972. function readRegionSegmentInformation(data, start) {
  33973. return {
  33974. width: readUint32(data, start),
  33975. height: readUint32(data, start + 4),
  33976. x: readUint32(data, start + 8),
  33977. y: readUint32(data, start + 12),
  33978. combinationOperator: data[start + 16] & 7
  33979. };
  33980. }
  33981. var RegionSegmentInformationFieldLength = 17;
  33982. function processSegment(segment, visitor) {
  33983. var header = segment.header;
  33984. var data = segment.data, position = segment.start, end = segment.end;
  33985. var args, at, i, atLength;
  33986. switch (header.type) {
  33987. case 0: // SymbolDictionary
  33988. // 7.4.2 Symbol dictionary segment syntax
  33989. var dictionary = {};
  33990. var dictionaryFlags = readUint16(data, position); // 7.4.2.1.1
  33991. dictionary.huffman = !!(dictionaryFlags & 1);
  33992. dictionary.refinement = !!(dictionaryFlags & 2);
  33993. dictionary.huffmanDHSelector = (dictionaryFlags >> 2) & 3;
  33994. dictionary.huffmanDWSelector = (dictionaryFlags >> 4) & 3;
  33995. dictionary.bitmapSizeSelector = (dictionaryFlags >> 6) & 1;
  33996. dictionary.aggregationInstancesSelector = (dictionaryFlags >> 7) & 1;
  33997. dictionary.bitmapCodingContextUsed = !!(dictionaryFlags & 256);
  33998. dictionary.bitmapCodingContextRetained = !!(dictionaryFlags & 512);
  33999. dictionary.template = (dictionaryFlags >> 10) & 3;
  34000. dictionary.refinementTemplate = (dictionaryFlags >> 12) & 1;
  34001. position += 2;
  34002. if (!dictionary.huffman) {
  34003. atLength = dictionary.template === 0 ? 4 : 1;
  34004. at = [];
  34005. for (i = 0; i < atLength; i++) {
  34006. at.push({
  34007. x: readInt8(data, position),
  34008. y: readInt8(data, position + 1)
  34009. });
  34010. position += 2;
  34011. }
  34012. dictionary.at = at;
  34013. }
  34014. if (dictionary.refinement && !dictionary.refinementTemplate) {
  34015. at = [];
  34016. for (i = 0; i < 2; i++) {
  34017. at.push({
  34018. x: readInt8(data, position),
  34019. y: readInt8(data, position + 1)
  34020. });
  34021. position += 2;
  34022. }
  34023. dictionary.refinementAt = at;
  34024. }
  34025. dictionary.numberOfExportedSymbols = readUint32(data, position);
  34026. position += 4;
  34027. dictionary.numberOfNewSymbols = readUint32(data, position);
  34028. position += 4;
  34029. args = [dictionary, header.number, header.referredTo,
  34030. data, position, end];
  34031. break;
  34032. case 6: // ImmediateTextRegion
  34033. case 7: // ImmediateLosslessTextRegion
  34034. var textRegion = {};
  34035. textRegion.info = readRegionSegmentInformation(data, position);
  34036. position += RegionSegmentInformationFieldLength;
  34037. var textRegionSegmentFlags = readUint16(data, position);
  34038. position += 2;
  34039. textRegion.huffman = !!(textRegionSegmentFlags & 1);
  34040. textRegion.refinement = !!(textRegionSegmentFlags & 2);
  34041. textRegion.stripSize = 1 << ((textRegionSegmentFlags >> 2) & 3);
  34042. textRegion.referenceCorner = (textRegionSegmentFlags >> 4) & 3;
  34043. textRegion.transposed = !!(textRegionSegmentFlags & 64);
  34044. textRegion.combinationOperator = (textRegionSegmentFlags >> 7) & 3;
  34045. textRegion.defaultPixelValue = (textRegionSegmentFlags >> 9) & 1;
  34046. textRegion.dsOffset = (textRegionSegmentFlags << 17) >> 27;
  34047. textRegion.refinementTemplate = (textRegionSegmentFlags >> 15) & 1;
  34048. if (textRegion.huffman) {
  34049. var textRegionHuffmanFlags = readUint16(data, position);
  34050. position += 2;
  34051. textRegion.huffmanFS = (textRegionHuffmanFlags) & 3;
  34052. textRegion.huffmanDS = (textRegionHuffmanFlags >> 2) & 3;
  34053. textRegion.huffmanDT = (textRegionHuffmanFlags >> 4) & 3;
  34054. textRegion.huffmanRefinementDW = (textRegionHuffmanFlags >> 6) & 3;
  34055. textRegion.huffmanRefinementDH = (textRegionHuffmanFlags >> 8) & 3;
  34056. textRegion.huffmanRefinementDX = (textRegionHuffmanFlags >> 10) & 3;
  34057. textRegion.huffmanRefinementDY = (textRegionHuffmanFlags >> 12) & 3;
  34058. textRegion.huffmanRefinementSizeSelector =
  34059. !!(textRegionHuffmanFlags & 14);
  34060. }
  34061. if (textRegion.refinement && !textRegion.refinementTemplate) {
  34062. at = [];
  34063. for (i = 0; i < 2; i++) {
  34064. at.push({
  34065. x: readInt8(data, position),
  34066. y: readInt8(data, position + 1)
  34067. });
  34068. position += 2;
  34069. }
  34070. textRegion.refinementAt = at;
  34071. }
  34072. textRegion.numberOfSymbolInstances = readUint32(data, position);
  34073. position += 4;
  34074. // TODO 7.4.3.1.7 Symbol ID Huffman table decoding
  34075. if (textRegion.huffman) {
  34076. error('JBIG2 error: huffman is not supported');
  34077. }
  34078. args = [textRegion, header.referredTo, data, position, end];
  34079. break;
  34080. case 38: // ImmediateGenericRegion
  34081. case 39: // ImmediateLosslessGenericRegion
  34082. var genericRegion = {};
  34083. genericRegion.info = readRegionSegmentInformation(data, position);
  34084. position += RegionSegmentInformationFieldLength;
  34085. var genericRegionSegmentFlags = data[position++];
  34086. genericRegion.mmr = !!(genericRegionSegmentFlags & 1);
  34087. genericRegion.template = (genericRegionSegmentFlags >> 1) & 3;
  34088. genericRegion.prediction = !!(genericRegionSegmentFlags & 8);
  34089. if (!genericRegion.mmr) {
  34090. atLength = genericRegion.template === 0 ? 4 : 1;
  34091. at = [];
  34092. for (i = 0; i < atLength; i++) {
  34093. at.push({
  34094. x: readInt8(data, position),
  34095. y: readInt8(data, position + 1)
  34096. });
  34097. position += 2;
  34098. }
  34099. genericRegion.at = at;
  34100. }
  34101. args = [genericRegion, data, position, end];
  34102. break;
  34103. case 48: // PageInformation
  34104. var pageInfo = {
  34105. width: readUint32(data, position),
  34106. height: readUint32(data, position + 4),
  34107. resolutionX: readUint32(data, position + 8),
  34108. resolutionY: readUint32(data, position + 12)
  34109. };
  34110. if (pageInfo.height == 0xFFFFFFFF) {
  34111. delete pageInfo.height;
  34112. }
  34113. var pageSegmentFlags = data[position + 16];
  34114. var pageStripingInformatiom = readUint16(data, position + 17);
  34115. pageInfo.lossless = !!(pageSegmentFlags & 1);
  34116. pageInfo.refinement = !!(pageSegmentFlags & 2);
  34117. pageInfo.defaultPixelValue = (pageSegmentFlags >> 2) & 1;
  34118. pageInfo.combinationOperator = (pageSegmentFlags >> 3) & 3;
  34119. pageInfo.requiresBuffer = !!(pageSegmentFlags & 32);
  34120. pageInfo.combinationOperatorOverride = !!(pageSegmentFlags & 64);
  34121. args = [pageInfo];
  34122. break;
  34123. case 49: // EndOfPage
  34124. break;
  34125. case 50: // EndOfStripe
  34126. break;
  34127. case 51: // EndOfFile
  34128. break;
  34129. case 62: // 7.4.15 defines 2 extension types which
  34130. // are comments and can be ignored.
  34131. break;
  34132. default:
  34133. error('JBIG2 error: segment type ' + header.typeName + '(' +
  34134. header.type + ') is not implemented');
  34135. }
  34136. var callbackName = 'on' + header.typeName;
  34137. if (callbackName in visitor) {
  34138. visitor[callbackName].apply(visitor, args);
  34139. }
  34140. }
  34141. function processSegments(segments, visitor) {
  34142. for (var i = 0, ii = segments.length; i < ii; i++) {
  34143. processSegment(segments[i], visitor);
  34144. }
  34145. }
  34146. function parseJbig2(data, start, end) {
  34147. var position = start;
  34148. if (data[position] != 0x97 || data[position + 1] != 0x4A ||
  34149. data[position + 2] != 0x42 || data[position + 3] != 0x32 ||
  34150. data[position + 4] != 0x0D || data[position + 5] != 0x0A ||
  34151. data[position + 6] != 0x1A || data[position + 7] != 0x0A) {
  34152. error('JBIG2 error: invalid header');
  34153. }
  34154. var header = {};
  34155. position += 8;
  34156. var flags = data[position++];
  34157. header.randomAccess = !(flags & 1);
  34158. if (!(flags & 2)) {
  34159. header.numberOfPages = readUint32(data, position);
  34160. position += 4;
  34161. }
  34162. var segments = readSegments(header, data, position, end);
  34163. error('Not implemented');
  34164. // processSegments(segments, new SimpleSegmentVisitor());
  34165. }
  34166. function parseJbig2Chunks(chunks) {
  34167. var visitor = new SimpleSegmentVisitor();
  34168. for (var i = 0, ii = chunks.length; i < ii; i++) {
  34169. var chunk = chunks[i];
  34170. var segments = readSegments({}, chunk.data, chunk.start, chunk.end);
  34171. processSegments(segments, visitor);
  34172. }
  34173. return visitor.buffer;
  34174. }
  34175. function SimpleSegmentVisitor() {}
  34176. SimpleSegmentVisitor.prototype = {
  34177. onPageInformation: function SimpleSegmentVisitor_onPageInformation(info) {
  34178. this.currentPageInfo = info;
  34179. var rowSize = (info.width + 7) >> 3;
  34180. var buffer = new Uint8Array(rowSize * info.height);
  34181. // The contents of ArrayBuffers are initialized to 0.
  34182. // Fill the buffer with 0xFF only if info.defaultPixelValue is set
  34183. if (info.defaultPixelValue) {
  34184. for (var i = 0, ii = buffer.length; i < ii; i++) {
  34185. buffer[i] = 0xFF;
  34186. }
  34187. }
  34188. this.buffer = buffer;
  34189. },
  34190. drawBitmap: function SimpleSegmentVisitor_drawBitmap(regionInfo, bitmap) {
  34191. var pageInfo = this.currentPageInfo;
  34192. var width = regionInfo.width, height = regionInfo.height;
  34193. var rowSize = (pageInfo.width + 7) >> 3;
  34194. var combinationOperator = pageInfo.combinationOperatorOverride ?
  34195. regionInfo.combinationOperator : pageInfo.combinationOperator;
  34196. var buffer = this.buffer;
  34197. var mask0 = 128 >> (regionInfo.x & 7);
  34198. var offset0 = regionInfo.y * rowSize + (regionInfo.x >> 3);
  34199. var i, j, mask, offset;
  34200. switch (combinationOperator) {
  34201. case 0: // OR
  34202. for (i = 0; i < height; i++) {
  34203. mask = mask0;
  34204. offset = offset0;
  34205. for (j = 0; j < width; j++) {
  34206. if (bitmap[i][j]) {
  34207. buffer[offset] |= mask;
  34208. }
  34209. mask >>= 1;
  34210. if (!mask) {
  34211. mask = 128;
  34212. offset++;
  34213. }
  34214. }
  34215. offset0 += rowSize;
  34216. }
  34217. break;
  34218. case 2: // XOR
  34219. for (i = 0; i < height; i++) {
  34220. mask = mask0;
  34221. offset = offset0;
  34222. for (j = 0; j < width; j++) {
  34223. if (bitmap[i][j]) {
  34224. buffer[offset] ^= mask;
  34225. }
  34226. mask >>= 1;
  34227. if (!mask) {
  34228. mask = 128;
  34229. offset++;
  34230. }
  34231. }
  34232. offset0 += rowSize;
  34233. }
  34234. break;
  34235. default:
  34236. error('JBIG2 error: operator ' + combinationOperator +
  34237. ' is not supported');
  34238. }
  34239. },
  34240. onImmediateGenericRegion:
  34241. function SimpleSegmentVisitor_onImmediateGenericRegion(region, data,
  34242. start, end) {
  34243. var regionInfo = region.info;
  34244. var decodingContext = new DecodingContext(data, start, end);
  34245. var bitmap = decodeBitmap(region.mmr, regionInfo.width, regionInfo.height,
  34246. region.template, region.prediction, null,
  34247. region.at, decodingContext);
  34248. this.drawBitmap(regionInfo, bitmap);
  34249. },
  34250. onImmediateLosslessGenericRegion:
  34251. function SimpleSegmentVisitor_onImmediateLosslessGenericRegion() {
  34252. this.onImmediateGenericRegion.apply(this, arguments);
  34253. },
  34254. onSymbolDictionary:
  34255. function SimpleSegmentVisitor_onSymbolDictionary(dictionary,
  34256. currentSegment,
  34257. referredSegments,
  34258. data, start, end) {
  34259. var huffmanTables;
  34260. if (dictionary.huffman) {
  34261. error('JBIG2 error: huffman is not supported');
  34262. }
  34263. // Combines exported symbols from all referred segments
  34264. var symbols = this.symbols;
  34265. if (!symbols) {
  34266. this.symbols = symbols = {};
  34267. }
  34268. var inputSymbols = [];
  34269. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  34270. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  34271. }
  34272. var decodingContext = new DecodingContext(data, start, end);
  34273. symbols[currentSegment] = decodeSymbolDictionary(dictionary.huffman,
  34274. dictionary.refinement, inputSymbols, dictionary.numberOfNewSymbols,
  34275. dictionary.numberOfExportedSymbols, huffmanTables,
  34276. dictionary.template, dictionary.at,
  34277. dictionary.refinementTemplate, dictionary.refinementAt,
  34278. decodingContext);
  34279. },
  34280. onImmediateTextRegion:
  34281. function SimpleSegmentVisitor_onImmediateTextRegion(region,
  34282. referredSegments,
  34283. data, start, end) {
  34284. var regionInfo = region.info;
  34285. var huffmanTables;
  34286. // Combines exported symbols from all referred segments
  34287. var symbols = this.symbols;
  34288. var inputSymbols = [];
  34289. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  34290. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  34291. }
  34292. var symbolCodeLength = log2(inputSymbols.length);
  34293. var decodingContext = new DecodingContext(data, start, end);
  34294. var bitmap = decodeTextRegion(region.huffman, region.refinement,
  34295. regionInfo.width, regionInfo.height, region.defaultPixelValue,
  34296. region.numberOfSymbolInstances, region.stripSize, inputSymbols,
  34297. symbolCodeLength, region.transposed, region.dsOffset,
  34298. region.referenceCorner, region.combinationOperator, huffmanTables,
  34299. region.refinementTemplate, region.refinementAt, decodingContext);
  34300. this.drawBitmap(regionInfo, bitmap);
  34301. },
  34302. onImmediateLosslessTextRegion:
  34303. function SimpleSegmentVisitor_onImmediateLosslessTextRegion() {
  34304. this.onImmediateTextRegion.apply(this, arguments);
  34305. }
  34306. };
  34307. function Jbig2Image() {}
  34308. Jbig2Image.prototype = {
  34309. parseChunks: function Jbig2Image_parseChunks(chunks) {
  34310. return parseJbig2Chunks(chunks);
  34311. }
  34312. };
  34313. return Jbig2Image;
  34314. })();
  34315. var bidi = PDFJS.bidi = (function bidiClosure() {
  34316. // Character types for symbols from 0000 to 00FF.
  34317. var baseTypes = [
  34318. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'S', 'B', 'S', 'WS',
  34319. 'B', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  34320. 'BN', 'BN', 'B', 'B', 'B', 'S', 'WS', 'ON', 'ON', 'ET', 'ET', 'ET', 'ON',
  34321. 'ON', 'ON', 'ON', 'ON', 'ON', 'CS', 'ON', 'CS', 'ON', 'EN', 'EN', 'EN',
  34322. 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'ON', 'ON', 'ON', 'ON', 'ON',
  34323. 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  34324. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'ON', 'ON',
  34325. 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  34326. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  34327. 'L', 'ON', 'ON', 'ON', 'ON', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'B', 'BN',
  34328. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  34329. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  34330. 'BN', 'CS', 'ON', 'ET', 'ET', 'ET', 'ET', 'ON', 'ON', 'ON', 'ON', 'L', 'ON',
  34331. 'ON', 'ON', 'ON', 'ON', 'ET', 'ET', 'EN', 'EN', 'ON', 'L', 'ON', 'ON', 'ON',
  34332. 'EN', 'L', 'ON', 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  34333. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  34334. 'L', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  34335. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  34336. 'L', 'L', 'L', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L'
  34337. ];
  34338. // Character types for symbols from 0600 to 06FF
  34339. var arabicTypes = [
  34340. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  34341. 'CS', 'AL', 'ON', 'ON', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL',
  34342. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  34343. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  34344. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  34345. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  34346. 'AL', 'AL', 'AL', 'AL', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM',
  34347. 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'AL', 'AL',
  34348. 'AL', 'AL', 'AL', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN',
  34349. 'AN', 'ET', 'AN', 'AN', 'AL', 'AL', 'AL', 'NSM', 'AL', 'AL', 'AL', 'AL',
  34350. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  34351. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  34352. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  34353. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  34354. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  34355. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  34356. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  34357. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  34358. 'AL', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM',
  34359. 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'ON', 'NSM',
  34360. 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  34361. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL'
  34362. ];
  34363. function isOdd(i) {
  34364. return (i & 1) !== 0;
  34365. }
  34366. function isEven(i) {
  34367. return (i & 1) === 0;
  34368. }
  34369. function findUnequal(arr, start, value) {
  34370. for (var j = start, jj = arr.length; j < jj; ++j) {
  34371. if (arr[j] != value) {
  34372. return j;
  34373. }
  34374. }
  34375. return j;
  34376. }
  34377. function setValues(arr, start, end, value) {
  34378. for (var j = start; j < end; ++j) {
  34379. arr[j] = value;
  34380. }
  34381. }
  34382. function reverseValues(arr, start, end) {
  34383. for (var i = start, j = end - 1; i < j; ++i, --j) {
  34384. var temp = arr[i];
  34385. arr[i] = arr[j];
  34386. arr[j] = temp;
  34387. }
  34388. }
  34389. function createBidiText(str, isLTR, vertical) {
  34390. return {
  34391. str: str,
  34392. dir: (vertical ? 'ttb' : (isLTR ? 'ltr' : 'rtl'))
  34393. };
  34394. }
  34395. // These are used in bidi(), which is called frequently. We re-use them on
  34396. // each call to avoid unnecessary allocations.
  34397. var chars = [];
  34398. var types = [];
  34399. function bidi(str, startLevel, vertical) {
  34400. var isLTR = true;
  34401. var strLength = str.length;
  34402. if (strLength === 0 || vertical) {
  34403. return createBidiText(str, isLTR, vertical);
  34404. }
  34405. // Get types and fill arrays
  34406. chars.length = strLength;
  34407. types.length = strLength;
  34408. var numBidi = 0;
  34409. var i, ii;
  34410. for (i = 0; i < strLength; ++i) {
  34411. chars[i] = str.charAt(i);
  34412. var charCode = str.charCodeAt(i);
  34413. var charType = 'L';
  34414. if (charCode <= 0x00ff) {
  34415. charType = baseTypes[charCode];
  34416. } else if (0x0590 <= charCode && charCode <= 0x05f4) {
  34417. charType = 'R';
  34418. } else if (0x0600 <= charCode && charCode <= 0x06ff) {
  34419. charType = arabicTypes[charCode & 0xff];
  34420. } else if (0x0700 <= charCode && charCode <= 0x08AC) {
  34421. charType = 'AL';
  34422. }
  34423. if (charType == 'R' || charType == 'AL' || charType == 'AN') {
  34424. numBidi++;
  34425. }
  34426. types[i] = charType;
  34427. }
  34428. // Detect the bidi method
  34429. // - If there are no rtl characters then no bidi needed
  34430. // - If less than 30% chars are rtl then string is primarily ltr
  34431. // - If more than 30% chars are rtl then string is primarily rtl
  34432. if (numBidi === 0) {
  34433. isLTR = true;
  34434. return createBidiText(str, isLTR);
  34435. }
  34436. if (startLevel == -1) {
  34437. if ((strLength / numBidi) < 0.3) {
  34438. isLTR = true;
  34439. startLevel = 0;
  34440. } else {
  34441. isLTR = false;
  34442. startLevel = 1;
  34443. }
  34444. }
  34445. var levels = [];
  34446. for (i = 0; i < strLength; ++i) {
  34447. levels[i] = startLevel;
  34448. }
  34449. /*
  34450. X1-X10: skip most of this, since we are NOT doing the embeddings.
  34451. */
  34452. var e = (isOdd(startLevel) ? 'R' : 'L');
  34453. var sor = e;
  34454. var eor = sor;
  34455. /*
  34456. W1. Examine each non-spacing mark (NSM) in the level run, and change the
  34457. type of the NSM to the type of the previous character. If the NSM is at the
  34458. start of the level run, it will get the type of sor.
  34459. */
  34460. var lastType = sor;
  34461. for (i = 0; i < strLength; ++i) {
  34462. if (types[i] == 'NSM') {
  34463. types[i] = lastType;
  34464. } else {
  34465. lastType = types[i];
  34466. }
  34467. }
  34468. /*
  34469. W2. Search backwards from each instance of a European number until the
  34470. first strong type (R, L, AL, or sor) is found. If an AL is found, change
  34471. the type of the European number to Arabic number.
  34472. */
  34473. lastType = sor;
  34474. var t;
  34475. for (i = 0; i < strLength; ++i) {
  34476. t = types[i];
  34477. if (t == 'EN') {
  34478. types[i] = (lastType == 'AL') ? 'AN' : 'EN';
  34479. } else if (t == 'R' || t == 'L' || t == 'AL') {
  34480. lastType = t;
  34481. }
  34482. }
  34483. /*
  34484. W3. Change all ALs to R.
  34485. */
  34486. for (i = 0; i < strLength; ++i) {
  34487. t = types[i];
  34488. if (t == 'AL') {
  34489. types[i] = 'R';
  34490. }
  34491. }
  34492. /*
  34493. W4. A single European separator between two European numbers changes to a
  34494. European number. A single common separator between two numbers of the same
  34495. type changes to that type:
  34496. */
  34497. for (i = 1; i < strLength - 1; ++i) {
  34498. if (types[i] == 'ES' && types[i - 1] == 'EN' && types[i + 1] == 'EN') {
  34499. types[i] = 'EN';
  34500. }
  34501. if (types[i] == 'CS' && (types[i - 1] == 'EN' || types[i - 1] == 'AN') &&
  34502. types[i + 1] == types[i - 1]) {
  34503. types[i] = types[i - 1];
  34504. }
  34505. }
  34506. /*
  34507. W5. A sequence of European terminators adjacent to European numbers changes
  34508. to all European numbers:
  34509. */
  34510. for (i = 0; i < strLength; ++i) {
  34511. if (types[i] == 'EN') {
  34512. // do before
  34513. var j;
  34514. for (j = i - 1; j >= 0; --j) {
  34515. if (types[j] != 'ET') {
  34516. break;
  34517. }
  34518. types[j] = 'EN';
  34519. }
  34520. // do after
  34521. for (j = i + 1; j < strLength; --j) {
  34522. if (types[j] != 'ET') {
  34523. break;
  34524. }
  34525. types[j] = 'EN';
  34526. }
  34527. }
  34528. }
  34529. /*
  34530. W6. Otherwise, separators and terminators change to Other Neutral:
  34531. */
  34532. for (i = 0; i < strLength; ++i) {
  34533. t = types[i];
  34534. if (t == 'WS' || t == 'ES' || t == 'ET' || t == 'CS') {
  34535. types[i] = 'ON';
  34536. }
  34537. }
  34538. /*
  34539. W7. Search backwards from each instance of a European number until the
  34540. first strong type (R, L, or sor) is found. If an L is found, then change
  34541. the type of the European number to L.
  34542. */
  34543. lastType = sor;
  34544. for (i = 0; i < strLength; ++i) {
  34545. t = types[i];
  34546. if (t == 'EN') {
  34547. types[i] = ((lastType == 'L') ? 'L' : 'EN');
  34548. } else if (t == 'R' || t == 'L') {
  34549. lastType = t;
  34550. }
  34551. }
  34552. /*
  34553. N1. A sequence of neutrals takes the direction of the surrounding strong
  34554. text if the text on both sides has the same direction. European and Arabic
  34555. numbers are treated as though they were R. Start-of-level-run (sor) and
  34556. end-of-level-run (eor) are used at level run boundaries.
  34557. */
  34558. for (i = 0; i < strLength; ++i) {
  34559. if (types[i] == 'ON') {
  34560. var end = findUnequal(types, i + 1, 'ON');
  34561. var before = sor;
  34562. if (i > 0) {
  34563. before = types[i - 1];
  34564. }
  34565. var after = eor;
  34566. if (end + 1 < strLength) {
  34567. after = types[end + 1];
  34568. }
  34569. if (before != 'L') {
  34570. before = 'R';
  34571. }
  34572. if (after != 'L') {
  34573. after = 'R';
  34574. }
  34575. if (before == after) {
  34576. setValues(types, i, end, before);
  34577. }
  34578. i = end - 1; // reset to end (-1 so next iteration is ok)
  34579. }
  34580. }
  34581. /*
  34582. N2. Any remaining neutrals take the embedding direction.
  34583. */
  34584. for (i = 0; i < strLength; ++i) {
  34585. if (types[i] == 'ON') {
  34586. types[i] = e;
  34587. }
  34588. }
  34589. /*
  34590. I1. For all characters with an even (left-to-right) embedding direction,
  34591. those of type R go up one level and those of type AN or EN go up two
  34592. levels.
  34593. I2. For all characters with an odd (right-to-left) embedding direction,
  34594. those of type L, EN or AN go up one level.
  34595. */
  34596. for (i = 0; i < strLength; ++i) {
  34597. t = types[i];
  34598. if (isEven(levels[i])) {
  34599. if (t == 'R') {
  34600. levels[i] += 1;
  34601. } else if (t == 'AN' || t == 'EN') {
  34602. levels[i] += 2;
  34603. }
  34604. } else { // isOdd
  34605. if (t == 'L' || t == 'AN' || t == 'EN') {
  34606. levels[i] += 1;
  34607. }
  34608. }
  34609. }
  34610. /*
  34611. L1. On each line, reset the embedding level of the following characters to
  34612. the paragraph embedding level:
  34613. segment separators,
  34614. paragraph separators,
  34615. any sequence of whitespace characters preceding a segment separator or
  34616. paragraph separator, and any sequence of white space characters at the end
  34617. of the line.
  34618. */
  34619. // don't bother as text is only single line
  34620. /*
  34621. L2. From the highest level found in the text to the lowest odd level on
  34622. each line, reverse any contiguous sequence of characters that are at that
  34623. level or higher.
  34624. */
  34625. // find highest level & lowest odd level
  34626. var highestLevel = -1;
  34627. var lowestOddLevel = 99;
  34628. var level;
  34629. for (i = 0, ii = levels.length; i < ii; ++i) {
  34630. level = levels[i];
  34631. if (highestLevel < level) {
  34632. highestLevel = level;
  34633. }
  34634. if (lowestOddLevel > level && isOdd(level)) {
  34635. lowestOddLevel = level;
  34636. }
  34637. }
  34638. // now reverse between those limits
  34639. for (level = highestLevel; level >= lowestOddLevel; --level) {
  34640. // find segments to reverse
  34641. var start = -1;
  34642. for (i = 0, ii = levels.length; i < ii; ++i) {
  34643. if (levels[i] < level) {
  34644. if (start >= 0) {
  34645. reverseValues(chars, start, i);
  34646. start = -1;
  34647. }
  34648. } else if (start < 0) {
  34649. start = i;
  34650. }
  34651. }
  34652. if (start >= 0) {
  34653. reverseValues(chars, start, levels.length);
  34654. }
  34655. }
  34656. /*
  34657. L3. Combining marks applied to a right-to-left base character will at this
  34658. point precede their base character. If the rendering engine expects them to
  34659. follow the base characters in the final display process, then the ordering
  34660. of the marks and the base character must be reversed.
  34661. */
  34662. // don't bother for now
  34663. /*
  34664. L4. A character that possesses the mirrored property as specified by
  34665. Section 4.7, Mirrored, must be depicted by a mirrored glyph if the resolved
  34666. directionality of that character is R.
  34667. */
  34668. // don't mirror as characters are already mirrored in the pdf
  34669. // Finally, return string
  34670. var result = '';
  34671. for (i = 0, ii = chars.length; i < ii; ++i) {
  34672. var ch = chars[i];
  34673. if (ch != '<' && ch != '>') {
  34674. result += ch;
  34675. }
  34676. }
  34677. return createBidiText(result, isLTR);
  34678. }
  34679. return bidi;
  34680. })();
  34681. /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  34682. /* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
  34683. /* Copyright 2014 Opera Software ASA
  34684. *
  34685. * Licensed under the Apache License, Version 2.0 (the "License");
  34686. * you may not use this file except in compliance with the License.
  34687. * You may obtain a copy of the License at
  34688. *
  34689. * http://www.apache.org/licenses/LICENSE-2.0
  34690. *
  34691. * Unless required by applicable law or agreed to in writing, software
  34692. * distributed under the License is distributed on an "AS IS" BASIS,
  34693. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  34694. * See the License for the specific language governing permissions and
  34695. * limitations under the License.
  34696. *
  34697. *
  34698. * Based on https://code.google.com/p/smhasher/wiki/MurmurHash3.
  34699. * Hashes roughly 100 KB per millisecond on i7 3.4 GHz.
  34700. */
  34701. /* globals Uint32ArrayView */
  34702. 'use strict';
  34703. var MurmurHash3_64 = (function MurmurHash3_64Closure (seed) {
  34704. // Workaround for missing math precison in JS.
  34705. var MASK_HIGH = 0xffff0000;
  34706. var MASK_LOW = 0xffff;
  34707. function MurmurHash3_64 (seed) {
  34708. var SEED = 0xc3d2e1f0;
  34709. this.h1 = seed ? seed & 0xffffffff : SEED;
  34710. this.h2 = seed ? seed & 0xffffffff : SEED;
  34711. }
  34712. var alwaysUseUint32ArrayView = false;
  34713. // old webkits have issues with non-aligned arrays
  34714. try {
  34715. new Uint32Array(new Uint8Array(5).buffer, 0, 1);
  34716. } catch (e) {
  34717. alwaysUseUint32ArrayView = true;
  34718. }
  34719. MurmurHash3_64.prototype = {
  34720. update: function MurmurHash3_64_update(input) {
  34721. var useUint32ArrayView = alwaysUseUint32ArrayView;
  34722. var i;
  34723. if (typeof input == 'string') {
  34724. var data = new Uint8Array(input.length * 2);
  34725. var length = 0;
  34726. for (i = 0; i < input.length; i++) {
  34727. var code = input.charCodeAt(i);
  34728. if (code <= 0xff) {
  34729. data[length++] = code;
  34730. }
  34731. else {
  34732. data[length++] = code >>> 8;
  34733. data[length++] = code & 0xff;
  34734. }
  34735. }
  34736. } else if (input instanceof Uint8Array) {
  34737. data = input;
  34738. length = data.length;
  34739. } else if (typeof input === 'object' && ('length' in input)) {
  34740. // processing regular arrays as well, e.g. for IE9
  34741. data = input;
  34742. length = data.length;
  34743. useUint32ArrayView = true;
  34744. } else {
  34745. throw new Error('Wrong data format in MurmurHash3_64_update. ' +
  34746. 'Input must be a string or array.');
  34747. }
  34748. var blockCounts = length >> 2;
  34749. var tailLength = length - blockCounts * 4;
  34750. // we don't care about endianness here
  34751. var dataUint32 = useUint32ArrayView ?
  34752. new Uint32ArrayView(data, blockCounts) :
  34753. new Uint32Array(data.buffer, 0, blockCounts);
  34754. var k1 = 0;
  34755. var k2 = 0;
  34756. var h1 = this.h1;
  34757. var h2 = this.h2;
  34758. var C1 = 0xcc9e2d51;
  34759. var C2 = 0x1b873593;
  34760. var C1_LOW = C1 & MASK_LOW;
  34761. var C2_LOW = C2 & MASK_LOW;
  34762. for (i = 0; i < blockCounts; i++) {
  34763. if (i & 1) {
  34764. k1 = dataUint32[i];
  34765. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  34766. k1 = k1 << 15 | k1 >>> 17;
  34767. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  34768. h1 ^= k1;
  34769. h1 = h1 << 13 | h1 >>> 19;
  34770. h1 = h1 * 5 + 0xe6546b64;
  34771. } else {
  34772. k2 = dataUint32[i];
  34773. k2 = (k2 * C1 & MASK_HIGH) | (k2 * C1_LOW & MASK_LOW);
  34774. k2 = k2 << 15 | k2 >>> 17;
  34775. k2 = (k2 * C2 & MASK_HIGH) | (k2 * C2_LOW & MASK_LOW);
  34776. h2 ^= k2;
  34777. h2 = h2 << 13 | h2 >>> 19;
  34778. h2 = h2 * 5 + 0xe6546b64;
  34779. }
  34780. }
  34781. k1 = 0;
  34782. switch (tailLength) {
  34783. case 3:
  34784. k1 ^= data[blockCounts * 4 + 2] << 16;
  34785. /* falls through */
  34786. case 2:
  34787. k1 ^= data[blockCounts * 4 + 1] << 8;
  34788. /* falls through */
  34789. case 1:
  34790. k1 ^= data[blockCounts * 4];
  34791. /* falls through */
  34792. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  34793. k1 = k1 << 15 | k1 >>> 17;
  34794. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  34795. if (blockCounts & 1) {
  34796. h1 ^= k1;
  34797. } else {
  34798. h2 ^= k1;
  34799. }
  34800. }
  34801. this.h1 = h1;
  34802. this.h2 = h2;
  34803. return this;
  34804. },
  34805. hexdigest: function MurmurHash3_64_hexdigest () {
  34806. var h1 = this.h1;
  34807. var h2 = this.h2;
  34808. h1 ^= h2 >>> 1;
  34809. h1 = (h1 * 0xed558ccd & MASK_HIGH) | (h1 * 0x8ccd & MASK_LOW);
  34810. h2 = (h2 * 0xff51afd7 & MASK_HIGH) |
  34811. (((h2 << 16 | h1 >>> 16) * 0xafd7ed55 & MASK_HIGH) >>> 16);
  34812. h1 ^= h2 >>> 1;
  34813. h1 = (h1 * 0x1a85ec53 & MASK_HIGH) | (h1 * 0xec53 & MASK_LOW);
  34814. h2 = (h2 * 0xc4ceb9fe & MASK_HIGH) |
  34815. (((h2 << 16 | h1 >>> 16) * 0xb9fe1a85 & MASK_HIGH) >>> 16);
  34816. h1 ^= h2 >>> 1;
  34817. for (var i = 0, arr = [h1, h2], str = ''; i < arr.length; i++) {
  34818. var hex = (arr[i] >>> 0).toString(16);
  34819. while (hex.length < 8) {
  34820. hex = '0' + hex;
  34821. }
  34822. str += hex;
  34823. }
  34824. return str;
  34825. }
  34826. };
  34827. return MurmurHash3_64;
  34828. })();
  34829. }).call((typeof window === 'undefined') ? this : window);
  34830. if (!PDFJS.workerSrc && typeof document !== 'undefined') {
  34831. // workerSrc is not set -- using last script url to define default location
  34832. PDFJS.workerSrc = (function () {
  34833. 'use strict';
  34834. var scriptTagContainer = document.body ||
  34835. document.getElementsByTagName('head')[0];
  34836. var pdfjsSrc = scriptTagContainer.lastChild.src;
  34837. return pdfjsSrc && pdfjsSrc.replace(/\.js$/i, '.worker.js');
  34838. })();
  34839. }