pdf.worker.js 1.3 MB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385213862138721388213892139021391213922139321394213952139621397213982139921400214012140221403214042140521406214072140821409214102141121412214132141421415214162141721418214192142021421214222142321424214252142621427214282142921430214312143221433214342143521436214372143821439214402144121442214432144421445214462144721448214492145021451214522145321454214552145621457214582145921460214612146221463214642146521466214672146821469214702147121472214732147421475214762147721478214792148021481214822148321484214852148621487214882148921490214912149221493214942149521496214972149821499215002150121502215032150421505215062150721508215092151021511215122151321514215152151621517215182151921520215212152221523215242152521526215272152821529215302153121532215332153421535215362153721538215392154021541215422154321544215452154621547215482154921550215512155221553215542155521556215572155821559215602156121562215632156421565215662156721568215692157021571215722157321574215752157621577215782157921580215812158221583215842158521586215872158821589215902159121592215932159421595215962159721598215992160021601216022160321604216052160621607216082160921610216112161221613216142161521616216172161821619216202162121622216232162421625216262162721628216292163021631216322163321634216352163621637216382163921640216412164221643216442164521646216472164821649216502165121652216532165421655216562165721658216592166021661216622166321664216652166621667216682166921670216712167221673216742167521676216772167821679216802168121682216832168421685216862168721688216892169021691216922169321694216952169621697216982169921700217012170221703217042170521706217072170821709217102171121712217132171421715217162171721718217192172021721217222172321724217252172621727217282172921730217312173221733217342173521736217372173821739217402174121742217432174421745217462174721748217492175021751217522175321754217552175621757217582175921760217612176221763217642176521766217672176821769217702177121772217732177421775217762177721778217792178021781217822178321784217852178621787217882178921790217912179221793217942179521796217972179821799218002180121802218032180421805218062180721808218092181021811218122181321814218152181621817218182181921820218212182221823218242182521826218272182821829218302183121832218332183421835218362183721838218392184021841218422184321844218452184621847218482184921850218512185221853218542185521856218572185821859218602186121862218632186421865218662186721868218692187021871218722187321874218752187621877218782187921880218812188221883218842188521886218872188821889218902189121892218932189421895218962189721898218992190021901219022190321904219052190621907219082190921910219112191221913219142191521916219172191821919219202192121922219232192421925219262192721928219292193021931219322193321934219352193621937219382193921940219412194221943219442194521946219472194821949219502195121952219532195421955219562195721958219592196021961219622196321964219652196621967219682196921970219712197221973219742197521976219772197821979219802198121982219832198421985219862198721988219892199021991219922199321994219952199621997219982199922000220012200222003220042200522006220072200822009220102201122012220132201422015220162201722018220192202022021220222202322024220252202622027220282202922030220312203222033220342203522036220372203822039220402204122042220432204422045220462204722048220492205022051220522205322054220552205622057220582205922060220612206222063220642206522066220672206822069220702207122072220732207422075220762207722078220792208022081220822208322084220852208622087220882208922090220912209222093220942209522096220972209822099221002210122102221032210422105221062210722108221092211022111221122211322114221152211622117221182211922120221212212222123221242212522126221272212822129221302213122132221332213422135221362213722138221392214022141221422214322144221452214622147221482214922150221512215222153221542215522156221572215822159221602216122162221632216422165221662216722168221692217022171221722217322174221752217622177221782217922180221812218222183221842218522186221872218822189221902219122192221932219422195221962219722198221992220022201222022220322204222052220622207222082220922210222112221222213222142221522216222172221822219222202222122222222232222422225222262222722228222292223022231222322223322234222352223622237222382223922240222412224222243222442224522246222472224822249222502225122252222532225422255222562225722258222592226022261222622226322264222652226622267222682226922270222712227222273222742227522276222772227822279222802228122282222832228422285222862228722288222892229022291222922229322294222952229622297222982229922300223012230222303223042230522306223072230822309223102231122312223132231422315223162231722318223192232022321223222232322324223252232622327223282232922330223312233222333223342233522336223372233822339223402234122342223432234422345223462234722348223492235022351223522235322354223552235622357223582235922360223612236222363223642236522366223672236822369223702237122372223732237422375223762237722378223792238022381223822238322384223852238622387223882238922390223912239222393223942239522396223972239822399224002240122402224032240422405224062240722408224092241022411224122241322414224152241622417224182241922420224212242222423224242242522426224272242822429224302243122432224332243422435224362243722438224392244022441224422244322444224452244622447224482244922450224512245222453224542245522456224572245822459224602246122462224632246422465224662246722468224692247022471224722247322474224752247622477224782247922480224812248222483224842248522486224872248822489224902249122492224932249422495224962249722498224992250022501225022250322504225052250622507225082250922510225112251222513225142251522516225172251822519225202252122522225232252422525225262252722528225292253022531225322253322534225352253622537225382253922540225412254222543225442254522546225472254822549225502255122552225532255422555225562255722558225592256022561225622256322564225652256622567225682256922570225712257222573225742257522576225772257822579225802258122582225832258422585225862258722588225892259022591225922259322594225952259622597225982259922600226012260222603226042260522606226072260822609226102261122612226132261422615226162261722618226192262022621226222262322624226252262622627226282262922630226312263222633226342263522636226372263822639226402264122642226432264422645226462264722648226492265022651226522265322654226552265622657226582265922660226612266222663226642266522666226672266822669226702267122672226732267422675226762267722678226792268022681226822268322684226852268622687226882268922690226912269222693226942269522696226972269822699227002270122702227032270422705227062270722708227092271022711227122271322714227152271622717227182271922720227212272222723227242272522726227272272822729227302273122732227332273422735227362273722738227392274022741227422274322744227452274622747227482274922750227512275222753227542275522756227572275822759227602276122762227632276422765227662276722768227692277022771227722277322774227752277622777227782277922780227812278222783227842278522786227872278822789227902279122792227932279422795227962279722798227992280022801228022280322804228052280622807228082280922810228112281222813228142281522816228172281822819228202282122822228232282422825228262282722828228292283022831228322283322834228352283622837228382283922840228412284222843228442284522846228472284822849228502285122852228532285422855228562285722858228592286022861228622286322864228652286622867228682286922870228712287222873228742287522876228772287822879228802288122882228832288422885228862288722888228892289022891228922289322894228952289622897228982289922900229012290222903229042290522906229072290822909229102291122912229132291422915229162291722918229192292022921229222292322924229252292622927229282292922930229312293222933229342293522936229372293822939229402294122942229432294422945229462294722948229492295022951229522295322954229552295622957229582295922960229612296222963229642296522966229672296822969229702297122972229732297422975229762297722978229792298022981229822298322984229852298622987229882298922990229912299222993229942299522996229972299822999230002300123002230032300423005230062300723008230092301023011230122301323014230152301623017230182301923020230212302223023230242302523026230272302823029230302303123032230332303423035230362303723038230392304023041230422304323044230452304623047230482304923050230512305223053230542305523056230572305823059230602306123062230632306423065230662306723068230692307023071230722307323074230752307623077230782307923080230812308223083230842308523086230872308823089230902309123092230932309423095230962309723098230992310023101231022310323104231052310623107231082310923110231112311223113231142311523116231172311823119231202312123122231232312423125231262312723128231292313023131231322313323134231352313623137231382313923140231412314223143231442314523146231472314823149231502315123152231532315423155231562315723158231592316023161231622316323164231652316623167231682316923170231712317223173231742317523176231772317823179231802318123182231832318423185231862318723188231892319023191231922319323194231952319623197231982319923200232012320223203232042320523206232072320823209232102321123212232132321423215232162321723218232192322023221232222322323224232252322623227232282322923230232312323223233232342323523236232372323823239232402324123242232432324423245232462324723248232492325023251232522325323254232552325623257232582325923260232612326223263232642326523266232672326823269232702327123272232732327423275232762327723278232792328023281232822328323284232852328623287232882328923290232912329223293232942329523296232972329823299233002330123302233032330423305233062330723308233092331023311233122331323314233152331623317233182331923320233212332223323233242332523326233272332823329233302333123332233332333423335233362333723338233392334023341233422334323344233452334623347233482334923350233512335223353233542335523356233572335823359233602336123362233632336423365233662336723368233692337023371233722337323374233752337623377233782337923380233812338223383233842338523386233872338823389233902339123392233932339423395233962339723398233992340023401234022340323404234052340623407234082340923410234112341223413234142341523416234172341823419234202342123422234232342423425234262342723428234292343023431234322343323434234352343623437234382343923440234412344223443234442344523446234472344823449234502345123452234532345423455234562345723458234592346023461234622346323464234652346623467234682346923470234712347223473234742347523476234772347823479234802348123482234832348423485234862348723488234892349023491234922349323494234952349623497234982349923500235012350223503235042350523506235072350823509235102351123512235132351423515235162351723518235192352023521235222352323524235252352623527235282352923530235312353223533235342353523536235372353823539235402354123542235432354423545235462354723548235492355023551235522355323554235552355623557235582355923560235612356223563235642356523566235672356823569235702357123572235732357423575235762357723578235792358023581235822358323584235852358623587235882358923590235912359223593235942359523596235972359823599236002360123602236032360423605236062360723608236092361023611236122361323614236152361623617236182361923620236212362223623236242362523626236272362823629236302363123632236332363423635236362363723638236392364023641236422364323644236452364623647236482364923650236512365223653236542365523656236572365823659236602366123662236632366423665236662366723668236692367023671236722367323674236752367623677236782367923680236812368223683236842368523686236872368823689236902369123692236932369423695236962369723698236992370023701237022370323704237052370623707237082370923710237112371223713237142371523716237172371823719237202372123722237232372423725237262372723728237292373023731237322373323734237352373623737237382373923740237412374223743237442374523746237472374823749237502375123752237532375423755237562375723758237592376023761237622376323764237652376623767237682376923770237712377223773237742377523776237772377823779237802378123782237832378423785237862378723788237892379023791237922379323794237952379623797237982379923800238012380223803238042380523806238072380823809238102381123812238132381423815238162381723818238192382023821238222382323824238252382623827238282382923830238312383223833238342383523836238372383823839238402384123842238432384423845238462384723848238492385023851238522385323854238552385623857238582385923860238612386223863238642386523866238672386823869238702387123872238732387423875238762387723878238792388023881238822388323884238852388623887238882388923890238912389223893238942389523896238972389823899239002390123902239032390423905239062390723908239092391023911239122391323914239152391623917239182391923920239212392223923239242392523926239272392823929239302393123932239332393423935239362393723938239392394023941239422394323944239452394623947239482394923950239512395223953239542395523956239572395823959239602396123962239632396423965239662396723968239692397023971239722397323974239752397623977239782397923980239812398223983239842398523986239872398823989239902399123992239932399423995239962399723998239992400024001240022400324004240052400624007240082400924010240112401224013240142401524016240172401824019240202402124022240232402424025240262402724028240292403024031240322403324034240352403624037240382403924040240412404224043240442404524046240472404824049240502405124052240532405424055240562405724058240592406024061240622406324064240652406624067240682406924070240712407224073240742407524076240772407824079240802408124082240832408424085240862408724088240892409024091240922409324094240952409624097240982409924100241012410224103241042410524106241072410824109241102411124112241132411424115241162411724118241192412024121241222412324124241252412624127241282412924130241312413224133241342413524136241372413824139241402414124142241432414424145241462414724148241492415024151241522415324154241552415624157241582415924160241612416224163241642416524166241672416824169241702417124172241732417424175241762417724178241792418024181241822418324184241852418624187241882418924190241912419224193241942419524196241972419824199242002420124202242032420424205242062420724208242092421024211242122421324214242152421624217242182421924220242212422224223242242422524226242272422824229242302423124232242332423424235242362423724238242392424024241242422424324244242452424624247242482424924250242512425224253242542425524256242572425824259242602426124262242632426424265242662426724268242692427024271242722427324274242752427624277242782427924280242812428224283242842428524286242872428824289242902429124292242932429424295242962429724298242992430024301243022430324304243052430624307243082430924310243112431224313243142431524316243172431824319243202432124322243232432424325243262432724328243292433024331243322433324334243352433624337243382433924340243412434224343243442434524346243472434824349243502435124352243532435424355243562435724358243592436024361243622436324364243652436624367243682436924370243712437224373243742437524376243772437824379243802438124382243832438424385243862438724388243892439024391243922439324394243952439624397243982439924400244012440224403244042440524406244072440824409244102441124412244132441424415244162441724418244192442024421244222442324424244252442624427244282442924430244312443224433244342443524436244372443824439244402444124442244432444424445244462444724448244492445024451244522445324454244552445624457244582445924460244612446224463244642446524466244672446824469244702447124472244732447424475244762447724478244792448024481244822448324484244852448624487244882448924490244912449224493244942449524496244972449824499245002450124502245032450424505245062450724508245092451024511245122451324514245152451624517245182451924520245212452224523245242452524526245272452824529245302453124532245332453424535245362453724538245392454024541245422454324544245452454624547245482454924550245512455224553245542455524556245572455824559245602456124562245632456424565245662456724568245692457024571245722457324574245752457624577245782457924580245812458224583245842458524586245872458824589245902459124592245932459424595245962459724598245992460024601246022460324604246052460624607246082460924610246112461224613246142461524616246172461824619246202462124622246232462424625246262462724628246292463024631246322463324634246352463624637246382463924640246412464224643246442464524646246472464824649246502465124652246532465424655246562465724658246592466024661246622466324664246652466624667246682466924670246712467224673246742467524676246772467824679246802468124682246832468424685246862468724688246892469024691246922469324694246952469624697246982469924700247012470224703247042470524706247072470824709247102471124712247132471424715247162471724718247192472024721247222472324724247252472624727247282472924730247312473224733247342473524736247372473824739247402474124742247432474424745247462474724748247492475024751247522475324754247552475624757247582475924760247612476224763247642476524766247672476824769247702477124772247732477424775247762477724778247792478024781247822478324784247852478624787247882478924790247912479224793247942479524796247972479824799248002480124802248032480424805248062480724808248092481024811248122481324814248152481624817248182481924820248212482224823248242482524826248272482824829248302483124832248332483424835248362483724838248392484024841248422484324844248452484624847248482484924850248512485224853248542485524856248572485824859248602486124862248632486424865248662486724868248692487024871248722487324874248752487624877248782487924880248812488224883248842488524886248872488824889248902489124892248932489424895248962489724898248992490024901249022490324904249052490624907249082490924910249112491224913249142491524916249172491824919249202492124922249232492424925249262492724928249292493024931249322493324934249352493624937249382493924940249412494224943249442494524946249472494824949249502495124952249532495424955249562495724958249592496024961249622496324964249652496624967249682496924970249712497224973249742497524976249772497824979249802498124982249832498424985249862498724988249892499024991249922499324994249952499624997249982499925000250012500225003250042500525006250072500825009250102501125012250132501425015250162501725018250192502025021250222502325024250252502625027250282502925030250312503225033250342503525036250372503825039250402504125042250432504425045250462504725048250492505025051250522505325054250552505625057250582505925060250612506225063250642506525066250672506825069250702507125072250732507425075250762507725078250792508025081250822508325084250852508625087250882508925090250912509225093250942509525096250972509825099251002510125102251032510425105251062510725108251092511025111251122511325114251152511625117251182511925120251212512225123251242512525126251272512825129251302513125132251332513425135251362513725138251392514025141251422514325144251452514625147251482514925150251512515225153251542515525156251572515825159251602516125162251632516425165251662516725168251692517025171251722517325174251752517625177251782517925180251812518225183251842518525186251872518825189251902519125192251932519425195251962519725198251992520025201252022520325204252052520625207252082520925210252112521225213252142521525216252172521825219252202522125222252232522425225252262522725228252292523025231252322523325234252352523625237252382523925240252412524225243252442524525246252472524825249252502525125252252532525425255252562525725258252592526025261252622526325264252652526625267252682526925270252712527225273252742527525276252772527825279252802528125282252832528425285252862528725288252892529025291252922529325294252952529625297252982529925300253012530225303253042530525306253072530825309253102531125312253132531425315253162531725318253192532025321253222532325324253252532625327253282532925330253312533225333253342533525336253372533825339253402534125342253432534425345253462534725348253492535025351253522535325354253552535625357253582535925360253612536225363253642536525366253672536825369253702537125372253732537425375253762537725378253792538025381253822538325384253852538625387253882538925390253912539225393253942539525396253972539825399254002540125402254032540425405254062540725408254092541025411254122541325414254152541625417254182541925420254212542225423254242542525426254272542825429254302543125432254332543425435254362543725438254392544025441254422544325444254452544625447254482544925450254512545225453254542545525456254572545825459254602546125462254632546425465254662546725468254692547025471254722547325474254752547625477254782547925480254812548225483254842548525486254872548825489254902549125492254932549425495254962549725498254992550025501255022550325504255052550625507255082550925510255112551225513255142551525516255172551825519255202552125522255232552425525255262552725528255292553025531255322553325534255352553625537255382553925540255412554225543255442554525546255472554825549255502555125552255532555425555255562555725558255592556025561255622556325564255652556625567255682556925570255712557225573255742557525576255772557825579255802558125582255832558425585255862558725588255892559025591255922559325594255952559625597255982559925600256012560225603256042560525606256072560825609256102561125612256132561425615256162561725618256192562025621256222562325624256252562625627256282562925630256312563225633256342563525636256372563825639256402564125642256432564425645256462564725648256492565025651256522565325654256552565625657256582565925660256612566225663256642566525666256672566825669256702567125672256732567425675256762567725678256792568025681256822568325684256852568625687256882568925690256912569225693256942569525696256972569825699257002570125702257032570425705257062570725708257092571025711257122571325714257152571625717257182571925720257212572225723257242572525726257272572825729257302573125732257332573425735257362573725738257392574025741257422574325744257452574625747257482574925750257512575225753257542575525756257572575825759257602576125762257632576425765257662576725768257692577025771257722577325774257752577625777257782577925780257812578225783257842578525786257872578825789257902579125792257932579425795257962579725798257992580025801258022580325804258052580625807258082580925810258112581225813258142581525816258172581825819258202582125822258232582425825258262582725828258292583025831258322583325834258352583625837258382583925840258412584225843258442584525846258472584825849258502585125852258532585425855258562585725858258592586025861258622586325864258652586625867258682586925870258712587225873258742587525876258772587825879258802588125882258832588425885258862588725888258892589025891258922589325894258952589625897258982589925900259012590225903259042590525906259072590825909259102591125912259132591425915259162591725918259192592025921259222592325924259252592625927259282592925930259312593225933259342593525936259372593825939259402594125942259432594425945259462594725948259492595025951259522595325954259552595625957259582595925960259612596225963259642596525966259672596825969259702597125972259732597425975259762597725978259792598025981259822598325984259852598625987259882598925990259912599225993259942599525996259972599825999260002600126002260032600426005260062600726008260092601026011260122601326014260152601626017260182601926020260212602226023260242602526026260272602826029260302603126032260332603426035260362603726038260392604026041260422604326044260452604626047260482604926050260512605226053260542605526056260572605826059260602606126062260632606426065260662606726068260692607026071260722607326074260752607626077260782607926080260812608226083260842608526086260872608826089260902609126092260932609426095260962609726098260992610026101261022610326104261052610626107261082610926110261112611226113261142611526116261172611826119261202612126122261232612426125261262612726128261292613026131261322613326134261352613626137261382613926140261412614226143261442614526146261472614826149261502615126152261532615426155261562615726158261592616026161261622616326164261652616626167261682616926170261712617226173261742617526176261772617826179261802618126182261832618426185261862618726188261892619026191261922619326194261952619626197261982619926200262012620226203262042620526206262072620826209262102621126212262132621426215262162621726218262192622026221262222622326224262252622626227262282622926230262312623226233262342623526236262372623826239262402624126242262432624426245262462624726248262492625026251262522625326254262552625626257262582625926260262612626226263262642626526266262672626826269262702627126272262732627426275262762627726278262792628026281262822628326284262852628626287262882628926290262912629226293262942629526296262972629826299263002630126302263032630426305263062630726308263092631026311263122631326314263152631626317263182631926320263212632226323263242632526326263272632826329263302633126332263332633426335263362633726338263392634026341263422634326344263452634626347263482634926350263512635226353263542635526356263572635826359263602636126362263632636426365263662636726368263692637026371263722637326374263752637626377263782637926380263812638226383263842638526386263872638826389263902639126392263932639426395263962639726398263992640026401264022640326404264052640626407264082640926410264112641226413264142641526416264172641826419264202642126422264232642426425264262642726428264292643026431264322643326434264352643626437264382643926440264412644226443264442644526446264472644826449264502645126452264532645426455264562645726458264592646026461264622646326464264652646626467264682646926470264712647226473264742647526476264772647826479264802648126482264832648426485264862648726488264892649026491264922649326494264952649626497264982649926500265012650226503265042650526506265072650826509265102651126512265132651426515265162651726518265192652026521265222652326524265252652626527265282652926530265312653226533265342653526536265372653826539265402654126542265432654426545265462654726548265492655026551265522655326554265552655626557265582655926560265612656226563265642656526566265672656826569265702657126572265732657426575265762657726578265792658026581265822658326584265852658626587265882658926590265912659226593265942659526596265972659826599266002660126602266032660426605266062660726608266092661026611266122661326614266152661626617266182661926620266212662226623266242662526626266272662826629266302663126632266332663426635266362663726638266392664026641266422664326644266452664626647266482664926650266512665226653266542665526656266572665826659266602666126662266632666426665266662666726668266692667026671266722667326674266752667626677266782667926680266812668226683266842668526686266872668826689266902669126692266932669426695266962669726698266992670026701267022670326704267052670626707267082670926710267112671226713267142671526716267172671826719267202672126722267232672426725267262672726728267292673026731267322673326734267352673626737267382673926740267412674226743267442674526746267472674826749267502675126752267532675426755267562675726758267592676026761267622676326764267652676626767267682676926770267712677226773267742677526776267772677826779267802678126782267832678426785267862678726788267892679026791267922679326794267952679626797267982679926800268012680226803268042680526806268072680826809268102681126812268132681426815268162681726818268192682026821268222682326824268252682626827268282682926830268312683226833268342683526836268372683826839268402684126842268432684426845268462684726848268492685026851268522685326854268552685626857268582685926860268612686226863268642686526866268672686826869268702687126872268732687426875268762687726878268792688026881268822688326884268852688626887268882688926890268912689226893268942689526896268972689826899269002690126902269032690426905269062690726908269092691026911269122691326914269152691626917269182691926920269212692226923269242692526926269272692826929269302693126932269332693426935269362693726938269392694026941269422694326944269452694626947269482694926950269512695226953269542695526956269572695826959269602696126962269632696426965269662696726968269692697026971269722697326974269752697626977269782697926980269812698226983269842698526986269872698826989269902699126992269932699426995269962699726998269992700027001270022700327004270052700627007270082700927010270112701227013270142701527016270172701827019270202702127022270232702427025270262702727028270292703027031270322703327034270352703627037270382703927040270412704227043270442704527046270472704827049270502705127052270532705427055270562705727058270592706027061270622706327064270652706627067270682706927070270712707227073270742707527076270772707827079270802708127082270832708427085270862708727088270892709027091270922709327094270952709627097270982709927100271012710227103271042710527106271072710827109271102711127112271132711427115271162711727118271192712027121271222712327124271252712627127271282712927130271312713227133271342713527136271372713827139271402714127142271432714427145271462714727148271492715027151271522715327154271552715627157271582715927160271612716227163271642716527166271672716827169271702717127172271732717427175271762717727178271792718027181271822718327184271852718627187271882718927190271912719227193271942719527196271972719827199272002720127202272032720427205272062720727208272092721027211272122721327214272152721627217272182721927220272212722227223272242722527226272272722827229272302723127232272332723427235272362723727238272392724027241272422724327244272452724627247272482724927250272512725227253272542725527256272572725827259272602726127262272632726427265272662726727268272692727027271272722727327274272752727627277272782727927280272812728227283272842728527286272872728827289272902729127292272932729427295272962729727298272992730027301273022730327304273052730627307273082730927310273112731227313273142731527316273172731827319273202732127322273232732427325273262732727328273292733027331273322733327334273352733627337273382733927340273412734227343273442734527346273472734827349273502735127352273532735427355273562735727358273592736027361273622736327364273652736627367273682736927370273712737227373273742737527376273772737827379273802738127382273832738427385273862738727388273892739027391273922739327394273952739627397273982739927400274012740227403274042740527406274072740827409274102741127412274132741427415274162741727418274192742027421274222742327424274252742627427274282742927430274312743227433274342743527436274372743827439274402744127442274432744427445274462744727448274492745027451274522745327454274552745627457274582745927460274612746227463274642746527466274672746827469274702747127472274732747427475274762747727478274792748027481274822748327484274852748627487274882748927490274912749227493274942749527496274972749827499275002750127502275032750427505275062750727508275092751027511275122751327514275152751627517275182751927520275212752227523275242752527526275272752827529275302753127532275332753427535275362753727538275392754027541275422754327544275452754627547275482754927550275512755227553275542755527556275572755827559275602756127562275632756427565275662756727568275692757027571275722757327574275752757627577275782757927580275812758227583275842758527586275872758827589275902759127592275932759427595275962759727598275992760027601276022760327604276052760627607276082760927610276112761227613276142761527616276172761827619276202762127622276232762427625276262762727628276292763027631276322763327634276352763627637276382763927640276412764227643276442764527646276472764827649276502765127652276532765427655276562765727658276592766027661276622766327664276652766627667276682766927670276712767227673276742767527676276772767827679276802768127682276832768427685276862768727688276892769027691276922769327694276952769627697276982769927700277012770227703277042770527706277072770827709277102771127712277132771427715277162771727718277192772027721277222772327724277252772627727277282772927730277312773227733277342773527736277372773827739277402774127742277432774427745277462774727748277492775027751277522775327754277552775627757277582775927760277612776227763277642776527766277672776827769277702777127772277732777427775277762777727778277792778027781277822778327784277852778627787277882778927790277912779227793277942779527796277972779827799278002780127802278032780427805278062780727808278092781027811278122781327814278152781627817278182781927820278212782227823278242782527826278272782827829278302783127832278332783427835278362783727838278392784027841278422784327844278452784627847278482784927850278512785227853278542785527856278572785827859278602786127862278632786427865278662786727868278692787027871278722787327874278752787627877278782787927880278812788227883278842788527886278872788827889278902789127892278932789427895278962789727898278992790027901279022790327904279052790627907279082790927910279112791227913279142791527916279172791827919279202792127922279232792427925279262792727928279292793027931279322793327934279352793627937279382793927940279412794227943279442794527946279472794827949279502795127952279532795427955279562795727958279592796027961279622796327964279652796627967279682796927970279712797227973279742797527976279772797827979279802798127982279832798427985279862798727988279892799027991279922799327994279952799627997279982799928000280012800228003280042800528006280072800828009280102801128012280132801428015280162801728018280192802028021280222802328024280252802628027280282802928030280312803228033280342803528036280372803828039280402804128042280432804428045280462804728048280492805028051280522805328054280552805628057280582805928060280612806228063280642806528066280672806828069280702807128072280732807428075280762807728078280792808028081280822808328084280852808628087280882808928090280912809228093280942809528096280972809828099281002810128102281032810428105281062810728108281092811028111281122811328114281152811628117281182811928120281212812228123281242812528126281272812828129281302813128132281332813428135281362813728138281392814028141281422814328144281452814628147281482814928150281512815228153281542815528156281572815828159281602816128162281632816428165281662816728168281692817028171281722817328174281752817628177281782817928180281812818228183281842818528186281872818828189281902819128192281932819428195281962819728198281992820028201282022820328204282052820628207282082820928210282112821228213282142821528216282172821828219282202822128222282232822428225282262822728228282292823028231282322823328234282352823628237282382823928240282412824228243282442824528246282472824828249282502825128252282532825428255282562825728258282592826028261282622826328264282652826628267282682826928270282712827228273282742827528276282772827828279282802828128282282832828428285282862828728288282892829028291282922829328294282952829628297282982829928300283012830228303283042830528306283072830828309283102831128312283132831428315283162831728318283192832028321283222832328324283252832628327283282832928330283312833228333283342833528336283372833828339283402834128342283432834428345283462834728348283492835028351283522835328354283552835628357283582835928360283612836228363283642836528366283672836828369283702837128372283732837428375283762837728378283792838028381283822838328384283852838628387283882838928390283912839228393283942839528396283972839828399284002840128402284032840428405284062840728408284092841028411284122841328414284152841628417284182841928420284212842228423284242842528426284272842828429284302843128432284332843428435284362843728438284392844028441284422844328444284452844628447284482844928450284512845228453284542845528456284572845828459284602846128462284632846428465284662846728468284692847028471284722847328474284752847628477284782847928480284812848228483284842848528486284872848828489284902849128492284932849428495284962849728498284992850028501285022850328504285052850628507285082850928510285112851228513285142851528516285172851828519285202852128522285232852428525285262852728528285292853028531285322853328534285352853628537285382853928540285412854228543285442854528546285472854828549285502855128552285532855428555285562855728558285592856028561285622856328564285652856628567285682856928570285712857228573285742857528576285772857828579285802858128582285832858428585285862858728588285892859028591285922859328594285952859628597285982859928600286012860228603286042860528606286072860828609286102861128612286132861428615286162861728618286192862028621286222862328624286252862628627286282862928630286312863228633286342863528636286372863828639286402864128642286432864428645286462864728648286492865028651286522865328654286552865628657286582865928660286612866228663286642866528666286672866828669286702867128672286732867428675286762867728678286792868028681286822868328684286852868628687286882868928690286912869228693286942869528696286972869828699287002870128702287032870428705287062870728708287092871028711287122871328714287152871628717287182871928720287212872228723287242872528726287272872828729287302873128732287332873428735287362873728738287392874028741287422874328744287452874628747287482874928750287512875228753287542875528756287572875828759287602876128762287632876428765287662876728768287692877028771287722877328774287752877628777287782877928780287812878228783287842878528786287872878828789287902879128792287932879428795287962879728798287992880028801288022880328804288052880628807288082880928810288112881228813288142881528816288172881828819288202882128822288232882428825288262882728828288292883028831288322883328834288352883628837288382883928840288412884228843288442884528846288472884828849288502885128852288532885428855288562885728858288592886028861288622886328864288652886628867288682886928870288712887228873288742887528876288772887828879288802888128882288832888428885288862888728888288892889028891288922889328894288952889628897288982889928900289012890228903289042890528906289072890828909289102891128912289132891428915289162891728918289192892028921289222892328924289252892628927289282892928930289312893228933289342893528936289372893828939289402894128942289432894428945289462894728948289492895028951289522895328954289552895628957289582895928960289612896228963289642896528966289672896828969289702897128972289732897428975289762897728978289792898028981289822898328984289852898628987289882898928990289912899228993289942899528996289972899828999290002900129002290032900429005290062900729008290092901029011290122901329014290152901629017290182901929020290212902229023290242902529026290272902829029290302903129032290332903429035290362903729038290392904029041290422904329044290452904629047290482904929050290512905229053290542905529056290572905829059290602906129062290632906429065290662906729068290692907029071290722907329074290752907629077290782907929080290812908229083290842908529086290872908829089290902909129092290932909429095290962909729098290992910029101291022910329104291052910629107291082910929110291112911229113291142911529116291172911829119291202912129122291232912429125291262912729128291292913029131291322913329134291352913629137291382913929140291412914229143291442914529146291472914829149291502915129152291532915429155291562915729158291592916029161291622916329164291652916629167291682916929170291712917229173291742917529176291772917829179291802918129182291832918429185291862918729188291892919029191291922919329194291952919629197291982919929200292012920229203292042920529206292072920829209292102921129212292132921429215292162921729218292192922029221292222922329224292252922629227292282922929230292312923229233292342923529236292372923829239292402924129242292432924429245292462924729248292492925029251292522925329254292552925629257292582925929260292612926229263292642926529266292672926829269292702927129272292732927429275292762927729278292792928029281292822928329284292852928629287292882928929290292912929229293292942929529296292972929829299293002930129302293032930429305293062930729308293092931029311293122931329314293152931629317293182931929320293212932229323293242932529326293272932829329293302933129332293332933429335293362933729338293392934029341293422934329344293452934629347293482934929350293512935229353293542935529356293572935829359293602936129362293632936429365293662936729368293692937029371293722937329374293752937629377293782937929380293812938229383293842938529386293872938829389293902939129392293932939429395293962939729398293992940029401294022940329404294052940629407294082940929410294112941229413294142941529416294172941829419294202942129422294232942429425294262942729428294292943029431294322943329434294352943629437294382943929440294412944229443294442944529446294472944829449294502945129452294532945429455294562945729458294592946029461294622946329464294652946629467294682946929470294712947229473294742947529476294772947829479294802948129482294832948429485294862948729488294892949029491294922949329494294952949629497294982949929500295012950229503295042950529506295072950829509295102951129512295132951429515295162951729518295192952029521295222952329524295252952629527295282952929530295312953229533295342953529536295372953829539295402954129542295432954429545295462954729548295492955029551295522955329554295552955629557295582955929560295612956229563295642956529566295672956829569295702957129572295732957429575295762957729578295792958029581295822958329584295852958629587295882958929590295912959229593295942959529596295972959829599296002960129602296032960429605296062960729608296092961029611296122961329614296152961629617296182961929620296212962229623296242962529626296272962829629296302963129632296332963429635296362963729638296392964029641296422964329644296452964629647296482964929650296512965229653296542965529656296572965829659296602966129662296632966429665296662966729668296692967029671296722967329674296752967629677296782967929680296812968229683296842968529686296872968829689296902969129692296932969429695296962969729698296992970029701297022970329704297052970629707297082970929710297112971229713297142971529716297172971829719297202972129722297232972429725297262972729728297292973029731297322973329734297352973629737297382973929740297412974229743297442974529746297472974829749297502975129752297532975429755297562975729758297592976029761297622976329764297652976629767297682976929770297712977229773297742977529776297772977829779297802978129782297832978429785297862978729788297892979029791297922979329794297952979629797297982979929800298012980229803298042980529806298072980829809298102981129812298132981429815298162981729818298192982029821298222982329824298252982629827298282982929830298312983229833298342983529836298372983829839298402984129842298432984429845298462984729848298492985029851298522985329854298552985629857298582985929860298612986229863298642986529866298672986829869298702987129872298732987429875298762987729878298792988029881298822988329884298852988629887298882988929890298912989229893298942989529896298972989829899299002990129902299032990429905299062990729908299092991029911299122991329914299152991629917299182991929920299212992229923299242992529926299272992829929299302993129932299332993429935299362993729938299392994029941299422994329944299452994629947299482994929950299512995229953299542995529956299572995829959299602996129962299632996429965299662996729968299692997029971299722997329974299752997629977299782997929980299812998229983299842998529986299872998829989299902999129992299932999429995299962999729998299993000030001300023000330004300053000630007300083000930010300113001230013300143001530016300173001830019300203002130022300233002430025300263002730028300293003030031300323003330034300353003630037300383003930040300413004230043300443004530046300473004830049300503005130052300533005430055300563005730058300593006030061300623006330064300653006630067300683006930070300713007230073300743007530076300773007830079300803008130082300833008430085300863008730088300893009030091300923009330094300953009630097300983009930100301013010230103301043010530106301073010830109301103011130112301133011430115301163011730118301193012030121301223012330124301253012630127301283012930130301313013230133301343013530136301373013830139301403014130142301433014430145301463014730148301493015030151301523015330154301553015630157301583015930160301613016230163301643016530166301673016830169301703017130172301733017430175301763017730178301793018030181301823018330184301853018630187301883018930190301913019230193301943019530196301973019830199302003020130202302033020430205302063020730208302093021030211302123021330214302153021630217302183021930220302213022230223302243022530226302273022830229302303023130232302333023430235302363023730238302393024030241302423024330244302453024630247302483024930250302513025230253302543025530256302573025830259302603026130262302633026430265302663026730268302693027030271302723027330274302753027630277302783027930280302813028230283302843028530286302873028830289302903029130292302933029430295302963029730298302993030030301303023030330304303053030630307303083030930310303113031230313303143031530316303173031830319303203032130322303233032430325303263032730328303293033030331303323033330334303353033630337303383033930340303413034230343303443034530346303473034830349303503035130352303533035430355303563035730358303593036030361303623036330364303653036630367303683036930370303713037230373303743037530376303773037830379303803038130382303833038430385303863038730388303893039030391303923039330394303953039630397303983039930400304013040230403304043040530406304073040830409304103041130412304133041430415304163041730418304193042030421304223042330424304253042630427304283042930430304313043230433304343043530436304373043830439304403044130442304433044430445304463044730448304493045030451304523045330454304553045630457304583045930460304613046230463304643046530466304673046830469304703047130472304733047430475304763047730478304793048030481304823048330484304853048630487304883048930490304913049230493304943049530496304973049830499305003050130502305033050430505305063050730508305093051030511305123051330514305153051630517305183051930520305213052230523305243052530526305273052830529305303053130532305333053430535305363053730538305393054030541305423054330544305453054630547305483054930550305513055230553305543055530556305573055830559305603056130562305633056430565305663056730568305693057030571305723057330574305753057630577305783057930580305813058230583305843058530586305873058830589305903059130592305933059430595305963059730598305993060030601306023060330604306053060630607306083060930610306113061230613306143061530616306173061830619306203062130622306233062430625306263062730628306293063030631306323063330634306353063630637306383063930640306413064230643306443064530646306473064830649306503065130652306533065430655306563065730658306593066030661306623066330664306653066630667306683066930670306713067230673306743067530676306773067830679306803068130682306833068430685306863068730688306893069030691306923069330694306953069630697306983069930700307013070230703307043070530706307073070830709307103071130712307133071430715307163071730718307193072030721307223072330724307253072630727307283072930730307313073230733307343073530736307373073830739307403074130742307433074430745307463074730748307493075030751307523075330754307553075630757307583075930760307613076230763307643076530766307673076830769307703077130772307733077430775307763077730778307793078030781307823078330784307853078630787307883078930790307913079230793307943079530796307973079830799308003080130802308033080430805308063080730808308093081030811308123081330814308153081630817308183081930820308213082230823308243082530826308273082830829308303083130832308333083430835308363083730838308393084030841308423084330844308453084630847308483084930850308513085230853308543085530856308573085830859308603086130862308633086430865308663086730868308693087030871308723087330874308753087630877308783087930880308813088230883308843088530886308873088830889308903089130892308933089430895308963089730898308993090030901309023090330904309053090630907309083090930910309113091230913309143091530916309173091830919309203092130922309233092430925309263092730928309293093030931309323093330934309353093630937309383093930940309413094230943309443094530946309473094830949309503095130952309533095430955309563095730958309593096030961309623096330964309653096630967309683096930970309713097230973309743097530976309773097830979309803098130982309833098430985309863098730988309893099030991309923099330994309953099630997309983099931000310013100231003310043100531006310073100831009310103101131012310133101431015310163101731018310193102031021310223102331024310253102631027310283102931030310313103231033310343103531036310373103831039310403104131042310433104431045310463104731048310493105031051310523105331054310553105631057310583105931060310613106231063310643106531066310673106831069310703107131072310733107431075310763107731078310793108031081310823108331084310853108631087310883108931090310913109231093310943109531096310973109831099311003110131102311033110431105311063110731108311093111031111311123111331114311153111631117311183111931120311213112231123311243112531126311273112831129311303113131132311333113431135311363113731138311393114031141311423114331144311453114631147311483114931150311513115231153311543115531156311573115831159311603116131162311633116431165311663116731168311693117031171311723117331174311753117631177311783117931180311813118231183311843118531186311873118831189311903119131192311933119431195311963119731198311993120031201312023120331204312053120631207312083120931210312113121231213312143121531216312173121831219312203122131222312233122431225312263122731228312293123031231312323123331234312353123631237312383123931240312413124231243312443124531246312473124831249312503125131252312533125431255312563125731258312593126031261312623126331264312653126631267312683126931270312713127231273312743127531276312773127831279312803128131282312833128431285312863128731288312893129031291312923129331294312953129631297312983129931300313013130231303313043130531306313073130831309313103131131312313133131431315313163131731318313193132031321313223132331324313253132631327313283132931330313313133231333313343133531336313373133831339313403134131342313433134431345313463134731348313493135031351313523135331354313553135631357313583135931360313613136231363313643136531366313673136831369313703137131372313733137431375313763137731378313793138031381313823138331384313853138631387313883138931390313913139231393313943139531396313973139831399314003140131402314033140431405314063140731408314093141031411314123141331414314153141631417314183141931420314213142231423314243142531426314273142831429314303143131432314333143431435314363143731438314393144031441314423144331444314453144631447314483144931450314513145231453314543145531456314573145831459314603146131462314633146431465314663146731468314693147031471314723147331474314753147631477314783147931480314813148231483314843148531486314873148831489314903149131492314933149431495314963149731498314993150031501315023150331504315053150631507315083150931510315113151231513315143151531516315173151831519315203152131522315233152431525315263152731528315293153031531315323153331534315353153631537315383153931540315413154231543315443154531546315473154831549315503155131552315533155431555315563155731558315593156031561315623156331564315653156631567315683156931570315713157231573315743157531576315773157831579315803158131582315833158431585315863158731588315893159031591315923159331594315953159631597315983159931600316013160231603316043160531606316073160831609316103161131612316133161431615316163161731618316193162031621316223162331624316253162631627316283162931630316313163231633316343163531636316373163831639316403164131642316433164431645316463164731648316493165031651316523165331654316553165631657316583165931660316613166231663316643166531666316673166831669316703167131672316733167431675316763167731678316793168031681316823168331684316853168631687316883168931690316913169231693316943169531696316973169831699317003170131702317033170431705317063170731708317093171031711317123171331714317153171631717317183171931720317213172231723317243172531726317273172831729317303173131732317333173431735317363173731738317393174031741317423174331744317453174631747317483174931750317513175231753317543175531756317573175831759317603176131762317633176431765317663176731768317693177031771317723177331774317753177631777317783177931780317813178231783317843178531786317873178831789317903179131792317933179431795317963179731798317993180031801318023180331804318053180631807318083180931810318113181231813318143181531816318173181831819318203182131822318233182431825318263182731828318293183031831318323183331834318353183631837318383183931840318413184231843318443184531846318473184831849318503185131852318533185431855318563185731858318593186031861318623186331864318653186631867318683186931870318713187231873318743187531876318773187831879318803188131882318833188431885318863188731888318893189031891318923189331894318953189631897318983189931900319013190231903319043190531906319073190831909319103191131912319133191431915319163191731918319193192031921319223192331924319253192631927319283192931930319313193231933319343193531936319373193831939319403194131942319433194431945319463194731948319493195031951319523195331954319553195631957319583195931960319613196231963319643196531966319673196831969319703197131972319733197431975319763197731978319793198031981319823198331984319853198631987319883198931990319913199231993319943199531996319973199831999320003200132002320033200432005320063200732008320093201032011320123201332014320153201632017320183201932020320213202232023320243202532026320273202832029320303203132032320333203432035320363203732038320393204032041320423204332044320453204632047320483204932050320513205232053320543205532056320573205832059320603206132062320633206432065320663206732068320693207032071320723207332074320753207632077320783207932080320813208232083320843208532086320873208832089320903209132092320933209432095320963209732098320993210032101321023210332104321053210632107321083210932110321113211232113321143211532116321173211832119321203212132122321233212432125321263212732128321293213032131321323213332134321353213632137321383213932140321413214232143321443214532146321473214832149321503215132152321533215432155321563215732158321593216032161321623216332164321653216632167321683216932170321713217232173321743217532176321773217832179321803218132182321833218432185321863218732188321893219032191321923219332194321953219632197321983219932200322013220232203322043220532206322073220832209322103221132212322133221432215322163221732218322193222032221322223222332224322253222632227322283222932230322313223232233322343223532236322373223832239322403224132242322433224432245322463224732248322493225032251322523225332254322553225632257322583225932260322613226232263322643226532266322673226832269322703227132272322733227432275322763227732278322793228032281322823228332284322853228632287322883228932290322913229232293322943229532296322973229832299323003230132302323033230432305323063230732308323093231032311323123231332314323153231632317323183231932320323213232232323323243232532326323273232832329323303233132332323333233432335323363233732338323393234032341323423234332344323453234632347323483234932350323513235232353323543235532356323573235832359323603236132362323633236432365323663236732368323693237032371323723237332374323753237632377323783237932380323813238232383323843238532386323873238832389323903239132392323933239432395323963239732398323993240032401324023240332404324053240632407324083240932410324113241232413324143241532416324173241832419324203242132422324233242432425324263242732428324293243032431324323243332434324353243632437324383243932440324413244232443324443244532446324473244832449324503245132452324533245432455324563245732458324593246032461324623246332464324653246632467324683246932470324713247232473324743247532476324773247832479324803248132482324833248432485324863248732488324893249032491324923249332494324953249632497324983249932500325013250232503325043250532506325073250832509325103251132512325133251432515325163251732518325193252032521325223252332524325253252632527325283252932530325313253232533325343253532536325373253832539325403254132542325433254432545325463254732548325493255032551325523255332554325553255632557325583255932560325613256232563325643256532566325673256832569325703257132572325733257432575325763257732578325793258032581325823258332584325853258632587325883258932590325913259232593325943259532596325973259832599326003260132602326033260432605326063260732608326093261032611326123261332614326153261632617326183261932620326213262232623326243262532626326273262832629326303263132632326333263432635326363263732638326393264032641326423264332644326453264632647326483264932650326513265232653326543265532656326573265832659326603266132662326633266432665326663266732668326693267032671326723267332674326753267632677326783267932680326813268232683326843268532686326873268832689326903269132692326933269432695326963269732698326993270032701327023270332704327053270632707327083270932710327113271232713327143271532716327173271832719327203272132722327233272432725327263272732728327293273032731327323273332734327353273632737327383273932740327413274232743327443274532746327473274832749327503275132752327533275432755327563275732758327593276032761327623276332764327653276632767327683276932770327713277232773327743277532776327773277832779327803278132782327833278432785327863278732788327893279032791327923279332794327953279632797327983279932800328013280232803328043280532806328073280832809328103281132812328133281432815328163281732818328193282032821328223282332824328253282632827328283282932830328313283232833328343283532836328373283832839328403284132842328433284432845328463284732848328493285032851328523285332854328553285632857328583285932860328613286232863328643286532866328673286832869328703287132872328733287432875328763287732878328793288032881328823288332884328853288632887328883288932890328913289232893328943289532896328973289832899329003290132902329033290432905329063290732908329093291032911329123291332914329153291632917329183291932920329213292232923329243292532926329273292832929329303293132932329333293432935329363293732938329393294032941329423294332944329453294632947329483294932950329513295232953329543295532956329573295832959329603296132962329633296432965329663296732968329693297032971329723297332974329753297632977329783297932980329813298232983329843298532986329873298832989329903299132992329933299432995329963299732998329993300033001330023300333004330053300633007330083300933010330113301233013330143301533016330173301833019330203302133022330233302433025330263302733028330293303033031330323303333034330353303633037330383303933040330413304233043330443304533046330473304833049330503305133052330533305433055330563305733058330593306033061330623306333064330653306633067330683306933070330713307233073330743307533076330773307833079330803308133082330833308433085330863308733088330893309033091330923309333094330953309633097330983309933100331013310233103331043310533106331073310833109331103311133112331133311433115331163311733118331193312033121331223312333124331253312633127331283312933130331313313233133331343313533136331373313833139331403314133142331433314433145331463314733148331493315033151331523315333154331553315633157331583315933160331613316233163331643316533166331673316833169331703317133172331733317433175331763317733178331793318033181331823318333184331853318633187331883318933190331913319233193331943319533196331973319833199332003320133202332033320433205332063320733208332093321033211332123321333214332153321633217332183321933220332213322233223332243322533226332273322833229332303323133232332333323433235332363323733238332393324033241332423324333244332453324633247332483324933250332513325233253332543325533256332573325833259332603326133262332633326433265332663326733268332693327033271332723327333274332753327633277332783327933280332813328233283332843328533286332873328833289332903329133292332933329433295332963329733298332993330033301333023330333304333053330633307333083330933310333113331233313333143331533316333173331833319333203332133322333233332433325333263332733328333293333033331333323333333334333353333633337333383333933340333413334233343333443334533346333473334833349333503335133352333533335433355333563335733358333593336033361333623336333364333653336633367333683336933370333713337233373333743337533376333773337833379333803338133382333833338433385333863338733388333893339033391333923339333394333953339633397333983339933400334013340233403334043340533406334073340833409334103341133412334133341433415334163341733418334193342033421334223342333424334253342633427334283342933430334313343233433334343343533436334373343833439334403344133442334433344433445334463344733448334493345033451334523345333454334553345633457334583345933460334613346233463334643346533466334673346833469334703347133472334733347433475334763347733478334793348033481334823348333484334853348633487334883348933490334913349233493334943349533496334973349833499335003350133502335033350433505335063350733508335093351033511335123351333514335153351633517335183351933520335213352233523335243352533526335273352833529335303353133532335333353433535335363353733538335393354033541335423354333544335453354633547335483354933550335513355233553335543355533556335573355833559335603356133562335633356433565335663356733568335693357033571335723357333574335753357633577335783357933580335813358233583335843358533586335873358833589335903359133592335933359433595335963359733598335993360033601336023360333604336053360633607336083360933610336113361233613336143361533616336173361833619336203362133622336233362433625336263362733628336293363033631336323363333634336353363633637336383363933640336413364233643336443364533646336473364833649336503365133652336533365433655336563365733658336593366033661336623366333664336653366633667336683366933670336713367233673336743367533676336773367833679336803368133682336833368433685336863368733688336893369033691336923369333694336953369633697336983369933700337013370233703337043370533706337073370833709337103371133712337133371433715337163371733718337193372033721337223372333724337253372633727337283372933730337313373233733337343373533736337373373833739337403374133742337433374433745337463374733748337493375033751337523375333754337553375633757337583375933760337613376233763337643376533766337673376833769337703377133772337733377433775337763377733778337793378033781337823378333784337853378633787337883378933790337913379233793337943379533796337973379833799338003380133802338033380433805338063380733808338093381033811338123381333814338153381633817338183381933820338213382233823338243382533826338273382833829338303383133832338333383433835338363383733838338393384033841338423384333844338453384633847338483384933850338513385233853338543385533856338573385833859338603386133862338633386433865338663386733868338693387033871338723387333874338753387633877338783387933880338813388233883338843388533886338873388833889338903389133892338933389433895338963389733898338993390033901339023390333904339053390633907339083390933910339113391233913339143391533916339173391833919339203392133922339233392433925339263392733928339293393033931339323393333934339353393633937339383393933940339413394233943339443394533946339473394833949339503395133952339533395433955339563395733958339593396033961339623396333964339653396633967339683396933970339713397233973339743397533976339773397833979339803398133982339833398433985339863398733988339893399033991339923399333994339953399633997339983399934000340013400234003340043400534006340073400834009340103401134012340133401434015340163401734018340193402034021340223402334024340253402634027340283402934030340313403234033340343403534036340373403834039340403404134042340433404434045340463404734048340493405034051340523405334054340553405634057340583405934060340613406234063340643406534066340673406834069340703407134072340733407434075340763407734078340793408034081340823408334084340853408634087340883408934090340913409234093340943409534096340973409834099341003410134102341033410434105341063410734108341093411034111341123411334114341153411634117341183411934120341213412234123341243412534126341273412834129341303413134132341333413434135341363413734138341393414034141341423414334144341453414634147341483414934150341513415234153341543415534156341573415834159341603416134162341633416434165341663416734168341693417034171341723417334174341753417634177341783417934180341813418234183341843418534186341873418834189341903419134192341933419434195341963419734198341993420034201342023420334204342053420634207342083420934210342113421234213342143421534216342173421834219342203422134222342233422434225342263422734228342293423034231342323423334234342353423634237342383423934240342413424234243342443424534246342473424834249342503425134252342533425434255342563425734258342593426034261342623426334264342653426634267342683426934270342713427234273342743427534276342773427834279342803428134282342833428434285342863428734288342893429034291342923429334294342953429634297342983429934300343013430234303343043430534306343073430834309343103431134312343133431434315343163431734318343193432034321343223432334324343253432634327343283432934330343313433234333343343433534336343373433834339343403434134342343433434434345343463434734348343493435034351343523435334354343553435634357343583435934360343613436234363343643436534366343673436834369343703437134372343733437434375343763437734378343793438034381343823438334384343853438634387343883438934390343913439234393343943439534396343973439834399344003440134402344033440434405344063440734408344093441034411344123441334414344153441634417344183441934420344213442234423344243442534426344273442834429344303443134432344333443434435344363443734438344393444034441344423444334444344453444634447344483444934450344513445234453344543445534456344573445834459344603446134462344633446434465344663446734468344693447034471344723447334474344753447634477344783447934480344813448234483344843448534486344873448834489344903449134492344933449434495344963449734498344993450034501345023450334504345053450634507345083450934510345113451234513345143451534516345173451834519345203452134522345233452434525345263452734528345293453034531345323453334534345353453634537345383453934540345413454234543345443454534546345473454834549345503455134552345533455434555345563455734558345593456034561345623456334564345653456634567345683456934570345713457234573345743457534576345773457834579345803458134582345833458434585345863458734588345893459034591345923459334594345953459634597345983459934600346013460234603346043460534606346073460834609346103461134612346133461434615346163461734618346193462034621346223462334624346253462634627346283462934630346313463234633346343463534636346373463834639346403464134642346433464434645346463464734648346493465034651346523465334654346553465634657346583465934660346613466234663346643466534666346673466834669346703467134672346733467434675346763467734678346793468034681346823468334684346853468634687346883468934690346913469234693346943469534696346973469834699347003470134702347033470434705347063470734708347093471034711347123471334714347153471634717347183471934720347213472234723347243472534726347273472834729347303473134732347333473434735347363473734738347393474034741347423474334744347453474634747347483474934750347513475234753347543475534756347573475834759347603476134762347633476434765347663476734768347693477034771347723477334774347753477634777347783477934780347813478234783347843478534786347873478834789347903479134792347933479434795347963479734798347993480034801348023480334804348053480634807348083480934810348113481234813348143481534816348173481834819348203482134822348233482434825348263482734828348293483034831348323483334834348353483634837348383483934840348413484234843348443484534846348473484834849348503485134852348533485434855348563485734858348593486034861348623486334864348653486634867348683486934870348713487234873348743487534876348773487834879348803488134882348833488434885348863488734888348893489034891348923489334894348953489634897348983489934900349013490234903349043490534906349073490834909349103491134912349133491434915349163491734918349193492034921349223492334924349253492634927349283492934930349313493234933349343493534936349373493834939349403494134942349433494434945349463494734948349493495034951349523495334954349553495634957349583495934960349613496234963349643496534966349673496834969349703497134972349733497434975349763497734978349793498034981349823498334984349853498634987349883498934990349913499234993349943499534996349973499834999350003500135002350033500435005350063500735008350093501035011350123501335014350153501635017350183501935020350213502235023350243502535026350273502835029350303503135032350333503435035350363503735038350393504035041350423504335044350453504635047350483504935050350513505235053350543505535056350573505835059350603506135062350633506435065350663506735068350693507035071350723507335074350753507635077350783507935080350813508235083350843508535086350873508835089350903509135092350933509435095350963509735098350993510035101351023510335104351053510635107351083510935110351113511235113351143511535116351173511835119351203512135122351233512435125351263512735128351293513035131351323513335134351353513635137351383513935140351413514235143351443514535146351473514835149351503515135152351533515435155351563515735158351593516035161351623516335164351653516635167351683516935170351713517235173351743517535176351773517835179351803518135182351833518435185351863518735188351893519035191351923519335194351953519635197351983519935200352013520235203352043520535206352073520835209352103521135212352133521435215352163521735218352193522035221352223522335224352253522635227352283522935230352313523235233352343523535236352373523835239352403524135242352433524435245352463524735248352493525035251352523525335254352553525635257352583525935260352613526235263352643526535266352673526835269352703527135272352733527435275352763527735278352793528035281352823528335284352853528635287352883528935290352913529235293352943529535296352973529835299353003530135302353033530435305353063530735308353093531035311353123531335314353153531635317353183531935320353213532235323353243532535326353273532835329353303533135332353333533435335353363533735338353393534035341353423534335344353453534635347353483534935350353513535235353353543535535356353573535835359353603536135362353633536435365353663536735368353693537035371353723537335374353753537635377353783537935380353813538235383353843538535386353873538835389353903539135392353933539435395353963539735398353993540035401354023540335404354053540635407354083540935410354113541235413354143541535416354173541835419354203542135422354233542435425354263542735428354293543035431354323543335434354353543635437354383543935440354413544235443354443544535446354473544835449354503545135452354533545435455354563545735458354593546035461354623546335464354653546635467354683546935470354713547235473354743547535476354773547835479354803548135482354833548435485354863548735488354893549035491354923549335494354953549635497354983549935500355013550235503355043550535506355073550835509355103551135512355133551435515355163551735518355193552035521355223552335524355253552635527355283552935530355313553235533355343553535536355373553835539355403554135542355433554435545355463554735548355493555035551355523555335554355553555635557355583555935560355613556235563355643556535566355673556835569355703557135572355733557435575355763557735578355793558035581355823558335584355853558635587355883558935590355913559235593355943559535596355973559835599356003560135602356033560435605356063560735608356093561035611356123561335614356153561635617356183561935620356213562235623356243562535626356273562835629356303563135632356333563435635356363563735638356393564035641356423564335644356453564635647356483564935650356513565235653356543565535656356573565835659356603566135662356633566435665356663566735668356693567035671356723567335674356753567635677356783567935680356813568235683356843568535686356873568835689356903569135692356933569435695356963569735698356993570035701357023570335704357053570635707357083570935710357113571235713357143571535716357173571835719357203572135722357233572435725357263572735728357293573035731357323573335734357353573635737357383573935740357413574235743357443574535746357473574835749357503575135752357533575435755357563575735758357593576035761357623576335764357653576635767357683576935770357713577235773357743577535776357773577835779357803578135782357833578435785357863578735788357893579035791357923579335794357953579635797357983579935800358013580235803358043580535806358073580835809358103581135812358133581435815358163581735818358193582035821358223582335824358253582635827358283582935830358313583235833358343583535836358373583835839358403584135842358433584435845358463584735848358493585035851358523585335854358553585635857358583585935860358613586235863358643586535866358673586835869358703587135872358733587435875358763587735878358793588035881358823588335884358853588635887358883588935890358913589235893358943589535896358973589835899359003590135902359033590435905359063590735908359093591035911359123591335914359153591635917359183591935920359213592235923359243592535926359273592835929359303593135932359333593435935359363593735938359393594035941359423594335944359453594635947359483594935950359513595235953359543595535956359573595835959359603596135962359633596435965359663596735968359693597035971359723597335974359753597635977359783597935980359813598235983359843598535986359873598835989359903599135992359933599435995359963599735998359993600036001360023600336004360053600636007360083600936010360113601236013360143601536016360173601836019360203602136022360233602436025360263602736028360293603036031360323603336034360353603636037360383603936040360413604236043360443604536046360473604836049360503605136052360533605436055360563605736058360593606036061360623606336064360653606636067360683606936070360713607236073360743607536076360773607836079360803608136082360833608436085360863608736088360893609036091360923609336094360953609636097360983609936100361013610236103361043610536106361073610836109361103611136112361133611436115361163611736118361193612036121361223612336124361253612636127361283612936130361313613236133361343613536136361373613836139361403614136142361433614436145361463614736148361493615036151361523615336154361553615636157361583615936160361613616236163361643616536166361673616836169361703617136172361733617436175361763617736178361793618036181361823618336184361853618636187361883618936190361913619236193361943619536196361973619836199362003620136202362033620436205362063620736208362093621036211362123621336214362153621636217362183621936220362213622236223362243622536226362273622836229362303623136232362333623436235362363623736238362393624036241362423624336244362453624636247362483624936250362513625236253362543625536256362573625836259362603626136262362633626436265362663626736268362693627036271362723627336274362753627636277362783627936280362813628236283362843628536286362873628836289362903629136292362933629436295362963629736298362993630036301363023630336304363053630636307363083630936310363113631236313363143631536316363173631836319363203632136322363233632436325363263632736328363293633036331363323633336334363353633636337363383633936340363413634236343363443634536346363473634836349363503635136352363533635436355363563635736358363593636036361363623636336364363653636636367363683636936370363713637236373363743637536376363773637836379363803638136382363833638436385363863638736388363893639036391363923639336394363953639636397363983639936400364013640236403364043640536406364073640836409364103641136412364133641436415364163641736418364193642036421364223642336424364253642636427364283642936430364313643236433364343643536436364373643836439364403644136442364433644436445364463644736448364493645036451364523645336454364553645636457364583645936460364613646236463364643646536466364673646836469364703647136472364733647436475364763647736478364793648036481364823648336484364853648636487364883648936490364913649236493364943649536496364973649836499365003650136502365033650436505365063650736508365093651036511365123651336514365153651636517365183651936520365213652236523365243652536526365273652836529365303653136532365333653436535365363653736538365393654036541365423654336544365453654636547365483654936550365513655236553365543655536556365573655836559365603656136562365633656436565365663656736568365693657036571365723657336574365753657636577365783657936580365813658236583365843658536586365873658836589365903659136592365933659436595365963659736598365993660036601366023660336604366053660636607366083660936610366113661236613366143661536616366173661836619366203662136622366233662436625366263662736628366293663036631366323663336634366353663636637366383663936640366413664236643366443664536646366473664836649366503665136652366533665436655366563665736658366593666036661366623666336664366653666636667366683666936670366713667236673366743667536676366773667836679366803668136682366833668436685366863668736688366893669036691366923669336694366953669636697366983669936700367013670236703367043670536706367073670836709367103671136712367133671436715367163671736718367193672036721367223672336724367253672636727367283672936730367313673236733367343673536736367373673836739367403674136742367433674436745367463674736748367493675036751367523675336754367553675636757367583675936760367613676236763367643676536766367673676836769367703677136772367733677436775367763677736778367793678036781367823678336784367853678636787367883678936790367913679236793367943679536796367973679836799368003680136802368033680436805368063680736808368093681036811368123681336814368153681636817368183681936820368213682236823368243682536826368273682836829368303683136832368333683436835368363683736838368393684036841368423684336844368453684636847368483684936850368513685236853368543685536856368573685836859368603686136862368633686436865368663686736868368693687036871368723687336874368753687636877368783687936880368813688236883368843688536886368873688836889368903689136892368933689436895368963689736898368993690036901369023690336904369053690636907369083690936910369113691236913369143691536916369173691836919369203692136922369233692436925369263692736928369293693036931369323693336934369353693636937369383693936940369413694236943369443694536946369473694836949369503695136952369533695436955369563695736958369593696036961369623696336964369653696636967369683696936970369713697236973369743697536976369773697836979369803698136982369833698436985369863698736988369893699036991369923699336994369953699636997369983699937000370013700237003370043700537006370073700837009370103701137012370133701437015370163701737018370193702037021370223702337024370253702637027370283702937030370313703237033370343703537036370373703837039370403704137042370433704437045370463704737048370493705037051370523705337054370553705637057370583705937060370613706237063370643706537066370673706837069370703707137072370733707437075370763707737078370793708037081370823708337084370853708637087370883708937090370913709237093370943709537096370973709837099371003710137102371033710437105371063710737108371093711037111371123711337114371153711637117371183711937120371213712237123371243712537126371273712837129371303713137132371333713437135371363713737138371393714037141371423714337144371453714637147371483714937150371513715237153371543715537156371573715837159371603716137162371633716437165371663716737168371693717037171371723717337174371753717637177371783717937180371813718237183371843718537186371873718837189371903719137192371933719437195371963719737198371993720037201372023720337204372053720637207372083720937210372113721237213372143721537216372173721837219372203722137222372233722437225372263722737228372293723037231372323723337234372353723637237372383723937240372413724237243372443724537246372473724837249372503725137252372533725437255372563725737258372593726037261372623726337264372653726637267372683726937270372713727237273372743727537276372773727837279372803728137282372833728437285372863728737288372893729037291372923729337294372953729637297372983729937300373013730237303373043730537306373073730837309373103731137312373133731437315373163731737318373193732037321373223732337324373253732637327373283732937330373313733237333373343733537336373373733837339373403734137342373433734437345373463734737348373493735037351373523735337354373553735637357373583735937360373613736237363373643736537366373673736837369373703737137372373733737437375373763737737378373793738037381373823738337384373853738637387373883738937390373913739237393373943739537396373973739837399374003740137402374033740437405374063740737408374093741037411374123741337414374153741637417374183741937420374213742237423374243742537426374273742837429374303743137432374333743437435374363743737438374393744037441374423744337444374453744637447374483744937450374513745237453374543745537456374573745837459374603746137462374633746437465374663746737468374693747037471374723747337474374753747637477374783747937480374813748237483374843748537486374873748837489374903749137492374933749437495374963749737498374993750037501375023750337504375053750637507375083750937510375113751237513375143751537516375173751837519375203752137522375233752437525375263752737528375293753037531375323753337534375353753637537375383753937540375413754237543375443754537546375473754837549375503755137552375533755437555375563755737558375593756037561375623756337564375653756637567375683756937570375713757237573375743757537576375773757837579375803758137582375833758437585375863758737588375893759037591375923759337594375953759637597375983759937600376013760237603376043760537606376073760837609376103761137612376133761437615376163761737618376193762037621376223762337624376253762637627376283762937630376313763237633376343763537636376373763837639376403764137642376433764437645376463764737648376493765037651376523765337654376553765637657376583765937660376613766237663376643766537666376673766837669376703767137672376733767437675376763767737678376793768037681376823768337684376853768637687376883768937690376913769237693376943769537696376973769837699377003770137702377033770437705377063770737708377093771037711377123771337714377153771637717377183771937720377213772237723377243772537726377273772837729377303773137732377333773437735377363773737738377393774037741377423774337744377453774637747377483774937750377513775237753377543775537756377573775837759377603776137762377633776437765377663776737768377693777037771377723777337774377753777637777377783777937780377813778237783377843778537786377873778837789377903779137792377933779437795377963779737798377993780037801378023780337804378053780637807378083780937810378113781237813378143781537816378173781837819378203782137822378233782437825378263782737828378293783037831378323783337834378353783637837378383783937840378413784237843378443784537846378473784837849378503785137852378533785437855378563785737858378593786037861378623786337864378653786637867378683786937870378713787237873378743787537876378773787837879378803788137882378833788437885378863788737888378893789037891378923789337894378953789637897378983789937900379013790237903379043790537906379073790837909379103791137912379133791437915379163791737918379193792037921379223792337924379253792637927379283792937930379313793237933379343793537936379373793837939379403794137942379433794437945379463794737948379493795037951379523795337954379553795637957379583795937960379613796237963379643796537966379673796837969379703797137972379733797437975379763797737978379793798037981379823798337984379853798637987379883798937990379913799237993379943799537996379973799837999380003800138002380033800438005380063800738008380093801038011380123801338014380153801638017380183801938020380213802238023380243802538026380273802838029380303803138032380333803438035380363803738038380393804038041380423804338044380453804638047380483804938050380513805238053380543805538056380573805838059380603806138062380633806438065380663806738068380693807038071380723807338074380753807638077380783807938080380813808238083380843808538086380873808838089380903809138092380933809438095380963809738098380993810038101381023810338104381053810638107381083810938110381113811238113381143811538116381173811838119381203812138122381233812438125381263812738128381293813038131381323813338134381353813638137381383813938140381413814238143381443814538146381473814838149381503815138152381533815438155381563815738158381593816038161381623816338164381653816638167381683816938170381713817238173381743817538176381773817838179381803818138182381833818438185381863818738188381893819038191381923819338194381953819638197381983819938200382013820238203382043820538206382073820838209382103821138212382133821438215382163821738218382193822038221382223822338224382253822638227382283822938230382313823238233382343823538236382373823838239382403824138242382433824438245382463824738248382493825038251382523825338254382553825638257382583825938260382613826238263382643826538266382673826838269382703827138272382733827438275382763827738278382793828038281382823828338284382853828638287382883828938290382913829238293382943829538296382973829838299383003830138302383033830438305383063830738308383093831038311383123831338314383153831638317383183831938320383213832238323383243832538326383273832838329383303833138332383333833438335383363833738338383393834038341383423834338344383453834638347383483834938350383513835238353383543835538356383573835838359383603836138362383633836438365383663836738368383693837038371383723837338374383753837638377383783837938380383813838238383383843838538386383873838838389383903839138392383933839438395383963839738398383993840038401384023840338404384053840638407384083840938410384113841238413384143841538416384173841838419384203842138422384233842438425384263842738428384293843038431384323843338434384353843638437384383843938440384413844238443384443844538446384473844838449384503845138452384533845438455384563845738458384593846038461384623846338464384653846638467384683846938470384713847238473384743847538476384773847838479384803848138482384833848438485384863848738488384893849038491384923849338494384953849638497384983849938500385013850238503385043850538506385073850838509385103851138512385133851438515385163851738518385193852038521385223852338524385253852638527385283852938530385313853238533385343853538536385373853838539385403854138542385433854438545385463854738548385493855038551385523855338554385553855638557385583855938560385613856238563385643856538566385673856838569385703857138572385733857438575385763857738578385793858038581385823858338584385853858638587385883858938590385913859238593385943859538596385973859838599386003860138602386033860438605386063860738608386093861038611386123861338614386153861638617386183861938620386213862238623386243862538626386273862838629386303863138632386333863438635386363863738638386393864038641386423864338644386453864638647386483864938650386513865238653386543865538656386573865838659386603866138662386633866438665386663866738668386693867038671386723867338674386753867638677386783867938680386813868238683386843868538686386873868838689386903869138692386933869438695386963869738698386993870038701387023870338704387053870638707387083870938710387113871238713387143871538716387173871838719387203872138722387233872438725387263872738728387293873038731387323873338734387353873638737387383873938740387413874238743387443874538746387473874838749387503875138752387533875438755387563875738758387593876038761387623876338764387653876638767387683876938770387713877238773387743877538776387773877838779387803878138782387833878438785387863878738788387893879038791387923879338794387953879638797387983879938800388013880238803388043880538806388073880838809388103881138812388133881438815388163881738818388193882038821388223882338824388253882638827388283882938830388313883238833388343883538836388373883838839388403884138842388433884438845388463884738848388493885038851388523885338854388553885638857388583885938860388613886238863388643886538866388673886838869388703887138872388733887438875388763887738878388793888038881388823888338884388853888638887388883888938890388913889238893388943889538896388973889838899389003890138902389033890438905389063890738908389093891038911389123891338914389153891638917389183891938920389213892238923389243892538926389273892838929389303893138932389333893438935389363893738938389393894038941389423894338944389453894638947389483894938950389513895238953389543895538956389573895838959389603896138962389633896438965389663896738968389693897038971389723897338974389753897638977389783897938980389813898238983389843898538986389873898838989389903899138992389933899438995389963899738998389993900039001390023900339004390053900639007390083900939010390113901239013390143901539016390173901839019390203902139022390233902439025390263902739028390293903039031390323903339034390353903639037390383903939040390413904239043390443904539046390473904839049390503905139052390533905439055390563905739058390593906039061390623906339064390653906639067390683906939070390713907239073390743907539076390773907839079390803908139082390833908439085390863908739088390893909039091390923909339094390953909639097390983909939100391013910239103391043910539106391073910839109391103911139112391133911439115391163911739118391193912039121391223912339124391253912639127391283912939130391313913239133391343913539136391373913839139391403914139142391433914439145391463914739148391493915039151391523915339154391553915639157391583915939160391613916239163391643916539166391673916839169391703917139172391733917439175391763917739178391793918039181391823918339184391853918639187391883918939190391913919239193391943919539196391973919839199392003920139202392033920439205392063920739208392093921039211392123921339214392153921639217392183921939220392213922239223392243922539226392273922839229392303923139232392333923439235392363923739238392393924039241392423924339244392453924639247392483924939250392513925239253392543925539256392573925839259392603926139262392633926439265392663926739268392693927039271392723927339274392753927639277392783927939280392813928239283392843928539286392873928839289392903929139292392933929439295392963929739298392993930039301393023930339304393053930639307393083930939310393113931239313393143931539316393173931839319393203932139322393233932439325393263932739328393293933039331393323933339334393353933639337393383933939340393413934239343393443934539346393473934839349393503935139352393533935439355393563935739358393593936039361393623936339364393653936639367393683936939370393713937239373393743937539376393773937839379393803938139382393833938439385393863938739388393893939039391393923939339394393953939639397393983939939400394013940239403394043940539406394073940839409394103941139412394133941439415394163941739418394193942039421394223942339424394253942639427394283942939430394313943239433394343943539436394373943839439394403944139442394433944439445394463944739448394493945039451394523945339454394553945639457394583945939460394613946239463394643946539466394673946839469394703947139472394733947439475394763947739478394793948039481394823948339484394853948639487394883948939490394913949239493394943949539496394973949839499395003950139502395033950439505395063950739508395093951039511395123951339514395153951639517395183951939520395213952239523395243952539526395273952839529395303953139532395333953439535395363953739538395393954039541395423954339544395453954639547395483954939550395513955239553395543955539556395573955839559395603956139562395633956439565395663956739568395693957039571395723957339574395753957639577395783957939580395813958239583395843958539586395873958839589395903959139592395933959439595395963959739598395993960039601396023960339604396053960639607396083960939610396113961239613396143961539616396173961839619396203962139622396233962439625396263962739628396293963039631396323963339634396353963639637396383963939640396413964239643396443964539646396473964839649396503965139652396533965439655396563965739658396593966039661396623966339664396653966639667396683966939670396713967239673396743967539676396773967839679396803968139682396833968439685396863968739688396893969039691396923969339694396953969639697396983969939700397013970239703397043970539706397073970839709397103971139712397133971439715397163971739718397193972039721397223972339724397253972639727397283972939730397313973239733397343973539736397373973839739397403974139742397433974439745397463974739748397493975039751397523975339754397553975639757397583975939760397613976239763397643976539766397673976839769397703977139772397733977439775397763977739778397793978039781397823978339784397853978639787397883978939790397913979239793397943979539796397973979839799398003980139802398033980439805398063980739808398093981039811398123981339814398153981639817398183981939820398213982239823398243982539826398273982839829398303983139832398333983439835398363983739838398393984039841398423984339844398453984639847398483984939850398513985239853398543985539856398573985839859398603986139862398633986439865398663986739868398693987039871398723987339874398753987639877398783987939880398813988239883398843988539886398873988839889398903989139892398933989439895398963989739898398993990039901399023990339904399053990639907399083990939910399113991239913399143991539916399173991839919399203992139922399233992439925399263992739928399293993039931399323993339934399353993639937399383993939940399413994239943399443994539946399473994839949399503995139952399533995439955399563995739958399593996039961399623996339964399653996639967399683996939970399713997239973399743997539976399773997839979399803998139982399833998439985399863998739988399893999039991399923999339994399953999639997399983999940000400014000240003400044000540006400074000840009400104001140012400134001440015400164001740018400194002040021400224002340024400254002640027400284002940030400314003240033400344003540036400374003840039400404004140042400434004440045400464004740048400494005040051400524005340054400554005640057400584005940060400614006240063400644006540066400674006840069400704007140072400734007440075400764007740078400794008040081400824008340084400854008640087400884008940090400914009240093400944009540096400974009840099401004010140102401034010440105401064010740108401094011040111401124011340114401154011640117401184011940120401214012240123401244012540126401274012840129401304013140132401334013440135401364013740138401394014040141401424014340144401454014640147401484014940150401514015240153401544015540156401574015840159401604016140162401634016440165401664016740168401694017040171401724017340174401754017640177401784017940180401814018240183401844018540186401874018840189401904019140192401934019440195401964019740198401994020040201402024020340204402054020640207402084020940210402114021240213402144021540216402174021840219402204022140222402234022440225402264022740228402294023040231402324023340234402354023640237402384023940240402414024240243402444024540246402474024840249402504025140252402534025440255402564025740258402594026040261402624026340264402654026640267402684026940270402714027240273402744027540276402774027840279402804028140282402834028440285402864028740288402894029040291402924029340294402954029640297402984029940300403014030240303403044030540306403074030840309403104031140312403134031440315403164031740318403194032040321403224032340324403254032640327403284032940330403314033240333403344033540336403374033840339403404034140342403434034440345403464034740348403494035040351403524035340354403554035640357403584035940360403614036240363403644036540366403674036840369403704037140372403734037440375403764037740378403794038040381403824038340384403854038640387403884038940390403914039240393403944039540396403974039840399404004040140402404034040440405404064040740408404094041040411404124041340414404154041640417404184041940420404214042240423404244042540426404274042840429404304043140432404334043440435404364043740438404394044040441404424044340444404454044640447404484044940450404514045240453404544045540456404574045840459404604046140462404634046440465404664046740468404694047040471404724047340474404754047640477404784047940480404814048240483404844048540486404874048840489404904049140492404934049440495404964049740498404994050040501405024050340504405054050640507405084050940510405114051240513405144051540516405174051840519405204052140522405234052440525405264052740528405294053040531405324053340534405354053640537405384053940540405414054240543405444054540546405474054840549405504055140552405534055440555405564055740558405594056040561405624056340564405654056640567405684056940570405714057240573405744057540576405774057840579405804058140582405834058440585405864058740588405894059040591405924059340594405954059640597405984059940600406014060240603406044060540606406074060840609406104061140612406134061440615406164061740618406194062040621406224062340624406254062640627406284062940630406314063240633406344063540636406374063840639406404064140642406434064440645406464064740648406494065040651406524065340654406554065640657406584065940660406614066240663406644066540666406674066840669406704067140672406734067440675406764067740678406794068040681406824068340684406854068640687406884068940690406914069240693406944069540696406974069840699407004070140702407034070440705407064070740708407094071040711407124071340714407154071640717407184071940720407214072240723407244072540726407274072840729407304073140732407334073440735407364073740738407394074040741407424074340744407454074640747407484074940750407514075240753407544075540756407574075840759407604076140762407634076440765407664076740768407694077040771407724077340774407754077640777407784077940780407814078240783407844078540786407874078840789407904079140792407934079440795407964079740798407994080040801408024080340804408054080640807408084080940810408114081240813408144081540816408174081840819408204082140822408234082440825408264082740828408294083040831408324083340834408354083640837408384083940840408414084240843408444084540846408474084840849408504085140852408534085440855408564085740858408594086040861408624086340864408654086640867408684086940870408714087240873408744087540876408774087840879408804088140882408834088440885408864088740888408894089040891408924089340894408954089640897408984089940900409014090240903409044090540906409074090840909409104091140912409134091440915409164091740918409194092040921409224092340924409254092640927409284092940930409314093240933409344093540936409374093840939409404094140942409434094440945409464094740948409494095040951409524095340954409554095640957409584095940960409614096240963409644096540966409674096840969409704097140972409734097440975409764097740978409794098040981409824098340984409854098640987409884098940990409914099240993409944099540996409974099840999410004100141002410034100441005410064100741008410094101041011410124101341014410154101641017410184101941020410214102241023410244102541026410274102841029410304103141032410334103441035410364103741038410394104041041410424104341044410454104641047410484104941050410514105241053410544105541056410574105841059410604106141062410634106441065410664106741068410694107041071410724107341074410754107641077410784107941080410814108241083410844108541086410874108841089410904109141092410934109441095410964109741098410994110041101411024110341104411054110641107411084110941110411114111241113411144111541116411174111841119411204112141122411234112441125411264112741128411294113041131411324113341134411354113641137411384113941140411414114241143411444114541146411474114841149411504115141152411534115441155411564115741158411594116041161411624116341164411654116641167411684116941170411714117241173411744117541176411774117841179411804118141182411834118441185411864118741188411894119041191411924119341194411954119641197411984119941200412014120241203412044120541206412074120841209412104121141212412134121441215412164121741218412194122041221412224122341224412254122641227
  1. /* Copyright 2012 Mozilla Foundation
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. /* jshint globalstrict: false */
  16. /* globals PDFJS, global */
  17. // Initializing PDFJS global object (if still undefined)
  18. if (typeof PDFJS === 'undefined') {
  19. (typeof window !== 'undefined' ? window :
  20. typeof global !== 'undefined' ? global : this).PDFJS = {};
  21. }
  22. PDFJS.version = '1.3.154';
  23. PDFJS.build = '4399d01';
  24. (function pdfjsWrapper() {
  25. // Use strict in our context only - users might not want it
  26. 'use strict';
  27. (function (root, factory) {
  28. {
  29. factory((root.pdfjsCoreArithmeticDecoder = {}));
  30. }
  31. }(this, function (exports) {
  32. /* This class implements the QM Coder decoding as defined in
  33. * JPEG 2000 Part I Final Committee Draft Version 1.0
  34. * Annex C.3 Arithmetic decoding procedure
  35. * available at http://www.jpeg.org/public/fcd15444-1.pdf
  36. *
  37. * The arithmetic decoder is used in conjunction with context models to decode
  38. * JPEG2000 and JBIG2 streams.
  39. */
  40. var ArithmeticDecoder = (function ArithmeticDecoderClosure() {
  41. // Table C-2
  42. var QeTable = [
  43. {qe: 0x5601, nmps: 1, nlps: 1, switchFlag: 1},
  44. {qe: 0x3401, nmps: 2, nlps: 6, switchFlag: 0},
  45. {qe: 0x1801, nmps: 3, nlps: 9, switchFlag: 0},
  46. {qe: 0x0AC1, nmps: 4, nlps: 12, switchFlag: 0},
  47. {qe: 0x0521, nmps: 5, nlps: 29, switchFlag: 0},
  48. {qe: 0x0221, nmps: 38, nlps: 33, switchFlag: 0},
  49. {qe: 0x5601, nmps: 7, nlps: 6, switchFlag: 1},
  50. {qe: 0x5401, nmps: 8, nlps: 14, switchFlag: 0},
  51. {qe: 0x4801, nmps: 9, nlps: 14, switchFlag: 0},
  52. {qe: 0x3801, nmps: 10, nlps: 14, switchFlag: 0},
  53. {qe: 0x3001, nmps: 11, nlps: 17, switchFlag: 0},
  54. {qe: 0x2401, nmps: 12, nlps: 18, switchFlag: 0},
  55. {qe: 0x1C01, nmps: 13, nlps: 20, switchFlag: 0},
  56. {qe: 0x1601, nmps: 29, nlps: 21, switchFlag: 0},
  57. {qe: 0x5601, nmps: 15, nlps: 14, switchFlag: 1},
  58. {qe: 0x5401, nmps: 16, nlps: 14, switchFlag: 0},
  59. {qe: 0x5101, nmps: 17, nlps: 15, switchFlag: 0},
  60. {qe: 0x4801, nmps: 18, nlps: 16, switchFlag: 0},
  61. {qe: 0x3801, nmps: 19, nlps: 17, switchFlag: 0},
  62. {qe: 0x3401, nmps: 20, nlps: 18, switchFlag: 0},
  63. {qe: 0x3001, nmps: 21, nlps: 19, switchFlag: 0},
  64. {qe: 0x2801, nmps: 22, nlps: 19, switchFlag: 0},
  65. {qe: 0x2401, nmps: 23, nlps: 20, switchFlag: 0},
  66. {qe: 0x2201, nmps: 24, nlps: 21, switchFlag: 0},
  67. {qe: 0x1C01, nmps: 25, nlps: 22, switchFlag: 0},
  68. {qe: 0x1801, nmps: 26, nlps: 23, switchFlag: 0},
  69. {qe: 0x1601, nmps: 27, nlps: 24, switchFlag: 0},
  70. {qe: 0x1401, nmps: 28, nlps: 25, switchFlag: 0},
  71. {qe: 0x1201, nmps: 29, nlps: 26, switchFlag: 0},
  72. {qe: 0x1101, nmps: 30, nlps: 27, switchFlag: 0},
  73. {qe: 0x0AC1, nmps: 31, nlps: 28, switchFlag: 0},
  74. {qe: 0x09C1, nmps: 32, nlps: 29, switchFlag: 0},
  75. {qe: 0x08A1, nmps: 33, nlps: 30, switchFlag: 0},
  76. {qe: 0x0521, nmps: 34, nlps: 31, switchFlag: 0},
  77. {qe: 0x0441, nmps: 35, nlps: 32, switchFlag: 0},
  78. {qe: 0x02A1, nmps: 36, nlps: 33, switchFlag: 0},
  79. {qe: 0x0221, nmps: 37, nlps: 34, switchFlag: 0},
  80. {qe: 0x0141, nmps: 38, nlps: 35, switchFlag: 0},
  81. {qe: 0x0111, nmps: 39, nlps: 36, switchFlag: 0},
  82. {qe: 0x0085, nmps: 40, nlps: 37, switchFlag: 0},
  83. {qe: 0x0049, nmps: 41, nlps: 38, switchFlag: 0},
  84. {qe: 0x0025, nmps: 42, nlps: 39, switchFlag: 0},
  85. {qe: 0x0015, nmps: 43, nlps: 40, switchFlag: 0},
  86. {qe: 0x0009, nmps: 44, nlps: 41, switchFlag: 0},
  87. {qe: 0x0005, nmps: 45, nlps: 42, switchFlag: 0},
  88. {qe: 0x0001, nmps: 45, nlps: 43, switchFlag: 0},
  89. {qe: 0x5601, nmps: 46, nlps: 46, switchFlag: 0}
  90. ];
  91. // C.3.5 Initialisation of the decoder (INITDEC)
  92. function ArithmeticDecoder(data, start, end) {
  93. this.data = data;
  94. this.bp = start;
  95. this.dataEnd = end;
  96. this.chigh = data[start];
  97. this.clow = 0;
  98. this.byteIn();
  99. this.chigh = ((this.chigh << 7) & 0xFFFF) | ((this.clow >> 9) & 0x7F);
  100. this.clow = (this.clow << 7) & 0xFFFF;
  101. this.ct -= 7;
  102. this.a = 0x8000;
  103. }
  104. ArithmeticDecoder.prototype = {
  105. // C.3.4 Compressed data input (BYTEIN)
  106. byteIn: function ArithmeticDecoder_byteIn() {
  107. var data = this.data;
  108. var bp = this.bp;
  109. if (data[bp] === 0xFF) {
  110. var b1 = data[bp + 1];
  111. if (b1 > 0x8F) {
  112. this.clow += 0xFF00;
  113. this.ct = 8;
  114. } else {
  115. bp++;
  116. this.clow += (data[bp] << 9);
  117. this.ct = 7;
  118. this.bp = bp;
  119. }
  120. } else {
  121. bp++;
  122. this.clow += bp < this.dataEnd ? (data[bp] << 8) : 0xFF00;
  123. this.ct = 8;
  124. this.bp = bp;
  125. }
  126. if (this.clow > 0xFFFF) {
  127. this.chigh += (this.clow >> 16);
  128. this.clow &= 0xFFFF;
  129. }
  130. },
  131. // C.3.2 Decoding a decision (DECODE)
  132. readBit: function ArithmeticDecoder_readBit(contexts, pos) {
  133. // contexts are packed into 1 byte:
  134. // highest 7 bits carry cx.index, lowest bit carries cx.mps
  135. var cx_index = contexts[pos] >> 1, cx_mps = contexts[pos] & 1;
  136. var qeTableIcx = QeTable[cx_index];
  137. var qeIcx = qeTableIcx.qe;
  138. var d;
  139. var a = this.a - qeIcx;
  140. if (this.chigh < qeIcx) {
  141. // exchangeLps
  142. if (a < qeIcx) {
  143. a = qeIcx;
  144. d = cx_mps;
  145. cx_index = qeTableIcx.nmps;
  146. } else {
  147. a = qeIcx;
  148. d = 1 ^ cx_mps;
  149. if (qeTableIcx.switchFlag === 1) {
  150. cx_mps = d;
  151. }
  152. cx_index = qeTableIcx.nlps;
  153. }
  154. } else {
  155. this.chigh -= qeIcx;
  156. if ((a & 0x8000) !== 0) {
  157. this.a = a;
  158. return cx_mps;
  159. }
  160. // exchangeMps
  161. if (a < qeIcx) {
  162. d = 1 ^ cx_mps;
  163. if (qeTableIcx.switchFlag === 1) {
  164. cx_mps = d;
  165. }
  166. cx_index = qeTableIcx.nlps;
  167. } else {
  168. d = cx_mps;
  169. cx_index = qeTableIcx.nmps;
  170. }
  171. }
  172. // C.3.3 renormD;
  173. do {
  174. if (this.ct === 0) {
  175. this.byteIn();
  176. }
  177. a <<= 1;
  178. this.chigh = ((this.chigh << 1) & 0xFFFF) | ((this.clow >> 15) & 1);
  179. this.clow = (this.clow << 1) & 0xFFFF;
  180. this.ct--;
  181. } while ((a & 0x8000) === 0);
  182. this.a = a;
  183. contexts[pos] = cx_index << 1 | cx_mps;
  184. return d;
  185. }
  186. };
  187. return ArithmeticDecoder;
  188. })();
  189. exports.ArithmeticDecoder = ArithmeticDecoder;
  190. }));
  191. (function (root, factory) {
  192. {
  193. factory((root.pdfjsCoreCharsets = {}));
  194. }
  195. }(this, function (exports) {
  196. var ISOAdobeCharset = [
  197. '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar',
  198. 'percent', 'ampersand', 'quoteright', 'parenleft', 'parenright',
  199. 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash', 'zero',
  200. 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  201. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question',
  202. 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
  203. 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
  204. 'bracketleft', 'backslash', 'bracketright', 'asciicircum', 'underscore',
  205. 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
  206. 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
  207. 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
  208. 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  209. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  210. 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
  211. 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase',
  212. 'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis',
  213. 'perthousand', 'questiondown', 'grave', 'acute', 'circumflex', 'tilde',
  214. 'macron', 'breve', 'dotaccent', 'dieresis', 'ring', 'cedilla',
  215. 'hungarumlaut', 'ogonek', 'caron', 'emdash', 'AE', 'ordfeminine',
  216. 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae', 'dotlessi', 'lslash',
  217. 'oslash', 'oe', 'germandbls', 'onesuperior', 'logicalnot', 'mu',
  218. 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn', 'onequarter',
  219. 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters', 'twosuperior',
  220. 'registered', 'minus', 'eth', 'multiply', 'threesuperior', 'copyright',
  221. 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring', 'Atilde',
  222. 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave', 'Iacute',
  223. 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute', 'Ocircumflex',
  224. 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute', 'Ucircumflex',
  225. 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron', 'aacute',
  226. 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde', 'ccedilla',
  227. 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute', 'icircumflex',
  228. 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex', 'odieresis',
  229. 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex', 'udieresis',
  230. 'ugrave', 'yacute', 'ydieresis', 'zcaron'
  231. ];
  232. var ExpertCharset = [
  233. '.notdef', 'space', 'exclamsmall', 'Hungarumlautsmall', 'dollaroldstyle',
  234. 'dollarsuperior', 'ampersandsmall', 'Acutesmall', 'parenleftsuperior',
  235. 'parenrightsuperior', 'twodotenleader', 'onedotenleader', 'comma',
  236. 'hyphen', 'period', 'fraction', 'zerooldstyle', 'oneoldstyle',
  237. 'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle',
  238. 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle',
  239. 'colon', 'semicolon', 'commasuperior', 'threequartersemdash',
  240. 'periodsuperior', 'questionsmall', 'asuperior', 'bsuperior',
  241. 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',
  242. 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  243. 'tsuperior', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior',
  244. 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall',
  245. 'Asmall', 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall',
  246. 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall',
  247. 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall',
  248. 'Vsmall', 'Wsmall', 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary',
  249. 'onefitted', 'rupiah', 'Tildesmall', 'exclamdownsmall', 'centoldstyle',
  250. 'Lslashsmall', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall',
  251. 'Brevesmall', 'Caronsmall', 'Dotaccentsmall', 'Macronsmall',
  252. 'figuredash', 'hypheninferior', 'Ogoneksmall', 'Ringsmall',
  253. 'Cedillasmall', 'onequarter', 'onehalf', 'threequarters',
  254. 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths',
  255. 'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'onesuperior',
  256. 'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',
  257. 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',
  258. 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior',
  259. 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior',
  260. 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior',
  261. 'periodinferior', 'commainferior', 'Agravesmall', 'Aacutesmall',
  262. 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall', 'Aringsmall',
  263. 'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall',
  264. 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall',
  265. 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall',
  266. 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall',
  267. 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall',
  268. 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall',
  269. 'Ydieresissmall'
  270. ];
  271. var ExpertSubsetCharset = [
  272. '.notdef', 'space', 'dollaroldstyle', 'dollarsuperior',
  273. 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  274. 'onedotenleader', 'comma', 'hyphen', 'period', 'fraction',
  275. 'zerooldstyle', 'oneoldstyle', 'twooldstyle', 'threeoldstyle',
  276. 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle',
  277. 'eightoldstyle', 'nineoldstyle', 'colon', 'semicolon', 'commasuperior',
  278. 'threequartersemdash', 'periodsuperior', 'asuperior', 'bsuperior',
  279. 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',
  280. 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  281. 'tsuperior', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior',
  282. 'parenrightinferior', 'hyphensuperior', 'colonmonetary', 'onefitted',
  283. 'rupiah', 'centoldstyle', 'figuredash', 'hypheninferior', 'onequarter',
  284. 'onehalf', 'threequarters', 'oneeighth', 'threeeighths', 'fiveeighths',
  285. 'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'onesuperior',
  286. 'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',
  287. 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',
  288. 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior',
  289. 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior',
  290. 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior',
  291. 'periodinferior', 'commainferior'
  292. ];
  293. exports.ISOAdobeCharset = ISOAdobeCharset;
  294. exports.ExpertCharset = ExpertCharset;
  295. exports.ExpertSubsetCharset = ExpertSubsetCharset;
  296. }));
  297. (function (root, factory) {
  298. {
  299. factory((root.pdfjsCoreGlyphList = {}));
  300. }
  301. }(this, function (exports) {
  302. var GlyphsUnicode = {
  303. A: 0x0041,
  304. AE: 0x00C6,
  305. AEacute: 0x01FC,
  306. AEmacron: 0x01E2,
  307. AEsmall: 0xF7E6,
  308. Aacute: 0x00C1,
  309. Aacutesmall: 0xF7E1,
  310. Abreve: 0x0102,
  311. Abreveacute: 0x1EAE,
  312. Abrevecyrillic: 0x04D0,
  313. Abrevedotbelow: 0x1EB6,
  314. Abrevegrave: 0x1EB0,
  315. Abrevehookabove: 0x1EB2,
  316. Abrevetilde: 0x1EB4,
  317. Acaron: 0x01CD,
  318. Acircle: 0x24B6,
  319. Acircumflex: 0x00C2,
  320. Acircumflexacute: 0x1EA4,
  321. Acircumflexdotbelow: 0x1EAC,
  322. Acircumflexgrave: 0x1EA6,
  323. Acircumflexhookabove: 0x1EA8,
  324. Acircumflexsmall: 0xF7E2,
  325. Acircumflextilde: 0x1EAA,
  326. Acute: 0xF6C9,
  327. Acutesmall: 0xF7B4,
  328. Acyrillic: 0x0410,
  329. Adblgrave: 0x0200,
  330. Adieresis: 0x00C4,
  331. Adieresiscyrillic: 0x04D2,
  332. Adieresismacron: 0x01DE,
  333. Adieresissmall: 0xF7E4,
  334. Adotbelow: 0x1EA0,
  335. Adotmacron: 0x01E0,
  336. Agrave: 0x00C0,
  337. Agravesmall: 0xF7E0,
  338. Ahookabove: 0x1EA2,
  339. Aiecyrillic: 0x04D4,
  340. Ainvertedbreve: 0x0202,
  341. Alpha: 0x0391,
  342. Alphatonos: 0x0386,
  343. Amacron: 0x0100,
  344. Amonospace: 0xFF21,
  345. Aogonek: 0x0104,
  346. Aring: 0x00C5,
  347. Aringacute: 0x01FA,
  348. Aringbelow: 0x1E00,
  349. Aringsmall: 0xF7E5,
  350. Asmall: 0xF761,
  351. Atilde: 0x00C3,
  352. Atildesmall: 0xF7E3,
  353. Aybarmenian: 0x0531,
  354. B: 0x0042,
  355. Bcircle: 0x24B7,
  356. Bdotaccent: 0x1E02,
  357. Bdotbelow: 0x1E04,
  358. Becyrillic: 0x0411,
  359. Benarmenian: 0x0532,
  360. Beta: 0x0392,
  361. Bhook: 0x0181,
  362. Blinebelow: 0x1E06,
  363. Bmonospace: 0xFF22,
  364. Brevesmall: 0xF6F4,
  365. Bsmall: 0xF762,
  366. Btopbar: 0x0182,
  367. C: 0x0043,
  368. Caarmenian: 0x053E,
  369. Cacute: 0x0106,
  370. Caron: 0xF6CA,
  371. Caronsmall: 0xF6F5,
  372. Ccaron: 0x010C,
  373. Ccedilla: 0x00C7,
  374. Ccedillaacute: 0x1E08,
  375. Ccedillasmall: 0xF7E7,
  376. Ccircle: 0x24B8,
  377. Ccircumflex: 0x0108,
  378. Cdot: 0x010A,
  379. Cdotaccent: 0x010A,
  380. Cedillasmall: 0xF7B8,
  381. Chaarmenian: 0x0549,
  382. Cheabkhasiancyrillic: 0x04BC,
  383. Checyrillic: 0x0427,
  384. Chedescenderabkhasiancyrillic: 0x04BE,
  385. Chedescendercyrillic: 0x04B6,
  386. Chedieresiscyrillic: 0x04F4,
  387. Cheharmenian: 0x0543,
  388. Chekhakassiancyrillic: 0x04CB,
  389. Cheverticalstrokecyrillic: 0x04B8,
  390. Chi: 0x03A7,
  391. Chook: 0x0187,
  392. Circumflexsmall: 0xF6F6,
  393. Cmonospace: 0xFF23,
  394. Coarmenian: 0x0551,
  395. Csmall: 0xF763,
  396. D: 0x0044,
  397. DZ: 0x01F1,
  398. DZcaron: 0x01C4,
  399. Daarmenian: 0x0534,
  400. Dafrican: 0x0189,
  401. Dcaron: 0x010E,
  402. Dcedilla: 0x1E10,
  403. Dcircle: 0x24B9,
  404. Dcircumflexbelow: 0x1E12,
  405. Dcroat: 0x0110,
  406. Ddotaccent: 0x1E0A,
  407. Ddotbelow: 0x1E0C,
  408. Decyrillic: 0x0414,
  409. Deicoptic: 0x03EE,
  410. Delta: 0x2206,
  411. Deltagreek: 0x0394,
  412. Dhook: 0x018A,
  413. Dieresis: 0xF6CB,
  414. DieresisAcute: 0xF6CC,
  415. DieresisGrave: 0xF6CD,
  416. Dieresissmall: 0xF7A8,
  417. Digammagreek: 0x03DC,
  418. Djecyrillic: 0x0402,
  419. Dlinebelow: 0x1E0E,
  420. Dmonospace: 0xFF24,
  421. Dotaccentsmall: 0xF6F7,
  422. Dslash: 0x0110,
  423. Dsmall: 0xF764,
  424. Dtopbar: 0x018B,
  425. Dz: 0x01F2,
  426. Dzcaron: 0x01C5,
  427. Dzeabkhasiancyrillic: 0x04E0,
  428. Dzecyrillic: 0x0405,
  429. Dzhecyrillic: 0x040F,
  430. E: 0x0045,
  431. Eacute: 0x00C9,
  432. Eacutesmall: 0xF7E9,
  433. Ebreve: 0x0114,
  434. Ecaron: 0x011A,
  435. Ecedillabreve: 0x1E1C,
  436. Echarmenian: 0x0535,
  437. Ecircle: 0x24BA,
  438. Ecircumflex: 0x00CA,
  439. Ecircumflexacute: 0x1EBE,
  440. Ecircumflexbelow: 0x1E18,
  441. Ecircumflexdotbelow: 0x1EC6,
  442. Ecircumflexgrave: 0x1EC0,
  443. Ecircumflexhookabove: 0x1EC2,
  444. Ecircumflexsmall: 0xF7EA,
  445. Ecircumflextilde: 0x1EC4,
  446. Ecyrillic: 0x0404,
  447. Edblgrave: 0x0204,
  448. Edieresis: 0x00CB,
  449. Edieresissmall: 0xF7EB,
  450. Edot: 0x0116,
  451. Edotaccent: 0x0116,
  452. Edotbelow: 0x1EB8,
  453. Efcyrillic: 0x0424,
  454. Egrave: 0x00C8,
  455. Egravesmall: 0xF7E8,
  456. Eharmenian: 0x0537,
  457. Ehookabove: 0x1EBA,
  458. Eightroman: 0x2167,
  459. Einvertedbreve: 0x0206,
  460. Eiotifiedcyrillic: 0x0464,
  461. Elcyrillic: 0x041B,
  462. Elevenroman: 0x216A,
  463. Emacron: 0x0112,
  464. Emacronacute: 0x1E16,
  465. Emacrongrave: 0x1E14,
  466. Emcyrillic: 0x041C,
  467. Emonospace: 0xFF25,
  468. Encyrillic: 0x041D,
  469. Endescendercyrillic: 0x04A2,
  470. Eng: 0x014A,
  471. Enghecyrillic: 0x04A4,
  472. Enhookcyrillic: 0x04C7,
  473. Eogonek: 0x0118,
  474. Eopen: 0x0190,
  475. Epsilon: 0x0395,
  476. Epsilontonos: 0x0388,
  477. Ercyrillic: 0x0420,
  478. Ereversed: 0x018E,
  479. Ereversedcyrillic: 0x042D,
  480. Escyrillic: 0x0421,
  481. Esdescendercyrillic: 0x04AA,
  482. Esh: 0x01A9,
  483. Esmall: 0xF765,
  484. Eta: 0x0397,
  485. Etarmenian: 0x0538,
  486. Etatonos: 0x0389,
  487. Eth: 0x00D0,
  488. Ethsmall: 0xF7F0,
  489. Etilde: 0x1EBC,
  490. Etildebelow: 0x1E1A,
  491. Euro: 0x20AC,
  492. Ezh: 0x01B7,
  493. Ezhcaron: 0x01EE,
  494. Ezhreversed: 0x01B8,
  495. F: 0x0046,
  496. Fcircle: 0x24BB,
  497. Fdotaccent: 0x1E1E,
  498. Feharmenian: 0x0556,
  499. Feicoptic: 0x03E4,
  500. Fhook: 0x0191,
  501. Fitacyrillic: 0x0472,
  502. Fiveroman: 0x2164,
  503. Fmonospace: 0xFF26,
  504. Fourroman: 0x2163,
  505. Fsmall: 0xF766,
  506. G: 0x0047,
  507. GBsquare: 0x3387,
  508. Gacute: 0x01F4,
  509. Gamma: 0x0393,
  510. Gammaafrican: 0x0194,
  511. Gangiacoptic: 0x03EA,
  512. Gbreve: 0x011E,
  513. Gcaron: 0x01E6,
  514. Gcedilla: 0x0122,
  515. Gcircle: 0x24BC,
  516. Gcircumflex: 0x011C,
  517. Gcommaaccent: 0x0122,
  518. Gdot: 0x0120,
  519. Gdotaccent: 0x0120,
  520. Gecyrillic: 0x0413,
  521. Ghadarmenian: 0x0542,
  522. Ghemiddlehookcyrillic: 0x0494,
  523. Ghestrokecyrillic: 0x0492,
  524. Gheupturncyrillic: 0x0490,
  525. Ghook: 0x0193,
  526. Gimarmenian: 0x0533,
  527. Gjecyrillic: 0x0403,
  528. Gmacron: 0x1E20,
  529. Gmonospace: 0xFF27,
  530. Grave: 0xF6CE,
  531. Gravesmall: 0xF760,
  532. Gsmall: 0xF767,
  533. Gsmallhook: 0x029B,
  534. Gstroke: 0x01E4,
  535. H: 0x0048,
  536. H18533: 0x25CF,
  537. H18543: 0x25AA,
  538. H18551: 0x25AB,
  539. H22073: 0x25A1,
  540. HPsquare: 0x33CB,
  541. Haabkhasiancyrillic: 0x04A8,
  542. Hadescendercyrillic: 0x04B2,
  543. Hardsigncyrillic: 0x042A,
  544. Hbar: 0x0126,
  545. Hbrevebelow: 0x1E2A,
  546. Hcedilla: 0x1E28,
  547. Hcircle: 0x24BD,
  548. Hcircumflex: 0x0124,
  549. Hdieresis: 0x1E26,
  550. Hdotaccent: 0x1E22,
  551. Hdotbelow: 0x1E24,
  552. Hmonospace: 0xFF28,
  553. Hoarmenian: 0x0540,
  554. Horicoptic: 0x03E8,
  555. Hsmall: 0xF768,
  556. Hungarumlaut: 0xF6CF,
  557. Hungarumlautsmall: 0xF6F8,
  558. Hzsquare: 0x3390,
  559. I: 0x0049,
  560. IAcyrillic: 0x042F,
  561. IJ: 0x0132,
  562. IUcyrillic: 0x042E,
  563. Iacute: 0x00CD,
  564. Iacutesmall: 0xF7ED,
  565. Ibreve: 0x012C,
  566. Icaron: 0x01CF,
  567. Icircle: 0x24BE,
  568. Icircumflex: 0x00CE,
  569. Icircumflexsmall: 0xF7EE,
  570. Icyrillic: 0x0406,
  571. Idblgrave: 0x0208,
  572. Idieresis: 0x00CF,
  573. Idieresisacute: 0x1E2E,
  574. Idieresiscyrillic: 0x04E4,
  575. Idieresissmall: 0xF7EF,
  576. Idot: 0x0130,
  577. Idotaccent: 0x0130,
  578. Idotbelow: 0x1ECA,
  579. Iebrevecyrillic: 0x04D6,
  580. Iecyrillic: 0x0415,
  581. Ifraktur: 0x2111,
  582. Igrave: 0x00CC,
  583. Igravesmall: 0xF7EC,
  584. Ihookabove: 0x1EC8,
  585. Iicyrillic: 0x0418,
  586. Iinvertedbreve: 0x020A,
  587. Iishortcyrillic: 0x0419,
  588. Imacron: 0x012A,
  589. Imacroncyrillic: 0x04E2,
  590. Imonospace: 0xFF29,
  591. Iniarmenian: 0x053B,
  592. Iocyrillic: 0x0401,
  593. Iogonek: 0x012E,
  594. Iota: 0x0399,
  595. Iotaafrican: 0x0196,
  596. Iotadieresis: 0x03AA,
  597. Iotatonos: 0x038A,
  598. Ismall: 0xF769,
  599. Istroke: 0x0197,
  600. Itilde: 0x0128,
  601. Itildebelow: 0x1E2C,
  602. Izhitsacyrillic: 0x0474,
  603. Izhitsadblgravecyrillic: 0x0476,
  604. J: 0x004A,
  605. Jaarmenian: 0x0541,
  606. Jcircle: 0x24BF,
  607. Jcircumflex: 0x0134,
  608. Jecyrillic: 0x0408,
  609. Jheharmenian: 0x054B,
  610. Jmonospace: 0xFF2A,
  611. Jsmall: 0xF76A,
  612. K: 0x004B,
  613. KBsquare: 0x3385,
  614. KKsquare: 0x33CD,
  615. Kabashkircyrillic: 0x04A0,
  616. Kacute: 0x1E30,
  617. Kacyrillic: 0x041A,
  618. Kadescendercyrillic: 0x049A,
  619. Kahookcyrillic: 0x04C3,
  620. Kappa: 0x039A,
  621. Kastrokecyrillic: 0x049E,
  622. Kaverticalstrokecyrillic: 0x049C,
  623. Kcaron: 0x01E8,
  624. Kcedilla: 0x0136,
  625. Kcircle: 0x24C0,
  626. Kcommaaccent: 0x0136,
  627. Kdotbelow: 0x1E32,
  628. Keharmenian: 0x0554,
  629. Kenarmenian: 0x053F,
  630. Khacyrillic: 0x0425,
  631. Kheicoptic: 0x03E6,
  632. Khook: 0x0198,
  633. Kjecyrillic: 0x040C,
  634. Klinebelow: 0x1E34,
  635. Kmonospace: 0xFF2B,
  636. Koppacyrillic: 0x0480,
  637. Koppagreek: 0x03DE,
  638. Ksicyrillic: 0x046E,
  639. Ksmall: 0xF76B,
  640. L: 0x004C,
  641. LJ: 0x01C7,
  642. LL: 0xF6BF,
  643. Lacute: 0x0139,
  644. Lambda: 0x039B,
  645. Lcaron: 0x013D,
  646. Lcedilla: 0x013B,
  647. Lcircle: 0x24C1,
  648. Lcircumflexbelow: 0x1E3C,
  649. Lcommaaccent: 0x013B,
  650. Ldot: 0x013F,
  651. Ldotaccent: 0x013F,
  652. Ldotbelow: 0x1E36,
  653. Ldotbelowmacron: 0x1E38,
  654. Liwnarmenian: 0x053C,
  655. Lj: 0x01C8,
  656. Ljecyrillic: 0x0409,
  657. Llinebelow: 0x1E3A,
  658. Lmonospace: 0xFF2C,
  659. Lslash: 0x0141,
  660. Lslashsmall: 0xF6F9,
  661. Lsmall: 0xF76C,
  662. M: 0x004D,
  663. MBsquare: 0x3386,
  664. Macron: 0xF6D0,
  665. Macronsmall: 0xF7AF,
  666. Macute: 0x1E3E,
  667. Mcircle: 0x24C2,
  668. Mdotaccent: 0x1E40,
  669. Mdotbelow: 0x1E42,
  670. Menarmenian: 0x0544,
  671. Mmonospace: 0xFF2D,
  672. Msmall: 0xF76D,
  673. Mturned: 0x019C,
  674. Mu: 0x039C,
  675. N: 0x004E,
  676. NJ: 0x01CA,
  677. Nacute: 0x0143,
  678. Ncaron: 0x0147,
  679. Ncedilla: 0x0145,
  680. Ncircle: 0x24C3,
  681. Ncircumflexbelow: 0x1E4A,
  682. Ncommaaccent: 0x0145,
  683. Ndotaccent: 0x1E44,
  684. Ndotbelow: 0x1E46,
  685. Nhookleft: 0x019D,
  686. Nineroman: 0x2168,
  687. Nj: 0x01CB,
  688. Njecyrillic: 0x040A,
  689. Nlinebelow: 0x1E48,
  690. Nmonospace: 0xFF2E,
  691. Nowarmenian: 0x0546,
  692. Nsmall: 0xF76E,
  693. Ntilde: 0x00D1,
  694. Ntildesmall: 0xF7F1,
  695. Nu: 0x039D,
  696. O: 0x004F,
  697. OE: 0x0152,
  698. OEsmall: 0xF6FA,
  699. Oacute: 0x00D3,
  700. Oacutesmall: 0xF7F3,
  701. Obarredcyrillic: 0x04E8,
  702. Obarreddieresiscyrillic: 0x04EA,
  703. Obreve: 0x014E,
  704. Ocaron: 0x01D1,
  705. Ocenteredtilde: 0x019F,
  706. Ocircle: 0x24C4,
  707. Ocircumflex: 0x00D4,
  708. Ocircumflexacute: 0x1ED0,
  709. Ocircumflexdotbelow: 0x1ED8,
  710. Ocircumflexgrave: 0x1ED2,
  711. Ocircumflexhookabove: 0x1ED4,
  712. Ocircumflexsmall: 0xF7F4,
  713. Ocircumflextilde: 0x1ED6,
  714. Ocyrillic: 0x041E,
  715. Odblacute: 0x0150,
  716. Odblgrave: 0x020C,
  717. Odieresis: 0x00D6,
  718. Odieresiscyrillic: 0x04E6,
  719. Odieresissmall: 0xF7F6,
  720. Odotbelow: 0x1ECC,
  721. Ogoneksmall: 0xF6FB,
  722. Ograve: 0x00D2,
  723. Ogravesmall: 0xF7F2,
  724. Oharmenian: 0x0555,
  725. Ohm: 0x2126,
  726. Ohookabove: 0x1ECE,
  727. Ohorn: 0x01A0,
  728. Ohornacute: 0x1EDA,
  729. Ohorndotbelow: 0x1EE2,
  730. Ohorngrave: 0x1EDC,
  731. Ohornhookabove: 0x1EDE,
  732. Ohorntilde: 0x1EE0,
  733. Ohungarumlaut: 0x0150,
  734. Oi: 0x01A2,
  735. Oinvertedbreve: 0x020E,
  736. Omacron: 0x014C,
  737. Omacronacute: 0x1E52,
  738. Omacrongrave: 0x1E50,
  739. Omega: 0x2126,
  740. Omegacyrillic: 0x0460,
  741. Omegagreek: 0x03A9,
  742. Omegaroundcyrillic: 0x047A,
  743. Omegatitlocyrillic: 0x047C,
  744. Omegatonos: 0x038F,
  745. Omicron: 0x039F,
  746. Omicrontonos: 0x038C,
  747. Omonospace: 0xFF2F,
  748. Oneroman: 0x2160,
  749. Oogonek: 0x01EA,
  750. Oogonekmacron: 0x01EC,
  751. Oopen: 0x0186,
  752. Oslash: 0x00D8,
  753. Oslashacute: 0x01FE,
  754. Oslashsmall: 0xF7F8,
  755. Osmall: 0xF76F,
  756. Ostrokeacute: 0x01FE,
  757. Otcyrillic: 0x047E,
  758. Otilde: 0x00D5,
  759. Otildeacute: 0x1E4C,
  760. Otildedieresis: 0x1E4E,
  761. Otildesmall: 0xF7F5,
  762. P: 0x0050,
  763. Pacute: 0x1E54,
  764. Pcircle: 0x24C5,
  765. Pdotaccent: 0x1E56,
  766. Pecyrillic: 0x041F,
  767. Peharmenian: 0x054A,
  768. Pemiddlehookcyrillic: 0x04A6,
  769. Phi: 0x03A6,
  770. Phook: 0x01A4,
  771. Pi: 0x03A0,
  772. Piwrarmenian: 0x0553,
  773. Pmonospace: 0xFF30,
  774. Psi: 0x03A8,
  775. Psicyrillic: 0x0470,
  776. Psmall: 0xF770,
  777. Q: 0x0051,
  778. Qcircle: 0x24C6,
  779. Qmonospace: 0xFF31,
  780. Qsmall: 0xF771,
  781. R: 0x0052,
  782. Raarmenian: 0x054C,
  783. Racute: 0x0154,
  784. Rcaron: 0x0158,
  785. Rcedilla: 0x0156,
  786. Rcircle: 0x24C7,
  787. Rcommaaccent: 0x0156,
  788. Rdblgrave: 0x0210,
  789. Rdotaccent: 0x1E58,
  790. Rdotbelow: 0x1E5A,
  791. Rdotbelowmacron: 0x1E5C,
  792. Reharmenian: 0x0550,
  793. Rfraktur: 0x211C,
  794. Rho: 0x03A1,
  795. Ringsmall: 0xF6FC,
  796. Rinvertedbreve: 0x0212,
  797. Rlinebelow: 0x1E5E,
  798. Rmonospace: 0xFF32,
  799. Rsmall: 0xF772,
  800. Rsmallinverted: 0x0281,
  801. Rsmallinvertedsuperior: 0x02B6,
  802. S: 0x0053,
  803. SF010000: 0x250C,
  804. SF020000: 0x2514,
  805. SF030000: 0x2510,
  806. SF040000: 0x2518,
  807. SF050000: 0x253C,
  808. SF060000: 0x252C,
  809. SF070000: 0x2534,
  810. SF080000: 0x251C,
  811. SF090000: 0x2524,
  812. SF100000: 0x2500,
  813. SF110000: 0x2502,
  814. SF190000: 0x2561,
  815. SF200000: 0x2562,
  816. SF210000: 0x2556,
  817. SF220000: 0x2555,
  818. SF230000: 0x2563,
  819. SF240000: 0x2551,
  820. SF250000: 0x2557,
  821. SF260000: 0x255D,
  822. SF270000: 0x255C,
  823. SF280000: 0x255B,
  824. SF360000: 0x255E,
  825. SF370000: 0x255F,
  826. SF380000: 0x255A,
  827. SF390000: 0x2554,
  828. SF400000: 0x2569,
  829. SF410000: 0x2566,
  830. SF420000: 0x2560,
  831. SF430000: 0x2550,
  832. SF440000: 0x256C,
  833. SF450000: 0x2567,
  834. SF460000: 0x2568,
  835. SF470000: 0x2564,
  836. SF480000: 0x2565,
  837. SF490000: 0x2559,
  838. SF500000: 0x2558,
  839. SF510000: 0x2552,
  840. SF520000: 0x2553,
  841. SF530000: 0x256B,
  842. SF540000: 0x256A,
  843. Sacute: 0x015A,
  844. Sacutedotaccent: 0x1E64,
  845. Sampigreek: 0x03E0,
  846. Scaron: 0x0160,
  847. Scarondotaccent: 0x1E66,
  848. Scaronsmall: 0xF6FD,
  849. Scedilla: 0x015E,
  850. Schwa: 0x018F,
  851. Schwacyrillic: 0x04D8,
  852. Schwadieresiscyrillic: 0x04DA,
  853. Scircle: 0x24C8,
  854. Scircumflex: 0x015C,
  855. Scommaaccent: 0x0218,
  856. Sdotaccent: 0x1E60,
  857. Sdotbelow: 0x1E62,
  858. Sdotbelowdotaccent: 0x1E68,
  859. Seharmenian: 0x054D,
  860. Sevenroman: 0x2166,
  861. Shaarmenian: 0x0547,
  862. Shacyrillic: 0x0428,
  863. Shchacyrillic: 0x0429,
  864. Sheicoptic: 0x03E2,
  865. Shhacyrillic: 0x04BA,
  866. Shimacoptic: 0x03EC,
  867. Sigma: 0x03A3,
  868. Sixroman: 0x2165,
  869. Smonospace: 0xFF33,
  870. Softsigncyrillic: 0x042C,
  871. Ssmall: 0xF773,
  872. Stigmagreek: 0x03DA,
  873. T: 0x0054,
  874. Tau: 0x03A4,
  875. Tbar: 0x0166,
  876. Tcaron: 0x0164,
  877. Tcedilla: 0x0162,
  878. Tcircle: 0x24C9,
  879. Tcircumflexbelow: 0x1E70,
  880. Tcommaaccent: 0x0162,
  881. Tdotaccent: 0x1E6A,
  882. Tdotbelow: 0x1E6C,
  883. Tecyrillic: 0x0422,
  884. Tedescendercyrillic: 0x04AC,
  885. Tenroman: 0x2169,
  886. Tetsecyrillic: 0x04B4,
  887. Theta: 0x0398,
  888. Thook: 0x01AC,
  889. Thorn: 0x00DE,
  890. Thornsmall: 0xF7FE,
  891. Threeroman: 0x2162,
  892. Tildesmall: 0xF6FE,
  893. Tiwnarmenian: 0x054F,
  894. Tlinebelow: 0x1E6E,
  895. Tmonospace: 0xFF34,
  896. Toarmenian: 0x0539,
  897. Tonefive: 0x01BC,
  898. Tonesix: 0x0184,
  899. Tonetwo: 0x01A7,
  900. Tretroflexhook: 0x01AE,
  901. Tsecyrillic: 0x0426,
  902. Tshecyrillic: 0x040B,
  903. Tsmall: 0xF774,
  904. Twelveroman: 0x216B,
  905. Tworoman: 0x2161,
  906. U: 0x0055,
  907. Uacute: 0x00DA,
  908. Uacutesmall: 0xF7FA,
  909. Ubreve: 0x016C,
  910. Ucaron: 0x01D3,
  911. Ucircle: 0x24CA,
  912. Ucircumflex: 0x00DB,
  913. Ucircumflexbelow: 0x1E76,
  914. Ucircumflexsmall: 0xF7FB,
  915. Ucyrillic: 0x0423,
  916. Udblacute: 0x0170,
  917. Udblgrave: 0x0214,
  918. Udieresis: 0x00DC,
  919. Udieresisacute: 0x01D7,
  920. Udieresisbelow: 0x1E72,
  921. Udieresiscaron: 0x01D9,
  922. Udieresiscyrillic: 0x04F0,
  923. Udieresisgrave: 0x01DB,
  924. Udieresismacron: 0x01D5,
  925. Udieresissmall: 0xF7FC,
  926. Udotbelow: 0x1EE4,
  927. Ugrave: 0x00D9,
  928. Ugravesmall: 0xF7F9,
  929. Uhookabove: 0x1EE6,
  930. Uhorn: 0x01AF,
  931. Uhornacute: 0x1EE8,
  932. Uhorndotbelow: 0x1EF0,
  933. Uhorngrave: 0x1EEA,
  934. Uhornhookabove: 0x1EEC,
  935. Uhorntilde: 0x1EEE,
  936. Uhungarumlaut: 0x0170,
  937. Uhungarumlautcyrillic: 0x04F2,
  938. Uinvertedbreve: 0x0216,
  939. Ukcyrillic: 0x0478,
  940. Umacron: 0x016A,
  941. Umacroncyrillic: 0x04EE,
  942. Umacrondieresis: 0x1E7A,
  943. Umonospace: 0xFF35,
  944. Uogonek: 0x0172,
  945. Upsilon: 0x03A5,
  946. Upsilon1: 0x03D2,
  947. Upsilonacutehooksymbolgreek: 0x03D3,
  948. Upsilonafrican: 0x01B1,
  949. Upsilondieresis: 0x03AB,
  950. Upsilondieresishooksymbolgreek: 0x03D4,
  951. Upsilonhooksymbol: 0x03D2,
  952. Upsilontonos: 0x038E,
  953. Uring: 0x016E,
  954. Ushortcyrillic: 0x040E,
  955. Usmall: 0xF775,
  956. Ustraightcyrillic: 0x04AE,
  957. Ustraightstrokecyrillic: 0x04B0,
  958. Utilde: 0x0168,
  959. Utildeacute: 0x1E78,
  960. Utildebelow: 0x1E74,
  961. V: 0x0056,
  962. Vcircle: 0x24CB,
  963. Vdotbelow: 0x1E7E,
  964. Vecyrillic: 0x0412,
  965. Vewarmenian: 0x054E,
  966. Vhook: 0x01B2,
  967. Vmonospace: 0xFF36,
  968. Voarmenian: 0x0548,
  969. Vsmall: 0xF776,
  970. Vtilde: 0x1E7C,
  971. W: 0x0057,
  972. Wacute: 0x1E82,
  973. Wcircle: 0x24CC,
  974. Wcircumflex: 0x0174,
  975. Wdieresis: 0x1E84,
  976. Wdotaccent: 0x1E86,
  977. Wdotbelow: 0x1E88,
  978. Wgrave: 0x1E80,
  979. Wmonospace: 0xFF37,
  980. Wsmall: 0xF777,
  981. X: 0x0058,
  982. Xcircle: 0x24CD,
  983. Xdieresis: 0x1E8C,
  984. Xdotaccent: 0x1E8A,
  985. Xeharmenian: 0x053D,
  986. Xi: 0x039E,
  987. Xmonospace: 0xFF38,
  988. Xsmall: 0xF778,
  989. Y: 0x0059,
  990. Yacute: 0x00DD,
  991. Yacutesmall: 0xF7FD,
  992. Yatcyrillic: 0x0462,
  993. Ycircle: 0x24CE,
  994. Ycircumflex: 0x0176,
  995. Ydieresis: 0x0178,
  996. Ydieresissmall: 0xF7FF,
  997. Ydotaccent: 0x1E8E,
  998. Ydotbelow: 0x1EF4,
  999. Yericyrillic: 0x042B,
  1000. Yerudieresiscyrillic: 0x04F8,
  1001. Ygrave: 0x1EF2,
  1002. Yhook: 0x01B3,
  1003. Yhookabove: 0x1EF6,
  1004. Yiarmenian: 0x0545,
  1005. Yicyrillic: 0x0407,
  1006. Yiwnarmenian: 0x0552,
  1007. Ymonospace: 0xFF39,
  1008. Ysmall: 0xF779,
  1009. Ytilde: 0x1EF8,
  1010. Yusbigcyrillic: 0x046A,
  1011. Yusbigiotifiedcyrillic: 0x046C,
  1012. Yuslittlecyrillic: 0x0466,
  1013. Yuslittleiotifiedcyrillic: 0x0468,
  1014. Z: 0x005A,
  1015. Zaarmenian: 0x0536,
  1016. Zacute: 0x0179,
  1017. Zcaron: 0x017D,
  1018. Zcaronsmall: 0xF6FF,
  1019. Zcircle: 0x24CF,
  1020. Zcircumflex: 0x1E90,
  1021. Zdot: 0x017B,
  1022. Zdotaccent: 0x017B,
  1023. Zdotbelow: 0x1E92,
  1024. Zecyrillic: 0x0417,
  1025. Zedescendercyrillic: 0x0498,
  1026. Zedieresiscyrillic: 0x04DE,
  1027. Zeta: 0x0396,
  1028. Zhearmenian: 0x053A,
  1029. Zhebrevecyrillic: 0x04C1,
  1030. Zhecyrillic: 0x0416,
  1031. Zhedescendercyrillic: 0x0496,
  1032. Zhedieresiscyrillic: 0x04DC,
  1033. Zlinebelow: 0x1E94,
  1034. Zmonospace: 0xFF3A,
  1035. Zsmall: 0xF77A,
  1036. Zstroke: 0x01B5,
  1037. a: 0x0061,
  1038. aabengali: 0x0986,
  1039. aacute: 0x00E1,
  1040. aadeva: 0x0906,
  1041. aagujarati: 0x0A86,
  1042. aagurmukhi: 0x0A06,
  1043. aamatragurmukhi: 0x0A3E,
  1044. aarusquare: 0x3303,
  1045. aavowelsignbengali: 0x09BE,
  1046. aavowelsigndeva: 0x093E,
  1047. aavowelsigngujarati: 0x0ABE,
  1048. abbreviationmarkarmenian: 0x055F,
  1049. abbreviationsigndeva: 0x0970,
  1050. abengali: 0x0985,
  1051. abopomofo: 0x311A,
  1052. abreve: 0x0103,
  1053. abreveacute: 0x1EAF,
  1054. abrevecyrillic: 0x04D1,
  1055. abrevedotbelow: 0x1EB7,
  1056. abrevegrave: 0x1EB1,
  1057. abrevehookabove: 0x1EB3,
  1058. abrevetilde: 0x1EB5,
  1059. acaron: 0x01CE,
  1060. acircle: 0x24D0,
  1061. acircumflex: 0x00E2,
  1062. acircumflexacute: 0x1EA5,
  1063. acircumflexdotbelow: 0x1EAD,
  1064. acircumflexgrave: 0x1EA7,
  1065. acircumflexhookabove: 0x1EA9,
  1066. acircumflextilde: 0x1EAB,
  1067. acute: 0x00B4,
  1068. acutebelowcmb: 0x0317,
  1069. acutecmb: 0x0301,
  1070. acutecomb: 0x0301,
  1071. acutedeva: 0x0954,
  1072. acutelowmod: 0x02CF,
  1073. acutetonecmb: 0x0341,
  1074. acyrillic: 0x0430,
  1075. adblgrave: 0x0201,
  1076. addakgurmukhi: 0x0A71,
  1077. adeva: 0x0905,
  1078. adieresis: 0x00E4,
  1079. adieresiscyrillic: 0x04D3,
  1080. adieresismacron: 0x01DF,
  1081. adotbelow: 0x1EA1,
  1082. adotmacron: 0x01E1,
  1083. ae: 0x00E6,
  1084. aeacute: 0x01FD,
  1085. aekorean: 0x3150,
  1086. aemacron: 0x01E3,
  1087. afii00208: 0x2015,
  1088. afii08941: 0x20A4,
  1089. afii10017: 0x0410,
  1090. afii10018: 0x0411,
  1091. afii10019: 0x0412,
  1092. afii10020: 0x0413,
  1093. afii10021: 0x0414,
  1094. afii10022: 0x0415,
  1095. afii10023: 0x0401,
  1096. afii10024: 0x0416,
  1097. afii10025: 0x0417,
  1098. afii10026: 0x0418,
  1099. afii10027: 0x0419,
  1100. afii10028: 0x041A,
  1101. afii10029: 0x041B,
  1102. afii10030: 0x041C,
  1103. afii10031: 0x041D,
  1104. afii10032: 0x041E,
  1105. afii10033: 0x041F,
  1106. afii10034: 0x0420,
  1107. afii10035: 0x0421,
  1108. afii10036: 0x0422,
  1109. afii10037: 0x0423,
  1110. afii10038: 0x0424,
  1111. afii10039: 0x0425,
  1112. afii10040: 0x0426,
  1113. afii10041: 0x0427,
  1114. afii10042: 0x0428,
  1115. afii10043: 0x0429,
  1116. afii10044: 0x042A,
  1117. afii10045: 0x042B,
  1118. afii10046: 0x042C,
  1119. afii10047: 0x042D,
  1120. afii10048: 0x042E,
  1121. afii10049: 0x042F,
  1122. afii10050: 0x0490,
  1123. afii10051: 0x0402,
  1124. afii10052: 0x0403,
  1125. afii10053: 0x0404,
  1126. afii10054: 0x0405,
  1127. afii10055: 0x0406,
  1128. afii10056: 0x0407,
  1129. afii10057: 0x0408,
  1130. afii10058: 0x0409,
  1131. afii10059: 0x040A,
  1132. afii10060: 0x040B,
  1133. afii10061: 0x040C,
  1134. afii10062: 0x040E,
  1135. afii10063: 0xF6C4,
  1136. afii10064: 0xF6C5,
  1137. afii10065: 0x0430,
  1138. afii10066: 0x0431,
  1139. afii10067: 0x0432,
  1140. afii10068: 0x0433,
  1141. afii10069: 0x0434,
  1142. afii10070: 0x0435,
  1143. afii10071: 0x0451,
  1144. afii10072: 0x0436,
  1145. afii10073: 0x0437,
  1146. afii10074: 0x0438,
  1147. afii10075: 0x0439,
  1148. afii10076: 0x043A,
  1149. afii10077: 0x043B,
  1150. afii10078: 0x043C,
  1151. afii10079: 0x043D,
  1152. afii10080: 0x043E,
  1153. afii10081: 0x043F,
  1154. afii10082: 0x0440,
  1155. afii10083: 0x0441,
  1156. afii10084: 0x0442,
  1157. afii10085: 0x0443,
  1158. afii10086: 0x0444,
  1159. afii10087: 0x0445,
  1160. afii10088: 0x0446,
  1161. afii10089: 0x0447,
  1162. afii10090: 0x0448,
  1163. afii10091: 0x0449,
  1164. afii10092: 0x044A,
  1165. afii10093: 0x044B,
  1166. afii10094: 0x044C,
  1167. afii10095: 0x044D,
  1168. afii10096: 0x044E,
  1169. afii10097: 0x044F,
  1170. afii10098: 0x0491,
  1171. afii10099: 0x0452,
  1172. afii10100: 0x0453,
  1173. afii10101: 0x0454,
  1174. afii10102: 0x0455,
  1175. afii10103: 0x0456,
  1176. afii10104: 0x0457,
  1177. afii10105: 0x0458,
  1178. afii10106: 0x0459,
  1179. afii10107: 0x045A,
  1180. afii10108: 0x045B,
  1181. afii10109: 0x045C,
  1182. afii10110: 0x045E,
  1183. afii10145: 0x040F,
  1184. afii10146: 0x0462,
  1185. afii10147: 0x0472,
  1186. afii10148: 0x0474,
  1187. afii10192: 0xF6C6,
  1188. afii10193: 0x045F,
  1189. afii10194: 0x0463,
  1190. afii10195: 0x0473,
  1191. afii10196: 0x0475,
  1192. afii10831: 0xF6C7,
  1193. afii10832: 0xF6C8,
  1194. afii10846: 0x04D9,
  1195. afii299: 0x200E,
  1196. afii300: 0x200F,
  1197. afii301: 0x200D,
  1198. afii57381: 0x066A,
  1199. afii57388: 0x060C,
  1200. afii57392: 0x0660,
  1201. afii57393: 0x0661,
  1202. afii57394: 0x0662,
  1203. afii57395: 0x0663,
  1204. afii57396: 0x0664,
  1205. afii57397: 0x0665,
  1206. afii57398: 0x0666,
  1207. afii57399: 0x0667,
  1208. afii57400: 0x0668,
  1209. afii57401: 0x0669,
  1210. afii57403: 0x061B,
  1211. afii57407: 0x061F,
  1212. afii57409: 0x0621,
  1213. afii57410: 0x0622,
  1214. afii57411: 0x0623,
  1215. afii57412: 0x0624,
  1216. afii57413: 0x0625,
  1217. afii57414: 0x0626,
  1218. afii57415: 0x0627,
  1219. afii57416: 0x0628,
  1220. afii57417: 0x0629,
  1221. afii57418: 0x062A,
  1222. afii57419: 0x062B,
  1223. afii57420: 0x062C,
  1224. afii57421: 0x062D,
  1225. afii57422: 0x062E,
  1226. afii57423: 0x062F,
  1227. afii57424: 0x0630,
  1228. afii57425: 0x0631,
  1229. afii57426: 0x0632,
  1230. afii57427: 0x0633,
  1231. afii57428: 0x0634,
  1232. afii57429: 0x0635,
  1233. afii57430: 0x0636,
  1234. afii57431: 0x0637,
  1235. afii57432: 0x0638,
  1236. afii57433: 0x0639,
  1237. afii57434: 0x063A,
  1238. afii57440: 0x0640,
  1239. afii57441: 0x0641,
  1240. afii57442: 0x0642,
  1241. afii57443: 0x0643,
  1242. afii57444: 0x0644,
  1243. afii57445: 0x0645,
  1244. afii57446: 0x0646,
  1245. afii57448: 0x0648,
  1246. afii57449: 0x0649,
  1247. afii57450: 0x064A,
  1248. afii57451: 0x064B,
  1249. afii57452: 0x064C,
  1250. afii57453: 0x064D,
  1251. afii57454: 0x064E,
  1252. afii57455: 0x064F,
  1253. afii57456: 0x0650,
  1254. afii57457: 0x0651,
  1255. afii57458: 0x0652,
  1256. afii57470: 0x0647,
  1257. afii57505: 0x06A4,
  1258. afii57506: 0x067E,
  1259. afii57507: 0x0686,
  1260. afii57508: 0x0698,
  1261. afii57509: 0x06AF,
  1262. afii57511: 0x0679,
  1263. afii57512: 0x0688,
  1264. afii57513: 0x0691,
  1265. afii57514: 0x06BA,
  1266. afii57519: 0x06D2,
  1267. afii57534: 0x06D5,
  1268. afii57636: 0x20AA,
  1269. afii57645: 0x05BE,
  1270. afii57658: 0x05C3,
  1271. afii57664: 0x05D0,
  1272. afii57665: 0x05D1,
  1273. afii57666: 0x05D2,
  1274. afii57667: 0x05D3,
  1275. afii57668: 0x05D4,
  1276. afii57669: 0x05D5,
  1277. afii57670: 0x05D6,
  1278. afii57671: 0x05D7,
  1279. afii57672: 0x05D8,
  1280. afii57673: 0x05D9,
  1281. afii57674: 0x05DA,
  1282. afii57675: 0x05DB,
  1283. afii57676: 0x05DC,
  1284. afii57677: 0x05DD,
  1285. afii57678: 0x05DE,
  1286. afii57679: 0x05DF,
  1287. afii57680: 0x05E0,
  1288. afii57681: 0x05E1,
  1289. afii57682: 0x05E2,
  1290. afii57683: 0x05E3,
  1291. afii57684: 0x05E4,
  1292. afii57685: 0x05E5,
  1293. afii57686: 0x05E6,
  1294. afii57687: 0x05E7,
  1295. afii57688: 0x05E8,
  1296. afii57689: 0x05E9,
  1297. afii57690: 0x05EA,
  1298. afii57694: 0xFB2A,
  1299. afii57695: 0xFB2B,
  1300. afii57700: 0xFB4B,
  1301. afii57705: 0xFB1F,
  1302. afii57716: 0x05F0,
  1303. afii57717: 0x05F1,
  1304. afii57718: 0x05F2,
  1305. afii57723: 0xFB35,
  1306. afii57793: 0x05B4,
  1307. afii57794: 0x05B5,
  1308. afii57795: 0x05B6,
  1309. afii57796: 0x05BB,
  1310. afii57797: 0x05B8,
  1311. afii57798: 0x05B7,
  1312. afii57799: 0x05B0,
  1313. afii57800: 0x05B2,
  1314. afii57801: 0x05B1,
  1315. afii57802: 0x05B3,
  1316. afii57803: 0x05C2,
  1317. afii57804: 0x05C1,
  1318. afii57806: 0x05B9,
  1319. afii57807: 0x05BC,
  1320. afii57839: 0x05BD,
  1321. afii57841: 0x05BF,
  1322. afii57842: 0x05C0,
  1323. afii57929: 0x02BC,
  1324. afii61248: 0x2105,
  1325. afii61289: 0x2113,
  1326. afii61352: 0x2116,
  1327. afii61573: 0x202C,
  1328. afii61574: 0x202D,
  1329. afii61575: 0x202E,
  1330. afii61664: 0x200C,
  1331. afii63167: 0x066D,
  1332. afii64937: 0x02BD,
  1333. agrave: 0x00E0,
  1334. agujarati: 0x0A85,
  1335. agurmukhi: 0x0A05,
  1336. ahiragana: 0x3042,
  1337. ahookabove: 0x1EA3,
  1338. aibengali: 0x0990,
  1339. aibopomofo: 0x311E,
  1340. aideva: 0x0910,
  1341. aiecyrillic: 0x04D5,
  1342. aigujarati: 0x0A90,
  1343. aigurmukhi: 0x0A10,
  1344. aimatragurmukhi: 0x0A48,
  1345. ainarabic: 0x0639,
  1346. ainfinalarabic: 0xFECA,
  1347. aininitialarabic: 0xFECB,
  1348. ainmedialarabic: 0xFECC,
  1349. ainvertedbreve: 0x0203,
  1350. aivowelsignbengali: 0x09C8,
  1351. aivowelsigndeva: 0x0948,
  1352. aivowelsigngujarati: 0x0AC8,
  1353. akatakana: 0x30A2,
  1354. akatakanahalfwidth: 0xFF71,
  1355. akorean: 0x314F,
  1356. alef: 0x05D0,
  1357. alefarabic: 0x0627,
  1358. alefdageshhebrew: 0xFB30,
  1359. aleffinalarabic: 0xFE8E,
  1360. alefhamzaabovearabic: 0x0623,
  1361. alefhamzaabovefinalarabic: 0xFE84,
  1362. alefhamzabelowarabic: 0x0625,
  1363. alefhamzabelowfinalarabic: 0xFE88,
  1364. alefhebrew: 0x05D0,
  1365. aleflamedhebrew: 0xFB4F,
  1366. alefmaddaabovearabic: 0x0622,
  1367. alefmaddaabovefinalarabic: 0xFE82,
  1368. alefmaksuraarabic: 0x0649,
  1369. alefmaksurafinalarabic: 0xFEF0,
  1370. alefmaksurainitialarabic: 0xFEF3,
  1371. alefmaksuramedialarabic: 0xFEF4,
  1372. alefpatahhebrew: 0xFB2E,
  1373. alefqamatshebrew: 0xFB2F,
  1374. aleph: 0x2135,
  1375. allequal: 0x224C,
  1376. alpha: 0x03B1,
  1377. alphatonos: 0x03AC,
  1378. amacron: 0x0101,
  1379. amonospace: 0xFF41,
  1380. ampersand: 0x0026,
  1381. ampersandmonospace: 0xFF06,
  1382. ampersandsmall: 0xF726,
  1383. amsquare: 0x33C2,
  1384. anbopomofo: 0x3122,
  1385. angbopomofo: 0x3124,
  1386. angbracketleft: 0x3008, // This glyph is missing from Adobe's original list.
  1387. angbracketright: 0x3009, // This glyph is missing from Adobe's original list.
  1388. angkhankhuthai: 0x0E5A,
  1389. angle: 0x2220,
  1390. anglebracketleft: 0x3008,
  1391. anglebracketleftvertical: 0xFE3F,
  1392. anglebracketright: 0x3009,
  1393. anglebracketrightvertical: 0xFE40,
  1394. angleleft: 0x2329,
  1395. angleright: 0x232A,
  1396. angstrom: 0x212B,
  1397. anoteleia: 0x0387,
  1398. anudattadeva: 0x0952,
  1399. anusvarabengali: 0x0982,
  1400. anusvaradeva: 0x0902,
  1401. anusvaragujarati: 0x0A82,
  1402. aogonek: 0x0105,
  1403. apaatosquare: 0x3300,
  1404. aparen: 0x249C,
  1405. apostrophearmenian: 0x055A,
  1406. apostrophemod: 0x02BC,
  1407. apple: 0xF8FF,
  1408. approaches: 0x2250,
  1409. approxequal: 0x2248,
  1410. approxequalorimage: 0x2252,
  1411. approximatelyequal: 0x2245,
  1412. araeaekorean: 0x318E,
  1413. araeakorean: 0x318D,
  1414. arc: 0x2312,
  1415. arighthalfring: 0x1E9A,
  1416. aring: 0x00E5,
  1417. aringacute: 0x01FB,
  1418. aringbelow: 0x1E01,
  1419. arrowboth: 0x2194,
  1420. arrowdashdown: 0x21E3,
  1421. arrowdashleft: 0x21E0,
  1422. arrowdashright: 0x21E2,
  1423. arrowdashup: 0x21E1,
  1424. arrowdblboth: 0x21D4,
  1425. arrowdbldown: 0x21D3,
  1426. arrowdblleft: 0x21D0,
  1427. arrowdblright: 0x21D2,
  1428. arrowdblup: 0x21D1,
  1429. arrowdown: 0x2193,
  1430. arrowdownleft: 0x2199,
  1431. arrowdownright: 0x2198,
  1432. arrowdownwhite: 0x21E9,
  1433. arrowheaddownmod: 0x02C5,
  1434. arrowheadleftmod: 0x02C2,
  1435. arrowheadrightmod: 0x02C3,
  1436. arrowheadupmod: 0x02C4,
  1437. arrowhorizex: 0xF8E7,
  1438. arrowleft: 0x2190,
  1439. arrowleftdbl: 0x21D0,
  1440. arrowleftdblstroke: 0x21CD,
  1441. arrowleftoverright: 0x21C6,
  1442. arrowleftwhite: 0x21E6,
  1443. arrowright: 0x2192,
  1444. arrowrightdblstroke: 0x21CF,
  1445. arrowrightheavy: 0x279E,
  1446. arrowrightoverleft: 0x21C4,
  1447. arrowrightwhite: 0x21E8,
  1448. arrowtableft: 0x21E4,
  1449. arrowtabright: 0x21E5,
  1450. arrowup: 0x2191,
  1451. arrowupdn: 0x2195,
  1452. arrowupdnbse: 0x21A8,
  1453. arrowupdownbase: 0x21A8,
  1454. arrowupleft: 0x2196,
  1455. arrowupleftofdown: 0x21C5,
  1456. arrowupright: 0x2197,
  1457. arrowupwhite: 0x21E7,
  1458. arrowvertex: 0xF8E6,
  1459. asciicircum: 0x005E,
  1460. asciicircummonospace: 0xFF3E,
  1461. asciitilde: 0x007E,
  1462. asciitildemonospace: 0xFF5E,
  1463. ascript: 0x0251,
  1464. ascriptturned: 0x0252,
  1465. asmallhiragana: 0x3041,
  1466. asmallkatakana: 0x30A1,
  1467. asmallkatakanahalfwidth: 0xFF67,
  1468. asterisk: 0x002A,
  1469. asteriskaltonearabic: 0x066D,
  1470. asteriskarabic: 0x066D,
  1471. asteriskmath: 0x2217,
  1472. asteriskmonospace: 0xFF0A,
  1473. asterisksmall: 0xFE61,
  1474. asterism: 0x2042,
  1475. asuperior: 0xF6E9,
  1476. asymptoticallyequal: 0x2243,
  1477. at: 0x0040,
  1478. atilde: 0x00E3,
  1479. atmonospace: 0xFF20,
  1480. atsmall: 0xFE6B,
  1481. aturned: 0x0250,
  1482. aubengali: 0x0994,
  1483. aubopomofo: 0x3120,
  1484. audeva: 0x0914,
  1485. augujarati: 0x0A94,
  1486. augurmukhi: 0x0A14,
  1487. aulengthmarkbengali: 0x09D7,
  1488. aumatragurmukhi: 0x0A4C,
  1489. auvowelsignbengali: 0x09CC,
  1490. auvowelsigndeva: 0x094C,
  1491. auvowelsigngujarati: 0x0ACC,
  1492. avagrahadeva: 0x093D,
  1493. aybarmenian: 0x0561,
  1494. ayin: 0x05E2,
  1495. ayinaltonehebrew: 0xFB20,
  1496. ayinhebrew: 0x05E2,
  1497. b: 0x0062,
  1498. babengali: 0x09AC,
  1499. backslash: 0x005C,
  1500. backslashmonospace: 0xFF3C,
  1501. badeva: 0x092C,
  1502. bagujarati: 0x0AAC,
  1503. bagurmukhi: 0x0A2C,
  1504. bahiragana: 0x3070,
  1505. bahtthai: 0x0E3F,
  1506. bakatakana: 0x30D0,
  1507. bar: 0x007C,
  1508. barmonospace: 0xFF5C,
  1509. bbopomofo: 0x3105,
  1510. bcircle: 0x24D1,
  1511. bdotaccent: 0x1E03,
  1512. bdotbelow: 0x1E05,
  1513. beamedsixteenthnotes: 0x266C,
  1514. because: 0x2235,
  1515. becyrillic: 0x0431,
  1516. beharabic: 0x0628,
  1517. behfinalarabic: 0xFE90,
  1518. behinitialarabic: 0xFE91,
  1519. behiragana: 0x3079,
  1520. behmedialarabic: 0xFE92,
  1521. behmeeminitialarabic: 0xFC9F,
  1522. behmeemisolatedarabic: 0xFC08,
  1523. behnoonfinalarabic: 0xFC6D,
  1524. bekatakana: 0x30D9,
  1525. benarmenian: 0x0562,
  1526. bet: 0x05D1,
  1527. beta: 0x03B2,
  1528. betasymbolgreek: 0x03D0,
  1529. betdagesh: 0xFB31,
  1530. betdageshhebrew: 0xFB31,
  1531. bethebrew: 0x05D1,
  1532. betrafehebrew: 0xFB4C,
  1533. bhabengali: 0x09AD,
  1534. bhadeva: 0x092D,
  1535. bhagujarati: 0x0AAD,
  1536. bhagurmukhi: 0x0A2D,
  1537. bhook: 0x0253,
  1538. bihiragana: 0x3073,
  1539. bikatakana: 0x30D3,
  1540. bilabialclick: 0x0298,
  1541. bindigurmukhi: 0x0A02,
  1542. birusquare: 0x3331,
  1543. blackcircle: 0x25CF,
  1544. blackdiamond: 0x25C6,
  1545. blackdownpointingtriangle: 0x25BC,
  1546. blackleftpointingpointer: 0x25C4,
  1547. blackleftpointingtriangle: 0x25C0,
  1548. blacklenticularbracketleft: 0x3010,
  1549. blacklenticularbracketleftvertical: 0xFE3B,
  1550. blacklenticularbracketright: 0x3011,
  1551. blacklenticularbracketrightvertical: 0xFE3C,
  1552. blacklowerlefttriangle: 0x25E3,
  1553. blacklowerrighttriangle: 0x25E2,
  1554. blackrectangle: 0x25AC,
  1555. blackrightpointingpointer: 0x25BA,
  1556. blackrightpointingtriangle: 0x25B6,
  1557. blacksmallsquare: 0x25AA,
  1558. blacksmilingface: 0x263B,
  1559. blacksquare: 0x25A0,
  1560. blackstar: 0x2605,
  1561. blackupperlefttriangle: 0x25E4,
  1562. blackupperrighttriangle: 0x25E5,
  1563. blackuppointingsmalltriangle: 0x25B4,
  1564. blackuppointingtriangle: 0x25B2,
  1565. blank: 0x2423,
  1566. blinebelow: 0x1E07,
  1567. block: 0x2588,
  1568. bmonospace: 0xFF42,
  1569. bobaimaithai: 0x0E1A,
  1570. bohiragana: 0x307C,
  1571. bokatakana: 0x30DC,
  1572. bparen: 0x249D,
  1573. bqsquare: 0x33C3,
  1574. braceex: 0xF8F4,
  1575. braceleft: 0x007B,
  1576. braceleftbt: 0xF8F3,
  1577. braceleftmid: 0xF8F2,
  1578. braceleftmonospace: 0xFF5B,
  1579. braceleftsmall: 0xFE5B,
  1580. bracelefttp: 0xF8F1,
  1581. braceleftvertical: 0xFE37,
  1582. braceright: 0x007D,
  1583. bracerightbt: 0xF8FE,
  1584. bracerightmid: 0xF8FD,
  1585. bracerightmonospace: 0xFF5D,
  1586. bracerightsmall: 0xFE5C,
  1587. bracerighttp: 0xF8FC,
  1588. bracerightvertical: 0xFE38,
  1589. bracketleft: 0x005B,
  1590. bracketleftbt: 0xF8F0,
  1591. bracketleftex: 0xF8EF,
  1592. bracketleftmonospace: 0xFF3B,
  1593. bracketlefttp: 0xF8EE,
  1594. bracketright: 0x005D,
  1595. bracketrightbt: 0xF8FB,
  1596. bracketrightex: 0xF8FA,
  1597. bracketrightmonospace: 0xFF3D,
  1598. bracketrighttp: 0xF8F9,
  1599. breve: 0x02D8,
  1600. brevebelowcmb: 0x032E,
  1601. brevecmb: 0x0306,
  1602. breveinvertedbelowcmb: 0x032F,
  1603. breveinvertedcmb: 0x0311,
  1604. breveinverteddoublecmb: 0x0361,
  1605. bridgebelowcmb: 0x032A,
  1606. bridgeinvertedbelowcmb: 0x033A,
  1607. brokenbar: 0x00A6,
  1608. bstroke: 0x0180,
  1609. bsuperior: 0xF6EA,
  1610. btopbar: 0x0183,
  1611. buhiragana: 0x3076,
  1612. bukatakana: 0x30D6,
  1613. bullet: 0x2022,
  1614. bulletinverse: 0x25D8,
  1615. bulletoperator: 0x2219,
  1616. bullseye: 0x25CE,
  1617. c: 0x0063,
  1618. caarmenian: 0x056E,
  1619. cabengali: 0x099A,
  1620. cacute: 0x0107,
  1621. cadeva: 0x091A,
  1622. cagujarati: 0x0A9A,
  1623. cagurmukhi: 0x0A1A,
  1624. calsquare: 0x3388,
  1625. candrabindubengali: 0x0981,
  1626. candrabinducmb: 0x0310,
  1627. candrabindudeva: 0x0901,
  1628. candrabindugujarati: 0x0A81,
  1629. capslock: 0x21EA,
  1630. careof: 0x2105,
  1631. caron: 0x02C7,
  1632. caronbelowcmb: 0x032C,
  1633. caroncmb: 0x030C,
  1634. carriagereturn: 0x21B5,
  1635. cbopomofo: 0x3118,
  1636. ccaron: 0x010D,
  1637. ccedilla: 0x00E7,
  1638. ccedillaacute: 0x1E09,
  1639. ccircle: 0x24D2,
  1640. ccircumflex: 0x0109,
  1641. ccurl: 0x0255,
  1642. cdot: 0x010B,
  1643. cdotaccent: 0x010B,
  1644. cdsquare: 0x33C5,
  1645. cedilla: 0x00B8,
  1646. cedillacmb: 0x0327,
  1647. cent: 0x00A2,
  1648. centigrade: 0x2103,
  1649. centinferior: 0xF6DF,
  1650. centmonospace: 0xFFE0,
  1651. centoldstyle: 0xF7A2,
  1652. centsuperior: 0xF6E0,
  1653. chaarmenian: 0x0579,
  1654. chabengali: 0x099B,
  1655. chadeva: 0x091B,
  1656. chagujarati: 0x0A9B,
  1657. chagurmukhi: 0x0A1B,
  1658. chbopomofo: 0x3114,
  1659. cheabkhasiancyrillic: 0x04BD,
  1660. checkmark: 0x2713,
  1661. checyrillic: 0x0447,
  1662. chedescenderabkhasiancyrillic: 0x04BF,
  1663. chedescendercyrillic: 0x04B7,
  1664. chedieresiscyrillic: 0x04F5,
  1665. cheharmenian: 0x0573,
  1666. chekhakassiancyrillic: 0x04CC,
  1667. cheverticalstrokecyrillic: 0x04B9,
  1668. chi: 0x03C7,
  1669. chieuchacirclekorean: 0x3277,
  1670. chieuchaparenkorean: 0x3217,
  1671. chieuchcirclekorean: 0x3269,
  1672. chieuchkorean: 0x314A,
  1673. chieuchparenkorean: 0x3209,
  1674. chochangthai: 0x0E0A,
  1675. chochanthai: 0x0E08,
  1676. chochingthai: 0x0E09,
  1677. chochoethai: 0x0E0C,
  1678. chook: 0x0188,
  1679. cieucacirclekorean: 0x3276,
  1680. cieucaparenkorean: 0x3216,
  1681. cieuccirclekorean: 0x3268,
  1682. cieuckorean: 0x3148,
  1683. cieucparenkorean: 0x3208,
  1684. cieucuparenkorean: 0x321C,
  1685. circle: 0x25CB,
  1686. circlecopyrt: 0x00A9, // This glyph is missing from Adobe's original list.
  1687. circlemultiply: 0x2297,
  1688. circleot: 0x2299,
  1689. circleplus: 0x2295,
  1690. circlepostalmark: 0x3036,
  1691. circlewithlefthalfblack: 0x25D0,
  1692. circlewithrighthalfblack: 0x25D1,
  1693. circumflex: 0x02C6,
  1694. circumflexbelowcmb: 0x032D,
  1695. circumflexcmb: 0x0302,
  1696. clear: 0x2327,
  1697. clickalveolar: 0x01C2,
  1698. clickdental: 0x01C0,
  1699. clicklateral: 0x01C1,
  1700. clickretroflex: 0x01C3,
  1701. club: 0x2663,
  1702. clubsuitblack: 0x2663,
  1703. clubsuitwhite: 0x2667,
  1704. cmcubedsquare: 0x33A4,
  1705. cmonospace: 0xFF43,
  1706. cmsquaredsquare: 0x33A0,
  1707. coarmenian: 0x0581,
  1708. colon: 0x003A,
  1709. colonmonetary: 0x20A1,
  1710. colonmonospace: 0xFF1A,
  1711. colonsign: 0x20A1,
  1712. colonsmall: 0xFE55,
  1713. colontriangularhalfmod: 0x02D1,
  1714. colontriangularmod: 0x02D0,
  1715. comma: 0x002C,
  1716. commaabovecmb: 0x0313,
  1717. commaaboverightcmb: 0x0315,
  1718. commaaccent: 0xF6C3,
  1719. commaarabic: 0x060C,
  1720. commaarmenian: 0x055D,
  1721. commainferior: 0xF6E1,
  1722. commamonospace: 0xFF0C,
  1723. commareversedabovecmb: 0x0314,
  1724. commareversedmod: 0x02BD,
  1725. commasmall: 0xFE50,
  1726. commasuperior: 0xF6E2,
  1727. commaturnedabovecmb: 0x0312,
  1728. commaturnedmod: 0x02BB,
  1729. compass: 0x263C,
  1730. congruent: 0x2245,
  1731. contourintegral: 0x222E,
  1732. control: 0x2303,
  1733. controlACK: 0x0006,
  1734. controlBEL: 0x0007,
  1735. controlBS: 0x0008,
  1736. controlCAN: 0x0018,
  1737. controlCR: 0x000D,
  1738. controlDC1: 0x0011,
  1739. controlDC2: 0x0012,
  1740. controlDC3: 0x0013,
  1741. controlDC4: 0x0014,
  1742. controlDEL: 0x007F,
  1743. controlDLE: 0x0010,
  1744. controlEM: 0x0019,
  1745. controlENQ: 0x0005,
  1746. controlEOT: 0x0004,
  1747. controlESC: 0x001B,
  1748. controlETB: 0x0017,
  1749. controlETX: 0x0003,
  1750. controlFF: 0x000C,
  1751. controlFS: 0x001C,
  1752. controlGS: 0x001D,
  1753. controlHT: 0x0009,
  1754. controlLF: 0x000A,
  1755. controlNAK: 0x0015,
  1756. controlRS: 0x001E,
  1757. controlSI: 0x000F,
  1758. controlSO: 0x000E,
  1759. controlSOT: 0x0002,
  1760. controlSTX: 0x0001,
  1761. controlSUB: 0x001A,
  1762. controlSYN: 0x0016,
  1763. controlUS: 0x001F,
  1764. controlVT: 0x000B,
  1765. copyright: 0x00A9,
  1766. copyrightsans: 0xF8E9,
  1767. copyrightserif: 0xF6D9,
  1768. cornerbracketleft: 0x300C,
  1769. cornerbracketlefthalfwidth: 0xFF62,
  1770. cornerbracketleftvertical: 0xFE41,
  1771. cornerbracketright: 0x300D,
  1772. cornerbracketrighthalfwidth: 0xFF63,
  1773. cornerbracketrightvertical: 0xFE42,
  1774. corporationsquare: 0x337F,
  1775. cosquare: 0x33C7,
  1776. coverkgsquare: 0x33C6,
  1777. cparen: 0x249E,
  1778. cruzeiro: 0x20A2,
  1779. cstretched: 0x0297,
  1780. curlyand: 0x22CF,
  1781. curlyor: 0x22CE,
  1782. currency: 0x00A4,
  1783. cyrBreve: 0xF6D1,
  1784. cyrFlex: 0xF6D2,
  1785. cyrbreve: 0xF6D4,
  1786. cyrflex: 0xF6D5,
  1787. d: 0x0064,
  1788. daarmenian: 0x0564,
  1789. dabengali: 0x09A6,
  1790. dadarabic: 0x0636,
  1791. dadeva: 0x0926,
  1792. dadfinalarabic: 0xFEBE,
  1793. dadinitialarabic: 0xFEBF,
  1794. dadmedialarabic: 0xFEC0,
  1795. dagesh: 0x05BC,
  1796. dageshhebrew: 0x05BC,
  1797. dagger: 0x2020,
  1798. daggerdbl: 0x2021,
  1799. dagujarati: 0x0AA6,
  1800. dagurmukhi: 0x0A26,
  1801. dahiragana: 0x3060,
  1802. dakatakana: 0x30C0,
  1803. dalarabic: 0x062F,
  1804. dalet: 0x05D3,
  1805. daletdagesh: 0xFB33,
  1806. daletdageshhebrew: 0xFB33,
  1807. dalethebrew: 0x05D3,
  1808. dalfinalarabic: 0xFEAA,
  1809. dammaarabic: 0x064F,
  1810. dammalowarabic: 0x064F,
  1811. dammatanaltonearabic: 0x064C,
  1812. dammatanarabic: 0x064C,
  1813. danda: 0x0964,
  1814. dargahebrew: 0x05A7,
  1815. dargalefthebrew: 0x05A7,
  1816. dasiapneumatacyrilliccmb: 0x0485,
  1817. dblGrave: 0xF6D3,
  1818. dblanglebracketleft: 0x300A,
  1819. dblanglebracketleftvertical: 0xFE3D,
  1820. dblanglebracketright: 0x300B,
  1821. dblanglebracketrightvertical: 0xFE3E,
  1822. dblarchinvertedbelowcmb: 0x032B,
  1823. dblarrowleft: 0x21D4,
  1824. dblarrowright: 0x21D2,
  1825. dbldanda: 0x0965,
  1826. dblgrave: 0xF6D6,
  1827. dblgravecmb: 0x030F,
  1828. dblintegral: 0x222C,
  1829. dbllowline: 0x2017,
  1830. dbllowlinecmb: 0x0333,
  1831. dbloverlinecmb: 0x033F,
  1832. dblprimemod: 0x02BA,
  1833. dblverticalbar: 0x2016,
  1834. dblverticallineabovecmb: 0x030E,
  1835. dbopomofo: 0x3109,
  1836. dbsquare: 0x33C8,
  1837. dcaron: 0x010F,
  1838. dcedilla: 0x1E11,
  1839. dcircle: 0x24D3,
  1840. dcircumflexbelow: 0x1E13,
  1841. dcroat: 0x0111,
  1842. ddabengali: 0x09A1,
  1843. ddadeva: 0x0921,
  1844. ddagujarati: 0x0AA1,
  1845. ddagurmukhi: 0x0A21,
  1846. ddalarabic: 0x0688,
  1847. ddalfinalarabic: 0xFB89,
  1848. dddhadeva: 0x095C,
  1849. ddhabengali: 0x09A2,
  1850. ddhadeva: 0x0922,
  1851. ddhagujarati: 0x0AA2,
  1852. ddhagurmukhi: 0x0A22,
  1853. ddotaccent: 0x1E0B,
  1854. ddotbelow: 0x1E0D,
  1855. decimalseparatorarabic: 0x066B,
  1856. decimalseparatorpersian: 0x066B,
  1857. decyrillic: 0x0434,
  1858. degree: 0x00B0,
  1859. dehihebrew: 0x05AD,
  1860. dehiragana: 0x3067,
  1861. deicoptic: 0x03EF,
  1862. dekatakana: 0x30C7,
  1863. deleteleft: 0x232B,
  1864. deleteright: 0x2326,
  1865. delta: 0x03B4,
  1866. deltaturned: 0x018D,
  1867. denominatorminusonenumeratorbengali: 0x09F8,
  1868. dezh: 0x02A4,
  1869. dhabengali: 0x09A7,
  1870. dhadeva: 0x0927,
  1871. dhagujarati: 0x0AA7,
  1872. dhagurmukhi: 0x0A27,
  1873. dhook: 0x0257,
  1874. dialytikatonos: 0x0385,
  1875. dialytikatonoscmb: 0x0344,
  1876. diamond: 0x2666,
  1877. diamondsuitwhite: 0x2662,
  1878. dieresis: 0x00A8,
  1879. dieresisacute: 0xF6D7,
  1880. dieresisbelowcmb: 0x0324,
  1881. dieresiscmb: 0x0308,
  1882. dieresisgrave: 0xF6D8,
  1883. dieresistonos: 0x0385,
  1884. dihiragana: 0x3062,
  1885. dikatakana: 0x30C2,
  1886. dittomark: 0x3003,
  1887. divide: 0x00F7,
  1888. divides: 0x2223,
  1889. divisionslash: 0x2215,
  1890. djecyrillic: 0x0452,
  1891. dkshade: 0x2593,
  1892. dlinebelow: 0x1E0F,
  1893. dlsquare: 0x3397,
  1894. dmacron: 0x0111,
  1895. dmonospace: 0xFF44,
  1896. dnblock: 0x2584,
  1897. dochadathai: 0x0E0E,
  1898. dodekthai: 0x0E14,
  1899. dohiragana: 0x3069,
  1900. dokatakana: 0x30C9,
  1901. dollar: 0x0024,
  1902. dollarinferior: 0xF6E3,
  1903. dollarmonospace: 0xFF04,
  1904. dollaroldstyle: 0xF724,
  1905. dollarsmall: 0xFE69,
  1906. dollarsuperior: 0xF6E4,
  1907. dong: 0x20AB,
  1908. dorusquare: 0x3326,
  1909. dotaccent: 0x02D9,
  1910. dotaccentcmb: 0x0307,
  1911. dotbelowcmb: 0x0323,
  1912. dotbelowcomb: 0x0323,
  1913. dotkatakana: 0x30FB,
  1914. dotlessi: 0x0131,
  1915. dotlessj: 0xF6BE,
  1916. dotlessjstrokehook: 0x0284,
  1917. dotmath: 0x22C5,
  1918. dottedcircle: 0x25CC,
  1919. doubleyodpatah: 0xFB1F,
  1920. doubleyodpatahhebrew: 0xFB1F,
  1921. downtackbelowcmb: 0x031E,
  1922. downtackmod: 0x02D5,
  1923. dparen: 0x249F,
  1924. dsuperior: 0xF6EB,
  1925. dtail: 0x0256,
  1926. dtopbar: 0x018C,
  1927. duhiragana: 0x3065,
  1928. dukatakana: 0x30C5,
  1929. dz: 0x01F3,
  1930. dzaltone: 0x02A3,
  1931. dzcaron: 0x01C6,
  1932. dzcurl: 0x02A5,
  1933. dzeabkhasiancyrillic: 0x04E1,
  1934. dzecyrillic: 0x0455,
  1935. dzhecyrillic: 0x045F,
  1936. e: 0x0065,
  1937. eacute: 0x00E9,
  1938. earth: 0x2641,
  1939. ebengali: 0x098F,
  1940. ebopomofo: 0x311C,
  1941. ebreve: 0x0115,
  1942. ecandradeva: 0x090D,
  1943. ecandragujarati: 0x0A8D,
  1944. ecandravowelsigndeva: 0x0945,
  1945. ecandravowelsigngujarati: 0x0AC5,
  1946. ecaron: 0x011B,
  1947. ecedillabreve: 0x1E1D,
  1948. echarmenian: 0x0565,
  1949. echyiwnarmenian: 0x0587,
  1950. ecircle: 0x24D4,
  1951. ecircumflex: 0x00EA,
  1952. ecircumflexacute: 0x1EBF,
  1953. ecircumflexbelow: 0x1E19,
  1954. ecircumflexdotbelow: 0x1EC7,
  1955. ecircumflexgrave: 0x1EC1,
  1956. ecircumflexhookabove: 0x1EC3,
  1957. ecircumflextilde: 0x1EC5,
  1958. ecyrillic: 0x0454,
  1959. edblgrave: 0x0205,
  1960. edeva: 0x090F,
  1961. edieresis: 0x00EB,
  1962. edot: 0x0117,
  1963. edotaccent: 0x0117,
  1964. edotbelow: 0x1EB9,
  1965. eegurmukhi: 0x0A0F,
  1966. eematragurmukhi: 0x0A47,
  1967. efcyrillic: 0x0444,
  1968. egrave: 0x00E8,
  1969. egujarati: 0x0A8F,
  1970. eharmenian: 0x0567,
  1971. ehbopomofo: 0x311D,
  1972. ehiragana: 0x3048,
  1973. ehookabove: 0x1EBB,
  1974. eibopomofo: 0x311F,
  1975. eight: 0x0038,
  1976. eightarabic: 0x0668,
  1977. eightbengali: 0x09EE,
  1978. eightcircle: 0x2467,
  1979. eightcircleinversesansserif: 0x2791,
  1980. eightdeva: 0x096E,
  1981. eighteencircle: 0x2471,
  1982. eighteenparen: 0x2485,
  1983. eighteenperiod: 0x2499,
  1984. eightgujarati: 0x0AEE,
  1985. eightgurmukhi: 0x0A6E,
  1986. eighthackarabic: 0x0668,
  1987. eighthangzhou: 0x3028,
  1988. eighthnotebeamed: 0x266B,
  1989. eightideographicparen: 0x3227,
  1990. eightinferior: 0x2088,
  1991. eightmonospace: 0xFF18,
  1992. eightoldstyle: 0xF738,
  1993. eightparen: 0x247B,
  1994. eightperiod: 0x248F,
  1995. eightpersian: 0x06F8,
  1996. eightroman: 0x2177,
  1997. eightsuperior: 0x2078,
  1998. eightthai: 0x0E58,
  1999. einvertedbreve: 0x0207,
  2000. eiotifiedcyrillic: 0x0465,
  2001. ekatakana: 0x30A8,
  2002. ekatakanahalfwidth: 0xFF74,
  2003. ekonkargurmukhi: 0x0A74,
  2004. ekorean: 0x3154,
  2005. elcyrillic: 0x043B,
  2006. element: 0x2208,
  2007. elevencircle: 0x246A,
  2008. elevenparen: 0x247E,
  2009. elevenperiod: 0x2492,
  2010. elevenroman: 0x217A,
  2011. ellipsis: 0x2026,
  2012. ellipsisvertical: 0x22EE,
  2013. emacron: 0x0113,
  2014. emacronacute: 0x1E17,
  2015. emacrongrave: 0x1E15,
  2016. emcyrillic: 0x043C,
  2017. emdash: 0x2014,
  2018. emdashvertical: 0xFE31,
  2019. emonospace: 0xFF45,
  2020. emphasismarkarmenian: 0x055B,
  2021. emptyset: 0x2205,
  2022. enbopomofo: 0x3123,
  2023. encyrillic: 0x043D,
  2024. endash: 0x2013,
  2025. endashvertical: 0xFE32,
  2026. endescendercyrillic: 0x04A3,
  2027. eng: 0x014B,
  2028. engbopomofo: 0x3125,
  2029. enghecyrillic: 0x04A5,
  2030. enhookcyrillic: 0x04C8,
  2031. enspace: 0x2002,
  2032. eogonek: 0x0119,
  2033. eokorean: 0x3153,
  2034. eopen: 0x025B,
  2035. eopenclosed: 0x029A,
  2036. eopenreversed: 0x025C,
  2037. eopenreversedclosed: 0x025E,
  2038. eopenreversedhook: 0x025D,
  2039. eparen: 0x24A0,
  2040. epsilon: 0x03B5,
  2041. epsilontonos: 0x03AD,
  2042. equal: 0x003D,
  2043. equalmonospace: 0xFF1D,
  2044. equalsmall: 0xFE66,
  2045. equalsuperior: 0x207C,
  2046. equivalence: 0x2261,
  2047. erbopomofo: 0x3126,
  2048. ercyrillic: 0x0440,
  2049. ereversed: 0x0258,
  2050. ereversedcyrillic: 0x044D,
  2051. escyrillic: 0x0441,
  2052. esdescendercyrillic: 0x04AB,
  2053. esh: 0x0283,
  2054. eshcurl: 0x0286,
  2055. eshortdeva: 0x090E,
  2056. eshortvowelsigndeva: 0x0946,
  2057. eshreversedloop: 0x01AA,
  2058. eshsquatreversed: 0x0285,
  2059. esmallhiragana: 0x3047,
  2060. esmallkatakana: 0x30A7,
  2061. esmallkatakanahalfwidth: 0xFF6A,
  2062. estimated: 0x212E,
  2063. esuperior: 0xF6EC,
  2064. eta: 0x03B7,
  2065. etarmenian: 0x0568,
  2066. etatonos: 0x03AE,
  2067. eth: 0x00F0,
  2068. etilde: 0x1EBD,
  2069. etildebelow: 0x1E1B,
  2070. etnahtafoukhhebrew: 0x0591,
  2071. etnahtafoukhlefthebrew: 0x0591,
  2072. etnahtahebrew: 0x0591,
  2073. etnahtalefthebrew: 0x0591,
  2074. eturned: 0x01DD,
  2075. eukorean: 0x3161,
  2076. euro: 0x20AC,
  2077. evowelsignbengali: 0x09C7,
  2078. evowelsigndeva: 0x0947,
  2079. evowelsigngujarati: 0x0AC7,
  2080. exclam: 0x0021,
  2081. exclamarmenian: 0x055C,
  2082. exclamdbl: 0x203C,
  2083. exclamdown: 0x00A1,
  2084. exclamdownsmall: 0xF7A1,
  2085. exclammonospace: 0xFF01,
  2086. exclamsmall: 0xF721,
  2087. existential: 0x2203,
  2088. ezh: 0x0292,
  2089. ezhcaron: 0x01EF,
  2090. ezhcurl: 0x0293,
  2091. ezhreversed: 0x01B9,
  2092. ezhtail: 0x01BA,
  2093. f: 0x0066,
  2094. fadeva: 0x095E,
  2095. fagurmukhi: 0x0A5E,
  2096. fahrenheit: 0x2109,
  2097. fathaarabic: 0x064E,
  2098. fathalowarabic: 0x064E,
  2099. fathatanarabic: 0x064B,
  2100. fbopomofo: 0x3108,
  2101. fcircle: 0x24D5,
  2102. fdotaccent: 0x1E1F,
  2103. feharabic: 0x0641,
  2104. feharmenian: 0x0586,
  2105. fehfinalarabic: 0xFED2,
  2106. fehinitialarabic: 0xFED3,
  2107. fehmedialarabic: 0xFED4,
  2108. feicoptic: 0x03E5,
  2109. female: 0x2640,
  2110. ff: 0xFB00,
  2111. ffi: 0xFB03,
  2112. ffl: 0xFB04,
  2113. fi: 0xFB01,
  2114. fifteencircle: 0x246E,
  2115. fifteenparen: 0x2482,
  2116. fifteenperiod: 0x2496,
  2117. figuredash: 0x2012,
  2118. filledbox: 0x25A0,
  2119. filledrect: 0x25AC,
  2120. finalkaf: 0x05DA,
  2121. finalkafdagesh: 0xFB3A,
  2122. finalkafdageshhebrew: 0xFB3A,
  2123. finalkafhebrew: 0x05DA,
  2124. finalmem: 0x05DD,
  2125. finalmemhebrew: 0x05DD,
  2126. finalnun: 0x05DF,
  2127. finalnunhebrew: 0x05DF,
  2128. finalpe: 0x05E3,
  2129. finalpehebrew: 0x05E3,
  2130. finaltsadi: 0x05E5,
  2131. finaltsadihebrew: 0x05E5,
  2132. firsttonechinese: 0x02C9,
  2133. fisheye: 0x25C9,
  2134. fitacyrillic: 0x0473,
  2135. five: 0x0035,
  2136. fivearabic: 0x0665,
  2137. fivebengali: 0x09EB,
  2138. fivecircle: 0x2464,
  2139. fivecircleinversesansserif: 0x278E,
  2140. fivedeva: 0x096B,
  2141. fiveeighths: 0x215D,
  2142. fivegujarati: 0x0AEB,
  2143. fivegurmukhi: 0x0A6B,
  2144. fivehackarabic: 0x0665,
  2145. fivehangzhou: 0x3025,
  2146. fiveideographicparen: 0x3224,
  2147. fiveinferior: 0x2085,
  2148. fivemonospace: 0xFF15,
  2149. fiveoldstyle: 0xF735,
  2150. fiveparen: 0x2478,
  2151. fiveperiod: 0x248C,
  2152. fivepersian: 0x06F5,
  2153. fiveroman: 0x2174,
  2154. fivesuperior: 0x2075,
  2155. fivethai: 0x0E55,
  2156. fl: 0xFB02,
  2157. florin: 0x0192,
  2158. fmonospace: 0xFF46,
  2159. fmsquare: 0x3399,
  2160. fofanthai: 0x0E1F,
  2161. fofathai: 0x0E1D,
  2162. fongmanthai: 0x0E4F,
  2163. forall: 0x2200,
  2164. four: 0x0034,
  2165. fourarabic: 0x0664,
  2166. fourbengali: 0x09EA,
  2167. fourcircle: 0x2463,
  2168. fourcircleinversesansserif: 0x278D,
  2169. fourdeva: 0x096A,
  2170. fourgujarati: 0x0AEA,
  2171. fourgurmukhi: 0x0A6A,
  2172. fourhackarabic: 0x0664,
  2173. fourhangzhou: 0x3024,
  2174. fourideographicparen: 0x3223,
  2175. fourinferior: 0x2084,
  2176. fourmonospace: 0xFF14,
  2177. fournumeratorbengali: 0x09F7,
  2178. fouroldstyle: 0xF734,
  2179. fourparen: 0x2477,
  2180. fourperiod: 0x248B,
  2181. fourpersian: 0x06F4,
  2182. fourroman: 0x2173,
  2183. foursuperior: 0x2074,
  2184. fourteencircle: 0x246D,
  2185. fourteenparen: 0x2481,
  2186. fourteenperiod: 0x2495,
  2187. fourthai: 0x0E54,
  2188. fourthtonechinese: 0x02CB,
  2189. fparen: 0x24A1,
  2190. fraction: 0x2044,
  2191. franc: 0x20A3,
  2192. g: 0x0067,
  2193. gabengali: 0x0997,
  2194. gacute: 0x01F5,
  2195. gadeva: 0x0917,
  2196. gafarabic: 0x06AF,
  2197. gaffinalarabic: 0xFB93,
  2198. gafinitialarabic: 0xFB94,
  2199. gafmedialarabic: 0xFB95,
  2200. gagujarati: 0x0A97,
  2201. gagurmukhi: 0x0A17,
  2202. gahiragana: 0x304C,
  2203. gakatakana: 0x30AC,
  2204. gamma: 0x03B3,
  2205. gammalatinsmall: 0x0263,
  2206. gammasuperior: 0x02E0,
  2207. gangiacoptic: 0x03EB,
  2208. gbopomofo: 0x310D,
  2209. gbreve: 0x011F,
  2210. gcaron: 0x01E7,
  2211. gcedilla: 0x0123,
  2212. gcircle: 0x24D6,
  2213. gcircumflex: 0x011D,
  2214. gcommaaccent: 0x0123,
  2215. gdot: 0x0121,
  2216. gdotaccent: 0x0121,
  2217. gecyrillic: 0x0433,
  2218. gehiragana: 0x3052,
  2219. gekatakana: 0x30B2,
  2220. geometricallyequal: 0x2251,
  2221. gereshaccenthebrew: 0x059C,
  2222. gereshhebrew: 0x05F3,
  2223. gereshmuqdamhebrew: 0x059D,
  2224. germandbls: 0x00DF,
  2225. gershayimaccenthebrew: 0x059E,
  2226. gershayimhebrew: 0x05F4,
  2227. getamark: 0x3013,
  2228. ghabengali: 0x0998,
  2229. ghadarmenian: 0x0572,
  2230. ghadeva: 0x0918,
  2231. ghagujarati: 0x0A98,
  2232. ghagurmukhi: 0x0A18,
  2233. ghainarabic: 0x063A,
  2234. ghainfinalarabic: 0xFECE,
  2235. ghaininitialarabic: 0xFECF,
  2236. ghainmedialarabic: 0xFED0,
  2237. ghemiddlehookcyrillic: 0x0495,
  2238. ghestrokecyrillic: 0x0493,
  2239. gheupturncyrillic: 0x0491,
  2240. ghhadeva: 0x095A,
  2241. ghhagurmukhi: 0x0A5A,
  2242. ghook: 0x0260,
  2243. ghzsquare: 0x3393,
  2244. gihiragana: 0x304E,
  2245. gikatakana: 0x30AE,
  2246. gimarmenian: 0x0563,
  2247. gimel: 0x05D2,
  2248. gimeldagesh: 0xFB32,
  2249. gimeldageshhebrew: 0xFB32,
  2250. gimelhebrew: 0x05D2,
  2251. gjecyrillic: 0x0453,
  2252. glottalinvertedstroke: 0x01BE,
  2253. glottalstop: 0x0294,
  2254. glottalstopinverted: 0x0296,
  2255. glottalstopmod: 0x02C0,
  2256. glottalstopreversed: 0x0295,
  2257. glottalstopreversedmod: 0x02C1,
  2258. glottalstopreversedsuperior: 0x02E4,
  2259. glottalstopstroke: 0x02A1,
  2260. glottalstopstrokereversed: 0x02A2,
  2261. gmacron: 0x1E21,
  2262. gmonospace: 0xFF47,
  2263. gohiragana: 0x3054,
  2264. gokatakana: 0x30B4,
  2265. gparen: 0x24A2,
  2266. gpasquare: 0x33AC,
  2267. gradient: 0x2207,
  2268. grave: 0x0060,
  2269. gravebelowcmb: 0x0316,
  2270. gravecmb: 0x0300,
  2271. gravecomb: 0x0300,
  2272. gravedeva: 0x0953,
  2273. gravelowmod: 0x02CE,
  2274. gravemonospace: 0xFF40,
  2275. gravetonecmb: 0x0340,
  2276. greater: 0x003E,
  2277. greaterequal: 0x2265,
  2278. greaterequalorless: 0x22DB,
  2279. greatermonospace: 0xFF1E,
  2280. greaterorequivalent: 0x2273,
  2281. greaterorless: 0x2277,
  2282. greateroverequal: 0x2267,
  2283. greatersmall: 0xFE65,
  2284. gscript: 0x0261,
  2285. gstroke: 0x01E5,
  2286. guhiragana: 0x3050,
  2287. guillemotleft: 0x00AB,
  2288. guillemotright: 0x00BB,
  2289. guilsinglleft: 0x2039,
  2290. guilsinglright: 0x203A,
  2291. gukatakana: 0x30B0,
  2292. guramusquare: 0x3318,
  2293. gysquare: 0x33C9,
  2294. h: 0x0068,
  2295. haabkhasiancyrillic: 0x04A9,
  2296. haaltonearabic: 0x06C1,
  2297. habengali: 0x09B9,
  2298. hadescendercyrillic: 0x04B3,
  2299. hadeva: 0x0939,
  2300. hagujarati: 0x0AB9,
  2301. hagurmukhi: 0x0A39,
  2302. haharabic: 0x062D,
  2303. hahfinalarabic: 0xFEA2,
  2304. hahinitialarabic: 0xFEA3,
  2305. hahiragana: 0x306F,
  2306. hahmedialarabic: 0xFEA4,
  2307. haitusquare: 0x332A,
  2308. hakatakana: 0x30CF,
  2309. hakatakanahalfwidth: 0xFF8A,
  2310. halantgurmukhi: 0x0A4D,
  2311. hamzaarabic: 0x0621,
  2312. hamzalowarabic: 0x0621,
  2313. hangulfiller: 0x3164,
  2314. hardsigncyrillic: 0x044A,
  2315. harpoonleftbarbup: 0x21BC,
  2316. harpoonrightbarbup: 0x21C0,
  2317. hasquare: 0x33CA,
  2318. hatafpatah: 0x05B2,
  2319. hatafpatah16: 0x05B2,
  2320. hatafpatah23: 0x05B2,
  2321. hatafpatah2f: 0x05B2,
  2322. hatafpatahhebrew: 0x05B2,
  2323. hatafpatahnarrowhebrew: 0x05B2,
  2324. hatafpatahquarterhebrew: 0x05B2,
  2325. hatafpatahwidehebrew: 0x05B2,
  2326. hatafqamats: 0x05B3,
  2327. hatafqamats1b: 0x05B3,
  2328. hatafqamats28: 0x05B3,
  2329. hatafqamats34: 0x05B3,
  2330. hatafqamatshebrew: 0x05B3,
  2331. hatafqamatsnarrowhebrew: 0x05B3,
  2332. hatafqamatsquarterhebrew: 0x05B3,
  2333. hatafqamatswidehebrew: 0x05B3,
  2334. hatafsegol: 0x05B1,
  2335. hatafsegol17: 0x05B1,
  2336. hatafsegol24: 0x05B1,
  2337. hatafsegol30: 0x05B1,
  2338. hatafsegolhebrew: 0x05B1,
  2339. hatafsegolnarrowhebrew: 0x05B1,
  2340. hatafsegolquarterhebrew: 0x05B1,
  2341. hatafsegolwidehebrew: 0x05B1,
  2342. hbar: 0x0127,
  2343. hbopomofo: 0x310F,
  2344. hbrevebelow: 0x1E2B,
  2345. hcedilla: 0x1E29,
  2346. hcircle: 0x24D7,
  2347. hcircumflex: 0x0125,
  2348. hdieresis: 0x1E27,
  2349. hdotaccent: 0x1E23,
  2350. hdotbelow: 0x1E25,
  2351. he: 0x05D4,
  2352. heart: 0x2665,
  2353. heartsuitblack: 0x2665,
  2354. heartsuitwhite: 0x2661,
  2355. hedagesh: 0xFB34,
  2356. hedageshhebrew: 0xFB34,
  2357. hehaltonearabic: 0x06C1,
  2358. heharabic: 0x0647,
  2359. hehebrew: 0x05D4,
  2360. hehfinalaltonearabic: 0xFBA7,
  2361. hehfinalalttwoarabic: 0xFEEA,
  2362. hehfinalarabic: 0xFEEA,
  2363. hehhamzaabovefinalarabic: 0xFBA5,
  2364. hehhamzaaboveisolatedarabic: 0xFBA4,
  2365. hehinitialaltonearabic: 0xFBA8,
  2366. hehinitialarabic: 0xFEEB,
  2367. hehiragana: 0x3078,
  2368. hehmedialaltonearabic: 0xFBA9,
  2369. hehmedialarabic: 0xFEEC,
  2370. heiseierasquare: 0x337B,
  2371. hekatakana: 0x30D8,
  2372. hekatakanahalfwidth: 0xFF8D,
  2373. hekutaarusquare: 0x3336,
  2374. henghook: 0x0267,
  2375. herutusquare: 0x3339,
  2376. het: 0x05D7,
  2377. hethebrew: 0x05D7,
  2378. hhook: 0x0266,
  2379. hhooksuperior: 0x02B1,
  2380. hieuhacirclekorean: 0x327B,
  2381. hieuhaparenkorean: 0x321B,
  2382. hieuhcirclekorean: 0x326D,
  2383. hieuhkorean: 0x314E,
  2384. hieuhparenkorean: 0x320D,
  2385. hihiragana: 0x3072,
  2386. hikatakana: 0x30D2,
  2387. hikatakanahalfwidth: 0xFF8B,
  2388. hiriq: 0x05B4,
  2389. hiriq14: 0x05B4,
  2390. hiriq21: 0x05B4,
  2391. hiriq2d: 0x05B4,
  2392. hiriqhebrew: 0x05B4,
  2393. hiriqnarrowhebrew: 0x05B4,
  2394. hiriqquarterhebrew: 0x05B4,
  2395. hiriqwidehebrew: 0x05B4,
  2396. hlinebelow: 0x1E96,
  2397. hmonospace: 0xFF48,
  2398. hoarmenian: 0x0570,
  2399. hohipthai: 0x0E2B,
  2400. hohiragana: 0x307B,
  2401. hokatakana: 0x30DB,
  2402. hokatakanahalfwidth: 0xFF8E,
  2403. holam: 0x05B9,
  2404. holam19: 0x05B9,
  2405. holam26: 0x05B9,
  2406. holam32: 0x05B9,
  2407. holamhebrew: 0x05B9,
  2408. holamnarrowhebrew: 0x05B9,
  2409. holamquarterhebrew: 0x05B9,
  2410. holamwidehebrew: 0x05B9,
  2411. honokhukthai: 0x0E2E,
  2412. hookabovecomb: 0x0309,
  2413. hookcmb: 0x0309,
  2414. hookpalatalizedbelowcmb: 0x0321,
  2415. hookretroflexbelowcmb: 0x0322,
  2416. hoonsquare: 0x3342,
  2417. horicoptic: 0x03E9,
  2418. horizontalbar: 0x2015,
  2419. horncmb: 0x031B,
  2420. hotsprings: 0x2668,
  2421. house: 0x2302,
  2422. hparen: 0x24A3,
  2423. hsuperior: 0x02B0,
  2424. hturned: 0x0265,
  2425. huhiragana: 0x3075,
  2426. huiitosquare: 0x3333,
  2427. hukatakana: 0x30D5,
  2428. hukatakanahalfwidth: 0xFF8C,
  2429. hungarumlaut: 0x02DD,
  2430. hungarumlautcmb: 0x030B,
  2431. hv: 0x0195,
  2432. hyphen: 0x002D,
  2433. hypheninferior: 0xF6E5,
  2434. hyphenmonospace: 0xFF0D,
  2435. hyphensmall: 0xFE63,
  2436. hyphensuperior: 0xF6E6,
  2437. hyphentwo: 0x2010,
  2438. i: 0x0069,
  2439. iacute: 0x00ED,
  2440. iacyrillic: 0x044F,
  2441. ibengali: 0x0987,
  2442. ibopomofo: 0x3127,
  2443. ibreve: 0x012D,
  2444. icaron: 0x01D0,
  2445. icircle: 0x24D8,
  2446. icircumflex: 0x00EE,
  2447. icyrillic: 0x0456,
  2448. idblgrave: 0x0209,
  2449. ideographearthcircle: 0x328F,
  2450. ideographfirecircle: 0x328B,
  2451. ideographicallianceparen: 0x323F,
  2452. ideographiccallparen: 0x323A,
  2453. ideographiccentrecircle: 0x32A5,
  2454. ideographicclose: 0x3006,
  2455. ideographiccomma: 0x3001,
  2456. ideographiccommaleft: 0xFF64,
  2457. ideographiccongratulationparen: 0x3237,
  2458. ideographiccorrectcircle: 0x32A3,
  2459. ideographicearthparen: 0x322F,
  2460. ideographicenterpriseparen: 0x323D,
  2461. ideographicexcellentcircle: 0x329D,
  2462. ideographicfestivalparen: 0x3240,
  2463. ideographicfinancialcircle: 0x3296,
  2464. ideographicfinancialparen: 0x3236,
  2465. ideographicfireparen: 0x322B,
  2466. ideographichaveparen: 0x3232,
  2467. ideographichighcircle: 0x32A4,
  2468. ideographiciterationmark: 0x3005,
  2469. ideographiclaborcircle: 0x3298,
  2470. ideographiclaborparen: 0x3238,
  2471. ideographicleftcircle: 0x32A7,
  2472. ideographiclowcircle: 0x32A6,
  2473. ideographicmedicinecircle: 0x32A9,
  2474. ideographicmetalparen: 0x322E,
  2475. ideographicmoonparen: 0x322A,
  2476. ideographicnameparen: 0x3234,
  2477. ideographicperiod: 0x3002,
  2478. ideographicprintcircle: 0x329E,
  2479. ideographicreachparen: 0x3243,
  2480. ideographicrepresentparen: 0x3239,
  2481. ideographicresourceparen: 0x323E,
  2482. ideographicrightcircle: 0x32A8,
  2483. ideographicsecretcircle: 0x3299,
  2484. ideographicselfparen: 0x3242,
  2485. ideographicsocietyparen: 0x3233,
  2486. ideographicspace: 0x3000,
  2487. ideographicspecialparen: 0x3235,
  2488. ideographicstockparen: 0x3231,
  2489. ideographicstudyparen: 0x323B,
  2490. ideographicsunparen: 0x3230,
  2491. ideographicsuperviseparen: 0x323C,
  2492. ideographicwaterparen: 0x322C,
  2493. ideographicwoodparen: 0x322D,
  2494. ideographiczero: 0x3007,
  2495. ideographmetalcircle: 0x328E,
  2496. ideographmooncircle: 0x328A,
  2497. ideographnamecircle: 0x3294,
  2498. ideographsuncircle: 0x3290,
  2499. ideographwatercircle: 0x328C,
  2500. ideographwoodcircle: 0x328D,
  2501. ideva: 0x0907,
  2502. idieresis: 0x00EF,
  2503. idieresisacute: 0x1E2F,
  2504. idieresiscyrillic: 0x04E5,
  2505. idotbelow: 0x1ECB,
  2506. iebrevecyrillic: 0x04D7,
  2507. iecyrillic: 0x0435,
  2508. ieungacirclekorean: 0x3275,
  2509. ieungaparenkorean: 0x3215,
  2510. ieungcirclekorean: 0x3267,
  2511. ieungkorean: 0x3147,
  2512. ieungparenkorean: 0x3207,
  2513. igrave: 0x00EC,
  2514. igujarati: 0x0A87,
  2515. igurmukhi: 0x0A07,
  2516. ihiragana: 0x3044,
  2517. ihookabove: 0x1EC9,
  2518. iibengali: 0x0988,
  2519. iicyrillic: 0x0438,
  2520. iideva: 0x0908,
  2521. iigujarati: 0x0A88,
  2522. iigurmukhi: 0x0A08,
  2523. iimatragurmukhi: 0x0A40,
  2524. iinvertedbreve: 0x020B,
  2525. iishortcyrillic: 0x0439,
  2526. iivowelsignbengali: 0x09C0,
  2527. iivowelsigndeva: 0x0940,
  2528. iivowelsigngujarati: 0x0AC0,
  2529. ij: 0x0133,
  2530. ikatakana: 0x30A4,
  2531. ikatakanahalfwidth: 0xFF72,
  2532. ikorean: 0x3163,
  2533. ilde: 0x02DC,
  2534. iluyhebrew: 0x05AC,
  2535. imacron: 0x012B,
  2536. imacroncyrillic: 0x04E3,
  2537. imageorapproximatelyequal: 0x2253,
  2538. imatragurmukhi: 0x0A3F,
  2539. imonospace: 0xFF49,
  2540. increment: 0x2206,
  2541. infinity: 0x221E,
  2542. iniarmenian: 0x056B,
  2543. integral: 0x222B,
  2544. integralbottom: 0x2321,
  2545. integralbt: 0x2321,
  2546. integralex: 0xF8F5,
  2547. integraltop: 0x2320,
  2548. integraltp: 0x2320,
  2549. intersection: 0x2229,
  2550. intisquare: 0x3305,
  2551. invbullet: 0x25D8,
  2552. invcircle: 0x25D9,
  2553. invsmileface: 0x263B,
  2554. iocyrillic: 0x0451,
  2555. iogonek: 0x012F,
  2556. iota: 0x03B9,
  2557. iotadieresis: 0x03CA,
  2558. iotadieresistonos: 0x0390,
  2559. iotalatin: 0x0269,
  2560. iotatonos: 0x03AF,
  2561. iparen: 0x24A4,
  2562. irigurmukhi: 0x0A72,
  2563. ismallhiragana: 0x3043,
  2564. ismallkatakana: 0x30A3,
  2565. ismallkatakanahalfwidth: 0xFF68,
  2566. issharbengali: 0x09FA,
  2567. istroke: 0x0268,
  2568. isuperior: 0xF6ED,
  2569. iterationhiragana: 0x309D,
  2570. iterationkatakana: 0x30FD,
  2571. itilde: 0x0129,
  2572. itildebelow: 0x1E2D,
  2573. iubopomofo: 0x3129,
  2574. iucyrillic: 0x044E,
  2575. ivowelsignbengali: 0x09BF,
  2576. ivowelsigndeva: 0x093F,
  2577. ivowelsigngujarati: 0x0ABF,
  2578. izhitsacyrillic: 0x0475,
  2579. izhitsadblgravecyrillic: 0x0477,
  2580. j: 0x006A,
  2581. jaarmenian: 0x0571,
  2582. jabengali: 0x099C,
  2583. jadeva: 0x091C,
  2584. jagujarati: 0x0A9C,
  2585. jagurmukhi: 0x0A1C,
  2586. jbopomofo: 0x3110,
  2587. jcaron: 0x01F0,
  2588. jcircle: 0x24D9,
  2589. jcircumflex: 0x0135,
  2590. jcrossedtail: 0x029D,
  2591. jdotlessstroke: 0x025F,
  2592. jecyrillic: 0x0458,
  2593. jeemarabic: 0x062C,
  2594. jeemfinalarabic: 0xFE9E,
  2595. jeeminitialarabic: 0xFE9F,
  2596. jeemmedialarabic: 0xFEA0,
  2597. jeharabic: 0x0698,
  2598. jehfinalarabic: 0xFB8B,
  2599. jhabengali: 0x099D,
  2600. jhadeva: 0x091D,
  2601. jhagujarati: 0x0A9D,
  2602. jhagurmukhi: 0x0A1D,
  2603. jheharmenian: 0x057B,
  2604. jis: 0x3004,
  2605. jmonospace: 0xFF4A,
  2606. jparen: 0x24A5,
  2607. jsuperior: 0x02B2,
  2608. k: 0x006B,
  2609. kabashkircyrillic: 0x04A1,
  2610. kabengali: 0x0995,
  2611. kacute: 0x1E31,
  2612. kacyrillic: 0x043A,
  2613. kadescendercyrillic: 0x049B,
  2614. kadeva: 0x0915,
  2615. kaf: 0x05DB,
  2616. kafarabic: 0x0643,
  2617. kafdagesh: 0xFB3B,
  2618. kafdageshhebrew: 0xFB3B,
  2619. kaffinalarabic: 0xFEDA,
  2620. kafhebrew: 0x05DB,
  2621. kafinitialarabic: 0xFEDB,
  2622. kafmedialarabic: 0xFEDC,
  2623. kafrafehebrew: 0xFB4D,
  2624. kagujarati: 0x0A95,
  2625. kagurmukhi: 0x0A15,
  2626. kahiragana: 0x304B,
  2627. kahookcyrillic: 0x04C4,
  2628. kakatakana: 0x30AB,
  2629. kakatakanahalfwidth: 0xFF76,
  2630. kappa: 0x03BA,
  2631. kappasymbolgreek: 0x03F0,
  2632. kapyeounmieumkorean: 0x3171,
  2633. kapyeounphieuphkorean: 0x3184,
  2634. kapyeounpieupkorean: 0x3178,
  2635. kapyeounssangpieupkorean: 0x3179,
  2636. karoriisquare: 0x330D,
  2637. kashidaautoarabic: 0x0640,
  2638. kashidaautonosidebearingarabic: 0x0640,
  2639. kasmallkatakana: 0x30F5,
  2640. kasquare: 0x3384,
  2641. kasraarabic: 0x0650,
  2642. kasratanarabic: 0x064D,
  2643. kastrokecyrillic: 0x049F,
  2644. katahiraprolongmarkhalfwidth: 0xFF70,
  2645. kaverticalstrokecyrillic: 0x049D,
  2646. kbopomofo: 0x310E,
  2647. kcalsquare: 0x3389,
  2648. kcaron: 0x01E9,
  2649. kcedilla: 0x0137,
  2650. kcircle: 0x24DA,
  2651. kcommaaccent: 0x0137,
  2652. kdotbelow: 0x1E33,
  2653. keharmenian: 0x0584,
  2654. kehiragana: 0x3051,
  2655. kekatakana: 0x30B1,
  2656. kekatakanahalfwidth: 0xFF79,
  2657. kenarmenian: 0x056F,
  2658. kesmallkatakana: 0x30F6,
  2659. kgreenlandic: 0x0138,
  2660. khabengali: 0x0996,
  2661. khacyrillic: 0x0445,
  2662. khadeva: 0x0916,
  2663. khagujarati: 0x0A96,
  2664. khagurmukhi: 0x0A16,
  2665. khaharabic: 0x062E,
  2666. khahfinalarabic: 0xFEA6,
  2667. khahinitialarabic: 0xFEA7,
  2668. khahmedialarabic: 0xFEA8,
  2669. kheicoptic: 0x03E7,
  2670. khhadeva: 0x0959,
  2671. khhagurmukhi: 0x0A59,
  2672. khieukhacirclekorean: 0x3278,
  2673. khieukhaparenkorean: 0x3218,
  2674. khieukhcirclekorean: 0x326A,
  2675. khieukhkorean: 0x314B,
  2676. khieukhparenkorean: 0x320A,
  2677. khokhaithai: 0x0E02,
  2678. khokhonthai: 0x0E05,
  2679. khokhuatthai: 0x0E03,
  2680. khokhwaithai: 0x0E04,
  2681. khomutthai: 0x0E5B,
  2682. khook: 0x0199,
  2683. khorakhangthai: 0x0E06,
  2684. khzsquare: 0x3391,
  2685. kihiragana: 0x304D,
  2686. kikatakana: 0x30AD,
  2687. kikatakanahalfwidth: 0xFF77,
  2688. kiroguramusquare: 0x3315,
  2689. kiromeetorusquare: 0x3316,
  2690. kirosquare: 0x3314,
  2691. kiyeokacirclekorean: 0x326E,
  2692. kiyeokaparenkorean: 0x320E,
  2693. kiyeokcirclekorean: 0x3260,
  2694. kiyeokkorean: 0x3131,
  2695. kiyeokparenkorean: 0x3200,
  2696. kiyeoksioskorean: 0x3133,
  2697. kjecyrillic: 0x045C,
  2698. klinebelow: 0x1E35,
  2699. klsquare: 0x3398,
  2700. kmcubedsquare: 0x33A6,
  2701. kmonospace: 0xFF4B,
  2702. kmsquaredsquare: 0x33A2,
  2703. kohiragana: 0x3053,
  2704. kohmsquare: 0x33C0,
  2705. kokaithai: 0x0E01,
  2706. kokatakana: 0x30B3,
  2707. kokatakanahalfwidth: 0xFF7A,
  2708. kooposquare: 0x331E,
  2709. koppacyrillic: 0x0481,
  2710. koreanstandardsymbol: 0x327F,
  2711. koroniscmb: 0x0343,
  2712. kparen: 0x24A6,
  2713. kpasquare: 0x33AA,
  2714. ksicyrillic: 0x046F,
  2715. ktsquare: 0x33CF,
  2716. kturned: 0x029E,
  2717. kuhiragana: 0x304F,
  2718. kukatakana: 0x30AF,
  2719. kukatakanahalfwidth: 0xFF78,
  2720. kvsquare: 0x33B8,
  2721. kwsquare: 0x33BE,
  2722. l: 0x006C,
  2723. labengali: 0x09B2,
  2724. lacute: 0x013A,
  2725. ladeva: 0x0932,
  2726. lagujarati: 0x0AB2,
  2727. lagurmukhi: 0x0A32,
  2728. lakkhangyaothai: 0x0E45,
  2729. lamaleffinalarabic: 0xFEFC,
  2730. lamalefhamzaabovefinalarabic: 0xFEF8,
  2731. lamalefhamzaaboveisolatedarabic: 0xFEF7,
  2732. lamalefhamzabelowfinalarabic: 0xFEFA,
  2733. lamalefhamzabelowisolatedarabic: 0xFEF9,
  2734. lamalefisolatedarabic: 0xFEFB,
  2735. lamalefmaddaabovefinalarabic: 0xFEF6,
  2736. lamalefmaddaaboveisolatedarabic: 0xFEF5,
  2737. lamarabic: 0x0644,
  2738. lambda: 0x03BB,
  2739. lambdastroke: 0x019B,
  2740. lamed: 0x05DC,
  2741. lameddagesh: 0xFB3C,
  2742. lameddageshhebrew: 0xFB3C,
  2743. lamedhebrew: 0x05DC,
  2744. lamfinalarabic: 0xFEDE,
  2745. lamhahinitialarabic: 0xFCCA,
  2746. laminitialarabic: 0xFEDF,
  2747. lamjeeminitialarabic: 0xFCC9,
  2748. lamkhahinitialarabic: 0xFCCB,
  2749. lamlamhehisolatedarabic: 0xFDF2,
  2750. lammedialarabic: 0xFEE0,
  2751. lammeemhahinitialarabic: 0xFD88,
  2752. lammeeminitialarabic: 0xFCCC,
  2753. largecircle: 0x25EF,
  2754. lbar: 0x019A,
  2755. lbelt: 0x026C,
  2756. lbopomofo: 0x310C,
  2757. lcaron: 0x013E,
  2758. lcedilla: 0x013C,
  2759. lcircle: 0x24DB,
  2760. lcircumflexbelow: 0x1E3D,
  2761. lcommaaccent: 0x013C,
  2762. ldot: 0x0140,
  2763. ldotaccent: 0x0140,
  2764. ldotbelow: 0x1E37,
  2765. ldotbelowmacron: 0x1E39,
  2766. leftangleabovecmb: 0x031A,
  2767. lefttackbelowcmb: 0x0318,
  2768. less: 0x003C,
  2769. lessequal: 0x2264,
  2770. lessequalorgreater: 0x22DA,
  2771. lessmonospace: 0xFF1C,
  2772. lessorequivalent: 0x2272,
  2773. lessorgreater: 0x2276,
  2774. lessoverequal: 0x2266,
  2775. lesssmall: 0xFE64,
  2776. lezh: 0x026E,
  2777. lfblock: 0x258C,
  2778. lhookretroflex: 0x026D,
  2779. lira: 0x20A4,
  2780. liwnarmenian: 0x056C,
  2781. lj: 0x01C9,
  2782. ljecyrillic: 0x0459,
  2783. ll: 0xF6C0,
  2784. lladeva: 0x0933,
  2785. llagujarati: 0x0AB3,
  2786. llinebelow: 0x1E3B,
  2787. llladeva: 0x0934,
  2788. llvocalicbengali: 0x09E1,
  2789. llvocalicdeva: 0x0961,
  2790. llvocalicvowelsignbengali: 0x09E3,
  2791. llvocalicvowelsigndeva: 0x0963,
  2792. lmiddletilde: 0x026B,
  2793. lmonospace: 0xFF4C,
  2794. lmsquare: 0x33D0,
  2795. lochulathai: 0x0E2C,
  2796. logicaland: 0x2227,
  2797. logicalnot: 0x00AC,
  2798. logicalnotreversed: 0x2310,
  2799. logicalor: 0x2228,
  2800. lolingthai: 0x0E25,
  2801. longs: 0x017F,
  2802. lowlinecenterline: 0xFE4E,
  2803. lowlinecmb: 0x0332,
  2804. lowlinedashed: 0xFE4D,
  2805. lozenge: 0x25CA,
  2806. lparen: 0x24A7,
  2807. lslash: 0x0142,
  2808. lsquare: 0x2113,
  2809. lsuperior: 0xF6EE,
  2810. ltshade: 0x2591,
  2811. luthai: 0x0E26,
  2812. lvocalicbengali: 0x098C,
  2813. lvocalicdeva: 0x090C,
  2814. lvocalicvowelsignbengali: 0x09E2,
  2815. lvocalicvowelsigndeva: 0x0962,
  2816. lxsquare: 0x33D3,
  2817. m: 0x006D,
  2818. mabengali: 0x09AE,
  2819. macron: 0x00AF,
  2820. macronbelowcmb: 0x0331,
  2821. macroncmb: 0x0304,
  2822. macronlowmod: 0x02CD,
  2823. macronmonospace: 0xFFE3,
  2824. macute: 0x1E3F,
  2825. madeva: 0x092E,
  2826. magujarati: 0x0AAE,
  2827. magurmukhi: 0x0A2E,
  2828. mahapakhhebrew: 0x05A4,
  2829. mahapakhlefthebrew: 0x05A4,
  2830. mahiragana: 0x307E,
  2831. maichattawalowleftthai: 0xF895,
  2832. maichattawalowrightthai: 0xF894,
  2833. maichattawathai: 0x0E4B,
  2834. maichattawaupperleftthai: 0xF893,
  2835. maieklowleftthai: 0xF88C,
  2836. maieklowrightthai: 0xF88B,
  2837. maiekthai: 0x0E48,
  2838. maiekupperleftthai: 0xF88A,
  2839. maihanakatleftthai: 0xF884,
  2840. maihanakatthai: 0x0E31,
  2841. maitaikhuleftthai: 0xF889,
  2842. maitaikhuthai: 0x0E47,
  2843. maitholowleftthai: 0xF88F,
  2844. maitholowrightthai: 0xF88E,
  2845. maithothai: 0x0E49,
  2846. maithoupperleftthai: 0xF88D,
  2847. maitrilowleftthai: 0xF892,
  2848. maitrilowrightthai: 0xF891,
  2849. maitrithai: 0x0E4A,
  2850. maitriupperleftthai: 0xF890,
  2851. maiyamokthai: 0x0E46,
  2852. makatakana: 0x30DE,
  2853. makatakanahalfwidth: 0xFF8F,
  2854. male: 0x2642,
  2855. mansyonsquare: 0x3347,
  2856. maqafhebrew: 0x05BE,
  2857. mars: 0x2642,
  2858. masoracirclehebrew: 0x05AF,
  2859. masquare: 0x3383,
  2860. mbopomofo: 0x3107,
  2861. mbsquare: 0x33D4,
  2862. mcircle: 0x24DC,
  2863. mcubedsquare: 0x33A5,
  2864. mdotaccent: 0x1E41,
  2865. mdotbelow: 0x1E43,
  2866. meemarabic: 0x0645,
  2867. meemfinalarabic: 0xFEE2,
  2868. meeminitialarabic: 0xFEE3,
  2869. meemmedialarabic: 0xFEE4,
  2870. meemmeeminitialarabic: 0xFCD1,
  2871. meemmeemisolatedarabic: 0xFC48,
  2872. meetorusquare: 0x334D,
  2873. mehiragana: 0x3081,
  2874. meizierasquare: 0x337E,
  2875. mekatakana: 0x30E1,
  2876. mekatakanahalfwidth: 0xFF92,
  2877. mem: 0x05DE,
  2878. memdagesh: 0xFB3E,
  2879. memdageshhebrew: 0xFB3E,
  2880. memhebrew: 0x05DE,
  2881. menarmenian: 0x0574,
  2882. merkhahebrew: 0x05A5,
  2883. merkhakefulahebrew: 0x05A6,
  2884. merkhakefulalefthebrew: 0x05A6,
  2885. merkhalefthebrew: 0x05A5,
  2886. mhook: 0x0271,
  2887. mhzsquare: 0x3392,
  2888. middledotkatakanahalfwidth: 0xFF65,
  2889. middot: 0x00B7,
  2890. mieumacirclekorean: 0x3272,
  2891. mieumaparenkorean: 0x3212,
  2892. mieumcirclekorean: 0x3264,
  2893. mieumkorean: 0x3141,
  2894. mieumpansioskorean: 0x3170,
  2895. mieumparenkorean: 0x3204,
  2896. mieumpieupkorean: 0x316E,
  2897. mieumsioskorean: 0x316F,
  2898. mihiragana: 0x307F,
  2899. mikatakana: 0x30DF,
  2900. mikatakanahalfwidth: 0xFF90,
  2901. minus: 0x2212,
  2902. minusbelowcmb: 0x0320,
  2903. minuscircle: 0x2296,
  2904. minusmod: 0x02D7,
  2905. minusplus: 0x2213,
  2906. minute: 0x2032,
  2907. miribaarusquare: 0x334A,
  2908. mirisquare: 0x3349,
  2909. mlonglegturned: 0x0270,
  2910. mlsquare: 0x3396,
  2911. mmcubedsquare: 0x33A3,
  2912. mmonospace: 0xFF4D,
  2913. mmsquaredsquare: 0x339F,
  2914. mohiragana: 0x3082,
  2915. mohmsquare: 0x33C1,
  2916. mokatakana: 0x30E2,
  2917. mokatakanahalfwidth: 0xFF93,
  2918. molsquare: 0x33D6,
  2919. momathai: 0x0E21,
  2920. moverssquare: 0x33A7,
  2921. moverssquaredsquare: 0x33A8,
  2922. mparen: 0x24A8,
  2923. mpasquare: 0x33AB,
  2924. mssquare: 0x33B3,
  2925. msuperior: 0xF6EF,
  2926. mturned: 0x026F,
  2927. mu: 0x00B5,
  2928. mu1: 0x00B5,
  2929. muasquare: 0x3382,
  2930. muchgreater: 0x226B,
  2931. muchless: 0x226A,
  2932. mufsquare: 0x338C,
  2933. mugreek: 0x03BC,
  2934. mugsquare: 0x338D,
  2935. muhiragana: 0x3080,
  2936. mukatakana: 0x30E0,
  2937. mukatakanahalfwidth: 0xFF91,
  2938. mulsquare: 0x3395,
  2939. multiply: 0x00D7,
  2940. mumsquare: 0x339B,
  2941. munahhebrew: 0x05A3,
  2942. munahlefthebrew: 0x05A3,
  2943. musicalnote: 0x266A,
  2944. musicalnotedbl: 0x266B,
  2945. musicflatsign: 0x266D,
  2946. musicsharpsign: 0x266F,
  2947. mussquare: 0x33B2,
  2948. muvsquare: 0x33B6,
  2949. muwsquare: 0x33BC,
  2950. mvmegasquare: 0x33B9,
  2951. mvsquare: 0x33B7,
  2952. mwmegasquare: 0x33BF,
  2953. mwsquare: 0x33BD,
  2954. n: 0x006E,
  2955. nabengali: 0x09A8,
  2956. nabla: 0x2207,
  2957. nacute: 0x0144,
  2958. nadeva: 0x0928,
  2959. nagujarati: 0x0AA8,
  2960. nagurmukhi: 0x0A28,
  2961. nahiragana: 0x306A,
  2962. nakatakana: 0x30CA,
  2963. nakatakanahalfwidth: 0xFF85,
  2964. napostrophe: 0x0149,
  2965. nasquare: 0x3381,
  2966. nbopomofo: 0x310B,
  2967. nbspace: 0x00A0,
  2968. ncaron: 0x0148,
  2969. ncedilla: 0x0146,
  2970. ncircle: 0x24DD,
  2971. ncircumflexbelow: 0x1E4B,
  2972. ncommaaccent: 0x0146,
  2973. ndotaccent: 0x1E45,
  2974. ndotbelow: 0x1E47,
  2975. nehiragana: 0x306D,
  2976. nekatakana: 0x30CD,
  2977. nekatakanahalfwidth: 0xFF88,
  2978. newsheqelsign: 0x20AA,
  2979. nfsquare: 0x338B,
  2980. ngabengali: 0x0999,
  2981. ngadeva: 0x0919,
  2982. ngagujarati: 0x0A99,
  2983. ngagurmukhi: 0x0A19,
  2984. ngonguthai: 0x0E07,
  2985. nhiragana: 0x3093,
  2986. nhookleft: 0x0272,
  2987. nhookretroflex: 0x0273,
  2988. nieunacirclekorean: 0x326F,
  2989. nieunaparenkorean: 0x320F,
  2990. nieuncieuckorean: 0x3135,
  2991. nieuncirclekorean: 0x3261,
  2992. nieunhieuhkorean: 0x3136,
  2993. nieunkorean: 0x3134,
  2994. nieunpansioskorean: 0x3168,
  2995. nieunparenkorean: 0x3201,
  2996. nieunsioskorean: 0x3167,
  2997. nieuntikeutkorean: 0x3166,
  2998. nihiragana: 0x306B,
  2999. nikatakana: 0x30CB,
  3000. nikatakanahalfwidth: 0xFF86,
  3001. nikhahitleftthai: 0xF899,
  3002. nikhahitthai: 0x0E4D,
  3003. nine: 0x0039,
  3004. ninearabic: 0x0669,
  3005. ninebengali: 0x09EF,
  3006. ninecircle: 0x2468,
  3007. ninecircleinversesansserif: 0x2792,
  3008. ninedeva: 0x096F,
  3009. ninegujarati: 0x0AEF,
  3010. ninegurmukhi: 0x0A6F,
  3011. ninehackarabic: 0x0669,
  3012. ninehangzhou: 0x3029,
  3013. nineideographicparen: 0x3228,
  3014. nineinferior: 0x2089,
  3015. ninemonospace: 0xFF19,
  3016. nineoldstyle: 0xF739,
  3017. nineparen: 0x247C,
  3018. nineperiod: 0x2490,
  3019. ninepersian: 0x06F9,
  3020. nineroman: 0x2178,
  3021. ninesuperior: 0x2079,
  3022. nineteencircle: 0x2472,
  3023. nineteenparen: 0x2486,
  3024. nineteenperiod: 0x249A,
  3025. ninethai: 0x0E59,
  3026. nj: 0x01CC,
  3027. njecyrillic: 0x045A,
  3028. nkatakana: 0x30F3,
  3029. nkatakanahalfwidth: 0xFF9D,
  3030. nlegrightlong: 0x019E,
  3031. nlinebelow: 0x1E49,
  3032. nmonospace: 0xFF4E,
  3033. nmsquare: 0x339A,
  3034. nnabengali: 0x09A3,
  3035. nnadeva: 0x0923,
  3036. nnagujarati: 0x0AA3,
  3037. nnagurmukhi: 0x0A23,
  3038. nnnadeva: 0x0929,
  3039. nohiragana: 0x306E,
  3040. nokatakana: 0x30CE,
  3041. nokatakanahalfwidth: 0xFF89,
  3042. nonbreakingspace: 0x00A0,
  3043. nonenthai: 0x0E13,
  3044. nonuthai: 0x0E19,
  3045. noonarabic: 0x0646,
  3046. noonfinalarabic: 0xFEE6,
  3047. noonghunnaarabic: 0x06BA,
  3048. noonghunnafinalarabic: 0xFB9F,
  3049. nooninitialarabic: 0xFEE7,
  3050. noonjeeminitialarabic: 0xFCD2,
  3051. noonjeemisolatedarabic: 0xFC4B,
  3052. noonmedialarabic: 0xFEE8,
  3053. noonmeeminitialarabic: 0xFCD5,
  3054. noonmeemisolatedarabic: 0xFC4E,
  3055. noonnoonfinalarabic: 0xFC8D,
  3056. notcontains: 0x220C,
  3057. notelement: 0x2209,
  3058. notelementof: 0x2209,
  3059. notequal: 0x2260,
  3060. notgreater: 0x226F,
  3061. notgreaternorequal: 0x2271,
  3062. notgreaternorless: 0x2279,
  3063. notidentical: 0x2262,
  3064. notless: 0x226E,
  3065. notlessnorequal: 0x2270,
  3066. notparallel: 0x2226,
  3067. notprecedes: 0x2280,
  3068. notsubset: 0x2284,
  3069. notsucceeds: 0x2281,
  3070. notsuperset: 0x2285,
  3071. nowarmenian: 0x0576,
  3072. nparen: 0x24A9,
  3073. nssquare: 0x33B1,
  3074. nsuperior: 0x207F,
  3075. ntilde: 0x00F1,
  3076. nu: 0x03BD,
  3077. nuhiragana: 0x306C,
  3078. nukatakana: 0x30CC,
  3079. nukatakanahalfwidth: 0xFF87,
  3080. nuktabengali: 0x09BC,
  3081. nuktadeva: 0x093C,
  3082. nuktagujarati: 0x0ABC,
  3083. nuktagurmukhi: 0x0A3C,
  3084. numbersign: 0x0023,
  3085. numbersignmonospace: 0xFF03,
  3086. numbersignsmall: 0xFE5F,
  3087. numeralsigngreek: 0x0374,
  3088. numeralsignlowergreek: 0x0375,
  3089. numero: 0x2116,
  3090. nun: 0x05E0,
  3091. nundagesh: 0xFB40,
  3092. nundageshhebrew: 0xFB40,
  3093. nunhebrew: 0x05E0,
  3094. nvsquare: 0x33B5,
  3095. nwsquare: 0x33BB,
  3096. nyabengali: 0x099E,
  3097. nyadeva: 0x091E,
  3098. nyagujarati: 0x0A9E,
  3099. nyagurmukhi: 0x0A1E,
  3100. o: 0x006F,
  3101. oacute: 0x00F3,
  3102. oangthai: 0x0E2D,
  3103. obarred: 0x0275,
  3104. obarredcyrillic: 0x04E9,
  3105. obarreddieresiscyrillic: 0x04EB,
  3106. obengali: 0x0993,
  3107. obopomofo: 0x311B,
  3108. obreve: 0x014F,
  3109. ocandradeva: 0x0911,
  3110. ocandragujarati: 0x0A91,
  3111. ocandravowelsigndeva: 0x0949,
  3112. ocandravowelsigngujarati: 0x0AC9,
  3113. ocaron: 0x01D2,
  3114. ocircle: 0x24DE,
  3115. ocircumflex: 0x00F4,
  3116. ocircumflexacute: 0x1ED1,
  3117. ocircumflexdotbelow: 0x1ED9,
  3118. ocircumflexgrave: 0x1ED3,
  3119. ocircumflexhookabove: 0x1ED5,
  3120. ocircumflextilde: 0x1ED7,
  3121. ocyrillic: 0x043E,
  3122. odblacute: 0x0151,
  3123. odblgrave: 0x020D,
  3124. odeva: 0x0913,
  3125. odieresis: 0x00F6,
  3126. odieresiscyrillic: 0x04E7,
  3127. odotbelow: 0x1ECD,
  3128. oe: 0x0153,
  3129. oekorean: 0x315A,
  3130. ogonek: 0x02DB,
  3131. ogonekcmb: 0x0328,
  3132. ograve: 0x00F2,
  3133. ogujarati: 0x0A93,
  3134. oharmenian: 0x0585,
  3135. ohiragana: 0x304A,
  3136. ohookabove: 0x1ECF,
  3137. ohorn: 0x01A1,
  3138. ohornacute: 0x1EDB,
  3139. ohorndotbelow: 0x1EE3,
  3140. ohorngrave: 0x1EDD,
  3141. ohornhookabove: 0x1EDF,
  3142. ohorntilde: 0x1EE1,
  3143. ohungarumlaut: 0x0151,
  3144. oi: 0x01A3,
  3145. oinvertedbreve: 0x020F,
  3146. okatakana: 0x30AA,
  3147. okatakanahalfwidth: 0xFF75,
  3148. okorean: 0x3157,
  3149. olehebrew: 0x05AB,
  3150. omacron: 0x014D,
  3151. omacronacute: 0x1E53,
  3152. omacrongrave: 0x1E51,
  3153. omdeva: 0x0950,
  3154. omega: 0x03C9,
  3155. omega1: 0x03D6,
  3156. omegacyrillic: 0x0461,
  3157. omegalatinclosed: 0x0277,
  3158. omegaroundcyrillic: 0x047B,
  3159. omegatitlocyrillic: 0x047D,
  3160. omegatonos: 0x03CE,
  3161. omgujarati: 0x0AD0,
  3162. omicron: 0x03BF,
  3163. omicrontonos: 0x03CC,
  3164. omonospace: 0xFF4F,
  3165. one: 0x0031,
  3166. onearabic: 0x0661,
  3167. onebengali: 0x09E7,
  3168. onecircle: 0x2460,
  3169. onecircleinversesansserif: 0x278A,
  3170. onedeva: 0x0967,
  3171. onedotenleader: 0x2024,
  3172. oneeighth: 0x215B,
  3173. onefitted: 0xF6DC,
  3174. onegujarati: 0x0AE7,
  3175. onegurmukhi: 0x0A67,
  3176. onehackarabic: 0x0661,
  3177. onehalf: 0x00BD,
  3178. onehangzhou: 0x3021,
  3179. oneideographicparen: 0x3220,
  3180. oneinferior: 0x2081,
  3181. onemonospace: 0xFF11,
  3182. onenumeratorbengali: 0x09F4,
  3183. oneoldstyle: 0xF731,
  3184. oneparen: 0x2474,
  3185. oneperiod: 0x2488,
  3186. onepersian: 0x06F1,
  3187. onequarter: 0x00BC,
  3188. oneroman: 0x2170,
  3189. onesuperior: 0x00B9,
  3190. onethai: 0x0E51,
  3191. onethird: 0x2153,
  3192. oogonek: 0x01EB,
  3193. oogonekmacron: 0x01ED,
  3194. oogurmukhi: 0x0A13,
  3195. oomatragurmukhi: 0x0A4B,
  3196. oopen: 0x0254,
  3197. oparen: 0x24AA,
  3198. openbullet: 0x25E6,
  3199. option: 0x2325,
  3200. ordfeminine: 0x00AA,
  3201. ordmasculine: 0x00BA,
  3202. orthogonal: 0x221F,
  3203. oshortdeva: 0x0912,
  3204. oshortvowelsigndeva: 0x094A,
  3205. oslash: 0x00F8,
  3206. oslashacute: 0x01FF,
  3207. osmallhiragana: 0x3049,
  3208. osmallkatakana: 0x30A9,
  3209. osmallkatakanahalfwidth: 0xFF6B,
  3210. ostrokeacute: 0x01FF,
  3211. osuperior: 0xF6F0,
  3212. otcyrillic: 0x047F,
  3213. otilde: 0x00F5,
  3214. otildeacute: 0x1E4D,
  3215. otildedieresis: 0x1E4F,
  3216. oubopomofo: 0x3121,
  3217. overline: 0x203E,
  3218. overlinecenterline: 0xFE4A,
  3219. overlinecmb: 0x0305,
  3220. overlinedashed: 0xFE49,
  3221. overlinedblwavy: 0xFE4C,
  3222. overlinewavy: 0xFE4B,
  3223. overscore: 0x00AF,
  3224. ovowelsignbengali: 0x09CB,
  3225. ovowelsigndeva: 0x094B,
  3226. ovowelsigngujarati: 0x0ACB,
  3227. p: 0x0070,
  3228. paampssquare: 0x3380,
  3229. paasentosquare: 0x332B,
  3230. pabengali: 0x09AA,
  3231. pacute: 0x1E55,
  3232. padeva: 0x092A,
  3233. pagedown: 0x21DF,
  3234. pageup: 0x21DE,
  3235. pagujarati: 0x0AAA,
  3236. pagurmukhi: 0x0A2A,
  3237. pahiragana: 0x3071,
  3238. paiyannoithai: 0x0E2F,
  3239. pakatakana: 0x30D1,
  3240. palatalizationcyrilliccmb: 0x0484,
  3241. palochkacyrillic: 0x04C0,
  3242. pansioskorean: 0x317F,
  3243. paragraph: 0x00B6,
  3244. parallel: 0x2225,
  3245. parenleft: 0x0028,
  3246. parenleftaltonearabic: 0xFD3E,
  3247. parenleftbt: 0xF8ED,
  3248. parenleftex: 0xF8EC,
  3249. parenleftinferior: 0x208D,
  3250. parenleftmonospace: 0xFF08,
  3251. parenleftsmall: 0xFE59,
  3252. parenleftsuperior: 0x207D,
  3253. parenlefttp: 0xF8EB,
  3254. parenleftvertical: 0xFE35,
  3255. parenright: 0x0029,
  3256. parenrightaltonearabic: 0xFD3F,
  3257. parenrightbt: 0xF8F8,
  3258. parenrightex: 0xF8F7,
  3259. parenrightinferior: 0x208E,
  3260. parenrightmonospace: 0xFF09,
  3261. parenrightsmall: 0xFE5A,
  3262. parenrightsuperior: 0x207E,
  3263. parenrighttp: 0xF8F6,
  3264. parenrightvertical: 0xFE36,
  3265. partialdiff: 0x2202,
  3266. paseqhebrew: 0x05C0,
  3267. pashtahebrew: 0x0599,
  3268. pasquare: 0x33A9,
  3269. patah: 0x05B7,
  3270. patah11: 0x05B7,
  3271. patah1d: 0x05B7,
  3272. patah2a: 0x05B7,
  3273. patahhebrew: 0x05B7,
  3274. patahnarrowhebrew: 0x05B7,
  3275. patahquarterhebrew: 0x05B7,
  3276. patahwidehebrew: 0x05B7,
  3277. pazerhebrew: 0x05A1,
  3278. pbopomofo: 0x3106,
  3279. pcircle: 0x24DF,
  3280. pdotaccent: 0x1E57,
  3281. pe: 0x05E4,
  3282. pecyrillic: 0x043F,
  3283. pedagesh: 0xFB44,
  3284. pedageshhebrew: 0xFB44,
  3285. peezisquare: 0x333B,
  3286. pefinaldageshhebrew: 0xFB43,
  3287. peharabic: 0x067E,
  3288. peharmenian: 0x057A,
  3289. pehebrew: 0x05E4,
  3290. pehfinalarabic: 0xFB57,
  3291. pehinitialarabic: 0xFB58,
  3292. pehiragana: 0x307A,
  3293. pehmedialarabic: 0xFB59,
  3294. pekatakana: 0x30DA,
  3295. pemiddlehookcyrillic: 0x04A7,
  3296. perafehebrew: 0xFB4E,
  3297. percent: 0x0025,
  3298. percentarabic: 0x066A,
  3299. percentmonospace: 0xFF05,
  3300. percentsmall: 0xFE6A,
  3301. period: 0x002E,
  3302. periodarmenian: 0x0589,
  3303. periodcentered: 0x00B7,
  3304. periodhalfwidth: 0xFF61,
  3305. periodinferior: 0xF6E7,
  3306. periodmonospace: 0xFF0E,
  3307. periodsmall: 0xFE52,
  3308. periodsuperior: 0xF6E8,
  3309. perispomenigreekcmb: 0x0342,
  3310. perpendicular: 0x22A5,
  3311. perthousand: 0x2030,
  3312. peseta: 0x20A7,
  3313. pfsquare: 0x338A,
  3314. phabengali: 0x09AB,
  3315. phadeva: 0x092B,
  3316. phagujarati: 0x0AAB,
  3317. phagurmukhi: 0x0A2B,
  3318. phi: 0x03C6,
  3319. phi1: 0x03D5,
  3320. phieuphacirclekorean: 0x327A,
  3321. phieuphaparenkorean: 0x321A,
  3322. phieuphcirclekorean: 0x326C,
  3323. phieuphkorean: 0x314D,
  3324. phieuphparenkorean: 0x320C,
  3325. philatin: 0x0278,
  3326. phinthuthai: 0x0E3A,
  3327. phisymbolgreek: 0x03D5,
  3328. phook: 0x01A5,
  3329. phophanthai: 0x0E1E,
  3330. phophungthai: 0x0E1C,
  3331. phosamphaothai: 0x0E20,
  3332. pi: 0x03C0,
  3333. pieupacirclekorean: 0x3273,
  3334. pieupaparenkorean: 0x3213,
  3335. pieupcieuckorean: 0x3176,
  3336. pieupcirclekorean: 0x3265,
  3337. pieupkiyeokkorean: 0x3172,
  3338. pieupkorean: 0x3142,
  3339. pieupparenkorean: 0x3205,
  3340. pieupsioskiyeokkorean: 0x3174,
  3341. pieupsioskorean: 0x3144,
  3342. pieupsiostikeutkorean: 0x3175,
  3343. pieupthieuthkorean: 0x3177,
  3344. pieuptikeutkorean: 0x3173,
  3345. pihiragana: 0x3074,
  3346. pikatakana: 0x30D4,
  3347. pisymbolgreek: 0x03D6,
  3348. piwrarmenian: 0x0583,
  3349. plus: 0x002B,
  3350. plusbelowcmb: 0x031F,
  3351. pluscircle: 0x2295,
  3352. plusminus: 0x00B1,
  3353. plusmod: 0x02D6,
  3354. plusmonospace: 0xFF0B,
  3355. plussmall: 0xFE62,
  3356. plussuperior: 0x207A,
  3357. pmonospace: 0xFF50,
  3358. pmsquare: 0x33D8,
  3359. pohiragana: 0x307D,
  3360. pointingindexdownwhite: 0x261F,
  3361. pointingindexleftwhite: 0x261C,
  3362. pointingindexrightwhite: 0x261E,
  3363. pointingindexupwhite: 0x261D,
  3364. pokatakana: 0x30DD,
  3365. poplathai: 0x0E1B,
  3366. postalmark: 0x3012,
  3367. postalmarkface: 0x3020,
  3368. pparen: 0x24AB,
  3369. precedes: 0x227A,
  3370. prescription: 0x211E,
  3371. primemod: 0x02B9,
  3372. primereversed: 0x2035,
  3373. product: 0x220F,
  3374. projective: 0x2305,
  3375. prolongedkana: 0x30FC,
  3376. propellor: 0x2318,
  3377. propersubset: 0x2282,
  3378. propersuperset: 0x2283,
  3379. proportion: 0x2237,
  3380. proportional: 0x221D,
  3381. psi: 0x03C8,
  3382. psicyrillic: 0x0471,
  3383. psilipneumatacyrilliccmb: 0x0486,
  3384. pssquare: 0x33B0,
  3385. puhiragana: 0x3077,
  3386. pukatakana: 0x30D7,
  3387. pvsquare: 0x33B4,
  3388. pwsquare: 0x33BA,
  3389. q: 0x0071,
  3390. qadeva: 0x0958,
  3391. qadmahebrew: 0x05A8,
  3392. qafarabic: 0x0642,
  3393. qaffinalarabic: 0xFED6,
  3394. qafinitialarabic: 0xFED7,
  3395. qafmedialarabic: 0xFED8,
  3396. qamats: 0x05B8,
  3397. qamats10: 0x05B8,
  3398. qamats1a: 0x05B8,
  3399. qamats1c: 0x05B8,
  3400. qamats27: 0x05B8,
  3401. qamats29: 0x05B8,
  3402. qamats33: 0x05B8,
  3403. qamatsde: 0x05B8,
  3404. qamatshebrew: 0x05B8,
  3405. qamatsnarrowhebrew: 0x05B8,
  3406. qamatsqatanhebrew: 0x05B8,
  3407. qamatsqatannarrowhebrew: 0x05B8,
  3408. qamatsqatanquarterhebrew: 0x05B8,
  3409. qamatsqatanwidehebrew: 0x05B8,
  3410. qamatsquarterhebrew: 0x05B8,
  3411. qamatswidehebrew: 0x05B8,
  3412. qarneyparahebrew: 0x059F,
  3413. qbopomofo: 0x3111,
  3414. qcircle: 0x24E0,
  3415. qhook: 0x02A0,
  3416. qmonospace: 0xFF51,
  3417. qof: 0x05E7,
  3418. qofdagesh: 0xFB47,
  3419. qofdageshhebrew: 0xFB47,
  3420. qofhebrew: 0x05E7,
  3421. qparen: 0x24AC,
  3422. quarternote: 0x2669,
  3423. qubuts: 0x05BB,
  3424. qubuts18: 0x05BB,
  3425. qubuts25: 0x05BB,
  3426. qubuts31: 0x05BB,
  3427. qubutshebrew: 0x05BB,
  3428. qubutsnarrowhebrew: 0x05BB,
  3429. qubutsquarterhebrew: 0x05BB,
  3430. qubutswidehebrew: 0x05BB,
  3431. question: 0x003F,
  3432. questionarabic: 0x061F,
  3433. questionarmenian: 0x055E,
  3434. questiondown: 0x00BF,
  3435. questiondownsmall: 0xF7BF,
  3436. questiongreek: 0x037E,
  3437. questionmonospace: 0xFF1F,
  3438. questionsmall: 0xF73F,
  3439. quotedbl: 0x0022,
  3440. quotedblbase: 0x201E,
  3441. quotedblleft: 0x201C,
  3442. quotedblmonospace: 0xFF02,
  3443. quotedblprime: 0x301E,
  3444. quotedblprimereversed: 0x301D,
  3445. quotedblright: 0x201D,
  3446. quoteleft: 0x2018,
  3447. quoteleftreversed: 0x201B,
  3448. quotereversed: 0x201B,
  3449. quoteright: 0x2019,
  3450. quoterightn: 0x0149,
  3451. quotesinglbase: 0x201A,
  3452. quotesingle: 0x0027,
  3453. quotesinglemonospace: 0xFF07,
  3454. r: 0x0072,
  3455. raarmenian: 0x057C,
  3456. rabengali: 0x09B0,
  3457. racute: 0x0155,
  3458. radeva: 0x0930,
  3459. radical: 0x221A,
  3460. radicalex: 0xF8E5,
  3461. radoverssquare: 0x33AE,
  3462. radoverssquaredsquare: 0x33AF,
  3463. radsquare: 0x33AD,
  3464. rafe: 0x05BF,
  3465. rafehebrew: 0x05BF,
  3466. ragujarati: 0x0AB0,
  3467. ragurmukhi: 0x0A30,
  3468. rahiragana: 0x3089,
  3469. rakatakana: 0x30E9,
  3470. rakatakanahalfwidth: 0xFF97,
  3471. ralowerdiagonalbengali: 0x09F1,
  3472. ramiddlediagonalbengali: 0x09F0,
  3473. ramshorn: 0x0264,
  3474. ratio: 0x2236,
  3475. rbopomofo: 0x3116,
  3476. rcaron: 0x0159,
  3477. rcedilla: 0x0157,
  3478. rcircle: 0x24E1,
  3479. rcommaaccent: 0x0157,
  3480. rdblgrave: 0x0211,
  3481. rdotaccent: 0x1E59,
  3482. rdotbelow: 0x1E5B,
  3483. rdotbelowmacron: 0x1E5D,
  3484. referencemark: 0x203B,
  3485. reflexsubset: 0x2286,
  3486. reflexsuperset: 0x2287,
  3487. registered: 0x00AE,
  3488. registersans: 0xF8E8,
  3489. registerserif: 0xF6DA,
  3490. reharabic: 0x0631,
  3491. reharmenian: 0x0580,
  3492. rehfinalarabic: 0xFEAE,
  3493. rehiragana: 0x308C,
  3494. rekatakana: 0x30EC,
  3495. rekatakanahalfwidth: 0xFF9A,
  3496. resh: 0x05E8,
  3497. reshdageshhebrew: 0xFB48,
  3498. reshhebrew: 0x05E8,
  3499. reversedtilde: 0x223D,
  3500. reviahebrew: 0x0597,
  3501. reviamugrashhebrew: 0x0597,
  3502. revlogicalnot: 0x2310,
  3503. rfishhook: 0x027E,
  3504. rfishhookreversed: 0x027F,
  3505. rhabengali: 0x09DD,
  3506. rhadeva: 0x095D,
  3507. rho: 0x03C1,
  3508. rhook: 0x027D,
  3509. rhookturned: 0x027B,
  3510. rhookturnedsuperior: 0x02B5,
  3511. rhosymbolgreek: 0x03F1,
  3512. rhotichookmod: 0x02DE,
  3513. rieulacirclekorean: 0x3271,
  3514. rieulaparenkorean: 0x3211,
  3515. rieulcirclekorean: 0x3263,
  3516. rieulhieuhkorean: 0x3140,
  3517. rieulkiyeokkorean: 0x313A,
  3518. rieulkiyeoksioskorean: 0x3169,
  3519. rieulkorean: 0x3139,
  3520. rieulmieumkorean: 0x313B,
  3521. rieulpansioskorean: 0x316C,
  3522. rieulparenkorean: 0x3203,
  3523. rieulphieuphkorean: 0x313F,
  3524. rieulpieupkorean: 0x313C,
  3525. rieulpieupsioskorean: 0x316B,
  3526. rieulsioskorean: 0x313D,
  3527. rieulthieuthkorean: 0x313E,
  3528. rieultikeutkorean: 0x316A,
  3529. rieulyeorinhieuhkorean: 0x316D,
  3530. rightangle: 0x221F,
  3531. righttackbelowcmb: 0x0319,
  3532. righttriangle: 0x22BF,
  3533. rihiragana: 0x308A,
  3534. rikatakana: 0x30EA,
  3535. rikatakanahalfwidth: 0xFF98,
  3536. ring: 0x02DA,
  3537. ringbelowcmb: 0x0325,
  3538. ringcmb: 0x030A,
  3539. ringhalfleft: 0x02BF,
  3540. ringhalfleftarmenian: 0x0559,
  3541. ringhalfleftbelowcmb: 0x031C,
  3542. ringhalfleftcentered: 0x02D3,
  3543. ringhalfright: 0x02BE,
  3544. ringhalfrightbelowcmb: 0x0339,
  3545. ringhalfrightcentered: 0x02D2,
  3546. rinvertedbreve: 0x0213,
  3547. rittorusquare: 0x3351,
  3548. rlinebelow: 0x1E5F,
  3549. rlongleg: 0x027C,
  3550. rlonglegturned: 0x027A,
  3551. rmonospace: 0xFF52,
  3552. rohiragana: 0x308D,
  3553. rokatakana: 0x30ED,
  3554. rokatakanahalfwidth: 0xFF9B,
  3555. roruathai: 0x0E23,
  3556. rparen: 0x24AD,
  3557. rrabengali: 0x09DC,
  3558. rradeva: 0x0931,
  3559. rragurmukhi: 0x0A5C,
  3560. rreharabic: 0x0691,
  3561. rrehfinalarabic: 0xFB8D,
  3562. rrvocalicbengali: 0x09E0,
  3563. rrvocalicdeva: 0x0960,
  3564. rrvocalicgujarati: 0x0AE0,
  3565. rrvocalicvowelsignbengali: 0x09C4,
  3566. rrvocalicvowelsigndeva: 0x0944,
  3567. rrvocalicvowelsigngujarati: 0x0AC4,
  3568. rsuperior: 0xF6F1,
  3569. rtblock: 0x2590,
  3570. rturned: 0x0279,
  3571. rturnedsuperior: 0x02B4,
  3572. ruhiragana: 0x308B,
  3573. rukatakana: 0x30EB,
  3574. rukatakanahalfwidth: 0xFF99,
  3575. rupeemarkbengali: 0x09F2,
  3576. rupeesignbengali: 0x09F3,
  3577. rupiah: 0xF6DD,
  3578. ruthai: 0x0E24,
  3579. rvocalicbengali: 0x098B,
  3580. rvocalicdeva: 0x090B,
  3581. rvocalicgujarati: 0x0A8B,
  3582. rvocalicvowelsignbengali: 0x09C3,
  3583. rvocalicvowelsigndeva: 0x0943,
  3584. rvocalicvowelsigngujarati: 0x0AC3,
  3585. s: 0x0073,
  3586. sabengali: 0x09B8,
  3587. sacute: 0x015B,
  3588. sacutedotaccent: 0x1E65,
  3589. sadarabic: 0x0635,
  3590. sadeva: 0x0938,
  3591. sadfinalarabic: 0xFEBA,
  3592. sadinitialarabic: 0xFEBB,
  3593. sadmedialarabic: 0xFEBC,
  3594. sagujarati: 0x0AB8,
  3595. sagurmukhi: 0x0A38,
  3596. sahiragana: 0x3055,
  3597. sakatakana: 0x30B5,
  3598. sakatakanahalfwidth: 0xFF7B,
  3599. sallallahoualayhewasallamarabic: 0xFDFA,
  3600. samekh: 0x05E1,
  3601. samekhdagesh: 0xFB41,
  3602. samekhdageshhebrew: 0xFB41,
  3603. samekhhebrew: 0x05E1,
  3604. saraaathai: 0x0E32,
  3605. saraaethai: 0x0E41,
  3606. saraaimaimalaithai: 0x0E44,
  3607. saraaimaimuanthai: 0x0E43,
  3608. saraamthai: 0x0E33,
  3609. saraathai: 0x0E30,
  3610. saraethai: 0x0E40,
  3611. saraiileftthai: 0xF886,
  3612. saraiithai: 0x0E35,
  3613. saraileftthai: 0xF885,
  3614. saraithai: 0x0E34,
  3615. saraothai: 0x0E42,
  3616. saraueeleftthai: 0xF888,
  3617. saraueethai: 0x0E37,
  3618. saraueleftthai: 0xF887,
  3619. sarauethai: 0x0E36,
  3620. sarauthai: 0x0E38,
  3621. sarauuthai: 0x0E39,
  3622. sbopomofo: 0x3119,
  3623. scaron: 0x0161,
  3624. scarondotaccent: 0x1E67,
  3625. scedilla: 0x015F,
  3626. schwa: 0x0259,
  3627. schwacyrillic: 0x04D9,
  3628. schwadieresiscyrillic: 0x04DB,
  3629. schwahook: 0x025A,
  3630. scircle: 0x24E2,
  3631. scircumflex: 0x015D,
  3632. scommaaccent: 0x0219,
  3633. sdotaccent: 0x1E61,
  3634. sdotbelow: 0x1E63,
  3635. sdotbelowdotaccent: 0x1E69,
  3636. seagullbelowcmb: 0x033C,
  3637. second: 0x2033,
  3638. secondtonechinese: 0x02CA,
  3639. section: 0x00A7,
  3640. seenarabic: 0x0633,
  3641. seenfinalarabic: 0xFEB2,
  3642. seeninitialarabic: 0xFEB3,
  3643. seenmedialarabic: 0xFEB4,
  3644. segol: 0x05B6,
  3645. segol13: 0x05B6,
  3646. segol1f: 0x05B6,
  3647. segol2c: 0x05B6,
  3648. segolhebrew: 0x05B6,
  3649. segolnarrowhebrew: 0x05B6,
  3650. segolquarterhebrew: 0x05B6,
  3651. segoltahebrew: 0x0592,
  3652. segolwidehebrew: 0x05B6,
  3653. seharmenian: 0x057D,
  3654. sehiragana: 0x305B,
  3655. sekatakana: 0x30BB,
  3656. sekatakanahalfwidth: 0xFF7E,
  3657. semicolon: 0x003B,
  3658. semicolonarabic: 0x061B,
  3659. semicolonmonospace: 0xFF1B,
  3660. semicolonsmall: 0xFE54,
  3661. semivoicedmarkkana: 0x309C,
  3662. semivoicedmarkkanahalfwidth: 0xFF9F,
  3663. sentisquare: 0x3322,
  3664. sentosquare: 0x3323,
  3665. seven: 0x0037,
  3666. sevenarabic: 0x0667,
  3667. sevenbengali: 0x09ED,
  3668. sevencircle: 0x2466,
  3669. sevencircleinversesansserif: 0x2790,
  3670. sevendeva: 0x096D,
  3671. seveneighths: 0x215E,
  3672. sevengujarati: 0x0AED,
  3673. sevengurmukhi: 0x0A6D,
  3674. sevenhackarabic: 0x0667,
  3675. sevenhangzhou: 0x3027,
  3676. sevenideographicparen: 0x3226,
  3677. seveninferior: 0x2087,
  3678. sevenmonospace: 0xFF17,
  3679. sevenoldstyle: 0xF737,
  3680. sevenparen: 0x247A,
  3681. sevenperiod: 0x248E,
  3682. sevenpersian: 0x06F7,
  3683. sevenroman: 0x2176,
  3684. sevensuperior: 0x2077,
  3685. seventeencircle: 0x2470,
  3686. seventeenparen: 0x2484,
  3687. seventeenperiod: 0x2498,
  3688. seventhai: 0x0E57,
  3689. sfthyphen: 0x00AD,
  3690. shaarmenian: 0x0577,
  3691. shabengali: 0x09B6,
  3692. shacyrillic: 0x0448,
  3693. shaddaarabic: 0x0651,
  3694. shaddadammaarabic: 0xFC61,
  3695. shaddadammatanarabic: 0xFC5E,
  3696. shaddafathaarabic: 0xFC60,
  3697. shaddakasraarabic: 0xFC62,
  3698. shaddakasratanarabic: 0xFC5F,
  3699. shade: 0x2592,
  3700. shadedark: 0x2593,
  3701. shadelight: 0x2591,
  3702. shademedium: 0x2592,
  3703. shadeva: 0x0936,
  3704. shagujarati: 0x0AB6,
  3705. shagurmukhi: 0x0A36,
  3706. shalshelethebrew: 0x0593,
  3707. shbopomofo: 0x3115,
  3708. shchacyrillic: 0x0449,
  3709. sheenarabic: 0x0634,
  3710. sheenfinalarabic: 0xFEB6,
  3711. sheeninitialarabic: 0xFEB7,
  3712. sheenmedialarabic: 0xFEB8,
  3713. sheicoptic: 0x03E3,
  3714. sheqel: 0x20AA,
  3715. sheqelhebrew: 0x20AA,
  3716. sheva: 0x05B0,
  3717. sheva115: 0x05B0,
  3718. sheva15: 0x05B0,
  3719. sheva22: 0x05B0,
  3720. sheva2e: 0x05B0,
  3721. shevahebrew: 0x05B0,
  3722. shevanarrowhebrew: 0x05B0,
  3723. shevaquarterhebrew: 0x05B0,
  3724. shevawidehebrew: 0x05B0,
  3725. shhacyrillic: 0x04BB,
  3726. shimacoptic: 0x03ED,
  3727. shin: 0x05E9,
  3728. shindagesh: 0xFB49,
  3729. shindageshhebrew: 0xFB49,
  3730. shindageshshindot: 0xFB2C,
  3731. shindageshshindothebrew: 0xFB2C,
  3732. shindageshsindot: 0xFB2D,
  3733. shindageshsindothebrew: 0xFB2D,
  3734. shindothebrew: 0x05C1,
  3735. shinhebrew: 0x05E9,
  3736. shinshindot: 0xFB2A,
  3737. shinshindothebrew: 0xFB2A,
  3738. shinsindot: 0xFB2B,
  3739. shinsindothebrew: 0xFB2B,
  3740. shook: 0x0282,
  3741. sigma: 0x03C3,
  3742. sigma1: 0x03C2,
  3743. sigmafinal: 0x03C2,
  3744. sigmalunatesymbolgreek: 0x03F2,
  3745. sihiragana: 0x3057,
  3746. sikatakana: 0x30B7,
  3747. sikatakanahalfwidth: 0xFF7C,
  3748. siluqhebrew: 0x05BD,
  3749. siluqlefthebrew: 0x05BD,
  3750. similar: 0x223C,
  3751. sindothebrew: 0x05C2,
  3752. siosacirclekorean: 0x3274,
  3753. siosaparenkorean: 0x3214,
  3754. sioscieuckorean: 0x317E,
  3755. sioscirclekorean: 0x3266,
  3756. sioskiyeokkorean: 0x317A,
  3757. sioskorean: 0x3145,
  3758. siosnieunkorean: 0x317B,
  3759. siosparenkorean: 0x3206,
  3760. siospieupkorean: 0x317D,
  3761. siostikeutkorean: 0x317C,
  3762. six: 0x0036,
  3763. sixarabic: 0x0666,
  3764. sixbengali: 0x09EC,
  3765. sixcircle: 0x2465,
  3766. sixcircleinversesansserif: 0x278F,
  3767. sixdeva: 0x096C,
  3768. sixgujarati: 0x0AEC,
  3769. sixgurmukhi: 0x0A6C,
  3770. sixhackarabic: 0x0666,
  3771. sixhangzhou: 0x3026,
  3772. sixideographicparen: 0x3225,
  3773. sixinferior: 0x2086,
  3774. sixmonospace: 0xFF16,
  3775. sixoldstyle: 0xF736,
  3776. sixparen: 0x2479,
  3777. sixperiod: 0x248D,
  3778. sixpersian: 0x06F6,
  3779. sixroman: 0x2175,
  3780. sixsuperior: 0x2076,
  3781. sixteencircle: 0x246F,
  3782. sixteencurrencydenominatorbengali: 0x09F9,
  3783. sixteenparen: 0x2483,
  3784. sixteenperiod: 0x2497,
  3785. sixthai: 0x0E56,
  3786. slash: 0x002F,
  3787. slashmonospace: 0xFF0F,
  3788. slong: 0x017F,
  3789. slongdotaccent: 0x1E9B,
  3790. smileface: 0x263A,
  3791. smonospace: 0xFF53,
  3792. sofpasuqhebrew: 0x05C3,
  3793. softhyphen: 0x00AD,
  3794. softsigncyrillic: 0x044C,
  3795. sohiragana: 0x305D,
  3796. sokatakana: 0x30BD,
  3797. sokatakanahalfwidth: 0xFF7F,
  3798. soliduslongoverlaycmb: 0x0338,
  3799. solidusshortoverlaycmb: 0x0337,
  3800. sorusithai: 0x0E29,
  3801. sosalathai: 0x0E28,
  3802. sosothai: 0x0E0B,
  3803. sosuathai: 0x0E2A,
  3804. space: 0x0020,
  3805. spacehackarabic: 0x0020,
  3806. spade: 0x2660,
  3807. spadesuitblack: 0x2660,
  3808. spadesuitwhite: 0x2664,
  3809. sparen: 0x24AE,
  3810. squarebelowcmb: 0x033B,
  3811. squarecc: 0x33C4,
  3812. squarecm: 0x339D,
  3813. squarediagonalcrosshatchfill: 0x25A9,
  3814. squarehorizontalfill: 0x25A4,
  3815. squarekg: 0x338F,
  3816. squarekm: 0x339E,
  3817. squarekmcapital: 0x33CE,
  3818. squareln: 0x33D1,
  3819. squarelog: 0x33D2,
  3820. squaremg: 0x338E,
  3821. squaremil: 0x33D5,
  3822. squaremm: 0x339C,
  3823. squaremsquared: 0x33A1,
  3824. squareorthogonalcrosshatchfill: 0x25A6,
  3825. squareupperlefttolowerrightfill: 0x25A7,
  3826. squareupperrighttolowerleftfill: 0x25A8,
  3827. squareverticalfill: 0x25A5,
  3828. squarewhitewithsmallblack: 0x25A3,
  3829. srsquare: 0x33DB,
  3830. ssabengali: 0x09B7,
  3831. ssadeva: 0x0937,
  3832. ssagujarati: 0x0AB7,
  3833. ssangcieuckorean: 0x3149,
  3834. ssanghieuhkorean: 0x3185,
  3835. ssangieungkorean: 0x3180,
  3836. ssangkiyeokkorean: 0x3132,
  3837. ssangnieunkorean: 0x3165,
  3838. ssangpieupkorean: 0x3143,
  3839. ssangsioskorean: 0x3146,
  3840. ssangtikeutkorean: 0x3138,
  3841. ssuperior: 0xF6F2,
  3842. sterling: 0x00A3,
  3843. sterlingmonospace: 0xFFE1,
  3844. strokelongoverlaycmb: 0x0336,
  3845. strokeshortoverlaycmb: 0x0335,
  3846. subset: 0x2282,
  3847. subsetnotequal: 0x228A,
  3848. subsetorequal: 0x2286,
  3849. succeeds: 0x227B,
  3850. suchthat: 0x220B,
  3851. suhiragana: 0x3059,
  3852. sukatakana: 0x30B9,
  3853. sukatakanahalfwidth: 0xFF7D,
  3854. sukunarabic: 0x0652,
  3855. summation: 0x2211,
  3856. sun: 0x263C,
  3857. superset: 0x2283,
  3858. supersetnotequal: 0x228B,
  3859. supersetorequal: 0x2287,
  3860. svsquare: 0x33DC,
  3861. syouwaerasquare: 0x337C,
  3862. t: 0x0074,
  3863. tabengali: 0x09A4,
  3864. tackdown: 0x22A4,
  3865. tackleft: 0x22A3,
  3866. tadeva: 0x0924,
  3867. tagujarati: 0x0AA4,
  3868. tagurmukhi: 0x0A24,
  3869. taharabic: 0x0637,
  3870. tahfinalarabic: 0xFEC2,
  3871. tahinitialarabic: 0xFEC3,
  3872. tahiragana: 0x305F,
  3873. tahmedialarabic: 0xFEC4,
  3874. taisyouerasquare: 0x337D,
  3875. takatakana: 0x30BF,
  3876. takatakanahalfwidth: 0xFF80,
  3877. tatweelarabic: 0x0640,
  3878. tau: 0x03C4,
  3879. tav: 0x05EA,
  3880. tavdages: 0xFB4A,
  3881. tavdagesh: 0xFB4A,
  3882. tavdageshhebrew: 0xFB4A,
  3883. tavhebrew: 0x05EA,
  3884. tbar: 0x0167,
  3885. tbopomofo: 0x310A,
  3886. tcaron: 0x0165,
  3887. tccurl: 0x02A8,
  3888. tcedilla: 0x0163,
  3889. tcheharabic: 0x0686,
  3890. tchehfinalarabic: 0xFB7B,
  3891. tchehinitialarabic: 0xFB7C,
  3892. tchehmedialarabic: 0xFB7D,
  3893. tcircle: 0x24E3,
  3894. tcircumflexbelow: 0x1E71,
  3895. tcommaaccent: 0x0163,
  3896. tdieresis: 0x1E97,
  3897. tdotaccent: 0x1E6B,
  3898. tdotbelow: 0x1E6D,
  3899. tecyrillic: 0x0442,
  3900. tedescendercyrillic: 0x04AD,
  3901. teharabic: 0x062A,
  3902. tehfinalarabic: 0xFE96,
  3903. tehhahinitialarabic: 0xFCA2,
  3904. tehhahisolatedarabic: 0xFC0C,
  3905. tehinitialarabic: 0xFE97,
  3906. tehiragana: 0x3066,
  3907. tehjeeminitialarabic: 0xFCA1,
  3908. tehjeemisolatedarabic: 0xFC0B,
  3909. tehmarbutaarabic: 0x0629,
  3910. tehmarbutafinalarabic: 0xFE94,
  3911. tehmedialarabic: 0xFE98,
  3912. tehmeeminitialarabic: 0xFCA4,
  3913. tehmeemisolatedarabic: 0xFC0E,
  3914. tehnoonfinalarabic: 0xFC73,
  3915. tekatakana: 0x30C6,
  3916. tekatakanahalfwidth: 0xFF83,
  3917. telephone: 0x2121,
  3918. telephoneblack: 0x260E,
  3919. telishagedolahebrew: 0x05A0,
  3920. telishaqetanahebrew: 0x05A9,
  3921. tencircle: 0x2469,
  3922. tenideographicparen: 0x3229,
  3923. tenparen: 0x247D,
  3924. tenperiod: 0x2491,
  3925. tenroman: 0x2179,
  3926. tesh: 0x02A7,
  3927. tet: 0x05D8,
  3928. tetdagesh: 0xFB38,
  3929. tetdageshhebrew: 0xFB38,
  3930. tethebrew: 0x05D8,
  3931. tetsecyrillic: 0x04B5,
  3932. tevirhebrew: 0x059B,
  3933. tevirlefthebrew: 0x059B,
  3934. thabengali: 0x09A5,
  3935. thadeva: 0x0925,
  3936. thagujarati: 0x0AA5,
  3937. thagurmukhi: 0x0A25,
  3938. thalarabic: 0x0630,
  3939. thalfinalarabic: 0xFEAC,
  3940. thanthakhatlowleftthai: 0xF898,
  3941. thanthakhatlowrightthai: 0xF897,
  3942. thanthakhatthai: 0x0E4C,
  3943. thanthakhatupperleftthai: 0xF896,
  3944. theharabic: 0x062B,
  3945. thehfinalarabic: 0xFE9A,
  3946. thehinitialarabic: 0xFE9B,
  3947. thehmedialarabic: 0xFE9C,
  3948. thereexists: 0x2203,
  3949. therefore: 0x2234,
  3950. theta: 0x03B8,
  3951. theta1: 0x03D1,
  3952. thetasymbolgreek: 0x03D1,
  3953. thieuthacirclekorean: 0x3279,
  3954. thieuthaparenkorean: 0x3219,
  3955. thieuthcirclekorean: 0x326B,
  3956. thieuthkorean: 0x314C,
  3957. thieuthparenkorean: 0x320B,
  3958. thirteencircle: 0x246C,
  3959. thirteenparen: 0x2480,
  3960. thirteenperiod: 0x2494,
  3961. thonangmonthothai: 0x0E11,
  3962. thook: 0x01AD,
  3963. thophuthaothai: 0x0E12,
  3964. thorn: 0x00FE,
  3965. thothahanthai: 0x0E17,
  3966. thothanthai: 0x0E10,
  3967. thothongthai: 0x0E18,
  3968. thothungthai: 0x0E16,
  3969. thousandcyrillic: 0x0482,
  3970. thousandsseparatorarabic: 0x066C,
  3971. thousandsseparatorpersian: 0x066C,
  3972. three: 0x0033,
  3973. threearabic: 0x0663,
  3974. threebengali: 0x09E9,
  3975. threecircle: 0x2462,
  3976. threecircleinversesansserif: 0x278C,
  3977. threedeva: 0x0969,
  3978. threeeighths: 0x215C,
  3979. threegujarati: 0x0AE9,
  3980. threegurmukhi: 0x0A69,
  3981. threehackarabic: 0x0663,
  3982. threehangzhou: 0x3023,
  3983. threeideographicparen: 0x3222,
  3984. threeinferior: 0x2083,
  3985. threemonospace: 0xFF13,
  3986. threenumeratorbengali: 0x09F6,
  3987. threeoldstyle: 0xF733,
  3988. threeparen: 0x2476,
  3989. threeperiod: 0x248A,
  3990. threepersian: 0x06F3,
  3991. threequarters: 0x00BE,
  3992. threequartersemdash: 0xF6DE,
  3993. threeroman: 0x2172,
  3994. threesuperior: 0x00B3,
  3995. threethai: 0x0E53,
  3996. thzsquare: 0x3394,
  3997. tihiragana: 0x3061,
  3998. tikatakana: 0x30C1,
  3999. tikatakanahalfwidth: 0xFF81,
  4000. tikeutacirclekorean: 0x3270,
  4001. tikeutaparenkorean: 0x3210,
  4002. tikeutcirclekorean: 0x3262,
  4003. tikeutkorean: 0x3137,
  4004. tikeutparenkorean: 0x3202,
  4005. tilde: 0x02DC,
  4006. tildebelowcmb: 0x0330,
  4007. tildecmb: 0x0303,
  4008. tildecomb: 0x0303,
  4009. tildedoublecmb: 0x0360,
  4010. tildeoperator: 0x223C,
  4011. tildeoverlaycmb: 0x0334,
  4012. tildeverticalcmb: 0x033E,
  4013. timescircle: 0x2297,
  4014. tipehahebrew: 0x0596,
  4015. tipehalefthebrew: 0x0596,
  4016. tippigurmukhi: 0x0A70,
  4017. titlocyrilliccmb: 0x0483,
  4018. tiwnarmenian: 0x057F,
  4019. tlinebelow: 0x1E6F,
  4020. tmonospace: 0xFF54,
  4021. toarmenian: 0x0569,
  4022. tohiragana: 0x3068,
  4023. tokatakana: 0x30C8,
  4024. tokatakanahalfwidth: 0xFF84,
  4025. tonebarextrahighmod: 0x02E5,
  4026. tonebarextralowmod: 0x02E9,
  4027. tonebarhighmod: 0x02E6,
  4028. tonebarlowmod: 0x02E8,
  4029. tonebarmidmod: 0x02E7,
  4030. tonefive: 0x01BD,
  4031. tonesix: 0x0185,
  4032. tonetwo: 0x01A8,
  4033. tonos: 0x0384,
  4034. tonsquare: 0x3327,
  4035. topatakthai: 0x0E0F,
  4036. tortoiseshellbracketleft: 0x3014,
  4037. tortoiseshellbracketleftsmall: 0xFE5D,
  4038. tortoiseshellbracketleftvertical: 0xFE39,
  4039. tortoiseshellbracketright: 0x3015,
  4040. tortoiseshellbracketrightsmall: 0xFE5E,
  4041. tortoiseshellbracketrightvertical: 0xFE3A,
  4042. totaothai: 0x0E15,
  4043. tpalatalhook: 0x01AB,
  4044. tparen: 0x24AF,
  4045. trademark: 0x2122,
  4046. trademarksans: 0xF8EA,
  4047. trademarkserif: 0xF6DB,
  4048. tretroflexhook: 0x0288,
  4049. triagdn: 0x25BC,
  4050. triaglf: 0x25C4,
  4051. triagrt: 0x25BA,
  4052. triagup: 0x25B2,
  4053. ts: 0x02A6,
  4054. tsadi: 0x05E6,
  4055. tsadidagesh: 0xFB46,
  4056. tsadidageshhebrew: 0xFB46,
  4057. tsadihebrew: 0x05E6,
  4058. tsecyrillic: 0x0446,
  4059. tsere: 0x05B5,
  4060. tsere12: 0x05B5,
  4061. tsere1e: 0x05B5,
  4062. tsere2b: 0x05B5,
  4063. tserehebrew: 0x05B5,
  4064. tserenarrowhebrew: 0x05B5,
  4065. tserequarterhebrew: 0x05B5,
  4066. tserewidehebrew: 0x05B5,
  4067. tshecyrillic: 0x045B,
  4068. tsuperior: 0xF6F3,
  4069. ttabengali: 0x099F,
  4070. ttadeva: 0x091F,
  4071. ttagujarati: 0x0A9F,
  4072. ttagurmukhi: 0x0A1F,
  4073. tteharabic: 0x0679,
  4074. ttehfinalarabic: 0xFB67,
  4075. ttehinitialarabic: 0xFB68,
  4076. ttehmedialarabic: 0xFB69,
  4077. tthabengali: 0x09A0,
  4078. tthadeva: 0x0920,
  4079. tthagujarati: 0x0AA0,
  4080. tthagurmukhi: 0x0A20,
  4081. tturned: 0x0287,
  4082. tuhiragana: 0x3064,
  4083. tukatakana: 0x30C4,
  4084. tukatakanahalfwidth: 0xFF82,
  4085. tusmallhiragana: 0x3063,
  4086. tusmallkatakana: 0x30C3,
  4087. tusmallkatakanahalfwidth: 0xFF6F,
  4088. twelvecircle: 0x246B,
  4089. twelveparen: 0x247F,
  4090. twelveperiod: 0x2493,
  4091. twelveroman: 0x217B,
  4092. twentycircle: 0x2473,
  4093. twentyhangzhou: 0x5344,
  4094. twentyparen: 0x2487,
  4095. twentyperiod: 0x249B,
  4096. two: 0x0032,
  4097. twoarabic: 0x0662,
  4098. twobengali: 0x09E8,
  4099. twocircle: 0x2461,
  4100. twocircleinversesansserif: 0x278B,
  4101. twodeva: 0x0968,
  4102. twodotenleader: 0x2025,
  4103. twodotleader: 0x2025,
  4104. twodotleadervertical: 0xFE30,
  4105. twogujarati: 0x0AE8,
  4106. twogurmukhi: 0x0A68,
  4107. twohackarabic: 0x0662,
  4108. twohangzhou: 0x3022,
  4109. twoideographicparen: 0x3221,
  4110. twoinferior: 0x2082,
  4111. twomonospace: 0xFF12,
  4112. twonumeratorbengali: 0x09F5,
  4113. twooldstyle: 0xF732,
  4114. twoparen: 0x2475,
  4115. twoperiod: 0x2489,
  4116. twopersian: 0x06F2,
  4117. tworoman: 0x2171,
  4118. twostroke: 0x01BB,
  4119. twosuperior: 0x00B2,
  4120. twothai: 0x0E52,
  4121. twothirds: 0x2154,
  4122. u: 0x0075,
  4123. uacute: 0x00FA,
  4124. ubar: 0x0289,
  4125. ubengali: 0x0989,
  4126. ubopomofo: 0x3128,
  4127. ubreve: 0x016D,
  4128. ucaron: 0x01D4,
  4129. ucircle: 0x24E4,
  4130. ucircumflex: 0x00FB,
  4131. ucircumflexbelow: 0x1E77,
  4132. ucyrillic: 0x0443,
  4133. udattadeva: 0x0951,
  4134. udblacute: 0x0171,
  4135. udblgrave: 0x0215,
  4136. udeva: 0x0909,
  4137. udieresis: 0x00FC,
  4138. udieresisacute: 0x01D8,
  4139. udieresisbelow: 0x1E73,
  4140. udieresiscaron: 0x01DA,
  4141. udieresiscyrillic: 0x04F1,
  4142. udieresisgrave: 0x01DC,
  4143. udieresismacron: 0x01D6,
  4144. udotbelow: 0x1EE5,
  4145. ugrave: 0x00F9,
  4146. ugujarati: 0x0A89,
  4147. ugurmukhi: 0x0A09,
  4148. uhiragana: 0x3046,
  4149. uhookabove: 0x1EE7,
  4150. uhorn: 0x01B0,
  4151. uhornacute: 0x1EE9,
  4152. uhorndotbelow: 0x1EF1,
  4153. uhorngrave: 0x1EEB,
  4154. uhornhookabove: 0x1EED,
  4155. uhorntilde: 0x1EEF,
  4156. uhungarumlaut: 0x0171,
  4157. uhungarumlautcyrillic: 0x04F3,
  4158. uinvertedbreve: 0x0217,
  4159. ukatakana: 0x30A6,
  4160. ukatakanahalfwidth: 0xFF73,
  4161. ukcyrillic: 0x0479,
  4162. ukorean: 0x315C,
  4163. umacron: 0x016B,
  4164. umacroncyrillic: 0x04EF,
  4165. umacrondieresis: 0x1E7B,
  4166. umatragurmukhi: 0x0A41,
  4167. umonospace: 0xFF55,
  4168. underscore: 0x005F,
  4169. underscoredbl: 0x2017,
  4170. underscoremonospace: 0xFF3F,
  4171. underscorevertical: 0xFE33,
  4172. underscorewavy: 0xFE4F,
  4173. union: 0x222A,
  4174. universal: 0x2200,
  4175. uogonek: 0x0173,
  4176. uparen: 0x24B0,
  4177. upblock: 0x2580,
  4178. upperdothebrew: 0x05C4,
  4179. upsilon: 0x03C5,
  4180. upsilondieresis: 0x03CB,
  4181. upsilondieresistonos: 0x03B0,
  4182. upsilonlatin: 0x028A,
  4183. upsilontonos: 0x03CD,
  4184. uptackbelowcmb: 0x031D,
  4185. uptackmod: 0x02D4,
  4186. uragurmukhi: 0x0A73,
  4187. uring: 0x016F,
  4188. ushortcyrillic: 0x045E,
  4189. usmallhiragana: 0x3045,
  4190. usmallkatakana: 0x30A5,
  4191. usmallkatakanahalfwidth: 0xFF69,
  4192. ustraightcyrillic: 0x04AF,
  4193. ustraightstrokecyrillic: 0x04B1,
  4194. utilde: 0x0169,
  4195. utildeacute: 0x1E79,
  4196. utildebelow: 0x1E75,
  4197. uubengali: 0x098A,
  4198. uudeva: 0x090A,
  4199. uugujarati: 0x0A8A,
  4200. uugurmukhi: 0x0A0A,
  4201. uumatragurmukhi: 0x0A42,
  4202. uuvowelsignbengali: 0x09C2,
  4203. uuvowelsigndeva: 0x0942,
  4204. uuvowelsigngujarati: 0x0AC2,
  4205. uvowelsignbengali: 0x09C1,
  4206. uvowelsigndeva: 0x0941,
  4207. uvowelsigngujarati: 0x0AC1,
  4208. v: 0x0076,
  4209. vadeva: 0x0935,
  4210. vagujarati: 0x0AB5,
  4211. vagurmukhi: 0x0A35,
  4212. vakatakana: 0x30F7,
  4213. vav: 0x05D5,
  4214. vavdagesh: 0xFB35,
  4215. vavdagesh65: 0xFB35,
  4216. vavdageshhebrew: 0xFB35,
  4217. vavhebrew: 0x05D5,
  4218. vavholam: 0xFB4B,
  4219. vavholamhebrew: 0xFB4B,
  4220. vavvavhebrew: 0x05F0,
  4221. vavyodhebrew: 0x05F1,
  4222. vcircle: 0x24E5,
  4223. vdotbelow: 0x1E7F,
  4224. vecyrillic: 0x0432,
  4225. veharabic: 0x06A4,
  4226. vehfinalarabic: 0xFB6B,
  4227. vehinitialarabic: 0xFB6C,
  4228. vehmedialarabic: 0xFB6D,
  4229. vekatakana: 0x30F9,
  4230. venus: 0x2640,
  4231. verticalbar: 0x007C,
  4232. verticallineabovecmb: 0x030D,
  4233. verticallinebelowcmb: 0x0329,
  4234. verticallinelowmod: 0x02CC,
  4235. verticallinemod: 0x02C8,
  4236. vewarmenian: 0x057E,
  4237. vhook: 0x028B,
  4238. vikatakana: 0x30F8,
  4239. viramabengali: 0x09CD,
  4240. viramadeva: 0x094D,
  4241. viramagujarati: 0x0ACD,
  4242. visargabengali: 0x0983,
  4243. visargadeva: 0x0903,
  4244. visargagujarati: 0x0A83,
  4245. vmonospace: 0xFF56,
  4246. voarmenian: 0x0578,
  4247. voicediterationhiragana: 0x309E,
  4248. voicediterationkatakana: 0x30FE,
  4249. voicedmarkkana: 0x309B,
  4250. voicedmarkkanahalfwidth: 0xFF9E,
  4251. vokatakana: 0x30FA,
  4252. vparen: 0x24B1,
  4253. vtilde: 0x1E7D,
  4254. vturned: 0x028C,
  4255. vuhiragana: 0x3094,
  4256. vukatakana: 0x30F4,
  4257. w: 0x0077,
  4258. wacute: 0x1E83,
  4259. waekorean: 0x3159,
  4260. wahiragana: 0x308F,
  4261. wakatakana: 0x30EF,
  4262. wakatakanahalfwidth: 0xFF9C,
  4263. wakorean: 0x3158,
  4264. wasmallhiragana: 0x308E,
  4265. wasmallkatakana: 0x30EE,
  4266. wattosquare: 0x3357,
  4267. wavedash: 0x301C,
  4268. wavyunderscorevertical: 0xFE34,
  4269. wawarabic: 0x0648,
  4270. wawfinalarabic: 0xFEEE,
  4271. wawhamzaabovearabic: 0x0624,
  4272. wawhamzaabovefinalarabic: 0xFE86,
  4273. wbsquare: 0x33DD,
  4274. wcircle: 0x24E6,
  4275. wcircumflex: 0x0175,
  4276. wdieresis: 0x1E85,
  4277. wdotaccent: 0x1E87,
  4278. wdotbelow: 0x1E89,
  4279. wehiragana: 0x3091,
  4280. weierstrass: 0x2118,
  4281. wekatakana: 0x30F1,
  4282. wekorean: 0x315E,
  4283. weokorean: 0x315D,
  4284. wgrave: 0x1E81,
  4285. whitebullet: 0x25E6,
  4286. whitecircle: 0x25CB,
  4287. whitecircleinverse: 0x25D9,
  4288. whitecornerbracketleft: 0x300E,
  4289. whitecornerbracketleftvertical: 0xFE43,
  4290. whitecornerbracketright: 0x300F,
  4291. whitecornerbracketrightvertical: 0xFE44,
  4292. whitediamond: 0x25C7,
  4293. whitediamondcontainingblacksmalldiamond: 0x25C8,
  4294. whitedownpointingsmalltriangle: 0x25BF,
  4295. whitedownpointingtriangle: 0x25BD,
  4296. whiteleftpointingsmalltriangle: 0x25C3,
  4297. whiteleftpointingtriangle: 0x25C1,
  4298. whitelenticularbracketleft: 0x3016,
  4299. whitelenticularbracketright: 0x3017,
  4300. whiterightpointingsmalltriangle: 0x25B9,
  4301. whiterightpointingtriangle: 0x25B7,
  4302. whitesmallsquare: 0x25AB,
  4303. whitesmilingface: 0x263A,
  4304. whitesquare: 0x25A1,
  4305. whitestar: 0x2606,
  4306. whitetelephone: 0x260F,
  4307. whitetortoiseshellbracketleft: 0x3018,
  4308. whitetortoiseshellbracketright: 0x3019,
  4309. whiteuppointingsmalltriangle: 0x25B5,
  4310. whiteuppointingtriangle: 0x25B3,
  4311. wihiragana: 0x3090,
  4312. wikatakana: 0x30F0,
  4313. wikorean: 0x315F,
  4314. wmonospace: 0xFF57,
  4315. wohiragana: 0x3092,
  4316. wokatakana: 0x30F2,
  4317. wokatakanahalfwidth: 0xFF66,
  4318. won: 0x20A9,
  4319. wonmonospace: 0xFFE6,
  4320. wowaenthai: 0x0E27,
  4321. wparen: 0x24B2,
  4322. wring: 0x1E98,
  4323. wsuperior: 0x02B7,
  4324. wturned: 0x028D,
  4325. wynn: 0x01BF,
  4326. x: 0x0078,
  4327. xabovecmb: 0x033D,
  4328. xbopomofo: 0x3112,
  4329. xcircle: 0x24E7,
  4330. xdieresis: 0x1E8D,
  4331. xdotaccent: 0x1E8B,
  4332. xeharmenian: 0x056D,
  4333. xi: 0x03BE,
  4334. xmonospace: 0xFF58,
  4335. xparen: 0x24B3,
  4336. xsuperior: 0x02E3,
  4337. y: 0x0079,
  4338. yaadosquare: 0x334E,
  4339. yabengali: 0x09AF,
  4340. yacute: 0x00FD,
  4341. yadeva: 0x092F,
  4342. yaekorean: 0x3152,
  4343. yagujarati: 0x0AAF,
  4344. yagurmukhi: 0x0A2F,
  4345. yahiragana: 0x3084,
  4346. yakatakana: 0x30E4,
  4347. yakatakanahalfwidth: 0xFF94,
  4348. yakorean: 0x3151,
  4349. yamakkanthai: 0x0E4E,
  4350. yasmallhiragana: 0x3083,
  4351. yasmallkatakana: 0x30E3,
  4352. yasmallkatakanahalfwidth: 0xFF6C,
  4353. yatcyrillic: 0x0463,
  4354. ycircle: 0x24E8,
  4355. ycircumflex: 0x0177,
  4356. ydieresis: 0x00FF,
  4357. ydotaccent: 0x1E8F,
  4358. ydotbelow: 0x1EF5,
  4359. yeharabic: 0x064A,
  4360. yehbarreearabic: 0x06D2,
  4361. yehbarreefinalarabic: 0xFBAF,
  4362. yehfinalarabic: 0xFEF2,
  4363. yehhamzaabovearabic: 0x0626,
  4364. yehhamzaabovefinalarabic: 0xFE8A,
  4365. yehhamzaaboveinitialarabic: 0xFE8B,
  4366. yehhamzaabovemedialarabic: 0xFE8C,
  4367. yehinitialarabic: 0xFEF3,
  4368. yehmedialarabic: 0xFEF4,
  4369. yehmeeminitialarabic: 0xFCDD,
  4370. yehmeemisolatedarabic: 0xFC58,
  4371. yehnoonfinalarabic: 0xFC94,
  4372. yehthreedotsbelowarabic: 0x06D1,
  4373. yekorean: 0x3156,
  4374. yen: 0x00A5,
  4375. yenmonospace: 0xFFE5,
  4376. yeokorean: 0x3155,
  4377. yeorinhieuhkorean: 0x3186,
  4378. yerahbenyomohebrew: 0x05AA,
  4379. yerahbenyomolefthebrew: 0x05AA,
  4380. yericyrillic: 0x044B,
  4381. yerudieresiscyrillic: 0x04F9,
  4382. yesieungkorean: 0x3181,
  4383. yesieungpansioskorean: 0x3183,
  4384. yesieungsioskorean: 0x3182,
  4385. yetivhebrew: 0x059A,
  4386. ygrave: 0x1EF3,
  4387. yhook: 0x01B4,
  4388. yhookabove: 0x1EF7,
  4389. yiarmenian: 0x0575,
  4390. yicyrillic: 0x0457,
  4391. yikorean: 0x3162,
  4392. yinyang: 0x262F,
  4393. yiwnarmenian: 0x0582,
  4394. ymonospace: 0xFF59,
  4395. yod: 0x05D9,
  4396. yoddagesh: 0xFB39,
  4397. yoddageshhebrew: 0xFB39,
  4398. yodhebrew: 0x05D9,
  4399. yodyodhebrew: 0x05F2,
  4400. yodyodpatahhebrew: 0xFB1F,
  4401. yohiragana: 0x3088,
  4402. yoikorean: 0x3189,
  4403. yokatakana: 0x30E8,
  4404. yokatakanahalfwidth: 0xFF96,
  4405. yokorean: 0x315B,
  4406. yosmallhiragana: 0x3087,
  4407. yosmallkatakana: 0x30E7,
  4408. yosmallkatakanahalfwidth: 0xFF6E,
  4409. yotgreek: 0x03F3,
  4410. yoyaekorean: 0x3188,
  4411. yoyakorean: 0x3187,
  4412. yoyakthai: 0x0E22,
  4413. yoyingthai: 0x0E0D,
  4414. yparen: 0x24B4,
  4415. ypogegrammeni: 0x037A,
  4416. ypogegrammenigreekcmb: 0x0345,
  4417. yr: 0x01A6,
  4418. yring: 0x1E99,
  4419. ysuperior: 0x02B8,
  4420. ytilde: 0x1EF9,
  4421. yturned: 0x028E,
  4422. yuhiragana: 0x3086,
  4423. yuikorean: 0x318C,
  4424. yukatakana: 0x30E6,
  4425. yukatakanahalfwidth: 0xFF95,
  4426. yukorean: 0x3160,
  4427. yusbigcyrillic: 0x046B,
  4428. yusbigiotifiedcyrillic: 0x046D,
  4429. yuslittlecyrillic: 0x0467,
  4430. yuslittleiotifiedcyrillic: 0x0469,
  4431. yusmallhiragana: 0x3085,
  4432. yusmallkatakana: 0x30E5,
  4433. yusmallkatakanahalfwidth: 0xFF6D,
  4434. yuyekorean: 0x318B,
  4435. yuyeokorean: 0x318A,
  4436. yyabengali: 0x09DF,
  4437. yyadeva: 0x095F,
  4438. z: 0x007A,
  4439. zaarmenian: 0x0566,
  4440. zacute: 0x017A,
  4441. zadeva: 0x095B,
  4442. zagurmukhi: 0x0A5B,
  4443. zaharabic: 0x0638,
  4444. zahfinalarabic: 0xFEC6,
  4445. zahinitialarabic: 0xFEC7,
  4446. zahiragana: 0x3056,
  4447. zahmedialarabic: 0xFEC8,
  4448. zainarabic: 0x0632,
  4449. zainfinalarabic: 0xFEB0,
  4450. zakatakana: 0x30B6,
  4451. zaqefgadolhebrew: 0x0595,
  4452. zaqefqatanhebrew: 0x0594,
  4453. zarqahebrew: 0x0598,
  4454. zayin: 0x05D6,
  4455. zayindagesh: 0xFB36,
  4456. zayindageshhebrew: 0xFB36,
  4457. zayinhebrew: 0x05D6,
  4458. zbopomofo: 0x3117,
  4459. zcaron: 0x017E,
  4460. zcircle: 0x24E9,
  4461. zcircumflex: 0x1E91,
  4462. zcurl: 0x0291,
  4463. zdot: 0x017C,
  4464. zdotaccent: 0x017C,
  4465. zdotbelow: 0x1E93,
  4466. zecyrillic: 0x0437,
  4467. zedescendercyrillic: 0x0499,
  4468. zedieresiscyrillic: 0x04DF,
  4469. zehiragana: 0x305C,
  4470. zekatakana: 0x30BC,
  4471. zero: 0x0030,
  4472. zeroarabic: 0x0660,
  4473. zerobengali: 0x09E6,
  4474. zerodeva: 0x0966,
  4475. zerogujarati: 0x0AE6,
  4476. zerogurmukhi: 0x0A66,
  4477. zerohackarabic: 0x0660,
  4478. zeroinferior: 0x2080,
  4479. zeromonospace: 0xFF10,
  4480. zerooldstyle: 0xF730,
  4481. zeropersian: 0x06F0,
  4482. zerosuperior: 0x2070,
  4483. zerothai: 0x0E50,
  4484. zerowidthjoiner: 0xFEFF,
  4485. zerowidthnonjoiner: 0x200C,
  4486. zerowidthspace: 0x200B,
  4487. zeta: 0x03B6,
  4488. zhbopomofo: 0x3113,
  4489. zhearmenian: 0x056A,
  4490. zhebrevecyrillic: 0x04C2,
  4491. zhecyrillic: 0x0436,
  4492. zhedescendercyrillic: 0x0497,
  4493. zhedieresiscyrillic: 0x04DD,
  4494. zihiragana: 0x3058,
  4495. zikatakana: 0x30B8,
  4496. zinorhebrew: 0x05AE,
  4497. zlinebelow: 0x1E95,
  4498. zmonospace: 0xFF5A,
  4499. zohiragana: 0x305E,
  4500. zokatakana: 0x30BE,
  4501. zparen: 0x24B5,
  4502. zretroflexhook: 0x0290,
  4503. zstroke: 0x01B6,
  4504. zuhiragana: 0x305A,
  4505. zukatakana: 0x30BA,
  4506. '.notdef': 0x0000
  4507. };
  4508. var DingbatsGlyphsUnicode = {
  4509. space: 0x0020,
  4510. a1: 0x2701,
  4511. a2: 0x2702,
  4512. a202: 0x2703,
  4513. a3: 0x2704,
  4514. a4: 0x260E,
  4515. a5: 0x2706,
  4516. a119: 0x2707,
  4517. a118: 0x2708,
  4518. a117: 0x2709,
  4519. a11: 0x261B,
  4520. a12: 0x261E,
  4521. a13: 0x270C,
  4522. a14: 0x270D,
  4523. a15: 0x270E,
  4524. a16: 0x270F,
  4525. a105: 0x2710,
  4526. a17: 0x2711,
  4527. a18: 0x2712,
  4528. a19: 0x2713,
  4529. a20: 0x2714,
  4530. a21: 0x2715,
  4531. a22: 0x2716,
  4532. a23: 0x2717,
  4533. a24: 0x2718,
  4534. a25: 0x2719,
  4535. a26: 0x271A,
  4536. a27: 0x271B,
  4537. a28: 0x271C,
  4538. a6: 0x271D,
  4539. a7: 0x271E,
  4540. a8: 0x271F,
  4541. a9: 0x2720,
  4542. a10: 0x2721,
  4543. a29: 0x2722,
  4544. a30: 0x2723,
  4545. a31: 0x2724,
  4546. a32: 0x2725,
  4547. a33: 0x2726,
  4548. a34: 0x2727,
  4549. a35: 0x2605,
  4550. a36: 0x2729,
  4551. a37: 0x272A,
  4552. a38: 0x272B,
  4553. a39: 0x272C,
  4554. a40: 0x272D,
  4555. a41: 0x272E,
  4556. a42: 0x272F,
  4557. a43: 0x2730,
  4558. a44: 0x2731,
  4559. a45: 0x2732,
  4560. a46: 0x2733,
  4561. a47: 0x2734,
  4562. a48: 0x2735,
  4563. a49: 0x2736,
  4564. a50: 0x2737,
  4565. a51: 0x2738,
  4566. a52: 0x2739,
  4567. a53: 0x273A,
  4568. a54: 0x273B,
  4569. a55: 0x273C,
  4570. a56: 0x273D,
  4571. a57: 0x273E,
  4572. a58: 0x273F,
  4573. a59: 0x2740,
  4574. a60: 0x2741,
  4575. a61: 0x2742,
  4576. a62: 0x2743,
  4577. a63: 0x2744,
  4578. a64: 0x2745,
  4579. a65: 0x2746,
  4580. a66: 0x2747,
  4581. a67: 0x2748,
  4582. a68: 0x2749,
  4583. a69: 0x274A,
  4584. a70: 0x274B,
  4585. a71: 0x25CF,
  4586. a72: 0x274D,
  4587. a73: 0x25A0,
  4588. a74: 0x274F,
  4589. a203: 0x2750,
  4590. a75: 0x2751,
  4591. a204: 0x2752,
  4592. a76: 0x25B2,
  4593. a77: 0x25BC,
  4594. a78: 0x25C6,
  4595. a79: 0x2756,
  4596. a81: 0x25D7,
  4597. a82: 0x2758,
  4598. a83: 0x2759,
  4599. a84: 0x275A,
  4600. a97: 0x275B,
  4601. a98: 0x275C,
  4602. a99: 0x275D,
  4603. a100: 0x275E,
  4604. a101: 0x2761,
  4605. a102: 0x2762,
  4606. a103: 0x2763,
  4607. a104: 0x2764,
  4608. a106: 0x2765,
  4609. a107: 0x2766,
  4610. a108: 0x2767,
  4611. a112: 0x2663,
  4612. a111: 0x2666,
  4613. a110: 0x2665,
  4614. a109: 0x2660,
  4615. a120: 0x2460,
  4616. a121: 0x2461,
  4617. a122: 0x2462,
  4618. a123: 0x2463,
  4619. a124: 0x2464,
  4620. a125: 0x2465,
  4621. a126: 0x2466,
  4622. a127: 0x2467,
  4623. a128: 0x2468,
  4624. a129: 0x2469,
  4625. a130: 0x2776,
  4626. a131: 0x2777,
  4627. a132: 0x2778,
  4628. a133: 0x2779,
  4629. a134: 0x277A,
  4630. a135: 0x277B,
  4631. a136: 0x277C,
  4632. a137: 0x277D,
  4633. a138: 0x277E,
  4634. a139: 0x277F,
  4635. a140: 0x2780,
  4636. a141: 0x2781,
  4637. a142: 0x2782,
  4638. a143: 0x2783,
  4639. a144: 0x2784,
  4640. a145: 0x2785,
  4641. a146: 0x2786,
  4642. a147: 0x2787,
  4643. a148: 0x2788,
  4644. a149: 0x2789,
  4645. a150: 0x278A,
  4646. a151: 0x278B,
  4647. a152: 0x278C,
  4648. a153: 0x278D,
  4649. a154: 0x278E,
  4650. a155: 0x278F,
  4651. a156: 0x2790,
  4652. a157: 0x2791,
  4653. a158: 0x2792,
  4654. a159: 0x2793,
  4655. a160: 0x2794,
  4656. a161: 0x2192,
  4657. a163: 0x2194,
  4658. a164: 0x2195,
  4659. a196: 0x2798,
  4660. a165: 0x2799,
  4661. a192: 0x279A,
  4662. a166: 0x279B,
  4663. a167: 0x279C,
  4664. a168: 0x279D,
  4665. a169: 0x279E,
  4666. a170: 0x279F,
  4667. a171: 0x27A0,
  4668. a172: 0x27A1,
  4669. a173: 0x27A2,
  4670. a162: 0x27A3,
  4671. a174: 0x27A4,
  4672. a175: 0x27A5,
  4673. a176: 0x27A6,
  4674. a177: 0x27A7,
  4675. a178: 0x27A8,
  4676. a179: 0x27A9,
  4677. a193: 0x27AA,
  4678. a180: 0x27AB,
  4679. a199: 0x27AC,
  4680. a181: 0x27AD,
  4681. a200: 0x27AE,
  4682. a182: 0x27AF,
  4683. a201: 0x27B1,
  4684. a183: 0x27B2,
  4685. a184: 0x27B3,
  4686. a197: 0x27B4,
  4687. a185: 0x27B5,
  4688. a194: 0x27B6,
  4689. a198: 0x27B7,
  4690. a186: 0x27B8,
  4691. a195: 0x27B9,
  4692. a187: 0x27BA,
  4693. a188: 0x27BB,
  4694. a189: 0x27BC,
  4695. a190: 0x27BD,
  4696. a191: 0x27BE,
  4697. a89: 0x2768, // 0xF8D7
  4698. a90: 0x2769, // 0xF8D8
  4699. a93: 0x276A, // 0xF8D9
  4700. a94: 0x276B, // 0xF8DA
  4701. a91: 0x276C, // 0xF8DB
  4702. a92: 0x276D, // 0xF8DC
  4703. a205: 0x276E, // 0xF8DD
  4704. a85: 0x276F, // 0xF8DE
  4705. a206: 0x2770, // 0xF8DF
  4706. a86: 0x2771, // 0xF8E0
  4707. a87: 0x2772, // 0xF8E1
  4708. a88: 0x2773, // 0xF8E2
  4709. a95: 0x2774, // 0xF8E3
  4710. a96: 0x2775, // 0xF8E4
  4711. '.notdef': 0x0000
  4712. };
  4713. exports.GlyphsUnicode = GlyphsUnicode;
  4714. exports.DingbatsGlyphsUnicode = DingbatsGlyphsUnicode;
  4715. }));
  4716. (function (root, factory) {
  4717. {
  4718. factory((root.pdfjsCoreJpg = {}));
  4719. }
  4720. }(this, function (exports) {
  4721. /*
  4722. This code was forked from https://github.com/notmasteryet/jpgjs. The original
  4723. version was created by github user notmasteryet
  4724. - The JPEG specification can be found in the ITU CCITT Recommendation T.81
  4725. (www.w3.org/Graphics/JPEG/itu-t81.pdf)
  4726. - The JFIF specification can be found in the JPEG File Interchange Format
  4727. (www.w3.org/Graphics/JPEG/jfif3.pdf)
  4728. - The Adobe Application-Specific JPEG markers in the Supporting the DCT Filters
  4729. in PostScript Level 2, Technical Note #5116
  4730. (partners.adobe.com/public/developer/en/ps/sdk/5116.DCT_Filter.pdf)
  4731. */
  4732. var JpegImage = (function jpegImage() {
  4733. var dctZigZag = new Uint8Array([
  4734. 0,
  4735. 1, 8,
  4736. 16, 9, 2,
  4737. 3, 10, 17, 24,
  4738. 32, 25, 18, 11, 4,
  4739. 5, 12, 19, 26, 33, 40,
  4740. 48, 41, 34, 27, 20, 13, 6,
  4741. 7, 14, 21, 28, 35, 42, 49, 56,
  4742. 57, 50, 43, 36, 29, 22, 15,
  4743. 23, 30, 37, 44, 51, 58,
  4744. 59, 52, 45, 38, 31,
  4745. 39, 46, 53, 60,
  4746. 61, 54, 47,
  4747. 55, 62,
  4748. 63
  4749. ]);
  4750. var dctCos1 = 4017; // cos(pi/16)
  4751. var dctSin1 = 799; // sin(pi/16)
  4752. var dctCos3 = 3406; // cos(3*pi/16)
  4753. var dctSin3 = 2276; // sin(3*pi/16)
  4754. var dctCos6 = 1567; // cos(6*pi/16)
  4755. var dctSin6 = 3784; // sin(6*pi/16)
  4756. var dctSqrt2 = 5793; // sqrt(2)
  4757. var dctSqrt1d2 = 2896; // sqrt(2) / 2
  4758. function constructor() {
  4759. }
  4760. function buildHuffmanTable(codeLengths, values) {
  4761. var k = 0, code = [], i, j, length = 16;
  4762. while (length > 0 && !codeLengths[length - 1]) {
  4763. length--;
  4764. }
  4765. code.push({children: [], index: 0});
  4766. var p = code[0], q;
  4767. for (i = 0; i < length; i++) {
  4768. for (j = 0; j < codeLengths[i]; j++) {
  4769. p = code.pop();
  4770. p.children[p.index] = values[k];
  4771. while (p.index > 0) {
  4772. p = code.pop();
  4773. }
  4774. p.index++;
  4775. code.push(p);
  4776. while (code.length <= i) {
  4777. code.push(q = {children: [], index: 0});
  4778. p.children[p.index] = q.children;
  4779. p = q;
  4780. }
  4781. k++;
  4782. }
  4783. if (i + 1 < length) {
  4784. // p here points to last code
  4785. code.push(q = {children: [], index: 0});
  4786. p.children[p.index] = q.children;
  4787. p = q;
  4788. }
  4789. }
  4790. return code[0].children;
  4791. }
  4792. function getBlockBufferOffset(component, row, col) {
  4793. return 64 * ((component.blocksPerLine + 1) * row + col);
  4794. }
  4795. function decodeScan(data, offset, frame, components, resetInterval,
  4796. spectralStart, spectralEnd, successivePrev, successive) {
  4797. var mcusPerLine = frame.mcusPerLine;
  4798. var progressive = frame.progressive;
  4799. var startOffset = offset, bitsData = 0, bitsCount = 0;
  4800. function readBit() {
  4801. if (bitsCount > 0) {
  4802. bitsCount--;
  4803. return (bitsData >> bitsCount) & 1;
  4804. }
  4805. bitsData = data[offset++];
  4806. if (bitsData === 0xFF) {
  4807. var nextByte = data[offset++];
  4808. if (nextByte) {
  4809. throw 'unexpected marker: ' +
  4810. ((bitsData << 8) | nextByte).toString(16);
  4811. }
  4812. // unstuff 0
  4813. }
  4814. bitsCount = 7;
  4815. return bitsData >>> 7;
  4816. }
  4817. function decodeHuffman(tree) {
  4818. var node = tree;
  4819. while (true) {
  4820. node = node[readBit()];
  4821. if (typeof node === 'number') {
  4822. return node;
  4823. }
  4824. if (typeof node !== 'object') {
  4825. throw 'invalid huffman sequence';
  4826. }
  4827. }
  4828. }
  4829. function receive(length) {
  4830. var n = 0;
  4831. while (length > 0) {
  4832. n = (n << 1) | readBit();
  4833. length--;
  4834. }
  4835. return n;
  4836. }
  4837. function receiveAndExtend(length) {
  4838. if (length === 1) {
  4839. return readBit() === 1 ? 1 : -1;
  4840. }
  4841. var n = receive(length);
  4842. if (n >= 1 << (length - 1)) {
  4843. return n;
  4844. }
  4845. return n + (-1 << length) + 1;
  4846. }
  4847. function decodeBaseline(component, offset) {
  4848. var t = decodeHuffman(component.huffmanTableDC);
  4849. var diff = t === 0 ? 0 : receiveAndExtend(t);
  4850. component.blockData[offset] = (component.pred += diff);
  4851. var k = 1;
  4852. while (k < 64) {
  4853. var rs = decodeHuffman(component.huffmanTableAC);
  4854. var s = rs & 15, r = rs >> 4;
  4855. if (s === 0) {
  4856. if (r < 15) {
  4857. break;
  4858. }
  4859. k += 16;
  4860. continue;
  4861. }
  4862. k += r;
  4863. var z = dctZigZag[k];
  4864. component.blockData[offset + z] = receiveAndExtend(s);
  4865. k++;
  4866. }
  4867. }
  4868. function decodeDCFirst(component, offset) {
  4869. var t = decodeHuffman(component.huffmanTableDC);
  4870. var diff = t === 0 ? 0 : (receiveAndExtend(t) << successive);
  4871. component.blockData[offset] = (component.pred += diff);
  4872. }
  4873. function decodeDCSuccessive(component, offset) {
  4874. component.blockData[offset] |= readBit() << successive;
  4875. }
  4876. var eobrun = 0;
  4877. function decodeACFirst(component, offset) {
  4878. if (eobrun > 0) {
  4879. eobrun--;
  4880. return;
  4881. }
  4882. var k = spectralStart, e = spectralEnd;
  4883. while (k <= e) {
  4884. var rs = decodeHuffman(component.huffmanTableAC);
  4885. var s = rs & 15, r = rs >> 4;
  4886. if (s === 0) {
  4887. if (r < 15) {
  4888. eobrun = receive(r) + (1 << r) - 1;
  4889. break;
  4890. }
  4891. k += 16;
  4892. continue;
  4893. }
  4894. k += r;
  4895. var z = dctZigZag[k];
  4896. component.blockData[offset + z] =
  4897. receiveAndExtend(s) * (1 << successive);
  4898. k++;
  4899. }
  4900. }
  4901. var successiveACState = 0, successiveACNextValue;
  4902. function decodeACSuccessive(component, offset) {
  4903. var k = spectralStart;
  4904. var e = spectralEnd;
  4905. var r = 0;
  4906. var s;
  4907. var rs;
  4908. while (k <= e) {
  4909. var z = dctZigZag[k];
  4910. switch (successiveACState) {
  4911. case 0: // initial state
  4912. rs = decodeHuffman(component.huffmanTableAC);
  4913. s = rs & 15;
  4914. r = rs >> 4;
  4915. if (s === 0) {
  4916. if (r < 15) {
  4917. eobrun = receive(r) + (1 << r);
  4918. successiveACState = 4;
  4919. } else {
  4920. r = 16;
  4921. successiveACState = 1;
  4922. }
  4923. } else {
  4924. if (s !== 1) {
  4925. throw 'invalid ACn encoding';
  4926. }
  4927. successiveACNextValue = receiveAndExtend(s);
  4928. successiveACState = r ? 2 : 3;
  4929. }
  4930. continue;
  4931. case 1: // skipping r zero items
  4932. case 2:
  4933. if (component.blockData[offset + z]) {
  4934. component.blockData[offset + z] += (readBit() << successive);
  4935. } else {
  4936. r--;
  4937. if (r === 0) {
  4938. successiveACState = successiveACState === 2 ? 3 : 0;
  4939. }
  4940. }
  4941. break;
  4942. case 3: // set value for a zero item
  4943. if (component.blockData[offset + z]) {
  4944. component.blockData[offset + z] += (readBit() << successive);
  4945. } else {
  4946. component.blockData[offset + z] =
  4947. successiveACNextValue << successive;
  4948. successiveACState = 0;
  4949. }
  4950. break;
  4951. case 4: // eob
  4952. if (component.blockData[offset + z]) {
  4953. component.blockData[offset + z] += (readBit() << successive);
  4954. }
  4955. break;
  4956. }
  4957. k++;
  4958. }
  4959. if (successiveACState === 4) {
  4960. eobrun--;
  4961. if (eobrun === 0) {
  4962. successiveACState = 0;
  4963. }
  4964. }
  4965. }
  4966. function decodeMcu(component, decode, mcu, row, col) {
  4967. var mcuRow = (mcu / mcusPerLine) | 0;
  4968. var mcuCol = mcu % mcusPerLine;
  4969. var blockRow = mcuRow * component.v + row;
  4970. var blockCol = mcuCol * component.h + col;
  4971. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  4972. decode(component, offset);
  4973. }
  4974. function decodeBlock(component, decode, mcu) {
  4975. var blockRow = (mcu / component.blocksPerLine) | 0;
  4976. var blockCol = mcu % component.blocksPerLine;
  4977. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  4978. decode(component, offset);
  4979. }
  4980. var componentsLength = components.length;
  4981. var component, i, j, k, n;
  4982. var decodeFn;
  4983. if (progressive) {
  4984. if (spectralStart === 0) {
  4985. decodeFn = successivePrev === 0 ? decodeDCFirst : decodeDCSuccessive;
  4986. } else {
  4987. decodeFn = successivePrev === 0 ? decodeACFirst : decodeACSuccessive;
  4988. }
  4989. } else {
  4990. decodeFn = decodeBaseline;
  4991. }
  4992. var mcu = 0, marker;
  4993. var mcuExpected;
  4994. if (componentsLength === 1) {
  4995. mcuExpected = components[0].blocksPerLine * components[0].blocksPerColumn;
  4996. } else {
  4997. mcuExpected = mcusPerLine * frame.mcusPerColumn;
  4998. }
  4999. if (!resetInterval) {
  5000. resetInterval = mcuExpected;
  5001. }
  5002. var h, v;
  5003. while (mcu < mcuExpected) {
  5004. // reset interval stuff
  5005. for (i = 0; i < componentsLength; i++) {
  5006. components[i].pred = 0;
  5007. }
  5008. eobrun = 0;
  5009. if (componentsLength === 1) {
  5010. component = components[0];
  5011. for (n = 0; n < resetInterval; n++) {
  5012. decodeBlock(component, decodeFn, mcu);
  5013. mcu++;
  5014. }
  5015. } else {
  5016. for (n = 0; n < resetInterval; n++) {
  5017. for (i = 0; i < componentsLength; i++) {
  5018. component = components[i];
  5019. h = component.h;
  5020. v = component.v;
  5021. for (j = 0; j < v; j++) {
  5022. for (k = 0; k < h; k++) {
  5023. decodeMcu(component, decodeFn, mcu, j, k);
  5024. }
  5025. }
  5026. }
  5027. mcu++;
  5028. }
  5029. }
  5030. // find marker
  5031. bitsCount = 0;
  5032. marker = (data[offset] << 8) | data[offset + 1];
  5033. if (marker <= 0xFF00) {
  5034. throw 'marker was not found';
  5035. }
  5036. if (marker >= 0xFFD0 && marker <= 0xFFD7) { // RSTx
  5037. offset += 2;
  5038. } else {
  5039. break;
  5040. }
  5041. }
  5042. return offset - startOffset;
  5043. }
  5044. // A port of poppler's IDCT method which in turn is taken from:
  5045. // Christoph Loeffler, Adriaan Ligtenberg, George S. Moschytz,
  5046. // 'Practical Fast 1-D DCT Algorithms with 11 Multiplications',
  5047. // IEEE Intl. Conf. on Acoustics, Speech & Signal Processing, 1989,
  5048. // 988-991.
  5049. function quantizeAndInverse(component, blockBufferOffset, p) {
  5050. var qt = component.quantizationTable, blockData = component.blockData;
  5051. var v0, v1, v2, v3, v4, v5, v6, v7;
  5052. var p0, p1, p2, p3, p4, p5, p6, p7;
  5053. var t;
  5054. // inverse DCT on rows
  5055. for (var row = 0; row < 64; row += 8) {
  5056. // gather block data
  5057. p0 = blockData[blockBufferOffset + row];
  5058. p1 = blockData[blockBufferOffset + row + 1];
  5059. p2 = blockData[blockBufferOffset + row + 2];
  5060. p3 = blockData[blockBufferOffset + row + 3];
  5061. p4 = blockData[blockBufferOffset + row + 4];
  5062. p5 = blockData[blockBufferOffset + row + 5];
  5063. p6 = blockData[blockBufferOffset + row + 6];
  5064. p7 = blockData[blockBufferOffset + row + 7];
  5065. // dequant p0
  5066. p0 *= qt[row];
  5067. // check for all-zero AC coefficients
  5068. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  5069. t = (dctSqrt2 * p0 + 512) >> 10;
  5070. p[row] = t;
  5071. p[row + 1] = t;
  5072. p[row + 2] = t;
  5073. p[row + 3] = t;
  5074. p[row + 4] = t;
  5075. p[row + 5] = t;
  5076. p[row + 6] = t;
  5077. p[row + 7] = t;
  5078. continue;
  5079. }
  5080. // dequant p1 ... p7
  5081. p1 *= qt[row + 1];
  5082. p2 *= qt[row + 2];
  5083. p3 *= qt[row + 3];
  5084. p4 *= qt[row + 4];
  5085. p5 *= qt[row + 5];
  5086. p6 *= qt[row + 6];
  5087. p7 *= qt[row + 7];
  5088. // stage 4
  5089. v0 = (dctSqrt2 * p0 + 128) >> 8;
  5090. v1 = (dctSqrt2 * p4 + 128) >> 8;
  5091. v2 = p2;
  5092. v3 = p6;
  5093. v4 = (dctSqrt1d2 * (p1 - p7) + 128) >> 8;
  5094. v7 = (dctSqrt1d2 * (p1 + p7) + 128) >> 8;
  5095. v5 = p3 << 4;
  5096. v6 = p5 << 4;
  5097. // stage 3
  5098. v0 = (v0 + v1 + 1) >> 1;
  5099. v1 = v0 - v1;
  5100. t = (v2 * dctSin6 + v3 * dctCos6 + 128) >> 8;
  5101. v2 = (v2 * dctCos6 - v3 * dctSin6 + 128) >> 8;
  5102. v3 = t;
  5103. v4 = (v4 + v6 + 1) >> 1;
  5104. v6 = v4 - v6;
  5105. v7 = (v7 + v5 + 1) >> 1;
  5106. v5 = v7 - v5;
  5107. // stage 2
  5108. v0 = (v0 + v3 + 1) >> 1;
  5109. v3 = v0 - v3;
  5110. v1 = (v1 + v2 + 1) >> 1;
  5111. v2 = v1 - v2;
  5112. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  5113. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  5114. v7 = t;
  5115. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  5116. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  5117. v6 = t;
  5118. // stage 1
  5119. p[row] = v0 + v7;
  5120. p[row + 7] = v0 - v7;
  5121. p[row + 1] = v1 + v6;
  5122. p[row + 6] = v1 - v6;
  5123. p[row + 2] = v2 + v5;
  5124. p[row + 5] = v2 - v5;
  5125. p[row + 3] = v3 + v4;
  5126. p[row + 4] = v3 - v4;
  5127. }
  5128. // inverse DCT on columns
  5129. for (var col = 0; col < 8; ++col) {
  5130. p0 = p[col];
  5131. p1 = p[col + 8];
  5132. p2 = p[col + 16];
  5133. p3 = p[col + 24];
  5134. p4 = p[col + 32];
  5135. p5 = p[col + 40];
  5136. p6 = p[col + 48];
  5137. p7 = p[col + 56];
  5138. // check for all-zero AC coefficients
  5139. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  5140. t = (dctSqrt2 * p0 + 8192) >> 14;
  5141. // convert to 8 bit
  5142. t = (t < -2040) ? 0 : (t >= 2024) ? 255 : (t + 2056) >> 4;
  5143. blockData[blockBufferOffset + col] = t;
  5144. blockData[blockBufferOffset + col + 8] = t;
  5145. blockData[blockBufferOffset + col + 16] = t;
  5146. blockData[blockBufferOffset + col + 24] = t;
  5147. blockData[blockBufferOffset + col + 32] = t;
  5148. blockData[blockBufferOffset + col + 40] = t;
  5149. blockData[blockBufferOffset + col + 48] = t;
  5150. blockData[blockBufferOffset + col + 56] = t;
  5151. continue;
  5152. }
  5153. // stage 4
  5154. v0 = (dctSqrt2 * p0 + 2048) >> 12;
  5155. v1 = (dctSqrt2 * p4 + 2048) >> 12;
  5156. v2 = p2;
  5157. v3 = p6;
  5158. v4 = (dctSqrt1d2 * (p1 - p7) + 2048) >> 12;
  5159. v7 = (dctSqrt1d2 * (p1 + p7) + 2048) >> 12;
  5160. v5 = p3;
  5161. v6 = p5;
  5162. // stage 3
  5163. // Shift v0 by 128.5 << 5 here, so we don't need to shift p0...p7 when
  5164. // converting to UInt8 range later.
  5165. v0 = ((v0 + v1 + 1) >> 1) + 4112;
  5166. v1 = v0 - v1;
  5167. t = (v2 * dctSin6 + v3 * dctCos6 + 2048) >> 12;
  5168. v2 = (v2 * dctCos6 - v3 * dctSin6 + 2048) >> 12;
  5169. v3 = t;
  5170. v4 = (v4 + v6 + 1) >> 1;
  5171. v6 = v4 - v6;
  5172. v7 = (v7 + v5 + 1) >> 1;
  5173. v5 = v7 - v5;
  5174. // stage 2
  5175. v0 = (v0 + v3 + 1) >> 1;
  5176. v3 = v0 - v3;
  5177. v1 = (v1 + v2 + 1) >> 1;
  5178. v2 = v1 - v2;
  5179. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  5180. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  5181. v7 = t;
  5182. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  5183. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  5184. v6 = t;
  5185. // stage 1
  5186. p0 = v0 + v7;
  5187. p7 = v0 - v7;
  5188. p1 = v1 + v6;
  5189. p6 = v1 - v6;
  5190. p2 = v2 + v5;
  5191. p5 = v2 - v5;
  5192. p3 = v3 + v4;
  5193. p4 = v3 - v4;
  5194. // convert to 8-bit integers
  5195. p0 = (p0 < 16) ? 0 : (p0 >= 4080) ? 255 : p0 >> 4;
  5196. p1 = (p1 < 16) ? 0 : (p1 >= 4080) ? 255 : p1 >> 4;
  5197. p2 = (p2 < 16) ? 0 : (p2 >= 4080) ? 255 : p2 >> 4;
  5198. p3 = (p3 < 16) ? 0 : (p3 >= 4080) ? 255 : p3 >> 4;
  5199. p4 = (p4 < 16) ? 0 : (p4 >= 4080) ? 255 : p4 >> 4;
  5200. p5 = (p5 < 16) ? 0 : (p5 >= 4080) ? 255 : p5 >> 4;
  5201. p6 = (p6 < 16) ? 0 : (p6 >= 4080) ? 255 : p6 >> 4;
  5202. p7 = (p7 < 16) ? 0 : (p7 >= 4080) ? 255 : p7 >> 4;
  5203. // store block data
  5204. blockData[blockBufferOffset + col] = p0;
  5205. blockData[blockBufferOffset + col + 8] = p1;
  5206. blockData[blockBufferOffset + col + 16] = p2;
  5207. blockData[blockBufferOffset + col + 24] = p3;
  5208. blockData[blockBufferOffset + col + 32] = p4;
  5209. blockData[blockBufferOffset + col + 40] = p5;
  5210. blockData[blockBufferOffset + col + 48] = p6;
  5211. blockData[blockBufferOffset + col + 56] = p7;
  5212. }
  5213. }
  5214. function buildComponentData(frame, component) {
  5215. var blocksPerLine = component.blocksPerLine;
  5216. var blocksPerColumn = component.blocksPerColumn;
  5217. var computationBuffer = new Int16Array(64);
  5218. for (var blockRow = 0; blockRow < blocksPerColumn; blockRow++) {
  5219. for (var blockCol = 0; blockCol < blocksPerLine; blockCol++) {
  5220. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  5221. quantizeAndInverse(component, offset, computationBuffer);
  5222. }
  5223. }
  5224. return component.blockData;
  5225. }
  5226. function clamp0to255(a) {
  5227. return a <= 0 ? 0 : a >= 255 ? 255 : a;
  5228. }
  5229. constructor.prototype = {
  5230. parse: function parse(data) {
  5231. function readUint16() {
  5232. var value = (data[offset] << 8) | data[offset + 1];
  5233. offset += 2;
  5234. return value;
  5235. }
  5236. function readDataBlock() {
  5237. var length = readUint16();
  5238. var array = data.subarray(offset, offset + length - 2);
  5239. offset += array.length;
  5240. return array;
  5241. }
  5242. function prepareComponents(frame) {
  5243. var mcusPerLine = Math.ceil(frame.samplesPerLine / 8 / frame.maxH);
  5244. var mcusPerColumn = Math.ceil(frame.scanLines / 8 / frame.maxV);
  5245. for (var i = 0; i < frame.components.length; i++) {
  5246. component = frame.components[i];
  5247. var blocksPerLine = Math.ceil(Math.ceil(frame.samplesPerLine / 8) *
  5248. component.h / frame.maxH);
  5249. var blocksPerColumn = Math.ceil(Math.ceil(frame.scanLines / 8) *
  5250. component.v / frame.maxV);
  5251. var blocksPerLineForMcu = mcusPerLine * component.h;
  5252. var blocksPerColumnForMcu = mcusPerColumn * component.v;
  5253. var blocksBufferSize = 64 * blocksPerColumnForMcu *
  5254. (blocksPerLineForMcu + 1);
  5255. component.blockData = new Int16Array(blocksBufferSize);
  5256. component.blocksPerLine = blocksPerLine;
  5257. component.blocksPerColumn = blocksPerColumn;
  5258. }
  5259. frame.mcusPerLine = mcusPerLine;
  5260. frame.mcusPerColumn = mcusPerColumn;
  5261. }
  5262. var offset = 0;
  5263. var jfif = null;
  5264. var adobe = null;
  5265. var frame, resetInterval;
  5266. var quantizationTables = [];
  5267. var huffmanTablesAC = [], huffmanTablesDC = [];
  5268. var fileMarker = readUint16();
  5269. if (fileMarker !== 0xFFD8) { // SOI (Start of Image)
  5270. throw 'SOI not found';
  5271. }
  5272. fileMarker = readUint16();
  5273. while (fileMarker !== 0xFFD9) { // EOI (End of image)
  5274. var i, j, l;
  5275. switch(fileMarker) {
  5276. case 0xFFE0: // APP0 (Application Specific)
  5277. case 0xFFE1: // APP1
  5278. case 0xFFE2: // APP2
  5279. case 0xFFE3: // APP3
  5280. case 0xFFE4: // APP4
  5281. case 0xFFE5: // APP5
  5282. case 0xFFE6: // APP6
  5283. case 0xFFE7: // APP7
  5284. case 0xFFE8: // APP8
  5285. case 0xFFE9: // APP9
  5286. case 0xFFEA: // APP10
  5287. case 0xFFEB: // APP11
  5288. case 0xFFEC: // APP12
  5289. case 0xFFED: // APP13
  5290. case 0xFFEE: // APP14
  5291. case 0xFFEF: // APP15
  5292. case 0xFFFE: // COM (Comment)
  5293. var appData = readDataBlock();
  5294. if (fileMarker === 0xFFE0) {
  5295. if (appData[0] === 0x4A && appData[1] === 0x46 &&
  5296. appData[2] === 0x49 && appData[3] === 0x46 &&
  5297. appData[4] === 0) { // 'JFIF\x00'
  5298. jfif = {
  5299. version: { major: appData[5], minor: appData[6] },
  5300. densityUnits: appData[7],
  5301. xDensity: (appData[8] << 8) | appData[9],
  5302. yDensity: (appData[10] << 8) | appData[11],
  5303. thumbWidth: appData[12],
  5304. thumbHeight: appData[13],
  5305. thumbData: appData.subarray(14, 14 +
  5306. 3 * appData[12] * appData[13])
  5307. };
  5308. }
  5309. }
  5310. // TODO APP1 - Exif
  5311. if (fileMarker === 0xFFEE) {
  5312. if (appData[0] === 0x41 && appData[1] === 0x64 &&
  5313. appData[2] === 0x6F && appData[3] === 0x62 &&
  5314. appData[4] === 0x65) { // 'Adobe'
  5315. adobe = {
  5316. version: (appData[5] << 8) | appData[6],
  5317. flags0: (appData[7] << 8) | appData[8],
  5318. flags1: (appData[9] << 8) | appData[10],
  5319. transformCode: appData[11]
  5320. };
  5321. }
  5322. }
  5323. break;
  5324. case 0xFFDB: // DQT (Define Quantization Tables)
  5325. var quantizationTablesLength = readUint16();
  5326. var quantizationTablesEnd = quantizationTablesLength + offset - 2;
  5327. var z;
  5328. while (offset < quantizationTablesEnd) {
  5329. var quantizationTableSpec = data[offset++];
  5330. var tableData = new Uint16Array(64);
  5331. if ((quantizationTableSpec >> 4) === 0) { // 8 bit values
  5332. for (j = 0; j < 64; j++) {
  5333. z = dctZigZag[j];
  5334. tableData[z] = data[offset++];
  5335. }
  5336. } else if ((quantizationTableSpec >> 4) === 1) { //16 bit
  5337. for (j = 0; j < 64; j++) {
  5338. z = dctZigZag[j];
  5339. tableData[z] = readUint16();
  5340. }
  5341. } else {
  5342. throw 'DQT: invalid table spec';
  5343. }
  5344. quantizationTables[quantizationTableSpec & 15] = tableData;
  5345. }
  5346. break;
  5347. case 0xFFC0: // SOF0 (Start of Frame, Baseline DCT)
  5348. case 0xFFC1: // SOF1 (Start of Frame, Extended DCT)
  5349. case 0xFFC2: // SOF2 (Start of Frame, Progressive DCT)
  5350. if (frame) {
  5351. throw 'Only single frame JPEGs supported';
  5352. }
  5353. readUint16(); // skip data length
  5354. frame = {};
  5355. frame.extended = (fileMarker === 0xFFC1);
  5356. frame.progressive = (fileMarker === 0xFFC2);
  5357. frame.precision = data[offset++];
  5358. frame.scanLines = readUint16();
  5359. frame.samplesPerLine = readUint16();
  5360. frame.components = [];
  5361. frame.componentIds = {};
  5362. var componentsCount = data[offset++], componentId;
  5363. var maxH = 0, maxV = 0;
  5364. for (i = 0; i < componentsCount; i++) {
  5365. componentId = data[offset];
  5366. var h = data[offset + 1] >> 4;
  5367. var v = data[offset + 1] & 15;
  5368. if (maxH < h) {
  5369. maxH = h;
  5370. }
  5371. if (maxV < v) {
  5372. maxV = v;
  5373. }
  5374. var qId = data[offset + 2];
  5375. l = frame.components.push({
  5376. h: h,
  5377. v: v,
  5378. quantizationTable: quantizationTables[qId]
  5379. });
  5380. frame.componentIds[componentId] = l - 1;
  5381. offset += 3;
  5382. }
  5383. frame.maxH = maxH;
  5384. frame.maxV = maxV;
  5385. prepareComponents(frame);
  5386. break;
  5387. case 0xFFC4: // DHT (Define Huffman Tables)
  5388. var huffmanLength = readUint16();
  5389. for (i = 2; i < huffmanLength;) {
  5390. var huffmanTableSpec = data[offset++];
  5391. var codeLengths = new Uint8Array(16);
  5392. var codeLengthSum = 0;
  5393. for (j = 0; j < 16; j++, offset++) {
  5394. codeLengthSum += (codeLengths[j] = data[offset]);
  5395. }
  5396. var huffmanValues = new Uint8Array(codeLengthSum);
  5397. for (j = 0; j < codeLengthSum; j++, offset++) {
  5398. huffmanValues[j] = data[offset];
  5399. }
  5400. i += 17 + codeLengthSum;
  5401. ((huffmanTableSpec >> 4) === 0 ?
  5402. huffmanTablesDC : huffmanTablesAC)[huffmanTableSpec & 15] =
  5403. buildHuffmanTable(codeLengths, huffmanValues);
  5404. }
  5405. break;
  5406. case 0xFFDD: // DRI (Define Restart Interval)
  5407. readUint16(); // skip data length
  5408. resetInterval = readUint16();
  5409. break;
  5410. case 0xFFDA: // SOS (Start of Scan)
  5411. var scanLength = readUint16();
  5412. var selectorsCount = data[offset++];
  5413. var components = [], component;
  5414. for (i = 0; i < selectorsCount; i++) {
  5415. var componentIndex = frame.componentIds[data[offset++]];
  5416. component = frame.components[componentIndex];
  5417. var tableSpec = data[offset++];
  5418. component.huffmanTableDC = huffmanTablesDC[tableSpec >> 4];
  5419. component.huffmanTableAC = huffmanTablesAC[tableSpec & 15];
  5420. components.push(component);
  5421. }
  5422. var spectralStart = data[offset++];
  5423. var spectralEnd = data[offset++];
  5424. var successiveApproximation = data[offset++];
  5425. var processed = decodeScan(data, offset,
  5426. frame, components, resetInterval,
  5427. spectralStart, spectralEnd,
  5428. successiveApproximation >> 4, successiveApproximation & 15);
  5429. offset += processed;
  5430. break;
  5431. case 0xFFFF: // Fill bytes
  5432. if (data[offset] !== 0xFF) { // Avoid skipping a valid marker.
  5433. offset--;
  5434. }
  5435. break;
  5436. default:
  5437. if (data[offset - 3] === 0xFF &&
  5438. data[offset - 2] >= 0xC0 && data[offset - 2] <= 0xFE) {
  5439. // could be incorrect encoding -- last 0xFF byte of the previous
  5440. // block was eaten by the encoder
  5441. offset -= 3;
  5442. break;
  5443. }
  5444. throw 'unknown JPEG marker ' + fileMarker.toString(16);
  5445. }
  5446. fileMarker = readUint16();
  5447. }
  5448. this.width = frame.samplesPerLine;
  5449. this.height = frame.scanLines;
  5450. this.jfif = jfif;
  5451. this.adobe = adobe;
  5452. this.components = [];
  5453. for (i = 0; i < frame.components.length; i++) {
  5454. component = frame.components[i];
  5455. this.components.push({
  5456. output: buildComponentData(frame, component),
  5457. scaleX: component.h / frame.maxH,
  5458. scaleY: component.v / frame.maxV,
  5459. blocksPerLine: component.blocksPerLine,
  5460. blocksPerColumn: component.blocksPerColumn
  5461. });
  5462. }
  5463. this.numComponents = this.components.length;
  5464. },
  5465. _getLinearizedBlockData: function getLinearizedBlockData(width, height) {
  5466. var scaleX = this.width / width, scaleY = this.height / height;
  5467. var component, componentScaleX, componentScaleY, blocksPerScanline;
  5468. var x, y, i, j, k;
  5469. var index;
  5470. var offset = 0;
  5471. var output;
  5472. var numComponents = this.components.length;
  5473. var dataLength = width * height * numComponents;
  5474. var data = new Uint8Array(dataLength);
  5475. var xScaleBlockOffset = new Uint32Array(width);
  5476. var mask3LSB = 0xfffffff8; // used to clear the 3 LSBs
  5477. for (i = 0; i < numComponents; i++) {
  5478. component = this.components[i];
  5479. componentScaleX = component.scaleX * scaleX;
  5480. componentScaleY = component.scaleY * scaleY;
  5481. offset = i;
  5482. output = component.output;
  5483. blocksPerScanline = (component.blocksPerLine + 1) << 3;
  5484. // precalculate the xScaleBlockOffset
  5485. for (x = 0; x < width; x++) {
  5486. j = 0 | (x * componentScaleX);
  5487. xScaleBlockOffset[x] = ((j & mask3LSB) << 3) | (j & 7);
  5488. }
  5489. // linearize the blocks of the component
  5490. for (y = 0; y < height; y++) {
  5491. j = 0 | (y * componentScaleY);
  5492. index = blocksPerScanline * (j & mask3LSB) | ((j & 7) << 3);
  5493. for (x = 0; x < width; x++) {
  5494. data[offset] = output[index + xScaleBlockOffset[x]];
  5495. offset += numComponents;
  5496. }
  5497. }
  5498. }
  5499. // decodeTransform contains pairs of multiplier (-256..256) and additive
  5500. var transform = this.decodeTransform;
  5501. if (transform) {
  5502. for (i = 0; i < dataLength;) {
  5503. for (j = 0, k = 0; j < numComponents; j++, i++, k += 2) {
  5504. data[i] = ((data[i] * transform[k]) >> 8) + transform[k + 1];
  5505. }
  5506. }
  5507. }
  5508. return data;
  5509. },
  5510. _isColorConversionNeeded: function isColorConversionNeeded() {
  5511. if (this.adobe && this.adobe.transformCode) {
  5512. // The adobe transform marker overrides any previous setting
  5513. return true;
  5514. } else if (this.numComponents === 3) {
  5515. return true;
  5516. } else {
  5517. return false;
  5518. }
  5519. },
  5520. _convertYccToRgb: function convertYccToRgb(data) {
  5521. var Y, Cb, Cr;
  5522. for (var i = 0, length = data.length; i < length; i += 3) {
  5523. Y = data[i ];
  5524. Cb = data[i + 1];
  5525. Cr = data[i + 2];
  5526. data[i ] = clamp0to255(Y - 179.456 + 1.402 * Cr);
  5527. data[i + 1] = clamp0to255(Y + 135.459 - 0.344 * Cb - 0.714 * Cr);
  5528. data[i + 2] = clamp0to255(Y - 226.816 + 1.772 * Cb);
  5529. }
  5530. return data;
  5531. },
  5532. _convertYcckToRgb: function convertYcckToRgb(data) {
  5533. var Y, Cb, Cr, k;
  5534. var offset = 0;
  5535. for (var i = 0, length = data.length; i < length; i += 4) {
  5536. Y = data[i];
  5537. Cb = data[i + 1];
  5538. Cr = data[i + 2];
  5539. k = data[i + 3];
  5540. var r = -122.67195406894 +
  5541. Cb * (-6.60635669420364e-5 * Cb + 0.000437130475926232 * Cr -
  5542. 5.4080610064599e-5 * Y + 0.00048449797120281 * k -
  5543. 0.154362151871126) +
  5544. Cr * (-0.000957964378445773 * Cr + 0.000817076911346625 * Y -
  5545. 0.00477271405408747 * k + 1.53380253221734) +
  5546. Y * (0.000961250184130688 * Y - 0.00266257332283933 * k +
  5547. 0.48357088451265) +
  5548. k * (-0.000336197177618394 * k + 0.484791561490776);
  5549. var g = 107.268039397724 +
  5550. Cb * (2.19927104525741e-5 * Cb - 0.000640992018297945 * Cr +
  5551. 0.000659397001245577 * Y + 0.000426105652938837 * k -
  5552. 0.176491792462875) +
  5553. Cr * (-0.000778269941513683 * Cr + 0.00130872261408275 * Y +
  5554. 0.000770482631801132 * k - 0.151051492775562) +
  5555. Y * (0.00126935368114843 * Y - 0.00265090189010898 * k +
  5556. 0.25802910206845) +
  5557. k * (-0.000318913117588328 * k - 0.213742400323665);
  5558. var b = -20.810012546947 +
  5559. Cb * (-0.000570115196973677 * Cb - 2.63409051004589e-5 * Cr +
  5560. 0.0020741088115012 * Y - 0.00288260236853442 * k +
  5561. 0.814272968359295) +
  5562. Cr * (-1.53496057440975e-5 * Cr - 0.000132689043961446 * Y +
  5563. 0.000560833691242812 * k - 0.195152027534049) +
  5564. Y * (0.00174418132927582 * Y - 0.00255243321439347 * k +
  5565. 0.116935020465145) +
  5566. k * (-0.000343531996510555 * k + 0.24165260232407);
  5567. data[offset++] = clamp0to255(r);
  5568. data[offset++] = clamp0to255(g);
  5569. data[offset++] = clamp0to255(b);
  5570. }
  5571. return data;
  5572. },
  5573. _convertYcckToCmyk: function convertYcckToCmyk(data) {
  5574. var Y, Cb, Cr;
  5575. for (var i = 0, length = data.length; i < length; i += 4) {
  5576. Y = data[i];
  5577. Cb = data[i + 1];
  5578. Cr = data[i + 2];
  5579. data[i ] = clamp0to255(434.456 - Y - 1.402 * Cr);
  5580. data[i + 1] = clamp0to255(119.541 - Y + 0.344 * Cb + 0.714 * Cr);
  5581. data[i + 2] = clamp0to255(481.816 - Y - 1.772 * Cb);
  5582. // K in data[i + 3] is unchanged
  5583. }
  5584. return data;
  5585. },
  5586. _convertCmykToRgb: function convertCmykToRgb(data) {
  5587. var c, m, y, k;
  5588. var offset = 0;
  5589. var min = -255 * 255 * 255;
  5590. var scale = 1 / 255 / 255;
  5591. for (var i = 0, length = data.length; i < length; i += 4) {
  5592. c = data[i];
  5593. m = data[i + 1];
  5594. y = data[i + 2];
  5595. k = data[i + 3];
  5596. var r =
  5597. c * (-4.387332384609988 * c + 54.48615194189176 * m +
  5598. 18.82290502165302 * y + 212.25662451639585 * k -
  5599. 72734.4411664936) +
  5600. m * (1.7149763477362134 * m - 5.6096736904047315 * y -
  5601. 17.873870861415444 * k - 1401.7366389350734) +
  5602. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  5603. 4465.541406466231) -
  5604. k * (21.86122147463605 * k + 48317.86113160301);
  5605. var g =
  5606. c * (8.841041422036149 * c + 60.118027045597366 * m +
  5607. 6.871425592049007 * y + 31.159100130055922 * k -
  5608. 20220.756542821975) +
  5609. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  5610. 131.35250912493976 * k - 48691.05921601825) +
  5611. y * (4.444339102852739 * y + 9.8632861493405 * k -
  5612. 6341.191035517494) -
  5613. k * (20.737325471181034 * k + 47890.15695978492);
  5614. var b =
  5615. c * (0.8842522430003296 * c + 8.078677503112928 * m +
  5616. 30.89978309703729 * y - 0.23883238689178934 * k -
  5617. 3616.812083916688) +
  5618. m * (10.49593273432072 * m + 63.02378494754052 * y +
  5619. 50.606957656360734 * k - 28620.90484698408) +
  5620. y * (0.03296041114873217 * y + 115.60384449646641 * k -
  5621. 49363.43385999684) -
  5622. k * (22.33816807309886 * k + 45932.16563550634);
  5623. data[offset++] = r >= 0 ? 255 : r <= min ? 0 : 255 + r * scale | 0;
  5624. data[offset++] = g >= 0 ? 255 : g <= min ? 0 : 255 + g * scale | 0;
  5625. data[offset++] = b >= 0 ? 255 : b <= min ? 0 : 255 + b * scale | 0;
  5626. }
  5627. return data;
  5628. },
  5629. getData: function getData(width, height, forceRGBoutput) {
  5630. if (this.numComponents > 4) {
  5631. throw 'Unsupported color mode';
  5632. }
  5633. // type of data: Uint8Array(width * height * numComponents)
  5634. var data = this._getLinearizedBlockData(width, height);
  5635. if (this.numComponents === 3) {
  5636. return this._convertYccToRgb(data);
  5637. } else if (this.numComponents === 4) {
  5638. if (this._isColorConversionNeeded()) {
  5639. if (forceRGBoutput) {
  5640. return this._convertYcckToRgb(data);
  5641. } else {
  5642. return this._convertYcckToCmyk(data);
  5643. }
  5644. } else if (forceRGBoutput) {
  5645. return this._convertCmykToRgb(data);
  5646. }
  5647. }
  5648. return data;
  5649. }
  5650. };
  5651. return constructor;
  5652. })();
  5653. exports.JpegImage = JpegImage;
  5654. }));
  5655. (function (root, factory) {
  5656. {
  5657. factory((root.pdfjsCoreMetrics = {}));
  5658. }
  5659. }(this, function (exports) {
  5660. // The Metrics object contains glyph widths (in glyph space units).
  5661. // As per PDF spec, for most fonts (Type 3 being an exception) a glyph
  5662. // space unit corresponds to 1/1000th of text space unit.
  5663. var Metrics = {
  5664. 'Courier': 600,
  5665. 'Courier-Bold': 600,
  5666. 'Courier-BoldOblique': 600,
  5667. 'Courier-Oblique': 600,
  5668. 'Helvetica' : {
  5669. 'space': 278,
  5670. 'exclam': 278,
  5671. 'quotedbl': 355,
  5672. 'numbersign': 556,
  5673. 'dollar': 556,
  5674. 'percent': 889,
  5675. 'ampersand': 667,
  5676. 'quoteright': 222,
  5677. 'parenleft': 333,
  5678. 'parenright': 333,
  5679. 'asterisk': 389,
  5680. 'plus': 584,
  5681. 'comma': 278,
  5682. 'hyphen': 333,
  5683. 'period': 278,
  5684. 'slash': 278,
  5685. 'zero': 556,
  5686. 'one': 556,
  5687. 'two': 556,
  5688. 'three': 556,
  5689. 'four': 556,
  5690. 'five': 556,
  5691. 'six': 556,
  5692. 'seven': 556,
  5693. 'eight': 556,
  5694. 'nine': 556,
  5695. 'colon': 278,
  5696. 'semicolon': 278,
  5697. 'less': 584,
  5698. 'equal': 584,
  5699. 'greater': 584,
  5700. 'question': 556,
  5701. 'at': 1015,
  5702. 'A': 667,
  5703. 'B': 667,
  5704. 'C': 722,
  5705. 'D': 722,
  5706. 'E': 667,
  5707. 'F': 611,
  5708. 'G': 778,
  5709. 'H': 722,
  5710. 'I': 278,
  5711. 'J': 500,
  5712. 'K': 667,
  5713. 'L': 556,
  5714. 'M': 833,
  5715. 'N': 722,
  5716. 'O': 778,
  5717. 'P': 667,
  5718. 'Q': 778,
  5719. 'R': 722,
  5720. 'S': 667,
  5721. 'T': 611,
  5722. 'U': 722,
  5723. 'V': 667,
  5724. 'W': 944,
  5725. 'X': 667,
  5726. 'Y': 667,
  5727. 'Z': 611,
  5728. 'bracketleft': 278,
  5729. 'backslash': 278,
  5730. 'bracketright': 278,
  5731. 'asciicircum': 469,
  5732. 'underscore': 556,
  5733. 'quoteleft': 222,
  5734. 'a': 556,
  5735. 'b': 556,
  5736. 'c': 500,
  5737. 'd': 556,
  5738. 'e': 556,
  5739. 'f': 278,
  5740. 'g': 556,
  5741. 'h': 556,
  5742. 'i': 222,
  5743. 'j': 222,
  5744. 'k': 500,
  5745. 'l': 222,
  5746. 'm': 833,
  5747. 'n': 556,
  5748. 'o': 556,
  5749. 'p': 556,
  5750. 'q': 556,
  5751. 'r': 333,
  5752. 's': 500,
  5753. 't': 278,
  5754. 'u': 556,
  5755. 'v': 500,
  5756. 'w': 722,
  5757. 'x': 500,
  5758. 'y': 500,
  5759. 'z': 500,
  5760. 'braceleft': 334,
  5761. 'bar': 260,
  5762. 'braceright': 334,
  5763. 'asciitilde': 584,
  5764. 'exclamdown': 333,
  5765. 'cent': 556,
  5766. 'sterling': 556,
  5767. 'fraction': 167,
  5768. 'yen': 556,
  5769. 'florin': 556,
  5770. 'section': 556,
  5771. 'currency': 556,
  5772. 'quotesingle': 191,
  5773. 'quotedblleft': 333,
  5774. 'guillemotleft': 556,
  5775. 'guilsinglleft': 333,
  5776. 'guilsinglright': 333,
  5777. 'fi': 500,
  5778. 'fl': 500,
  5779. 'endash': 556,
  5780. 'dagger': 556,
  5781. 'daggerdbl': 556,
  5782. 'periodcentered': 278,
  5783. 'paragraph': 537,
  5784. 'bullet': 350,
  5785. 'quotesinglbase': 222,
  5786. 'quotedblbase': 333,
  5787. 'quotedblright': 333,
  5788. 'guillemotright': 556,
  5789. 'ellipsis': 1000,
  5790. 'perthousand': 1000,
  5791. 'questiondown': 611,
  5792. 'grave': 333,
  5793. 'acute': 333,
  5794. 'circumflex': 333,
  5795. 'tilde': 333,
  5796. 'macron': 333,
  5797. 'breve': 333,
  5798. 'dotaccent': 333,
  5799. 'dieresis': 333,
  5800. 'ring': 333,
  5801. 'cedilla': 333,
  5802. 'hungarumlaut': 333,
  5803. 'ogonek': 333,
  5804. 'caron': 333,
  5805. 'emdash': 1000,
  5806. 'AE': 1000,
  5807. 'ordfeminine': 370,
  5808. 'Lslash': 556,
  5809. 'Oslash': 778,
  5810. 'OE': 1000,
  5811. 'ordmasculine': 365,
  5812. 'ae': 889,
  5813. 'dotlessi': 278,
  5814. 'lslash': 222,
  5815. 'oslash': 611,
  5816. 'oe': 944,
  5817. 'germandbls': 611,
  5818. 'Idieresis': 278,
  5819. 'eacute': 556,
  5820. 'abreve': 556,
  5821. 'uhungarumlaut': 556,
  5822. 'ecaron': 556,
  5823. 'Ydieresis': 667,
  5824. 'divide': 584,
  5825. 'Yacute': 667,
  5826. 'Acircumflex': 667,
  5827. 'aacute': 556,
  5828. 'Ucircumflex': 722,
  5829. 'yacute': 500,
  5830. 'scommaaccent': 500,
  5831. 'ecircumflex': 556,
  5832. 'Uring': 722,
  5833. 'Udieresis': 722,
  5834. 'aogonek': 556,
  5835. 'Uacute': 722,
  5836. 'uogonek': 556,
  5837. 'Edieresis': 667,
  5838. 'Dcroat': 722,
  5839. 'commaaccent': 250,
  5840. 'copyright': 737,
  5841. 'Emacron': 667,
  5842. 'ccaron': 500,
  5843. 'aring': 556,
  5844. 'Ncommaaccent': 722,
  5845. 'lacute': 222,
  5846. 'agrave': 556,
  5847. 'Tcommaaccent': 611,
  5848. 'Cacute': 722,
  5849. 'atilde': 556,
  5850. 'Edotaccent': 667,
  5851. 'scaron': 500,
  5852. 'scedilla': 500,
  5853. 'iacute': 278,
  5854. 'lozenge': 471,
  5855. 'Rcaron': 722,
  5856. 'Gcommaaccent': 778,
  5857. 'ucircumflex': 556,
  5858. 'acircumflex': 556,
  5859. 'Amacron': 667,
  5860. 'rcaron': 333,
  5861. 'ccedilla': 500,
  5862. 'Zdotaccent': 611,
  5863. 'Thorn': 667,
  5864. 'Omacron': 778,
  5865. 'Racute': 722,
  5866. 'Sacute': 667,
  5867. 'dcaron': 643,
  5868. 'Umacron': 722,
  5869. 'uring': 556,
  5870. 'threesuperior': 333,
  5871. 'Ograve': 778,
  5872. 'Agrave': 667,
  5873. 'Abreve': 667,
  5874. 'multiply': 584,
  5875. 'uacute': 556,
  5876. 'Tcaron': 611,
  5877. 'partialdiff': 476,
  5878. 'ydieresis': 500,
  5879. 'Nacute': 722,
  5880. 'icircumflex': 278,
  5881. 'Ecircumflex': 667,
  5882. 'adieresis': 556,
  5883. 'edieresis': 556,
  5884. 'cacute': 500,
  5885. 'nacute': 556,
  5886. 'umacron': 556,
  5887. 'Ncaron': 722,
  5888. 'Iacute': 278,
  5889. 'plusminus': 584,
  5890. 'brokenbar': 260,
  5891. 'registered': 737,
  5892. 'Gbreve': 778,
  5893. 'Idotaccent': 278,
  5894. 'summation': 600,
  5895. 'Egrave': 667,
  5896. 'racute': 333,
  5897. 'omacron': 556,
  5898. 'Zacute': 611,
  5899. 'Zcaron': 611,
  5900. 'greaterequal': 549,
  5901. 'Eth': 722,
  5902. 'Ccedilla': 722,
  5903. 'lcommaaccent': 222,
  5904. 'tcaron': 317,
  5905. 'eogonek': 556,
  5906. 'Uogonek': 722,
  5907. 'Aacute': 667,
  5908. 'Adieresis': 667,
  5909. 'egrave': 556,
  5910. 'zacute': 500,
  5911. 'iogonek': 222,
  5912. 'Oacute': 778,
  5913. 'oacute': 556,
  5914. 'amacron': 556,
  5915. 'sacute': 500,
  5916. 'idieresis': 278,
  5917. 'Ocircumflex': 778,
  5918. 'Ugrave': 722,
  5919. 'Delta': 612,
  5920. 'thorn': 556,
  5921. 'twosuperior': 333,
  5922. 'Odieresis': 778,
  5923. 'mu': 556,
  5924. 'igrave': 278,
  5925. 'ohungarumlaut': 556,
  5926. 'Eogonek': 667,
  5927. 'dcroat': 556,
  5928. 'threequarters': 834,
  5929. 'Scedilla': 667,
  5930. 'lcaron': 299,
  5931. 'Kcommaaccent': 667,
  5932. 'Lacute': 556,
  5933. 'trademark': 1000,
  5934. 'edotaccent': 556,
  5935. 'Igrave': 278,
  5936. 'Imacron': 278,
  5937. 'Lcaron': 556,
  5938. 'onehalf': 834,
  5939. 'lessequal': 549,
  5940. 'ocircumflex': 556,
  5941. 'ntilde': 556,
  5942. 'Uhungarumlaut': 722,
  5943. 'Eacute': 667,
  5944. 'emacron': 556,
  5945. 'gbreve': 556,
  5946. 'onequarter': 834,
  5947. 'Scaron': 667,
  5948. 'Scommaaccent': 667,
  5949. 'Ohungarumlaut': 778,
  5950. 'degree': 400,
  5951. 'ograve': 556,
  5952. 'Ccaron': 722,
  5953. 'ugrave': 556,
  5954. 'radical': 453,
  5955. 'Dcaron': 722,
  5956. 'rcommaaccent': 333,
  5957. 'Ntilde': 722,
  5958. 'otilde': 556,
  5959. 'Rcommaaccent': 722,
  5960. 'Lcommaaccent': 556,
  5961. 'Atilde': 667,
  5962. 'Aogonek': 667,
  5963. 'Aring': 667,
  5964. 'Otilde': 778,
  5965. 'zdotaccent': 500,
  5966. 'Ecaron': 667,
  5967. 'Iogonek': 278,
  5968. 'kcommaaccent': 500,
  5969. 'minus': 584,
  5970. 'Icircumflex': 278,
  5971. 'ncaron': 556,
  5972. 'tcommaaccent': 278,
  5973. 'logicalnot': 584,
  5974. 'odieresis': 556,
  5975. 'udieresis': 556,
  5976. 'notequal': 549,
  5977. 'gcommaaccent': 556,
  5978. 'eth': 556,
  5979. 'zcaron': 500,
  5980. 'ncommaaccent': 556,
  5981. 'onesuperior': 333,
  5982. 'imacron': 278,
  5983. 'Euro': 556
  5984. },
  5985. 'Helvetica-Bold': {
  5986. 'space': 278,
  5987. 'exclam': 333,
  5988. 'quotedbl': 474,
  5989. 'numbersign': 556,
  5990. 'dollar': 556,
  5991. 'percent': 889,
  5992. 'ampersand': 722,
  5993. 'quoteright': 278,
  5994. 'parenleft': 333,
  5995. 'parenright': 333,
  5996. 'asterisk': 389,
  5997. 'plus': 584,
  5998. 'comma': 278,
  5999. 'hyphen': 333,
  6000. 'period': 278,
  6001. 'slash': 278,
  6002. 'zero': 556,
  6003. 'one': 556,
  6004. 'two': 556,
  6005. 'three': 556,
  6006. 'four': 556,
  6007. 'five': 556,
  6008. 'six': 556,
  6009. 'seven': 556,
  6010. 'eight': 556,
  6011. 'nine': 556,
  6012. 'colon': 333,
  6013. 'semicolon': 333,
  6014. 'less': 584,
  6015. 'equal': 584,
  6016. 'greater': 584,
  6017. 'question': 611,
  6018. 'at': 975,
  6019. 'A': 722,
  6020. 'B': 722,
  6021. 'C': 722,
  6022. 'D': 722,
  6023. 'E': 667,
  6024. 'F': 611,
  6025. 'G': 778,
  6026. 'H': 722,
  6027. 'I': 278,
  6028. 'J': 556,
  6029. 'K': 722,
  6030. 'L': 611,
  6031. 'M': 833,
  6032. 'N': 722,
  6033. 'O': 778,
  6034. 'P': 667,
  6035. 'Q': 778,
  6036. 'R': 722,
  6037. 'S': 667,
  6038. 'T': 611,
  6039. 'U': 722,
  6040. 'V': 667,
  6041. 'W': 944,
  6042. 'X': 667,
  6043. 'Y': 667,
  6044. 'Z': 611,
  6045. 'bracketleft': 333,
  6046. 'backslash': 278,
  6047. 'bracketright': 333,
  6048. 'asciicircum': 584,
  6049. 'underscore': 556,
  6050. 'quoteleft': 278,
  6051. 'a': 556,
  6052. 'b': 611,
  6053. 'c': 556,
  6054. 'd': 611,
  6055. 'e': 556,
  6056. 'f': 333,
  6057. 'g': 611,
  6058. 'h': 611,
  6059. 'i': 278,
  6060. 'j': 278,
  6061. 'k': 556,
  6062. 'l': 278,
  6063. 'm': 889,
  6064. 'n': 611,
  6065. 'o': 611,
  6066. 'p': 611,
  6067. 'q': 611,
  6068. 'r': 389,
  6069. 's': 556,
  6070. 't': 333,
  6071. 'u': 611,
  6072. 'v': 556,
  6073. 'w': 778,
  6074. 'x': 556,
  6075. 'y': 556,
  6076. 'z': 500,
  6077. 'braceleft': 389,
  6078. 'bar': 280,
  6079. 'braceright': 389,
  6080. 'asciitilde': 584,
  6081. 'exclamdown': 333,
  6082. 'cent': 556,
  6083. 'sterling': 556,
  6084. 'fraction': 167,
  6085. 'yen': 556,
  6086. 'florin': 556,
  6087. 'section': 556,
  6088. 'currency': 556,
  6089. 'quotesingle': 238,
  6090. 'quotedblleft': 500,
  6091. 'guillemotleft': 556,
  6092. 'guilsinglleft': 333,
  6093. 'guilsinglright': 333,
  6094. 'fi': 611,
  6095. 'fl': 611,
  6096. 'endash': 556,
  6097. 'dagger': 556,
  6098. 'daggerdbl': 556,
  6099. 'periodcentered': 278,
  6100. 'paragraph': 556,
  6101. 'bullet': 350,
  6102. 'quotesinglbase': 278,
  6103. 'quotedblbase': 500,
  6104. 'quotedblright': 500,
  6105. 'guillemotright': 556,
  6106. 'ellipsis': 1000,
  6107. 'perthousand': 1000,
  6108. 'questiondown': 611,
  6109. 'grave': 333,
  6110. 'acute': 333,
  6111. 'circumflex': 333,
  6112. 'tilde': 333,
  6113. 'macron': 333,
  6114. 'breve': 333,
  6115. 'dotaccent': 333,
  6116. 'dieresis': 333,
  6117. 'ring': 333,
  6118. 'cedilla': 333,
  6119. 'hungarumlaut': 333,
  6120. 'ogonek': 333,
  6121. 'caron': 333,
  6122. 'emdash': 1000,
  6123. 'AE': 1000,
  6124. 'ordfeminine': 370,
  6125. 'Lslash': 611,
  6126. 'Oslash': 778,
  6127. 'OE': 1000,
  6128. 'ordmasculine': 365,
  6129. 'ae': 889,
  6130. 'dotlessi': 278,
  6131. 'lslash': 278,
  6132. 'oslash': 611,
  6133. 'oe': 944,
  6134. 'germandbls': 611,
  6135. 'Idieresis': 278,
  6136. 'eacute': 556,
  6137. 'abreve': 556,
  6138. 'uhungarumlaut': 611,
  6139. 'ecaron': 556,
  6140. 'Ydieresis': 667,
  6141. 'divide': 584,
  6142. 'Yacute': 667,
  6143. 'Acircumflex': 722,
  6144. 'aacute': 556,
  6145. 'Ucircumflex': 722,
  6146. 'yacute': 556,
  6147. 'scommaaccent': 556,
  6148. 'ecircumflex': 556,
  6149. 'Uring': 722,
  6150. 'Udieresis': 722,
  6151. 'aogonek': 556,
  6152. 'Uacute': 722,
  6153. 'uogonek': 611,
  6154. 'Edieresis': 667,
  6155. 'Dcroat': 722,
  6156. 'commaaccent': 250,
  6157. 'copyright': 737,
  6158. 'Emacron': 667,
  6159. 'ccaron': 556,
  6160. 'aring': 556,
  6161. 'Ncommaaccent': 722,
  6162. 'lacute': 278,
  6163. 'agrave': 556,
  6164. 'Tcommaaccent': 611,
  6165. 'Cacute': 722,
  6166. 'atilde': 556,
  6167. 'Edotaccent': 667,
  6168. 'scaron': 556,
  6169. 'scedilla': 556,
  6170. 'iacute': 278,
  6171. 'lozenge': 494,
  6172. 'Rcaron': 722,
  6173. 'Gcommaaccent': 778,
  6174. 'ucircumflex': 611,
  6175. 'acircumflex': 556,
  6176. 'Amacron': 722,
  6177. 'rcaron': 389,
  6178. 'ccedilla': 556,
  6179. 'Zdotaccent': 611,
  6180. 'Thorn': 667,
  6181. 'Omacron': 778,
  6182. 'Racute': 722,
  6183. 'Sacute': 667,
  6184. 'dcaron': 743,
  6185. 'Umacron': 722,
  6186. 'uring': 611,
  6187. 'threesuperior': 333,
  6188. 'Ograve': 778,
  6189. 'Agrave': 722,
  6190. 'Abreve': 722,
  6191. 'multiply': 584,
  6192. 'uacute': 611,
  6193. 'Tcaron': 611,
  6194. 'partialdiff': 494,
  6195. 'ydieresis': 556,
  6196. 'Nacute': 722,
  6197. 'icircumflex': 278,
  6198. 'Ecircumflex': 667,
  6199. 'adieresis': 556,
  6200. 'edieresis': 556,
  6201. 'cacute': 556,
  6202. 'nacute': 611,
  6203. 'umacron': 611,
  6204. 'Ncaron': 722,
  6205. 'Iacute': 278,
  6206. 'plusminus': 584,
  6207. 'brokenbar': 280,
  6208. 'registered': 737,
  6209. 'Gbreve': 778,
  6210. 'Idotaccent': 278,
  6211. 'summation': 600,
  6212. 'Egrave': 667,
  6213. 'racute': 389,
  6214. 'omacron': 611,
  6215. 'Zacute': 611,
  6216. 'Zcaron': 611,
  6217. 'greaterequal': 549,
  6218. 'Eth': 722,
  6219. 'Ccedilla': 722,
  6220. 'lcommaaccent': 278,
  6221. 'tcaron': 389,
  6222. 'eogonek': 556,
  6223. 'Uogonek': 722,
  6224. 'Aacute': 722,
  6225. 'Adieresis': 722,
  6226. 'egrave': 556,
  6227. 'zacute': 500,
  6228. 'iogonek': 278,
  6229. 'Oacute': 778,
  6230. 'oacute': 611,
  6231. 'amacron': 556,
  6232. 'sacute': 556,
  6233. 'idieresis': 278,
  6234. 'Ocircumflex': 778,
  6235. 'Ugrave': 722,
  6236. 'Delta': 612,
  6237. 'thorn': 611,
  6238. 'twosuperior': 333,
  6239. 'Odieresis': 778,
  6240. 'mu': 611,
  6241. 'igrave': 278,
  6242. 'ohungarumlaut': 611,
  6243. 'Eogonek': 667,
  6244. 'dcroat': 611,
  6245. 'threequarters': 834,
  6246. 'Scedilla': 667,
  6247. 'lcaron': 400,
  6248. 'Kcommaaccent': 722,
  6249. 'Lacute': 611,
  6250. 'trademark': 1000,
  6251. 'edotaccent': 556,
  6252. 'Igrave': 278,
  6253. 'Imacron': 278,
  6254. 'Lcaron': 611,
  6255. 'onehalf': 834,
  6256. 'lessequal': 549,
  6257. 'ocircumflex': 611,
  6258. 'ntilde': 611,
  6259. 'Uhungarumlaut': 722,
  6260. 'Eacute': 667,
  6261. 'emacron': 556,
  6262. 'gbreve': 611,
  6263. 'onequarter': 834,
  6264. 'Scaron': 667,
  6265. 'Scommaaccent': 667,
  6266. 'Ohungarumlaut': 778,
  6267. 'degree': 400,
  6268. 'ograve': 611,
  6269. 'Ccaron': 722,
  6270. 'ugrave': 611,
  6271. 'radical': 549,
  6272. 'Dcaron': 722,
  6273. 'rcommaaccent': 389,
  6274. 'Ntilde': 722,
  6275. 'otilde': 611,
  6276. 'Rcommaaccent': 722,
  6277. 'Lcommaaccent': 611,
  6278. 'Atilde': 722,
  6279. 'Aogonek': 722,
  6280. 'Aring': 722,
  6281. 'Otilde': 778,
  6282. 'zdotaccent': 500,
  6283. 'Ecaron': 667,
  6284. 'Iogonek': 278,
  6285. 'kcommaaccent': 556,
  6286. 'minus': 584,
  6287. 'Icircumflex': 278,
  6288. 'ncaron': 611,
  6289. 'tcommaaccent': 333,
  6290. 'logicalnot': 584,
  6291. 'odieresis': 611,
  6292. 'udieresis': 611,
  6293. 'notequal': 549,
  6294. 'gcommaaccent': 611,
  6295. 'eth': 611,
  6296. 'zcaron': 500,
  6297. 'ncommaaccent': 611,
  6298. 'onesuperior': 333,
  6299. 'imacron': 278,
  6300. 'Euro': 556
  6301. },
  6302. 'Helvetica-BoldOblique': {
  6303. 'space': 278,
  6304. 'exclam': 333,
  6305. 'quotedbl': 474,
  6306. 'numbersign': 556,
  6307. 'dollar': 556,
  6308. 'percent': 889,
  6309. 'ampersand': 722,
  6310. 'quoteright': 278,
  6311. 'parenleft': 333,
  6312. 'parenright': 333,
  6313. 'asterisk': 389,
  6314. 'plus': 584,
  6315. 'comma': 278,
  6316. 'hyphen': 333,
  6317. 'period': 278,
  6318. 'slash': 278,
  6319. 'zero': 556,
  6320. 'one': 556,
  6321. 'two': 556,
  6322. 'three': 556,
  6323. 'four': 556,
  6324. 'five': 556,
  6325. 'six': 556,
  6326. 'seven': 556,
  6327. 'eight': 556,
  6328. 'nine': 556,
  6329. 'colon': 333,
  6330. 'semicolon': 333,
  6331. 'less': 584,
  6332. 'equal': 584,
  6333. 'greater': 584,
  6334. 'question': 611,
  6335. 'at': 975,
  6336. 'A': 722,
  6337. 'B': 722,
  6338. 'C': 722,
  6339. 'D': 722,
  6340. 'E': 667,
  6341. 'F': 611,
  6342. 'G': 778,
  6343. 'H': 722,
  6344. 'I': 278,
  6345. 'J': 556,
  6346. 'K': 722,
  6347. 'L': 611,
  6348. 'M': 833,
  6349. 'N': 722,
  6350. 'O': 778,
  6351. 'P': 667,
  6352. 'Q': 778,
  6353. 'R': 722,
  6354. 'S': 667,
  6355. 'T': 611,
  6356. 'U': 722,
  6357. 'V': 667,
  6358. 'W': 944,
  6359. 'X': 667,
  6360. 'Y': 667,
  6361. 'Z': 611,
  6362. 'bracketleft': 333,
  6363. 'backslash': 278,
  6364. 'bracketright': 333,
  6365. 'asciicircum': 584,
  6366. 'underscore': 556,
  6367. 'quoteleft': 278,
  6368. 'a': 556,
  6369. 'b': 611,
  6370. 'c': 556,
  6371. 'd': 611,
  6372. 'e': 556,
  6373. 'f': 333,
  6374. 'g': 611,
  6375. 'h': 611,
  6376. 'i': 278,
  6377. 'j': 278,
  6378. 'k': 556,
  6379. 'l': 278,
  6380. 'm': 889,
  6381. 'n': 611,
  6382. 'o': 611,
  6383. 'p': 611,
  6384. 'q': 611,
  6385. 'r': 389,
  6386. 's': 556,
  6387. 't': 333,
  6388. 'u': 611,
  6389. 'v': 556,
  6390. 'w': 778,
  6391. 'x': 556,
  6392. 'y': 556,
  6393. 'z': 500,
  6394. 'braceleft': 389,
  6395. 'bar': 280,
  6396. 'braceright': 389,
  6397. 'asciitilde': 584,
  6398. 'exclamdown': 333,
  6399. 'cent': 556,
  6400. 'sterling': 556,
  6401. 'fraction': 167,
  6402. 'yen': 556,
  6403. 'florin': 556,
  6404. 'section': 556,
  6405. 'currency': 556,
  6406. 'quotesingle': 238,
  6407. 'quotedblleft': 500,
  6408. 'guillemotleft': 556,
  6409. 'guilsinglleft': 333,
  6410. 'guilsinglright': 333,
  6411. 'fi': 611,
  6412. 'fl': 611,
  6413. 'endash': 556,
  6414. 'dagger': 556,
  6415. 'daggerdbl': 556,
  6416. 'periodcentered': 278,
  6417. 'paragraph': 556,
  6418. 'bullet': 350,
  6419. 'quotesinglbase': 278,
  6420. 'quotedblbase': 500,
  6421. 'quotedblright': 500,
  6422. 'guillemotright': 556,
  6423. 'ellipsis': 1000,
  6424. 'perthousand': 1000,
  6425. 'questiondown': 611,
  6426. 'grave': 333,
  6427. 'acute': 333,
  6428. 'circumflex': 333,
  6429. 'tilde': 333,
  6430. 'macron': 333,
  6431. 'breve': 333,
  6432. 'dotaccent': 333,
  6433. 'dieresis': 333,
  6434. 'ring': 333,
  6435. 'cedilla': 333,
  6436. 'hungarumlaut': 333,
  6437. 'ogonek': 333,
  6438. 'caron': 333,
  6439. 'emdash': 1000,
  6440. 'AE': 1000,
  6441. 'ordfeminine': 370,
  6442. 'Lslash': 611,
  6443. 'Oslash': 778,
  6444. 'OE': 1000,
  6445. 'ordmasculine': 365,
  6446. 'ae': 889,
  6447. 'dotlessi': 278,
  6448. 'lslash': 278,
  6449. 'oslash': 611,
  6450. 'oe': 944,
  6451. 'germandbls': 611,
  6452. 'Idieresis': 278,
  6453. 'eacute': 556,
  6454. 'abreve': 556,
  6455. 'uhungarumlaut': 611,
  6456. 'ecaron': 556,
  6457. 'Ydieresis': 667,
  6458. 'divide': 584,
  6459. 'Yacute': 667,
  6460. 'Acircumflex': 722,
  6461. 'aacute': 556,
  6462. 'Ucircumflex': 722,
  6463. 'yacute': 556,
  6464. 'scommaaccent': 556,
  6465. 'ecircumflex': 556,
  6466. 'Uring': 722,
  6467. 'Udieresis': 722,
  6468. 'aogonek': 556,
  6469. 'Uacute': 722,
  6470. 'uogonek': 611,
  6471. 'Edieresis': 667,
  6472. 'Dcroat': 722,
  6473. 'commaaccent': 250,
  6474. 'copyright': 737,
  6475. 'Emacron': 667,
  6476. 'ccaron': 556,
  6477. 'aring': 556,
  6478. 'Ncommaaccent': 722,
  6479. 'lacute': 278,
  6480. 'agrave': 556,
  6481. 'Tcommaaccent': 611,
  6482. 'Cacute': 722,
  6483. 'atilde': 556,
  6484. 'Edotaccent': 667,
  6485. 'scaron': 556,
  6486. 'scedilla': 556,
  6487. 'iacute': 278,
  6488. 'lozenge': 494,
  6489. 'Rcaron': 722,
  6490. 'Gcommaaccent': 778,
  6491. 'ucircumflex': 611,
  6492. 'acircumflex': 556,
  6493. 'Amacron': 722,
  6494. 'rcaron': 389,
  6495. 'ccedilla': 556,
  6496. 'Zdotaccent': 611,
  6497. 'Thorn': 667,
  6498. 'Omacron': 778,
  6499. 'Racute': 722,
  6500. 'Sacute': 667,
  6501. 'dcaron': 743,
  6502. 'Umacron': 722,
  6503. 'uring': 611,
  6504. 'threesuperior': 333,
  6505. 'Ograve': 778,
  6506. 'Agrave': 722,
  6507. 'Abreve': 722,
  6508. 'multiply': 584,
  6509. 'uacute': 611,
  6510. 'Tcaron': 611,
  6511. 'partialdiff': 494,
  6512. 'ydieresis': 556,
  6513. 'Nacute': 722,
  6514. 'icircumflex': 278,
  6515. 'Ecircumflex': 667,
  6516. 'adieresis': 556,
  6517. 'edieresis': 556,
  6518. 'cacute': 556,
  6519. 'nacute': 611,
  6520. 'umacron': 611,
  6521. 'Ncaron': 722,
  6522. 'Iacute': 278,
  6523. 'plusminus': 584,
  6524. 'brokenbar': 280,
  6525. 'registered': 737,
  6526. 'Gbreve': 778,
  6527. 'Idotaccent': 278,
  6528. 'summation': 600,
  6529. 'Egrave': 667,
  6530. 'racute': 389,
  6531. 'omacron': 611,
  6532. 'Zacute': 611,
  6533. 'Zcaron': 611,
  6534. 'greaterequal': 549,
  6535. 'Eth': 722,
  6536. 'Ccedilla': 722,
  6537. 'lcommaaccent': 278,
  6538. 'tcaron': 389,
  6539. 'eogonek': 556,
  6540. 'Uogonek': 722,
  6541. 'Aacute': 722,
  6542. 'Adieresis': 722,
  6543. 'egrave': 556,
  6544. 'zacute': 500,
  6545. 'iogonek': 278,
  6546. 'Oacute': 778,
  6547. 'oacute': 611,
  6548. 'amacron': 556,
  6549. 'sacute': 556,
  6550. 'idieresis': 278,
  6551. 'Ocircumflex': 778,
  6552. 'Ugrave': 722,
  6553. 'Delta': 612,
  6554. 'thorn': 611,
  6555. 'twosuperior': 333,
  6556. 'Odieresis': 778,
  6557. 'mu': 611,
  6558. 'igrave': 278,
  6559. 'ohungarumlaut': 611,
  6560. 'Eogonek': 667,
  6561. 'dcroat': 611,
  6562. 'threequarters': 834,
  6563. 'Scedilla': 667,
  6564. 'lcaron': 400,
  6565. 'Kcommaaccent': 722,
  6566. 'Lacute': 611,
  6567. 'trademark': 1000,
  6568. 'edotaccent': 556,
  6569. 'Igrave': 278,
  6570. 'Imacron': 278,
  6571. 'Lcaron': 611,
  6572. 'onehalf': 834,
  6573. 'lessequal': 549,
  6574. 'ocircumflex': 611,
  6575. 'ntilde': 611,
  6576. 'Uhungarumlaut': 722,
  6577. 'Eacute': 667,
  6578. 'emacron': 556,
  6579. 'gbreve': 611,
  6580. 'onequarter': 834,
  6581. 'Scaron': 667,
  6582. 'Scommaaccent': 667,
  6583. 'Ohungarumlaut': 778,
  6584. 'degree': 400,
  6585. 'ograve': 611,
  6586. 'Ccaron': 722,
  6587. 'ugrave': 611,
  6588. 'radical': 549,
  6589. 'Dcaron': 722,
  6590. 'rcommaaccent': 389,
  6591. 'Ntilde': 722,
  6592. 'otilde': 611,
  6593. 'Rcommaaccent': 722,
  6594. 'Lcommaaccent': 611,
  6595. 'Atilde': 722,
  6596. 'Aogonek': 722,
  6597. 'Aring': 722,
  6598. 'Otilde': 778,
  6599. 'zdotaccent': 500,
  6600. 'Ecaron': 667,
  6601. 'Iogonek': 278,
  6602. 'kcommaaccent': 556,
  6603. 'minus': 584,
  6604. 'Icircumflex': 278,
  6605. 'ncaron': 611,
  6606. 'tcommaaccent': 333,
  6607. 'logicalnot': 584,
  6608. 'odieresis': 611,
  6609. 'udieresis': 611,
  6610. 'notequal': 549,
  6611. 'gcommaaccent': 611,
  6612. 'eth': 611,
  6613. 'zcaron': 500,
  6614. 'ncommaaccent': 611,
  6615. 'onesuperior': 333,
  6616. 'imacron': 278,
  6617. 'Euro': 556
  6618. },
  6619. 'Helvetica-Oblique' : {
  6620. 'space': 278,
  6621. 'exclam': 278,
  6622. 'quotedbl': 355,
  6623. 'numbersign': 556,
  6624. 'dollar': 556,
  6625. 'percent': 889,
  6626. 'ampersand': 667,
  6627. 'quoteright': 222,
  6628. 'parenleft': 333,
  6629. 'parenright': 333,
  6630. 'asterisk': 389,
  6631. 'plus': 584,
  6632. 'comma': 278,
  6633. 'hyphen': 333,
  6634. 'period': 278,
  6635. 'slash': 278,
  6636. 'zero': 556,
  6637. 'one': 556,
  6638. 'two': 556,
  6639. 'three': 556,
  6640. 'four': 556,
  6641. 'five': 556,
  6642. 'six': 556,
  6643. 'seven': 556,
  6644. 'eight': 556,
  6645. 'nine': 556,
  6646. 'colon': 278,
  6647. 'semicolon': 278,
  6648. 'less': 584,
  6649. 'equal': 584,
  6650. 'greater': 584,
  6651. 'question': 556,
  6652. 'at': 1015,
  6653. 'A': 667,
  6654. 'B': 667,
  6655. 'C': 722,
  6656. 'D': 722,
  6657. 'E': 667,
  6658. 'F': 611,
  6659. 'G': 778,
  6660. 'H': 722,
  6661. 'I': 278,
  6662. 'J': 500,
  6663. 'K': 667,
  6664. 'L': 556,
  6665. 'M': 833,
  6666. 'N': 722,
  6667. 'O': 778,
  6668. 'P': 667,
  6669. 'Q': 778,
  6670. 'R': 722,
  6671. 'S': 667,
  6672. 'T': 611,
  6673. 'U': 722,
  6674. 'V': 667,
  6675. 'W': 944,
  6676. 'X': 667,
  6677. 'Y': 667,
  6678. 'Z': 611,
  6679. 'bracketleft': 278,
  6680. 'backslash': 278,
  6681. 'bracketright': 278,
  6682. 'asciicircum': 469,
  6683. 'underscore': 556,
  6684. 'quoteleft': 222,
  6685. 'a': 556,
  6686. 'b': 556,
  6687. 'c': 500,
  6688. 'd': 556,
  6689. 'e': 556,
  6690. 'f': 278,
  6691. 'g': 556,
  6692. 'h': 556,
  6693. 'i': 222,
  6694. 'j': 222,
  6695. 'k': 500,
  6696. 'l': 222,
  6697. 'm': 833,
  6698. 'n': 556,
  6699. 'o': 556,
  6700. 'p': 556,
  6701. 'q': 556,
  6702. 'r': 333,
  6703. 's': 500,
  6704. 't': 278,
  6705. 'u': 556,
  6706. 'v': 500,
  6707. 'w': 722,
  6708. 'x': 500,
  6709. 'y': 500,
  6710. 'z': 500,
  6711. 'braceleft': 334,
  6712. 'bar': 260,
  6713. 'braceright': 334,
  6714. 'asciitilde': 584,
  6715. 'exclamdown': 333,
  6716. 'cent': 556,
  6717. 'sterling': 556,
  6718. 'fraction': 167,
  6719. 'yen': 556,
  6720. 'florin': 556,
  6721. 'section': 556,
  6722. 'currency': 556,
  6723. 'quotesingle': 191,
  6724. 'quotedblleft': 333,
  6725. 'guillemotleft': 556,
  6726. 'guilsinglleft': 333,
  6727. 'guilsinglright': 333,
  6728. 'fi': 500,
  6729. 'fl': 500,
  6730. 'endash': 556,
  6731. 'dagger': 556,
  6732. 'daggerdbl': 556,
  6733. 'periodcentered': 278,
  6734. 'paragraph': 537,
  6735. 'bullet': 350,
  6736. 'quotesinglbase': 222,
  6737. 'quotedblbase': 333,
  6738. 'quotedblright': 333,
  6739. 'guillemotright': 556,
  6740. 'ellipsis': 1000,
  6741. 'perthousand': 1000,
  6742. 'questiondown': 611,
  6743. 'grave': 333,
  6744. 'acute': 333,
  6745. 'circumflex': 333,
  6746. 'tilde': 333,
  6747. 'macron': 333,
  6748. 'breve': 333,
  6749. 'dotaccent': 333,
  6750. 'dieresis': 333,
  6751. 'ring': 333,
  6752. 'cedilla': 333,
  6753. 'hungarumlaut': 333,
  6754. 'ogonek': 333,
  6755. 'caron': 333,
  6756. 'emdash': 1000,
  6757. 'AE': 1000,
  6758. 'ordfeminine': 370,
  6759. 'Lslash': 556,
  6760. 'Oslash': 778,
  6761. 'OE': 1000,
  6762. 'ordmasculine': 365,
  6763. 'ae': 889,
  6764. 'dotlessi': 278,
  6765. 'lslash': 222,
  6766. 'oslash': 611,
  6767. 'oe': 944,
  6768. 'germandbls': 611,
  6769. 'Idieresis': 278,
  6770. 'eacute': 556,
  6771. 'abreve': 556,
  6772. 'uhungarumlaut': 556,
  6773. 'ecaron': 556,
  6774. 'Ydieresis': 667,
  6775. 'divide': 584,
  6776. 'Yacute': 667,
  6777. 'Acircumflex': 667,
  6778. 'aacute': 556,
  6779. 'Ucircumflex': 722,
  6780. 'yacute': 500,
  6781. 'scommaaccent': 500,
  6782. 'ecircumflex': 556,
  6783. 'Uring': 722,
  6784. 'Udieresis': 722,
  6785. 'aogonek': 556,
  6786. 'Uacute': 722,
  6787. 'uogonek': 556,
  6788. 'Edieresis': 667,
  6789. 'Dcroat': 722,
  6790. 'commaaccent': 250,
  6791. 'copyright': 737,
  6792. 'Emacron': 667,
  6793. 'ccaron': 500,
  6794. 'aring': 556,
  6795. 'Ncommaaccent': 722,
  6796. 'lacute': 222,
  6797. 'agrave': 556,
  6798. 'Tcommaaccent': 611,
  6799. 'Cacute': 722,
  6800. 'atilde': 556,
  6801. 'Edotaccent': 667,
  6802. 'scaron': 500,
  6803. 'scedilla': 500,
  6804. 'iacute': 278,
  6805. 'lozenge': 471,
  6806. 'Rcaron': 722,
  6807. 'Gcommaaccent': 778,
  6808. 'ucircumflex': 556,
  6809. 'acircumflex': 556,
  6810. 'Amacron': 667,
  6811. 'rcaron': 333,
  6812. 'ccedilla': 500,
  6813. 'Zdotaccent': 611,
  6814. 'Thorn': 667,
  6815. 'Omacron': 778,
  6816. 'Racute': 722,
  6817. 'Sacute': 667,
  6818. 'dcaron': 643,
  6819. 'Umacron': 722,
  6820. 'uring': 556,
  6821. 'threesuperior': 333,
  6822. 'Ograve': 778,
  6823. 'Agrave': 667,
  6824. 'Abreve': 667,
  6825. 'multiply': 584,
  6826. 'uacute': 556,
  6827. 'Tcaron': 611,
  6828. 'partialdiff': 476,
  6829. 'ydieresis': 500,
  6830. 'Nacute': 722,
  6831. 'icircumflex': 278,
  6832. 'Ecircumflex': 667,
  6833. 'adieresis': 556,
  6834. 'edieresis': 556,
  6835. 'cacute': 500,
  6836. 'nacute': 556,
  6837. 'umacron': 556,
  6838. 'Ncaron': 722,
  6839. 'Iacute': 278,
  6840. 'plusminus': 584,
  6841. 'brokenbar': 260,
  6842. 'registered': 737,
  6843. 'Gbreve': 778,
  6844. 'Idotaccent': 278,
  6845. 'summation': 600,
  6846. 'Egrave': 667,
  6847. 'racute': 333,
  6848. 'omacron': 556,
  6849. 'Zacute': 611,
  6850. 'Zcaron': 611,
  6851. 'greaterequal': 549,
  6852. 'Eth': 722,
  6853. 'Ccedilla': 722,
  6854. 'lcommaaccent': 222,
  6855. 'tcaron': 317,
  6856. 'eogonek': 556,
  6857. 'Uogonek': 722,
  6858. 'Aacute': 667,
  6859. 'Adieresis': 667,
  6860. 'egrave': 556,
  6861. 'zacute': 500,
  6862. 'iogonek': 222,
  6863. 'Oacute': 778,
  6864. 'oacute': 556,
  6865. 'amacron': 556,
  6866. 'sacute': 500,
  6867. 'idieresis': 278,
  6868. 'Ocircumflex': 778,
  6869. 'Ugrave': 722,
  6870. 'Delta': 612,
  6871. 'thorn': 556,
  6872. 'twosuperior': 333,
  6873. 'Odieresis': 778,
  6874. 'mu': 556,
  6875. 'igrave': 278,
  6876. 'ohungarumlaut': 556,
  6877. 'Eogonek': 667,
  6878. 'dcroat': 556,
  6879. 'threequarters': 834,
  6880. 'Scedilla': 667,
  6881. 'lcaron': 299,
  6882. 'Kcommaaccent': 667,
  6883. 'Lacute': 556,
  6884. 'trademark': 1000,
  6885. 'edotaccent': 556,
  6886. 'Igrave': 278,
  6887. 'Imacron': 278,
  6888. 'Lcaron': 556,
  6889. 'onehalf': 834,
  6890. 'lessequal': 549,
  6891. 'ocircumflex': 556,
  6892. 'ntilde': 556,
  6893. 'Uhungarumlaut': 722,
  6894. 'Eacute': 667,
  6895. 'emacron': 556,
  6896. 'gbreve': 556,
  6897. 'onequarter': 834,
  6898. 'Scaron': 667,
  6899. 'Scommaaccent': 667,
  6900. 'Ohungarumlaut': 778,
  6901. 'degree': 400,
  6902. 'ograve': 556,
  6903. 'Ccaron': 722,
  6904. 'ugrave': 556,
  6905. 'radical': 453,
  6906. 'Dcaron': 722,
  6907. 'rcommaaccent': 333,
  6908. 'Ntilde': 722,
  6909. 'otilde': 556,
  6910. 'Rcommaaccent': 722,
  6911. 'Lcommaaccent': 556,
  6912. 'Atilde': 667,
  6913. 'Aogonek': 667,
  6914. 'Aring': 667,
  6915. 'Otilde': 778,
  6916. 'zdotaccent': 500,
  6917. 'Ecaron': 667,
  6918. 'Iogonek': 278,
  6919. 'kcommaaccent': 500,
  6920. 'minus': 584,
  6921. 'Icircumflex': 278,
  6922. 'ncaron': 556,
  6923. 'tcommaaccent': 278,
  6924. 'logicalnot': 584,
  6925. 'odieresis': 556,
  6926. 'udieresis': 556,
  6927. 'notequal': 549,
  6928. 'gcommaaccent': 556,
  6929. 'eth': 556,
  6930. 'zcaron': 500,
  6931. 'ncommaaccent': 556,
  6932. 'onesuperior': 333,
  6933. 'imacron': 278,
  6934. 'Euro': 556
  6935. },
  6936. 'Symbol': {
  6937. 'space': 250,
  6938. 'exclam': 333,
  6939. 'universal': 713,
  6940. 'numbersign': 500,
  6941. 'existential': 549,
  6942. 'percent': 833,
  6943. 'ampersand': 778,
  6944. 'suchthat': 439,
  6945. 'parenleft': 333,
  6946. 'parenright': 333,
  6947. 'asteriskmath': 500,
  6948. 'plus': 549,
  6949. 'comma': 250,
  6950. 'minus': 549,
  6951. 'period': 250,
  6952. 'slash': 278,
  6953. 'zero': 500,
  6954. 'one': 500,
  6955. 'two': 500,
  6956. 'three': 500,
  6957. 'four': 500,
  6958. 'five': 500,
  6959. 'six': 500,
  6960. 'seven': 500,
  6961. 'eight': 500,
  6962. 'nine': 500,
  6963. 'colon': 278,
  6964. 'semicolon': 278,
  6965. 'less': 549,
  6966. 'equal': 549,
  6967. 'greater': 549,
  6968. 'question': 444,
  6969. 'congruent': 549,
  6970. 'Alpha': 722,
  6971. 'Beta': 667,
  6972. 'Chi': 722,
  6973. 'Delta': 612,
  6974. 'Epsilon': 611,
  6975. 'Phi': 763,
  6976. 'Gamma': 603,
  6977. 'Eta': 722,
  6978. 'Iota': 333,
  6979. 'theta1': 631,
  6980. 'Kappa': 722,
  6981. 'Lambda': 686,
  6982. 'Mu': 889,
  6983. 'Nu': 722,
  6984. 'Omicron': 722,
  6985. 'Pi': 768,
  6986. 'Theta': 741,
  6987. 'Rho': 556,
  6988. 'Sigma': 592,
  6989. 'Tau': 611,
  6990. 'Upsilon': 690,
  6991. 'sigma1': 439,
  6992. 'Omega': 768,
  6993. 'Xi': 645,
  6994. 'Psi': 795,
  6995. 'Zeta': 611,
  6996. 'bracketleft': 333,
  6997. 'therefore': 863,
  6998. 'bracketright': 333,
  6999. 'perpendicular': 658,
  7000. 'underscore': 500,
  7001. 'radicalex': 500,
  7002. 'alpha': 631,
  7003. 'beta': 549,
  7004. 'chi': 549,
  7005. 'delta': 494,
  7006. 'epsilon': 439,
  7007. 'phi': 521,
  7008. 'gamma': 411,
  7009. 'eta': 603,
  7010. 'iota': 329,
  7011. 'phi1': 603,
  7012. 'kappa': 549,
  7013. 'lambda': 549,
  7014. 'mu': 576,
  7015. 'nu': 521,
  7016. 'omicron': 549,
  7017. 'pi': 549,
  7018. 'theta': 521,
  7019. 'rho': 549,
  7020. 'sigma': 603,
  7021. 'tau': 439,
  7022. 'upsilon': 576,
  7023. 'omega1': 713,
  7024. 'omega': 686,
  7025. 'xi': 493,
  7026. 'psi': 686,
  7027. 'zeta': 494,
  7028. 'braceleft': 480,
  7029. 'bar': 200,
  7030. 'braceright': 480,
  7031. 'similar': 549,
  7032. 'Euro': 750,
  7033. 'Upsilon1': 620,
  7034. 'minute': 247,
  7035. 'lessequal': 549,
  7036. 'fraction': 167,
  7037. 'infinity': 713,
  7038. 'florin': 500,
  7039. 'club': 753,
  7040. 'diamond': 753,
  7041. 'heart': 753,
  7042. 'spade': 753,
  7043. 'arrowboth': 1042,
  7044. 'arrowleft': 987,
  7045. 'arrowup': 603,
  7046. 'arrowright': 987,
  7047. 'arrowdown': 603,
  7048. 'degree': 400,
  7049. 'plusminus': 549,
  7050. 'second': 411,
  7051. 'greaterequal': 549,
  7052. 'multiply': 549,
  7053. 'proportional': 713,
  7054. 'partialdiff': 494,
  7055. 'bullet': 460,
  7056. 'divide': 549,
  7057. 'notequal': 549,
  7058. 'equivalence': 549,
  7059. 'approxequal': 549,
  7060. 'ellipsis': 1000,
  7061. 'arrowvertex': 603,
  7062. 'arrowhorizex': 1000,
  7063. 'carriagereturn': 658,
  7064. 'aleph': 823,
  7065. 'Ifraktur': 686,
  7066. 'Rfraktur': 795,
  7067. 'weierstrass': 987,
  7068. 'circlemultiply': 768,
  7069. 'circleplus': 768,
  7070. 'emptyset': 823,
  7071. 'intersection': 768,
  7072. 'union': 768,
  7073. 'propersuperset': 713,
  7074. 'reflexsuperset': 713,
  7075. 'notsubset': 713,
  7076. 'propersubset': 713,
  7077. 'reflexsubset': 713,
  7078. 'element': 713,
  7079. 'notelement': 713,
  7080. 'angle': 768,
  7081. 'gradient': 713,
  7082. 'registerserif': 790,
  7083. 'copyrightserif': 790,
  7084. 'trademarkserif': 890,
  7085. 'product': 823,
  7086. 'radical': 549,
  7087. 'dotmath': 250,
  7088. 'logicalnot': 713,
  7089. 'logicaland': 603,
  7090. 'logicalor': 603,
  7091. 'arrowdblboth': 1042,
  7092. 'arrowdblleft': 987,
  7093. 'arrowdblup': 603,
  7094. 'arrowdblright': 987,
  7095. 'arrowdbldown': 603,
  7096. 'lozenge': 494,
  7097. 'angleleft': 329,
  7098. 'registersans': 790,
  7099. 'copyrightsans': 790,
  7100. 'trademarksans': 786,
  7101. 'summation': 713,
  7102. 'parenlefttp': 384,
  7103. 'parenleftex': 384,
  7104. 'parenleftbt': 384,
  7105. 'bracketlefttp': 384,
  7106. 'bracketleftex': 384,
  7107. 'bracketleftbt': 384,
  7108. 'bracelefttp': 494,
  7109. 'braceleftmid': 494,
  7110. 'braceleftbt': 494,
  7111. 'braceex': 494,
  7112. 'angleright': 329,
  7113. 'integral': 274,
  7114. 'integraltp': 686,
  7115. 'integralex': 686,
  7116. 'integralbt': 686,
  7117. 'parenrighttp': 384,
  7118. 'parenrightex': 384,
  7119. 'parenrightbt': 384,
  7120. 'bracketrighttp': 384,
  7121. 'bracketrightex': 384,
  7122. 'bracketrightbt': 384,
  7123. 'bracerighttp': 494,
  7124. 'bracerightmid': 494,
  7125. 'bracerightbt': 494,
  7126. 'apple': 790
  7127. },
  7128. 'Times-Roman': {
  7129. 'space': 250,
  7130. 'exclam': 333,
  7131. 'quotedbl': 408,
  7132. 'numbersign': 500,
  7133. 'dollar': 500,
  7134. 'percent': 833,
  7135. 'ampersand': 778,
  7136. 'quoteright': 333,
  7137. 'parenleft': 333,
  7138. 'parenright': 333,
  7139. 'asterisk': 500,
  7140. 'plus': 564,
  7141. 'comma': 250,
  7142. 'hyphen': 333,
  7143. 'period': 250,
  7144. 'slash': 278,
  7145. 'zero': 500,
  7146. 'one': 500,
  7147. 'two': 500,
  7148. 'three': 500,
  7149. 'four': 500,
  7150. 'five': 500,
  7151. 'six': 500,
  7152. 'seven': 500,
  7153. 'eight': 500,
  7154. 'nine': 500,
  7155. 'colon': 278,
  7156. 'semicolon': 278,
  7157. 'less': 564,
  7158. 'equal': 564,
  7159. 'greater': 564,
  7160. 'question': 444,
  7161. 'at': 921,
  7162. 'A': 722,
  7163. 'B': 667,
  7164. 'C': 667,
  7165. 'D': 722,
  7166. 'E': 611,
  7167. 'F': 556,
  7168. 'G': 722,
  7169. 'H': 722,
  7170. 'I': 333,
  7171. 'J': 389,
  7172. 'K': 722,
  7173. 'L': 611,
  7174. 'M': 889,
  7175. 'N': 722,
  7176. 'O': 722,
  7177. 'P': 556,
  7178. 'Q': 722,
  7179. 'R': 667,
  7180. 'S': 556,
  7181. 'T': 611,
  7182. 'U': 722,
  7183. 'V': 722,
  7184. 'W': 944,
  7185. 'X': 722,
  7186. 'Y': 722,
  7187. 'Z': 611,
  7188. 'bracketleft': 333,
  7189. 'backslash': 278,
  7190. 'bracketright': 333,
  7191. 'asciicircum': 469,
  7192. 'underscore': 500,
  7193. 'quoteleft': 333,
  7194. 'a': 444,
  7195. 'b': 500,
  7196. 'c': 444,
  7197. 'd': 500,
  7198. 'e': 444,
  7199. 'f': 333,
  7200. 'g': 500,
  7201. 'h': 500,
  7202. 'i': 278,
  7203. 'j': 278,
  7204. 'k': 500,
  7205. 'l': 278,
  7206. 'm': 778,
  7207. 'n': 500,
  7208. 'o': 500,
  7209. 'p': 500,
  7210. 'q': 500,
  7211. 'r': 333,
  7212. 's': 389,
  7213. 't': 278,
  7214. 'u': 500,
  7215. 'v': 500,
  7216. 'w': 722,
  7217. 'x': 500,
  7218. 'y': 500,
  7219. 'z': 444,
  7220. 'braceleft': 480,
  7221. 'bar': 200,
  7222. 'braceright': 480,
  7223. 'asciitilde': 541,
  7224. 'exclamdown': 333,
  7225. 'cent': 500,
  7226. 'sterling': 500,
  7227. 'fraction': 167,
  7228. 'yen': 500,
  7229. 'florin': 500,
  7230. 'section': 500,
  7231. 'currency': 500,
  7232. 'quotesingle': 180,
  7233. 'quotedblleft': 444,
  7234. 'guillemotleft': 500,
  7235. 'guilsinglleft': 333,
  7236. 'guilsinglright': 333,
  7237. 'fi': 556,
  7238. 'fl': 556,
  7239. 'endash': 500,
  7240. 'dagger': 500,
  7241. 'daggerdbl': 500,
  7242. 'periodcentered': 250,
  7243. 'paragraph': 453,
  7244. 'bullet': 350,
  7245. 'quotesinglbase': 333,
  7246. 'quotedblbase': 444,
  7247. 'quotedblright': 444,
  7248. 'guillemotright': 500,
  7249. 'ellipsis': 1000,
  7250. 'perthousand': 1000,
  7251. 'questiondown': 444,
  7252. 'grave': 333,
  7253. 'acute': 333,
  7254. 'circumflex': 333,
  7255. 'tilde': 333,
  7256. 'macron': 333,
  7257. 'breve': 333,
  7258. 'dotaccent': 333,
  7259. 'dieresis': 333,
  7260. 'ring': 333,
  7261. 'cedilla': 333,
  7262. 'hungarumlaut': 333,
  7263. 'ogonek': 333,
  7264. 'caron': 333,
  7265. 'emdash': 1000,
  7266. 'AE': 889,
  7267. 'ordfeminine': 276,
  7268. 'Lslash': 611,
  7269. 'Oslash': 722,
  7270. 'OE': 889,
  7271. 'ordmasculine': 310,
  7272. 'ae': 667,
  7273. 'dotlessi': 278,
  7274. 'lslash': 278,
  7275. 'oslash': 500,
  7276. 'oe': 722,
  7277. 'germandbls': 500,
  7278. 'Idieresis': 333,
  7279. 'eacute': 444,
  7280. 'abreve': 444,
  7281. 'uhungarumlaut': 500,
  7282. 'ecaron': 444,
  7283. 'Ydieresis': 722,
  7284. 'divide': 564,
  7285. 'Yacute': 722,
  7286. 'Acircumflex': 722,
  7287. 'aacute': 444,
  7288. 'Ucircumflex': 722,
  7289. 'yacute': 500,
  7290. 'scommaaccent': 389,
  7291. 'ecircumflex': 444,
  7292. 'Uring': 722,
  7293. 'Udieresis': 722,
  7294. 'aogonek': 444,
  7295. 'Uacute': 722,
  7296. 'uogonek': 500,
  7297. 'Edieresis': 611,
  7298. 'Dcroat': 722,
  7299. 'commaaccent': 250,
  7300. 'copyright': 760,
  7301. 'Emacron': 611,
  7302. 'ccaron': 444,
  7303. 'aring': 444,
  7304. 'Ncommaaccent': 722,
  7305. 'lacute': 278,
  7306. 'agrave': 444,
  7307. 'Tcommaaccent': 611,
  7308. 'Cacute': 667,
  7309. 'atilde': 444,
  7310. 'Edotaccent': 611,
  7311. 'scaron': 389,
  7312. 'scedilla': 389,
  7313. 'iacute': 278,
  7314. 'lozenge': 471,
  7315. 'Rcaron': 667,
  7316. 'Gcommaaccent': 722,
  7317. 'ucircumflex': 500,
  7318. 'acircumflex': 444,
  7319. 'Amacron': 722,
  7320. 'rcaron': 333,
  7321. 'ccedilla': 444,
  7322. 'Zdotaccent': 611,
  7323. 'Thorn': 556,
  7324. 'Omacron': 722,
  7325. 'Racute': 667,
  7326. 'Sacute': 556,
  7327. 'dcaron': 588,
  7328. 'Umacron': 722,
  7329. 'uring': 500,
  7330. 'threesuperior': 300,
  7331. 'Ograve': 722,
  7332. 'Agrave': 722,
  7333. 'Abreve': 722,
  7334. 'multiply': 564,
  7335. 'uacute': 500,
  7336. 'Tcaron': 611,
  7337. 'partialdiff': 476,
  7338. 'ydieresis': 500,
  7339. 'Nacute': 722,
  7340. 'icircumflex': 278,
  7341. 'Ecircumflex': 611,
  7342. 'adieresis': 444,
  7343. 'edieresis': 444,
  7344. 'cacute': 444,
  7345. 'nacute': 500,
  7346. 'umacron': 500,
  7347. 'Ncaron': 722,
  7348. 'Iacute': 333,
  7349. 'plusminus': 564,
  7350. 'brokenbar': 200,
  7351. 'registered': 760,
  7352. 'Gbreve': 722,
  7353. 'Idotaccent': 333,
  7354. 'summation': 600,
  7355. 'Egrave': 611,
  7356. 'racute': 333,
  7357. 'omacron': 500,
  7358. 'Zacute': 611,
  7359. 'Zcaron': 611,
  7360. 'greaterequal': 549,
  7361. 'Eth': 722,
  7362. 'Ccedilla': 667,
  7363. 'lcommaaccent': 278,
  7364. 'tcaron': 326,
  7365. 'eogonek': 444,
  7366. 'Uogonek': 722,
  7367. 'Aacute': 722,
  7368. 'Adieresis': 722,
  7369. 'egrave': 444,
  7370. 'zacute': 444,
  7371. 'iogonek': 278,
  7372. 'Oacute': 722,
  7373. 'oacute': 500,
  7374. 'amacron': 444,
  7375. 'sacute': 389,
  7376. 'idieresis': 278,
  7377. 'Ocircumflex': 722,
  7378. 'Ugrave': 722,
  7379. 'Delta': 612,
  7380. 'thorn': 500,
  7381. 'twosuperior': 300,
  7382. 'Odieresis': 722,
  7383. 'mu': 500,
  7384. 'igrave': 278,
  7385. 'ohungarumlaut': 500,
  7386. 'Eogonek': 611,
  7387. 'dcroat': 500,
  7388. 'threequarters': 750,
  7389. 'Scedilla': 556,
  7390. 'lcaron': 344,
  7391. 'Kcommaaccent': 722,
  7392. 'Lacute': 611,
  7393. 'trademark': 980,
  7394. 'edotaccent': 444,
  7395. 'Igrave': 333,
  7396. 'Imacron': 333,
  7397. 'Lcaron': 611,
  7398. 'onehalf': 750,
  7399. 'lessequal': 549,
  7400. 'ocircumflex': 500,
  7401. 'ntilde': 500,
  7402. 'Uhungarumlaut': 722,
  7403. 'Eacute': 611,
  7404. 'emacron': 444,
  7405. 'gbreve': 500,
  7406. 'onequarter': 750,
  7407. 'Scaron': 556,
  7408. 'Scommaaccent': 556,
  7409. 'Ohungarumlaut': 722,
  7410. 'degree': 400,
  7411. 'ograve': 500,
  7412. 'Ccaron': 667,
  7413. 'ugrave': 500,
  7414. 'radical': 453,
  7415. 'Dcaron': 722,
  7416. 'rcommaaccent': 333,
  7417. 'Ntilde': 722,
  7418. 'otilde': 500,
  7419. 'Rcommaaccent': 667,
  7420. 'Lcommaaccent': 611,
  7421. 'Atilde': 722,
  7422. 'Aogonek': 722,
  7423. 'Aring': 722,
  7424. 'Otilde': 722,
  7425. 'zdotaccent': 444,
  7426. 'Ecaron': 611,
  7427. 'Iogonek': 333,
  7428. 'kcommaaccent': 500,
  7429. 'minus': 564,
  7430. 'Icircumflex': 333,
  7431. 'ncaron': 500,
  7432. 'tcommaaccent': 278,
  7433. 'logicalnot': 564,
  7434. 'odieresis': 500,
  7435. 'udieresis': 500,
  7436. 'notequal': 549,
  7437. 'gcommaaccent': 500,
  7438. 'eth': 500,
  7439. 'zcaron': 444,
  7440. 'ncommaaccent': 500,
  7441. 'onesuperior': 300,
  7442. 'imacron': 278,
  7443. 'Euro': 500
  7444. },
  7445. 'Times-Bold': {
  7446. 'space': 250,
  7447. 'exclam': 333,
  7448. 'quotedbl': 555,
  7449. 'numbersign': 500,
  7450. 'dollar': 500,
  7451. 'percent': 1000,
  7452. 'ampersand': 833,
  7453. 'quoteright': 333,
  7454. 'parenleft': 333,
  7455. 'parenright': 333,
  7456. 'asterisk': 500,
  7457. 'plus': 570,
  7458. 'comma': 250,
  7459. 'hyphen': 333,
  7460. 'period': 250,
  7461. 'slash': 278,
  7462. 'zero': 500,
  7463. 'one': 500,
  7464. 'two': 500,
  7465. 'three': 500,
  7466. 'four': 500,
  7467. 'five': 500,
  7468. 'six': 500,
  7469. 'seven': 500,
  7470. 'eight': 500,
  7471. 'nine': 500,
  7472. 'colon': 333,
  7473. 'semicolon': 333,
  7474. 'less': 570,
  7475. 'equal': 570,
  7476. 'greater': 570,
  7477. 'question': 500,
  7478. 'at': 930,
  7479. 'A': 722,
  7480. 'B': 667,
  7481. 'C': 722,
  7482. 'D': 722,
  7483. 'E': 667,
  7484. 'F': 611,
  7485. 'G': 778,
  7486. 'H': 778,
  7487. 'I': 389,
  7488. 'J': 500,
  7489. 'K': 778,
  7490. 'L': 667,
  7491. 'M': 944,
  7492. 'N': 722,
  7493. 'O': 778,
  7494. 'P': 611,
  7495. 'Q': 778,
  7496. 'R': 722,
  7497. 'S': 556,
  7498. 'T': 667,
  7499. 'U': 722,
  7500. 'V': 722,
  7501. 'W': 1000,
  7502. 'X': 722,
  7503. 'Y': 722,
  7504. 'Z': 667,
  7505. 'bracketleft': 333,
  7506. 'backslash': 278,
  7507. 'bracketright': 333,
  7508. 'asciicircum': 581,
  7509. 'underscore': 500,
  7510. 'quoteleft': 333,
  7511. 'a': 500,
  7512. 'b': 556,
  7513. 'c': 444,
  7514. 'd': 556,
  7515. 'e': 444,
  7516. 'f': 333,
  7517. 'g': 500,
  7518. 'h': 556,
  7519. 'i': 278,
  7520. 'j': 333,
  7521. 'k': 556,
  7522. 'l': 278,
  7523. 'm': 833,
  7524. 'n': 556,
  7525. 'o': 500,
  7526. 'p': 556,
  7527. 'q': 556,
  7528. 'r': 444,
  7529. 's': 389,
  7530. 't': 333,
  7531. 'u': 556,
  7532. 'v': 500,
  7533. 'w': 722,
  7534. 'x': 500,
  7535. 'y': 500,
  7536. 'z': 444,
  7537. 'braceleft': 394,
  7538. 'bar': 220,
  7539. 'braceright': 394,
  7540. 'asciitilde': 520,
  7541. 'exclamdown': 333,
  7542. 'cent': 500,
  7543. 'sterling': 500,
  7544. 'fraction': 167,
  7545. 'yen': 500,
  7546. 'florin': 500,
  7547. 'section': 500,
  7548. 'currency': 500,
  7549. 'quotesingle': 278,
  7550. 'quotedblleft': 500,
  7551. 'guillemotleft': 500,
  7552. 'guilsinglleft': 333,
  7553. 'guilsinglright': 333,
  7554. 'fi': 556,
  7555. 'fl': 556,
  7556. 'endash': 500,
  7557. 'dagger': 500,
  7558. 'daggerdbl': 500,
  7559. 'periodcentered': 250,
  7560. 'paragraph': 540,
  7561. 'bullet': 350,
  7562. 'quotesinglbase': 333,
  7563. 'quotedblbase': 500,
  7564. 'quotedblright': 500,
  7565. 'guillemotright': 500,
  7566. 'ellipsis': 1000,
  7567. 'perthousand': 1000,
  7568. 'questiondown': 500,
  7569. 'grave': 333,
  7570. 'acute': 333,
  7571. 'circumflex': 333,
  7572. 'tilde': 333,
  7573. 'macron': 333,
  7574. 'breve': 333,
  7575. 'dotaccent': 333,
  7576. 'dieresis': 333,
  7577. 'ring': 333,
  7578. 'cedilla': 333,
  7579. 'hungarumlaut': 333,
  7580. 'ogonek': 333,
  7581. 'caron': 333,
  7582. 'emdash': 1000,
  7583. 'AE': 1000,
  7584. 'ordfeminine': 300,
  7585. 'Lslash': 667,
  7586. 'Oslash': 778,
  7587. 'OE': 1000,
  7588. 'ordmasculine': 330,
  7589. 'ae': 722,
  7590. 'dotlessi': 278,
  7591. 'lslash': 278,
  7592. 'oslash': 500,
  7593. 'oe': 722,
  7594. 'germandbls': 556,
  7595. 'Idieresis': 389,
  7596. 'eacute': 444,
  7597. 'abreve': 500,
  7598. 'uhungarumlaut': 556,
  7599. 'ecaron': 444,
  7600. 'Ydieresis': 722,
  7601. 'divide': 570,
  7602. 'Yacute': 722,
  7603. 'Acircumflex': 722,
  7604. 'aacute': 500,
  7605. 'Ucircumflex': 722,
  7606. 'yacute': 500,
  7607. 'scommaaccent': 389,
  7608. 'ecircumflex': 444,
  7609. 'Uring': 722,
  7610. 'Udieresis': 722,
  7611. 'aogonek': 500,
  7612. 'Uacute': 722,
  7613. 'uogonek': 556,
  7614. 'Edieresis': 667,
  7615. 'Dcroat': 722,
  7616. 'commaaccent': 250,
  7617. 'copyright': 747,
  7618. 'Emacron': 667,
  7619. 'ccaron': 444,
  7620. 'aring': 500,
  7621. 'Ncommaaccent': 722,
  7622. 'lacute': 278,
  7623. 'agrave': 500,
  7624. 'Tcommaaccent': 667,
  7625. 'Cacute': 722,
  7626. 'atilde': 500,
  7627. 'Edotaccent': 667,
  7628. 'scaron': 389,
  7629. 'scedilla': 389,
  7630. 'iacute': 278,
  7631. 'lozenge': 494,
  7632. 'Rcaron': 722,
  7633. 'Gcommaaccent': 778,
  7634. 'ucircumflex': 556,
  7635. 'acircumflex': 500,
  7636. 'Amacron': 722,
  7637. 'rcaron': 444,
  7638. 'ccedilla': 444,
  7639. 'Zdotaccent': 667,
  7640. 'Thorn': 611,
  7641. 'Omacron': 778,
  7642. 'Racute': 722,
  7643. 'Sacute': 556,
  7644. 'dcaron': 672,
  7645. 'Umacron': 722,
  7646. 'uring': 556,
  7647. 'threesuperior': 300,
  7648. 'Ograve': 778,
  7649. 'Agrave': 722,
  7650. 'Abreve': 722,
  7651. 'multiply': 570,
  7652. 'uacute': 556,
  7653. 'Tcaron': 667,
  7654. 'partialdiff': 494,
  7655. 'ydieresis': 500,
  7656. 'Nacute': 722,
  7657. 'icircumflex': 278,
  7658. 'Ecircumflex': 667,
  7659. 'adieresis': 500,
  7660. 'edieresis': 444,
  7661. 'cacute': 444,
  7662. 'nacute': 556,
  7663. 'umacron': 556,
  7664. 'Ncaron': 722,
  7665. 'Iacute': 389,
  7666. 'plusminus': 570,
  7667. 'brokenbar': 220,
  7668. 'registered': 747,
  7669. 'Gbreve': 778,
  7670. 'Idotaccent': 389,
  7671. 'summation': 600,
  7672. 'Egrave': 667,
  7673. 'racute': 444,
  7674. 'omacron': 500,
  7675. 'Zacute': 667,
  7676. 'Zcaron': 667,
  7677. 'greaterequal': 549,
  7678. 'Eth': 722,
  7679. 'Ccedilla': 722,
  7680. 'lcommaaccent': 278,
  7681. 'tcaron': 416,
  7682. 'eogonek': 444,
  7683. 'Uogonek': 722,
  7684. 'Aacute': 722,
  7685. 'Adieresis': 722,
  7686. 'egrave': 444,
  7687. 'zacute': 444,
  7688. 'iogonek': 278,
  7689. 'Oacute': 778,
  7690. 'oacute': 500,
  7691. 'amacron': 500,
  7692. 'sacute': 389,
  7693. 'idieresis': 278,
  7694. 'Ocircumflex': 778,
  7695. 'Ugrave': 722,
  7696. 'Delta': 612,
  7697. 'thorn': 556,
  7698. 'twosuperior': 300,
  7699. 'Odieresis': 778,
  7700. 'mu': 556,
  7701. 'igrave': 278,
  7702. 'ohungarumlaut': 500,
  7703. 'Eogonek': 667,
  7704. 'dcroat': 556,
  7705. 'threequarters': 750,
  7706. 'Scedilla': 556,
  7707. 'lcaron': 394,
  7708. 'Kcommaaccent': 778,
  7709. 'Lacute': 667,
  7710. 'trademark': 1000,
  7711. 'edotaccent': 444,
  7712. 'Igrave': 389,
  7713. 'Imacron': 389,
  7714. 'Lcaron': 667,
  7715. 'onehalf': 750,
  7716. 'lessequal': 549,
  7717. 'ocircumflex': 500,
  7718. 'ntilde': 556,
  7719. 'Uhungarumlaut': 722,
  7720. 'Eacute': 667,
  7721. 'emacron': 444,
  7722. 'gbreve': 500,
  7723. 'onequarter': 750,
  7724. 'Scaron': 556,
  7725. 'Scommaaccent': 556,
  7726. 'Ohungarumlaut': 778,
  7727. 'degree': 400,
  7728. 'ograve': 500,
  7729. 'Ccaron': 722,
  7730. 'ugrave': 556,
  7731. 'radical': 549,
  7732. 'Dcaron': 722,
  7733. 'rcommaaccent': 444,
  7734. 'Ntilde': 722,
  7735. 'otilde': 500,
  7736. 'Rcommaaccent': 722,
  7737. 'Lcommaaccent': 667,
  7738. 'Atilde': 722,
  7739. 'Aogonek': 722,
  7740. 'Aring': 722,
  7741. 'Otilde': 778,
  7742. 'zdotaccent': 444,
  7743. 'Ecaron': 667,
  7744. 'Iogonek': 389,
  7745. 'kcommaaccent': 556,
  7746. 'minus': 570,
  7747. 'Icircumflex': 389,
  7748. 'ncaron': 556,
  7749. 'tcommaaccent': 333,
  7750. 'logicalnot': 570,
  7751. 'odieresis': 500,
  7752. 'udieresis': 556,
  7753. 'notequal': 549,
  7754. 'gcommaaccent': 500,
  7755. 'eth': 500,
  7756. 'zcaron': 444,
  7757. 'ncommaaccent': 556,
  7758. 'onesuperior': 300,
  7759. 'imacron': 278,
  7760. 'Euro': 500
  7761. },
  7762. 'Times-BoldItalic': {
  7763. 'space': 250,
  7764. 'exclam': 389,
  7765. 'quotedbl': 555,
  7766. 'numbersign': 500,
  7767. 'dollar': 500,
  7768. 'percent': 833,
  7769. 'ampersand': 778,
  7770. 'quoteright': 333,
  7771. 'parenleft': 333,
  7772. 'parenright': 333,
  7773. 'asterisk': 500,
  7774. 'plus': 570,
  7775. 'comma': 250,
  7776. 'hyphen': 333,
  7777. 'period': 250,
  7778. 'slash': 278,
  7779. 'zero': 500,
  7780. 'one': 500,
  7781. 'two': 500,
  7782. 'three': 500,
  7783. 'four': 500,
  7784. 'five': 500,
  7785. 'six': 500,
  7786. 'seven': 500,
  7787. 'eight': 500,
  7788. 'nine': 500,
  7789. 'colon': 333,
  7790. 'semicolon': 333,
  7791. 'less': 570,
  7792. 'equal': 570,
  7793. 'greater': 570,
  7794. 'question': 500,
  7795. 'at': 832,
  7796. 'A': 667,
  7797. 'B': 667,
  7798. 'C': 667,
  7799. 'D': 722,
  7800. 'E': 667,
  7801. 'F': 667,
  7802. 'G': 722,
  7803. 'H': 778,
  7804. 'I': 389,
  7805. 'J': 500,
  7806. 'K': 667,
  7807. 'L': 611,
  7808. 'M': 889,
  7809. 'N': 722,
  7810. 'O': 722,
  7811. 'P': 611,
  7812. 'Q': 722,
  7813. 'R': 667,
  7814. 'S': 556,
  7815. 'T': 611,
  7816. 'U': 722,
  7817. 'V': 667,
  7818. 'W': 889,
  7819. 'X': 667,
  7820. 'Y': 611,
  7821. 'Z': 611,
  7822. 'bracketleft': 333,
  7823. 'backslash': 278,
  7824. 'bracketright': 333,
  7825. 'asciicircum': 570,
  7826. 'underscore': 500,
  7827. 'quoteleft': 333,
  7828. 'a': 500,
  7829. 'b': 500,
  7830. 'c': 444,
  7831. 'd': 500,
  7832. 'e': 444,
  7833. 'f': 333,
  7834. 'g': 500,
  7835. 'h': 556,
  7836. 'i': 278,
  7837. 'j': 278,
  7838. 'k': 500,
  7839. 'l': 278,
  7840. 'm': 778,
  7841. 'n': 556,
  7842. 'o': 500,
  7843. 'p': 500,
  7844. 'q': 500,
  7845. 'r': 389,
  7846. 's': 389,
  7847. 't': 278,
  7848. 'u': 556,
  7849. 'v': 444,
  7850. 'w': 667,
  7851. 'x': 500,
  7852. 'y': 444,
  7853. 'z': 389,
  7854. 'braceleft': 348,
  7855. 'bar': 220,
  7856. 'braceright': 348,
  7857. 'asciitilde': 570,
  7858. 'exclamdown': 389,
  7859. 'cent': 500,
  7860. 'sterling': 500,
  7861. 'fraction': 167,
  7862. 'yen': 500,
  7863. 'florin': 500,
  7864. 'section': 500,
  7865. 'currency': 500,
  7866. 'quotesingle': 278,
  7867. 'quotedblleft': 500,
  7868. 'guillemotleft': 500,
  7869. 'guilsinglleft': 333,
  7870. 'guilsinglright': 333,
  7871. 'fi': 556,
  7872. 'fl': 556,
  7873. 'endash': 500,
  7874. 'dagger': 500,
  7875. 'daggerdbl': 500,
  7876. 'periodcentered': 250,
  7877. 'paragraph': 500,
  7878. 'bullet': 350,
  7879. 'quotesinglbase': 333,
  7880. 'quotedblbase': 500,
  7881. 'quotedblright': 500,
  7882. 'guillemotright': 500,
  7883. 'ellipsis': 1000,
  7884. 'perthousand': 1000,
  7885. 'questiondown': 500,
  7886. 'grave': 333,
  7887. 'acute': 333,
  7888. 'circumflex': 333,
  7889. 'tilde': 333,
  7890. 'macron': 333,
  7891. 'breve': 333,
  7892. 'dotaccent': 333,
  7893. 'dieresis': 333,
  7894. 'ring': 333,
  7895. 'cedilla': 333,
  7896. 'hungarumlaut': 333,
  7897. 'ogonek': 333,
  7898. 'caron': 333,
  7899. 'emdash': 1000,
  7900. 'AE': 944,
  7901. 'ordfeminine': 266,
  7902. 'Lslash': 611,
  7903. 'Oslash': 722,
  7904. 'OE': 944,
  7905. 'ordmasculine': 300,
  7906. 'ae': 722,
  7907. 'dotlessi': 278,
  7908. 'lslash': 278,
  7909. 'oslash': 500,
  7910. 'oe': 722,
  7911. 'germandbls': 500,
  7912. 'Idieresis': 389,
  7913. 'eacute': 444,
  7914. 'abreve': 500,
  7915. 'uhungarumlaut': 556,
  7916. 'ecaron': 444,
  7917. 'Ydieresis': 611,
  7918. 'divide': 570,
  7919. 'Yacute': 611,
  7920. 'Acircumflex': 667,
  7921. 'aacute': 500,
  7922. 'Ucircumflex': 722,
  7923. 'yacute': 444,
  7924. 'scommaaccent': 389,
  7925. 'ecircumflex': 444,
  7926. 'Uring': 722,
  7927. 'Udieresis': 722,
  7928. 'aogonek': 500,
  7929. 'Uacute': 722,
  7930. 'uogonek': 556,
  7931. 'Edieresis': 667,
  7932. 'Dcroat': 722,
  7933. 'commaaccent': 250,
  7934. 'copyright': 747,
  7935. 'Emacron': 667,
  7936. 'ccaron': 444,
  7937. 'aring': 500,
  7938. 'Ncommaaccent': 722,
  7939. 'lacute': 278,
  7940. 'agrave': 500,
  7941. 'Tcommaaccent': 611,
  7942. 'Cacute': 667,
  7943. 'atilde': 500,
  7944. 'Edotaccent': 667,
  7945. 'scaron': 389,
  7946. 'scedilla': 389,
  7947. 'iacute': 278,
  7948. 'lozenge': 494,
  7949. 'Rcaron': 667,
  7950. 'Gcommaaccent': 722,
  7951. 'ucircumflex': 556,
  7952. 'acircumflex': 500,
  7953. 'Amacron': 667,
  7954. 'rcaron': 389,
  7955. 'ccedilla': 444,
  7956. 'Zdotaccent': 611,
  7957. 'Thorn': 611,
  7958. 'Omacron': 722,
  7959. 'Racute': 667,
  7960. 'Sacute': 556,
  7961. 'dcaron': 608,
  7962. 'Umacron': 722,
  7963. 'uring': 556,
  7964. 'threesuperior': 300,
  7965. 'Ograve': 722,
  7966. 'Agrave': 667,
  7967. 'Abreve': 667,
  7968. 'multiply': 570,
  7969. 'uacute': 556,
  7970. 'Tcaron': 611,
  7971. 'partialdiff': 494,
  7972. 'ydieresis': 444,
  7973. 'Nacute': 722,
  7974. 'icircumflex': 278,
  7975. 'Ecircumflex': 667,
  7976. 'adieresis': 500,
  7977. 'edieresis': 444,
  7978. 'cacute': 444,
  7979. 'nacute': 556,
  7980. 'umacron': 556,
  7981. 'Ncaron': 722,
  7982. 'Iacute': 389,
  7983. 'plusminus': 570,
  7984. 'brokenbar': 220,
  7985. 'registered': 747,
  7986. 'Gbreve': 722,
  7987. 'Idotaccent': 389,
  7988. 'summation': 600,
  7989. 'Egrave': 667,
  7990. 'racute': 389,
  7991. 'omacron': 500,
  7992. 'Zacute': 611,
  7993. 'Zcaron': 611,
  7994. 'greaterequal': 549,
  7995. 'Eth': 722,
  7996. 'Ccedilla': 667,
  7997. 'lcommaaccent': 278,
  7998. 'tcaron': 366,
  7999. 'eogonek': 444,
  8000. 'Uogonek': 722,
  8001. 'Aacute': 667,
  8002. 'Adieresis': 667,
  8003. 'egrave': 444,
  8004. 'zacute': 389,
  8005. 'iogonek': 278,
  8006. 'Oacute': 722,
  8007. 'oacute': 500,
  8008. 'amacron': 500,
  8009. 'sacute': 389,
  8010. 'idieresis': 278,
  8011. 'Ocircumflex': 722,
  8012. 'Ugrave': 722,
  8013. 'Delta': 612,
  8014. 'thorn': 500,
  8015. 'twosuperior': 300,
  8016. 'Odieresis': 722,
  8017. 'mu': 576,
  8018. 'igrave': 278,
  8019. 'ohungarumlaut': 500,
  8020. 'Eogonek': 667,
  8021. 'dcroat': 500,
  8022. 'threequarters': 750,
  8023. 'Scedilla': 556,
  8024. 'lcaron': 382,
  8025. 'Kcommaaccent': 667,
  8026. 'Lacute': 611,
  8027. 'trademark': 1000,
  8028. 'edotaccent': 444,
  8029. 'Igrave': 389,
  8030. 'Imacron': 389,
  8031. 'Lcaron': 611,
  8032. 'onehalf': 750,
  8033. 'lessequal': 549,
  8034. 'ocircumflex': 500,
  8035. 'ntilde': 556,
  8036. 'Uhungarumlaut': 722,
  8037. 'Eacute': 667,
  8038. 'emacron': 444,
  8039. 'gbreve': 500,
  8040. 'onequarter': 750,
  8041. 'Scaron': 556,
  8042. 'Scommaaccent': 556,
  8043. 'Ohungarumlaut': 722,
  8044. 'degree': 400,
  8045. 'ograve': 500,
  8046. 'Ccaron': 667,
  8047. 'ugrave': 556,
  8048. 'radical': 549,
  8049. 'Dcaron': 722,
  8050. 'rcommaaccent': 389,
  8051. 'Ntilde': 722,
  8052. 'otilde': 500,
  8053. 'Rcommaaccent': 667,
  8054. 'Lcommaaccent': 611,
  8055. 'Atilde': 667,
  8056. 'Aogonek': 667,
  8057. 'Aring': 667,
  8058. 'Otilde': 722,
  8059. 'zdotaccent': 389,
  8060. 'Ecaron': 667,
  8061. 'Iogonek': 389,
  8062. 'kcommaaccent': 500,
  8063. 'minus': 606,
  8064. 'Icircumflex': 389,
  8065. 'ncaron': 556,
  8066. 'tcommaaccent': 278,
  8067. 'logicalnot': 606,
  8068. 'odieresis': 500,
  8069. 'udieresis': 556,
  8070. 'notequal': 549,
  8071. 'gcommaaccent': 500,
  8072. 'eth': 500,
  8073. 'zcaron': 389,
  8074. 'ncommaaccent': 556,
  8075. 'onesuperior': 300,
  8076. 'imacron': 278,
  8077. 'Euro': 500
  8078. },
  8079. 'Times-Italic': {
  8080. 'space': 250,
  8081. 'exclam': 333,
  8082. 'quotedbl': 420,
  8083. 'numbersign': 500,
  8084. 'dollar': 500,
  8085. 'percent': 833,
  8086. 'ampersand': 778,
  8087. 'quoteright': 333,
  8088. 'parenleft': 333,
  8089. 'parenright': 333,
  8090. 'asterisk': 500,
  8091. 'plus': 675,
  8092. 'comma': 250,
  8093. 'hyphen': 333,
  8094. 'period': 250,
  8095. 'slash': 278,
  8096. 'zero': 500,
  8097. 'one': 500,
  8098. 'two': 500,
  8099. 'three': 500,
  8100. 'four': 500,
  8101. 'five': 500,
  8102. 'six': 500,
  8103. 'seven': 500,
  8104. 'eight': 500,
  8105. 'nine': 500,
  8106. 'colon': 333,
  8107. 'semicolon': 333,
  8108. 'less': 675,
  8109. 'equal': 675,
  8110. 'greater': 675,
  8111. 'question': 500,
  8112. 'at': 920,
  8113. 'A': 611,
  8114. 'B': 611,
  8115. 'C': 667,
  8116. 'D': 722,
  8117. 'E': 611,
  8118. 'F': 611,
  8119. 'G': 722,
  8120. 'H': 722,
  8121. 'I': 333,
  8122. 'J': 444,
  8123. 'K': 667,
  8124. 'L': 556,
  8125. 'M': 833,
  8126. 'N': 667,
  8127. 'O': 722,
  8128. 'P': 611,
  8129. 'Q': 722,
  8130. 'R': 611,
  8131. 'S': 500,
  8132. 'T': 556,
  8133. 'U': 722,
  8134. 'V': 611,
  8135. 'W': 833,
  8136. 'X': 611,
  8137. 'Y': 556,
  8138. 'Z': 556,
  8139. 'bracketleft': 389,
  8140. 'backslash': 278,
  8141. 'bracketright': 389,
  8142. 'asciicircum': 422,
  8143. 'underscore': 500,
  8144. 'quoteleft': 333,
  8145. 'a': 500,
  8146. 'b': 500,
  8147. 'c': 444,
  8148. 'd': 500,
  8149. 'e': 444,
  8150. 'f': 278,
  8151. 'g': 500,
  8152. 'h': 500,
  8153. 'i': 278,
  8154. 'j': 278,
  8155. 'k': 444,
  8156. 'l': 278,
  8157. 'm': 722,
  8158. 'n': 500,
  8159. 'o': 500,
  8160. 'p': 500,
  8161. 'q': 500,
  8162. 'r': 389,
  8163. 's': 389,
  8164. 't': 278,
  8165. 'u': 500,
  8166. 'v': 444,
  8167. 'w': 667,
  8168. 'x': 444,
  8169. 'y': 444,
  8170. 'z': 389,
  8171. 'braceleft': 400,
  8172. 'bar': 275,
  8173. 'braceright': 400,
  8174. 'asciitilde': 541,
  8175. 'exclamdown': 389,
  8176. 'cent': 500,
  8177. 'sterling': 500,
  8178. 'fraction': 167,
  8179. 'yen': 500,
  8180. 'florin': 500,
  8181. 'section': 500,
  8182. 'currency': 500,
  8183. 'quotesingle': 214,
  8184. 'quotedblleft': 556,
  8185. 'guillemotleft': 500,
  8186. 'guilsinglleft': 333,
  8187. 'guilsinglright': 333,
  8188. 'fi': 500,
  8189. 'fl': 500,
  8190. 'endash': 500,
  8191. 'dagger': 500,
  8192. 'daggerdbl': 500,
  8193. 'periodcentered': 250,
  8194. 'paragraph': 523,
  8195. 'bullet': 350,
  8196. 'quotesinglbase': 333,
  8197. 'quotedblbase': 556,
  8198. 'quotedblright': 556,
  8199. 'guillemotright': 500,
  8200. 'ellipsis': 889,
  8201. 'perthousand': 1000,
  8202. 'questiondown': 500,
  8203. 'grave': 333,
  8204. 'acute': 333,
  8205. 'circumflex': 333,
  8206. 'tilde': 333,
  8207. 'macron': 333,
  8208. 'breve': 333,
  8209. 'dotaccent': 333,
  8210. 'dieresis': 333,
  8211. 'ring': 333,
  8212. 'cedilla': 333,
  8213. 'hungarumlaut': 333,
  8214. 'ogonek': 333,
  8215. 'caron': 333,
  8216. 'emdash': 889,
  8217. 'AE': 889,
  8218. 'ordfeminine': 276,
  8219. 'Lslash': 556,
  8220. 'Oslash': 722,
  8221. 'OE': 944,
  8222. 'ordmasculine': 310,
  8223. 'ae': 667,
  8224. 'dotlessi': 278,
  8225. 'lslash': 278,
  8226. 'oslash': 500,
  8227. 'oe': 667,
  8228. 'germandbls': 500,
  8229. 'Idieresis': 333,
  8230. 'eacute': 444,
  8231. 'abreve': 500,
  8232. 'uhungarumlaut': 500,
  8233. 'ecaron': 444,
  8234. 'Ydieresis': 556,
  8235. 'divide': 675,
  8236. 'Yacute': 556,
  8237. 'Acircumflex': 611,
  8238. 'aacute': 500,
  8239. 'Ucircumflex': 722,
  8240. 'yacute': 444,
  8241. 'scommaaccent': 389,
  8242. 'ecircumflex': 444,
  8243. 'Uring': 722,
  8244. 'Udieresis': 722,
  8245. 'aogonek': 500,
  8246. 'Uacute': 722,
  8247. 'uogonek': 500,
  8248. 'Edieresis': 611,
  8249. 'Dcroat': 722,
  8250. 'commaaccent': 250,
  8251. 'copyright': 760,
  8252. 'Emacron': 611,
  8253. 'ccaron': 444,
  8254. 'aring': 500,
  8255. 'Ncommaaccent': 667,
  8256. 'lacute': 278,
  8257. 'agrave': 500,
  8258. 'Tcommaaccent': 556,
  8259. 'Cacute': 667,
  8260. 'atilde': 500,
  8261. 'Edotaccent': 611,
  8262. 'scaron': 389,
  8263. 'scedilla': 389,
  8264. 'iacute': 278,
  8265. 'lozenge': 471,
  8266. 'Rcaron': 611,
  8267. 'Gcommaaccent': 722,
  8268. 'ucircumflex': 500,
  8269. 'acircumflex': 500,
  8270. 'Amacron': 611,
  8271. 'rcaron': 389,
  8272. 'ccedilla': 444,
  8273. 'Zdotaccent': 556,
  8274. 'Thorn': 611,
  8275. 'Omacron': 722,
  8276. 'Racute': 611,
  8277. 'Sacute': 500,
  8278. 'dcaron': 544,
  8279. 'Umacron': 722,
  8280. 'uring': 500,
  8281. 'threesuperior': 300,
  8282. 'Ograve': 722,
  8283. 'Agrave': 611,
  8284. 'Abreve': 611,
  8285. 'multiply': 675,
  8286. 'uacute': 500,
  8287. 'Tcaron': 556,
  8288. 'partialdiff': 476,
  8289. 'ydieresis': 444,
  8290. 'Nacute': 667,
  8291. 'icircumflex': 278,
  8292. 'Ecircumflex': 611,
  8293. 'adieresis': 500,
  8294. 'edieresis': 444,
  8295. 'cacute': 444,
  8296. 'nacute': 500,
  8297. 'umacron': 500,
  8298. 'Ncaron': 667,
  8299. 'Iacute': 333,
  8300. 'plusminus': 675,
  8301. 'brokenbar': 275,
  8302. 'registered': 760,
  8303. 'Gbreve': 722,
  8304. 'Idotaccent': 333,
  8305. 'summation': 600,
  8306. 'Egrave': 611,
  8307. 'racute': 389,
  8308. 'omacron': 500,
  8309. 'Zacute': 556,
  8310. 'Zcaron': 556,
  8311. 'greaterequal': 549,
  8312. 'Eth': 722,
  8313. 'Ccedilla': 667,
  8314. 'lcommaaccent': 278,
  8315. 'tcaron': 300,
  8316. 'eogonek': 444,
  8317. 'Uogonek': 722,
  8318. 'Aacute': 611,
  8319. 'Adieresis': 611,
  8320. 'egrave': 444,
  8321. 'zacute': 389,
  8322. 'iogonek': 278,
  8323. 'Oacute': 722,
  8324. 'oacute': 500,
  8325. 'amacron': 500,
  8326. 'sacute': 389,
  8327. 'idieresis': 278,
  8328. 'Ocircumflex': 722,
  8329. 'Ugrave': 722,
  8330. 'Delta': 612,
  8331. 'thorn': 500,
  8332. 'twosuperior': 300,
  8333. 'Odieresis': 722,
  8334. 'mu': 500,
  8335. 'igrave': 278,
  8336. 'ohungarumlaut': 500,
  8337. 'Eogonek': 611,
  8338. 'dcroat': 500,
  8339. 'threequarters': 750,
  8340. 'Scedilla': 500,
  8341. 'lcaron': 300,
  8342. 'Kcommaaccent': 667,
  8343. 'Lacute': 556,
  8344. 'trademark': 980,
  8345. 'edotaccent': 444,
  8346. 'Igrave': 333,
  8347. 'Imacron': 333,
  8348. 'Lcaron': 611,
  8349. 'onehalf': 750,
  8350. 'lessequal': 549,
  8351. 'ocircumflex': 500,
  8352. 'ntilde': 500,
  8353. 'Uhungarumlaut': 722,
  8354. 'Eacute': 611,
  8355. 'emacron': 444,
  8356. 'gbreve': 500,
  8357. 'onequarter': 750,
  8358. 'Scaron': 500,
  8359. 'Scommaaccent': 500,
  8360. 'Ohungarumlaut': 722,
  8361. 'degree': 400,
  8362. 'ograve': 500,
  8363. 'Ccaron': 667,
  8364. 'ugrave': 500,
  8365. 'radical': 453,
  8366. 'Dcaron': 722,
  8367. 'rcommaaccent': 389,
  8368. 'Ntilde': 667,
  8369. 'otilde': 500,
  8370. 'Rcommaaccent': 611,
  8371. 'Lcommaaccent': 556,
  8372. 'Atilde': 611,
  8373. 'Aogonek': 611,
  8374. 'Aring': 611,
  8375. 'Otilde': 722,
  8376. 'zdotaccent': 389,
  8377. 'Ecaron': 611,
  8378. 'Iogonek': 333,
  8379. 'kcommaaccent': 444,
  8380. 'minus': 675,
  8381. 'Icircumflex': 333,
  8382. 'ncaron': 500,
  8383. 'tcommaaccent': 278,
  8384. 'logicalnot': 675,
  8385. 'odieresis': 500,
  8386. 'udieresis': 500,
  8387. 'notequal': 549,
  8388. 'gcommaaccent': 500,
  8389. 'eth': 500,
  8390. 'zcaron': 389,
  8391. 'ncommaaccent': 500,
  8392. 'onesuperior': 300,
  8393. 'imacron': 278,
  8394. 'Euro': 500
  8395. },
  8396. 'ZapfDingbats': {
  8397. 'space': 278,
  8398. 'a1': 974,
  8399. 'a2': 961,
  8400. 'a202': 974,
  8401. 'a3': 980,
  8402. 'a4': 719,
  8403. 'a5': 789,
  8404. 'a119': 790,
  8405. 'a118': 791,
  8406. 'a117': 690,
  8407. 'a11': 960,
  8408. 'a12': 939,
  8409. 'a13': 549,
  8410. 'a14': 855,
  8411. 'a15': 911,
  8412. 'a16': 933,
  8413. 'a105': 911,
  8414. 'a17': 945,
  8415. 'a18': 974,
  8416. 'a19': 755,
  8417. 'a20': 846,
  8418. 'a21': 762,
  8419. 'a22': 761,
  8420. 'a23': 571,
  8421. 'a24': 677,
  8422. 'a25': 763,
  8423. 'a26': 760,
  8424. 'a27': 759,
  8425. 'a28': 754,
  8426. 'a6': 494,
  8427. 'a7': 552,
  8428. 'a8': 537,
  8429. 'a9': 577,
  8430. 'a10': 692,
  8431. 'a29': 786,
  8432. 'a30': 788,
  8433. 'a31': 788,
  8434. 'a32': 790,
  8435. 'a33': 793,
  8436. 'a34': 794,
  8437. 'a35': 816,
  8438. 'a36': 823,
  8439. 'a37': 789,
  8440. 'a38': 841,
  8441. 'a39': 823,
  8442. 'a40': 833,
  8443. 'a41': 816,
  8444. 'a42': 831,
  8445. 'a43': 923,
  8446. 'a44': 744,
  8447. 'a45': 723,
  8448. 'a46': 749,
  8449. 'a47': 790,
  8450. 'a48': 792,
  8451. 'a49': 695,
  8452. 'a50': 776,
  8453. 'a51': 768,
  8454. 'a52': 792,
  8455. 'a53': 759,
  8456. 'a54': 707,
  8457. 'a55': 708,
  8458. 'a56': 682,
  8459. 'a57': 701,
  8460. 'a58': 826,
  8461. 'a59': 815,
  8462. 'a60': 789,
  8463. 'a61': 789,
  8464. 'a62': 707,
  8465. 'a63': 687,
  8466. 'a64': 696,
  8467. 'a65': 689,
  8468. 'a66': 786,
  8469. 'a67': 787,
  8470. 'a68': 713,
  8471. 'a69': 791,
  8472. 'a70': 785,
  8473. 'a71': 791,
  8474. 'a72': 873,
  8475. 'a73': 761,
  8476. 'a74': 762,
  8477. 'a203': 762,
  8478. 'a75': 759,
  8479. 'a204': 759,
  8480. 'a76': 892,
  8481. 'a77': 892,
  8482. 'a78': 788,
  8483. 'a79': 784,
  8484. 'a81': 438,
  8485. 'a82': 138,
  8486. 'a83': 277,
  8487. 'a84': 415,
  8488. 'a97': 392,
  8489. 'a98': 392,
  8490. 'a99': 668,
  8491. 'a100': 668,
  8492. 'a89': 390,
  8493. 'a90': 390,
  8494. 'a93': 317,
  8495. 'a94': 317,
  8496. 'a91': 276,
  8497. 'a92': 276,
  8498. 'a205': 509,
  8499. 'a85': 509,
  8500. 'a206': 410,
  8501. 'a86': 410,
  8502. 'a87': 234,
  8503. 'a88': 234,
  8504. 'a95': 334,
  8505. 'a96': 334,
  8506. 'a101': 732,
  8507. 'a102': 544,
  8508. 'a103': 544,
  8509. 'a104': 910,
  8510. 'a106': 667,
  8511. 'a107': 760,
  8512. 'a108': 760,
  8513. 'a112': 776,
  8514. 'a111': 595,
  8515. 'a110': 694,
  8516. 'a109': 626,
  8517. 'a120': 788,
  8518. 'a121': 788,
  8519. 'a122': 788,
  8520. 'a123': 788,
  8521. 'a124': 788,
  8522. 'a125': 788,
  8523. 'a126': 788,
  8524. 'a127': 788,
  8525. 'a128': 788,
  8526. 'a129': 788,
  8527. 'a130': 788,
  8528. 'a131': 788,
  8529. 'a132': 788,
  8530. 'a133': 788,
  8531. 'a134': 788,
  8532. 'a135': 788,
  8533. 'a136': 788,
  8534. 'a137': 788,
  8535. 'a138': 788,
  8536. 'a139': 788,
  8537. 'a140': 788,
  8538. 'a141': 788,
  8539. 'a142': 788,
  8540. 'a143': 788,
  8541. 'a144': 788,
  8542. 'a145': 788,
  8543. 'a146': 788,
  8544. 'a147': 788,
  8545. 'a148': 788,
  8546. 'a149': 788,
  8547. 'a150': 788,
  8548. 'a151': 788,
  8549. 'a152': 788,
  8550. 'a153': 788,
  8551. 'a154': 788,
  8552. 'a155': 788,
  8553. 'a156': 788,
  8554. 'a157': 788,
  8555. 'a158': 788,
  8556. 'a159': 788,
  8557. 'a160': 894,
  8558. 'a161': 838,
  8559. 'a163': 1016,
  8560. 'a164': 458,
  8561. 'a196': 748,
  8562. 'a165': 924,
  8563. 'a192': 748,
  8564. 'a166': 918,
  8565. 'a167': 927,
  8566. 'a168': 928,
  8567. 'a169': 928,
  8568. 'a170': 834,
  8569. 'a171': 873,
  8570. 'a172': 828,
  8571. 'a173': 924,
  8572. 'a162': 924,
  8573. 'a174': 917,
  8574. 'a175': 930,
  8575. 'a176': 931,
  8576. 'a177': 463,
  8577. 'a178': 883,
  8578. 'a179': 836,
  8579. 'a193': 836,
  8580. 'a180': 867,
  8581. 'a199': 867,
  8582. 'a181': 696,
  8583. 'a200': 696,
  8584. 'a182': 874,
  8585. 'a201': 874,
  8586. 'a183': 760,
  8587. 'a184': 946,
  8588. 'a197': 771,
  8589. 'a185': 865,
  8590. 'a194': 771,
  8591. 'a198': 888,
  8592. 'a186': 967,
  8593. 'a195': 888,
  8594. 'a187': 831,
  8595. 'a188': 873,
  8596. 'a189': 927,
  8597. 'a190': 970,
  8598. 'a191': 918
  8599. }
  8600. };
  8601. exports.Metrics = Metrics;
  8602. }));
  8603. var NetworkManager = (function NetworkManagerClosure() {
  8604. var OK_RESPONSE = 200;
  8605. var PARTIAL_CONTENT_RESPONSE = 206;
  8606. function NetworkManager(url, args) {
  8607. this.url = url;
  8608. args = args || {};
  8609. this.isHttp = /^https?:/i.test(url);
  8610. this.httpHeaders = (this.isHttp && args.httpHeaders) || {};
  8611. this.withCredentials = args.withCredentials || false;
  8612. this.getXhr = args.getXhr ||
  8613. function NetworkManager_getXhr() {
  8614. return new XMLHttpRequest();
  8615. };
  8616. this.currXhrId = 0;
  8617. this.pendingRequests = {};
  8618. this.loadedRequests = {};
  8619. }
  8620. function getArrayBuffer(xhr) {
  8621. var data = xhr.response;
  8622. if (typeof data !== 'string') {
  8623. return data;
  8624. }
  8625. var length = data.length;
  8626. var array = new Uint8Array(length);
  8627. for (var i = 0; i < length; i++) {
  8628. array[i] = data.charCodeAt(i) & 0xFF;
  8629. }
  8630. return array.buffer;
  8631. }
  8632. var supportsMozChunked = (function supportsMozChunkedClosure() {
  8633. try {
  8634. var x = new XMLHttpRequest();
  8635. // Firefox 37- required .open() to be called before setting responseType.
  8636. // https://bugzilla.mozilla.org/show_bug.cgi?id=707484
  8637. // Even though the URL is not visited, .open() could fail if the URL is
  8638. // blocked, e.g. via the connect-src CSP directive or the NoScript addon.
  8639. // When this error occurs, this feature detection method will mistakenly
  8640. // report that moz-chunked-arraybuffer is not supported in Firefox 37-.
  8641. x.open('GET', 'https://example.com');
  8642. x.responseType = 'moz-chunked-arraybuffer';
  8643. return x.responseType === 'moz-chunked-arraybuffer';
  8644. } catch (e) {
  8645. return false;
  8646. }
  8647. })();
  8648. NetworkManager.prototype = {
  8649. requestRange: function NetworkManager_requestRange(begin, end, listeners) {
  8650. var args = {
  8651. begin: begin,
  8652. end: end
  8653. };
  8654. for (var prop in listeners) {
  8655. args[prop] = listeners[prop];
  8656. }
  8657. return this.request(args);
  8658. },
  8659. requestFull: function NetworkManager_requestFull(listeners) {
  8660. return this.request(listeners);
  8661. },
  8662. request: function NetworkManager_request(args) {
  8663. var xhr = this.getXhr();
  8664. var xhrId = this.currXhrId++;
  8665. var pendingRequest = this.pendingRequests[xhrId] = {
  8666. xhr: xhr
  8667. };
  8668. xhr.open('GET', this.url);
  8669. xhr.withCredentials = this.withCredentials;
  8670. for (var property in this.httpHeaders) {
  8671. var value = this.httpHeaders[property];
  8672. if (typeof value === 'undefined') {
  8673. continue;
  8674. }
  8675. xhr.setRequestHeader(property, value);
  8676. }
  8677. if (this.isHttp && 'begin' in args && 'end' in args) {
  8678. var rangeStr = args.begin + '-' + (args.end - 1);
  8679. xhr.setRequestHeader('Range', 'bytes=' + rangeStr);
  8680. pendingRequest.expectedStatus = 206;
  8681. } else {
  8682. pendingRequest.expectedStatus = 200;
  8683. }
  8684. var useMozChunkedLoading = supportsMozChunked && !!args.onProgressiveData;
  8685. if (useMozChunkedLoading) {
  8686. xhr.responseType = 'moz-chunked-arraybuffer';
  8687. pendingRequest.onProgressiveData = args.onProgressiveData;
  8688. pendingRequest.mozChunked = true;
  8689. } else {
  8690. xhr.responseType = 'arraybuffer';
  8691. }
  8692. if (args.onError) {
  8693. xhr.onerror = function(evt) {
  8694. args.onError(xhr.status);
  8695. };
  8696. }
  8697. xhr.onreadystatechange = this.onStateChange.bind(this, xhrId);
  8698. xhr.onprogress = this.onProgress.bind(this, xhrId);
  8699. pendingRequest.onHeadersReceived = args.onHeadersReceived;
  8700. pendingRequest.onDone = args.onDone;
  8701. pendingRequest.onError = args.onError;
  8702. pendingRequest.onProgress = args.onProgress;
  8703. xhr.send(null);
  8704. return xhrId;
  8705. },
  8706. onProgress: function NetworkManager_onProgress(xhrId, evt) {
  8707. var pendingRequest = this.pendingRequests[xhrId];
  8708. if (!pendingRequest) {
  8709. // Maybe abortRequest was called...
  8710. return;
  8711. }
  8712. if (pendingRequest.mozChunked) {
  8713. var chunk = getArrayBuffer(pendingRequest.xhr);
  8714. pendingRequest.onProgressiveData(chunk);
  8715. }
  8716. var onProgress = pendingRequest.onProgress;
  8717. if (onProgress) {
  8718. onProgress(evt);
  8719. }
  8720. },
  8721. onStateChange: function NetworkManager_onStateChange(xhrId, evt) {
  8722. var pendingRequest = this.pendingRequests[xhrId];
  8723. if (!pendingRequest) {
  8724. // Maybe abortRequest was called...
  8725. return;
  8726. }
  8727. var xhr = pendingRequest.xhr;
  8728. if (xhr.readyState >= 2 && pendingRequest.onHeadersReceived) {
  8729. pendingRequest.onHeadersReceived();
  8730. delete pendingRequest.onHeadersReceived;
  8731. }
  8732. if (xhr.readyState !== 4) {
  8733. return;
  8734. }
  8735. if (!(xhrId in this.pendingRequests)) {
  8736. // The XHR request might have been aborted in onHeadersReceived()
  8737. // callback, in which case we should abort request
  8738. return;
  8739. }
  8740. delete this.pendingRequests[xhrId];
  8741. // success status == 0 can be on ftp, file and other protocols
  8742. if (xhr.status === 0 && this.isHttp) {
  8743. if (pendingRequest.onError) {
  8744. pendingRequest.onError(xhr.status);
  8745. }
  8746. return;
  8747. }
  8748. var xhrStatus = xhr.status || OK_RESPONSE;
  8749. // From http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35.2:
  8750. // "A server MAY ignore the Range header". This means it's possible to
  8751. // get a 200 rather than a 206 response from a range request.
  8752. var ok_response_on_range_request =
  8753. xhrStatus === OK_RESPONSE &&
  8754. pendingRequest.expectedStatus === PARTIAL_CONTENT_RESPONSE;
  8755. if (!ok_response_on_range_request &&
  8756. xhrStatus !== pendingRequest.expectedStatus) {
  8757. if (pendingRequest.onError) {
  8758. pendingRequest.onError(xhr.status);
  8759. }
  8760. return;
  8761. }
  8762. this.loadedRequests[xhrId] = true;
  8763. var chunk = getArrayBuffer(xhr);
  8764. if (xhrStatus === PARTIAL_CONTENT_RESPONSE) {
  8765. var rangeHeader = xhr.getResponseHeader('Content-Range');
  8766. var matches = /bytes (\d+)-(\d+)\/(\d+)/.exec(rangeHeader);
  8767. var begin = parseInt(matches[1], 10);
  8768. pendingRequest.onDone({
  8769. begin: begin,
  8770. chunk: chunk
  8771. });
  8772. } else if (pendingRequest.onProgressiveData) {
  8773. pendingRequest.onDone(null);
  8774. } else if (chunk) {
  8775. pendingRequest.onDone({
  8776. begin: 0,
  8777. chunk: chunk
  8778. });
  8779. } else if (pendingRequest.onError) {
  8780. pendingRequest.onError(xhr.status);
  8781. }
  8782. },
  8783. hasPendingRequests: function NetworkManager_hasPendingRequests() {
  8784. for (var xhrId in this.pendingRequests) {
  8785. return true;
  8786. }
  8787. return false;
  8788. },
  8789. getRequestXhr: function NetworkManager_getXhr(xhrId) {
  8790. return this.pendingRequests[xhrId].xhr;
  8791. },
  8792. isStreamingRequest: function NetworkManager_isStreamingRequest(xhrId) {
  8793. return !!(this.pendingRequests[xhrId].onProgressiveData);
  8794. },
  8795. isPendingRequest: function NetworkManager_isPendingRequest(xhrId) {
  8796. return xhrId in this.pendingRequests;
  8797. },
  8798. isLoadedRequest: function NetworkManager_isLoadedRequest(xhrId) {
  8799. return xhrId in this.loadedRequests;
  8800. },
  8801. abortAllRequests: function NetworkManager_abortAllRequests() {
  8802. for (var xhrId in this.pendingRequests) {
  8803. this.abortRequest(xhrId | 0);
  8804. }
  8805. },
  8806. abortRequest: function NetworkManager_abortRequest(xhrId) {
  8807. var xhr = this.pendingRequests[xhrId].xhr;
  8808. delete this.pendingRequests[xhrId];
  8809. xhr.abort();
  8810. }
  8811. };
  8812. return NetworkManager;
  8813. })();
  8814. (function (root, factory) {
  8815. {
  8816. factory((root.pdfjsCoreNetwork = {}));
  8817. }
  8818. }(this, function (exports) {
  8819. exports.NetworkManager = NetworkManager;
  8820. }));
  8821. (function (root, factory) {
  8822. {
  8823. factory((root.pdfjsSharedGlobal = {}));
  8824. }
  8825. }(this, function (exports) {
  8826. var globalScope = (typeof window !== 'undefined') ? window :
  8827. (typeof global !== 'undefined') ? global :
  8828. (typeof self !== 'undefined') ? self : this;
  8829. var isWorker = (typeof window === 'undefined');
  8830. // The global PDFJS object exposes the API
  8831. // In production, it will be declared outside a global wrapper
  8832. // In development, it will be declared here
  8833. if (!globalScope.PDFJS) {
  8834. globalScope.PDFJS = {};
  8835. }
  8836. globalScope.PDFJS.pdfBug = false;
  8837. exports.globalScope = globalScope;
  8838. exports.isWorker = isWorker;
  8839. exports.PDFJS = globalScope.PDFJS;
  8840. }));
  8841. (function (root, factory) {
  8842. {
  8843. factory((root.pdfjsCoreBidi = {}), root.pdfjsSharedGlobal);
  8844. }
  8845. }(this, function (exports, sharedGlobal) {
  8846. var PDFJS = sharedGlobal.PDFJS;
  8847. var bidi = PDFJS.bidi = (function bidiClosure() {
  8848. // Character types for symbols from 0000 to 00FF.
  8849. var baseTypes = [
  8850. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'S', 'B', 'S', 'WS',
  8851. 'B', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  8852. 'BN', 'BN', 'B', 'B', 'B', 'S', 'WS', 'ON', 'ON', 'ET', 'ET', 'ET', 'ON',
  8853. 'ON', 'ON', 'ON', 'ON', 'ON', 'CS', 'ON', 'CS', 'ON', 'EN', 'EN', 'EN',
  8854. 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'ON', 'ON', 'ON', 'ON', 'ON',
  8855. 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  8856. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'ON', 'ON',
  8857. 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  8858. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  8859. 'L', 'ON', 'ON', 'ON', 'ON', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'B', 'BN',
  8860. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  8861. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  8862. 'BN', 'CS', 'ON', 'ET', 'ET', 'ET', 'ET', 'ON', 'ON', 'ON', 'ON', 'L', 'ON',
  8863. 'ON', 'ON', 'ON', 'ON', 'ET', 'ET', 'EN', 'EN', 'ON', 'L', 'ON', 'ON', 'ON',
  8864. 'EN', 'L', 'ON', 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  8865. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  8866. 'L', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  8867. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  8868. 'L', 'L', 'L', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L'
  8869. ];
  8870. // Character types for symbols from 0600 to 06FF
  8871. var arabicTypes = [
  8872. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  8873. 'CS', 'AL', 'ON', 'ON', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL',
  8874. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  8875. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  8876. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  8877. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  8878. 'AL', 'AL', 'AL', 'AL', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM',
  8879. 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'AL', 'AL',
  8880. 'AL', 'AL', 'AL', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN',
  8881. 'AN', 'ET', 'AN', 'AN', 'AL', 'AL', 'AL', 'NSM', 'AL', 'AL', 'AL', 'AL',
  8882. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  8883. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  8884. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  8885. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  8886. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  8887. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  8888. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  8889. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  8890. 'AL', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM',
  8891. 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'ON', 'NSM',
  8892. 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  8893. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL'
  8894. ];
  8895. function isOdd(i) {
  8896. return (i & 1) !== 0;
  8897. }
  8898. function isEven(i) {
  8899. return (i & 1) === 0;
  8900. }
  8901. function findUnequal(arr, start, value) {
  8902. for (var j = start, jj = arr.length; j < jj; ++j) {
  8903. if (arr[j] !== value) {
  8904. return j;
  8905. }
  8906. }
  8907. return j;
  8908. }
  8909. function setValues(arr, start, end, value) {
  8910. for (var j = start; j < end; ++j) {
  8911. arr[j] = value;
  8912. }
  8913. }
  8914. function reverseValues(arr, start, end) {
  8915. for (var i = start, j = end - 1; i < j; ++i, --j) {
  8916. var temp = arr[i];
  8917. arr[i] = arr[j];
  8918. arr[j] = temp;
  8919. }
  8920. }
  8921. function createBidiText(str, isLTR, vertical) {
  8922. return {
  8923. str: str,
  8924. dir: (vertical ? 'ttb' : (isLTR ? 'ltr' : 'rtl'))
  8925. };
  8926. }
  8927. // These are used in bidi(), which is called frequently. We re-use them on
  8928. // each call to avoid unnecessary allocations.
  8929. var chars = [];
  8930. var types = [];
  8931. function bidi(str, startLevel, vertical) {
  8932. var isLTR = true;
  8933. var strLength = str.length;
  8934. if (strLength === 0 || vertical) {
  8935. return createBidiText(str, isLTR, vertical);
  8936. }
  8937. // Get types and fill arrays
  8938. chars.length = strLength;
  8939. types.length = strLength;
  8940. var numBidi = 0;
  8941. var i, ii;
  8942. for (i = 0; i < strLength; ++i) {
  8943. chars[i] = str.charAt(i);
  8944. var charCode = str.charCodeAt(i);
  8945. var charType = 'L';
  8946. if (charCode <= 0x00ff) {
  8947. charType = baseTypes[charCode];
  8948. } else if (0x0590 <= charCode && charCode <= 0x05f4) {
  8949. charType = 'R';
  8950. } else if (0x0600 <= charCode && charCode <= 0x06ff) {
  8951. charType = arabicTypes[charCode & 0xff];
  8952. } else if (0x0700 <= charCode && charCode <= 0x08AC) {
  8953. charType = 'AL';
  8954. }
  8955. if (charType === 'R' || charType === 'AL' || charType === 'AN') {
  8956. numBidi++;
  8957. }
  8958. types[i] = charType;
  8959. }
  8960. // Detect the bidi method
  8961. // - If there are no rtl characters then no bidi needed
  8962. // - If less than 30% chars are rtl then string is primarily ltr
  8963. // - If more than 30% chars are rtl then string is primarily rtl
  8964. if (numBidi === 0) {
  8965. isLTR = true;
  8966. return createBidiText(str, isLTR);
  8967. }
  8968. if (startLevel === -1) {
  8969. if ((strLength / numBidi) < 0.3) {
  8970. isLTR = true;
  8971. startLevel = 0;
  8972. } else {
  8973. isLTR = false;
  8974. startLevel = 1;
  8975. }
  8976. }
  8977. var levels = [];
  8978. for (i = 0; i < strLength; ++i) {
  8979. levels[i] = startLevel;
  8980. }
  8981. /*
  8982. X1-X10: skip most of this, since we are NOT doing the embeddings.
  8983. */
  8984. var e = (isOdd(startLevel) ? 'R' : 'L');
  8985. var sor = e;
  8986. var eor = sor;
  8987. /*
  8988. W1. Examine each non-spacing mark (NSM) in the level run, and change the
  8989. type of the NSM to the type of the previous character. If the NSM is at the
  8990. start of the level run, it will get the type of sor.
  8991. */
  8992. var lastType = sor;
  8993. for (i = 0; i < strLength; ++i) {
  8994. if (types[i] === 'NSM') {
  8995. types[i] = lastType;
  8996. } else {
  8997. lastType = types[i];
  8998. }
  8999. }
  9000. /*
  9001. W2. Search backwards from each instance of a European number until the
  9002. first strong type (R, L, AL, or sor) is found. If an AL is found, change
  9003. the type of the European number to Arabic number.
  9004. */
  9005. lastType = sor;
  9006. var t;
  9007. for (i = 0; i < strLength; ++i) {
  9008. t = types[i];
  9009. if (t === 'EN') {
  9010. types[i] = (lastType === 'AL') ? 'AN' : 'EN';
  9011. } else if (t === 'R' || t === 'L' || t === 'AL') {
  9012. lastType = t;
  9013. }
  9014. }
  9015. /*
  9016. W3. Change all ALs to R.
  9017. */
  9018. for (i = 0; i < strLength; ++i) {
  9019. t = types[i];
  9020. if (t === 'AL') {
  9021. types[i] = 'R';
  9022. }
  9023. }
  9024. /*
  9025. W4. A single European separator between two European numbers changes to a
  9026. European number. A single common separator between two numbers of the same
  9027. type changes to that type:
  9028. */
  9029. for (i = 1; i < strLength - 1; ++i) {
  9030. if (types[i] === 'ES' && types[i - 1] === 'EN' && types[i + 1] === 'EN') {
  9031. types[i] = 'EN';
  9032. }
  9033. if (types[i] === 'CS' &&
  9034. (types[i - 1] === 'EN' || types[i - 1] === 'AN') &&
  9035. types[i + 1] === types[i - 1]) {
  9036. types[i] = types[i - 1];
  9037. }
  9038. }
  9039. /*
  9040. W5. A sequence of European terminators adjacent to European numbers changes
  9041. to all European numbers:
  9042. */
  9043. for (i = 0; i < strLength; ++i) {
  9044. if (types[i] === 'EN') {
  9045. // do before
  9046. var j;
  9047. for (j = i - 1; j >= 0; --j) {
  9048. if (types[j] !== 'ET') {
  9049. break;
  9050. }
  9051. types[j] = 'EN';
  9052. }
  9053. // do after
  9054. for (j = i + 1; j < strLength; --j) {
  9055. if (types[j] !== 'ET') {
  9056. break;
  9057. }
  9058. types[j] = 'EN';
  9059. }
  9060. }
  9061. }
  9062. /*
  9063. W6. Otherwise, separators and terminators change to Other Neutral:
  9064. */
  9065. for (i = 0; i < strLength; ++i) {
  9066. t = types[i];
  9067. if (t === 'WS' || t === 'ES' || t === 'ET' || t === 'CS') {
  9068. types[i] = 'ON';
  9069. }
  9070. }
  9071. /*
  9072. W7. Search backwards from each instance of a European number until the
  9073. first strong type (R, L, or sor) is found. If an L is found, then change
  9074. the type of the European number to L.
  9075. */
  9076. lastType = sor;
  9077. for (i = 0; i < strLength; ++i) {
  9078. t = types[i];
  9079. if (t === 'EN') {
  9080. types[i] = ((lastType === 'L') ? 'L' : 'EN');
  9081. } else if (t === 'R' || t === 'L') {
  9082. lastType = t;
  9083. }
  9084. }
  9085. /*
  9086. N1. A sequence of neutrals takes the direction of the surrounding strong
  9087. text if the text on both sides has the same direction. European and Arabic
  9088. numbers are treated as though they were R. Start-of-level-run (sor) and
  9089. end-of-level-run (eor) are used at level run boundaries.
  9090. */
  9091. for (i = 0; i < strLength; ++i) {
  9092. if (types[i] === 'ON') {
  9093. var end = findUnequal(types, i + 1, 'ON');
  9094. var before = sor;
  9095. if (i > 0) {
  9096. before = types[i - 1];
  9097. }
  9098. var after = eor;
  9099. if (end + 1 < strLength) {
  9100. after = types[end + 1];
  9101. }
  9102. if (before !== 'L') {
  9103. before = 'R';
  9104. }
  9105. if (after !== 'L') {
  9106. after = 'R';
  9107. }
  9108. if (before === after) {
  9109. setValues(types, i, end, before);
  9110. }
  9111. i = end - 1; // reset to end (-1 so next iteration is ok)
  9112. }
  9113. }
  9114. /*
  9115. N2. Any remaining neutrals take the embedding direction.
  9116. */
  9117. for (i = 0; i < strLength; ++i) {
  9118. if (types[i] === 'ON') {
  9119. types[i] = e;
  9120. }
  9121. }
  9122. /*
  9123. I1. For all characters with an even (left-to-right) embedding direction,
  9124. those of type R go up one level and those of type AN or EN go up two
  9125. levels.
  9126. I2. For all characters with an odd (right-to-left) embedding direction,
  9127. those of type L, EN or AN go up one level.
  9128. */
  9129. for (i = 0; i < strLength; ++i) {
  9130. t = types[i];
  9131. if (isEven(levels[i])) {
  9132. if (t === 'R') {
  9133. levels[i] += 1;
  9134. } else if (t === 'AN' || t === 'EN') {
  9135. levels[i] += 2;
  9136. }
  9137. } else { // isOdd
  9138. if (t === 'L' || t === 'AN' || t === 'EN') {
  9139. levels[i] += 1;
  9140. }
  9141. }
  9142. }
  9143. /*
  9144. L1. On each line, reset the embedding level of the following characters to
  9145. the paragraph embedding level:
  9146. segment separators,
  9147. paragraph separators,
  9148. any sequence of whitespace characters preceding a segment separator or
  9149. paragraph separator, and any sequence of white space characters at the end
  9150. of the line.
  9151. */
  9152. // don't bother as text is only single line
  9153. /*
  9154. L2. From the highest level found in the text to the lowest odd level on
  9155. each line, reverse any contiguous sequence of characters that are at that
  9156. level or higher.
  9157. */
  9158. // find highest level & lowest odd level
  9159. var highestLevel = -1;
  9160. var lowestOddLevel = 99;
  9161. var level;
  9162. for (i = 0, ii = levels.length; i < ii; ++i) {
  9163. level = levels[i];
  9164. if (highestLevel < level) {
  9165. highestLevel = level;
  9166. }
  9167. if (lowestOddLevel > level && isOdd(level)) {
  9168. lowestOddLevel = level;
  9169. }
  9170. }
  9171. // now reverse between those limits
  9172. for (level = highestLevel; level >= lowestOddLevel; --level) {
  9173. // find segments to reverse
  9174. var start = -1;
  9175. for (i = 0, ii = levels.length; i < ii; ++i) {
  9176. if (levels[i] < level) {
  9177. if (start >= 0) {
  9178. reverseValues(chars, start, i);
  9179. start = -1;
  9180. }
  9181. } else if (start < 0) {
  9182. start = i;
  9183. }
  9184. }
  9185. if (start >= 0) {
  9186. reverseValues(chars, start, levels.length);
  9187. }
  9188. }
  9189. /*
  9190. L3. Combining marks applied to a right-to-left base character will at this
  9191. point precede their base character. If the rendering engine expects them to
  9192. follow the base characters in the final display process, then the ordering
  9193. of the marks and the base character must be reversed.
  9194. */
  9195. // don't bother for now
  9196. /*
  9197. L4. A character that possesses the mirrored property as specified by
  9198. Section 4.7, Mirrored, must be depicted by a mirrored glyph if the resolved
  9199. directionality of that character is R.
  9200. */
  9201. // don't mirror as characters are already mirrored in the pdf
  9202. // Finally, return string
  9203. for (i = 0, ii = chars.length; i < ii; ++i) {
  9204. var ch = chars[i];
  9205. if (ch === '<' || ch === '>') {
  9206. chars[i] = '';
  9207. }
  9208. }
  9209. return createBidiText(chars.join(''), isLTR);
  9210. }
  9211. return bidi;
  9212. })();
  9213. exports.bidi = bidi;
  9214. }));
  9215. (function (root, factory) {
  9216. {
  9217. factory((root.pdfjsSharedUtil = {}), root.pdfjsSharedGlobal);
  9218. }
  9219. }(this, function (exports, sharedGlobal) {
  9220. var PDFJS = sharedGlobal.PDFJS;
  9221. var globalScope = sharedGlobal.globalScope;
  9222. var FONT_IDENTITY_MATRIX = [0.001, 0, 0, 0.001, 0, 0];
  9223. var TextRenderingMode = {
  9224. FILL: 0,
  9225. STROKE: 1,
  9226. FILL_STROKE: 2,
  9227. INVISIBLE: 3,
  9228. FILL_ADD_TO_PATH: 4,
  9229. STROKE_ADD_TO_PATH: 5,
  9230. FILL_STROKE_ADD_TO_PATH: 6,
  9231. ADD_TO_PATH: 7,
  9232. FILL_STROKE_MASK: 3,
  9233. ADD_TO_PATH_FLAG: 4
  9234. };
  9235. var ImageKind = {
  9236. GRAYSCALE_1BPP: 1,
  9237. RGB_24BPP: 2,
  9238. RGBA_32BPP: 3
  9239. };
  9240. var AnnotationType = {
  9241. TEXT: 1,
  9242. LINK: 2,
  9243. FREETEXT: 3,
  9244. LINE: 4,
  9245. SQUARE: 5,
  9246. CIRCLE: 6,
  9247. POLYGON: 7,
  9248. POLYLINE: 8,
  9249. HIGHLIGHT: 9,
  9250. UNDERLINE: 10,
  9251. SQUIGGLY: 11,
  9252. STRIKEOUT: 12,
  9253. STAMP: 13,
  9254. CARET: 14,
  9255. INK: 15,
  9256. POPUP: 16,
  9257. FILEATTACHMENT: 17,
  9258. SOUND: 18,
  9259. MOVIE: 19,
  9260. WIDGET: 20,
  9261. SCREEN: 21,
  9262. PRINTERMARK: 22,
  9263. TRAPNET: 23,
  9264. WATERMARK: 24,
  9265. THREED: 25,
  9266. REDACT: 26
  9267. };
  9268. var AnnotationFlag = {
  9269. INVISIBLE: 0x01,
  9270. HIDDEN: 0x02,
  9271. PRINT: 0x04,
  9272. NOZOOM: 0x08,
  9273. NOROTATE: 0x10,
  9274. NOVIEW: 0x20,
  9275. READONLY: 0x40,
  9276. LOCKED: 0x80,
  9277. TOGGLENOVIEW: 0x100,
  9278. LOCKEDCONTENTS: 0x200
  9279. };
  9280. var AnnotationBorderStyleType = {
  9281. SOLID: 1,
  9282. DASHED: 2,
  9283. BEVELED: 3,
  9284. INSET: 4,
  9285. UNDERLINE: 5
  9286. };
  9287. var StreamType = {
  9288. UNKNOWN: 0,
  9289. FLATE: 1,
  9290. LZW: 2,
  9291. DCT: 3,
  9292. JPX: 4,
  9293. JBIG: 5,
  9294. A85: 6,
  9295. AHX: 7,
  9296. CCF: 8,
  9297. RL: 9
  9298. };
  9299. var FontType = {
  9300. UNKNOWN: 0,
  9301. TYPE1: 1,
  9302. TYPE1C: 2,
  9303. CIDFONTTYPE0: 3,
  9304. CIDFONTTYPE0C: 4,
  9305. TRUETYPE: 5,
  9306. CIDFONTTYPE2: 6,
  9307. TYPE3: 7,
  9308. OPENTYPE: 8,
  9309. TYPE0: 9,
  9310. MMTYPE1: 10
  9311. };
  9312. PDFJS.VERBOSITY_LEVELS = {
  9313. errors: 0,
  9314. warnings: 1,
  9315. infos: 5
  9316. };
  9317. // All the possible operations for an operator list.
  9318. var OPS = PDFJS.OPS = {
  9319. // Intentionally start from 1 so it is easy to spot bad operators that will be
  9320. // 0's.
  9321. dependency: 1,
  9322. setLineWidth: 2,
  9323. setLineCap: 3,
  9324. setLineJoin: 4,
  9325. setMiterLimit: 5,
  9326. setDash: 6,
  9327. setRenderingIntent: 7,
  9328. setFlatness: 8,
  9329. setGState: 9,
  9330. save: 10,
  9331. restore: 11,
  9332. transform: 12,
  9333. moveTo: 13,
  9334. lineTo: 14,
  9335. curveTo: 15,
  9336. curveTo2: 16,
  9337. curveTo3: 17,
  9338. closePath: 18,
  9339. rectangle: 19,
  9340. stroke: 20,
  9341. closeStroke: 21,
  9342. fill: 22,
  9343. eoFill: 23,
  9344. fillStroke: 24,
  9345. eoFillStroke: 25,
  9346. closeFillStroke: 26,
  9347. closeEOFillStroke: 27,
  9348. endPath: 28,
  9349. clip: 29,
  9350. eoClip: 30,
  9351. beginText: 31,
  9352. endText: 32,
  9353. setCharSpacing: 33,
  9354. setWordSpacing: 34,
  9355. setHScale: 35,
  9356. setLeading: 36,
  9357. setFont: 37,
  9358. setTextRenderingMode: 38,
  9359. setTextRise: 39,
  9360. moveText: 40,
  9361. setLeadingMoveText: 41,
  9362. setTextMatrix: 42,
  9363. nextLine: 43,
  9364. showText: 44,
  9365. showSpacedText: 45,
  9366. nextLineShowText: 46,
  9367. nextLineSetSpacingShowText: 47,
  9368. setCharWidth: 48,
  9369. setCharWidthAndBounds: 49,
  9370. setStrokeColorSpace: 50,
  9371. setFillColorSpace: 51,
  9372. setStrokeColor: 52,
  9373. setStrokeColorN: 53,
  9374. setFillColor: 54,
  9375. setFillColorN: 55,
  9376. setStrokeGray: 56,
  9377. setFillGray: 57,
  9378. setStrokeRGBColor: 58,
  9379. setFillRGBColor: 59,
  9380. setStrokeCMYKColor: 60,
  9381. setFillCMYKColor: 61,
  9382. shadingFill: 62,
  9383. beginInlineImage: 63,
  9384. beginImageData: 64,
  9385. endInlineImage: 65,
  9386. paintXObject: 66,
  9387. markPoint: 67,
  9388. markPointProps: 68,
  9389. beginMarkedContent: 69,
  9390. beginMarkedContentProps: 70,
  9391. endMarkedContent: 71,
  9392. beginCompat: 72,
  9393. endCompat: 73,
  9394. paintFormXObjectBegin: 74,
  9395. paintFormXObjectEnd: 75,
  9396. beginGroup: 76,
  9397. endGroup: 77,
  9398. beginAnnotations: 78,
  9399. endAnnotations: 79,
  9400. beginAnnotation: 80,
  9401. endAnnotation: 81,
  9402. paintJpegXObject: 82,
  9403. paintImageMaskXObject: 83,
  9404. paintImageMaskXObjectGroup: 84,
  9405. paintImageXObject: 85,
  9406. paintInlineImageXObject: 86,
  9407. paintInlineImageXObjectGroup: 87,
  9408. paintImageXObjectRepeat: 88,
  9409. paintImageMaskXObjectRepeat: 89,
  9410. paintSolidColorImageMask: 90,
  9411. constructPath: 91
  9412. };
  9413. // A notice for devs. These are good for things that are helpful to devs, such
  9414. // as warning that Workers were disabled, which is important to devs but not
  9415. // end users.
  9416. function info(msg) {
  9417. if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.infos) {
  9418. console.log('Info: ' + msg);
  9419. }
  9420. }
  9421. // Non-fatal warnings.
  9422. function warn(msg) {
  9423. if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.warnings) {
  9424. console.log('Warning: ' + msg);
  9425. }
  9426. }
  9427. // Deprecated API function -- treated as warnings.
  9428. function deprecated(details) {
  9429. warn('Deprecated API usage: ' + details);
  9430. }
  9431. // Fatal errors that should trigger the fallback UI and halt execution by
  9432. // throwing an exception.
  9433. function error(msg) {
  9434. if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.errors) {
  9435. console.log('Error: ' + msg);
  9436. console.log(backtrace());
  9437. }
  9438. throw new Error(msg);
  9439. }
  9440. function backtrace() {
  9441. try {
  9442. throw new Error();
  9443. } catch (e) {
  9444. return e.stack ? e.stack.split('\n').slice(2).join('\n') : '';
  9445. }
  9446. }
  9447. function assert(cond, msg) {
  9448. if (!cond) {
  9449. error(msg);
  9450. }
  9451. }
  9452. var UNSUPPORTED_FEATURES = PDFJS.UNSUPPORTED_FEATURES = {
  9453. unknown: 'unknown',
  9454. forms: 'forms',
  9455. javaScript: 'javaScript',
  9456. smask: 'smask',
  9457. shadingPattern: 'shadingPattern',
  9458. font: 'font'
  9459. };
  9460. // Combines two URLs. The baseUrl shall be absolute URL. If the url is an
  9461. // absolute URL, it will be returned as is.
  9462. function combineUrl(baseUrl, url) {
  9463. if (!url) {
  9464. return baseUrl;
  9465. }
  9466. if (/^[a-z][a-z0-9+\-.]*:/i.test(url)) {
  9467. return url;
  9468. }
  9469. var i;
  9470. if (url.charAt(0) === '/') {
  9471. // absolute path
  9472. i = baseUrl.indexOf('://');
  9473. if (url.charAt(1) === '/') {
  9474. ++i;
  9475. } else {
  9476. i = baseUrl.indexOf('/', i + 3);
  9477. }
  9478. return baseUrl.substring(0, i) + url;
  9479. } else {
  9480. // relative path
  9481. var pathLength = baseUrl.length;
  9482. i = baseUrl.lastIndexOf('#');
  9483. pathLength = i >= 0 ? i : pathLength;
  9484. i = baseUrl.lastIndexOf('?', pathLength);
  9485. pathLength = i >= 0 ? i : pathLength;
  9486. var prefixLength = baseUrl.lastIndexOf('/', pathLength);
  9487. return baseUrl.substring(0, prefixLength + 1) + url;
  9488. }
  9489. }
  9490. // Validates if URL is safe and allowed, e.g. to avoid XSS.
  9491. function isValidUrl(url, allowRelative) {
  9492. if (!url) {
  9493. return false;
  9494. }
  9495. // RFC 3986 (http://tools.ietf.org/html/rfc3986#section-3.1)
  9496. // scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
  9497. var protocol = /^[a-z][a-z0-9+\-.]*(?=:)/i.exec(url);
  9498. if (!protocol) {
  9499. return allowRelative;
  9500. }
  9501. protocol = protocol[0].toLowerCase();
  9502. switch (protocol) {
  9503. case 'http':
  9504. case 'https':
  9505. case 'ftp':
  9506. case 'mailto':
  9507. case 'tel':
  9508. return true;
  9509. default:
  9510. return false;
  9511. }
  9512. }
  9513. PDFJS.isValidUrl = isValidUrl;
  9514. function shadow(obj, prop, value) {
  9515. Object.defineProperty(obj, prop, { value: value,
  9516. enumerable: true,
  9517. configurable: true,
  9518. writable: false });
  9519. return value;
  9520. }
  9521. PDFJS.shadow = shadow;
  9522. var LinkTarget = PDFJS.LinkTarget = {
  9523. NONE: 0, // Default value.
  9524. SELF: 1,
  9525. BLANK: 2,
  9526. PARENT: 3,
  9527. TOP: 4,
  9528. };
  9529. var LinkTargetStringMap = [
  9530. '',
  9531. '_self',
  9532. '_blank',
  9533. '_parent',
  9534. '_top'
  9535. ];
  9536. function isExternalLinkTargetSet() {
  9537. if (PDFJS.openExternalLinksInNewWindow) {
  9538. deprecated('PDFJS.openExternalLinksInNewWindow, please use ' +
  9539. '"PDFJS.externalLinkTarget = PDFJS.LinkTarget.BLANK" instead.');
  9540. if (PDFJS.externalLinkTarget === LinkTarget.NONE) {
  9541. PDFJS.externalLinkTarget = LinkTarget.BLANK;
  9542. }
  9543. // Reset the deprecated parameter, to suppress further warnings.
  9544. PDFJS.openExternalLinksInNewWindow = false;
  9545. }
  9546. switch (PDFJS.externalLinkTarget) {
  9547. case LinkTarget.NONE:
  9548. return false;
  9549. case LinkTarget.SELF:
  9550. case LinkTarget.BLANK:
  9551. case LinkTarget.PARENT:
  9552. case LinkTarget.TOP:
  9553. return true;
  9554. }
  9555. warn('PDFJS.externalLinkTarget is invalid: ' + PDFJS.externalLinkTarget);
  9556. // Reset the external link target, to suppress further warnings.
  9557. PDFJS.externalLinkTarget = LinkTarget.NONE;
  9558. return false;
  9559. }
  9560. PDFJS.isExternalLinkTargetSet = isExternalLinkTargetSet;
  9561. var PasswordResponses = PDFJS.PasswordResponses = {
  9562. NEED_PASSWORD: 1,
  9563. INCORRECT_PASSWORD: 2
  9564. };
  9565. var PasswordException = (function PasswordExceptionClosure() {
  9566. function PasswordException(msg, code) {
  9567. this.name = 'PasswordException';
  9568. this.message = msg;
  9569. this.code = code;
  9570. }
  9571. PasswordException.prototype = new Error();
  9572. PasswordException.constructor = PasswordException;
  9573. return PasswordException;
  9574. })();
  9575. PDFJS.PasswordException = PasswordException;
  9576. var UnknownErrorException = (function UnknownErrorExceptionClosure() {
  9577. function UnknownErrorException(msg, details) {
  9578. this.name = 'UnknownErrorException';
  9579. this.message = msg;
  9580. this.details = details;
  9581. }
  9582. UnknownErrorException.prototype = new Error();
  9583. UnknownErrorException.constructor = UnknownErrorException;
  9584. return UnknownErrorException;
  9585. })();
  9586. PDFJS.UnknownErrorException = UnknownErrorException;
  9587. var InvalidPDFException = (function InvalidPDFExceptionClosure() {
  9588. function InvalidPDFException(msg) {
  9589. this.name = 'InvalidPDFException';
  9590. this.message = msg;
  9591. }
  9592. InvalidPDFException.prototype = new Error();
  9593. InvalidPDFException.constructor = InvalidPDFException;
  9594. return InvalidPDFException;
  9595. })();
  9596. PDFJS.InvalidPDFException = InvalidPDFException;
  9597. var MissingPDFException = (function MissingPDFExceptionClosure() {
  9598. function MissingPDFException(msg) {
  9599. this.name = 'MissingPDFException';
  9600. this.message = msg;
  9601. }
  9602. MissingPDFException.prototype = new Error();
  9603. MissingPDFException.constructor = MissingPDFException;
  9604. return MissingPDFException;
  9605. })();
  9606. PDFJS.MissingPDFException = MissingPDFException;
  9607. var UnexpectedResponseException =
  9608. (function UnexpectedResponseExceptionClosure() {
  9609. function UnexpectedResponseException(msg, status) {
  9610. this.name = 'UnexpectedResponseException';
  9611. this.message = msg;
  9612. this.status = status;
  9613. }
  9614. UnexpectedResponseException.prototype = new Error();
  9615. UnexpectedResponseException.constructor = UnexpectedResponseException;
  9616. return UnexpectedResponseException;
  9617. })();
  9618. PDFJS.UnexpectedResponseException = UnexpectedResponseException;
  9619. var NotImplementedException = (function NotImplementedExceptionClosure() {
  9620. function NotImplementedException(msg) {
  9621. this.message = msg;
  9622. }
  9623. NotImplementedException.prototype = new Error();
  9624. NotImplementedException.prototype.name = 'NotImplementedException';
  9625. NotImplementedException.constructor = NotImplementedException;
  9626. return NotImplementedException;
  9627. })();
  9628. var MissingDataException = (function MissingDataExceptionClosure() {
  9629. function MissingDataException(begin, end) {
  9630. this.begin = begin;
  9631. this.end = end;
  9632. this.message = 'Missing data [' + begin + ', ' + end + ')';
  9633. }
  9634. MissingDataException.prototype = new Error();
  9635. MissingDataException.prototype.name = 'MissingDataException';
  9636. MissingDataException.constructor = MissingDataException;
  9637. return MissingDataException;
  9638. })();
  9639. var XRefParseException = (function XRefParseExceptionClosure() {
  9640. function XRefParseException(msg) {
  9641. this.message = msg;
  9642. }
  9643. XRefParseException.prototype = new Error();
  9644. XRefParseException.prototype.name = 'XRefParseException';
  9645. XRefParseException.constructor = XRefParseException;
  9646. return XRefParseException;
  9647. })();
  9648. var NullCharactersRegExp = /\x00/g;
  9649. function removeNullCharacters(str) {
  9650. if (typeof str !== 'string') {
  9651. warn('The argument for removeNullCharacters must be a string.');
  9652. return str;
  9653. }
  9654. return str.replace(NullCharactersRegExp, '');
  9655. }
  9656. PDFJS.removeNullCharacters = removeNullCharacters;
  9657. function bytesToString(bytes) {
  9658. assert(bytes !== null && typeof bytes === 'object' &&
  9659. bytes.length !== undefined, 'Invalid argument for bytesToString');
  9660. var length = bytes.length;
  9661. var MAX_ARGUMENT_COUNT = 8192;
  9662. if (length < MAX_ARGUMENT_COUNT) {
  9663. return String.fromCharCode.apply(null, bytes);
  9664. }
  9665. var strBuf = [];
  9666. for (var i = 0; i < length; i += MAX_ARGUMENT_COUNT) {
  9667. var chunkEnd = Math.min(i + MAX_ARGUMENT_COUNT, length);
  9668. var chunk = bytes.subarray(i, chunkEnd);
  9669. strBuf.push(String.fromCharCode.apply(null, chunk));
  9670. }
  9671. return strBuf.join('');
  9672. }
  9673. function stringToBytes(str) {
  9674. assert(typeof str === 'string', 'Invalid argument for stringToBytes');
  9675. var length = str.length;
  9676. var bytes = new Uint8Array(length);
  9677. for (var i = 0; i < length; ++i) {
  9678. bytes[i] = str.charCodeAt(i) & 0xFF;
  9679. }
  9680. return bytes;
  9681. }
  9682. function string32(value) {
  9683. return String.fromCharCode((value >> 24) & 0xff, (value >> 16) & 0xff,
  9684. (value >> 8) & 0xff, value & 0xff);
  9685. }
  9686. function log2(x) {
  9687. var n = 1, i = 0;
  9688. while (x > n) {
  9689. n <<= 1;
  9690. i++;
  9691. }
  9692. return i;
  9693. }
  9694. function readInt8(data, start) {
  9695. return (data[start] << 24) >> 24;
  9696. }
  9697. function readUint16(data, offset) {
  9698. return (data[offset] << 8) | data[offset + 1];
  9699. }
  9700. function readUint32(data, offset) {
  9701. return ((data[offset] << 24) | (data[offset + 1] << 16) |
  9702. (data[offset + 2] << 8) | data[offset + 3]) >>> 0;
  9703. }
  9704. // Lazy test the endianness of the platform
  9705. // NOTE: This will be 'true' for simulated TypedArrays
  9706. function isLittleEndian() {
  9707. var buffer8 = new Uint8Array(2);
  9708. buffer8[0] = 1;
  9709. var buffer16 = new Uint16Array(buffer8.buffer);
  9710. return (buffer16[0] === 1);
  9711. }
  9712. Object.defineProperty(PDFJS, 'isLittleEndian', {
  9713. configurable: true,
  9714. get: function PDFJS_isLittleEndian() {
  9715. return shadow(PDFJS, 'isLittleEndian', isLittleEndian());
  9716. }
  9717. });
  9718. // Lazy test if the userAgent support CanvasTypedArrays
  9719. function hasCanvasTypedArrays() {
  9720. var canvas = document.createElement('canvas');
  9721. canvas.width = canvas.height = 1;
  9722. var ctx = canvas.getContext('2d');
  9723. var imageData = ctx.createImageData(1, 1);
  9724. return (typeof imageData.data.buffer !== 'undefined');
  9725. }
  9726. Object.defineProperty(PDFJS, 'hasCanvasTypedArrays', {
  9727. configurable: true,
  9728. get: function PDFJS_hasCanvasTypedArrays() {
  9729. return shadow(PDFJS, 'hasCanvasTypedArrays', hasCanvasTypedArrays());
  9730. }
  9731. });
  9732. var Uint32ArrayView = (function Uint32ArrayViewClosure() {
  9733. function Uint32ArrayView(buffer, length) {
  9734. this.buffer = buffer;
  9735. this.byteLength = buffer.length;
  9736. this.length = length === undefined ? (this.byteLength >> 2) : length;
  9737. ensureUint32ArrayViewProps(this.length);
  9738. }
  9739. Uint32ArrayView.prototype = Object.create(null);
  9740. var uint32ArrayViewSetters = 0;
  9741. function createUint32ArrayProp(index) {
  9742. return {
  9743. get: function () {
  9744. var buffer = this.buffer, offset = index << 2;
  9745. return (buffer[offset] | (buffer[offset + 1] << 8) |
  9746. (buffer[offset + 2] << 16) | (buffer[offset + 3] << 24)) >>> 0;
  9747. },
  9748. set: function (value) {
  9749. var buffer = this.buffer, offset = index << 2;
  9750. buffer[offset] = value & 255;
  9751. buffer[offset + 1] = (value >> 8) & 255;
  9752. buffer[offset + 2] = (value >> 16) & 255;
  9753. buffer[offset + 3] = (value >>> 24) & 255;
  9754. }
  9755. };
  9756. }
  9757. function ensureUint32ArrayViewProps(length) {
  9758. while (uint32ArrayViewSetters < length) {
  9759. Object.defineProperty(Uint32ArrayView.prototype,
  9760. uint32ArrayViewSetters,
  9761. createUint32ArrayProp(uint32ArrayViewSetters));
  9762. uint32ArrayViewSetters++;
  9763. }
  9764. }
  9765. return Uint32ArrayView;
  9766. })();
  9767. exports.Uint32ArrayView = Uint32ArrayView;
  9768. var IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0];
  9769. var Util = PDFJS.Util = (function UtilClosure() {
  9770. function Util() {}
  9771. var rgbBuf = ['rgb(', 0, ',', 0, ',', 0, ')'];
  9772. // makeCssRgb() can be called thousands of times. Using |rgbBuf| avoids
  9773. // creating many intermediate strings.
  9774. Util.makeCssRgb = function Util_makeCssRgb(r, g, b) {
  9775. rgbBuf[1] = r;
  9776. rgbBuf[3] = g;
  9777. rgbBuf[5] = b;
  9778. return rgbBuf.join('');
  9779. };
  9780. // Concatenates two transformation matrices together and returns the result.
  9781. Util.transform = function Util_transform(m1, m2) {
  9782. return [
  9783. m1[0] * m2[0] + m1[2] * m2[1],
  9784. m1[1] * m2[0] + m1[3] * m2[1],
  9785. m1[0] * m2[2] + m1[2] * m2[3],
  9786. m1[1] * m2[2] + m1[3] * m2[3],
  9787. m1[0] * m2[4] + m1[2] * m2[5] + m1[4],
  9788. m1[1] * m2[4] + m1[3] * m2[5] + m1[5]
  9789. ];
  9790. };
  9791. // For 2d affine transforms
  9792. Util.applyTransform = function Util_applyTransform(p, m) {
  9793. var xt = p[0] * m[0] + p[1] * m[2] + m[4];
  9794. var yt = p[0] * m[1] + p[1] * m[3] + m[5];
  9795. return [xt, yt];
  9796. };
  9797. Util.applyInverseTransform = function Util_applyInverseTransform(p, m) {
  9798. var d = m[0] * m[3] - m[1] * m[2];
  9799. var xt = (p[0] * m[3] - p[1] * m[2] + m[2] * m[5] - m[4] * m[3]) / d;
  9800. var yt = (-p[0] * m[1] + p[1] * m[0] + m[4] * m[1] - m[5] * m[0]) / d;
  9801. return [xt, yt];
  9802. };
  9803. // Applies the transform to the rectangle and finds the minimum axially
  9804. // aligned bounding box.
  9805. Util.getAxialAlignedBoundingBox =
  9806. function Util_getAxialAlignedBoundingBox(r, m) {
  9807. var p1 = Util.applyTransform(r, m);
  9808. var p2 = Util.applyTransform(r.slice(2, 4), m);
  9809. var p3 = Util.applyTransform([r[0], r[3]], m);
  9810. var p4 = Util.applyTransform([r[2], r[1]], m);
  9811. return [
  9812. Math.min(p1[0], p2[0], p3[0], p4[0]),
  9813. Math.min(p1[1], p2[1], p3[1], p4[1]),
  9814. Math.max(p1[0], p2[0], p3[0], p4[0]),
  9815. Math.max(p1[1], p2[1], p3[1], p4[1])
  9816. ];
  9817. };
  9818. Util.inverseTransform = function Util_inverseTransform(m) {
  9819. var d = m[0] * m[3] - m[1] * m[2];
  9820. return [m[3] / d, -m[1] / d, -m[2] / d, m[0] / d,
  9821. (m[2] * m[5] - m[4] * m[3]) / d, (m[4] * m[1] - m[5] * m[0]) / d];
  9822. };
  9823. // Apply a generic 3d matrix M on a 3-vector v:
  9824. // | a b c | | X |
  9825. // | d e f | x | Y |
  9826. // | g h i | | Z |
  9827. // M is assumed to be serialized as [a,b,c,d,e,f,g,h,i],
  9828. // with v as [X,Y,Z]
  9829. Util.apply3dTransform = function Util_apply3dTransform(m, v) {
  9830. return [
  9831. m[0] * v[0] + m[1] * v[1] + m[2] * v[2],
  9832. m[3] * v[0] + m[4] * v[1] + m[5] * v[2],
  9833. m[6] * v[0] + m[7] * v[1] + m[8] * v[2]
  9834. ];
  9835. };
  9836. // This calculation uses Singular Value Decomposition.
  9837. // The SVD can be represented with formula A = USV. We are interested in the
  9838. // matrix S here because it represents the scale values.
  9839. Util.singularValueDecompose2dScale =
  9840. function Util_singularValueDecompose2dScale(m) {
  9841. var transpose = [m[0], m[2], m[1], m[3]];
  9842. // Multiply matrix m with its transpose.
  9843. var a = m[0] * transpose[0] + m[1] * transpose[2];
  9844. var b = m[0] * transpose[1] + m[1] * transpose[3];
  9845. var c = m[2] * transpose[0] + m[3] * transpose[2];
  9846. var d = m[2] * transpose[1] + m[3] * transpose[3];
  9847. // Solve the second degree polynomial to get roots.
  9848. var first = (a + d) / 2;
  9849. var second = Math.sqrt((a + d) * (a + d) - 4 * (a * d - c * b)) / 2;
  9850. var sx = first + second || 1;
  9851. var sy = first - second || 1;
  9852. // Scale values are the square roots of the eigenvalues.
  9853. return [Math.sqrt(sx), Math.sqrt(sy)];
  9854. };
  9855. // Normalize rectangle rect=[x1, y1, x2, y2] so that (x1,y1) < (x2,y2)
  9856. // For coordinate systems whose origin lies in the bottom-left, this
  9857. // means normalization to (BL,TR) ordering. For systems with origin in the
  9858. // top-left, this means (TL,BR) ordering.
  9859. Util.normalizeRect = function Util_normalizeRect(rect) {
  9860. var r = rect.slice(0); // clone rect
  9861. if (rect[0] > rect[2]) {
  9862. r[0] = rect[2];
  9863. r[2] = rect[0];
  9864. }
  9865. if (rect[1] > rect[3]) {
  9866. r[1] = rect[3];
  9867. r[3] = rect[1];
  9868. }
  9869. return r;
  9870. };
  9871. // Returns a rectangle [x1, y1, x2, y2] corresponding to the
  9872. // intersection of rect1 and rect2. If no intersection, returns 'false'
  9873. // The rectangle coordinates of rect1, rect2 should be [x1, y1, x2, y2]
  9874. Util.intersect = function Util_intersect(rect1, rect2) {
  9875. function compare(a, b) {
  9876. return a - b;
  9877. }
  9878. // Order points along the axes
  9879. var orderedX = [rect1[0], rect1[2], rect2[0], rect2[2]].sort(compare),
  9880. orderedY = [rect1[1], rect1[3], rect2[1], rect2[3]].sort(compare),
  9881. result = [];
  9882. rect1 = Util.normalizeRect(rect1);
  9883. rect2 = Util.normalizeRect(rect2);
  9884. // X: first and second points belong to different rectangles?
  9885. if ((orderedX[0] === rect1[0] && orderedX[1] === rect2[0]) ||
  9886. (orderedX[0] === rect2[0] && orderedX[1] === rect1[0])) {
  9887. // Intersection must be between second and third points
  9888. result[0] = orderedX[1];
  9889. result[2] = orderedX[2];
  9890. } else {
  9891. return false;
  9892. }
  9893. // Y: first and second points belong to different rectangles?
  9894. if ((orderedY[0] === rect1[1] && orderedY[1] === rect2[1]) ||
  9895. (orderedY[0] === rect2[1] && orderedY[1] === rect1[1])) {
  9896. // Intersection must be between second and third points
  9897. result[1] = orderedY[1];
  9898. result[3] = orderedY[2];
  9899. } else {
  9900. return false;
  9901. }
  9902. return result;
  9903. };
  9904. Util.sign = function Util_sign(num) {
  9905. return num < 0 ? -1 : 1;
  9906. };
  9907. Util.appendToArray = function Util_appendToArray(arr1, arr2) {
  9908. Array.prototype.push.apply(arr1, arr2);
  9909. };
  9910. Util.prependToArray = function Util_prependToArray(arr1, arr2) {
  9911. Array.prototype.unshift.apply(arr1, arr2);
  9912. };
  9913. Util.extendObj = function extendObj(obj1, obj2) {
  9914. for (var key in obj2) {
  9915. obj1[key] = obj2[key];
  9916. }
  9917. };
  9918. Util.getInheritableProperty = function Util_getInheritableProperty(dict,
  9919. name) {
  9920. while (dict && !dict.has(name)) {
  9921. dict = dict.get('Parent');
  9922. }
  9923. if (!dict) {
  9924. return null;
  9925. }
  9926. return dict.get(name);
  9927. };
  9928. Util.inherit = function Util_inherit(sub, base, prototype) {
  9929. sub.prototype = Object.create(base.prototype);
  9930. sub.prototype.constructor = sub;
  9931. for (var prop in prototype) {
  9932. sub.prototype[prop] = prototype[prop];
  9933. }
  9934. };
  9935. Util.loadScript = function Util_loadScript(src, callback) {
  9936. var script = document.createElement('script');
  9937. var loaded = false;
  9938. script.setAttribute('src', src);
  9939. if (callback) {
  9940. script.onload = function() {
  9941. if (!loaded) {
  9942. callback();
  9943. }
  9944. loaded = true;
  9945. };
  9946. }
  9947. document.getElementsByTagName('head')[0].appendChild(script);
  9948. };
  9949. return Util;
  9950. })();
  9951. /**
  9952. * PDF page viewport created based on scale, rotation and offset.
  9953. * @class
  9954. * @alias PDFJS.PageViewport
  9955. */
  9956. var PageViewport = PDFJS.PageViewport = (function PageViewportClosure() {
  9957. /**
  9958. * @constructor
  9959. * @private
  9960. * @param viewBox {Array} xMin, yMin, xMax and yMax coordinates.
  9961. * @param scale {number} scale of the viewport.
  9962. * @param rotation {number} rotations of the viewport in degrees.
  9963. * @param offsetX {number} offset X
  9964. * @param offsetY {number} offset Y
  9965. * @param dontFlip {boolean} if true, axis Y will not be flipped.
  9966. */
  9967. function PageViewport(viewBox, scale, rotation, offsetX, offsetY, dontFlip) {
  9968. this.viewBox = viewBox;
  9969. this.scale = scale;
  9970. this.rotation = rotation;
  9971. this.offsetX = offsetX;
  9972. this.offsetY = offsetY;
  9973. // creating transform to convert pdf coordinate system to the normal
  9974. // canvas like coordinates taking in account scale and rotation
  9975. var centerX = (viewBox[2] + viewBox[0]) / 2;
  9976. var centerY = (viewBox[3] + viewBox[1]) / 2;
  9977. var rotateA, rotateB, rotateC, rotateD;
  9978. rotation = rotation % 360;
  9979. rotation = rotation < 0 ? rotation + 360 : rotation;
  9980. switch (rotation) {
  9981. case 180:
  9982. rotateA = -1; rotateB = 0; rotateC = 0; rotateD = 1;
  9983. break;
  9984. case 90:
  9985. rotateA = 0; rotateB = 1; rotateC = 1; rotateD = 0;
  9986. break;
  9987. case 270:
  9988. rotateA = 0; rotateB = -1; rotateC = -1; rotateD = 0;
  9989. break;
  9990. //case 0:
  9991. default:
  9992. rotateA = 1; rotateB = 0; rotateC = 0; rotateD = -1;
  9993. break;
  9994. }
  9995. if (dontFlip) {
  9996. rotateC = -rotateC; rotateD = -rotateD;
  9997. }
  9998. var offsetCanvasX, offsetCanvasY;
  9999. var width, height;
  10000. if (rotateA === 0) {
  10001. offsetCanvasX = Math.abs(centerY - viewBox[1]) * scale + offsetX;
  10002. offsetCanvasY = Math.abs(centerX - viewBox[0]) * scale + offsetY;
  10003. width = Math.abs(viewBox[3] - viewBox[1]) * scale;
  10004. height = Math.abs(viewBox[2] - viewBox[0]) * scale;
  10005. } else {
  10006. offsetCanvasX = Math.abs(centerX - viewBox[0]) * scale + offsetX;
  10007. offsetCanvasY = Math.abs(centerY - viewBox[1]) * scale + offsetY;
  10008. width = Math.abs(viewBox[2] - viewBox[0]) * scale;
  10009. height = Math.abs(viewBox[3] - viewBox[1]) * scale;
  10010. }
  10011. // creating transform for the following operations:
  10012. // translate(-centerX, -centerY), rotate and flip vertically,
  10013. // scale, and translate(offsetCanvasX, offsetCanvasY)
  10014. this.transform = [
  10015. rotateA * scale,
  10016. rotateB * scale,
  10017. rotateC * scale,
  10018. rotateD * scale,
  10019. offsetCanvasX - rotateA * scale * centerX - rotateC * scale * centerY,
  10020. offsetCanvasY - rotateB * scale * centerX - rotateD * scale * centerY
  10021. ];
  10022. this.width = width;
  10023. this.height = height;
  10024. this.fontScale = scale;
  10025. }
  10026. PageViewport.prototype = /** @lends PDFJS.PageViewport.prototype */ {
  10027. /**
  10028. * Clones viewport with additional properties.
  10029. * @param args {Object} (optional) If specified, may contain the 'scale' or
  10030. * 'rotation' properties to override the corresponding properties in
  10031. * the cloned viewport.
  10032. * @returns {PDFJS.PageViewport} Cloned viewport.
  10033. */
  10034. clone: function PageViewPort_clone(args) {
  10035. args = args || {};
  10036. var scale = 'scale' in args ? args.scale : this.scale;
  10037. var rotation = 'rotation' in args ? args.rotation : this.rotation;
  10038. return new PageViewport(this.viewBox.slice(), scale, rotation,
  10039. this.offsetX, this.offsetY, args.dontFlip);
  10040. },
  10041. /**
  10042. * Converts PDF point to the viewport coordinates. For examples, useful for
  10043. * converting PDF location into canvas pixel coordinates.
  10044. * @param x {number} X coordinate.
  10045. * @param y {number} Y coordinate.
  10046. * @returns {Object} Object that contains 'x' and 'y' properties of the
  10047. * point in the viewport coordinate space.
  10048. * @see {@link convertToPdfPoint}
  10049. * @see {@link convertToViewportRectangle}
  10050. */
  10051. convertToViewportPoint: function PageViewport_convertToViewportPoint(x, y) {
  10052. return Util.applyTransform([x, y], this.transform);
  10053. },
  10054. /**
  10055. * Converts PDF rectangle to the viewport coordinates.
  10056. * @param rect {Array} xMin, yMin, xMax and yMax coordinates.
  10057. * @returns {Array} Contains corresponding coordinates of the rectangle
  10058. * in the viewport coordinate space.
  10059. * @see {@link convertToViewportPoint}
  10060. */
  10061. convertToViewportRectangle:
  10062. function PageViewport_convertToViewportRectangle(rect) {
  10063. var tl = Util.applyTransform([rect[0], rect[1]], this.transform);
  10064. var br = Util.applyTransform([rect[2], rect[3]], this.transform);
  10065. return [tl[0], tl[1], br[0], br[1]];
  10066. },
  10067. /**
  10068. * Converts viewport coordinates to the PDF location. For examples, useful
  10069. * for converting canvas pixel location into PDF one.
  10070. * @param x {number} X coordinate.
  10071. * @param y {number} Y coordinate.
  10072. * @returns {Object} Object that contains 'x' and 'y' properties of the
  10073. * point in the PDF coordinate space.
  10074. * @see {@link convertToViewportPoint}
  10075. */
  10076. convertToPdfPoint: function PageViewport_convertToPdfPoint(x, y) {
  10077. return Util.applyInverseTransform([x, y], this.transform);
  10078. }
  10079. };
  10080. return PageViewport;
  10081. })();
  10082. var PDFStringTranslateTable = [
  10083. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10084. 0x2D8, 0x2C7, 0x2C6, 0x2D9, 0x2DD, 0x2DB, 0x2DA, 0x2DC, 0, 0, 0, 0, 0, 0, 0,
  10085. 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,
  10086. 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,
  10087. 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,
  10088. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x2022, 0x2020, 0x2021, 0x2026, 0x2014,
  10089. 0x2013, 0x192, 0x2044, 0x2039, 0x203A, 0x2212, 0x2030, 0x201E, 0x201C,
  10090. 0x201D, 0x2018, 0x2019, 0x201A, 0x2122, 0xFB01, 0xFB02, 0x141, 0x152, 0x160,
  10091. 0x178, 0x17D, 0x131, 0x142, 0x153, 0x161, 0x17E, 0, 0x20AC
  10092. ];
  10093. function stringToPDFString(str) {
  10094. var i, n = str.length, strBuf = [];
  10095. if (str[0] === '\xFE' && str[1] === '\xFF') {
  10096. // UTF16BE BOM
  10097. for (i = 2; i < n; i += 2) {
  10098. strBuf.push(String.fromCharCode(
  10099. (str.charCodeAt(i) << 8) | str.charCodeAt(i + 1)));
  10100. }
  10101. } else {
  10102. for (i = 0; i < n; ++i) {
  10103. var code = PDFStringTranslateTable[str.charCodeAt(i)];
  10104. strBuf.push(code ? String.fromCharCode(code) : str.charAt(i));
  10105. }
  10106. }
  10107. return strBuf.join('');
  10108. }
  10109. function stringToUTF8String(str) {
  10110. return decodeURIComponent(escape(str));
  10111. }
  10112. function utf8StringToString(str) {
  10113. return unescape(encodeURIComponent(str));
  10114. }
  10115. function isEmptyObj(obj) {
  10116. for (var key in obj) {
  10117. return false;
  10118. }
  10119. return true;
  10120. }
  10121. function isBool(v) {
  10122. return typeof v === 'boolean';
  10123. }
  10124. function isInt(v) {
  10125. return typeof v === 'number' && ((v | 0) === v);
  10126. }
  10127. function isNum(v) {
  10128. return typeof v === 'number';
  10129. }
  10130. function isString(v) {
  10131. return typeof v === 'string';
  10132. }
  10133. function isArray(v) {
  10134. return v instanceof Array;
  10135. }
  10136. function isArrayBuffer(v) {
  10137. return typeof v === 'object' && v !== null && v.byteLength !== undefined;
  10138. }
  10139. /**
  10140. * Promise Capability object.
  10141. *
  10142. * @typedef {Object} PromiseCapability
  10143. * @property {Promise} promise - A promise object.
  10144. * @property {function} resolve - Fullfills the promise.
  10145. * @property {function} reject - Rejects the promise.
  10146. */
  10147. /**
  10148. * Creates a promise capability object.
  10149. * @alias PDFJS.createPromiseCapability
  10150. *
  10151. * @return {PromiseCapability} A capability object contains:
  10152. * - a Promise, resolve and reject methods.
  10153. */
  10154. function createPromiseCapability() {
  10155. var capability = {};
  10156. capability.promise = new Promise(function (resolve, reject) {
  10157. capability.resolve = resolve;
  10158. capability.reject = reject;
  10159. });
  10160. return capability;
  10161. }
  10162. PDFJS.createPromiseCapability = createPromiseCapability;
  10163. /**
  10164. * Polyfill for Promises:
  10165. * The following promise implementation tries to generally implement the
  10166. * Promise/A+ spec. Some notable differences from other promise libaries are:
  10167. * - There currently isn't a seperate deferred and promise object.
  10168. * - Unhandled rejections eventually show an error if they aren't handled.
  10169. *
  10170. * Based off of the work in:
  10171. * https://bugzilla.mozilla.org/show_bug.cgi?id=810490
  10172. */
  10173. (function PromiseClosure() {
  10174. if (globalScope.Promise) {
  10175. // Promises existing in the DOM/Worker, checking presence of all/resolve
  10176. if (typeof globalScope.Promise.all !== 'function') {
  10177. globalScope.Promise.all = function (iterable) {
  10178. var count = 0, results = [], resolve, reject;
  10179. var promise = new globalScope.Promise(function (resolve_, reject_) {
  10180. resolve = resolve_;
  10181. reject = reject_;
  10182. });
  10183. iterable.forEach(function (p, i) {
  10184. count++;
  10185. p.then(function (result) {
  10186. results[i] = result;
  10187. count--;
  10188. if (count === 0) {
  10189. resolve(results);
  10190. }
  10191. }, reject);
  10192. });
  10193. if (count === 0) {
  10194. resolve(results);
  10195. }
  10196. return promise;
  10197. };
  10198. }
  10199. if (typeof globalScope.Promise.resolve !== 'function') {
  10200. globalScope.Promise.resolve = function (value) {
  10201. return new globalScope.Promise(function (resolve) { resolve(value); });
  10202. };
  10203. }
  10204. if (typeof globalScope.Promise.reject !== 'function') {
  10205. globalScope.Promise.reject = function (reason) {
  10206. return new globalScope.Promise(function (resolve, reject) {
  10207. reject(reason);
  10208. });
  10209. };
  10210. }
  10211. if (typeof globalScope.Promise.prototype.catch !== 'function') {
  10212. globalScope.Promise.prototype.catch = function (onReject) {
  10213. return globalScope.Promise.prototype.then(undefined, onReject);
  10214. };
  10215. }
  10216. return;
  10217. }
  10218. var STATUS_PENDING = 0;
  10219. var STATUS_RESOLVED = 1;
  10220. var STATUS_REJECTED = 2;
  10221. // In an attempt to avoid silent exceptions, unhandled rejections are
  10222. // tracked and if they aren't handled in a certain amount of time an
  10223. // error is logged.
  10224. var REJECTION_TIMEOUT = 500;
  10225. var HandlerManager = {
  10226. handlers: [],
  10227. running: false,
  10228. unhandledRejections: [],
  10229. pendingRejectionCheck: false,
  10230. scheduleHandlers: function scheduleHandlers(promise) {
  10231. if (promise._status === STATUS_PENDING) {
  10232. return;
  10233. }
  10234. this.handlers = this.handlers.concat(promise._handlers);
  10235. promise._handlers = [];
  10236. if (this.running) {
  10237. return;
  10238. }
  10239. this.running = true;
  10240. setTimeout(this.runHandlers.bind(this), 0);
  10241. },
  10242. runHandlers: function runHandlers() {
  10243. var RUN_TIMEOUT = 1; // ms
  10244. var timeoutAt = Date.now() + RUN_TIMEOUT;
  10245. while (this.handlers.length > 0) {
  10246. var handler = this.handlers.shift();
  10247. var nextStatus = handler.thisPromise._status;
  10248. var nextValue = handler.thisPromise._value;
  10249. try {
  10250. if (nextStatus === STATUS_RESOLVED) {
  10251. if (typeof handler.onResolve === 'function') {
  10252. nextValue = handler.onResolve(nextValue);
  10253. }
  10254. } else if (typeof handler.onReject === 'function') {
  10255. nextValue = handler.onReject(nextValue);
  10256. nextStatus = STATUS_RESOLVED;
  10257. if (handler.thisPromise._unhandledRejection) {
  10258. this.removeUnhandeledRejection(handler.thisPromise);
  10259. }
  10260. }
  10261. } catch (ex) {
  10262. nextStatus = STATUS_REJECTED;
  10263. nextValue = ex;
  10264. }
  10265. handler.nextPromise._updateStatus(nextStatus, nextValue);
  10266. if (Date.now() >= timeoutAt) {
  10267. break;
  10268. }
  10269. }
  10270. if (this.handlers.length > 0) {
  10271. setTimeout(this.runHandlers.bind(this), 0);
  10272. return;
  10273. }
  10274. this.running = false;
  10275. },
  10276. addUnhandledRejection: function addUnhandledRejection(promise) {
  10277. this.unhandledRejections.push({
  10278. promise: promise,
  10279. time: Date.now()
  10280. });
  10281. this.scheduleRejectionCheck();
  10282. },
  10283. removeUnhandeledRejection: function removeUnhandeledRejection(promise) {
  10284. promise._unhandledRejection = false;
  10285. for (var i = 0; i < this.unhandledRejections.length; i++) {
  10286. if (this.unhandledRejections[i].promise === promise) {
  10287. this.unhandledRejections.splice(i);
  10288. i--;
  10289. }
  10290. }
  10291. },
  10292. scheduleRejectionCheck: function scheduleRejectionCheck() {
  10293. if (this.pendingRejectionCheck) {
  10294. return;
  10295. }
  10296. this.pendingRejectionCheck = true;
  10297. setTimeout(function rejectionCheck() {
  10298. this.pendingRejectionCheck = false;
  10299. var now = Date.now();
  10300. for (var i = 0; i < this.unhandledRejections.length; i++) {
  10301. if (now - this.unhandledRejections[i].time > REJECTION_TIMEOUT) {
  10302. var unhandled = this.unhandledRejections[i].promise._value;
  10303. var msg = 'Unhandled rejection: ' + unhandled;
  10304. if (unhandled.stack) {
  10305. msg += '\n' + unhandled.stack;
  10306. }
  10307. warn(msg);
  10308. this.unhandledRejections.splice(i);
  10309. i--;
  10310. }
  10311. }
  10312. if (this.unhandledRejections.length) {
  10313. this.scheduleRejectionCheck();
  10314. }
  10315. }.bind(this), REJECTION_TIMEOUT);
  10316. }
  10317. };
  10318. function Promise(resolver) {
  10319. this._status = STATUS_PENDING;
  10320. this._handlers = [];
  10321. try {
  10322. resolver.call(this, this._resolve.bind(this), this._reject.bind(this));
  10323. } catch (e) {
  10324. this._reject(e);
  10325. }
  10326. }
  10327. /**
  10328. * Builds a promise that is resolved when all the passed in promises are
  10329. * resolved.
  10330. * @param {array} array of data and/or promises to wait for.
  10331. * @return {Promise} New dependant promise.
  10332. */
  10333. Promise.all = function Promise_all(promises) {
  10334. var resolveAll, rejectAll;
  10335. var deferred = new Promise(function (resolve, reject) {
  10336. resolveAll = resolve;
  10337. rejectAll = reject;
  10338. });
  10339. var unresolved = promises.length;
  10340. var results = [];
  10341. if (unresolved === 0) {
  10342. resolveAll(results);
  10343. return deferred;
  10344. }
  10345. function reject(reason) {
  10346. if (deferred._status === STATUS_REJECTED) {
  10347. return;
  10348. }
  10349. results = [];
  10350. rejectAll(reason);
  10351. }
  10352. for (var i = 0, ii = promises.length; i < ii; ++i) {
  10353. var promise = promises[i];
  10354. var resolve = (function(i) {
  10355. return function(value) {
  10356. if (deferred._status === STATUS_REJECTED) {
  10357. return;
  10358. }
  10359. results[i] = value;
  10360. unresolved--;
  10361. if (unresolved === 0) {
  10362. resolveAll(results);
  10363. }
  10364. };
  10365. })(i);
  10366. if (Promise.isPromise(promise)) {
  10367. promise.then(resolve, reject);
  10368. } else {
  10369. resolve(promise);
  10370. }
  10371. }
  10372. return deferred;
  10373. };
  10374. /**
  10375. * Checks if the value is likely a promise (has a 'then' function).
  10376. * @return {boolean} true if value is thenable
  10377. */
  10378. Promise.isPromise = function Promise_isPromise(value) {
  10379. return value && typeof value.then === 'function';
  10380. };
  10381. /**
  10382. * Creates resolved promise
  10383. * @param value resolve value
  10384. * @returns {Promise}
  10385. */
  10386. Promise.resolve = function Promise_resolve(value) {
  10387. return new Promise(function (resolve) { resolve(value); });
  10388. };
  10389. /**
  10390. * Creates rejected promise
  10391. * @param reason rejection value
  10392. * @returns {Promise}
  10393. */
  10394. Promise.reject = function Promise_reject(reason) {
  10395. return new Promise(function (resolve, reject) { reject(reason); });
  10396. };
  10397. Promise.prototype = {
  10398. _status: null,
  10399. _value: null,
  10400. _handlers: null,
  10401. _unhandledRejection: null,
  10402. _updateStatus: function Promise__updateStatus(status, value) {
  10403. if (this._status === STATUS_RESOLVED ||
  10404. this._status === STATUS_REJECTED) {
  10405. return;
  10406. }
  10407. if (status === STATUS_RESOLVED &&
  10408. Promise.isPromise(value)) {
  10409. value.then(this._updateStatus.bind(this, STATUS_RESOLVED),
  10410. this._updateStatus.bind(this, STATUS_REJECTED));
  10411. return;
  10412. }
  10413. this._status = status;
  10414. this._value = value;
  10415. if (status === STATUS_REJECTED && this._handlers.length === 0) {
  10416. this._unhandledRejection = true;
  10417. HandlerManager.addUnhandledRejection(this);
  10418. }
  10419. HandlerManager.scheduleHandlers(this);
  10420. },
  10421. _resolve: function Promise_resolve(value) {
  10422. this._updateStatus(STATUS_RESOLVED, value);
  10423. },
  10424. _reject: function Promise_reject(reason) {
  10425. this._updateStatus(STATUS_REJECTED, reason);
  10426. },
  10427. then: function Promise_then(onResolve, onReject) {
  10428. var nextPromise = new Promise(function (resolve, reject) {
  10429. this.resolve = resolve;
  10430. this.reject = reject;
  10431. });
  10432. this._handlers.push({
  10433. thisPromise: this,
  10434. onResolve: onResolve,
  10435. onReject: onReject,
  10436. nextPromise: nextPromise
  10437. });
  10438. HandlerManager.scheduleHandlers(this);
  10439. return nextPromise;
  10440. },
  10441. catch: function Promise_catch(onReject) {
  10442. return this.then(undefined, onReject);
  10443. }
  10444. };
  10445. globalScope.Promise = Promise;
  10446. })();
  10447. var StatTimer = (function StatTimerClosure() {
  10448. function rpad(str, pad, length) {
  10449. while (str.length < length) {
  10450. str += pad;
  10451. }
  10452. return str;
  10453. }
  10454. function StatTimer() {
  10455. this.started = {};
  10456. this.times = [];
  10457. this.enabled = true;
  10458. }
  10459. StatTimer.prototype = {
  10460. time: function StatTimer_time(name) {
  10461. if (!this.enabled) {
  10462. return;
  10463. }
  10464. if (name in this.started) {
  10465. warn('Timer is already running for ' + name);
  10466. }
  10467. this.started[name] = Date.now();
  10468. },
  10469. timeEnd: function StatTimer_timeEnd(name) {
  10470. if (!this.enabled) {
  10471. return;
  10472. }
  10473. if (!(name in this.started)) {
  10474. warn('Timer has not been started for ' + name);
  10475. }
  10476. this.times.push({
  10477. 'name': name,
  10478. 'start': this.started[name],
  10479. 'end': Date.now()
  10480. });
  10481. // Remove timer from started so it can be called again.
  10482. delete this.started[name];
  10483. },
  10484. toString: function StatTimer_toString() {
  10485. var i, ii;
  10486. var times = this.times;
  10487. var out = '';
  10488. // Find the longest name for padding purposes.
  10489. var longest = 0;
  10490. for (i = 0, ii = times.length; i < ii; ++i) {
  10491. var name = times[i]['name'];
  10492. if (name.length > longest) {
  10493. longest = name.length;
  10494. }
  10495. }
  10496. for (i = 0, ii = times.length; i < ii; ++i) {
  10497. var span = times[i];
  10498. var duration = span.end - span.start;
  10499. out += rpad(span['name'], ' ', longest) + ' ' + duration + 'ms\n';
  10500. }
  10501. return out;
  10502. }
  10503. };
  10504. return StatTimer;
  10505. })();
  10506. PDFJS.createBlob = function createBlob(data, contentType) {
  10507. if (typeof Blob !== 'undefined') {
  10508. return new Blob([data], { type: contentType });
  10509. }
  10510. // Blob builder is deprecated in FF14 and removed in FF18.
  10511. var bb = new MozBlobBuilder();
  10512. bb.append(data);
  10513. return bb.getBlob(contentType);
  10514. };
  10515. PDFJS.createObjectURL = (function createObjectURLClosure() {
  10516. // Blob/createObjectURL is not available, falling back to data schema.
  10517. var digits =
  10518. 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
  10519. return function createObjectURL(data, contentType) {
  10520. if (!PDFJS.disableCreateObjectURL &&
  10521. typeof URL !== 'undefined' && URL.createObjectURL) {
  10522. var blob = PDFJS.createBlob(data, contentType);
  10523. return URL.createObjectURL(blob);
  10524. }
  10525. var buffer = 'data:' + contentType + ';base64,';
  10526. for (var i = 0, ii = data.length; i < ii; i += 3) {
  10527. var b1 = data[i] & 0xFF;
  10528. var b2 = data[i + 1] & 0xFF;
  10529. var b3 = data[i + 2] & 0xFF;
  10530. var d1 = b1 >> 2, d2 = ((b1 & 3) << 4) | (b2 >> 4);
  10531. var d3 = i + 1 < ii ? ((b2 & 0xF) << 2) | (b3 >> 6) : 64;
  10532. var d4 = i + 2 < ii ? (b3 & 0x3F) : 64;
  10533. buffer += digits[d1] + digits[d2] + digits[d3] + digits[d4];
  10534. }
  10535. return buffer;
  10536. };
  10537. })();
  10538. function MessageHandler(sourceName, targetName, comObj) {
  10539. this.sourceName = sourceName;
  10540. this.targetName = targetName;
  10541. this.comObj = comObj;
  10542. this.callbackIndex = 1;
  10543. this.postMessageTransfers = true;
  10544. var callbacksCapabilities = this.callbacksCapabilities = {};
  10545. var ah = this.actionHandler = {};
  10546. this._onComObjOnMessage = function messageHandlerComObjOnMessage(event) {
  10547. var data = event.data;
  10548. if (data.targetName !== this.sourceName) {
  10549. return;
  10550. }
  10551. if (data.isReply) {
  10552. var callbackId = data.callbackId;
  10553. if (data.callbackId in callbacksCapabilities) {
  10554. var callback = callbacksCapabilities[callbackId];
  10555. delete callbacksCapabilities[callbackId];
  10556. if ('error' in data) {
  10557. callback.reject(data.error);
  10558. } else {
  10559. callback.resolve(data.data);
  10560. }
  10561. } else {
  10562. error('Cannot resolve callback ' + callbackId);
  10563. }
  10564. } else if (data.action in ah) {
  10565. var action = ah[data.action];
  10566. if (data.callbackId) {
  10567. var sourceName = this.sourceName;
  10568. var targetName = data.sourceName;
  10569. Promise.resolve().then(function () {
  10570. return action[0].call(action[1], data.data);
  10571. }).then(function (result) {
  10572. comObj.postMessage({
  10573. sourceName: sourceName,
  10574. targetName: targetName,
  10575. isReply: true,
  10576. callbackId: data.callbackId,
  10577. data: result
  10578. });
  10579. }, function (reason) {
  10580. if (reason instanceof Error) {
  10581. // Serialize error to avoid "DataCloneError"
  10582. reason = reason + '';
  10583. }
  10584. comObj.postMessage({
  10585. sourceName: sourceName,
  10586. targetName: targetName,
  10587. isReply: true,
  10588. callbackId: data.callbackId,
  10589. error: reason
  10590. });
  10591. });
  10592. } else {
  10593. action[0].call(action[1], data.data);
  10594. }
  10595. } else {
  10596. error('Unknown action from worker: ' + data.action);
  10597. }
  10598. }.bind(this);
  10599. comObj.addEventListener('message', this._onComObjOnMessage);
  10600. }
  10601. MessageHandler.prototype = {
  10602. on: function messageHandlerOn(actionName, handler, scope) {
  10603. var ah = this.actionHandler;
  10604. if (ah[actionName]) {
  10605. error('There is already an actionName called "' + actionName + '"');
  10606. }
  10607. ah[actionName] = [handler, scope];
  10608. },
  10609. /**
  10610. * Sends a message to the comObj to invoke the action with the supplied data.
  10611. * @param {String} actionName Action to call.
  10612. * @param {JSON} data JSON data to send.
  10613. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers
  10614. */
  10615. send: function messageHandlerSend(actionName, data, transfers) {
  10616. var message = {
  10617. sourceName: this.sourceName,
  10618. targetName: this.targetName,
  10619. action: actionName,
  10620. data: data
  10621. };
  10622. this.postMessage(message, transfers);
  10623. },
  10624. /**
  10625. * Sends a message to the comObj to invoke the action with the supplied data.
  10626. * Expects that other side will callback with the response.
  10627. * @param {String} actionName Action to call.
  10628. * @param {JSON} data JSON data to send.
  10629. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers.
  10630. * @returns {Promise} Promise to be resolved with response data.
  10631. */
  10632. sendWithPromise:
  10633. function messageHandlerSendWithPromise(actionName, data, transfers) {
  10634. var callbackId = this.callbackIndex++;
  10635. var message = {
  10636. sourceName: this.sourceName,
  10637. targetName: this.targetName,
  10638. action: actionName,
  10639. data: data,
  10640. callbackId: callbackId
  10641. };
  10642. var capability = createPromiseCapability();
  10643. this.callbacksCapabilities[callbackId] = capability;
  10644. try {
  10645. this.postMessage(message, transfers);
  10646. } catch (e) {
  10647. capability.reject(e);
  10648. }
  10649. return capability.promise;
  10650. },
  10651. /**
  10652. * Sends raw message to the comObj.
  10653. * @private
  10654. * @param message {Object} Raw message.
  10655. * @param transfers List of transfers/ArrayBuffers, or undefined.
  10656. */
  10657. postMessage: function (message, transfers) {
  10658. if (transfers && this.postMessageTransfers) {
  10659. this.comObj.postMessage(message, transfers);
  10660. } else {
  10661. this.comObj.postMessage(message);
  10662. }
  10663. },
  10664. destroy: function () {
  10665. this.comObj.removeEventListener('message', this._onComObjOnMessage);
  10666. }
  10667. };
  10668. function loadJpegStream(id, imageUrl, objs) {
  10669. var img = new Image();
  10670. img.onload = (function loadJpegStream_onloadClosure() {
  10671. objs.resolve(id, img);
  10672. });
  10673. img.onerror = (function loadJpegStream_onerrorClosure() {
  10674. objs.resolve(id, null);
  10675. warn('Error during JPEG image loading');
  10676. });
  10677. img.src = imageUrl;
  10678. }
  10679. exports.FONT_IDENTITY_MATRIX = FONT_IDENTITY_MATRIX;
  10680. exports.IDENTITY_MATRIX = IDENTITY_MATRIX;
  10681. exports.OPS = OPS;
  10682. exports.UNSUPPORTED_FEATURES = UNSUPPORTED_FEATURES;
  10683. exports.AnnotationBorderStyleType = AnnotationBorderStyleType;
  10684. exports.AnnotationFlag = AnnotationFlag;
  10685. exports.AnnotationType = AnnotationType;
  10686. exports.FontType = FontType;
  10687. exports.ImageKind = ImageKind;
  10688. exports.InvalidPDFException = InvalidPDFException;
  10689. exports.LinkTarget = LinkTarget;
  10690. exports.LinkTargetStringMap = LinkTargetStringMap;
  10691. exports.MessageHandler = MessageHandler;
  10692. exports.MissingDataException = MissingDataException;
  10693. exports.MissingPDFException = MissingPDFException;
  10694. exports.NotImplementedException = NotImplementedException;
  10695. exports.PasswordException = PasswordException;
  10696. exports.PasswordResponses = PasswordResponses;
  10697. exports.StatTimer = StatTimer;
  10698. exports.StreamType = StreamType;
  10699. exports.TextRenderingMode = TextRenderingMode;
  10700. exports.UnexpectedResponseException = UnexpectedResponseException;
  10701. exports.UnknownErrorException = UnknownErrorException;
  10702. exports.Util = Util;
  10703. exports.XRefParseException = XRefParseException;
  10704. exports.assert = assert;
  10705. exports.bytesToString = bytesToString;
  10706. exports.combineUrl = combineUrl;
  10707. exports.createPromiseCapability = createPromiseCapability;
  10708. exports.deprecated = deprecated;
  10709. exports.error = error;
  10710. exports.info = info;
  10711. exports.isArray = isArray;
  10712. exports.isArrayBuffer = isArrayBuffer;
  10713. exports.isBool = isBool;
  10714. exports.isEmptyObj = isEmptyObj;
  10715. exports.isExternalLinkTargetSet = isExternalLinkTargetSet;
  10716. exports.isInt = isInt;
  10717. exports.isNum = isNum;
  10718. exports.isString = isString;
  10719. exports.isValidUrl = isValidUrl;
  10720. exports.loadJpegStream = loadJpegStream;
  10721. exports.log2 = log2;
  10722. exports.readInt8 = readInt8;
  10723. exports.readUint16 = readUint16;
  10724. exports.readUint32 = readUint32;
  10725. exports.removeNullCharacters = removeNullCharacters;
  10726. exports.shadow = shadow;
  10727. exports.string32 = string32;
  10728. exports.stringToBytes = stringToBytes;
  10729. exports.stringToPDFString = stringToPDFString;
  10730. exports.stringToUTF8String = stringToUTF8String;
  10731. exports.utf8StringToString = utf8StringToString;
  10732. exports.warn = warn;
  10733. }));
  10734. (function (root, factory) {
  10735. {
  10736. factory((root.pdfjsCoreChunkedStream = {}), root.pdfjsSharedUtil);
  10737. }
  10738. }(this, function (exports, sharedUtil) {
  10739. var MissingDataException = sharedUtil.MissingDataException;
  10740. var assert = sharedUtil.assert;
  10741. var createPromiseCapability = sharedUtil.createPromiseCapability;
  10742. var isInt = sharedUtil.isInt;
  10743. var isEmptyObj = sharedUtil.isEmptyObj;
  10744. var ChunkedStream = (function ChunkedStreamClosure() {
  10745. function ChunkedStream(length, chunkSize, manager) {
  10746. this.bytes = new Uint8Array(length);
  10747. this.start = 0;
  10748. this.pos = 0;
  10749. this.end = length;
  10750. this.chunkSize = chunkSize;
  10751. this.loadedChunks = [];
  10752. this.numChunksLoaded = 0;
  10753. this.numChunks = Math.ceil(length / chunkSize);
  10754. this.manager = manager;
  10755. this.progressiveDataLength = 0;
  10756. this.lastSuccessfulEnsureByteChunk = -1; // a single-entry cache
  10757. }
  10758. // required methods for a stream. if a particular stream does not
  10759. // implement these, an error should be thrown
  10760. ChunkedStream.prototype = {
  10761. getMissingChunks: function ChunkedStream_getMissingChunks() {
  10762. var chunks = [];
  10763. for (var chunk = 0, n = this.numChunks; chunk < n; ++chunk) {
  10764. if (!this.loadedChunks[chunk]) {
  10765. chunks.push(chunk);
  10766. }
  10767. }
  10768. return chunks;
  10769. },
  10770. getBaseStreams: function ChunkedStream_getBaseStreams() {
  10771. return [this];
  10772. },
  10773. allChunksLoaded: function ChunkedStream_allChunksLoaded() {
  10774. return this.numChunksLoaded === this.numChunks;
  10775. },
  10776. onReceiveData: function ChunkedStream_onReceiveData(begin, chunk) {
  10777. var end = begin + chunk.byteLength;
  10778. assert(begin % this.chunkSize === 0, 'Bad begin offset: ' + begin);
  10779. // Using this.length is inaccurate here since this.start can be moved
  10780. // See ChunkedStream.moveStart()
  10781. var length = this.bytes.length;
  10782. assert(end % this.chunkSize === 0 || end === length,
  10783. 'Bad end offset: ' + end);
  10784. this.bytes.set(new Uint8Array(chunk), begin);
  10785. var chunkSize = this.chunkSize;
  10786. var beginChunk = Math.floor(begin / chunkSize);
  10787. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  10788. var curChunk;
  10789. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  10790. if (!this.loadedChunks[curChunk]) {
  10791. this.loadedChunks[curChunk] = true;
  10792. ++this.numChunksLoaded;
  10793. }
  10794. }
  10795. },
  10796. onReceiveProgressiveData:
  10797. function ChunkedStream_onReceiveProgressiveData(data) {
  10798. var position = this.progressiveDataLength;
  10799. var beginChunk = Math.floor(position / this.chunkSize);
  10800. this.bytes.set(new Uint8Array(data), position);
  10801. position += data.byteLength;
  10802. this.progressiveDataLength = position;
  10803. var endChunk = position >= this.end ? this.numChunks :
  10804. Math.floor(position / this.chunkSize);
  10805. var curChunk;
  10806. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  10807. if (!this.loadedChunks[curChunk]) {
  10808. this.loadedChunks[curChunk] = true;
  10809. ++this.numChunksLoaded;
  10810. }
  10811. }
  10812. },
  10813. ensureByte: function ChunkedStream_ensureByte(pos) {
  10814. var chunk = Math.floor(pos / this.chunkSize);
  10815. if (chunk === this.lastSuccessfulEnsureByteChunk) {
  10816. return;
  10817. }
  10818. if (!this.loadedChunks[chunk]) {
  10819. throw new MissingDataException(pos, pos + 1);
  10820. }
  10821. this.lastSuccessfulEnsureByteChunk = chunk;
  10822. },
  10823. ensureRange: function ChunkedStream_ensureRange(begin, end) {
  10824. if (begin >= end) {
  10825. return;
  10826. }
  10827. if (end <= this.progressiveDataLength) {
  10828. return;
  10829. }
  10830. var chunkSize = this.chunkSize;
  10831. var beginChunk = Math.floor(begin / chunkSize);
  10832. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  10833. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  10834. if (!this.loadedChunks[chunk]) {
  10835. throw new MissingDataException(begin, end);
  10836. }
  10837. }
  10838. },
  10839. nextEmptyChunk: function ChunkedStream_nextEmptyChunk(beginChunk) {
  10840. var chunk, numChunks = this.numChunks;
  10841. for (var i = 0; i < numChunks; ++i) {
  10842. chunk = (beginChunk + i) % numChunks; // Wrap around to beginning
  10843. if (!this.loadedChunks[chunk]) {
  10844. return chunk;
  10845. }
  10846. }
  10847. return null;
  10848. },
  10849. hasChunk: function ChunkedStream_hasChunk(chunk) {
  10850. return !!this.loadedChunks[chunk];
  10851. },
  10852. get length() {
  10853. return this.end - this.start;
  10854. },
  10855. get isEmpty() {
  10856. return this.length === 0;
  10857. },
  10858. getByte: function ChunkedStream_getByte() {
  10859. var pos = this.pos;
  10860. if (pos >= this.end) {
  10861. return -1;
  10862. }
  10863. this.ensureByte(pos);
  10864. return this.bytes[this.pos++];
  10865. },
  10866. getUint16: function ChunkedStream_getUint16() {
  10867. var b0 = this.getByte();
  10868. var b1 = this.getByte();
  10869. if (b0 === -1 || b1 === -1) {
  10870. return -1;
  10871. }
  10872. return (b0 << 8) + b1;
  10873. },
  10874. getInt32: function ChunkedStream_getInt32() {
  10875. var b0 = this.getByte();
  10876. var b1 = this.getByte();
  10877. var b2 = this.getByte();
  10878. var b3 = this.getByte();
  10879. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  10880. },
  10881. // returns subarray of original buffer
  10882. // should only be read
  10883. getBytes: function ChunkedStream_getBytes(length) {
  10884. var bytes = this.bytes;
  10885. var pos = this.pos;
  10886. var strEnd = this.end;
  10887. if (!length) {
  10888. this.ensureRange(pos, strEnd);
  10889. return bytes.subarray(pos, strEnd);
  10890. }
  10891. var end = pos + length;
  10892. if (end > strEnd) {
  10893. end = strEnd;
  10894. }
  10895. this.ensureRange(pos, end);
  10896. this.pos = end;
  10897. return bytes.subarray(pos, end);
  10898. },
  10899. peekByte: function ChunkedStream_peekByte() {
  10900. var peekedByte = this.getByte();
  10901. this.pos--;
  10902. return peekedByte;
  10903. },
  10904. peekBytes: function ChunkedStream_peekBytes(length) {
  10905. var bytes = this.getBytes(length);
  10906. this.pos -= bytes.length;
  10907. return bytes;
  10908. },
  10909. getByteRange: function ChunkedStream_getBytes(begin, end) {
  10910. this.ensureRange(begin, end);
  10911. return this.bytes.subarray(begin, end);
  10912. },
  10913. skip: function ChunkedStream_skip(n) {
  10914. if (!n) {
  10915. n = 1;
  10916. }
  10917. this.pos += n;
  10918. },
  10919. reset: function ChunkedStream_reset() {
  10920. this.pos = this.start;
  10921. },
  10922. moveStart: function ChunkedStream_moveStart() {
  10923. this.start = this.pos;
  10924. },
  10925. makeSubStream: function ChunkedStream_makeSubStream(start, length, dict) {
  10926. this.ensureRange(start, start + length);
  10927. function ChunkedStreamSubstream() {}
  10928. ChunkedStreamSubstream.prototype = Object.create(this);
  10929. ChunkedStreamSubstream.prototype.getMissingChunks = function() {
  10930. var chunkSize = this.chunkSize;
  10931. var beginChunk = Math.floor(this.start / chunkSize);
  10932. var endChunk = Math.floor((this.end - 1) / chunkSize) + 1;
  10933. var missingChunks = [];
  10934. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  10935. if (!this.loadedChunks[chunk]) {
  10936. missingChunks.push(chunk);
  10937. }
  10938. }
  10939. return missingChunks;
  10940. };
  10941. var subStream = new ChunkedStreamSubstream();
  10942. subStream.pos = subStream.start = start;
  10943. subStream.end = start + length || this.end;
  10944. subStream.dict = dict;
  10945. return subStream;
  10946. },
  10947. isStream: true
  10948. };
  10949. return ChunkedStream;
  10950. })();
  10951. var ChunkedStreamManager = (function ChunkedStreamManagerClosure() {
  10952. function ChunkedStreamManager(length, chunkSize, url, args) {
  10953. this.stream = new ChunkedStream(length, chunkSize, this);
  10954. this.length = length;
  10955. this.chunkSize = chunkSize;
  10956. this.url = url;
  10957. this.disableAutoFetch = args.disableAutoFetch;
  10958. var msgHandler = this.msgHandler = args.msgHandler;
  10959. if (args.chunkedViewerLoading) {
  10960. msgHandler.on('OnDataRange', this.onReceiveData.bind(this));
  10961. msgHandler.on('OnDataProgress', this.onProgress.bind(this));
  10962. this.sendRequest = function ChunkedStreamManager_sendRequest(begin, end) {
  10963. msgHandler.send('RequestDataRange', { begin: begin, end: end });
  10964. };
  10965. } else {
  10966. var getXhr = function getXhr() {
  10967. return new XMLHttpRequest();
  10968. };
  10969. this.networkManager = new NetworkManager(this.url, {
  10970. getXhr: getXhr,
  10971. httpHeaders: args.httpHeaders,
  10972. withCredentials: args.withCredentials
  10973. });
  10974. this.sendRequest = function ChunkedStreamManager_sendRequest(begin, end) {
  10975. this.networkManager.requestRange(begin, end, {
  10976. onDone: this.onReceiveData.bind(this),
  10977. onProgress: this.onProgress.bind(this)
  10978. });
  10979. };
  10980. }
  10981. this.currRequestId = 0;
  10982. this.chunksNeededByRequest = {};
  10983. this.requestsByChunk = {};
  10984. this.promisesByRequest = {};
  10985. this.progressiveDataLength = 0;
  10986. this._loadedStreamCapability = createPromiseCapability();
  10987. if (args.initialData) {
  10988. this.onReceiveData({chunk: args.initialData});
  10989. }
  10990. }
  10991. ChunkedStreamManager.prototype = {
  10992. onLoadedStream: function ChunkedStreamManager_getLoadedStream() {
  10993. return this._loadedStreamCapability.promise;
  10994. },
  10995. // Get all the chunks that are not yet loaded and groups them into
  10996. // contiguous ranges to load in as few requests as possible
  10997. requestAllChunks: function ChunkedStreamManager_requestAllChunks() {
  10998. var missingChunks = this.stream.getMissingChunks();
  10999. this._requestChunks(missingChunks);
  11000. return this._loadedStreamCapability.promise;
  11001. },
  11002. _requestChunks: function ChunkedStreamManager_requestChunks(chunks) {
  11003. var requestId = this.currRequestId++;
  11004. var chunksNeeded;
  11005. var i, ii;
  11006. this.chunksNeededByRequest[requestId] = chunksNeeded = {};
  11007. for (i = 0, ii = chunks.length; i < ii; i++) {
  11008. if (!this.stream.hasChunk(chunks[i])) {
  11009. chunksNeeded[chunks[i]] = true;
  11010. }
  11011. }
  11012. if (isEmptyObj(chunksNeeded)) {
  11013. return Promise.resolve();
  11014. }
  11015. var capability = createPromiseCapability();
  11016. this.promisesByRequest[requestId] = capability;
  11017. var chunksToRequest = [];
  11018. for (var chunk in chunksNeeded) {
  11019. chunk = chunk | 0;
  11020. if (!(chunk in this.requestsByChunk)) {
  11021. this.requestsByChunk[chunk] = [];
  11022. chunksToRequest.push(chunk);
  11023. }
  11024. this.requestsByChunk[chunk].push(requestId);
  11025. }
  11026. if (!chunksToRequest.length) {
  11027. return capability.promise;
  11028. }
  11029. var groupedChunksToRequest = this.groupChunks(chunksToRequest);
  11030. for (i = 0; i < groupedChunksToRequest.length; ++i) {
  11031. var groupedChunk = groupedChunksToRequest[i];
  11032. var begin = groupedChunk.beginChunk * this.chunkSize;
  11033. var end = Math.min(groupedChunk.endChunk * this.chunkSize, this.length);
  11034. this.sendRequest(begin, end);
  11035. }
  11036. return capability.promise;
  11037. },
  11038. getStream: function ChunkedStreamManager_getStream() {
  11039. return this.stream;
  11040. },
  11041. // Loads any chunks in the requested range that are not yet loaded
  11042. requestRange: function ChunkedStreamManager_requestRange(begin, end) {
  11043. end = Math.min(end, this.length);
  11044. var beginChunk = this.getBeginChunk(begin);
  11045. var endChunk = this.getEndChunk(end);
  11046. var chunks = [];
  11047. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  11048. chunks.push(chunk);
  11049. }
  11050. return this._requestChunks(chunks);
  11051. },
  11052. requestRanges: function ChunkedStreamManager_requestRanges(ranges) {
  11053. ranges = ranges || [];
  11054. var chunksToRequest = [];
  11055. for (var i = 0; i < ranges.length; i++) {
  11056. var beginChunk = this.getBeginChunk(ranges[i].begin);
  11057. var endChunk = this.getEndChunk(ranges[i].end);
  11058. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  11059. if (chunksToRequest.indexOf(chunk) < 0) {
  11060. chunksToRequest.push(chunk);
  11061. }
  11062. }
  11063. }
  11064. chunksToRequest.sort(function(a, b) { return a - b; });
  11065. return this._requestChunks(chunksToRequest);
  11066. },
  11067. // Groups a sorted array of chunks into as few contiguous larger
  11068. // chunks as possible
  11069. groupChunks: function ChunkedStreamManager_groupChunks(chunks) {
  11070. var groupedChunks = [];
  11071. var beginChunk = -1;
  11072. var prevChunk = -1;
  11073. for (var i = 0; i < chunks.length; ++i) {
  11074. var chunk = chunks[i];
  11075. if (beginChunk < 0) {
  11076. beginChunk = chunk;
  11077. }
  11078. if (prevChunk >= 0 && prevChunk + 1 !== chunk) {
  11079. groupedChunks.push({ beginChunk: beginChunk,
  11080. endChunk: prevChunk + 1 });
  11081. beginChunk = chunk;
  11082. }
  11083. if (i + 1 === chunks.length) {
  11084. groupedChunks.push({ beginChunk: beginChunk,
  11085. endChunk: chunk + 1 });
  11086. }
  11087. prevChunk = chunk;
  11088. }
  11089. return groupedChunks;
  11090. },
  11091. onProgress: function ChunkedStreamManager_onProgress(args) {
  11092. var bytesLoaded = (this.stream.numChunksLoaded * this.chunkSize +
  11093. args.loaded);
  11094. this.msgHandler.send('DocProgress', {
  11095. loaded: bytesLoaded,
  11096. total: this.length
  11097. });
  11098. },
  11099. onReceiveData: function ChunkedStreamManager_onReceiveData(args) {
  11100. var chunk = args.chunk;
  11101. var isProgressive = args.begin === undefined;
  11102. var begin = isProgressive ? this.progressiveDataLength : args.begin;
  11103. var end = begin + chunk.byteLength;
  11104. var beginChunk = Math.floor(begin / this.chunkSize);
  11105. var endChunk = end < this.length ? Math.floor(end / this.chunkSize) :
  11106. Math.ceil(end / this.chunkSize);
  11107. if (isProgressive) {
  11108. this.stream.onReceiveProgressiveData(chunk);
  11109. this.progressiveDataLength = end;
  11110. } else {
  11111. this.stream.onReceiveData(begin, chunk);
  11112. }
  11113. if (this.stream.allChunksLoaded()) {
  11114. this._loadedStreamCapability.resolve(this.stream);
  11115. }
  11116. var loadedRequests = [];
  11117. var i, requestId;
  11118. for (chunk = beginChunk; chunk < endChunk; ++chunk) {
  11119. // The server might return more chunks than requested
  11120. var requestIds = this.requestsByChunk[chunk] || [];
  11121. delete this.requestsByChunk[chunk];
  11122. for (i = 0; i < requestIds.length; ++i) {
  11123. requestId = requestIds[i];
  11124. var chunksNeeded = this.chunksNeededByRequest[requestId];
  11125. if (chunk in chunksNeeded) {
  11126. delete chunksNeeded[chunk];
  11127. }
  11128. if (!isEmptyObj(chunksNeeded)) {
  11129. continue;
  11130. }
  11131. loadedRequests.push(requestId);
  11132. }
  11133. }
  11134. // If there are no pending requests, automatically fetch the next
  11135. // unfetched chunk of the PDF
  11136. if (!this.disableAutoFetch && isEmptyObj(this.requestsByChunk)) {
  11137. var nextEmptyChunk;
  11138. if (this.stream.numChunksLoaded === 1) {
  11139. // This is a special optimization so that after fetching the first
  11140. // chunk, rather than fetching the second chunk, we fetch the last
  11141. // chunk.
  11142. var lastChunk = this.stream.numChunks - 1;
  11143. if (!this.stream.hasChunk(lastChunk)) {
  11144. nextEmptyChunk = lastChunk;
  11145. }
  11146. } else {
  11147. nextEmptyChunk = this.stream.nextEmptyChunk(endChunk);
  11148. }
  11149. if (isInt(nextEmptyChunk)) {
  11150. this._requestChunks([nextEmptyChunk]);
  11151. }
  11152. }
  11153. for (i = 0; i < loadedRequests.length; ++i) {
  11154. requestId = loadedRequests[i];
  11155. var capability = this.promisesByRequest[requestId];
  11156. delete this.promisesByRequest[requestId];
  11157. capability.resolve();
  11158. }
  11159. this.msgHandler.send('DocProgress', {
  11160. loaded: this.stream.numChunksLoaded * this.chunkSize,
  11161. total: this.length
  11162. });
  11163. },
  11164. onError: function ChunkedStreamManager_onError(err) {
  11165. this._loadedStreamCapability.reject(err);
  11166. },
  11167. getBeginChunk: function ChunkedStreamManager_getBeginChunk(begin) {
  11168. var chunk = Math.floor(begin / this.chunkSize);
  11169. return chunk;
  11170. },
  11171. getEndChunk: function ChunkedStreamManager_getEndChunk(end) {
  11172. var chunk = Math.floor((end - 1) / this.chunkSize) + 1;
  11173. return chunk;
  11174. },
  11175. abort: function ChunkedStreamManager_abort() {
  11176. if (this.networkManager) {
  11177. this.networkManager.abortAllRequests();
  11178. }
  11179. for(var requestId in this.promisesByRequest) {
  11180. var capability = this.promisesByRequest[requestId];
  11181. capability.reject(new Error('Request was aborted'));
  11182. }
  11183. }
  11184. };
  11185. return ChunkedStreamManager;
  11186. })();
  11187. exports.ChunkedStream = ChunkedStream;
  11188. exports.ChunkedStreamManager = ChunkedStreamManager;
  11189. }));
  11190. (function (root, factory) {
  11191. {
  11192. factory((root.pdfjsCoreJbig2 = {}), root.pdfjsSharedUtil,
  11193. root.pdfjsCoreArithmeticDecoder);
  11194. }
  11195. }(this, function (exports, sharedUtil, coreArithmeticDecoder) {
  11196. var error = sharedUtil.error;
  11197. var log2 = sharedUtil.log2;
  11198. var readInt8 = sharedUtil.readInt8;
  11199. var readUint16 = sharedUtil.readUint16;
  11200. var readUint32 = sharedUtil.readUint32;
  11201. var shadow = sharedUtil.shadow;
  11202. var ArithmeticDecoder = coreArithmeticDecoder.ArithmeticDecoder;
  11203. var Jbig2Image = (function Jbig2ImageClosure() {
  11204. // Utility data structures
  11205. function ContextCache() {}
  11206. ContextCache.prototype = {
  11207. getContexts: function(id) {
  11208. if (id in this) {
  11209. return this[id];
  11210. }
  11211. return (this[id] = new Int8Array(1 << 16));
  11212. }
  11213. };
  11214. function DecodingContext(data, start, end) {
  11215. this.data = data;
  11216. this.start = start;
  11217. this.end = end;
  11218. }
  11219. DecodingContext.prototype = {
  11220. get decoder() {
  11221. var decoder = new ArithmeticDecoder(this.data, this.start, this.end);
  11222. return shadow(this, 'decoder', decoder);
  11223. },
  11224. get contextCache() {
  11225. var cache = new ContextCache();
  11226. return shadow(this, 'contextCache', cache);
  11227. }
  11228. };
  11229. // Annex A. Arithmetic Integer Decoding Procedure
  11230. // A.2 Procedure for decoding values
  11231. function decodeInteger(contextCache, procedure, decoder) {
  11232. var contexts = contextCache.getContexts(procedure);
  11233. var prev = 1;
  11234. function readBits(length) {
  11235. var v = 0;
  11236. for (var i = 0; i < length; i++) {
  11237. var bit = decoder.readBit(contexts, prev);
  11238. prev = (prev < 256 ? (prev << 1) | bit :
  11239. (((prev << 1) | bit) & 511) | 256);
  11240. v = (v << 1) | bit;
  11241. }
  11242. return v >>> 0;
  11243. }
  11244. var sign = readBits(1);
  11245. var value = readBits(1) ?
  11246. (readBits(1) ?
  11247. (readBits(1) ?
  11248. (readBits(1) ?
  11249. (readBits(1) ?
  11250. (readBits(32) + 4436) :
  11251. readBits(12) + 340) :
  11252. readBits(8) + 84) :
  11253. readBits(6) + 20) :
  11254. readBits(4) + 4) :
  11255. readBits(2);
  11256. return (sign === 0 ? value : (value > 0 ? -value : null));
  11257. }
  11258. // A.3 The IAID decoding procedure
  11259. function decodeIAID(contextCache, decoder, codeLength) {
  11260. var contexts = contextCache.getContexts('IAID');
  11261. var prev = 1;
  11262. for (var i = 0; i < codeLength; i++) {
  11263. var bit = decoder.readBit(contexts, prev);
  11264. prev = (prev << 1) | bit;
  11265. }
  11266. if (codeLength < 31) {
  11267. return prev & ((1 << codeLength) - 1);
  11268. }
  11269. return prev & 0x7FFFFFFF;
  11270. }
  11271. // 7.3 Segment types
  11272. var SegmentTypes = [
  11273. 'SymbolDictionary', null, null, null, 'IntermediateTextRegion', null,
  11274. 'ImmediateTextRegion', 'ImmediateLosslessTextRegion', null, null, null,
  11275. null, null, null, null, null, 'patternDictionary', null, null, null,
  11276. 'IntermediateHalftoneRegion', null, 'ImmediateHalftoneRegion',
  11277. 'ImmediateLosslessHalftoneRegion', null, null, null, null, null, null, null,
  11278. null, null, null, null, null, 'IntermediateGenericRegion', null,
  11279. 'ImmediateGenericRegion', 'ImmediateLosslessGenericRegion',
  11280. 'IntermediateGenericRefinementRegion', null,
  11281. 'ImmediateGenericRefinementRegion',
  11282. 'ImmediateLosslessGenericRefinementRegion', null, null, null, null,
  11283. 'PageInformation', 'EndOfPage', 'EndOfStripe', 'EndOfFile', 'Profiles',
  11284. 'Tables', null, null, null, null, null, null, null, null,
  11285. 'Extension'
  11286. ];
  11287. var CodingTemplates = [
  11288. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  11289. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: 2, y: -1},
  11290. {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  11291. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: 2, y: -2},
  11292. {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1},
  11293. {x: 2, y: -1}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  11294. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  11295. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -2, y: 0},
  11296. {x: -1, y: 0}],
  11297. [{x: -3, y: -1}, {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1},
  11298. {x: 1, y: -1}, {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}]
  11299. ];
  11300. var RefinementTemplates = [
  11301. {
  11302. coding: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  11303. reference: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}, {x: 0, y: 0},
  11304. {x: 1, y: 0}, {x: -1, y: 1}, {x: 0, y: 1}, {x: 1, y: 1}]
  11305. },
  11306. {
  11307. coding: [{x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  11308. reference: [{x: 0, y: -1}, {x: -1, y: 0}, {x: 0, y: 0}, {x: 1, y: 0},
  11309. {x: 0, y: 1}, {x: 1, y: 1}]
  11310. }
  11311. ];
  11312. // See 6.2.5.7 Decoding the bitmap.
  11313. var ReusedContexts = [
  11314. 0x9B25, // 10011 0110010 0101
  11315. 0x0795, // 0011 110010 101
  11316. 0x00E5, // 001 11001 01
  11317. 0x0195 // 011001 0101
  11318. ];
  11319. var RefinementReusedContexts = [
  11320. 0x0020, // '000' + '0' (coding) + '00010000' + '0' (reference)
  11321. 0x0008 // '0000' + '001000'
  11322. ];
  11323. function decodeBitmapTemplate0(width, height, decodingContext) {
  11324. var decoder = decodingContext.decoder;
  11325. var contexts = decodingContext.contextCache.getContexts('GB');
  11326. var contextLabel, i, j, pixel, row, row1, row2, bitmap = [];
  11327. // ...ooooo....
  11328. // ..ooooooo... Context template for current pixel (X)
  11329. // .ooooX...... (concatenate values of 'o'-pixels to get contextLabel)
  11330. var OLD_PIXEL_MASK = 0x7BF7; // 01111 0111111 0111
  11331. for (i = 0; i < height; i++) {
  11332. row = bitmap[i] = new Uint8Array(width);
  11333. row1 = (i < 1) ? row : bitmap[i - 1];
  11334. row2 = (i < 2) ? row : bitmap[i - 2];
  11335. // At the beginning of each row:
  11336. // Fill contextLabel with pixels that are above/right of (X)
  11337. contextLabel = (row2[0] << 13) | (row2[1] << 12) | (row2[2] << 11) |
  11338. (row1[0] << 7) | (row1[1] << 6) | (row1[2] << 5) |
  11339. (row1[3] << 4);
  11340. for (j = 0; j < width; j++) {
  11341. row[j] = pixel = decoder.readBit(contexts, contextLabel);
  11342. // At each pixel: Clear contextLabel pixels that are shifted
  11343. // out of the context, then add new ones.
  11344. contextLabel = ((contextLabel & OLD_PIXEL_MASK) << 1) |
  11345. (j + 3 < width ? row2[j + 3] << 11 : 0) |
  11346. (j + 4 < width ? row1[j + 4] << 4 : 0) | pixel;
  11347. }
  11348. }
  11349. return bitmap;
  11350. }
  11351. // 6.2 Generic Region Decoding Procedure
  11352. function decodeBitmap(mmr, width, height, templateIndex, prediction, skip, at,
  11353. decodingContext) {
  11354. if (mmr) {
  11355. error('JBIG2 error: MMR encoding is not supported');
  11356. }
  11357. // Use optimized version for the most common case
  11358. if (templateIndex === 0 && !skip && !prediction && at.length === 4 &&
  11359. at[0].x === 3 && at[0].y === -1 && at[1].x === -3 && at[1].y === -1 &&
  11360. at[2].x === 2 && at[2].y === -2 && at[3].x === -2 && at[3].y === -2) {
  11361. return decodeBitmapTemplate0(width, height, decodingContext);
  11362. }
  11363. var useskip = !!skip;
  11364. var template = CodingTemplates[templateIndex].concat(at);
  11365. // Sorting is non-standard, and it is not required. But sorting increases
  11366. // the number of template bits that can be reused from the previous
  11367. // contextLabel in the main loop.
  11368. template.sort(function (a, b) {
  11369. return (a.y - b.y) || (a.x - b.x);
  11370. });
  11371. var templateLength = template.length;
  11372. var templateX = new Int8Array(templateLength);
  11373. var templateY = new Int8Array(templateLength);
  11374. var changingTemplateEntries = [];
  11375. var reuseMask = 0, minX = 0, maxX = 0, minY = 0;
  11376. var c, k;
  11377. for (k = 0; k < templateLength; k++) {
  11378. templateX[k] = template[k].x;
  11379. templateY[k] = template[k].y;
  11380. minX = Math.min(minX, template[k].x);
  11381. maxX = Math.max(maxX, template[k].x);
  11382. minY = Math.min(minY, template[k].y);
  11383. // Check if the template pixel appears in two consecutive context labels,
  11384. // so it can be reused. Otherwise, we add it to the list of changing
  11385. // template entries.
  11386. if (k < templateLength - 1 &&
  11387. template[k].y === template[k + 1].y &&
  11388. template[k].x === template[k + 1].x - 1) {
  11389. reuseMask |= 1 << (templateLength - 1 - k);
  11390. } else {
  11391. changingTemplateEntries.push(k);
  11392. }
  11393. }
  11394. var changingEntriesLength = changingTemplateEntries.length;
  11395. var changingTemplateX = new Int8Array(changingEntriesLength);
  11396. var changingTemplateY = new Int8Array(changingEntriesLength);
  11397. var changingTemplateBit = new Uint16Array(changingEntriesLength);
  11398. for (c = 0; c < changingEntriesLength; c++) {
  11399. k = changingTemplateEntries[c];
  11400. changingTemplateX[c] = template[k].x;
  11401. changingTemplateY[c] = template[k].y;
  11402. changingTemplateBit[c] = 1 << (templateLength - 1 - k);
  11403. }
  11404. // Get the safe bounding box edges from the width, height, minX, maxX, minY
  11405. var sbb_left = -minX;
  11406. var sbb_top = -minY;
  11407. var sbb_right = width - maxX;
  11408. var pseudoPixelContext = ReusedContexts[templateIndex];
  11409. var row = new Uint8Array(width);
  11410. var bitmap = [];
  11411. var decoder = decodingContext.decoder;
  11412. var contexts = decodingContext.contextCache.getContexts('GB');
  11413. var ltp = 0, j, i0, j0, contextLabel = 0, bit, shift;
  11414. for (var i = 0; i < height; i++) {
  11415. if (prediction) {
  11416. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  11417. ltp ^= sltp;
  11418. if (ltp) {
  11419. bitmap.push(row); // duplicate previous row
  11420. continue;
  11421. }
  11422. }
  11423. row = new Uint8Array(row);
  11424. bitmap.push(row);
  11425. for (j = 0; j < width; j++) {
  11426. if (useskip && skip[i][j]) {
  11427. row[j] = 0;
  11428. continue;
  11429. }
  11430. // Are we in the middle of a scanline, so we can reuse contextLabel
  11431. // bits?
  11432. if (j >= sbb_left && j < sbb_right && i >= sbb_top) {
  11433. // If yes, we can just shift the bits that are reusable and only
  11434. // fetch the remaining ones.
  11435. contextLabel = (contextLabel << 1) & reuseMask;
  11436. for (k = 0; k < changingEntriesLength; k++) {
  11437. i0 = i + changingTemplateY[k];
  11438. j0 = j + changingTemplateX[k];
  11439. bit = bitmap[i0][j0];
  11440. if (bit) {
  11441. bit = changingTemplateBit[k];
  11442. contextLabel |= bit;
  11443. }
  11444. }
  11445. } else {
  11446. // compute the contextLabel from scratch
  11447. contextLabel = 0;
  11448. shift = templateLength - 1;
  11449. for (k = 0; k < templateLength; k++, shift--) {
  11450. j0 = j + templateX[k];
  11451. if (j0 >= 0 && j0 < width) {
  11452. i0 = i + templateY[k];
  11453. if (i0 >= 0) {
  11454. bit = bitmap[i0][j0];
  11455. if (bit) {
  11456. contextLabel |= bit << shift;
  11457. }
  11458. }
  11459. }
  11460. }
  11461. }
  11462. var pixel = decoder.readBit(contexts, contextLabel);
  11463. row[j] = pixel;
  11464. }
  11465. }
  11466. return bitmap;
  11467. }
  11468. // 6.3.2 Generic Refinement Region Decoding Procedure
  11469. function decodeRefinement(width, height, templateIndex, referenceBitmap,
  11470. offsetX, offsetY, prediction, at,
  11471. decodingContext) {
  11472. var codingTemplate = RefinementTemplates[templateIndex].coding;
  11473. if (templateIndex === 0) {
  11474. codingTemplate = codingTemplate.concat([at[0]]);
  11475. }
  11476. var codingTemplateLength = codingTemplate.length;
  11477. var codingTemplateX = new Int32Array(codingTemplateLength);
  11478. var codingTemplateY = new Int32Array(codingTemplateLength);
  11479. var k;
  11480. for (k = 0; k < codingTemplateLength; k++) {
  11481. codingTemplateX[k] = codingTemplate[k].x;
  11482. codingTemplateY[k] = codingTemplate[k].y;
  11483. }
  11484. var referenceTemplate = RefinementTemplates[templateIndex].reference;
  11485. if (templateIndex === 0) {
  11486. referenceTemplate = referenceTemplate.concat([at[1]]);
  11487. }
  11488. var referenceTemplateLength = referenceTemplate.length;
  11489. var referenceTemplateX = new Int32Array(referenceTemplateLength);
  11490. var referenceTemplateY = new Int32Array(referenceTemplateLength);
  11491. for (k = 0; k < referenceTemplateLength; k++) {
  11492. referenceTemplateX[k] = referenceTemplate[k].x;
  11493. referenceTemplateY[k] = referenceTemplate[k].y;
  11494. }
  11495. var referenceWidth = referenceBitmap[0].length;
  11496. var referenceHeight = referenceBitmap.length;
  11497. var pseudoPixelContext = RefinementReusedContexts[templateIndex];
  11498. var bitmap = [];
  11499. var decoder = decodingContext.decoder;
  11500. var contexts = decodingContext.contextCache.getContexts('GR');
  11501. var ltp = 0;
  11502. for (var i = 0; i < height; i++) {
  11503. if (prediction) {
  11504. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  11505. ltp ^= sltp;
  11506. if (ltp) {
  11507. error('JBIG2 error: prediction is not supported');
  11508. }
  11509. }
  11510. var row = new Uint8Array(width);
  11511. bitmap.push(row);
  11512. for (var j = 0; j < width; j++) {
  11513. var i0, j0;
  11514. var contextLabel = 0;
  11515. for (k = 0; k < codingTemplateLength; k++) {
  11516. i0 = i + codingTemplateY[k];
  11517. j0 = j + codingTemplateX[k];
  11518. if (i0 < 0 || j0 < 0 || j0 >= width) {
  11519. contextLabel <<= 1; // out of bound pixel
  11520. } else {
  11521. contextLabel = (contextLabel << 1) | bitmap[i0][j0];
  11522. }
  11523. }
  11524. for (k = 0; k < referenceTemplateLength; k++) {
  11525. i0 = i + referenceTemplateY[k] + offsetY;
  11526. j0 = j + referenceTemplateX[k] + offsetX;
  11527. if (i0 < 0 || i0 >= referenceHeight || j0 < 0 ||
  11528. j0 >= referenceWidth) {
  11529. contextLabel <<= 1; // out of bound pixel
  11530. } else {
  11531. contextLabel = (contextLabel << 1) | referenceBitmap[i0][j0];
  11532. }
  11533. }
  11534. var pixel = decoder.readBit(contexts, contextLabel);
  11535. row[j] = pixel;
  11536. }
  11537. }
  11538. return bitmap;
  11539. }
  11540. // 6.5.5 Decoding the symbol dictionary
  11541. function decodeSymbolDictionary(huffman, refinement, symbols,
  11542. numberOfNewSymbols, numberOfExportedSymbols,
  11543. huffmanTables, templateIndex, at,
  11544. refinementTemplateIndex, refinementAt,
  11545. decodingContext) {
  11546. if (huffman) {
  11547. error('JBIG2 error: huffman is not supported');
  11548. }
  11549. var newSymbols = [];
  11550. var currentHeight = 0;
  11551. var symbolCodeLength = log2(symbols.length + numberOfNewSymbols);
  11552. var decoder = decodingContext.decoder;
  11553. var contextCache = decodingContext.contextCache;
  11554. while (newSymbols.length < numberOfNewSymbols) {
  11555. var deltaHeight = decodeInteger(contextCache, 'IADH', decoder); // 6.5.6
  11556. currentHeight += deltaHeight;
  11557. var currentWidth = 0;
  11558. var totalWidth = 0;
  11559. while (true) {
  11560. var deltaWidth = decodeInteger(contextCache, 'IADW', decoder); // 6.5.7
  11561. if (deltaWidth === null) {
  11562. break; // OOB
  11563. }
  11564. currentWidth += deltaWidth;
  11565. totalWidth += currentWidth;
  11566. var bitmap;
  11567. if (refinement) {
  11568. // 6.5.8.2 Refinement/aggregate-coded symbol bitmap
  11569. var numberOfInstances = decodeInteger(contextCache, 'IAAI', decoder);
  11570. if (numberOfInstances > 1) {
  11571. bitmap = decodeTextRegion(huffman, refinement,
  11572. currentWidth, currentHeight, 0,
  11573. numberOfInstances, 1, //strip size
  11574. symbols.concat(newSymbols),
  11575. symbolCodeLength,
  11576. 0, //transposed
  11577. 0, //ds offset
  11578. 1, //top left 7.4.3.1.1
  11579. 0, //OR operator
  11580. huffmanTables,
  11581. refinementTemplateIndex, refinementAt,
  11582. decodingContext);
  11583. } else {
  11584. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  11585. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  11586. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  11587. var symbol = (symbolId < symbols.length ? symbols[symbolId] :
  11588. newSymbols[symbolId - symbols.length]);
  11589. bitmap = decodeRefinement(currentWidth, currentHeight,
  11590. refinementTemplateIndex, symbol, rdx, rdy, false, refinementAt,
  11591. decodingContext);
  11592. }
  11593. } else {
  11594. // 6.5.8.1 Direct-coded symbol bitmap
  11595. bitmap = decodeBitmap(false, currentWidth, currentHeight,
  11596. templateIndex, false, null, at, decodingContext);
  11597. }
  11598. newSymbols.push(bitmap);
  11599. }
  11600. }
  11601. // 6.5.10 Exported symbols
  11602. var exportedSymbols = [];
  11603. var flags = [], currentFlag = false;
  11604. var totalSymbolsLength = symbols.length + numberOfNewSymbols;
  11605. while (flags.length < totalSymbolsLength) {
  11606. var runLength = decodeInteger(contextCache, 'IAEX', decoder);
  11607. while (runLength--) {
  11608. flags.push(currentFlag);
  11609. }
  11610. currentFlag = !currentFlag;
  11611. }
  11612. for (var i = 0, ii = symbols.length; i < ii; i++) {
  11613. if (flags[i]) {
  11614. exportedSymbols.push(symbols[i]);
  11615. }
  11616. }
  11617. for (var j = 0; j < numberOfNewSymbols; i++, j++) {
  11618. if (flags[i]) {
  11619. exportedSymbols.push(newSymbols[j]);
  11620. }
  11621. }
  11622. return exportedSymbols;
  11623. }
  11624. function decodeTextRegion(huffman, refinement, width, height,
  11625. defaultPixelValue, numberOfSymbolInstances,
  11626. stripSize, inputSymbols, symbolCodeLength,
  11627. transposed, dsOffset, referenceCorner,
  11628. combinationOperator, huffmanTables,
  11629. refinementTemplateIndex, refinementAt,
  11630. decodingContext) {
  11631. if (huffman) {
  11632. error('JBIG2 error: huffman is not supported');
  11633. }
  11634. // Prepare bitmap
  11635. var bitmap = [];
  11636. var i, row;
  11637. for (i = 0; i < height; i++) {
  11638. row = new Uint8Array(width);
  11639. if (defaultPixelValue) {
  11640. for (var j = 0; j < width; j++) {
  11641. row[j] = defaultPixelValue;
  11642. }
  11643. }
  11644. bitmap.push(row);
  11645. }
  11646. var decoder = decodingContext.decoder;
  11647. var contextCache = decodingContext.contextCache;
  11648. var stripT = -decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  11649. var firstS = 0;
  11650. i = 0;
  11651. while (i < numberOfSymbolInstances) {
  11652. var deltaT = decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  11653. stripT += deltaT;
  11654. var deltaFirstS = decodeInteger(contextCache, 'IAFS', decoder); // 6.4.7
  11655. firstS += deltaFirstS;
  11656. var currentS = firstS;
  11657. do {
  11658. var currentT = (stripSize === 1 ? 0 :
  11659. decodeInteger(contextCache, 'IAIT', decoder)); // 6.4.9
  11660. var t = stripSize * stripT + currentT;
  11661. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  11662. var applyRefinement = (refinement &&
  11663. decodeInteger(contextCache, 'IARI', decoder));
  11664. var symbolBitmap = inputSymbols[symbolId];
  11665. var symbolWidth = symbolBitmap[0].length;
  11666. var symbolHeight = symbolBitmap.length;
  11667. if (applyRefinement) {
  11668. var rdw = decodeInteger(contextCache, 'IARDW', decoder); // 6.4.11.1
  11669. var rdh = decodeInteger(contextCache, 'IARDH', decoder); // 6.4.11.2
  11670. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  11671. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  11672. symbolWidth += rdw;
  11673. symbolHeight += rdh;
  11674. symbolBitmap = decodeRefinement(symbolWidth, symbolHeight,
  11675. refinementTemplateIndex, symbolBitmap, (rdw >> 1) + rdx,
  11676. (rdh >> 1) + rdy, false, refinementAt,
  11677. decodingContext);
  11678. }
  11679. var offsetT = t - ((referenceCorner & 1) ? 0 : symbolHeight);
  11680. var offsetS = currentS - ((referenceCorner & 2) ? symbolWidth : 0);
  11681. var s2, t2, symbolRow;
  11682. if (transposed) {
  11683. // Place Symbol Bitmap from T1,S1
  11684. for (s2 = 0; s2 < symbolHeight; s2++) {
  11685. row = bitmap[offsetS + s2];
  11686. if (!row) {
  11687. continue;
  11688. }
  11689. symbolRow = symbolBitmap[s2];
  11690. // To ignore Parts of Symbol bitmap which goes
  11691. // outside bitmap region
  11692. var maxWidth = Math.min(width - offsetT, symbolWidth);
  11693. switch (combinationOperator) {
  11694. case 0: // OR
  11695. for (t2 = 0; t2 < maxWidth; t2++) {
  11696. row[offsetT + t2] |= symbolRow[t2];
  11697. }
  11698. break;
  11699. case 2: // XOR
  11700. for (t2 = 0; t2 < maxWidth; t2++) {
  11701. row[offsetT + t2] ^= symbolRow[t2];
  11702. }
  11703. break;
  11704. default:
  11705. error('JBIG2 error: operator ' + combinationOperator +
  11706. ' is not supported');
  11707. }
  11708. }
  11709. currentS += symbolHeight - 1;
  11710. } else {
  11711. for (t2 = 0; t2 < symbolHeight; t2++) {
  11712. row = bitmap[offsetT + t2];
  11713. if (!row) {
  11714. continue;
  11715. }
  11716. symbolRow = symbolBitmap[t2];
  11717. switch (combinationOperator) {
  11718. case 0: // OR
  11719. for (s2 = 0; s2 < symbolWidth; s2++) {
  11720. row[offsetS + s2] |= symbolRow[s2];
  11721. }
  11722. break;
  11723. case 2: // XOR
  11724. for (s2 = 0; s2 < symbolWidth; s2++) {
  11725. row[offsetS + s2] ^= symbolRow[s2];
  11726. }
  11727. break;
  11728. default:
  11729. error('JBIG2 error: operator ' + combinationOperator +
  11730. ' is not supported');
  11731. }
  11732. }
  11733. currentS += symbolWidth - 1;
  11734. }
  11735. i++;
  11736. var deltaS = decodeInteger(contextCache, 'IADS', decoder); // 6.4.8
  11737. if (deltaS === null) {
  11738. break; // OOB
  11739. }
  11740. currentS += deltaS + dsOffset;
  11741. } while (true);
  11742. }
  11743. return bitmap;
  11744. }
  11745. function readSegmentHeader(data, start) {
  11746. var segmentHeader = {};
  11747. segmentHeader.number = readUint32(data, start);
  11748. var flags = data[start + 4];
  11749. var segmentType = flags & 0x3F;
  11750. if (!SegmentTypes[segmentType]) {
  11751. error('JBIG2 error: invalid segment type: ' + segmentType);
  11752. }
  11753. segmentHeader.type = segmentType;
  11754. segmentHeader.typeName = SegmentTypes[segmentType];
  11755. segmentHeader.deferredNonRetain = !!(flags & 0x80);
  11756. var pageAssociationFieldSize = !!(flags & 0x40);
  11757. var referredFlags = data[start + 5];
  11758. var referredToCount = (referredFlags >> 5) & 7;
  11759. var retainBits = [referredFlags & 31];
  11760. var position = start + 6;
  11761. if (referredFlags === 7) {
  11762. referredToCount = readUint32(data, position - 1) & 0x1FFFFFFF;
  11763. position += 3;
  11764. var bytes = (referredToCount + 7) >> 3;
  11765. retainBits[0] = data[position++];
  11766. while (--bytes > 0) {
  11767. retainBits.push(data[position++]);
  11768. }
  11769. } else if (referredFlags === 5 || referredFlags === 6) {
  11770. error('JBIG2 error: invalid referred-to flags');
  11771. }
  11772. segmentHeader.retainBits = retainBits;
  11773. var referredToSegmentNumberSize = (segmentHeader.number <= 256 ? 1 :
  11774. (segmentHeader.number <= 65536 ? 2 : 4));
  11775. var referredTo = [];
  11776. var i, ii;
  11777. for (i = 0; i < referredToCount; i++) {
  11778. var number = (referredToSegmentNumberSize === 1 ? data[position] :
  11779. (referredToSegmentNumberSize === 2 ? readUint16(data, position) :
  11780. readUint32(data, position)));
  11781. referredTo.push(number);
  11782. position += referredToSegmentNumberSize;
  11783. }
  11784. segmentHeader.referredTo = referredTo;
  11785. if (!pageAssociationFieldSize) {
  11786. segmentHeader.pageAssociation = data[position++];
  11787. } else {
  11788. segmentHeader.pageAssociation = readUint32(data, position);
  11789. position += 4;
  11790. }
  11791. segmentHeader.length = readUint32(data, position);
  11792. position += 4;
  11793. if (segmentHeader.length === 0xFFFFFFFF) {
  11794. // 7.2.7 Segment data length, unknown segment length
  11795. if (segmentType === 38) { // ImmediateGenericRegion
  11796. var genericRegionInfo = readRegionSegmentInformation(data, position);
  11797. var genericRegionSegmentFlags = data[position +
  11798. RegionSegmentInformationFieldLength];
  11799. var genericRegionMmr = !!(genericRegionSegmentFlags & 1);
  11800. // searching for the segment end
  11801. var searchPatternLength = 6;
  11802. var searchPattern = new Uint8Array(searchPatternLength);
  11803. if (!genericRegionMmr) {
  11804. searchPattern[0] = 0xFF;
  11805. searchPattern[1] = 0xAC;
  11806. }
  11807. searchPattern[2] = (genericRegionInfo.height >>> 24) & 0xFF;
  11808. searchPattern[3] = (genericRegionInfo.height >> 16) & 0xFF;
  11809. searchPattern[4] = (genericRegionInfo.height >> 8) & 0xFF;
  11810. searchPattern[5] = genericRegionInfo.height & 0xFF;
  11811. for (i = position, ii = data.length; i < ii; i++) {
  11812. var j = 0;
  11813. while (j < searchPatternLength && searchPattern[j] === data[i + j]) {
  11814. j++;
  11815. }
  11816. if (j === searchPatternLength) {
  11817. segmentHeader.length = i + searchPatternLength;
  11818. break;
  11819. }
  11820. }
  11821. if (segmentHeader.length === 0xFFFFFFFF) {
  11822. error('JBIG2 error: segment end was not found');
  11823. }
  11824. } else {
  11825. error('JBIG2 error: invalid unknown segment length');
  11826. }
  11827. }
  11828. segmentHeader.headerEnd = position;
  11829. return segmentHeader;
  11830. }
  11831. function readSegments(header, data, start, end) {
  11832. var segments = [];
  11833. var position = start;
  11834. while (position < end) {
  11835. var segmentHeader = readSegmentHeader(data, position);
  11836. position = segmentHeader.headerEnd;
  11837. var segment = {
  11838. header: segmentHeader,
  11839. data: data
  11840. };
  11841. if (!header.randomAccess) {
  11842. segment.start = position;
  11843. position += segmentHeader.length;
  11844. segment.end = position;
  11845. }
  11846. segments.push(segment);
  11847. if (segmentHeader.type === 51) {
  11848. break; // end of file is found
  11849. }
  11850. }
  11851. if (header.randomAccess) {
  11852. for (var i = 0, ii = segments.length; i < ii; i++) {
  11853. segments[i].start = position;
  11854. position += segments[i].header.length;
  11855. segments[i].end = position;
  11856. }
  11857. }
  11858. return segments;
  11859. }
  11860. // 7.4.1 Region segment information field
  11861. function readRegionSegmentInformation(data, start) {
  11862. return {
  11863. width: readUint32(data, start),
  11864. height: readUint32(data, start + 4),
  11865. x: readUint32(data, start + 8),
  11866. y: readUint32(data, start + 12),
  11867. combinationOperator: data[start + 16] & 7
  11868. };
  11869. }
  11870. var RegionSegmentInformationFieldLength = 17;
  11871. function processSegment(segment, visitor) {
  11872. var header = segment.header;
  11873. var data = segment.data, position = segment.start, end = segment.end;
  11874. var args, at, i, atLength;
  11875. switch (header.type) {
  11876. case 0: // SymbolDictionary
  11877. // 7.4.2 Symbol dictionary segment syntax
  11878. var dictionary = {};
  11879. var dictionaryFlags = readUint16(data, position); // 7.4.2.1.1
  11880. dictionary.huffman = !!(dictionaryFlags & 1);
  11881. dictionary.refinement = !!(dictionaryFlags & 2);
  11882. dictionary.huffmanDHSelector = (dictionaryFlags >> 2) & 3;
  11883. dictionary.huffmanDWSelector = (dictionaryFlags >> 4) & 3;
  11884. dictionary.bitmapSizeSelector = (dictionaryFlags >> 6) & 1;
  11885. dictionary.aggregationInstancesSelector = (dictionaryFlags >> 7) & 1;
  11886. dictionary.bitmapCodingContextUsed = !!(dictionaryFlags & 256);
  11887. dictionary.bitmapCodingContextRetained = !!(dictionaryFlags & 512);
  11888. dictionary.template = (dictionaryFlags >> 10) & 3;
  11889. dictionary.refinementTemplate = (dictionaryFlags >> 12) & 1;
  11890. position += 2;
  11891. if (!dictionary.huffman) {
  11892. atLength = dictionary.template === 0 ? 4 : 1;
  11893. at = [];
  11894. for (i = 0; i < atLength; i++) {
  11895. at.push({
  11896. x: readInt8(data, position),
  11897. y: readInt8(data, position + 1)
  11898. });
  11899. position += 2;
  11900. }
  11901. dictionary.at = at;
  11902. }
  11903. if (dictionary.refinement && !dictionary.refinementTemplate) {
  11904. at = [];
  11905. for (i = 0; i < 2; i++) {
  11906. at.push({
  11907. x: readInt8(data, position),
  11908. y: readInt8(data, position + 1)
  11909. });
  11910. position += 2;
  11911. }
  11912. dictionary.refinementAt = at;
  11913. }
  11914. dictionary.numberOfExportedSymbols = readUint32(data, position);
  11915. position += 4;
  11916. dictionary.numberOfNewSymbols = readUint32(data, position);
  11917. position += 4;
  11918. args = [dictionary, header.number, header.referredTo,
  11919. data, position, end];
  11920. break;
  11921. case 6: // ImmediateTextRegion
  11922. case 7: // ImmediateLosslessTextRegion
  11923. var textRegion = {};
  11924. textRegion.info = readRegionSegmentInformation(data, position);
  11925. position += RegionSegmentInformationFieldLength;
  11926. var textRegionSegmentFlags = readUint16(data, position);
  11927. position += 2;
  11928. textRegion.huffman = !!(textRegionSegmentFlags & 1);
  11929. textRegion.refinement = !!(textRegionSegmentFlags & 2);
  11930. textRegion.stripSize = 1 << ((textRegionSegmentFlags >> 2) & 3);
  11931. textRegion.referenceCorner = (textRegionSegmentFlags >> 4) & 3;
  11932. textRegion.transposed = !!(textRegionSegmentFlags & 64);
  11933. textRegion.combinationOperator = (textRegionSegmentFlags >> 7) & 3;
  11934. textRegion.defaultPixelValue = (textRegionSegmentFlags >> 9) & 1;
  11935. textRegion.dsOffset = (textRegionSegmentFlags << 17) >> 27;
  11936. textRegion.refinementTemplate = (textRegionSegmentFlags >> 15) & 1;
  11937. if (textRegion.huffman) {
  11938. var textRegionHuffmanFlags = readUint16(data, position);
  11939. position += 2;
  11940. textRegion.huffmanFS = (textRegionHuffmanFlags) & 3;
  11941. textRegion.huffmanDS = (textRegionHuffmanFlags >> 2) & 3;
  11942. textRegion.huffmanDT = (textRegionHuffmanFlags >> 4) & 3;
  11943. textRegion.huffmanRefinementDW = (textRegionHuffmanFlags >> 6) & 3;
  11944. textRegion.huffmanRefinementDH = (textRegionHuffmanFlags >> 8) & 3;
  11945. textRegion.huffmanRefinementDX = (textRegionHuffmanFlags >> 10) & 3;
  11946. textRegion.huffmanRefinementDY = (textRegionHuffmanFlags >> 12) & 3;
  11947. textRegion.huffmanRefinementSizeSelector =
  11948. !!(textRegionHuffmanFlags & 14);
  11949. }
  11950. if (textRegion.refinement && !textRegion.refinementTemplate) {
  11951. at = [];
  11952. for (i = 0; i < 2; i++) {
  11953. at.push({
  11954. x: readInt8(data, position),
  11955. y: readInt8(data, position + 1)
  11956. });
  11957. position += 2;
  11958. }
  11959. textRegion.refinementAt = at;
  11960. }
  11961. textRegion.numberOfSymbolInstances = readUint32(data, position);
  11962. position += 4;
  11963. // TODO 7.4.3.1.7 Symbol ID Huffman table decoding
  11964. if (textRegion.huffman) {
  11965. error('JBIG2 error: huffman is not supported');
  11966. }
  11967. args = [textRegion, header.referredTo, data, position, end];
  11968. break;
  11969. case 38: // ImmediateGenericRegion
  11970. case 39: // ImmediateLosslessGenericRegion
  11971. var genericRegion = {};
  11972. genericRegion.info = readRegionSegmentInformation(data, position);
  11973. position += RegionSegmentInformationFieldLength;
  11974. var genericRegionSegmentFlags = data[position++];
  11975. genericRegion.mmr = !!(genericRegionSegmentFlags & 1);
  11976. genericRegion.template = (genericRegionSegmentFlags >> 1) & 3;
  11977. genericRegion.prediction = !!(genericRegionSegmentFlags & 8);
  11978. if (!genericRegion.mmr) {
  11979. atLength = genericRegion.template === 0 ? 4 : 1;
  11980. at = [];
  11981. for (i = 0; i < atLength; i++) {
  11982. at.push({
  11983. x: readInt8(data, position),
  11984. y: readInt8(data, position + 1)
  11985. });
  11986. position += 2;
  11987. }
  11988. genericRegion.at = at;
  11989. }
  11990. args = [genericRegion, data, position, end];
  11991. break;
  11992. case 48: // PageInformation
  11993. var pageInfo = {
  11994. width: readUint32(data, position),
  11995. height: readUint32(data, position + 4),
  11996. resolutionX: readUint32(data, position + 8),
  11997. resolutionY: readUint32(data, position + 12)
  11998. };
  11999. if (pageInfo.height === 0xFFFFFFFF) {
  12000. delete pageInfo.height;
  12001. }
  12002. var pageSegmentFlags = data[position + 16];
  12003. var pageStripingInformation = readUint16(data, position + 17);
  12004. pageInfo.lossless = !!(pageSegmentFlags & 1);
  12005. pageInfo.refinement = !!(pageSegmentFlags & 2);
  12006. pageInfo.defaultPixelValue = (pageSegmentFlags >> 2) & 1;
  12007. pageInfo.combinationOperator = (pageSegmentFlags >> 3) & 3;
  12008. pageInfo.requiresBuffer = !!(pageSegmentFlags & 32);
  12009. pageInfo.combinationOperatorOverride = !!(pageSegmentFlags & 64);
  12010. args = [pageInfo];
  12011. break;
  12012. case 49: // EndOfPage
  12013. break;
  12014. case 50: // EndOfStripe
  12015. break;
  12016. case 51: // EndOfFile
  12017. break;
  12018. case 62: // 7.4.15 defines 2 extension types which
  12019. // are comments and can be ignored.
  12020. break;
  12021. default:
  12022. error('JBIG2 error: segment type ' + header.typeName + '(' +
  12023. header.type + ') is not implemented');
  12024. }
  12025. var callbackName = 'on' + header.typeName;
  12026. if (callbackName in visitor) {
  12027. visitor[callbackName].apply(visitor, args);
  12028. }
  12029. }
  12030. function processSegments(segments, visitor) {
  12031. for (var i = 0, ii = segments.length; i < ii; i++) {
  12032. processSegment(segments[i], visitor);
  12033. }
  12034. }
  12035. function parseJbig2(data, start, end) {
  12036. var position = start;
  12037. if (data[position] !== 0x97 || data[position + 1] !== 0x4A ||
  12038. data[position + 2] !== 0x42 || data[position + 3] !== 0x32 ||
  12039. data[position + 4] !== 0x0D || data[position + 5] !== 0x0A ||
  12040. data[position + 6] !== 0x1A || data[position + 7] !== 0x0A) {
  12041. error('JBIG2 error: invalid header');
  12042. }
  12043. var header = {};
  12044. position += 8;
  12045. var flags = data[position++];
  12046. header.randomAccess = !(flags & 1);
  12047. if (!(flags & 2)) {
  12048. header.numberOfPages = readUint32(data, position);
  12049. position += 4;
  12050. }
  12051. var segments = readSegments(header, data, position, end);
  12052. error('Not implemented');
  12053. // processSegments(segments, new SimpleSegmentVisitor());
  12054. }
  12055. function parseJbig2Chunks(chunks) {
  12056. var visitor = new SimpleSegmentVisitor();
  12057. for (var i = 0, ii = chunks.length; i < ii; i++) {
  12058. var chunk = chunks[i];
  12059. var segments = readSegments({}, chunk.data, chunk.start, chunk.end);
  12060. processSegments(segments, visitor);
  12061. }
  12062. return visitor.buffer;
  12063. }
  12064. function SimpleSegmentVisitor() {}
  12065. SimpleSegmentVisitor.prototype = {
  12066. onPageInformation: function SimpleSegmentVisitor_onPageInformation(info) {
  12067. this.currentPageInfo = info;
  12068. var rowSize = (info.width + 7) >> 3;
  12069. var buffer = new Uint8Array(rowSize * info.height);
  12070. // The contents of ArrayBuffers are initialized to 0.
  12071. // Fill the buffer with 0xFF only if info.defaultPixelValue is set
  12072. if (info.defaultPixelValue) {
  12073. for (var i = 0, ii = buffer.length; i < ii; i++) {
  12074. buffer[i] = 0xFF;
  12075. }
  12076. }
  12077. this.buffer = buffer;
  12078. },
  12079. drawBitmap: function SimpleSegmentVisitor_drawBitmap(regionInfo, bitmap) {
  12080. var pageInfo = this.currentPageInfo;
  12081. var width = regionInfo.width, height = regionInfo.height;
  12082. var rowSize = (pageInfo.width + 7) >> 3;
  12083. var combinationOperator = pageInfo.combinationOperatorOverride ?
  12084. regionInfo.combinationOperator : pageInfo.combinationOperator;
  12085. var buffer = this.buffer;
  12086. var mask0 = 128 >> (regionInfo.x & 7);
  12087. var offset0 = regionInfo.y * rowSize + (regionInfo.x >> 3);
  12088. var i, j, mask, offset;
  12089. switch (combinationOperator) {
  12090. case 0: // OR
  12091. for (i = 0; i < height; i++) {
  12092. mask = mask0;
  12093. offset = offset0;
  12094. for (j = 0; j < width; j++) {
  12095. if (bitmap[i][j]) {
  12096. buffer[offset] |= mask;
  12097. }
  12098. mask >>= 1;
  12099. if (!mask) {
  12100. mask = 128;
  12101. offset++;
  12102. }
  12103. }
  12104. offset0 += rowSize;
  12105. }
  12106. break;
  12107. case 2: // XOR
  12108. for (i = 0; i < height; i++) {
  12109. mask = mask0;
  12110. offset = offset0;
  12111. for (j = 0; j < width; j++) {
  12112. if (bitmap[i][j]) {
  12113. buffer[offset] ^= mask;
  12114. }
  12115. mask >>= 1;
  12116. if (!mask) {
  12117. mask = 128;
  12118. offset++;
  12119. }
  12120. }
  12121. offset0 += rowSize;
  12122. }
  12123. break;
  12124. default:
  12125. error('JBIG2 error: operator ' + combinationOperator +
  12126. ' is not supported');
  12127. }
  12128. },
  12129. onImmediateGenericRegion:
  12130. function SimpleSegmentVisitor_onImmediateGenericRegion(region, data,
  12131. start, end) {
  12132. var regionInfo = region.info;
  12133. var decodingContext = new DecodingContext(data, start, end);
  12134. var bitmap = decodeBitmap(region.mmr, regionInfo.width, regionInfo.height,
  12135. region.template, region.prediction, null,
  12136. region.at, decodingContext);
  12137. this.drawBitmap(regionInfo, bitmap);
  12138. },
  12139. onImmediateLosslessGenericRegion:
  12140. function SimpleSegmentVisitor_onImmediateLosslessGenericRegion() {
  12141. this.onImmediateGenericRegion.apply(this, arguments);
  12142. },
  12143. onSymbolDictionary:
  12144. function SimpleSegmentVisitor_onSymbolDictionary(dictionary,
  12145. currentSegment,
  12146. referredSegments,
  12147. data, start, end) {
  12148. var huffmanTables;
  12149. if (dictionary.huffman) {
  12150. error('JBIG2 error: huffman is not supported');
  12151. }
  12152. // Combines exported symbols from all referred segments
  12153. var symbols = this.symbols;
  12154. if (!symbols) {
  12155. this.symbols = symbols = {};
  12156. }
  12157. var inputSymbols = [];
  12158. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  12159. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  12160. }
  12161. var decodingContext = new DecodingContext(data, start, end);
  12162. symbols[currentSegment] = decodeSymbolDictionary(dictionary.huffman,
  12163. dictionary.refinement, inputSymbols, dictionary.numberOfNewSymbols,
  12164. dictionary.numberOfExportedSymbols, huffmanTables,
  12165. dictionary.template, dictionary.at,
  12166. dictionary.refinementTemplate, dictionary.refinementAt,
  12167. decodingContext);
  12168. },
  12169. onImmediateTextRegion:
  12170. function SimpleSegmentVisitor_onImmediateTextRegion(region,
  12171. referredSegments,
  12172. data, start, end) {
  12173. var regionInfo = region.info;
  12174. var huffmanTables;
  12175. // Combines exported symbols from all referred segments
  12176. var symbols = this.symbols;
  12177. var inputSymbols = [];
  12178. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  12179. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  12180. }
  12181. var symbolCodeLength = log2(inputSymbols.length);
  12182. var decodingContext = new DecodingContext(data, start, end);
  12183. var bitmap = decodeTextRegion(region.huffman, region.refinement,
  12184. regionInfo.width, regionInfo.height, region.defaultPixelValue,
  12185. region.numberOfSymbolInstances, region.stripSize, inputSymbols,
  12186. symbolCodeLength, region.transposed, region.dsOffset,
  12187. region.referenceCorner, region.combinationOperator, huffmanTables,
  12188. region.refinementTemplate, region.refinementAt, decodingContext);
  12189. this.drawBitmap(regionInfo, bitmap);
  12190. },
  12191. onImmediateLosslessTextRegion:
  12192. function SimpleSegmentVisitor_onImmediateLosslessTextRegion() {
  12193. this.onImmediateTextRegion.apply(this, arguments);
  12194. }
  12195. };
  12196. function Jbig2Image() {}
  12197. Jbig2Image.prototype = {
  12198. parseChunks: function Jbig2Image_parseChunks(chunks) {
  12199. return parseJbig2Chunks(chunks);
  12200. }
  12201. };
  12202. return Jbig2Image;
  12203. })();
  12204. exports.Jbig2Image = Jbig2Image;
  12205. }));
  12206. (function (root, factory) {
  12207. {
  12208. factory((root.pdfjsCoreJpx = {}), root.pdfjsSharedUtil,
  12209. root.pdfjsCoreArithmeticDecoder);
  12210. }
  12211. }(this, function (exports, sharedUtil, coreArithmeticDecoder) {
  12212. var info = sharedUtil.info;
  12213. var log2 = sharedUtil.log2;
  12214. var readUint16 = sharedUtil.readUint16;
  12215. var readUint32 = sharedUtil.readUint32;
  12216. var warn = sharedUtil.warn;
  12217. var ArithmeticDecoder = coreArithmeticDecoder.ArithmeticDecoder;
  12218. var JpxImage = (function JpxImageClosure() {
  12219. // Table E.1
  12220. var SubbandsGainLog2 = {
  12221. 'LL': 0,
  12222. 'LH': 1,
  12223. 'HL': 1,
  12224. 'HH': 2
  12225. };
  12226. function JpxImage() {
  12227. this.failOnCorruptedImage = false;
  12228. }
  12229. JpxImage.prototype = {
  12230. parse: function JpxImage_parse(data) {
  12231. var head = readUint16(data, 0);
  12232. // No box header, immediate start of codestream (SOC)
  12233. if (head === 0xFF4F) {
  12234. this.parseCodestream(data, 0, data.length);
  12235. return;
  12236. }
  12237. var position = 0, length = data.length;
  12238. while (position < length) {
  12239. var headerSize = 8;
  12240. var lbox = readUint32(data, position);
  12241. var tbox = readUint32(data, position + 4);
  12242. position += headerSize;
  12243. if (lbox === 1) {
  12244. // XLBox: read UInt64 according to spec.
  12245. // JavaScript's int precision of 53 bit should be sufficient here.
  12246. lbox = readUint32(data, position) * 4294967296 +
  12247. readUint32(data, position + 4);
  12248. position += 8;
  12249. headerSize += 8;
  12250. }
  12251. if (lbox === 0) {
  12252. lbox = length - position + headerSize;
  12253. }
  12254. if (lbox < headerSize) {
  12255. throw new Error('JPX Error: Invalid box field size');
  12256. }
  12257. var dataLength = lbox - headerSize;
  12258. var jumpDataLength = true;
  12259. switch (tbox) {
  12260. case 0x6A703268: // 'jp2h'
  12261. jumpDataLength = false; // parsing child boxes
  12262. break;
  12263. case 0x636F6C72: // 'colr'
  12264. // Colorspaces are not used, the CS from the PDF is used.
  12265. var method = data[position];
  12266. if (method === 1) {
  12267. // enumerated colorspace
  12268. var colorspace = readUint32(data, position + 3);
  12269. switch (colorspace) {
  12270. case 16: // this indicates a sRGB colorspace
  12271. case 17: // this indicates a grayscale colorspace
  12272. case 18: // this indicates a YUV colorspace
  12273. break;
  12274. default:
  12275. warn('Unknown colorspace ' + colorspace);
  12276. break;
  12277. }
  12278. } else if (method === 2) {
  12279. info('ICC profile not supported');
  12280. }
  12281. break;
  12282. case 0x6A703263: // 'jp2c'
  12283. this.parseCodestream(data, position, position + dataLength);
  12284. break;
  12285. case 0x6A502020: // 'jP\024\024'
  12286. if (0x0d0a870a !== readUint32(data, position)) {
  12287. warn('Invalid JP2 signature');
  12288. }
  12289. break;
  12290. // The following header types are valid but currently not used:
  12291. case 0x6A501A1A: // 'jP\032\032'
  12292. case 0x66747970: // 'ftyp'
  12293. case 0x72726571: // 'rreq'
  12294. case 0x72657320: // 'res '
  12295. case 0x69686472: // 'ihdr'
  12296. break;
  12297. default:
  12298. var headerType = String.fromCharCode((tbox >> 24) & 0xFF,
  12299. (tbox >> 16) & 0xFF,
  12300. (tbox >> 8) & 0xFF,
  12301. tbox & 0xFF);
  12302. warn('Unsupported header type ' + tbox + ' (' + headerType + ')');
  12303. break;
  12304. }
  12305. if (jumpDataLength) {
  12306. position += dataLength;
  12307. }
  12308. }
  12309. },
  12310. parseImageProperties: function JpxImage_parseImageProperties(stream) {
  12311. var newByte = stream.getByte();
  12312. while (newByte >= 0) {
  12313. var oldByte = newByte;
  12314. newByte = stream.getByte();
  12315. var code = (oldByte << 8) | newByte;
  12316. // Image and tile size (SIZ)
  12317. if (code === 0xFF51) {
  12318. stream.skip(4);
  12319. var Xsiz = stream.getInt32() >>> 0; // Byte 4
  12320. var Ysiz = stream.getInt32() >>> 0; // Byte 8
  12321. var XOsiz = stream.getInt32() >>> 0; // Byte 12
  12322. var YOsiz = stream.getInt32() >>> 0; // Byte 16
  12323. stream.skip(16);
  12324. var Csiz = stream.getUint16(); // Byte 36
  12325. this.width = Xsiz - XOsiz;
  12326. this.height = Ysiz - YOsiz;
  12327. this.componentsCount = Csiz;
  12328. // Results are always returned as Uint8Arrays
  12329. this.bitsPerComponent = 8;
  12330. return;
  12331. }
  12332. }
  12333. throw new Error('JPX Error: No size marker found in JPX stream');
  12334. },
  12335. parseCodestream: function JpxImage_parseCodestream(data, start, end) {
  12336. var context = {};
  12337. try {
  12338. var doNotRecover = false;
  12339. var position = start;
  12340. while (position + 1 < end) {
  12341. var code = readUint16(data, position);
  12342. position += 2;
  12343. var length = 0, j, sqcd, spqcds, spqcdSize, scalarExpounded, tile;
  12344. switch (code) {
  12345. case 0xFF4F: // Start of codestream (SOC)
  12346. context.mainHeader = true;
  12347. break;
  12348. case 0xFFD9: // End of codestream (EOC)
  12349. break;
  12350. case 0xFF51: // Image and tile size (SIZ)
  12351. length = readUint16(data, position);
  12352. var siz = {};
  12353. siz.Xsiz = readUint32(data, position + 4);
  12354. siz.Ysiz = readUint32(data, position + 8);
  12355. siz.XOsiz = readUint32(data, position + 12);
  12356. siz.YOsiz = readUint32(data, position + 16);
  12357. siz.XTsiz = readUint32(data, position + 20);
  12358. siz.YTsiz = readUint32(data, position + 24);
  12359. siz.XTOsiz = readUint32(data, position + 28);
  12360. siz.YTOsiz = readUint32(data, position + 32);
  12361. var componentsCount = readUint16(data, position + 36);
  12362. siz.Csiz = componentsCount;
  12363. var components = [];
  12364. j = position + 38;
  12365. for (var i = 0; i < componentsCount; i++) {
  12366. var component = {
  12367. precision: (data[j] & 0x7F) + 1,
  12368. isSigned: !!(data[j] & 0x80),
  12369. XRsiz: data[j + 1],
  12370. YRsiz: data[j + 1]
  12371. };
  12372. calculateComponentDimensions(component, siz);
  12373. components.push(component);
  12374. }
  12375. context.SIZ = siz;
  12376. context.components = components;
  12377. calculateTileGrids(context, components);
  12378. context.QCC = [];
  12379. context.COC = [];
  12380. break;
  12381. case 0xFF5C: // Quantization default (QCD)
  12382. length = readUint16(data, position);
  12383. var qcd = {};
  12384. j = position + 2;
  12385. sqcd = data[j++];
  12386. switch (sqcd & 0x1F) {
  12387. case 0:
  12388. spqcdSize = 8;
  12389. scalarExpounded = true;
  12390. break;
  12391. case 1:
  12392. spqcdSize = 16;
  12393. scalarExpounded = false;
  12394. break;
  12395. case 2:
  12396. spqcdSize = 16;
  12397. scalarExpounded = true;
  12398. break;
  12399. default:
  12400. throw new Error('JPX Error: Invalid SQcd value ' + sqcd);
  12401. }
  12402. qcd.noQuantization = (spqcdSize === 8);
  12403. qcd.scalarExpounded = scalarExpounded;
  12404. qcd.guardBits = sqcd >> 5;
  12405. spqcds = [];
  12406. while (j < length + position) {
  12407. var spqcd = {};
  12408. if (spqcdSize === 8) {
  12409. spqcd.epsilon = data[j++] >> 3;
  12410. spqcd.mu = 0;
  12411. } else {
  12412. spqcd.epsilon = data[j] >> 3;
  12413. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  12414. j += 2;
  12415. }
  12416. spqcds.push(spqcd);
  12417. }
  12418. qcd.SPqcds = spqcds;
  12419. if (context.mainHeader) {
  12420. context.QCD = qcd;
  12421. } else {
  12422. context.currentTile.QCD = qcd;
  12423. context.currentTile.QCC = [];
  12424. }
  12425. break;
  12426. case 0xFF5D: // Quantization component (QCC)
  12427. length = readUint16(data, position);
  12428. var qcc = {};
  12429. j = position + 2;
  12430. var cqcc;
  12431. if (context.SIZ.Csiz < 257) {
  12432. cqcc = data[j++];
  12433. } else {
  12434. cqcc = readUint16(data, j);
  12435. j += 2;
  12436. }
  12437. sqcd = data[j++];
  12438. switch (sqcd & 0x1F) {
  12439. case 0:
  12440. spqcdSize = 8;
  12441. scalarExpounded = true;
  12442. break;
  12443. case 1:
  12444. spqcdSize = 16;
  12445. scalarExpounded = false;
  12446. break;
  12447. case 2:
  12448. spqcdSize = 16;
  12449. scalarExpounded = true;
  12450. break;
  12451. default:
  12452. throw new Error('JPX Error: Invalid SQcd value ' + sqcd);
  12453. }
  12454. qcc.noQuantization = (spqcdSize === 8);
  12455. qcc.scalarExpounded = scalarExpounded;
  12456. qcc.guardBits = sqcd >> 5;
  12457. spqcds = [];
  12458. while (j < (length + position)) {
  12459. spqcd = {};
  12460. if (spqcdSize === 8) {
  12461. spqcd.epsilon = data[j++] >> 3;
  12462. spqcd.mu = 0;
  12463. } else {
  12464. spqcd.epsilon = data[j] >> 3;
  12465. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  12466. j += 2;
  12467. }
  12468. spqcds.push(spqcd);
  12469. }
  12470. qcc.SPqcds = spqcds;
  12471. if (context.mainHeader) {
  12472. context.QCC[cqcc] = qcc;
  12473. } else {
  12474. context.currentTile.QCC[cqcc] = qcc;
  12475. }
  12476. break;
  12477. case 0xFF52: // Coding style default (COD)
  12478. length = readUint16(data, position);
  12479. var cod = {};
  12480. j = position + 2;
  12481. var scod = data[j++];
  12482. cod.entropyCoderWithCustomPrecincts = !!(scod & 1);
  12483. cod.sopMarkerUsed = !!(scod & 2);
  12484. cod.ephMarkerUsed = !!(scod & 4);
  12485. cod.progressionOrder = data[j++];
  12486. cod.layersCount = readUint16(data, j);
  12487. j += 2;
  12488. cod.multipleComponentTransform = data[j++];
  12489. cod.decompositionLevelsCount = data[j++];
  12490. cod.xcb = (data[j++] & 0xF) + 2;
  12491. cod.ycb = (data[j++] & 0xF) + 2;
  12492. var blockStyle = data[j++];
  12493. cod.selectiveArithmeticCodingBypass = !!(blockStyle & 1);
  12494. cod.resetContextProbabilities = !!(blockStyle & 2);
  12495. cod.terminationOnEachCodingPass = !!(blockStyle & 4);
  12496. cod.verticalyStripe = !!(blockStyle & 8);
  12497. cod.predictableTermination = !!(blockStyle & 16);
  12498. cod.segmentationSymbolUsed = !!(blockStyle & 32);
  12499. cod.reversibleTransformation = data[j++];
  12500. if (cod.entropyCoderWithCustomPrecincts) {
  12501. var precinctsSizes = [];
  12502. while (j < length + position) {
  12503. var precinctsSize = data[j++];
  12504. precinctsSizes.push({
  12505. PPx: precinctsSize & 0xF,
  12506. PPy: precinctsSize >> 4
  12507. });
  12508. }
  12509. cod.precinctsSizes = precinctsSizes;
  12510. }
  12511. var unsupported = [];
  12512. if (cod.selectiveArithmeticCodingBypass) {
  12513. unsupported.push('selectiveArithmeticCodingBypass');
  12514. }
  12515. if (cod.resetContextProbabilities) {
  12516. unsupported.push('resetContextProbabilities');
  12517. }
  12518. if (cod.terminationOnEachCodingPass) {
  12519. unsupported.push('terminationOnEachCodingPass');
  12520. }
  12521. if (cod.verticalyStripe) {
  12522. unsupported.push('verticalyStripe');
  12523. }
  12524. if (cod.predictableTermination) {
  12525. unsupported.push('predictableTermination');
  12526. }
  12527. if (unsupported.length > 0) {
  12528. doNotRecover = true;
  12529. throw new Error('JPX Error: Unsupported COD options (' +
  12530. unsupported.join(', ') + ')');
  12531. }
  12532. if (context.mainHeader) {
  12533. context.COD = cod;
  12534. } else {
  12535. context.currentTile.COD = cod;
  12536. context.currentTile.COC = [];
  12537. }
  12538. break;
  12539. case 0xFF90: // Start of tile-part (SOT)
  12540. length = readUint16(data, position);
  12541. tile = {};
  12542. tile.index = readUint16(data, position + 2);
  12543. tile.length = readUint32(data, position + 4);
  12544. tile.dataEnd = tile.length + position - 2;
  12545. tile.partIndex = data[position + 8];
  12546. tile.partsCount = data[position + 9];
  12547. context.mainHeader = false;
  12548. if (tile.partIndex === 0) {
  12549. // reset component specific settings
  12550. tile.COD = context.COD;
  12551. tile.COC = context.COC.slice(0); // clone of the global COC
  12552. tile.QCD = context.QCD;
  12553. tile.QCC = context.QCC.slice(0); // clone of the global COC
  12554. }
  12555. context.currentTile = tile;
  12556. break;
  12557. case 0xFF93: // Start of data (SOD)
  12558. tile = context.currentTile;
  12559. if (tile.partIndex === 0) {
  12560. initializeTile(context, tile.index);
  12561. buildPackets(context);
  12562. }
  12563. // moving to the end of the data
  12564. length = tile.dataEnd - position;
  12565. parseTilePackets(context, data, position, length);
  12566. break;
  12567. case 0xFF55: // Tile-part lengths, main header (TLM)
  12568. case 0xFF57: // Packet length, main header (PLM)
  12569. case 0xFF58: // Packet length, tile-part header (PLT)
  12570. case 0xFF64: // Comment (COM)
  12571. length = readUint16(data, position);
  12572. // skipping content
  12573. break;
  12574. case 0xFF53: // Coding style component (COC)
  12575. throw new Error('JPX Error: Codestream code 0xFF53 (COC) is ' +
  12576. 'not implemented');
  12577. default:
  12578. throw new Error('JPX Error: Unknown codestream code: ' +
  12579. code.toString(16));
  12580. }
  12581. position += length;
  12582. }
  12583. } catch (e) {
  12584. if (doNotRecover || this.failOnCorruptedImage) {
  12585. throw e;
  12586. } else {
  12587. warn('Trying to recover from ' + e.message);
  12588. }
  12589. }
  12590. this.tiles = transformComponents(context);
  12591. this.width = context.SIZ.Xsiz - context.SIZ.XOsiz;
  12592. this.height = context.SIZ.Ysiz - context.SIZ.YOsiz;
  12593. this.componentsCount = context.SIZ.Csiz;
  12594. }
  12595. };
  12596. function calculateComponentDimensions(component, siz) {
  12597. // Section B.2 Component mapping
  12598. component.x0 = Math.ceil(siz.XOsiz / component.XRsiz);
  12599. component.x1 = Math.ceil(siz.Xsiz / component.XRsiz);
  12600. component.y0 = Math.ceil(siz.YOsiz / component.YRsiz);
  12601. component.y1 = Math.ceil(siz.Ysiz / component.YRsiz);
  12602. component.width = component.x1 - component.x0;
  12603. component.height = component.y1 - component.y0;
  12604. }
  12605. function calculateTileGrids(context, components) {
  12606. var siz = context.SIZ;
  12607. // Section B.3 Division into tile and tile-components
  12608. var tile, tiles = [];
  12609. var numXtiles = Math.ceil((siz.Xsiz - siz.XTOsiz) / siz.XTsiz);
  12610. var numYtiles = Math.ceil((siz.Ysiz - siz.YTOsiz) / siz.YTsiz);
  12611. for (var q = 0; q < numYtiles; q++) {
  12612. for (var p = 0; p < numXtiles; p++) {
  12613. tile = {};
  12614. tile.tx0 = Math.max(siz.XTOsiz + p * siz.XTsiz, siz.XOsiz);
  12615. tile.ty0 = Math.max(siz.YTOsiz + q * siz.YTsiz, siz.YOsiz);
  12616. tile.tx1 = Math.min(siz.XTOsiz + (p + 1) * siz.XTsiz, siz.Xsiz);
  12617. tile.ty1 = Math.min(siz.YTOsiz + (q + 1) * siz.YTsiz, siz.Ysiz);
  12618. tile.width = tile.tx1 - tile.tx0;
  12619. tile.height = tile.ty1 - tile.ty0;
  12620. tile.components = [];
  12621. tiles.push(tile);
  12622. }
  12623. }
  12624. context.tiles = tiles;
  12625. var componentsCount = siz.Csiz;
  12626. for (var i = 0, ii = componentsCount; i < ii; i++) {
  12627. var component = components[i];
  12628. for (var j = 0, jj = tiles.length; j < jj; j++) {
  12629. var tileComponent = {};
  12630. tile = tiles[j];
  12631. tileComponent.tcx0 = Math.ceil(tile.tx0 / component.XRsiz);
  12632. tileComponent.tcy0 = Math.ceil(tile.ty0 / component.YRsiz);
  12633. tileComponent.tcx1 = Math.ceil(tile.tx1 / component.XRsiz);
  12634. tileComponent.tcy1 = Math.ceil(tile.ty1 / component.YRsiz);
  12635. tileComponent.width = tileComponent.tcx1 - tileComponent.tcx0;
  12636. tileComponent.height = tileComponent.tcy1 - tileComponent.tcy0;
  12637. tile.components[i] = tileComponent;
  12638. }
  12639. }
  12640. }
  12641. function getBlocksDimensions(context, component, r) {
  12642. var codOrCoc = component.codingStyleParameters;
  12643. var result = {};
  12644. if (!codOrCoc.entropyCoderWithCustomPrecincts) {
  12645. result.PPx = 15;
  12646. result.PPy = 15;
  12647. } else {
  12648. result.PPx = codOrCoc.precinctsSizes[r].PPx;
  12649. result.PPy = codOrCoc.precinctsSizes[r].PPy;
  12650. }
  12651. // calculate codeblock size as described in section B.7
  12652. result.xcb_ = (r > 0 ? Math.min(codOrCoc.xcb, result.PPx - 1) :
  12653. Math.min(codOrCoc.xcb, result.PPx));
  12654. result.ycb_ = (r > 0 ? Math.min(codOrCoc.ycb, result.PPy - 1) :
  12655. Math.min(codOrCoc.ycb, result.PPy));
  12656. return result;
  12657. }
  12658. function buildPrecincts(context, resolution, dimensions) {
  12659. // Section B.6 Division resolution to precincts
  12660. var precinctWidth = 1 << dimensions.PPx;
  12661. var precinctHeight = 1 << dimensions.PPy;
  12662. // Jasper introduces codeblock groups for mapping each subband codeblocks
  12663. // to precincts. Precinct partition divides a resolution according to width
  12664. // and height parameters. The subband that belongs to the resolution level
  12665. // has a different size than the level, unless it is the zero resolution.
  12666. // From Jasper documentation: jpeg2000.pdf, section K: Tier-2 coding:
  12667. // The precinct partitioning for a particular subband is derived from a
  12668. // partitioning of its parent LL band (i.e., the LL band at the next higher
  12669. // resolution level)... The LL band associated with each resolution level is
  12670. // divided into precincts... Each of the resulting precinct regions is then
  12671. // mapped into its child subbands (if any) at the next lower resolution
  12672. // level. This is accomplished by using the coordinate transformation
  12673. // (u, v) = (ceil(x/2), ceil(y/2)) where (x, y) and (u, v) are the
  12674. // coordinates of a point in the LL band and child subband, respectively.
  12675. var isZeroRes = resolution.resLevel === 0;
  12676. var precinctWidthInSubband = 1 << (dimensions.PPx + (isZeroRes ? 0 : -1));
  12677. var precinctHeightInSubband = 1 << (dimensions.PPy + (isZeroRes ? 0 : -1));
  12678. var numprecinctswide = (resolution.trx1 > resolution.trx0 ?
  12679. Math.ceil(resolution.trx1 / precinctWidth) -
  12680. Math.floor(resolution.trx0 / precinctWidth) : 0);
  12681. var numprecinctshigh = (resolution.try1 > resolution.try0 ?
  12682. Math.ceil(resolution.try1 / precinctHeight) -
  12683. Math.floor(resolution.try0 / precinctHeight) : 0);
  12684. var numprecincts = numprecinctswide * numprecinctshigh;
  12685. resolution.precinctParameters = {
  12686. precinctWidth: precinctWidth,
  12687. precinctHeight: precinctHeight,
  12688. numprecinctswide: numprecinctswide,
  12689. numprecinctshigh: numprecinctshigh,
  12690. numprecincts: numprecincts,
  12691. precinctWidthInSubband: precinctWidthInSubband,
  12692. precinctHeightInSubband: precinctHeightInSubband
  12693. };
  12694. }
  12695. function buildCodeblocks(context, subband, dimensions) {
  12696. // Section B.7 Division sub-band into code-blocks
  12697. var xcb_ = dimensions.xcb_;
  12698. var ycb_ = dimensions.ycb_;
  12699. var codeblockWidth = 1 << xcb_;
  12700. var codeblockHeight = 1 << ycb_;
  12701. var cbx0 = subband.tbx0 >> xcb_;
  12702. var cby0 = subband.tby0 >> ycb_;
  12703. var cbx1 = (subband.tbx1 + codeblockWidth - 1) >> xcb_;
  12704. var cby1 = (subband.tby1 + codeblockHeight - 1) >> ycb_;
  12705. var precinctParameters = subband.resolution.precinctParameters;
  12706. var codeblocks = [];
  12707. var precincts = [];
  12708. var i, j, codeblock, precinctNumber;
  12709. for (j = cby0; j < cby1; j++) {
  12710. for (i = cbx0; i < cbx1; i++) {
  12711. codeblock = {
  12712. cbx: i,
  12713. cby: j,
  12714. tbx0: codeblockWidth * i,
  12715. tby0: codeblockHeight * j,
  12716. tbx1: codeblockWidth * (i + 1),
  12717. tby1: codeblockHeight * (j + 1)
  12718. };
  12719. codeblock.tbx0_ = Math.max(subband.tbx0, codeblock.tbx0);
  12720. codeblock.tby0_ = Math.max(subband.tby0, codeblock.tby0);
  12721. codeblock.tbx1_ = Math.min(subband.tbx1, codeblock.tbx1);
  12722. codeblock.tby1_ = Math.min(subband.tby1, codeblock.tby1);
  12723. // Calculate precinct number for this codeblock, codeblock position
  12724. // should be relative to its subband, use actual dimension and position
  12725. // See comment about codeblock group width and height
  12726. var pi = Math.floor((codeblock.tbx0_ - subband.tbx0) /
  12727. precinctParameters.precinctWidthInSubband);
  12728. var pj = Math.floor((codeblock.tby0_ - subband.tby0) /
  12729. precinctParameters.precinctHeightInSubband);
  12730. precinctNumber = pi + (pj * precinctParameters.numprecinctswide);
  12731. codeblock.precinctNumber = precinctNumber;
  12732. codeblock.subbandType = subband.type;
  12733. codeblock.Lblock = 3;
  12734. if (codeblock.tbx1_ <= codeblock.tbx0_ ||
  12735. codeblock.tby1_ <= codeblock.tby0_) {
  12736. continue;
  12737. }
  12738. codeblocks.push(codeblock);
  12739. // building precinct for the sub-band
  12740. var precinct = precincts[precinctNumber];
  12741. if (precinct !== undefined) {
  12742. if (i < precinct.cbxMin) {
  12743. precinct.cbxMin = i;
  12744. } else if (i > precinct.cbxMax) {
  12745. precinct.cbxMax = i;
  12746. }
  12747. if (j < precinct.cbyMin) {
  12748. precinct.cbxMin = j;
  12749. } else if (j > precinct.cbyMax) {
  12750. precinct.cbyMax = j;
  12751. }
  12752. } else {
  12753. precincts[precinctNumber] = precinct = {
  12754. cbxMin: i,
  12755. cbyMin: j,
  12756. cbxMax: i,
  12757. cbyMax: j
  12758. };
  12759. }
  12760. codeblock.precinct = precinct;
  12761. }
  12762. }
  12763. subband.codeblockParameters = {
  12764. codeblockWidth: xcb_,
  12765. codeblockHeight: ycb_,
  12766. numcodeblockwide: cbx1 - cbx0 + 1,
  12767. numcodeblockhigh: cby1 - cby0 + 1
  12768. };
  12769. subband.codeblocks = codeblocks;
  12770. subband.precincts = precincts;
  12771. }
  12772. function createPacket(resolution, precinctNumber, layerNumber) {
  12773. var precinctCodeblocks = [];
  12774. // Section B.10.8 Order of info in packet
  12775. var subbands = resolution.subbands;
  12776. // sub-bands already ordered in 'LL', 'HL', 'LH', and 'HH' sequence
  12777. for (var i = 0, ii = subbands.length; i < ii; i++) {
  12778. var subband = subbands[i];
  12779. var codeblocks = subband.codeblocks;
  12780. for (var j = 0, jj = codeblocks.length; j < jj; j++) {
  12781. var codeblock = codeblocks[j];
  12782. if (codeblock.precinctNumber !== precinctNumber) {
  12783. continue;
  12784. }
  12785. precinctCodeblocks.push(codeblock);
  12786. }
  12787. }
  12788. return {
  12789. layerNumber: layerNumber,
  12790. codeblocks: precinctCodeblocks
  12791. };
  12792. }
  12793. function LayerResolutionComponentPositionIterator(context) {
  12794. var siz = context.SIZ;
  12795. var tileIndex = context.currentTile.index;
  12796. var tile = context.tiles[tileIndex];
  12797. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  12798. var componentsCount = siz.Csiz;
  12799. var maxDecompositionLevelsCount = 0;
  12800. for (var q = 0; q < componentsCount; q++) {
  12801. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  12802. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  12803. }
  12804. var l = 0, r = 0, i = 0, k = 0;
  12805. this.nextPacket = function JpxImage_nextPacket() {
  12806. // Section B.12.1.1 Layer-resolution-component-position
  12807. for (; l < layersCount; l++) {
  12808. for (; r <= maxDecompositionLevelsCount; r++) {
  12809. for (; i < componentsCount; i++) {
  12810. var component = tile.components[i];
  12811. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  12812. continue;
  12813. }
  12814. var resolution = component.resolutions[r];
  12815. var numprecincts = resolution.precinctParameters.numprecincts;
  12816. for (; k < numprecincts;) {
  12817. var packet = createPacket(resolution, k, l);
  12818. k++;
  12819. return packet;
  12820. }
  12821. k = 0;
  12822. }
  12823. i = 0;
  12824. }
  12825. r = 0;
  12826. }
  12827. throw new Error('JPX Error: Out of packets');
  12828. };
  12829. }
  12830. function ResolutionLayerComponentPositionIterator(context) {
  12831. var siz = context.SIZ;
  12832. var tileIndex = context.currentTile.index;
  12833. var tile = context.tiles[tileIndex];
  12834. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  12835. var componentsCount = siz.Csiz;
  12836. var maxDecompositionLevelsCount = 0;
  12837. for (var q = 0; q < componentsCount; q++) {
  12838. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  12839. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  12840. }
  12841. var r = 0, l = 0, i = 0, k = 0;
  12842. this.nextPacket = function JpxImage_nextPacket() {
  12843. // Section B.12.1.2 Resolution-layer-component-position
  12844. for (; r <= maxDecompositionLevelsCount; r++) {
  12845. for (; l < layersCount; l++) {
  12846. for (; i < componentsCount; i++) {
  12847. var component = tile.components[i];
  12848. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  12849. continue;
  12850. }
  12851. var resolution = component.resolutions[r];
  12852. var numprecincts = resolution.precinctParameters.numprecincts;
  12853. for (; k < numprecincts;) {
  12854. var packet = createPacket(resolution, k, l);
  12855. k++;
  12856. return packet;
  12857. }
  12858. k = 0;
  12859. }
  12860. i = 0;
  12861. }
  12862. l = 0;
  12863. }
  12864. throw new Error('JPX Error: Out of packets');
  12865. };
  12866. }
  12867. function ResolutionPositionComponentLayerIterator(context) {
  12868. var siz = context.SIZ;
  12869. var tileIndex = context.currentTile.index;
  12870. var tile = context.tiles[tileIndex];
  12871. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  12872. var componentsCount = siz.Csiz;
  12873. var l, r, c, p;
  12874. var maxDecompositionLevelsCount = 0;
  12875. for (c = 0; c < componentsCount; c++) {
  12876. var component = tile.components[c];
  12877. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  12878. component.codingStyleParameters.decompositionLevelsCount);
  12879. }
  12880. var maxNumPrecinctsInLevel = new Int32Array(
  12881. maxDecompositionLevelsCount + 1);
  12882. for (r = 0; r <= maxDecompositionLevelsCount; ++r) {
  12883. var maxNumPrecincts = 0;
  12884. for (c = 0; c < componentsCount; ++c) {
  12885. var resolutions = tile.components[c].resolutions;
  12886. if (r < resolutions.length) {
  12887. maxNumPrecincts = Math.max(maxNumPrecincts,
  12888. resolutions[r].precinctParameters.numprecincts);
  12889. }
  12890. }
  12891. maxNumPrecinctsInLevel[r] = maxNumPrecincts;
  12892. }
  12893. l = 0;
  12894. r = 0;
  12895. c = 0;
  12896. p = 0;
  12897. this.nextPacket = function JpxImage_nextPacket() {
  12898. // Section B.12.1.3 Resolution-position-component-layer
  12899. for (; r <= maxDecompositionLevelsCount; r++) {
  12900. for (; p < maxNumPrecinctsInLevel[r]; p++) {
  12901. for (; c < componentsCount; c++) {
  12902. var component = tile.components[c];
  12903. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  12904. continue;
  12905. }
  12906. var resolution = component.resolutions[r];
  12907. var numprecincts = resolution.precinctParameters.numprecincts;
  12908. if (p >= numprecincts) {
  12909. continue;
  12910. }
  12911. for (; l < layersCount;) {
  12912. var packet = createPacket(resolution, p, l);
  12913. l++;
  12914. return packet;
  12915. }
  12916. l = 0;
  12917. }
  12918. c = 0;
  12919. }
  12920. p = 0;
  12921. }
  12922. throw new Error('JPX Error: Out of packets');
  12923. };
  12924. }
  12925. function PositionComponentResolutionLayerIterator(context) {
  12926. var siz = context.SIZ;
  12927. var tileIndex = context.currentTile.index;
  12928. var tile = context.tiles[tileIndex];
  12929. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  12930. var componentsCount = siz.Csiz;
  12931. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  12932. var precinctsIterationSizes = precinctsSizes;
  12933. var l = 0, r = 0, c = 0, px = 0, py = 0;
  12934. this.nextPacket = function JpxImage_nextPacket() {
  12935. // Section B.12.1.4 Position-component-resolution-layer
  12936. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  12937. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  12938. for (; c < componentsCount; c++) {
  12939. var component = tile.components[c];
  12940. var decompositionLevelsCount =
  12941. component.codingStyleParameters.decompositionLevelsCount;
  12942. for (; r <= decompositionLevelsCount; r++) {
  12943. var resolution = component.resolutions[r];
  12944. var sizeInImageScale =
  12945. precinctsSizes.components[c].resolutions[r];
  12946. var k = getPrecinctIndexIfExist(
  12947. px,
  12948. py,
  12949. sizeInImageScale,
  12950. precinctsIterationSizes,
  12951. resolution);
  12952. if (k === null) {
  12953. continue;
  12954. }
  12955. for (; l < layersCount;) {
  12956. var packet = createPacket(resolution, k, l);
  12957. l++;
  12958. return packet;
  12959. }
  12960. l = 0;
  12961. }
  12962. r = 0;
  12963. }
  12964. c = 0;
  12965. }
  12966. px = 0;
  12967. }
  12968. throw new Error('JPX Error: Out of packets');
  12969. };
  12970. }
  12971. function ComponentPositionResolutionLayerIterator(context) {
  12972. var siz = context.SIZ;
  12973. var tileIndex = context.currentTile.index;
  12974. var tile = context.tiles[tileIndex];
  12975. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  12976. var componentsCount = siz.Csiz;
  12977. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  12978. var l = 0, r = 0, c = 0, px = 0, py = 0;
  12979. this.nextPacket = function JpxImage_nextPacket() {
  12980. // Section B.12.1.5 Component-position-resolution-layer
  12981. for (; c < componentsCount; ++c) {
  12982. var component = tile.components[c];
  12983. var precinctsIterationSizes = precinctsSizes.components[c];
  12984. var decompositionLevelsCount =
  12985. component.codingStyleParameters.decompositionLevelsCount;
  12986. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  12987. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  12988. for (; r <= decompositionLevelsCount; r++) {
  12989. var resolution = component.resolutions[r];
  12990. var sizeInImageScale = precinctsIterationSizes.resolutions[r];
  12991. var k = getPrecinctIndexIfExist(
  12992. px,
  12993. py,
  12994. sizeInImageScale,
  12995. precinctsIterationSizes,
  12996. resolution);
  12997. if (k === null) {
  12998. continue;
  12999. }
  13000. for (; l < layersCount;) {
  13001. var packet = createPacket(resolution, k, l);
  13002. l++;
  13003. return packet;
  13004. }
  13005. l = 0;
  13006. }
  13007. r = 0;
  13008. }
  13009. px = 0;
  13010. }
  13011. py = 0;
  13012. }
  13013. throw new Error('JPX Error: Out of packets');
  13014. };
  13015. }
  13016. function getPrecinctIndexIfExist(
  13017. pxIndex, pyIndex, sizeInImageScale, precinctIterationSizes, resolution) {
  13018. var posX = pxIndex * precinctIterationSizes.minWidth;
  13019. var posY = pyIndex * precinctIterationSizes.minHeight;
  13020. if (posX % sizeInImageScale.width !== 0 ||
  13021. posY % sizeInImageScale.height !== 0) {
  13022. return null;
  13023. }
  13024. var startPrecinctRowIndex =
  13025. (posY / sizeInImageScale.width) *
  13026. resolution.precinctParameters.numprecinctswide;
  13027. return (posX / sizeInImageScale.height) + startPrecinctRowIndex;
  13028. }
  13029. function getPrecinctSizesInImageScale(tile) {
  13030. var componentsCount = tile.components.length;
  13031. var minWidth = Number.MAX_VALUE;
  13032. var minHeight = Number.MAX_VALUE;
  13033. var maxNumWide = 0;
  13034. var maxNumHigh = 0;
  13035. var sizePerComponent = new Array(componentsCount);
  13036. for (var c = 0; c < componentsCount; c++) {
  13037. var component = tile.components[c];
  13038. var decompositionLevelsCount =
  13039. component.codingStyleParameters.decompositionLevelsCount;
  13040. var sizePerResolution = new Array(decompositionLevelsCount + 1);
  13041. var minWidthCurrentComponent = Number.MAX_VALUE;
  13042. var minHeightCurrentComponent = Number.MAX_VALUE;
  13043. var maxNumWideCurrentComponent = 0;
  13044. var maxNumHighCurrentComponent = 0;
  13045. var scale = 1;
  13046. for (var r = decompositionLevelsCount; r >= 0; --r) {
  13047. var resolution = component.resolutions[r];
  13048. var widthCurrentResolution =
  13049. scale * resolution.precinctParameters.precinctWidth;
  13050. var heightCurrentResolution =
  13051. scale * resolution.precinctParameters.precinctHeight;
  13052. minWidthCurrentComponent = Math.min(
  13053. minWidthCurrentComponent,
  13054. widthCurrentResolution);
  13055. minHeightCurrentComponent = Math.min(
  13056. minHeightCurrentComponent,
  13057. heightCurrentResolution);
  13058. maxNumWideCurrentComponent = Math.max(maxNumWideCurrentComponent,
  13059. resolution.precinctParameters.numprecinctswide);
  13060. maxNumHighCurrentComponent = Math.max(maxNumHighCurrentComponent,
  13061. resolution.precinctParameters.numprecinctshigh);
  13062. sizePerResolution[r] = {
  13063. width: widthCurrentResolution,
  13064. height: heightCurrentResolution
  13065. };
  13066. scale <<= 1;
  13067. }
  13068. minWidth = Math.min(minWidth, minWidthCurrentComponent);
  13069. minHeight = Math.min(minHeight, minHeightCurrentComponent);
  13070. maxNumWide = Math.max(maxNumWide, maxNumWideCurrentComponent);
  13071. maxNumHigh = Math.max(maxNumHigh, maxNumHighCurrentComponent);
  13072. sizePerComponent[c] = {
  13073. resolutions: sizePerResolution,
  13074. minWidth: minWidthCurrentComponent,
  13075. minHeight: minHeightCurrentComponent,
  13076. maxNumWide: maxNumWideCurrentComponent,
  13077. maxNumHigh: maxNumHighCurrentComponent
  13078. };
  13079. }
  13080. return {
  13081. components: sizePerComponent,
  13082. minWidth: minWidth,
  13083. minHeight: minHeight,
  13084. maxNumWide: maxNumWide,
  13085. maxNumHigh: maxNumHigh
  13086. };
  13087. }
  13088. function buildPackets(context) {
  13089. var siz = context.SIZ;
  13090. var tileIndex = context.currentTile.index;
  13091. var tile = context.tiles[tileIndex];
  13092. var componentsCount = siz.Csiz;
  13093. // Creating resolutions and sub-bands for each component
  13094. for (var c = 0; c < componentsCount; c++) {
  13095. var component = tile.components[c];
  13096. var decompositionLevelsCount =
  13097. component.codingStyleParameters.decompositionLevelsCount;
  13098. // Section B.5 Resolution levels and sub-bands
  13099. var resolutions = [];
  13100. var subbands = [];
  13101. for (var r = 0; r <= decompositionLevelsCount; r++) {
  13102. var blocksDimensions = getBlocksDimensions(context, component, r);
  13103. var resolution = {};
  13104. var scale = 1 << (decompositionLevelsCount - r);
  13105. resolution.trx0 = Math.ceil(component.tcx0 / scale);
  13106. resolution.try0 = Math.ceil(component.tcy0 / scale);
  13107. resolution.trx1 = Math.ceil(component.tcx1 / scale);
  13108. resolution.try1 = Math.ceil(component.tcy1 / scale);
  13109. resolution.resLevel = r;
  13110. buildPrecincts(context, resolution, blocksDimensions);
  13111. resolutions.push(resolution);
  13112. var subband;
  13113. if (r === 0) {
  13114. // one sub-band (LL) with last decomposition
  13115. subband = {};
  13116. subband.type = 'LL';
  13117. subband.tbx0 = Math.ceil(component.tcx0 / scale);
  13118. subband.tby0 = Math.ceil(component.tcy0 / scale);
  13119. subband.tbx1 = Math.ceil(component.tcx1 / scale);
  13120. subband.tby1 = Math.ceil(component.tcy1 / scale);
  13121. subband.resolution = resolution;
  13122. buildCodeblocks(context, subband, blocksDimensions);
  13123. subbands.push(subband);
  13124. resolution.subbands = [subband];
  13125. } else {
  13126. var bscale = 1 << (decompositionLevelsCount - r + 1);
  13127. var resolutionSubbands = [];
  13128. // three sub-bands (HL, LH and HH) with rest of decompositions
  13129. subband = {};
  13130. subband.type = 'HL';
  13131. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  13132. subband.tby0 = Math.ceil(component.tcy0 / bscale);
  13133. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  13134. subband.tby1 = Math.ceil(component.tcy1 / bscale);
  13135. subband.resolution = resolution;
  13136. buildCodeblocks(context, subband, blocksDimensions);
  13137. subbands.push(subband);
  13138. resolutionSubbands.push(subband);
  13139. subband = {};
  13140. subband.type = 'LH';
  13141. subband.tbx0 = Math.ceil(component.tcx0 / bscale);
  13142. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  13143. subband.tbx1 = Math.ceil(component.tcx1 / bscale);
  13144. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  13145. subband.resolution = resolution;
  13146. buildCodeblocks(context, subband, blocksDimensions);
  13147. subbands.push(subband);
  13148. resolutionSubbands.push(subband);
  13149. subband = {};
  13150. subband.type = 'HH';
  13151. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  13152. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  13153. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  13154. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  13155. subband.resolution = resolution;
  13156. buildCodeblocks(context, subband, blocksDimensions);
  13157. subbands.push(subband);
  13158. resolutionSubbands.push(subband);
  13159. resolution.subbands = resolutionSubbands;
  13160. }
  13161. }
  13162. component.resolutions = resolutions;
  13163. component.subbands = subbands;
  13164. }
  13165. // Generate the packets sequence
  13166. var progressionOrder = tile.codingStyleDefaultParameters.progressionOrder;
  13167. switch (progressionOrder) {
  13168. case 0:
  13169. tile.packetsIterator =
  13170. new LayerResolutionComponentPositionIterator(context);
  13171. break;
  13172. case 1:
  13173. tile.packetsIterator =
  13174. new ResolutionLayerComponentPositionIterator(context);
  13175. break;
  13176. case 2:
  13177. tile.packetsIterator =
  13178. new ResolutionPositionComponentLayerIterator(context);
  13179. break;
  13180. case 3:
  13181. tile.packetsIterator =
  13182. new PositionComponentResolutionLayerIterator(context);
  13183. break;
  13184. case 4:
  13185. tile.packetsIterator =
  13186. new ComponentPositionResolutionLayerIterator(context);
  13187. break;
  13188. default:
  13189. throw new Error('JPX Error: Unsupported progression order ' +
  13190. progressionOrder);
  13191. }
  13192. }
  13193. function parseTilePackets(context, data, offset, dataLength) {
  13194. var position = 0;
  13195. var buffer, bufferSize = 0, skipNextBit = false;
  13196. function readBits(count) {
  13197. while (bufferSize < count) {
  13198. var b = data[offset + position];
  13199. position++;
  13200. if (skipNextBit) {
  13201. buffer = (buffer << 7) | b;
  13202. bufferSize += 7;
  13203. skipNextBit = false;
  13204. } else {
  13205. buffer = (buffer << 8) | b;
  13206. bufferSize += 8;
  13207. }
  13208. if (b === 0xFF) {
  13209. skipNextBit = true;
  13210. }
  13211. }
  13212. bufferSize -= count;
  13213. return (buffer >>> bufferSize) & ((1 << count) - 1);
  13214. }
  13215. function skipMarkerIfEqual(value) {
  13216. if (data[offset + position - 1] === 0xFF &&
  13217. data[offset + position] === value) {
  13218. skipBytes(1);
  13219. return true;
  13220. } else if (data[offset + position] === 0xFF &&
  13221. data[offset + position + 1] === value) {
  13222. skipBytes(2);
  13223. return true;
  13224. }
  13225. return false;
  13226. }
  13227. function skipBytes(count) {
  13228. position += count;
  13229. }
  13230. function alignToByte() {
  13231. bufferSize = 0;
  13232. if (skipNextBit) {
  13233. position++;
  13234. skipNextBit = false;
  13235. }
  13236. }
  13237. function readCodingpasses() {
  13238. if (readBits(1) === 0) {
  13239. return 1;
  13240. }
  13241. if (readBits(1) === 0) {
  13242. return 2;
  13243. }
  13244. var value = readBits(2);
  13245. if (value < 3) {
  13246. return value + 3;
  13247. }
  13248. value = readBits(5);
  13249. if (value < 31) {
  13250. return value + 6;
  13251. }
  13252. value = readBits(7);
  13253. return value + 37;
  13254. }
  13255. var tileIndex = context.currentTile.index;
  13256. var tile = context.tiles[tileIndex];
  13257. var sopMarkerUsed = context.COD.sopMarkerUsed;
  13258. var ephMarkerUsed = context.COD.ephMarkerUsed;
  13259. var packetsIterator = tile.packetsIterator;
  13260. while (position < dataLength) {
  13261. alignToByte();
  13262. if (sopMarkerUsed && skipMarkerIfEqual(0x91)) {
  13263. // Skip also marker segment length and packet sequence ID
  13264. skipBytes(4);
  13265. }
  13266. var packet = packetsIterator.nextPacket();
  13267. if (!readBits(1)) {
  13268. continue;
  13269. }
  13270. var layerNumber = packet.layerNumber;
  13271. var queue = [], codeblock;
  13272. for (var i = 0, ii = packet.codeblocks.length; i < ii; i++) {
  13273. codeblock = packet.codeblocks[i];
  13274. var precinct = codeblock.precinct;
  13275. var codeblockColumn = codeblock.cbx - precinct.cbxMin;
  13276. var codeblockRow = codeblock.cby - precinct.cbyMin;
  13277. var codeblockIncluded = false;
  13278. var firstTimeInclusion = false;
  13279. var valueReady;
  13280. if (codeblock['included'] !== undefined) {
  13281. codeblockIncluded = !!readBits(1);
  13282. } else {
  13283. // reading inclusion tree
  13284. precinct = codeblock.precinct;
  13285. var inclusionTree, zeroBitPlanesTree;
  13286. if (precinct['inclusionTree'] !== undefined) {
  13287. inclusionTree = precinct.inclusionTree;
  13288. } else {
  13289. // building inclusion and zero bit-planes trees
  13290. var width = precinct.cbxMax - precinct.cbxMin + 1;
  13291. var height = precinct.cbyMax - precinct.cbyMin + 1;
  13292. inclusionTree = new InclusionTree(width, height, layerNumber);
  13293. zeroBitPlanesTree = new TagTree(width, height);
  13294. precinct.inclusionTree = inclusionTree;
  13295. precinct.zeroBitPlanesTree = zeroBitPlanesTree;
  13296. }
  13297. if (inclusionTree.reset(codeblockColumn, codeblockRow, layerNumber)) {
  13298. while (true) {
  13299. if (readBits(1)) {
  13300. valueReady = !inclusionTree.nextLevel();
  13301. if (valueReady) {
  13302. codeblock.included = true;
  13303. codeblockIncluded = firstTimeInclusion = true;
  13304. break;
  13305. }
  13306. } else {
  13307. inclusionTree.incrementValue(layerNumber);
  13308. break;
  13309. }
  13310. }
  13311. }
  13312. }
  13313. if (!codeblockIncluded) {
  13314. continue;
  13315. }
  13316. if (firstTimeInclusion) {
  13317. zeroBitPlanesTree = precinct.zeroBitPlanesTree;
  13318. zeroBitPlanesTree.reset(codeblockColumn, codeblockRow);
  13319. while (true) {
  13320. if (readBits(1)) {
  13321. valueReady = !zeroBitPlanesTree.nextLevel();
  13322. if (valueReady) {
  13323. break;
  13324. }
  13325. } else {
  13326. zeroBitPlanesTree.incrementValue();
  13327. }
  13328. }
  13329. codeblock.zeroBitPlanes = zeroBitPlanesTree.value;
  13330. }
  13331. var codingpasses = readCodingpasses();
  13332. while (readBits(1)) {
  13333. codeblock.Lblock++;
  13334. }
  13335. var codingpassesLog2 = log2(codingpasses);
  13336. // rounding down log2
  13337. var bits = ((codingpasses < (1 << codingpassesLog2)) ?
  13338. codingpassesLog2 - 1 : codingpassesLog2) + codeblock.Lblock;
  13339. var codedDataLength = readBits(bits);
  13340. queue.push({
  13341. codeblock: codeblock,
  13342. codingpasses: codingpasses,
  13343. dataLength: codedDataLength
  13344. });
  13345. }
  13346. alignToByte();
  13347. if (ephMarkerUsed) {
  13348. skipMarkerIfEqual(0x92);
  13349. }
  13350. while (queue.length > 0) {
  13351. var packetItem = queue.shift();
  13352. codeblock = packetItem.codeblock;
  13353. if (codeblock['data'] === undefined) {
  13354. codeblock.data = [];
  13355. }
  13356. codeblock.data.push({
  13357. data: data,
  13358. start: offset + position,
  13359. end: offset + position + packetItem.dataLength,
  13360. codingpasses: packetItem.codingpasses
  13361. });
  13362. position += packetItem.dataLength;
  13363. }
  13364. }
  13365. return position;
  13366. }
  13367. function copyCoefficients(coefficients, levelWidth, levelHeight, subband,
  13368. delta, mb, reversible, segmentationSymbolUsed) {
  13369. var x0 = subband.tbx0;
  13370. var y0 = subband.tby0;
  13371. var width = subband.tbx1 - subband.tbx0;
  13372. var codeblocks = subband.codeblocks;
  13373. var right = subband.type.charAt(0) === 'H' ? 1 : 0;
  13374. var bottom = subband.type.charAt(1) === 'H' ? levelWidth : 0;
  13375. for (var i = 0, ii = codeblocks.length; i < ii; ++i) {
  13376. var codeblock = codeblocks[i];
  13377. var blockWidth = codeblock.tbx1_ - codeblock.tbx0_;
  13378. var blockHeight = codeblock.tby1_ - codeblock.tby0_;
  13379. if (blockWidth === 0 || blockHeight === 0) {
  13380. continue;
  13381. }
  13382. if (codeblock['data'] === undefined) {
  13383. continue;
  13384. }
  13385. var bitModel, currentCodingpassType;
  13386. bitModel = new BitModel(blockWidth, blockHeight, codeblock.subbandType,
  13387. codeblock.zeroBitPlanes, mb);
  13388. currentCodingpassType = 2; // first bit plane starts from cleanup
  13389. // collect data
  13390. var data = codeblock.data, totalLength = 0, codingpasses = 0;
  13391. var j, jj, dataItem;
  13392. for (j = 0, jj = data.length; j < jj; j++) {
  13393. dataItem = data[j];
  13394. totalLength += dataItem.end - dataItem.start;
  13395. codingpasses += dataItem.codingpasses;
  13396. }
  13397. var encodedData = new Uint8Array(totalLength);
  13398. var position = 0;
  13399. for (j = 0, jj = data.length; j < jj; j++) {
  13400. dataItem = data[j];
  13401. var chunk = dataItem.data.subarray(dataItem.start, dataItem.end);
  13402. encodedData.set(chunk, position);
  13403. position += chunk.length;
  13404. }
  13405. // decoding the item
  13406. var decoder = new ArithmeticDecoder(encodedData, 0, totalLength);
  13407. bitModel.setDecoder(decoder);
  13408. for (j = 0; j < codingpasses; j++) {
  13409. switch (currentCodingpassType) {
  13410. case 0:
  13411. bitModel.runSignificancePropogationPass();
  13412. break;
  13413. case 1:
  13414. bitModel.runMagnitudeRefinementPass();
  13415. break;
  13416. case 2:
  13417. bitModel.runCleanupPass();
  13418. if (segmentationSymbolUsed) {
  13419. bitModel.checkSegmentationSymbol();
  13420. }
  13421. break;
  13422. }
  13423. currentCodingpassType = (currentCodingpassType + 1) % 3;
  13424. }
  13425. var offset = (codeblock.tbx0_ - x0) + (codeblock.tby0_ - y0) * width;
  13426. var sign = bitModel.coefficentsSign;
  13427. var magnitude = bitModel.coefficentsMagnitude;
  13428. var bitsDecoded = bitModel.bitsDecoded;
  13429. var magnitudeCorrection = reversible ? 0 : 0.5;
  13430. var k, n, nb;
  13431. position = 0;
  13432. // Do the interleaving of Section F.3.3 here, so we do not need
  13433. // to copy later. LL level is not interleaved, just copied.
  13434. var interleave = (subband.type !== 'LL');
  13435. for (j = 0; j < blockHeight; j++) {
  13436. var row = (offset / width) | 0; // row in the non-interleaved subband
  13437. var levelOffset = 2 * row * (levelWidth - width) + right + bottom;
  13438. for (k = 0; k < blockWidth; k++) {
  13439. n = magnitude[position];
  13440. if (n !== 0) {
  13441. n = (n + magnitudeCorrection) * delta;
  13442. if (sign[position] !== 0) {
  13443. n = -n;
  13444. }
  13445. nb = bitsDecoded[position];
  13446. var pos = interleave ? (levelOffset + (offset << 1)) : offset;
  13447. if (reversible && (nb >= mb)) {
  13448. coefficients[pos] = n;
  13449. } else {
  13450. coefficients[pos] = n * (1 << (mb - nb));
  13451. }
  13452. }
  13453. offset++;
  13454. position++;
  13455. }
  13456. offset += width - blockWidth;
  13457. }
  13458. }
  13459. }
  13460. function transformTile(context, tile, c) {
  13461. var component = tile.components[c];
  13462. var codingStyleParameters = component.codingStyleParameters;
  13463. var quantizationParameters = component.quantizationParameters;
  13464. var decompositionLevelsCount =
  13465. codingStyleParameters.decompositionLevelsCount;
  13466. var spqcds = quantizationParameters.SPqcds;
  13467. var scalarExpounded = quantizationParameters.scalarExpounded;
  13468. var guardBits = quantizationParameters.guardBits;
  13469. var segmentationSymbolUsed = codingStyleParameters.segmentationSymbolUsed;
  13470. var precision = context.components[c].precision;
  13471. var reversible = codingStyleParameters.reversibleTransformation;
  13472. var transform = (reversible ? new ReversibleTransform() :
  13473. new IrreversibleTransform());
  13474. var subbandCoefficients = [];
  13475. var b = 0;
  13476. for (var i = 0; i <= decompositionLevelsCount; i++) {
  13477. var resolution = component.resolutions[i];
  13478. var width = resolution.trx1 - resolution.trx0;
  13479. var height = resolution.try1 - resolution.try0;
  13480. // Allocate space for the whole sublevel.
  13481. var coefficients = new Float32Array(width * height);
  13482. for (var j = 0, jj = resolution.subbands.length; j < jj; j++) {
  13483. var mu, epsilon;
  13484. if (!scalarExpounded) {
  13485. // formula E-5
  13486. mu = spqcds[0].mu;
  13487. epsilon = spqcds[0].epsilon + (i > 0 ? 1 - i : 0);
  13488. } else {
  13489. mu = spqcds[b].mu;
  13490. epsilon = spqcds[b].epsilon;
  13491. b++;
  13492. }
  13493. var subband = resolution.subbands[j];
  13494. var gainLog2 = SubbandsGainLog2[subband.type];
  13495. // calulate quantization coefficient (Section E.1.1.1)
  13496. var delta = (reversible ? 1 :
  13497. Math.pow(2, precision + gainLog2 - epsilon) * (1 + mu / 2048));
  13498. var mb = (guardBits + epsilon - 1);
  13499. // In the first resolution level, copyCoefficients will fill the
  13500. // whole array with coefficients. In the succeding passes,
  13501. // copyCoefficients will consecutively fill in the values that belong
  13502. // to the interleaved positions of the HL, LH, and HH coefficients.
  13503. // The LL coefficients will then be interleaved in Transform.iterate().
  13504. copyCoefficients(coefficients, width, height, subband, delta, mb,
  13505. reversible, segmentationSymbolUsed);
  13506. }
  13507. subbandCoefficients.push({
  13508. width: width,
  13509. height: height,
  13510. items: coefficients
  13511. });
  13512. }
  13513. var result = transform.calculate(subbandCoefficients,
  13514. component.tcx0, component.tcy0);
  13515. return {
  13516. left: component.tcx0,
  13517. top: component.tcy0,
  13518. width: result.width,
  13519. height: result.height,
  13520. items: result.items
  13521. };
  13522. }
  13523. function transformComponents(context) {
  13524. var siz = context.SIZ;
  13525. var components = context.components;
  13526. var componentsCount = siz.Csiz;
  13527. var resultImages = [];
  13528. for (var i = 0, ii = context.tiles.length; i < ii; i++) {
  13529. var tile = context.tiles[i];
  13530. var transformedTiles = [];
  13531. var c;
  13532. for (c = 0; c < componentsCount; c++) {
  13533. transformedTiles[c] = transformTile(context, tile, c);
  13534. }
  13535. var tile0 = transformedTiles[0];
  13536. var out = new Uint8Array(tile0.items.length * componentsCount);
  13537. var result = {
  13538. left: tile0.left,
  13539. top: tile0.top,
  13540. width: tile0.width,
  13541. height: tile0.height,
  13542. items: out
  13543. };
  13544. // Section G.2.2 Inverse multi component transform
  13545. var shift, offset, max, min, maxK;
  13546. var pos = 0, j, jj, y0, y1, y2, r, g, b, k, val;
  13547. if (tile.codingStyleDefaultParameters.multipleComponentTransform) {
  13548. var fourComponents = componentsCount === 4;
  13549. var y0items = transformedTiles[0].items;
  13550. var y1items = transformedTiles[1].items;
  13551. var y2items = transformedTiles[2].items;
  13552. var y3items = fourComponents ? transformedTiles[3].items : null;
  13553. // HACK: The multiple component transform formulas below assume that
  13554. // all components have the same precision. With this in mind, we
  13555. // compute shift and offset only once.
  13556. shift = components[0].precision - 8;
  13557. offset = (128 << shift) + 0.5;
  13558. max = 255 * (1 << shift);
  13559. maxK = max * 0.5;
  13560. min = -maxK;
  13561. var component0 = tile.components[0];
  13562. var alpha01 = componentsCount - 3;
  13563. jj = y0items.length;
  13564. if (!component0.codingStyleParameters.reversibleTransformation) {
  13565. // inverse irreversible multiple component transform
  13566. for (j = 0; j < jj; j++, pos += alpha01) {
  13567. y0 = y0items[j] + offset;
  13568. y1 = y1items[j];
  13569. y2 = y2items[j];
  13570. r = y0 + 1.402 * y2;
  13571. g = y0 - 0.34413 * y1 - 0.71414 * y2;
  13572. b = y0 + 1.772 * y1;
  13573. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  13574. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  13575. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  13576. }
  13577. } else {
  13578. // inverse reversible multiple component transform
  13579. for (j = 0; j < jj; j++, pos += alpha01) {
  13580. y0 = y0items[j] + offset;
  13581. y1 = y1items[j];
  13582. y2 = y2items[j];
  13583. g = y0 - ((y2 + y1) >> 2);
  13584. r = g + y2;
  13585. b = g + y1;
  13586. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  13587. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  13588. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  13589. }
  13590. }
  13591. if (fourComponents) {
  13592. for (j = 0, pos = 3; j < jj; j++, pos += 4) {
  13593. k = y3items[j];
  13594. out[pos] = k <= min ? 0 : k >= maxK ? 255 : (k + offset) >> shift;
  13595. }
  13596. }
  13597. } else { // no multi-component transform
  13598. for (c = 0; c < componentsCount; c++) {
  13599. var items = transformedTiles[c].items;
  13600. shift = components[c].precision - 8;
  13601. offset = (128 << shift) + 0.5;
  13602. max = (127.5 * (1 << shift));
  13603. min = -max;
  13604. for (pos = c, j = 0, jj = items.length; j < jj; j++) {
  13605. val = items[j];
  13606. out[pos] = val <= min ? 0 :
  13607. val >= max ? 255 : (val + offset) >> shift;
  13608. pos += componentsCount;
  13609. }
  13610. }
  13611. }
  13612. resultImages.push(result);
  13613. }
  13614. return resultImages;
  13615. }
  13616. function initializeTile(context, tileIndex) {
  13617. var siz = context.SIZ;
  13618. var componentsCount = siz.Csiz;
  13619. var tile = context.tiles[tileIndex];
  13620. for (var c = 0; c < componentsCount; c++) {
  13621. var component = tile.components[c];
  13622. var qcdOrQcc = (context.currentTile.QCC[c] !== undefined ?
  13623. context.currentTile.QCC[c] : context.currentTile.QCD);
  13624. component.quantizationParameters = qcdOrQcc;
  13625. var codOrCoc = (context.currentTile.COC[c] !== undefined ?
  13626. context.currentTile.COC[c] : context.currentTile.COD);
  13627. component.codingStyleParameters = codOrCoc;
  13628. }
  13629. tile.codingStyleDefaultParameters = context.currentTile.COD;
  13630. }
  13631. // Section B.10.2 Tag trees
  13632. var TagTree = (function TagTreeClosure() {
  13633. function TagTree(width, height) {
  13634. var levelsLength = log2(Math.max(width, height)) + 1;
  13635. this.levels = [];
  13636. for (var i = 0; i < levelsLength; i++) {
  13637. var level = {
  13638. width: width,
  13639. height: height,
  13640. items: []
  13641. };
  13642. this.levels.push(level);
  13643. width = Math.ceil(width / 2);
  13644. height = Math.ceil(height / 2);
  13645. }
  13646. }
  13647. TagTree.prototype = {
  13648. reset: function TagTree_reset(i, j) {
  13649. var currentLevel = 0, value = 0, level;
  13650. while (currentLevel < this.levels.length) {
  13651. level = this.levels[currentLevel];
  13652. var index = i + j * level.width;
  13653. if (level.items[index] !== undefined) {
  13654. value = level.items[index];
  13655. break;
  13656. }
  13657. level.index = index;
  13658. i >>= 1;
  13659. j >>= 1;
  13660. currentLevel++;
  13661. }
  13662. currentLevel--;
  13663. level = this.levels[currentLevel];
  13664. level.items[level.index] = value;
  13665. this.currentLevel = currentLevel;
  13666. delete this.value;
  13667. },
  13668. incrementValue: function TagTree_incrementValue() {
  13669. var level = this.levels[this.currentLevel];
  13670. level.items[level.index]++;
  13671. },
  13672. nextLevel: function TagTree_nextLevel() {
  13673. var currentLevel = this.currentLevel;
  13674. var level = this.levels[currentLevel];
  13675. var value = level.items[level.index];
  13676. currentLevel--;
  13677. if (currentLevel < 0) {
  13678. this.value = value;
  13679. return false;
  13680. }
  13681. this.currentLevel = currentLevel;
  13682. level = this.levels[currentLevel];
  13683. level.items[level.index] = value;
  13684. return true;
  13685. }
  13686. };
  13687. return TagTree;
  13688. })();
  13689. var InclusionTree = (function InclusionTreeClosure() {
  13690. function InclusionTree(width, height, defaultValue) {
  13691. var levelsLength = log2(Math.max(width, height)) + 1;
  13692. this.levels = [];
  13693. for (var i = 0; i < levelsLength; i++) {
  13694. var items = new Uint8Array(width * height);
  13695. for (var j = 0, jj = items.length; j < jj; j++) {
  13696. items[j] = defaultValue;
  13697. }
  13698. var level = {
  13699. width: width,
  13700. height: height,
  13701. items: items
  13702. };
  13703. this.levels.push(level);
  13704. width = Math.ceil(width / 2);
  13705. height = Math.ceil(height / 2);
  13706. }
  13707. }
  13708. InclusionTree.prototype = {
  13709. reset: function InclusionTree_reset(i, j, stopValue) {
  13710. var currentLevel = 0;
  13711. while (currentLevel < this.levels.length) {
  13712. var level = this.levels[currentLevel];
  13713. var index = i + j * level.width;
  13714. level.index = index;
  13715. var value = level.items[index];
  13716. if (value === 0xFF) {
  13717. break;
  13718. }
  13719. if (value > stopValue) {
  13720. this.currentLevel = currentLevel;
  13721. // already know about this one, propagating the value to top levels
  13722. this.propagateValues();
  13723. return false;
  13724. }
  13725. i >>= 1;
  13726. j >>= 1;
  13727. currentLevel++;
  13728. }
  13729. this.currentLevel = currentLevel - 1;
  13730. return true;
  13731. },
  13732. incrementValue: function InclusionTree_incrementValue(stopValue) {
  13733. var level = this.levels[this.currentLevel];
  13734. level.items[level.index] = stopValue + 1;
  13735. this.propagateValues();
  13736. },
  13737. propagateValues: function InclusionTree_propagateValues() {
  13738. var levelIndex = this.currentLevel;
  13739. var level = this.levels[levelIndex];
  13740. var currentValue = level.items[level.index];
  13741. while (--levelIndex >= 0) {
  13742. level = this.levels[levelIndex];
  13743. level.items[level.index] = currentValue;
  13744. }
  13745. },
  13746. nextLevel: function InclusionTree_nextLevel() {
  13747. var currentLevel = this.currentLevel;
  13748. var level = this.levels[currentLevel];
  13749. var value = level.items[level.index];
  13750. level.items[level.index] = 0xFF;
  13751. currentLevel--;
  13752. if (currentLevel < 0) {
  13753. return false;
  13754. }
  13755. this.currentLevel = currentLevel;
  13756. level = this.levels[currentLevel];
  13757. level.items[level.index] = value;
  13758. return true;
  13759. }
  13760. };
  13761. return InclusionTree;
  13762. })();
  13763. // Section D. Coefficient bit modeling
  13764. var BitModel = (function BitModelClosure() {
  13765. var UNIFORM_CONTEXT = 17;
  13766. var RUNLENGTH_CONTEXT = 18;
  13767. // Table D-1
  13768. // The index is binary presentation: 0dddvvhh, ddd - sum of Di (0..4),
  13769. // vv - sum of Vi (0..2), and hh - sum of Hi (0..2)
  13770. var LLAndLHContextsLabel = new Uint8Array([
  13771. 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,
  13772. 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,
  13773. 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
  13774. ]);
  13775. var HLContextLabel = new Uint8Array([
  13776. 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,
  13777. 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,
  13778. 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
  13779. ]);
  13780. var HHContextLabel = new Uint8Array([
  13781. 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,
  13782. 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,
  13783. 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
  13784. ]);
  13785. function BitModel(width, height, subband, zeroBitPlanes, mb) {
  13786. this.width = width;
  13787. this.height = height;
  13788. this.contextLabelTable = (subband === 'HH' ? HHContextLabel :
  13789. (subband === 'HL' ? HLContextLabel : LLAndLHContextsLabel));
  13790. var coefficientCount = width * height;
  13791. // coefficients outside the encoding region treated as insignificant
  13792. // add border state cells for significanceState
  13793. this.neighborsSignificance = new Uint8Array(coefficientCount);
  13794. this.coefficentsSign = new Uint8Array(coefficientCount);
  13795. this.coefficentsMagnitude = mb > 14 ? new Uint32Array(coefficientCount) :
  13796. mb > 6 ? new Uint16Array(coefficientCount) :
  13797. new Uint8Array(coefficientCount);
  13798. this.processingFlags = new Uint8Array(coefficientCount);
  13799. var bitsDecoded = new Uint8Array(coefficientCount);
  13800. if (zeroBitPlanes !== 0) {
  13801. for (var i = 0; i < coefficientCount; i++) {
  13802. bitsDecoded[i] = zeroBitPlanes;
  13803. }
  13804. }
  13805. this.bitsDecoded = bitsDecoded;
  13806. this.reset();
  13807. }
  13808. BitModel.prototype = {
  13809. setDecoder: function BitModel_setDecoder(decoder) {
  13810. this.decoder = decoder;
  13811. },
  13812. reset: function BitModel_reset() {
  13813. // We have 17 contexts that are accessed via context labels,
  13814. // plus the uniform and runlength context.
  13815. this.contexts = new Int8Array(19);
  13816. // Contexts are packed into 1 byte:
  13817. // highest 7 bits carry the index, lowest bit carries mps
  13818. this.contexts[0] = (4 << 1) | 0;
  13819. this.contexts[UNIFORM_CONTEXT] = (46 << 1) | 0;
  13820. this.contexts[RUNLENGTH_CONTEXT] = (3 << 1) | 0;
  13821. },
  13822. setNeighborsSignificance:
  13823. function BitModel_setNeighborsSignificance(row, column, index) {
  13824. var neighborsSignificance = this.neighborsSignificance;
  13825. var width = this.width, height = this.height;
  13826. var left = (column > 0);
  13827. var right = (column + 1 < width);
  13828. var i;
  13829. if (row > 0) {
  13830. i = index - width;
  13831. if (left) {
  13832. neighborsSignificance[i - 1] += 0x10;
  13833. }
  13834. if (right) {
  13835. neighborsSignificance[i + 1] += 0x10;
  13836. }
  13837. neighborsSignificance[i] += 0x04;
  13838. }
  13839. if (row + 1 < height) {
  13840. i = index + width;
  13841. if (left) {
  13842. neighborsSignificance[i - 1] += 0x10;
  13843. }
  13844. if (right) {
  13845. neighborsSignificance[i + 1] += 0x10;
  13846. }
  13847. neighborsSignificance[i] += 0x04;
  13848. }
  13849. if (left) {
  13850. neighborsSignificance[index - 1] += 0x01;
  13851. }
  13852. if (right) {
  13853. neighborsSignificance[index + 1] += 0x01;
  13854. }
  13855. neighborsSignificance[index] |= 0x80;
  13856. },
  13857. runSignificancePropogationPass:
  13858. function BitModel_runSignificancePropogationPass() {
  13859. var decoder = this.decoder;
  13860. var width = this.width, height = this.height;
  13861. var coefficentsMagnitude = this.coefficentsMagnitude;
  13862. var coefficentsSign = this.coefficentsSign;
  13863. var neighborsSignificance = this.neighborsSignificance;
  13864. var processingFlags = this.processingFlags;
  13865. var contexts = this.contexts;
  13866. var labels = this.contextLabelTable;
  13867. var bitsDecoded = this.bitsDecoded;
  13868. var processedInverseMask = ~1;
  13869. var processedMask = 1;
  13870. var firstMagnitudeBitMask = 2;
  13871. for (var i0 = 0; i0 < height; i0 += 4) {
  13872. for (var j = 0; j < width; j++) {
  13873. var index = i0 * width + j;
  13874. for (var i1 = 0; i1 < 4; i1++, index += width) {
  13875. var i = i0 + i1;
  13876. if (i >= height) {
  13877. break;
  13878. }
  13879. // clear processed flag first
  13880. processingFlags[index] &= processedInverseMask;
  13881. if (coefficentsMagnitude[index] ||
  13882. !neighborsSignificance[index]) {
  13883. continue;
  13884. }
  13885. var contextLabel = labels[neighborsSignificance[index]];
  13886. var decision = decoder.readBit(contexts, contextLabel);
  13887. if (decision) {
  13888. var sign = this.decodeSignBit(i, j, index);
  13889. coefficentsSign[index] = sign;
  13890. coefficentsMagnitude[index] = 1;
  13891. this.setNeighborsSignificance(i, j, index);
  13892. processingFlags[index] |= firstMagnitudeBitMask;
  13893. }
  13894. bitsDecoded[index]++;
  13895. processingFlags[index] |= processedMask;
  13896. }
  13897. }
  13898. }
  13899. },
  13900. decodeSignBit: function BitModel_decodeSignBit(row, column, index) {
  13901. var width = this.width, height = this.height;
  13902. var coefficentsMagnitude = this.coefficentsMagnitude;
  13903. var coefficentsSign = this.coefficentsSign;
  13904. var contribution, sign0, sign1, significance1;
  13905. var contextLabel, decoded;
  13906. // calculate horizontal contribution
  13907. significance1 = (column > 0 && coefficentsMagnitude[index - 1] !== 0);
  13908. if (column + 1 < width && coefficentsMagnitude[index + 1] !== 0) {
  13909. sign1 = coefficentsSign[index + 1];
  13910. if (significance1) {
  13911. sign0 = coefficentsSign[index - 1];
  13912. contribution = 1 - sign1 - sign0;
  13913. } else {
  13914. contribution = 1 - sign1 - sign1;
  13915. }
  13916. } else if (significance1) {
  13917. sign0 = coefficentsSign[index - 1];
  13918. contribution = 1 - sign0 - sign0;
  13919. } else {
  13920. contribution = 0;
  13921. }
  13922. var horizontalContribution = 3 * contribution;
  13923. // calculate vertical contribution and combine with the horizontal
  13924. significance1 = (row > 0 && coefficentsMagnitude[index - width] !== 0);
  13925. if (row + 1 < height && coefficentsMagnitude[index + width] !== 0) {
  13926. sign1 = coefficentsSign[index + width];
  13927. if (significance1) {
  13928. sign0 = coefficentsSign[index - width];
  13929. contribution = 1 - sign1 - sign0 + horizontalContribution;
  13930. } else {
  13931. contribution = 1 - sign1 - sign1 + horizontalContribution;
  13932. }
  13933. } else if (significance1) {
  13934. sign0 = coefficentsSign[index - width];
  13935. contribution = 1 - sign0 - sign0 + horizontalContribution;
  13936. } else {
  13937. contribution = horizontalContribution;
  13938. }
  13939. if (contribution >= 0) {
  13940. contextLabel = 9 + contribution;
  13941. decoded = this.decoder.readBit(this.contexts, contextLabel);
  13942. } else {
  13943. contextLabel = 9 - contribution;
  13944. decoded = this.decoder.readBit(this.contexts, contextLabel) ^ 1;
  13945. }
  13946. return decoded;
  13947. },
  13948. runMagnitudeRefinementPass:
  13949. function BitModel_runMagnitudeRefinementPass() {
  13950. var decoder = this.decoder;
  13951. var width = this.width, height = this.height;
  13952. var coefficentsMagnitude = this.coefficentsMagnitude;
  13953. var neighborsSignificance = this.neighborsSignificance;
  13954. var contexts = this.contexts;
  13955. var bitsDecoded = this.bitsDecoded;
  13956. var processingFlags = this.processingFlags;
  13957. var processedMask = 1;
  13958. var firstMagnitudeBitMask = 2;
  13959. var length = width * height;
  13960. var width4 = width * 4;
  13961. for (var index0 = 0, indexNext; index0 < length; index0 = indexNext) {
  13962. indexNext = Math.min(length, index0 + width4);
  13963. for (var j = 0; j < width; j++) {
  13964. for (var index = index0 + j; index < indexNext; index += width) {
  13965. // significant but not those that have just become
  13966. if (!coefficentsMagnitude[index] ||
  13967. (processingFlags[index] & processedMask) !== 0) {
  13968. continue;
  13969. }
  13970. var contextLabel = 16;
  13971. if ((processingFlags[index] & firstMagnitudeBitMask) !== 0) {
  13972. processingFlags[index] ^= firstMagnitudeBitMask;
  13973. // first refinement
  13974. var significance = neighborsSignificance[index] & 127;
  13975. contextLabel = significance === 0 ? 15 : 14;
  13976. }
  13977. var bit = decoder.readBit(contexts, contextLabel);
  13978. coefficentsMagnitude[index] =
  13979. (coefficentsMagnitude[index] << 1) | bit;
  13980. bitsDecoded[index]++;
  13981. processingFlags[index] |= processedMask;
  13982. }
  13983. }
  13984. }
  13985. },
  13986. runCleanupPass: function BitModel_runCleanupPass() {
  13987. var decoder = this.decoder;
  13988. var width = this.width, height = this.height;
  13989. var neighborsSignificance = this.neighborsSignificance;
  13990. var coefficentsMagnitude = this.coefficentsMagnitude;
  13991. var coefficentsSign = this.coefficentsSign;
  13992. var contexts = this.contexts;
  13993. var labels = this.contextLabelTable;
  13994. var bitsDecoded = this.bitsDecoded;
  13995. var processingFlags = this.processingFlags;
  13996. var processedMask = 1;
  13997. var firstMagnitudeBitMask = 2;
  13998. var oneRowDown = width;
  13999. var twoRowsDown = width * 2;
  14000. var threeRowsDown = width * 3;
  14001. var iNext;
  14002. for (var i0 = 0; i0 < height; i0 = iNext) {
  14003. iNext = Math.min(i0 + 4, height);
  14004. var indexBase = i0 * width;
  14005. var checkAllEmpty = i0 + 3 < height;
  14006. for (var j = 0; j < width; j++) {
  14007. var index0 = indexBase + j;
  14008. // using the property: labels[neighborsSignificance[index]] === 0
  14009. // when neighborsSignificance[index] === 0
  14010. var allEmpty = (checkAllEmpty &&
  14011. processingFlags[index0] === 0 &&
  14012. processingFlags[index0 + oneRowDown] === 0 &&
  14013. processingFlags[index0 + twoRowsDown] === 0 &&
  14014. processingFlags[index0 + threeRowsDown] === 0 &&
  14015. neighborsSignificance[index0] === 0 &&
  14016. neighborsSignificance[index0 + oneRowDown] === 0 &&
  14017. neighborsSignificance[index0 + twoRowsDown] === 0 &&
  14018. neighborsSignificance[index0 + threeRowsDown] === 0);
  14019. var i1 = 0, index = index0;
  14020. var i = i0, sign;
  14021. if (allEmpty) {
  14022. var hasSignificantCoefficent =
  14023. decoder.readBit(contexts, RUNLENGTH_CONTEXT);
  14024. if (!hasSignificantCoefficent) {
  14025. bitsDecoded[index0]++;
  14026. bitsDecoded[index0 + oneRowDown]++;
  14027. bitsDecoded[index0 + twoRowsDown]++;
  14028. bitsDecoded[index0 + threeRowsDown]++;
  14029. continue; // next column
  14030. }
  14031. i1 = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  14032. decoder.readBit(contexts, UNIFORM_CONTEXT);
  14033. if (i1 !== 0) {
  14034. i = i0 + i1;
  14035. index += i1 * width;
  14036. }
  14037. sign = this.decodeSignBit(i, j, index);
  14038. coefficentsSign[index] = sign;
  14039. coefficentsMagnitude[index] = 1;
  14040. this.setNeighborsSignificance(i, j, index);
  14041. processingFlags[index] |= firstMagnitudeBitMask;
  14042. index = index0;
  14043. for (var i2 = i0; i2 <= i; i2++, index += width) {
  14044. bitsDecoded[index]++;
  14045. }
  14046. i1++;
  14047. }
  14048. for (i = i0 + i1; i < iNext; i++, index += width) {
  14049. if (coefficentsMagnitude[index] ||
  14050. (processingFlags[index] & processedMask) !== 0) {
  14051. continue;
  14052. }
  14053. var contextLabel = labels[neighborsSignificance[index]];
  14054. var decision = decoder.readBit(contexts, contextLabel);
  14055. if (decision === 1) {
  14056. sign = this.decodeSignBit(i, j, index);
  14057. coefficentsSign[index] = sign;
  14058. coefficentsMagnitude[index] = 1;
  14059. this.setNeighborsSignificance(i, j, index);
  14060. processingFlags[index] |= firstMagnitudeBitMask;
  14061. }
  14062. bitsDecoded[index]++;
  14063. }
  14064. }
  14065. }
  14066. },
  14067. checkSegmentationSymbol: function BitModel_checkSegmentationSymbol() {
  14068. var decoder = this.decoder;
  14069. var contexts = this.contexts;
  14070. var symbol = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 3) |
  14071. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 2) |
  14072. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  14073. decoder.readBit(contexts, UNIFORM_CONTEXT);
  14074. if (symbol !== 0xA) {
  14075. throw new Error('JPX Error: Invalid segmentation symbol');
  14076. }
  14077. }
  14078. };
  14079. return BitModel;
  14080. })();
  14081. // Section F, Discrete wavelet transformation
  14082. var Transform = (function TransformClosure() {
  14083. function Transform() {}
  14084. Transform.prototype.calculate =
  14085. function transformCalculate(subbands, u0, v0) {
  14086. var ll = subbands[0];
  14087. for (var i = 1, ii = subbands.length; i < ii; i++) {
  14088. ll = this.iterate(ll, subbands[i], u0, v0);
  14089. }
  14090. return ll;
  14091. };
  14092. Transform.prototype.extend = function extend(buffer, offset, size) {
  14093. // Section F.3.7 extending... using max extension of 4
  14094. var i1 = offset - 1, j1 = offset + 1;
  14095. var i2 = offset + size - 2, j2 = offset + size;
  14096. buffer[i1--] = buffer[j1++];
  14097. buffer[j2++] = buffer[i2--];
  14098. buffer[i1--] = buffer[j1++];
  14099. buffer[j2++] = buffer[i2--];
  14100. buffer[i1--] = buffer[j1++];
  14101. buffer[j2++] = buffer[i2--];
  14102. buffer[i1] = buffer[j1];
  14103. buffer[j2] = buffer[i2];
  14104. };
  14105. Transform.prototype.iterate = function Transform_iterate(ll, hl_lh_hh,
  14106. u0, v0) {
  14107. var llWidth = ll.width, llHeight = ll.height, llItems = ll.items;
  14108. var width = hl_lh_hh.width;
  14109. var height = hl_lh_hh.height;
  14110. var items = hl_lh_hh.items;
  14111. var i, j, k, l, u, v;
  14112. // Interleave LL according to Section F.3.3
  14113. for (k = 0, i = 0; i < llHeight; i++) {
  14114. l = i * 2 * width;
  14115. for (j = 0; j < llWidth; j++, k++, l += 2) {
  14116. items[l] = llItems[k];
  14117. }
  14118. }
  14119. // The LL band is not needed anymore.
  14120. llItems = ll.items = null;
  14121. var bufferPadding = 4;
  14122. var rowBuffer = new Float32Array(width + 2 * bufferPadding);
  14123. // Section F.3.4 HOR_SR
  14124. if (width === 1) {
  14125. // if width = 1, when u0 even keep items as is, when odd divide by 2
  14126. if ((u0 & 1) !== 0) {
  14127. for (v = 0, k = 0; v < height; v++, k += width) {
  14128. items[k] *= 0.5;
  14129. }
  14130. }
  14131. } else {
  14132. for (v = 0, k = 0; v < height; v++, k += width) {
  14133. rowBuffer.set(items.subarray(k, k + width), bufferPadding);
  14134. this.extend(rowBuffer, bufferPadding, width);
  14135. this.filter(rowBuffer, bufferPadding, width);
  14136. items.set(
  14137. rowBuffer.subarray(bufferPadding, bufferPadding + width),
  14138. k);
  14139. }
  14140. }
  14141. // Accesses to the items array can take long, because it may not fit into
  14142. // CPU cache and has to be fetched from main memory. Since subsequent
  14143. // accesses to the items array are not local when reading columns, we
  14144. // have a cache miss every time. To reduce cache misses, get up to
  14145. // 'numBuffers' items at a time and store them into the individual
  14146. // buffers. The colBuffers should be small enough to fit into CPU cache.
  14147. var numBuffers = 16;
  14148. var colBuffers = [];
  14149. for (i = 0; i < numBuffers; i++) {
  14150. colBuffers.push(new Float32Array(height + 2 * bufferPadding));
  14151. }
  14152. var b, currentBuffer = 0;
  14153. ll = bufferPadding + height;
  14154. // Section F.3.5 VER_SR
  14155. if (height === 1) {
  14156. // if height = 1, when v0 even keep items as is, when odd divide by 2
  14157. if ((v0 & 1) !== 0) {
  14158. for (u = 0; u < width; u++) {
  14159. items[u] *= 0.5;
  14160. }
  14161. }
  14162. } else {
  14163. for (u = 0; u < width; u++) {
  14164. // if we ran out of buffers, copy several image columns at once
  14165. if (currentBuffer === 0) {
  14166. numBuffers = Math.min(width - u, numBuffers);
  14167. for (k = u, l = bufferPadding; l < ll; k += width, l++) {
  14168. for (b = 0; b < numBuffers; b++) {
  14169. colBuffers[b][l] = items[k + b];
  14170. }
  14171. }
  14172. currentBuffer = numBuffers;
  14173. }
  14174. currentBuffer--;
  14175. var buffer = colBuffers[currentBuffer];
  14176. this.extend(buffer, bufferPadding, height);
  14177. this.filter(buffer, bufferPadding, height);
  14178. // If this is last buffer in this group of buffers, flush all buffers.
  14179. if (currentBuffer === 0) {
  14180. k = u - numBuffers + 1;
  14181. for (l = bufferPadding; l < ll; k += width, l++) {
  14182. for (b = 0; b < numBuffers; b++) {
  14183. items[k + b] = colBuffers[b][l];
  14184. }
  14185. }
  14186. }
  14187. }
  14188. }
  14189. return {
  14190. width: width,
  14191. height: height,
  14192. items: items
  14193. };
  14194. };
  14195. return Transform;
  14196. })();
  14197. // Section 3.8.2 Irreversible 9-7 filter
  14198. var IrreversibleTransform = (function IrreversibleTransformClosure() {
  14199. function IrreversibleTransform() {
  14200. Transform.call(this);
  14201. }
  14202. IrreversibleTransform.prototype = Object.create(Transform.prototype);
  14203. IrreversibleTransform.prototype.filter =
  14204. function irreversibleTransformFilter(x, offset, length) {
  14205. var len = length >> 1;
  14206. offset = offset | 0;
  14207. var j, n, current, next;
  14208. var alpha = -1.586134342059924;
  14209. var beta = -0.052980118572961;
  14210. var gamma = 0.882911075530934;
  14211. var delta = 0.443506852043971;
  14212. var K = 1.230174104914001;
  14213. var K_ = 1 / K;
  14214. // step 1 is combined with step 3
  14215. // step 2
  14216. j = offset - 3;
  14217. for (n = len + 4; n--; j += 2) {
  14218. x[j] *= K_;
  14219. }
  14220. // step 1 & 3
  14221. j = offset - 2;
  14222. current = delta * x[j -1];
  14223. for (n = len + 3; n--; j += 2) {
  14224. next = delta * x[j + 1];
  14225. x[j] = K * x[j] - current - next;
  14226. if (n--) {
  14227. j += 2;
  14228. current = delta * x[j + 1];
  14229. x[j] = K * x[j] - current - next;
  14230. } else {
  14231. break;
  14232. }
  14233. }
  14234. // step 4
  14235. j = offset - 1;
  14236. current = gamma * x[j - 1];
  14237. for (n = len + 2; n--; j += 2) {
  14238. next = gamma * x[j + 1];
  14239. x[j] -= current + next;
  14240. if (n--) {
  14241. j += 2;
  14242. current = gamma * x[j + 1];
  14243. x[j] -= current + next;
  14244. } else {
  14245. break;
  14246. }
  14247. }
  14248. // step 5
  14249. j = offset;
  14250. current = beta * x[j - 1];
  14251. for (n = len + 1; n--; j += 2) {
  14252. next = beta * x[j + 1];
  14253. x[j] -= current + next;
  14254. if (n--) {
  14255. j += 2;
  14256. current = beta * x[j + 1];
  14257. x[j] -= current + next;
  14258. } else {
  14259. break;
  14260. }
  14261. }
  14262. // step 6
  14263. if (len !== 0) {
  14264. j = offset + 1;
  14265. current = alpha * x[j - 1];
  14266. for (n = len; n--; j += 2) {
  14267. next = alpha * x[j + 1];
  14268. x[j] -= current + next;
  14269. if (n--) {
  14270. j += 2;
  14271. current = alpha * x[j + 1];
  14272. x[j] -= current + next;
  14273. } else {
  14274. break;
  14275. }
  14276. }
  14277. }
  14278. };
  14279. return IrreversibleTransform;
  14280. })();
  14281. // Section 3.8.1 Reversible 5-3 filter
  14282. var ReversibleTransform = (function ReversibleTransformClosure() {
  14283. function ReversibleTransform() {
  14284. Transform.call(this);
  14285. }
  14286. ReversibleTransform.prototype = Object.create(Transform.prototype);
  14287. ReversibleTransform.prototype.filter =
  14288. function reversibleTransformFilter(x, offset, length) {
  14289. var len = length >> 1;
  14290. offset = offset | 0;
  14291. var j, n;
  14292. for (j = offset, n = len + 1; n--; j += 2) {
  14293. x[j] -= (x[j - 1] + x[j + 1] + 2) >> 2;
  14294. }
  14295. for (j = offset + 1, n = len; n--; j += 2) {
  14296. x[j] += (x[j - 1] + x[j + 1]) >> 1;
  14297. }
  14298. };
  14299. return ReversibleTransform;
  14300. })();
  14301. return JpxImage;
  14302. })();
  14303. exports.JpxImage = JpxImage;
  14304. }));
  14305. (function (root, factory) {
  14306. {
  14307. factory((root.pdfjsCoreMurmurHash3 = {}), root.pdfjsSharedUtil);
  14308. }
  14309. }(this, function (exports, sharedUtil) {
  14310. var Uint32ArrayView = sharedUtil.Uint32ArrayView;
  14311. var MurmurHash3_64 = (function MurmurHash3_64Closure (seed) {
  14312. // Workaround for missing math precison in JS.
  14313. var MASK_HIGH = 0xffff0000;
  14314. var MASK_LOW = 0xffff;
  14315. function MurmurHash3_64 (seed) {
  14316. var SEED = 0xc3d2e1f0;
  14317. this.h1 = seed ? seed & 0xffffffff : SEED;
  14318. this.h2 = seed ? seed & 0xffffffff : SEED;
  14319. }
  14320. var alwaysUseUint32ArrayView = false;
  14321. // old webkits have issues with non-aligned arrays
  14322. try {
  14323. new Uint32Array(new Uint8Array(5).buffer, 0, 1);
  14324. } catch (e) {
  14325. alwaysUseUint32ArrayView = true;
  14326. }
  14327. MurmurHash3_64.prototype = {
  14328. update: function MurmurHash3_64_update(input) {
  14329. var useUint32ArrayView = alwaysUseUint32ArrayView;
  14330. var i;
  14331. if (typeof input === 'string') {
  14332. var data = new Uint8Array(input.length * 2);
  14333. var length = 0;
  14334. for (i = 0; i < input.length; i++) {
  14335. var code = input.charCodeAt(i);
  14336. if (code <= 0xff) {
  14337. data[length++] = code;
  14338. }
  14339. else {
  14340. data[length++] = code >>> 8;
  14341. data[length++] = code & 0xff;
  14342. }
  14343. }
  14344. } else if (input instanceof Uint8Array) {
  14345. data = input;
  14346. length = data.length;
  14347. } else if (typeof input === 'object' && ('length' in input)) {
  14348. // processing regular arrays as well, e.g. for IE9
  14349. data = input;
  14350. length = data.length;
  14351. useUint32ArrayView = true;
  14352. } else {
  14353. throw new Error('Wrong data format in MurmurHash3_64_update. ' +
  14354. 'Input must be a string or array.');
  14355. }
  14356. var blockCounts = length >> 2;
  14357. var tailLength = length - blockCounts * 4;
  14358. // we don't care about endianness here
  14359. var dataUint32 = useUint32ArrayView ?
  14360. new Uint32ArrayView(data, blockCounts) :
  14361. new Uint32Array(data.buffer, 0, blockCounts);
  14362. var k1 = 0;
  14363. var k2 = 0;
  14364. var h1 = this.h1;
  14365. var h2 = this.h2;
  14366. var C1 = 0xcc9e2d51;
  14367. var C2 = 0x1b873593;
  14368. var C1_LOW = C1 & MASK_LOW;
  14369. var C2_LOW = C2 & MASK_LOW;
  14370. for (i = 0; i < blockCounts; i++) {
  14371. if (i & 1) {
  14372. k1 = dataUint32[i];
  14373. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  14374. k1 = k1 << 15 | k1 >>> 17;
  14375. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  14376. h1 ^= k1;
  14377. h1 = h1 << 13 | h1 >>> 19;
  14378. h1 = h1 * 5 + 0xe6546b64;
  14379. } else {
  14380. k2 = dataUint32[i];
  14381. k2 = (k2 * C1 & MASK_HIGH) | (k2 * C1_LOW & MASK_LOW);
  14382. k2 = k2 << 15 | k2 >>> 17;
  14383. k2 = (k2 * C2 & MASK_HIGH) | (k2 * C2_LOW & MASK_LOW);
  14384. h2 ^= k2;
  14385. h2 = h2 << 13 | h2 >>> 19;
  14386. h2 = h2 * 5 + 0xe6546b64;
  14387. }
  14388. }
  14389. k1 = 0;
  14390. switch (tailLength) {
  14391. case 3:
  14392. k1 ^= data[blockCounts * 4 + 2] << 16;
  14393. /* falls through */
  14394. case 2:
  14395. k1 ^= data[blockCounts * 4 + 1] << 8;
  14396. /* falls through */
  14397. case 1:
  14398. k1 ^= data[blockCounts * 4];
  14399. /* falls through */
  14400. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  14401. k1 = k1 << 15 | k1 >>> 17;
  14402. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  14403. if (blockCounts & 1) {
  14404. h1 ^= k1;
  14405. } else {
  14406. h2 ^= k1;
  14407. }
  14408. }
  14409. this.h1 = h1;
  14410. this.h2 = h2;
  14411. return this;
  14412. },
  14413. hexdigest: function MurmurHash3_64_hexdigest () {
  14414. var h1 = this.h1;
  14415. var h2 = this.h2;
  14416. h1 ^= h2 >>> 1;
  14417. h1 = (h1 * 0xed558ccd & MASK_HIGH) | (h1 * 0x8ccd & MASK_LOW);
  14418. h2 = (h2 * 0xff51afd7 & MASK_HIGH) |
  14419. (((h2 << 16 | h1 >>> 16) * 0xafd7ed55 & MASK_HIGH) >>> 16);
  14420. h1 ^= h2 >>> 1;
  14421. h1 = (h1 * 0x1a85ec53 & MASK_HIGH) | (h1 * 0xec53 & MASK_LOW);
  14422. h2 = (h2 * 0xc4ceb9fe & MASK_HIGH) |
  14423. (((h2 << 16 | h1 >>> 16) * 0xb9fe1a85 & MASK_HIGH) >>> 16);
  14424. h1 ^= h2 >>> 1;
  14425. for (var i = 0, arr = [h1, h2], str = ''; i < arr.length; i++) {
  14426. var hex = (arr[i] >>> 0).toString(16);
  14427. while (hex.length < 8) {
  14428. hex = '0' + hex;
  14429. }
  14430. str += hex;
  14431. }
  14432. return str;
  14433. }
  14434. };
  14435. return MurmurHash3_64;
  14436. })();
  14437. exports.MurmurHash3_64 = MurmurHash3_64;
  14438. }));
  14439. (function (root, factory) {
  14440. {
  14441. factory((root.pdfjsCorePrimitives = {}), root.pdfjsSharedUtil);
  14442. }
  14443. }(this, function (exports, sharedUtil) {
  14444. var isArray = sharedUtil.isArray;
  14445. var Name = (function NameClosure() {
  14446. function Name(name) {
  14447. this.name = name;
  14448. }
  14449. Name.prototype = {};
  14450. var nameCache = {};
  14451. Name.get = function Name_get(name) {
  14452. var nameValue = nameCache[name];
  14453. return (nameValue ? nameValue : (nameCache[name] = new Name(name)));
  14454. };
  14455. return Name;
  14456. })();
  14457. var Cmd = (function CmdClosure() {
  14458. function Cmd(cmd) {
  14459. this.cmd = cmd;
  14460. }
  14461. Cmd.prototype = {};
  14462. var cmdCache = {};
  14463. Cmd.get = function Cmd_get(cmd) {
  14464. var cmdValue = cmdCache[cmd];
  14465. return (cmdValue ? cmdValue : (cmdCache[cmd] = new Cmd(cmd)));
  14466. };
  14467. return Cmd;
  14468. })();
  14469. var Dict = (function DictClosure() {
  14470. var nonSerializable = function nonSerializableClosure() {
  14471. return nonSerializable; // creating closure on some variable
  14472. };
  14473. var GETALL_DICTIONARY_TYPES_WHITELIST = {
  14474. 'Background': true,
  14475. 'ExtGState': true,
  14476. 'Halftone': true,
  14477. 'Layout': true,
  14478. 'Mask': true,
  14479. 'Pagination': true,
  14480. 'Printing': true
  14481. };
  14482. function isRecursionAllowedFor(dict) {
  14483. if (!isName(dict.Type)) {
  14484. return true;
  14485. }
  14486. var dictType = dict.Type.name;
  14487. return GETALL_DICTIONARY_TYPES_WHITELIST[dictType] === true;
  14488. }
  14489. // xref is optional
  14490. function Dict(xref) {
  14491. // Map should only be used internally, use functions below to access.
  14492. this.map = Object.create(null);
  14493. this.xref = xref;
  14494. this.objId = null;
  14495. this.__nonSerializable__ = nonSerializable; // disable cloning of the Dict
  14496. }
  14497. Dict.prototype = {
  14498. assignXref: function Dict_assignXref(newXref) {
  14499. this.xref = newXref;
  14500. },
  14501. // automatically dereferences Ref objects
  14502. get: function Dict_get(key1, key2, key3) {
  14503. var value;
  14504. var xref = this.xref;
  14505. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  14506. typeof key2 === 'undefined') {
  14507. return xref ? xref.fetchIfRef(value) : value;
  14508. }
  14509. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  14510. typeof key3 === 'undefined') {
  14511. return xref ? xref.fetchIfRef(value) : value;
  14512. }
  14513. value = this.map[key3] || null;
  14514. return xref ? xref.fetchIfRef(value) : value;
  14515. },
  14516. // Same as get(), but returns a promise and uses fetchIfRefAsync().
  14517. getAsync: function Dict_getAsync(key1, key2, key3) {
  14518. var value;
  14519. var xref = this.xref;
  14520. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  14521. typeof key2 === 'undefined') {
  14522. if (xref) {
  14523. return xref.fetchIfRefAsync(value);
  14524. }
  14525. return Promise.resolve(value);
  14526. }
  14527. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  14528. typeof key3 === 'undefined') {
  14529. if (xref) {
  14530. return xref.fetchIfRefAsync(value);
  14531. }
  14532. return Promise.resolve(value);
  14533. }
  14534. value = this.map[key3] || null;
  14535. if (xref) {
  14536. return xref.fetchIfRefAsync(value);
  14537. }
  14538. return Promise.resolve(value);
  14539. },
  14540. // Same as get(), but dereferences all elements if the result is an Array.
  14541. getArray: function Dict_getArray(key1, key2, key3) {
  14542. var value = this.get(key1, key2, key3);
  14543. var xref = this.xref;
  14544. if (!isArray(value) || !xref) {
  14545. return value;
  14546. }
  14547. value = value.slice(); // Ensure that we don't modify the Dict data.
  14548. for (var i = 0, ii = value.length; i < ii; i++) {
  14549. if (!isRef(value[i])) {
  14550. continue;
  14551. }
  14552. value[i] = xref.fetch(value[i]);
  14553. }
  14554. return value;
  14555. },
  14556. // no dereferencing
  14557. getRaw: function Dict_getRaw(key) {
  14558. return this.map[key];
  14559. },
  14560. // creates new map and dereferences all Refs
  14561. getAll: function Dict_getAll() {
  14562. var all = Object.create(null);
  14563. var queue = null;
  14564. var key, obj;
  14565. for (key in this.map) {
  14566. obj = this.get(key);
  14567. if (obj instanceof Dict) {
  14568. if (isRecursionAllowedFor(obj)) {
  14569. (queue || (queue = [])).push({target: all, key: key, obj: obj});
  14570. } else {
  14571. all[key] = this.getRaw(key);
  14572. }
  14573. } else {
  14574. all[key] = obj;
  14575. }
  14576. }
  14577. if (!queue) {
  14578. return all;
  14579. }
  14580. // trying to take cyclic references into the account
  14581. var processed = Object.create(null);
  14582. while (queue.length > 0) {
  14583. var item = queue.shift();
  14584. var itemObj = item.obj;
  14585. var objId = itemObj.objId;
  14586. if (objId && objId in processed) {
  14587. item.target[item.key] = processed[objId];
  14588. continue;
  14589. }
  14590. var dereferenced = Object.create(null);
  14591. for (key in itemObj.map) {
  14592. obj = itemObj.get(key);
  14593. if (obj instanceof Dict) {
  14594. if (isRecursionAllowedFor(obj)) {
  14595. queue.push({target: dereferenced, key: key, obj: obj});
  14596. } else {
  14597. dereferenced[key] = itemObj.getRaw(key);
  14598. }
  14599. } else {
  14600. dereferenced[key] = obj;
  14601. }
  14602. }
  14603. if (objId) {
  14604. processed[objId] = dereferenced;
  14605. }
  14606. item.target[item.key] = dereferenced;
  14607. }
  14608. return all;
  14609. },
  14610. getKeys: function Dict_getKeys() {
  14611. return Object.keys(this.map);
  14612. },
  14613. set: function Dict_set(key, value) {
  14614. this.map[key] = value;
  14615. },
  14616. has: function Dict_has(key) {
  14617. return key in this.map;
  14618. },
  14619. forEach: function Dict_forEach(callback) {
  14620. for (var key in this.map) {
  14621. callback(key, this.get(key));
  14622. }
  14623. }
  14624. };
  14625. Dict.empty = new Dict(null);
  14626. Dict.merge = function Dict_merge(xref, dictArray) {
  14627. var mergedDict = new Dict(xref);
  14628. for (var i = 0, ii = dictArray.length; i < ii; i++) {
  14629. var dict = dictArray[i];
  14630. if (!isDict(dict)) {
  14631. continue;
  14632. }
  14633. for (var keyName in dict.map) {
  14634. if (mergedDict.map[keyName]) {
  14635. continue;
  14636. }
  14637. mergedDict.map[keyName] = dict.map[keyName];
  14638. }
  14639. }
  14640. return mergedDict;
  14641. };
  14642. return Dict;
  14643. })();
  14644. var Ref = (function RefClosure() {
  14645. function Ref(num, gen) {
  14646. this.num = num;
  14647. this.gen = gen;
  14648. }
  14649. Ref.prototype = {
  14650. toString: function Ref_toString() {
  14651. // This function is hot, so we make the string as compact as possible.
  14652. // |this.gen| is almost always zero, so we treat that case specially.
  14653. var str = this.num + 'R';
  14654. if (this.gen !== 0) {
  14655. str += this.gen;
  14656. }
  14657. return str;
  14658. }
  14659. };
  14660. return Ref;
  14661. })();
  14662. // The reference is identified by number and generation.
  14663. // This structure stores only one instance of the reference.
  14664. var RefSet = (function RefSetClosure() {
  14665. function RefSet() {
  14666. this.dict = {};
  14667. }
  14668. RefSet.prototype = {
  14669. has: function RefSet_has(ref) {
  14670. return ref.toString() in this.dict;
  14671. },
  14672. put: function RefSet_put(ref) {
  14673. this.dict[ref.toString()] = true;
  14674. },
  14675. remove: function RefSet_remove(ref) {
  14676. delete this.dict[ref.toString()];
  14677. }
  14678. };
  14679. return RefSet;
  14680. })();
  14681. var RefSetCache = (function RefSetCacheClosure() {
  14682. function RefSetCache() {
  14683. this.dict = Object.create(null);
  14684. }
  14685. RefSetCache.prototype = {
  14686. get: function RefSetCache_get(ref) {
  14687. return this.dict[ref.toString()];
  14688. },
  14689. has: function RefSetCache_has(ref) {
  14690. return ref.toString() in this.dict;
  14691. },
  14692. put: function RefSetCache_put(ref, obj) {
  14693. this.dict[ref.toString()] = obj;
  14694. },
  14695. putAlias: function RefSetCache_putAlias(ref, aliasRef) {
  14696. this.dict[ref.toString()] = this.get(aliasRef);
  14697. },
  14698. forEach: function RefSetCache_forEach(fn, thisArg) {
  14699. for (var i in this.dict) {
  14700. fn.call(thisArg, this.dict[i]);
  14701. }
  14702. },
  14703. clear: function RefSetCache_clear() {
  14704. this.dict = Object.create(null);
  14705. }
  14706. };
  14707. return RefSetCache;
  14708. })();
  14709. function isName(v) {
  14710. return v instanceof Name;
  14711. }
  14712. function isCmd(v, cmd) {
  14713. return v instanceof Cmd && (cmd === undefined || v.cmd === cmd);
  14714. }
  14715. function isDict(v, type) {
  14716. if (!(v instanceof Dict)) {
  14717. return false;
  14718. }
  14719. if (!type) {
  14720. return true;
  14721. }
  14722. var dictType = v.get('Type');
  14723. return isName(dictType) && dictType.name === type;
  14724. }
  14725. function isRef(v) {
  14726. return v instanceof Ref;
  14727. }
  14728. function isStream(v) {
  14729. return typeof v === 'object' && v !== null && v.getBytes !== undefined;
  14730. }
  14731. exports.Cmd = Cmd;
  14732. exports.Dict = Dict;
  14733. exports.Name = Name;
  14734. exports.Ref = Ref;
  14735. exports.RefSet = RefSet;
  14736. exports.RefSetCache = RefSetCache;
  14737. exports.isCmd = isCmd;
  14738. exports.isDict = isDict;
  14739. exports.isName = isName;
  14740. exports.isRef = isRef;
  14741. exports.isStream = isStream;
  14742. }));
  14743. (function (root, factory) {
  14744. {
  14745. factory((root.pdfjsCoreStream = {}), root.pdfjsSharedUtil,
  14746. root.pdfjsCorePrimitives, root.pdfjsCoreJbig2, root.pdfjsCoreJpg,
  14747. root.pdfjsCoreJpx);
  14748. }
  14749. }(this, function (exports, sharedUtil, corePrimitives, coreJbig2, coreJpg,
  14750. coreJpx) {
  14751. var Util = sharedUtil.Util;
  14752. var error = sharedUtil.error;
  14753. var info = sharedUtil.info;
  14754. var isArray = sharedUtil.isArray;
  14755. var shadow = sharedUtil.shadow;
  14756. var warn = sharedUtil.warn;
  14757. var Dict = corePrimitives.Dict;
  14758. var Jbig2Image = coreJbig2.Jbig2Image;
  14759. var JpegImage = coreJpg.JpegImage;
  14760. var JpxImage = coreJpx.JpxImage;
  14761. var coreParser; // see _setCoreParser below
  14762. var EOF; // = coreParser.EOF;
  14763. var Lexer; // = coreParser.Lexer;
  14764. var coreColorSpace; // see _setCoreColorSpace below
  14765. var ColorSpace; // = coreColorSpace.ColorSpace;
  14766. var Stream = (function StreamClosure() {
  14767. function Stream(arrayBuffer, start, length, dict) {
  14768. this.bytes = (arrayBuffer instanceof Uint8Array ?
  14769. arrayBuffer : new Uint8Array(arrayBuffer));
  14770. this.start = start || 0;
  14771. this.pos = this.start;
  14772. this.end = (start + length) || this.bytes.length;
  14773. this.dict = dict;
  14774. }
  14775. // required methods for a stream. if a particular stream does not
  14776. // implement these, an error should be thrown
  14777. Stream.prototype = {
  14778. get length() {
  14779. return this.end - this.start;
  14780. },
  14781. get isEmpty() {
  14782. return this.length === 0;
  14783. },
  14784. getByte: function Stream_getByte() {
  14785. if (this.pos >= this.end) {
  14786. return -1;
  14787. }
  14788. return this.bytes[this.pos++];
  14789. },
  14790. getUint16: function Stream_getUint16() {
  14791. var b0 = this.getByte();
  14792. var b1 = this.getByte();
  14793. if (b0 === -1 || b1 === -1) {
  14794. return -1;
  14795. }
  14796. return (b0 << 8) + b1;
  14797. },
  14798. getInt32: function Stream_getInt32() {
  14799. var b0 = this.getByte();
  14800. var b1 = this.getByte();
  14801. var b2 = this.getByte();
  14802. var b3 = this.getByte();
  14803. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  14804. },
  14805. // returns subarray of original buffer
  14806. // should only be read
  14807. getBytes: function Stream_getBytes(length) {
  14808. var bytes = this.bytes;
  14809. var pos = this.pos;
  14810. var strEnd = this.end;
  14811. if (!length) {
  14812. return bytes.subarray(pos, strEnd);
  14813. }
  14814. var end = pos + length;
  14815. if (end > strEnd) {
  14816. end = strEnd;
  14817. }
  14818. this.pos = end;
  14819. return bytes.subarray(pos, end);
  14820. },
  14821. peekByte: function Stream_peekByte() {
  14822. var peekedByte = this.getByte();
  14823. this.pos--;
  14824. return peekedByte;
  14825. },
  14826. peekBytes: function Stream_peekBytes(length) {
  14827. var bytes = this.getBytes(length);
  14828. this.pos -= bytes.length;
  14829. return bytes;
  14830. },
  14831. skip: function Stream_skip(n) {
  14832. if (!n) {
  14833. n = 1;
  14834. }
  14835. this.pos += n;
  14836. },
  14837. reset: function Stream_reset() {
  14838. this.pos = this.start;
  14839. },
  14840. moveStart: function Stream_moveStart() {
  14841. this.start = this.pos;
  14842. },
  14843. makeSubStream: function Stream_makeSubStream(start, length, dict) {
  14844. return new Stream(this.bytes.buffer, start, length, dict);
  14845. },
  14846. isStream: true
  14847. };
  14848. return Stream;
  14849. })();
  14850. var StringStream = (function StringStreamClosure() {
  14851. function StringStream(str) {
  14852. var length = str.length;
  14853. var bytes = new Uint8Array(length);
  14854. for (var n = 0; n < length; ++n) {
  14855. bytes[n] = str.charCodeAt(n);
  14856. }
  14857. Stream.call(this, bytes);
  14858. }
  14859. StringStream.prototype = Stream.prototype;
  14860. return StringStream;
  14861. })();
  14862. // super class for the decoding streams
  14863. var DecodeStream = (function DecodeStreamClosure() {
  14864. // Lots of DecodeStreams are created whose buffers are never used. For these
  14865. // we share a single empty buffer. This is (a) space-efficient and (b) avoids
  14866. // having special cases that would be required if we used |null| for an empty
  14867. // buffer.
  14868. var emptyBuffer = new Uint8Array(0);
  14869. function DecodeStream(maybeMinBufferLength) {
  14870. this.pos = 0;
  14871. this.bufferLength = 0;
  14872. this.eof = false;
  14873. this.buffer = emptyBuffer;
  14874. this.minBufferLength = 512;
  14875. if (maybeMinBufferLength) {
  14876. // Compute the first power of two that is as big as maybeMinBufferLength.
  14877. while (this.minBufferLength < maybeMinBufferLength) {
  14878. this.minBufferLength *= 2;
  14879. }
  14880. }
  14881. }
  14882. DecodeStream.prototype = {
  14883. get isEmpty() {
  14884. while (!this.eof && this.bufferLength === 0) {
  14885. this.readBlock();
  14886. }
  14887. return this.bufferLength === 0;
  14888. },
  14889. ensureBuffer: function DecodeStream_ensureBuffer(requested) {
  14890. var buffer = this.buffer;
  14891. if (requested <= buffer.byteLength) {
  14892. return buffer;
  14893. }
  14894. var size = this.minBufferLength;
  14895. while (size < requested) {
  14896. size *= 2;
  14897. }
  14898. var buffer2 = new Uint8Array(size);
  14899. buffer2.set(buffer);
  14900. return (this.buffer = buffer2);
  14901. },
  14902. getByte: function DecodeStream_getByte() {
  14903. var pos = this.pos;
  14904. while (this.bufferLength <= pos) {
  14905. if (this.eof) {
  14906. return -1;
  14907. }
  14908. this.readBlock();
  14909. }
  14910. return this.buffer[this.pos++];
  14911. },
  14912. getUint16: function DecodeStream_getUint16() {
  14913. var b0 = this.getByte();
  14914. var b1 = this.getByte();
  14915. if (b0 === -1 || b1 === -1) {
  14916. return -1;
  14917. }
  14918. return (b0 << 8) + b1;
  14919. },
  14920. getInt32: function DecodeStream_getInt32() {
  14921. var b0 = this.getByte();
  14922. var b1 = this.getByte();
  14923. var b2 = this.getByte();
  14924. var b3 = this.getByte();
  14925. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  14926. },
  14927. getBytes: function DecodeStream_getBytes(length) {
  14928. var end, pos = this.pos;
  14929. if (length) {
  14930. this.ensureBuffer(pos + length);
  14931. end = pos + length;
  14932. while (!this.eof && this.bufferLength < end) {
  14933. this.readBlock();
  14934. }
  14935. var bufEnd = this.bufferLength;
  14936. if (end > bufEnd) {
  14937. end = bufEnd;
  14938. }
  14939. } else {
  14940. while (!this.eof) {
  14941. this.readBlock();
  14942. }
  14943. end = this.bufferLength;
  14944. }
  14945. this.pos = end;
  14946. return this.buffer.subarray(pos, end);
  14947. },
  14948. peekByte: function DecodeStream_peekByte() {
  14949. var peekedByte = this.getByte();
  14950. this.pos--;
  14951. return peekedByte;
  14952. },
  14953. peekBytes: function DecodeStream_peekBytes(length) {
  14954. var bytes = this.getBytes(length);
  14955. this.pos -= bytes.length;
  14956. return bytes;
  14957. },
  14958. makeSubStream: function DecodeStream_makeSubStream(start, length, dict) {
  14959. var end = start + length;
  14960. while (this.bufferLength <= end && !this.eof) {
  14961. this.readBlock();
  14962. }
  14963. return new Stream(this.buffer, start, length, dict);
  14964. },
  14965. skip: function DecodeStream_skip(n) {
  14966. if (!n) {
  14967. n = 1;
  14968. }
  14969. this.pos += n;
  14970. },
  14971. reset: function DecodeStream_reset() {
  14972. this.pos = 0;
  14973. },
  14974. getBaseStreams: function DecodeStream_getBaseStreams() {
  14975. if (this.str && this.str.getBaseStreams) {
  14976. return this.str.getBaseStreams();
  14977. }
  14978. return [];
  14979. }
  14980. };
  14981. return DecodeStream;
  14982. })();
  14983. var StreamsSequenceStream = (function StreamsSequenceStreamClosure() {
  14984. function StreamsSequenceStream(streams) {
  14985. this.streams = streams;
  14986. DecodeStream.call(this, /* maybeLength = */ null);
  14987. }
  14988. StreamsSequenceStream.prototype = Object.create(DecodeStream.prototype);
  14989. StreamsSequenceStream.prototype.readBlock =
  14990. function streamSequenceStreamReadBlock() {
  14991. var streams = this.streams;
  14992. if (streams.length === 0) {
  14993. this.eof = true;
  14994. return;
  14995. }
  14996. var stream = streams.shift();
  14997. var chunk = stream.getBytes();
  14998. var bufferLength = this.bufferLength;
  14999. var newLength = bufferLength + chunk.length;
  15000. var buffer = this.ensureBuffer(newLength);
  15001. buffer.set(chunk, bufferLength);
  15002. this.bufferLength = newLength;
  15003. };
  15004. StreamsSequenceStream.prototype.getBaseStreams =
  15005. function StreamsSequenceStream_getBaseStreams() {
  15006. var baseStreams = [];
  15007. for (var i = 0, ii = this.streams.length; i < ii; i++) {
  15008. var stream = this.streams[i];
  15009. if (stream.getBaseStreams) {
  15010. Util.appendToArray(baseStreams, stream.getBaseStreams());
  15011. }
  15012. }
  15013. return baseStreams;
  15014. };
  15015. return StreamsSequenceStream;
  15016. })();
  15017. var FlateStream = (function FlateStreamClosure() {
  15018. var codeLenCodeMap = new Int32Array([
  15019. 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
  15020. ]);
  15021. var lengthDecode = new Int32Array([
  15022. 0x00003, 0x00004, 0x00005, 0x00006, 0x00007, 0x00008, 0x00009, 0x0000a,
  15023. 0x1000b, 0x1000d, 0x1000f, 0x10011, 0x20013, 0x20017, 0x2001b, 0x2001f,
  15024. 0x30023, 0x3002b, 0x30033, 0x3003b, 0x40043, 0x40053, 0x40063, 0x40073,
  15025. 0x50083, 0x500a3, 0x500c3, 0x500e3, 0x00102, 0x00102, 0x00102
  15026. ]);
  15027. var distDecode = new Int32Array([
  15028. 0x00001, 0x00002, 0x00003, 0x00004, 0x10005, 0x10007, 0x20009, 0x2000d,
  15029. 0x30011, 0x30019, 0x40021, 0x40031, 0x50041, 0x50061, 0x60081, 0x600c1,
  15030. 0x70101, 0x70181, 0x80201, 0x80301, 0x90401, 0x90601, 0xa0801, 0xa0c01,
  15031. 0xb1001, 0xb1801, 0xc2001, 0xc3001, 0xd4001, 0xd6001
  15032. ]);
  15033. var fixedLitCodeTab = [new Int32Array([
  15034. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c0,
  15035. 0x70108, 0x80060, 0x80020, 0x900a0, 0x80000, 0x80080, 0x80040, 0x900e0,
  15036. 0x70104, 0x80058, 0x80018, 0x90090, 0x70114, 0x80078, 0x80038, 0x900d0,
  15037. 0x7010c, 0x80068, 0x80028, 0x900b0, 0x80008, 0x80088, 0x80048, 0x900f0,
  15038. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c8,
  15039. 0x7010a, 0x80064, 0x80024, 0x900a8, 0x80004, 0x80084, 0x80044, 0x900e8,
  15040. 0x70106, 0x8005c, 0x8001c, 0x90098, 0x70116, 0x8007c, 0x8003c, 0x900d8,
  15041. 0x7010e, 0x8006c, 0x8002c, 0x900b8, 0x8000c, 0x8008c, 0x8004c, 0x900f8,
  15042. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c4,
  15043. 0x70109, 0x80062, 0x80022, 0x900a4, 0x80002, 0x80082, 0x80042, 0x900e4,
  15044. 0x70105, 0x8005a, 0x8001a, 0x90094, 0x70115, 0x8007a, 0x8003a, 0x900d4,
  15045. 0x7010d, 0x8006a, 0x8002a, 0x900b4, 0x8000a, 0x8008a, 0x8004a, 0x900f4,
  15046. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cc,
  15047. 0x7010b, 0x80066, 0x80026, 0x900ac, 0x80006, 0x80086, 0x80046, 0x900ec,
  15048. 0x70107, 0x8005e, 0x8001e, 0x9009c, 0x70117, 0x8007e, 0x8003e, 0x900dc,
  15049. 0x7010f, 0x8006e, 0x8002e, 0x900bc, 0x8000e, 0x8008e, 0x8004e, 0x900fc,
  15050. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c2,
  15051. 0x70108, 0x80061, 0x80021, 0x900a2, 0x80001, 0x80081, 0x80041, 0x900e2,
  15052. 0x70104, 0x80059, 0x80019, 0x90092, 0x70114, 0x80079, 0x80039, 0x900d2,
  15053. 0x7010c, 0x80069, 0x80029, 0x900b2, 0x80009, 0x80089, 0x80049, 0x900f2,
  15054. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900ca,
  15055. 0x7010a, 0x80065, 0x80025, 0x900aa, 0x80005, 0x80085, 0x80045, 0x900ea,
  15056. 0x70106, 0x8005d, 0x8001d, 0x9009a, 0x70116, 0x8007d, 0x8003d, 0x900da,
  15057. 0x7010e, 0x8006d, 0x8002d, 0x900ba, 0x8000d, 0x8008d, 0x8004d, 0x900fa,
  15058. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c6,
  15059. 0x70109, 0x80063, 0x80023, 0x900a6, 0x80003, 0x80083, 0x80043, 0x900e6,
  15060. 0x70105, 0x8005b, 0x8001b, 0x90096, 0x70115, 0x8007b, 0x8003b, 0x900d6,
  15061. 0x7010d, 0x8006b, 0x8002b, 0x900b6, 0x8000b, 0x8008b, 0x8004b, 0x900f6,
  15062. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900ce,
  15063. 0x7010b, 0x80067, 0x80027, 0x900ae, 0x80007, 0x80087, 0x80047, 0x900ee,
  15064. 0x70107, 0x8005f, 0x8001f, 0x9009e, 0x70117, 0x8007f, 0x8003f, 0x900de,
  15065. 0x7010f, 0x8006f, 0x8002f, 0x900be, 0x8000f, 0x8008f, 0x8004f, 0x900fe,
  15066. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c1,
  15067. 0x70108, 0x80060, 0x80020, 0x900a1, 0x80000, 0x80080, 0x80040, 0x900e1,
  15068. 0x70104, 0x80058, 0x80018, 0x90091, 0x70114, 0x80078, 0x80038, 0x900d1,
  15069. 0x7010c, 0x80068, 0x80028, 0x900b1, 0x80008, 0x80088, 0x80048, 0x900f1,
  15070. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c9,
  15071. 0x7010a, 0x80064, 0x80024, 0x900a9, 0x80004, 0x80084, 0x80044, 0x900e9,
  15072. 0x70106, 0x8005c, 0x8001c, 0x90099, 0x70116, 0x8007c, 0x8003c, 0x900d9,
  15073. 0x7010e, 0x8006c, 0x8002c, 0x900b9, 0x8000c, 0x8008c, 0x8004c, 0x900f9,
  15074. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c5,
  15075. 0x70109, 0x80062, 0x80022, 0x900a5, 0x80002, 0x80082, 0x80042, 0x900e5,
  15076. 0x70105, 0x8005a, 0x8001a, 0x90095, 0x70115, 0x8007a, 0x8003a, 0x900d5,
  15077. 0x7010d, 0x8006a, 0x8002a, 0x900b5, 0x8000a, 0x8008a, 0x8004a, 0x900f5,
  15078. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cd,
  15079. 0x7010b, 0x80066, 0x80026, 0x900ad, 0x80006, 0x80086, 0x80046, 0x900ed,
  15080. 0x70107, 0x8005e, 0x8001e, 0x9009d, 0x70117, 0x8007e, 0x8003e, 0x900dd,
  15081. 0x7010f, 0x8006e, 0x8002e, 0x900bd, 0x8000e, 0x8008e, 0x8004e, 0x900fd,
  15082. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c3,
  15083. 0x70108, 0x80061, 0x80021, 0x900a3, 0x80001, 0x80081, 0x80041, 0x900e3,
  15084. 0x70104, 0x80059, 0x80019, 0x90093, 0x70114, 0x80079, 0x80039, 0x900d3,
  15085. 0x7010c, 0x80069, 0x80029, 0x900b3, 0x80009, 0x80089, 0x80049, 0x900f3,
  15086. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900cb,
  15087. 0x7010a, 0x80065, 0x80025, 0x900ab, 0x80005, 0x80085, 0x80045, 0x900eb,
  15088. 0x70106, 0x8005d, 0x8001d, 0x9009b, 0x70116, 0x8007d, 0x8003d, 0x900db,
  15089. 0x7010e, 0x8006d, 0x8002d, 0x900bb, 0x8000d, 0x8008d, 0x8004d, 0x900fb,
  15090. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c7,
  15091. 0x70109, 0x80063, 0x80023, 0x900a7, 0x80003, 0x80083, 0x80043, 0x900e7,
  15092. 0x70105, 0x8005b, 0x8001b, 0x90097, 0x70115, 0x8007b, 0x8003b, 0x900d7,
  15093. 0x7010d, 0x8006b, 0x8002b, 0x900b7, 0x8000b, 0x8008b, 0x8004b, 0x900f7,
  15094. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900cf,
  15095. 0x7010b, 0x80067, 0x80027, 0x900af, 0x80007, 0x80087, 0x80047, 0x900ef,
  15096. 0x70107, 0x8005f, 0x8001f, 0x9009f, 0x70117, 0x8007f, 0x8003f, 0x900df,
  15097. 0x7010f, 0x8006f, 0x8002f, 0x900bf, 0x8000f, 0x8008f, 0x8004f, 0x900ff
  15098. ]), 9];
  15099. var fixedDistCodeTab = [new Int32Array([
  15100. 0x50000, 0x50010, 0x50008, 0x50018, 0x50004, 0x50014, 0x5000c, 0x5001c,
  15101. 0x50002, 0x50012, 0x5000a, 0x5001a, 0x50006, 0x50016, 0x5000e, 0x00000,
  15102. 0x50001, 0x50011, 0x50009, 0x50019, 0x50005, 0x50015, 0x5000d, 0x5001d,
  15103. 0x50003, 0x50013, 0x5000b, 0x5001b, 0x50007, 0x50017, 0x5000f, 0x00000
  15104. ]), 5];
  15105. function FlateStream(str, maybeLength) {
  15106. this.str = str;
  15107. this.dict = str.dict;
  15108. var cmf = str.getByte();
  15109. var flg = str.getByte();
  15110. if (cmf === -1 || flg === -1) {
  15111. error('Invalid header in flate stream: ' + cmf + ', ' + flg);
  15112. }
  15113. if ((cmf & 0x0f) !== 0x08) {
  15114. error('Unknown compression method in flate stream: ' + cmf + ', ' + flg);
  15115. }
  15116. if ((((cmf << 8) + flg) % 31) !== 0) {
  15117. error('Bad FCHECK in flate stream: ' + cmf + ', ' + flg);
  15118. }
  15119. if (flg & 0x20) {
  15120. error('FDICT bit set in flate stream: ' + cmf + ', ' + flg);
  15121. }
  15122. this.codeSize = 0;
  15123. this.codeBuf = 0;
  15124. DecodeStream.call(this, maybeLength);
  15125. }
  15126. FlateStream.prototype = Object.create(DecodeStream.prototype);
  15127. FlateStream.prototype.getBits = function FlateStream_getBits(bits) {
  15128. var str = this.str;
  15129. var codeSize = this.codeSize;
  15130. var codeBuf = this.codeBuf;
  15131. var b;
  15132. while (codeSize < bits) {
  15133. if ((b = str.getByte()) === -1) {
  15134. error('Bad encoding in flate stream');
  15135. }
  15136. codeBuf |= b << codeSize;
  15137. codeSize += 8;
  15138. }
  15139. b = codeBuf & ((1 << bits) - 1);
  15140. this.codeBuf = codeBuf >> bits;
  15141. this.codeSize = codeSize -= bits;
  15142. return b;
  15143. };
  15144. FlateStream.prototype.getCode = function FlateStream_getCode(table) {
  15145. var str = this.str;
  15146. var codes = table[0];
  15147. var maxLen = table[1];
  15148. var codeSize = this.codeSize;
  15149. var codeBuf = this.codeBuf;
  15150. var b;
  15151. while (codeSize < maxLen) {
  15152. if ((b = str.getByte()) === -1) {
  15153. // premature end of stream. code might however still be valid.
  15154. // codeSize < codeLen check below guards against incomplete codeVal.
  15155. break;
  15156. }
  15157. codeBuf |= (b << codeSize);
  15158. codeSize += 8;
  15159. }
  15160. var code = codes[codeBuf & ((1 << maxLen) - 1)];
  15161. var codeLen = code >> 16;
  15162. var codeVal = code & 0xffff;
  15163. if (codeLen < 1 || codeSize < codeLen) {
  15164. error('Bad encoding in flate stream');
  15165. }
  15166. this.codeBuf = (codeBuf >> codeLen);
  15167. this.codeSize = (codeSize - codeLen);
  15168. return codeVal;
  15169. };
  15170. FlateStream.prototype.generateHuffmanTable =
  15171. function flateStreamGenerateHuffmanTable(lengths) {
  15172. var n = lengths.length;
  15173. // find max code length
  15174. var maxLen = 0;
  15175. var i;
  15176. for (i = 0; i < n; ++i) {
  15177. if (lengths[i] > maxLen) {
  15178. maxLen = lengths[i];
  15179. }
  15180. }
  15181. // build the table
  15182. var size = 1 << maxLen;
  15183. var codes = new Int32Array(size);
  15184. for (var len = 1, code = 0, skip = 2;
  15185. len <= maxLen;
  15186. ++len, code <<= 1, skip <<= 1) {
  15187. for (var val = 0; val < n; ++val) {
  15188. if (lengths[val] === len) {
  15189. // bit-reverse the code
  15190. var code2 = 0;
  15191. var t = code;
  15192. for (i = 0; i < len; ++i) {
  15193. code2 = (code2 << 1) | (t & 1);
  15194. t >>= 1;
  15195. }
  15196. // fill the table entries
  15197. for (i = code2; i < size; i += skip) {
  15198. codes[i] = (len << 16) | val;
  15199. }
  15200. ++code;
  15201. }
  15202. }
  15203. }
  15204. return [codes, maxLen];
  15205. };
  15206. FlateStream.prototype.readBlock = function FlateStream_readBlock() {
  15207. var buffer, len;
  15208. var str = this.str;
  15209. // read block header
  15210. var hdr = this.getBits(3);
  15211. if (hdr & 1) {
  15212. this.eof = true;
  15213. }
  15214. hdr >>= 1;
  15215. if (hdr === 0) { // uncompressed block
  15216. var b;
  15217. if ((b = str.getByte()) === -1) {
  15218. error('Bad block header in flate stream');
  15219. }
  15220. var blockLen = b;
  15221. if ((b = str.getByte()) === -1) {
  15222. error('Bad block header in flate stream');
  15223. }
  15224. blockLen |= (b << 8);
  15225. if ((b = str.getByte()) === -1) {
  15226. error('Bad block header in flate stream');
  15227. }
  15228. var check = b;
  15229. if ((b = str.getByte()) === -1) {
  15230. error('Bad block header in flate stream');
  15231. }
  15232. check |= (b << 8);
  15233. if (check !== (~blockLen & 0xffff) &&
  15234. (blockLen !== 0 || check !== 0)) {
  15235. // Ignoring error for bad "empty" block (see issue 1277)
  15236. error('Bad uncompressed block length in flate stream');
  15237. }
  15238. this.codeBuf = 0;
  15239. this.codeSize = 0;
  15240. var bufferLength = this.bufferLength;
  15241. buffer = this.ensureBuffer(bufferLength + blockLen);
  15242. var end = bufferLength + blockLen;
  15243. this.bufferLength = end;
  15244. if (blockLen === 0) {
  15245. if (str.peekByte() === -1) {
  15246. this.eof = true;
  15247. }
  15248. } else {
  15249. for (var n = bufferLength; n < end; ++n) {
  15250. if ((b = str.getByte()) === -1) {
  15251. this.eof = true;
  15252. break;
  15253. }
  15254. buffer[n] = b;
  15255. }
  15256. }
  15257. return;
  15258. }
  15259. var litCodeTable;
  15260. var distCodeTable;
  15261. if (hdr === 1) { // compressed block, fixed codes
  15262. litCodeTable = fixedLitCodeTab;
  15263. distCodeTable = fixedDistCodeTab;
  15264. } else if (hdr === 2) { // compressed block, dynamic codes
  15265. var numLitCodes = this.getBits(5) + 257;
  15266. var numDistCodes = this.getBits(5) + 1;
  15267. var numCodeLenCodes = this.getBits(4) + 4;
  15268. // build the code lengths code table
  15269. var codeLenCodeLengths = new Uint8Array(codeLenCodeMap.length);
  15270. var i;
  15271. for (i = 0; i < numCodeLenCodes; ++i) {
  15272. codeLenCodeLengths[codeLenCodeMap[i]] = this.getBits(3);
  15273. }
  15274. var codeLenCodeTab = this.generateHuffmanTable(codeLenCodeLengths);
  15275. // build the literal and distance code tables
  15276. len = 0;
  15277. i = 0;
  15278. var codes = numLitCodes + numDistCodes;
  15279. var codeLengths = new Uint8Array(codes);
  15280. var bitsLength, bitsOffset, what;
  15281. while (i < codes) {
  15282. var code = this.getCode(codeLenCodeTab);
  15283. if (code === 16) {
  15284. bitsLength = 2; bitsOffset = 3; what = len;
  15285. } else if (code === 17) {
  15286. bitsLength = 3; bitsOffset = 3; what = (len = 0);
  15287. } else if (code === 18) {
  15288. bitsLength = 7; bitsOffset = 11; what = (len = 0);
  15289. } else {
  15290. codeLengths[i++] = len = code;
  15291. continue;
  15292. }
  15293. var repeatLength = this.getBits(bitsLength) + bitsOffset;
  15294. while (repeatLength-- > 0) {
  15295. codeLengths[i++] = what;
  15296. }
  15297. }
  15298. litCodeTable =
  15299. this.generateHuffmanTable(codeLengths.subarray(0, numLitCodes));
  15300. distCodeTable =
  15301. this.generateHuffmanTable(codeLengths.subarray(numLitCodes, codes));
  15302. } else {
  15303. error('Unknown block type in flate stream');
  15304. }
  15305. buffer = this.buffer;
  15306. var limit = buffer ? buffer.length : 0;
  15307. var pos = this.bufferLength;
  15308. while (true) {
  15309. var code1 = this.getCode(litCodeTable);
  15310. if (code1 < 256) {
  15311. if (pos + 1 >= limit) {
  15312. buffer = this.ensureBuffer(pos + 1);
  15313. limit = buffer.length;
  15314. }
  15315. buffer[pos++] = code1;
  15316. continue;
  15317. }
  15318. if (code1 === 256) {
  15319. this.bufferLength = pos;
  15320. return;
  15321. }
  15322. code1 -= 257;
  15323. code1 = lengthDecode[code1];
  15324. var code2 = code1 >> 16;
  15325. if (code2 > 0) {
  15326. code2 = this.getBits(code2);
  15327. }
  15328. len = (code1 & 0xffff) + code2;
  15329. code1 = this.getCode(distCodeTable);
  15330. code1 = distDecode[code1];
  15331. code2 = code1 >> 16;
  15332. if (code2 > 0) {
  15333. code2 = this.getBits(code2);
  15334. }
  15335. var dist = (code1 & 0xffff) + code2;
  15336. if (pos + len >= limit) {
  15337. buffer = this.ensureBuffer(pos + len);
  15338. limit = buffer.length;
  15339. }
  15340. for (var k = 0; k < len; ++k, ++pos) {
  15341. buffer[pos] = buffer[pos - dist];
  15342. }
  15343. }
  15344. };
  15345. return FlateStream;
  15346. })();
  15347. var PredictorStream = (function PredictorStreamClosure() {
  15348. function PredictorStream(str, maybeLength, params) {
  15349. var predictor = this.predictor = params.get('Predictor') || 1;
  15350. if (predictor <= 1) {
  15351. return str; // no prediction
  15352. }
  15353. if (predictor !== 2 && (predictor < 10 || predictor > 15)) {
  15354. error('Unsupported predictor: ' + predictor);
  15355. }
  15356. if (predictor === 2) {
  15357. this.readBlock = this.readBlockTiff;
  15358. } else {
  15359. this.readBlock = this.readBlockPng;
  15360. }
  15361. this.str = str;
  15362. this.dict = str.dict;
  15363. var colors = this.colors = params.get('Colors') || 1;
  15364. var bits = this.bits = params.get('BitsPerComponent') || 8;
  15365. var columns = this.columns = params.get('Columns') || 1;
  15366. this.pixBytes = (colors * bits + 7) >> 3;
  15367. this.rowBytes = (columns * colors * bits + 7) >> 3;
  15368. DecodeStream.call(this, maybeLength);
  15369. return this;
  15370. }
  15371. PredictorStream.prototype = Object.create(DecodeStream.prototype);
  15372. PredictorStream.prototype.readBlockTiff =
  15373. function predictorStreamReadBlockTiff() {
  15374. var rowBytes = this.rowBytes;
  15375. var bufferLength = this.bufferLength;
  15376. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  15377. var bits = this.bits;
  15378. var colors = this.colors;
  15379. var rawBytes = this.str.getBytes(rowBytes);
  15380. this.eof = !rawBytes.length;
  15381. if (this.eof) {
  15382. return;
  15383. }
  15384. var inbuf = 0, outbuf = 0;
  15385. var inbits = 0, outbits = 0;
  15386. var pos = bufferLength;
  15387. var i;
  15388. if (bits === 1) {
  15389. for (i = 0; i < rowBytes; ++i) {
  15390. var c = rawBytes[i];
  15391. inbuf = (inbuf << 8) | c;
  15392. // bitwise addition is exclusive or
  15393. // first shift inbuf and then add
  15394. buffer[pos++] = (c ^ (inbuf >> colors)) & 0xFF;
  15395. // truncate inbuf (assumes colors < 16)
  15396. inbuf &= 0xFFFF;
  15397. }
  15398. } else if (bits === 8) {
  15399. for (i = 0; i < colors; ++i) {
  15400. buffer[pos++] = rawBytes[i];
  15401. }
  15402. for (; i < rowBytes; ++i) {
  15403. buffer[pos] = buffer[pos - colors] + rawBytes[i];
  15404. pos++;
  15405. }
  15406. } else {
  15407. var compArray = new Uint8Array(colors + 1);
  15408. var bitMask = (1 << bits) - 1;
  15409. var j = 0, k = bufferLength;
  15410. var columns = this.columns;
  15411. for (i = 0; i < columns; ++i) {
  15412. for (var kk = 0; kk < colors; ++kk) {
  15413. if (inbits < bits) {
  15414. inbuf = (inbuf << 8) | (rawBytes[j++] & 0xFF);
  15415. inbits += 8;
  15416. }
  15417. compArray[kk] = (compArray[kk] +
  15418. (inbuf >> (inbits - bits))) & bitMask;
  15419. inbits -= bits;
  15420. outbuf = (outbuf << bits) | compArray[kk];
  15421. outbits += bits;
  15422. if (outbits >= 8) {
  15423. buffer[k++] = (outbuf >> (outbits - 8)) & 0xFF;
  15424. outbits -= 8;
  15425. }
  15426. }
  15427. }
  15428. if (outbits > 0) {
  15429. buffer[k++] = (outbuf << (8 - outbits)) +
  15430. (inbuf & ((1 << (8 - outbits)) - 1));
  15431. }
  15432. }
  15433. this.bufferLength += rowBytes;
  15434. };
  15435. PredictorStream.prototype.readBlockPng =
  15436. function predictorStreamReadBlockPng() {
  15437. var rowBytes = this.rowBytes;
  15438. var pixBytes = this.pixBytes;
  15439. var predictor = this.str.getByte();
  15440. var rawBytes = this.str.getBytes(rowBytes);
  15441. this.eof = !rawBytes.length;
  15442. if (this.eof) {
  15443. return;
  15444. }
  15445. var bufferLength = this.bufferLength;
  15446. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  15447. var prevRow = buffer.subarray(bufferLength - rowBytes, bufferLength);
  15448. if (prevRow.length === 0) {
  15449. prevRow = new Uint8Array(rowBytes);
  15450. }
  15451. var i, j = bufferLength, up, c;
  15452. switch (predictor) {
  15453. case 0:
  15454. for (i = 0; i < rowBytes; ++i) {
  15455. buffer[j++] = rawBytes[i];
  15456. }
  15457. break;
  15458. case 1:
  15459. for (i = 0; i < pixBytes; ++i) {
  15460. buffer[j++] = rawBytes[i];
  15461. }
  15462. for (; i < rowBytes; ++i) {
  15463. buffer[j] = (buffer[j - pixBytes] + rawBytes[i]) & 0xFF;
  15464. j++;
  15465. }
  15466. break;
  15467. case 2:
  15468. for (i = 0; i < rowBytes; ++i) {
  15469. buffer[j++] = (prevRow[i] + rawBytes[i]) & 0xFF;
  15470. }
  15471. break;
  15472. case 3:
  15473. for (i = 0; i < pixBytes; ++i) {
  15474. buffer[j++] = (prevRow[i] >> 1) + rawBytes[i];
  15475. }
  15476. for (; i < rowBytes; ++i) {
  15477. buffer[j] = (((prevRow[i] + buffer[j - pixBytes]) >> 1) +
  15478. rawBytes[i]) & 0xFF;
  15479. j++;
  15480. }
  15481. break;
  15482. case 4:
  15483. // we need to save the up left pixels values. the simplest way
  15484. // is to create a new buffer
  15485. for (i = 0; i < pixBytes; ++i) {
  15486. up = prevRow[i];
  15487. c = rawBytes[i];
  15488. buffer[j++] = up + c;
  15489. }
  15490. for (; i < rowBytes; ++i) {
  15491. up = prevRow[i];
  15492. var upLeft = prevRow[i - pixBytes];
  15493. var left = buffer[j - pixBytes];
  15494. var p = left + up - upLeft;
  15495. var pa = p - left;
  15496. if (pa < 0) {
  15497. pa = -pa;
  15498. }
  15499. var pb = p - up;
  15500. if (pb < 0) {
  15501. pb = -pb;
  15502. }
  15503. var pc = p - upLeft;
  15504. if (pc < 0) {
  15505. pc = -pc;
  15506. }
  15507. c = rawBytes[i];
  15508. if (pa <= pb && pa <= pc) {
  15509. buffer[j++] = left + c;
  15510. } else if (pb <= pc) {
  15511. buffer[j++] = up + c;
  15512. } else {
  15513. buffer[j++] = upLeft + c;
  15514. }
  15515. }
  15516. break;
  15517. default:
  15518. error('Unsupported predictor: ' + predictor);
  15519. }
  15520. this.bufferLength += rowBytes;
  15521. };
  15522. return PredictorStream;
  15523. })();
  15524. /**
  15525. * Depending on the type of JPEG a JpegStream is handled in different ways. For
  15526. * JPEG's that are supported natively such as DeviceGray and DeviceRGB the image
  15527. * data is stored and then loaded by the browser. For unsupported JPEG's we use
  15528. * a library to decode these images and the stream behaves like all the other
  15529. * DecodeStreams.
  15530. */
  15531. var JpegStream = (function JpegStreamClosure() {
  15532. function JpegStream(stream, maybeLength, dict, xref) {
  15533. // Some images may contain 'junk' before the SOI (start-of-image) marker.
  15534. // Note: this seems to mainly affect inline images.
  15535. var ch;
  15536. while ((ch = stream.getByte()) !== -1) {
  15537. if (ch === 0xFF) { // Find the first byte of the SOI marker (0xFFD8).
  15538. stream.skip(-1); // Reset the stream position to the SOI.
  15539. break;
  15540. }
  15541. }
  15542. this.stream = stream;
  15543. this.maybeLength = maybeLength;
  15544. this.dict = dict;
  15545. DecodeStream.call(this, maybeLength);
  15546. }
  15547. JpegStream.prototype = Object.create(DecodeStream.prototype);
  15548. Object.defineProperty(JpegStream.prototype, 'bytes', {
  15549. get: function JpegStream_bytes() {
  15550. // If this.maybeLength is null, we'll get the entire stream.
  15551. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  15552. },
  15553. configurable: true
  15554. });
  15555. JpegStream.prototype.ensureBuffer = function JpegStream_ensureBuffer(req) {
  15556. if (this.bufferLength) {
  15557. return;
  15558. }
  15559. try {
  15560. var jpegImage = new JpegImage();
  15561. // checking if values needs to be transformed before conversion
  15562. if (this.forceRGB && this.dict && isArray(this.dict.get('Decode'))) {
  15563. var decodeArr = this.dict.get('Decode');
  15564. var bitsPerComponent = this.dict.get('BitsPerComponent') || 8;
  15565. var decodeArrLength = decodeArr.length;
  15566. var transform = new Int32Array(decodeArrLength);
  15567. var transformNeeded = false;
  15568. var maxValue = (1 << bitsPerComponent) - 1;
  15569. for (var i = 0; i < decodeArrLength; i += 2) {
  15570. transform[i] = ((decodeArr[i + 1] - decodeArr[i]) * 256) | 0;
  15571. transform[i + 1] = (decodeArr[i] * maxValue) | 0;
  15572. if (transform[i] !== 256 || transform[i + 1] !== 0) {
  15573. transformNeeded = true;
  15574. }
  15575. }
  15576. if (transformNeeded) {
  15577. jpegImage.decodeTransform = transform;
  15578. }
  15579. }
  15580. jpegImage.parse(this.bytes);
  15581. var data = jpegImage.getData(this.drawWidth, this.drawHeight,
  15582. this.forceRGB);
  15583. this.buffer = data;
  15584. this.bufferLength = data.length;
  15585. this.eof = true;
  15586. } catch (e) {
  15587. error('JPEG error: ' + e);
  15588. }
  15589. };
  15590. JpegStream.prototype.getBytes = function JpegStream_getBytes(length) {
  15591. this.ensureBuffer();
  15592. return this.buffer;
  15593. };
  15594. JpegStream.prototype.getIR = function JpegStream_getIR() {
  15595. return PDFJS.createObjectURL(this.bytes, 'image/jpeg');
  15596. };
  15597. /**
  15598. * Checks if the image can be decoded and displayed by the browser without any
  15599. * further processing such as color space conversions.
  15600. */
  15601. JpegStream.prototype.isNativelySupported =
  15602. function JpegStream_isNativelySupported(xref, res) {
  15603. var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
  15604. return (cs.name === 'DeviceGray' || cs.name === 'DeviceRGB') &&
  15605. cs.isDefaultDecode(this.dict.get('Decode', 'D'));
  15606. };
  15607. /**
  15608. * Checks if the image can be decoded by the browser.
  15609. */
  15610. JpegStream.prototype.isNativelyDecodable =
  15611. function JpegStream_isNativelyDecodable(xref, res) {
  15612. var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
  15613. return (cs.numComps === 1 || cs.numComps === 3) &&
  15614. cs.isDefaultDecode(this.dict.get('Decode', 'D'));
  15615. };
  15616. return JpegStream;
  15617. })();
  15618. /**
  15619. * For JPEG 2000's we use a library to decode these images and
  15620. * the stream behaves like all the other DecodeStreams.
  15621. */
  15622. var JpxStream = (function JpxStreamClosure() {
  15623. function JpxStream(stream, maybeLength, dict) {
  15624. this.stream = stream;
  15625. this.maybeLength = maybeLength;
  15626. this.dict = dict;
  15627. DecodeStream.call(this, maybeLength);
  15628. }
  15629. JpxStream.prototype = Object.create(DecodeStream.prototype);
  15630. Object.defineProperty(JpxStream.prototype, 'bytes', {
  15631. get: function JpxStream_bytes() {
  15632. // If this.maybeLength is null, we'll get the entire stream.
  15633. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  15634. },
  15635. configurable: true
  15636. });
  15637. JpxStream.prototype.ensureBuffer = function JpxStream_ensureBuffer(req) {
  15638. if (this.bufferLength) {
  15639. return;
  15640. }
  15641. var jpxImage = new JpxImage();
  15642. jpxImage.parse(this.bytes);
  15643. var width = jpxImage.width;
  15644. var height = jpxImage.height;
  15645. var componentsCount = jpxImage.componentsCount;
  15646. var tileCount = jpxImage.tiles.length;
  15647. if (tileCount === 1) {
  15648. this.buffer = jpxImage.tiles[0].items;
  15649. } else {
  15650. var data = new Uint8Array(width * height * componentsCount);
  15651. for (var k = 0; k < tileCount; k++) {
  15652. var tileComponents = jpxImage.tiles[k];
  15653. var tileWidth = tileComponents.width;
  15654. var tileHeight = tileComponents.height;
  15655. var tileLeft = tileComponents.left;
  15656. var tileTop = tileComponents.top;
  15657. var src = tileComponents.items;
  15658. var srcPosition = 0;
  15659. var dataPosition = (width * tileTop + tileLeft) * componentsCount;
  15660. var imgRowSize = width * componentsCount;
  15661. var tileRowSize = tileWidth * componentsCount;
  15662. for (var j = 0; j < tileHeight; j++) {
  15663. var rowBytes = src.subarray(srcPosition, srcPosition + tileRowSize);
  15664. data.set(rowBytes, dataPosition);
  15665. srcPosition += tileRowSize;
  15666. dataPosition += imgRowSize;
  15667. }
  15668. }
  15669. this.buffer = data;
  15670. }
  15671. this.bufferLength = this.buffer.length;
  15672. this.eof = true;
  15673. };
  15674. return JpxStream;
  15675. })();
  15676. /**
  15677. * For JBIG2's we use a library to decode these images and
  15678. * the stream behaves like all the other DecodeStreams.
  15679. */
  15680. var Jbig2Stream = (function Jbig2StreamClosure() {
  15681. function Jbig2Stream(stream, maybeLength, dict) {
  15682. this.stream = stream;
  15683. this.maybeLength = maybeLength;
  15684. this.dict = dict;
  15685. DecodeStream.call(this, maybeLength);
  15686. }
  15687. Jbig2Stream.prototype = Object.create(DecodeStream.prototype);
  15688. Object.defineProperty(Jbig2Stream.prototype, 'bytes', {
  15689. get: function Jbig2Stream_bytes() {
  15690. // If this.maybeLength is null, we'll get the entire stream.
  15691. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  15692. },
  15693. configurable: true
  15694. });
  15695. Jbig2Stream.prototype.ensureBuffer = function Jbig2Stream_ensureBuffer(req) {
  15696. if (this.bufferLength) {
  15697. return;
  15698. }
  15699. var jbig2Image = new Jbig2Image();
  15700. var chunks = [], xref = this.dict.xref;
  15701. var decodeParams = xref.fetchIfRef(this.dict.get('DecodeParms'));
  15702. // According to the PDF specification, DecodeParms can be either
  15703. // a dictionary, or an array whose elements are dictionaries.
  15704. if (isArray(decodeParams)) {
  15705. if (decodeParams.length > 1) {
  15706. warn('JBIG2 - \'DecodeParms\' array with multiple elements ' +
  15707. 'not supported.');
  15708. }
  15709. decodeParams = xref.fetchIfRef(decodeParams[0]);
  15710. }
  15711. if (decodeParams && decodeParams.has('JBIG2Globals')) {
  15712. var globalsStream = decodeParams.get('JBIG2Globals');
  15713. var globals = globalsStream.getBytes();
  15714. chunks.push({data: globals, start: 0, end: globals.length});
  15715. }
  15716. chunks.push({data: this.bytes, start: 0, end: this.bytes.length});
  15717. var data = jbig2Image.parseChunks(chunks);
  15718. var dataLength = data.length;
  15719. // JBIG2 had black as 1 and white as 0, inverting the colors
  15720. for (var i = 0; i < dataLength; i++) {
  15721. data[i] ^= 0xFF;
  15722. }
  15723. this.buffer = data;
  15724. this.bufferLength = dataLength;
  15725. this.eof = true;
  15726. };
  15727. return Jbig2Stream;
  15728. })();
  15729. var DecryptStream = (function DecryptStreamClosure() {
  15730. function DecryptStream(str, maybeLength, decrypt) {
  15731. this.str = str;
  15732. this.dict = str.dict;
  15733. this.decrypt = decrypt;
  15734. this.nextChunk = null;
  15735. this.initialized = false;
  15736. DecodeStream.call(this, maybeLength);
  15737. }
  15738. var chunkSize = 512;
  15739. DecryptStream.prototype = Object.create(DecodeStream.prototype);
  15740. DecryptStream.prototype.readBlock = function DecryptStream_readBlock() {
  15741. var chunk;
  15742. if (this.initialized) {
  15743. chunk = this.nextChunk;
  15744. } else {
  15745. chunk = this.str.getBytes(chunkSize);
  15746. this.initialized = true;
  15747. }
  15748. if (!chunk || chunk.length === 0) {
  15749. this.eof = true;
  15750. return;
  15751. }
  15752. this.nextChunk = this.str.getBytes(chunkSize);
  15753. var hasMoreData = this.nextChunk && this.nextChunk.length > 0;
  15754. var decrypt = this.decrypt;
  15755. chunk = decrypt(chunk, !hasMoreData);
  15756. var bufferLength = this.bufferLength;
  15757. var i, n = chunk.length;
  15758. var buffer = this.ensureBuffer(bufferLength + n);
  15759. for (i = 0; i < n; i++) {
  15760. buffer[bufferLength++] = chunk[i];
  15761. }
  15762. this.bufferLength = bufferLength;
  15763. };
  15764. return DecryptStream;
  15765. })();
  15766. var Ascii85Stream = (function Ascii85StreamClosure() {
  15767. function Ascii85Stream(str, maybeLength) {
  15768. this.str = str;
  15769. this.dict = str.dict;
  15770. this.input = new Uint8Array(5);
  15771. // Most streams increase in size when decoded, but Ascii85 streams
  15772. // typically shrink by ~20%.
  15773. if (maybeLength) {
  15774. maybeLength = 0.8 * maybeLength;
  15775. }
  15776. DecodeStream.call(this, maybeLength);
  15777. }
  15778. Ascii85Stream.prototype = Object.create(DecodeStream.prototype);
  15779. Ascii85Stream.prototype.readBlock = function Ascii85Stream_readBlock() {
  15780. var TILDA_CHAR = 0x7E; // '~'
  15781. var Z_LOWER_CHAR = 0x7A; // 'z'
  15782. var EOF = -1;
  15783. var str = this.str;
  15784. var c = str.getByte();
  15785. while (Lexer.isSpace(c)) {
  15786. c = str.getByte();
  15787. }
  15788. if (c === EOF || c === TILDA_CHAR) {
  15789. this.eof = true;
  15790. return;
  15791. }
  15792. var bufferLength = this.bufferLength, buffer;
  15793. var i;
  15794. // special code for z
  15795. if (c === Z_LOWER_CHAR) {
  15796. buffer = this.ensureBuffer(bufferLength + 4);
  15797. for (i = 0; i < 4; ++i) {
  15798. buffer[bufferLength + i] = 0;
  15799. }
  15800. this.bufferLength += 4;
  15801. } else {
  15802. var input = this.input;
  15803. input[0] = c;
  15804. for (i = 1; i < 5; ++i) {
  15805. c = str.getByte();
  15806. while (Lexer.isSpace(c)) {
  15807. c = str.getByte();
  15808. }
  15809. input[i] = c;
  15810. if (c === EOF || c === TILDA_CHAR) {
  15811. break;
  15812. }
  15813. }
  15814. buffer = this.ensureBuffer(bufferLength + i - 1);
  15815. this.bufferLength += i - 1;
  15816. // partial ending;
  15817. if (i < 5) {
  15818. for (; i < 5; ++i) {
  15819. input[i] = 0x21 + 84;
  15820. }
  15821. this.eof = true;
  15822. }
  15823. var t = 0;
  15824. for (i = 0; i < 5; ++i) {
  15825. t = t * 85 + (input[i] - 0x21);
  15826. }
  15827. for (i = 3; i >= 0; --i) {
  15828. buffer[bufferLength + i] = t & 0xFF;
  15829. t >>= 8;
  15830. }
  15831. }
  15832. };
  15833. return Ascii85Stream;
  15834. })();
  15835. var AsciiHexStream = (function AsciiHexStreamClosure() {
  15836. function AsciiHexStream(str, maybeLength) {
  15837. this.str = str;
  15838. this.dict = str.dict;
  15839. this.firstDigit = -1;
  15840. // Most streams increase in size when decoded, but AsciiHex streams shrink
  15841. // by 50%.
  15842. if (maybeLength) {
  15843. maybeLength = 0.5 * maybeLength;
  15844. }
  15845. DecodeStream.call(this, maybeLength);
  15846. }
  15847. AsciiHexStream.prototype = Object.create(DecodeStream.prototype);
  15848. AsciiHexStream.prototype.readBlock = function AsciiHexStream_readBlock() {
  15849. var UPSTREAM_BLOCK_SIZE = 8000;
  15850. var bytes = this.str.getBytes(UPSTREAM_BLOCK_SIZE);
  15851. if (!bytes.length) {
  15852. this.eof = true;
  15853. return;
  15854. }
  15855. var maxDecodeLength = (bytes.length + 1) >> 1;
  15856. var buffer = this.ensureBuffer(this.bufferLength + maxDecodeLength);
  15857. var bufferLength = this.bufferLength;
  15858. var firstDigit = this.firstDigit;
  15859. for (var i = 0, ii = bytes.length; i < ii; i++) {
  15860. var ch = bytes[i], digit;
  15861. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  15862. digit = ch & 0x0F;
  15863. } else if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  15864. // 'A'-'Z', 'a'-'z'
  15865. digit = (ch & 0x0F) + 9;
  15866. } else if (ch === 0x3E) { // '>'
  15867. this.eof = true;
  15868. break;
  15869. } else { // probably whitespace
  15870. continue; // ignoring
  15871. }
  15872. if (firstDigit < 0) {
  15873. firstDigit = digit;
  15874. } else {
  15875. buffer[bufferLength++] = (firstDigit << 4) | digit;
  15876. firstDigit = -1;
  15877. }
  15878. }
  15879. if (firstDigit >= 0 && this.eof) {
  15880. // incomplete byte
  15881. buffer[bufferLength++] = (firstDigit << 4);
  15882. firstDigit = -1;
  15883. }
  15884. this.firstDigit = firstDigit;
  15885. this.bufferLength = bufferLength;
  15886. };
  15887. return AsciiHexStream;
  15888. })();
  15889. var RunLengthStream = (function RunLengthStreamClosure() {
  15890. function RunLengthStream(str, maybeLength) {
  15891. this.str = str;
  15892. this.dict = str.dict;
  15893. DecodeStream.call(this, maybeLength);
  15894. }
  15895. RunLengthStream.prototype = Object.create(DecodeStream.prototype);
  15896. RunLengthStream.prototype.readBlock = function RunLengthStream_readBlock() {
  15897. // The repeatHeader has following format. The first byte defines type of run
  15898. // and amount of bytes to repeat/copy: n = 0 through 127 - copy next n bytes
  15899. // (in addition to the second byte from the header), n = 129 through 255 -
  15900. // duplicate the second byte from the header (257 - n) times, n = 128 - end.
  15901. var repeatHeader = this.str.getBytes(2);
  15902. if (!repeatHeader || repeatHeader.length < 2 || repeatHeader[0] === 128) {
  15903. this.eof = true;
  15904. return;
  15905. }
  15906. var buffer;
  15907. var bufferLength = this.bufferLength;
  15908. var n = repeatHeader[0];
  15909. if (n < 128) {
  15910. // copy n bytes
  15911. buffer = this.ensureBuffer(bufferLength + n + 1);
  15912. buffer[bufferLength++] = repeatHeader[1];
  15913. if (n > 0) {
  15914. var source = this.str.getBytes(n);
  15915. buffer.set(source, bufferLength);
  15916. bufferLength += n;
  15917. }
  15918. } else {
  15919. n = 257 - n;
  15920. var b = repeatHeader[1];
  15921. buffer = this.ensureBuffer(bufferLength + n + 1);
  15922. for (var i = 0; i < n; i++) {
  15923. buffer[bufferLength++] = b;
  15924. }
  15925. }
  15926. this.bufferLength = bufferLength;
  15927. };
  15928. return RunLengthStream;
  15929. })();
  15930. var CCITTFaxStream = (function CCITTFaxStreamClosure() {
  15931. var ccittEOL = -2;
  15932. var twoDimPass = 0;
  15933. var twoDimHoriz = 1;
  15934. var twoDimVert0 = 2;
  15935. var twoDimVertR1 = 3;
  15936. var twoDimVertL1 = 4;
  15937. var twoDimVertR2 = 5;
  15938. var twoDimVertL2 = 6;
  15939. var twoDimVertR3 = 7;
  15940. var twoDimVertL3 = 8;
  15941. var twoDimTable = [
  15942. [-1, -1], [-1, -1], // 000000x
  15943. [7, twoDimVertL3], // 0000010
  15944. [7, twoDimVertR3], // 0000011
  15945. [6, twoDimVertL2], [6, twoDimVertL2], // 000010x
  15946. [6, twoDimVertR2], [6, twoDimVertR2], // 000011x
  15947. [4, twoDimPass], [4, twoDimPass], // 0001xxx
  15948. [4, twoDimPass], [4, twoDimPass],
  15949. [4, twoDimPass], [4, twoDimPass],
  15950. [4, twoDimPass], [4, twoDimPass],
  15951. [3, twoDimHoriz], [3, twoDimHoriz], // 001xxxx
  15952. [3, twoDimHoriz], [3, twoDimHoriz],
  15953. [3, twoDimHoriz], [3, twoDimHoriz],
  15954. [3, twoDimHoriz], [3, twoDimHoriz],
  15955. [3, twoDimHoriz], [3, twoDimHoriz],
  15956. [3, twoDimHoriz], [3, twoDimHoriz],
  15957. [3, twoDimHoriz], [3, twoDimHoriz],
  15958. [3, twoDimHoriz], [3, twoDimHoriz],
  15959. [3, twoDimVertL1], [3, twoDimVertL1], // 010xxxx
  15960. [3, twoDimVertL1], [3, twoDimVertL1],
  15961. [3, twoDimVertL1], [3, twoDimVertL1],
  15962. [3, twoDimVertL1], [3, twoDimVertL1],
  15963. [3, twoDimVertL1], [3, twoDimVertL1],
  15964. [3, twoDimVertL1], [3, twoDimVertL1],
  15965. [3, twoDimVertL1], [3, twoDimVertL1],
  15966. [3, twoDimVertL1], [3, twoDimVertL1],
  15967. [3, twoDimVertR1], [3, twoDimVertR1], // 011xxxx
  15968. [3, twoDimVertR1], [3, twoDimVertR1],
  15969. [3, twoDimVertR1], [3, twoDimVertR1],
  15970. [3, twoDimVertR1], [3, twoDimVertR1],
  15971. [3, twoDimVertR1], [3, twoDimVertR1],
  15972. [3, twoDimVertR1], [3, twoDimVertR1],
  15973. [3, twoDimVertR1], [3, twoDimVertR1],
  15974. [3, twoDimVertR1], [3, twoDimVertR1],
  15975. [1, twoDimVert0], [1, twoDimVert0], // 1xxxxxx
  15976. [1, twoDimVert0], [1, twoDimVert0],
  15977. [1, twoDimVert0], [1, twoDimVert0],
  15978. [1, twoDimVert0], [1, twoDimVert0],
  15979. [1, twoDimVert0], [1, twoDimVert0],
  15980. [1, twoDimVert0], [1, twoDimVert0],
  15981. [1, twoDimVert0], [1, twoDimVert0],
  15982. [1, twoDimVert0], [1, twoDimVert0],
  15983. [1, twoDimVert0], [1, twoDimVert0],
  15984. [1, twoDimVert0], [1, twoDimVert0],
  15985. [1, twoDimVert0], [1, twoDimVert0],
  15986. [1, twoDimVert0], [1, twoDimVert0],
  15987. [1, twoDimVert0], [1, twoDimVert0],
  15988. [1, twoDimVert0], [1, twoDimVert0],
  15989. [1, twoDimVert0], [1, twoDimVert0],
  15990. [1, twoDimVert0], [1, twoDimVert0],
  15991. [1, twoDimVert0], [1, twoDimVert0],
  15992. [1, twoDimVert0], [1, twoDimVert0],
  15993. [1, twoDimVert0], [1, twoDimVert0],
  15994. [1, twoDimVert0], [1, twoDimVert0],
  15995. [1, twoDimVert0], [1, twoDimVert0],
  15996. [1, twoDimVert0], [1, twoDimVert0],
  15997. [1, twoDimVert0], [1, twoDimVert0],
  15998. [1, twoDimVert0], [1, twoDimVert0],
  15999. [1, twoDimVert0], [1, twoDimVert0],
  16000. [1, twoDimVert0], [1, twoDimVert0],
  16001. [1, twoDimVert0], [1, twoDimVert0],
  16002. [1, twoDimVert0], [1, twoDimVert0],
  16003. [1, twoDimVert0], [1, twoDimVert0],
  16004. [1, twoDimVert0], [1, twoDimVert0],
  16005. [1, twoDimVert0], [1, twoDimVert0],
  16006. [1, twoDimVert0], [1, twoDimVert0]
  16007. ];
  16008. var whiteTable1 = [
  16009. [-1, -1], // 00000
  16010. [12, ccittEOL], // 00001
  16011. [-1, -1], [-1, -1], // 0001x
  16012. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 001xx
  16013. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 010xx
  16014. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 011xx
  16015. [11, 1792], [11, 1792], // 1000x
  16016. [12, 1984], // 10010
  16017. [12, 2048], // 10011
  16018. [12, 2112], // 10100
  16019. [12, 2176], // 10101
  16020. [12, 2240], // 10110
  16021. [12, 2304], // 10111
  16022. [11, 1856], [11, 1856], // 1100x
  16023. [11, 1920], [11, 1920], // 1101x
  16024. [12, 2368], // 11100
  16025. [12, 2432], // 11101
  16026. [12, 2496], // 11110
  16027. [12, 2560] // 11111
  16028. ];
  16029. var whiteTable2 = [
  16030. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000000xx
  16031. [8, 29], [8, 29], // 00000010x
  16032. [8, 30], [8, 30], // 00000011x
  16033. [8, 45], [8, 45], // 00000100x
  16034. [8, 46], [8, 46], // 00000101x
  16035. [7, 22], [7, 22], [7, 22], [7, 22], // 0000011xx
  16036. [7, 23], [7, 23], [7, 23], [7, 23], // 0000100xx
  16037. [8, 47], [8, 47], // 00001010x
  16038. [8, 48], [8, 48], // 00001011x
  16039. [6, 13], [6, 13], [6, 13], [6, 13], // 000011xxx
  16040. [6, 13], [6, 13], [6, 13], [6, 13],
  16041. [7, 20], [7, 20], [7, 20], [7, 20], // 0001000xx
  16042. [8, 33], [8, 33], // 00010010x
  16043. [8, 34], [8, 34], // 00010011x
  16044. [8, 35], [8, 35], // 00010100x
  16045. [8, 36], [8, 36], // 00010101x
  16046. [8, 37], [8, 37], // 00010110x
  16047. [8, 38], [8, 38], // 00010111x
  16048. [7, 19], [7, 19], [7, 19], [7, 19], // 0001100xx
  16049. [8, 31], [8, 31], // 00011010x
  16050. [8, 32], [8, 32], // 00011011x
  16051. [6, 1], [6, 1], [6, 1], [6, 1], // 000111xxx
  16052. [6, 1], [6, 1], [6, 1], [6, 1],
  16053. [6, 12], [6, 12], [6, 12], [6, 12], // 001000xxx
  16054. [6, 12], [6, 12], [6, 12], [6, 12],
  16055. [8, 53], [8, 53], // 00100100x
  16056. [8, 54], [8, 54], // 00100101x
  16057. [7, 26], [7, 26], [7, 26], [7, 26], // 0010011xx
  16058. [8, 39], [8, 39], // 00101000x
  16059. [8, 40], [8, 40], // 00101001x
  16060. [8, 41], [8, 41], // 00101010x
  16061. [8, 42], [8, 42], // 00101011x
  16062. [8, 43], [8, 43], // 00101100x
  16063. [8, 44], [8, 44], // 00101101x
  16064. [7, 21], [7, 21], [7, 21], [7, 21], // 0010111xx
  16065. [7, 28], [7, 28], [7, 28], [7, 28], // 0011000xx
  16066. [8, 61], [8, 61], // 00110010x
  16067. [8, 62], [8, 62], // 00110011x
  16068. [8, 63], [8, 63], // 00110100x
  16069. [8, 0], [8, 0], // 00110101x
  16070. [8, 320], [8, 320], // 00110110x
  16071. [8, 384], [8, 384], // 00110111x
  16072. [5, 10], [5, 10], [5, 10], [5, 10], // 00111xxxx
  16073. [5, 10], [5, 10], [5, 10], [5, 10],
  16074. [5, 10], [5, 10], [5, 10], [5, 10],
  16075. [5, 10], [5, 10], [5, 10], [5, 10],
  16076. [5, 11], [5, 11], [5, 11], [5, 11], // 01000xxxx
  16077. [5, 11], [5, 11], [5, 11], [5, 11],
  16078. [5, 11], [5, 11], [5, 11], [5, 11],
  16079. [5, 11], [5, 11], [5, 11], [5, 11],
  16080. [7, 27], [7, 27], [7, 27], [7, 27], // 0100100xx
  16081. [8, 59], [8, 59], // 01001010x
  16082. [8, 60], [8, 60], // 01001011x
  16083. [9, 1472], // 010011000
  16084. [9, 1536], // 010011001
  16085. [9, 1600], // 010011010
  16086. [9, 1728], // 010011011
  16087. [7, 18], [7, 18], [7, 18], [7, 18], // 0100111xx
  16088. [7, 24], [7, 24], [7, 24], [7, 24], // 0101000xx
  16089. [8, 49], [8, 49], // 01010010x
  16090. [8, 50], [8, 50], // 01010011x
  16091. [8, 51], [8, 51], // 01010100x
  16092. [8, 52], [8, 52], // 01010101x
  16093. [7, 25], [7, 25], [7, 25], [7, 25], // 0101011xx
  16094. [8, 55], [8, 55], // 01011000x
  16095. [8, 56], [8, 56], // 01011001x
  16096. [8, 57], [8, 57], // 01011010x
  16097. [8, 58], [8, 58], // 01011011x
  16098. [6, 192], [6, 192], [6, 192], [6, 192], // 010111xxx
  16099. [6, 192], [6, 192], [6, 192], [6, 192],
  16100. [6, 1664], [6, 1664], [6, 1664], [6, 1664], // 011000xxx
  16101. [6, 1664], [6, 1664], [6, 1664], [6, 1664],
  16102. [8, 448], [8, 448], // 01100100x
  16103. [8, 512], [8, 512], // 01100101x
  16104. [9, 704], // 011001100
  16105. [9, 768], // 011001101
  16106. [8, 640], [8, 640], // 01100111x
  16107. [8, 576], [8, 576], // 01101000x
  16108. [9, 832], // 011010010
  16109. [9, 896], // 011010011
  16110. [9, 960], // 011010100
  16111. [9, 1024], // 011010101
  16112. [9, 1088], // 011010110
  16113. [9, 1152], // 011010111
  16114. [9, 1216], // 011011000
  16115. [9, 1280], // 011011001
  16116. [9, 1344], // 011011010
  16117. [9, 1408], // 011011011
  16118. [7, 256], [7, 256], [7, 256], [7, 256], // 0110111xx
  16119. [4, 2], [4, 2], [4, 2], [4, 2], // 0111xxxxx
  16120. [4, 2], [4, 2], [4, 2], [4, 2],
  16121. [4, 2], [4, 2], [4, 2], [4, 2],
  16122. [4, 2], [4, 2], [4, 2], [4, 2],
  16123. [4, 2], [4, 2], [4, 2], [4, 2],
  16124. [4, 2], [4, 2], [4, 2], [4, 2],
  16125. [4, 2], [4, 2], [4, 2], [4, 2],
  16126. [4, 2], [4, 2], [4, 2], [4, 2],
  16127. [4, 3], [4, 3], [4, 3], [4, 3], // 1000xxxxx
  16128. [4, 3], [4, 3], [4, 3], [4, 3],
  16129. [4, 3], [4, 3], [4, 3], [4, 3],
  16130. [4, 3], [4, 3], [4, 3], [4, 3],
  16131. [4, 3], [4, 3], [4, 3], [4, 3],
  16132. [4, 3], [4, 3], [4, 3], [4, 3],
  16133. [4, 3], [4, 3], [4, 3], [4, 3],
  16134. [4, 3], [4, 3], [4, 3], [4, 3],
  16135. [5, 128], [5, 128], [5, 128], [5, 128], // 10010xxxx
  16136. [5, 128], [5, 128], [5, 128], [5, 128],
  16137. [5, 128], [5, 128], [5, 128], [5, 128],
  16138. [5, 128], [5, 128], [5, 128], [5, 128],
  16139. [5, 8], [5, 8], [5, 8], [5, 8], // 10011xxxx
  16140. [5, 8], [5, 8], [5, 8], [5, 8],
  16141. [5, 8], [5, 8], [5, 8], [5, 8],
  16142. [5, 8], [5, 8], [5, 8], [5, 8],
  16143. [5, 9], [5, 9], [5, 9], [5, 9], // 10100xxxx
  16144. [5, 9], [5, 9], [5, 9], [5, 9],
  16145. [5, 9], [5, 9], [5, 9], [5, 9],
  16146. [5, 9], [5, 9], [5, 9], [5, 9],
  16147. [6, 16], [6, 16], [6, 16], [6, 16], // 101010xxx
  16148. [6, 16], [6, 16], [6, 16], [6, 16],
  16149. [6, 17], [6, 17], [6, 17], [6, 17], // 101011xxx
  16150. [6, 17], [6, 17], [6, 17], [6, 17],
  16151. [4, 4], [4, 4], [4, 4], [4, 4], // 1011xxxxx
  16152. [4, 4], [4, 4], [4, 4], [4, 4],
  16153. [4, 4], [4, 4], [4, 4], [4, 4],
  16154. [4, 4], [4, 4], [4, 4], [4, 4],
  16155. [4, 4], [4, 4], [4, 4], [4, 4],
  16156. [4, 4], [4, 4], [4, 4], [4, 4],
  16157. [4, 4], [4, 4], [4, 4], [4, 4],
  16158. [4, 4], [4, 4], [4, 4], [4, 4],
  16159. [4, 5], [4, 5], [4, 5], [4, 5], // 1100xxxxx
  16160. [4, 5], [4, 5], [4, 5], [4, 5],
  16161. [4, 5], [4, 5], [4, 5], [4, 5],
  16162. [4, 5], [4, 5], [4, 5], [4, 5],
  16163. [4, 5], [4, 5], [4, 5], [4, 5],
  16164. [4, 5], [4, 5], [4, 5], [4, 5],
  16165. [4, 5], [4, 5], [4, 5], [4, 5],
  16166. [4, 5], [4, 5], [4, 5], [4, 5],
  16167. [6, 14], [6, 14], [6, 14], [6, 14], // 110100xxx
  16168. [6, 14], [6, 14], [6, 14], [6, 14],
  16169. [6, 15], [6, 15], [6, 15], [6, 15], // 110101xxx
  16170. [6, 15], [6, 15], [6, 15], [6, 15],
  16171. [5, 64], [5, 64], [5, 64], [5, 64], // 11011xxxx
  16172. [5, 64], [5, 64], [5, 64], [5, 64],
  16173. [5, 64], [5, 64], [5, 64], [5, 64],
  16174. [5, 64], [5, 64], [5, 64], [5, 64],
  16175. [4, 6], [4, 6], [4, 6], [4, 6], // 1110xxxxx
  16176. [4, 6], [4, 6], [4, 6], [4, 6],
  16177. [4, 6], [4, 6], [4, 6], [4, 6],
  16178. [4, 6], [4, 6], [4, 6], [4, 6],
  16179. [4, 6], [4, 6], [4, 6], [4, 6],
  16180. [4, 6], [4, 6], [4, 6], [4, 6],
  16181. [4, 6], [4, 6], [4, 6], [4, 6],
  16182. [4, 6], [4, 6], [4, 6], [4, 6],
  16183. [4, 7], [4, 7], [4, 7], [4, 7], // 1111xxxxx
  16184. [4, 7], [4, 7], [4, 7], [4, 7],
  16185. [4, 7], [4, 7], [4, 7], [4, 7],
  16186. [4, 7], [4, 7], [4, 7], [4, 7],
  16187. [4, 7], [4, 7], [4, 7], [4, 7],
  16188. [4, 7], [4, 7], [4, 7], [4, 7],
  16189. [4, 7], [4, 7], [4, 7], [4, 7],
  16190. [4, 7], [4, 7], [4, 7], [4, 7]
  16191. ];
  16192. var blackTable1 = [
  16193. [-1, -1], [-1, -1], // 000000000000x
  16194. [12, ccittEOL], [12, ccittEOL], // 000000000001x
  16195. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000001xx
  16196. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000010xx
  16197. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000011xx
  16198. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000100xx
  16199. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000101xx
  16200. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000110xx
  16201. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000111xx
  16202. [11, 1792], [11, 1792], [11, 1792], [11, 1792], // 00000001000xx
  16203. [12, 1984], [12, 1984], // 000000010010x
  16204. [12, 2048], [12, 2048], // 000000010011x
  16205. [12, 2112], [12, 2112], // 000000010100x
  16206. [12, 2176], [12, 2176], // 000000010101x
  16207. [12, 2240], [12, 2240], // 000000010110x
  16208. [12, 2304], [12, 2304], // 000000010111x
  16209. [11, 1856], [11, 1856], [11, 1856], [11, 1856], // 00000001100xx
  16210. [11, 1920], [11, 1920], [11, 1920], [11, 1920], // 00000001101xx
  16211. [12, 2368], [12, 2368], // 000000011100x
  16212. [12, 2432], [12, 2432], // 000000011101x
  16213. [12, 2496], [12, 2496], // 000000011110x
  16214. [12, 2560], [12, 2560], // 000000011111x
  16215. [10, 18], [10, 18], [10, 18], [10, 18], // 0000001000xxx
  16216. [10, 18], [10, 18], [10, 18], [10, 18],
  16217. [12, 52], [12, 52], // 000000100100x
  16218. [13, 640], // 0000001001010
  16219. [13, 704], // 0000001001011
  16220. [13, 768], // 0000001001100
  16221. [13, 832], // 0000001001101
  16222. [12, 55], [12, 55], // 000000100111x
  16223. [12, 56], [12, 56], // 000000101000x
  16224. [13, 1280], // 0000001010010
  16225. [13, 1344], // 0000001010011
  16226. [13, 1408], // 0000001010100
  16227. [13, 1472], // 0000001010101
  16228. [12, 59], [12, 59], // 000000101011x
  16229. [12, 60], [12, 60], // 000000101100x
  16230. [13, 1536], // 0000001011010
  16231. [13, 1600], // 0000001011011
  16232. [11, 24], [11, 24], [11, 24], [11, 24], // 00000010111xx
  16233. [11, 25], [11, 25], [11, 25], [11, 25], // 00000011000xx
  16234. [13, 1664], // 0000001100100
  16235. [13, 1728], // 0000001100101
  16236. [12, 320], [12, 320], // 000000110011x
  16237. [12, 384], [12, 384], // 000000110100x
  16238. [12, 448], [12, 448], // 000000110101x
  16239. [13, 512], // 0000001101100
  16240. [13, 576], // 0000001101101
  16241. [12, 53], [12, 53], // 000000110111x
  16242. [12, 54], [12, 54], // 000000111000x
  16243. [13, 896], // 0000001110010
  16244. [13, 960], // 0000001110011
  16245. [13, 1024], // 0000001110100
  16246. [13, 1088], // 0000001110101
  16247. [13, 1152], // 0000001110110
  16248. [13, 1216], // 0000001110111
  16249. [10, 64], [10, 64], [10, 64], [10, 64], // 0000001111xxx
  16250. [10, 64], [10, 64], [10, 64], [10, 64]
  16251. ];
  16252. var blackTable2 = [
  16253. [8, 13], [8, 13], [8, 13], [8, 13], // 00000100xxxx
  16254. [8, 13], [8, 13], [8, 13], [8, 13],
  16255. [8, 13], [8, 13], [8, 13], [8, 13],
  16256. [8, 13], [8, 13], [8, 13], [8, 13],
  16257. [11, 23], [11, 23], // 00000101000x
  16258. [12, 50], // 000001010010
  16259. [12, 51], // 000001010011
  16260. [12, 44], // 000001010100
  16261. [12, 45], // 000001010101
  16262. [12, 46], // 000001010110
  16263. [12, 47], // 000001010111
  16264. [12, 57], // 000001011000
  16265. [12, 58], // 000001011001
  16266. [12, 61], // 000001011010
  16267. [12, 256], // 000001011011
  16268. [10, 16], [10, 16], [10, 16], [10, 16], // 0000010111xx
  16269. [10, 17], [10, 17], [10, 17], [10, 17], // 0000011000xx
  16270. [12, 48], // 000001100100
  16271. [12, 49], // 000001100101
  16272. [12, 62], // 000001100110
  16273. [12, 63], // 000001100111
  16274. [12, 30], // 000001101000
  16275. [12, 31], // 000001101001
  16276. [12, 32], // 000001101010
  16277. [12, 33], // 000001101011
  16278. [12, 40], // 000001101100
  16279. [12, 41], // 000001101101
  16280. [11, 22], [11, 22], // 00000110111x
  16281. [8, 14], [8, 14], [8, 14], [8, 14], // 00000111xxxx
  16282. [8, 14], [8, 14], [8, 14], [8, 14],
  16283. [8, 14], [8, 14], [8, 14], [8, 14],
  16284. [8, 14], [8, 14], [8, 14], [8, 14],
  16285. [7, 10], [7, 10], [7, 10], [7, 10], // 0000100xxxxx
  16286. [7, 10], [7, 10], [7, 10], [7, 10],
  16287. [7, 10], [7, 10], [7, 10], [7, 10],
  16288. [7, 10], [7, 10], [7, 10], [7, 10],
  16289. [7, 10], [7, 10], [7, 10], [7, 10],
  16290. [7, 10], [7, 10], [7, 10], [7, 10],
  16291. [7, 10], [7, 10], [7, 10], [7, 10],
  16292. [7, 10], [7, 10], [7, 10], [7, 10],
  16293. [7, 11], [7, 11], [7, 11], [7, 11], // 0000101xxxxx
  16294. [7, 11], [7, 11], [7, 11], [7, 11],
  16295. [7, 11], [7, 11], [7, 11], [7, 11],
  16296. [7, 11], [7, 11], [7, 11], [7, 11],
  16297. [7, 11], [7, 11], [7, 11], [7, 11],
  16298. [7, 11], [7, 11], [7, 11], [7, 11],
  16299. [7, 11], [7, 11], [7, 11], [7, 11],
  16300. [7, 11], [7, 11], [7, 11], [7, 11],
  16301. [9, 15], [9, 15], [9, 15], [9, 15], // 000011000xxx
  16302. [9, 15], [9, 15], [9, 15], [9, 15],
  16303. [12, 128], // 000011001000
  16304. [12, 192], // 000011001001
  16305. [12, 26], // 000011001010
  16306. [12, 27], // 000011001011
  16307. [12, 28], // 000011001100
  16308. [12, 29], // 000011001101
  16309. [11, 19], [11, 19], // 00001100111x
  16310. [11, 20], [11, 20], // 00001101000x
  16311. [12, 34], // 000011010010
  16312. [12, 35], // 000011010011
  16313. [12, 36], // 000011010100
  16314. [12, 37], // 000011010101
  16315. [12, 38], // 000011010110
  16316. [12, 39], // 000011010111
  16317. [11, 21], [11, 21], // 00001101100x
  16318. [12, 42], // 000011011010
  16319. [12, 43], // 000011011011
  16320. [10, 0], [10, 0], [10, 0], [10, 0], // 0000110111xx
  16321. [7, 12], [7, 12], [7, 12], [7, 12], // 0000111xxxxx
  16322. [7, 12], [7, 12], [7, 12], [7, 12],
  16323. [7, 12], [7, 12], [7, 12], [7, 12],
  16324. [7, 12], [7, 12], [7, 12], [7, 12],
  16325. [7, 12], [7, 12], [7, 12], [7, 12],
  16326. [7, 12], [7, 12], [7, 12], [7, 12],
  16327. [7, 12], [7, 12], [7, 12], [7, 12],
  16328. [7, 12], [7, 12], [7, 12], [7, 12]
  16329. ];
  16330. var blackTable3 = [
  16331. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000xx
  16332. [6, 9], // 000100
  16333. [6, 8], // 000101
  16334. [5, 7], [5, 7], // 00011x
  16335. [4, 6], [4, 6], [4, 6], [4, 6], // 0010xx
  16336. [4, 5], [4, 5], [4, 5], [4, 5], // 0011xx
  16337. [3, 1], [3, 1], [3, 1], [3, 1], // 010xxx
  16338. [3, 1], [3, 1], [3, 1], [3, 1],
  16339. [3, 4], [3, 4], [3, 4], [3, 4], // 011xxx
  16340. [3, 4], [3, 4], [3, 4], [3, 4],
  16341. [2, 3], [2, 3], [2, 3], [2, 3], // 10xxxx
  16342. [2, 3], [2, 3], [2, 3], [2, 3],
  16343. [2, 3], [2, 3], [2, 3], [2, 3],
  16344. [2, 3], [2, 3], [2, 3], [2, 3],
  16345. [2, 2], [2, 2], [2, 2], [2, 2], // 11xxxx
  16346. [2, 2], [2, 2], [2, 2], [2, 2],
  16347. [2, 2], [2, 2], [2, 2], [2, 2],
  16348. [2, 2], [2, 2], [2, 2], [2, 2]
  16349. ];
  16350. function CCITTFaxStream(str, maybeLength, params) {
  16351. this.str = str;
  16352. this.dict = str.dict;
  16353. params = params || Dict.empty;
  16354. this.encoding = params.get('K') || 0;
  16355. this.eoline = params.get('EndOfLine') || false;
  16356. this.byteAlign = params.get('EncodedByteAlign') || false;
  16357. this.columns = params.get('Columns') || 1728;
  16358. this.rows = params.get('Rows') || 0;
  16359. var eoblock = params.get('EndOfBlock');
  16360. if (eoblock === null || eoblock === undefined) {
  16361. eoblock = true;
  16362. }
  16363. this.eoblock = eoblock;
  16364. this.black = params.get('BlackIs1') || false;
  16365. this.codingLine = new Uint32Array(this.columns + 1);
  16366. this.refLine = new Uint32Array(this.columns + 2);
  16367. this.codingLine[0] = this.columns;
  16368. this.codingPos = 0;
  16369. this.row = 0;
  16370. this.nextLine2D = this.encoding < 0;
  16371. this.inputBits = 0;
  16372. this.inputBuf = 0;
  16373. this.outputBits = 0;
  16374. var code1;
  16375. while ((code1 = this.lookBits(12)) === 0) {
  16376. this.eatBits(1);
  16377. }
  16378. if (code1 === 1) {
  16379. this.eatBits(12);
  16380. }
  16381. if (this.encoding > 0) {
  16382. this.nextLine2D = !this.lookBits(1);
  16383. this.eatBits(1);
  16384. }
  16385. DecodeStream.call(this, maybeLength);
  16386. }
  16387. CCITTFaxStream.prototype = Object.create(DecodeStream.prototype);
  16388. CCITTFaxStream.prototype.readBlock = function CCITTFaxStream_readBlock() {
  16389. while (!this.eof) {
  16390. var c = this.lookChar();
  16391. this.ensureBuffer(this.bufferLength + 1);
  16392. this.buffer[this.bufferLength++] = c;
  16393. }
  16394. };
  16395. CCITTFaxStream.prototype.addPixels =
  16396. function ccittFaxStreamAddPixels(a1, blackPixels) {
  16397. var codingLine = this.codingLine;
  16398. var codingPos = this.codingPos;
  16399. if (a1 > codingLine[codingPos]) {
  16400. if (a1 > this.columns) {
  16401. info('row is wrong length');
  16402. this.err = true;
  16403. a1 = this.columns;
  16404. }
  16405. if ((codingPos & 1) ^ blackPixels) {
  16406. ++codingPos;
  16407. }
  16408. codingLine[codingPos] = a1;
  16409. }
  16410. this.codingPos = codingPos;
  16411. };
  16412. CCITTFaxStream.prototype.addPixelsNeg =
  16413. function ccittFaxStreamAddPixelsNeg(a1, blackPixels) {
  16414. var codingLine = this.codingLine;
  16415. var codingPos = this.codingPos;
  16416. if (a1 > codingLine[codingPos]) {
  16417. if (a1 > this.columns) {
  16418. info('row is wrong length');
  16419. this.err = true;
  16420. a1 = this.columns;
  16421. }
  16422. if ((codingPos & 1) ^ blackPixels) {
  16423. ++codingPos;
  16424. }
  16425. codingLine[codingPos] = a1;
  16426. } else if (a1 < codingLine[codingPos]) {
  16427. if (a1 < 0) {
  16428. info('invalid code');
  16429. this.err = true;
  16430. a1 = 0;
  16431. }
  16432. while (codingPos > 0 && a1 < codingLine[codingPos - 1]) {
  16433. --codingPos;
  16434. }
  16435. codingLine[codingPos] = a1;
  16436. }
  16437. this.codingPos = codingPos;
  16438. };
  16439. CCITTFaxStream.prototype.lookChar = function CCITTFaxStream_lookChar() {
  16440. var refLine = this.refLine;
  16441. var codingLine = this.codingLine;
  16442. var columns = this.columns;
  16443. var refPos, blackPixels, bits, i;
  16444. if (this.outputBits === 0) {
  16445. if (this.eof) {
  16446. return null;
  16447. }
  16448. this.err = false;
  16449. var code1, code2, code3;
  16450. if (this.nextLine2D) {
  16451. for (i = 0; codingLine[i] < columns; ++i) {
  16452. refLine[i] = codingLine[i];
  16453. }
  16454. refLine[i++] = columns;
  16455. refLine[i] = columns;
  16456. codingLine[0] = 0;
  16457. this.codingPos = 0;
  16458. refPos = 0;
  16459. blackPixels = 0;
  16460. while (codingLine[this.codingPos] < columns) {
  16461. code1 = this.getTwoDimCode();
  16462. switch (code1) {
  16463. case twoDimPass:
  16464. this.addPixels(refLine[refPos + 1], blackPixels);
  16465. if (refLine[refPos + 1] < columns) {
  16466. refPos += 2;
  16467. }
  16468. break;
  16469. case twoDimHoriz:
  16470. code1 = code2 = 0;
  16471. if (blackPixels) {
  16472. do {
  16473. code1 += (code3 = this.getBlackCode());
  16474. } while (code3 >= 64);
  16475. do {
  16476. code2 += (code3 = this.getWhiteCode());
  16477. } while (code3 >= 64);
  16478. } else {
  16479. do {
  16480. code1 += (code3 = this.getWhiteCode());
  16481. } while (code3 >= 64);
  16482. do {
  16483. code2 += (code3 = this.getBlackCode());
  16484. } while (code3 >= 64);
  16485. }
  16486. this.addPixels(codingLine[this.codingPos] +
  16487. code1, blackPixels);
  16488. if (codingLine[this.codingPos] < columns) {
  16489. this.addPixels(codingLine[this.codingPos] + code2,
  16490. blackPixels ^ 1);
  16491. }
  16492. while (refLine[refPos] <= codingLine[this.codingPos] &&
  16493. refLine[refPos] < columns) {
  16494. refPos += 2;
  16495. }
  16496. break;
  16497. case twoDimVertR3:
  16498. this.addPixels(refLine[refPos] + 3, blackPixels);
  16499. blackPixels ^= 1;
  16500. if (codingLine[this.codingPos] < columns) {
  16501. ++refPos;
  16502. while (refLine[refPos] <= codingLine[this.codingPos] &&
  16503. refLine[refPos] < columns) {
  16504. refPos += 2;
  16505. }
  16506. }
  16507. break;
  16508. case twoDimVertR2:
  16509. this.addPixels(refLine[refPos] + 2, blackPixels);
  16510. blackPixels ^= 1;
  16511. if (codingLine[this.codingPos] < columns) {
  16512. ++refPos;
  16513. while (refLine[refPos] <= codingLine[this.codingPos] &&
  16514. refLine[refPos] < columns) {
  16515. refPos += 2;
  16516. }
  16517. }
  16518. break;
  16519. case twoDimVertR1:
  16520. this.addPixels(refLine[refPos] + 1, blackPixels);
  16521. blackPixels ^= 1;
  16522. if (codingLine[this.codingPos] < columns) {
  16523. ++refPos;
  16524. while (refLine[refPos] <= codingLine[this.codingPos] &&
  16525. refLine[refPos] < columns) {
  16526. refPos += 2;
  16527. }
  16528. }
  16529. break;
  16530. case twoDimVert0:
  16531. this.addPixels(refLine[refPos], blackPixels);
  16532. blackPixels ^= 1;
  16533. if (codingLine[this.codingPos] < columns) {
  16534. ++refPos;
  16535. while (refLine[refPos] <= codingLine[this.codingPos] &&
  16536. refLine[refPos] < columns) {
  16537. refPos += 2;
  16538. }
  16539. }
  16540. break;
  16541. case twoDimVertL3:
  16542. this.addPixelsNeg(refLine[refPos] - 3, blackPixels);
  16543. blackPixels ^= 1;
  16544. if (codingLine[this.codingPos] < columns) {
  16545. if (refPos > 0) {
  16546. --refPos;
  16547. } else {
  16548. ++refPos;
  16549. }
  16550. while (refLine[refPos] <= codingLine[this.codingPos] &&
  16551. refLine[refPos] < columns) {
  16552. refPos += 2;
  16553. }
  16554. }
  16555. break;
  16556. case twoDimVertL2:
  16557. this.addPixelsNeg(refLine[refPos] - 2, blackPixels);
  16558. blackPixels ^= 1;
  16559. if (codingLine[this.codingPos] < columns) {
  16560. if (refPos > 0) {
  16561. --refPos;
  16562. } else {
  16563. ++refPos;
  16564. }
  16565. while (refLine[refPos] <= codingLine[this.codingPos] &&
  16566. refLine[refPos] < columns) {
  16567. refPos += 2;
  16568. }
  16569. }
  16570. break;
  16571. case twoDimVertL1:
  16572. this.addPixelsNeg(refLine[refPos] - 1, blackPixels);
  16573. blackPixels ^= 1;
  16574. if (codingLine[this.codingPos] < columns) {
  16575. if (refPos > 0) {
  16576. --refPos;
  16577. } else {
  16578. ++refPos;
  16579. }
  16580. while (refLine[refPos] <= codingLine[this.codingPos] &&
  16581. refLine[refPos] < columns) {
  16582. refPos += 2;
  16583. }
  16584. }
  16585. break;
  16586. case EOF:
  16587. this.addPixels(columns, 0);
  16588. this.eof = true;
  16589. break;
  16590. default:
  16591. info('bad 2d code');
  16592. this.addPixels(columns, 0);
  16593. this.err = true;
  16594. }
  16595. }
  16596. } else {
  16597. codingLine[0] = 0;
  16598. this.codingPos = 0;
  16599. blackPixels = 0;
  16600. while (codingLine[this.codingPos] < columns) {
  16601. code1 = 0;
  16602. if (blackPixels) {
  16603. do {
  16604. code1 += (code3 = this.getBlackCode());
  16605. } while (code3 >= 64);
  16606. } else {
  16607. do {
  16608. code1 += (code3 = this.getWhiteCode());
  16609. } while (code3 >= 64);
  16610. }
  16611. this.addPixels(codingLine[this.codingPos] + code1, blackPixels);
  16612. blackPixels ^= 1;
  16613. }
  16614. }
  16615. var gotEOL = false;
  16616. if (this.byteAlign) {
  16617. this.inputBits &= ~7;
  16618. }
  16619. if (!this.eoblock && this.row === this.rows - 1) {
  16620. this.eof = true;
  16621. } else {
  16622. code1 = this.lookBits(12);
  16623. if (this.eoline) {
  16624. while (code1 !== EOF && code1 !== 1) {
  16625. this.eatBits(1);
  16626. code1 = this.lookBits(12);
  16627. }
  16628. } else {
  16629. while (code1 === 0) {
  16630. this.eatBits(1);
  16631. code1 = this.lookBits(12);
  16632. }
  16633. }
  16634. if (code1 === 1) {
  16635. this.eatBits(12);
  16636. gotEOL = true;
  16637. } else if (code1 === EOF) {
  16638. this.eof = true;
  16639. }
  16640. }
  16641. if (!this.eof && this.encoding > 0) {
  16642. this.nextLine2D = !this.lookBits(1);
  16643. this.eatBits(1);
  16644. }
  16645. if (this.eoblock && gotEOL && this.byteAlign) {
  16646. code1 = this.lookBits(12);
  16647. if (code1 === 1) {
  16648. this.eatBits(12);
  16649. if (this.encoding > 0) {
  16650. this.lookBits(1);
  16651. this.eatBits(1);
  16652. }
  16653. if (this.encoding >= 0) {
  16654. for (i = 0; i < 4; ++i) {
  16655. code1 = this.lookBits(12);
  16656. if (code1 !== 1) {
  16657. info('bad rtc code: ' + code1);
  16658. }
  16659. this.eatBits(12);
  16660. if (this.encoding > 0) {
  16661. this.lookBits(1);
  16662. this.eatBits(1);
  16663. }
  16664. }
  16665. }
  16666. this.eof = true;
  16667. }
  16668. } else if (this.err && this.eoline) {
  16669. while (true) {
  16670. code1 = this.lookBits(13);
  16671. if (code1 === EOF) {
  16672. this.eof = true;
  16673. return null;
  16674. }
  16675. if ((code1 >> 1) === 1) {
  16676. break;
  16677. }
  16678. this.eatBits(1);
  16679. }
  16680. this.eatBits(12);
  16681. if (this.encoding > 0) {
  16682. this.eatBits(1);
  16683. this.nextLine2D = !(code1 & 1);
  16684. }
  16685. }
  16686. if (codingLine[0] > 0) {
  16687. this.outputBits = codingLine[this.codingPos = 0];
  16688. } else {
  16689. this.outputBits = codingLine[this.codingPos = 1];
  16690. }
  16691. this.row++;
  16692. }
  16693. var c;
  16694. if (this.outputBits >= 8) {
  16695. c = (this.codingPos & 1) ? 0 : 0xFF;
  16696. this.outputBits -= 8;
  16697. if (this.outputBits === 0 && codingLine[this.codingPos] < columns) {
  16698. this.codingPos++;
  16699. this.outputBits = (codingLine[this.codingPos] -
  16700. codingLine[this.codingPos - 1]);
  16701. }
  16702. } else {
  16703. bits = 8;
  16704. c = 0;
  16705. do {
  16706. if (this.outputBits > bits) {
  16707. c <<= bits;
  16708. if (!(this.codingPos & 1)) {
  16709. c |= 0xFF >> (8 - bits);
  16710. }
  16711. this.outputBits -= bits;
  16712. bits = 0;
  16713. } else {
  16714. c <<= this.outputBits;
  16715. if (!(this.codingPos & 1)) {
  16716. c |= 0xFF >> (8 - this.outputBits);
  16717. }
  16718. bits -= this.outputBits;
  16719. this.outputBits = 0;
  16720. if (codingLine[this.codingPos] < columns) {
  16721. this.codingPos++;
  16722. this.outputBits = (codingLine[this.codingPos] -
  16723. codingLine[this.codingPos - 1]);
  16724. } else if (bits > 0) {
  16725. c <<= bits;
  16726. bits = 0;
  16727. }
  16728. }
  16729. } while (bits);
  16730. }
  16731. if (this.black) {
  16732. c ^= 0xFF;
  16733. }
  16734. return c;
  16735. };
  16736. // This functions returns the code found from the table.
  16737. // The start and end parameters set the boundaries for searching the table.
  16738. // The limit parameter is optional. Function returns an array with three
  16739. // values. The first array element indicates whether a valid code is being
  16740. // returned. The second array element is the actual code. The third array
  16741. // element indicates whether EOF was reached.
  16742. CCITTFaxStream.prototype.findTableCode =
  16743. function ccittFaxStreamFindTableCode(start, end, table, limit) {
  16744. var limitValue = limit || 0;
  16745. for (var i = start; i <= end; ++i) {
  16746. var code = this.lookBits(i);
  16747. if (code === EOF) {
  16748. return [true, 1, false];
  16749. }
  16750. if (i < end) {
  16751. code <<= end - i;
  16752. }
  16753. if (!limitValue || code >= limitValue) {
  16754. var p = table[code - limitValue];
  16755. if (p[0] === i) {
  16756. this.eatBits(i);
  16757. return [true, p[1], true];
  16758. }
  16759. }
  16760. }
  16761. return [false, 0, false];
  16762. };
  16763. CCITTFaxStream.prototype.getTwoDimCode =
  16764. function ccittFaxStreamGetTwoDimCode() {
  16765. var code = 0;
  16766. var p;
  16767. if (this.eoblock) {
  16768. code = this.lookBits(7);
  16769. p = twoDimTable[code];
  16770. if (p && p[0] > 0) {
  16771. this.eatBits(p[0]);
  16772. return p[1];
  16773. }
  16774. } else {
  16775. var result = this.findTableCode(1, 7, twoDimTable);
  16776. if (result[0] && result[2]) {
  16777. return result[1];
  16778. }
  16779. }
  16780. info('Bad two dim code');
  16781. return EOF;
  16782. };
  16783. CCITTFaxStream.prototype.getWhiteCode =
  16784. function ccittFaxStreamGetWhiteCode() {
  16785. var code = 0;
  16786. var p;
  16787. if (this.eoblock) {
  16788. code = this.lookBits(12);
  16789. if (code === EOF) {
  16790. return 1;
  16791. }
  16792. if ((code >> 5) === 0) {
  16793. p = whiteTable1[code];
  16794. } else {
  16795. p = whiteTable2[code >> 3];
  16796. }
  16797. if (p[0] > 0) {
  16798. this.eatBits(p[0]);
  16799. return p[1];
  16800. }
  16801. } else {
  16802. var result = this.findTableCode(1, 9, whiteTable2);
  16803. if (result[0]) {
  16804. return result[1];
  16805. }
  16806. result = this.findTableCode(11, 12, whiteTable1);
  16807. if (result[0]) {
  16808. return result[1];
  16809. }
  16810. }
  16811. info('bad white code');
  16812. this.eatBits(1);
  16813. return 1;
  16814. };
  16815. CCITTFaxStream.prototype.getBlackCode =
  16816. function ccittFaxStreamGetBlackCode() {
  16817. var code, p;
  16818. if (this.eoblock) {
  16819. code = this.lookBits(13);
  16820. if (code === EOF) {
  16821. return 1;
  16822. }
  16823. if ((code >> 7) === 0) {
  16824. p = blackTable1[code];
  16825. } else if ((code >> 9) === 0 && (code >> 7) !== 0) {
  16826. p = blackTable2[(code >> 1) - 64];
  16827. } else {
  16828. p = blackTable3[code >> 7];
  16829. }
  16830. if (p[0] > 0) {
  16831. this.eatBits(p[0]);
  16832. return p[1];
  16833. }
  16834. } else {
  16835. var result = this.findTableCode(2, 6, blackTable3);
  16836. if (result[0]) {
  16837. return result[1];
  16838. }
  16839. result = this.findTableCode(7, 12, blackTable2, 64);
  16840. if (result[0]) {
  16841. return result[1];
  16842. }
  16843. result = this.findTableCode(10, 13, blackTable1);
  16844. if (result[0]) {
  16845. return result[1];
  16846. }
  16847. }
  16848. info('bad black code');
  16849. this.eatBits(1);
  16850. return 1;
  16851. };
  16852. CCITTFaxStream.prototype.lookBits = function CCITTFaxStream_lookBits(n) {
  16853. var c;
  16854. while (this.inputBits < n) {
  16855. if ((c = this.str.getByte()) === -1) {
  16856. if (this.inputBits === 0) {
  16857. return EOF;
  16858. }
  16859. return ((this.inputBuf << (n - this.inputBits)) &
  16860. (0xFFFF >> (16 - n)));
  16861. }
  16862. this.inputBuf = (this.inputBuf << 8) + c;
  16863. this.inputBits += 8;
  16864. }
  16865. return (this.inputBuf >> (this.inputBits - n)) & (0xFFFF >> (16 - n));
  16866. };
  16867. CCITTFaxStream.prototype.eatBits = function CCITTFaxStream_eatBits(n) {
  16868. if ((this.inputBits -= n) < 0) {
  16869. this.inputBits = 0;
  16870. }
  16871. };
  16872. return CCITTFaxStream;
  16873. })();
  16874. var LZWStream = (function LZWStreamClosure() {
  16875. function LZWStream(str, maybeLength, earlyChange) {
  16876. this.str = str;
  16877. this.dict = str.dict;
  16878. this.cachedData = 0;
  16879. this.bitsCached = 0;
  16880. var maxLzwDictionarySize = 4096;
  16881. var lzwState = {
  16882. earlyChange: earlyChange,
  16883. codeLength: 9,
  16884. nextCode: 258,
  16885. dictionaryValues: new Uint8Array(maxLzwDictionarySize),
  16886. dictionaryLengths: new Uint16Array(maxLzwDictionarySize),
  16887. dictionaryPrevCodes: new Uint16Array(maxLzwDictionarySize),
  16888. currentSequence: new Uint8Array(maxLzwDictionarySize),
  16889. currentSequenceLength: 0
  16890. };
  16891. for (var i = 0; i < 256; ++i) {
  16892. lzwState.dictionaryValues[i] = i;
  16893. lzwState.dictionaryLengths[i] = 1;
  16894. }
  16895. this.lzwState = lzwState;
  16896. DecodeStream.call(this, maybeLength);
  16897. }
  16898. LZWStream.prototype = Object.create(DecodeStream.prototype);
  16899. LZWStream.prototype.readBits = function LZWStream_readBits(n) {
  16900. var bitsCached = this.bitsCached;
  16901. var cachedData = this.cachedData;
  16902. while (bitsCached < n) {
  16903. var c = this.str.getByte();
  16904. if (c === -1) {
  16905. this.eof = true;
  16906. return null;
  16907. }
  16908. cachedData = (cachedData << 8) | c;
  16909. bitsCached += 8;
  16910. }
  16911. this.bitsCached = (bitsCached -= n);
  16912. this.cachedData = cachedData;
  16913. this.lastCode = null;
  16914. return (cachedData >>> bitsCached) & ((1 << n) - 1);
  16915. };
  16916. LZWStream.prototype.readBlock = function LZWStream_readBlock() {
  16917. var blockSize = 512;
  16918. var estimatedDecodedSize = blockSize * 2, decodedSizeDelta = blockSize;
  16919. var i, j, q;
  16920. var lzwState = this.lzwState;
  16921. if (!lzwState) {
  16922. return; // eof was found
  16923. }
  16924. var earlyChange = lzwState.earlyChange;
  16925. var nextCode = lzwState.nextCode;
  16926. var dictionaryValues = lzwState.dictionaryValues;
  16927. var dictionaryLengths = lzwState.dictionaryLengths;
  16928. var dictionaryPrevCodes = lzwState.dictionaryPrevCodes;
  16929. var codeLength = lzwState.codeLength;
  16930. var prevCode = lzwState.prevCode;
  16931. var currentSequence = lzwState.currentSequence;
  16932. var currentSequenceLength = lzwState.currentSequenceLength;
  16933. var decodedLength = 0;
  16934. var currentBufferLength = this.bufferLength;
  16935. var buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  16936. for (i = 0; i < blockSize; i++) {
  16937. var code = this.readBits(codeLength);
  16938. var hasPrev = currentSequenceLength > 0;
  16939. if (code < 256) {
  16940. currentSequence[0] = code;
  16941. currentSequenceLength = 1;
  16942. } else if (code >= 258) {
  16943. if (code < nextCode) {
  16944. currentSequenceLength = dictionaryLengths[code];
  16945. for (j = currentSequenceLength - 1, q = code; j >= 0; j--) {
  16946. currentSequence[j] = dictionaryValues[q];
  16947. q = dictionaryPrevCodes[q];
  16948. }
  16949. } else {
  16950. currentSequence[currentSequenceLength++] = currentSequence[0];
  16951. }
  16952. } else if (code === 256) {
  16953. codeLength = 9;
  16954. nextCode = 258;
  16955. currentSequenceLength = 0;
  16956. continue;
  16957. } else {
  16958. this.eof = true;
  16959. delete this.lzwState;
  16960. break;
  16961. }
  16962. if (hasPrev) {
  16963. dictionaryPrevCodes[nextCode] = prevCode;
  16964. dictionaryLengths[nextCode] = dictionaryLengths[prevCode] + 1;
  16965. dictionaryValues[nextCode] = currentSequence[0];
  16966. nextCode++;
  16967. codeLength = (nextCode + earlyChange) & (nextCode + earlyChange - 1) ?
  16968. codeLength : Math.min(Math.log(nextCode + earlyChange) /
  16969. 0.6931471805599453 + 1, 12) | 0;
  16970. }
  16971. prevCode = code;
  16972. decodedLength += currentSequenceLength;
  16973. if (estimatedDecodedSize < decodedLength) {
  16974. do {
  16975. estimatedDecodedSize += decodedSizeDelta;
  16976. } while (estimatedDecodedSize < decodedLength);
  16977. buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  16978. }
  16979. for (j = 0; j < currentSequenceLength; j++) {
  16980. buffer[currentBufferLength++] = currentSequence[j];
  16981. }
  16982. }
  16983. lzwState.nextCode = nextCode;
  16984. lzwState.codeLength = codeLength;
  16985. lzwState.prevCode = prevCode;
  16986. lzwState.currentSequenceLength = currentSequenceLength;
  16987. this.bufferLength = currentBufferLength;
  16988. };
  16989. return LZWStream;
  16990. })();
  16991. var NullStream = (function NullStreamClosure() {
  16992. function NullStream() {
  16993. Stream.call(this, new Uint8Array(0));
  16994. }
  16995. NullStream.prototype = Stream.prototype;
  16996. return NullStream;
  16997. })();
  16998. // TODO refactor to remove dependency on parser.js
  16999. function _setCoreParser(coreParser_) {
  17000. coreParser = coreParser_;
  17001. EOF = coreParser_.EOF;
  17002. Lexer = coreParser_.Lexer;
  17003. }
  17004. exports._setCoreParser = _setCoreParser;
  17005. // TODO refactor to remove dependency on colorspace.js
  17006. function _setCoreColorSpace(coreColorSpace_) {
  17007. coreColorSpace = coreColorSpace_;
  17008. ColorSpace = coreColorSpace_.ColorSpace;
  17009. }
  17010. exports._setCoreColorSpace = _setCoreColorSpace;
  17011. exports.Ascii85Stream = Ascii85Stream;
  17012. exports.AsciiHexStream = AsciiHexStream;
  17013. exports.CCITTFaxStream = CCITTFaxStream;
  17014. exports.DecryptStream = DecryptStream;
  17015. exports.DecodeStream = DecodeStream;
  17016. exports.FlateStream = FlateStream;
  17017. exports.Jbig2Stream = Jbig2Stream;
  17018. exports.JpegStream = JpegStream;
  17019. exports.JpxStream = JpxStream;
  17020. exports.NullStream = NullStream;
  17021. exports.PredictorStream = PredictorStream;
  17022. exports.RunLengthStream = RunLengthStream;
  17023. exports.Stream = Stream;
  17024. exports.StreamsSequenceStream = StreamsSequenceStream;
  17025. exports.StringStream = StringStream;
  17026. exports.LZWStream = LZWStream;
  17027. }));
  17028. (function (root, factory) {
  17029. {
  17030. factory((root.pdfjsCoreCrypto = {}), root.pdfjsSharedUtil,
  17031. root.pdfjsCorePrimitives, root.pdfjsCoreStream);
  17032. }
  17033. }(this, function (exports, sharedUtil, corePrimitives, coreStream) {
  17034. var PasswordException = sharedUtil.PasswordException;
  17035. var PasswordResponses = sharedUtil.PasswordResponses;
  17036. var bytesToString = sharedUtil.bytesToString;
  17037. var error = sharedUtil.error;
  17038. var isInt = sharedUtil.isInt;
  17039. var stringToBytes = sharedUtil.stringToBytes;
  17040. var utf8StringToString = sharedUtil.utf8StringToString;
  17041. var warn = sharedUtil.warn;
  17042. var Name = corePrimitives.Name;
  17043. var isName = corePrimitives.isName;
  17044. var isDict = corePrimitives.isDict;
  17045. var DecryptStream = coreStream.DecryptStream;
  17046. var ARCFourCipher = (function ARCFourCipherClosure() {
  17047. function ARCFourCipher(key) {
  17048. this.a = 0;
  17049. this.b = 0;
  17050. var s = new Uint8Array(256);
  17051. var i, j = 0, tmp, keyLength = key.length;
  17052. for (i = 0; i < 256; ++i) {
  17053. s[i] = i;
  17054. }
  17055. for (i = 0; i < 256; ++i) {
  17056. tmp = s[i];
  17057. j = (j + tmp + key[i % keyLength]) & 0xFF;
  17058. s[i] = s[j];
  17059. s[j] = tmp;
  17060. }
  17061. this.s = s;
  17062. }
  17063. ARCFourCipher.prototype = {
  17064. encryptBlock: function ARCFourCipher_encryptBlock(data) {
  17065. var i, n = data.length, tmp, tmp2;
  17066. var a = this.a, b = this.b, s = this.s;
  17067. var output = new Uint8Array(n);
  17068. for (i = 0; i < n; ++i) {
  17069. a = (a + 1) & 0xFF;
  17070. tmp = s[a];
  17071. b = (b + tmp) & 0xFF;
  17072. tmp2 = s[b];
  17073. s[a] = tmp2;
  17074. s[b] = tmp;
  17075. output[i] = data[i] ^ s[(tmp + tmp2) & 0xFF];
  17076. }
  17077. this.a = a;
  17078. this.b = b;
  17079. return output;
  17080. }
  17081. };
  17082. ARCFourCipher.prototype.decryptBlock = ARCFourCipher.prototype.encryptBlock;
  17083. return ARCFourCipher;
  17084. })();
  17085. var calculateMD5 = (function calculateMD5Closure() {
  17086. var r = new Uint8Array([
  17087. 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22,
  17088. 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20,
  17089. 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23,
  17090. 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21]);
  17091. var k = new Int32Array([
  17092. -680876936, -389564586, 606105819, -1044525330, -176418897, 1200080426,
  17093. -1473231341, -45705983, 1770035416, -1958414417, -42063, -1990404162,
  17094. 1804603682, -40341101, -1502002290, 1236535329, -165796510, -1069501632,
  17095. 643717713, -373897302, -701558691, 38016083, -660478335, -405537848,
  17096. 568446438, -1019803690, -187363961, 1163531501, -1444681467, -51403784,
  17097. 1735328473, -1926607734, -378558, -2022574463, 1839030562, -35309556,
  17098. -1530992060, 1272893353, -155497632, -1094730640, 681279174, -358537222,
  17099. -722521979, 76029189, -640364487, -421815835, 530742520, -995338651,
  17100. -198630844, 1126891415, -1416354905, -57434055, 1700485571, -1894986606,
  17101. -1051523, -2054922799, 1873313359, -30611744, -1560198380, 1309151649,
  17102. -145523070, -1120210379, 718787259, -343485551]);
  17103. function hash(data, offset, length) {
  17104. var h0 = 1732584193, h1 = -271733879, h2 = -1732584194, h3 = 271733878;
  17105. // pre-processing
  17106. var paddedLength = (length + 72) & ~63; // data + 9 extra bytes
  17107. var padded = new Uint8Array(paddedLength);
  17108. var i, j, n;
  17109. for (i = 0; i < length; ++i) {
  17110. padded[i] = data[offset++];
  17111. }
  17112. padded[i++] = 0x80;
  17113. n = paddedLength - 8;
  17114. while (i < n) {
  17115. padded[i++] = 0;
  17116. }
  17117. padded[i++] = (length << 3) & 0xFF;
  17118. padded[i++] = (length >> 5) & 0xFF;
  17119. padded[i++] = (length >> 13) & 0xFF;
  17120. padded[i++] = (length >> 21) & 0xFF;
  17121. padded[i++] = (length >>> 29) & 0xFF;
  17122. padded[i++] = 0;
  17123. padded[i++] = 0;
  17124. padded[i++] = 0;
  17125. var w = new Int32Array(16);
  17126. for (i = 0; i < paddedLength;) {
  17127. for (j = 0; j < 16; ++j, i += 4) {
  17128. w[j] = (padded[i] | (padded[i + 1] << 8) |
  17129. (padded[i + 2] << 16) | (padded[i + 3] << 24));
  17130. }
  17131. var a = h0, b = h1, c = h2, d = h3, f, g;
  17132. for (j = 0; j < 64; ++j) {
  17133. if (j < 16) {
  17134. f = (b & c) | ((~b) & d);
  17135. g = j;
  17136. } else if (j < 32) {
  17137. f = (d & b) | ((~d) & c);
  17138. g = (5 * j + 1) & 15;
  17139. } else if (j < 48) {
  17140. f = b ^ c ^ d;
  17141. g = (3 * j + 5) & 15;
  17142. } else {
  17143. f = c ^ (b | (~d));
  17144. g = (7 * j) & 15;
  17145. }
  17146. var tmp = d, rotateArg = (a + f + k[j] + w[g]) | 0, rotate = r[j];
  17147. d = c;
  17148. c = b;
  17149. b = (b + ((rotateArg << rotate) | (rotateArg >>> (32 - rotate)))) | 0;
  17150. a = tmp;
  17151. }
  17152. h0 = (h0 + a) | 0;
  17153. h1 = (h1 + b) | 0;
  17154. h2 = (h2 + c) | 0;
  17155. h3 = (h3 + d) | 0;
  17156. }
  17157. return new Uint8Array([
  17158. h0 & 0xFF, (h0 >> 8) & 0xFF, (h0 >> 16) & 0xFF, (h0 >>> 24) & 0xFF,
  17159. h1 & 0xFF, (h1 >> 8) & 0xFF, (h1 >> 16) & 0xFF, (h1 >>> 24) & 0xFF,
  17160. h2 & 0xFF, (h2 >> 8) & 0xFF, (h2 >> 16) & 0xFF, (h2 >>> 24) & 0xFF,
  17161. h3 & 0xFF, (h3 >> 8) & 0xFF, (h3 >> 16) & 0xFF, (h3 >>> 24) & 0xFF
  17162. ]);
  17163. }
  17164. return hash;
  17165. })();
  17166. var Word64 = (function Word64Closure() {
  17167. function Word64(highInteger, lowInteger) {
  17168. this.high = highInteger | 0;
  17169. this.low = lowInteger | 0;
  17170. }
  17171. Word64.prototype = {
  17172. and: function Word64_and(word) {
  17173. this.high &= word.high;
  17174. this.low &= word.low;
  17175. },
  17176. xor: function Word64_xor(word) {
  17177. this.high ^= word.high;
  17178. this.low ^= word.low;
  17179. },
  17180. or: function Word64_or(word) {
  17181. this.high |= word.high;
  17182. this.low |= word.low;
  17183. },
  17184. shiftRight: function Word64_shiftRight(places) {
  17185. if (places >= 32) {
  17186. this.low = (this.high >>> (places - 32)) | 0;
  17187. this.high = 0;
  17188. } else {
  17189. this.low = (this.low >>> places) | (this.high << (32 - places));
  17190. this.high = (this.high >>> places) | 0;
  17191. }
  17192. },
  17193. shiftLeft: function Word64_shiftLeft(places) {
  17194. if (places >= 32) {
  17195. this.high = this.low << (places - 32);
  17196. this.low = 0;
  17197. } else {
  17198. this.high = (this.high << places) | (this.low >>> (32 - places));
  17199. this.low = this.low << places;
  17200. }
  17201. },
  17202. rotateRight: function Word64_rotateRight(places) {
  17203. var low, high;
  17204. if (places & 32) {
  17205. high = this.low;
  17206. low = this.high;
  17207. } else {
  17208. low = this.low;
  17209. high = this.high;
  17210. }
  17211. places &= 31;
  17212. this.low = (low >>> places) | (high << (32 - places));
  17213. this.high = (high >>> places) | (low << (32 - places));
  17214. },
  17215. not: function Word64_not() {
  17216. this.high = ~this.high;
  17217. this.low = ~this.low;
  17218. },
  17219. add: function Word64_add(word) {
  17220. var lowAdd = (this.low >>> 0) + (word.low >>> 0);
  17221. var highAdd = (this.high >>> 0) + (word.high >>> 0);
  17222. if (lowAdd > 0xFFFFFFFF) {
  17223. highAdd += 1;
  17224. }
  17225. this.low = lowAdd | 0;
  17226. this.high = highAdd | 0;
  17227. },
  17228. copyTo: function Word64_copyTo(bytes, offset) {
  17229. bytes[offset] = (this.high >>> 24) & 0xFF;
  17230. bytes[offset + 1] = (this.high >> 16) & 0xFF;
  17231. bytes[offset + 2] = (this.high >> 8) & 0xFF;
  17232. bytes[offset + 3] = this.high & 0xFF;
  17233. bytes[offset + 4] = (this.low >>> 24) & 0xFF;
  17234. bytes[offset + 5] = (this.low >> 16) & 0xFF;
  17235. bytes[offset + 6] = (this.low >> 8) & 0xFF;
  17236. bytes[offset + 7] = this.low & 0xFF;
  17237. },
  17238. assign: function Word64_assign(word) {
  17239. this.high = word.high;
  17240. this.low = word.low;
  17241. }
  17242. };
  17243. return Word64;
  17244. })();
  17245. var calculateSHA256 = (function calculateSHA256Closure() {
  17246. function rotr(x, n) {
  17247. return (x >>> n) | (x << 32 - n);
  17248. }
  17249. function ch(x, y, z) {
  17250. return (x & y) ^ (~x & z);
  17251. }
  17252. function maj(x, y, z) {
  17253. return (x & y) ^ (x & z) ^ (y & z);
  17254. }
  17255. function sigma(x) {
  17256. return rotr(x, 2) ^ rotr(x, 13) ^ rotr(x, 22);
  17257. }
  17258. function sigmaPrime(x) {
  17259. return rotr(x, 6) ^ rotr(x, 11) ^ rotr(x, 25);
  17260. }
  17261. function littleSigma(x) {
  17262. return rotr(x, 7) ^ rotr(x, 18) ^ x >>> 3;
  17263. }
  17264. function littleSigmaPrime(x) {
  17265. return rotr(x, 17) ^ rotr(x, 19) ^ x >>> 10;
  17266. }
  17267. var k = [0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
  17268. 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
  17269. 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
  17270. 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
  17271. 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
  17272. 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
  17273. 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
  17274. 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
  17275. 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
  17276. 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
  17277. 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
  17278. 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
  17279. 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
  17280. 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
  17281. 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
  17282. 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2];
  17283. function hash(data, offset, length) {
  17284. // initial hash values
  17285. var h0 = 0x6a09e667, h1 = 0xbb67ae85, h2 = 0x3c6ef372,
  17286. h3 = 0xa54ff53a, h4 = 0x510e527f, h5 = 0x9b05688c,
  17287. h6 = 0x1f83d9ab, h7 = 0x5be0cd19;
  17288. // pre-processing
  17289. var paddedLength = Math.ceil((length + 9) / 64) * 64;
  17290. var padded = new Uint8Array(paddedLength);
  17291. var i, j, n;
  17292. for (i = 0; i < length; ++i) {
  17293. padded[i] = data[offset++];
  17294. }
  17295. padded[i++] = 0x80;
  17296. n = paddedLength - 8;
  17297. while (i < n) {
  17298. padded[i++] = 0;
  17299. }
  17300. padded[i++] = 0;
  17301. padded[i++] = 0;
  17302. padded[i++] = 0;
  17303. padded[i++] = (length >>> 29) & 0xFF;
  17304. padded[i++] = (length >> 21) & 0xFF;
  17305. padded[i++] = (length >> 13) & 0xFF;
  17306. padded[i++] = (length >> 5) & 0xFF;
  17307. padded[i++] = (length << 3) & 0xFF;
  17308. var w = new Uint32Array(64);
  17309. // for each 512 bit block
  17310. for (i = 0; i < paddedLength;) {
  17311. for (j = 0; j < 16; ++j) {
  17312. w[j] = (padded[i] << 24 | (padded[i + 1] << 16) |
  17313. (padded[i + 2] << 8) | (padded[i + 3]));
  17314. i += 4;
  17315. }
  17316. for (j = 16; j < 64; ++j) {
  17317. w[j] = littleSigmaPrime(w[j - 2]) + w[j - 7] +
  17318. littleSigma(w[j - 15]) + w[j - 16] | 0;
  17319. }
  17320. var a = h0, b = h1, c = h2, d = h3, e = h4,
  17321. f = h5, g = h6, h = h7, t1, t2;
  17322. for (j = 0; j < 64; ++j) {
  17323. t1 = h + sigmaPrime(e) + ch(e, f, g) + k[j] + w[j];
  17324. t2 = sigma(a) + maj(a, b, c);
  17325. h = g;
  17326. g = f;
  17327. f = e;
  17328. e = (d + t1) | 0;
  17329. d = c;
  17330. c = b;
  17331. b = a;
  17332. a = (t1 + t2) | 0;
  17333. }
  17334. h0 = (h0 + a) | 0;
  17335. h1 = (h1 + b) | 0;
  17336. h2 = (h2 + c) | 0;
  17337. h3 = (h3 + d) | 0;
  17338. h4 = (h4 + e) | 0;
  17339. h5 = (h5 + f) | 0;
  17340. h6 = (h6 + g) | 0;
  17341. h7 = (h7 + h) | 0;
  17342. }
  17343. return new Uint8Array([
  17344. (h0 >> 24) & 0xFF, (h0 >> 16) & 0xFF, (h0 >> 8) & 0xFF, (h0) & 0xFF,
  17345. (h1 >> 24) & 0xFF, (h1 >> 16) & 0xFF, (h1 >> 8) & 0xFF, (h1) & 0xFF,
  17346. (h2 >> 24) & 0xFF, (h2 >> 16) & 0xFF, (h2 >> 8) & 0xFF, (h2) & 0xFF,
  17347. (h3 >> 24) & 0xFF, (h3 >> 16) & 0xFF, (h3 >> 8) & 0xFF, (h3) & 0xFF,
  17348. (h4 >> 24) & 0xFF, (h4 >> 16) & 0xFF, (h4 >> 8) & 0xFF, (h4) & 0xFF,
  17349. (h5 >> 24) & 0xFF, (h5 >> 16) & 0xFF, (h5 >> 8) & 0xFF, (h5) & 0xFF,
  17350. (h6 >> 24) & 0xFF, (h6 >> 16) & 0xFF, (h6 >> 8) & 0xFF, (h6) & 0xFF,
  17351. (h7 >> 24) & 0xFF, (h7 >> 16) & 0xFF, (h7 >> 8) & 0xFF, (h7) & 0xFF
  17352. ]);
  17353. }
  17354. return hash;
  17355. })();
  17356. var calculateSHA512 = (function calculateSHA512Closure() {
  17357. function ch(result, x, y, z, tmp) {
  17358. result.assign(x);
  17359. result.and(y);
  17360. tmp.assign(x);
  17361. tmp.not();
  17362. tmp.and(z);
  17363. result.xor(tmp);
  17364. }
  17365. function maj(result, x, y, z, tmp) {
  17366. result.assign(x);
  17367. result.and(y);
  17368. tmp.assign(x);
  17369. tmp.and(z);
  17370. result.xor(tmp);
  17371. tmp.assign(y);
  17372. tmp.and(z);
  17373. result.xor(tmp);
  17374. }
  17375. function sigma(result, x, tmp) {
  17376. result.assign(x);
  17377. result.rotateRight(28);
  17378. tmp.assign(x);
  17379. tmp.rotateRight(34);
  17380. result.xor(tmp);
  17381. tmp.assign(x);
  17382. tmp.rotateRight(39);
  17383. result.xor(tmp);
  17384. }
  17385. function sigmaPrime(result, x, tmp) {
  17386. result.assign(x);
  17387. result.rotateRight(14);
  17388. tmp.assign(x);
  17389. tmp.rotateRight(18);
  17390. result.xor(tmp);
  17391. tmp.assign(x);
  17392. tmp.rotateRight(41);
  17393. result.xor(tmp);
  17394. }
  17395. function littleSigma(result, x, tmp) {
  17396. result.assign(x);
  17397. result.rotateRight(1);
  17398. tmp.assign(x);
  17399. tmp.rotateRight(8);
  17400. result.xor(tmp);
  17401. tmp.assign(x);
  17402. tmp.shiftRight(7);
  17403. result.xor(tmp);
  17404. }
  17405. function littleSigmaPrime(result, x, tmp) {
  17406. result.assign(x);
  17407. result.rotateRight(19);
  17408. tmp.assign(x);
  17409. tmp.rotateRight(61);
  17410. result.xor(tmp);
  17411. tmp.assign(x);
  17412. tmp.shiftRight(6);
  17413. result.xor(tmp);
  17414. }
  17415. var k = [
  17416. new Word64(0x428a2f98, 0xd728ae22), new Word64(0x71374491, 0x23ef65cd),
  17417. new Word64(0xb5c0fbcf, 0xec4d3b2f), new Word64(0xe9b5dba5, 0x8189dbbc),
  17418. new Word64(0x3956c25b, 0xf348b538), new Word64(0x59f111f1, 0xb605d019),
  17419. new Word64(0x923f82a4, 0xaf194f9b), new Word64(0xab1c5ed5, 0xda6d8118),
  17420. new Word64(0xd807aa98, 0xa3030242), new Word64(0x12835b01, 0x45706fbe),
  17421. new Word64(0x243185be, 0x4ee4b28c), new Word64(0x550c7dc3, 0xd5ffb4e2),
  17422. new Word64(0x72be5d74, 0xf27b896f), new Word64(0x80deb1fe, 0x3b1696b1),
  17423. new Word64(0x9bdc06a7, 0x25c71235), new Word64(0xc19bf174, 0xcf692694),
  17424. new Word64(0xe49b69c1, 0x9ef14ad2), new Word64(0xefbe4786, 0x384f25e3),
  17425. new Word64(0x0fc19dc6, 0x8b8cd5b5), new Word64(0x240ca1cc, 0x77ac9c65),
  17426. new Word64(0x2de92c6f, 0x592b0275), new Word64(0x4a7484aa, 0x6ea6e483),
  17427. new Word64(0x5cb0a9dc, 0xbd41fbd4), new Word64(0x76f988da, 0x831153b5),
  17428. new Word64(0x983e5152, 0xee66dfab), new Word64(0xa831c66d, 0x2db43210),
  17429. new Word64(0xb00327c8, 0x98fb213f), new Word64(0xbf597fc7, 0xbeef0ee4),
  17430. new Word64(0xc6e00bf3, 0x3da88fc2), new Word64(0xd5a79147, 0x930aa725),
  17431. new Word64(0x06ca6351, 0xe003826f), new Word64(0x14292967, 0x0a0e6e70),
  17432. new Word64(0x27b70a85, 0x46d22ffc), new Word64(0x2e1b2138, 0x5c26c926),
  17433. new Word64(0x4d2c6dfc, 0x5ac42aed), new Word64(0x53380d13, 0x9d95b3df),
  17434. new Word64(0x650a7354, 0x8baf63de), new Word64(0x766a0abb, 0x3c77b2a8),
  17435. new Word64(0x81c2c92e, 0x47edaee6), new Word64(0x92722c85, 0x1482353b),
  17436. new Word64(0xa2bfe8a1, 0x4cf10364), new Word64(0xa81a664b, 0xbc423001),
  17437. new Word64(0xc24b8b70, 0xd0f89791), new Word64(0xc76c51a3, 0x0654be30),
  17438. new Word64(0xd192e819, 0xd6ef5218), new Word64(0xd6990624, 0x5565a910),
  17439. new Word64(0xf40e3585, 0x5771202a), new Word64(0x106aa070, 0x32bbd1b8),
  17440. new Word64(0x19a4c116, 0xb8d2d0c8), new Word64(0x1e376c08, 0x5141ab53),
  17441. new Word64(0x2748774c, 0xdf8eeb99), new Word64(0x34b0bcb5, 0xe19b48a8),
  17442. new Word64(0x391c0cb3, 0xc5c95a63), new Word64(0x4ed8aa4a, 0xe3418acb),
  17443. new Word64(0x5b9cca4f, 0x7763e373), new Word64(0x682e6ff3, 0xd6b2b8a3),
  17444. new Word64(0x748f82ee, 0x5defb2fc), new Word64(0x78a5636f, 0x43172f60),
  17445. new Word64(0x84c87814, 0xa1f0ab72), new Word64(0x8cc70208, 0x1a6439ec),
  17446. new Word64(0x90befffa, 0x23631e28), new Word64(0xa4506ceb, 0xde82bde9),
  17447. new Word64(0xbef9a3f7, 0xb2c67915), new Word64(0xc67178f2, 0xe372532b),
  17448. new Word64(0xca273ece, 0xea26619c), new Word64(0xd186b8c7, 0x21c0c207),
  17449. new Word64(0xeada7dd6, 0xcde0eb1e), new Word64(0xf57d4f7f, 0xee6ed178),
  17450. new Word64(0x06f067aa, 0x72176fba), new Word64(0x0a637dc5, 0xa2c898a6),
  17451. new Word64(0x113f9804, 0xbef90dae), new Word64(0x1b710b35, 0x131c471b),
  17452. new Word64(0x28db77f5, 0x23047d84), new Word64(0x32caab7b, 0x40c72493),
  17453. new Word64(0x3c9ebe0a, 0x15c9bebc), new Word64(0x431d67c4, 0x9c100d4c),
  17454. new Word64(0x4cc5d4be, 0xcb3e42b6), new Word64(0x597f299c, 0xfc657e2a),
  17455. new Word64(0x5fcb6fab, 0x3ad6faec), new Word64(0x6c44198c, 0x4a475817)];
  17456. function hash(data, offset, length, mode384) {
  17457. mode384 = !!mode384;
  17458. // initial hash values
  17459. var h0, h1, h2, h3, h4, h5, h6, h7;
  17460. if (!mode384) {
  17461. h0 = new Word64(0x6a09e667, 0xf3bcc908);
  17462. h1 = new Word64(0xbb67ae85, 0x84caa73b);
  17463. h2 = new Word64(0x3c6ef372, 0xfe94f82b);
  17464. h3 = new Word64(0xa54ff53a, 0x5f1d36f1);
  17465. h4 = new Word64(0x510e527f, 0xade682d1);
  17466. h5 = new Word64(0x9b05688c, 0x2b3e6c1f);
  17467. h6 = new Word64(0x1f83d9ab, 0xfb41bd6b);
  17468. h7 = new Word64(0x5be0cd19, 0x137e2179);
  17469. }
  17470. else {
  17471. // SHA384 is exactly the same
  17472. // except with different starting values and a trimmed result
  17473. h0 = new Word64(0xcbbb9d5d, 0xc1059ed8);
  17474. h1 = new Word64(0x629a292a, 0x367cd507);
  17475. h2 = new Word64(0x9159015a, 0x3070dd17);
  17476. h3 = new Word64(0x152fecd8, 0xf70e5939);
  17477. h4 = new Word64(0x67332667, 0xffc00b31);
  17478. h5 = new Word64(0x8eb44a87, 0x68581511);
  17479. h6 = new Word64(0xdb0c2e0d, 0x64f98fa7);
  17480. h7 = new Word64(0x47b5481d, 0xbefa4fa4);
  17481. }
  17482. // pre-processing
  17483. var paddedLength = Math.ceil((length + 17) / 128) * 128;
  17484. var padded = new Uint8Array(paddedLength);
  17485. var i, j, n;
  17486. for (i = 0; i < length; ++i) {
  17487. padded[i] = data[offset++];
  17488. }
  17489. padded[i++] = 0x80;
  17490. n = paddedLength - 16;
  17491. while (i < n) {
  17492. padded[i++] = 0;
  17493. }
  17494. padded[i++] = 0;
  17495. padded[i++] = 0;
  17496. padded[i++] = 0;
  17497. padded[i++] = 0;
  17498. padded[i++] = 0;
  17499. padded[i++] = 0;
  17500. padded[i++] = 0;
  17501. padded[i++] = 0;
  17502. padded[i++] = 0;
  17503. padded[i++] = 0;
  17504. padded[i++] = 0;
  17505. padded[i++] = (length >>> 29) & 0xFF;
  17506. padded[i++] = (length >> 21) & 0xFF;
  17507. padded[i++] = (length >> 13) & 0xFF;
  17508. padded[i++] = (length >> 5) & 0xFF;
  17509. padded[i++] = (length << 3) & 0xFF;
  17510. var w = new Array(80);
  17511. for (i = 0; i < 80; i++) {
  17512. w[i] = new Word64(0, 0);
  17513. }
  17514. var a = new Word64(0, 0), b = new Word64(0, 0), c = new Word64(0, 0);
  17515. var d = new Word64(0, 0), e = new Word64(0, 0), f = new Word64(0, 0);
  17516. var g = new Word64(0, 0), h = new Word64(0, 0);
  17517. var t1 = new Word64(0, 0), t2 = new Word64(0, 0);
  17518. var tmp1 = new Word64(0, 0), tmp2 = new Word64(0, 0), tmp3;
  17519. // for each 1024 bit block
  17520. for (i = 0; i < paddedLength;) {
  17521. for (j = 0; j < 16; ++j) {
  17522. w[j].high = (padded[i] << 24) | (padded[i + 1] << 16) |
  17523. (padded[i + 2] << 8) | (padded[i + 3]);
  17524. w[j].low = (padded[i + 4]) << 24 | (padded[i + 5]) << 16 |
  17525. (padded[i + 6]) << 8 | (padded[i + 7]);
  17526. i += 8;
  17527. }
  17528. for (j = 16; j < 80; ++j) {
  17529. tmp3 = w[j];
  17530. littleSigmaPrime(tmp3, w[j - 2], tmp2);
  17531. tmp3.add(w[j - 7]);
  17532. littleSigma(tmp1, w[j - 15], tmp2);
  17533. tmp3.add(tmp1);
  17534. tmp3.add(w[j - 16]);
  17535. }
  17536. a.assign(h0); b.assign(h1); c.assign(h2); d.assign(h3);
  17537. e.assign(h4); f.assign(h5); g.assign(h6); h.assign(h7);
  17538. for (j = 0; j < 80; ++j) {
  17539. t1.assign(h);
  17540. sigmaPrime(tmp1, e, tmp2);
  17541. t1.add(tmp1);
  17542. ch(tmp1, e, f, g, tmp2);
  17543. t1.add(tmp1);
  17544. t1.add(k[j]);
  17545. t1.add(w[j]);
  17546. sigma(t2, a, tmp2);
  17547. maj(tmp1, a, b, c, tmp2);
  17548. t2.add(tmp1);
  17549. tmp3 = h;
  17550. h = g;
  17551. g = f;
  17552. f = e;
  17553. d.add(t1);
  17554. e = d;
  17555. d = c;
  17556. c = b;
  17557. b = a;
  17558. tmp3.assign(t1);
  17559. tmp3.add(t2);
  17560. a = tmp3;
  17561. }
  17562. h0.add(a);
  17563. h1.add(b);
  17564. h2.add(c);
  17565. h3.add(d);
  17566. h4.add(e);
  17567. h5.add(f);
  17568. h6.add(g);
  17569. h7.add(h);
  17570. }
  17571. var result;
  17572. if (!mode384) {
  17573. result = new Uint8Array(64);
  17574. h0.copyTo(result,0);
  17575. h1.copyTo(result,8);
  17576. h2.copyTo(result,16);
  17577. h3.copyTo(result,24);
  17578. h4.copyTo(result,32);
  17579. h5.copyTo(result,40);
  17580. h6.copyTo(result,48);
  17581. h7.copyTo(result,56);
  17582. }
  17583. else {
  17584. result = new Uint8Array(48);
  17585. h0.copyTo(result,0);
  17586. h1.copyTo(result,8);
  17587. h2.copyTo(result,16);
  17588. h3.copyTo(result,24);
  17589. h4.copyTo(result,32);
  17590. h5.copyTo(result,40);
  17591. }
  17592. return result;
  17593. }
  17594. return hash;
  17595. })();
  17596. var calculateSHA384 = (function calculateSHA384Closure() {
  17597. function hash(data, offset, length) {
  17598. return calculateSHA512(data, offset, length, true);
  17599. }
  17600. return hash;
  17601. })();
  17602. var NullCipher = (function NullCipherClosure() {
  17603. function NullCipher() {
  17604. }
  17605. NullCipher.prototype = {
  17606. decryptBlock: function NullCipher_decryptBlock(data) {
  17607. return data;
  17608. }
  17609. };
  17610. return NullCipher;
  17611. })();
  17612. var AES128Cipher = (function AES128CipherClosure() {
  17613. var rcon = new Uint8Array([
  17614. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  17615. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  17616. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  17617. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  17618. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  17619. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  17620. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  17621. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  17622. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  17623. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  17624. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  17625. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  17626. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  17627. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  17628. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  17629. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  17630. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  17631. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  17632. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  17633. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  17634. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  17635. 0x74, 0xe8, 0xcb, 0x8d]);
  17636. var s = new Uint8Array([
  17637. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  17638. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  17639. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  17640. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  17641. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  17642. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  17643. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  17644. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  17645. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  17646. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  17647. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  17648. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  17649. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  17650. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  17651. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  17652. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  17653. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  17654. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  17655. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  17656. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  17657. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  17658. 0xb0, 0x54, 0xbb, 0x16]);
  17659. var inv_s = new Uint8Array([
  17660. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  17661. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  17662. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  17663. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  17664. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  17665. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  17666. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  17667. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  17668. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  17669. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  17670. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  17671. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  17672. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  17673. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  17674. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  17675. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  17676. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  17677. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  17678. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  17679. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  17680. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  17681. 0x55, 0x21, 0x0c, 0x7d]);
  17682. var mixCol = new Uint8Array(256);
  17683. for (var i = 0; i < 256; i++) {
  17684. if (i < 128) {
  17685. mixCol[i] = i << 1;
  17686. } else {
  17687. mixCol[i] = (i << 1) ^ 0x1b;
  17688. }
  17689. }
  17690. var mix = new Uint32Array([
  17691. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  17692. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  17693. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  17694. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  17695. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  17696. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  17697. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  17698. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  17699. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  17700. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  17701. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  17702. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  17703. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  17704. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  17705. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  17706. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  17707. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  17708. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  17709. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  17710. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  17711. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  17712. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  17713. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  17714. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  17715. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  17716. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  17717. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  17718. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  17719. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  17720. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  17721. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  17722. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  17723. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  17724. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  17725. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  17726. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  17727. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  17728. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  17729. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  17730. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  17731. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  17732. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  17733. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  17734. function expandKey128(cipherKey) {
  17735. var b = 176, result = new Uint8Array(b);
  17736. result.set(cipherKey);
  17737. for (var j = 16, i = 1; j < b; ++i) {
  17738. // RotWord
  17739. var t1 = result[j - 3], t2 = result[j - 2],
  17740. t3 = result[j - 1], t4 = result[j - 4];
  17741. // SubWord
  17742. t1 = s[t1];
  17743. t2 = s[t2];
  17744. t3 = s[t3];
  17745. t4 = s[t4];
  17746. // Rcon
  17747. t1 = t1 ^ rcon[i];
  17748. for (var n = 0; n < 4; ++n) {
  17749. result[j] = (t1 ^= result[j - 16]);
  17750. j++;
  17751. result[j] = (t2 ^= result[j - 16]);
  17752. j++;
  17753. result[j] = (t3 ^= result[j - 16]);
  17754. j++;
  17755. result[j] = (t4 ^= result[j - 16]);
  17756. j++;
  17757. }
  17758. }
  17759. return result;
  17760. }
  17761. function decrypt128(input, key) {
  17762. var state = new Uint8Array(16);
  17763. state.set(input);
  17764. var i, j, k;
  17765. var t, u, v;
  17766. // AddRoundKey
  17767. for (j = 0, k = 160; j < 16; ++j, ++k) {
  17768. state[j] ^= key[k];
  17769. }
  17770. for (i = 9; i >= 1; --i) {
  17771. // InvShiftRows
  17772. t = state[13];
  17773. state[13] = state[9];
  17774. state[9] = state[5];
  17775. state[5] = state[1];
  17776. state[1] = t;
  17777. t = state[14];
  17778. u = state[10];
  17779. state[14] = state[6];
  17780. state[10] = state[2];
  17781. state[6] = t;
  17782. state[2] = u;
  17783. t = state[15];
  17784. u = state[11];
  17785. v = state[7];
  17786. state[15] = state[3];
  17787. state[11] = t;
  17788. state[7] = u;
  17789. state[3] = v;
  17790. // InvSubBytes
  17791. for (j = 0; j < 16; ++j) {
  17792. state[j] = inv_s[state[j]];
  17793. }
  17794. // AddRoundKey
  17795. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  17796. state[j] ^= key[k];
  17797. }
  17798. // InvMixColumns
  17799. for (j = 0; j < 16; j += 4) {
  17800. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  17801. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  17802. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  17803. (s3 >>> 24) ^ (s3 << 8));
  17804. state[j] = (t >>> 24) & 0xFF;
  17805. state[j + 1] = (t >> 16) & 0xFF;
  17806. state[j + 2] = (t >> 8) & 0xFF;
  17807. state[j + 3] = t & 0xFF;
  17808. }
  17809. }
  17810. // InvShiftRows
  17811. t = state[13];
  17812. state[13] = state[9];
  17813. state[9] = state[5];
  17814. state[5] = state[1];
  17815. state[1] = t;
  17816. t = state[14];
  17817. u = state[10];
  17818. state[14] = state[6];
  17819. state[10] = state[2];
  17820. state[6] = t;
  17821. state[2] = u;
  17822. t = state[15];
  17823. u = state[11];
  17824. v = state[7];
  17825. state[15] = state[3];
  17826. state[11] = t;
  17827. state[7] = u;
  17828. state[3] = v;
  17829. for (j = 0; j < 16; ++j) {
  17830. // InvSubBytes
  17831. state[j] = inv_s[state[j]];
  17832. // AddRoundKey
  17833. state[j] ^= key[j];
  17834. }
  17835. return state;
  17836. }
  17837. function encrypt128(input, key) {
  17838. var t, u, v, k;
  17839. var state = new Uint8Array(16);
  17840. state.set(input);
  17841. for (j = 0; j < 16; ++j) {
  17842. // AddRoundKey
  17843. state[j] ^= key[j];
  17844. }
  17845. for (i = 1; i < 10; i++) {
  17846. //SubBytes
  17847. for (j = 0; j < 16; ++j) {
  17848. state[j] = s[state[j]];
  17849. }
  17850. //ShiftRows
  17851. v = state[1];
  17852. state[1] = state[5];
  17853. state[5] = state[9];
  17854. state[9] = state[13];
  17855. state[13] = v;
  17856. v = state[2];
  17857. u = state[6];
  17858. state[2] = state[10];
  17859. state[6] = state[14];
  17860. state[10] = v;
  17861. state[14] = u;
  17862. v = state[3];
  17863. u = state[7];
  17864. t = state[11];
  17865. state[3] = state[15];
  17866. state[7] = v;
  17867. state[11] = u;
  17868. state[15] = t;
  17869. //MixColumns
  17870. for (var j = 0; j < 16; j += 4) {
  17871. var s0 = state[j + 0], s1 = state[j + 1];
  17872. var s2 = state[j + 2], s3 = state[j + 3];
  17873. t = s0 ^ s1 ^ s2 ^ s3;
  17874. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  17875. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  17876. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  17877. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  17878. }
  17879. //AddRoundKey
  17880. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  17881. state[j] ^= key[k];
  17882. }
  17883. }
  17884. //SubBytes
  17885. for (j = 0; j < 16; ++j) {
  17886. state[j] = s[state[j]];
  17887. }
  17888. //ShiftRows
  17889. v = state[1];
  17890. state[1] = state[5];
  17891. state[5] = state[9];
  17892. state[9] = state[13];
  17893. state[13] = v;
  17894. v = state[2];
  17895. u = state[6];
  17896. state[2] = state[10];
  17897. state[6] = state[14];
  17898. state[10] = v;
  17899. state[14] = u;
  17900. v = state[3];
  17901. u = state[7];
  17902. t = state[11];
  17903. state[3] = state[15];
  17904. state[7] = v;
  17905. state[11] = u;
  17906. state[15] = t;
  17907. //AddRoundKey
  17908. for (j = 0, k = 160; j < 16; ++j, ++k) {
  17909. state[j] ^= key[k];
  17910. }
  17911. return state;
  17912. }
  17913. function AES128Cipher(key) {
  17914. this.key = expandKey128(key);
  17915. this.buffer = new Uint8Array(16);
  17916. this.bufferPosition = 0;
  17917. }
  17918. function decryptBlock2(data, finalize) {
  17919. var i, j, ii, sourceLength = data.length,
  17920. buffer = this.buffer, bufferLength = this.bufferPosition,
  17921. result = [], iv = this.iv;
  17922. for (i = 0; i < sourceLength; ++i) {
  17923. buffer[bufferLength] = data[i];
  17924. ++bufferLength;
  17925. if (bufferLength < 16) {
  17926. continue;
  17927. }
  17928. // buffer is full, decrypting
  17929. var plain = decrypt128(buffer, this.key);
  17930. // xor-ing the IV vector to get plain text
  17931. for (j = 0; j < 16; ++j) {
  17932. plain[j] ^= iv[j];
  17933. }
  17934. iv = buffer;
  17935. result.push(plain);
  17936. buffer = new Uint8Array(16);
  17937. bufferLength = 0;
  17938. }
  17939. // saving incomplete buffer
  17940. this.buffer = buffer;
  17941. this.bufferLength = bufferLength;
  17942. this.iv = iv;
  17943. if (result.length === 0) {
  17944. return new Uint8Array([]);
  17945. }
  17946. // combining plain text blocks into one
  17947. var outputLength = 16 * result.length;
  17948. if (finalize) {
  17949. // undo a padding that is described in RFC 2898
  17950. var lastBlock = result[result.length - 1];
  17951. var psLen = lastBlock[15];
  17952. if (psLen <= 16) {
  17953. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  17954. if (lastBlock[i] !== psLen) {
  17955. // Invalid padding, assume that the block has no padding.
  17956. psLen = 0;
  17957. break;
  17958. }
  17959. }
  17960. outputLength -= psLen;
  17961. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  17962. }
  17963. }
  17964. var output = new Uint8Array(outputLength);
  17965. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  17966. output.set(result[i], j);
  17967. }
  17968. return output;
  17969. }
  17970. AES128Cipher.prototype = {
  17971. decryptBlock: function AES128Cipher_decryptBlock(data, finalize) {
  17972. var i, sourceLength = data.length;
  17973. var buffer = this.buffer, bufferLength = this.bufferPosition;
  17974. // waiting for IV values -- they are at the start of the stream
  17975. for (i = 0; bufferLength < 16 && i < sourceLength; ++i, ++bufferLength) {
  17976. buffer[bufferLength] = data[i];
  17977. }
  17978. if (bufferLength < 16) {
  17979. // need more data
  17980. this.bufferLength = bufferLength;
  17981. return new Uint8Array([]);
  17982. }
  17983. this.iv = buffer;
  17984. this.buffer = new Uint8Array(16);
  17985. this.bufferLength = 0;
  17986. // starting decryption
  17987. this.decryptBlock = decryptBlock2;
  17988. return this.decryptBlock(data.subarray(16), finalize);
  17989. },
  17990. encrypt: function AES128Cipher_encrypt(data, iv) {
  17991. var i, j, ii, sourceLength = data.length,
  17992. buffer = this.buffer, bufferLength = this.bufferPosition,
  17993. result = [];
  17994. if (!iv) {
  17995. iv = new Uint8Array(16);
  17996. }
  17997. for (i = 0; i < sourceLength; ++i) {
  17998. buffer[bufferLength] = data[i];
  17999. ++bufferLength;
  18000. if (bufferLength < 16) {
  18001. continue;
  18002. }
  18003. for (j = 0; j < 16; ++j) {
  18004. buffer[j] ^= iv[j];
  18005. }
  18006. // buffer is full, encrypting
  18007. var cipher = encrypt128(buffer, this.key);
  18008. iv = cipher;
  18009. result.push(cipher);
  18010. buffer = new Uint8Array(16);
  18011. bufferLength = 0;
  18012. }
  18013. // saving incomplete buffer
  18014. this.buffer = buffer;
  18015. this.bufferLength = bufferLength;
  18016. this.iv = iv;
  18017. if (result.length === 0) {
  18018. return new Uint8Array([]);
  18019. }
  18020. // combining plain text blocks into one
  18021. var outputLength = 16 * result.length;
  18022. var output = new Uint8Array(outputLength);
  18023. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  18024. output.set(result[i], j);
  18025. }
  18026. return output;
  18027. }
  18028. };
  18029. return AES128Cipher;
  18030. })();
  18031. var AES256Cipher = (function AES256CipherClosure() {
  18032. var rcon = new Uint8Array([
  18033. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  18034. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  18035. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  18036. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  18037. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  18038. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  18039. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  18040. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  18041. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  18042. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  18043. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  18044. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  18045. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  18046. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  18047. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  18048. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  18049. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  18050. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  18051. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  18052. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  18053. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  18054. 0x74, 0xe8, 0xcb, 0x8d]);
  18055. var s = new Uint8Array([
  18056. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  18057. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  18058. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  18059. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  18060. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  18061. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  18062. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  18063. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  18064. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  18065. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  18066. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  18067. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  18068. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  18069. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  18070. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  18071. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  18072. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  18073. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  18074. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  18075. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  18076. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  18077. 0xb0, 0x54, 0xbb, 0x16]);
  18078. var inv_s = new Uint8Array([
  18079. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  18080. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  18081. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  18082. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  18083. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  18084. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  18085. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  18086. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  18087. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  18088. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  18089. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  18090. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  18091. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  18092. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  18093. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  18094. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  18095. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  18096. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  18097. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  18098. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  18099. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  18100. 0x55, 0x21, 0x0c, 0x7d]);
  18101. var mixCol = new Uint8Array(256);
  18102. for (var i = 0; i < 256; i++) {
  18103. if (i < 128) {
  18104. mixCol[i] = i << 1;
  18105. } else {
  18106. mixCol[i] = (i << 1) ^ 0x1b;
  18107. }
  18108. }
  18109. var mix = new Uint32Array([
  18110. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  18111. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  18112. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  18113. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  18114. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  18115. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  18116. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  18117. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  18118. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  18119. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  18120. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  18121. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  18122. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  18123. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  18124. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  18125. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  18126. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  18127. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  18128. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  18129. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  18130. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  18131. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  18132. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  18133. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  18134. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  18135. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  18136. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  18137. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  18138. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  18139. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  18140. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  18141. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  18142. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  18143. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  18144. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  18145. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  18146. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  18147. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  18148. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  18149. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  18150. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  18151. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  18152. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  18153. function expandKey256(cipherKey) {
  18154. var b = 240, result = new Uint8Array(b);
  18155. var r = 1;
  18156. result.set(cipherKey);
  18157. for (var j = 32, i = 1; j < b; ++i) {
  18158. if (j % 32 === 16) {
  18159. t1 = s[t1];
  18160. t2 = s[t2];
  18161. t3 = s[t3];
  18162. t4 = s[t4];
  18163. } else if (j % 32 === 0) {
  18164. // RotWord
  18165. var t1 = result[j - 3], t2 = result[j - 2],
  18166. t3 = result[j - 1], t4 = result[j - 4];
  18167. // SubWord
  18168. t1 = s[t1];
  18169. t2 = s[t2];
  18170. t3 = s[t3];
  18171. t4 = s[t4];
  18172. // Rcon
  18173. t1 = t1 ^ r;
  18174. if ((r <<= 1) >= 256) {
  18175. r = (r ^ 0x1b) & 0xFF;
  18176. }
  18177. }
  18178. for (var n = 0; n < 4; ++n) {
  18179. result[j] = (t1 ^= result[j - 32]);
  18180. j++;
  18181. result[j] = (t2 ^= result[j - 32]);
  18182. j++;
  18183. result[j] = (t3 ^= result[j - 32]);
  18184. j++;
  18185. result[j] = (t4 ^= result[j - 32]);
  18186. j++;
  18187. }
  18188. }
  18189. return result;
  18190. }
  18191. function decrypt256(input, key) {
  18192. var state = new Uint8Array(16);
  18193. state.set(input);
  18194. var i, j, k;
  18195. var t, u, v;
  18196. // AddRoundKey
  18197. for (j = 0, k = 224; j < 16; ++j, ++k) {
  18198. state[j] ^= key[k];
  18199. }
  18200. for (i = 13; i >= 1; --i) {
  18201. // InvShiftRows
  18202. t = state[13];
  18203. state[13] = state[9];
  18204. state[9] = state[5];
  18205. state[5] = state[1];
  18206. state[1] = t;
  18207. t = state[14];
  18208. u = state[10];
  18209. state[14] = state[6];
  18210. state[10] = state[2];
  18211. state[6] = t;
  18212. state[2] = u;
  18213. t = state[15];
  18214. u = state[11];
  18215. v = state[7];
  18216. state[15] = state[3];
  18217. state[11] = t;
  18218. state[7] = u;
  18219. state[3] = v;
  18220. // InvSubBytes
  18221. for (j = 0; j < 16; ++j) {
  18222. state[j] = inv_s[state[j]];
  18223. }
  18224. // AddRoundKey
  18225. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  18226. state[j] ^= key[k];
  18227. }
  18228. // InvMixColumns
  18229. for (j = 0; j < 16; j += 4) {
  18230. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  18231. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  18232. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  18233. (s3 >>> 24) ^ (s3 << 8));
  18234. state[j] = (t >>> 24) & 0xFF;
  18235. state[j + 1] = (t >> 16) & 0xFF;
  18236. state[j + 2] = (t >> 8) & 0xFF;
  18237. state[j + 3] = t & 0xFF;
  18238. }
  18239. }
  18240. // InvShiftRows
  18241. t = state[13];
  18242. state[13] = state[9];
  18243. state[9] = state[5];
  18244. state[5] = state[1];
  18245. state[1] = t;
  18246. t = state[14];
  18247. u = state[10];
  18248. state[14] = state[6];
  18249. state[10] = state[2];
  18250. state[6] = t;
  18251. state[2] = u;
  18252. t = state[15];
  18253. u = state[11];
  18254. v = state[7];
  18255. state[15] = state[3];
  18256. state[11] = t;
  18257. state[7] = u;
  18258. state[3] = v;
  18259. for (j = 0; j < 16; ++j) {
  18260. // InvSubBytes
  18261. state[j] = inv_s[state[j]];
  18262. // AddRoundKey
  18263. state[j] ^= key[j];
  18264. }
  18265. return state;
  18266. }
  18267. function encrypt256(input, key) {
  18268. var t, u, v, k;
  18269. var state = new Uint8Array(16);
  18270. state.set(input);
  18271. for (j = 0; j < 16; ++j) {
  18272. // AddRoundKey
  18273. state[j] ^= key[j];
  18274. }
  18275. for (i = 1; i < 14; i++) {
  18276. //SubBytes
  18277. for (j = 0; j < 16; ++j) {
  18278. state[j] = s[state[j]];
  18279. }
  18280. //ShiftRows
  18281. v = state[1];
  18282. state[1] = state[5];
  18283. state[5] = state[9];
  18284. state[9] = state[13];
  18285. state[13] = v;
  18286. v = state[2];
  18287. u = state[6];
  18288. state[2] = state[10];
  18289. state[6] = state[14];
  18290. state[10] = v;
  18291. state[14] = u;
  18292. v = state[3];
  18293. u = state[7];
  18294. t = state[11];
  18295. state[3] = state[15];
  18296. state[7] = v;
  18297. state[11] = u;
  18298. state[15] = t;
  18299. //MixColumns
  18300. for (var j = 0; j < 16; j += 4) {
  18301. var s0 = state[j + 0], s1 = state[j + 1];
  18302. var s2 = state[j + 2], s3 = state[j + 3];
  18303. t = s0 ^ s1 ^ s2 ^ s3;
  18304. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  18305. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  18306. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  18307. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  18308. }
  18309. //AddRoundKey
  18310. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  18311. state[j] ^= key[k];
  18312. }
  18313. }
  18314. //SubBytes
  18315. for (j = 0; j < 16; ++j) {
  18316. state[j] = s[state[j]];
  18317. }
  18318. //ShiftRows
  18319. v = state[1];
  18320. state[1] = state[5];
  18321. state[5] = state[9];
  18322. state[9] = state[13];
  18323. state[13] = v;
  18324. v = state[2];
  18325. u = state[6];
  18326. state[2] = state[10];
  18327. state[6] = state[14];
  18328. state[10] = v;
  18329. state[14] = u;
  18330. v = state[3];
  18331. u = state[7];
  18332. t = state[11];
  18333. state[3] = state[15];
  18334. state[7] = v;
  18335. state[11] = u;
  18336. state[15] = t;
  18337. //AddRoundKey
  18338. for (j = 0, k = 224; j < 16; ++j, ++k) {
  18339. state[j] ^= key[k];
  18340. }
  18341. return state;
  18342. }
  18343. function AES256Cipher(key) {
  18344. this.key = expandKey256(key);
  18345. this.buffer = new Uint8Array(16);
  18346. this.bufferPosition = 0;
  18347. }
  18348. function decryptBlock2(data, finalize) {
  18349. var i, j, ii, sourceLength = data.length,
  18350. buffer = this.buffer, bufferLength = this.bufferPosition,
  18351. result = [], iv = this.iv;
  18352. for (i = 0; i < sourceLength; ++i) {
  18353. buffer[bufferLength] = data[i];
  18354. ++bufferLength;
  18355. if (bufferLength < 16) {
  18356. continue;
  18357. }
  18358. // buffer is full, decrypting
  18359. var plain = decrypt256(buffer, this.key);
  18360. // xor-ing the IV vector to get plain text
  18361. for (j = 0; j < 16; ++j) {
  18362. plain[j] ^= iv[j];
  18363. }
  18364. iv = buffer;
  18365. result.push(plain);
  18366. buffer = new Uint8Array(16);
  18367. bufferLength = 0;
  18368. }
  18369. // saving incomplete buffer
  18370. this.buffer = buffer;
  18371. this.bufferLength = bufferLength;
  18372. this.iv = iv;
  18373. if (result.length === 0) {
  18374. return new Uint8Array([]);
  18375. }
  18376. // combining plain text blocks into one
  18377. var outputLength = 16 * result.length;
  18378. if (finalize) {
  18379. // undo a padding that is described in RFC 2898
  18380. var lastBlock = result[result.length - 1];
  18381. var psLen = lastBlock[15];
  18382. if (psLen <= 16) {
  18383. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  18384. if (lastBlock[i] !== psLen) {
  18385. // Invalid padding, assume that the block has no padding.
  18386. psLen = 0;
  18387. break;
  18388. }
  18389. }
  18390. outputLength -= psLen;
  18391. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  18392. }
  18393. }
  18394. var output = new Uint8Array(outputLength);
  18395. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  18396. output.set(result[i], j);
  18397. }
  18398. return output;
  18399. }
  18400. AES256Cipher.prototype = {
  18401. decryptBlock: function AES256Cipher_decryptBlock(data, finalize, iv) {
  18402. var i, sourceLength = data.length;
  18403. var buffer = this.buffer, bufferLength = this.bufferPosition;
  18404. // if not supplied an IV wait for IV values
  18405. // they are at the start of the stream
  18406. if (iv) {
  18407. this.iv = iv;
  18408. } else {
  18409. for (i = 0; bufferLength < 16 &&
  18410. i < sourceLength; ++i, ++bufferLength) {
  18411. buffer[bufferLength] = data[i];
  18412. }
  18413. if (bufferLength < 16) {
  18414. //need more data
  18415. this.bufferLength = bufferLength;
  18416. return new Uint8Array([]);
  18417. }
  18418. this.iv = buffer;
  18419. data = data.subarray(16);
  18420. }
  18421. this.buffer = new Uint8Array(16);
  18422. this.bufferLength = 0;
  18423. // starting decryption
  18424. this.decryptBlock = decryptBlock2;
  18425. return this.decryptBlock(data, finalize);
  18426. },
  18427. encrypt: function AES256Cipher_encrypt(data, iv) {
  18428. var i, j, ii, sourceLength = data.length,
  18429. buffer = this.buffer, bufferLength = this.bufferPosition,
  18430. result = [];
  18431. if (!iv) {
  18432. iv = new Uint8Array(16);
  18433. }
  18434. for (i = 0; i < sourceLength; ++i) {
  18435. buffer[bufferLength] = data[i];
  18436. ++bufferLength;
  18437. if (bufferLength < 16) {
  18438. continue;
  18439. }
  18440. for (j = 0; j < 16; ++j) {
  18441. buffer[j] ^= iv[j];
  18442. }
  18443. // buffer is full, encrypting
  18444. var cipher = encrypt256(buffer, this.key);
  18445. this.iv = cipher;
  18446. result.push(cipher);
  18447. buffer = new Uint8Array(16);
  18448. bufferLength = 0;
  18449. }
  18450. // saving incomplete buffer
  18451. this.buffer = buffer;
  18452. this.bufferLength = bufferLength;
  18453. this.iv = iv;
  18454. if (result.length === 0) {
  18455. return new Uint8Array([]);
  18456. }
  18457. // combining plain text blocks into one
  18458. var outputLength = 16 * result.length;
  18459. var output = new Uint8Array(outputLength);
  18460. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  18461. output.set(result[i], j);
  18462. }
  18463. return output;
  18464. }
  18465. };
  18466. return AES256Cipher;
  18467. })();
  18468. var PDF17 = (function PDF17Closure() {
  18469. function compareByteArrays(array1, array2) {
  18470. if (array1.length !== array2.length) {
  18471. return false;
  18472. }
  18473. for (var i = 0; i < array1.length; i++) {
  18474. if (array1[i] !== array2[i]) {
  18475. return false;
  18476. }
  18477. }
  18478. return true;
  18479. }
  18480. function PDF17() {
  18481. }
  18482. PDF17.prototype = {
  18483. checkOwnerPassword: function PDF17_checkOwnerPassword(password,
  18484. ownerValidationSalt,
  18485. userBytes,
  18486. ownerPassword) {
  18487. var hashData = new Uint8Array(password.length + 56);
  18488. hashData.set(password, 0);
  18489. hashData.set(ownerValidationSalt, password.length);
  18490. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  18491. var result = calculateSHA256(hashData, 0, hashData.length);
  18492. return compareByteArrays(result, ownerPassword);
  18493. },
  18494. checkUserPassword: function PDF17_checkUserPassword(password,
  18495. userValidationSalt,
  18496. userPassword) {
  18497. var hashData = new Uint8Array(password.length + 8);
  18498. hashData.set(password, 0);
  18499. hashData.set(userValidationSalt, password.length);
  18500. var result = calculateSHA256(hashData, 0, hashData.length);
  18501. return compareByteArrays(result, userPassword);
  18502. },
  18503. getOwnerKey: function PDF17_getOwnerKey(password, ownerKeySalt, userBytes,
  18504. ownerEncryption) {
  18505. var hashData = new Uint8Array(password.length + 56);
  18506. hashData.set(password, 0);
  18507. hashData.set(ownerKeySalt, password.length);
  18508. hashData.set(userBytes, password.length + ownerKeySalt.length);
  18509. var key = calculateSHA256(hashData, 0, hashData.length);
  18510. var cipher = new AES256Cipher(key);
  18511. return cipher.decryptBlock(ownerEncryption,
  18512. false,
  18513. new Uint8Array(16));
  18514. },
  18515. getUserKey: function PDF17_getUserKey(password, userKeySalt,
  18516. userEncryption) {
  18517. var hashData = new Uint8Array(password.length + 8);
  18518. hashData.set(password, 0);
  18519. hashData.set(userKeySalt, password.length);
  18520. //key is the decryption key for the UE string
  18521. var key = calculateSHA256(hashData, 0, hashData.length);
  18522. var cipher = new AES256Cipher(key);
  18523. return cipher.decryptBlock(userEncryption,
  18524. false,
  18525. new Uint8Array(16));
  18526. }
  18527. };
  18528. return PDF17;
  18529. })();
  18530. var PDF20 = (function PDF20Closure() {
  18531. function concatArrays(array1, array2) {
  18532. var t = new Uint8Array(array1.length + array2.length);
  18533. t.set(array1, 0);
  18534. t.set(array2, array1.length);
  18535. return t;
  18536. }
  18537. function calculatePDF20Hash(password, input, userBytes) {
  18538. //This refers to Algorithm 2.B as defined in ISO 32000-2
  18539. var k = calculateSHA256(input, 0, input.length).subarray(0, 32);
  18540. var e = [0];
  18541. var i = 0;
  18542. while (i < 64 || e[e.length - 1] > i - 32) {
  18543. var arrayLength = password.length + k.length + userBytes.length;
  18544. var k1 = new Uint8Array(arrayLength * 64);
  18545. var array = concatArrays(password, k);
  18546. array = concatArrays(array, userBytes);
  18547. for (var j = 0, pos = 0; j < 64; j++, pos += arrayLength) {
  18548. k1.set(array, pos);
  18549. }
  18550. //AES128 CBC NO PADDING with
  18551. //first 16 bytes of k as the key and the second 16 as the iv.
  18552. var cipher = new AES128Cipher(k.subarray(0, 16));
  18553. e = cipher.encrypt(k1, k.subarray(16, 32));
  18554. //Now we have to take the first 16 bytes of an unsigned
  18555. //big endian integer... and compute the remainder
  18556. //modulo 3.... That is a fairly large number and
  18557. //JavaScript isn't going to handle that well...
  18558. //So we're using a trick that allows us to perform
  18559. //modulo math byte by byte
  18560. var remainder = 0;
  18561. for (var z = 0; z < 16; z++) {
  18562. remainder *= (256 % 3);
  18563. remainder %= 3;
  18564. remainder += ((e[z] >>> 0) % 3);
  18565. remainder %= 3;
  18566. }
  18567. if (remainder === 0) {
  18568. k = calculateSHA256(e, 0, e.length);
  18569. }
  18570. else if (remainder === 1) {
  18571. k = calculateSHA384(e, 0, e.length);
  18572. }
  18573. else if (remainder === 2) {
  18574. k = calculateSHA512(e, 0, e.length);
  18575. }
  18576. i++;
  18577. }
  18578. return k.subarray(0, 32);
  18579. }
  18580. function PDF20() {
  18581. }
  18582. function compareByteArrays(array1, array2) {
  18583. if (array1.length !== array2.length) {
  18584. return false;
  18585. }
  18586. for (var i = 0; i < array1.length; i++) {
  18587. if (array1[i] !== array2[i]) {
  18588. return false;
  18589. }
  18590. }
  18591. return true;
  18592. }
  18593. PDF20.prototype = {
  18594. hash: function PDF20_hash(password, concatBytes, userBytes) {
  18595. return calculatePDF20Hash(password, concatBytes, userBytes);
  18596. },
  18597. checkOwnerPassword: function PDF20_checkOwnerPassword(password,
  18598. ownerValidationSalt,
  18599. userBytes,
  18600. ownerPassword) {
  18601. var hashData = new Uint8Array(password.length + 56);
  18602. hashData.set(password, 0);
  18603. hashData.set(ownerValidationSalt, password.length);
  18604. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  18605. var result = calculatePDF20Hash(password, hashData, userBytes);
  18606. return compareByteArrays(result, ownerPassword);
  18607. },
  18608. checkUserPassword: function PDF20_checkUserPassword(password,
  18609. userValidationSalt,
  18610. userPassword) {
  18611. var hashData = new Uint8Array(password.length + 8);
  18612. hashData.set(password, 0);
  18613. hashData.set(userValidationSalt, password.length);
  18614. var result = calculatePDF20Hash(password, hashData, []);
  18615. return compareByteArrays(result, userPassword);
  18616. },
  18617. getOwnerKey: function PDF20_getOwnerKey(password, ownerKeySalt, userBytes,
  18618. ownerEncryption) {
  18619. var hashData = new Uint8Array(password.length + 56);
  18620. hashData.set(password, 0);
  18621. hashData.set(ownerKeySalt, password.length);
  18622. hashData.set(userBytes, password.length + ownerKeySalt.length);
  18623. var key = calculatePDF20Hash(password, hashData, userBytes);
  18624. var cipher = new AES256Cipher(key);
  18625. return cipher.decryptBlock(ownerEncryption,
  18626. false,
  18627. new Uint8Array(16));
  18628. },
  18629. getUserKey: function PDF20_getUserKey(password, userKeySalt,
  18630. userEncryption) {
  18631. var hashData = new Uint8Array(password.length + 8);
  18632. hashData.set(password, 0);
  18633. hashData.set(userKeySalt, password.length);
  18634. //key is the decryption key for the UE string
  18635. var key = calculatePDF20Hash(password, hashData, []);
  18636. var cipher = new AES256Cipher(key);
  18637. return cipher.decryptBlock(userEncryption,
  18638. false,
  18639. new Uint8Array(16));
  18640. }
  18641. };
  18642. return PDF20;
  18643. })();
  18644. var CipherTransform = (function CipherTransformClosure() {
  18645. function CipherTransform(stringCipherConstructor, streamCipherConstructor) {
  18646. this.stringCipherConstructor = stringCipherConstructor;
  18647. this.streamCipherConstructor = streamCipherConstructor;
  18648. }
  18649. CipherTransform.prototype = {
  18650. createStream: function CipherTransform_createStream(stream, length) {
  18651. var cipher = new this.streamCipherConstructor();
  18652. return new DecryptStream(stream, length,
  18653. function cipherTransformDecryptStream(data, finalize) {
  18654. return cipher.decryptBlock(data, finalize);
  18655. }
  18656. );
  18657. },
  18658. decryptString: function CipherTransform_decryptString(s) {
  18659. var cipher = new this.stringCipherConstructor();
  18660. var data = stringToBytes(s);
  18661. data = cipher.decryptBlock(data, true);
  18662. return bytesToString(data);
  18663. }
  18664. };
  18665. return CipherTransform;
  18666. })();
  18667. var CipherTransformFactory = (function CipherTransformFactoryClosure() {
  18668. var defaultPasswordBytes = new Uint8Array([
  18669. 0x28, 0xBF, 0x4E, 0x5E, 0x4E, 0x75, 0x8A, 0x41,
  18670. 0x64, 0x00, 0x4E, 0x56, 0xFF, 0xFA, 0x01, 0x08,
  18671. 0x2E, 0x2E, 0x00, 0xB6, 0xD0, 0x68, 0x3E, 0x80,
  18672. 0x2F, 0x0C, 0xA9, 0xFE, 0x64, 0x53, 0x69, 0x7A]);
  18673. function createEncryptionKey20(revision, password, ownerPassword,
  18674. ownerValidationSalt, ownerKeySalt, uBytes,
  18675. userPassword, userValidationSalt, userKeySalt,
  18676. ownerEncryption, userEncryption, perms) {
  18677. if (password) {
  18678. var passwordLength = Math.min(127, password.length);
  18679. password = password.subarray(0, passwordLength);
  18680. } else {
  18681. password = [];
  18682. }
  18683. var pdfAlgorithm;
  18684. if (revision === 6) {
  18685. pdfAlgorithm = new PDF20();
  18686. } else {
  18687. pdfAlgorithm = new PDF17();
  18688. }
  18689. if (pdfAlgorithm) {
  18690. if (pdfAlgorithm.checkUserPassword(password, userValidationSalt,
  18691. userPassword)) {
  18692. return pdfAlgorithm.getUserKey(password, userKeySalt, userEncryption);
  18693. } else if (password.length && pdfAlgorithm.checkOwnerPassword(password,
  18694. ownerValidationSalt,
  18695. uBytes,
  18696. ownerPassword)) {
  18697. return pdfAlgorithm.getOwnerKey(password, ownerKeySalt, uBytes,
  18698. ownerEncryption);
  18699. }
  18700. }
  18701. return null;
  18702. }
  18703. function prepareKeyData(fileId, password, ownerPassword, userPassword,
  18704. flags, revision, keyLength, encryptMetadata) {
  18705. var hashDataSize = 40 + ownerPassword.length + fileId.length;
  18706. var hashData = new Uint8Array(hashDataSize), i = 0, j, n;
  18707. if (password) {
  18708. n = Math.min(32, password.length);
  18709. for (; i < n; ++i) {
  18710. hashData[i] = password[i];
  18711. }
  18712. }
  18713. j = 0;
  18714. while (i < 32) {
  18715. hashData[i++] = defaultPasswordBytes[j++];
  18716. }
  18717. // as now the padded password in the hashData[0..i]
  18718. for (j = 0, n = ownerPassword.length; j < n; ++j) {
  18719. hashData[i++] = ownerPassword[j];
  18720. }
  18721. hashData[i++] = flags & 0xFF;
  18722. hashData[i++] = (flags >> 8) & 0xFF;
  18723. hashData[i++] = (flags >> 16) & 0xFF;
  18724. hashData[i++] = (flags >>> 24) & 0xFF;
  18725. for (j = 0, n = fileId.length; j < n; ++j) {
  18726. hashData[i++] = fileId[j];
  18727. }
  18728. if (revision >= 4 && !encryptMetadata) {
  18729. hashData[i++] = 0xFF;
  18730. hashData[i++] = 0xFF;
  18731. hashData[i++] = 0xFF;
  18732. hashData[i++] = 0xFF;
  18733. }
  18734. var hash = calculateMD5(hashData, 0, i);
  18735. var keyLengthInBytes = keyLength >> 3;
  18736. if (revision >= 3) {
  18737. for (j = 0; j < 50; ++j) {
  18738. hash = calculateMD5(hash, 0, keyLengthInBytes);
  18739. }
  18740. }
  18741. var encryptionKey = hash.subarray(0, keyLengthInBytes);
  18742. var cipher, checkData;
  18743. if (revision >= 3) {
  18744. for (i = 0; i < 32; ++i) {
  18745. hashData[i] = defaultPasswordBytes[i];
  18746. }
  18747. for (j = 0, n = fileId.length; j < n; ++j) {
  18748. hashData[i++] = fileId[j];
  18749. }
  18750. cipher = new ARCFourCipher(encryptionKey);
  18751. checkData = cipher.encryptBlock(calculateMD5(hashData, 0, i));
  18752. n = encryptionKey.length;
  18753. var derivedKey = new Uint8Array(n), k;
  18754. for (j = 1; j <= 19; ++j) {
  18755. for (k = 0; k < n; ++k) {
  18756. derivedKey[k] = encryptionKey[k] ^ j;
  18757. }
  18758. cipher = new ARCFourCipher(derivedKey);
  18759. checkData = cipher.encryptBlock(checkData);
  18760. }
  18761. for (j = 0, n = checkData.length; j < n; ++j) {
  18762. if (userPassword[j] !== checkData[j]) {
  18763. return null;
  18764. }
  18765. }
  18766. } else {
  18767. cipher = new ARCFourCipher(encryptionKey);
  18768. checkData = cipher.encryptBlock(defaultPasswordBytes);
  18769. for (j = 0, n = checkData.length; j < n; ++j) {
  18770. if (userPassword[j] !== checkData[j]) {
  18771. return null;
  18772. }
  18773. }
  18774. }
  18775. return encryptionKey;
  18776. }
  18777. function decodeUserPassword(password, ownerPassword, revision, keyLength) {
  18778. var hashData = new Uint8Array(32), i = 0, j, n;
  18779. n = Math.min(32, password.length);
  18780. for (; i < n; ++i) {
  18781. hashData[i] = password[i];
  18782. }
  18783. j = 0;
  18784. while (i < 32) {
  18785. hashData[i++] = defaultPasswordBytes[j++];
  18786. }
  18787. var hash = calculateMD5(hashData, 0, i);
  18788. var keyLengthInBytes = keyLength >> 3;
  18789. if (revision >= 3) {
  18790. for (j = 0; j < 50; ++j) {
  18791. hash = calculateMD5(hash, 0, hash.length);
  18792. }
  18793. }
  18794. var cipher, userPassword;
  18795. if (revision >= 3) {
  18796. userPassword = ownerPassword;
  18797. var derivedKey = new Uint8Array(keyLengthInBytes), k;
  18798. for (j = 19; j >= 0; j--) {
  18799. for (k = 0; k < keyLengthInBytes; ++k) {
  18800. derivedKey[k] = hash[k] ^ j;
  18801. }
  18802. cipher = new ARCFourCipher(derivedKey);
  18803. userPassword = cipher.encryptBlock(userPassword);
  18804. }
  18805. } else {
  18806. cipher = new ARCFourCipher(hash.subarray(0, keyLengthInBytes));
  18807. userPassword = cipher.encryptBlock(ownerPassword);
  18808. }
  18809. return userPassword;
  18810. }
  18811. var identityName = Name.get('Identity');
  18812. function CipherTransformFactory(dict, fileId, password) {
  18813. var filter = dict.get('Filter');
  18814. if (!isName(filter) || filter.name !== 'Standard') {
  18815. error('unknown encryption method');
  18816. }
  18817. this.dict = dict;
  18818. var algorithm = dict.get('V');
  18819. if (!isInt(algorithm) ||
  18820. (algorithm !== 1 && algorithm !== 2 && algorithm !== 4 &&
  18821. algorithm !== 5)) {
  18822. error('unsupported encryption algorithm');
  18823. }
  18824. this.algorithm = algorithm;
  18825. var keyLength = dict.get('Length');
  18826. if (!keyLength) {
  18827. // Spec asks to rely on encryption dictionary's Length entry, however
  18828. // some PDFs don't have it. Trying to recover.
  18829. if (algorithm <= 3) {
  18830. // For 1 and 2 it's fixed to 40-bit, for 3 40-bit is a minimal value.
  18831. keyLength = 40;
  18832. } else {
  18833. // Trying to find default handler -- it usually has Length.
  18834. var cfDict = dict.get('CF');
  18835. var streamCryptoName = dict.get('StmF');
  18836. if (isDict(cfDict) && isName(streamCryptoName)) {
  18837. var handlerDict = cfDict.get(streamCryptoName.name);
  18838. keyLength = (handlerDict && handlerDict.get('Length')) || 128;
  18839. if (keyLength < 40) {
  18840. // Sometimes it's incorrect value of bits, generators specify bytes.
  18841. keyLength <<= 3;
  18842. }
  18843. }
  18844. }
  18845. }
  18846. if (!isInt(keyLength) ||
  18847. keyLength < 40 || (keyLength % 8) !== 0) {
  18848. error('invalid key length');
  18849. }
  18850. // prepare keys
  18851. var ownerPassword = stringToBytes(dict.get('O')).subarray(0, 32);
  18852. var userPassword = stringToBytes(dict.get('U')).subarray(0, 32);
  18853. var flags = dict.get('P');
  18854. var revision = dict.get('R');
  18855. // meaningful when V is 4 or 5
  18856. var encryptMetadata = ((algorithm === 4 || algorithm === 5) &&
  18857. dict.get('EncryptMetadata') !== false);
  18858. this.encryptMetadata = encryptMetadata;
  18859. var fileIdBytes = stringToBytes(fileId);
  18860. var passwordBytes;
  18861. if (password) {
  18862. if (revision === 6) {
  18863. try {
  18864. password = utf8StringToString(password);
  18865. } catch (ex) {
  18866. warn('CipherTransformFactory: ' +
  18867. 'Unable to convert UTF8 encoded password.');
  18868. }
  18869. }
  18870. passwordBytes = stringToBytes(password);
  18871. }
  18872. var encryptionKey;
  18873. if (algorithm !== 5) {
  18874. encryptionKey = prepareKeyData(fileIdBytes, passwordBytes,
  18875. ownerPassword, userPassword, flags,
  18876. revision, keyLength, encryptMetadata);
  18877. }
  18878. else {
  18879. var ownerValidationSalt = stringToBytes(dict.get('O')).subarray(32, 40);
  18880. var ownerKeySalt = stringToBytes(dict.get('O')).subarray(40, 48);
  18881. var uBytes = stringToBytes(dict.get('U')).subarray(0, 48);
  18882. var userValidationSalt = stringToBytes(dict.get('U')).subarray(32, 40);
  18883. var userKeySalt = stringToBytes(dict.get('U')).subarray(40, 48);
  18884. var ownerEncryption = stringToBytes(dict.get('OE'));
  18885. var userEncryption = stringToBytes(dict.get('UE'));
  18886. var perms = stringToBytes(dict.get('Perms'));
  18887. encryptionKey =
  18888. createEncryptionKey20(revision, passwordBytes,
  18889. ownerPassword, ownerValidationSalt,
  18890. ownerKeySalt, uBytes,
  18891. userPassword, userValidationSalt,
  18892. userKeySalt, ownerEncryption,
  18893. userEncryption, perms);
  18894. }
  18895. if (!encryptionKey && !password) {
  18896. throw new PasswordException('No password given',
  18897. PasswordResponses.NEED_PASSWORD);
  18898. } else if (!encryptionKey && password) {
  18899. // Attempting use the password as an owner password
  18900. var decodedPassword = decodeUserPassword(passwordBytes, ownerPassword,
  18901. revision, keyLength);
  18902. encryptionKey = prepareKeyData(fileIdBytes, decodedPassword,
  18903. ownerPassword, userPassword, flags,
  18904. revision, keyLength, encryptMetadata);
  18905. }
  18906. if (!encryptionKey) {
  18907. throw new PasswordException('Incorrect Password',
  18908. PasswordResponses.INCORRECT_PASSWORD);
  18909. }
  18910. this.encryptionKey = encryptionKey;
  18911. if (algorithm >= 4) {
  18912. this.cf = dict.get('CF');
  18913. this.stmf = dict.get('StmF') || identityName;
  18914. this.strf = dict.get('StrF') || identityName;
  18915. this.eff = dict.get('EFF') || this.stmf;
  18916. }
  18917. }
  18918. function buildObjectKey(num, gen, encryptionKey, isAes) {
  18919. var key = new Uint8Array(encryptionKey.length + 9), i, n;
  18920. for (i = 0, n = encryptionKey.length; i < n; ++i) {
  18921. key[i] = encryptionKey[i];
  18922. }
  18923. key[i++] = num & 0xFF;
  18924. key[i++] = (num >> 8) & 0xFF;
  18925. key[i++] = (num >> 16) & 0xFF;
  18926. key[i++] = gen & 0xFF;
  18927. key[i++] = (gen >> 8) & 0xFF;
  18928. if (isAes) {
  18929. key[i++] = 0x73;
  18930. key[i++] = 0x41;
  18931. key[i++] = 0x6C;
  18932. key[i++] = 0x54;
  18933. }
  18934. var hash = calculateMD5(key, 0, i);
  18935. return hash.subarray(0, Math.min(encryptionKey.length + 5, 16));
  18936. }
  18937. function buildCipherConstructor(cf, name, num, gen, key) {
  18938. var cryptFilter = cf.get(name.name);
  18939. var cfm;
  18940. if (cryptFilter !== null && cryptFilter !== undefined) {
  18941. cfm = cryptFilter.get('CFM');
  18942. }
  18943. if (!cfm || cfm.name === 'None') {
  18944. return function cipherTransformFactoryBuildCipherConstructorNone() {
  18945. return new NullCipher();
  18946. };
  18947. }
  18948. if ('V2' === cfm.name) {
  18949. return function cipherTransformFactoryBuildCipherConstructorV2() {
  18950. return new ARCFourCipher(buildObjectKey(num, gen, key, false));
  18951. };
  18952. }
  18953. if ('AESV2' === cfm.name) {
  18954. return function cipherTransformFactoryBuildCipherConstructorAESV2() {
  18955. return new AES128Cipher(buildObjectKey(num, gen, key, true));
  18956. };
  18957. }
  18958. if ('AESV3' === cfm.name) {
  18959. return function cipherTransformFactoryBuildCipherConstructorAESV3() {
  18960. return new AES256Cipher(key);
  18961. };
  18962. }
  18963. error('Unknown crypto method');
  18964. }
  18965. CipherTransformFactory.prototype = {
  18966. createCipherTransform:
  18967. function CipherTransformFactory_createCipherTransform(num, gen) {
  18968. if (this.algorithm === 4 || this.algorithm === 5) {
  18969. return new CipherTransform(
  18970. buildCipherConstructor(this.cf, this.stmf,
  18971. num, gen, this.encryptionKey),
  18972. buildCipherConstructor(this.cf, this.strf,
  18973. num, gen, this.encryptionKey));
  18974. }
  18975. // algorithms 1 and 2
  18976. var key = buildObjectKey(num, gen, this.encryptionKey, false);
  18977. var cipherConstructor = function buildCipherCipherConstructor() {
  18978. return new ARCFourCipher(key);
  18979. };
  18980. return new CipherTransform(cipherConstructor, cipherConstructor);
  18981. }
  18982. };
  18983. return CipherTransformFactory;
  18984. })();
  18985. exports.AES128Cipher = AES128Cipher;
  18986. exports.AES256Cipher = AES256Cipher;
  18987. exports.ARCFourCipher = ARCFourCipher;
  18988. exports.CipherTransformFactory = CipherTransformFactory;
  18989. exports.PDF17 = PDF17;
  18990. exports.PDF20 = PDF20;
  18991. exports.calculateMD5 = calculateMD5;
  18992. exports.calculateSHA256 = calculateSHA256;
  18993. exports.calculateSHA384 = calculateSHA384;
  18994. exports.calculateSHA512 = calculateSHA512;
  18995. }));
  18996. (function (root, factory) {
  18997. {
  18998. factory((root.pdfjsCoreFontRenderer = {}), root.pdfjsSharedUtil,
  18999. root.pdfjsCoreStream, root.pdfjsCoreGlyphList);
  19000. }
  19001. }(this, function (exports, sharedUtil, coreStream, coreGlyphList) {
  19002. var Util = sharedUtil.Util;
  19003. var bytesToString = sharedUtil.bytesToString;
  19004. var error = sharedUtil.error;
  19005. var Stream = coreStream.Stream;
  19006. var GlyphsUnicode = coreGlyphList.GlyphsUnicode;
  19007. var coreFonts; // see _setCoreFonts below
  19008. var CFFParser; // = coreFonts.CFFParser;
  19009. var Encodings; // = coreFonts.Encodings;
  19010. var FontRendererFactory = (function FontRendererFactoryClosure() {
  19011. function getLong(data, offset) {
  19012. return (data[offset] << 24) | (data[offset + 1] << 16) |
  19013. (data[offset + 2] << 8) | data[offset + 3];
  19014. }
  19015. function getUshort(data, offset) {
  19016. return (data[offset] << 8) | data[offset + 1];
  19017. }
  19018. function parseCmap(data, start, end) {
  19019. var offset = (getUshort(data, start + 2) === 1 ?
  19020. getLong(data, start + 8) : getLong(data, start + 16));
  19021. var format = getUshort(data, start + offset);
  19022. var length, ranges, p, i;
  19023. if (format === 4) {
  19024. length = getUshort(data, start + offset + 2);
  19025. var segCount = getUshort(data, start + offset + 6) >> 1;
  19026. p = start + offset + 14;
  19027. ranges = [];
  19028. for (i = 0; i < segCount; i++, p += 2) {
  19029. ranges[i] = {end: getUshort(data, p)};
  19030. }
  19031. p += 2;
  19032. for (i = 0; i < segCount; i++, p += 2) {
  19033. ranges[i].start = getUshort(data, p);
  19034. }
  19035. for (i = 0; i < segCount; i++, p += 2) {
  19036. ranges[i].idDelta = getUshort(data, p);
  19037. }
  19038. for (i = 0; i < segCount; i++, p += 2) {
  19039. var idOffset = getUshort(data, p);
  19040. if (idOffset === 0) {
  19041. continue;
  19042. }
  19043. ranges[i].ids = [];
  19044. for (var j = 0, jj = ranges[i].end - ranges[i].start + 1; j < jj; j++) {
  19045. ranges[i].ids[j] = getUshort(data, p + idOffset);
  19046. idOffset += 2;
  19047. }
  19048. }
  19049. return ranges;
  19050. } else if (format === 12) {
  19051. length = getLong(data, start + offset + 4);
  19052. var groups = getLong(data, start + offset + 12);
  19053. p = start + offset + 16;
  19054. ranges = [];
  19055. for (i = 0; i < groups; i++) {
  19056. ranges.push({
  19057. start: getLong(data, p),
  19058. end: getLong(data, p + 4),
  19059. idDelta: getLong(data, p + 8) - getLong(data, p)
  19060. });
  19061. p += 12;
  19062. }
  19063. return ranges;
  19064. }
  19065. error('not supported cmap: ' + format);
  19066. }
  19067. function parseCff(data, start, end) {
  19068. var properties = {};
  19069. var parser = new CFFParser(new Stream(data, start, end - start),
  19070. properties);
  19071. var cff = parser.parse();
  19072. return {
  19073. glyphs: cff.charStrings.objects,
  19074. subrs: (cff.topDict.privateDict && cff.topDict.privateDict.subrsIndex &&
  19075. cff.topDict.privateDict.subrsIndex.objects),
  19076. gsubrs: cff.globalSubrIndex && cff.globalSubrIndex.objects
  19077. };
  19078. }
  19079. function parseGlyfTable(glyf, loca, isGlyphLocationsLong) {
  19080. var itemSize, itemDecode;
  19081. if (isGlyphLocationsLong) {
  19082. itemSize = 4;
  19083. itemDecode = function fontItemDecodeLong(data, offset) {
  19084. return (data[offset] << 24) | (data[offset + 1] << 16) |
  19085. (data[offset + 2] << 8) | data[offset + 3];
  19086. };
  19087. } else {
  19088. itemSize = 2;
  19089. itemDecode = function fontItemDecode(data, offset) {
  19090. return (data[offset] << 9) | (data[offset + 1] << 1);
  19091. };
  19092. }
  19093. var glyphs = [];
  19094. var startOffset = itemDecode(loca, 0);
  19095. for (var j = itemSize; j < loca.length; j += itemSize) {
  19096. var endOffset = itemDecode(loca, j);
  19097. glyphs.push(glyf.subarray(startOffset, endOffset));
  19098. startOffset = endOffset;
  19099. }
  19100. return glyphs;
  19101. }
  19102. function lookupCmap(ranges, unicode) {
  19103. var code = unicode.charCodeAt(0);
  19104. var l = 0, r = ranges.length - 1;
  19105. while (l < r) {
  19106. var c = (l + r + 1) >> 1;
  19107. if (code < ranges[c].start) {
  19108. r = c - 1;
  19109. } else {
  19110. l = c;
  19111. }
  19112. }
  19113. if (ranges[l].start <= code && code <= ranges[l].end) {
  19114. return (ranges[l].idDelta + (ranges[l].ids ?
  19115. ranges[l].ids[code - ranges[l].start] : code)) & 0xFFFF;
  19116. }
  19117. return 0;
  19118. }
  19119. function compileGlyf(code, cmds, font) {
  19120. function moveTo(x, y) {
  19121. cmds.push({cmd: 'moveTo', args: [x, y]});
  19122. }
  19123. function lineTo(x, y) {
  19124. cmds.push({cmd: 'lineTo', args: [x, y]});
  19125. }
  19126. function quadraticCurveTo(xa, ya, x, y) {
  19127. cmds.push({cmd: 'quadraticCurveTo', args: [xa, ya, x, y]});
  19128. }
  19129. var i = 0;
  19130. var numberOfContours = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  19131. var flags;
  19132. var x = 0, y = 0;
  19133. i += 10;
  19134. if (numberOfContours < 0) {
  19135. // composite glyph
  19136. do {
  19137. flags = (code[i] << 8) | code[i + 1];
  19138. var glyphIndex = (code[i + 2] << 8) | code[i + 3];
  19139. i += 4;
  19140. var arg1, arg2;
  19141. if ((flags & 0x01)) {
  19142. arg1 = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  19143. arg2 = ((code[i + 2] << 24) | (code[i + 3] << 16)) >> 16;
  19144. i += 4;
  19145. } else {
  19146. arg1 = code[i++]; arg2 = code[i++];
  19147. }
  19148. if ((flags & 0x02)) {
  19149. x = arg1;
  19150. y = arg2;
  19151. } else {
  19152. x = 0; y = 0; // TODO "they are points" ?
  19153. }
  19154. var scaleX = 1, scaleY = 1, scale01 = 0, scale10 = 0;
  19155. if ((flags & 0x08)) {
  19156. scaleX =
  19157. scaleY = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  19158. i += 2;
  19159. } else if ((flags & 0x40)) {
  19160. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  19161. scaleY = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  19162. i += 4;
  19163. } else if ((flags & 0x80)) {
  19164. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  19165. scale01 = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  19166. scale10 = ((code[i + 4] << 24) | (code[i + 5] << 16)) / 1073741824;
  19167. scaleY = ((code[i + 6] << 24) | (code[i + 7] << 16)) / 1073741824;
  19168. i += 8;
  19169. }
  19170. var subglyph = font.glyphs[glyphIndex];
  19171. if (subglyph) {
  19172. cmds.push({cmd: 'save'});
  19173. cmds.push({cmd: 'transform',
  19174. args: [scaleX, scale01, scale10, scaleY, x, y]});
  19175. compileGlyf(subglyph, cmds, font);
  19176. cmds.push({cmd: 'restore'});
  19177. }
  19178. } while ((flags & 0x20));
  19179. } else {
  19180. // simple glyph
  19181. var endPtsOfContours = [];
  19182. var j, jj;
  19183. for (j = 0; j < numberOfContours; j++) {
  19184. endPtsOfContours.push((code[i] << 8) | code[i + 1]);
  19185. i += 2;
  19186. }
  19187. var instructionLength = (code[i] << 8) | code[i + 1];
  19188. i += 2 + instructionLength; // skipping the instructions
  19189. var numberOfPoints = endPtsOfContours[endPtsOfContours.length - 1] + 1;
  19190. var points = [];
  19191. while (points.length < numberOfPoints) {
  19192. flags = code[i++];
  19193. var repeat = 1;
  19194. if ((flags & 0x08)) {
  19195. repeat += code[i++];
  19196. }
  19197. while (repeat-- > 0) {
  19198. points.push({flags: flags});
  19199. }
  19200. }
  19201. for (j = 0; j < numberOfPoints; j++) {
  19202. switch (points[j].flags & 0x12) {
  19203. case 0x00:
  19204. x += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  19205. i += 2;
  19206. break;
  19207. case 0x02:
  19208. x -= code[i++];
  19209. break;
  19210. case 0x12:
  19211. x += code[i++];
  19212. break;
  19213. }
  19214. points[j].x = x;
  19215. }
  19216. for (j = 0; j < numberOfPoints; j++) {
  19217. switch (points[j].flags & 0x24) {
  19218. case 0x00:
  19219. y += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  19220. i += 2;
  19221. break;
  19222. case 0x04:
  19223. y -= code[i++];
  19224. break;
  19225. case 0x24:
  19226. y += code[i++];
  19227. break;
  19228. }
  19229. points[j].y = y;
  19230. }
  19231. var startPoint = 0;
  19232. for (i = 0; i < numberOfContours; i++) {
  19233. var endPoint = endPtsOfContours[i];
  19234. // contours might have implicit points, which is located in the middle
  19235. // between two neighboring off-curve points
  19236. var contour = points.slice(startPoint, endPoint + 1);
  19237. if ((contour[0].flags & 1)) {
  19238. contour.push(contour[0]); // using start point at the contour end
  19239. } else if ((contour[contour.length - 1].flags & 1)) {
  19240. // first is off-curve point, trying to use one from the end
  19241. contour.unshift(contour[contour.length - 1]);
  19242. } else {
  19243. // start and end are off-curve points, creating implicit one
  19244. var p = {
  19245. flags: 1,
  19246. x: (contour[0].x + contour[contour.length - 1].x) / 2,
  19247. y: (contour[0].y + contour[contour.length - 1].y) / 2
  19248. };
  19249. contour.unshift(p);
  19250. contour.push(p);
  19251. }
  19252. moveTo(contour[0].x, contour[0].y);
  19253. for (j = 1, jj = contour.length; j < jj; j++) {
  19254. if ((contour[j].flags & 1)) {
  19255. lineTo(contour[j].x, contour[j].y);
  19256. } else if ((contour[j + 1].flags & 1)){
  19257. quadraticCurveTo(contour[j].x, contour[j].y,
  19258. contour[j + 1].x, contour[j + 1].y);
  19259. j++;
  19260. } else {
  19261. quadraticCurveTo(contour[j].x, contour[j].y,
  19262. (contour[j].x + contour[j + 1].x) / 2,
  19263. (contour[j].y + contour[j + 1].y) / 2);
  19264. }
  19265. }
  19266. startPoint = endPoint + 1;
  19267. }
  19268. }
  19269. }
  19270. function compileCharString(code, cmds, font) {
  19271. var stack = [];
  19272. var x = 0, y = 0;
  19273. var stems = 0;
  19274. function moveTo(x, y) {
  19275. cmds.push({cmd: 'moveTo', args: [x, y]});
  19276. }
  19277. function lineTo(x, y) {
  19278. cmds.push({cmd: 'lineTo', args: [x, y]});
  19279. }
  19280. function bezierCurveTo(x1, y1, x2, y2, x, y) {
  19281. cmds.push({cmd: 'bezierCurveTo', args: [x1, y1, x2, y2, x, y]});
  19282. }
  19283. function parse(code) {
  19284. var i = 0;
  19285. while (i < code.length) {
  19286. var stackClean = false;
  19287. var v = code[i++];
  19288. var xa, xb, ya, yb, y1, y2, y3, n, subrCode;
  19289. switch (v) {
  19290. case 1: // hstem
  19291. stems += stack.length >> 1;
  19292. stackClean = true;
  19293. break;
  19294. case 3: // vstem
  19295. stems += stack.length >> 1;
  19296. stackClean = true;
  19297. break;
  19298. case 4: // vmoveto
  19299. y += stack.pop();
  19300. moveTo(x, y);
  19301. stackClean = true;
  19302. break;
  19303. case 5: // rlineto
  19304. while (stack.length > 0) {
  19305. x += stack.shift();
  19306. y += stack.shift();
  19307. lineTo(x, y);
  19308. }
  19309. break;
  19310. case 6: // hlineto
  19311. while (stack.length > 0) {
  19312. x += stack.shift();
  19313. lineTo(x, y);
  19314. if (stack.length === 0) {
  19315. break;
  19316. }
  19317. y += stack.shift();
  19318. lineTo(x, y);
  19319. }
  19320. break;
  19321. case 7: // vlineto
  19322. while (stack.length > 0) {
  19323. y += stack.shift();
  19324. lineTo(x, y);
  19325. if (stack.length === 0) {
  19326. break;
  19327. }
  19328. x += stack.shift();
  19329. lineTo(x, y);
  19330. }
  19331. break;
  19332. case 8: // rrcurveto
  19333. while (stack.length > 0) {
  19334. xa = x + stack.shift(); ya = y + stack.shift();
  19335. xb = xa + stack.shift(); yb = ya + stack.shift();
  19336. x = xb + stack.shift(); y = yb + stack.shift();
  19337. bezierCurveTo(xa, ya, xb, yb, x, y);
  19338. }
  19339. break;
  19340. case 10: // callsubr
  19341. n = stack.pop() + font.subrsBias;
  19342. subrCode = font.subrs[n];
  19343. if (subrCode) {
  19344. parse(subrCode);
  19345. }
  19346. break;
  19347. case 11: // return
  19348. return;
  19349. case 12:
  19350. v = code[i++];
  19351. switch (v) {
  19352. case 34: // flex
  19353. xa = x + stack.shift();
  19354. xb = xa + stack.shift(); y1 = y + stack.shift();
  19355. x = xb + stack.shift();
  19356. bezierCurveTo(xa, y, xb, y1, x, y1);
  19357. xa = x + stack.shift();
  19358. xb = xa + stack.shift();
  19359. x = xb + stack.shift();
  19360. bezierCurveTo(xa, y1, xb, y, x, y);
  19361. break;
  19362. case 35: // flex
  19363. xa = x + stack.shift(); ya = y + stack.shift();
  19364. xb = xa + stack.shift(); yb = ya + stack.shift();
  19365. x = xb + stack.shift(); y = yb + stack.shift();
  19366. bezierCurveTo(xa, ya, xb, yb, x, y);
  19367. xa = x + stack.shift(); ya = y + stack.shift();
  19368. xb = xa + stack.shift(); yb = ya + stack.shift();
  19369. x = xb + stack.shift(); y = yb + stack.shift();
  19370. bezierCurveTo(xa, ya, xb, yb, x, y);
  19371. stack.pop(); // fd
  19372. break;
  19373. case 36: // hflex1
  19374. xa = x + stack.shift(); y1 = y + stack.shift();
  19375. xb = xa + stack.shift(); y2 = y1 + stack.shift();
  19376. x = xb + stack.shift();
  19377. bezierCurveTo(xa, y1, xb, y2, x, y2);
  19378. xa = x + stack.shift();
  19379. xb = xa + stack.shift(); y3 = y2 + stack.shift();
  19380. x = xb + stack.shift();
  19381. bezierCurveTo(xa, y2, xb, y3, x, y);
  19382. break;
  19383. case 37: // flex1
  19384. var x0 = x, y0 = y;
  19385. xa = x + stack.shift(); ya = y + stack.shift();
  19386. xb = xa + stack.shift(); yb = ya + stack.shift();
  19387. x = xb + stack.shift(); y = yb + stack.shift();
  19388. bezierCurveTo(xa, ya, xb, yb, x, y);
  19389. xa = x + stack.shift(); ya = y + stack.shift();
  19390. xb = xa + stack.shift(); yb = ya + stack.shift();
  19391. x = xb; y = yb;
  19392. if (Math.abs(x - x0) > Math.abs(y - y0)) {
  19393. x += stack.shift();
  19394. } else {
  19395. y += stack.shift();
  19396. }
  19397. bezierCurveTo(xa, ya, xb, yb, x, y);
  19398. break;
  19399. default:
  19400. error('unknown operator: 12 ' + v);
  19401. }
  19402. break;
  19403. case 14: // endchar
  19404. if (stack.length >= 4) {
  19405. var achar = stack.pop();
  19406. var bchar = stack.pop();
  19407. y = stack.pop();
  19408. x = stack.pop();
  19409. cmds.push({cmd: 'save'});
  19410. cmds.push({cmd: 'translate', args: [x, y]});
  19411. var gid = lookupCmap(font.cmap, String.fromCharCode(
  19412. font.glyphNameMap[Encodings.StandardEncoding[achar]]));
  19413. compileCharString(font.glyphs[gid], cmds, font);
  19414. cmds.push({cmd: 'restore'});
  19415. gid = lookupCmap(font.cmap, String.fromCharCode(
  19416. font.glyphNameMap[Encodings.StandardEncoding[bchar]]));
  19417. compileCharString(font.glyphs[gid], cmds, font);
  19418. }
  19419. return;
  19420. case 18: // hstemhm
  19421. stems += stack.length >> 1;
  19422. stackClean = true;
  19423. break;
  19424. case 19: // hintmask
  19425. stems += stack.length >> 1;
  19426. i += (stems + 7) >> 3;
  19427. stackClean = true;
  19428. break;
  19429. case 20: // cntrmask
  19430. stems += stack.length >> 1;
  19431. i += (stems + 7) >> 3;
  19432. stackClean = true;
  19433. break;
  19434. case 21: // rmoveto
  19435. y += stack.pop();
  19436. x += stack.pop();
  19437. moveTo(x, y);
  19438. stackClean = true;
  19439. break;
  19440. case 22: // hmoveto
  19441. x += stack.pop();
  19442. moveTo(x, y);
  19443. stackClean = true;
  19444. break;
  19445. case 23: // vstemhm
  19446. stems += stack.length >> 1;
  19447. stackClean = true;
  19448. break;
  19449. case 24: // rcurveline
  19450. while (stack.length > 2) {
  19451. xa = x + stack.shift(); ya = y + stack.shift();
  19452. xb = xa + stack.shift(); yb = ya + stack.shift();
  19453. x = xb + stack.shift(); y = yb + stack.shift();
  19454. bezierCurveTo(xa, ya, xb, yb, x, y);
  19455. }
  19456. x += stack.shift();
  19457. y += stack.shift();
  19458. lineTo(x, y);
  19459. break;
  19460. case 25: // rlinecurve
  19461. while (stack.length > 6) {
  19462. x += stack.shift();
  19463. y += stack.shift();
  19464. lineTo(x, y);
  19465. }
  19466. xa = x + stack.shift(); ya = y + stack.shift();
  19467. xb = xa + stack.shift(); yb = ya + stack.shift();
  19468. x = xb + stack.shift(); y = yb + stack.shift();
  19469. bezierCurveTo(xa, ya, xb, yb, x, y);
  19470. break;
  19471. case 26: // vvcurveto
  19472. if (stack.length % 2) {
  19473. x += stack.shift();
  19474. }
  19475. while (stack.length > 0) {
  19476. xa = x; ya = y + stack.shift();
  19477. xb = xa + stack.shift(); yb = ya + stack.shift();
  19478. x = xb; y = yb + stack.shift();
  19479. bezierCurveTo(xa, ya, xb, yb, x, y);
  19480. }
  19481. break;
  19482. case 27: // hhcurveto
  19483. if (stack.length % 2) {
  19484. y += stack.shift();
  19485. }
  19486. while (stack.length > 0) {
  19487. xa = x + stack.shift(); ya = y;
  19488. xb = xa + stack.shift(); yb = ya + stack.shift();
  19489. x = xb + stack.shift(); y = yb;
  19490. bezierCurveTo(xa, ya, xb, yb, x, y);
  19491. }
  19492. break;
  19493. case 28:
  19494. stack.push(((code[i] << 24) | (code[i + 1] << 16)) >> 16);
  19495. i += 2;
  19496. break;
  19497. case 29: // callgsubr
  19498. n = stack.pop() + font.gsubrsBias;
  19499. subrCode = font.gsubrs[n];
  19500. if (subrCode) {
  19501. parse(subrCode);
  19502. }
  19503. break;
  19504. case 30: // vhcurveto
  19505. while (stack.length > 0) {
  19506. xa = x; ya = y + stack.shift();
  19507. xb = xa + stack.shift(); yb = ya + stack.shift();
  19508. x = xb + stack.shift();
  19509. y = yb + (stack.length === 1 ? stack.shift() : 0);
  19510. bezierCurveTo(xa, ya, xb, yb, x, y);
  19511. if (stack.length === 0) {
  19512. break;
  19513. }
  19514. xa = x + stack.shift(); ya = y;
  19515. xb = xa + stack.shift(); yb = ya + stack.shift();
  19516. y = yb + stack.shift();
  19517. x = xb + (stack.length === 1 ? stack.shift() : 0);
  19518. bezierCurveTo(xa, ya, xb, yb, x, y);
  19519. }
  19520. break;
  19521. case 31: // hvcurveto
  19522. while (stack.length > 0) {
  19523. xa = x + stack.shift(); ya = y;
  19524. xb = xa + stack.shift(); yb = ya + stack.shift();
  19525. y = yb + stack.shift();
  19526. x = xb + (stack.length === 1 ? stack.shift() : 0);
  19527. bezierCurveTo(xa, ya, xb, yb, x, y);
  19528. if (stack.length === 0) {
  19529. break;
  19530. }
  19531. xa = x; ya = y + stack.shift();
  19532. xb = xa + stack.shift(); yb = ya + stack.shift();
  19533. x = xb + stack.shift();
  19534. y = yb + (stack.length === 1 ? stack.shift() : 0);
  19535. bezierCurveTo(xa, ya, xb, yb, x, y);
  19536. }
  19537. break;
  19538. default:
  19539. if (v < 32) {
  19540. error('unknown operator: ' + v);
  19541. }
  19542. if (v < 247) {
  19543. stack.push(v - 139);
  19544. } else if (v < 251) {
  19545. stack.push((v - 247) * 256 + code[i++] + 108);
  19546. } else if (v < 255) {
  19547. stack.push(-(v - 251) * 256 - code[i++] - 108);
  19548. } else {
  19549. stack.push(((code[i] << 24) | (code[i + 1] << 16) |
  19550. (code[i + 2] << 8) | code[i + 3]) / 65536);
  19551. i += 4;
  19552. }
  19553. break;
  19554. }
  19555. if (stackClean) {
  19556. stack.length = 0;
  19557. }
  19558. }
  19559. }
  19560. parse(code);
  19561. }
  19562. var noop = '';
  19563. function CompiledFont(fontMatrix) {
  19564. this.compiledGlyphs = {};
  19565. this.fontMatrix = fontMatrix;
  19566. }
  19567. CompiledFont.prototype = {
  19568. getPathJs: function (unicode) {
  19569. var gid = lookupCmap(this.cmap, unicode);
  19570. var fn = this.compiledGlyphs[gid];
  19571. if (!fn) {
  19572. this.compiledGlyphs[gid] = fn = this.compileGlyph(this.glyphs[gid]);
  19573. }
  19574. return fn;
  19575. },
  19576. compileGlyph: function (code) {
  19577. if (!code || code.length === 0 || code[0] === 14) {
  19578. return noop;
  19579. }
  19580. var cmds = [];
  19581. cmds.push({cmd: 'save'});
  19582. cmds.push({cmd: 'transform', args: this.fontMatrix.slice()});
  19583. cmds.push({cmd: 'scale', args: ['size', '-size']});
  19584. this.compileGlyphImpl(code, cmds);
  19585. cmds.push({cmd: 'restore'});
  19586. return cmds;
  19587. },
  19588. compileGlyphImpl: function () {
  19589. error('Children classes should implement this.');
  19590. },
  19591. hasBuiltPath: function (unicode) {
  19592. var gid = lookupCmap(this.cmap, unicode);
  19593. return gid in this.compiledGlyphs;
  19594. }
  19595. };
  19596. function TrueTypeCompiled(glyphs, cmap, fontMatrix) {
  19597. fontMatrix = fontMatrix || [0.000488, 0, 0, 0.000488, 0, 0];
  19598. CompiledFont.call(this, fontMatrix);
  19599. this.glyphs = glyphs;
  19600. this.cmap = cmap;
  19601. this.compiledGlyphs = [];
  19602. }
  19603. Util.inherit(TrueTypeCompiled, CompiledFont, {
  19604. compileGlyphImpl: function (code, cmds) {
  19605. compileGlyf(code, cmds, this);
  19606. }
  19607. });
  19608. function Type2Compiled(cffInfo, cmap, fontMatrix, glyphNameMap) {
  19609. fontMatrix = fontMatrix || [0.001, 0, 0, 0.001, 0, 0];
  19610. CompiledFont.call(this, fontMatrix);
  19611. this.glyphs = cffInfo.glyphs;
  19612. this.gsubrs = cffInfo.gsubrs || [];
  19613. this.subrs = cffInfo.subrs || [];
  19614. this.cmap = cmap;
  19615. this.glyphNameMap = glyphNameMap || GlyphsUnicode;
  19616. this.compiledGlyphs = [];
  19617. this.gsubrsBias = (this.gsubrs.length < 1240 ?
  19618. 107 : (this.gsubrs.length < 33900 ? 1131 : 32768));
  19619. this.subrsBias = (this.subrs.length < 1240 ?
  19620. 107 : (this.subrs.length < 33900 ? 1131 : 32768));
  19621. }
  19622. Util.inherit(Type2Compiled, CompiledFont, {
  19623. compileGlyphImpl: function (code, cmds) {
  19624. compileCharString(code, cmds, this);
  19625. }
  19626. });
  19627. return {
  19628. create: function FontRendererFactory_create(font) {
  19629. var data = new Uint8Array(font.data);
  19630. var cmap, glyf, loca, cff, indexToLocFormat, unitsPerEm;
  19631. var numTables = getUshort(data, 4);
  19632. for (var i = 0, p = 12; i < numTables; i++, p += 16) {
  19633. var tag = bytesToString(data.subarray(p, p + 4));
  19634. var offset = getLong(data, p + 8);
  19635. var length = getLong(data, p + 12);
  19636. switch (tag) {
  19637. case 'cmap':
  19638. cmap = parseCmap(data, offset, offset + length);
  19639. break;
  19640. case 'glyf':
  19641. glyf = data.subarray(offset, offset + length);
  19642. break;
  19643. case 'loca':
  19644. loca = data.subarray(offset, offset + length);
  19645. break;
  19646. case 'head':
  19647. unitsPerEm = getUshort(data, offset + 18);
  19648. indexToLocFormat = getUshort(data, offset + 50);
  19649. break;
  19650. case 'CFF ':
  19651. cff = parseCff(data, offset, offset + length);
  19652. break;
  19653. }
  19654. }
  19655. if (glyf) {
  19656. var fontMatrix = (!unitsPerEm ? font.fontMatrix :
  19657. [1 / unitsPerEm, 0, 0, 1 / unitsPerEm, 0, 0]);
  19658. return new TrueTypeCompiled(
  19659. parseGlyfTable(glyf, loca, indexToLocFormat), cmap, fontMatrix);
  19660. } else {
  19661. return new Type2Compiled(cff, cmap, font.fontMatrix, font.glyphNameMap);
  19662. }
  19663. }
  19664. };
  19665. })();
  19666. // TODO refactor to remove cyclic dependency on fonts.js
  19667. function _setCoreFonts(coreFonts_) {
  19668. coreFonts = coreFonts_;
  19669. Encodings = coreFonts_.Encodings;
  19670. CFFParser = coreFonts_.CFFParser;
  19671. }
  19672. exports._setCoreFonts = _setCoreFonts;
  19673. exports.FontRendererFactory = FontRendererFactory;
  19674. }));
  19675. (function (root, factory) {
  19676. {
  19677. factory((root.pdfjsCoreParser = {}), root.pdfjsSharedUtil,
  19678. root.pdfjsCorePrimitives, root.pdfjsCoreStream);
  19679. }
  19680. }(this, function (exports, sharedUtil, corePrimitives, coreStream) {
  19681. var MissingDataException = sharedUtil.MissingDataException;
  19682. var StreamType = sharedUtil.StreamType;
  19683. var assert = sharedUtil.assert;
  19684. var error = sharedUtil.error;
  19685. var info = sharedUtil.info;
  19686. var isArray = sharedUtil.isArray;
  19687. var isInt = sharedUtil.isInt;
  19688. var isNum = sharedUtil.isNum;
  19689. var isString = sharedUtil.isString;
  19690. var warn = sharedUtil.warn;
  19691. var Cmd = corePrimitives.Cmd;
  19692. var Dict = corePrimitives.Dict;
  19693. var Name = corePrimitives.Name;
  19694. var Ref = corePrimitives.Ref;
  19695. var isCmd = corePrimitives.isCmd;
  19696. var isDict = corePrimitives.isDict;
  19697. var isName = corePrimitives.isName;
  19698. var Ascii85Stream = coreStream.Ascii85Stream;
  19699. var AsciiHexStream = coreStream.AsciiHexStream;
  19700. var CCITTFaxStream = coreStream.CCITTFaxStream;
  19701. var FlateStream = coreStream.FlateStream;
  19702. var Jbig2Stream = coreStream.Jbig2Stream;
  19703. var JpegStream = coreStream.JpegStream;
  19704. var JpxStream = coreStream.JpxStream;
  19705. var LZWStream = coreStream.LZWStream;
  19706. var NullStream = coreStream.NullStream;
  19707. var PredictorStream = coreStream.PredictorStream;
  19708. var RunLengthStream = coreStream.RunLengthStream;
  19709. var EOF = {};
  19710. function isEOF(v) {
  19711. return (v === EOF);
  19712. }
  19713. var MAX_LENGTH_TO_CACHE = 1000;
  19714. var Parser = (function ParserClosure() {
  19715. function Parser(lexer, allowStreams, xref) {
  19716. this.lexer = lexer;
  19717. this.allowStreams = allowStreams;
  19718. this.xref = xref;
  19719. this.imageCache = {};
  19720. this.refill();
  19721. }
  19722. Parser.prototype = {
  19723. refill: function Parser_refill() {
  19724. this.buf1 = this.lexer.getObj();
  19725. this.buf2 = this.lexer.getObj();
  19726. },
  19727. shift: function Parser_shift() {
  19728. if (isCmd(this.buf2, 'ID')) {
  19729. this.buf1 = this.buf2;
  19730. this.buf2 = null;
  19731. } else {
  19732. this.buf1 = this.buf2;
  19733. this.buf2 = this.lexer.getObj();
  19734. }
  19735. },
  19736. tryShift: function Parser_tryShift() {
  19737. try {
  19738. this.shift();
  19739. return true;
  19740. } catch (e) {
  19741. if (e instanceof MissingDataException) {
  19742. throw e;
  19743. }
  19744. // Upon failure, the caller should reset this.lexer.pos to a known good
  19745. // state and call this.shift() twice to reset the buffers.
  19746. return false;
  19747. }
  19748. },
  19749. getObj: function Parser_getObj(cipherTransform) {
  19750. var buf1 = this.buf1;
  19751. this.shift();
  19752. if (buf1 instanceof Cmd) {
  19753. switch (buf1.cmd) {
  19754. case 'BI': // inline image
  19755. return this.makeInlineImage(cipherTransform);
  19756. case '[': // array
  19757. var array = [];
  19758. while (!isCmd(this.buf1, ']') && !isEOF(this.buf1)) {
  19759. array.push(this.getObj(cipherTransform));
  19760. }
  19761. if (isEOF(this.buf1)) {
  19762. error('End of file inside array');
  19763. }
  19764. this.shift();
  19765. return array;
  19766. case '<<': // dictionary or stream
  19767. var dict = new Dict(this.xref);
  19768. while (!isCmd(this.buf1, '>>') && !isEOF(this.buf1)) {
  19769. if (!isName(this.buf1)) {
  19770. info('Malformed dictionary: key must be a name object');
  19771. this.shift();
  19772. continue;
  19773. }
  19774. var key = this.buf1.name;
  19775. this.shift();
  19776. if (isEOF(this.buf1)) {
  19777. break;
  19778. }
  19779. dict.set(key, this.getObj(cipherTransform));
  19780. }
  19781. if (isEOF(this.buf1)) {
  19782. error('End of file inside dictionary');
  19783. }
  19784. // Stream objects are not allowed inside content streams or
  19785. // object streams.
  19786. if (isCmd(this.buf2, 'stream')) {
  19787. return (this.allowStreams ?
  19788. this.makeStream(dict, cipherTransform) : dict);
  19789. }
  19790. this.shift();
  19791. return dict;
  19792. default: // simple object
  19793. return buf1;
  19794. }
  19795. }
  19796. if (isInt(buf1)) { // indirect reference or integer
  19797. var num = buf1;
  19798. if (isInt(this.buf1) && isCmd(this.buf2, 'R')) {
  19799. var ref = new Ref(num, this.buf1);
  19800. this.shift();
  19801. this.shift();
  19802. return ref;
  19803. }
  19804. return num;
  19805. }
  19806. if (isString(buf1)) { // string
  19807. var str = buf1;
  19808. if (cipherTransform) {
  19809. str = cipherTransform.decryptString(str);
  19810. }
  19811. return str;
  19812. }
  19813. // simple object
  19814. return buf1;
  19815. },
  19816. /**
  19817. * Find the end of the stream by searching for the /EI\s/.
  19818. * @returns {number} The inline stream length.
  19819. */
  19820. findDefaultInlineStreamEnd:
  19821. function Parser_findDefaultInlineStreamEnd(stream) {
  19822. var E = 0x45, I = 0x49, SPACE = 0x20, LF = 0xA, CR = 0xD;
  19823. var startPos = stream.pos, state = 0, ch, i, n, followingBytes;
  19824. while ((ch = stream.getByte()) !== -1) {
  19825. if (state === 0) {
  19826. state = (ch === E) ? 1 : 0;
  19827. } else if (state === 1) {
  19828. state = (ch === I) ? 2 : 0;
  19829. } else {
  19830. assert(state === 2);
  19831. if (ch === SPACE || ch === LF || ch === CR) {
  19832. // Let's check the next five bytes are ASCII... just be sure.
  19833. n = 5;
  19834. followingBytes = stream.peekBytes(n);
  19835. for (i = 0; i < n; i++) {
  19836. ch = followingBytes[i];
  19837. if (ch !== LF && ch !== CR && (ch < SPACE || ch > 0x7F)) {
  19838. // Not a LF, CR, SPACE or any visible ASCII character, i.e.
  19839. // it's binary stuff. Resetting the state.
  19840. state = 0;
  19841. break;
  19842. }
  19843. }
  19844. if (state === 2) {
  19845. break; // Finished!
  19846. }
  19847. } else {
  19848. state = 0;
  19849. }
  19850. }
  19851. }
  19852. return ((stream.pos - 4) - startPos);
  19853. },
  19854. /**
  19855. * Find the EOI (end-of-image) marker 0xFFD9 of the stream.
  19856. * @returns {number} The inline stream length.
  19857. */
  19858. findDCTDecodeInlineStreamEnd:
  19859. function Parser_findDCTDecodeInlineStreamEnd(stream) {
  19860. var startPos = stream.pos, foundEOI = false, b, markerLength, length;
  19861. while ((b = stream.getByte()) !== -1) {
  19862. if (b !== 0xFF) { // Not a valid marker.
  19863. continue;
  19864. }
  19865. switch (stream.getByte()) {
  19866. case 0x00: // Byte stuffing.
  19867. // 0xFF00 appears to be a very common byte sequence in JPEG images.
  19868. break;
  19869. case 0xFF: // Fill byte.
  19870. // Avoid skipping a valid marker, resetting the stream position.
  19871. stream.skip(-1);
  19872. break;
  19873. case 0xD9: // EOI
  19874. foundEOI = true;
  19875. break;
  19876. case 0xC0: // SOF0
  19877. case 0xC1: // SOF1
  19878. case 0xC2: // SOF2
  19879. case 0xC3: // SOF3
  19880. case 0xC5: // SOF5
  19881. case 0xC6: // SOF6
  19882. case 0xC7: // SOF7
  19883. case 0xC9: // SOF9
  19884. case 0xCA: // SOF10
  19885. case 0xCB: // SOF11
  19886. case 0xCD: // SOF13
  19887. case 0xCE: // SOF14
  19888. case 0xCF: // SOF15
  19889. case 0xC4: // DHT
  19890. case 0xCC: // DAC
  19891. case 0xDA: // SOS
  19892. case 0xDB: // DQT
  19893. case 0xDC: // DNL
  19894. case 0xDD: // DRI
  19895. case 0xDE: // DHP
  19896. case 0xDF: // EXP
  19897. case 0xE0: // APP0
  19898. case 0xE1: // APP1
  19899. case 0xE2: // APP2
  19900. case 0xE3: // APP3
  19901. case 0xE4: // APP4
  19902. case 0xE5: // APP5
  19903. case 0xE6: // APP6
  19904. case 0xE7: // APP7
  19905. case 0xE8: // APP8
  19906. case 0xE9: // APP9
  19907. case 0xEA: // APP10
  19908. case 0xEB: // APP11
  19909. case 0xEC: // APP12
  19910. case 0xED: // APP13
  19911. case 0xEE: // APP14
  19912. case 0xEF: // APP15
  19913. case 0xFE: // COM
  19914. // The marker should be followed by the length of the segment.
  19915. markerLength = stream.getUint16();
  19916. if (markerLength > 2) {
  19917. // |markerLength| contains the byte length of the marker segment,
  19918. // including its own length (2 bytes) and excluding the marker.
  19919. stream.skip(markerLength - 2); // Jump to the next marker.
  19920. } else {
  19921. // The marker length is invalid, resetting the stream position.
  19922. stream.skip(-2);
  19923. }
  19924. break;
  19925. }
  19926. if (foundEOI) {
  19927. break;
  19928. }
  19929. }
  19930. length = stream.pos - startPos;
  19931. if (b === -1) {
  19932. warn('Inline DCTDecode image stream: ' +
  19933. 'EOI marker not found, searching for /EI/ instead.');
  19934. stream.skip(-length); // Reset the stream position.
  19935. return this.findDefaultInlineStreamEnd(stream);
  19936. }
  19937. this.inlineStreamSkipEI(stream);
  19938. return length;
  19939. },
  19940. /**
  19941. * Find the EOD (end-of-data) marker '~>' (i.e. TILDE + GT) of the stream.
  19942. * @returns {number} The inline stream length.
  19943. */
  19944. findASCII85DecodeInlineStreamEnd:
  19945. function Parser_findASCII85DecodeInlineStreamEnd(stream) {
  19946. var TILDE = 0x7E, GT = 0x3E;
  19947. var startPos = stream.pos, ch, length;
  19948. while ((ch = stream.getByte()) !== -1) {
  19949. if (ch === TILDE && stream.peekByte() === GT) {
  19950. stream.skip();
  19951. break;
  19952. }
  19953. }
  19954. length = stream.pos - startPos;
  19955. if (ch === -1) {
  19956. warn('Inline ASCII85Decode image stream: ' +
  19957. 'EOD marker not found, searching for /EI/ instead.');
  19958. stream.skip(-length); // Reset the stream position.
  19959. return this.findDefaultInlineStreamEnd(stream);
  19960. }
  19961. this.inlineStreamSkipEI(stream);
  19962. return length;
  19963. },
  19964. /**
  19965. * Find the EOD (end-of-data) marker '>' (i.e. GT) of the stream.
  19966. * @returns {number} The inline stream length.
  19967. */
  19968. findASCIIHexDecodeInlineStreamEnd:
  19969. function Parser_findASCIIHexDecodeInlineStreamEnd(stream) {
  19970. var GT = 0x3E;
  19971. var startPos = stream.pos, ch, length;
  19972. while ((ch = stream.getByte()) !== -1) {
  19973. if (ch === GT) {
  19974. break;
  19975. }
  19976. }
  19977. length = stream.pos - startPos;
  19978. if (ch === -1) {
  19979. warn('Inline ASCIIHexDecode image stream: ' +
  19980. 'EOD marker not found, searching for /EI/ instead.');
  19981. stream.skip(-length); // Reset the stream position.
  19982. return this.findDefaultInlineStreamEnd(stream);
  19983. }
  19984. this.inlineStreamSkipEI(stream);
  19985. return length;
  19986. },
  19987. /**
  19988. * Skip over the /EI/ for streams where we search for an EOD marker.
  19989. */
  19990. inlineStreamSkipEI: function Parser_inlineStreamSkipEI(stream) {
  19991. var E = 0x45, I = 0x49;
  19992. var state = 0, ch;
  19993. while ((ch = stream.getByte()) !== -1) {
  19994. if (state === 0) {
  19995. state = (ch === E) ? 1 : 0;
  19996. } else if (state === 1) {
  19997. state = (ch === I) ? 2 : 0;
  19998. } else if (state === 2) {
  19999. break;
  20000. }
  20001. }
  20002. },
  20003. makeInlineImage: function Parser_makeInlineImage(cipherTransform) {
  20004. var lexer = this.lexer;
  20005. var stream = lexer.stream;
  20006. // Parse dictionary.
  20007. var dict = new Dict(this.xref);
  20008. while (!isCmd(this.buf1, 'ID') && !isEOF(this.buf1)) {
  20009. if (!isName(this.buf1)) {
  20010. error('Dictionary key must be a name object');
  20011. }
  20012. var key = this.buf1.name;
  20013. this.shift();
  20014. if (isEOF(this.buf1)) {
  20015. break;
  20016. }
  20017. dict.set(key, this.getObj(cipherTransform));
  20018. }
  20019. // Extract the name of the first (i.e. the current) image filter.
  20020. var filter = dict.get('Filter', 'F'), filterName;
  20021. if (isName(filter)) {
  20022. filterName = filter.name;
  20023. } else if (isArray(filter) && isName(filter[0])) {
  20024. filterName = filter[0].name;
  20025. }
  20026. // Parse image stream.
  20027. var startPos = stream.pos, length, i, ii;
  20028. if (filterName === 'DCTDecode' || filterName === 'DCT') {
  20029. length = this.findDCTDecodeInlineStreamEnd(stream);
  20030. } else if (filterName === 'ASCII85Decide' || filterName === 'A85') {
  20031. length = this.findASCII85DecodeInlineStreamEnd(stream);
  20032. } else if (filterName === 'ASCIIHexDecode' || filterName === 'AHx') {
  20033. length = this.findASCIIHexDecodeInlineStreamEnd(stream);
  20034. } else {
  20035. length = this.findDefaultInlineStreamEnd(stream);
  20036. }
  20037. var imageStream = stream.makeSubStream(startPos, length, dict);
  20038. // Cache all images below the MAX_LENGTH_TO_CACHE threshold by their
  20039. // adler32 checksum.
  20040. var adler32;
  20041. if (length < MAX_LENGTH_TO_CACHE) {
  20042. var imageBytes = imageStream.getBytes();
  20043. imageStream.reset();
  20044. var a = 1;
  20045. var b = 0;
  20046. for (i = 0, ii = imageBytes.length; i < ii; ++i) {
  20047. // No modulo required in the loop if imageBytes.length < 5552.
  20048. a += imageBytes[i] & 0xff;
  20049. b += a;
  20050. }
  20051. adler32 = ((b % 65521) << 16) | (a % 65521);
  20052. if (this.imageCache.adler32 === adler32) {
  20053. this.buf2 = Cmd.get('EI');
  20054. this.shift();
  20055. this.imageCache[adler32].reset();
  20056. return this.imageCache[adler32];
  20057. }
  20058. }
  20059. if (cipherTransform) {
  20060. imageStream = cipherTransform.createStream(imageStream, length);
  20061. }
  20062. imageStream = this.filter(imageStream, dict, length);
  20063. imageStream.dict = dict;
  20064. if (adler32 !== undefined) {
  20065. imageStream.cacheKey = 'inline_' + length + '_' + adler32;
  20066. this.imageCache[adler32] = imageStream;
  20067. }
  20068. this.buf2 = Cmd.get('EI');
  20069. this.shift();
  20070. return imageStream;
  20071. },
  20072. makeStream: function Parser_makeStream(dict, cipherTransform) {
  20073. var lexer = this.lexer;
  20074. var stream = lexer.stream;
  20075. // get stream start position
  20076. lexer.skipToNextLine();
  20077. var pos = stream.pos - 1;
  20078. // get length
  20079. var length = dict.get('Length');
  20080. if (!isInt(length)) {
  20081. info('Bad ' + length + ' attribute in stream');
  20082. length = 0;
  20083. }
  20084. // skip over the stream data
  20085. stream.pos = pos + length;
  20086. lexer.nextChar();
  20087. // Shift '>>' and check whether the new object marks the end of the stream
  20088. if (this.tryShift() && isCmd(this.buf2, 'endstream')) {
  20089. this.shift(); // 'stream'
  20090. } else {
  20091. // bad stream length, scanning for endstream
  20092. stream.pos = pos;
  20093. var SCAN_BLOCK_SIZE = 2048;
  20094. var ENDSTREAM_SIGNATURE_LENGTH = 9;
  20095. var ENDSTREAM_SIGNATURE = [0x65, 0x6E, 0x64, 0x73, 0x74, 0x72, 0x65,
  20096. 0x61, 0x6D];
  20097. var skipped = 0, found = false, i, j;
  20098. while (stream.pos < stream.end) {
  20099. var scanBytes = stream.peekBytes(SCAN_BLOCK_SIZE);
  20100. var scanLength = scanBytes.length - ENDSTREAM_SIGNATURE_LENGTH;
  20101. if (scanLength <= 0) {
  20102. break;
  20103. }
  20104. found = false;
  20105. for (i = 0, j = 0; i < scanLength; i++) {
  20106. var b = scanBytes[i];
  20107. if (b !== ENDSTREAM_SIGNATURE[j]) {
  20108. i -= j;
  20109. j = 0;
  20110. } else {
  20111. j++;
  20112. if (j >= ENDSTREAM_SIGNATURE_LENGTH) {
  20113. i++;
  20114. found = true;
  20115. break;
  20116. }
  20117. }
  20118. }
  20119. if (found) {
  20120. skipped += i - ENDSTREAM_SIGNATURE_LENGTH;
  20121. stream.pos += i - ENDSTREAM_SIGNATURE_LENGTH;
  20122. break;
  20123. }
  20124. skipped += scanLength;
  20125. stream.pos += scanLength;
  20126. }
  20127. if (!found) {
  20128. error('Missing endstream');
  20129. }
  20130. length = skipped;
  20131. lexer.nextChar();
  20132. this.shift();
  20133. this.shift();
  20134. }
  20135. this.shift(); // 'endstream'
  20136. stream = stream.makeSubStream(pos, length, dict);
  20137. if (cipherTransform) {
  20138. stream = cipherTransform.createStream(stream, length);
  20139. }
  20140. stream = this.filter(stream, dict, length);
  20141. stream.dict = dict;
  20142. return stream;
  20143. },
  20144. filter: function Parser_filter(stream, dict, length) {
  20145. var filter = dict.get('Filter', 'F');
  20146. var params = dict.get('DecodeParms', 'DP');
  20147. if (isName(filter)) {
  20148. return this.makeFilter(stream, filter.name, length, params);
  20149. }
  20150. var maybeLength = length;
  20151. if (isArray(filter)) {
  20152. var filterArray = filter;
  20153. var paramsArray = params;
  20154. for (var i = 0, ii = filterArray.length; i < ii; ++i) {
  20155. filter = filterArray[i];
  20156. if (!isName(filter)) {
  20157. error('Bad filter name: ' + filter);
  20158. }
  20159. params = null;
  20160. if (isArray(paramsArray) && (i in paramsArray)) {
  20161. params = paramsArray[i];
  20162. }
  20163. stream = this.makeFilter(stream, filter.name, maybeLength, params);
  20164. // after the first stream the length variable is invalid
  20165. maybeLength = null;
  20166. }
  20167. }
  20168. return stream;
  20169. },
  20170. makeFilter: function Parser_makeFilter(stream, name, maybeLength, params) {
  20171. if (stream.dict.get('Length') === 0 && !maybeLength) {
  20172. warn('Empty "' + name + '" stream.');
  20173. return new NullStream(stream);
  20174. }
  20175. try {
  20176. if (params && this.xref) {
  20177. params = this.xref.fetchIfRef(params);
  20178. }
  20179. var xrefStreamStats = this.xref.stats.streamTypes;
  20180. if (name === 'FlateDecode' || name === 'Fl') {
  20181. xrefStreamStats[StreamType.FLATE] = true;
  20182. if (params) {
  20183. return new PredictorStream(new FlateStream(stream, maybeLength),
  20184. maybeLength, params);
  20185. }
  20186. return new FlateStream(stream, maybeLength);
  20187. }
  20188. if (name === 'LZWDecode' || name === 'LZW') {
  20189. xrefStreamStats[StreamType.LZW] = true;
  20190. var earlyChange = 1;
  20191. if (params) {
  20192. if (params.has('EarlyChange')) {
  20193. earlyChange = params.get('EarlyChange');
  20194. }
  20195. return new PredictorStream(
  20196. new LZWStream(stream, maybeLength, earlyChange),
  20197. maybeLength, params);
  20198. }
  20199. return new LZWStream(stream, maybeLength, earlyChange);
  20200. }
  20201. if (name === 'DCTDecode' || name === 'DCT') {
  20202. xrefStreamStats[StreamType.DCT] = true;
  20203. return new JpegStream(stream, maybeLength, stream.dict, this.xref);
  20204. }
  20205. if (name === 'JPXDecode' || name === 'JPX') {
  20206. xrefStreamStats[StreamType.JPX] = true;
  20207. return new JpxStream(stream, maybeLength, stream.dict);
  20208. }
  20209. if (name === 'ASCII85Decode' || name === 'A85') {
  20210. xrefStreamStats[StreamType.A85] = true;
  20211. return new Ascii85Stream(stream, maybeLength);
  20212. }
  20213. if (name === 'ASCIIHexDecode' || name === 'AHx') {
  20214. xrefStreamStats[StreamType.AHX] = true;
  20215. return new AsciiHexStream(stream, maybeLength);
  20216. }
  20217. if (name === 'CCITTFaxDecode' || name === 'CCF') {
  20218. xrefStreamStats[StreamType.CCF] = true;
  20219. return new CCITTFaxStream(stream, maybeLength, params);
  20220. }
  20221. if (name === 'RunLengthDecode' || name === 'RL') {
  20222. xrefStreamStats[StreamType.RL] = true;
  20223. return new RunLengthStream(stream, maybeLength);
  20224. }
  20225. if (name === 'JBIG2Decode') {
  20226. xrefStreamStats[StreamType.JBIG] = true;
  20227. return new Jbig2Stream(stream, maybeLength, stream.dict);
  20228. }
  20229. warn('filter "' + name + '" not supported yet');
  20230. return stream;
  20231. } catch (ex) {
  20232. if (ex instanceof MissingDataException) {
  20233. throw ex;
  20234. }
  20235. warn('Invalid stream: \"' + ex + '\"');
  20236. return new NullStream(stream);
  20237. }
  20238. }
  20239. };
  20240. return Parser;
  20241. })();
  20242. var Lexer = (function LexerClosure() {
  20243. function Lexer(stream, knownCommands) {
  20244. this.stream = stream;
  20245. this.nextChar();
  20246. // While lexing, we build up many strings one char at a time. Using += for
  20247. // this can result in lots of garbage strings. It's better to build an
  20248. // array of single-char strings and then join() them together at the end.
  20249. // And reusing a single array (i.e. |this.strBuf|) over and over for this
  20250. // purpose uses less memory than using a new array for each string.
  20251. this.strBuf = [];
  20252. // The PDFs might have "glued" commands with other commands, operands or
  20253. // literals, e.g. "q1". The knownCommands is a dictionary of the valid
  20254. // commands and their prefixes. The prefixes are built the following way:
  20255. // if there a command that is a prefix of the other valid command or
  20256. // literal (e.g. 'f' and 'false') the following prefixes must be included,
  20257. // 'fa', 'fal', 'fals'. The prefixes are not needed, if the command has no
  20258. // other commands or literals as a prefix. The knowCommands is optional.
  20259. this.knownCommands = knownCommands;
  20260. }
  20261. Lexer.isSpace = function Lexer_isSpace(ch) {
  20262. // Space is one of the following characters: SPACE, TAB, CR or LF.
  20263. return (ch === 0x20 || ch === 0x09 || ch === 0x0D || ch === 0x0A);
  20264. };
  20265. // A '1' in this array means the character is white space. A '1' or
  20266. // '2' means the character ends a name or command.
  20267. var specialChars = [
  20268. 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, // 0x
  20269. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 1x
  20270. 1, 0, 0, 0, 0, 2, 0, 0, 2, 2, 0, 0, 0, 0, 0, 2, // 2x
  20271. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, // 3x
  20272. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 4x
  20273. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 5x
  20274. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 6x
  20275. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 7x
  20276. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 8x
  20277. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 9x
  20278. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ax
  20279. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // bx
  20280. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // cx
  20281. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // dx
  20282. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ex
  20283. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 // fx
  20284. ];
  20285. function toHexDigit(ch) {
  20286. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  20287. return ch & 0x0F;
  20288. }
  20289. if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  20290. // 'A'-'F', 'a'-'f'
  20291. return (ch & 0x0F) + 9;
  20292. }
  20293. return -1;
  20294. }
  20295. Lexer.prototype = {
  20296. nextChar: function Lexer_nextChar() {
  20297. return (this.currentChar = this.stream.getByte());
  20298. },
  20299. peekChar: function Lexer_peekChar() {
  20300. return this.stream.peekByte();
  20301. },
  20302. getNumber: function Lexer_getNumber() {
  20303. var ch = this.currentChar;
  20304. var eNotation = false;
  20305. var divideBy = 0; // different from 0 if it's a floating point value
  20306. var sign = 1;
  20307. if (ch === 0x2D) { // '-'
  20308. sign = -1;
  20309. ch = this.nextChar();
  20310. if (ch === 0x2D) { // '-'
  20311. // Ignore double negative (this is consistent with Adobe Reader).
  20312. ch = this.nextChar();
  20313. }
  20314. } else if (ch === 0x2B) { // '+'
  20315. ch = this.nextChar();
  20316. }
  20317. if (ch === 0x2E) { // '.'
  20318. divideBy = 10;
  20319. ch = this.nextChar();
  20320. }
  20321. if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  20322. error('Invalid number: ' + String.fromCharCode(ch));
  20323. return 0;
  20324. }
  20325. var baseValue = ch - 0x30; // '0'
  20326. var powerValue = 0;
  20327. var powerValueSign = 1;
  20328. while ((ch = this.nextChar()) >= 0) {
  20329. if (0x30 <= ch && ch <= 0x39) { // '0' - '9'
  20330. var currentDigit = ch - 0x30; // '0'
  20331. if (eNotation) { // We are after an 'e' or 'E'
  20332. powerValue = powerValue * 10 + currentDigit;
  20333. } else {
  20334. if (divideBy !== 0) { // We are after a point
  20335. divideBy *= 10;
  20336. }
  20337. baseValue = baseValue * 10 + currentDigit;
  20338. }
  20339. } else if (ch === 0x2E) { // '.'
  20340. if (divideBy === 0) {
  20341. divideBy = 1;
  20342. } else {
  20343. // A number can have only one '.'
  20344. break;
  20345. }
  20346. } else if (ch === 0x2D) { // '-'
  20347. // ignore minus signs in the middle of numbers to match
  20348. // Adobe's behavior
  20349. warn('Badly formated number');
  20350. } else if (ch === 0x45 || ch === 0x65) { // 'E', 'e'
  20351. // 'E' can be either a scientific notation or the beginning of a new
  20352. // operator
  20353. ch = this.peekChar();
  20354. if (ch === 0x2B || ch === 0x2D) { // '+', '-'
  20355. powerValueSign = (ch === 0x2D) ? -1 : 1;
  20356. this.nextChar(); // Consume the sign character
  20357. } else if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  20358. // The 'E' must be the beginning of a new operator
  20359. break;
  20360. }
  20361. eNotation = true;
  20362. } else {
  20363. // the last character doesn't belong to us
  20364. break;
  20365. }
  20366. }
  20367. if (divideBy !== 0) {
  20368. baseValue /= divideBy;
  20369. }
  20370. if (eNotation) {
  20371. baseValue *= Math.pow(10, powerValueSign * powerValue);
  20372. }
  20373. return sign * baseValue;
  20374. },
  20375. getString: function Lexer_getString() {
  20376. var numParen = 1;
  20377. var done = false;
  20378. var strBuf = this.strBuf;
  20379. strBuf.length = 0;
  20380. var ch = this.nextChar();
  20381. while (true) {
  20382. var charBuffered = false;
  20383. switch (ch | 0) {
  20384. case -1:
  20385. warn('Unterminated string');
  20386. done = true;
  20387. break;
  20388. case 0x28: // '('
  20389. ++numParen;
  20390. strBuf.push('(');
  20391. break;
  20392. case 0x29: // ')'
  20393. if (--numParen === 0) {
  20394. this.nextChar(); // consume strings ')'
  20395. done = true;
  20396. } else {
  20397. strBuf.push(')');
  20398. }
  20399. break;
  20400. case 0x5C: // '\\'
  20401. ch = this.nextChar();
  20402. switch (ch) {
  20403. case -1:
  20404. warn('Unterminated string');
  20405. done = true;
  20406. break;
  20407. case 0x6E: // 'n'
  20408. strBuf.push('\n');
  20409. break;
  20410. case 0x72: // 'r'
  20411. strBuf.push('\r');
  20412. break;
  20413. case 0x74: // 't'
  20414. strBuf.push('\t');
  20415. break;
  20416. case 0x62: // 'b'
  20417. strBuf.push('\b');
  20418. break;
  20419. case 0x66: // 'f'
  20420. strBuf.push('\f');
  20421. break;
  20422. case 0x5C: // '\'
  20423. case 0x28: // '('
  20424. case 0x29: // ')'
  20425. strBuf.push(String.fromCharCode(ch));
  20426. break;
  20427. case 0x30: case 0x31: case 0x32: case 0x33: // '0'-'3'
  20428. case 0x34: case 0x35: case 0x36: case 0x37: // '4'-'7'
  20429. var x = ch & 0x0F;
  20430. ch = this.nextChar();
  20431. charBuffered = true;
  20432. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  20433. x = (x << 3) + (ch & 0x0F);
  20434. ch = this.nextChar();
  20435. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  20436. charBuffered = false;
  20437. x = (x << 3) + (ch & 0x0F);
  20438. }
  20439. }
  20440. strBuf.push(String.fromCharCode(x));
  20441. break;
  20442. case 0x0D: // CR
  20443. if (this.peekChar() === 0x0A) { // LF
  20444. this.nextChar();
  20445. }
  20446. break;
  20447. case 0x0A: // LF
  20448. break;
  20449. default:
  20450. strBuf.push(String.fromCharCode(ch));
  20451. break;
  20452. }
  20453. break;
  20454. default:
  20455. strBuf.push(String.fromCharCode(ch));
  20456. break;
  20457. }
  20458. if (done) {
  20459. break;
  20460. }
  20461. if (!charBuffered) {
  20462. ch = this.nextChar();
  20463. }
  20464. }
  20465. return strBuf.join('');
  20466. },
  20467. getName: function Lexer_getName() {
  20468. var ch, previousCh;
  20469. var strBuf = this.strBuf;
  20470. strBuf.length = 0;
  20471. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  20472. if (ch === 0x23) { // '#'
  20473. ch = this.nextChar();
  20474. if (specialChars[ch]) {
  20475. warn('Lexer_getName: ' +
  20476. 'NUMBER SIGN (#) should be followed by a hexadecimal number.');
  20477. strBuf.push('#');
  20478. break;
  20479. }
  20480. var x = toHexDigit(ch);
  20481. if (x !== -1) {
  20482. previousCh = ch;
  20483. ch = this.nextChar();
  20484. var x2 = toHexDigit(ch);
  20485. if (x2 === -1) {
  20486. warn('Lexer_getName: Illegal digit (' +
  20487. String.fromCharCode(ch) +') in hexadecimal number.');
  20488. strBuf.push('#', String.fromCharCode(previousCh));
  20489. if (specialChars[ch]) {
  20490. break;
  20491. }
  20492. strBuf.push(String.fromCharCode(ch));
  20493. continue;
  20494. }
  20495. strBuf.push(String.fromCharCode((x << 4) | x2));
  20496. } else {
  20497. strBuf.push('#', String.fromCharCode(ch));
  20498. }
  20499. } else {
  20500. strBuf.push(String.fromCharCode(ch));
  20501. }
  20502. }
  20503. if (strBuf.length > 127) {
  20504. warn('name token is longer than allowed by the spec: ' + strBuf.length);
  20505. }
  20506. return Name.get(strBuf.join(''));
  20507. },
  20508. getHexString: function Lexer_getHexString() {
  20509. var strBuf = this.strBuf;
  20510. strBuf.length = 0;
  20511. var ch = this.currentChar;
  20512. var isFirstHex = true;
  20513. var firstDigit;
  20514. var secondDigit;
  20515. while (true) {
  20516. if (ch < 0) {
  20517. warn('Unterminated hex string');
  20518. break;
  20519. } else if (ch === 0x3E) { // '>'
  20520. this.nextChar();
  20521. break;
  20522. } else if (specialChars[ch] === 1) {
  20523. ch = this.nextChar();
  20524. continue;
  20525. } else {
  20526. if (isFirstHex) {
  20527. firstDigit = toHexDigit(ch);
  20528. if (firstDigit === -1) {
  20529. warn('Ignoring invalid character "' + ch + '" in hex string');
  20530. ch = this.nextChar();
  20531. continue;
  20532. }
  20533. } else {
  20534. secondDigit = toHexDigit(ch);
  20535. if (secondDigit === -1) {
  20536. warn('Ignoring invalid character "' + ch + '" in hex string');
  20537. ch = this.nextChar();
  20538. continue;
  20539. }
  20540. strBuf.push(String.fromCharCode((firstDigit << 4) | secondDigit));
  20541. }
  20542. isFirstHex = !isFirstHex;
  20543. ch = this.nextChar();
  20544. }
  20545. }
  20546. return strBuf.join('');
  20547. },
  20548. getObj: function Lexer_getObj() {
  20549. // skip whitespace and comments
  20550. var comment = false;
  20551. var ch = this.currentChar;
  20552. while (true) {
  20553. if (ch < 0) {
  20554. return EOF;
  20555. }
  20556. if (comment) {
  20557. if (ch === 0x0A || ch === 0x0D) { // LF, CR
  20558. comment = false;
  20559. }
  20560. } else if (ch === 0x25) { // '%'
  20561. comment = true;
  20562. } else if (specialChars[ch] !== 1) {
  20563. break;
  20564. }
  20565. ch = this.nextChar();
  20566. }
  20567. // start reading token
  20568. switch (ch | 0) {
  20569. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  20570. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  20571. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  20572. return this.getNumber();
  20573. case 0x28: // '('
  20574. return this.getString();
  20575. case 0x2F: // '/'
  20576. return this.getName();
  20577. // array punctuation
  20578. case 0x5B: // '['
  20579. this.nextChar();
  20580. return Cmd.get('[');
  20581. case 0x5D: // ']'
  20582. this.nextChar();
  20583. return Cmd.get(']');
  20584. // hex string or dict punctuation
  20585. case 0x3C: // '<'
  20586. ch = this.nextChar();
  20587. if (ch === 0x3C) {
  20588. // dict punctuation
  20589. this.nextChar();
  20590. return Cmd.get('<<');
  20591. }
  20592. return this.getHexString();
  20593. // dict punctuation
  20594. case 0x3E: // '>'
  20595. ch = this.nextChar();
  20596. if (ch === 0x3E) {
  20597. this.nextChar();
  20598. return Cmd.get('>>');
  20599. }
  20600. return Cmd.get('>');
  20601. case 0x7B: // '{'
  20602. this.nextChar();
  20603. return Cmd.get('{');
  20604. case 0x7D: // '}'
  20605. this.nextChar();
  20606. return Cmd.get('}');
  20607. case 0x29: // ')'
  20608. error('Illegal character: ' + ch);
  20609. break;
  20610. }
  20611. // command
  20612. var str = String.fromCharCode(ch);
  20613. var knownCommands = this.knownCommands;
  20614. var knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  20615. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  20616. // stop if known command is found and next character does not make
  20617. // the str a command
  20618. var possibleCommand = str + String.fromCharCode(ch);
  20619. if (knownCommandFound && knownCommands[possibleCommand] === undefined) {
  20620. break;
  20621. }
  20622. if (str.length === 128) {
  20623. error('Command token too long: ' + str.length);
  20624. }
  20625. str = possibleCommand;
  20626. knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  20627. }
  20628. if (str === 'true') {
  20629. return true;
  20630. }
  20631. if (str === 'false') {
  20632. return false;
  20633. }
  20634. if (str === 'null') {
  20635. return null;
  20636. }
  20637. return Cmd.get(str);
  20638. },
  20639. skipToNextLine: function Lexer_skipToNextLine() {
  20640. var ch = this.currentChar;
  20641. while (ch >= 0) {
  20642. if (ch === 0x0D) { // CR
  20643. ch = this.nextChar();
  20644. if (ch === 0x0A) { // LF
  20645. this.nextChar();
  20646. }
  20647. break;
  20648. } else if (ch === 0x0A) { // LF
  20649. this.nextChar();
  20650. break;
  20651. }
  20652. ch = this.nextChar();
  20653. }
  20654. }
  20655. };
  20656. return Lexer;
  20657. })();
  20658. var Linearization = {
  20659. create: function LinearizationCreate(stream) {
  20660. function getInt(name, allowZeroValue) {
  20661. var obj = linDict.get(name);
  20662. if (isInt(obj) && (allowZeroValue ? obj >= 0 : obj > 0)) {
  20663. return obj;
  20664. }
  20665. throw new Error('The "' + name + '" parameter in the linearization ' +
  20666. 'dictionary is invalid.');
  20667. }
  20668. function getHints() {
  20669. var hints = linDict.get('H'), hintsLength, item;
  20670. if (isArray(hints) &&
  20671. ((hintsLength = hints.length) === 2 || hintsLength === 4)) {
  20672. for (var index = 0; index < hintsLength; index++) {
  20673. if (!(isInt(item = hints[index]) && item > 0)) {
  20674. throw new Error('Hint (' + index +
  20675. ') in the linearization dictionary is invalid.');
  20676. }
  20677. }
  20678. return hints;
  20679. }
  20680. throw new Error('Hint array in the linearization dictionary is invalid.');
  20681. }
  20682. var parser = new Parser(new Lexer(stream), false, null);
  20683. var obj1 = parser.getObj();
  20684. var obj2 = parser.getObj();
  20685. var obj3 = parser.getObj();
  20686. var linDict = parser.getObj();
  20687. var obj, length;
  20688. if (!(isInt(obj1) && isInt(obj2) && isCmd(obj3, 'obj') && isDict(linDict) &&
  20689. isNum(obj = linDict.get('Linearized')) && obj > 0)) {
  20690. return null; // No valid linearization dictionary found.
  20691. } else if ((length = getInt('L')) !== stream.length) {
  20692. throw new Error('The "L" parameter in the linearization dictionary ' +
  20693. 'does not equal the stream length.');
  20694. }
  20695. return {
  20696. length: length,
  20697. hints: getHints(),
  20698. objectNumberFirst: getInt('O'),
  20699. endFirst: getInt('E'),
  20700. numPages: getInt('N'),
  20701. mainXRefEntriesOffset: getInt('T'),
  20702. pageFirst: (linDict.has('P') ? getInt('P', true) : 0)
  20703. };
  20704. }
  20705. };
  20706. exports.EOF = EOF;
  20707. exports.Lexer = Lexer;
  20708. exports.Linearization = Linearization;
  20709. exports.Parser = Parser;
  20710. exports.isEOF = isEOF;
  20711. // TODO refactor to remove dependency on stream.js
  20712. coreStream._setCoreParser(exports);
  20713. }));
  20714. (function (root, factory) {
  20715. {
  20716. factory((root.pdfjsCoreCMap = {}), root.pdfjsSharedUtil,
  20717. root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreParser);
  20718. }
  20719. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreParser) {
  20720. var Util = sharedUtil.Util;
  20721. var assert = sharedUtil.assert;
  20722. var error = sharedUtil.error;
  20723. var isInt = sharedUtil.isInt;
  20724. var isString = sharedUtil.isString;
  20725. var warn = sharedUtil.warn;
  20726. var isName = corePrimitives.isName;
  20727. var isCmd = corePrimitives.isCmd;
  20728. var isStream = corePrimitives.isStream;
  20729. var StringStream = coreStream.StringStream;
  20730. var Lexer = coreParser.Lexer;
  20731. var isEOF = coreParser.isEOF;
  20732. var BUILT_IN_CMAPS = [
  20733. // << Start unicode maps.
  20734. 'Adobe-GB1-UCS2',
  20735. 'Adobe-CNS1-UCS2',
  20736. 'Adobe-Japan1-UCS2',
  20737. 'Adobe-Korea1-UCS2',
  20738. // >> End unicode maps.
  20739. '78-EUC-H',
  20740. '78-EUC-V',
  20741. '78-H',
  20742. '78-RKSJ-H',
  20743. '78-RKSJ-V',
  20744. '78-V',
  20745. '78ms-RKSJ-H',
  20746. '78ms-RKSJ-V',
  20747. '83pv-RKSJ-H',
  20748. '90ms-RKSJ-H',
  20749. '90ms-RKSJ-V',
  20750. '90msp-RKSJ-H',
  20751. '90msp-RKSJ-V',
  20752. '90pv-RKSJ-H',
  20753. '90pv-RKSJ-V',
  20754. 'Add-H',
  20755. 'Add-RKSJ-H',
  20756. 'Add-RKSJ-V',
  20757. 'Add-V',
  20758. 'Adobe-CNS1-0',
  20759. 'Adobe-CNS1-1',
  20760. 'Adobe-CNS1-2',
  20761. 'Adobe-CNS1-3',
  20762. 'Adobe-CNS1-4',
  20763. 'Adobe-CNS1-5',
  20764. 'Adobe-CNS1-6',
  20765. 'Adobe-GB1-0',
  20766. 'Adobe-GB1-1',
  20767. 'Adobe-GB1-2',
  20768. 'Adobe-GB1-3',
  20769. 'Adobe-GB1-4',
  20770. 'Adobe-GB1-5',
  20771. 'Adobe-Japan1-0',
  20772. 'Adobe-Japan1-1',
  20773. 'Adobe-Japan1-2',
  20774. 'Adobe-Japan1-3',
  20775. 'Adobe-Japan1-4',
  20776. 'Adobe-Japan1-5',
  20777. 'Adobe-Japan1-6',
  20778. 'Adobe-Korea1-0',
  20779. 'Adobe-Korea1-1',
  20780. 'Adobe-Korea1-2',
  20781. 'B5-H',
  20782. 'B5-V',
  20783. 'B5pc-H',
  20784. 'B5pc-V',
  20785. 'CNS-EUC-H',
  20786. 'CNS-EUC-V',
  20787. 'CNS1-H',
  20788. 'CNS1-V',
  20789. 'CNS2-H',
  20790. 'CNS2-V',
  20791. 'ETHK-B5-H',
  20792. 'ETHK-B5-V',
  20793. 'ETen-B5-H',
  20794. 'ETen-B5-V',
  20795. 'ETenms-B5-H',
  20796. 'ETenms-B5-V',
  20797. 'EUC-H',
  20798. 'EUC-V',
  20799. 'Ext-H',
  20800. 'Ext-RKSJ-H',
  20801. 'Ext-RKSJ-V',
  20802. 'Ext-V',
  20803. 'GB-EUC-H',
  20804. 'GB-EUC-V',
  20805. 'GB-H',
  20806. 'GB-V',
  20807. 'GBK-EUC-H',
  20808. 'GBK-EUC-V',
  20809. 'GBK2K-H',
  20810. 'GBK2K-V',
  20811. 'GBKp-EUC-H',
  20812. 'GBKp-EUC-V',
  20813. 'GBT-EUC-H',
  20814. 'GBT-EUC-V',
  20815. 'GBT-H',
  20816. 'GBT-V',
  20817. 'GBTpc-EUC-H',
  20818. 'GBTpc-EUC-V',
  20819. 'GBpc-EUC-H',
  20820. 'GBpc-EUC-V',
  20821. 'H',
  20822. 'HKdla-B5-H',
  20823. 'HKdla-B5-V',
  20824. 'HKdlb-B5-H',
  20825. 'HKdlb-B5-V',
  20826. 'HKgccs-B5-H',
  20827. 'HKgccs-B5-V',
  20828. 'HKm314-B5-H',
  20829. 'HKm314-B5-V',
  20830. 'HKm471-B5-H',
  20831. 'HKm471-B5-V',
  20832. 'HKscs-B5-H',
  20833. 'HKscs-B5-V',
  20834. 'Hankaku',
  20835. 'Hiragana',
  20836. 'KSC-EUC-H',
  20837. 'KSC-EUC-V',
  20838. 'KSC-H',
  20839. 'KSC-Johab-H',
  20840. 'KSC-Johab-V',
  20841. 'KSC-V',
  20842. 'KSCms-UHC-H',
  20843. 'KSCms-UHC-HW-H',
  20844. 'KSCms-UHC-HW-V',
  20845. 'KSCms-UHC-V',
  20846. 'KSCpc-EUC-H',
  20847. 'KSCpc-EUC-V',
  20848. 'Katakana',
  20849. 'NWP-H',
  20850. 'NWP-V',
  20851. 'RKSJ-H',
  20852. 'RKSJ-V',
  20853. 'Roman',
  20854. 'UniCNS-UCS2-H',
  20855. 'UniCNS-UCS2-V',
  20856. 'UniCNS-UTF16-H',
  20857. 'UniCNS-UTF16-V',
  20858. 'UniCNS-UTF32-H',
  20859. 'UniCNS-UTF32-V',
  20860. 'UniCNS-UTF8-H',
  20861. 'UniCNS-UTF8-V',
  20862. 'UniGB-UCS2-H',
  20863. 'UniGB-UCS2-V',
  20864. 'UniGB-UTF16-H',
  20865. 'UniGB-UTF16-V',
  20866. 'UniGB-UTF32-H',
  20867. 'UniGB-UTF32-V',
  20868. 'UniGB-UTF8-H',
  20869. 'UniGB-UTF8-V',
  20870. 'UniJIS-UCS2-H',
  20871. 'UniJIS-UCS2-HW-H',
  20872. 'UniJIS-UCS2-HW-V',
  20873. 'UniJIS-UCS2-V',
  20874. 'UniJIS-UTF16-H',
  20875. 'UniJIS-UTF16-V',
  20876. 'UniJIS-UTF32-H',
  20877. 'UniJIS-UTF32-V',
  20878. 'UniJIS-UTF8-H',
  20879. 'UniJIS-UTF8-V',
  20880. 'UniJIS2004-UTF16-H',
  20881. 'UniJIS2004-UTF16-V',
  20882. 'UniJIS2004-UTF32-H',
  20883. 'UniJIS2004-UTF32-V',
  20884. 'UniJIS2004-UTF8-H',
  20885. 'UniJIS2004-UTF8-V',
  20886. 'UniJISPro-UCS2-HW-V',
  20887. 'UniJISPro-UCS2-V',
  20888. 'UniJISPro-UTF8-V',
  20889. 'UniJISX0213-UTF32-H',
  20890. 'UniJISX0213-UTF32-V',
  20891. 'UniJISX02132004-UTF32-H',
  20892. 'UniJISX02132004-UTF32-V',
  20893. 'UniKS-UCS2-H',
  20894. 'UniKS-UCS2-V',
  20895. 'UniKS-UTF16-H',
  20896. 'UniKS-UTF16-V',
  20897. 'UniKS-UTF32-H',
  20898. 'UniKS-UTF32-V',
  20899. 'UniKS-UTF8-H',
  20900. 'UniKS-UTF8-V',
  20901. 'V',
  20902. 'WP-Symbol'];
  20903. // CMap, not to be confused with TrueType's cmap.
  20904. var CMap = (function CMapClosure() {
  20905. function CMap(builtInCMap) {
  20906. // Codespace ranges are stored as follows:
  20907. // [[1BytePairs], [2BytePairs], [3BytePairs], [4BytePairs]]
  20908. // where nBytePairs are ranges e.g. [low1, high1, low2, high2, ...]
  20909. this.codespaceRanges = [[], [], [], []];
  20910. this.numCodespaceRanges = 0;
  20911. // Map entries have one of two forms.
  20912. // - cid chars are 16-bit unsigned integers, stored as integers.
  20913. // - bf chars are variable-length byte sequences, stored as strings, with
  20914. // one byte per character.
  20915. this._map = [];
  20916. this.name = '';
  20917. this.vertical = false;
  20918. this.useCMap = null;
  20919. this.builtInCMap = builtInCMap;
  20920. }
  20921. CMap.prototype = {
  20922. addCodespaceRange: function(n, low, high) {
  20923. this.codespaceRanges[n - 1].push(low, high);
  20924. this.numCodespaceRanges++;
  20925. },
  20926. mapCidRange: function(low, high, dstLow) {
  20927. while (low <= high) {
  20928. this._map[low++] = dstLow++;
  20929. }
  20930. },
  20931. mapBfRange: function(low, high, dstLow) {
  20932. var lastByte = dstLow.length - 1;
  20933. while (low <= high) {
  20934. this._map[low++] = dstLow;
  20935. // Only the last byte has to be incremented.
  20936. dstLow = dstLow.substr(0, lastByte) +
  20937. String.fromCharCode(dstLow.charCodeAt(lastByte) + 1);
  20938. }
  20939. },
  20940. mapBfRangeToArray: function(low, high, array) {
  20941. var i = 0, ii = array.length;
  20942. while (low <= high && i < ii) {
  20943. this._map[low] = array[i++];
  20944. ++low;
  20945. }
  20946. },
  20947. // This is used for both bf and cid chars.
  20948. mapOne: function(src, dst) {
  20949. this._map[src] = dst;
  20950. },
  20951. lookup: function(code) {
  20952. return this._map[code];
  20953. },
  20954. contains: function(code) {
  20955. return this._map[code] !== undefined;
  20956. },
  20957. forEach: function(callback) {
  20958. // Most maps have fewer than 65536 entries, and for those we use normal
  20959. // array iteration. But really sparse tables are possible -- e.g. with
  20960. // indices in the *billions*. For such tables we use for..in, which isn't
  20961. // ideal because it stringifies the indices for all present elements, but
  20962. // it does avoid iterating over every undefined entry.
  20963. var map = this._map;
  20964. var length = map.length;
  20965. var i;
  20966. if (length <= 0x10000) {
  20967. for (i = 0; i < length; i++) {
  20968. if (map[i] !== undefined) {
  20969. callback(i, map[i]);
  20970. }
  20971. }
  20972. } else {
  20973. for (i in this._map) {
  20974. callback(i, map[i]);
  20975. }
  20976. }
  20977. },
  20978. charCodeOf: function(value) {
  20979. return this._map.indexOf(value);
  20980. },
  20981. getMap: function() {
  20982. return this._map;
  20983. },
  20984. readCharCode: function(str, offset, out) {
  20985. var c = 0;
  20986. var codespaceRanges = this.codespaceRanges;
  20987. var codespaceRangesLen = this.codespaceRanges.length;
  20988. // 9.7.6.2 CMap Mapping
  20989. // The code length is at most 4.
  20990. for (var n = 0; n < codespaceRangesLen; n++) {
  20991. c = ((c << 8) | str.charCodeAt(offset + n)) >>> 0;
  20992. // Check each codespace range to see if it falls within.
  20993. var codespaceRange = codespaceRanges[n];
  20994. for (var k = 0, kk = codespaceRange.length; k < kk;) {
  20995. var low = codespaceRange[k++];
  20996. var high = codespaceRange[k++];
  20997. if (c >= low && c <= high) {
  20998. out.charcode = c;
  20999. out.length = n + 1;
  21000. return;
  21001. }
  21002. }
  21003. }
  21004. out.charcode = 0;
  21005. out.length = 1;
  21006. },
  21007. get length() {
  21008. return this._map.length;
  21009. },
  21010. get isIdentityCMap() {
  21011. if (!(this.name === 'Identity-H' || this.name === 'Identity-V')) {
  21012. return false;
  21013. }
  21014. if (this._map.length !== 0x10000) {
  21015. return false;
  21016. }
  21017. for (var i = 0; i < 0x10000; i++) {
  21018. if (this._map[i] !== i) {
  21019. return false;
  21020. }
  21021. }
  21022. return true;
  21023. }
  21024. };
  21025. return CMap;
  21026. })();
  21027. // A special case of CMap, where the _map array implicitly has a length of
  21028. // 65536 and each element is equal to its index.
  21029. var IdentityCMap = (function IdentityCMapClosure() {
  21030. function IdentityCMap(vertical, n) {
  21031. CMap.call(this);
  21032. this.vertical = vertical;
  21033. this.addCodespaceRange(n, 0, 0xffff);
  21034. }
  21035. Util.inherit(IdentityCMap, CMap, {});
  21036. IdentityCMap.prototype = {
  21037. addCodespaceRange: CMap.prototype.addCodespaceRange,
  21038. mapCidRange: function(low, high, dstLow) {
  21039. error('should not call mapCidRange');
  21040. },
  21041. mapBfRange: function(low, high, dstLow) {
  21042. error('should not call mapBfRange');
  21043. },
  21044. mapBfRangeToArray: function(low, high, array) {
  21045. error('should not call mapBfRangeToArray');
  21046. },
  21047. mapOne: function(src, dst) {
  21048. error('should not call mapCidOne');
  21049. },
  21050. lookup: function(code) {
  21051. return (isInt(code) && code <= 0xffff) ? code : undefined;
  21052. },
  21053. contains: function(code) {
  21054. return isInt(code) && code <= 0xffff;
  21055. },
  21056. forEach: function(callback) {
  21057. for (var i = 0; i <= 0xffff; i++) {
  21058. callback(i, i);
  21059. }
  21060. },
  21061. charCodeOf: function(value) {
  21062. return (isInt(value) && value <= 0xffff) ? value : -1;
  21063. },
  21064. getMap: function() {
  21065. // Sometimes identity maps must be instantiated, but it's rare.
  21066. var map = new Array(0x10000);
  21067. for (var i = 0; i <= 0xffff; i++) {
  21068. map[i] = i;
  21069. }
  21070. return map;
  21071. },
  21072. readCharCode: CMap.prototype.readCharCode,
  21073. get length() {
  21074. return 0x10000;
  21075. },
  21076. get isIdentityCMap() {
  21077. error('should not access .isIdentityCMap');
  21078. }
  21079. };
  21080. return IdentityCMap;
  21081. })();
  21082. var BinaryCMapReader = (function BinaryCMapReaderClosure() {
  21083. function fetchBinaryData(url) {
  21084. var nonBinaryRequest = PDFJS.disableWorker;
  21085. var request = new XMLHttpRequest();
  21086. request.open('GET', url, false);
  21087. if (!nonBinaryRequest) {
  21088. try {
  21089. request.responseType = 'arraybuffer';
  21090. nonBinaryRequest = request.responseType !== 'arraybuffer';
  21091. } catch (e) {
  21092. nonBinaryRequest = true;
  21093. }
  21094. }
  21095. if (nonBinaryRequest && request.overrideMimeType) {
  21096. request.overrideMimeType('text/plain; charset=x-user-defined');
  21097. }
  21098. request.send(null);
  21099. if (nonBinaryRequest ? !request.responseText : !request.response) {
  21100. error('Unable to get binary cMap at: ' + url);
  21101. }
  21102. if (nonBinaryRequest) {
  21103. var data = Array.prototype.map.call(request.responseText, function (ch) {
  21104. return ch.charCodeAt(0) & 255;
  21105. });
  21106. return new Uint8Array(data);
  21107. }
  21108. return new Uint8Array(request.response);
  21109. }
  21110. function hexToInt(a, size) {
  21111. var n = 0;
  21112. for (var i = 0; i <= size; i++) {
  21113. n = (n << 8) | a[i];
  21114. }
  21115. return n >>> 0;
  21116. }
  21117. function hexToStr(a, size) {
  21118. // This code is hot. Special-case some common values to avoid creating an
  21119. // object with subarray().
  21120. if (size === 1) {
  21121. return String.fromCharCode(a[0], a[1]);
  21122. }
  21123. if (size === 3) {
  21124. return String.fromCharCode(a[0], a[1], a[2], a[3]);
  21125. }
  21126. return String.fromCharCode.apply(null, a.subarray(0, size + 1));
  21127. }
  21128. function addHex(a, b, size) {
  21129. var c = 0;
  21130. for (var i = size; i >= 0; i--) {
  21131. c += a[i] + b[i];
  21132. a[i] = c & 255;
  21133. c >>= 8;
  21134. }
  21135. }
  21136. function incHex(a, size) {
  21137. var c = 1;
  21138. for (var i = size; i >= 0 && c > 0; i--) {
  21139. c += a[i];
  21140. a[i] = c & 255;
  21141. c >>= 8;
  21142. }
  21143. }
  21144. var MAX_NUM_SIZE = 16;
  21145. var MAX_ENCODED_NUM_SIZE = 19; // ceil(MAX_NUM_SIZE * 7 / 8)
  21146. function BinaryCMapStream(data) {
  21147. this.buffer = data;
  21148. this.pos = 0;
  21149. this.end = data.length;
  21150. this.tmpBuf = new Uint8Array(MAX_ENCODED_NUM_SIZE);
  21151. }
  21152. BinaryCMapStream.prototype = {
  21153. readByte: function () {
  21154. if (this.pos >= this.end) {
  21155. return -1;
  21156. }
  21157. return this.buffer[this.pos++];
  21158. },
  21159. readNumber: function () {
  21160. var n = 0;
  21161. var last;
  21162. do {
  21163. var b = this.readByte();
  21164. if (b < 0) {
  21165. error('unexpected EOF in bcmap');
  21166. }
  21167. last = !(b & 0x80);
  21168. n = (n << 7) | (b & 0x7F);
  21169. } while (!last);
  21170. return n;
  21171. },
  21172. readSigned: function () {
  21173. var n = this.readNumber();
  21174. return (n & 1) ? ~(n >>> 1) : n >>> 1;
  21175. },
  21176. readHex: function (num, size) {
  21177. num.set(this.buffer.subarray(this.pos,
  21178. this.pos + size + 1));
  21179. this.pos += size + 1;
  21180. },
  21181. readHexNumber: function (num, size) {
  21182. var last;
  21183. var stack = this.tmpBuf, sp = 0;
  21184. do {
  21185. var b = this.readByte();
  21186. if (b < 0) {
  21187. error('unexpected EOF in bcmap');
  21188. }
  21189. last = !(b & 0x80);
  21190. stack[sp++] = b & 0x7F;
  21191. } while (!last);
  21192. var i = size, buffer = 0, bufferSize = 0;
  21193. while (i >= 0) {
  21194. while (bufferSize < 8 && stack.length > 0) {
  21195. buffer = (stack[--sp] << bufferSize) | buffer;
  21196. bufferSize += 7;
  21197. }
  21198. num[i] = buffer & 255;
  21199. i--;
  21200. buffer >>= 8;
  21201. bufferSize -= 8;
  21202. }
  21203. },
  21204. readHexSigned: function (num, size) {
  21205. this.readHexNumber(num, size);
  21206. var sign = num[size] & 1 ? 255 : 0;
  21207. var c = 0;
  21208. for (var i = 0; i <= size; i++) {
  21209. c = ((c & 1) << 8) | num[i];
  21210. num[i] = (c >> 1) ^ sign;
  21211. }
  21212. },
  21213. readString: function () {
  21214. var len = this.readNumber();
  21215. var s = '';
  21216. for (var i = 0; i < len; i++) {
  21217. s += String.fromCharCode(this.readNumber());
  21218. }
  21219. return s;
  21220. }
  21221. };
  21222. function processBinaryCMap(url, cMap, extend) {
  21223. var data = fetchBinaryData(url);
  21224. var stream = new BinaryCMapStream(data);
  21225. var header = stream.readByte();
  21226. cMap.vertical = !!(header & 1);
  21227. var useCMap = null;
  21228. var start = new Uint8Array(MAX_NUM_SIZE);
  21229. var end = new Uint8Array(MAX_NUM_SIZE);
  21230. var char = new Uint8Array(MAX_NUM_SIZE);
  21231. var charCode = new Uint8Array(MAX_NUM_SIZE);
  21232. var tmp = new Uint8Array(MAX_NUM_SIZE);
  21233. var code;
  21234. var b;
  21235. while ((b = stream.readByte()) >= 0) {
  21236. var type = b >> 5;
  21237. if (type === 7) { // metadata, e.g. comment or usecmap
  21238. switch (b & 0x1F) {
  21239. case 0:
  21240. stream.readString(); // skipping comment
  21241. break;
  21242. case 1:
  21243. useCMap = stream.readString();
  21244. break;
  21245. }
  21246. continue;
  21247. }
  21248. var sequence = !!(b & 0x10);
  21249. var dataSize = b & 15;
  21250. assert(dataSize + 1 <= MAX_NUM_SIZE);
  21251. var ucs2DataSize = 1;
  21252. var subitemsCount = stream.readNumber();
  21253. var i;
  21254. switch (type) {
  21255. case 0: // codespacerange
  21256. stream.readHex(start, dataSize);
  21257. stream.readHexNumber(end, dataSize);
  21258. addHex(end, start, dataSize);
  21259. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  21260. hexToInt(end, dataSize));
  21261. for (i = 1; i < subitemsCount; i++) {
  21262. incHex(end, dataSize);
  21263. stream.readHexNumber(start, dataSize);
  21264. addHex(start, end, dataSize);
  21265. stream.readHexNumber(end, dataSize);
  21266. addHex(end, start, dataSize);
  21267. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  21268. hexToInt(end, dataSize));
  21269. }
  21270. break;
  21271. case 1: // notdefrange
  21272. stream.readHex(start, dataSize);
  21273. stream.readHexNumber(end, dataSize);
  21274. addHex(end, start, dataSize);
  21275. code = stream.readNumber();
  21276. // undefined range, skipping
  21277. for (i = 1; i < subitemsCount; i++) {
  21278. incHex(end, dataSize);
  21279. stream.readHexNumber(start, dataSize);
  21280. addHex(start, end, dataSize);
  21281. stream.readHexNumber(end, dataSize);
  21282. addHex(end, start, dataSize);
  21283. code = stream.readNumber();
  21284. // nop
  21285. }
  21286. break;
  21287. case 2: // cidchar
  21288. stream.readHex(char, dataSize);
  21289. code = stream.readNumber();
  21290. cMap.mapOne(hexToInt(char, dataSize), code);
  21291. for (i = 1; i < subitemsCount; i++) {
  21292. incHex(char, dataSize);
  21293. if (!sequence) {
  21294. stream.readHexNumber(tmp, dataSize);
  21295. addHex(char, tmp, dataSize);
  21296. }
  21297. code = stream.readSigned() + (code + 1);
  21298. cMap.mapOne(hexToInt(char, dataSize), code);
  21299. }
  21300. break;
  21301. case 3: // cidrange
  21302. stream.readHex(start, dataSize);
  21303. stream.readHexNumber(end, dataSize);
  21304. addHex(end, start, dataSize);
  21305. code = stream.readNumber();
  21306. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  21307. code);
  21308. for (i = 1; i < subitemsCount; i++) {
  21309. incHex(end, dataSize);
  21310. if (!sequence) {
  21311. stream.readHexNumber(start, dataSize);
  21312. addHex(start, end, dataSize);
  21313. } else {
  21314. start.set(end);
  21315. }
  21316. stream.readHexNumber(end, dataSize);
  21317. addHex(end, start, dataSize);
  21318. code = stream.readNumber();
  21319. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  21320. code);
  21321. }
  21322. break;
  21323. case 4: // bfchar
  21324. stream.readHex(char, ucs2DataSize);
  21325. stream.readHex(charCode, dataSize);
  21326. cMap.mapOne(hexToInt(char, ucs2DataSize),
  21327. hexToStr(charCode, dataSize));
  21328. for (i = 1; i < subitemsCount; i++) {
  21329. incHex(char, ucs2DataSize);
  21330. if (!sequence) {
  21331. stream.readHexNumber(tmp, ucs2DataSize);
  21332. addHex(char, tmp, ucs2DataSize);
  21333. }
  21334. incHex(charCode, dataSize);
  21335. stream.readHexSigned(tmp, dataSize);
  21336. addHex(charCode, tmp, dataSize);
  21337. cMap.mapOne(hexToInt(char, ucs2DataSize),
  21338. hexToStr(charCode, dataSize));
  21339. }
  21340. break;
  21341. case 5: // bfrange
  21342. stream.readHex(start, ucs2DataSize);
  21343. stream.readHexNumber(end, ucs2DataSize);
  21344. addHex(end, start, ucs2DataSize);
  21345. stream.readHex(charCode, dataSize);
  21346. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  21347. hexToInt(end, ucs2DataSize),
  21348. hexToStr(charCode, dataSize));
  21349. for (i = 1; i < subitemsCount; i++) {
  21350. incHex(end, ucs2DataSize);
  21351. if (!sequence) {
  21352. stream.readHexNumber(start, ucs2DataSize);
  21353. addHex(start, end, ucs2DataSize);
  21354. } else {
  21355. start.set(end);
  21356. }
  21357. stream.readHexNumber(end, ucs2DataSize);
  21358. addHex(end, start, ucs2DataSize);
  21359. stream.readHex(charCode, dataSize);
  21360. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  21361. hexToInt(end, ucs2DataSize),
  21362. hexToStr(charCode, dataSize));
  21363. }
  21364. break;
  21365. default:
  21366. error('Unknown type: ' + type);
  21367. break;
  21368. }
  21369. }
  21370. if (useCMap) {
  21371. extend(useCMap);
  21372. }
  21373. return cMap;
  21374. }
  21375. function BinaryCMapReader() {}
  21376. BinaryCMapReader.prototype = {
  21377. read: processBinaryCMap
  21378. };
  21379. return BinaryCMapReader;
  21380. })();
  21381. var CMapFactory = (function CMapFactoryClosure() {
  21382. function strToInt(str) {
  21383. var a = 0;
  21384. for (var i = 0; i < str.length; i++) {
  21385. a = (a << 8) | str.charCodeAt(i);
  21386. }
  21387. return a >>> 0;
  21388. }
  21389. function expectString(obj) {
  21390. if (!isString(obj)) {
  21391. error('Malformed CMap: expected string.');
  21392. }
  21393. }
  21394. function expectInt(obj) {
  21395. if (!isInt(obj)) {
  21396. error('Malformed CMap: expected int.');
  21397. }
  21398. }
  21399. function parseBfChar(cMap, lexer) {
  21400. while (true) {
  21401. var obj = lexer.getObj();
  21402. if (isEOF(obj)) {
  21403. break;
  21404. }
  21405. if (isCmd(obj, 'endbfchar')) {
  21406. return;
  21407. }
  21408. expectString(obj);
  21409. var src = strToInt(obj);
  21410. obj = lexer.getObj();
  21411. // TODO are /dstName used?
  21412. expectString(obj);
  21413. var dst = obj;
  21414. cMap.mapOne(src, dst);
  21415. }
  21416. }
  21417. function parseBfRange(cMap, lexer) {
  21418. while (true) {
  21419. var obj = lexer.getObj();
  21420. if (isEOF(obj)) {
  21421. break;
  21422. }
  21423. if (isCmd(obj, 'endbfrange')) {
  21424. return;
  21425. }
  21426. expectString(obj);
  21427. var low = strToInt(obj);
  21428. obj = lexer.getObj();
  21429. expectString(obj);
  21430. var high = strToInt(obj);
  21431. obj = lexer.getObj();
  21432. if (isInt(obj) || isString(obj)) {
  21433. var dstLow = isInt(obj) ? String.fromCharCode(obj) : obj;
  21434. cMap.mapBfRange(low, high, dstLow);
  21435. } else if (isCmd(obj, '[')) {
  21436. obj = lexer.getObj();
  21437. var array = [];
  21438. while (!isCmd(obj, ']') && !isEOF(obj)) {
  21439. array.push(obj);
  21440. obj = lexer.getObj();
  21441. }
  21442. cMap.mapBfRangeToArray(low, high, array);
  21443. } else {
  21444. break;
  21445. }
  21446. }
  21447. error('Invalid bf range.');
  21448. }
  21449. function parseCidChar(cMap, lexer) {
  21450. while (true) {
  21451. var obj = lexer.getObj();
  21452. if (isEOF(obj)) {
  21453. break;
  21454. }
  21455. if (isCmd(obj, 'endcidchar')) {
  21456. return;
  21457. }
  21458. expectString(obj);
  21459. var src = strToInt(obj);
  21460. obj = lexer.getObj();
  21461. expectInt(obj);
  21462. var dst = obj;
  21463. cMap.mapOne(src, dst);
  21464. }
  21465. }
  21466. function parseCidRange(cMap, lexer) {
  21467. while (true) {
  21468. var obj = lexer.getObj();
  21469. if (isEOF(obj)) {
  21470. break;
  21471. }
  21472. if (isCmd(obj, 'endcidrange')) {
  21473. return;
  21474. }
  21475. expectString(obj);
  21476. var low = strToInt(obj);
  21477. obj = lexer.getObj();
  21478. expectString(obj);
  21479. var high = strToInt(obj);
  21480. obj = lexer.getObj();
  21481. expectInt(obj);
  21482. var dstLow = obj;
  21483. cMap.mapCidRange(low, high, dstLow);
  21484. }
  21485. }
  21486. function parseCodespaceRange(cMap, lexer) {
  21487. while (true) {
  21488. var obj = lexer.getObj();
  21489. if (isEOF(obj)) {
  21490. break;
  21491. }
  21492. if (isCmd(obj, 'endcodespacerange')) {
  21493. return;
  21494. }
  21495. if (!isString(obj)) {
  21496. break;
  21497. }
  21498. var low = strToInt(obj);
  21499. obj = lexer.getObj();
  21500. if (!isString(obj)) {
  21501. break;
  21502. }
  21503. var high = strToInt(obj);
  21504. cMap.addCodespaceRange(obj.length, low, high);
  21505. }
  21506. error('Invalid codespace range.');
  21507. }
  21508. function parseWMode(cMap, lexer) {
  21509. var obj = lexer.getObj();
  21510. if (isInt(obj)) {
  21511. cMap.vertical = !!obj;
  21512. }
  21513. }
  21514. function parseCMapName(cMap, lexer) {
  21515. var obj = lexer.getObj();
  21516. if (isName(obj) && isString(obj.name)) {
  21517. cMap.name = obj.name;
  21518. }
  21519. }
  21520. function parseCMap(cMap, lexer, builtInCMapParams, useCMap) {
  21521. var previous;
  21522. var embededUseCMap;
  21523. objLoop: while (true) {
  21524. var obj = lexer.getObj();
  21525. if (isEOF(obj)) {
  21526. break;
  21527. } else if (isName(obj)) {
  21528. if (obj.name === 'WMode') {
  21529. parseWMode(cMap, lexer);
  21530. } else if (obj.name === 'CMapName') {
  21531. parseCMapName(cMap, lexer);
  21532. }
  21533. previous = obj;
  21534. } else if (isCmd(obj)) {
  21535. switch (obj.cmd) {
  21536. case 'endcmap':
  21537. break objLoop;
  21538. case 'usecmap':
  21539. if (isName(previous)) {
  21540. embededUseCMap = previous.name;
  21541. }
  21542. break;
  21543. case 'begincodespacerange':
  21544. parseCodespaceRange(cMap, lexer);
  21545. break;
  21546. case 'beginbfchar':
  21547. parseBfChar(cMap, lexer);
  21548. break;
  21549. case 'begincidchar':
  21550. parseCidChar(cMap, lexer);
  21551. break;
  21552. case 'beginbfrange':
  21553. parseBfRange(cMap, lexer);
  21554. break;
  21555. case 'begincidrange':
  21556. parseCidRange(cMap, lexer);
  21557. break;
  21558. }
  21559. }
  21560. }
  21561. if (!useCMap && embededUseCMap) {
  21562. // Load the usecmap definition from the file only if there wasn't one
  21563. // specified.
  21564. useCMap = embededUseCMap;
  21565. }
  21566. if (useCMap) {
  21567. extendCMap(cMap, builtInCMapParams, useCMap);
  21568. }
  21569. }
  21570. function extendCMap(cMap, builtInCMapParams, useCMap) {
  21571. cMap.useCMap = createBuiltInCMap(useCMap, builtInCMapParams);
  21572. // If there aren't any code space ranges defined clone all the parent ones
  21573. // into this cMap.
  21574. if (cMap.numCodespaceRanges === 0) {
  21575. var useCodespaceRanges = cMap.useCMap.codespaceRanges;
  21576. for (var i = 0; i < useCodespaceRanges.length; i++) {
  21577. cMap.codespaceRanges[i] = useCodespaceRanges[i].slice();
  21578. }
  21579. cMap.numCodespaceRanges = cMap.useCMap.numCodespaceRanges;
  21580. }
  21581. // Merge the map into the current one, making sure not to override
  21582. // any previously defined entries.
  21583. cMap.useCMap.forEach(function(key, value) {
  21584. if (!cMap.contains(key)) {
  21585. cMap.mapOne(key, cMap.useCMap.lookup(key));
  21586. }
  21587. });
  21588. }
  21589. function parseBinaryCMap(name, builtInCMapParams) {
  21590. var url = builtInCMapParams.url + name + '.bcmap';
  21591. var cMap = new CMap(true);
  21592. new BinaryCMapReader().read(url, cMap, function (useCMap) {
  21593. extendCMap(cMap, builtInCMapParams, useCMap);
  21594. });
  21595. return cMap;
  21596. }
  21597. function createBuiltInCMap(name, builtInCMapParams) {
  21598. if (name === 'Identity-H') {
  21599. return new IdentityCMap(false, 2);
  21600. } else if (name === 'Identity-V') {
  21601. return new IdentityCMap(true, 2);
  21602. }
  21603. if (BUILT_IN_CMAPS.indexOf(name) === -1) {
  21604. error('Unknown cMap name: ' + name);
  21605. }
  21606. assert(builtInCMapParams, 'built-in cMap parameters are not provided');
  21607. if (builtInCMapParams.packed) {
  21608. return parseBinaryCMap(name, builtInCMapParams);
  21609. }
  21610. var request = new XMLHttpRequest();
  21611. var url = builtInCMapParams.url + name;
  21612. request.open('GET', url, false);
  21613. request.send(null);
  21614. if (!request.responseText) {
  21615. error('Unable to get cMap at: ' + url);
  21616. }
  21617. var cMap = new CMap(true);
  21618. var lexer = new Lexer(new StringStream(request.responseText));
  21619. parseCMap(cMap, lexer, builtInCMapParams, null);
  21620. return cMap;
  21621. }
  21622. return {
  21623. create: function (encoding, builtInCMapParams, useCMap) {
  21624. if (isName(encoding)) {
  21625. return createBuiltInCMap(encoding.name, builtInCMapParams);
  21626. } else if (isStream(encoding)) {
  21627. var cMap = new CMap();
  21628. var lexer = new Lexer(encoding);
  21629. try {
  21630. parseCMap(cMap, lexer, builtInCMapParams, useCMap);
  21631. } catch (e) {
  21632. warn('Invalid CMap data. ' + e);
  21633. }
  21634. if (cMap.isIdentityCMap) {
  21635. return createBuiltInCMap(cMap.name, builtInCMapParams);
  21636. }
  21637. return cMap;
  21638. }
  21639. error('Encoding required.');
  21640. }
  21641. };
  21642. })();
  21643. exports.CMap = CMap;
  21644. exports.CMapFactory = CMapFactory;
  21645. exports.IdentityCMap = IdentityCMap;
  21646. }));
  21647. (function (root, factory) {
  21648. {
  21649. factory((root.pdfjsCoreObj = {}), root.pdfjsSharedUtil,
  21650. root.pdfjsCorePrimitives, root.pdfjsCoreCrypto, root.pdfjsCoreParser,
  21651. root.pdfjsCoreChunkedStream);
  21652. }
  21653. }(this, function (exports, sharedUtil, corePrimitives, coreCrypto, coreParser,
  21654. coreChunkedStream) {
  21655. var InvalidPDFException = sharedUtil.InvalidPDFException;
  21656. var MissingDataException = sharedUtil.MissingDataException;
  21657. var XRefParseException = sharedUtil.XRefParseException;
  21658. var assert = sharedUtil.assert;
  21659. var bytesToString = sharedUtil.bytesToString;
  21660. var createPromiseCapability = sharedUtil.createPromiseCapability;
  21661. var error = sharedUtil.error;
  21662. var info = sharedUtil.info;
  21663. var isArray = sharedUtil.isArray;
  21664. var isInt = sharedUtil.isInt;
  21665. var isString = sharedUtil.isString;
  21666. var shadow = sharedUtil.shadow;
  21667. var stringToPDFString = sharedUtil.stringToPDFString;
  21668. var stringToUTF8String = sharedUtil.stringToUTF8String;
  21669. var warn = sharedUtil.warn;
  21670. var Ref = corePrimitives.Ref;
  21671. var RefSet = corePrimitives.RefSet;
  21672. var RefSetCache = corePrimitives.RefSetCache;
  21673. var isName = corePrimitives.isName;
  21674. var isCmd = corePrimitives.isCmd;
  21675. var isDict = corePrimitives.isDict;
  21676. var isRef = corePrimitives.isRef;
  21677. var isStream = corePrimitives.isStream;
  21678. var CipherTransformFactory = coreCrypto.CipherTransformFactory;
  21679. var Lexer = coreParser.Lexer;
  21680. var Parser = coreParser.Parser;
  21681. var ChunkedStream = coreChunkedStream.ChunkedStream;
  21682. var Catalog = (function CatalogClosure() {
  21683. function Catalog(pdfManager, xref, pageFactory) {
  21684. this.pdfManager = pdfManager;
  21685. this.xref = xref;
  21686. this.catDict = xref.getCatalogObj();
  21687. this.fontCache = new RefSetCache();
  21688. assert(isDict(this.catDict),
  21689. 'catalog object is not a dictionary');
  21690. // TODO refactor to move getPage() to the PDFDocument.
  21691. this.pageFactory = pageFactory;
  21692. this.pagePromises = [];
  21693. }
  21694. Catalog.prototype = {
  21695. get metadata() {
  21696. var streamRef = this.catDict.getRaw('Metadata');
  21697. if (!isRef(streamRef)) {
  21698. return shadow(this, 'metadata', null);
  21699. }
  21700. var encryptMetadata = (!this.xref.encrypt ? false :
  21701. this.xref.encrypt.encryptMetadata);
  21702. var stream = this.xref.fetch(streamRef, !encryptMetadata);
  21703. var metadata;
  21704. if (stream && isDict(stream.dict)) {
  21705. var type = stream.dict.get('Type');
  21706. var subtype = stream.dict.get('Subtype');
  21707. if (isName(type) && isName(subtype) &&
  21708. type.name === 'Metadata' && subtype.name === 'XML') {
  21709. // XXX: This should examine the charset the XML document defines,
  21710. // however since there are currently no real means to decode
  21711. // arbitrary charsets, let's just hope that the author of the PDF
  21712. // was reasonable enough to stick with the XML default charset,
  21713. // which is UTF-8.
  21714. try {
  21715. metadata = stringToUTF8String(bytesToString(stream.getBytes()));
  21716. } catch (e) {
  21717. info('Skipping invalid metadata.');
  21718. }
  21719. }
  21720. }
  21721. return shadow(this, 'metadata', metadata);
  21722. },
  21723. get toplevelPagesDict() {
  21724. var pagesObj = this.catDict.get('Pages');
  21725. assert(isDict(pagesObj), 'invalid top-level pages dictionary');
  21726. // shadow the prototype getter
  21727. return shadow(this, 'toplevelPagesDict', pagesObj);
  21728. },
  21729. get documentOutline() {
  21730. var obj = null;
  21731. try {
  21732. obj = this.readDocumentOutline();
  21733. } catch (ex) {
  21734. if (ex instanceof MissingDataException) {
  21735. throw ex;
  21736. }
  21737. warn('Unable to read document outline');
  21738. }
  21739. return shadow(this, 'documentOutline', obj);
  21740. },
  21741. readDocumentOutline: function Catalog_readDocumentOutline() {
  21742. var xref = this.xref;
  21743. var obj = this.catDict.get('Outlines');
  21744. var root = { items: [] };
  21745. if (isDict(obj)) {
  21746. obj = obj.getRaw('First');
  21747. var processed = new RefSet();
  21748. if (isRef(obj)) {
  21749. var queue = [{obj: obj, parent: root}];
  21750. // to avoid recursion keeping track of the items
  21751. // in the processed dictionary
  21752. processed.put(obj);
  21753. while (queue.length > 0) {
  21754. var i = queue.shift();
  21755. var outlineDict = xref.fetchIfRef(i.obj);
  21756. if (outlineDict === null) {
  21757. continue;
  21758. }
  21759. if (!outlineDict.has('Title')) {
  21760. error('Invalid outline item');
  21761. }
  21762. var dest = outlineDict.get('A');
  21763. if (dest) {
  21764. dest = dest.get('D');
  21765. } else if (outlineDict.has('Dest')) {
  21766. dest = outlineDict.getRaw('Dest');
  21767. if (isName(dest)) {
  21768. dest = dest.name;
  21769. }
  21770. }
  21771. var title = outlineDict.get('Title');
  21772. var outlineItem = {
  21773. dest: dest,
  21774. title: stringToPDFString(title),
  21775. color: outlineDict.get('C') || [0, 0, 0],
  21776. count: outlineDict.get('Count'),
  21777. bold: !!(outlineDict.get('F') & 2),
  21778. italic: !!(outlineDict.get('F') & 1),
  21779. items: []
  21780. };
  21781. i.parent.items.push(outlineItem);
  21782. obj = outlineDict.getRaw('First');
  21783. if (isRef(obj) && !processed.has(obj)) {
  21784. queue.push({obj: obj, parent: outlineItem});
  21785. processed.put(obj);
  21786. }
  21787. obj = outlineDict.getRaw('Next');
  21788. if (isRef(obj) && !processed.has(obj)) {
  21789. queue.push({obj: obj, parent: i.parent});
  21790. processed.put(obj);
  21791. }
  21792. }
  21793. }
  21794. }
  21795. return (root.items.length > 0 ? root.items : null);
  21796. },
  21797. get numPages() {
  21798. var obj = this.toplevelPagesDict.get('Count');
  21799. assert(
  21800. isInt(obj),
  21801. 'page count in top level pages object is not an integer'
  21802. );
  21803. // shadow the prototype getter
  21804. return shadow(this, 'num', obj);
  21805. },
  21806. get destinations() {
  21807. function fetchDestination(dest) {
  21808. return isDict(dest) ? dest.get('D') : dest;
  21809. }
  21810. var xref = this.xref;
  21811. var dests = {}, nameTreeRef, nameDictionaryRef;
  21812. var obj = this.catDict.get('Names');
  21813. if (obj && obj.has('Dests')) {
  21814. nameTreeRef = obj.getRaw('Dests');
  21815. } else if (this.catDict.has('Dests')) {
  21816. nameDictionaryRef = this.catDict.get('Dests');
  21817. }
  21818. if (nameDictionaryRef) {
  21819. // reading simple destination dictionary
  21820. obj = nameDictionaryRef;
  21821. obj.forEach(function catalogForEach(key, value) {
  21822. if (!value) {
  21823. return;
  21824. }
  21825. dests[key] = fetchDestination(value);
  21826. });
  21827. }
  21828. if (nameTreeRef) {
  21829. var nameTree = new NameTree(nameTreeRef, xref);
  21830. var names = nameTree.getAll();
  21831. for (var name in names) {
  21832. if (!names.hasOwnProperty(name)) {
  21833. continue;
  21834. }
  21835. dests[name] = fetchDestination(names[name]);
  21836. }
  21837. }
  21838. return shadow(this, 'destinations', dests);
  21839. },
  21840. getDestination: function Catalog_getDestination(destinationId) {
  21841. function fetchDestination(dest) {
  21842. return isDict(dest) ? dest.get('D') : dest;
  21843. }
  21844. var xref = this.xref;
  21845. var dest = null, nameTreeRef, nameDictionaryRef;
  21846. var obj = this.catDict.get('Names');
  21847. if (obj && obj.has('Dests')) {
  21848. nameTreeRef = obj.getRaw('Dests');
  21849. } else if (this.catDict.has('Dests')) {
  21850. nameDictionaryRef = this.catDict.get('Dests');
  21851. }
  21852. if (nameDictionaryRef) { // Simple destination dictionary.
  21853. var value = nameDictionaryRef.get(destinationId);
  21854. if (value) {
  21855. dest = fetchDestination(value);
  21856. }
  21857. }
  21858. if (nameTreeRef) {
  21859. var nameTree = new NameTree(nameTreeRef, xref);
  21860. dest = fetchDestination(nameTree.get(destinationId));
  21861. }
  21862. return dest;
  21863. },
  21864. get attachments() {
  21865. var xref = this.xref;
  21866. var attachments = null, nameTreeRef;
  21867. var obj = this.catDict.get('Names');
  21868. if (obj) {
  21869. nameTreeRef = obj.getRaw('EmbeddedFiles');
  21870. }
  21871. if (nameTreeRef) {
  21872. var nameTree = new NameTree(nameTreeRef, xref);
  21873. var names = nameTree.getAll();
  21874. for (var name in names) {
  21875. if (!names.hasOwnProperty(name)) {
  21876. continue;
  21877. }
  21878. var fs = new FileSpec(names[name], xref);
  21879. if (!attachments) {
  21880. attachments = {};
  21881. }
  21882. attachments[stringToPDFString(name)] = fs.serializable;
  21883. }
  21884. }
  21885. return shadow(this, 'attachments', attachments);
  21886. },
  21887. get javaScript() {
  21888. var xref = this.xref;
  21889. var obj = this.catDict.get('Names');
  21890. var javaScript = [];
  21891. function appendIfJavaScriptDict(jsDict) {
  21892. var type = jsDict.get('S');
  21893. if (!isName(type) || type.name !== 'JavaScript') {
  21894. return;
  21895. }
  21896. var js = jsDict.get('JS');
  21897. if (isStream(js)) {
  21898. js = bytesToString(js.getBytes());
  21899. } else if (!isString(js)) {
  21900. return;
  21901. }
  21902. javaScript.push(stringToPDFString(js));
  21903. }
  21904. if (obj && obj.has('JavaScript')) {
  21905. var nameTree = new NameTree(obj.getRaw('JavaScript'), xref);
  21906. var names = nameTree.getAll();
  21907. for (var name in names) {
  21908. if (!names.hasOwnProperty(name)) {
  21909. continue;
  21910. }
  21911. // We don't really use the JavaScript right now. This code is
  21912. // defensive so we don't cause errors on document load.
  21913. var jsDict = names[name];
  21914. if (isDict(jsDict)) {
  21915. appendIfJavaScriptDict(jsDict);
  21916. }
  21917. }
  21918. }
  21919. // Append OpenAction actions to javaScript array
  21920. var openactionDict = this.catDict.get('OpenAction');
  21921. if (isDict(openactionDict, 'Action')) {
  21922. var actionType = openactionDict.get('S');
  21923. if (isName(actionType) && actionType.name === 'Named') {
  21924. // The named Print action is not a part of the PDF 1.7 specification,
  21925. // but is supported by many PDF readers/writers (including Adobe's).
  21926. var action = openactionDict.get('N');
  21927. if (isName(action) && action.name === 'Print') {
  21928. javaScript.push('print({});');
  21929. }
  21930. } else {
  21931. appendIfJavaScriptDict(openactionDict);
  21932. }
  21933. }
  21934. return shadow(this, 'javaScript', javaScript);
  21935. },
  21936. cleanup: function Catalog_cleanup() {
  21937. var promises = [];
  21938. this.fontCache.forEach(function (promise) {
  21939. promises.push(promise);
  21940. });
  21941. return Promise.all(promises).then(function (translatedFonts) {
  21942. for (var i = 0, ii = translatedFonts.length; i < ii; i++) {
  21943. var font = translatedFonts[i].dict;
  21944. delete font.translated;
  21945. }
  21946. this.fontCache.clear();
  21947. }.bind(this));
  21948. },
  21949. getPage: function Catalog_getPage(pageIndex) {
  21950. if (!(pageIndex in this.pagePromises)) {
  21951. this.pagePromises[pageIndex] = this.getPageDict(pageIndex).then(
  21952. function (a) {
  21953. var dict = a[0];
  21954. var ref = a[1];
  21955. return this.pageFactory.createPage(pageIndex, dict, ref,
  21956. this.fontCache);
  21957. }.bind(this)
  21958. );
  21959. }
  21960. return this.pagePromises[pageIndex];
  21961. },
  21962. getPageDict: function Catalog_getPageDict(pageIndex) {
  21963. var capability = createPromiseCapability();
  21964. var nodesToVisit = [this.catDict.getRaw('Pages')];
  21965. var currentPageIndex = 0;
  21966. var xref = this.xref;
  21967. var checkAllKids = false;
  21968. function next() {
  21969. while (nodesToVisit.length) {
  21970. var currentNode = nodesToVisit.pop();
  21971. if (isRef(currentNode)) {
  21972. xref.fetchAsync(currentNode).then(function (obj) {
  21973. if (isDict(obj, 'Page') || (isDict(obj) && !obj.has('Kids'))) {
  21974. if (pageIndex === currentPageIndex) {
  21975. capability.resolve([obj, currentNode]);
  21976. } else {
  21977. currentPageIndex++;
  21978. next();
  21979. }
  21980. return;
  21981. }
  21982. nodesToVisit.push(obj);
  21983. next();
  21984. }, capability.reject);
  21985. return;
  21986. }
  21987. // Must be a child page dictionary.
  21988. assert(
  21989. isDict(currentNode),
  21990. 'page dictionary kid reference points to wrong type of object'
  21991. );
  21992. var count = currentNode.get('Count');
  21993. // If the current node doesn't have any children, avoid getting stuck
  21994. // in an empty node further down in the tree (see issue5644.pdf).
  21995. if (count === 0) {
  21996. checkAllKids = true;
  21997. }
  21998. // Skip nodes where the page can't be.
  21999. if (currentPageIndex + count <= pageIndex) {
  22000. currentPageIndex += count;
  22001. continue;
  22002. }
  22003. var kids = currentNode.get('Kids');
  22004. assert(isArray(kids), 'page dictionary kids object is not an array');
  22005. if (!checkAllKids && count === kids.length) {
  22006. // Nodes that don't have the page have been skipped and this is the
  22007. // bottom of the tree which means the page requested must be a
  22008. // descendant of this pages node. Ideally we would just resolve the
  22009. // promise with the page ref here, but there is the case where more
  22010. // pages nodes could link to single a page (see issue 3666 pdf). To
  22011. // handle this push it back on the queue so if it is a pages node it
  22012. // will be descended into.
  22013. nodesToVisit = [kids[pageIndex - currentPageIndex]];
  22014. currentPageIndex = pageIndex;
  22015. continue;
  22016. } else {
  22017. for (var last = kids.length - 1; last >= 0; last--) {
  22018. nodesToVisit.push(kids[last]);
  22019. }
  22020. }
  22021. }
  22022. capability.reject('Page index ' + pageIndex + ' not found.');
  22023. }
  22024. next();
  22025. return capability.promise;
  22026. },
  22027. getPageIndex: function Catalog_getPageIndex(ref) {
  22028. // The page tree nodes have the count of all the leaves below them. To get
  22029. // how many pages are before we just have to walk up the tree and keep
  22030. // adding the count of siblings to the left of the node.
  22031. var xref = this.xref;
  22032. function pagesBeforeRef(kidRef) {
  22033. var total = 0;
  22034. var parentRef;
  22035. return xref.fetchAsync(kidRef).then(function (node) {
  22036. if (!node) {
  22037. return null;
  22038. }
  22039. parentRef = node.getRaw('Parent');
  22040. return node.getAsync('Parent');
  22041. }).then(function (parent) {
  22042. if (!parent) {
  22043. return null;
  22044. }
  22045. return parent.getAsync('Kids');
  22046. }).then(function (kids) {
  22047. if (!kids) {
  22048. return null;
  22049. }
  22050. var kidPromises = [];
  22051. var found = false;
  22052. for (var i = 0; i < kids.length; i++) {
  22053. var kid = kids[i];
  22054. assert(isRef(kid), 'kids must be a ref');
  22055. if (kid.num === kidRef.num) {
  22056. found = true;
  22057. break;
  22058. }
  22059. kidPromises.push(xref.fetchAsync(kid).then(function (kid) {
  22060. if (kid.has('Count')) {
  22061. var count = kid.get('Count');
  22062. total += count;
  22063. } else { // page leaf node
  22064. total++;
  22065. }
  22066. }));
  22067. }
  22068. if (!found) {
  22069. error('kid ref not found in parents kids');
  22070. }
  22071. return Promise.all(kidPromises).then(function () {
  22072. return [total, parentRef];
  22073. });
  22074. });
  22075. }
  22076. var total = 0;
  22077. function next(ref) {
  22078. return pagesBeforeRef(ref).then(function (args) {
  22079. if (!args) {
  22080. return total;
  22081. }
  22082. var count = args[0];
  22083. var parentRef = args[1];
  22084. total += count;
  22085. return next(parentRef);
  22086. });
  22087. }
  22088. return next(ref);
  22089. }
  22090. };
  22091. return Catalog;
  22092. })();
  22093. var XRef = (function XRefClosure() {
  22094. function XRef(stream, password) {
  22095. this.stream = stream;
  22096. this.entries = [];
  22097. this.xrefstms = {};
  22098. // prepare the XRef cache
  22099. this.cache = [];
  22100. this.password = password;
  22101. this.stats = {
  22102. streamTypes: [],
  22103. fontTypes: []
  22104. };
  22105. }
  22106. XRef.prototype = {
  22107. setStartXRef: function XRef_setStartXRef(startXRef) {
  22108. // Store the starting positions of xref tables as we process them
  22109. // so we can recover from missing data errors
  22110. this.startXRefQueue = [startXRef];
  22111. },
  22112. parse: function XRef_parse(recoveryMode) {
  22113. var trailerDict;
  22114. if (!recoveryMode) {
  22115. trailerDict = this.readXRef();
  22116. } else {
  22117. warn('Indexing all PDF objects');
  22118. trailerDict = this.indexObjects();
  22119. }
  22120. trailerDict.assignXref(this);
  22121. this.trailer = trailerDict;
  22122. var encrypt = trailerDict.get('Encrypt');
  22123. if (encrypt) {
  22124. var ids = trailerDict.get('ID');
  22125. var fileId = (ids && ids.length) ? ids[0] : '';
  22126. this.encrypt = new CipherTransformFactory(encrypt, fileId,
  22127. this.password);
  22128. }
  22129. // get the root dictionary (catalog) object
  22130. if (!(this.root = trailerDict.get('Root'))) {
  22131. error('Invalid root reference');
  22132. }
  22133. },
  22134. processXRefTable: function XRef_processXRefTable(parser) {
  22135. if (!('tableState' in this)) {
  22136. // Stores state of the table as we process it so we can resume
  22137. // from middle of table in case of missing data error
  22138. this.tableState = {
  22139. entryNum: 0,
  22140. streamPos: parser.lexer.stream.pos,
  22141. parserBuf1: parser.buf1,
  22142. parserBuf2: parser.buf2
  22143. };
  22144. }
  22145. var obj = this.readXRefTable(parser);
  22146. // Sanity check
  22147. if (!isCmd(obj, 'trailer')) {
  22148. error('Invalid XRef table: could not find trailer dictionary');
  22149. }
  22150. // Read trailer dictionary, e.g.
  22151. // trailer
  22152. // << /Size 22
  22153. // /Root 20R
  22154. // /Info 10R
  22155. // /ID [ <81b14aafa313db63dbd6f981e49f94f4> ]
  22156. // >>
  22157. // The parser goes through the entire stream << ... >> and provides
  22158. // a getter interface for the key-value table
  22159. var dict = parser.getObj();
  22160. // The pdflib PDF generator can generate a nested trailer dictionary
  22161. if (!isDict(dict) && dict.dict) {
  22162. dict = dict.dict;
  22163. }
  22164. if (!isDict(dict)) {
  22165. error('Invalid XRef table: could not parse trailer dictionary');
  22166. }
  22167. delete this.tableState;
  22168. return dict;
  22169. },
  22170. readXRefTable: function XRef_readXRefTable(parser) {
  22171. // Example of cross-reference table:
  22172. // xref
  22173. // 0 1 <-- subsection header (first obj #, obj count)
  22174. // 0000000000 65535 f <-- actual object (offset, generation #, f/n)
  22175. // 23 2 <-- subsection header ... and so on ...
  22176. // 0000025518 00002 n
  22177. // 0000025635 00000 n
  22178. // trailer
  22179. // ...
  22180. var stream = parser.lexer.stream;
  22181. var tableState = this.tableState;
  22182. stream.pos = tableState.streamPos;
  22183. parser.buf1 = tableState.parserBuf1;
  22184. parser.buf2 = tableState.parserBuf2;
  22185. // Outer loop is over subsection headers
  22186. var obj;
  22187. while (true) {
  22188. if (!('firstEntryNum' in tableState) || !('entryCount' in tableState)) {
  22189. if (isCmd(obj = parser.getObj(), 'trailer')) {
  22190. break;
  22191. }
  22192. tableState.firstEntryNum = obj;
  22193. tableState.entryCount = parser.getObj();
  22194. }
  22195. var first = tableState.firstEntryNum;
  22196. var count = tableState.entryCount;
  22197. if (!isInt(first) || !isInt(count)) {
  22198. error('Invalid XRef table: wrong types in subsection header');
  22199. }
  22200. // Inner loop is over objects themselves
  22201. for (var i = tableState.entryNum; i < count; i++) {
  22202. tableState.streamPos = stream.pos;
  22203. tableState.entryNum = i;
  22204. tableState.parserBuf1 = parser.buf1;
  22205. tableState.parserBuf2 = parser.buf2;
  22206. var entry = {};
  22207. entry.offset = parser.getObj();
  22208. entry.gen = parser.getObj();
  22209. var type = parser.getObj();
  22210. if (isCmd(type, 'f')) {
  22211. entry.free = true;
  22212. } else if (isCmd(type, 'n')) {
  22213. entry.uncompressed = true;
  22214. }
  22215. // Validate entry obj
  22216. if (!isInt(entry.offset) || !isInt(entry.gen) ||
  22217. !(entry.free || entry.uncompressed)) {
  22218. error('Invalid entry in XRef subsection: ' + first + ', ' + count);
  22219. }
  22220. if (!this.entries[i + first]) {
  22221. this.entries[i + first] = entry;
  22222. }
  22223. }
  22224. tableState.entryNum = 0;
  22225. tableState.streamPos = stream.pos;
  22226. tableState.parserBuf1 = parser.buf1;
  22227. tableState.parserBuf2 = parser.buf2;
  22228. delete tableState.firstEntryNum;
  22229. delete tableState.entryCount;
  22230. }
  22231. // Per issue 3248: hp scanners generate bad XRef
  22232. if (first === 1 && this.entries[1] && this.entries[1].free) {
  22233. // shifting the entries
  22234. this.entries.shift();
  22235. }
  22236. // Sanity check: as per spec, first object must be free
  22237. if (this.entries[0] && !this.entries[0].free) {
  22238. error('Invalid XRef table: unexpected first object');
  22239. }
  22240. return obj;
  22241. },
  22242. processXRefStream: function XRef_processXRefStream(stream) {
  22243. if (!('streamState' in this)) {
  22244. // Stores state of the stream as we process it so we can resume
  22245. // from middle of stream in case of missing data error
  22246. var streamParameters = stream.dict;
  22247. var byteWidths = streamParameters.get('W');
  22248. var range = streamParameters.get('Index');
  22249. if (!range) {
  22250. range = [0, streamParameters.get('Size')];
  22251. }
  22252. this.streamState = {
  22253. entryRanges: range,
  22254. byteWidths: byteWidths,
  22255. entryNum: 0,
  22256. streamPos: stream.pos
  22257. };
  22258. }
  22259. this.readXRefStream(stream);
  22260. delete this.streamState;
  22261. return stream.dict;
  22262. },
  22263. readXRefStream: function XRef_readXRefStream(stream) {
  22264. var i, j;
  22265. var streamState = this.streamState;
  22266. stream.pos = streamState.streamPos;
  22267. var byteWidths = streamState.byteWidths;
  22268. var typeFieldWidth = byteWidths[0];
  22269. var offsetFieldWidth = byteWidths[1];
  22270. var generationFieldWidth = byteWidths[2];
  22271. var entryRanges = streamState.entryRanges;
  22272. while (entryRanges.length > 0) {
  22273. var first = entryRanges[0];
  22274. var n = entryRanges[1];
  22275. if (!isInt(first) || !isInt(n)) {
  22276. error('Invalid XRef range fields: ' + first + ', ' + n);
  22277. }
  22278. if (!isInt(typeFieldWidth) || !isInt(offsetFieldWidth) ||
  22279. !isInt(generationFieldWidth)) {
  22280. error('Invalid XRef entry fields length: ' + first + ', ' + n);
  22281. }
  22282. for (i = streamState.entryNum; i < n; ++i) {
  22283. streamState.entryNum = i;
  22284. streamState.streamPos = stream.pos;
  22285. var type = 0, offset = 0, generation = 0;
  22286. for (j = 0; j < typeFieldWidth; ++j) {
  22287. type = (type << 8) | stream.getByte();
  22288. }
  22289. // if type field is absent, its default value is 1
  22290. if (typeFieldWidth === 0) {
  22291. type = 1;
  22292. }
  22293. for (j = 0; j < offsetFieldWidth; ++j) {
  22294. offset = (offset << 8) | stream.getByte();
  22295. }
  22296. for (j = 0; j < generationFieldWidth; ++j) {
  22297. generation = (generation << 8) | stream.getByte();
  22298. }
  22299. var entry = {};
  22300. entry.offset = offset;
  22301. entry.gen = generation;
  22302. switch (type) {
  22303. case 0:
  22304. entry.free = true;
  22305. break;
  22306. case 1:
  22307. entry.uncompressed = true;
  22308. break;
  22309. case 2:
  22310. break;
  22311. default:
  22312. error('Invalid XRef entry type: ' + type);
  22313. }
  22314. if (!this.entries[first + i]) {
  22315. this.entries[first + i] = entry;
  22316. }
  22317. }
  22318. streamState.entryNum = 0;
  22319. streamState.streamPos = stream.pos;
  22320. entryRanges.splice(0, 2);
  22321. }
  22322. },
  22323. indexObjects: function XRef_indexObjects() {
  22324. // Simple scan through the PDF content to find objects,
  22325. // trailers and XRef streams.
  22326. var TAB = 0x9, LF = 0xA, CR = 0xD, SPACE = 0x20;
  22327. var PERCENT = 0x25, LT = 0x3C;
  22328. function readToken(data, offset) {
  22329. var token = '', ch = data[offset];
  22330. while (ch !== LF && ch !== CR && ch !== LT) {
  22331. if (++offset >= data.length) {
  22332. break;
  22333. }
  22334. token += String.fromCharCode(ch);
  22335. ch = data[offset];
  22336. }
  22337. return token;
  22338. }
  22339. function skipUntil(data, offset, what) {
  22340. var length = what.length, dataLength = data.length;
  22341. var skipped = 0;
  22342. // finding byte sequence
  22343. while (offset < dataLength) {
  22344. var i = 0;
  22345. while (i < length && data[offset + i] === what[i]) {
  22346. ++i;
  22347. }
  22348. if (i >= length) {
  22349. break; // sequence found
  22350. }
  22351. offset++;
  22352. skipped++;
  22353. }
  22354. return skipped;
  22355. }
  22356. var objRegExp = /^(\d+)\s+(\d+)\s+obj\b/;
  22357. var trailerBytes = new Uint8Array([116, 114, 97, 105, 108, 101, 114]);
  22358. var startxrefBytes = new Uint8Array([115, 116, 97, 114, 116, 120, 114,
  22359. 101, 102]);
  22360. var endobjBytes = new Uint8Array([101, 110, 100, 111, 98, 106]);
  22361. var xrefBytes = new Uint8Array([47, 88, 82, 101, 102]);
  22362. // Clear out any existing entries, since they may be bogus.
  22363. this.entries.length = 0;
  22364. var stream = this.stream;
  22365. stream.pos = 0;
  22366. var buffer = stream.getBytes();
  22367. var position = stream.start, length = buffer.length;
  22368. var trailers = [], xrefStms = [];
  22369. while (position < length) {
  22370. var ch = buffer[position];
  22371. if (ch === TAB || ch === LF || ch === CR || ch === SPACE) {
  22372. ++position;
  22373. continue;
  22374. }
  22375. if (ch === PERCENT) { // %-comment
  22376. do {
  22377. ++position;
  22378. if (position >= length) {
  22379. break;
  22380. }
  22381. ch = buffer[position];
  22382. } while (ch !== LF && ch !== CR);
  22383. continue;
  22384. }
  22385. var token = readToken(buffer, position);
  22386. var m;
  22387. if (token.indexOf('xref') === 0 &&
  22388. (token.length === 4 || /\s/.test(token[4]))) {
  22389. position += skipUntil(buffer, position, trailerBytes);
  22390. trailers.push(position);
  22391. position += skipUntil(buffer, position, startxrefBytes);
  22392. } else if ((m = objRegExp.exec(token))) {
  22393. if (typeof this.entries[m[1]] === 'undefined') {
  22394. this.entries[m[1]] = {
  22395. offset: position - stream.start,
  22396. gen: m[2] | 0,
  22397. uncompressed: true
  22398. };
  22399. }
  22400. var contentLength = skipUntil(buffer, position, endobjBytes) + 7;
  22401. var content = buffer.subarray(position, position + contentLength);
  22402. // checking XRef stream suspect
  22403. // (it shall have '/XRef' and next char is not a letter)
  22404. var xrefTagOffset = skipUntil(content, 0, xrefBytes);
  22405. if (xrefTagOffset < contentLength &&
  22406. content[xrefTagOffset + 5] < 64) {
  22407. xrefStms.push(position - stream.start);
  22408. this.xrefstms[position - stream.start] = 1; // Avoid recursion
  22409. }
  22410. position += contentLength;
  22411. } else if (token.indexOf('trailer') === 0 &&
  22412. (token.length === 7 || /\s/.test(token[7]))) {
  22413. trailers.push(position);
  22414. position += skipUntil(buffer, position, startxrefBytes);
  22415. } else {
  22416. position += token.length + 1;
  22417. }
  22418. }
  22419. // reading XRef streams
  22420. var i, ii;
  22421. for (i = 0, ii = xrefStms.length; i < ii; ++i) {
  22422. this.startXRefQueue.push(xrefStms[i]);
  22423. this.readXRef(/* recoveryMode */ true);
  22424. }
  22425. // finding main trailer
  22426. var dict;
  22427. for (i = 0, ii = trailers.length; i < ii; ++i) {
  22428. stream.pos = trailers[i];
  22429. var parser = new Parser(new Lexer(stream), true, this);
  22430. var obj = parser.getObj();
  22431. if (!isCmd(obj, 'trailer')) {
  22432. continue;
  22433. }
  22434. // read the trailer dictionary
  22435. if (!isDict(dict = parser.getObj())) {
  22436. continue;
  22437. }
  22438. // taking the first one with 'ID'
  22439. if (dict.has('ID')) {
  22440. return dict;
  22441. }
  22442. }
  22443. // no tailer with 'ID', taking last one (if exists)
  22444. if (dict) {
  22445. return dict;
  22446. }
  22447. // nothing helps
  22448. // calling error() would reject worker with an UnknownErrorException.
  22449. throw new InvalidPDFException('Invalid PDF structure');
  22450. },
  22451. readXRef: function XRef_readXRef(recoveryMode) {
  22452. var stream = this.stream;
  22453. try {
  22454. while (this.startXRefQueue.length) {
  22455. var startXRef = this.startXRefQueue[0];
  22456. stream.pos = startXRef + stream.start;
  22457. var parser = new Parser(new Lexer(stream), true, this);
  22458. var obj = parser.getObj();
  22459. var dict;
  22460. // Get dictionary
  22461. if (isCmd(obj, 'xref')) {
  22462. // Parse end-of-file XRef
  22463. dict = this.processXRefTable(parser);
  22464. if (!this.topDict) {
  22465. this.topDict = dict;
  22466. }
  22467. // Recursively get other XRefs 'XRefStm', if any
  22468. obj = dict.get('XRefStm');
  22469. if (isInt(obj)) {
  22470. var pos = obj;
  22471. // ignore previously loaded xref streams
  22472. // (possible infinite recursion)
  22473. if (!(pos in this.xrefstms)) {
  22474. this.xrefstms[pos] = 1;
  22475. this.startXRefQueue.push(pos);
  22476. }
  22477. }
  22478. } else if (isInt(obj)) {
  22479. // Parse in-stream XRef
  22480. if (!isInt(parser.getObj()) ||
  22481. !isCmd(parser.getObj(), 'obj') ||
  22482. !isStream(obj = parser.getObj())) {
  22483. error('Invalid XRef stream');
  22484. }
  22485. dict = this.processXRefStream(obj);
  22486. if (!this.topDict) {
  22487. this.topDict = dict;
  22488. }
  22489. if (!dict) {
  22490. error('Failed to read XRef stream');
  22491. }
  22492. } else {
  22493. error('Invalid XRef stream header');
  22494. }
  22495. // Recursively get previous dictionary, if any
  22496. obj = dict.get('Prev');
  22497. if (isInt(obj)) {
  22498. this.startXRefQueue.push(obj);
  22499. } else if (isRef(obj)) {
  22500. // The spec says Prev must not be a reference, i.e. "/Prev NNN"
  22501. // This is a fallback for non-compliant PDFs, i.e. "/Prev NNN 0 R"
  22502. this.startXRefQueue.push(obj.num);
  22503. }
  22504. this.startXRefQueue.shift();
  22505. }
  22506. return this.topDict;
  22507. } catch (e) {
  22508. if (e instanceof MissingDataException) {
  22509. throw e;
  22510. }
  22511. info('(while reading XRef): ' + e);
  22512. }
  22513. if (recoveryMode) {
  22514. return;
  22515. }
  22516. throw new XRefParseException();
  22517. },
  22518. getEntry: function XRef_getEntry(i) {
  22519. var xrefEntry = this.entries[i];
  22520. if (xrefEntry && !xrefEntry.free && xrefEntry.offset) {
  22521. return xrefEntry;
  22522. }
  22523. return null;
  22524. },
  22525. fetchIfRef: function XRef_fetchIfRef(obj) {
  22526. if (!isRef(obj)) {
  22527. return obj;
  22528. }
  22529. return this.fetch(obj);
  22530. },
  22531. fetch: function XRef_fetch(ref, suppressEncryption) {
  22532. assert(isRef(ref), 'ref object is not a reference');
  22533. var num = ref.num;
  22534. if (num in this.cache) {
  22535. var cacheEntry = this.cache[num];
  22536. return cacheEntry;
  22537. }
  22538. var xrefEntry = this.getEntry(num);
  22539. // the referenced entry can be free
  22540. if (xrefEntry === null) {
  22541. return (this.cache[num] = null);
  22542. }
  22543. if (xrefEntry.uncompressed) {
  22544. xrefEntry = this.fetchUncompressed(ref, xrefEntry, suppressEncryption);
  22545. } else {
  22546. xrefEntry = this.fetchCompressed(xrefEntry, suppressEncryption);
  22547. }
  22548. if (isDict(xrefEntry)){
  22549. xrefEntry.objId = ref.toString();
  22550. } else if (isStream(xrefEntry)) {
  22551. xrefEntry.dict.objId = ref.toString();
  22552. }
  22553. return xrefEntry;
  22554. },
  22555. fetchUncompressed: function XRef_fetchUncompressed(ref, xrefEntry,
  22556. suppressEncryption) {
  22557. var gen = ref.gen;
  22558. var num = ref.num;
  22559. if (xrefEntry.gen !== gen) {
  22560. error('inconsistent generation in XRef');
  22561. }
  22562. var stream = this.stream.makeSubStream(xrefEntry.offset +
  22563. this.stream.start);
  22564. var parser = new Parser(new Lexer(stream), true, this);
  22565. var obj1 = parser.getObj();
  22566. var obj2 = parser.getObj();
  22567. var obj3 = parser.getObj();
  22568. if (!isInt(obj1) || parseInt(obj1, 10) !== num ||
  22569. !isInt(obj2) || parseInt(obj2, 10) !== gen ||
  22570. !isCmd(obj3)) {
  22571. error('bad XRef entry');
  22572. }
  22573. if (!isCmd(obj3, 'obj')) {
  22574. // some bad PDFs use "obj1234" and really mean 1234
  22575. if (obj3.cmd.indexOf('obj') === 0) {
  22576. num = parseInt(obj3.cmd.substring(3), 10);
  22577. if (!isNaN(num)) {
  22578. return num;
  22579. }
  22580. }
  22581. error('bad XRef entry');
  22582. }
  22583. if (this.encrypt && !suppressEncryption) {
  22584. xrefEntry = parser.getObj(this.encrypt.createCipherTransform(num, gen));
  22585. } else {
  22586. xrefEntry = parser.getObj();
  22587. }
  22588. if (!isStream(xrefEntry)) {
  22589. this.cache[num] = xrefEntry;
  22590. }
  22591. return xrefEntry;
  22592. },
  22593. fetchCompressed: function XRef_fetchCompressed(xrefEntry,
  22594. suppressEncryption) {
  22595. var tableOffset = xrefEntry.offset;
  22596. var stream = this.fetch(new Ref(tableOffset, 0));
  22597. if (!isStream(stream)) {
  22598. error('bad ObjStm stream');
  22599. }
  22600. var first = stream.dict.get('First');
  22601. var n = stream.dict.get('N');
  22602. if (!isInt(first) || !isInt(n)) {
  22603. error('invalid first and n parameters for ObjStm stream');
  22604. }
  22605. var parser = new Parser(new Lexer(stream), false, this);
  22606. parser.allowStreams = true;
  22607. var i, entries = [], num, nums = [];
  22608. // read the object numbers to populate cache
  22609. for (i = 0; i < n; ++i) {
  22610. num = parser.getObj();
  22611. if (!isInt(num)) {
  22612. error('invalid object number in the ObjStm stream: ' + num);
  22613. }
  22614. nums.push(num);
  22615. var offset = parser.getObj();
  22616. if (!isInt(offset)) {
  22617. error('invalid object offset in the ObjStm stream: ' + offset);
  22618. }
  22619. }
  22620. // read stream objects for cache
  22621. for (i = 0; i < n; ++i) {
  22622. entries.push(parser.getObj());
  22623. num = nums[i];
  22624. var entry = this.entries[num];
  22625. if (entry && entry.offset === tableOffset && entry.gen === i) {
  22626. this.cache[num] = entries[i];
  22627. }
  22628. }
  22629. xrefEntry = entries[xrefEntry.gen];
  22630. if (xrefEntry === undefined) {
  22631. error('bad XRef entry for compressed object');
  22632. }
  22633. return xrefEntry;
  22634. },
  22635. fetchIfRefAsync: function XRef_fetchIfRefAsync(obj) {
  22636. if (!isRef(obj)) {
  22637. return Promise.resolve(obj);
  22638. }
  22639. return this.fetchAsync(obj);
  22640. },
  22641. fetchAsync: function XRef_fetchAsync(ref, suppressEncryption) {
  22642. var streamManager = this.stream.manager;
  22643. var xref = this;
  22644. return new Promise(function tryFetch(resolve, reject) {
  22645. try {
  22646. resolve(xref.fetch(ref, suppressEncryption));
  22647. } catch (e) {
  22648. if (e instanceof MissingDataException) {
  22649. streamManager.requestRange(e.begin, e.end).then(function () {
  22650. tryFetch(resolve, reject);
  22651. }, reject);
  22652. return;
  22653. }
  22654. reject(e);
  22655. }
  22656. });
  22657. },
  22658. getCatalogObj: function XRef_getCatalogObj() {
  22659. return this.root;
  22660. }
  22661. };
  22662. return XRef;
  22663. })();
  22664. /**
  22665. * A NameTree is like a Dict but has some advantageous properties, see the
  22666. * spec (7.9.6) for more details.
  22667. * TODO: implement all the Dict functions and make this more efficent.
  22668. */
  22669. var NameTree = (function NameTreeClosure() {
  22670. function NameTree(root, xref) {
  22671. this.root = root;
  22672. this.xref = xref;
  22673. }
  22674. NameTree.prototype = {
  22675. getAll: function NameTree_getAll() {
  22676. var dict = {};
  22677. if (!this.root) {
  22678. return dict;
  22679. }
  22680. var xref = this.xref;
  22681. // reading name tree
  22682. var processed = new RefSet();
  22683. processed.put(this.root);
  22684. var queue = [this.root];
  22685. while (queue.length > 0) {
  22686. var i, n;
  22687. var obj = xref.fetchIfRef(queue.shift());
  22688. if (!isDict(obj)) {
  22689. continue;
  22690. }
  22691. if (obj.has('Kids')) {
  22692. var kids = obj.get('Kids');
  22693. for (i = 0, n = kids.length; i < n; i++) {
  22694. var kid = kids[i];
  22695. if (processed.has(kid)) {
  22696. error('invalid destinations');
  22697. }
  22698. queue.push(kid);
  22699. processed.put(kid);
  22700. }
  22701. continue;
  22702. }
  22703. var names = obj.get('Names');
  22704. if (names) {
  22705. for (i = 0, n = names.length; i < n; i += 2) {
  22706. dict[xref.fetchIfRef(names[i])] = xref.fetchIfRef(names[i + 1]);
  22707. }
  22708. }
  22709. }
  22710. return dict;
  22711. },
  22712. get: function NameTree_get(destinationId) {
  22713. if (!this.root) {
  22714. return null;
  22715. }
  22716. var xref = this.xref;
  22717. var kidsOrNames = xref.fetchIfRef(this.root);
  22718. var loopCount = 0;
  22719. var MAX_NAMES_LEVELS = 10;
  22720. var l, r, m;
  22721. // Perform a binary search to quickly find the entry that
  22722. // contains the named destination we are looking for.
  22723. while (kidsOrNames.has('Kids')) {
  22724. loopCount++;
  22725. if (loopCount > MAX_NAMES_LEVELS) {
  22726. warn('Search depth limit for named destionations has been reached.');
  22727. return null;
  22728. }
  22729. var kids = kidsOrNames.get('Kids');
  22730. if (!isArray(kids)) {
  22731. return null;
  22732. }
  22733. l = 0;
  22734. r = kids.length - 1;
  22735. while (l <= r) {
  22736. m = (l + r) >> 1;
  22737. var kid = xref.fetchIfRef(kids[m]);
  22738. var limits = kid.get('Limits');
  22739. if (destinationId < xref.fetchIfRef(limits[0])) {
  22740. r = m - 1;
  22741. } else if (destinationId > xref.fetchIfRef(limits[1])) {
  22742. l = m + 1;
  22743. } else {
  22744. kidsOrNames = xref.fetchIfRef(kids[m]);
  22745. break;
  22746. }
  22747. }
  22748. if (l > r) {
  22749. return null;
  22750. }
  22751. }
  22752. // If we get here, then we have found the right entry. Now
  22753. // go through the named destinations in the Named dictionary
  22754. // until we find the exact destination we're looking for.
  22755. var names = kidsOrNames.get('Names');
  22756. if (isArray(names)) {
  22757. // Perform a binary search to reduce the lookup time.
  22758. l = 0;
  22759. r = names.length - 2;
  22760. while (l <= r) {
  22761. // Check only even indices (0, 2, 4, ...) because the
  22762. // odd indices contain the actual D array.
  22763. m = (l + r) & ~1;
  22764. if (destinationId < xref.fetchIfRef(names[m])) {
  22765. r = m - 2;
  22766. } else if (destinationId > xref.fetchIfRef(names[m])) {
  22767. l = m + 2;
  22768. } else {
  22769. return xref.fetchIfRef(names[m + 1]);
  22770. }
  22771. }
  22772. }
  22773. return null;
  22774. }
  22775. };
  22776. return NameTree;
  22777. })();
  22778. /**
  22779. * "A PDF file can refer to the contents of another file by using a File
  22780. * Specification (PDF 1.1)", see the spec (7.11) for more details.
  22781. * NOTE: Only embedded files are supported (as part of the attachments support)
  22782. * TODO: support the 'URL' file system (with caching if !/V), portable
  22783. * collections attributes and related files (/RF)
  22784. */
  22785. var FileSpec = (function FileSpecClosure() {
  22786. function FileSpec(root, xref) {
  22787. if (!root || !isDict(root)) {
  22788. return;
  22789. }
  22790. this.xref = xref;
  22791. this.root = root;
  22792. if (root.has('FS')) {
  22793. this.fs = root.get('FS');
  22794. }
  22795. this.description = root.has('Desc') ?
  22796. stringToPDFString(root.get('Desc')) :
  22797. '';
  22798. if (root.has('RF')) {
  22799. warn('Related file specifications are not supported');
  22800. }
  22801. this.contentAvailable = true;
  22802. if (!root.has('EF')) {
  22803. this.contentAvailable = false;
  22804. warn('Non-embedded file specifications are not supported');
  22805. }
  22806. }
  22807. function pickPlatformItem(dict) {
  22808. // Look for the filename in this order:
  22809. // UF, F, Unix, Mac, DOS
  22810. if (dict.has('UF')) {
  22811. return dict.get('UF');
  22812. } else if (dict.has('F')) {
  22813. return dict.get('F');
  22814. } else if (dict.has('Unix')) {
  22815. return dict.get('Unix');
  22816. } else if (dict.has('Mac')) {
  22817. return dict.get('Mac');
  22818. } else if (dict.has('DOS')) {
  22819. return dict.get('DOS');
  22820. } else {
  22821. return null;
  22822. }
  22823. }
  22824. FileSpec.prototype = {
  22825. get filename() {
  22826. if (!this._filename && this.root) {
  22827. var filename = pickPlatformItem(this.root) || 'unnamed';
  22828. this._filename = stringToPDFString(filename).
  22829. replace(/\\\\/g, '\\').
  22830. replace(/\\\//g, '/').
  22831. replace(/\\/g, '/');
  22832. }
  22833. return this._filename;
  22834. },
  22835. get content() {
  22836. if (!this.contentAvailable) {
  22837. return null;
  22838. }
  22839. if (!this.contentRef && this.root) {
  22840. this.contentRef = pickPlatformItem(this.root.get('EF'));
  22841. }
  22842. var content = null;
  22843. if (this.contentRef) {
  22844. var xref = this.xref;
  22845. var fileObj = xref.fetchIfRef(this.contentRef);
  22846. if (fileObj && isStream(fileObj)) {
  22847. content = fileObj.getBytes();
  22848. } else {
  22849. warn('Embedded file specification points to non-existing/invalid ' +
  22850. 'content');
  22851. }
  22852. } else {
  22853. warn('Embedded file specification does not have a content');
  22854. }
  22855. return content;
  22856. },
  22857. get serializable() {
  22858. return {
  22859. filename: this.filename,
  22860. content: this.content
  22861. };
  22862. }
  22863. };
  22864. return FileSpec;
  22865. })();
  22866. /**
  22867. * A helper for loading missing data in object graphs. It traverses the graph
  22868. * depth first and queues up any objects that have missing data. Once it has
  22869. * has traversed as many objects that are available it attempts to bundle the
  22870. * missing data requests and then resume from the nodes that weren't ready.
  22871. *
  22872. * NOTE: It provides protection from circular references by keeping track of
  22873. * of loaded references. However, you must be careful not to load any graphs
  22874. * that have references to the catalog or other pages since that will cause the
  22875. * entire PDF document object graph to be traversed.
  22876. */
  22877. var ObjectLoader = (function() {
  22878. function mayHaveChildren(value) {
  22879. return isRef(value) || isDict(value) || isArray(value) || isStream(value);
  22880. }
  22881. function addChildren(node, nodesToVisit) {
  22882. var value;
  22883. if (isDict(node) || isStream(node)) {
  22884. var map;
  22885. if (isDict(node)) {
  22886. map = node.map;
  22887. } else {
  22888. map = node.dict.map;
  22889. }
  22890. for (var key in map) {
  22891. value = map[key];
  22892. if (mayHaveChildren(value)) {
  22893. nodesToVisit.push(value);
  22894. }
  22895. }
  22896. } else if (isArray(node)) {
  22897. for (var i = 0, ii = node.length; i < ii; i++) {
  22898. value = node[i];
  22899. if (mayHaveChildren(value)) {
  22900. nodesToVisit.push(value);
  22901. }
  22902. }
  22903. }
  22904. }
  22905. function ObjectLoader(obj, keys, xref) {
  22906. this.obj = obj;
  22907. this.keys = keys;
  22908. this.xref = xref;
  22909. this.refSet = null;
  22910. this.capability = null;
  22911. }
  22912. ObjectLoader.prototype = {
  22913. load: function ObjectLoader_load() {
  22914. var keys = this.keys;
  22915. this.capability = createPromiseCapability();
  22916. // Don't walk the graph if all the data is already loaded.
  22917. if (!(this.xref.stream instanceof ChunkedStream) ||
  22918. this.xref.stream.getMissingChunks().length === 0) {
  22919. this.capability.resolve();
  22920. return this.capability.promise;
  22921. }
  22922. this.refSet = new RefSet();
  22923. // Setup the initial nodes to visit.
  22924. var nodesToVisit = [];
  22925. for (var i = 0; i < keys.length; i++) {
  22926. nodesToVisit.push(this.obj[keys[i]]);
  22927. }
  22928. this._walk(nodesToVisit);
  22929. return this.capability.promise;
  22930. },
  22931. _walk: function ObjectLoader_walk(nodesToVisit) {
  22932. var nodesToRevisit = [];
  22933. var pendingRequests = [];
  22934. // DFS walk of the object graph.
  22935. while (nodesToVisit.length) {
  22936. var currentNode = nodesToVisit.pop();
  22937. // Only references or chunked streams can cause missing data exceptions.
  22938. if (isRef(currentNode)) {
  22939. // Skip nodes that have already been visited.
  22940. if (this.refSet.has(currentNode)) {
  22941. continue;
  22942. }
  22943. try {
  22944. var ref = currentNode;
  22945. this.refSet.put(ref);
  22946. currentNode = this.xref.fetch(currentNode);
  22947. } catch (e) {
  22948. if (!(e instanceof MissingDataException)) {
  22949. throw e;
  22950. }
  22951. nodesToRevisit.push(currentNode);
  22952. pendingRequests.push({ begin: e.begin, end: e.end });
  22953. }
  22954. }
  22955. if (currentNode && currentNode.getBaseStreams) {
  22956. var baseStreams = currentNode.getBaseStreams();
  22957. var foundMissingData = false;
  22958. for (var i = 0; i < baseStreams.length; i++) {
  22959. var stream = baseStreams[i];
  22960. if (stream.getMissingChunks && stream.getMissingChunks().length) {
  22961. foundMissingData = true;
  22962. pendingRequests.push({
  22963. begin: stream.start,
  22964. end: stream.end
  22965. });
  22966. }
  22967. }
  22968. if (foundMissingData) {
  22969. nodesToRevisit.push(currentNode);
  22970. }
  22971. }
  22972. addChildren(currentNode, nodesToVisit);
  22973. }
  22974. if (pendingRequests.length) {
  22975. this.xref.stream.manager.requestRanges(pendingRequests).then(
  22976. function pendingRequestCallback() {
  22977. nodesToVisit = nodesToRevisit;
  22978. for (var i = 0; i < nodesToRevisit.length; i++) {
  22979. var node = nodesToRevisit[i];
  22980. // Remove any reference nodes from the currrent refset so they
  22981. // aren't skipped when we revist them.
  22982. if (isRef(node)) {
  22983. this.refSet.remove(node);
  22984. }
  22985. }
  22986. this._walk(nodesToVisit);
  22987. }.bind(this), this.capability.reject);
  22988. return;
  22989. }
  22990. // Everything is loaded.
  22991. this.refSet = null;
  22992. this.capability.resolve();
  22993. }
  22994. };
  22995. return ObjectLoader;
  22996. })();
  22997. exports.Catalog = Catalog;
  22998. exports.ObjectLoader = ObjectLoader;
  22999. exports.XRef = XRef;
  23000. }));
  23001. (function (root, factory) {
  23002. {
  23003. factory((root.pdfjsCorePsParser = {}), root.pdfjsSharedUtil,
  23004. root.pdfjsCoreParser);
  23005. }
  23006. }(this, function (exports, sharedUtil, coreParser) {
  23007. var error = sharedUtil.error;
  23008. var EOF = coreParser.EOF;
  23009. var Lexer = coreParser.Lexer;
  23010. var PostScriptParser = (function PostScriptParserClosure() {
  23011. function PostScriptParser(lexer) {
  23012. this.lexer = lexer;
  23013. this.operators = [];
  23014. this.token = null;
  23015. this.prev = null;
  23016. }
  23017. PostScriptParser.prototype = {
  23018. nextToken: function PostScriptParser_nextToken() {
  23019. this.prev = this.token;
  23020. this.token = this.lexer.getToken();
  23021. },
  23022. accept: function PostScriptParser_accept(type) {
  23023. if (this.token.type === type) {
  23024. this.nextToken();
  23025. return true;
  23026. }
  23027. return false;
  23028. },
  23029. expect: function PostScriptParser_expect(type) {
  23030. if (this.accept(type)) {
  23031. return true;
  23032. }
  23033. error('Unexpected symbol: found ' + this.token.type + ' expected ' +
  23034. type + '.');
  23035. },
  23036. parse: function PostScriptParser_parse() {
  23037. this.nextToken();
  23038. this.expect(PostScriptTokenTypes.LBRACE);
  23039. this.parseBlock();
  23040. this.expect(PostScriptTokenTypes.RBRACE);
  23041. return this.operators;
  23042. },
  23043. parseBlock: function PostScriptParser_parseBlock() {
  23044. while (true) {
  23045. if (this.accept(PostScriptTokenTypes.NUMBER)) {
  23046. this.operators.push(this.prev.value);
  23047. } else if (this.accept(PostScriptTokenTypes.OPERATOR)) {
  23048. this.operators.push(this.prev.value);
  23049. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  23050. this.parseCondition();
  23051. } else {
  23052. return;
  23053. }
  23054. }
  23055. },
  23056. parseCondition: function PostScriptParser_parseCondition() {
  23057. // Add two place holders that will be updated later
  23058. var conditionLocation = this.operators.length;
  23059. this.operators.push(null, null);
  23060. this.parseBlock();
  23061. this.expect(PostScriptTokenTypes.RBRACE);
  23062. if (this.accept(PostScriptTokenTypes.IF)) {
  23063. // The true block is right after the 'if' so it just falls through on
  23064. // true else it jumps and skips the true block.
  23065. this.operators[conditionLocation] = this.operators.length;
  23066. this.operators[conditionLocation + 1] = 'jz';
  23067. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  23068. var jumpLocation = this.operators.length;
  23069. this.operators.push(null, null);
  23070. var endOfTrue = this.operators.length;
  23071. this.parseBlock();
  23072. this.expect(PostScriptTokenTypes.RBRACE);
  23073. this.expect(PostScriptTokenTypes.IFELSE);
  23074. // The jump is added at the end of the true block to skip the false
  23075. // block.
  23076. this.operators[jumpLocation] = this.operators.length;
  23077. this.operators[jumpLocation + 1] = 'j';
  23078. this.operators[conditionLocation] = endOfTrue;
  23079. this.operators[conditionLocation + 1] = 'jz';
  23080. } else {
  23081. error('PS Function: error parsing conditional.');
  23082. }
  23083. }
  23084. };
  23085. return PostScriptParser;
  23086. })();
  23087. var PostScriptTokenTypes = {
  23088. LBRACE: 0,
  23089. RBRACE: 1,
  23090. NUMBER: 2,
  23091. OPERATOR: 3,
  23092. IF: 4,
  23093. IFELSE: 5
  23094. };
  23095. var PostScriptToken = (function PostScriptTokenClosure() {
  23096. function PostScriptToken(type, value) {
  23097. this.type = type;
  23098. this.value = value;
  23099. }
  23100. var opCache = {};
  23101. PostScriptToken.getOperator = function PostScriptToken_getOperator(op) {
  23102. var opValue = opCache[op];
  23103. if (opValue) {
  23104. return opValue;
  23105. }
  23106. return opCache[op] = new PostScriptToken(PostScriptTokenTypes.OPERATOR, op);
  23107. };
  23108. PostScriptToken.LBRACE = new PostScriptToken(PostScriptTokenTypes.LBRACE,
  23109. '{');
  23110. PostScriptToken.RBRACE = new PostScriptToken(PostScriptTokenTypes.RBRACE,
  23111. '}');
  23112. PostScriptToken.IF = new PostScriptToken(PostScriptTokenTypes.IF, 'IF');
  23113. PostScriptToken.IFELSE = new PostScriptToken(PostScriptTokenTypes.IFELSE,
  23114. 'IFELSE');
  23115. return PostScriptToken;
  23116. })();
  23117. var PostScriptLexer = (function PostScriptLexerClosure() {
  23118. function PostScriptLexer(stream) {
  23119. this.stream = stream;
  23120. this.nextChar();
  23121. this.strBuf = [];
  23122. }
  23123. PostScriptLexer.prototype = {
  23124. nextChar: function PostScriptLexer_nextChar() {
  23125. return (this.currentChar = this.stream.getByte());
  23126. },
  23127. getToken: function PostScriptLexer_getToken() {
  23128. var comment = false;
  23129. var ch = this.currentChar;
  23130. // skip comments
  23131. while (true) {
  23132. if (ch < 0) {
  23133. return EOF;
  23134. }
  23135. if (comment) {
  23136. if (ch === 0x0A || ch === 0x0D) {
  23137. comment = false;
  23138. }
  23139. } else if (ch === 0x25) { // '%'
  23140. comment = true;
  23141. } else if (!Lexer.isSpace(ch)) {
  23142. break;
  23143. }
  23144. ch = this.nextChar();
  23145. }
  23146. switch (ch | 0) {
  23147. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  23148. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  23149. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  23150. return new PostScriptToken(PostScriptTokenTypes.NUMBER,
  23151. this.getNumber());
  23152. case 0x7B: // '{'
  23153. this.nextChar();
  23154. return PostScriptToken.LBRACE;
  23155. case 0x7D: // '}'
  23156. this.nextChar();
  23157. return PostScriptToken.RBRACE;
  23158. }
  23159. // operator
  23160. var strBuf = this.strBuf;
  23161. strBuf.length = 0;
  23162. strBuf[0] = String.fromCharCode(ch);
  23163. while ((ch = this.nextChar()) >= 0 && // and 'A'-'Z', 'a'-'z'
  23164. ((ch >= 0x41 && ch <= 0x5A) || (ch >= 0x61 && ch <= 0x7A))) {
  23165. strBuf.push(String.fromCharCode(ch));
  23166. }
  23167. var str = strBuf.join('');
  23168. switch (str.toLowerCase()) {
  23169. case 'if':
  23170. return PostScriptToken.IF;
  23171. case 'ifelse':
  23172. return PostScriptToken.IFELSE;
  23173. default:
  23174. return PostScriptToken.getOperator(str);
  23175. }
  23176. },
  23177. getNumber: function PostScriptLexer_getNumber() {
  23178. var ch = this.currentChar;
  23179. var strBuf = this.strBuf;
  23180. strBuf.length = 0;
  23181. strBuf[0] = String.fromCharCode(ch);
  23182. while ((ch = this.nextChar()) >= 0) {
  23183. if ((ch >= 0x30 && ch <= 0x39) || // '0'-'9'
  23184. ch === 0x2D || ch === 0x2E) { // '-', '.'
  23185. strBuf.push(String.fromCharCode(ch));
  23186. } else {
  23187. break;
  23188. }
  23189. }
  23190. var value = parseFloat(strBuf.join(''));
  23191. if (isNaN(value)) {
  23192. error('Invalid floating point number: ' + value);
  23193. }
  23194. return value;
  23195. }
  23196. };
  23197. return PostScriptLexer;
  23198. })();
  23199. exports.PostScriptLexer = PostScriptLexer;
  23200. exports.PostScriptParser = PostScriptParser;
  23201. }));
  23202. (function (root, factory) {
  23203. {
  23204. factory((root.pdfjsCoreFonts = {}), root.pdfjsSharedUtil,
  23205. root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreParser,
  23206. root.pdfjsCoreCMap, root.pdfjsCoreGlyphList, root.pdfjsCoreCharsets,
  23207. root.pdfjsCoreFontRenderer);
  23208. }
  23209. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreParser,
  23210. coreCMap, coreGlyphList, coreCharsets, coreFontRenderer) {
  23211. var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
  23212. var FontType = sharedUtil.FontType;
  23213. var Util = sharedUtil.Util;
  23214. var assert = sharedUtil.assert;
  23215. var bytesToString = sharedUtil.bytesToString;
  23216. var error = sharedUtil.error;
  23217. var info = sharedUtil.info;
  23218. var isArray = sharedUtil.isArray;
  23219. var isInt = sharedUtil.isInt;
  23220. var isNum = sharedUtil.isNum;
  23221. var readUint32 = sharedUtil.readUint32;
  23222. var shadow = sharedUtil.shadow;
  23223. var stringToBytes = sharedUtil.stringToBytes;
  23224. var string32 = sharedUtil.string32;
  23225. var warn = sharedUtil.warn;
  23226. var Name = corePrimitives.Name;
  23227. var Stream = coreStream.Stream;
  23228. var Lexer = coreParser.Lexer;
  23229. var CMapFactory = coreCMap.CMapFactory;
  23230. var IdentityCMap = coreCMap.IdentityCMap;
  23231. var GlyphsUnicode = coreGlyphList.GlyphsUnicode;
  23232. var DingbatsGlyphsUnicode = coreGlyphList.DingbatsGlyphsUnicode;
  23233. var ISOAdobeCharset = coreCharsets.ISOAdobeCharset;
  23234. var ExpertCharset = coreCharsets.ExpertCharset;
  23235. var ExpertSubsetCharset = coreCharsets.ExpertSubsetCharset;
  23236. var FontRendererFactory = coreFontRenderer.FontRendererFactory;
  23237. // Unicode Private Use Area
  23238. var PRIVATE_USE_OFFSET_START = 0xE000;
  23239. var PRIVATE_USE_OFFSET_END = 0xF8FF;
  23240. var SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = false;
  23241. // PDF Glyph Space Units are one Thousandth of a TextSpace Unit
  23242. // except for Type 3 fonts
  23243. var PDF_GLYPH_SPACE_UNITS = 1000;
  23244. // Hinting is currently disabled due to unknown problems on windows
  23245. // in tracemonkey and various other pdfs with type1 fonts.
  23246. var HINTING_ENABLED = false;
  23247. // Accented charactars are not displayed properly on windows, using this flag
  23248. // to control analysis of seac charstrings.
  23249. var SEAC_ANALYSIS_ENABLED = false;
  23250. // Maximum subroutine call depth of type 2 chartrings. Matches OTS.
  23251. var MAX_SUBR_NESTING = 10;
  23252. var FontFlags = {
  23253. FixedPitch: 1,
  23254. Serif: 2,
  23255. Symbolic: 4,
  23256. Script: 8,
  23257. Nonsymbolic: 32,
  23258. Italic: 64,
  23259. AllCap: 65536,
  23260. SmallCap: 131072,
  23261. ForceBold: 262144
  23262. };
  23263. var Encodings = {
  23264. ExpertEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  23265. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  23266. 'space', 'exclamsmall', 'Hungarumlautsmall', '', 'dollaroldstyle',
  23267. 'dollarsuperior', 'ampersandsmall', 'Acutesmall', 'parenleftsuperior',
  23268. 'parenrightsuperior', 'twodotenleader', 'onedotenleader', 'comma',
  23269. 'hyphen', 'period', 'fraction', 'zerooldstyle', 'oneoldstyle',
  23270. 'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle',
  23271. 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'colon',
  23272. 'semicolon', 'commasuperior', 'threequartersemdash', 'periodsuperior',
  23273. 'questionsmall', '', 'asuperior', 'bsuperior', 'centsuperior', 'dsuperior',
  23274. 'esuperior', '', '', 'isuperior', '', '', 'lsuperior', 'msuperior',
  23275. 'nsuperior', 'osuperior', '', '', 'rsuperior', 'ssuperior', 'tsuperior',
  23276. '', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior', '',
  23277. 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall',
  23278. 'Asmall', 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall',
  23279. 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall',
  23280. 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall',
  23281. 'Vsmall', 'Wsmall', 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary',
  23282. 'onefitted', 'rupiah', 'Tildesmall', '', '', '', '', '', '', '', '', '',
  23283. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  23284. '', '', '', '', '', '', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall',
  23285. '', '', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall',
  23286. 'Caronsmall', '', 'Dotaccentsmall', '', '', 'Macronsmall', '', '',
  23287. 'figuredash', 'hypheninferior', '', '', 'Ogoneksmall', 'Ringsmall',
  23288. 'Cedillasmall', '', '', '', 'onequarter', 'onehalf', 'threequarters',
  23289. 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths',
  23290. 'seveneighths', 'onethird', 'twothirds', '', '', 'zerosuperior',
  23291. 'onesuperior', 'twosuperior', 'threesuperior', 'foursuperior',
  23292. 'fivesuperior', 'sixsuperior', 'sevensuperior', 'eightsuperior',
  23293. 'ninesuperior', 'zeroinferior', 'oneinferior', 'twoinferior',
  23294. 'threeinferior', 'fourinferior', 'fiveinferior', 'sixinferior',
  23295. 'seveninferior', 'eightinferior', 'nineinferior', 'centinferior',
  23296. 'dollarinferior', 'periodinferior', 'commainferior', 'Agravesmall',
  23297. 'Aacutesmall', 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall',
  23298. 'Aringsmall', 'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall',
  23299. 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall',
  23300. 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall',
  23301. 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall',
  23302. 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall',
  23303. 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall',
  23304. 'Ydieresissmall'],
  23305. MacExpertEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  23306. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  23307. 'space', 'exclamsmall', 'Hungarumlautsmall', 'centoldstyle',
  23308. 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall', 'Acutesmall',
  23309. 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  23310. 'onedotenleader', 'comma', 'hyphen', 'period', 'fraction', 'zerooldstyle',
  23311. 'oneoldstyle', 'twooldstyle', 'threeoldstyle', 'fouroldstyle',
  23312. 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle',
  23313. 'nineoldstyle', 'colon', 'semicolon', '', 'threequartersemdash', '',
  23314. 'questionsmall', '', '', '', '', 'Ethsmall', '', '', 'onequarter',
  23315. 'onehalf', 'threequarters', 'oneeighth', 'threeeighths', 'fiveeighths',
  23316. 'seveneighths', 'onethird', 'twothirds', '', '', '', '', '', '', 'ff',
  23317. 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior', '', 'parenrightinferior',
  23318. 'Circumflexsmall', 'hypheninferior', 'Gravesmall', 'Asmall', 'Bsmall',
  23319. 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall',
  23320. 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall',
  23321. 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
  23322. 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah',
  23323. 'Tildesmall', '', '', 'asuperior', 'centsuperior', '', '', '', '',
  23324. 'Aacutesmall', 'Agravesmall', 'Acircumflexsmall', 'Adieresissmall',
  23325. 'Atildesmall', 'Aringsmall', 'Ccedillasmall', 'Eacutesmall', 'Egravesmall',
  23326. 'Ecircumflexsmall', 'Edieresissmall', 'Iacutesmall', 'Igravesmall',
  23327. 'Icircumflexsmall', 'Idieresissmall', 'Ntildesmall', 'Oacutesmall',
  23328. 'Ogravesmall', 'Ocircumflexsmall', 'Odieresissmall', 'Otildesmall',
  23329. 'Uacutesmall', 'Ugravesmall', 'Ucircumflexsmall', 'Udieresissmall', '',
  23330. 'eightsuperior', 'fourinferior', 'threeinferior', 'sixinferior',
  23331. 'eightinferior', 'seveninferior', 'Scaronsmall', '', 'centinferior',
  23332. 'twoinferior', '', 'Dieresissmall', '', 'Caronsmall', 'osuperior',
  23333. 'fiveinferior', '', 'commainferior', 'periodinferior', 'Yacutesmall', '',
  23334. 'dollarinferior', '', 'Thornsmall', '', 'nineinferior', 'zeroinferior',
  23335. 'Zcaronsmall', 'AEsmall', 'Oslashsmall', 'questiondownsmall',
  23336. 'oneinferior', 'Lslashsmall', '', '', '', '', '', '', 'Cedillasmall', '',
  23337. '', '', '', '', 'OEsmall', 'figuredash', 'hyphensuperior', '', '', '', '',
  23338. 'exclamdownsmall', '', 'Ydieresissmall', '', 'onesuperior', 'twosuperior',
  23339. 'threesuperior', 'foursuperior', 'fivesuperior', 'sixsuperior',
  23340. 'sevensuperior', 'ninesuperior', 'zerosuperior', '', 'esuperior',
  23341. 'rsuperior', 'tsuperior', '', '', 'isuperior', 'ssuperior', 'dsuperior',
  23342. '', '', '', '', '', 'lsuperior', 'Ogoneksmall', 'Brevesmall',
  23343. 'Macronsmall', 'bsuperior', 'nsuperior', 'msuperior', 'commasuperior',
  23344. 'periodsuperior', 'Dotaccentsmall', 'Ringsmall'],
  23345. MacRomanEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  23346. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  23347. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  23348. 'ampersand', 'quotesingle', 'parenleft', 'parenright', 'asterisk', 'plus',
  23349. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  23350. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  23351. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  23352. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  23353. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  23354. 'asciicircum', 'underscore', 'grave', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
  23355. 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
  23356. 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', '',
  23357. 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde', 'Odieresis',
  23358. 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis', 'atilde',
  23359. 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  23360. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute',
  23361. 'ograve', 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave',
  23362. 'ucircumflex', 'udieresis', 'dagger', 'degree', 'cent', 'sterling',
  23363. 'section', 'bullet', 'paragraph', 'germandbls', 'registered', 'copyright',
  23364. 'trademark', 'acute', 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity',
  23365. 'plusminus', 'lessequal', 'greaterequal', 'yen', 'mu', 'partialdiff',
  23366. 'summation', 'product', 'pi', 'integral', 'ordfeminine', 'ordmasculine',
  23367. 'Omega', 'ae', 'oslash', 'questiondown', 'exclamdown', 'logicalnot',
  23368. 'radical', 'florin', 'approxequal', 'Delta', 'guillemotleft',
  23369. 'guillemotright', 'ellipsis', 'space', 'Agrave', 'Atilde', 'Otilde', 'OE',
  23370. 'oe', 'endash', 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft',
  23371. 'quoteright', 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction',
  23372. 'currency', 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl',
  23373. 'periodcentered', 'quotesinglbase', 'quotedblbase', 'perthousand',
  23374. 'Acircumflex', 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute',
  23375. 'Icircumflex', 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple',
  23376. 'Ograve', 'Uacute', 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex',
  23377. 'tilde', 'macron', 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut',
  23378. 'ogonek', 'caron'],
  23379. StandardEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  23380. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  23381. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  23382. 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus',
  23383. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  23384. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  23385. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  23386. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  23387. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  23388. 'asciicircum', 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f',
  23389. 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u',
  23390. 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde',
  23391. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  23392. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', 'exclamdown',
  23393. 'cent', 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  23394. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  23395. 'guilsinglright', 'fi', 'fl', '', 'endash', 'dagger', 'daggerdbl',
  23396. 'periodcentered', '', 'paragraph', 'bullet', 'quotesinglbase',
  23397. 'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis',
  23398. 'perthousand', '', 'questiondown', '', 'grave', 'acute', 'circumflex',
  23399. 'tilde', 'macron', 'breve', 'dotaccent', 'dieresis', '', 'ring', 'cedilla',
  23400. '', 'hungarumlaut', 'ogonek', 'caron', 'emdash', '', '', '', '', '', '',
  23401. '', '', '', '', '', '', '', '', '', '', 'AE', '', 'ordfeminine', '', '',
  23402. '', '', 'Lslash', 'Oslash', 'OE', 'ordmasculine', '', '', '', '', '', 'ae',
  23403. '', '', '', 'dotlessi', '', '', 'lslash', 'oslash', 'oe', 'germandbls'],
  23404. WinAnsiEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  23405. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  23406. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  23407. 'ampersand', 'quotesingle', 'parenleft', 'parenright', 'asterisk', 'plus',
  23408. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  23409. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  23410. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  23411. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  23412. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  23413. 'asciicircum', 'underscore', 'grave', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
  23414. 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
  23415. 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde',
  23416. 'bullet', 'Euro', 'bullet', 'quotesinglbase', 'florin', 'quotedblbase',
  23417. 'ellipsis', 'dagger', 'daggerdbl', 'circumflex', 'perthousand', 'Scaron',
  23418. 'guilsinglleft', 'OE', 'bullet', 'Zcaron', 'bullet', 'bullet', 'quoteleft',
  23419. 'quoteright', 'quotedblleft', 'quotedblright', 'bullet', 'endash',
  23420. 'emdash', 'tilde', 'trademark', 'scaron', 'guilsinglright', 'oe', 'bullet',
  23421. 'zcaron', 'Ydieresis', 'space', 'exclamdown', 'cent', 'sterling',
  23422. 'currency', 'yen', 'brokenbar', 'section', 'dieresis', 'copyright',
  23423. 'ordfeminine', 'guillemotleft', 'logicalnot', 'hyphen', 'registered',
  23424. 'macron', 'degree', 'plusminus', 'twosuperior', 'threesuperior', 'acute',
  23425. 'mu', 'paragraph', 'periodcentered', 'cedilla', 'onesuperior',
  23426. 'ordmasculine', 'guillemotright', 'onequarter', 'onehalf', 'threequarters',
  23427. 'questiondown', 'Agrave', 'Aacute', 'Acircumflex', 'Atilde', 'Adieresis',
  23428. 'Aring', 'AE', 'Ccedilla', 'Egrave', 'Eacute', 'Ecircumflex', 'Edieresis',
  23429. 'Igrave', 'Iacute', 'Icircumflex', 'Idieresis', 'Eth', 'Ntilde', 'Ograve',
  23430. 'Oacute', 'Ocircumflex', 'Otilde', 'Odieresis', 'multiply', 'Oslash',
  23431. 'Ugrave', 'Uacute', 'Ucircumflex', 'Udieresis', 'Yacute', 'Thorn',
  23432. 'germandbls', 'agrave', 'aacute', 'acircumflex', 'atilde', 'adieresis',
  23433. 'aring', 'ae', 'ccedilla', 'egrave', 'eacute', 'ecircumflex', 'edieresis',
  23434. 'igrave', 'iacute', 'icircumflex', 'idieresis', 'eth', 'ntilde', 'ograve',
  23435. 'oacute', 'ocircumflex', 'otilde', 'odieresis', 'divide', 'oslash',
  23436. 'ugrave', 'uacute', 'ucircumflex', 'udieresis', 'yacute', 'thorn',
  23437. 'ydieresis'],
  23438. SymbolSetEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  23439. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  23440. 'space', 'exclam', 'universal', 'numbersign', 'existential', 'percent',
  23441. 'ampersand', 'suchthat', 'parenleft', 'parenright', 'asteriskmath', 'plus',
  23442. 'comma', 'minus', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
  23443. 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',
  23444. 'equal', 'greater', 'question', 'congruent', 'Alpha', 'Beta', 'Chi',
  23445. 'Delta', 'Epsilon', 'Phi', 'Gamma', 'Eta', 'Iota', 'theta1', 'Kappa',
  23446. 'Lambda', 'Mu', 'Nu', 'Omicron', 'Pi', 'Theta', 'Rho', 'Sigma', 'Tau',
  23447. 'Upsilon', 'sigma1', 'Omega', 'Xi', 'Psi', 'Zeta', 'bracketleft',
  23448. 'therefore', 'bracketright', 'perpendicular', 'underscore', 'radicalex',
  23449. 'alpha', 'beta', 'chi', 'delta', 'epsilon', 'phi', 'gamma', 'eta', 'iota',
  23450. 'phi1', 'kappa', 'lambda', 'mu', 'nu', 'omicron', 'pi', 'theta', 'rho',
  23451. 'sigma', 'tau', 'upsilon', 'omega1', 'omega', 'xi', 'psi', 'zeta',
  23452. 'braceleft', 'bar', 'braceright', 'similar', '', '', '', '', '', '', '',
  23453. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  23454. '', '', '', '', '', '', '', 'Euro', 'Upsilon1', 'minute', 'lessequal',
  23455. 'fraction', 'infinity', 'florin', 'club', 'diamond', 'heart', 'spade',
  23456. 'arrowboth', 'arrowleft', 'arrowup', 'arrowright', 'arrowdown', 'degree',
  23457. 'plusminus', 'second', 'greaterequal', 'multiply', 'proportional',
  23458. 'partialdiff', 'bullet', 'divide', 'notequal', 'equivalence',
  23459. 'approxequal', 'ellipsis', 'arrowvertex', 'arrowhorizex', 'carriagereturn',
  23460. 'aleph', 'Ifraktur', 'Rfraktur', 'weierstrass', 'circlemultiply',
  23461. 'circleplus', 'emptyset', 'intersection', 'union', 'propersuperset',
  23462. 'reflexsuperset', 'notsubset', 'propersubset', 'reflexsubset', 'element',
  23463. 'notelement', 'angle', 'gradient', 'registerserif', 'copyrightserif',
  23464. 'trademarkserif', 'product', 'radical', 'dotmath', 'logicalnot',
  23465. 'logicaland', 'logicalor', 'arrowdblboth', 'arrowdblleft', 'arrowdblup',
  23466. 'arrowdblright', 'arrowdbldown', 'lozenge', 'angleleft', 'registersans',
  23467. 'copyrightsans', 'trademarksans', 'summation', 'parenlefttp',
  23468. 'parenleftex', 'parenleftbt', 'bracketlefttp', 'bracketleftex',
  23469. 'bracketleftbt', 'bracelefttp', 'braceleftmid', 'braceleftbt', 'braceex',
  23470. '', 'angleright', 'integral', 'integraltp', 'integralex', 'integralbt',
  23471. 'parenrighttp', 'parenrightex', 'parenrightbt', 'bracketrighttp',
  23472. 'bracketrightex', 'bracketrightbt', 'bracerighttp', 'bracerightmid',
  23473. 'bracerightbt'],
  23474. ZapfDingbatsEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  23475. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  23476. 'space', 'a1', 'a2', 'a202', 'a3', 'a4', 'a5', 'a119', 'a118', 'a117',
  23477. 'a11', 'a12', 'a13', 'a14', 'a15', 'a16', 'a105', 'a17', 'a18', 'a19',
  23478. 'a20', 'a21', 'a22', 'a23', 'a24', 'a25', 'a26', 'a27', 'a28', 'a6', 'a7',
  23479. 'a8', 'a9', 'a10', 'a29', 'a30', 'a31', 'a32', 'a33', 'a34', 'a35', 'a36',
  23480. 'a37', 'a38', 'a39', 'a40', 'a41', 'a42', 'a43', 'a44', 'a45', 'a46',
  23481. 'a47', 'a48', 'a49', 'a50', 'a51', 'a52', 'a53', 'a54', 'a55', 'a56',
  23482. 'a57', 'a58', 'a59', 'a60', 'a61', 'a62', 'a63', 'a64', 'a65', 'a66',
  23483. 'a67', 'a68', 'a69', 'a70', 'a71', 'a72', 'a73', 'a74', 'a203', 'a75',
  23484. 'a204', 'a76', 'a77', 'a78', 'a79', 'a81', 'a82', 'a83', 'a84', 'a97',
  23485. 'a98', 'a99', 'a100', '', 'a89', 'a90', 'a93', 'a94', 'a91', 'a92', 'a205',
  23486. 'a85', 'a206', 'a86', 'a87', 'a88', 'a95', 'a96', '', '', '', '', '', '',
  23487. '', '', '', '', '', '', '', '', '', '', '', '', '', 'a101', 'a102', 'a103',
  23488. 'a104', 'a106', 'a107', 'a108', 'a112', 'a111', 'a110', 'a109', 'a120',
  23489. 'a121', 'a122', 'a123', 'a124', 'a125', 'a126', 'a127', 'a128', 'a129',
  23490. 'a130', 'a131', 'a132', 'a133', 'a134', 'a135', 'a136', 'a137', 'a138',
  23491. 'a139', 'a140', 'a141', 'a142', 'a143', 'a144', 'a145', 'a146', 'a147',
  23492. 'a148', 'a149', 'a150', 'a151', 'a152', 'a153', 'a154', 'a155', 'a156',
  23493. 'a157', 'a158', 'a159', 'a160', 'a161', 'a163', 'a164', 'a196', 'a165',
  23494. 'a192', 'a166', 'a167', 'a168', 'a169', 'a170', 'a171', 'a172', 'a173',
  23495. 'a162', 'a174', 'a175', 'a176', 'a177', 'a178', 'a179', 'a193', 'a180',
  23496. 'a199', 'a181', 'a200', 'a182', '', 'a201', 'a183', 'a184', 'a197', 'a185',
  23497. 'a194', 'a198', 'a186', 'a195', 'a187', 'a188', 'a189', 'a190', 'a191']
  23498. };
  23499. /**
  23500. * Hold a map of decoded fonts and of the standard fourteen Type1
  23501. * fonts and their acronyms.
  23502. */
  23503. var stdFontMap = {
  23504. 'ArialNarrow': 'Helvetica',
  23505. 'ArialNarrow-Bold': 'Helvetica-Bold',
  23506. 'ArialNarrow-BoldItalic': 'Helvetica-BoldOblique',
  23507. 'ArialNarrow-Italic': 'Helvetica-Oblique',
  23508. 'ArialBlack': 'Helvetica',
  23509. 'ArialBlack-Bold': 'Helvetica-Bold',
  23510. 'ArialBlack-BoldItalic': 'Helvetica-BoldOblique',
  23511. 'ArialBlack-Italic': 'Helvetica-Oblique',
  23512. 'Arial': 'Helvetica',
  23513. 'Arial-Bold': 'Helvetica-Bold',
  23514. 'Arial-BoldItalic': 'Helvetica-BoldOblique',
  23515. 'Arial-Italic': 'Helvetica-Oblique',
  23516. 'Arial-BoldItalicMT': 'Helvetica-BoldOblique',
  23517. 'Arial-BoldMT': 'Helvetica-Bold',
  23518. 'Arial-ItalicMT': 'Helvetica-Oblique',
  23519. 'ArialMT': 'Helvetica',
  23520. 'Courier-Bold': 'Courier-Bold',
  23521. 'Courier-BoldItalic': 'Courier-BoldOblique',
  23522. 'Courier-Italic': 'Courier-Oblique',
  23523. 'CourierNew': 'Courier',
  23524. 'CourierNew-Bold': 'Courier-Bold',
  23525. 'CourierNew-BoldItalic': 'Courier-BoldOblique',
  23526. 'CourierNew-Italic': 'Courier-Oblique',
  23527. 'CourierNewPS-BoldItalicMT': 'Courier-BoldOblique',
  23528. 'CourierNewPS-BoldMT': 'Courier-Bold',
  23529. 'CourierNewPS-ItalicMT': 'Courier-Oblique',
  23530. 'CourierNewPSMT': 'Courier',
  23531. 'Helvetica': 'Helvetica',
  23532. 'Helvetica-Bold': 'Helvetica-Bold',
  23533. 'Helvetica-BoldItalic': 'Helvetica-BoldOblique',
  23534. 'Helvetica-BoldOblique': 'Helvetica-BoldOblique',
  23535. 'Helvetica-Italic': 'Helvetica-Oblique',
  23536. 'Helvetica-Oblique':'Helvetica-Oblique',
  23537. 'Symbol-Bold': 'Symbol',
  23538. 'Symbol-BoldItalic': 'Symbol',
  23539. 'Symbol-Italic': 'Symbol',
  23540. 'TimesNewRoman': 'Times-Roman',
  23541. 'TimesNewRoman-Bold': 'Times-Bold',
  23542. 'TimesNewRoman-BoldItalic': 'Times-BoldItalic',
  23543. 'TimesNewRoman-Italic': 'Times-Italic',
  23544. 'TimesNewRomanPS': 'Times-Roman',
  23545. 'TimesNewRomanPS-Bold': 'Times-Bold',
  23546. 'TimesNewRomanPS-BoldItalic': 'Times-BoldItalic',
  23547. 'TimesNewRomanPS-BoldItalicMT': 'Times-BoldItalic',
  23548. 'TimesNewRomanPS-BoldMT': 'Times-Bold',
  23549. 'TimesNewRomanPS-Italic': 'Times-Italic',
  23550. 'TimesNewRomanPS-ItalicMT': 'Times-Italic',
  23551. 'TimesNewRomanPSMT': 'Times-Roman',
  23552. 'TimesNewRomanPSMT-Bold': 'Times-Bold',
  23553. 'TimesNewRomanPSMT-BoldItalic': 'Times-BoldItalic',
  23554. 'TimesNewRomanPSMT-Italic': 'Times-Italic'
  23555. };
  23556. /**
  23557. * Holds the map of the non-standard fonts that might be included as a standard
  23558. * fonts without glyph data.
  23559. */
  23560. var nonStdFontMap = {
  23561. 'CenturyGothic': 'Helvetica',
  23562. 'CenturyGothic-Bold': 'Helvetica-Bold',
  23563. 'CenturyGothic-BoldItalic': 'Helvetica-BoldOblique',
  23564. 'CenturyGothic-Italic': 'Helvetica-Oblique',
  23565. 'ComicSansMS': 'Comic Sans MS',
  23566. 'ComicSansMS-Bold': 'Comic Sans MS-Bold',
  23567. 'ComicSansMS-BoldItalic': 'Comic Sans MS-BoldItalic',
  23568. 'ComicSansMS-Italic': 'Comic Sans MS-Italic',
  23569. 'LucidaConsole': 'Courier',
  23570. 'LucidaConsole-Bold': 'Courier-Bold',
  23571. 'LucidaConsole-BoldItalic': 'Courier-BoldOblique',
  23572. 'LucidaConsole-Italic': 'Courier-Oblique',
  23573. 'MS-Gothic': 'MS Gothic',
  23574. 'MS-Gothic-Bold': 'MS Gothic-Bold',
  23575. 'MS-Gothic-BoldItalic': 'MS Gothic-BoldItalic',
  23576. 'MS-Gothic-Italic': 'MS Gothic-Italic',
  23577. 'MS-Mincho': 'MS Mincho',
  23578. 'MS-Mincho-Bold': 'MS Mincho-Bold',
  23579. 'MS-Mincho-BoldItalic': 'MS Mincho-BoldItalic',
  23580. 'MS-Mincho-Italic': 'MS Mincho-Italic',
  23581. 'MS-PGothic': 'MS PGothic',
  23582. 'MS-PGothic-Bold': 'MS PGothic-Bold',
  23583. 'MS-PGothic-BoldItalic': 'MS PGothic-BoldItalic',
  23584. 'MS-PGothic-Italic': 'MS PGothic-Italic',
  23585. 'MS-PMincho': 'MS PMincho',
  23586. 'MS-PMincho-Bold': 'MS PMincho-Bold',
  23587. 'MS-PMincho-BoldItalic': 'MS PMincho-BoldItalic',
  23588. 'MS-PMincho-Italic': 'MS PMincho-Italic',
  23589. 'Wingdings': 'ZapfDingbats'
  23590. };
  23591. var serifFonts = {
  23592. 'Adobe Jenson': true, 'Adobe Text': true, 'Albertus': true,
  23593. 'Aldus': true, 'Alexandria': true, 'Algerian': true,
  23594. 'American Typewriter': true, 'Antiqua': true, 'Apex': true,
  23595. 'Arno': true, 'Aster': true, 'Aurora': true,
  23596. 'Baskerville': true, 'Bell': true, 'Bembo': true,
  23597. 'Bembo Schoolbook': true, 'Benguiat': true, 'Berkeley Old Style': true,
  23598. 'Bernhard Modern': true, 'Berthold City': true, 'Bodoni': true,
  23599. 'Bauer Bodoni': true, 'Book Antiqua': true, 'Bookman': true,
  23600. 'Bordeaux Roman': true, 'Californian FB': true, 'Calisto': true,
  23601. 'Calvert': true, 'Capitals': true, 'Cambria': true,
  23602. 'Cartier': true, 'Caslon': true, 'Catull': true,
  23603. 'Centaur': true, 'Century Old Style': true, 'Century Schoolbook': true,
  23604. 'Chaparral': true, 'Charis SIL': true, 'Cheltenham': true,
  23605. 'Cholla Slab': true, 'Clarendon': true, 'Clearface': true,
  23606. 'Cochin': true, 'Colonna': true, 'Computer Modern': true,
  23607. 'Concrete Roman': true, 'Constantia': true, 'Cooper Black': true,
  23608. 'Corona': true, 'Ecotype': true, 'Egyptienne': true,
  23609. 'Elephant': true, 'Excelsior': true, 'Fairfield': true,
  23610. 'FF Scala': true, 'Folkard': true, 'Footlight': true,
  23611. 'FreeSerif': true, 'Friz Quadrata': true, 'Garamond': true,
  23612. 'Gentium': true, 'Georgia': true, 'Gloucester': true,
  23613. 'Goudy Old Style': true, 'Goudy Schoolbook': true, 'Goudy Pro Font': true,
  23614. 'Granjon': true, 'Guardian Egyptian': true, 'Heather': true,
  23615. 'Hercules': true, 'High Tower Text': true, 'Hiroshige': true,
  23616. 'Hoefler Text': true, 'Humana Serif': true, 'Imprint': true,
  23617. 'Ionic No. 5': true, 'Janson': true, 'Joanna': true,
  23618. 'Korinna': true, 'Lexicon': true, 'Liberation Serif': true,
  23619. 'Linux Libertine': true, 'Literaturnaya': true, 'Lucida': true,
  23620. 'Lucida Bright': true, 'Melior': true, 'Memphis': true,
  23621. 'Miller': true, 'Minion': true, 'Modern': true,
  23622. 'Mona Lisa': true, 'Mrs Eaves': true, 'MS Serif': true,
  23623. 'Museo Slab': true, 'New York': true, 'Nimbus Roman': true,
  23624. 'NPS Rawlinson Roadway': true, 'Palatino': true, 'Perpetua': true,
  23625. 'Plantin': true, 'Plantin Schoolbook': true, 'Playbill': true,
  23626. 'Poor Richard': true, 'Rawlinson Roadway': true, 'Renault': true,
  23627. 'Requiem': true, 'Rockwell': true, 'Roman': true,
  23628. 'Rotis Serif': true, 'Sabon': true, 'Scala': true,
  23629. 'Seagull': true, 'Sistina': true, 'Souvenir': true,
  23630. 'STIX': true, 'Stone Informal': true, 'Stone Serif': true,
  23631. 'Sylfaen': true, 'Times': true, 'Trajan': true,
  23632. 'Trinité': true, 'Trump Mediaeval': true, 'Utopia': true,
  23633. 'Vale Type': true, 'Bitstream Vera': true, 'Vera Serif': true,
  23634. 'Versailles': true, 'Wanted': true, 'Weiss': true,
  23635. 'Wide Latin': true, 'Windsor': true, 'XITS': true
  23636. };
  23637. var symbolsFonts = {
  23638. 'Dingbats': true, 'Symbol': true, 'ZapfDingbats': true
  23639. };
  23640. // Glyph map for well-known standard fonts. Sometimes Ghostscript uses CID fonts
  23641. // but does not embed the CID to GID mapping. The mapping is incomplete for all
  23642. // glyphs, but common for some set of the standard fonts.
  23643. var GlyphMapForStandardFonts = {
  23644. '2': 10, '3': 32, '4': 33, '5': 34, '6': 35, '7': 36, '8': 37, '9': 38,
  23645. '10': 39, '11': 40, '12': 41, '13': 42, '14': 43, '15': 44, '16': 45,
  23646. '17': 46, '18': 47, '19': 48, '20': 49, '21': 50, '22': 51, '23': 52,
  23647. '24': 53, '25': 54, '26': 55, '27': 56, '28': 57, '29': 58, '30': 894,
  23648. '31': 60, '32': 61, '33': 62, '34': 63, '35': 64, '36': 65, '37': 66,
  23649. '38': 67, '39': 68, '40': 69, '41': 70, '42': 71, '43': 72, '44': 73,
  23650. '45': 74, '46': 75, '47': 76, '48': 77, '49': 78, '50': 79, '51': 80,
  23651. '52': 81, '53': 82, '54': 83, '55': 84, '56': 85, '57': 86, '58': 87,
  23652. '59': 88, '60': 89, '61': 90, '62': 91, '63': 92, '64': 93, '65': 94,
  23653. '66': 95, '67': 96, '68': 97, '69': 98, '70': 99, '71': 100, '72': 101,
  23654. '73': 102, '74': 103, '75': 104, '76': 105, '77': 106, '78': 107, '79': 108,
  23655. '80': 109, '81': 110, '82': 111, '83': 112, '84': 113, '85': 114, '86': 115,
  23656. '87': 116, '88': 117, '89': 118, '90': 119, '91': 120, '92': 121, '93': 122,
  23657. '94': 123, '95': 124, '96': 125, '97': 126, '98': 196, '99': 197, '100': 199,
  23658. '101': 201, '102': 209, '103': 214, '104': 220, '105': 225, '106': 224,
  23659. '107': 226, '108': 228, '109': 227, '110': 229, '111': 231, '112': 233,
  23660. '113': 232, '114': 234, '115': 235, '116': 237, '117': 236, '118': 238,
  23661. '119': 239, '120': 241, '121': 243, '122': 242, '123': 244, '124': 246,
  23662. '125': 245, '126': 250, '127': 249, '128': 251, '129': 252, '130': 8224,
  23663. '131': 176, '132': 162, '133': 163, '134': 167, '135': 8226, '136': 182,
  23664. '137': 223, '138': 174, '139': 169, '140': 8482, '141': 180, '142': 168,
  23665. '143': 8800, '144': 198, '145': 216, '146': 8734, '147': 177, '148': 8804,
  23666. '149': 8805, '150': 165, '151': 181, '152': 8706, '153': 8721, '154': 8719,
  23667. '156': 8747, '157': 170, '158': 186, '159': 8486, '160': 230, '161': 248,
  23668. '162': 191, '163': 161, '164': 172, '165': 8730, '166': 402, '167': 8776,
  23669. '168': 8710, '169': 171, '170': 187, '171': 8230, '210': 218, '223': 711,
  23670. '224': 321, '225': 322, '227': 353, '229': 382, '234': 253, '252': 263,
  23671. '253': 268, '254': 269, '258': 258, '260': 260, '261': 261, '265': 280,
  23672. '266': 281, '268': 283, '269': 313, '275': 323, '276': 324, '278': 328,
  23673. '284': 345, '285': 346, '286': 347, '292': 367, '295': 377, '296': 378,
  23674. '298': 380, '305': 963,
  23675. '306': 964, '307': 966, '308': 8215, '309': 8252, '310': 8319, '311': 8359,
  23676. '312': 8592, '313': 8593, '337': 9552, '493': 1039, '494': 1040, '705': 1524,
  23677. '706': 8362, '710': 64288, '711': 64298, '759': 1617, '761': 1776,
  23678. '763': 1778, '775': 1652, '777': 1764, '778': 1780, '779': 1781, '780': 1782,
  23679. '782': 771, '783': 64726, '786': 8363, '788': 8532, '790': 768, '791': 769,
  23680. '792': 768, '795': 803, '797': 64336, '798': 64337, '799': 64342,
  23681. '800': 64343, '801': 64344, '802': 64345, '803': 64362, '804': 64363,
  23682. '805': 64364, '2424': 7821, '2425': 7822, '2426': 7823, '2427': 7824,
  23683. '2428': 7825, '2429': 7826, '2430': 7827, '2433': 7682, '2678': 8045,
  23684. '2679': 8046, '2830': 1552, '2838': 686, '2840': 751, '2842': 753,
  23685. '2843': 754, '2844': 755, '2846': 757, '2856': 767, '2857': 848, '2858': 849,
  23686. '2862': 853, '2863': 854, '2864': 855, '2865': 861, '2866': 862, '2906': 7460,
  23687. '2908': 7462, '2909': 7463, '2910': 7464, '2912': 7466, '2913': 7467,
  23688. '2914': 7468, '2916': 7470, '2917': 7471, '2918': 7472, '2920': 7474,
  23689. '2921': 7475, '2922': 7476, '2924': 7478, '2925': 7479, '2926': 7480,
  23690. '2928': 7482, '2929': 7483, '2930': 7484, '2932': 7486, '2933': 7487,
  23691. '2934': 7488, '2936': 7490, '2937': 7491, '2938': 7492, '2940': 7494,
  23692. '2941': 7495, '2942': 7496, '2944': 7498, '2946': 7500, '2948': 7502,
  23693. '2950': 7504, '2951': 7505, '2952': 7506, '2954': 7508, '2955': 7509,
  23694. '2956': 7510, '2958': 7512, '2959': 7513, '2960': 7514, '2962': 7516,
  23695. '2963': 7517, '2964': 7518, '2966': 7520, '2967': 7521, '2968': 7522,
  23696. '2970': 7524, '2971': 7525, '2972': 7526, '2974': 7528, '2975': 7529,
  23697. '2976': 7530, '2978': 1537, '2979': 1538, '2980': 1539, '2982': 1549,
  23698. '2983': 1551, '2984': 1552, '2986': 1554, '2987': 1555, '2988': 1556,
  23699. '2990': 1623, '2991': 1624, '2995': 1775, '2999': 1791, '3002': 64290,
  23700. '3003': 64291, '3004': 64292, '3006': 64294, '3007': 64295, '3008': 64296,
  23701. '3011': 1900, '3014': 8223, '3015': 8244, '3017': 7532, '3018': 7533,
  23702. '3019': 7534, '3075': 7590, '3076': 7591, '3079': 7594, '3080': 7595,
  23703. '3083': 7598, '3084': 7599, '3087': 7602, '3088': 7603, '3091': 7606,
  23704. '3092': 7607, '3095': 7610, '3096': 7611, '3099': 7614, '3100': 7615,
  23705. '3103': 7618, '3104': 7619, '3107': 8337, '3108': 8338, '3116': 1884,
  23706. '3119': 1885, '3120': 1885, '3123': 1886, '3124': 1886, '3127': 1887,
  23707. '3128': 1887, '3131': 1888, '3132': 1888, '3135': 1889, '3136': 1889,
  23708. '3139': 1890, '3140': 1890, '3143': 1891, '3144': 1891, '3147': 1892,
  23709. '3148': 1892, '3153': 580, '3154': 581, '3157': 584, '3158': 585, '3161': 588,
  23710. '3162': 589, '3165': 891, '3166': 892, '3169': 1274, '3170': 1275,
  23711. '3173': 1278, '3174': 1279, '3181': 7622, '3182': 7623, '3282': 11799,
  23712. '3316': 578, '3379': 42785, '3393': 1159, '3416': 8377
  23713. };
  23714. // The glyph map for ArialBlack differs slightly from the glyph map used for
  23715. // other well-known standard fonts. Hence we use this (incomplete) CID to GID
  23716. // mapping to adjust the glyph map for non-embedded ArialBlack fonts.
  23717. var SupplementalGlyphMapForArialBlack = {
  23718. '227': 322, '264': 261, '291': 346,
  23719. };
  23720. // Some characters, e.g. copyrightserif, are mapped to the private use area and
  23721. // might not be displayed using standard fonts. Mapping/hacking well-known chars
  23722. // to the similar equivalents in the normal characters range.
  23723. var SpecialPUASymbols = {
  23724. '63721': 0x00A9, // copyrightsans (0xF8E9) => copyright
  23725. '63193': 0x00A9, // copyrightserif (0xF6D9) => copyright
  23726. '63720': 0x00AE, // registersans (0xF8E8) => registered
  23727. '63194': 0x00AE, // registerserif (0xF6DA) => registered
  23728. '63722': 0x2122, // trademarksans (0xF8EA) => trademark
  23729. '63195': 0x2122, // trademarkserif (0xF6DB) => trademark
  23730. '63729': 0x23A7, // bracelefttp (0xF8F1)
  23731. '63730': 0x23A8, // braceleftmid (0xF8F2)
  23732. '63731': 0x23A9, // braceleftbt (0xF8F3)
  23733. '63740': 0x23AB, // bracerighttp (0xF8FC)
  23734. '63741': 0x23AC, // bracerightmid (0xF8FD)
  23735. '63742': 0x23AD, // bracerightbt (0xF8FE)
  23736. '63726': 0x23A1, // bracketlefttp (0xF8EE)
  23737. '63727': 0x23A2, // bracketleftex (0xF8EF)
  23738. '63728': 0x23A3, // bracketleftbt (0xF8F0)
  23739. '63737': 0x23A4, // bracketrighttp (0xF8F9)
  23740. '63738': 0x23A5, // bracketrightex (0xF8FA)
  23741. '63739': 0x23A6, // bracketrightbt (0xF8FB)
  23742. '63723': 0x239B, // parenlefttp (0xF8EB)
  23743. '63724': 0x239C, // parenleftex (0xF8EC)
  23744. '63725': 0x239D, // parenleftbt (0xF8ED)
  23745. '63734': 0x239E, // parenrighttp (0xF8F6)
  23746. '63735': 0x239F, // parenrightex (0xF8F7)
  23747. '63736': 0x23A0, // parenrightbt (0xF8F8)
  23748. };
  23749. function mapSpecialUnicodeValues(code) {
  23750. if (code >= 0xFFF0 && code <= 0xFFFF) { // Specials unicode block.
  23751. return 0;
  23752. } else if (code >= 0xF600 && code <= 0xF8FF) {
  23753. return (SpecialPUASymbols[code] || code);
  23754. }
  23755. return code;
  23756. }
  23757. var UnicodeRanges = [
  23758. { 'begin': 0x0000, 'end': 0x007F }, // Basic Latin
  23759. { 'begin': 0x0080, 'end': 0x00FF }, // Latin-1 Supplement
  23760. { 'begin': 0x0100, 'end': 0x017F }, // Latin Extended-A
  23761. { 'begin': 0x0180, 'end': 0x024F }, // Latin Extended-B
  23762. { 'begin': 0x0250, 'end': 0x02AF }, // IPA Extensions
  23763. { 'begin': 0x02B0, 'end': 0x02FF }, // Spacing Modifier Letters
  23764. { 'begin': 0x0300, 'end': 0x036F }, // Combining Diacritical Marks
  23765. { 'begin': 0x0370, 'end': 0x03FF }, // Greek and Coptic
  23766. { 'begin': 0x2C80, 'end': 0x2CFF }, // Coptic
  23767. { 'begin': 0x0400, 'end': 0x04FF }, // Cyrillic
  23768. { 'begin': 0x0530, 'end': 0x058F }, // Armenian
  23769. { 'begin': 0x0590, 'end': 0x05FF }, // Hebrew
  23770. { 'begin': 0xA500, 'end': 0xA63F }, // Vai
  23771. { 'begin': 0x0600, 'end': 0x06FF }, // Arabic
  23772. { 'begin': 0x07C0, 'end': 0x07FF }, // NKo
  23773. { 'begin': 0x0900, 'end': 0x097F }, // Devanagari
  23774. { 'begin': 0x0980, 'end': 0x09FF }, // Bengali
  23775. { 'begin': 0x0A00, 'end': 0x0A7F }, // Gurmukhi
  23776. { 'begin': 0x0A80, 'end': 0x0AFF }, // Gujarati
  23777. { 'begin': 0x0B00, 'end': 0x0B7F }, // Oriya
  23778. { 'begin': 0x0B80, 'end': 0x0BFF }, // Tamil
  23779. { 'begin': 0x0C00, 'end': 0x0C7F }, // Telugu
  23780. { 'begin': 0x0C80, 'end': 0x0CFF }, // Kannada
  23781. { 'begin': 0x0D00, 'end': 0x0D7F }, // Malayalam
  23782. { 'begin': 0x0E00, 'end': 0x0E7F }, // Thai
  23783. { 'begin': 0x0E80, 'end': 0x0EFF }, // Lao
  23784. { 'begin': 0x10A0, 'end': 0x10FF }, // Georgian
  23785. { 'begin': 0x1B00, 'end': 0x1B7F }, // Balinese
  23786. { 'begin': 0x1100, 'end': 0x11FF }, // Hangul Jamo
  23787. { 'begin': 0x1E00, 'end': 0x1EFF }, // Latin Extended Additional
  23788. { 'begin': 0x1F00, 'end': 0x1FFF }, // Greek Extended
  23789. { 'begin': 0x2000, 'end': 0x206F }, // General Punctuation
  23790. { 'begin': 0x2070, 'end': 0x209F }, // Superscripts And Subscripts
  23791. { 'begin': 0x20A0, 'end': 0x20CF }, // Currency Symbol
  23792. { 'begin': 0x20D0, 'end': 0x20FF }, // Combining Diacritical Marks For Symbols
  23793. { 'begin': 0x2100, 'end': 0x214F }, // Letterlike Symbols
  23794. { 'begin': 0x2150, 'end': 0x218F }, // Number Forms
  23795. { 'begin': 0x2190, 'end': 0x21FF }, // Arrows
  23796. { 'begin': 0x2200, 'end': 0x22FF }, // Mathematical Operators
  23797. { 'begin': 0x2300, 'end': 0x23FF }, // Miscellaneous Technical
  23798. { 'begin': 0x2400, 'end': 0x243F }, // Control Pictures
  23799. { 'begin': 0x2440, 'end': 0x245F }, // Optical Character Recognition
  23800. { 'begin': 0x2460, 'end': 0x24FF }, // Enclosed Alphanumerics
  23801. { 'begin': 0x2500, 'end': 0x257F }, // Box Drawing
  23802. { 'begin': 0x2580, 'end': 0x259F }, // Block Elements
  23803. { 'begin': 0x25A0, 'end': 0x25FF }, // Geometric Shapes
  23804. { 'begin': 0x2600, 'end': 0x26FF }, // Miscellaneous Symbols
  23805. { 'begin': 0x2700, 'end': 0x27BF }, // Dingbats
  23806. { 'begin': 0x3000, 'end': 0x303F }, // CJK Symbols And Punctuation
  23807. { 'begin': 0x3040, 'end': 0x309F }, // Hiragana
  23808. { 'begin': 0x30A0, 'end': 0x30FF }, // Katakana
  23809. { 'begin': 0x3100, 'end': 0x312F }, // Bopomofo
  23810. { 'begin': 0x3130, 'end': 0x318F }, // Hangul Compatibility Jamo
  23811. { 'begin': 0xA840, 'end': 0xA87F }, // Phags-pa
  23812. { 'begin': 0x3200, 'end': 0x32FF }, // Enclosed CJK Letters And Months
  23813. { 'begin': 0x3300, 'end': 0x33FF }, // CJK Compatibility
  23814. { 'begin': 0xAC00, 'end': 0xD7AF }, // Hangul Syllables
  23815. { 'begin': 0xD800, 'end': 0xDFFF }, // Non-Plane 0 *
  23816. { 'begin': 0x10900, 'end': 0x1091F }, // Phoenicia
  23817. { 'begin': 0x4E00, 'end': 0x9FFF }, // CJK Unified Ideographs
  23818. { 'begin': 0xE000, 'end': 0xF8FF }, // Private Use Area (plane 0)
  23819. { 'begin': 0x31C0, 'end': 0x31EF }, // CJK Strokes
  23820. { 'begin': 0xFB00, 'end': 0xFB4F }, // Alphabetic Presentation Forms
  23821. { 'begin': 0xFB50, 'end': 0xFDFF }, // Arabic Presentation Forms-A
  23822. { 'begin': 0xFE20, 'end': 0xFE2F }, // Combining Half Marks
  23823. { 'begin': 0xFE10, 'end': 0xFE1F }, // Vertical Forms
  23824. { 'begin': 0xFE50, 'end': 0xFE6F }, // Small Form Variants
  23825. { 'begin': 0xFE70, 'end': 0xFEFF }, // Arabic Presentation Forms-B
  23826. { 'begin': 0xFF00, 'end': 0xFFEF }, // Halfwidth And Fullwidth Forms
  23827. { 'begin': 0xFFF0, 'end': 0xFFFF }, // Specials
  23828. { 'begin': 0x0F00, 'end': 0x0FFF }, // Tibetan
  23829. { 'begin': 0x0700, 'end': 0x074F }, // Syriac
  23830. { 'begin': 0x0780, 'end': 0x07BF }, // Thaana
  23831. { 'begin': 0x0D80, 'end': 0x0DFF }, // Sinhala
  23832. { 'begin': 0x1000, 'end': 0x109F }, // Myanmar
  23833. { 'begin': 0x1200, 'end': 0x137F }, // Ethiopic
  23834. { 'begin': 0x13A0, 'end': 0x13FF }, // Cherokee
  23835. { 'begin': 0x1400, 'end': 0x167F }, // Unified Canadian Aboriginal Syllabics
  23836. { 'begin': 0x1680, 'end': 0x169F }, // Ogham
  23837. { 'begin': 0x16A0, 'end': 0x16FF }, // Runic
  23838. { 'begin': 0x1780, 'end': 0x17FF }, // Khmer
  23839. { 'begin': 0x1800, 'end': 0x18AF }, // Mongolian
  23840. { 'begin': 0x2800, 'end': 0x28FF }, // Braille Patterns
  23841. { 'begin': 0xA000, 'end': 0xA48F }, // Yi Syllables
  23842. { 'begin': 0x1700, 'end': 0x171F }, // Tagalog
  23843. { 'begin': 0x10300, 'end': 0x1032F }, // Old Italic
  23844. { 'begin': 0x10330, 'end': 0x1034F }, // Gothic
  23845. { 'begin': 0x10400, 'end': 0x1044F }, // Deseret
  23846. { 'begin': 0x1D000, 'end': 0x1D0FF }, // Byzantine Musical Symbols
  23847. { 'begin': 0x1D400, 'end': 0x1D7FF }, // Mathematical Alphanumeric Symbols
  23848. { 'begin': 0xFF000, 'end': 0xFFFFD }, // Private Use (plane 15)
  23849. { 'begin': 0xFE00, 'end': 0xFE0F }, // Variation Selectors
  23850. { 'begin': 0xE0000, 'end': 0xE007F }, // Tags
  23851. { 'begin': 0x1900, 'end': 0x194F }, // Limbu
  23852. { 'begin': 0x1950, 'end': 0x197F }, // Tai Le
  23853. { 'begin': 0x1980, 'end': 0x19DF }, // New Tai Lue
  23854. { 'begin': 0x1A00, 'end': 0x1A1F }, // Buginese
  23855. { 'begin': 0x2C00, 'end': 0x2C5F }, // Glagolitic
  23856. { 'begin': 0x2D30, 'end': 0x2D7F }, // Tifinagh
  23857. { 'begin': 0x4DC0, 'end': 0x4DFF }, // Yijing Hexagram Symbols
  23858. { 'begin': 0xA800, 'end': 0xA82F }, // Syloti Nagri
  23859. { 'begin': 0x10000, 'end': 0x1007F }, // Linear B Syllabary
  23860. { 'begin': 0x10140, 'end': 0x1018F }, // Ancient Greek Numbers
  23861. { 'begin': 0x10380, 'end': 0x1039F }, // Ugaritic
  23862. { 'begin': 0x103A0, 'end': 0x103DF }, // Old Persian
  23863. { 'begin': 0x10450, 'end': 0x1047F }, // Shavian
  23864. { 'begin': 0x10480, 'end': 0x104AF }, // Osmanya
  23865. { 'begin': 0x10800, 'end': 0x1083F }, // Cypriot Syllabary
  23866. { 'begin': 0x10A00, 'end': 0x10A5F }, // Kharoshthi
  23867. { 'begin': 0x1D300, 'end': 0x1D35F }, // Tai Xuan Jing Symbols
  23868. { 'begin': 0x12000, 'end': 0x123FF }, // Cuneiform
  23869. { 'begin': 0x1D360, 'end': 0x1D37F }, // Counting Rod Numerals
  23870. { 'begin': 0x1B80, 'end': 0x1BBF }, // Sundanese
  23871. { 'begin': 0x1C00, 'end': 0x1C4F }, // Lepcha
  23872. { 'begin': 0x1C50, 'end': 0x1C7F }, // Ol Chiki
  23873. { 'begin': 0xA880, 'end': 0xA8DF }, // Saurashtra
  23874. { 'begin': 0xA900, 'end': 0xA92F }, // Kayah Li
  23875. { 'begin': 0xA930, 'end': 0xA95F }, // Rejang
  23876. { 'begin': 0xAA00, 'end': 0xAA5F }, // Cham
  23877. { 'begin': 0x10190, 'end': 0x101CF }, // Ancient Symbols
  23878. { 'begin': 0x101D0, 'end': 0x101FF }, // Phaistos Disc
  23879. { 'begin': 0x102A0, 'end': 0x102DF }, // Carian
  23880. { 'begin': 0x1F030, 'end': 0x1F09F } // Domino Tiles
  23881. ];
  23882. var MacStandardGlyphOrdering = [
  23883. '.notdef', '.null', 'nonmarkingreturn', 'space', 'exclam', 'quotedbl',
  23884. 'numbersign', 'dollar', 'percent', 'ampersand', 'quotesingle', 'parenleft',
  23885. 'parenright', 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash',
  23886. 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  23887. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question', 'at',
  23888. 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
  23889. 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'bracketleft',
  23890. 'backslash', 'bracketright', 'asciicircum', 'underscore', 'grave', 'a', 'b',
  23891. 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q',
  23892. 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright',
  23893. 'asciitilde', 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde',
  23894. 'Odieresis', 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis',
  23895. 'atilde', 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  23896. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute', 'ograve',
  23897. 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave', 'ucircumflex',
  23898. 'udieresis', 'dagger', 'degree', 'cent', 'sterling', 'section', 'bullet',
  23899. 'paragraph', 'germandbls', 'registered', 'copyright', 'trademark', 'acute',
  23900. 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity', 'plusminus', 'lessequal',
  23901. 'greaterequal', 'yen', 'mu', 'partialdiff', 'summation', 'product', 'pi',
  23902. 'integral', 'ordfeminine', 'ordmasculine', 'Omega', 'ae', 'oslash',
  23903. 'questiondown', 'exclamdown', 'logicalnot', 'radical', 'florin',
  23904. 'approxequal', 'Delta', 'guillemotleft', 'guillemotright', 'ellipsis',
  23905. 'nonbreakingspace', 'Agrave', 'Atilde', 'Otilde', 'OE', 'oe', 'endash',
  23906. 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft', 'quoteright',
  23907. 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction', 'currency',
  23908. 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl', 'periodcentered',
  23909. 'quotesinglbase', 'quotedblbase', 'perthousand', 'Acircumflex',
  23910. 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute', 'Icircumflex',
  23911. 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple', 'Ograve', 'Uacute',
  23912. 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex', 'tilde', 'macron',
  23913. 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron',
  23914. 'Lslash', 'lslash', 'Scaron', 'scaron', 'Zcaron', 'zcaron', 'brokenbar',
  23915. 'Eth', 'eth', 'Yacute', 'yacute', 'Thorn', 'thorn', 'minus', 'multiply',
  23916. 'onesuperior', 'twosuperior', 'threesuperior', 'onehalf', 'onequarter',
  23917. 'threequarters', 'franc', 'Gbreve', 'gbreve', 'Idotaccent', 'Scedilla',
  23918. 'scedilla', 'Cacute', 'cacute', 'Ccaron', 'ccaron', 'dcroat'];
  23919. function getUnicodeRangeFor(value) {
  23920. for (var i = 0, ii = UnicodeRanges.length; i < ii; i++) {
  23921. var range = UnicodeRanges[i];
  23922. if (value >= range.begin && value < range.end) {
  23923. return i;
  23924. }
  23925. }
  23926. return -1;
  23927. }
  23928. function isRTLRangeFor(value) {
  23929. var range = UnicodeRanges[13];
  23930. if (value >= range.begin && value < range.end) {
  23931. return true;
  23932. }
  23933. range = UnicodeRanges[11];
  23934. if (value >= range.begin && value < range.end) {
  23935. return true;
  23936. }
  23937. return false;
  23938. }
  23939. // The normalization table is obtained by filtering the Unicode characters
  23940. // database with <compat> entries.
  23941. var NormalizedUnicodes = {
  23942. '\u00A8': '\u0020\u0308',
  23943. '\u00AF': '\u0020\u0304',
  23944. '\u00B4': '\u0020\u0301',
  23945. '\u00B5': '\u03BC',
  23946. '\u00B8': '\u0020\u0327',
  23947. '\u0132': '\u0049\u004A',
  23948. '\u0133': '\u0069\u006A',
  23949. '\u013F': '\u004C\u00B7',
  23950. '\u0140': '\u006C\u00B7',
  23951. '\u0149': '\u02BC\u006E',
  23952. '\u017F': '\u0073',
  23953. '\u01C4': '\u0044\u017D',
  23954. '\u01C5': '\u0044\u017E',
  23955. '\u01C6': '\u0064\u017E',
  23956. '\u01C7': '\u004C\u004A',
  23957. '\u01C8': '\u004C\u006A',
  23958. '\u01C9': '\u006C\u006A',
  23959. '\u01CA': '\u004E\u004A',
  23960. '\u01CB': '\u004E\u006A',
  23961. '\u01CC': '\u006E\u006A',
  23962. '\u01F1': '\u0044\u005A',
  23963. '\u01F2': '\u0044\u007A',
  23964. '\u01F3': '\u0064\u007A',
  23965. '\u02D8': '\u0020\u0306',
  23966. '\u02D9': '\u0020\u0307',
  23967. '\u02DA': '\u0020\u030A',
  23968. '\u02DB': '\u0020\u0328',
  23969. '\u02DC': '\u0020\u0303',
  23970. '\u02DD': '\u0020\u030B',
  23971. '\u037A': '\u0020\u0345',
  23972. '\u0384': '\u0020\u0301',
  23973. '\u03D0': '\u03B2',
  23974. '\u03D1': '\u03B8',
  23975. '\u03D2': '\u03A5',
  23976. '\u03D5': '\u03C6',
  23977. '\u03D6': '\u03C0',
  23978. '\u03F0': '\u03BA',
  23979. '\u03F1': '\u03C1',
  23980. '\u03F2': '\u03C2',
  23981. '\u03F4': '\u0398',
  23982. '\u03F5': '\u03B5',
  23983. '\u03F9': '\u03A3',
  23984. '\u0587': '\u0565\u0582',
  23985. '\u0675': '\u0627\u0674',
  23986. '\u0676': '\u0648\u0674',
  23987. '\u0677': '\u06C7\u0674',
  23988. '\u0678': '\u064A\u0674',
  23989. '\u0E33': '\u0E4D\u0E32',
  23990. '\u0EB3': '\u0ECD\u0EB2',
  23991. '\u0EDC': '\u0EAB\u0E99',
  23992. '\u0EDD': '\u0EAB\u0EA1',
  23993. '\u0F77': '\u0FB2\u0F81',
  23994. '\u0F79': '\u0FB3\u0F81',
  23995. '\u1E9A': '\u0061\u02BE',
  23996. '\u1FBD': '\u0020\u0313',
  23997. '\u1FBF': '\u0020\u0313',
  23998. '\u1FC0': '\u0020\u0342',
  23999. '\u1FFE': '\u0020\u0314',
  24000. '\u2002': '\u0020',
  24001. '\u2003': '\u0020',
  24002. '\u2004': '\u0020',
  24003. '\u2005': '\u0020',
  24004. '\u2006': '\u0020',
  24005. '\u2008': '\u0020',
  24006. '\u2009': '\u0020',
  24007. '\u200A': '\u0020',
  24008. '\u2017': '\u0020\u0333',
  24009. '\u2024': '\u002E',
  24010. '\u2025': '\u002E\u002E',
  24011. '\u2026': '\u002E\u002E\u002E',
  24012. '\u2033': '\u2032\u2032',
  24013. '\u2034': '\u2032\u2032\u2032',
  24014. '\u2036': '\u2035\u2035',
  24015. '\u2037': '\u2035\u2035\u2035',
  24016. '\u203C': '\u0021\u0021',
  24017. '\u203E': '\u0020\u0305',
  24018. '\u2047': '\u003F\u003F',
  24019. '\u2048': '\u003F\u0021',
  24020. '\u2049': '\u0021\u003F',
  24021. '\u2057': '\u2032\u2032\u2032\u2032',
  24022. '\u205F': '\u0020',
  24023. '\u20A8': '\u0052\u0073',
  24024. '\u2100': '\u0061\u002F\u0063',
  24025. '\u2101': '\u0061\u002F\u0073',
  24026. '\u2103': '\u00B0\u0043',
  24027. '\u2105': '\u0063\u002F\u006F',
  24028. '\u2106': '\u0063\u002F\u0075',
  24029. '\u2107': '\u0190',
  24030. '\u2109': '\u00B0\u0046',
  24031. '\u2116': '\u004E\u006F',
  24032. '\u2121': '\u0054\u0045\u004C',
  24033. '\u2135': '\u05D0',
  24034. '\u2136': '\u05D1',
  24035. '\u2137': '\u05D2',
  24036. '\u2138': '\u05D3',
  24037. '\u213B': '\u0046\u0041\u0058',
  24038. '\u2160': '\u0049',
  24039. '\u2161': '\u0049\u0049',
  24040. '\u2162': '\u0049\u0049\u0049',
  24041. '\u2163': '\u0049\u0056',
  24042. '\u2164': '\u0056',
  24043. '\u2165': '\u0056\u0049',
  24044. '\u2166': '\u0056\u0049\u0049',
  24045. '\u2167': '\u0056\u0049\u0049\u0049',
  24046. '\u2168': '\u0049\u0058',
  24047. '\u2169': '\u0058',
  24048. '\u216A': '\u0058\u0049',
  24049. '\u216B': '\u0058\u0049\u0049',
  24050. '\u216C': '\u004C',
  24051. '\u216D': '\u0043',
  24052. '\u216E': '\u0044',
  24053. '\u216F': '\u004D',
  24054. '\u2170': '\u0069',
  24055. '\u2171': '\u0069\u0069',
  24056. '\u2172': '\u0069\u0069\u0069',
  24057. '\u2173': '\u0069\u0076',
  24058. '\u2174': '\u0076',
  24059. '\u2175': '\u0076\u0069',
  24060. '\u2176': '\u0076\u0069\u0069',
  24061. '\u2177': '\u0076\u0069\u0069\u0069',
  24062. '\u2178': '\u0069\u0078',
  24063. '\u2179': '\u0078',
  24064. '\u217A': '\u0078\u0069',
  24065. '\u217B': '\u0078\u0069\u0069',
  24066. '\u217C': '\u006C',
  24067. '\u217D': '\u0063',
  24068. '\u217E': '\u0064',
  24069. '\u217F': '\u006D',
  24070. '\u222C': '\u222B\u222B',
  24071. '\u222D': '\u222B\u222B\u222B',
  24072. '\u222F': '\u222E\u222E',
  24073. '\u2230': '\u222E\u222E\u222E',
  24074. '\u2474': '\u0028\u0031\u0029',
  24075. '\u2475': '\u0028\u0032\u0029',
  24076. '\u2476': '\u0028\u0033\u0029',
  24077. '\u2477': '\u0028\u0034\u0029',
  24078. '\u2478': '\u0028\u0035\u0029',
  24079. '\u2479': '\u0028\u0036\u0029',
  24080. '\u247A': '\u0028\u0037\u0029',
  24081. '\u247B': '\u0028\u0038\u0029',
  24082. '\u247C': '\u0028\u0039\u0029',
  24083. '\u247D': '\u0028\u0031\u0030\u0029',
  24084. '\u247E': '\u0028\u0031\u0031\u0029',
  24085. '\u247F': '\u0028\u0031\u0032\u0029',
  24086. '\u2480': '\u0028\u0031\u0033\u0029',
  24087. '\u2481': '\u0028\u0031\u0034\u0029',
  24088. '\u2482': '\u0028\u0031\u0035\u0029',
  24089. '\u2483': '\u0028\u0031\u0036\u0029',
  24090. '\u2484': '\u0028\u0031\u0037\u0029',
  24091. '\u2485': '\u0028\u0031\u0038\u0029',
  24092. '\u2486': '\u0028\u0031\u0039\u0029',
  24093. '\u2487': '\u0028\u0032\u0030\u0029',
  24094. '\u2488': '\u0031\u002E',
  24095. '\u2489': '\u0032\u002E',
  24096. '\u248A': '\u0033\u002E',
  24097. '\u248B': '\u0034\u002E',
  24098. '\u248C': '\u0035\u002E',
  24099. '\u248D': '\u0036\u002E',
  24100. '\u248E': '\u0037\u002E',
  24101. '\u248F': '\u0038\u002E',
  24102. '\u2490': '\u0039\u002E',
  24103. '\u2491': '\u0031\u0030\u002E',
  24104. '\u2492': '\u0031\u0031\u002E',
  24105. '\u2493': '\u0031\u0032\u002E',
  24106. '\u2494': '\u0031\u0033\u002E',
  24107. '\u2495': '\u0031\u0034\u002E',
  24108. '\u2496': '\u0031\u0035\u002E',
  24109. '\u2497': '\u0031\u0036\u002E',
  24110. '\u2498': '\u0031\u0037\u002E',
  24111. '\u2499': '\u0031\u0038\u002E',
  24112. '\u249A': '\u0031\u0039\u002E',
  24113. '\u249B': '\u0032\u0030\u002E',
  24114. '\u249C': '\u0028\u0061\u0029',
  24115. '\u249D': '\u0028\u0062\u0029',
  24116. '\u249E': '\u0028\u0063\u0029',
  24117. '\u249F': '\u0028\u0064\u0029',
  24118. '\u24A0': '\u0028\u0065\u0029',
  24119. '\u24A1': '\u0028\u0066\u0029',
  24120. '\u24A2': '\u0028\u0067\u0029',
  24121. '\u24A3': '\u0028\u0068\u0029',
  24122. '\u24A4': '\u0028\u0069\u0029',
  24123. '\u24A5': '\u0028\u006A\u0029',
  24124. '\u24A6': '\u0028\u006B\u0029',
  24125. '\u24A7': '\u0028\u006C\u0029',
  24126. '\u24A8': '\u0028\u006D\u0029',
  24127. '\u24A9': '\u0028\u006E\u0029',
  24128. '\u24AA': '\u0028\u006F\u0029',
  24129. '\u24AB': '\u0028\u0070\u0029',
  24130. '\u24AC': '\u0028\u0071\u0029',
  24131. '\u24AD': '\u0028\u0072\u0029',
  24132. '\u24AE': '\u0028\u0073\u0029',
  24133. '\u24AF': '\u0028\u0074\u0029',
  24134. '\u24B0': '\u0028\u0075\u0029',
  24135. '\u24B1': '\u0028\u0076\u0029',
  24136. '\u24B2': '\u0028\u0077\u0029',
  24137. '\u24B3': '\u0028\u0078\u0029',
  24138. '\u24B4': '\u0028\u0079\u0029',
  24139. '\u24B5': '\u0028\u007A\u0029',
  24140. '\u2A0C': '\u222B\u222B\u222B\u222B',
  24141. '\u2A74': '\u003A\u003A\u003D',
  24142. '\u2A75': '\u003D\u003D',
  24143. '\u2A76': '\u003D\u003D\u003D',
  24144. '\u2E9F': '\u6BCD',
  24145. '\u2EF3': '\u9F9F',
  24146. '\u2F00': '\u4E00',
  24147. '\u2F01': '\u4E28',
  24148. '\u2F02': '\u4E36',
  24149. '\u2F03': '\u4E3F',
  24150. '\u2F04': '\u4E59',
  24151. '\u2F05': '\u4E85',
  24152. '\u2F06': '\u4E8C',
  24153. '\u2F07': '\u4EA0',
  24154. '\u2F08': '\u4EBA',
  24155. '\u2F09': '\u513F',
  24156. '\u2F0A': '\u5165',
  24157. '\u2F0B': '\u516B',
  24158. '\u2F0C': '\u5182',
  24159. '\u2F0D': '\u5196',
  24160. '\u2F0E': '\u51AB',
  24161. '\u2F0F': '\u51E0',
  24162. '\u2F10': '\u51F5',
  24163. '\u2F11': '\u5200',
  24164. '\u2F12': '\u529B',
  24165. '\u2F13': '\u52F9',
  24166. '\u2F14': '\u5315',
  24167. '\u2F15': '\u531A',
  24168. '\u2F16': '\u5338',
  24169. '\u2F17': '\u5341',
  24170. '\u2F18': '\u535C',
  24171. '\u2F19': '\u5369',
  24172. '\u2F1A': '\u5382',
  24173. '\u2F1B': '\u53B6',
  24174. '\u2F1C': '\u53C8',
  24175. '\u2F1D': '\u53E3',
  24176. '\u2F1E': '\u56D7',
  24177. '\u2F1F': '\u571F',
  24178. '\u2F20': '\u58EB',
  24179. '\u2F21': '\u5902',
  24180. '\u2F22': '\u590A',
  24181. '\u2F23': '\u5915',
  24182. '\u2F24': '\u5927',
  24183. '\u2F25': '\u5973',
  24184. '\u2F26': '\u5B50',
  24185. '\u2F27': '\u5B80',
  24186. '\u2F28': '\u5BF8',
  24187. '\u2F29': '\u5C0F',
  24188. '\u2F2A': '\u5C22',
  24189. '\u2F2B': '\u5C38',
  24190. '\u2F2C': '\u5C6E',
  24191. '\u2F2D': '\u5C71',
  24192. '\u2F2E': '\u5DDB',
  24193. '\u2F2F': '\u5DE5',
  24194. '\u2F30': '\u5DF1',
  24195. '\u2F31': '\u5DFE',
  24196. '\u2F32': '\u5E72',
  24197. '\u2F33': '\u5E7A',
  24198. '\u2F34': '\u5E7F',
  24199. '\u2F35': '\u5EF4',
  24200. '\u2F36': '\u5EFE',
  24201. '\u2F37': '\u5F0B',
  24202. '\u2F38': '\u5F13',
  24203. '\u2F39': '\u5F50',
  24204. '\u2F3A': '\u5F61',
  24205. '\u2F3B': '\u5F73',
  24206. '\u2F3C': '\u5FC3',
  24207. '\u2F3D': '\u6208',
  24208. '\u2F3E': '\u6236',
  24209. '\u2F3F': '\u624B',
  24210. '\u2F40': '\u652F',
  24211. '\u2F41': '\u6534',
  24212. '\u2F42': '\u6587',
  24213. '\u2F43': '\u6597',
  24214. '\u2F44': '\u65A4',
  24215. '\u2F45': '\u65B9',
  24216. '\u2F46': '\u65E0',
  24217. '\u2F47': '\u65E5',
  24218. '\u2F48': '\u66F0',
  24219. '\u2F49': '\u6708',
  24220. '\u2F4A': '\u6728',
  24221. '\u2F4B': '\u6B20',
  24222. '\u2F4C': '\u6B62',
  24223. '\u2F4D': '\u6B79',
  24224. '\u2F4E': '\u6BB3',
  24225. '\u2F4F': '\u6BCB',
  24226. '\u2F50': '\u6BD4',
  24227. '\u2F51': '\u6BDB',
  24228. '\u2F52': '\u6C0F',
  24229. '\u2F53': '\u6C14',
  24230. '\u2F54': '\u6C34',
  24231. '\u2F55': '\u706B',
  24232. '\u2F56': '\u722A',
  24233. '\u2F57': '\u7236',
  24234. '\u2F58': '\u723B',
  24235. '\u2F59': '\u723F',
  24236. '\u2F5A': '\u7247',
  24237. '\u2F5B': '\u7259',
  24238. '\u2F5C': '\u725B',
  24239. '\u2F5D': '\u72AC',
  24240. '\u2F5E': '\u7384',
  24241. '\u2F5F': '\u7389',
  24242. '\u2F60': '\u74DC',
  24243. '\u2F61': '\u74E6',
  24244. '\u2F62': '\u7518',
  24245. '\u2F63': '\u751F',
  24246. '\u2F64': '\u7528',
  24247. '\u2F65': '\u7530',
  24248. '\u2F66': '\u758B',
  24249. '\u2F67': '\u7592',
  24250. '\u2F68': '\u7676',
  24251. '\u2F69': '\u767D',
  24252. '\u2F6A': '\u76AE',
  24253. '\u2F6B': '\u76BF',
  24254. '\u2F6C': '\u76EE',
  24255. '\u2F6D': '\u77DB',
  24256. '\u2F6E': '\u77E2',
  24257. '\u2F6F': '\u77F3',
  24258. '\u2F70': '\u793A',
  24259. '\u2F71': '\u79B8',
  24260. '\u2F72': '\u79BE',
  24261. '\u2F73': '\u7A74',
  24262. '\u2F74': '\u7ACB',
  24263. '\u2F75': '\u7AF9',
  24264. '\u2F76': '\u7C73',
  24265. '\u2F77': '\u7CF8',
  24266. '\u2F78': '\u7F36',
  24267. '\u2F79': '\u7F51',
  24268. '\u2F7A': '\u7F8A',
  24269. '\u2F7B': '\u7FBD',
  24270. '\u2F7C': '\u8001',
  24271. '\u2F7D': '\u800C',
  24272. '\u2F7E': '\u8012',
  24273. '\u2F7F': '\u8033',
  24274. '\u2F80': '\u807F',
  24275. '\u2F81': '\u8089',
  24276. '\u2F82': '\u81E3',
  24277. '\u2F83': '\u81EA',
  24278. '\u2F84': '\u81F3',
  24279. '\u2F85': '\u81FC',
  24280. '\u2F86': '\u820C',
  24281. '\u2F87': '\u821B',
  24282. '\u2F88': '\u821F',
  24283. '\u2F89': '\u826E',
  24284. '\u2F8A': '\u8272',
  24285. '\u2F8B': '\u8278',
  24286. '\u2F8C': '\u864D',
  24287. '\u2F8D': '\u866B',
  24288. '\u2F8E': '\u8840',
  24289. '\u2F8F': '\u884C',
  24290. '\u2F90': '\u8863',
  24291. '\u2F91': '\u897E',
  24292. '\u2F92': '\u898B',
  24293. '\u2F93': '\u89D2',
  24294. '\u2F94': '\u8A00',
  24295. '\u2F95': '\u8C37',
  24296. '\u2F96': '\u8C46',
  24297. '\u2F97': '\u8C55',
  24298. '\u2F98': '\u8C78',
  24299. '\u2F99': '\u8C9D',
  24300. '\u2F9A': '\u8D64',
  24301. '\u2F9B': '\u8D70',
  24302. '\u2F9C': '\u8DB3',
  24303. '\u2F9D': '\u8EAB',
  24304. '\u2F9E': '\u8ECA',
  24305. '\u2F9F': '\u8F9B',
  24306. '\u2FA0': '\u8FB0',
  24307. '\u2FA1': '\u8FB5',
  24308. '\u2FA2': '\u9091',
  24309. '\u2FA3': '\u9149',
  24310. '\u2FA4': '\u91C6',
  24311. '\u2FA5': '\u91CC',
  24312. '\u2FA6': '\u91D1',
  24313. '\u2FA7': '\u9577',
  24314. '\u2FA8': '\u9580',
  24315. '\u2FA9': '\u961C',
  24316. '\u2FAA': '\u96B6',
  24317. '\u2FAB': '\u96B9',
  24318. '\u2FAC': '\u96E8',
  24319. '\u2FAD': '\u9751',
  24320. '\u2FAE': '\u975E',
  24321. '\u2FAF': '\u9762',
  24322. '\u2FB0': '\u9769',
  24323. '\u2FB1': '\u97CB',
  24324. '\u2FB2': '\u97ED',
  24325. '\u2FB3': '\u97F3',
  24326. '\u2FB4': '\u9801',
  24327. '\u2FB5': '\u98A8',
  24328. '\u2FB6': '\u98DB',
  24329. '\u2FB7': '\u98DF',
  24330. '\u2FB8': '\u9996',
  24331. '\u2FB9': '\u9999',
  24332. '\u2FBA': '\u99AC',
  24333. '\u2FBB': '\u9AA8',
  24334. '\u2FBC': '\u9AD8',
  24335. '\u2FBD': '\u9ADF',
  24336. '\u2FBE': '\u9B25',
  24337. '\u2FBF': '\u9B2F',
  24338. '\u2FC0': '\u9B32',
  24339. '\u2FC1': '\u9B3C',
  24340. '\u2FC2': '\u9B5A',
  24341. '\u2FC3': '\u9CE5',
  24342. '\u2FC4': '\u9E75',
  24343. '\u2FC5': '\u9E7F',
  24344. '\u2FC6': '\u9EA5',
  24345. '\u2FC7': '\u9EBB',
  24346. '\u2FC8': '\u9EC3',
  24347. '\u2FC9': '\u9ECD',
  24348. '\u2FCA': '\u9ED1',
  24349. '\u2FCB': '\u9EF9',
  24350. '\u2FCC': '\u9EFD',
  24351. '\u2FCD': '\u9F0E',
  24352. '\u2FCE': '\u9F13',
  24353. '\u2FCF': '\u9F20',
  24354. '\u2FD0': '\u9F3B',
  24355. '\u2FD1': '\u9F4A',
  24356. '\u2FD2': '\u9F52',
  24357. '\u2FD3': '\u9F8D',
  24358. '\u2FD4': '\u9F9C',
  24359. '\u2FD5': '\u9FA0',
  24360. '\u3036': '\u3012',
  24361. '\u3038': '\u5341',
  24362. '\u3039': '\u5344',
  24363. '\u303A': '\u5345',
  24364. '\u309B': '\u0020\u3099',
  24365. '\u309C': '\u0020\u309A',
  24366. '\u3131': '\u1100',
  24367. '\u3132': '\u1101',
  24368. '\u3133': '\u11AA',
  24369. '\u3134': '\u1102',
  24370. '\u3135': '\u11AC',
  24371. '\u3136': '\u11AD',
  24372. '\u3137': '\u1103',
  24373. '\u3138': '\u1104',
  24374. '\u3139': '\u1105',
  24375. '\u313A': '\u11B0',
  24376. '\u313B': '\u11B1',
  24377. '\u313C': '\u11B2',
  24378. '\u313D': '\u11B3',
  24379. '\u313E': '\u11B4',
  24380. '\u313F': '\u11B5',
  24381. '\u3140': '\u111A',
  24382. '\u3141': '\u1106',
  24383. '\u3142': '\u1107',
  24384. '\u3143': '\u1108',
  24385. '\u3144': '\u1121',
  24386. '\u3145': '\u1109',
  24387. '\u3146': '\u110A',
  24388. '\u3147': '\u110B',
  24389. '\u3148': '\u110C',
  24390. '\u3149': '\u110D',
  24391. '\u314A': '\u110E',
  24392. '\u314B': '\u110F',
  24393. '\u314C': '\u1110',
  24394. '\u314D': '\u1111',
  24395. '\u314E': '\u1112',
  24396. '\u314F': '\u1161',
  24397. '\u3150': '\u1162',
  24398. '\u3151': '\u1163',
  24399. '\u3152': '\u1164',
  24400. '\u3153': '\u1165',
  24401. '\u3154': '\u1166',
  24402. '\u3155': '\u1167',
  24403. '\u3156': '\u1168',
  24404. '\u3157': '\u1169',
  24405. '\u3158': '\u116A',
  24406. '\u3159': '\u116B',
  24407. '\u315A': '\u116C',
  24408. '\u315B': '\u116D',
  24409. '\u315C': '\u116E',
  24410. '\u315D': '\u116F',
  24411. '\u315E': '\u1170',
  24412. '\u315F': '\u1171',
  24413. '\u3160': '\u1172',
  24414. '\u3161': '\u1173',
  24415. '\u3162': '\u1174',
  24416. '\u3163': '\u1175',
  24417. '\u3164': '\u1160',
  24418. '\u3165': '\u1114',
  24419. '\u3166': '\u1115',
  24420. '\u3167': '\u11C7',
  24421. '\u3168': '\u11C8',
  24422. '\u3169': '\u11CC',
  24423. '\u316A': '\u11CE',
  24424. '\u316B': '\u11D3',
  24425. '\u316C': '\u11D7',
  24426. '\u316D': '\u11D9',
  24427. '\u316E': '\u111C',
  24428. '\u316F': '\u11DD',
  24429. '\u3170': '\u11DF',
  24430. '\u3171': '\u111D',
  24431. '\u3172': '\u111E',
  24432. '\u3173': '\u1120',
  24433. '\u3174': '\u1122',
  24434. '\u3175': '\u1123',
  24435. '\u3176': '\u1127',
  24436. '\u3177': '\u1129',
  24437. '\u3178': '\u112B',
  24438. '\u3179': '\u112C',
  24439. '\u317A': '\u112D',
  24440. '\u317B': '\u112E',
  24441. '\u317C': '\u112F',
  24442. '\u317D': '\u1132',
  24443. '\u317E': '\u1136',
  24444. '\u317F': '\u1140',
  24445. '\u3180': '\u1147',
  24446. '\u3181': '\u114C',
  24447. '\u3182': '\u11F1',
  24448. '\u3183': '\u11F2',
  24449. '\u3184': '\u1157',
  24450. '\u3185': '\u1158',
  24451. '\u3186': '\u1159',
  24452. '\u3187': '\u1184',
  24453. '\u3188': '\u1185',
  24454. '\u3189': '\u1188',
  24455. '\u318A': '\u1191',
  24456. '\u318B': '\u1192',
  24457. '\u318C': '\u1194',
  24458. '\u318D': '\u119E',
  24459. '\u318E': '\u11A1',
  24460. '\u3200': '\u0028\u1100\u0029',
  24461. '\u3201': '\u0028\u1102\u0029',
  24462. '\u3202': '\u0028\u1103\u0029',
  24463. '\u3203': '\u0028\u1105\u0029',
  24464. '\u3204': '\u0028\u1106\u0029',
  24465. '\u3205': '\u0028\u1107\u0029',
  24466. '\u3206': '\u0028\u1109\u0029',
  24467. '\u3207': '\u0028\u110B\u0029',
  24468. '\u3208': '\u0028\u110C\u0029',
  24469. '\u3209': '\u0028\u110E\u0029',
  24470. '\u320A': '\u0028\u110F\u0029',
  24471. '\u320B': '\u0028\u1110\u0029',
  24472. '\u320C': '\u0028\u1111\u0029',
  24473. '\u320D': '\u0028\u1112\u0029',
  24474. '\u320E': '\u0028\u1100\u1161\u0029',
  24475. '\u320F': '\u0028\u1102\u1161\u0029',
  24476. '\u3210': '\u0028\u1103\u1161\u0029',
  24477. '\u3211': '\u0028\u1105\u1161\u0029',
  24478. '\u3212': '\u0028\u1106\u1161\u0029',
  24479. '\u3213': '\u0028\u1107\u1161\u0029',
  24480. '\u3214': '\u0028\u1109\u1161\u0029',
  24481. '\u3215': '\u0028\u110B\u1161\u0029',
  24482. '\u3216': '\u0028\u110C\u1161\u0029',
  24483. '\u3217': '\u0028\u110E\u1161\u0029',
  24484. '\u3218': '\u0028\u110F\u1161\u0029',
  24485. '\u3219': '\u0028\u1110\u1161\u0029',
  24486. '\u321A': '\u0028\u1111\u1161\u0029',
  24487. '\u321B': '\u0028\u1112\u1161\u0029',
  24488. '\u321C': '\u0028\u110C\u116E\u0029',
  24489. '\u321D': '\u0028\u110B\u1169\u110C\u1165\u11AB\u0029',
  24490. '\u321E': '\u0028\u110B\u1169\u1112\u116E\u0029',
  24491. '\u3220': '\u0028\u4E00\u0029',
  24492. '\u3221': '\u0028\u4E8C\u0029',
  24493. '\u3222': '\u0028\u4E09\u0029',
  24494. '\u3223': '\u0028\u56DB\u0029',
  24495. '\u3224': '\u0028\u4E94\u0029',
  24496. '\u3225': '\u0028\u516D\u0029',
  24497. '\u3226': '\u0028\u4E03\u0029',
  24498. '\u3227': '\u0028\u516B\u0029',
  24499. '\u3228': '\u0028\u4E5D\u0029',
  24500. '\u3229': '\u0028\u5341\u0029',
  24501. '\u322A': '\u0028\u6708\u0029',
  24502. '\u322B': '\u0028\u706B\u0029',
  24503. '\u322C': '\u0028\u6C34\u0029',
  24504. '\u322D': '\u0028\u6728\u0029',
  24505. '\u322E': '\u0028\u91D1\u0029',
  24506. '\u322F': '\u0028\u571F\u0029',
  24507. '\u3230': '\u0028\u65E5\u0029',
  24508. '\u3231': '\u0028\u682A\u0029',
  24509. '\u3232': '\u0028\u6709\u0029',
  24510. '\u3233': '\u0028\u793E\u0029',
  24511. '\u3234': '\u0028\u540D\u0029',
  24512. '\u3235': '\u0028\u7279\u0029',
  24513. '\u3236': '\u0028\u8CA1\u0029',
  24514. '\u3237': '\u0028\u795D\u0029',
  24515. '\u3238': '\u0028\u52B4\u0029',
  24516. '\u3239': '\u0028\u4EE3\u0029',
  24517. '\u323A': '\u0028\u547C\u0029',
  24518. '\u323B': '\u0028\u5B66\u0029',
  24519. '\u323C': '\u0028\u76E3\u0029',
  24520. '\u323D': '\u0028\u4F01\u0029',
  24521. '\u323E': '\u0028\u8CC7\u0029',
  24522. '\u323F': '\u0028\u5354\u0029',
  24523. '\u3240': '\u0028\u796D\u0029',
  24524. '\u3241': '\u0028\u4F11\u0029',
  24525. '\u3242': '\u0028\u81EA\u0029',
  24526. '\u3243': '\u0028\u81F3\u0029',
  24527. '\u32C0': '\u0031\u6708',
  24528. '\u32C1': '\u0032\u6708',
  24529. '\u32C2': '\u0033\u6708',
  24530. '\u32C3': '\u0034\u6708',
  24531. '\u32C4': '\u0035\u6708',
  24532. '\u32C5': '\u0036\u6708',
  24533. '\u32C6': '\u0037\u6708',
  24534. '\u32C7': '\u0038\u6708',
  24535. '\u32C8': '\u0039\u6708',
  24536. '\u32C9': '\u0031\u0030\u6708',
  24537. '\u32CA': '\u0031\u0031\u6708',
  24538. '\u32CB': '\u0031\u0032\u6708',
  24539. '\u3358': '\u0030\u70B9',
  24540. '\u3359': '\u0031\u70B9',
  24541. '\u335A': '\u0032\u70B9',
  24542. '\u335B': '\u0033\u70B9',
  24543. '\u335C': '\u0034\u70B9',
  24544. '\u335D': '\u0035\u70B9',
  24545. '\u335E': '\u0036\u70B9',
  24546. '\u335F': '\u0037\u70B9',
  24547. '\u3360': '\u0038\u70B9',
  24548. '\u3361': '\u0039\u70B9',
  24549. '\u3362': '\u0031\u0030\u70B9',
  24550. '\u3363': '\u0031\u0031\u70B9',
  24551. '\u3364': '\u0031\u0032\u70B9',
  24552. '\u3365': '\u0031\u0033\u70B9',
  24553. '\u3366': '\u0031\u0034\u70B9',
  24554. '\u3367': '\u0031\u0035\u70B9',
  24555. '\u3368': '\u0031\u0036\u70B9',
  24556. '\u3369': '\u0031\u0037\u70B9',
  24557. '\u336A': '\u0031\u0038\u70B9',
  24558. '\u336B': '\u0031\u0039\u70B9',
  24559. '\u336C': '\u0032\u0030\u70B9',
  24560. '\u336D': '\u0032\u0031\u70B9',
  24561. '\u336E': '\u0032\u0032\u70B9',
  24562. '\u336F': '\u0032\u0033\u70B9',
  24563. '\u3370': '\u0032\u0034\u70B9',
  24564. '\u33E0': '\u0031\u65E5',
  24565. '\u33E1': '\u0032\u65E5',
  24566. '\u33E2': '\u0033\u65E5',
  24567. '\u33E3': '\u0034\u65E5',
  24568. '\u33E4': '\u0035\u65E5',
  24569. '\u33E5': '\u0036\u65E5',
  24570. '\u33E6': '\u0037\u65E5',
  24571. '\u33E7': '\u0038\u65E5',
  24572. '\u33E8': '\u0039\u65E5',
  24573. '\u33E9': '\u0031\u0030\u65E5',
  24574. '\u33EA': '\u0031\u0031\u65E5',
  24575. '\u33EB': '\u0031\u0032\u65E5',
  24576. '\u33EC': '\u0031\u0033\u65E5',
  24577. '\u33ED': '\u0031\u0034\u65E5',
  24578. '\u33EE': '\u0031\u0035\u65E5',
  24579. '\u33EF': '\u0031\u0036\u65E5',
  24580. '\u33F0': '\u0031\u0037\u65E5',
  24581. '\u33F1': '\u0031\u0038\u65E5',
  24582. '\u33F2': '\u0031\u0039\u65E5',
  24583. '\u33F3': '\u0032\u0030\u65E5',
  24584. '\u33F4': '\u0032\u0031\u65E5',
  24585. '\u33F5': '\u0032\u0032\u65E5',
  24586. '\u33F6': '\u0032\u0033\u65E5',
  24587. '\u33F7': '\u0032\u0034\u65E5',
  24588. '\u33F8': '\u0032\u0035\u65E5',
  24589. '\u33F9': '\u0032\u0036\u65E5',
  24590. '\u33FA': '\u0032\u0037\u65E5',
  24591. '\u33FB': '\u0032\u0038\u65E5',
  24592. '\u33FC': '\u0032\u0039\u65E5',
  24593. '\u33FD': '\u0033\u0030\u65E5',
  24594. '\u33FE': '\u0033\u0031\u65E5',
  24595. '\uFB00': '\u0066\u0066',
  24596. '\uFB01': '\u0066\u0069',
  24597. '\uFB02': '\u0066\u006C',
  24598. '\uFB03': '\u0066\u0066\u0069',
  24599. '\uFB04': '\u0066\u0066\u006C',
  24600. '\uFB05': '\u017F\u0074',
  24601. '\uFB06': '\u0073\u0074',
  24602. '\uFB13': '\u0574\u0576',
  24603. '\uFB14': '\u0574\u0565',
  24604. '\uFB15': '\u0574\u056B',
  24605. '\uFB16': '\u057E\u0576',
  24606. '\uFB17': '\u0574\u056D',
  24607. '\uFB4F': '\u05D0\u05DC',
  24608. '\uFB50': '\u0671',
  24609. '\uFB51': '\u0671',
  24610. '\uFB52': '\u067B',
  24611. '\uFB53': '\u067B',
  24612. '\uFB54': '\u067B',
  24613. '\uFB55': '\u067B',
  24614. '\uFB56': '\u067E',
  24615. '\uFB57': '\u067E',
  24616. '\uFB58': '\u067E',
  24617. '\uFB59': '\u067E',
  24618. '\uFB5A': '\u0680',
  24619. '\uFB5B': '\u0680',
  24620. '\uFB5C': '\u0680',
  24621. '\uFB5D': '\u0680',
  24622. '\uFB5E': '\u067A',
  24623. '\uFB5F': '\u067A',
  24624. '\uFB60': '\u067A',
  24625. '\uFB61': '\u067A',
  24626. '\uFB62': '\u067F',
  24627. '\uFB63': '\u067F',
  24628. '\uFB64': '\u067F',
  24629. '\uFB65': '\u067F',
  24630. '\uFB66': '\u0679',
  24631. '\uFB67': '\u0679',
  24632. '\uFB68': '\u0679',
  24633. '\uFB69': '\u0679',
  24634. '\uFB6A': '\u06A4',
  24635. '\uFB6B': '\u06A4',
  24636. '\uFB6C': '\u06A4',
  24637. '\uFB6D': '\u06A4',
  24638. '\uFB6E': '\u06A6',
  24639. '\uFB6F': '\u06A6',
  24640. '\uFB70': '\u06A6',
  24641. '\uFB71': '\u06A6',
  24642. '\uFB72': '\u0684',
  24643. '\uFB73': '\u0684',
  24644. '\uFB74': '\u0684',
  24645. '\uFB75': '\u0684',
  24646. '\uFB76': '\u0683',
  24647. '\uFB77': '\u0683',
  24648. '\uFB78': '\u0683',
  24649. '\uFB79': '\u0683',
  24650. '\uFB7A': '\u0686',
  24651. '\uFB7B': '\u0686',
  24652. '\uFB7C': '\u0686',
  24653. '\uFB7D': '\u0686',
  24654. '\uFB7E': '\u0687',
  24655. '\uFB7F': '\u0687',
  24656. '\uFB80': '\u0687',
  24657. '\uFB81': '\u0687',
  24658. '\uFB82': '\u068D',
  24659. '\uFB83': '\u068D',
  24660. '\uFB84': '\u068C',
  24661. '\uFB85': '\u068C',
  24662. '\uFB86': '\u068E',
  24663. '\uFB87': '\u068E',
  24664. '\uFB88': '\u0688',
  24665. '\uFB89': '\u0688',
  24666. '\uFB8A': '\u0698',
  24667. '\uFB8B': '\u0698',
  24668. '\uFB8C': '\u0691',
  24669. '\uFB8D': '\u0691',
  24670. '\uFB8E': '\u06A9',
  24671. '\uFB8F': '\u06A9',
  24672. '\uFB90': '\u06A9',
  24673. '\uFB91': '\u06A9',
  24674. '\uFB92': '\u06AF',
  24675. '\uFB93': '\u06AF',
  24676. '\uFB94': '\u06AF',
  24677. '\uFB95': '\u06AF',
  24678. '\uFB96': '\u06B3',
  24679. '\uFB97': '\u06B3',
  24680. '\uFB98': '\u06B3',
  24681. '\uFB99': '\u06B3',
  24682. '\uFB9A': '\u06B1',
  24683. '\uFB9B': '\u06B1',
  24684. '\uFB9C': '\u06B1',
  24685. '\uFB9D': '\u06B1',
  24686. '\uFB9E': '\u06BA',
  24687. '\uFB9F': '\u06BA',
  24688. '\uFBA0': '\u06BB',
  24689. '\uFBA1': '\u06BB',
  24690. '\uFBA2': '\u06BB',
  24691. '\uFBA3': '\u06BB',
  24692. '\uFBA4': '\u06C0',
  24693. '\uFBA5': '\u06C0',
  24694. '\uFBA6': '\u06C1',
  24695. '\uFBA7': '\u06C1',
  24696. '\uFBA8': '\u06C1',
  24697. '\uFBA9': '\u06C1',
  24698. '\uFBAA': '\u06BE',
  24699. '\uFBAB': '\u06BE',
  24700. '\uFBAC': '\u06BE',
  24701. '\uFBAD': '\u06BE',
  24702. '\uFBAE': '\u06D2',
  24703. '\uFBAF': '\u06D2',
  24704. '\uFBB0': '\u06D3',
  24705. '\uFBB1': '\u06D3',
  24706. '\uFBD3': '\u06AD',
  24707. '\uFBD4': '\u06AD',
  24708. '\uFBD5': '\u06AD',
  24709. '\uFBD6': '\u06AD',
  24710. '\uFBD7': '\u06C7',
  24711. '\uFBD8': '\u06C7',
  24712. '\uFBD9': '\u06C6',
  24713. '\uFBDA': '\u06C6',
  24714. '\uFBDB': '\u06C8',
  24715. '\uFBDC': '\u06C8',
  24716. '\uFBDD': '\u0677',
  24717. '\uFBDE': '\u06CB',
  24718. '\uFBDF': '\u06CB',
  24719. '\uFBE0': '\u06C5',
  24720. '\uFBE1': '\u06C5',
  24721. '\uFBE2': '\u06C9',
  24722. '\uFBE3': '\u06C9',
  24723. '\uFBE4': '\u06D0',
  24724. '\uFBE5': '\u06D0',
  24725. '\uFBE6': '\u06D0',
  24726. '\uFBE7': '\u06D0',
  24727. '\uFBE8': '\u0649',
  24728. '\uFBE9': '\u0649',
  24729. '\uFBEA': '\u0626\u0627',
  24730. '\uFBEB': '\u0626\u0627',
  24731. '\uFBEC': '\u0626\u06D5',
  24732. '\uFBED': '\u0626\u06D5',
  24733. '\uFBEE': '\u0626\u0648',
  24734. '\uFBEF': '\u0626\u0648',
  24735. '\uFBF0': '\u0626\u06C7',
  24736. '\uFBF1': '\u0626\u06C7',
  24737. '\uFBF2': '\u0626\u06C6',
  24738. '\uFBF3': '\u0626\u06C6',
  24739. '\uFBF4': '\u0626\u06C8',
  24740. '\uFBF5': '\u0626\u06C8',
  24741. '\uFBF6': '\u0626\u06D0',
  24742. '\uFBF7': '\u0626\u06D0',
  24743. '\uFBF8': '\u0626\u06D0',
  24744. '\uFBF9': '\u0626\u0649',
  24745. '\uFBFA': '\u0626\u0649',
  24746. '\uFBFB': '\u0626\u0649',
  24747. '\uFBFC': '\u06CC',
  24748. '\uFBFD': '\u06CC',
  24749. '\uFBFE': '\u06CC',
  24750. '\uFBFF': '\u06CC',
  24751. '\uFC00': '\u0626\u062C',
  24752. '\uFC01': '\u0626\u062D',
  24753. '\uFC02': '\u0626\u0645',
  24754. '\uFC03': '\u0626\u0649',
  24755. '\uFC04': '\u0626\u064A',
  24756. '\uFC05': '\u0628\u062C',
  24757. '\uFC06': '\u0628\u062D',
  24758. '\uFC07': '\u0628\u062E',
  24759. '\uFC08': '\u0628\u0645',
  24760. '\uFC09': '\u0628\u0649',
  24761. '\uFC0A': '\u0628\u064A',
  24762. '\uFC0B': '\u062A\u062C',
  24763. '\uFC0C': '\u062A\u062D',
  24764. '\uFC0D': '\u062A\u062E',
  24765. '\uFC0E': '\u062A\u0645',
  24766. '\uFC0F': '\u062A\u0649',
  24767. '\uFC10': '\u062A\u064A',
  24768. '\uFC11': '\u062B\u062C',
  24769. '\uFC12': '\u062B\u0645',
  24770. '\uFC13': '\u062B\u0649',
  24771. '\uFC14': '\u062B\u064A',
  24772. '\uFC15': '\u062C\u062D',
  24773. '\uFC16': '\u062C\u0645',
  24774. '\uFC17': '\u062D\u062C',
  24775. '\uFC18': '\u062D\u0645',
  24776. '\uFC19': '\u062E\u062C',
  24777. '\uFC1A': '\u062E\u062D',
  24778. '\uFC1B': '\u062E\u0645',
  24779. '\uFC1C': '\u0633\u062C',
  24780. '\uFC1D': '\u0633\u062D',
  24781. '\uFC1E': '\u0633\u062E',
  24782. '\uFC1F': '\u0633\u0645',
  24783. '\uFC20': '\u0635\u062D',
  24784. '\uFC21': '\u0635\u0645',
  24785. '\uFC22': '\u0636\u062C',
  24786. '\uFC23': '\u0636\u062D',
  24787. '\uFC24': '\u0636\u062E',
  24788. '\uFC25': '\u0636\u0645',
  24789. '\uFC26': '\u0637\u062D',
  24790. '\uFC27': '\u0637\u0645',
  24791. '\uFC28': '\u0638\u0645',
  24792. '\uFC29': '\u0639\u062C',
  24793. '\uFC2A': '\u0639\u0645',
  24794. '\uFC2B': '\u063A\u062C',
  24795. '\uFC2C': '\u063A\u0645',
  24796. '\uFC2D': '\u0641\u062C',
  24797. '\uFC2E': '\u0641\u062D',
  24798. '\uFC2F': '\u0641\u062E',
  24799. '\uFC30': '\u0641\u0645',
  24800. '\uFC31': '\u0641\u0649',
  24801. '\uFC32': '\u0641\u064A',
  24802. '\uFC33': '\u0642\u062D',
  24803. '\uFC34': '\u0642\u0645',
  24804. '\uFC35': '\u0642\u0649',
  24805. '\uFC36': '\u0642\u064A',
  24806. '\uFC37': '\u0643\u0627',
  24807. '\uFC38': '\u0643\u062C',
  24808. '\uFC39': '\u0643\u062D',
  24809. '\uFC3A': '\u0643\u062E',
  24810. '\uFC3B': '\u0643\u0644',
  24811. '\uFC3C': '\u0643\u0645',
  24812. '\uFC3D': '\u0643\u0649',
  24813. '\uFC3E': '\u0643\u064A',
  24814. '\uFC3F': '\u0644\u062C',
  24815. '\uFC40': '\u0644\u062D',
  24816. '\uFC41': '\u0644\u062E',
  24817. '\uFC42': '\u0644\u0645',
  24818. '\uFC43': '\u0644\u0649',
  24819. '\uFC44': '\u0644\u064A',
  24820. '\uFC45': '\u0645\u062C',
  24821. '\uFC46': '\u0645\u062D',
  24822. '\uFC47': '\u0645\u062E',
  24823. '\uFC48': '\u0645\u0645',
  24824. '\uFC49': '\u0645\u0649',
  24825. '\uFC4A': '\u0645\u064A',
  24826. '\uFC4B': '\u0646\u062C',
  24827. '\uFC4C': '\u0646\u062D',
  24828. '\uFC4D': '\u0646\u062E',
  24829. '\uFC4E': '\u0646\u0645',
  24830. '\uFC4F': '\u0646\u0649',
  24831. '\uFC50': '\u0646\u064A',
  24832. '\uFC51': '\u0647\u062C',
  24833. '\uFC52': '\u0647\u0645',
  24834. '\uFC53': '\u0647\u0649',
  24835. '\uFC54': '\u0647\u064A',
  24836. '\uFC55': '\u064A\u062C',
  24837. '\uFC56': '\u064A\u062D',
  24838. '\uFC57': '\u064A\u062E',
  24839. '\uFC58': '\u064A\u0645',
  24840. '\uFC59': '\u064A\u0649',
  24841. '\uFC5A': '\u064A\u064A',
  24842. '\uFC5B': '\u0630\u0670',
  24843. '\uFC5C': '\u0631\u0670',
  24844. '\uFC5D': '\u0649\u0670',
  24845. '\uFC5E': '\u0020\u064C\u0651',
  24846. '\uFC5F': '\u0020\u064D\u0651',
  24847. '\uFC60': '\u0020\u064E\u0651',
  24848. '\uFC61': '\u0020\u064F\u0651',
  24849. '\uFC62': '\u0020\u0650\u0651',
  24850. '\uFC63': '\u0020\u0651\u0670',
  24851. '\uFC64': '\u0626\u0631',
  24852. '\uFC65': '\u0626\u0632',
  24853. '\uFC66': '\u0626\u0645',
  24854. '\uFC67': '\u0626\u0646',
  24855. '\uFC68': '\u0626\u0649',
  24856. '\uFC69': '\u0626\u064A',
  24857. '\uFC6A': '\u0628\u0631',
  24858. '\uFC6B': '\u0628\u0632',
  24859. '\uFC6C': '\u0628\u0645',
  24860. '\uFC6D': '\u0628\u0646',
  24861. '\uFC6E': '\u0628\u0649',
  24862. '\uFC6F': '\u0628\u064A',
  24863. '\uFC70': '\u062A\u0631',
  24864. '\uFC71': '\u062A\u0632',
  24865. '\uFC72': '\u062A\u0645',
  24866. '\uFC73': '\u062A\u0646',
  24867. '\uFC74': '\u062A\u0649',
  24868. '\uFC75': '\u062A\u064A',
  24869. '\uFC76': '\u062B\u0631',
  24870. '\uFC77': '\u062B\u0632',
  24871. '\uFC78': '\u062B\u0645',
  24872. '\uFC79': '\u062B\u0646',
  24873. '\uFC7A': '\u062B\u0649',
  24874. '\uFC7B': '\u062B\u064A',
  24875. '\uFC7C': '\u0641\u0649',
  24876. '\uFC7D': '\u0641\u064A',
  24877. '\uFC7E': '\u0642\u0649',
  24878. '\uFC7F': '\u0642\u064A',
  24879. '\uFC80': '\u0643\u0627',
  24880. '\uFC81': '\u0643\u0644',
  24881. '\uFC82': '\u0643\u0645',
  24882. '\uFC83': '\u0643\u0649',
  24883. '\uFC84': '\u0643\u064A',
  24884. '\uFC85': '\u0644\u0645',
  24885. '\uFC86': '\u0644\u0649',
  24886. '\uFC87': '\u0644\u064A',
  24887. '\uFC88': '\u0645\u0627',
  24888. '\uFC89': '\u0645\u0645',
  24889. '\uFC8A': '\u0646\u0631',
  24890. '\uFC8B': '\u0646\u0632',
  24891. '\uFC8C': '\u0646\u0645',
  24892. '\uFC8D': '\u0646\u0646',
  24893. '\uFC8E': '\u0646\u0649',
  24894. '\uFC8F': '\u0646\u064A',
  24895. '\uFC90': '\u0649\u0670',
  24896. '\uFC91': '\u064A\u0631',
  24897. '\uFC92': '\u064A\u0632',
  24898. '\uFC93': '\u064A\u0645',
  24899. '\uFC94': '\u064A\u0646',
  24900. '\uFC95': '\u064A\u0649',
  24901. '\uFC96': '\u064A\u064A',
  24902. '\uFC97': '\u0626\u062C',
  24903. '\uFC98': '\u0626\u062D',
  24904. '\uFC99': '\u0626\u062E',
  24905. '\uFC9A': '\u0626\u0645',
  24906. '\uFC9B': '\u0626\u0647',
  24907. '\uFC9C': '\u0628\u062C',
  24908. '\uFC9D': '\u0628\u062D',
  24909. '\uFC9E': '\u0628\u062E',
  24910. '\uFC9F': '\u0628\u0645',
  24911. '\uFCA0': '\u0628\u0647',
  24912. '\uFCA1': '\u062A\u062C',
  24913. '\uFCA2': '\u062A\u062D',
  24914. '\uFCA3': '\u062A\u062E',
  24915. '\uFCA4': '\u062A\u0645',
  24916. '\uFCA5': '\u062A\u0647',
  24917. '\uFCA6': '\u062B\u0645',
  24918. '\uFCA7': '\u062C\u062D',
  24919. '\uFCA8': '\u062C\u0645',
  24920. '\uFCA9': '\u062D\u062C',
  24921. '\uFCAA': '\u062D\u0645',
  24922. '\uFCAB': '\u062E\u062C',
  24923. '\uFCAC': '\u062E\u0645',
  24924. '\uFCAD': '\u0633\u062C',
  24925. '\uFCAE': '\u0633\u062D',
  24926. '\uFCAF': '\u0633\u062E',
  24927. '\uFCB0': '\u0633\u0645',
  24928. '\uFCB1': '\u0635\u062D',
  24929. '\uFCB2': '\u0635\u062E',
  24930. '\uFCB3': '\u0635\u0645',
  24931. '\uFCB4': '\u0636\u062C',
  24932. '\uFCB5': '\u0636\u062D',
  24933. '\uFCB6': '\u0636\u062E',
  24934. '\uFCB7': '\u0636\u0645',
  24935. '\uFCB8': '\u0637\u062D',
  24936. '\uFCB9': '\u0638\u0645',
  24937. '\uFCBA': '\u0639\u062C',
  24938. '\uFCBB': '\u0639\u0645',
  24939. '\uFCBC': '\u063A\u062C',
  24940. '\uFCBD': '\u063A\u0645',
  24941. '\uFCBE': '\u0641\u062C',
  24942. '\uFCBF': '\u0641\u062D',
  24943. '\uFCC0': '\u0641\u062E',
  24944. '\uFCC1': '\u0641\u0645',
  24945. '\uFCC2': '\u0642\u062D',
  24946. '\uFCC3': '\u0642\u0645',
  24947. '\uFCC4': '\u0643\u062C',
  24948. '\uFCC5': '\u0643\u062D',
  24949. '\uFCC6': '\u0643\u062E',
  24950. '\uFCC7': '\u0643\u0644',
  24951. '\uFCC8': '\u0643\u0645',
  24952. '\uFCC9': '\u0644\u062C',
  24953. '\uFCCA': '\u0644\u062D',
  24954. '\uFCCB': '\u0644\u062E',
  24955. '\uFCCC': '\u0644\u0645',
  24956. '\uFCCD': '\u0644\u0647',
  24957. '\uFCCE': '\u0645\u062C',
  24958. '\uFCCF': '\u0645\u062D',
  24959. '\uFCD0': '\u0645\u062E',
  24960. '\uFCD1': '\u0645\u0645',
  24961. '\uFCD2': '\u0646\u062C',
  24962. '\uFCD3': '\u0646\u062D',
  24963. '\uFCD4': '\u0646\u062E',
  24964. '\uFCD5': '\u0646\u0645',
  24965. '\uFCD6': '\u0646\u0647',
  24966. '\uFCD7': '\u0647\u062C',
  24967. '\uFCD8': '\u0647\u0645',
  24968. '\uFCD9': '\u0647\u0670',
  24969. '\uFCDA': '\u064A\u062C',
  24970. '\uFCDB': '\u064A\u062D',
  24971. '\uFCDC': '\u064A\u062E',
  24972. '\uFCDD': '\u064A\u0645',
  24973. '\uFCDE': '\u064A\u0647',
  24974. '\uFCDF': '\u0626\u0645',
  24975. '\uFCE0': '\u0626\u0647',
  24976. '\uFCE1': '\u0628\u0645',
  24977. '\uFCE2': '\u0628\u0647',
  24978. '\uFCE3': '\u062A\u0645',
  24979. '\uFCE4': '\u062A\u0647',
  24980. '\uFCE5': '\u062B\u0645',
  24981. '\uFCE6': '\u062B\u0647',
  24982. '\uFCE7': '\u0633\u0645',
  24983. '\uFCE8': '\u0633\u0647',
  24984. '\uFCE9': '\u0634\u0645',
  24985. '\uFCEA': '\u0634\u0647',
  24986. '\uFCEB': '\u0643\u0644',
  24987. '\uFCEC': '\u0643\u0645',
  24988. '\uFCED': '\u0644\u0645',
  24989. '\uFCEE': '\u0646\u0645',
  24990. '\uFCEF': '\u0646\u0647',
  24991. '\uFCF0': '\u064A\u0645',
  24992. '\uFCF1': '\u064A\u0647',
  24993. '\uFCF2': '\u0640\u064E\u0651',
  24994. '\uFCF3': '\u0640\u064F\u0651',
  24995. '\uFCF4': '\u0640\u0650\u0651',
  24996. '\uFCF5': '\u0637\u0649',
  24997. '\uFCF6': '\u0637\u064A',
  24998. '\uFCF7': '\u0639\u0649',
  24999. '\uFCF8': '\u0639\u064A',
  25000. '\uFCF9': '\u063A\u0649',
  25001. '\uFCFA': '\u063A\u064A',
  25002. '\uFCFB': '\u0633\u0649',
  25003. '\uFCFC': '\u0633\u064A',
  25004. '\uFCFD': '\u0634\u0649',
  25005. '\uFCFE': '\u0634\u064A',
  25006. '\uFCFF': '\u062D\u0649',
  25007. '\uFD00': '\u062D\u064A',
  25008. '\uFD01': '\u062C\u0649',
  25009. '\uFD02': '\u062C\u064A',
  25010. '\uFD03': '\u062E\u0649',
  25011. '\uFD04': '\u062E\u064A',
  25012. '\uFD05': '\u0635\u0649',
  25013. '\uFD06': '\u0635\u064A',
  25014. '\uFD07': '\u0636\u0649',
  25015. '\uFD08': '\u0636\u064A',
  25016. '\uFD09': '\u0634\u062C',
  25017. '\uFD0A': '\u0634\u062D',
  25018. '\uFD0B': '\u0634\u062E',
  25019. '\uFD0C': '\u0634\u0645',
  25020. '\uFD0D': '\u0634\u0631',
  25021. '\uFD0E': '\u0633\u0631',
  25022. '\uFD0F': '\u0635\u0631',
  25023. '\uFD10': '\u0636\u0631',
  25024. '\uFD11': '\u0637\u0649',
  25025. '\uFD12': '\u0637\u064A',
  25026. '\uFD13': '\u0639\u0649',
  25027. '\uFD14': '\u0639\u064A',
  25028. '\uFD15': '\u063A\u0649',
  25029. '\uFD16': '\u063A\u064A',
  25030. '\uFD17': '\u0633\u0649',
  25031. '\uFD18': '\u0633\u064A',
  25032. '\uFD19': '\u0634\u0649',
  25033. '\uFD1A': '\u0634\u064A',
  25034. '\uFD1B': '\u062D\u0649',
  25035. '\uFD1C': '\u062D\u064A',
  25036. '\uFD1D': '\u062C\u0649',
  25037. '\uFD1E': '\u062C\u064A',
  25038. '\uFD1F': '\u062E\u0649',
  25039. '\uFD20': '\u062E\u064A',
  25040. '\uFD21': '\u0635\u0649',
  25041. '\uFD22': '\u0635\u064A',
  25042. '\uFD23': '\u0636\u0649',
  25043. '\uFD24': '\u0636\u064A',
  25044. '\uFD25': '\u0634\u062C',
  25045. '\uFD26': '\u0634\u062D',
  25046. '\uFD27': '\u0634\u062E',
  25047. '\uFD28': '\u0634\u0645',
  25048. '\uFD29': '\u0634\u0631',
  25049. '\uFD2A': '\u0633\u0631',
  25050. '\uFD2B': '\u0635\u0631',
  25051. '\uFD2C': '\u0636\u0631',
  25052. '\uFD2D': '\u0634\u062C',
  25053. '\uFD2E': '\u0634\u062D',
  25054. '\uFD2F': '\u0634\u062E',
  25055. '\uFD30': '\u0634\u0645',
  25056. '\uFD31': '\u0633\u0647',
  25057. '\uFD32': '\u0634\u0647',
  25058. '\uFD33': '\u0637\u0645',
  25059. '\uFD34': '\u0633\u062C',
  25060. '\uFD35': '\u0633\u062D',
  25061. '\uFD36': '\u0633\u062E',
  25062. '\uFD37': '\u0634\u062C',
  25063. '\uFD38': '\u0634\u062D',
  25064. '\uFD39': '\u0634\u062E',
  25065. '\uFD3A': '\u0637\u0645',
  25066. '\uFD3B': '\u0638\u0645',
  25067. '\uFD3C': '\u0627\u064B',
  25068. '\uFD3D': '\u0627\u064B',
  25069. '\uFD50': '\u062A\u062C\u0645',
  25070. '\uFD51': '\u062A\u062D\u062C',
  25071. '\uFD52': '\u062A\u062D\u062C',
  25072. '\uFD53': '\u062A\u062D\u0645',
  25073. '\uFD54': '\u062A\u062E\u0645',
  25074. '\uFD55': '\u062A\u0645\u062C',
  25075. '\uFD56': '\u062A\u0645\u062D',
  25076. '\uFD57': '\u062A\u0645\u062E',
  25077. '\uFD58': '\u062C\u0645\u062D',
  25078. '\uFD59': '\u062C\u0645\u062D',
  25079. '\uFD5A': '\u062D\u0645\u064A',
  25080. '\uFD5B': '\u062D\u0645\u0649',
  25081. '\uFD5C': '\u0633\u062D\u062C',
  25082. '\uFD5D': '\u0633\u062C\u062D',
  25083. '\uFD5E': '\u0633\u062C\u0649',
  25084. '\uFD5F': '\u0633\u0645\u062D',
  25085. '\uFD60': '\u0633\u0645\u062D',
  25086. '\uFD61': '\u0633\u0645\u062C',
  25087. '\uFD62': '\u0633\u0645\u0645',
  25088. '\uFD63': '\u0633\u0645\u0645',
  25089. '\uFD64': '\u0635\u062D\u062D',
  25090. '\uFD65': '\u0635\u062D\u062D',
  25091. '\uFD66': '\u0635\u0645\u0645',
  25092. '\uFD67': '\u0634\u062D\u0645',
  25093. '\uFD68': '\u0634\u062D\u0645',
  25094. '\uFD69': '\u0634\u062C\u064A',
  25095. '\uFD6A': '\u0634\u0645\u062E',
  25096. '\uFD6B': '\u0634\u0645\u062E',
  25097. '\uFD6C': '\u0634\u0645\u0645',
  25098. '\uFD6D': '\u0634\u0645\u0645',
  25099. '\uFD6E': '\u0636\u062D\u0649',
  25100. '\uFD6F': '\u0636\u062E\u0645',
  25101. '\uFD70': '\u0636\u062E\u0645',
  25102. '\uFD71': '\u0637\u0645\u062D',
  25103. '\uFD72': '\u0637\u0645\u062D',
  25104. '\uFD73': '\u0637\u0645\u0645',
  25105. '\uFD74': '\u0637\u0645\u064A',
  25106. '\uFD75': '\u0639\u062C\u0645',
  25107. '\uFD76': '\u0639\u0645\u0645',
  25108. '\uFD77': '\u0639\u0645\u0645',
  25109. '\uFD78': '\u0639\u0645\u0649',
  25110. '\uFD79': '\u063A\u0645\u0645',
  25111. '\uFD7A': '\u063A\u0645\u064A',
  25112. '\uFD7B': '\u063A\u0645\u0649',
  25113. '\uFD7C': '\u0641\u062E\u0645',
  25114. '\uFD7D': '\u0641\u062E\u0645',
  25115. '\uFD7E': '\u0642\u0645\u062D',
  25116. '\uFD7F': '\u0642\u0645\u0645',
  25117. '\uFD80': '\u0644\u062D\u0645',
  25118. '\uFD81': '\u0644\u062D\u064A',
  25119. '\uFD82': '\u0644\u062D\u0649',
  25120. '\uFD83': '\u0644\u062C\u062C',
  25121. '\uFD84': '\u0644\u062C\u062C',
  25122. '\uFD85': '\u0644\u062E\u0645',
  25123. '\uFD86': '\u0644\u062E\u0645',
  25124. '\uFD87': '\u0644\u0645\u062D',
  25125. '\uFD88': '\u0644\u0645\u062D',
  25126. '\uFD89': '\u0645\u062D\u062C',
  25127. '\uFD8A': '\u0645\u062D\u0645',
  25128. '\uFD8B': '\u0645\u062D\u064A',
  25129. '\uFD8C': '\u0645\u062C\u062D',
  25130. '\uFD8D': '\u0645\u062C\u0645',
  25131. '\uFD8E': '\u0645\u062E\u062C',
  25132. '\uFD8F': '\u0645\u062E\u0645',
  25133. '\uFD92': '\u0645\u062C\u062E',
  25134. '\uFD93': '\u0647\u0645\u062C',
  25135. '\uFD94': '\u0647\u0645\u0645',
  25136. '\uFD95': '\u0646\u062D\u0645',
  25137. '\uFD96': '\u0646\u062D\u0649',
  25138. '\uFD97': '\u0646\u062C\u0645',
  25139. '\uFD98': '\u0646\u062C\u0645',
  25140. '\uFD99': '\u0646\u062C\u0649',
  25141. '\uFD9A': '\u0646\u0645\u064A',
  25142. '\uFD9B': '\u0646\u0645\u0649',
  25143. '\uFD9C': '\u064A\u0645\u0645',
  25144. '\uFD9D': '\u064A\u0645\u0645',
  25145. '\uFD9E': '\u0628\u062E\u064A',
  25146. '\uFD9F': '\u062A\u062C\u064A',
  25147. '\uFDA0': '\u062A\u062C\u0649',
  25148. '\uFDA1': '\u062A\u062E\u064A',
  25149. '\uFDA2': '\u062A\u062E\u0649',
  25150. '\uFDA3': '\u062A\u0645\u064A',
  25151. '\uFDA4': '\u062A\u0645\u0649',
  25152. '\uFDA5': '\u062C\u0645\u064A',
  25153. '\uFDA6': '\u062C\u062D\u0649',
  25154. '\uFDA7': '\u062C\u0645\u0649',
  25155. '\uFDA8': '\u0633\u062E\u0649',
  25156. '\uFDA9': '\u0635\u062D\u064A',
  25157. '\uFDAA': '\u0634\u062D\u064A',
  25158. '\uFDAB': '\u0636\u062D\u064A',
  25159. '\uFDAC': '\u0644\u062C\u064A',
  25160. '\uFDAD': '\u0644\u0645\u064A',
  25161. '\uFDAE': '\u064A\u062D\u064A',
  25162. '\uFDAF': '\u064A\u062C\u064A',
  25163. '\uFDB0': '\u064A\u0645\u064A',
  25164. '\uFDB1': '\u0645\u0645\u064A',
  25165. '\uFDB2': '\u0642\u0645\u064A',
  25166. '\uFDB3': '\u0646\u062D\u064A',
  25167. '\uFDB4': '\u0642\u0645\u062D',
  25168. '\uFDB5': '\u0644\u062D\u0645',
  25169. '\uFDB6': '\u0639\u0645\u064A',
  25170. '\uFDB7': '\u0643\u0645\u064A',
  25171. '\uFDB8': '\u0646\u062C\u062D',
  25172. '\uFDB9': '\u0645\u062E\u064A',
  25173. '\uFDBA': '\u0644\u062C\u0645',
  25174. '\uFDBB': '\u0643\u0645\u0645',
  25175. '\uFDBC': '\u0644\u062C\u0645',
  25176. '\uFDBD': '\u0646\u062C\u062D',
  25177. '\uFDBE': '\u062C\u062D\u064A',
  25178. '\uFDBF': '\u062D\u062C\u064A',
  25179. '\uFDC0': '\u0645\u062C\u064A',
  25180. '\uFDC1': '\u0641\u0645\u064A',
  25181. '\uFDC2': '\u0628\u062D\u064A',
  25182. '\uFDC3': '\u0643\u0645\u0645',
  25183. '\uFDC4': '\u0639\u062C\u0645',
  25184. '\uFDC5': '\u0635\u0645\u0645',
  25185. '\uFDC6': '\u0633\u062E\u064A',
  25186. '\uFDC7': '\u0646\u062C\u064A',
  25187. '\uFE49': '\u203E',
  25188. '\uFE4A': '\u203E',
  25189. '\uFE4B': '\u203E',
  25190. '\uFE4C': '\u203E',
  25191. '\uFE4D': '\u005F',
  25192. '\uFE4E': '\u005F',
  25193. '\uFE4F': '\u005F',
  25194. '\uFE80': '\u0621',
  25195. '\uFE81': '\u0622',
  25196. '\uFE82': '\u0622',
  25197. '\uFE83': '\u0623',
  25198. '\uFE84': '\u0623',
  25199. '\uFE85': '\u0624',
  25200. '\uFE86': '\u0624',
  25201. '\uFE87': '\u0625',
  25202. '\uFE88': '\u0625',
  25203. '\uFE89': '\u0626',
  25204. '\uFE8A': '\u0626',
  25205. '\uFE8B': '\u0626',
  25206. '\uFE8C': '\u0626',
  25207. '\uFE8D': '\u0627',
  25208. '\uFE8E': '\u0627',
  25209. '\uFE8F': '\u0628',
  25210. '\uFE90': '\u0628',
  25211. '\uFE91': '\u0628',
  25212. '\uFE92': '\u0628',
  25213. '\uFE93': '\u0629',
  25214. '\uFE94': '\u0629',
  25215. '\uFE95': '\u062A',
  25216. '\uFE96': '\u062A',
  25217. '\uFE97': '\u062A',
  25218. '\uFE98': '\u062A',
  25219. '\uFE99': '\u062B',
  25220. '\uFE9A': '\u062B',
  25221. '\uFE9B': '\u062B',
  25222. '\uFE9C': '\u062B',
  25223. '\uFE9D': '\u062C',
  25224. '\uFE9E': '\u062C',
  25225. '\uFE9F': '\u062C',
  25226. '\uFEA0': '\u062C',
  25227. '\uFEA1': '\u062D',
  25228. '\uFEA2': '\u062D',
  25229. '\uFEA3': '\u062D',
  25230. '\uFEA4': '\u062D',
  25231. '\uFEA5': '\u062E',
  25232. '\uFEA6': '\u062E',
  25233. '\uFEA7': '\u062E',
  25234. '\uFEA8': '\u062E',
  25235. '\uFEA9': '\u062F',
  25236. '\uFEAA': '\u062F',
  25237. '\uFEAB': '\u0630',
  25238. '\uFEAC': '\u0630',
  25239. '\uFEAD': '\u0631',
  25240. '\uFEAE': '\u0631',
  25241. '\uFEAF': '\u0632',
  25242. '\uFEB0': '\u0632',
  25243. '\uFEB1': '\u0633',
  25244. '\uFEB2': '\u0633',
  25245. '\uFEB3': '\u0633',
  25246. '\uFEB4': '\u0633',
  25247. '\uFEB5': '\u0634',
  25248. '\uFEB6': '\u0634',
  25249. '\uFEB7': '\u0634',
  25250. '\uFEB8': '\u0634',
  25251. '\uFEB9': '\u0635',
  25252. '\uFEBA': '\u0635',
  25253. '\uFEBB': '\u0635',
  25254. '\uFEBC': '\u0635',
  25255. '\uFEBD': '\u0636',
  25256. '\uFEBE': '\u0636',
  25257. '\uFEBF': '\u0636',
  25258. '\uFEC0': '\u0636',
  25259. '\uFEC1': '\u0637',
  25260. '\uFEC2': '\u0637',
  25261. '\uFEC3': '\u0637',
  25262. '\uFEC4': '\u0637',
  25263. '\uFEC5': '\u0638',
  25264. '\uFEC6': '\u0638',
  25265. '\uFEC7': '\u0638',
  25266. '\uFEC8': '\u0638',
  25267. '\uFEC9': '\u0639',
  25268. '\uFECA': '\u0639',
  25269. '\uFECB': '\u0639',
  25270. '\uFECC': '\u0639',
  25271. '\uFECD': '\u063A',
  25272. '\uFECE': '\u063A',
  25273. '\uFECF': '\u063A',
  25274. '\uFED0': '\u063A',
  25275. '\uFED1': '\u0641',
  25276. '\uFED2': '\u0641',
  25277. '\uFED3': '\u0641',
  25278. '\uFED4': '\u0641',
  25279. '\uFED5': '\u0642',
  25280. '\uFED6': '\u0642',
  25281. '\uFED7': '\u0642',
  25282. '\uFED8': '\u0642',
  25283. '\uFED9': '\u0643',
  25284. '\uFEDA': '\u0643',
  25285. '\uFEDB': '\u0643',
  25286. '\uFEDC': '\u0643',
  25287. '\uFEDD': '\u0644',
  25288. '\uFEDE': '\u0644',
  25289. '\uFEDF': '\u0644',
  25290. '\uFEE0': '\u0644',
  25291. '\uFEE1': '\u0645',
  25292. '\uFEE2': '\u0645',
  25293. '\uFEE3': '\u0645',
  25294. '\uFEE4': '\u0645',
  25295. '\uFEE5': '\u0646',
  25296. '\uFEE6': '\u0646',
  25297. '\uFEE7': '\u0646',
  25298. '\uFEE8': '\u0646',
  25299. '\uFEE9': '\u0647',
  25300. '\uFEEA': '\u0647',
  25301. '\uFEEB': '\u0647',
  25302. '\uFEEC': '\u0647',
  25303. '\uFEED': '\u0648',
  25304. '\uFEEE': '\u0648',
  25305. '\uFEEF': '\u0649',
  25306. '\uFEF0': '\u0649',
  25307. '\uFEF1': '\u064A',
  25308. '\uFEF2': '\u064A',
  25309. '\uFEF3': '\u064A',
  25310. '\uFEF4': '\u064A',
  25311. '\uFEF5': '\u0644\u0622',
  25312. '\uFEF6': '\u0644\u0622',
  25313. '\uFEF7': '\u0644\u0623',
  25314. '\uFEF8': '\u0644\u0623',
  25315. '\uFEF9': '\u0644\u0625',
  25316. '\uFEFA': '\u0644\u0625',
  25317. '\uFEFB': '\u0644\u0627',
  25318. '\uFEFC': '\u0644\u0627'
  25319. };
  25320. function reverseIfRtl(chars) {
  25321. var charsLength = chars.length;
  25322. //reverse an arabic ligature
  25323. if (charsLength <= 1 || !isRTLRangeFor(chars.charCodeAt(0))) {
  25324. return chars;
  25325. }
  25326. var s = '';
  25327. for (var ii = charsLength - 1; ii >= 0; ii--) {
  25328. s += chars[ii];
  25329. }
  25330. return s;
  25331. }
  25332. function adjustWidths(properties) {
  25333. if (!properties.fontMatrix) {
  25334. return;
  25335. }
  25336. if (properties.fontMatrix[0] === FONT_IDENTITY_MATRIX[0]) {
  25337. return;
  25338. }
  25339. // adjusting width to fontMatrix scale
  25340. var scale = 0.001 / properties.fontMatrix[0];
  25341. var glyphsWidths = properties.widths;
  25342. for (var glyph in glyphsWidths) {
  25343. glyphsWidths[glyph] *= scale;
  25344. }
  25345. properties.defaultWidth *= scale;
  25346. }
  25347. function getFontType(type, subtype) {
  25348. switch (type) {
  25349. case 'Type1':
  25350. return subtype === 'Type1C' ? FontType.TYPE1C : FontType.TYPE1;
  25351. case 'CIDFontType0':
  25352. return subtype === 'CIDFontType0C' ? FontType.CIDFONTTYPE0C :
  25353. FontType.CIDFONTTYPE0;
  25354. case 'OpenType':
  25355. return FontType.OPENTYPE;
  25356. case 'TrueType':
  25357. return FontType.TRUETYPE;
  25358. case 'CIDFontType2':
  25359. return FontType.CIDFONTTYPE2;
  25360. case 'MMType1':
  25361. return FontType.MMTYPE1;
  25362. case 'Type0':
  25363. return FontType.TYPE0;
  25364. default:
  25365. return FontType.UNKNOWN;
  25366. }
  25367. }
  25368. var Glyph = (function GlyphClosure() {
  25369. function Glyph(fontChar, unicode, accent, width, vmetric, operatorListId,
  25370. isSpace) {
  25371. this.fontChar = fontChar;
  25372. this.unicode = unicode;
  25373. this.accent = accent;
  25374. this.width = width;
  25375. this.vmetric = vmetric;
  25376. this.operatorListId = operatorListId;
  25377. this.isSpace = isSpace;
  25378. }
  25379. Glyph.prototype.matchesForCache = function(fontChar, unicode, accent, width,
  25380. vmetric, operatorListId, isSpace) {
  25381. return this.fontChar === fontChar &&
  25382. this.unicode === unicode &&
  25383. this.accent === accent &&
  25384. this.width === width &&
  25385. this.vmetric === vmetric &&
  25386. this.operatorListId === operatorListId &&
  25387. this.isSpace === isSpace;
  25388. };
  25389. return Glyph;
  25390. })();
  25391. var ToUnicodeMap = (function ToUnicodeMapClosure() {
  25392. function ToUnicodeMap(cmap) {
  25393. // The elements of this._map can be integers or strings, depending on how
  25394. // |cmap| was created.
  25395. this._map = cmap;
  25396. }
  25397. ToUnicodeMap.prototype = {
  25398. get length() {
  25399. return this._map.length;
  25400. },
  25401. forEach: function(callback) {
  25402. for (var charCode in this._map) {
  25403. callback(charCode, this._map[charCode].charCodeAt(0));
  25404. }
  25405. },
  25406. has: function(i) {
  25407. return this._map[i] !== undefined;
  25408. },
  25409. get: function(i) {
  25410. return this._map[i];
  25411. },
  25412. charCodeOf: function(v) {
  25413. return this._map.indexOf(v);
  25414. }
  25415. };
  25416. return ToUnicodeMap;
  25417. })();
  25418. var IdentityToUnicodeMap = (function IdentityToUnicodeMapClosure() {
  25419. function IdentityToUnicodeMap(firstChar, lastChar) {
  25420. this.firstChar = firstChar;
  25421. this.lastChar = lastChar;
  25422. }
  25423. IdentityToUnicodeMap.prototype = {
  25424. get length() {
  25425. return (this.lastChar + 1) - this.firstChar;
  25426. },
  25427. forEach: function (callback) {
  25428. for (var i = this.firstChar, ii = this.lastChar; i <= ii; i++) {
  25429. callback(i, i);
  25430. }
  25431. },
  25432. has: function (i) {
  25433. return this.firstChar <= i && i <= this.lastChar;
  25434. },
  25435. get: function (i) {
  25436. if (this.firstChar <= i && i <= this.lastChar) {
  25437. return String.fromCharCode(i);
  25438. }
  25439. return undefined;
  25440. },
  25441. charCodeOf: function (v) {
  25442. return (isInt(v) && v >= this.firstChar && v <= this.lastChar) ? v : -1;
  25443. }
  25444. };
  25445. return IdentityToUnicodeMap;
  25446. })();
  25447. var OpenTypeFileBuilder = (function OpenTypeFileBuilderClosure() {
  25448. function writeInt16(dest, offset, num) {
  25449. dest[offset] = (num >> 8) & 0xFF;
  25450. dest[offset + 1] = num & 0xFF;
  25451. }
  25452. function writeInt32(dest, offset, num) {
  25453. dest[offset] = (num >> 24) & 0xFF;
  25454. dest[offset + 1] = (num >> 16) & 0xFF;
  25455. dest[offset + 2] = (num >> 8) & 0xFF;
  25456. dest[offset + 3] = num & 0xFF;
  25457. }
  25458. function writeData(dest, offset, data) {
  25459. var i, ii;
  25460. if (data instanceof Uint8Array) {
  25461. dest.set(data, offset);
  25462. } else if (typeof data === 'string') {
  25463. for (i = 0, ii = data.length; i < ii; i++) {
  25464. dest[offset++] = data.charCodeAt(i) & 0xFF;
  25465. }
  25466. } else {
  25467. // treating everything else as array
  25468. for (i = 0, ii = data.length; i < ii; i++) {
  25469. dest[offset++] = data[i] & 0xFF;
  25470. }
  25471. }
  25472. }
  25473. function OpenTypeFileBuilder(sfnt) {
  25474. this.sfnt = sfnt;
  25475. this.tables = Object.create(null);
  25476. }
  25477. OpenTypeFileBuilder.getSearchParams =
  25478. function OpenTypeFileBuilder_getSearchParams(entriesCount, entrySize) {
  25479. var maxPower2 = 1, log2 = 0;
  25480. while ((maxPower2 ^ entriesCount) > maxPower2) {
  25481. maxPower2 <<= 1;
  25482. log2++;
  25483. }
  25484. var searchRange = maxPower2 * entrySize;
  25485. return {
  25486. range: searchRange,
  25487. entry: log2,
  25488. rangeShift: entrySize * entriesCount - searchRange
  25489. };
  25490. };
  25491. var OTF_HEADER_SIZE = 12;
  25492. var OTF_TABLE_ENTRY_SIZE = 16;
  25493. OpenTypeFileBuilder.prototype = {
  25494. toArray: function OpenTypeFileBuilder_toArray() {
  25495. var sfnt = this.sfnt;
  25496. // Tables needs to be written by ascendant alphabetic order
  25497. var tables = this.tables;
  25498. var tablesNames = Object.keys(tables);
  25499. tablesNames.sort();
  25500. var numTables = tablesNames.length;
  25501. var i, j, jj, table, tableName;
  25502. // layout the tables data
  25503. var offset = OTF_HEADER_SIZE + numTables * OTF_TABLE_ENTRY_SIZE;
  25504. var tableOffsets = [offset];
  25505. for (i = 0; i < numTables; i++) {
  25506. table = tables[tablesNames[i]];
  25507. var paddedLength = ((table.length + 3) & ~3) >>> 0;
  25508. offset += paddedLength;
  25509. tableOffsets.push(offset);
  25510. }
  25511. var file = new Uint8Array(offset);
  25512. // write the table data first (mostly for checksum)
  25513. for (i = 0; i < numTables; i++) {
  25514. table = tables[tablesNames[i]];
  25515. writeData(file, tableOffsets[i], table);
  25516. }
  25517. // sfnt version (4 bytes)
  25518. if (sfnt === 'true') {
  25519. // Windows hates the Mac TrueType sfnt version number
  25520. sfnt = string32(0x00010000);
  25521. }
  25522. file[0] = sfnt.charCodeAt(0) & 0xFF;
  25523. file[1] = sfnt.charCodeAt(1) & 0xFF;
  25524. file[2] = sfnt.charCodeAt(2) & 0xFF;
  25525. file[3] = sfnt.charCodeAt(3) & 0xFF;
  25526. // numTables (2 bytes)
  25527. writeInt16(file, 4, numTables);
  25528. var searchParams = OpenTypeFileBuilder.getSearchParams(numTables, 16);
  25529. // searchRange (2 bytes)
  25530. writeInt16(file, 6, searchParams.range);
  25531. // entrySelector (2 bytes)
  25532. writeInt16(file, 8, searchParams.entry);
  25533. // rangeShift (2 bytes)
  25534. writeInt16(file, 10, searchParams.rangeShift);
  25535. offset = OTF_HEADER_SIZE;
  25536. // writing table entries
  25537. for (i = 0; i < numTables; i++) {
  25538. tableName = tablesNames[i];
  25539. file[offset] = tableName.charCodeAt(0) & 0xFF;
  25540. file[offset + 1] = tableName.charCodeAt(1) & 0xFF;
  25541. file[offset + 2] = tableName.charCodeAt(2) & 0xFF;
  25542. file[offset + 3] = tableName.charCodeAt(3) & 0xFF;
  25543. // checksum
  25544. var checksum = 0;
  25545. for (j = tableOffsets[i], jj = tableOffsets[i + 1]; j < jj; j += 4) {
  25546. var quad = (file[j] << 24) + (file[j + 1] << 16) +
  25547. (file[j + 2] << 8) + file[j + 3];
  25548. checksum = (checksum + quad) | 0;
  25549. }
  25550. writeInt32(file, offset + 4, checksum);
  25551. // offset
  25552. writeInt32(file, offset + 8, tableOffsets[i]);
  25553. // length
  25554. writeInt32(file, offset + 12, tables[tableName].length);
  25555. offset += OTF_TABLE_ENTRY_SIZE;
  25556. }
  25557. return file;
  25558. },
  25559. addTable: function OpenTypeFileBuilder_addTable(tag, data) {
  25560. if (tag in this.tables) {
  25561. throw new Error('Table ' + tag + ' already exists');
  25562. }
  25563. this.tables[tag] = data;
  25564. }
  25565. };
  25566. return OpenTypeFileBuilder;
  25567. })();
  25568. // Problematic Unicode characters in the fonts that needs to be moved to avoid
  25569. // issues when they are painted on the canvas, e.g. complex-script shaping or
  25570. // control/whitespace characters. The ranges are listed in pairs: the first item
  25571. // is a code of the first problematic code, the second one is the next
  25572. // non-problematic code. The ranges must be in sorted order.
  25573. var ProblematicCharRanges = new Int32Array([
  25574. // Control characters.
  25575. 0x0000, 0x0020,
  25576. 0x007F, 0x00A1,
  25577. 0x00AD, 0x00AE,
  25578. // Chars that is used in complex-script shaping.
  25579. 0x0600, 0x0780,
  25580. 0x08A0, 0x10A0,
  25581. 0x1780, 0x1800,
  25582. // General punctuation chars.
  25583. 0x2000, 0x2010,
  25584. 0x2011, 0x2012,
  25585. 0x2028, 0x2030,
  25586. 0x205F, 0x2070,
  25587. 0x25CC, 0x25CD,
  25588. // Chars that is used in complex-script shaping.
  25589. 0xAA60, 0xAA80,
  25590. // Specials Unicode block.
  25591. 0xFFF0, 0x10000
  25592. ]);
  25593. /**
  25594. * 'Font' is the class the outside world should use, it encapsulate all the font
  25595. * decoding logics whatever type it is (assuming the font type is supported).
  25596. *
  25597. * For example to read a Type1 font and to attach it to the document:
  25598. * var type1Font = new Font("MyFontName", binaryFile, propertiesObject);
  25599. * type1Font.bind();
  25600. */
  25601. var Font = (function FontClosure() {
  25602. function Font(name, file, properties) {
  25603. var charCode, glyphName, fontChar;
  25604. this.name = name;
  25605. this.loadedName = properties.loadedName;
  25606. this.isType3Font = properties.isType3Font;
  25607. this.sizes = [];
  25608. this.glyphCache = {};
  25609. var names = name.split('+');
  25610. names = names.length > 1 ? names[1] : names[0];
  25611. names = names.split(/[-,_]/g)[0];
  25612. this.isSerifFont = !!(properties.flags & FontFlags.Serif);
  25613. this.isSymbolicFont = !!(properties.flags & FontFlags.Symbolic);
  25614. this.isMonospace = !!(properties.flags & FontFlags.FixedPitch);
  25615. var type = properties.type;
  25616. var subtype = properties.subtype;
  25617. this.type = type;
  25618. this.fallbackName = (this.isMonospace ? 'monospace' :
  25619. (this.isSerifFont ? 'serif' : 'sans-serif'));
  25620. this.differences = properties.differences;
  25621. this.widths = properties.widths;
  25622. this.defaultWidth = properties.defaultWidth;
  25623. this.composite = properties.composite;
  25624. this.wideChars = properties.wideChars;
  25625. this.cMap = properties.cMap;
  25626. this.ascent = properties.ascent / PDF_GLYPH_SPACE_UNITS;
  25627. this.descent = properties.descent / PDF_GLYPH_SPACE_UNITS;
  25628. this.fontMatrix = properties.fontMatrix;
  25629. this.bbox = properties.bbox;
  25630. this.toUnicode = properties.toUnicode = this.buildToUnicode(properties);
  25631. this.toFontChar = [];
  25632. if (properties.type === 'Type3') {
  25633. for (charCode = 0; charCode < 256; charCode++) {
  25634. this.toFontChar[charCode] = (this.differences[charCode] ||
  25635. properties.defaultEncoding[charCode]);
  25636. }
  25637. this.fontType = FontType.TYPE3;
  25638. return;
  25639. }
  25640. this.cidEncoding = properties.cidEncoding;
  25641. this.vertical = properties.vertical;
  25642. if (this.vertical) {
  25643. this.vmetrics = properties.vmetrics;
  25644. this.defaultVMetrics = properties.defaultVMetrics;
  25645. }
  25646. if (!file || file.isEmpty) {
  25647. if (file) {
  25648. // Some bad PDF generators will include empty font files,
  25649. // attempting to recover by assuming that no file exists.
  25650. warn('Font file is empty in "' + name + '" (' + this.loadedName + ')');
  25651. }
  25652. this.missingFile = true;
  25653. // The file data is not specified. Trying to fix the font name
  25654. // to be used with the canvas.font.
  25655. var fontName = name.replace(/[,_]/g, '-');
  25656. var isStandardFont = !!stdFontMap[fontName] ||
  25657. !!(nonStdFontMap[fontName] && stdFontMap[nonStdFontMap[fontName]]);
  25658. fontName = stdFontMap[fontName] || nonStdFontMap[fontName] || fontName;
  25659. this.bold = (fontName.search(/bold/gi) !== -1);
  25660. this.italic = ((fontName.search(/oblique/gi) !== -1) ||
  25661. (fontName.search(/italic/gi) !== -1));
  25662. // Use 'name' instead of 'fontName' here because the original
  25663. // name ArialBlack for example will be replaced by Helvetica.
  25664. this.black = (name.search(/Black/g) !== -1);
  25665. // if at least one width is present, remeasure all chars when exists
  25666. this.remeasure = Object.keys(this.widths).length > 0;
  25667. if (isStandardFont && type === 'CIDFontType2' &&
  25668. properties.cidEncoding.indexOf('Identity-') === 0) {
  25669. // Standard fonts might be embedded as CID font without glyph mapping.
  25670. // Building one based on GlyphMapForStandardFonts.
  25671. var map = [];
  25672. for (charCode in GlyphMapForStandardFonts) {
  25673. map[+charCode] = GlyphMapForStandardFonts[charCode];
  25674. }
  25675. if (/ArialBlack/i.test(name)) {
  25676. for (charCode in SupplementalGlyphMapForArialBlack) {
  25677. map[+charCode] = SupplementalGlyphMapForArialBlack[charCode];
  25678. }
  25679. }
  25680. var isIdentityUnicode = this.toUnicode instanceof IdentityToUnicodeMap;
  25681. if (!isIdentityUnicode) {
  25682. this.toUnicode.forEach(function(charCode, unicodeCharCode) {
  25683. map[+charCode] = unicodeCharCode;
  25684. });
  25685. }
  25686. this.toFontChar = map;
  25687. this.toUnicode = new ToUnicodeMap(map);
  25688. } else if (/Symbol/i.test(fontName)) {
  25689. var symbols = Encodings.SymbolSetEncoding;
  25690. for (charCode in symbols) {
  25691. fontChar = GlyphsUnicode[symbols[charCode]];
  25692. if (!fontChar) {
  25693. continue;
  25694. }
  25695. this.toFontChar[charCode] = fontChar;
  25696. }
  25697. for (charCode in properties.differences) {
  25698. fontChar = GlyphsUnicode[properties.differences[charCode]];
  25699. if (!fontChar) {
  25700. continue;
  25701. }
  25702. this.toFontChar[charCode] = fontChar;
  25703. }
  25704. } else if (/Dingbats/i.test(fontName)) {
  25705. if (/Wingdings/i.test(name)) {
  25706. warn('Wingdings font without embedded font file, ' +
  25707. 'falling back to the ZapfDingbats encoding.');
  25708. }
  25709. var dingbats = Encodings.ZapfDingbatsEncoding;
  25710. for (charCode in dingbats) {
  25711. fontChar = DingbatsGlyphsUnicode[dingbats[charCode]];
  25712. if (!fontChar) {
  25713. continue;
  25714. }
  25715. this.toFontChar[charCode] = fontChar;
  25716. }
  25717. for (charCode in properties.differences) {
  25718. fontChar = DingbatsGlyphsUnicode[properties.differences[charCode]];
  25719. if (!fontChar) {
  25720. continue;
  25721. }
  25722. this.toFontChar[charCode] = fontChar;
  25723. }
  25724. } else if (isStandardFont) {
  25725. this.toFontChar = [];
  25726. for (charCode in properties.defaultEncoding) {
  25727. glyphName = (properties.differences[charCode] ||
  25728. properties.defaultEncoding[charCode]);
  25729. this.toFontChar[charCode] = GlyphsUnicode[glyphName];
  25730. }
  25731. } else {
  25732. var unicodeCharCode, notCidFont = (type.indexOf('CIDFontType') === -1);
  25733. this.toUnicode.forEach(function(charCode, unicodeCharCode) {
  25734. if (notCidFont) {
  25735. glyphName = (properties.differences[charCode] ||
  25736. properties.defaultEncoding[charCode]);
  25737. unicodeCharCode = (GlyphsUnicode[glyphName] || unicodeCharCode);
  25738. }
  25739. this.toFontChar[charCode] = unicodeCharCode;
  25740. }.bind(this));
  25741. }
  25742. this.loadedName = fontName.split('-')[0];
  25743. this.loading = false;
  25744. this.fontType = getFontType(type, subtype);
  25745. return;
  25746. }
  25747. // Some fonts might use wrong font types for Type1C or CIDFontType0C
  25748. if (subtype === 'Type1C' && (type !== 'Type1' && type !== 'MMType1')) {
  25749. // Some TrueType fonts by mistake claim Type1C
  25750. if (isTrueTypeFile(file)) {
  25751. subtype = 'TrueType';
  25752. } else {
  25753. type = 'Type1';
  25754. }
  25755. }
  25756. if (subtype === 'CIDFontType0C' && type !== 'CIDFontType0') {
  25757. type = 'CIDFontType0';
  25758. }
  25759. if (subtype === 'OpenType') {
  25760. type = 'OpenType';
  25761. }
  25762. // Some CIDFontType0C fonts by mistake claim CIDFontType0.
  25763. if (type === 'CIDFontType0') {
  25764. subtype = isType1File(file) ? 'CIDFontType0' : 'CIDFontType0C';
  25765. }
  25766. var data;
  25767. switch (type) {
  25768. case 'MMType1':
  25769. info('MMType1 font (' + name + '), falling back to Type1.');
  25770. /* falls through */
  25771. case 'Type1':
  25772. case 'CIDFontType0':
  25773. this.mimetype = 'font/opentype';
  25774. var cff = (subtype === 'Type1C' || subtype === 'CIDFontType0C') ?
  25775. new CFFFont(file, properties) : new Type1Font(name, file, properties);
  25776. adjustWidths(properties);
  25777. // Wrap the CFF data inside an OTF font file
  25778. data = this.convert(name, cff, properties);
  25779. break;
  25780. case 'OpenType':
  25781. case 'TrueType':
  25782. case 'CIDFontType2':
  25783. this.mimetype = 'font/opentype';
  25784. // Repair the TrueType file. It is can be damaged in the point of
  25785. // view of the sanitizer
  25786. data = this.checkAndRepair(name, file, properties);
  25787. if (this.isOpenType) {
  25788. adjustWidths(properties);
  25789. type = 'OpenType';
  25790. }
  25791. break;
  25792. default:
  25793. error('Font ' + type + ' is not supported');
  25794. break;
  25795. }
  25796. this.data = data;
  25797. this.fontType = getFontType(type, subtype);
  25798. // Transfer some properties again that could change during font conversion
  25799. this.fontMatrix = properties.fontMatrix;
  25800. this.widths = properties.widths;
  25801. this.defaultWidth = properties.defaultWidth;
  25802. this.encoding = properties.baseEncoding;
  25803. this.seacMap = properties.seacMap;
  25804. this.loading = true;
  25805. }
  25806. Font.getFontID = (function () {
  25807. var ID = 1;
  25808. return function Font_getFontID() {
  25809. return String(ID++);
  25810. };
  25811. })();
  25812. function int16(b0, b1) {
  25813. return (b0 << 8) + b1;
  25814. }
  25815. function int32(b0, b1, b2, b3) {
  25816. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  25817. }
  25818. function string16(value) {
  25819. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  25820. }
  25821. function safeString16(value) {
  25822. // clamp value to the 16-bit int range
  25823. value = (value > 0x7FFF ? 0x7FFF : (value < -0x8000 ? -0x8000 : value));
  25824. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  25825. }
  25826. function isTrueTypeFile(file) {
  25827. var header = file.peekBytes(4);
  25828. return readUint32(header, 0) === 0x00010000;
  25829. }
  25830. function isType1File(file) {
  25831. var header = file.peekBytes(2);
  25832. // All Type1 font programs must begin with the comment '%!' (0x25 + 0x21).
  25833. if (header[0] === 0x25 && header[1] === 0x21) {
  25834. return true;
  25835. }
  25836. // ... obviously some fonts violate that part of the specification,
  25837. // please refer to the comment in |Type1Font| below.
  25838. if (header[0] === 0x80 && header[1] === 0x01) { // pfb file header.
  25839. return true;
  25840. }
  25841. return false;
  25842. }
  25843. /**
  25844. * Helper function for |adjustMapping|.
  25845. * @return {boolean}
  25846. */
  25847. function isProblematicUnicodeLocation(code) {
  25848. // Using binary search to find a range start.
  25849. var i = 0, j = ProblematicCharRanges.length - 1;
  25850. while (i < j) {
  25851. var c = (i + j + 1) >> 1;
  25852. if (code < ProblematicCharRanges[c]) {
  25853. j = c - 1;
  25854. } else {
  25855. i = c;
  25856. }
  25857. }
  25858. // Even index means code in problematic range.
  25859. return !(i & 1);
  25860. }
  25861. /**
  25862. * Rebuilds the char code to glyph ID map by trying to replace the char codes
  25863. * with their unicode value. It also moves char codes that are in known
  25864. * problematic locations.
  25865. * @return {Object} Two properties:
  25866. * 'toFontChar' - maps original char codes(the value that will be read
  25867. * from commands such as show text) to the char codes that will be used in the
  25868. * font that we build
  25869. * 'charCodeToGlyphId' - maps the new font char codes to glyph ids
  25870. */
  25871. function adjustMapping(charCodeToGlyphId, properties) {
  25872. var toUnicode = properties.toUnicode;
  25873. var isSymbolic = !!(properties.flags & FontFlags.Symbolic);
  25874. var isIdentityUnicode =
  25875. properties.toUnicode instanceof IdentityToUnicodeMap;
  25876. var newMap = Object.create(null);
  25877. var toFontChar = [];
  25878. var usedFontCharCodes = [];
  25879. var nextAvailableFontCharCode = PRIVATE_USE_OFFSET_START;
  25880. for (var originalCharCode in charCodeToGlyphId) {
  25881. originalCharCode |= 0;
  25882. var glyphId = charCodeToGlyphId[originalCharCode];
  25883. var fontCharCode = originalCharCode;
  25884. // First try to map the value to a unicode position if a non identity map
  25885. // was created.
  25886. if (!isIdentityUnicode && toUnicode.has(originalCharCode)) {
  25887. var unicode = toUnicode.get(fontCharCode);
  25888. // TODO: Try to map ligatures to the correct spot.
  25889. if (unicode.length === 1) {
  25890. fontCharCode = unicode.charCodeAt(0);
  25891. }
  25892. }
  25893. // Try to move control characters, special characters and already mapped
  25894. // characters to the private use area since they will not be drawn by
  25895. // canvas if left in their current position. Also, move characters if the
  25896. // font was symbolic and there is only an identity unicode map since the
  25897. // characters probably aren't in the correct position (fixes an issue
  25898. // with firefox and thuluthfont).
  25899. if ((usedFontCharCodes[fontCharCode] !== undefined ||
  25900. isProblematicUnicodeLocation(fontCharCode) ||
  25901. (isSymbolic && isIdentityUnicode)) &&
  25902. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END) { // Room left.
  25903. // Loop to try and find a free spot in the private use area.
  25904. do {
  25905. fontCharCode = nextAvailableFontCharCode++;
  25906. if (SKIP_PRIVATE_USE_RANGE_F000_TO_F01F && fontCharCode === 0xF000) {
  25907. fontCharCode = 0xF020;
  25908. nextAvailableFontCharCode = fontCharCode + 1;
  25909. }
  25910. } while (usedFontCharCodes[fontCharCode] !== undefined &&
  25911. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END);
  25912. }
  25913. newMap[fontCharCode] = glyphId;
  25914. toFontChar[originalCharCode] = fontCharCode;
  25915. usedFontCharCodes[fontCharCode] = true;
  25916. }
  25917. return {
  25918. toFontChar: toFontChar,
  25919. charCodeToGlyphId: newMap,
  25920. nextAvailableFontCharCode: nextAvailableFontCharCode
  25921. };
  25922. }
  25923. function getRanges(glyphs, numGlyphs) {
  25924. // Array.sort() sorts by characters, not numerically, so convert to an
  25925. // array of characters.
  25926. var codes = [];
  25927. for (var charCode in glyphs) {
  25928. // Remove an invalid glyph ID mappings to make OTS happy.
  25929. if (glyphs[charCode] >= numGlyphs) {
  25930. continue;
  25931. }
  25932. codes.push({ fontCharCode: charCode | 0, glyphId: glyphs[charCode] });
  25933. }
  25934. codes.sort(function fontGetRangesSort(a, b) {
  25935. return a.fontCharCode - b.fontCharCode;
  25936. });
  25937. // Split the sorted codes into ranges.
  25938. var ranges = [];
  25939. var length = codes.length;
  25940. for (var n = 0; n < length; ) {
  25941. var start = codes[n].fontCharCode;
  25942. var codeIndices = [codes[n].glyphId];
  25943. ++n;
  25944. var end = start;
  25945. while (n < length && end + 1 === codes[n].fontCharCode) {
  25946. codeIndices.push(codes[n].glyphId);
  25947. ++end;
  25948. ++n;
  25949. if (end === 0xFFFF) {
  25950. break;
  25951. }
  25952. }
  25953. ranges.push([start, end, codeIndices]);
  25954. }
  25955. return ranges;
  25956. }
  25957. function createCmapTable(glyphs, numGlyphs) {
  25958. var ranges = getRanges(glyphs, numGlyphs);
  25959. var numTables = ranges[ranges.length - 1][1] > 0xFFFF ? 2 : 1;
  25960. var cmap = '\x00\x00' + // version
  25961. string16(numTables) + // numTables
  25962. '\x00\x03' + // platformID
  25963. '\x00\x01' + // encodingID
  25964. string32(4 + numTables * 8); // start of the table record
  25965. var i, ii, j, jj;
  25966. for (i = ranges.length - 1; i >= 0; --i) {
  25967. if (ranges[i][0] <= 0xFFFF) { break; }
  25968. }
  25969. var bmpLength = i + 1;
  25970. if (ranges[i][0] < 0xFFFF && ranges[i][1] === 0xFFFF) {
  25971. ranges[i][1] = 0xFFFE;
  25972. }
  25973. var trailingRangesCount = ranges[i][1] < 0xFFFF ? 1 : 0;
  25974. var segCount = bmpLength + trailingRangesCount;
  25975. var searchParams = OpenTypeFileBuilder.getSearchParams(segCount, 2);
  25976. // Fill up the 4 parallel arrays describing the segments.
  25977. var startCount = '';
  25978. var endCount = '';
  25979. var idDeltas = '';
  25980. var idRangeOffsets = '';
  25981. var glyphsIds = '';
  25982. var bias = 0;
  25983. var range, start, end, codes;
  25984. for (i = 0, ii = bmpLength; i < ii; i++) {
  25985. range = ranges[i];
  25986. start = range[0];
  25987. end = range[1];
  25988. startCount += string16(start);
  25989. endCount += string16(end);
  25990. codes = range[2];
  25991. var contiguous = true;
  25992. for (j = 1, jj = codes.length; j < jj; ++j) {
  25993. if (codes[j] !== codes[j - 1] + 1) {
  25994. contiguous = false;
  25995. break;
  25996. }
  25997. }
  25998. if (!contiguous) {
  25999. var offset = (segCount - i) * 2 + bias * 2;
  26000. bias += (end - start + 1);
  26001. idDeltas += string16(0);
  26002. idRangeOffsets += string16(offset);
  26003. for (j = 0, jj = codes.length; j < jj; ++j) {
  26004. glyphsIds += string16(codes[j]);
  26005. }
  26006. } else {
  26007. var startCode = codes[0];
  26008. idDeltas += string16((startCode - start) & 0xFFFF);
  26009. idRangeOffsets += string16(0);
  26010. }
  26011. }
  26012. if (trailingRangesCount > 0) {
  26013. endCount += '\xFF\xFF';
  26014. startCount += '\xFF\xFF';
  26015. idDeltas += '\x00\x01';
  26016. idRangeOffsets += '\x00\x00';
  26017. }
  26018. var format314 = '\x00\x00' + // language
  26019. string16(2 * segCount) +
  26020. string16(searchParams.range) +
  26021. string16(searchParams.entry) +
  26022. string16(searchParams.rangeShift) +
  26023. endCount + '\x00\x00' + startCount +
  26024. idDeltas + idRangeOffsets + glyphsIds;
  26025. var format31012 = '';
  26026. var header31012 = '';
  26027. if (numTables > 1) {
  26028. cmap += '\x00\x03' + // platformID
  26029. '\x00\x0A' + // encodingID
  26030. string32(4 + numTables * 8 +
  26031. 4 + format314.length); // start of the table record
  26032. format31012 = '';
  26033. for (i = 0, ii = ranges.length; i < ii; i++) {
  26034. range = ranges[i];
  26035. start = range[0];
  26036. codes = range[2];
  26037. var code = codes[0];
  26038. for (j = 1, jj = codes.length; j < jj; ++j) {
  26039. if (codes[j] !== codes[j - 1] + 1) {
  26040. end = range[0] + j - 1;
  26041. format31012 += string32(start) + // startCharCode
  26042. string32(end) + // endCharCode
  26043. string32(code); // startGlyphID
  26044. start = end + 1;
  26045. code = codes[j];
  26046. }
  26047. }
  26048. format31012 += string32(start) + // startCharCode
  26049. string32(range[1]) + // endCharCode
  26050. string32(code); // startGlyphID
  26051. }
  26052. header31012 = '\x00\x0C' + // format
  26053. '\x00\x00' + // reserved
  26054. string32(format31012.length + 16) + // length
  26055. '\x00\x00\x00\x00' + // language
  26056. string32(format31012.length / 12); // nGroups
  26057. }
  26058. return cmap + '\x00\x04' + // format
  26059. string16(format314.length + 4) + // length
  26060. format314 + header31012 + format31012;
  26061. }
  26062. function validateOS2Table(os2) {
  26063. var stream = new Stream(os2.data);
  26064. var version = stream.getUint16();
  26065. // TODO verify all OS/2 tables fields, but currently we validate only those
  26066. // that give us issues
  26067. stream.getBytes(60); // skipping type, misc sizes, panose, unicode ranges
  26068. var selection = stream.getUint16();
  26069. if (version < 4 && (selection & 0x0300)) {
  26070. return false;
  26071. }
  26072. var firstChar = stream.getUint16();
  26073. var lastChar = stream.getUint16();
  26074. if (firstChar > lastChar) {
  26075. return false;
  26076. }
  26077. stream.getBytes(6); // skipping sTypoAscender/Descender/LineGap
  26078. var usWinAscent = stream.getUint16();
  26079. if (usWinAscent === 0) { // makes font unreadable by windows
  26080. return false;
  26081. }
  26082. // OS/2 appears to be valid, resetting some fields
  26083. os2.data[8] = os2.data[9] = 0; // IE rejects fonts if fsType != 0
  26084. return true;
  26085. }
  26086. function createOS2Table(properties, charstrings, override) {
  26087. override = override || {
  26088. unitsPerEm: 0,
  26089. yMax: 0,
  26090. yMin: 0,
  26091. ascent: 0,
  26092. descent: 0
  26093. };
  26094. var ulUnicodeRange1 = 0;
  26095. var ulUnicodeRange2 = 0;
  26096. var ulUnicodeRange3 = 0;
  26097. var ulUnicodeRange4 = 0;
  26098. var firstCharIndex = null;
  26099. var lastCharIndex = 0;
  26100. if (charstrings) {
  26101. for (var code in charstrings) {
  26102. code |= 0;
  26103. if (firstCharIndex > code || !firstCharIndex) {
  26104. firstCharIndex = code;
  26105. }
  26106. if (lastCharIndex < code) {
  26107. lastCharIndex = code;
  26108. }
  26109. var position = getUnicodeRangeFor(code);
  26110. if (position < 32) {
  26111. ulUnicodeRange1 |= 1 << position;
  26112. } else if (position < 64) {
  26113. ulUnicodeRange2 |= 1 << position - 32;
  26114. } else if (position < 96) {
  26115. ulUnicodeRange3 |= 1 << position - 64;
  26116. } else if (position < 123) {
  26117. ulUnicodeRange4 |= 1 << position - 96;
  26118. } else {
  26119. error('Unicode ranges Bits > 123 are reserved for internal usage');
  26120. }
  26121. }
  26122. } else {
  26123. // TODO
  26124. firstCharIndex = 0;
  26125. lastCharIndex = 255;
  26126. }
  26127. var bbox = properties.bbox || [0, 0, 0, 0];
  26128. var unitsPerEm = (override.unitsPerEm ||
  26129. 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0]);
  26130. // if the font units differ to the PDF glyph space units
  26131. // then scale up the values
  26132. var scale = (properties.ascentScaled ? 1.0 :
  26133. unitsPerEm / PDF_GLYPH_SPACE_UNITS);
  26134. var typoAscent = (override.ascent ||
  26135. Math.round(scale * (properties.ascent || bbox[3])));
  26136. var typoDescent = (override.descent ||
  26137. Math.round(scale * (properties.descent || bbox[1])));
  26138. if (typoDescent > 0 && properties.descent > 0 && bbox[1] < 0) {
  26139. typoDescent = -typoDescent; // fixing incorrect descent
  26140. }
  26141. var winAscent = override.yMax || typoAscent;
  26142. var winDescent = -override.yMin || -typoDescent;
  26143. return '\x00\x03' + // version
  26144. '\x02\x24' + // xAvgCharWidth
  26145. '\x01\xF4' + // usWeightClass
  26146. '\x00\x05' + // usWidthClass
  26147. '\x00\x00' + // fstype (0 to let the font loads via font-face on IE)
  26148. '\x02\x8A' + // ySubscriptXSize
  26149. '\x02\xBB' + // ySubscriptYSize
  26150. '\x00\x00' + // ySubscriptXOffset
  26151. '\x00\x8C' + // ySubscriptYOffset
  26152. '\x02\x8A' + // ySuperScriptXSize
  26153. '\x02\xBB' + // ySuperScriptYSize
  26154. '\x00\x00' + // ySuperScriptXOffset
  26155. '\x01\xDF' + // ySuperScriptYOffset
  26156. '\x00\x31' + // yStrikeOutSize
  26157. '\x01\x02' + // yStrikeOutPosition
  26158. '\x00\x00' + // sFamilyClass
  26159. '\x00\x00\x06' +
  26160. String.fromCharCode(properties.fixedPitch ? 0x09 : 0x00) +
  26161. '\x00\x00\x00\x00\x00\x00' + // Panose
  26162. string32(ulUnicodeRange1) + // ulUnicodeRange1 (Bits 0-31)
  26163. string32(ulUnicodeRange2) + // ulUnicodeRange2 (Bits 32-63)
  26164. string32(ulUnicodeRange3) + // ulUnicodeRange3 (Bits 64-95)
  26165. string32(ulUnicodeRange4) + // ulUnicodeRange4 (Bits 96-127)
  26166. '\x2A\x32\x31\x2A' + // achVendID
  26167. string16(properties.italicAngle ? 1 : 0) + // fsSelection
  26168. string16(firstCharIndex ||
  26169. properties.firstChar) + // usFirstCharIndex
  26170. string16(lastCharIndex || properties.lastChar) + // usLastCharIndex
  26171. string16(typoAscent) + // sTypoAscender
  26172. string16(typoDescent) + // sTypoDescender
  26173. '\x00\x64' + // sTypoLineGap (7%-10% of the unitsPerEM value)
  26174. string16(winAscent) + // usWinAscent
  26175. string16(winDescent) + // usWinDescent
  26176. '\x00\x00\x00\x00' + // ulCodePageRange1 (Bits 0-31)
  26177. '\x00\x00\x00\x00' + // ulCodePageRange2 (Bits 32-63)
  26178. string16(properties.xHeight) + // sxHeight
  26179. string16(properties.capHeight) + // sCapHeight
  26180. string16(0) + // usDefaultChar
  26181. string16(firstCharIndex || properties.firstChar) + // usBreakChar
  26182. '\x00\x03'; // usMaxContext
  26183. }
  26184. function createPostTable(properties) {
  26185. var angle = Math.floor(properties.italicAngle * (Math.pow(2, 16)));
  26186. return ('\x00\x03\x00\x00' + // Version number
  26187. string32(angle) + // italicAngle
  26188. '\x00\x00' + // underlinePosition
  26189. '\x00\x00' + // underlineThickness
  26190. string32(properties.fixedPitch) + // isFixedPitch
  26191. '\x00\x00\x00\x00' + // minMemType42
  26192. '\x00\x00\x00\x00' + // maxMemType42
  26193. '\x00\x00\x00\x00' + // minMemType1
  26194. '\x00\x00\x00\x00'); // maxMemType1
  26195. }
  26196. function createNameTable(name, proto) {
  26197. if (!proto) {
  26198. proto = [[], []]; // no strings and unicode strings
  26199. }
  26200. var strings = [
  26201. proto[0][0] || 'Original licence', // 0.Copyright
  26202. proto[0][1] || name, // 1.Font family
  26203. proto[0][2] || 'Unknown', // 2.Font subfamily (font weight)
  26204. proto[0][3] || 'uniqueID', // 3.Unique ID
  26205. proto[0][4] || name, // 4.Full font name
  26206. proto[0][5] || 'Version 0.11', // 5.Version
  26207. proto[0][6] || '', // 6.Postscript name
  26208. proto[0][7] || 'Unknown', // 7.Trademark
  26209. proto[0][8] || 'Unknown', // 8.Manufacturer
  26210. proto[0][9] || 'Unknown' // 9.Designer
  26211. ];
  26212. // Mac want 1-byte per character strings while Windows want
  26213. // 2-bytes per character, so duplicate the names table
  26214. var stringsUnicode = [];
  26215. var i, ii, j, jj, str;
  26216. for (i = 0, ii = strings.length; i < ii; i++) {
  26217. str = proto[1][i] || strings[i];
  26218. var strBufUnicode = [];
  26219. for (j = 0, jj = str.length; j < jj; j++) {
  26220. strBufUnicode.push(string16(str.charCodeAt(j)));
  26221. }
  26222. stringsUnicode.push(strBufUnicode.join(''));
  26223. }
  26224. var names = [strings, stringsUnicode];
  26225. var platforms = ['\x00\x01', '\x00\x03'];
  26226. var encodings = ['\x00\x00', '\x00\x01'];
  26227. var languages = ['\x00\x00', '\x04\x09'];
  26228. var namesRecordCount = strings.length * platforms.length;
  26229. var nameTable =
  26230. '\x00\x00' + // format
  26231. string16(namesRecordCount) + // Number of names Record
  26232. string16(namesRecordCount * 12 + 6); // Storage
  26233. // Build the name records field
  26234. var strOffset = 0;
  26235. for (i = 0, ii = platforms.length; i < ii; i++) {
  26236. var strs = names[i];
  26237. for (j = 0, jj = strs.length; j < jj; j++) {
  26238. str = strs[j];
  26239. var nameRecord =
  26240. platforms[i] + // platform ID
  26241. encodings[i] + // encoding ID
  26242. languages[i] + // language ID
  26243. string16(j) + // name ID
  26244. string16(str.length) +
  26245. string16(strOffset);
  26246. nameTable += nameRecord;
  26247. strOffset += str.length;
  26248. }
  26249. }
  26250. nameTable += strings.join('') + stringsUnicode.join('');
  26251. return nameTable;
  26252. }
  26253. Font.prototype = {
  26254. name: null,
  26255. font: null,
  26256. mimetype: null,
  26257. encoding: null,
  26258. get renderer() {
  26259. var renderer = FontRendererFactory.create(this);
  26260. return shadow(this, 'renderer', renderer);
  26261. },
  26262. exportData: function Font_exportData() {
  26263. var data = {};
  26264. for (var i in this) {
  26265. if (this.hasOwnProperty(i)) {
  26266. data[i] = this[i];
  26267. }
  26268. }
  26269. return data;
  26270. },
  26271. checkAndRepair: function Font_checkAndRepair(name, font, properties) {
  26272. function readTableEntry(file) {
  26273. var tag = bytesToString(file.getBytes(4));
  26274. var checksum = file.getInt32();
  26275. var offset = file.getInt32() >>> 0;
  26276. var length = file.getInt32() >>> 0;
  26277. // Read the table associated data
  26278. var previousPosition = file.pos;
  26279. file.pos = file.start ? file.start : 0;
  26280. file.skip(offset);
  26281. var data = file.getBytes(length);
  26282. file.pos = previousPosition;
  26283. if (tag === 'head') {
  26284. // clearing checksum adjustment
  26285. data[8] = data[9] = data[10] = data[11] = 0;
  26286. data[17] |= 0x20; //Set font optimized for cleartype flag
  26287. }
  26288. return {
  26289. tag: tag,
  26290. checksum: checksum,
  26291. length: length,
  26292. offset: offset,
  26293. data: data
  26294. };
  26295. }
  26296. function readOpenTypeHeader(ttf) {
  26297. return {
  26298. version: bytesToString(ttf.getBytes(4)),
  26299. numTables: ttf.getUint16(),
  26300. searchRange: ttf.getUint16(),
  26301. entrySelector: ttf.getUint16(),
  26302. rangeShift: ttf.getUint16()
  26303. };
  26304. }
  26305. /**
  26306. * Read the appropriate subtable from the cmap according to 9.6.6.4 from
  26307. * PDF spec
  26308. */
  26309. function readCmapTable(cmap, font, isSymbolicFont, hasEncoding) {
  26310. if (!cmap) {
  26311. warn('No cmap table available.');
  26312. return {
  26313. platformId: -1,
  26314. encodingId: -1,
  26315. mappings: [],
  26316. hasShortCmap: false
  26317. };
  26318. }
  26319. var segment;
  26320. var start = (font.start ? font.start : 0) + cmap.offset;
  26321. font.pos = start;
  26322. var version = font.getUint16();
  26323. var numTables = font.getUint16();
  26324. var potentialTable;
  26325. var canBreak = false;
  26326. // There's an order of preference in terms of which cmap subtable to
  26327. // use:
  26328. // - non-symbolic fonts the preference is a 3,1 table then a 1,0 table
  26329. // - symbolic fonts the preference is a 3,0 table then a 1,0 table
  26330. // The following takes advantage of the fact that the tables are sorted
  26331. // to work.
  26332. for (var i = 0; i < numTables; i++) {
  26333. var platformId = font.getUint16();
  26334. var encodingId = font.getUint16();
  26335. var offset = font.getInt32() >>> 0;
  26336. var useTable = false;
  26337. if (platformId === 0 && encodingId === 0) {
  26338. useTable = true;
  26339. // Continue the loop since there still may be a higher priority
  26340. // table.
  26341. } else if (platformId === 1 && encodingId === 0) {
  26342. useTable = true;
  26343. // Continue the loop since there still may be a higher priority
  26344. // table.
  26345. } else if (platformId === 3 && encodingId === 1 &&
  26346. ((!isSymbolicFont && hasEncoding) || !potentialTable)) {
  26347. useTable = true;
  26348. if (!isSymbolicFont) {
  26349. canBreak = true;
  26350. }
  26351. } else if (isSymbolicFont && platformId === 3 && encodingId === 0) {
  26352. useTable = true;
  26353. canBreak = true;
  26354. }
  26355. if (useTable) {
  26356. potentialTable = {
  26357. platformId: platformId,
  26358. encodingId: encodingId,
  26359. offset: offset
  26360. };
  26361. }
  26362. if (canBreak) {
  26363. break;
  26364. }
  26365. }
  26366. if (potentialTable) {
  26367. font.pos = start + potentialTable.offset;
  26368. }
  26369. if (!potentialTable || font.peekByte() === -1) {
  26370. warn('Could not find a preferred cmap table.');
  26371. return {
  26372. platformId: -1,
  26373. encodingId: -1,
  26374. mappings: [],
  26375. hasShortCmap: false
  26376. };
  26377. }
  26378. var format = font.getUint16();
  26379. var length = font.getUint16();
  26380. var language = font.getUint16();
  26381. var hasShortCmap = false;
  26382. var mappings = [];
  26383. var j, glyphId;
  26384. // TODO(mack): refactor this cmap subtable reading logic out
  26385. if (format === 0) {
  26386. for (j = 0; j < 256; j++) {
  26387. var index = font.getByte();
  26388. if (!index) {
  26389. continue;
  26390. }
  26391. mappings.push({
  26392. charCode: j,
  26393. glyphId: index
  26394. });
  26395. }
  26396. hasShortCmap = true;
  26397. } else if (format === 4) {
  26398. // re-creating the table in format 4 since the encoding
  26399. // might be changed
  26400. var segCount = (font.getUint16() >> 1);
  26401. font.getBytes(6); // skipping range fields
  26402. var segIndex, segments = [];
  26403. for (segIndex = 0; segIndex < segCount; segIndex++) {
  26404. segments.push({ end: font.getUint16() });
  26405. }
  26406. font.getUint16();
  26407. for (segIndex = 0; segIndex < segCount; segIndex++) {
  26408. segments[segIndex].start = font.getUint16();
  26409. }
  26410. for (segIndex = 0; segIndex < segCount; segIndex++) {
  26411. segments[segIndex].delta = font.getUint16();
  26412. }
  26413. var offsetsCount = 0;
  26414. for (segIndex = 0; segIndex < segCount; segIndex++) {
  26415. segment = segments[segIndex];
  26416. var rangeOffset = font.getUint16();
  26417. if (!rangeOffset) {
  26418. segment.offsetIndex = -1;
  26419. continue;
  26420. }
  26421. var offsetIndex = (rangeOffset >> 1) - (segCount - segIndex);
  26422. segment.offsetIndex = offsetIndex;
  26423. offsetsCount = Math.max(offsetsCount, offsetIndex +
  26424. segment.end - segment.start + 1);
  26425. }
  26426. var offsets = [];
  26427. for (j = 0; j < offsetsCount; j++) {
  26428. offsets.push(font.getUint16());
  26429. }
  26430. for (segIndex = 0; segIndex < segCount; segIndex++) {
  26431. segment = segments[segIndex];
  26432. start = segment.start;
  26433. var end = segment.end;
  26434. var delta = segment.delta;
  26435. offsetIndex = segment.offsetIndex;
  26436. for (j = start; j <= end; j++) {
  26437. if (j === 0xFFFF) {
  26438. continue;
  26439. }
  26440. glyphId = (offsetIndex < 0 ?
  26441. j : offsets[offsetIndex + j - start]);
  26442. glyphId = (glyphId + delta) & 0xFFFF;
  26443. if (glyphId === 0) {
  26444. continue;
  26445. }
  26446. mappings.push({
  26447. charCode: j,
  26448. glyphId: glyphId
  26449. });
  26450. }
  26451. }
  26452. } else if (format === 6) {
  26453. // Format 6 is a 2-bytes dense mapping, which means the font data
  26454. // lives glue together even if they are pretty far in the unicode
  26455. // table. (This looks weird, so I can have missed something), this
  26456. // works on Linux but seems to fails on Mac so let's rewrite the
  26457. // cmap table to a 3-1-4 style
  26458. var firstCode = font.getUint16();
  26459. var entryCount = font.getUint16();
  26460. for (j = 0; j < entryCount; j++) {
  26461. glyphId = font.getUint16();
  26462. var charCode = firstCode + j;
  26463. mappings.push({
  26464. charCode: charCode,
  26465. glyphId: glyphId
  26466. });
  26467. }
  26468. } else {
  26469. warn('cmap table has unsupported format: ' + format);
  26470. return {
  26471. platformId: -1,
  26472. encodingId: -1,
  26473. mappings: [],
  26474. hasShortCmap: false
  26475. };
  26476. }
  26477. // removing duplicate entries
  26478. mappings.sort(function (a, b) {
  26479. return a.charCode - b.charCode;
  26480. });
  26481. for (i = 1; i < mappings.length; i++) {
  26482. if (mappings[i - 1].charCode === mappings[i].charCode) {
  26483. mappings.splice(i, 1);
  26484. i--;
  26485. }
  26486. }
  26487. return {
  26488. platformId: potentialTable.platformId,
  26489. encodingId: potentialTable.encodingId,
  26490. mappings: mappings,
  26491. hasShortCmap: hasShortCmap
  26492. };
  26493. }
  26494. function sanitizeMetrics(font, header, metrics, numGlyphs) {
  26495. if (!header) {
  26496. if (metrics) {
  26497. metrics.data = null;
  26498. }
  26499. return;
  26500. }
  26501. font.pos = (font.start ? font.start : 0) + header.offset;
  26502. font.pos += header.length - 2;
  26503. var numOfMetrics = font.getUint16();
  26504. if (numOfMetrics > numGlyphs) {
  26505. info('The numOfMetrics (' + numOfMetrics + ') should not be ' +
  26506. 'greater than the numGlyphs (' + numGlyphs + ')');
  26507. // Reduce numOfMetrics if it is greater than numGlyphs
  26508. numOfMetrics = numGlyphs;
  26509. header.data[34] = (numOfMetrics & 0xff00) >> 8;
  26510. header.data[35] = numOfMetrics & 0x00ff;
  26511. }
  26512. var numOfSidebearings = numGlyphs - numOfMetrics;
  26513. var numMissing = numOfSidebearings -
  26514. ((metrics.length - numOfMetrics * 4) >> 1);
  26515. if (numMissing > 0) {
  26516. // For each missing glyph, we set both the width and lsb to 0 (zero).
  26517. // Since we need to add two properties for each glyph, this explains
  26518. // the use of |numMissing * 2| when initializing the typed array.
  26519. var entries = new Uint8Array(metrics.length + numMissing * 2);
  26520. entries.set(metrics.data);
  26521. metrics.data = entries;
  26522. }
  26523. }
  26524. function sanitizeGlyph(source, sourceStart, sourceEnd, dest, destStart,
  26525. hintsValid) {
  26526. if (sourceEnd - sourceStart <= 12) {
  26527. // glyph with data less than 12 is invalid one
  26528. return 0;
  26529. }
  26530. var glyf = source.subarray(sourceStart, sourceEnd);
  26531. var contoursCount = (glyf[0] << 8) | glyf[1];
  26532. if (contoursCount & 0x8000) {
  26533. // complex glyph, writing as is
  26534. dest.set(glyf, destStart);
  26535. return glyf.length;
  26536. }
  26537. var i, j = 10, flagsCount = 0;
  26538. for (i = 0; i < contoursCount; i++) {
  26539. var endPoint = (glyf[j] << 8) | glyf[j + 1];
  26540. flagsCount = endPoint + 1;
  26541. j += 2;
  26542. }
  26543. // skipping instructions
  26544. var instructionsStart = j;
  26545. var instructionsLength = (glyf[j] << 8) | glyf[j + 1];
  26546. j += 2 + instructionsLength;
  26547. var instructionsEnd = j;
  26548. // validating flags
  26549. var coordinatesLength = 0;
  26550. for (i = 0; i < flagsCount; i++) {
  26551. var flag = glyf[j++];
  26552. if (flag & 0xC0) {
  26553. // reserved flags must be zero, cleaning up
  26554. glyf[j - 1] = flag & 0x3F;
  26555. }
  26556. var xyLength = ((flag & 2) ? 1 : (flag & 16) ? 0 : 2) +
  26557. ((flag & 4) ? 1 : (flag & 32) ? 0 : 2);
  26558. coordinatesLength += xyLength;
  26559. if (flag & 8) {
  26560. var repeat = glyf[j++];
  26561. i += repeat;
  26562. coordinatesLength += repeat * xyLength;
  26563. }
  26564. }
  26565. // glyph without coordinates will be rejected
  26566. if (coordinatesLength === 0) {
  26567. return 0;
  26568. }
  26569. var glyphDataLength = j + coordinatesLength;
  26570. if (glyphDataLength > glyf.length) {
  26571. // not enough data for coordinates
  26572. return 0;
  26573. }
  26574. if (!hintsValid && instructionsLength > 0) {
  26575. dest.set(glyf.subarray(0, instructionsStart), destStart);
  26576. dest.set([0, 0], destStart + instructionsStart);
  26577. dest.set(glyf.subarray(instructionsEnd, glyphDataLength),
  26578. destStart + instructionsStart + 2);
  26579. glyphDataLength -= instructionsLength;
  26580. if (glyf.length - glyphDataLength > 3) {
  26581. glyphDataLength = (glyphDataLength + 3) & ~3;
  26582. }
  26583. return glyphDataLength;
  26584. }
  26585. if (glyf.length - glyphDataLength > 3) {
  26586. // truncating and aligning to 4 bytes the long glyph data
  26587. glyphDataLength = (glyphDataLength + 3) & ~3;
  26588. dest.set(glyf.subarray(0, glyphDataLength), destStart);
  26589. return glyphDataLength;
  26590. }
  26591. // glyph data is fine
  26592. dest.set(glyf, destStart);
  26593. return glyf.length;
  26594. }
  26595. function sanitizeHead(head, numGlyphs, locaLength) {
  26596. var data = head.data;
  26597. // Validate version:
  26598. // Should always be 0x00010000
  26599. var version = int32(data[0], data[1], data[2], data[3]);
  26600. if (version >> 16 !== 1) {
  26601. info('Attempting to fix invalid version in head table: ' + version);
  26602. data[0] = 0;
  26603. data[1] = 1;
  26604. data[2] = 0;
  26605. data[3] = 0;
  26606. }
  26607. var indexToLocFormat = int16(data[50], data[51]);
  26608. if (indexToLocFormat < 0 || indexToLocFormat > 1) {
  26609. info('Attempting to fix invalid indexToLocFormat in head table: ' +
  26610. indexToLocFormat);
  26611. // The value of indexToLocFormat should be 0 if the loca table
  26612. // consists of short offsets, and should be 1 if the loca table
  26613. // consists of long offsets.
  26614. //
  26615. // The number of entries in the loca table should be numGlyphs + 1.
  26616. //
  26617. // Using this information, we can work backwards to deduce if the
  26618. // size of each offset in the loca table, and thus figure out the
  26619. // appropriate value for indexToLocFormat.
  26620. var numGlyphsPlusOne = numGlyphs + 1;
  26621. if (locaLength === numGlyphsPlusOne << 1) {
  26622. // 0x0000 indicates the loca table consists of short offsets
  26623. data[50] = 0;
  26624. data[51] = 0;
  26625. } else if (locaLength === numGlyphsPlusOne << 2) {
  26626. // 0x0001 indicates the loca table consists of long offsets
  26627. data[50] = 0;
  26628. data[51] = 1;
  26629. } else {
  26630. warn('Could not fix indexToLocFormat: ' + indexToLocFormat);
  26631. }
  26632. }
  26633. }
  26634. function sanitizeGlyphLocations(loca, glyf, numGlyphs,
  26635. isGlyphLocationsLong, hintsValid,
  26636. dupFirstEntry) {
  26637. var itemSize, itemDecode, itemEncode;
  26638. if (isGlyphLocationsLong) {
  26639. itemSize = 4;
  26640. itemDecode = function fontItemDecodeLong(data, offset) {
  26641. return (data[offset] << 24) | (data[offset + 1] << 16) |
  26642. (data[offset + 2] << 8) | data[offset + 3];
  26643. };
  26644. itemEncode = function fontItemEncodeLong(data, offset, value) {
  26645. data[offset] = (value >>> 24) & 0xFF;
  26646. data[offset + 1] = (value >> 16) & 0xFF;
  26647. data[offset + 2] = (value >> 8) & 0xFF;
  26648. data[offset + 3] = value & 0xFF;
  26649. };
  26650. } else {
  26651. itemSize = 2;
  26652. itemDecode = function fontItemDecode(data, offset) {
  26653. return (data[offset] << 9) | (data[offset + 1] << 1);
  26654. };
  26655. itemEncode = function fontItemEncode(data, offset, value) {
  26656. data[offset] = (value >> 9) & 0xFF;
  26657. data[offset + 1] = (value >> 1) & 0xFF;
  26658. };
  26659. }
  26660. var locaData = loca.data;
  26661. var locaDataSize = itemSize * (1 + numGlyphs);
  26662. // is loca.data too short or long?
  26663. if (locaData.length !== locaDataSize) {
  26664. locaData = new Uint8Array(locaDataSize);
  26665. locaData.set(loca.data.subarray(0, locaDataSize));
  26666. loca.data = locaData;
  26667. }
  26668. // removing the invalid glyphs
  26669. var oldGlyfData = glyf.data;
  26670. var oldGlyfDataLength = oldGlyfData.length;
  26671. var newGlyfData = new Uint8Array(oldGlyfDataLength);
  26672. var startOffset = itemDecode(locaData, 0);
  26673. var writeOffset = 0;
  26674. var missingGlyphData = {};
  26675. itemEncode(locaData, 0, writeOffset);
  26676. var i, j;
  26677. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  26678. var endOffset = itemDecode(locaData, j);
  26679. if (endOffset > oldGlyfDataLength &&
  26680. ((oldGlyfDataLength + 3) & ~3) === endOffset) {
  26681. // Aspose breaks fonts by aligning the glyphs to the qword, but not
  26682. // the glyf table size, which makes last glyph out of range.
  26683. endOffset = oldGlyfDataLength;
  26684. }
  26685. if (endOffset > oldGlyfDataLength) {
  26686. // glyph end offset points outside glyf data, rejecting the glyph
  26687. itemEncode(locaData, j, writeOffset);
  26688. startOffset = endOffset;
  26689. continue;
  26690. }
  26691. if (startOffset === endOffset) {
  26692. missingGlyphData[i] = true;
  26693. }
  26694. var newLength = sanitizeGlyph(oldGlyfData, startOffset, endOffset,
  26695. newGlyfData, writeOffset, hintsValid);
  26696. writeOffset += newLength;
  26697. itemEncode(locaData, j, writeOffset);
  26698. startOffset = endOffset;
  26699. }
  26700. if (writeOffset === 0) {
  26701. // glyf table cannot be empty -- redoing the glyf and loca tables
  26702. // to have single glyph with one point
  26703. var simpleGlyph = new Uint8Array(
  26704. [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 49, 0]);
  26705. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  26706. itemEncode(locaData, j, simpleGlyph.length);
  26707. }
  26708. glyf.data = simpleGlyph;
  26709. return missingGlyphData;
  26710. }
  26711. if (dupFirstEntry) {
  26712. var firstEntryLength = itemDecode(locaData, itemSize);
  26713. if (newGlyfData.length > firstEntryLength + writeOffset) {
  26714. glyf.data = newGlyfData.subarray(0, firstEntryLength + writeOffset);
  26715. } else {
  26716. glyf.data = new Uint8Array(firstEntryLength + writeOffset);
  26717. glyf.data.set(newGlyfData.subarray(0, writeOffset));
  26718. }
  26719. glyf.data.set(newGlyfData.subarray(0, firstEntryLength), writeOffset);
  26720. itemEncode(loca.data, locaData.length - itemSize,
  26721. writeOffset + firstEntryLength);
  26722. } else {
  26723. glyf.data = newGlyfData.subarray(0, writeOffset);
  26724. }
  26725. return missingGlyphData;
  26726. }
  26727. function readPostScriptTable(post, properties, maxpNumGlyphs) {
  26728. var start = (font.start ? font.start : 0) + post.offset;
  26729. font.pos = start;
  26730. var length = post.length, end = start + length;
  26731. var version = font.getInt32();
  26732. // skip rest to the tables
  26733. font.getBytes(28);
  26734. var glyphNames;
  26735. var valid = true;
  26736. var i;
  26737. switch (version) {
  26738. case 0x00010000:
  26739. glyphNames = MacStandardGlyphOrdering;
  26740. break;
  26741. case 0x00020000:
  26742. var numGlyphs = font.getUint16();
  26743. if (numGlyphs !== maxpNumGlyphs) {
  26744. valid = false;
  26745. break;
  26746. }
  26747. var glyphNameIndexes = [];
  26748. for (i = 0; i < numGlyphs; ++i) {
  26749. var index = font.getUint16();
  26750. if (index >= 32768) {
  26751. valid = false;
  26752. break;
  26753. }
  26754. glyphNameIndexes.push(index);
  26755. }
  26756. if (!valid) {
  26757. break;
  26758. }
  26759. var customNames = [];
  26760. var strBuf = [];
  26761. while (font.pos < end) {
  26762. var stringLength = font.getByte();
  26763. strBuf.length = stringLength;
  26764. for (i = 0; i < stringLength; ++i) {
  26765. strBuf[i] = String.fromCharCode(font.getByte());
  26766. }
  26767. customNames.push(strBuf.join(''));
  26768. }
  26769. glyphNames = [];
  26770. for (i = 0; i < numGlyphs; ++i) {
  26771. var j = glyphNameIndexes[i];
  26772. if (j < 258) {
  26773. glyphNames.push(MacStandardGlyphOrdering[j]);
  26774. continue;
  26775. }
  26776. glyphNames.push(customNames[j - 258]);
  26777. }
  26778. break;
  26779. case 0x00030000:
  26780. break;
  26781. default:
  26782. warn('Unknown/unsupported post table version ' + version);
  26783. valid = false;
  26784. if (properties.defaultEncoding) {
  26785. glyphNames = properties.defaultEncoding;
  26786. }
  26787. break;
  26788. }
  26789. properties.glyphNames = glyphNames;
  26790. return valid;
  26791. }
  26792. function readNameTable(nameTable) {
  26793. var start = (font.start ? font.start : 0) + nameTable.offset;
  26794. font.pos = start;
  26795. var names = [[], []];
  26796. var length = nameTable.length, end = start + length;
  26797. var format = font.getUint16();
  26798. var FORMAT_0_HEADER_LENGTH = 6;
  26799. if (format !== 0 || length < FORMAT_0_HEADER_LENGTH) {
  26800. // unsupported name table format or table "too" small
  26801. return names;
  26802. }
  26803. var numRecords = font.getUint16();
  26804. var stringsStart = font.getUint16();
  26805. var records = [];
  26806. var NAME_RECORD_LENGTH = 12;
  26807. var i, ii;
  26808. for (i = 0; i < numRecords &&
  26809. font.pos + NAME_RECORD_LENGTH <= end; i++) {
  26810. var r = {
  26811. platform: font.getUint16(),
  26812. encoding: font.getUint16(),
  26813. language: font.getUint16(),
  26814. name: font.getUint16(),
  26815. length: font.getUint16(),
  26816. offset: font.getUint16()
  26817. };
  26818. // using only Macintosh and Windows platform/encoding names
  26819. if ((r.platform === 1 && r.encoding === 0 && r.language === 0) ||
  26820. (r.platform === 3 && r.encoding === 1 && r.language === 0x409)) {
  26821. records.push(r);
  26822. }
  26823. }
  26824. for (i = 0, ii = records.length; i < ii; i++) {
  26825. var record = records[i];
  26826. var pos = start + stringsStart + record.offset;
  26827. if (pos + record.length > end) {
  26828. continue; // outside of name table, ignoring
  26829. }
  26830. font.pos = pos;
  26831. var nameIndex = record.name;
  26832. if (record.encoding) {
  26833. // unicode
  26834. var str = '';
  26835. for (var j = 0, jj = record.length; j < jj; j += 2) {
  26836. str += String.fromCharCode(font.getUint16());
  26837. }
  26838. names[1][nameIndex] = str;
  26839. } else {
  26840. names[0][nameIndex] = bytesToString(font.getBytes(record.length));
  26841. }
  26842. }
  26843. return names;
  26844. }
  26845. var TTOpsStackDeltas = [
  26846. 0, 0, 0, 0, 0, 0, 0, 0, -2, -2, -2, -2, 0, 0, -2, -5,
  26847. -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, -1, -1,
  26848. 1, -1, -999, 0, 1, 0, -1, -2, 0, -1, -2, -1, -1, 0, -1, -1,
  26849. 0, 0, -999, -999, -1, -1, -1, -1, -2, -999, -2, -2, -999, 0, -2, -2,
  26850. 0, 0, -2, 0, -2, 0, 0, 0, -2, -1, -1, 1, 1, 0, 0, -1,
  26851. -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, 0, -999, -1, -1,
  26852. -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  26853. -2, -999, -999, -999, -999, -999, -1, -1, -2, -2, 0, 0, 0, 0, -1, -1,
  26854. -999, -2, -2, 0, 0, -1, -2, -2, 0, 0, 0, -1, -1, -1, -2];
  26855. // 0xC0-DF == -1 and 0xE0-FF == -2
  26856. function sanitizeTTProgram(table, ttContext) {
  26857. var data = table.data;
  26858. var i = 0, j, n, b, funcId, pc, lastEndf = 0, lastDeff = 0;
  26859. var stack = [];
  26860. var callstack = [];
  26861. var functionsCalled = [];
  26862. var tooComplexToFollowFunctions =
  26863. ttContext.tooComplexToFollowFunctions;
  26864. var inFDEF = false, ifLevel = 0, inELSE = 0;
  26865. for (var ii = data.length; i < ii;) {
  26866. var op = data[i++];
  26867. // The TrueType instruction set docs can be found at
  26868. // https://developer.apple.com/fonts/TTRefMan/RM05/Chap5.html
  26869. if (op === 0x40) { // NPUSHB - pushes n bytes
  26870. n = data[i++];
  26871. if (inFDEF || inELSE) {
  26872. i += n;
  26873. } else {
  26874. for (j = 0; j < n; j++) {
  26875. stack.push(data[i++]);
  26876. }
  26877. }
  26878. } else if (op === 0x41) { // NPUSHW - pushes n words
  26879. n = data[i++];
  26880. if (inFDEF || inELSE) {
  26881. i += n * 2;
  26882. } else {
  26883. for (j = 0; j < n; j++) {
  26884. b = data[i++];
  26885. stack.push((b << 8) | data[i++]);
  26886. }
  26887. }
  26888. } else if ((op & 0xF8) === 0xB0) { // PUSHB - pushes bytes
  26889. n = op - 0xB0 + 1;
  26890. if (inFDEF || inELSE) {
  26891. i += n;
  26892. } else {
  26893. for (j = 0; j < n; j++) {
  26894. stack.push(data[i++]);
  26895. }
  26896. }
  26897. } else if ((op & 0xF8) === 0xB8) { // PUSHW - pushes words
  26898. n = op - 0xB8 + 1;
  26899. if (inFDEF || inELSE) {
  26900. i += n * 2;
  26901. } else {
  26902. for (j = 0; j < n; j++) {
  26903. b = data[i++];
  26904. stack.push((b << 8) | data[i++]);
  26905. }
  26906. }
  26907. } else if (op === 0x2B && !tooComplexToFollowFunctions) { // CALL
  26908. if (!inFDEF && !inELSE) {
  26909. // collecting inforamtion about which functions are used
  26910. funcId = stack[stack.length - 1];
  26911. ttContext.functionsUsed[funcId] = true;
  26912. if (funcId in ttContext.functionsStackDeltas) {
  26913. stack.length += ttContext.functionsStackDeltas[funcId];
  26914. } else if (funcId in ttContext.functionsDefined &&
  26915. functionsCalled.indexOf(funcId) < 0) {
  26916. callstack.push({data: data, i: i, stackTop: stack.length - 1});
  26917. functionsCalled.push(funcId);
  26918. pc = ttContext.functionsDefined[funcId];
  26919. if (!pc) {
  26920. warn('TT: CALL non-existent function');
  26921. ttContext.hintsValid = false;
  26922. return;
  26923. }
  26924. data = pc.data;
  26925. i = pc.i;
  26926. }
  26927. }
  26928. } else if (op === 0x2C && !tooComplexToFollowFunctions) { // FDEF
  26929. if (inFDEF || inELSE) {
  26930. warn('TT: nested FDEFs not allowed');
  26931. tooComplexToFollowFunctions = true;
  26932. }
  26933. inFDEF = true;
  26934. // collecting inforamtion about which functions are defined
  26935. lastDeff = i;
  26936. funcId = stack.pop();
  26937. ttContext.functionsDefined[funcId] = {data: data, i: i};
  26938. } else if (op === 0x2D) { // ENDF - end of function
  26939. if (inFDEF) {
  26940. inFDEF = false;
  26941. lastEndf = i;
  26942. } else {
  26943. pc = callstack.pop();
  26944. if (!pc) {
  26945. warn('TT: ENDF bad stack');
  26946. ttContext.hintsValid = false;
  26947. return;
  26948. }
  26949. funcId = functionsCalled.pop();
  26950. data = pc.data;
  26951. i = pc.i;
  26952. ttContext.functionsStackDeltas[funcId] =
  26953. stack.length - pc.stackTop;
  26954. }
  26955. } else if (op === 0x89) { // IDEF - instruction definition
  26956. if (inFDEF || inELSE) {
  26957. warn('TT: nested IDEFs not allowed');
  26958. tooComplexToFollowFunctions = true;
  26959. }
  26960. inFDEF = true;
  26961. // recording it as a function to track ENDF
  26962. lastDeff = i;
  26963. } else if (op === 0x58) { // IF
  26964. ++ifLevel;
  26965. } else if (op === 0x1B) { // ELSE
  26966. inELSE = ifLevel;
  26967. } else if (op === 0x59) { // EIF
  26968. if (inELSE === ifLevel) {
  26969. inELSE = 0;
  26970. }
  26971. --ifLevel;
  26972. } else if (op === 0x1C) { // JMPR
  26973. if (!inFDEF && !inELSE) {
  26974. var offset = stack[stack.length - 1];
  26975. // only jumping forward to prevent infinite loop
  26976. if (offset > 0) {
  26977. i += offset - 1;
  26978. }
  26979. }
  26980. }
  26981. // Adjusting stack not extactly, but just enough to get function id
  26982. if (!inFDEF && !inELSE) {
  26983. var stackDelta = op <= 0x8E ? TTOpsStackDeltas[op] :
  26984. op >= 0xC0 && op <= 0xDF ? -1 : op >= 0xE0 ? -2 : 0;
  26985. if (op >= 0x71 && op <= 0x75) {
  26986. n = stack.pop();
  26987. if (n === n) {
  26988. stackDelta = -n * 2;
  26989. }
  26990. }
  26991. while (stackDelta < 0 && stack.length > 0) {
  26992. stack.pop();
  26993. stackDelta++;
  26994. }
  26995. while (stackDelta > 0) {
  26996. stack.push(NaN); // pushing any number into stack
  26997. stackDelta--;
  26998. }
  26999. }
  27000. }
  27001. ttContext.tooComplexToFollowFunctions = tooComplexToFollowFunctions;
  27002. var content = [data];
  27003. if (i > data.length) {
  27004. content.push(new Uint8Array(i - data.length));
  27005. }
  27006. if (lastDeff > lastEndf) {
  27007. warn('TT: complementing a missing function tail');
  27008. // new function definition started, but not finished
  27009. // complete function by [CLEAR, ENDF]
  27010. content.push(new Uint8Array([0x22, 0x2D]));
  27011. }
  27012. foldTTTable(table, content);
  27013. }
  27014. function checkInvalidFunctions(ttContext, maxFunctionDefs) {
  27015. if (ttContext.tooComplexToFollowFunctions) {
  27016. return;
  27017. }
  27018. if (ttContext.functionsDefined.length > maxFunctionDefs) {
  27019. warn('TT: more functions defined than expected');
  27020. ttContext.hintsValid = false;
  27021. return;
  27022. }
  27023. for (var j = 0, jj = ttContext.functionsUsed.length; j < jj; j++) {
  27024. if (j > maxFunctionDefs) {
  27025. warn('TT: invalid function id: ' + j);
  27026. ttContext.hintsValid = false;
  27027. return;
  27028. }
  27029. if (ttContext.functionsUsed[j] && !ttContext.functionsDefined[j]) {
  27030. warn('TT: undefined function: ' + j);
  27031. ttContext.hintsValid = false;
  27032. return;
  27033. }
  27034. }
  27035. }
  27036. function foldTTTable(table, content) {
  27037. if (content.length > 1) {
  27038. // concatenating the content items
  27039. var newLength = 0;
  27040. var j, jj;
  27041. for (j = 0, jj = content.length; j < jj; j++) {
  27042. newLength += content[j].length;
  27043. }
  27044. newLength = (newLength + 3) & ~3;
  27045. var result = new Uint8Array(newLength);
  27046. var pos = 0;
  27047. for (j = 0, jj = content.length; j < jj; j++) {
  27048. result.set(content[j], pos);
  27049. pos += content[j].length;
  27050. }
  27051. table.data = result;
  27052. table.length = newLength;
  27053. }
  27054. }
  27055. function sanitizeTTPrograms(fpgm, prep, cvt) {
  27056. var ttContext = {
  27057. functionsDefined: [],
  27058. functionsUsed: [],
  27059. functionsStackDeltas: [],
  27060. tooComplexToFollowFunctions: false,
  27061. hintsValid: true
  27062. };
  27063. if (fpgm) {
  27064. sanitizeTTProgram(fpgm, ttContext);
  27065. }
  27066. if (prep) {
  27067. sanitizeTTProgram(prep, ttContext);
  27068. }
  27069. if (fpgm) {
  27070. checkInvalidFunctions(ttContext, maxFunctionDefs);
  27071. }
  27072. if (cvt && (cvt.length & 1)) {
  27073. var cvtData = new Uint8Array(cvt.length + 1);
  27074. cvtData.set(cvt.data);
  27075. cvt.data = cvtData;
  27076. }
  27077. return ttContext.hintsValid;
  27078. }
  27079. // The following steps modify the original font data, making copy
  27080. font = new Stream(new Uint8Array(font.getBytes()));
  27081. var VALID_TABLES = ['OS/2', 'cmap', 'head', 'hhea', 'hmtx', 'maxp',
  27082. 'name', 'post', 'loca', 'glyf', 'fpgm', 'prep', 'cvt ', 'CFF '];
  27083. var header = readOpenTypeHeader(font);
  27084. var numTables = header.numTables;
  27085. var cff, cffFile;
  27086. var tables = { 'OS/2': null, cmap: null, head: null, hhea: null,
  27087. hmtx: null, maxp: null, name: null, post: null };
  27088. var table;
  27089. for (var i = 0; i < numTables; i++) {
  27090. table = readTableEntry(font);
  27091. if (VALID_TABLES.indexOf(table.tag) < 0) {
  27092. continue; // skipping table if it's not a required or optional table
  27093. }
  27094. if (table.length === 0) {
  27095. continue; // skipping empty tables
  27096. }
  27097. tables[table.tag] = table;
  27098. }
  27099. var isTrueType = !tables['CFF '];
  27100. if (!isTrueType) {
  27101. // OpenType font
  27102. if ((header.version === 'OTTO' && properties.type !== 'CIDFontType2') ||
  27103. !tables.head || !tables.hhea || !tables.maxp || !tables.post) {
  27104. // no major tables: throwing everything at CFFFont
  27105. cffFile = new Stream(tables['CFF '].data);
  27106. cff = new CFFFont(cffFile, properties);
  27107. adjustWidths(properties);
  27108. return this.convert(name, cff, properties);
  27109. }
  27110. delete tables.glyf;
  27111. delete tables.loca;
  27112. delete tables.fpgm;
  27113. delete tables.prep;
  27114. delete tables['cvt '];
  27115. this.isOpenType = true;
  27116. } else {
  27117. if (!tables.glyf || !tables.loca) {
  27118. error('Required "glyf" or "loca" tables are not found');
  27119. }
  27120. this.isOpenType = false;
  27121. }
  27122. if (!tables.maxp) {
  27123. error('Required "maxp" table is not found');
  27124. }
  27125. font.pos = (font.start || 0) + tables.maxp.offset;
  27126. var version = font.getInt32();
  27127. var numGlyphs = font.getUint16();
  27128. var maxFunctionDefs = 0;
  27129. if (version >= 0x00010000 && tables.maxp.length >= 22) {
  27130. // maxZones can be invalid
  27131. font.pos += 8;
  27132. var maxZones = font.getUint16();
  27133. if (maxZones > 2) { // reset to 2 if font has invalid maxZones
  27134. tables.maxp.data[14] = 0;
  27135. tables.maxp.data[15] = 2;
  27136. }
  27137. font.pos += 4;
  27138. maxFunctionDefs = font.getUint16();
  27139. }
  27140. var dupFirstEntry = false;
  27141. if (properties.type === 'CIDFontType2' && properties.toUnicode &&
  27142. properties.toUnicode.get(0) > '\u0000') {
  27143. // oracle's defect (see 3427), duplicating first entry
  27144. dupFirstEntry = true;
  27145. numGlyphs++;
  27146. tables.maxp.data[4] = numGlyphs >> 8;
  27147. tables.maxp.data[5] = numGlyphs & 255;
  27148. }
  27149. var hintsValid = sanitizeTTPrograms(tables.fpgm, tables.prep,
  27150. tables['cvt '], maxFunctionDefs);
  27151. if (!hintsValid) {
  27152. delete tables.fpgm;
  27153. delete tables.prep;
  27154. delete tables['cvt '];
  27155. }
  27156. // Ensure the hmtx table contains the advance width and
  27157. // sidebearings information for numGlyphs in the maxp table
  27158. sanitizeMetrics(font, tables.hhea, tables.hmtx, numGlyphs);
  27159. if (!tables.head) {
  27160. error('Required "head" table is not found');
  27161. }
  27162. sanitizeHead(tables.head, numGlyphs, isTrueType ? tables.loca.length : 0);
  27163. var missingGlyphs = {};
  27164. if (isTrueType) {
  27165. var isGlyphLocationsLong = int16(tables.head.data[50],
  27166. tables.head.data[51]);
  27167. missingGlyphs = sanitizeGlyphLocations(tables.loca, tables.glyf,
  27168. numGlyphs, isGlyphLocationsLong,
  27169. hintsValid, dupFirstEntry);
  27170. }
  27171. if (!tables.hhea) {
  27172. error('Required "hhea" table is not found');
  27173. }
  27174. // Sanitizer reduces the glyph advanceWidth to the maxAdvanceWidth
  27175. // Sometimes it's 0. That needs to be fixed
  27176. if (tables.hhea.data[10] === 0 && tables.hhea.data[11] === 0) {
  27177. tables.hhea.data[10] = 0xFF;
  27178. tables.hhea.data[11] = 0xFF;
  27179. }
  27180. // Extract some more font properties from the OpenType head and
  27181. // hhea tables; yMin and descent value are always negative.
  27182. var metricsOverride = {
  27183. unitsPerEm: int16(tables.head.data[18], tables.head.data[19]),
  27184. yMax: int16(tables.head.data[42], tables.head.data[43]),
  27185. yMin: int16(tables.head.data[38], tables.head.data[39]) - 0x10000,
  27186. ascent: int16(tables.hhea.data[4], tables.hhea.data[5]),
  27187. descent: int16(tables.hhea.data[6], tables.hhea.data[7]) - 0x10000
  27188. };
  27189. // PDF FontDescriptor metrics lie -- using data from actual font.
  27190. this.ascent = metricsOverride.ascent / metricsOverride.unitsPerEm;
  27191. this.descent = metricsOverride.descent / metricsOverride.unitsPerEm;
  27192. // The 'post' table has glyphs names.
  27193. if (tables.post) {
  27194. var valid = readPostScriptTable(tables.post, properties, numGlyphs);
  27195. if (!valid) {
  27196. tables.post = null;
  27197. }
  27198. }
  27199. var charCodeToGlyphId = [], charCode;
  27200. var toUnicode = properties.toUnicode, widths = properties.widths;
  27201. var skipToUnicode = (toUnicode instanceof IdentityToUnicodeMap ||
  27202. toUnicode.length === 0x10000);
  27203. // Helper function to try to skip mapping of empty glyphs.
  27204. // Note: In some cases, just relying on the glyph data doesn't work,
  27205. // hence we also use a few heuristics to fix various PDF files.
  27206. function hasGlyph(glyphId, charCode, widthCode) {
  27207. if (!missingGlyphs[glyphId]) {
  27208. return true;
  27209. }
  27210. if (!skipToUnicode && charCode >= 0 && toUnicode.has(charCode)) {
  27211. return true;
  27212. }
  27213. if (widths && widthCode >= 0 && isNum(widths[widthCode])) {
  27214. return true;
  27215. }
  27216. return false;
  27217. }
  27218. if (properties.type === 'CIDFontType2') {
  27219. var cidToGidMap = properties.cidToGidMap || [];
  27220. var isCidToGidMapEmpty = cidToGidMap.length === 0;
  27221. properties.cMap.forEach(function(charCode, cid) {
  27222. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  27223. var glyphId = -1;
  27224. if (isCidToGidMapEmpty) {
  27225. glyphId = charCode;
  27226. } else if (cidToGidMap[cid] !== undefined) {
  27227. glyphId = cidToGidMap[cid];
  27228. }
  27229. if (glyphId >= 0 && glyphId < numGlyphs &&
  27230. hasGlyph(glyphId, charCode, cid)) {
  27231. charCodeToGlyphId[charCode] = glyphId;
  27232. }
  27233. });
  27234. if (dupFirstEntry) {
  27235. charCodeToGlyphId[0] = numGlyphs - 1;
  27236. }
  27237. } else {
  27238. // Most of the following logic in this code branch is based on the
  27239. // 9.6.6.4 of the PDF spec.
  27240. var hasEncoding =
  27241. properties.differences.length > 0 || !!properties.baseEncodingName;
  27242. var cmapTable =
  27243. readCmapTable(tables.cmap, font, this.isSymbolicFont, hasEncoding);
  27244. var cmapPlatformId = cmapTable.platformId;
  27245. var cmapEncodingId = cmapTable.encodingId;
  27246. var cmapMappings = cmapTable.mappings;
  27247. var cmapMappingsLength = cmapMappings.length;
  27248. // The spec seems to imply that if the font is symbolic the encoding
  27249. // should be ignored, this doesn't appear to work for 'preistabelle.pdf'
  27250. // where the the font is symbolic and it has an encoding.
  27251. if (hasEncoding &&
  27252. (cmapPlatformId === 3 && cmapEncodingId === 1 ||
  27253. cmapPlatformId === 1 && cmapEncodingId === 0) ||
  27254. (cmapPlatformId === -1 && cmapEncodingId === -1 && // Temporary hack
  27255. !!Encodings[properties.baseEncodingName])) { // Temporary hack
  27256. // When no preferred cmap table was found and |baseEncodingName| is
  27257. // one of the predefined encodings, we seem to obtain a better
  27258. // |charCodeToGlyphId| map from the code below (fixes bug 1057544).
  27259. // TODO: Note that this is a hack which should be removed as soon as
  27260. // we have proper support for more exotic cmap tables.
  27261. var baseEncoding = [];
  27262. if (properties.baseEncodingName === 'MacRomanEncoding' ||
  27263. properties.baseEncodingName === 'WinAnsiEncoding') {
  27264. baseEncoding = Encodings[properties.baseEncodingName];
  27265. }
  27266. for (charCode = 0; charCode < 256; charCode++) {
  27267. var glyphName;
  27268. if (this.differences && charCode in this.differences) {
  27269. glyphName = this.differences[charCode];
  27270. } else if (charCode in baseEncoding &&
  27271. baseEncoding[charCode] !== '') {
  27272. glyphName = baseEncoding[charCode];
  27273. } else {
  27274. glyphName = Encodings.StandardEncoding[charCode];
  27275. }
  27276. if (!glyphName) {
  27277. continue;
  27278. }
  27279. var unicodeOrCharCode, isUnicode = false;
  27280. if (cmapPlatformId === 3 && cmapEncodingId === 1) {
  27281. unicodeOrCharCode = GlyphsUnicode[glyphName];
  27282. isUnicode = true;
  27283. } else if (cmapPlatformId === 1 && cmapEncodingId === 0) {
  27284. // TODO: the encoding needs to be updated with mac os table.
  27285. unicodeOrCharCode = Encodings.MacRomanEncoding.indexOf(glyphName);
  27286. }
  27287. var found = false;
  27288. for (i = 0; i < cmapMappingsLength; ++i) {
  27289. if (cmapMappings[i].charCode !== unicodeOrCharCode) {
  27290. continue;
  27291. }
  27292. var code = isUnicode ? charCode : unicodeOrCharCode;
  27293. if (hasGlyph(cmapMappings[i].glyphId, code, -1)) {
  27294. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  27295. found = true;
  27296. break;
  27297. }
  27298. }
  27299. if (!found && properties.glyphNames) {
  27300. // Try to map using the post table.
  27301. var glyphId = properties.glyphNames.indexOf(glyphName);
  27302. if (glyphId > 0 && hasGlyph(glyphId, -1, -1)) {
  27303. charCodeToGlyphId[charCode] = glyphId;
  27304. } else {
  27305. charCodeToGlyphId[charCode] = 0; // notdef
  27306. }
  27307. }
  27308. }
  27309. } else if (cmapPlatformId === 0 && cmapEncodingId === 0) {
  27310. // Default Unicode semantics, use the charcodes as is.
  27311. for (i = 0; i < cmapMappingsLength; ++i) {
  27312. charCodeToGlyphId[cmapMappings[i].charCode] =
  27313. cmapMappings[i].glyphId;
  27314. }
  27315. } else {
  27316. // For (3, 0) cmap tables:
  27317. // The charcode key being stored in charCodeToGlyphId is the lower
  27318. // byte of the two-byte charcodes of the cmap table since according to
  27319. // the spec: 'each byte from the string shall be prepended with the
  27320. // high byte of the range [of charcodes in the cmap table], to form
  27321. // a two-byte character, which shall be used to select the
  27322. // associated glyph description from the subtable'.
  27323. //
  27324. // For (1, 0) cmap tables:
  27325. // 'single bytes from the string shall be used to look up the
  27326. // associated glyph descriptions from the subtable'. This means
  27327. // charcodes in the cmap will be single bytes, so no-op since
  27328. // glyph.charCode & 0xFF === glyph.charCode
  27329. for (i = 0; i < cmapMappingsLength; ++i) {
  27330. charCode = cmapMappings[i].charCode & 0xFF;
  27331. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  27332. }
  27333. }
  27334. }
  27335. if (charCodeToGlyphId.length === 0) {
  27336. // defines at least one glyph
  27337. charCodeToGlyphId[0] = 0;
  27338. }
  27339. // Converting glyphs and ids into font's cmap table
  27340. var newMapping = adjustMapping(charCodeToGlyphId, properties);
  27341. this.toFontChar = newMapping.toFontChar;
  27342. tables.cmap = {
  27343. tag: 'cmap',
  27344. data: createCmapTable(newMapping.charCodeToGlyphId, numGlyphs)
  27345. };
  27346. if (!tables['OS/2'] || !validateOS2Table(tables['OS/2'])) {
  27347. tables['OS/2'] = {
  27348. tag: 'OS/2',
  27349. data: createOS2Table(properties, newMapping.charCodeToGlyphId,
  27350. metricsOverride)
  27351. };
  27352. }
  27353. // Rewrite the 'post' table if needed
  27354. if (!tables.post) {
  27355. tables.post = {
  27356. tag: 'post',
  27357. data: createPostTable(properties)
  27358. };
  27359. }
  27360. if (!isTrueType) {
  27361. try {
  27362. // Trying to repair CFF file
  27363. cffFile = new Stream(tables['CFF '].data);
  27364. var parser = new CFFParser(cffFile, properties);
  27365. cff = parser.parse();
  27366. var compiler = new CFFCompiler(cff);
  27367. tables['CFF '].data = compiler.compile();
  27368. } catch (e) {
  27369. warn('Failed to compile font ' + properties.loadedName);
  27370. }
  27371. }
  27372. // Re-creating 'name' table
  27373. if (!tables.name) {
  27374. tables.name = {
  27375. tag: 'name',
  27376. data: createNameTable(this.name)
  27377. };
  27378. } else {
  27379. // ... using existing 'name' table as prototype
  27380. var namePrototype = readNameTable(tables.name);
  27381. tables.name.data = createNameTable(name, namePrototype);
  27382. }
  27383. var builder = new OpenTypeFileBuilder(header.version);
  27384. for (var tableTag in tables) {
  27385. builder.addTable(tableTag, tables[tableTag].data);
  27386. }
  27387. return builder.toArray();
  27388. },
  27389. convert: function Font_convert(fontName, font, properties) {
  27390. // TODO: Check the charstring widths to determine this.
  27391. properties.fixedPitch = false;
  27392. var mapping = font.getGlyphMapping(properties);
  27393. var newMapping = adjustMapping(mapping, properties);
  27394. this.toFontChar = newMapping.toFontChar;
  27395. var numGlyphs = font.numGlyphs;
  27396. function getCharCodes(charCodeToGlyphId, glyphId) {
  27397. var charCodes = null;
  27398. for (var charCode in charCodeToGlyphId) {
  27399. if (glyphId === charCodeToGlyphId[charCode]) {
  27400. if (!charCodes) {
  27401. charCodes = [];
  27402. }
  27403. charCodes.push(charCode | 0);
  27404. }
  27405. }
  27406. return charCodes;
  27407. }
  27408. function createCharCode(charCodeToGlyphId, glyphId) {
  27409. for (var charCode in charCodeToGlyphId) {
  27410. if (glyphId === charCodeToGlyphId[charCode]) {
  27411. return charCode | 0;
  27412. }
  27413. }
  27414. newMapping.charCodeToGlyphId[newMapping.nextAvailableFontCharCode] =
  27415. glyphId;
  27416. return newMapping.nextAvailableFontCharCode++;
  27417. }
  27418. var seacs = font.seacs;
  27419. if (SEAC_ANALYSIS_ENABLED && seacs && seacs.length) {
  27420. var matrix = properties.fontMatrix || FONT_IDENTITY_MATRIX;
  27421. var charset = font.getCharset();
  27422. var seacMap = Object.create(null);
  27423. for (var glyphId in seacs) {
  27424. glyphId |= 0;
  27425. var seac = seacs[glyphId];
  27426. var baseGlyphName = Encodings.StandardEncoding[seac[2]];
  27427. var accentGlyphName = Encodings.StandardEncoding[seac[3]];
  27428. var baseGlyphId = charset.indexOf(baseGlyphName);
  27429. var accentGlyphId = charset.indexOf(accentGlyphName);
  27430. if (baseGlyphId < 0 || accentGlyphId < 0) {
  27431. continue;
  27432. }
  27433. var accentOffset = {
  27434. x: seac[0] * matrix[0] + seac[1] * matrix[2] + matrix[4],
  27435. y: seac[0] * matrix[1] + seac[1] * matrix[3] + matrix[5]
  27436. };
  27437. var charCodes = getCharCodes(mapping, glyphId);
  27438. if (!charCodes) {
  27439. // There's no point in mapping it if the char code was never mapped
  27440. // to begin with.
  27441. continue;
  27442. }
  27443. for (var i = 0, ii = charCodes.length; i < ii; i++) {
  27444. var charCode = charCodes[i];
  27445. // Find a fontCharCode that maps to the base and accent glyphs.
  27446. // If one doesn't exists, create it.
  27447. var charCodeToGlyphId = newMapping.charCodeToGlyphId;
  27448. var baseFontCharCode = createCharCode(charCodeToGlyphId,
  27449. baseGlyphId);
  27450. var accentFontCharCode = createCharCode(charCodeToGlyphId,
  27451. accentGlyphId);
  27452. seacMap[charCode] = {
  27453. baseFontCharCode: baseFontCharCode,
  27454. accentFontCharCode: accentFontCharCode,
  27455. accentOffset: accentOffset
  27456. };
  27457. }
  27458. }
  27459. properties.seacMap = seacMap;
  27460. }
  27461. var unitsPerEm = 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0];
  27462. var builder = new OpenTypeFileBuilder('\x4F\x54\x54\x4F');
  27463. // PostScript Font Program
  27464. builder.addTable('CFF ', font.data);
  27465. // OS/2 and Windows Specific metrics
  27466. builder.addTable('OS/2', createOS2Table(properties,
  27467. newMapping.charCodeToGlyphId));
  27468. // Character to glyphs mapping
  27469. builder.addTable('cmap', createCmapTable(newMapping.charCodeToGlyphId,
  27470. numGlyphs));
  27471. // Font header
  27472. builder.addTable('head',
  27473. '\x00\x01\x00\x00' + // Version number
  27474. '\x00\x00\x10\x00' + // fontRevision
  27475. '\x00\x00\x00\x00' + // checksumAdjustement
  27476. '\x5F\x0F\x3C\xF5' + // magicNumber
  27477. '\x00\x00' + // Flags
  27478. safeString16(unitsPerEm) + // unitsPerEM
  27479. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // creation date
  27480. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // modifification date
  27481. '\x00\x00' + // xMin
  27482. safeString16(properties.descent) + // yMin
  27483. '\x0F\xFF' + // xMax
  27484. safeString16(properties.ascent) + // yMax
  27485. string16(properties.italicAngle ? 2 : 0) + // macStyle
  27486. '\x00\x11' + // lowestRecPPEM
  27487. '\x00\x00' + // fontDirectionHint
  27488. '\x00\x00' + // indexToLocFormat
  27489. '\x00\x00'); // glyphDataFormat
  27490. // Horizontal header
  27491. builder.addTable('hhea',
  27492. '\x00\x01\x00\x00' + // Version number
  27493. safeString16(properties.ascent) + // Typographic Ascent
  27494. safeString16(properties.descent) + // Typographic Descent
  27495. '\x00\x00' + // Line Gap
  27496. '\xFF\xFF' + // advanceWidthMax
  27497. '\x00\x00' + // minLeftSidebearing
  27498. '\x00\x00' + // minRightSidebearing
  27499. '\x00\x00' + // xMaxExtent
  27500. safeString16(properties.capHeight) + // caretSlopeRise
  27501. safeString16(Math.tan(properties.italicAngle) *
  27502. properties.xHeight) + // caretSlopeRun
  27503. '\x00\x00' + // caretOffset
  27504. '\x00\x00' + // -reserved-
  27505. '\x00\x00' + // -reserved-
  27506. '\x00\x00' + // -reserved-
  27507. '\x00\x00' + // -reserved-
  27508. '\x00\x00' + // metricDataFormat
  27509. string16(numGlyphs)); // Number of HMetrics
  27510. // Horizontal metrics
  27511. builder.addTable('hmtx', (function fontFieldsHmtx() {
  27512. var charstrings = font.charstrings;
  27513. var cffWidths = font.cff ? font.cff.widths : null;
  27514. var hmtx = '\x00\x00\x00\x00'; // Fake .notdef
  27515. for (var i = 1, ii = numGlyphs; i < ii; i++) {
  27516. var width = 0;
  27517. if (charstrings) {
  27518. var charstring = charstrings[i - 1];
  27519. width = 'width' in charstring ? charstring.width : 0;
  27520. } else if (cffWidths) {
  27521. width = Math.ceil(cffWidths[i] || 0);
  27522. }
  27523. hmtx += string16(width) + string16(0);
  27524. }
  27525. return hmtx;
  27526. })());
  27527. // Maximum profile
  27528. builder.addTable('maxp',
  27529. '\x00\x00\x50\x00' + // Version number
  27530. string16(numGlyphs)); // Num of glyphs
  27531. // Naming tables
  27532. builder.addTable('name', createNameTable(fontName));
  27533. // PostScript informations
  27534. builder.addTable('post', createPostTable(properties));
  27535. return builder.toArray();
  27536. },
  27537. /**
  27538. * Builds a char code to unicode map based on section 9.10 of the spec.
  27539. * @param {Object} properties Font properties object.
  27540. * @return {Object} A ToUnicodeMap object.
  27541. */
  27542. buildToUnicode: function Font_buildToUnicode(properties) {
  27543. // Section 9.10.2 Mapping Character Codes to Unicode Values
  27544. if (properties.toUnicode && properties.toUnicode.length !== 0) {
  27545. return properties.toUnicode;
  27546. }
  27547. // According to the spec if the font is a simple font we should only map
  27548. // to unicode if the base encoding is MacRoman, MacExpert, or WinAnsi or
  27549. // the differences array only contains adobe standard or symbol set names,
  27550. // in pratice it seems better to always try to create a toUnicode
  27551. // map based of the default encoding.
  27552. var toUnicode, charcode;
  27553. if (!properties.composite /* is simple font */) {
  27554. toUnicode = [];
  27555. var encoding = properties.defaultEncoding.slice();
  27556. var baseEncodingName = properties.baseEncodingName;
  27557. // Merge in the differences array.
  27558. var differences = properties.differences;
  27559. for (charcode in differences) {
  27560. encoding[charcode] = differences[charcode];
  27561. }
  27562. for (charcode in encoding) {
  27563. // a) Map the character code to a character name.
  27564. var glyphName = encoding[charcode];
  27565. // b) Look up the character name in the Adobe Glyph List (see the
  27566. // Bibliography) to obtain the corresponding Unicode value.
  27567. if (glyphName === '') {
  27568. continue;
  27569. } else if (GlyphsUnicode[glyphName] === undefined) {
  27570. // (undocumented) c) Few heuristics to recognize unknown glyphs
  27571. // NOTE: Adobe Reader does not do this step, but OSX Preview does
  27572. var code = 0;
  27573. switch (glyphName[0]) {
  27574. case 'G': // Gxx glyph
  27575. if (glyphName.length === 3) {
  27576. code = parseInt(glyphName.substr(1), 16);
  27577. }
  27578. break;
  27579. case 'g': // g00xx glyph
  27580. if (glyphName.length === 5) {
  27581. code = parseInt(glyphName.substr(1), 16);
  27582. }
  27583. break;
  27584. case 'C': // Cddd glyph
  27585. case 'c': // cddd glyph
  27586. if (glyphName.length >= 3) {
  27587. code = +glyphName.substr(1);
  27588. }
  27589. break;
  27590. }
  27591. if (code) {
  27592. // If |baseEncodingName| is one the predefined encodings,
  27593. // and |code| equals |charcode|, using the glyph defined in the
  27594. // baseEncoding seems to yield a better |toUnicode| mapping
  27595. // (fixes issue 5070).
  27596. if (baseEncodingName && code === +charcode) {
  27597. var baseEncoding = Encodings[baseEncodingName];
  27598. if (baseEncoding && (glyphName = baseEncoding[charcode])) {
  27599. toUnicode[charcode] =
  27600. String.fromCharCode(GlyphsUnicode[glyphName]);
  27601. continue;
  27602. }
  27603. }
  27604. toUnicode[charcode] = String.fromCharCode(code);
  27605. }
  27606. continue;
  27607. }
  27608. toUnicode[charcode] = String.fromCharCode(GlyphsUnicode[glyphName]);
  27609. }
  27610. return new ToUnicodeMap(toUnicode);
  27611. }
  27612. // If the font is a composite font that uses one of the predefined CMaps
  27613. // listed in Table 118 (except Identity–H and Identity–V) or whose
  27614. // descendant CIDFont uses the Adobe-GB1, Adobe-CNS1, Adobe-Japan1, or
  27615. // Adobe-Korea1 character collection:
  27616. if (properties.composite && (
  27617. (properties.cMap.builtInCMap &&
  27618. !(properties.cMap instanceof IdentityCMap)) ||
  27619. (properties.cidSystemInfo.registry === 'Adobe' &&
  27620. (properties.cidSystemInfo.ordering === 'GB1' ||
  27621. properties.cidSystemInfo.ordering === 'CNS1' ||
  27622. properties.cidSystemInfo.ordering === 'Japan1' ||
  27623. properties.cidSystemInfo.ordering === 'Korea1')))) {
  27624. // Then:
  27625. // a) Map the character code to a character identifier (CID) according
  27626. // to the font’s CMap.
  27627. // b) Obtain the registry and ordering of the character collection used
  27628. // by the font’s CMap (for example, Adobe and Japan1) from its
  27629. // CIDSystemInfo dictionary.
  27630. var registry = properties.cidSystemInfo.registry;
  27631. var ordering = properties.cidSystemInfo.ordering;
  27632. // c) Construct a second CMap name by concatenating the registry and
  27633. // ordering obtained in step (b) in the format registry–ordering–UCS2
  27634. // (for example, Adobe–Japan1–UCS2).
  27635. var ucs2CMapName = new Name(registry + '-' + ordering + '-UCS2');
  27636. // d) Obtain the CMap with the name constructed in step (c) (available
  27637. // from the ASN Web site; see the Bibliography).
  27638. var ucs2CMap = CMapFactory.create(ucs2CMapName,
  27639. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  27640. var cMap = properties.cMap;
  27641. toUnicode = [];
  27642. cMap.forEach(function(charcode, cid) {
  27643. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  27644. // e) Map the CID obtained in step (a) according to the CMap obtained
  27645. // in step (d), producing a Unicode value.
  27646. var ucs2 = ucs2CMap.lookup(cid);
  27647. if (ucs2) {
  27648. toUnicode[charcode] =
  27649. String.fromCharCode((ucs2.charCodeAt(0) << 8) +
  27650. ucs2.charCodeAt(1));
  27651. }
  27652. });
  27653. return new ToUnicodeMap(toUnicode);
  27654. }
  27655. // The viewer's choice, just use an identity map.
  27656. return new IdentityToUnicodeMap(properties.firstChar,
  27657. properties.lastChar);
  27658. },
  27659. get spaceWidth() {
  27660. if ('_shadowWidth' in this) {
  27661. return this._shadowWidth;
  27662. }
  27663. // trying to estimate space character width
  27664. var possibleSpaceReplacements = ['space', 'minus', 'one', 'i'];
  27665. var width;
  27666. for (var i = 0, ii = possibleSpaceReplacements.length; i < ii; i++) {
  27667. var glyphName = possibleSpaceReplacements[i];
  27668. // if possible, getting width by glyph name
  27669. if (glyphName in this.widths) {
  27670. width = this.widths[glyphName];
  27671. break;
  27672. }
  27673. var glyphUnicode = GlyphsUnicode[glyphName];
  27674. // finding the charcode via unicodeToCID map
  27675. var charcode = 0;
  27676. if (this.composite) {
  27677. if (this.cMap.contains(glyphUnicode)) {
  27678. charcode = this.cMap.lookup(glyphUnicode);
  27679. }
  27680. }
  27681. // ... via toUnicode map
  27682. if (!charcode && this.toUnicode) {
  27683. charcode = this.toUnicode.charCodeOf(glyphUnicode);
  27684. }
  27685. // setting it to unicode if negative or undefined
  27686. if (charcode <= 0) {
  27687. charcode = glyphUnicode;
  27688. }
  27689. // trying to get width via charcode
  27690. width = this.widths[charcode];
  27691. if (width) {
  27692. break; // the non-zero width found
  27693. }
  27694. }
  27695. width = width || this.defaultWidth;
  27696. // Do not shadow the property here. See discussion:
  27697. // https://github.com/mozilla/pdf.js/pull/2127#discussion_r1662280
  27698. this._shadowWidth = width;
  27699. return width;
  27700. },
  27701. charToGlyph: function Font_charToGlyph(charcode, isSpace) {
  27702. var fontCharCode, width, operatorListId;
  27703. var widthCode = charcode;
  27704. if (this.cMap && this.cMap.contains(charcode)) {
  27705. widthCode = this.cMap.lookup(charcode);
  27706. }
  27707. width = this.widths[widthCode];
  27708. width = isNum(width) ? width : this.defaultWidth;
  27709. var vmetric = this.vmetrics && this.vmetrics[widthCode];
  27710. var unicode = this.toUnicode.get(charcode) || charcode;
  27711. if (typeof unicode === 'number') {
  27712. unicode = String.fromCharCode(unicode);
  27713. }
  27714. // First try the toFontChar map, if it's not there then try falling
  27715. // back to the char code.
  27716. fontCharCode = this.toFontChar[charcode] || charcode;
  27717. if (this.missingFile) {
  27718. fontCharCode = mapSpecialUnicodeValues(fontCharCode);
  27719. }
  27720. if (this.isType3Font) {
  27721. // Font char code in this case is actually a glyph name.
  27722. operatorListId = fontCharCode;
  27723. }
  27724. var accent = null;
  27725. if (this.seacMap && this.seacMap[charcode]) {
  27726. var seac = this.seacMap[charcode];
  27727. fontCharCode = seac.baseFontCharCode;
  27728. accent = {
  27729. fontChar: String.fromCharCode(seac.accentFontCharCode),
  27730. offset: seac.accentOffset
  27731. };
  27732. }
  27733. var fontChar = String.fromCharCode(fontCharCode);
  27734. var glyph = this.glyphCache[charcode];
  27735. if (!glyph ||
  27736. !glyph.matchesForCache(fontChar, unicode, accent, width, vmetric,
  27737. operatorListId, isSpace)) {
  27738. glyph = new Glyph(fontChar, unicode, accent, width, vmetric,
  27739. operatorListId, isSpace);
  27740. this.glyphCache[charcode] = glyph;
  27741. }
  27742. return glyph;
  27743. },
  27744. charsToGlyphs: function Font_charsToGlyphs(chars) {
  27745. var charsCache = this.charsCache;
  27746. var glyphs, glyph, charcode;
  27747. // if we translated this string before, just grab it from the cache
  27748. if (charsCache) {
  27749. glyphs = charsCache[chars];
  27750. if (glyphs) {
  27751. return glyphs;
  27752. }
  27753. }
  27754. // lazily create the translation cache
  27755. if (!charsCache) {
  27756. charsCache = this.charsCache = Object.create(null);
  27757. }
  27758. glyphs = [];
  27759. var charsCacheKey = chars;
  27760. var i = 0, ii;
  27761. if (this.cMap) {
  27762. // composite fonts have multi-byte strings convert the string from
  27763. // single-byte to multi-byte
  27764. var c = {};
  27765. while (i < chars.length) {
  27766. this.cMap.readCharCode(chars, i, c);
  27767. charcode = c.charcode;
  27768. var length = c.length;
  27769. i += length;
  27770. // Space is char with code 0x20 and length 1 in multiple-byte codes.
  27771. var isSpace = length === 1 && chars.charCodeAt(i - 1) === 0x20;
  27772. glyph = this.charToGlyph(charcode, isSpace);
  27773. glyphs.push(glyph);
  27774. }
  27775. } else {
  27776. for (i = 0, ii = chars.length; i < ii; ++i) {
  27777. charcode = chars.charCodeAt(i);
  27778. glyph = this.charToGlyph(charcode, charcode === 0x20);
  27779. glyphs.push(glyph);
  27780. }
  27781. }
  27782. // Enter the translated string into the cache
  27783. return (charsCache[charsCacheKey] = glyphs);
  27784. }
  27785. };
  27786. return Font;
  27787. })();
  27788. var ErrorFont = (function ErrorFontClosure() {
  27789. function ErrorFont(error) {
  27790. this.error = error;
  27791. this.loadedName = 'g_font_error';
  27792. this.loading = false;
  27793. }
  27794. ErrorFont.prototype = {
  27795. charsToGlyphs: function ErrorFont_charsToGlyphs() {
  27796. return [];
  27797. },
  27798. exportData: function ErrorFont_exportData() {
  27799. return {error: this.error};
  27800. }
  27801. };
  27802. return ErrorFont;
  27803. })();
  27804. /**
  27805. * Shared logic for building a char code to glyph id mapping for Type1 and
  27806. * simple CFF fonts. See section 9.6.6.2 of the spec.
  27807. * @param {Object} properties Font properties object.
  27808. * @param {Object} builtInEncoding The encoding contained within the actual font
  27809. * data.
  27810. * @param {Array} Array of glyph names where the index is the glyph ID.
  27811. * @returns {Object} A char code to glyph ID map.
  27812. */
  27813. function type1FontGlyphMapping(properties, builtInEncoding, glyphNames) {
  27814. var charCodeToGlyphId = Object.create(null);
  27815. var glyphId, charCode, baseEncoding;
  27816. if (properties.baseEncodingName) {
  27817. // If a valid base encoding name was used, the mapping is initialized with
  27818. // that.
  27819. baseEncoding = Encodings[properties.baseEncodingName];
  27820. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  27821. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  27822. if (glyphId >= 0) {
  27823. charCodeToGlyphId[charCode] = glyphId;
  27824. } else {
  27825. charCodeToGlyphId[charCode] = 0; // notdef
  27826. }
  27827. }
  27828. } else if (!!(properties.flags & FontFlags.Symbolic)) {
  27829. // For a symbolic font the encoding should be the fonts built-in
  27830. // encoding.
  27831. for (charCode in builtInEncoding) {
  27832. charCodeToGlyphId[charCode] = builtInEncoding[charCode];
  27833. }
  27834. } else {
  27835. // For non-symbolic fonts that don't have a base encoding the standard
  27836. // encoding should be used.
  27837. baseEncoding = Encodings.StandardEncoding;
  27838. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  27839. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  27840. if (glyphId >= 0) {
  27841. charCodeToGlyphId[charCode] = glyphId;
  27842. } else {
  27843. charCodeToGlyphId[charCode] = 0; // notdef
  27844. }
  27845. }
  27846. }
  27847. // Lastly, merge in the differences.
  27848. var differences = properties.differences;
  27849. if (differences) {
  27850. for (charCode in differences) {
  27851. var glyphName = differences[charCode];
  27852. glyphId = glyphNames.indexOf(glyphName);
  27853. if (glyphId >= 0) {
  27854. charCodeToGlyphId[charCode] = glyphId;
  27855. } else {
  27856. charCodeToGlyphId[charCode] = 0; // notdef
  27857. }
  27858. }
  27859. }
  27860. return charCodeToGlyphId;
  27861. }
  27862. /*
  27863. * CharStrings are encoded following the the CharString Encoding sequence
  27864. * describe in Chapter 6 of the "Adobe Type1 Font Format" specification.
  27865. * The value in a byte indicates a command, a number, or subsequent bytes
  27866. * that are to be interpreted in a special way.
  27867. *
  27868. * CharString Number Encoding:
  27869. * A CharString byte containing the values from 32 through 255 inclusive
  27870. * indicate an integer. These values are decoded in four ranges.
  27871. *
  27872. * 1. A CharString byte containing a value, v, between 32 and 246 inclusive,
  27873. * indicate the integer v - 139. Thus, the integer values from -107 through
  27874. * 107 inclusive may be encoded in single byte.
  27875. *
  27876. * 2. A CharString byte containing a value, v, between 247 and 250 inclusive,
  27877. * indicates an integer involving the next byte, w, according to the formula:
  27878. * [(v - 247) x 256] + w + 108
  27879. *
  27880. * 3. A CharString byte containing a value, v, between 251 and 254 inclusive,
  27881. * indicates an integer involving the next byte, w, according to the formula:
  27882. * -[(v - 251) * 256] - w - 108
  27883. *
  27884. * 4. A CharString containing the value 255 indicates that the next 4 bytes
  27885. * are a two complement signed integer. The first of these bytes contains the
  27886. * highest order bits, the second byte contains the next higher order bits
  27887. * and the fourth byte contain the lowest order bits.
  27888. *
  27889. *
  27890. * CharString Command Encoding:
  27891. * CharStrings commands are encoded in 1 or 2 bytes.
  27892. *
  27893. * Single byte commands are encoded in 1 byte that contains a value between
  27894. * 0 and 31 inclusive.
  27895. * If a command byte contains the value 12, then the value in the next byte
  27896. * indicates a command. This "escape" mechanism allows many extra commands
  27897. * to be encoded and this encoding technique helps to minimize the length of
  27898. * the charStrings.
  27899. */
  27900. var Type1CharString = (function Type1CharStringClosure() {
  27901. var COMMAND_MAP = {
  27902. 'hstem': [1],
  27903. 'vstem': [3],
  27904. 'vmoveto': [4],
  27905. 'rlineto': [5],
  27906. 'hlineto': [6],
  27907. 'vlineto': [7],
  27908. 'rrcurveto': [8],
  27909. 'callsubr': [10],
  27910. 'flex': [12, 35],
  27911. 'drop' : [12, 18],
  27912. 'endchar': [14],
  27913. 'rmoveto': [21],
  27914. 'hmoveto': [22],
  27915. 'vhcurveto': [30],
  27916. 'hvcurveto': [31]
  27917. };
  27918. function Type1CharString() {
  27919. this.width = 0;
  27920. this.lsb = 0;
  27921. this.flexing = false;
  27922. this.output = [];
  27923. this.stack = [];
  27924. }
  27925. Type1CharString.prototype = {
  27926. convert: function Type1CharString_convert(encoded, subrs) {
  27927. var count = encoded.length;
  27928. var error = false;
  27929. var wx, sbx, subrNumber;
  27930. for (var i = 0; i < count; i++) {
  27931. var value = encoded[i];
  27932. if (value < 32) {
  27933. if (value === 12) {
  27934. value = (value << 8) + encoded[++i];
  27935. }
  27936. switch (value) {
  27937. case 1: // hstem
  27938. if (!HINTING_ENABLED) {
  27939. this.stack = [];
  27940. break;
  27941. }
  27942. error = this.executeCommand(2, COMMAND_MAP.hstem);
  27943. break;
  27944. case 3: // vstem
  27945. if (!HINTING_ENABLED) {
  27946. this.stack = [];
  27947. break;
  27948. }
  27949. error = this.executeCommand(2, COMMAND_MAP.vstem);
  27950. break;
  27951. case 4: // vmoveto
  27952. if (this.flexing) {
  27953. if (this.stack.length < 1) {
  27954. error = true;
  27955. break;
  27956. }
  27957. // Add the dx for flex and but also swap the values so they are
  27958. // the right order.
  27959. var dy = this.stack.pop();
  27960. this.stack.push(0, dy);
  27961. break;
  27962. }
  27963. error = this.executeCommand(1, COMMAND_MAP.vmoveto);
  27964. break;
  27965. case 5: // rlineto
  27966. error = this.executeCommand(2, COMMAND_MAP.rlineto);
  27967. break;
  27968. case 6: // hlineto
  27969. error = this.executeCommand(1, COMMAND_MAP.hlineto);
  27970. break;
  27971. case 7: // vlineto
  27972. error = this.executeCommand(1, COMMAND_MAP.vlineto);
  27973. break;
  27974. case 8: // rrcurveto
  27975. error = this.executeCommand(6, COMMAND_MAP.rrcurveto);
  27976. break;
  27977. case 9: // closepath
  27978. // closepath is a Type1 command that does not take argument and is
  27979. // useless in Type2 and it can simply be ignored.
  27980. this.stack = [];
  27981. break;
  27982. case 10: // callsubr
  27983. if (this.stack.length < 1) {
  27984. error = true;
  27985. break;
  27986. }
  27987. subrNumber = this.stack.pop();
  27988. error = this.convert(subrs[subrNumber], subrs);
  27989. break;
  27990. case 11: // return
  27991. return error;
  27992. case 13: // hsbw
  27993. if (this.stack.length < 2) {
  27994. error = true;
  27995. break;
  27996. }
  27997. // To convert to type2 we have to move the width value to the
  27998. // first part of the charstring and then use hmoveto with lsb.
  27999. wx = this.stack.pop();
  28000. sbx = this.stack.pop();
  28001. this.lsb = sbx;
  28002. this.width = wx;
  28003. this.stack.push(wx, sbx);
  28004. error = this.executeCommand(2, COMMAND_MAP.hmoveto);
  28005. break;
  28006. case 14: // endchar
  28007. this.output.push(COMMAND_MAP.endchar[0]);
  28008. break;
  28009. case 21: // rmoveto
  28010. if (this.flexing) {
  28011. break;
  28012. }
  28013. error = this.executeCommand(2, COMMAND_MAP.rmoveto);
  28014. break;
  28015. case 22: // hmoveto
  28016. if (this.flexing) {
  28017. // Add the dy for flex.
  28018. this.stack.push(0);
  28019. break;
  28020. }
  28021. error = this.executeCommand(1, COMMAND_MAP.hmoveto);
  28022. break;
  28023. case 30: // vhcurveto
  28024. error = this.executeCommand(4, COMMAND_MAP.vhcurveto);
  28025. break;
  28026. case 31: // hvcurveto
  28027. error = this.executeCommand(4, COMMAND_MAP.hvcurveto);
  28028. break;
  28029. case (12 << 8) + 0: // dotsection
  28030. // dotsection is a Type1 command to specify some hinting feature
  28031. // for dots that do not take a parameter and it can safely be
  28032. // ignored for Type2.
  28033. this.stack = [];
  28034. break;
  28035. case (12 << 8) + 1: // vstem3
  28036. if (!HINTING_ENABLED) {
  28037. this.stack = [];
  28038. break;
  28039. }
  28040. // [vh]stem3 are Type1 only and Type2 supports [vh]stem with
  28041. // multiple parameters, so instead of returning [vh]stem3 take a
  28042. // shortcut and return [vhstem] instead.
  28043. error = this.executeCommand(2, COMMAND_MAP.vstem);
  28044. break;
  28045. case (12 << 8) + 2: // hstem3
  28046. if (!HINTING_ENABLED) {
  28047. this.stack = [];
  28048. break;
  28049. }
  28050. // See vstem3.
  28051. error = this.executeCommand(2, COMMAND_MAP.hstem);
  28052. break;
  28053. case (12 << 8) + 6: // seac
  28054. // seac is like type 2's special endchar but it doesn't use the
  28055. // first argument asb, so remove it.
  28056. if (SEAC_ANALYSIS_ENABLED) {
  28057. this.seac = this.stack.splice(-4, 4);
  28058. error = this.executeCommand(0, COMMAND_MAP.endchar);
  28059. } else {
  28060. error = this.executeCommand(4, COMMAND_MAP.endchar);
  28061. }
  28062. break;
  28063. case (12 << 8) + 7: // sbw
  28064. if (this.stack.length < 4) {
  28065. error = true;
  28066. break;
  28067. }
  28068. // To convert to type2 we have to move the width value to the
  28069. // first part of the charstring and then use rmoveto with
  28070. // (dx, dy). The height argument will not be used for vmtx and
  28071. // vhea tables reconstruction -- ignoring it.
  28072. var wy = this.stack.pop();
  28073. wx = this.stack.pop();
  28074. var sby = this.stack.pop();
  28075. sbx = this.stack.pop();
  28076. this.lsb = sbx;
  28077. this.width = wx;
  28078. this.stack.push(wx, sbx, sby);
  28079. error = this.executeCommand(3, COMMAND_MAP.rmoveto);
  28080. break;
  28081. case (12 << 8) + 12: // div
  28082. if (this.stack.length < 2) {
  28083. error = true;
  28084. break;
  28085. }
  28086. var num2 = this.stack.pop();
  28087. var num1 = this.stack.pop();
  28088. this.stack.push(num1 / num2);
  28089. break;
  28090. case (12 << 8) + 16: // callothersubr
  28091. if (this.stack.length < 2) {
  28092. error = true;
  28093. break;
  28094. }
  28095. subrNumber = this.stack.pop();
  28096. var numArgs = this.stack.pop();
  28097. if (subrNumber === 0 && numArgs === 3) {
  28098. var flexArgs = this.stack.splice(this.stack.length - 17, 17);
  28099. this.stack.push(
  28100. flexArgs[2] + flexArgs[0], // bcp1x + rpx
  28101. flexArgs[3] + flexArgs[1], // bcp1y + rpy
  28102. flexArgs[4], // bcp2x
  28103. flexArgs[5], // bcp2y
  28104. flexArgs[6], // p2x
  28105. flexArgs[7], // p2y
  28106. flexArgs[8], // bcp3x
  28107. flexArgs[9], // bcp3y
  28108. flexArgs[10], // bcp4x
  28109. flexArgs[11], // bcp4y
  28110. flexArgs[12], // p3x
  28111. flexArgs[13], // p3y
  28112. flexArgs[14] // flexDepth
  28113. // 15 = finalx unused by flex
  28114. // 16 = finaly unused by flex
  28115. );
  28116. error = this.executeCommand(13, COMMAND_MAP.flex, true);
  28117. this.flexing = false;
  28118. this.stack.push(flexArgs[15], flexArgs[16]);
  28119. } else if (subrNumber === 1 && numArgs === 0) {
  28120. this.flexing = true;
  28121. }
  28122. break;
  28123. case (12 << 8) + 17: // pop
  28124. // Ignore this since it is only used with othersubr.
  28125. break;
  28126. case (12 << 8) + 33: // setcurrentpoint
  28127. // Ignore for now.
  28128. this.stack = [];
  28129. break;
  28130. default:
  28131. warn('Unknown type 1 charstring command of "' + value + '"');
  28132. break;
  28133. }
  28134. if (error) {
  28135. break;
  28136. }
  28137. continue;
  28138. } else if (value <= 246) {
  28139. value = value - 139;
  28140. } else if (value <= 250) {
  28141. value = ((value - 247) * 256) + encoded[++i] + 108;
  28142. } else if (value <= 254) {
  28143. value = -((value - 251) * 256) - encoded[++i] - 108;
  28144. } else {
  28145. value = (encoded[++i] & 0xff) << 24 | (encoded[++i] & 0xff) << 16 |
  28146. (encoded[++i] & 0xff) << 8 | (encoded[++i] & 0xff) << 0;
  28147. }
  28148. this.stack.push(value);
  28149. }
  28150. return error;
  28151. },
  28152. executeCommand: function(howManyArgs, command, keepStack) {
  28153. var stackLength = this.stack.length;
  28154. if (howManyArgs > stackLength) {
  28155. return true;
  28156. }
  28157. var start = stackLength - howManyArgs;
  28158. for (var i = start; i < stackLength; i++) {
  28159. var value = this.stack[i];
  28160. if (value === (value | 0)) { // int
  28161. this.output.push(28, (value >> 8) & 0xff, value & 0xff);
  28162. } else { // fixed point
  28163. value = (65536 * value) | 0;
  28164. this.output.push(255,
  28165. (value >> 24) & 0xFF,
  28166. (value >> 16) & 0xFF,
  28167. (value >> 8) & 0xFF,
  28168. value & 0xFF);
  28169. }
  28170. }
  28171. this.output.push.apply(this.output, command);
  28172. if (keepStack) {
  28173. this.stack.splice(start, howManyArgs);
  28174. } else {
  28175. this.stack.length = 0;
  28176. }
  28177. return false;
  28178. }
  28179. };
  28180. return Type1CharString;
  28181. })();
  28182. /*
  28183. * Type1Parser encapsulate the needed code for parsing a Type1 font
  28184. * program. Some of its logic depends on the Type2 charstrings
  28185. * structure.
  28186. * Note: this doesn't really parse the font since that would require evaluation
  28187. * of PostScript, but it is possible in most cases to extract what we need
  28188. * without a full parse.
  28189. */
  28190. var Type1Parser = (function Type1ParserClosure() {
  28191. /*
  28192. * Decrypt a Sequence of Ciphertext Bytes to Produce the Original Sequence
  28193. * of Plaintext Bytes. The function took a key as a parameter which can be
  28194. * for decrypting the eexec block of for decoding charStrings.
  28195. */
  28196. var EEXEC_ENCRYPT_KEY = 55665;
  28197. var CHAR_STRS_ENCRYPT_KEY = 4330;
  28198. function isHexDigit(code) {
  28199. return code >= 48 && code <= 57 || // '0'-'9'
  28200. code >= 65 && code <= 70 || // 'A'-'F'
  28201. code >= 97 && code <= 102; // 'a'-'f'
  28202. }
  28203. function decrypt(data, key, discardNumber) {
  28204. var r = key | 0, c1 = 52845, c2 = 22719;
  28205. var count = data.length;
  28206. var decrypted = new Uint8Array(count);
  28207. for (var i = 0; i < count; i++) {
  28208. var value = data[i];
  28209. decrypted[i] = value ^ (r >> 8);
  28210. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  28211. }
  28212. return Array.prototype.slice.call(decrypted, discardNumber);
  28213. }
  28214. function decryptAscii(data, key, discardNumber) {
  28215. var r = key | 0, c1 = 52845, c2 = 22719;
  28216. var count = data.length, maybeLength = count >>> 1;
  28217. var decrypted = new Uint8Array(maybeLength);
  28218. var i, j;
  28219. for (i = 0, j = 0; i < count; i++) {
  28220. var digit1 = data[i];
  28221. if (!isHexDigit(digit1)) {
  28222. continue;
  28223. }
  28224. i++;
  28225. var digit2;
  28226. while (i < count && !isHexDigit(digit2 = data[i])) {
  28227. i++;
  28228. }
  28229. if (i < count) {
  28230. var value = parseInt(String.fromCharCode(digit1, digit2), 16);
  28231. decrypted[j++] = value ^ (r >> 8);
  28232. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  28233. }
  28234. }
  28235. return Array.prototype.slice.call(decrypted, discardNumber, j);
  28236. }
  28237. function isSpecial(c) {
  28238. return c === 0x2F || // '/'
  28239. c === 0x5B || c === 0x5D || // '[', ']'
  28240. c === 0x7B || c === 0x7D || // '{', '}'
  28241. c === 0x28 || c === 0x29; // '(', ')'
  28242. }
  28243. function Type1Parser(stream, encrypted) {
  28244. if (encrypted) {
  28245. var data = stream.getBytes();
  28246. var isBinary = !(isHexDigit(data[0]) && isHexDigit(data[1]) &&
  28247. isHexDigit(data[2]) && isHexDigit(data[3]));
  28248. stream = new Stream(isBinary ? decrypt(data, EEXEC_ENCRYPT_KEY, 4) :
  28249. decryptAscii(data, EEXEC_ENCRYPT_KEY, 4));
  28250. }
  28251. this.stream = stream;
  28252. this.nextChar();
  28253. }
  28254. Type1Parser.prototype = {
  28255. readNumberArray: function Type1Parser_readNumberArray() {
  28256. this.getToken(); // read '[' or '{' (arrays can start with either)
  28257. var array = [];
  28258. while (true) {
  28259. var token = this.getToken();
  28260. if (token === null || token === ']' || token === '}') {
  28261. break;
  28262. }
  28263. array.push(parseFloat(token || 0));
  28264. }
  28265. return array;
  28266. },
  28267. readNumber: function Type1Parser_readNumber() {
  28268. var token = this.getToken();
  28269. return parseFloat(token || 0);
  28270. },
  28271. readInt: function Type1Parser_readInt() {
  28272. // Use '| 0' to prevent setting a double into length such as the double
  28273. // does not flow into the loop variable.
  28274. var token = this.getToken();
  28275. return parseInt(token || 0, 10) | 0;
  28276. },
  28277. readBoolean: function Type1Parser_readBoolean() {
  28278. var token = this.getToken();
  28279. // Use 1 and 0 since that's what type2 charstrings use.
  28280. return token === 'true' ? 1 : 0;
  28281. },
  28282. nextChar : function Type1_nextChar() {
  28283. return (this.currentChar = this.stream.getByte());
  28284. },
  28285. getToken: function Type1Parser_getToken() {
  28286. // Eat whitespace and comments.
  28287. var comment = false;
  28288. var ch = this.currentChar;
  28289. while (true) {
  28290. if (ch === -1) {
  28291. return null;
  28292. }
  28293. if (comment) {
  28294. if (ch === 0x0A || ch === 0x0D) {
  28295. comment = false;
  28296. }
  28297. } else if (ch === 0x25) { // '%'
  28298. comment = true;
  28299. } else if (!Lexer.isSpace(ch)) {
  28300. break;
  28301. }
  28302. ch = this.nextChar();
  28303. }
  28304. if (isSpecial(ch)) {
  28305. this.nextChar();
  28306. return String.fromCharCode(ch);
  28307. }
  28308. var token = '';
  28309. do {
  28310. token += String.fromCharCode(ch);
  28311. ch = this.nextChar();
  28312. } while (ch >= 0 && !Lexer.isSpace(ch) && !isSpecial(ch));
  28313. return token;
  28314. },
  28315. /*
  28316. * Returns an object containing a Subrs array and a CharStrings
  28317. * array extracted from and eexec encrypted block of data
  28318. */
  28319. extractFontProgram: function Type1Parser_extractFontProgram() {
  28320. var stream = this.stream;
  28321. var subrs = [], charstrings = [];
  28322. var program = {
  28323. subrs: [],
  28324. charstrings: [],
  28325. properties: {
  28326. 'privateData': {
  28327. 'lenIV': 4
  28328. }
  28329. }
  28330. };
  28331. var token, length, data, lenIV, encoded;
  28332. while ((token = this.getToken()) !== null) {
  28333. if (token !== '/') {
  28334. continue;
  28335. }
  28336. token = this.getToken();
  28337. switch (token) {
  28338. case 'CharStrings':
  28339. // The number immediately following CharStrings must be greater or
  28340. // equal to the number of CharStrings.
  28341. this.getToken();
  28342. this.getToken(); // read in 'dict'
  28343. this.getToken(); // read in 'dup'
  28344. this.getToken(); // read in 'begin'
  28345. while(true) {
  28346. token = this.getToken();
  28347. if (token === null || token === 'end') {
  28348. break;
  28349. }
  28350. if (token !== '/') {
  28351. continue;
  28352. }
  28353. var glyph = this.getToken();
  28354. length = this.readInt();
  28355. this.getToken(); // read in 'RD' or '-|'
  28356. data = stream.makeSubStream(stream.pos, length);
  28357. lenIV = program.properties.privateData['lenIV'];
  28358. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  28359. // Skip past the required space and binary data.
  28360. stream.skip(length);
  28361. this.nextChar();
  28362. token = this.getToken(); // read in 'ND' or '|-'
  28363. if (token === 'noaccess') {
  28364. this.getToken(); // read in 'def'
  28365. }
  28366. charstrings.push({
  28367. glyph: glyph,
  28368. encoded: encoded
  28369. });
  28370. }
  28371. break;
  28372. case 'Subrs':
  28373. var num = this.readInt();
  28374. this.getToken(); // read in 'array'
  28375. while ((token = this.getToken()) === 'dup') {
  28376. var index = this.readInt();
  28377. length = this.readInt();
  28378. this.getToken(); // read in 'RD' or '-|'
  28379. data = stream.makeSubStream(stream.pos, length);
  28380. lenIV = program.properties.privateData['lenIV'];
  28381. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  28382. // Skip past the required space and binary data.
  28383. stream.skip(length);
  28384. this.nextChar();
  28385. token = this.getToken(); // read in 'NP' or '|'
  28386. if (token === 'noaccess') {
  28387. this.getToken(); // read in 'put'
  28388. }
  28389. subrs[index] = encoded;
  28390. }
  28391. break;
  28392. case 'BlueValues':
  28393. case 'OtherBlues':
  28394. case 'FamilyBlues':
  28395. case 'FamilyOtherBlues':
  28396. var blueArray = this.readNumberArray();
  28397. // *Blue* values may contain invalid data: disables reading of
  28398. // those values when hinting is disabled.
  28399. if (blueArray.length > 0 && (blueArray.length % 2) === 0 &&
  28400. HINTING_ENABLED) {
  28401. program.properties.privateData[token] = blueArray;
  28402. }
  28403. break;
  28404. case 'StemSnapH':
  28405. case 'StemSnapV':
  28406. program.properties.privateData[token] = this.readNumberArray();
  28407. break;
  28408. case 'StdHW':
  28409. case 'StdVW':
  28410. program.properties.privateData[token] =
  28411. this.readNumberArray()[0];
  28412. break;
  28413. case 'BlueShift':
  28414. case 'lenIV':
  28415. case 'BlueFuzz':
  28416. case 'BlueScale':
  28417. case 'LanguageGroup':
  28418. case 'ExpansionFactor':
  28419. program.properties.privateData[token] = this.readNumber();
  28420. break;
  28421. case 'ForceBold':
  28422. program.properties.privateData[token] = this.readBoolean();
  28423. break;
  28424. }
  28425. }
  28426. for (var i = 0; i < charstrings.length; i++) {
  28427. glyph = charstrings[i].glyph;
  28428. encoded = charstrings[i].encoded;
  28429. var charString = new Type1CharString();
  28430. var error = charString.convert(encoded, subrs);
  28431. var output = charString.output;
  28432. if (error) {
  28433. // It seems when FreeType encounters an error while evaluating a glyph
  28434. // that it completely ignores the glyph so we'll mimic that behaviour
  28435. // here and put an endchar to make the validator happy.
  28436. output = [14];
  28437. }
  28438. program.charstrings.push({
  28439. glyphName: glyph,
  28440. charstring: output,
  28441. width: charString.width,
  28442. lsb: charString.lsb,
  28443. seac: charString.seac
  28444. });
  28445. }
  28446. return program;
  28447. },
  28448. extractFontHeader: function Type1Parser_extractFontHeader(properties) {
  28449. var token;
  28450. while ((token = this.getToken()) !== null) {
  28451. if (token !== '/') {
  28452. continue;
  28453. }
  28454. token = this.getToken();
  28455. switch (token) {
  28456. case 'FontMatrix':
  28457. var matrix = this.readNumberArray();
  28458. properties.fontMatrix = matrix;
  28459. break;
  28460. case 'Encoding':
  28461. var encodingArg = this.getToken();
  28462. var encoding;
  28463. if (!/^\d+$/.test(encodingArg)) {
  28464. // encoding name is specified
  28465. encoding = Encodings[encodingArg];
  28466. } else {
  28467. encoding = [];
  28468. var size = parseInt(encodingArg, 10) | 0;
  28469. this.getToken(); // read in 'array'
  28470. for (var j = 0; j < size; j++) {
  28471. token = this.getToken();
  28472. // skipping till first dup or def (e.g. ignoring for statement)
  28473. while (token !== 'dup' && token !== 'def') {
  28474. token = this.getToken();
  28475. if (token === null) {
  28476. return; // invalid header
  28477. }
  28478. }
  28479. if (token === 'def') {
  28480. break; // read all array data
  28481. }
  28482. var index = this.readInt();
  28483. this.getToken(); // read in '/'
  28484. var glyph = this.getToken();
  28485. encoding[index] = glyph;
  28486. this.getToken(); // read the in 'put'
  28487. }
  28488. }
  28489. properties.builtInEncoding = encoding;
  28490. break;
  28491. case 'FontBBox':
  28492. var fontBBox = this.readNumberArray();
  28493. // adjusting ascent/descent
  28494. properties.ascent = fontBBox[3];
  28495. properties.descent = fontBBox[1];
  28496. properties.ascentScaled = true;
  28497. break;
  28498. }
  28499. }
  28500. }
  28501. };
  28502. return Type1Parser;
  28503. })();
  28504. /**
  28505. * The CFF class takes a Type1 file and wrap it into a
  28506. * 'Compact Font Format' which itself embed Type2 charstrings.
  28507. */
  28508. var CFFStandardStrings = [
  28509. '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  28510. 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus',
  28511. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
  28512. 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',
  28513. 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
  28514. 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
  28515. 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright', 'asciicircum',
  28516. 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
  28517. 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
  28518. 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
  28519. 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  28520. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  28521. 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
  28522. 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase', 'quotedblbase',
  28523. 'quotedblright', 'guillemotright', 'ellipsis', 'perthousand', 'questiondown',
  28524. 'grave', 'acute', 'circumflex', 'tilde', 'macron', 'breve', 'dotaccent',
  28525. 'dieresis', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron', 'emdash',
  28526. 'AE', 'ordfeminine', 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae',
  28527. 'dotlessi', 'lslash', 'oslash', 'oe', 'germandbls', 'onesuperior',
  28528. 'logicalnot', 'mu', 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn',
  28529. 'onequarter', 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters',
  28530. 'twosuperior', 'registered', 'minus', 'eth', 'multiply', 'threesuperior',
  28531. 'copyright', 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring',
  28532. 'Atilde', 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave',
  28533. 'Iacute', 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute',
  28534. 'Ocircumflex', 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute',
  28535. 'Ucircumflex', 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron',
  28536. 'aacute', 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde',
  28537. 'ccedilla', 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute',
  28538. 'icircumflex', 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex',
  28539. 'odieresis', 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex',
  28540. 'udieresis', 'ugrave', 'yacute', 'ydieresis', 'zcaron', 'exclamsmall',
  28541. 'Hungarumlautsmall', 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall',
  28542. 'Acutesmall', 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  28543. 'onedotenleader', 'zerooldstyle', 'oneoldstyle', 'twooldstyle',
  28544. 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle',
  28545. 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'commasuperior',
  28546. 'threequartersemdash', 'periodsuperior', 'questionsmall', 'asuperior',
  28547. 'bsuperior', 'centsuperior', 'dsuperior', 'esuperior', 'isuperior',
  28548. 'lsuperior', 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  28549. 'tsuperior', 'ff', 'ffi', 'ffl', 'parenleftinferior', 'parenrightinferior',
  28550. 'Circumflexsmall', 'hyphensuperior', 'Gravesmall', 'Asmall', 'Bsmall',
  28551. 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall',
  28552. 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall',
  28553. 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
  28554. 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah',
  28555. 'Tildesmall', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall',
  28556. 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall', 'Caronsmall',
  28557. 'Dotaccentsmall', 'Macronsmall', 'figuredash', 'hypheninferior',
  28558. 'Ogoneksmall', 'Ringsmall', 'Cedillasmall', 'questiondownsmall', 'oneeighth',
  28559. 'threeeighths', 'fiveeighths', 'seveneighths', 'onethird', 'twothirds',
  28560. 'zerosuperior', 'foursuperior', 'fivesuperior', 'sixsuperior',
  28561. 'sevensuperior', 'eightsuperior', 'ninesuperior', 'zeroinferior',
  28562. 'oneinferior', 'twoinferior', 'threeinferior', 'fourinferior',
  28563. 'fiveinferior', 'sixinferior', 'seveninferior', 'eightinferior',
  28564. 'nineinferior', 'centinferior', 'dollarinferior', 'periodinferior',
  28565. 'commainferior', 'Agravesmall', 'Aacutesmall', 'Acircumflexsmall',
  28566. 'Atildesmall', 'Adieresissmall', 'Aringsmall', 'AEsmall', 'Ccedillasmall',
  28567. 'Egravesmall', 'Eacutesmall', 'Ecircumflexsmall', 'Edieresissmall',
  28568. 'Igravesmall', 'Iacutesmall', 'Icircumflexsmall', 'Idieresissmall',
  28569. 'Ethsmall', 'Ntildesmall', 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall',
  28570. 'Otildesmall', 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall',
  28571. 'Uacutesmall', 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall',
  28572. 'Thornsmall', 'Ydieresissmall', '001.000', '001.001', '001.002', '001.003',
  28573. 'Black', 'Bold', 'Book', 'Light', 'Medium', 'Regular', 'Roman', 'Semibold'
  28574. ];
  28575. // Type1Font is also a CIDFontType0.
  28576. var Type1Font = function Type1Font(name, file, properties) {
  28577. // Some bad generators embed pfb file as is, we have to strip 6-byte headers.
  28578. // Also, length1 and length2 might be off by 6 bytes as well.
  28579. // http://www.math.ubc.ca/~cass/piscript/type1.pdf
  28580. var PFB_HEADER_SIZE = 6;
  28581. var headerBlockLength = properties.length1;
  28582. var eexecBlockLength = properties.length2;
  28583. var pfbHeader = file.peekBytes(PFB_HEADER_SIZE);
  28584. var pfbHeaderPresent = pfbHeader[0] === 0x80 && pfbHeader[1] === 0x01;
  28585. if (pfbHeaderPresent) {
  28586. file.skip(PFB_HEADER_SIZE);
  28587. headerBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  28588. (pfbHeader[3] << 8) | pfbHeader[2];
  28589. }
  28590. // Get the data block containing glyphs and subrs informations
  28591. var headerBlock = new Stream(file.getBytes(headerBlockLength));
  28592. var headerBlockParser = new Type1Parser(headerBlock);
  28593. headerBlockParser.extractFontHeader(properties);
  28594. if (pfbHeaderPresent) {
  28595. pfbHeader = file.getBytes(PFB_HEADER_SIZE);
  28596. eexecBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  28597. (pfbHeader[3] << 8) | pfbHeader[2];
  28598. }
  28599. // Decrypt the data blocks and retrieve it's content
  28600. var eexecBlock = new Stream(file.getBytes(eexecBlockLength));
  28601. var eexecBlockParser = new Type1Parser(eexecBlock, true);
  28602. var data = eexecBlockParser.extractFontProgram();
  28603. for (var info in data.properties) {
  28604. properties[info] = data.properties[info];
  28605. }
  28606. var charstrings = data.charstrings;
  28607. var type2Charstrings = this.getType2Charstrings(charstrings);
  28608. var subrs = this.getType2Subrs(data.subrs);
  28609. this.charstrings = charstrings;
  28610. this.data = this.wrap(name, type2Charstrings, this.charstrings,
  28611. subrs, properties);
  28612. this.seacs = this.getSeacs(data.charstrings);
  28613. };
  28614. Type1Font.prototype = {
  28615. get numGlyphs() {
  28616. return this.charstrings.length + 1;
  28617. },
  28618. getCharset: function Type1Font_getCharset() {
  28619. var charset = ['.notdef'];
  28620. var charstrings = this.charstrings;
  28621. for (var glyphId = 0; glyphId < charstrings.length; glyphId++) {
  28622. charset.push(charstrings[glyphId].glyphName);
  28623. }
  28624. return charset;
  28625. },
  28626. getGlyphMapping: function Type1Font_getGlyphMapping(properties) {
  28627. var charstrings = this.charstrings;
  28628. var glyphNames = ['.notdef'], glyphId;
  28629. for (glyphId = 0; glyphId < charstrings.length; glyphId++) {
  28630. glyphNames.push(charstrings[glyphId].glyphName);
  28631. }
  28632. var encoding = properties.builtInEncoding;
  28633. if (encoding) {
  28634. var builtInEncoding = {};
  28635. for (var charCode in encoding) {
  28636. glyphId = glyphNames.indexOf(encoding[charCode]);
  28637. if (glyphId >= 0) {
  28638. builtInEncoding[charCode] = glyphId;
  28639. }
  28640. }
  28641. }
  28642. return type1FontGlyphMapping(properties, builtInEncoding, glyphNames);
  28643. },
  28644. getSeacs: function Type1Font_getSeacs(charstrings) {
  28645. var i, ii;
  28646. var seacMap = [];
  28647. for (i = 0, ii = charstrings.length; i < ii; i++) {
  28648. var charstring = charstrings[i];
  28649. if (charstring.seac) {
  28650. // Offset by 1 for .notdef
  28651. seacMap[i + 1] = charstring.seac;
  28652. }
  28653. }
  28654. return seacMap;
  28655. },
  28656. getType2Charstrings: function Type1Font_getType2Charstrings(
  28657. type1Charstrings) {
  28658. var type2Charstrings = [];
  28659. for (var i = 0, ii = type1Charstrings.length; i < ii; i++) {
  28660. type2Charstrings.push(type1Charstrings[i].charstring);
  28661. }
  28662. return type2Charstrings;
  28663. },
  28664. getType2Subrs: function Type1Font_getType2Subrs(type1Subrs) {
  28665. var bias = 0;
  28666. var count = type1Subrs.length;
  28667. if (count < 1133) {
  28668. bias = 107;
  28669. } else if (count < 33769) {
  28670. bias = 1131;
  28671. } else {
  28672. bias = 32768;
  28673. }
  28674. // Add a bunch of empty subrs to deal with the Type2 bias
  28675. var type2Subrs = [];
  28676. var i;
  28677. for (i = 0; i < bias; i++) {
  28678. type2Subrs.push([0x0B]);
  28679. }
  28680. for (i = 0; i < count; i++) {
  28681. type2Subrs.push(type1Subrs[i]);
  28682. }
  28683. return type2Subrs;
  28684. },
  28685. wrap: function Type1Font_wrap(name, glyphs, charstrings, subrs, properties) {
  28686. var cff = new CFF();
  28687. cff.header = new CFFHeader(1, 0, 4, 4);
  28688. cff.names = [name];
  28689. var topDict = new CFFTopDict();
  28690. // CFF strings IDs 0...390 are predefined names, so refering
  28691. // to entries in our own String INDEX starts at SID 391.
  28692. topDict.setByName('version', 391);
  28693. topDict.setByName('Notice', 392);
  28694. topDict.setByName('FullName', 393);
  28695. topDict.setByName('FamilyName', 394);
  28696. topDict.setByName('Weight', 395);
  28697. topDict.setByName('Encoding', null); // placeholder
  28698. topDict.setByName('FontMatrix', properties.fontMatrix);
  28699. topDict.setByName('FontBBox', properties.bbox);
  28700. topDict.setByName('charset', null); // placeholder
  28701. topDict.setByName('CharStrings', null); // placeholder
  28702. topDict.setByName('Private', null); // placeholder
  28703. cff.topDict = topDict;
  28704. var strings = new CFFStrings();
  28705. strings.add('Version 0.11'); // Version
  28706. strings.add('See original notice'); // Notice
  28707. strings.add(name); // FullName
  28708. strings.add(name); // FamilyName
  28709. strings.add('Medium'); // Weight
  28710. cff.strings = strings;
  28711. cff.globalSubrIndex = new CFFIndex();
  28712. var count = glyphs.length;
  28713. var charsetArray = [0];
  28714. var i, ii;
  28715. for (i = 0; i < count; i++) {
  28716. var index = CFFStandardStrings.indexOf(charstrings[i].glyphName);
  28717. // TODO: Insert the string and correctly map it. Previously it was
  28718. // thought mapping names that aren't in the standard strings to .notdef
  28719. // was fine, however in issue818 when mapping them all to .notdef the
  28720. // adieresis glyph no longer worked.
  28721. if (index === -1) {
  28722. index = 0;
  28723. }
  28724. charsetArray.push((index >> 8) & 0xff, index & 0xff);
  28725. }
  28726. cff.charset = new CFFCharset(false, 0, [], charsetArray);
  28727. var charStringsIndex = new CFFIndex();
  28728. charStringsIndex.add([0x8B, 0x0E]); // .notdef
  28729. for (i = 0; i < count; i++) {
  28730. charStringsIndex.add(glyphs[i]);
  28731. }
  28732. cff.charStrings = charStringsIndex;
  28733. var privateDict = new CFFPrivateDict();
  28734. privateDict.setByName('Subrs', null); // placeholder
  28735. var fields = [
  28736. 'BlueValues',
  28737. 'OtherBlues',
  28738. 'FamilyBlues',
  28739. 'FamilyOtherBlues',
  28740. 'StemSnapH',
  28741. 'StemSnapV',
  28742. 'BlueShift',
  28743. 'BlueFuzz',
  28744. 'BlueScale',
  28745. 'LanguageGroup',
  28746. 'ExpansionFactor',
  28747. 'ForceBold',
  28748. 'StdHW',
  28749. 'StdVW'
  28750. ];
  28751. for (i = 0, ii = fields.length; i < ii; i++) {
  28752. var field = fields[i];
  28753. if (!properties.privateData.hasOwnProperty(field)) {
  28754. continue;
  28755. }
  28756. var value = properties.privateData[field];
  28757. if (isArray(value)) {
  28758. // All of the private dictionary array data in CFF must be stored as
  28759. // "delta-encoded" numbers.
  28760. for (var j = value.length - 1; j > 0; j--) {
  28761. value[j] -= value[j - 1]; // ... difference from previous value
  28762. }
  28763. }
  28764. privateDict.setByName(field, value);
  28765. }
  28766. cff.topDict.privateDict = privateDict;
  28767. var subrIndex = new CFFIndex();
  28768. for (i = 0, ii = subrs.length; i < ii; i++) {
  28769. subrIndex.add(subrs[i]);
  28770. }
  28771. privateDict.subrsIndex = subrIndex;
  28772. var compiler = new CFFCompiler(cff);
  28773. return compiler.compile();
  28774. }
  28775. };
  28776. var CFFFont = (function CFFFontClosure() {
  28777. function CFFFont(file, properties) {
  28778. this.properties = properties;
  28779. var parser = new CFFParser(file, properties);
  28780. this.cff = parser.parse();
  28781. var compiler = new CFFCompiler(this.cff);
  28782. this.seacs = this.cff.seacs;
  28783. try {
  28784. this.data = compiler.compile();
  28785. } catch (e) {
  28786. warn('Failed to compile font ' + properties.loadedName);
  28787. // There may have just been an issue with the compiler, set the data
  28788. // anyway and hope the font loaded.
  28789. this.data = file;
  28790. }
  28791. }
  28792. CFFFont.prototype = {
  28793. get numGlyphs() {
  28794. return this.cff.charStrings.count;
  28795. },
  28796. getCharset: function CFFFont_getCharset() {
  28797. return this.cff.charset.charset;
  28798. },
  28799. getGlyphMapping: function CFFFont_getGlyphMapping() {
  28800. var cff = this.cff;
  28801. var properties = this.properties;
  28802. var charsets = cff.charset.charset;
  28803. var charCodeToGlyphId;
  28804. var glyphId;
  28805. if (properties.composite) {
  28806. charCodeToGlyphId = Object.create(null);
  28807. if (cff.isCIDFont) {
  28808. // If the font is actually a CID font then we should use the charset
  28809. // to map CIDs to GIDs.
  28810. for (glyphId = 0; glyphId < charsets.length; glyphId++) {
  28811. var cid = charsets[glyphId];
  28812. var charCode = properties.cMap.charCodeOf(cid);
  28813. charCodeToGlyphId[charCode] = glyphId;
  28814. }
  28815. } else {
  28816. // If it is NOT actually a CID font then CIDs should be mapped
  28817. // directly to GIDs.
  28818. for (glyphId = 0; glyphId < cff.charStrings.count; glyphId++) {
  28819. charCodeToGlyphId[glyphId] = glyphId;
  28820. }
  28821. }
  28822. return charCodeToGlyphId;
  28823. }
  28824. var encoding = cff.encoding ? cff.encoding.encoding : null;
  28825. charCodeToGlyphId = type1FontGlyphMapping(properties, encoding, charsets);
  28826. return charCodeToGlyphId;
  28827. }
  28828. };
  28829. return CFFFont;
  28830. })();
  28831. var CFFParser = (function CFFParserClosure() {
  28832. var CharstringValidationData = [
  28833. null,
  28834. { id: 'hstem', min: 2, stackClearing: true, stem: true },
  28835. null,
  28836. { id: 'vstem', min: 2, stackClearing: true, stem: true },
  28837. { id: 'vmoveto', min: 1, stackClearing: true },
  28838. { id: 'rlineto', min: 2, resetStack: true },
  28839. { id: 'hlineto', min: 1, resetStack: true },
  28840. { id: 'vlineto', min: 1, resetStack: true },
  28841. { id: 'rrcurveto', min: 6, resetStack: true },
  28842. null,
  28843. { id: 'callsubr', min: 1, undefStack: true },
  28844. { id: 'return', min: 0, undefStack: true },
  28845. null, // 12
  28846. null,
  28847. { id: 'endchar', min: 0, stackClearing: true },
  28848. null,
  28849. null,
  28850. null,
  28851. { id: 'hstemhm', min: 2, stackClearing: true, stem: true },
  28852. { id: 'hintmask', min: 0, stackClearing: true },
  28853. { id: 'cntrmask', min: 0, stackClearing: true },
  28854. { id: 'rmoveto', min: 2, stackClearing: true },
  28855. { id: 'hmoveto', min: 1, stackClearing: true },
  28856. { id: 'vstemhm', min: 2, stackClearing: true, stem: true },
  28857. { id: 'rcurveline', min: 8, resetStack: true },
  28858. { id: 'rlinecurve', min: 8, resetStack: true },
  28859. { id: 'vvcurveto', min: 4, resetStack: true },
  28860. { id: 'hhcurveto', min: 4, resetStack: true },
  28861. null, // shortint
  28862. { id: 'callgsubr', min: 1, undefStack: true },
  28863. { id: 'vhcurveto', min: 4, resetStack: true },
  28864. { id: 'hvcurveto', min: 4, resetStack: true }
  28865. ];
  28866. var CharstringValidationData12 = [
  28867. null,
  28868. null,
  28869. null,
  28870. { id: 'and', min: 2, stackDelta: -1 },
  28871. { id: 'or', min: 2, stackDelta: -1 },
  28872. { id: 'not', min: 1, stackDelta: 0 },
  28873. null,
  28874. null,
  28875. null,
  28876. { id: 'abs', min: 1, stackDelta: 0 },
  28877. { id: 'add', min: 2, stackDelta: -1,
  28878. stackFn: function stack_div(stack, index) {
  28879. stack[index - 2] = stack[index - 2] + stack[index - 1];
  28880. }
  28881. },
  28882. { id: 'sub', min: 2, stackDelta: -1,
  28883. stackFn: function stack_div(stack, index) {
  28884. stack[index - 2] = stack[index - 2] - stack[index - 1];
  28885. }
  28886. },
  28887. { id: 'div', min: 2, stackDelta: -1,
  28888. stackFn: function stack_div(stack, index) {
  28889. stack[index - 2] = stack[index - 2] / stack[index - 1];
  28890. }
  28891. },
  28892. null,
  28893. { id: 'neg', min: 1, stackDelta: 0,
  28894. stackFn: function stack_div(stack, index) {
  28895. stack[index - 1] = -stack[index - 1];
  28896. }
  28897. },
  28898. { id: 'eq', min: 2, stackDelta: -1 },
  28899. null,
  28900. null,
  28901. { id: 'drop', min: 1, stackDelta: -1 },
  28902. null,
  28903. { id: 'put', min: 2, stackDelta: -2 },
  28904. { id: 'get', min: 1, stackDelta: 0 },
  28905. { id: 'ifelse', min: 4, stackDelta: -3 },
  28906. { id: 'random', min: 0, stackDelta: 1 },
  28907. { id: 'mul', min: 2, stackDelta: -1,
  28908. stackFn: function stack_div(stack, index) {
  28909. stack[index - 2] = stack[index - 2] * stack[index - 1];
  28910. }
  28911. },
  28912. null,
  28913. { id: 'sqrt', min: 1, stackDelta: 0 },
  28914. { id: 'dup', min: 1, stackDelta: 1 },
  28915. { id: 'exch', min: 2, stackDelta: 0 },
  28916. { id: 'index', min: 2, stackDelta: 0 },
  28917. { id: 'roll', min: 3, stackDelta: -2 },
  28918. null,
  28919. null,
  28920. null,
  28921. { id: 'hflex', min: 7, resetStack: true },
  28922. { id: 'flex', min: 13, resetStack: true },
  28923. { id: 'hflex1', min: 9, resetStack: true },
  28924. { id: 'flex1', min: 11, resetStack: true }
  28925. ];
  28926. function CFFParser(file, properties) {
  28927. this.bytes = file.getBytes();
  28928. this.properties = properties;
  28929. }
  28930. CFFParser.prototype = {
  28931. parse: function CFFParser_parse() {
  28932. var properties = this.properties;
  28933. var cff = new CFF();
  28934. this.cff = cff;
  28935. // The first five sections must be in order, all the others are reached
  28936. // via offsets contained in one of the below.
  28937. var header = this.parseHeader();
  28938. var nameIndex = this.parseIndex(header.endPos);
  28939. var topDictIndex = this.parseIndex(nameIndex.endPos);
  28940. var stringIndex = this.parseIndex(topDictIndex.endPos);
  28941. var globalSubrIndex = this.parseIndex(stringIndex.endPos);
  28942. var topDictParsed = this.parseDict(topDictIndex.obj.get(0));
  28943. var topDict = this.createDict(CFFTopDict, topDictParsed, cff.strings);
  28944. cff.header = header.obj;
  28945. cff.names = this.parseNameIndex(nameIndex.obj);
  28946. cff.strings = this.parseStringIndex(stringIndex.obj);
  28947. cff.topDict = topDict;
  28948. cff.globalSubrIndex = globalSubrIndex.obj;
  28949. this.parsePrivateDict(cff.topDict);
  28950. cff.isCIDFont = topDict.hasName('ROS');
  28951. var charStringOffset = topDict.getByName('CharStrings');
  28952. var charStringIndex = this.parseIndex(charStringOffset).obj;
  28953. var fontMatrix = topDict.getByName('FontMatrix');
  28954. if (fontMatrix) {
  28955. properties.fontMatrix = fontMatrix;
  28956. }
  28957. var fontBBox = topDict.getByName('FontBBox');
  28958. if (fontBBox) {
  28959. // adjusting ascent/descent
  28960. properties.ascent = fontBBox[3];
  28961. properties.descent = fontBBox[1];
  28962. properties.ascentScaled = true;
  28963. }
  28964. var charset, encoding;
  28965. if (cff.isCIDFont) {
  28966. var fdArrayIndex = this.parseIndex(topDict.getByName('FDArray')).obj;
  28967. for (var i = 0, ii = fdArrayIndex.count; i < ii; ++i) {
  28968. var dictRaw = fdArrayIndex.get(i);
  28969. var fontDict = this.createDict(CFFTopDict, this.parseDict(dictRaw),
  28970. cff.strings);
  28971. this.parsePrivateDict(fontDict);
  28972. cff.fdArray.push(fontDict);
  28973. }
  28974. // cid fonts don't have an encoding
  28975. encoding = null;
  28976. charset = this.parseCharsets(topDict.getByName('charset'),
  28977. charStringIndex.count, cff.strings, true);
  28978. cff.fdSelect = this.parseFDSelect(topDict.getByName('FDSelect'),
  28979. charStringIndex.count);
  28980. } else {
  28981. charset = this.parseCharsets(topDict.getByName('charset'),
  28982. charStringIndex.count, cff.strings, false);
  28983. encoding = this.parseEncoding(topDict.getByName('Encoding'),
  28984. properties,
  28985. cff.strings, charset.charset);
  28986. }
  28987. cff.charset = charset;
  28988. cff.encoding = encoding;
  28989. var charStringsAndSeacs = this.parseCharStrings(
  28990. charStringIndex,
  28991. topDict.privateDict.subrsIndex,
  28992. globalSubrIndex.obj,
  28993. cff.fdSelect,
  28994. cff.fdArray);
  28995. cff.charStrings = charStringsAndSeacs.charStrings;
  28996. cff.seacs = charStringsAndSeacs.seacs;
  28997. cff.widths = charStringsAndSeacs.widths;
  28998. return cff;
  28999. },
  29000. parseHeader: function CFFParser_parseHeader() {
  29001. var bytes = this.bytes;
  29002. var bytesLength = bytes.length;
  29003. var offset = 0;
  29004. // Prevent an infinite loop, by checking that the offset is within the
  29005. // bounds of the bytes array. Necessary in empty, or invalid, font files.
  29006. while (offset < bytesLength && bytes[offset] !== 1) {
  29007. ++offset;
  29008. }
  29009. if (offset >= bytesLength) {
  29010. error('Invalid CFF header');
  29011. } else if (offset !== 0) {
  29012. info('cff data is shifted');
  29013. bytes = bytes.subarray(offset);
  29014. this.bytes = bytes;
  29015. }
  29016. var major = bytes[0];
  29017. var minor = bytes[1];
  29018. var hdrSize = bytes[2];
  29019. var offSize = bytes[3];
  29020. var header = new CFFHeader(major, minor, hdrSize, offSize);
  29021. return { obj: header, endPos: hdrSize };
  29022. },
  29023. parseDict: function CFFParser_parseDict(dict) {
  29024. var pos = 0;
  29025. function parseOperand() {
  29026. var value = dict[pos++];
  29027. if (value === 30) {
  29028. return parseFloatOperand(pos);
  29029. } else if (value === 28) {
  29030. value = dict[pos++];
  29031. value = ((value << 24) | (dict[pos++] << 16)) >> 16;
  29032. return value;
  29033. } else if (value === 29) {
  29034. value = dict[pos++];
  29035. value = (value << 8) | dict[pos++];
  29036. value = (value << 8) | dict[pos++];
  29037. value = (value << 8) | dict[pos++];
  29038. return value;
  29039. } else if (value >= 32 && value <= 246) {
  29040. return value - 139;
  29041. } else if (value >= 247 && value <= 250) {
  29042. return ((value - 247) * 256) + dict[pos++] + 108;
  29043. } else if (value >= 251 && value <= 254) {
  29044. return -((value - 251) * 256) - dict[pos++] - 108;
  29045. } else {
  29046. error('255 is not a valid DICT command');
  29047. }
  29048. return -1;
  29049. }
  29050. function parseFloatOperand() {
  29051. var str = '';
  29052. var eof = 15;
  29053. var lookup = ['0', '1', '2', '3', '4', '5', '6', '7', '8',
  29054. '9', '.', 'E', 'E-', null, '-'];
  29055. var length = dict.length;
  29056. while (pos < length) {
  29057. var b = dict[pos++];
  29058. var b1 = b >> 4;
  29059. var b2 = b & 15;
  29060. if (b1 === eof) {
  29061. break;
  29062. }
  29063. str += lookup[b1];
  29064. if (b2 === eof) {
  29065. break;
  29066. }
  29067. str += lookup[b2];
  29068. }
  29069. return parseFloat(str);
  29070. }
  29071. var operands = [];
  29072. var entries = [];
  29073. pos = 0;
  29074. var end = dict.length;
  29075. while (pos < end) {
  29076. var b = dict[pos];
  29077. if (b <= 21) {
  29078. if (b === 12) {
  29079. b = (b << 8) | dict[++pos];
  29080. }
  29081. entries.push([b, operands]);
  29082. operands = [];
  29083. ++pos;
  29084. } else {
  29085. operands.push(parseOperand());
  29086. }
  29087. }
  29088. return entries;
  29089. },
  29090. parseIndex: function CFFParser_parseIndex(pos) {
  29091. var cffIndex = new CFFIndex();
  29092. var bytes = this.bytes;
  29093. var count = (bytes[pos++] << 8) | bytes[pos++];
  29094. var offsets = [];
  29095. var end = pos;
  29096. var i, ii;
  29097. if (count !== 0) {
  29098. var offsetSize = bytes[pos++];
  29099. // add 1 for offset to determine size of last object
  29100. var startPos = pos + ((count + 1) * offsetSize) - 1;
  29101. for (i = 0, ii = count + 1; i < ii; ++i) {
  29102. var offset = 0;
  29103. for (var j = 0; j < offsetSize; ++j) {
  29104. offset <<= 8;
  29105. offset += bytes[pos++];
  29106. }
  29107. offsets.push(startPos + offset);
  29108. }
  29109. end = offsets[count];
  29110. }
  29111. for (i = 0, ii = offsets.length - 1; i < ii; ++i) {
  29112. var offsetStart = offsets[i];
  29113. var offsetEnd = offsets[i + 1];
  29114. cffIndex.add(bytes.subarray(offsetStart, offsetEnd));
  29115. }
  29116. return {obj: cffIndex, endPos: end};
  29117. },
  29118. parseNameIndex: function CFFParser_parseNameIndex(index) {
  29119. var names = [];
  29120. for (var i = 0, ii = index.count; i < ii; ++i) {
  29121. var name = index.get(i);
  29122. // OTS doesn't allow names to be over 127 characters.
  29123. var length = Math.min(name.length, 127);
  29124. var data = [];
  29125. // OTS also only permits certain characters in the name.
  29126. for (var j = 0; j < length; ++j) {
  29127. var c = name[j];
  29128. if (j === 0 && c === 0) {
  29129. data[j] = c;
  29130. continue;
  29131. }
  29132. if ((c < 33 || c > 126) || c === 91 /* [ */ || c === 93 /* ] */ ||
  29133. c === 40 /* ( */ || c === 41 /* ) */ || c === 123 /* { */ ||
  29134. c === 125 /* } */ || c === 60 /* < */ || c === 62 /* > */ ||
  29135. c === 47 /* / */ || c === 37 /* % */ || c === 35 /* # */) {
  29136. data[j] = 95;
  29137. continue;
  29138. }
  29139. data[j] = c;
  29140. }
  29141. names.push(bytesToString(data));
  29142. }
  29143. return names;
  29144. },
  29145. parseStringIndex: function CFFParser_parseStringIndex(index) {
  29146. var strings = new CFFStrings();
  29147. for (var i = 0, ii = index.count; i < ii; ++i) {
  29148. var data = index.get(i);
  29149. strings.add(bytesToString(data));
  29150. }
  29151. return strings;
  29152. },
  29153. createDict: function CFFParser_createDict(Type, dict, strings) {
  29154. var cffDict = new Type(strings);
  29155. for (var i = 0, ii = dict.length; i < ii; ++i) {
  29156. var pair = dict[i];
  29157. var key = pair[0];
  29158. var value = pair[1];
  29159. cffDict.setByKey(key, value);
  29160. }
  29161. return cffDict;
  29162. },
  29163. parseCharString: function CFFParser_parseCharString(state, data,
  29164. localSubrIndex,
  29165. globalSubrIndex) {
  29166. if (state.callDepth > MAX_SUBR_NESTING) {
  29167. return false;
  29168. }
  29169. var stackSize = state.stackSize;
  29170. var stack = state.stack;
  29171. var length = data.length;
  29172. for (var j = 0; j < length;) {
  29173. var value = data[j++];
  29174. var validationCommand = null;
  29175. if (value === 12) {
  29176. var q = data[j++];
  29177. if (q === 0) {
  29178. // The CFF specification state that the 'dotsection' command
  29179. // (12, 0) is deprecated and treated as a no-op, but all Type2
  29180. // charstrings processors should support them. Unfortunately
  29181. // the font sanitizer don't. As a workaround the sequence (12, 0)
  29182. // is replaced by a useless (0, hmoveto).
  29183. data[j - 2] = 139;
  29184. data[j - 1] = 22;
  29185. stackSize = 0;
  29186. } else {
  29187. validationCommand = CharstringValidationData12[q];
  29188. }
  29189. } else if (value === 28) { // number (16 bit)
  29190. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16)) >> 16;
  29191. j += 2;
  29192. stackSize++;
  29193. } else if (value === 14) {
  29194. if (stackSize >= 4) {
  29195. stackSize -= 4;
  29196. if (SEAC_ANALYSIS_ENABLED) {
  29197. state.seac = stack.slice(stackSize, stackSize + 4);
  29198. return false;
  29199. }
  29200. }
  29201. validationCommand = CharstringValidationData[value];
  29202. } else if (value >= 32 && value <= 246) { // number
  29203. stack[stackSize] = value - 139;
  29204. stackSize++;
  29205. } else if (value >= 247 && value <= 254) { // number (+1 bytes)
  29206. stack[stackSize] = (value < 251 ?
  29207. ((value - 247) << 8) + data[j] + 108 :
  29208. -((value - 251) << 8) - data[j] - 108);
  29209. j++;
  29210. stackSize++;
  29211. } else if (value === 255) { // number (32 bit)
  29212. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16) |
  29213. (data[j + 2] << 8) | data[j + 3]) / 65536;
  29214. j += 4;
  29215. stackSize++;
  29216. } else if (value === 19 || value === 20) {
  29217. state.hints += stackSize >> 1;
  29218. // skipping right amount of hints flag data
  29219. j += (state.hints + 7) >> 3;
  29220. stackSize %= 2;
  29221. validationCommand = CharstringValidationData[value];
  29222. } else if (value === 10 || value === 29) {
  29223. var subrsIndex;
  29224. if (value === 10) {
  29225. subrsIndex = localSubrIndex;
  29226. } else {
  29227. subrsIndex = globalSubrIndex;
  29228. }
  29229. if (!subrsIndex) {
  29230. validationCommand = CharstringValidationData[value];
  29231. warn('Missing subrsIndex for ' + validationCommand.id);
  29232. return false;
  29233. }
  29234. var bias = 32768;
  29235. if (subrsIndex.count < 1240) {
  29236. bias = 107;
  29237. } else if (subrsIndex.count < 33900) {
  29238. bias = 1131;
  29239. }
  29240. var subrNumber = stack[--stackSize] + bias;
  29241. if (subrNumber < 0 || subrNumber >= subrsIndex.count) {
  29242. validationCommand = CharstringValidationData[value];
  29243. warn('Out of bounds subrIndex for ' + validationCommand.id);
  29244. return false;
  29245. }
  29246. state.stackSize = stackSize;
  29247. state.callDepth++;
  29248. var valid = this.parseCharString(state, subrsIndex.get(subrNumber),
  29249. localSubrIndex, globalSubrIndex);
  29250. if (!valid) {
  29251. return false;
  29252. }
  29253. state.callDepth--;
  29254. stackSize = state.stackSize;
  29255. continue;
  29256. } else if (value === 11) {
  29257. state.stackSize = stackSize;
  29258. return true;
  29259. } else {
  29260. validationCommand = CharstringValidationData[value];
  29261. }
  29262. if (validationCommand) {
  29263. if (validationCommand.stem) {
  29264. state.hints += stackSize >> 1;
  29265. }
  29266. if ('min' in validationCommand) {
  29267. if (!state.undefStack && stackSize < validationCommand.min) {
  29268. warn('Not enough parameters for ' + validationCommand.id +
  29269. '; actual: ' + stackSize +
  29270. ', expected: ' + validationCommand.min);
  29271. return false;
  29272. }
  29273. }
  29274. if (state.firstStackClearing && validationCommand.stackClearing) {
  29275. state.firstStackClearing = false;
  29276. // the optional character width can be found before the first
  29277. // stack-clearing command arguments
  29278. stackSize -= validationCommand.min;
  29279. if (stackSize >= 2 && validationCommand.stem) {
  29280. // there are even amount of arguments for stem commands
  29281. stackSize %= 2;
  29282. } else if (stackSize > 1) {
  29283. warn('Found too many parameters for stack-clearing command');
  29284. }
  29285. if (stackSize > 0 && stack[stackSize - 1] >= 0) {
  29286. state.width = stack[stackSize - 1];
  29287. }
  29288. }
  29289. if ('stackDelta' in validationCommand) {
  29290. if ('stackFn' in validationCommand) {
  29291. validationCommand.stackFn(stack, stackSize);
  29292. }
  29293. stackSize += validationCommand.stackDelta;
  29294. } else if (validationCommand.stackClearing) {
  29295. stackSize = 0;
  29296. } else if (validationCommand.resetStack) {
  29297. stackSize = 0;
  29298. state.undefStack = false;
  29299. } else if (validationCommand.undefStack) {
  29300. stackSize = 0;
  29301. state.undefStack = true;
  29302. state.firstStackClearing = false;
  29303. }
  29304. }
  29305. }
  29306. state.stackSize = stackSize;
  29307. return true;
  29308. },
  29309. parseCharStrings: function CFFParser_parseCharStrings(charStrings,
  29310. localSubrIndex,
  29311. globalSubrIndex,
  29312. fdSelect,
  29313. fdArray) {
  29314. var seacs = [];
  29315. var widths = [];
  29316. var count = charStrings.count;
  29317. for (var i = 0; i < count; i++) {
  29318. var charstring = charStrings.get(i);
  29319. var state = {
  29320. callDepth: 0,
  29321. stackSize: 0,
  29322. stack: [],
  29323. undefStack: true,
  29324. hints: 0,
  29325. firstStackClearing: true,
  29326. seac: null,
  29327. width: null
  29328. };
  29329. var valid = true;
  29330. var localSubrToUse = null;
  29331. if (fdSelect && fdArray.length) {
  29332. var fdIndex = fdSelect.getFDIndex(i);
  29333. if (fdIndex === -1) {
  29334. warn('Glyph index is not in fd select.');
  29335. valid = false;
  29336. }
  29337. if (fdIndex >= fdArray.length) {
  29338. warn('Invalid fd index for glyph index.');
  29339. valid = false;
  29340. }
  29341. if (valid) {
  29342. localSubrToUse = fdArray[fdIndex].privateDict.subrsIndex;
  29343. }
  29344. } else if (localSubrIndex) {
  29345. localSubrToUse = localSubrIndex;
  29346. }
  29347. if (valid) {
  29348. valid = this.parseCharString(state, charstring, localSubrToUse,
  29349. globalSubrIndex);
  29350. }
  29351. if (state.width !== null) {
  29352. widths[i] = state.width;
  29353. }
  29354. if (state.seac !== null) {
  29355. seacs[i] = state.seac;
  29356. }
  29357. if (!valid) {
  29358. // resetting invalid charstring to single 'endchar'
  29359. charStrings.set(i, new Uint8Array([14]));
  29360. }
  29361. }
  29362. return { charStrings: charStrings, seacs: seacs, widths: widths };
  29363. },
  29364. emptyPrivateDictionary:
  29365. function CFFParser_emptyPrivateDictionary(parentDict) {
  29366. var privateDict = this.createDict(CFFPrivateDict, [],
  29367. parentDict.strings);
  29368. parentDict.setByKey(18, [0, 0]);
  29369. parentDict.privateDict = privateDict;
  29370. },
  29371. parsePrivateDict: function CFFParser_parsePrivateDict(parentDict) {
  29372. // no private dict, do nothing
  29373. if (!parentDict.hasName('Private')) {
  29374. this.emptyPrivateDictionary(parentDict);
  29375. return;
  29376. }
  29377. var privateOffset = parentDict.getByName('Private');
  29378. // make sure the params are formatted correctly
  29379. if (!isArray(privateOffset) || privateOffset.length !== 2) {
  29380. parentDict.removeByName('Private');
  29381. return;
  29382. }
  29383. var size = privateOffset[0];
  29384. var offset = privateOffset[1];
  29385. // remove empty dicts or ones that refer to invalid location
  29386. if (size === 0 || offset >= this.bytes.length) {
  29387. this.emptyPrivateDictionary(parentDict);
  29388. return;
  29389. }
  29390. var privateDictEnd = offset + size;
  29391. var dictData = this.bytes.subarray(offset, privateDictEnd);
  29392. var dict = this.parseDict(dictData);
  29393. var privateDict = this.createDict(CFFPrivateDict, dict,
  29394. parentDict.strings);
  29395. parentDict.privateDict = privateDict;
  29396. // Parse the Subrs index also since it's relative to the private dict.
  29397. if (!privateDict.getByName('Subrs')) {
  29398. return;
  29399. }
  29400. var subrsOffset = privateDict.getByName('Subrs');
  29401. var relativeOffset = offset + subrsOffset;
  29402. // Validate the offset.
  29403. if (subrsOffset === 0 || relativeOffset >= this.bytes.length) {
  29404. this.emptyPrivateDictionary(parentDict);
  29405. return;
  29406. }
  29407. var subrsIndex = this.parseIndex(relativeOffset);
  29408. privateDict.subrsIndex = subrsIndex.obj;
  29409. },
  29410. parseCharsets: function CFFParser_parseCharsets(pos, length, strings, cid) {
  29411. if (pos === 0) {
  29412. return new CFFCharset(true, CFFCharsetPredefinedTypes.ISO_ADOBE,
  29413. ISOAdobeCharset);
  29414. } else if (pos === 1) {
  29415. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT,
  29416. ExpertCharset);
  29417. } else if (pos === 2) {
  29418. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT_SUBSET,
  29419. ExpertSubsetCharset);
  29420. }
  29421. var bytes = this.bytes;
  29422. var start = pos;
  29423. var format = bytes[pos++];
  29424. var charset = ['.notdef'];
  29425. var id, count, i;
  29426. // subtract 1 for the .notdef glyph
  29427. length -= 1;
  29428. switch (format) {
  29429. case 0:
  29430. for (i = 0; i < length; i++) {
  29431. id = (bytes[pos++] << 8) | bytes[pos++];
  29432. charset.push(cid ? id : strings.get(id));
  29433. }
  29434. break;
  29435. case 1:
  29436. while (charset.length <= length) {
  29437. id = (bytes[pos++] << 8) | bytes[pos++];
  29438. count = bytes[pos++];
  29439. for (i = 0; i <= count; i++) {
  29440. charset.push(cid ? id++ : strings.get(id++));
  29441. }
  29442. }
  29443. break;
  29444. case 2:
  29445. while (charset.length <= length) {
  29446. id = (bytes[pos++] << 8) | bytes[pos++];
  29447. count = (bytes[pos++] << 8) | bytes[pos++];
  29448. for (i = 0; i <= count; i++) {
  29449. charset.push(cid ? id++ : strings.get(id++));
  29450. }
  29451. }
  29452. break;
  29453. default:
  29454. error('Unknown charset format');
  29455. }
  29456. // Raw won't be needed if we actually compile the charset.
  29457. var end = pos;
  29458. var raw = bytes.subarray(start, end);
  29459. return new CFFCharset(false, format, charset, raw);
  29460. },
  29461. parseEncoding: function CFFParser_parseEncoding(pos,
  29462. properties,
  29463. strings,
  29464. charset) {
  29465. var encoding = {};
  29466. var bytes = this.bytes;
  29467. var predefined = false;
  29468. var hasSupplement = false;
  29469. var format, i, ii;
  29470. var raw = null;
  29471. function readSupplement() {
  29472. var supplementsCount = bytes[pos++];
  29473. for (i = 0; i < supplementsCount; i++) {
  29474. var code = bytes[pos++];
  29475. var sid = (bytes[pos++] << 8) + (bytes[pos++] & 0xff);
  29476. encoding[code] = charset.indexOf(strings.get(sid));
  29477. }
  29478. }
  29479. if (pos === 0 || pos === 1) {
  29480. predefined = true;
  29481. format = pos;
  29482. var baseEncoding = pos ? Encodings.ExpertEncoding :
  29483. Encodings.StandardEncoding;
  29484. for (i = 0, ii = charset.length; i < ii; i++) {
  29485. var index = baseEncoding.indexOf(charset[i]);
  29486. if (index !== -1) {
  29487. encoding[index] = i;
  29488. }
  29489. }
  29490. } else {
  29491. var dataStart = pos;
  29492. format = bytes[pos++];
  29493. switch (format & 0x7f) {
  29494. case 0:
  29495. var glyphsCount = bytes[pos++];
  29496. for (i = 1; i <= glyphsCount; i++) {
  29497. encoding[bytes[pos++]] = i;
  29498. }
  29499. break;
  29500. case 1:
  29501. var rangesCount = bytes[pos++];
  29502. var gid = 1;
  29503. for (i = 0; i < rangesCount; i++) {
  29504. var start = bytes[pos++];
  29505. var left = bytes[pos++];
  29506. for (var j = start; j <= start + left; j++) {
  29507. encoding[j] = gid++;
  29508. }
  29509. }
  29510. break;
  29511. default:
  29512. error('Unknow encoding format: ' + format + ' in CFF');
  29513. break;
  29514. }
  29515. var dataEnd = pos;
  29516. if (format & 0x80) {
  29517. // The font sanitizer does not support CFF encoding with a
  29518. // supplement, since the encoding is not really used to map
  29519. // between gid to glyph, let's overwrite what is declared in
  29520. // the top dictionary to let the sanitizer think the font use
  29521. // StandardEncoding, that's a lie but that's ok.
  29522. bytes[dataStart] &= 0x7f;
  29523. readSupplement();
  29524. hasSupplement = true;
  29525. }
  29526. raw = bytes.subarray(dataStart, dataEnd);
  29527. }
  29528. format = format & 0x7f;
  29529. return new CFFEncoding(predefined, format, encoding, raw);
  29530. },
  29531. parseFDSelect: function CFFParser_parseFDSelect(pos, length) {
  29532. var start = pos;
  29533. var bytes = this.bytes;
  29534. var format = bytes[pos++];
  29535. var fdSelect = [];
  29536. var i;
  29537. switch (format) {
  29538. case 0:
  29539. for (i = 0; i < length; ++i) {
  29540. var id = bytes[pos++];
  29541. fdSelect.push(id);
  29542. }
  29543. break;
  29544. case 3:
  29545. var rangesCount = (bytes[pos++] << 8) | bytes[pos++];
  29546. for (i = 0; i < rangesCount; ++i) {
  29547. var first = (bytes[pos++] << 8) | bytes[pos++];
  29548. var fdIndex = bytes[pos++];
  29549. var next = (bytes[pos] << 8) | bytes[pos + 1];
  29550. for (var j = first; j < next; ++j) {
  29551. fdSelect.push(fdIndex);
  29552. }
  29553. }
  29554. // Advance past the sentinel(next).
  29555. pos += 2;
  29556. break;
  29557. default:
  29558. error('Unknown fdselect format ' + format);
  29559. break;
  29560. }
  29561. var end = pos;
  29562. return new CFFFDSelect(fdSelect, bytes.subarray(start, end));
  29563. }
  29564. };
  29565. return CFFParser;
  29566. })();
  29567. // Compact Font Format
  29568. var CFF = (function CFFClosure() {
  29569. function CFF() {
  29570. this.header = null;
  29571. this.names = [];
  29572. this.topDict = null;
  29573. this.strings = new CFFStrings();
  29574. this.globalSubrIndex = null;
  29575. // The following could really be per font, but since we only have one font
  29576. // store them here.
  29577. this.encoding = null;
  29578. this.charset = null;
  29579. this.charStrings = null;
  29580. this.fdArray = [];
  29581. this.fdSelect = null;
  29582. this.isCIDFont = false;
  29583. }
  29584. return CFF;
  29585. })();
  29586. var CFFHeader = (function CFFHeaderClosure() {
  29587. function CFFHeader(major, minor, hdrSize, offSize) {
  29588. this.major = major;
  29589. this.minor = minor;
  29590. this.hdrSize = hdrSize;
  29591. this.offSize = offSize;
  29592. }
  29593. return CFFHeader;
  29594. })();
  29595. var CFFStrings = (function CFFStringsClosure() {
  29596. function CFFStrings() {
  29597. this.strings = [];
  29598. }
  29599. CFFStrings.prototype = {
  29600. get: function CFFStrings_get(index) {
  29601. if (index >= 0 && index <= 390) {
  29602. return CFFStandardStrings[index];
  29603. }
  29604. if (index - 391 <= this.strings.length) {
  29605. return this.strings[index - 391];
  29606. }
  29607. return CFFStandardStrings[0];
  29608. },
  29609. add: function CFFStrings_add(value) {
  29610. this.strings.push(value);
  29611. },
  29612. get count() {
  29613. return this.strings.length;
  29614. }
  29615. };
  29616. return CFFStrings;
  29617. })();
  29618. var CFFIndex = (function CFFIndexClosure() {
  29619. function CFFIndex() {
  29620. this.objects = [];
  29621. this.length = 0;
  29622. }
  29623. CFFIndex.prototype = {
  29624. add: function CFFIndex_add(data) {
  29625. this.length += data.length;
  29626. this.objects.push(data);
  29627. },
  29628. set: function CFFIndex_set(index, data) {
  29629. this.length += data.length - this.objects[index].length;
  29630. this.objects[index] = data;
  29631. },
  29632. get: function CFFIndex_get(index) {
  29633. return this.objects[index];
  29634. },
  29635. get count() {
  29636. return this.objects.length;
  29637. }
  29638. };
  29639. return CFFIndex;
  29640. })();
  29641. var CFFDict = (function CFFDictClosure() {
  29642. function CFFDict(tables, strings) {
  29643. this.keyToNameMap = tables.keyToNameMap;
  29644. this.nameToKeyMap = tables.nameToKeyMap;
  29645. this.defaults = tables.defaults;
  29646. this.types = tables.types;
  29647. this.opcodes = tables.opcodes;
  29648. this.order = tables.order;
  29649. this.strings = strings;
  29650. this.values = {};
  29651. }
  29652. CFFDict.prototype = {
  29653. // value should always be an array
  29654. setByKey: function CFFDict_setByKey(key, value) {
  29655. if (!(key in this.keyToNameMap)) {
  29656. return false;
  29657. }
  29658. // ignore empty values
  29659. if (value.length === 0) {
  29660. return true;
  29661. }
  29662. var type = this.types[key];
  29663. // remove the array wrapping these types of values
  29664. if (type === 'num' || type === 'sid' || type === 'offset') {
  29665. value = value[0];
  29666. }
  29667. this.values[key] = value;
  29668. return true;
  29669. },
  29670. setByName: function CFFDict_setByName(name, value) {
  29671. if (!(name in this.nameToKeyMap)) {
  29672. error('Invalid dictionary name "' + name + '"');
  29673. }
  29674. this.values[this.nameToKeyMap[name]] = value;
  29675. },
  29676. hasName: function CFFDict_hasName(name) {
  29677. return this.nameToKeyMap[name] in this.values;
  29678. },
  29679. getByName: function CFFDict_getByName(name) {
  29680. if (!(name in this.nameToKeyMap)) {
  29681. error('Invalid dictionary name "' + name + '"');
  29682. }
  29683. var key = this.nameToKeyMap[name];
  29684. if (!(key in this.values)) {
  29685. return this.defaults[key];
  29686. }
  29687. return this.values[key];
  29688. },
  29689. removeByName: function CFFDict_removeByName(name) {
  29690. delete this.values[this.nameToKeyMap[name]];
  29691. }
  29692. };
  29693. CFFDict.createTables = function CFFDict_createTables(layout) {
  29694. var tables = {
  29695. keyToNameMap: {},
  29696. nameToKeyMap: {},
  29697. defaults: {},
  29698. types: {},
  29699. opcodes: {},
  29700. order: []
  29701. };
  29702. for (var i = 0, ii = layout.length; i < ii; ++i) {
  29703. var entry = layout[i];
  29704. var key = isArray(entry[0]) ? (entry[0][0] << 8) + entry[0][1] : entry[0];
  29705. tables.keyToNameMap[key] = entry[1];
  29706. tables.nameToKeyMap[entry[1]] = key;
  29707. tables.types[key] = entry[2];
  29708. tables.defaults[key] = entry[3];
  29709. tables.opcodes[key] = isArray(entry[0]) ? entry[0] : [entry[0]];
  29710. tables.order.push(key);
  29711. }
  29712. return tables;
  29713. };
  29714. return CFFDict;
  29715. })();
  29716. var CFFTopDict = (function CFFTopDictClosure() {
  29717. var layout = [
  29718. [[12, 30], 'ROS', ['sid', 'sid', 'num'], null],
  29719. [[12, 20], 'SyntheticBase', 'num', null],
  29720. [0, 'version', 'sid', null],
  29721. [1, 'Notice', 'sid', null],
  29722. [[12, 0], 'Copyright', 'sid', null],
  29723. [2, 'FullName', 'sid', null],
  29724. [3, 'FamilyName', 'sid', null],
  29725. [4, 'Weight', 'sid', null],
  29726. [[12, 1], 'isFixedPitch', 'num', 0],
  29727. [[12, 2], 'ItalicAngle', 'num', 0],
  29728. [[12, 3], 'UnderlinePosition', 'num', -100],
  29729. [[12, 4], 'UnderlineThickness', 'num', 50],
  29730. [[12, 5], 'PaintType', 'num', 0],
  29731. [[12, 6], 'CharstringType', 'num', 2],
  29732. [[12, 7], 'FontMatrix', ['num', 'num', 'num', 'num', 'num', 'num'],
  29733. [0.001, 0, 0, 0.001, 0, 0]],
  29734. [13, 'UniqueID', 'num', null],
  29735. [5, 'FontBBox', ['num', 'num', 'num', 'num'], [0, 0, 0, 0]],
  29736. [[12, 8], 'StrokeWidth', 'num', 0],
  29737. [14, 'XUID', 'array', null],
  29738. [15, 'charset', 'offset', 0],
  29739. [16, 'Encoding', 'offset', 0],
  29740. [17, 'CharStrings', 'offset', 0],
  29741. [18, 'Private', ['offset', 'offset'], null],
  29742. [[12, 21], 'PostScript', 'sid', null],
  29743. [[12, 22], 'BaseFontName', 'sid', null],
  29744. [[12, 23], 'BaseFontBlend', 'delta', null],
  29745. [[12, 31], 'CIDFontVersion', 'num', 0],
  29746. [[12, 32], 'CIDFontRevision', 'num', 0],
  29747. [[12, 33], 'CIDFontType', 'num', 0],
  29748. [[12, 34], 'CIDCount', 'num', 8720],
  29749. [[12, 35], 'UIDBase', 'num', null],
  29750. // XXX: CID Fonts on DirectWrite 6.1 only seem to work if FDSelect comes
  29751. // before FDArray.
  29752. [[12, 37], 'FDSelect', 'offset', null],
  29753. [[12, 36], 'FDArray', 'offset', null],
  29754. [[12, 38], 'FontName', 'sid', null]
  29755. ];
  29756. var tables = null;
  29757. function CFFTopDict(strings) {
  29758. if (tables === null) {
  29759. tables = CFFDict.createTables(layout);
  29760. }
  29761. CFFDict.call(this, tables, strings);
  29762. this.privateDict = null;
  29763. }
  29764. CFFTopDict.prototype = Object.create(CFFDict.prototype);
  29765. return CFFTopDict;
  29766. })();
  29767. var CFFPrivateDict = (function CFFPrivateDictClosure() {
  29768. var layout = [
  29769. [6, 'BlueValues', 'delta', null],
  29770. [7, 'OtherBlues', 'delta', null],
  29771. [8, 'FamilyBlues', 'delta', null],
  29772. [9, 'FamilyOtherBlues', 'delta', null],
  29773. [[12, 9], 'BlueScale', 'num', 0.039625],
  29774. [[12, 10], 'BlueShift', 'num', 7],
  29775. [[12, 11], 'BlueFuzz', 'num', 1],
  29776. [10, 'StdHW', 'num', null],
  29777. [11, 'StdVW', 'num', null],
  29778. [[12, 12], 'StemSnapH', 'delta', null],
  29779. [[12, 13], 'StemSnapV', 'delta', null],
  29780. [[12, 14], 'ForceBold', 'num', 0],
  29781. [[12, 17], 'LanguageGroup', 'num', 0],
  29782. [[12, 18], 'ExpansionFactor', 'num', 0.06],
  29783. [[12, 19], 'initialRandomSeed', 'num', 0],
  29784. [20, 'defaultWidthX', 'num', 0],
  29785. [21, 'nominalWidthX', 'num', 0],
  29786. [19, 'Subrs', 'offset', null]
  29787. ];
  29788. var tables = null;
  29789. function CFFPrivateDict(strings) {
  29790. if (tables === null) {
  29791. tables = CFFDict.createTables(layout);
  29792. }
  29793. CFFDict.call(this, tables, strings);
  29794. this.subrsIndex = null;
  29795. }
  29796. CFFPrivateDict.prototype = Object.create(CFFDict.prototype);
  29797. return CFFPrivateDict;
  29798. })();
  29799. var CFFCharsetPredefinedTypes = {
  29800. ISO_ADOBE: 0,
  29801. EXPERT: 1,
  29802. EXPERT_SUBSET: 2
  29803. };
  29804. var CFFCharset = (function CFFCharsetClosure() {
  29805. function CFFCharset(predefined, format, charset, raw) {
  29806. this.predefined = predefined;
  29807. this.format = format;
  29808. this.charset = charset;
  29809. this.raw = raw;
  29810. }
  29811. return CFFCharset;
  29812. })();
  29813. var CFFEncoding = (function CFFEncodingClosure() {
  29814. function CFFEncoding(predefined, format, encoding, raw) {
  29815. this.predefined = predefined;
  29816. this.format = format;
  29817. this.encoding = encoding;
  29818. this.raw = raw;
  29819. }
  29820. return CFFEncoding;
  29821. })();
  29822. var CFFFDSelect = (function CFFFDSelectClosure() {
  29823. function CFFFDSelect(fdSelect, raw) {
  29824. this.fdSelect = fdSelect;
  29825. this.raw = raw;
  29826. }
  29827. CFFFDSelect.prototype = {
  29828. getFDIndex: function CFFFDSelect_get(glyphIndex) {
  29829. if (glyphIndex < 0 || glyphIndex >= this.fdSelect.length) {
  29830. return -1;
  29831. }
  29832. return this.fdSelect[glyphIndex];
  29833. }
  29834. };
  29835. return CFFFDSelect;
  29836. })();
  29837. // Helper class to keep track of where an offset is within the data and helps
  29838. // filling in that offset once it's known.
  29839. var CFFOffsetTracker = (function CFFOffsetTrackerClosure() {
  29840. function CFFOffsetTracker() {
  29841. this.offsets = {};
  29842. }
  29843. CFFOffsetTracker.prototype = {
  29844. isTracking: function CFFOffsetTracker_isTracking(key) {
  29845. return key in this.offsets;
  29846. },
  29847. track: function CFFOffsetTracker_track(key, location) {
  29848. if (key in this.offsets) {
  29849. error('Already tracking location of ' + key);
  29850. }
  29851. this.offsets[key] = location;
  29852. },
  29853. offset: function CFFOffsetTracker_offset(value) {
  29854. for (var key in this.offsets) {
  29855. this.offsets[key] += value;
  29856. }
  29857. },
  29858. setEntryLocation: function CFFOffsetTracker_setEntryLocation(key,
  29859. values,
  29860. output) {
  29861. if (!(key in this.offsets)) {
  29862. error('Not tracking location of ' + key);
  29863. }
  29864. var data = output.data;
  29865. var dataOffset = this.offsets[key];
  29866. var size = 5;
  29867. for (var i = 0, ii = values.length; i < ii; ++i) {
  29868. var offset0 = i * size + dataOffset;
  29869. var offset1 = offset0 + 1;
  29870. var offset2 = offset0 + 2;
  29871. var offset3 = offset0 + 3;
  29872. var offset4 = offset0 + 4;
  29873. // It's easy to screw up offsets so perform this sanity check.
  29874. if (data[offset0] !== 0x1d || data[offset1] !== 0 ||
  29875. data[offset2] !== 0 || data[offset3] !== 0 || data[offset4] !== 0) {
  29876. error('writing to an offset that is not empty');
  29877. }
  29878. var value = values[i];
  29879. data[offset0] = 0x1d;
  29880. data[offset1] = (value >> 24) & 0xFF;
  29881. data[offset2] = (value >> 16) & 0xFF;
  29882. data[offset3] = (value >> 8) & 0xFF;
  29883. data[offset4] = value & 0xFF;
  29884. }
  29885. }
  29886. };
  29887. return CFFOffsetTracker;
  29888. })();
  29889. // Takes a CFF and converts it to the binary representation.
  29890. var CFFCompiler = (function CFFCompilerClosure() {
  29891. function CFFCompiler(cff) {
  29892. this.cff = cff;
  29893. }
  29894. CFFCompiler.prototype = {
  29895. compile: function CFFCompiler_compile() {
  29896. var cff = this.cff;
  29897. var output = {
  29898. data: [],
  29899. length: 0,
  29900. add: function CFFCompiler_add(data) {
  29901. this.data = this.data.concat(data);
  29902. this.length = this.data.length;
  29903. }
  29904. };
  29905. // Compile the five entries that must be in order.
  29906. var header = this.compileHeader(cff.header);
  29907. output.add(header);
  29908. var nameIndex = this.compileNameIndex(cff.names);
  29909. output.add(nameIndex);
  29910. if (cff.isCIDFont) {
  29911. // The spec is unclear on how font matrices should relate to each other
  29912. // when there is one in the main top dict and the sub top dicts.
  29913. // Windows handles this differently than linux and osx so we have to
  29914. // normalize to work on all.
  29915. // Rules based off of some mailing list discussions:
  29916. // - If main font has a matrix and subfont doesn't, use the main matrix.
  29917. // - If no main font matrix and there is a subfont matrix, use the
  29918. // subfont matrix.
  29919. // - If both have matrices, concat together.
  29920. // - If neither have matrices, use default.
  29921. // To make this work on all platforms we move the top matrix into each
  29922. // sub top dict and concat if necessary.
  29923. if (cff.topDict.hasName('FontMatrix')) {
  29924. var base = cff.topDict.getByName('FontMatrix');
  29925. cff.topDict.removeByName('FontMatrix');
  29926. for (var i = 0, ii = cff.fdArray.length; i < ii; i++) {
  29927. var subDict = cff.fdArray[i];
  29928. var matrix = base.slice(0);
  29929. if (subDict.hasName('FontMatrix')) {
  29930. matrix = Util.transform(matrix, subDict.getByName('FontMatrix'));
  29931. }
  29932. subDict.setByName('FontMatrix', matrix);
  29933. }
  29934. }
  29935. }
  29936. var compiled = this.compileTopDicts([cff.topDict],
  29937. output.length,
  29938. cff.isCIDFont);
  29939. output.add(compiled.output);
  29940. var topDictTracker = compiled.trackers[0];
  29941. var stringIndex = this.compileStringIndex(cff.strings.strings);
  29942. output.add(stringIndex);
  29943. var globalSubrIndex = this.compileIndex(cff.globalSubrIndex);
  29944. output.add(globalSubrIndex);
  29945. // Now start on the other entries that have no specfic order.
  29946. if (cff.encoding && cff.topDict.hasName('Encoding')) {
  29947. if (cff.encoding.predefined) {
  29948. topDictTracker.setEntryLocation('Encoding', [cff.encoding.format],
  29949. output);
  29950. } else {
  29951. var encoding = this.compileEncoding(cff.encoding);
  29952. topDictTracker.setEntryLocation('Encoding', [output.length], output);
  29953. output.add(encoding);
  29954. }
  29955. }
  29956. if (cff.charset && cff.topDict.hasName('charset')) {
  29957. if (cff.charset.predefined) {
  29958. topDictTracker.setEntryLocation('charset', [cff.charset.format],
  29959. output);
  29960. } else {
  29961. var charset = this.compileCharset(cff.charset);
  29962. topDictTracker.setEntryLocation('charset', [output.length], output);
  29963. output.add(charset);
  29964. }
  29965. }
  29966. var charStrings = this.compileCharStrings(cff.charStrings);
  29967. topDictTracker.setEntryLocation('CharStrings', [output.length], output);
  29968. output.add(charStrings);
  29969. if (cff.isCIDFont) {
  29970. // For some reason FDSelect must be in front of FDArray on windows. OSX
  29971. // and linux don't seem to care.
  29972. topDictTracker.setEntryLocation('FDSelect', [output.length], output);
  29973. var fdSelect = this.compileFDSelect(cff.fdSelect.raw);
  29974. output.add(fdSelect);
  29975. // It is unclear if the sub font dictionary can have CID related
  29976. // dictionary keys, but the sanitizer doesn't like them so remove them.
  29977. compiled = this.compileTopDicts(cff.fdArray, output.length, true);
  29978. topDictTracker.setEntryLocation('FDArray', [output.length], output);
  29979. output.add(compiled.output);
  29980. var fontDictTrackers = compiled.trackers;
  29981. this.compilePrivateDicts(cff.fdArray, fontDictTrackers, output);
  29982. }
  29983. this.compilePrivateDicts([cff.topDict], [topDictTracker], output);
  29984. // If the font data ends with INDEX whose object data is zero-length,
  29985. // the sanitizer will bail out. Add a dummy byte to avoid that.
  29986. output.add([0]);
  29987. return output.data;
  29988. },
  29989. encodeNumber: function CFFCompiler_encodeNumber(value) {
  29990. if (parseFloat(value) === parseInt(value, 10) && !isNaN(value)) { // isInt
  29991. return this.encodeInteger(value);
  29992. } else {
  29993. return this.encodeFloat(value);
  29994. }
  29995. },
  29996. encodeFloat: function CFFCompiler_encodeFloat(num) {
  29997. var value = num.toString();
  29998. // rounding inaccurate doubles
  29999. var m = /\.(\d*?)(?:9{5,20}|0{5,20})\d{0,2}(?:e(.+)|$)/.exec(value);
  30000. if (m) {
  30001. var epsilon = parseFloat('1e' + ((m[2] ? +m[2] : 0) + m[1].length));
  30002. value = (Math.round(num * epsilon) / epsilon).toString();
  30003. }
  30004. var nibbles = '';
  30005. var i, ii;
  30006. for (i = 0, ii = value.length; i < ii; ++i) {
  30007. var a = value[i];
  30008. if (a === 'e') {
  30009. nibbles += value[++i] === '-' ? 'c' : 'b';
  30010. } else if (a === '.') {
  30011. nibbles += 'a';
  30012. } else if (a === '-') {
  30013. nibbles += 'e';
  30014. } else {
  30015. nibbles += a;
  30016. }
  30017. }
  30018. nibbles += (nibbles.length & 1) ? 'f' : 'ff';
  30019. var out = [30];
  30020. for (i = 0, ii = nibbles.length; i < ii; i += 2) {
  30021. out.push(parseInt(nibbles.substr(i, 2), 16));
  30022. }
  30023. return out;
  30024. },
  30025. encodeInteger: function CFFCompiler_encodeInteger(value) {
  30026. var code;
  30027. if (value >= -107 && value <= 107) {
  30028. code = [value + 139];
  30029. } else if (value >= 108 && value <= 1131) {
  30030. value = [value - 108];
  30031. code = [(value >> 8) + 247, value & 0xFF];
  30032. } else if (value >= -1131 && value <= -108) {
  30033. value = -value - 108;
  30034. code = [(value >> 8) + 251, value & 0xFF];
  30035. } else if (value >= -32768 && value <= 32767) {
  30036. code = [0x1c, (value >> 8) & 0xFF, value & 0xFF];
  30037. } else {
  30038. code = [0x1d,
  30039. (value >> 24) & 0xFF,
  30040. (value >> 16) & 0xFF,
  30041. (value >> 8) & 0xFF,
  30042. value & 0xFF];
  30043. }
  30044. return code;
  30045. },
  30046. compileHeader: function CFFCompiler_compileHeader(header) {
  30047. return [
  30048. header.major,
  30049. header.minor,
  30050. header.hdrSize,
  30051. header.offSize
  30052. ];
  30053. },
  30054. compileNameIndex: function CFFCompiler_compileNameIndex(names) {
  30055. var nameIndex = new CFFIndex();
  30056. for (var i = 0, ii = names.length; i < ii; ++i) {
  30057. nameIndex.add(stringToBytes(names[i]));
  30058. }
  30059. return this.compileIndex(nameIndex);
  30060. },
  30061. compileTopDicts: function CFFCompiler_compileTopDicts(dicts,
  30062. length,
  30063. removeCidKeys) {
  30064. var fontDictTrackers = [];
  30065. var fdArrayIndex = new CFFIndex();
  30066. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  30067. var fontDict = dicts[i];
  30068. if (removeCidKeys) {
  30069. fontDict.removeByName('CIDFontVersion');
  30070. fontDict.removeByName('CIDFontRevision');
  30071. fontDict.removeByName('CIDFontType');
  30072. fontDict.removeByName('CIDCount');
  30073. fontDict.removeByName('UIDBase');
  30074. }
  30075. var fontDictTracker = new CFFOffsetTracker();
  30076. var fontDictData = this.compileDict(fontDict, fontDictTracker);
  30077. fontDictTrackers.push(fontDictTracker);
  30078. fdArrayIndex.add(fontDictData);
  30079. fontDictTracker.offset(length);
  30080. }
  30081. fdArrayIndex = this.compileIndex(fdArrayIndex, fontDictTrackers);
  30082. return {
  30083. trackers: fontDictTrackers,
  30084. output: fdArrayIndex
  30085. };
  30086. },
  30087. compilePrivateDicts: function CFFCompiler_compilePrivateDicts(dicts,
  30088. trackers,
  30089. output) {
  30090. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  30091. var fontDict = dicts[i];
  30092. assert(fontDict.privateDict && fontDict.hasName('Private'),
  30093. 'There must be an private dictionary.');
  30094. var privateDict = fontDict.privateDict;
  30095. var privateDictTracker = new CFFOffsetTracker();
  30096. var privateDictData = this.compileDict(privateDict, privateDictTracker);
  30097. var outputLength = output.length;
  30098. privateDictTracker.offset(outputLength);
  30099. if (!privateDictData.length) {
  30100. // The private dictionary was empty, set the output length to zero to
  30101. // ensure the offset length isn't out of bounds in the eyes of the
  30102. // sanitizer.
  30103. outputLength = 0;
  30104. }
  30105. trackers[i].setEntryLocation('Private',
  30106. [privateDictData.length, outputLength],
  30107. output);
  30108. output.add(privateDictData);
  30109. if (privateDict.subrsIndex && privateDict.hasName('Subrs')) {
  30110. var subrs = this.compileIndex(privateDict.subrsIndex);
  30111. privateDictTracker.setEntryLocation('Subrs', [privateDictData.length],
  30112. output);
  30113. output.add(subrs);
  30114. }
  30115. }
  30116. },
  30117. compileDict: function CFFCompiler_compileDict(dict, offsetTracker) {
  30118. var out = [];
  30119. // The dictionary keys must be in a certain order.
  30120. var order = dict.order;
  30121. for (var i = 0; i < order.length; ++i) {
  30122. var key = order[i];
  30123. if (!(key in dict.values)) {
  30124. continue;
  30125. }
  30126. var values = dict.values[key];
  30127. var types = dict.types[key];
  30128. if (!isArray(types)) {
  30129. types = [types];
  30130. }
  30131. if (!isArray(values)) {
  30132. values = [values];
  30133. }
  30134. // Remove any empty dict values.
  30135. if (values.length === 0) {
  30136. continue;
  30137. }
  30138. for (var j = 0, jj = types.length; j < jj; ++j) {
  30139. var type = types[j];
  30140. var value = values[j];
  30141. switch (type) {
  30142. case 'num':
  30143. case 'sid':
  30144. out = out.concat(this.encodeNumber(value));
  30145. break;
  30146. case 'offset':
  30147. // For offsets we just insert a 32bit integer so we don't have to
  30148. // deal with figuring out the length of the offset when it gets
  30149. // replaced later on by the compiler.
  30150. var name = dict.keyToNameMap[key];
  30151. // Some offsets have the offset and the length, so just record the
  30152. // position of the first one.
  30153. if (!offsetTracker.isTracking(name)) {
  30154. offsetTracker.track(name, out.length);
  30155. }
  30156. out = out.concat([0x1d, 0, 0, 0, 0]);
  30157. break;
  30158. case 'array':
  30159. case 'delta':
  30160. out = out.concat(this.encodeNumber(value));
  30161. for (var k = 1, kk = values.length; k < kk; ++k) {
  30162. out = out.concat(this.encodeNumber(values[k]));
  30163. }
  30164. break;
  30165. default:
  30166. error('Unknown data type of ' + type);
  30167. break;
  30168. }
  30169. }
  30170. out = out.concat(dict.opcodes[key]);
  30171. }
  30172. return out;
  30173. },
  30174. compileStringIndex: function CFFCompiler_compileStringIndex(strings) {
  30175. var stringIndex = new CFFIndex();
  30176. for (var i = 0, ii = strings.length; i < ii; ++i) {
  30177. stringIndex.add(stringToBytes(strings[i]));
  30178. }
  30179. return this.compileIndex(stringIndex);
  30180. },
  30181. compileGlobalSubrIndex: function CFFCompiler_compileGlobalSubrIndex() {
  30182. var globalSubrIndex = this.cff.globalSubrIndex;
  30183. this.out.writeByteArray(this.compileIndex(globalSubrIndex));
  30184. },
  30185. compileCharStrings: function CFFCompiler_compileCharStrings(charStrings) {
  30186. return this.compileIndex(charStrings);
  30187. },
  30188. compileCharset: function CFFCompiler_compileCharset(charset) {
  30189. return this.compileTypedArray(charset.raw);
  30190. },
  30191. compileEncoding: function CFFCompiler_compileEncoding(encoding) {
  30192. return this.compileTypedArray(encoding.raw);
  30193. },
  30194. compileFDSelect: function CFFCompiler_compileFDSelect(fdSelect) {
  30195. return this.compileTypedArray(fdSelect);
  30196. },
  30197. compileTypedArray: function CFFCompiler_compileTypedArray(data) {
  30198. var out = [];
  30199. for (var i = 0, ii = data.length; i < ii; ++i) {
  30200. out[i] = data[i];
  30201. }
  30202. return out;
  30203. },
  30204. compileIndex: function CFFCompiler_compileIndex(index, trackers) {
  30205. trackers = trackers || [];
  30206. var objects = index.objects;
  30207. // First 2 bytes contains the number of objects contained into this index
  30208. var count = objects.length;
  30209. // If there is no object, just create an index. This technically
  30210. // should just be [0, 0] but OTS has an issue with that.
  30211. if (count === 0) {
  30212. return [0, 0, 0];
  30213. }
  30214. var data = [(count >> 8) & 0xFF, count & 0xff];
  30215. var lastOffset = 1, i;
  30216. for (i = 0; i < count; ++i) {
  30217. lastOffset += objects[i].length;
  30218. }
  30219. var offsetSize;
  30220. if (lastOffset < 0x100) {
  30221. offsetSize = 1;
  30222. } else if (lastOffset < 0x10000) {
  30223. offsetSize = 2;
  30224. } else if (lastOffset < 0x1000000) {
  30225. offsetSize = 3;
  30226. } else {
  30227. offsetSize = 4;
  30228. }
  30229. // Next byte contains the offset size use to reference object in the file
  30230. data.push(offsetSize);
  30231. // Add another offset after this one because we need a new offset
  30232. var relativeOffset = 1;
  30233. for (i = 0; i < count + 1; i++) {
  30234. if (offsetSize === 1) {
  30235. data.push(relativeOffset & 0xFF);
  30236. } else if (offsetSize === 2) {
  30237. data.push((relativeOffset >> 8) & 0xFF,
  30238. relativeOffset & 0xFF);
  30239. } else if (offsetSize === 3) {
  30240. data.push((relativeOffset >> 16) & 0xFF,
  30241. (relativeOffset >> 8) & 0xFF,
  30242. relativeOffset & 0xFF);
  30243. } else {
  30244. data.push((relativeOffset >>> 24) & 0xFF,
  30245. (relativeOffset >> 16) & 0xFF,
  30246. (relativeOffset >> 8) & 0xFF,
  30247. relativeOffset & 0xFF);
  30248. }
  30249. if (objects[i]) {
  30250. relativeOffset += objects[i].length;
  30251. }
  30252. }
  30253. for (i = 0; i < count; i++) {
  30254. // Notify the tracker where the object will be offset in the data.
  30255. if (trackers[i]) {
  30256. trackers[i].offset(data.length);
  30257. }
  30258. for (var j = 0, jj = objects[i].length; j < jj; j++) {
  30259. data.push(objects[i][j]);
  30260. }
  30261. }
  30262. return data;
  30263. }
  30264. };
  30265. return CFFCompiler;
  30266. })();
  30267. function _enableSeacAnalysis(enabled) {
  30268. exports.SEAC_ANALYSIS_ENABLED = SEAC_ANALYSIS_ENABLED = enabled;
  30269. }
  30270. // Workaround for seac on Windows.
  30271. (function checkSeacSupport() {
  30272. if (typeof navigator !== 'undefined' && /Windows/.test(navigator.userAgent)) {
  30273. SEAC_ANALYSIS_ENABLED = true;
  30274. }
  30275. })();
  30276. // Workaround for Private Use Area characters in Chrome on Windows
  30277. // http://code.google.com/p/chromium/issues/detail?id=122465
  30278. // https://github.com/mozilla/pdf.js/issues/1689
  30279. (function checkChromeWindows() {
  30280. if (typeof navigator !== 'undefined' &&
  30281. /Windows.*Chrome/.test(navigator.userAgent)) {
  30282. SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = true;
  30283. }
  30284. })();
  30285. exports.SEAC_ANALYSIS_ENABLED = SEAC_ANALYSIS_ENABLED;
  30286. exports.CFFCompiler = CFFCompiler;
  30287. exports.CFFIndex = CFFIndex;
  30288. exports.CFFParser = CFFParser;
  30289. exports.CFFStrings = CFFStrings;
  30290. exports.Encodings = Encodings;
  30291. exports.ErrorFont = ErrorFont;
  30292. exports.FontFlags = FontFlags;
  30293. exports.Font = Font;
  30294. exports.IdentityToUnicodeMap = IdentityToUnicodeMap;
  30295. exports.NormalizedUnicodes = NormalizedUnicodes;
  30296. exports.ToUnicodeMap = ToUnicodeMap;
  30297. exports.Type1Parser = Type1Parser;
  30298. exports.getFontType = getFontType;
  30299. exports.reverseIfRtl = reverseIfRtl;
  30300. exports.serifFonts = serifFonts;
  30301. exports.symbolsFonts = symbolsFonts;
  30302. exports.stdFontMap = stdFontMap;
  30303. exports._enableSeacAnalysis = _enableSeacAnalysis;
  30304. // TODO refactor to remove cyclic dependency on font_renderer.js
  30305. coreFontRenderer._setCoreFonts(exports);
  30306. }));
  30307. (function (root, factory) {
  30308. {
  30309. factory((root.pdfjsCoreFunction = {}), root.pdfjsSharedUtil,
  30310. root.pdfjsCorePrimitives, root.pdfjsCorePsParser);
  30311. }
  30312. }(this, function (exports, sharedUtil, corePrimitives, corePsParser) {
  30313. var error = sharedUtil.error;
  30314. var info = sharedUtil.info;
  30315. var isArray = sharedUtil.isArray;
  30316. var isBool = sharedUtil.isBool;
  30317. var isDict = corePrimitives.isDict;
  30318. var isStream = corePrimitives.isStream;
  30319. var PostScriptLexer = corePsParser.PostScriptLexer;
  30320. var PostScriptParser = corePsParser.PostScriptParser;
  30321. var PDFFunction = (function PDFFunctionClosure() {
  30322. var CONSTRUCT_SAMPLED = 0;
  30323. var CONSTRUCT_INTERPOLATED = 2;
  30324. var CONSTRUCT_STICHED = 3;
  30325. var CONSTRUCT_POSTSCRIPT = 4;
  30326. return {
  30327. getSampleArray: function PDFFunction_getSampleArray(size, outputSize, bps,
  30328. str) {
  30329. var i, ii;
  30330. var length = 1;
  30331. for (i = 0, ii = size.length; i < ii; i++) {
  30332. length *= size[i];
  30333. }
  30334. length *= outputSize;
  30335. var array = new Array(length);
  30336. var codeSize = 0;
  30337. var codeBuf = 0;
  30338. // 32 is a valid bps so shifting won't work
  30339. var sampleMul = 1.0 / (Math.pow(2.0, bps) - 1);
  30340. var strBytes = str.getBytes((length * bps + 7) / 8);
  30341. var strIdx = 0;
  30342. for (i = 0; i < length; i++) {
  30343. while (codeSize < bps) {
  30344. codeBuf <<= 8;
  30345. codeBuf |= strBytes[strIdx++];
  30346. codeSize += 8;
  30347. }
  30348. codeSize -= bps;
  30349. array[i] = (codeBuf >> codeSize) * sampleMul;
  30350. codeBuf &= (1 << codeSize) - 1;
  30351. }
  30352. return array;
  30353. },
  30354. getIR: function PDFFunction_getIR(xref, fn) {
  30355. var dict = fn.dict;
  30356. if (!dict) {
  30357. dict = fn;
  30358. }
  30359. var types = [this.constructSampled,
  30360. null,
  30361. this.constructInterpolated,
  30362. this.constructStiched,
  30363. this.constructPostScript];
  30364. var typeNum = dict.get('FunctionType');
  30365. var typeFn = types[typeNum];
  30366. if (!typeFn) {
  30367. error('Unknown type of function');
  30368. }
  30369. return typeFn.call(this, fn, dict, xref);
  30370. },
  30371. fromIR: function PDFFunction_fromIR(IR) {
  30372. var type = IR[0];
  30373. switch (type) {
  30374. case CONSTRUCT_SAMPLED:
  30375. return this.constructSampledFromIR(IR);
  30376. case CONSTRUCT_INTERPOLATED:
  30377. return this.constructInterpolatedFromIR(IR);
  30378. case CONSTRUCT_STICHED:
  30379. return this.constructStichedFromIR(IR);
  30380. //case CONSTRUCT_POSTSCRIPT:
  30381. default:
  30382. return this.constructPostScriptFromIR(IR);
  30383. }
  30384. },
  30385. parse: function PDFFunction_parse(xref, fn) {
  30386. var IR = this.getIR(xref, fn);
  30387. return this.fromIR(IR);
  30388. },
  30389. parseArray: function PDFFunction_parseArray(xref, fnObj) {
  30390. if (!isArray(fnObj)) {
  30391. // not an array -- parsing as regular function
  30392. return this.parse(xref, fnObj);
  30393. }
  30394. var fnArray = [];
  30395. for (var j = 0, jj = fnObj.length; j < jj; j++) {
  30396. var obj = xref.fetchIfRef(fnObj[j]);
  30397. fnArray.push(PDFFunction.parse(xref, obj));
  30398. }
  30399. return function (src, srcOffset, dest, destOffset) {
  30400. for (var i = 0, ii = fnArray.length; i < ii; i++) {
  30401. fnArray[i](src, srcOffset, dest, destOffset + i);
  30402. }
  30403. };
  30404. },
  30405. constructSampled: function PDFFunction_constructSampled(str, dict) {
  30406. function toMultiArray(arr) {
  30407. var inputLength = arr.length;
  30408. var out = [];
  30409. var index = 0;
  30410. for (var i = 0; i < inputLength; i += 2) {
  30411. out[index] = [arr[i], arr[i + 1]];
  30412. ++index;
  30413. }
  30414. return out;
  30415. }
  30416. var domain = dict.get('Domain');
  30417. var range = dict.get('Range');
  30418. if (!domain || !range) {
  30419. error('No domain or range');
  30420. }
  30421. var inputSize = domain.length / 2;
  30422. var outputSize = range.length / 2;
  30423. domain = toMultiArray(domain);
  30424. range = toMultiArray(range);
  30425. var size = dict.get('Size');
  30426. var bps = dict.get('BitsPerSample');
  30427. var order = dict.get('Order') || 1;
  30428. if (order !== 1) {
  30429. // No description how cubic spline interpolation works in PDF32000:2008
  30430. // As in poppler, ignoring order, linear interpolation may work as good
  30431. info('No support for cubic spline interpolation: ' + order);
  30432. }
  30433. var encode = dict.get('Encode');
  30434. if (!encode) {
  30435. encode = [];
  30436. for (var i = 0; i < inputSize; ++i) {
  30437. encode.push(0);
  30438. encode.push(size[i] - 1);
  30439. }
  30440. }
  30441. encode = toMultiArray(encode);
  30442. var decode = dict.get('Decode');
  30443. if (!decode) {
  30444. decode = range;
  30445. } else {
  30446. decode = toMultiArray(decode);
  30447. }
  30448. var samples = this.getSampleArray(size, outputSize, bps, str);
  30449. return [
  30450. CONSTRUCT_SAMPLED, inputSize, domain, encode, decode, samples, size,
  30451. outputSize, Math.pow(2, bps) - 1, range
  30452. ];
  30453. },
  30454. constructSampledFromIR: function PDFFunction_constructSampledFromIR(IR) {
  30455. // See chapter 3, page 109 of the PDF reference
  30456. function interpolate(x, xmin, xmax, ymin, ymax) {
  30457. return ymin + ((x - xmin) * ((ymax - ymin) / (xmax - xmin)));
  30458. }
  30459. return function constructSampledFromIRResult(src, srcOffset,
  30460. dest, destOffset) {
  30461. // See chapter 3, page 110 of the PDF reference.
  30462. var m = IR[1];
  30463. var domain = IR[2];
  30464. var encode = IR[3];
  30465. var decode = IR[4];
  30466. var samples = IR[5];
  30467. var size = IR[6];
  30468. var n = IR[7];
  30469. //var mask = IR[8];
  30470. var range = IR[9];
  30471. // Building the cube vertices: its part and sample index
  30472. // http://rjwagner49.com/Mathematics/Interpolation.pdf
  30473. var cubeVertices = 1 << m;
  30474. var cubeN = new Float64Array(cubeVertices);
  30475. var cubeVertex = new Uint32Array(cubeVertices);
  30476. var i, j;
  30477. for (j = 0; j < cubeVertices; j++) {
  30478. cubeN[j] = 1;
  30479. }
  30480. var k = n, pos = 1;
  30481. // Map x_i to y_j for 0 <= i < m using the sampled function.
  30482. for (i = 0; i < m; ++i) {
  30483. // x_i' = min(max(x_i, Domain_2i), Domain_2i+1)
  30484. var domain_2i = domain[i][0];
  30485. var domain_2i_1 = domain[i][1];
  30486. var xi = Math.min(Math.max(src[srcOffset +i], domain_2i),
  30487. domain_2i_1);
  30488. // e_i = Interpolate(x_i', Domain_2i, Domain_2i+1,
  30489. // Encode_2i, Encode_2i+1)
  30490. var e = interpolate(xi, domain_2i, domain_2i_1,
  30491. encode[i][0], encode[i][1]);
  30492. // e_i' = min(max(e_i, 0), Size_i - 1)
  30493. var size_i = size[i];
  30494. e = Math.min(Math.max(e, 0), size_i - 1);
  30495. // Adjusting the cube: N and vertex sample index
  30496. var e0 = e < size_i - 1 ? Math.floor(e) : e - 1; // e1 = e0 + 1;
  30497. var n0 = e0 + 1 - e; // (e1 - e) / (e1 - e0);
  30498. var n1 = e - e0; // (e - e0) / (e1 - e0);
  30499. var offset0 = e0 * k;
  30500. var offset1 = offset0 + k; // e1 * k
  30501. for (j = 0; j < cubeVertices; j++) {
  30502. if (j & pos) {
  30503. cubeN[j] *= n1;
  30504. cubeVertex[j] += offset1;
  30505. } else {
  30506. cubeN[j] *= n0;
  30507. cubeVertex[j] += offset0;
  30508. }
  30509. }
  30510. k *= size_i;
  30511. pos <<= 1;
  30512. }
  30513. for (j = 0; j < n; ++j) {
  30514. // Sum all cube vertices' samples portions
  30515. var rj = 0;
  30516. for (i = 0; i < cubeVertices; i++) {
  30517. rj += samples[cubeVertex[i] + j] * cubeN[i];
  30518. }
  30519. // r_j' = Interpolate(r_j, 0, 2^BitsPerSample - 1,
  30520. // Decode_2j, Decode_2j+1)
  30521. rj = interpolate(rj, 0, 1, decode[j][0], decode[j][1]);
  30522. // y_j = min(max(r_j, range_2j), range_2j+1)
  30523. dest[destOffset + j] = Math.min(Math.max(rj, range[j][0]),
  30524. range[j][1]);
  30525. }
  30526. };
  30527. },
  30528. constructInterpolated: function PDFFunction_constructInterpolated(str,
  30529. dict) {
  30530. var c0 = dict.get('C0') || [0];
  30531. var c1 = dict.get('C1') || [1];
  30532. var n = dict.get('N');
  30533. if (!isArray(c0) || !isArray(c1)) {
  30534. error('Illegal dictionary for interpolated function');
  30535. }
  30536. var length = c0.length;
  30537. var diff = [];
  30538. for (var i = 0; i < length; ++i) {
  30539. diff.push(c1[i] - c0[i]);
  30540. }
  30541. return [CONSTRUCT_INTERPOLATED, c0, diff, n];
  30542. },
  30543. constructInterpolatedFromIR:
  30544. function PDFFunction_constructInterpolatedFromIR(IR) {
  30545. var c0 = IR[1];
  30546. var diff = IR[2];
  30547. var n = IR[3];
  30548. var length = diff.length;
  30549. return function constructInterpolatedFromIRResult(src, srcOffset,
  30550. dest, destOffset) {
  30551. var x = n === 1 ? src[srcOffset] : Math.pow(src[srcOffset], n);
  30552. for (var j = 0; j < length; ++j) {
  30553. dest[destOffset + j] = c0[j] + (x * diff[j]);
  30554. }
  30555. };
  30556. },
  30557. constructStiched: function PDFFunction_constructStiched(fn, dict, xref) {
  30558. var domain = dict.get('Domain');
  30559. if (!domain) {
  30560. error('No domain');
  30561. }
  30562. var inputSize = domain.length / 2;
  30563. if (inputSize !== 1) {
  30564. error('Bad domain for stiched function');
  30565. }
  30566. var fnRefs = dict.get('Functions');
  30567. var fns = [];
  30568. for (var i = 0, ii = fnRefs.length; i < ii; ++i) {
  30569. fns.push(PDFFunction.getIR(xref, xref.fetchIfRef(fnRefs[i])));
  30570. }
  30571. var bounds = dict.get('Bounds');
  30572. var encode = dict.get('Encode');
  30573. return [CONSTRUCT_STICHED, domain, bounds, encode, fns];
  30574. },
  30575. constructStichedFromIR: function PDFFunction_constructStichedFromIR(IR) {
  30576. var domain = IR[1];
  30577. var bounds = IR[2];
  30578. var encode = IR[3];
  30579. var fnsIR = IR[4];
  30580. var fns = [];
  30581. var tmpBuf = new Float32Array(1);
  30582. for (var i = 0, ii = fnsIR.length; i < ii; i++) {
  30583. fns.push(PDFFunction.fromIR(fnsIR[i]));
  30584. }
  30585. return function constructStichedFromIRResult(src, srcOffset,
  30586. dest, destOffset) {
  30587. var clip = function constructStichedFromIRClip(v, min, max) {
  30588. if (v > max) {
  30589. v = max;
  30590. } else if (v < min) {
  30591. v = min;
  30592. }
  30593. return v;
  30594. };
  30595. // clip to domain
  30596. var v = clip(src[srcOffset], domain[0], domain[1]);
  30597. // calulate which bound the value is in
  30598. for (var i = 0, ii = bounds.length; i < ii; ++i) {
  30599. if (v < bounds[i]) {
  30600. break;
  30601. }
  30602. }
  30603. // encode value into domain of function
  30604. var dmin = domain[0];
  30605. if (i > 0) {
  30606. dmin = bounds[i - 1];
  30607. }
  30608. var dmax = domain[1];
  30609. if (i < bounds.length) {
  30610. dmax = bounds[i];
  30611. }
  30612. var rmin = encode[2 * i];
  30613. var rmax = encode[2 * i + 1];
  30614. // Prevent the value from becoming NaN as a result
  30615. // of division by zero (fixes issue6113.pdf).
  30616. tmpBuf[0] = dmin === dmax ? rmin :
  30617. rmin + (v - dmin) * (rmax - rmin) / (dmax - dmin);
  30618. // call the appropriate function
  30619. fns[i](tmpBuf, 0, dest, destOffset);
  30620. };
  30621. },
  30622. constructPostScript: function PDFFunction_constructPostScript(fn, dict,
  30623. xref) {
  30624. var domain = dict.get('Domain');
  30625. var range = dict.get('Range');
  30626. if (!domain) {
  30627. error('No domain.');
  30628. }
  30629. if (!range) {
  30630. error('No range.');
  30631. }
  30632. var lexer = new PostScriptLexer(fn);
  30633. var parser = new PostScriptParser(lexer);
  30634. var code = parser.parse();
  30635. return [CONSTRUCT_POSTSCRIPT, domain, range, code];
  30636. },
  30637. constructPostScriptFromIR: function PDFFunction_constructPostScriptFromIR(
  30638. IR) {
  30639. var domain = IR[1];
  30640. var range = IR[2];
  30641. var code = IR[3];
  30642. var compiled = (new PostScriptCompiler()).compile(code, domain, range);
  30643. if (compiled) {
  30644. // Compiled function consists of simple expressions such as addition,
  30645. // subtraction, Math.max, and also contains 'var' and 'return'
  30646. // statements. See the generation in the PostScriptCompiler below.
  30647. /*jshint -W054 */
  30648. return new Function('src', 'srcOffset', 'dest', 'destOffset', compiled);
  30649. }
  30650. info('Unable to compile PS function');
  30651. var numOutputs = range.length >> 1;
  30652. var numInputs = domain.length >> 1;
  30653. var evaluator = new PostScriptEvaluator(code);
  30654. // Cache the values for a big speed up, the cache size is limited though
  30655. // since the number of possible values can be huge from a PS function.
  30656. var cache = {};
  30657. // The MAX_CACHE_SIZE is set to ~4x the maximum number of distinct values
  30658. // seen in our tests.
  30659. var MAX_CACHE_SIZE = 2048 * 4;
  30660. var cache_available = MAX_CACHE_SIZE;
  30661. var tmpBuf = new Float32Array(numInputs);
  30662. return function constructPostScriptFromIRResult(src, srcOffset,
  30663. dest, destOffset) {
  30664. var i, value;
  30665. var key = '';
  30666. var input = tmpBuf;
  30667. for (i = 0; i < numInputs; i++) {
  30668. value = src[srcOffset + i];
  30669. input[i] = value;
  30670. key += value + '_';
  30671. }
  30672. var cachedValue = cache[key];
  30673. if (cachedValue !== undefined) {
  30674. dest.set(cachedValue, destOffset);
  30675. return;
  30676. }
  30677. var output = new Float32Array(numOutputs);
  30678. var stack = evaluator.execute(input);
  30679. var stackIndex = stack.length - numOutputs;
  30680. for (i = 0; i < numOutputs; i++) {
  30681. value = stack[stackIndex + i];
  30682. var bound = range[i * 2];
  30683. if (value < bound) {
  30684. value = bound;
  30685. } else {
  30686. bound = range[i * 2 +1];
  30687. if (value > bound) {
  30688. value = bound;
  30689. }
  30690. }
  30691. output[i] = value;
  30692. }
  30693. if (cache_available > 0) {
  30694. cache_available--;
  30695. cache[key] = output;
  30696. }
  30697. dest.set(output, destOffset);
  30698. };
  30699. }
  30700. };
  30701. })();
  30702. function isPDFFunction(v) {
  30703. var fnDict;
  30704. if (typeof v !== 'object') {
  30705. return false;
  30706. } else if (isDict(v)) {
  30707. fnDict = v;
  30708. } else if (isStream(v)) {
  30709. fnDict = v.dict;
  30710. } else {
  30711. return false;
  30712. }
  30713. return fnDict.has('FunctionType');
  30714. }
  30715. var PostScriptStack = (function PostScriptStackClosure() {
  30716. var MAX_STACK_SIZE = 100;
  30717. function PostScriptStack(initialStack) {
  30718. this.stack = !initialStack ? [] :
  30719. Array.prototype.slice.call(initialStack, 0);
  30720. }
  30721. PostScriptStack.prototype = {
  30722. push: function PostScriptStack_push(value) {
  30723. if (this.stack.length >= MAX_STACK_SIZE) {
  30724. error('PostScript function stack overflow.');
  30725. }
  30726. this.stack.push(value);
  30727. },
  30728. pop: function PostScriptStack_pop() {
  30729. if (this.stack.length <= 0) {
  30730. error('PostScript function stack underflow.');
  30731. }
  30732. return this.stack.pop();
  30733. },
  30734. copy: function PostScriptStack_copy(n) {
  30735. if (this.stack.length + n >= MAX_STACK_SIZE) {
  30736. error('PostScript function stack overflow.');
  30737. }
  30738. var stack = this.stack;
  30739. for (var i = stack.length - n, j = n - 1; j >= 0; j--, i++) {
  30740. stack.push(stack[i]);
  30741. }
  30742. },
  30743. index: function PostScriptStack_index(n) {
  30744. this.push(this.stack[this.stack.length - n - 1]);
  30745. },
  30746. // rotate the last n stack elements p times
  30747. roll: function PostScriptStack_roll(n, p) {
  30748. var stack = this.stack;
  30749. var l = stack.length - n;
  30750. var r = stack.length - 1, c = l + (p - Math.floor(p / n) * n), i, j, t;
  30751. for (i = l, j = r; i < j; i++, j--) {
  30752. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  30753. }
  30754. for (i = l, j = c - 1; i < j; i++, j--) {
  30755. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  30756. }
  30757. for (i = c, j = r; i < j; i++, j--) {
  30758. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  30759. }
  30760. }
  30761. };
  30762. return PostScriptStack;
  30763. })();
  30764. var PostScriptEvaluator = (function PostScriptEvaluatorClosure() {
  30765. function PostScriptEvaluator(operators) {
  30766. this.operators = operators;
  30767. }
  30768. PostScriptEvaluator.prototype = {
  30769. execute: function PostScriptEvaluator_execute(initialStack) {
  30770. var stack = new PostScriptStack(initialStack);
  30771. var counter = 0;
  30772. var operators = this.operators;
  30773. var length = operators.length;
  30774. var operator, a, b;
  30775. while (counter < length) {
  30776. operator = operators[counter++];
  30777. if (typeof operator === 'number') {
  30778. // Operator is really an operand and should be pushed to the stack.
  30779. stack.push(operator);
  30780. continue;
  30781. }
  30782. switch (operator) {
  30783. // non standard ps operators
  30784. case 'jz': // jump if false
  30785. b = stack.pop();
  30786. a = stack.pop();
  30787. if (!a) {
  30788. counter = b;
  30789. }
  30790. break;
  30791. case 'j': // jump
  30792. a = stack.pop();
  30793. counter = a;
  30794. break;
  30795. // all ps operators in alphabetical order (excluding if/ifelse)
  30796. case 'abs':
  30797. a = stack.pop();
  30798. stack.push(Math.abs(a));
  30799. break;
  30800. case 'add':
  30801. b = stack.pop();
  30802. a = stack.pop();
  30803. stack.push(a + b);
  30804. break;
  30805. case 'and':
  30806. b = stack.pop();
  30807. a = stack.pop();
  30808. if (isBool(a) && isBool(b)) {
  30809. stack.push(a && b);
  30810. } else {
  30811. stack.push(a & b);
  30812. }
  30813. break;
  30814. case 'atan':
  30815. a = stack.pop();
  30816. stack.push(Math.atan(a));
  30817. break;
  30818. case 'bitshift':
  30819. b = stack.pop();
  30820. a = stack.pop();
  30821. if (a > 0) {
  30822. stack.push(a << b);
  30823. } else {
  30824. stack.push(a >> b);
  30825. }
  30826. break;
  30827. case 'ceiling':
  30828. a = stack.pop();
  30829. stack.push(Math.ceil(a));
  30830. break;
  30831. case 'copy':
  30832. a = stack.pop();
  30833. stack.copy(a);
  30834. break;
  30835. case 'cos':
  30836. a = stack.pop();
  30837. stack.push(Math.cos(a));
  30838. break;
  30839. case 'cvi':
  30840. a = stack.pop() | 0;
  30841. stack.push(a);
  30842. break;
  30843. case 'cvr':
  30844. // noop
  30845. break;
  30846. case 'div':
  30847. b = stack.pop();
  30848. a = stack.pop();
  30849. stack.push(a / b);
  30850. break;
  30851. case 'dup':
  30852. stack.copy(1);
  30853. break;
  30854. case 'eq':
  30855. b = stack.pop();
  30856. a = stack.pop();
  30857. stack.push(a === b);
  30858. break;
  30859. case 'exch':
  30860. stack.roll(2, 1);
  30861. break;
  30862. case 'exp':
  30863. b = stack.pop();
  30864. a = stack.pop();
  30865. stack.push(Math.pow(a, b));
  30866. break;
  30867. case 'false':
  30868. stack.push(false);
  30869. break;
  30870. case 'floor':
  30871. a = stack.pop();
  30872. stack.push(Math.floor(a));
  30873. break;
  30874. case 'ge':
  30875. b = stack.pop();
  30876. a = stack.pop();
  30877. stack.push(a >= b);
  30878. break;
  30879. case 'gt':
  30880. b = stack.pop();
  30881. a = stack.pop();
  30882. stack.push(a > b);
  30883. break;
  30884. case 'idiv':
  30885. b = stack.pop();
  30886. a = stack.pop();
  30887. stack.push((a / b) | 0);
  30888. break;
  30889. case 'index':
  30890. a = stack.pop();
  30891. stack.index(a);
  30892. break;
  30893. case 'le':
  30894. b = stack.pop();
  30895. a = stack.pop();
  30896. stack.push(a <= b);
  30897. break;
  30898. case 'ln':
  30899. a = stack.pop();
  30900. stack.push(Math.log(a));
  30901. break;
  30902. case 'log':
  30903. a = stack.pop();
  30904. stack.push(Math.log(a) / Math.LN10);
  30905. break;
  30906. case 'lt':
  30907. b = stack.pop();
  30908. a = stack.pop();
  30909. stack.push(a < b);
  30910. break;
  30911. case 'mod':
  30912. b = stack.pop();
  30913. a = stack.pop();
  30914. stack.push(a % b);
  30915. break;
  30916. case 'mul':
  30917. b = stack.pop();
  30918. a = stack.pop();
  30919. stack.push(a * b);
  30920. break;
  30921. case 'ne':
  30922. b = stack.pop();
  30923. a = stack.pop();
  30924. stack.push(a !== b);
  30925. break;
  30926. case 'neg':
  30927. a = stack.pop();
  30928. stack.push(-a);
  30929. break;
  30930. case 'not':
  30931. a = stack.pop();
  30932. if (isBool(a)) {
  30933. stack.push(!a);
  30934. } else {
  30935. stack.push(~a);
  30936. }
  30937. break;
  30938. case 'or':
  30939. b = stack.pop();
  30940. a = stack.pop();
  30941. if (isBool(a) && isBool(b)) {
  30942. stack.push(a || b);
  30943. } else {
  30944. stack.push(a | b);
  30945. }
  30946. break;
  30947. case 'pop':
  30948. stack.pop();
  30949. break;
  30950. case 'roll':
  30951. b = stack.pop();
  30952. a = stack.pop();
  30953. stack.roll(a, b);
  30954. break;
  30955. case 'round':
  30956. a = stack.pop();
  30957. stack.push(Math.round(a));
  30958. break;
  30959. case 'sin':
  30960. a = stack.pop();
  30961. stack.push(Math.sin(a));
  30962. break;
  30963. case 'sqrt':
  30964. a = stack.pop();
  30965. stack.push(Math.sqrt(a));
  30966. break;
  30967. case 'sub':
  30968. b = stack.pop();
  30969. a = stack.pop();
  30970. stack.push(a - b);
  30971. break;
  30972. case 'true':
  30973. stack.push(true);
  30974. break;
  30975. case 'truncate':
  30976. a = stack.pop();
  30977. a = a < 0 ? Math.ceil(a) : Math.floor(a);
  30978. stack.push(a);
  30979. break;
  30980. case 'xor':
  30981. b = stack.pop();
  30982. a = stack.pop();
  30983. if (isBool(a) && isBool(b)) {
  30984. stack.push(a !== b);
  30985. } else {
  30986. stack.push(a ^ b);
  30987. }
  30988. break;
  30989. default:
  30990. error('Unknown operator ' + operator);
  30991. break;
  30992. }
  30993. }
  30994. return stack.stack;
  30995. }
  30996. };
  30997. return PostScriptEvaluator;
  30998. })();
  30999. // Most of the PDFs functions consist of simple operations such as:
  31000. // roll, exch, sub, cvr, pop, index, dup, mul, if, gt, add.
  31001. //
  31002. // We can compile most of such programs, and at the same moment, we can
  31003. // optimize some expressions using basic math properties. Keeping track of
  31004. // min/max values will allow us to avoid extra Math.min/Math.max calls.
  31005. var PostScriptCompiler = (function PostScriptCompilerClosure() {
  31006. function AstNode(type) {
  31007. this.type = type;
  31008. }
  31009. AstNode.prototype.visit = function (visitor) {
  31010. throw new Error('abstract method');
  31011. };
  31012. function AstArgument(index, min, max) {
  31013. AstNode.call(this, 'args');
  31014. this.index = index;
  31015. this.min = min;
  31016. this.max = max;
  31017. }
  31018. AstArgument.prototype = Object.create(AstNode.prototype);
  31019. AstArgument.prototype.visit = function (visitor) {
  31020. visitor.visitArgument(this);
  31021. };
  31022. function AstLiteral(number) {
  31023. AstNode.call(this, 'literal');
  31024. this.number = number;
  31025. this.min = number;
  31026. this.max = number;
  31027. }
  31028. AstLiteral.prototype = Object.create(AstNode.prototype);
  31029. AstLiteral.prototype.visit = function (visitor) {
  31030. visitor.visitLiteral(this);
  31031. };
  31032. function AstBinaryOperation(op, arg1, arg2, min, max) {
  31033. AstNode.call(this, 'binary');
  31034. this.op = op;
  31035. this.arg1 = arg1;
  31036. this.arg2 = arg2;
  31037. this.min = min;
  31038. this.max = max;
  31039. }
  31040. AstBinaryOperation.prototype = Object.create(AstNode.prototype);
  31041. AstBinaryOperation.prototype.visit = function (visitor) {
  31042. visitor.visitBinaryOperation(this);
  31043. };
  31044. function AstMin(arg, max) {
  31045. AstNode.call(this, 'max');
  31046. this.arg = arg;
  31047. this.min = arg.min;
  31048. this.max = max;
  31049. }
  31050. AstMin.prototype = Object.create(AstNode.prototype);
  31051. AstMin.prototype.visit = function (visitor) {
  31052. visitor.visitMin(this);
  31053. };
  31054. function AstVariable(index, min, max) {
  31055. AstNode.call(this, 'var');
  31056. this.index = index;
  31057. this.min = min;
  31058. this.max = max;
  31059. }
  31060. AstVariable.prototype = Object.create(AstNode.prototype);
  31061. AstVariable.prototype.visit = function (visitor) {
  31062. visitor.visitVariable(this);
  31063. };
  31064. function AstVariableDefinition(variable, arg) {
  31065. AstNode.call(this, 'definition');
  31066. this.variable = variable;
  31067. this.arg = arg;
  31068. }
  31069. AstVariableDefinition.prototype = Object.create(AstNode.prototype);
  31070. AstVariableDefinition.prototype.visit = function (visitor) {
  31071. visitor.visitVariableDefinition(this);
  31072. };
  31073. function ExpressionBuilderVisitor() {
  31074. this.parts = [];
  31075. }
  31076. ExpressionBuilderVisitor.prototype = {
  31077. visitArgument: function (arg) {
  31078. this.parts.push('Math.max(', arg.min, ', Math.min(',
  31079. arg.max, ', src[srcOffset + ', arg.index, ']))');
  31080. },
  31081. visitVariable: function (variable) {
  31082. this.parts.push('v', variable.index);
  31083. },
  31084. visitLiteral: function (literal) {
  31085. this.parts.push(literal.number);
  31086. },
  31087. visitBinaryOperation: function (operation) {
  31088. this.parts.push('(');
  31089. operation.arg1.visit(this);
  31090. this.parts.push(' ', operation.op, ' ');
  31091. operation.arg2.visit(this);
  31092. this.parts.push(')');
  31093. },
  31094. visitVariableDefinition: function (definition) {
  31095. this.parts.push('var ');
  31096. definition.variable.visit(this);
  31097. this.parts.push(' = ');
  31098. definition.arg.visit(this);
  31099. this.parts.push(';');
  31100. },
  31101. visitMin: function (max) {
  31102. this.parts.push('Math.min(');
  31103. max.arg.visit(this);
  31104. this.parts.push(', ', max.max, ')');
  31105. },
  31106. toString: function () {
  31107. return this.parts.join('');
  31108. }
  31109. };
  31110. function buildAddOperation(num1, num2) {
  31111. if (num2.type === 'literal' && num2.number === 0) {
  31112. // optimization: second operand is 0
  31113. return num1;
  31114. }
  31115. if (num1.type === 'literal' && num1.number === 0) {
  31116. // optimization: first operand is 0
  31117. return num2;
  31118. }
  31119. if (num2.type === 'literal' && num1.type === 'literal') {
  31120. // optimization: operands operand are literals
  31121. return new AstLiteral(num1.number + num2.number);
  31122. }
  31123. return new AstBinaryOperation('+', num1, num2,
  31124. num1.min + num2.min, num1.max + num2.max);
  31125. }
  31126. function buildMulOperation(num1, num2) {
  31127. if (num2.type === 'literal') {
  31128. // optimization: second operands is a literal...
  31129. if (num2.number === 0) {
  31130. return new AstLiteral(0); // and it's 0
  31131. } else if (num2.number === 1) {
  31132. return num1; // and it's 1
  31133. } else if (num1.type === 'literal') {
  31134. // ... and first operands is a literal too
  31135. return new AstLiteral(num1.number * num2.number);
  31136. }
  31137. }
  31138. if (num1.type === 'literal') {
  31139. // optimization: first operands is a literal...
  31140. if (num1.number === 0) {
  31141. return new AstLiteral(0); // and it's 0
  31142. } else if (num1.number === 1) {
  31143. return num2; // and it's 1
  31144. }
  31145. }
  31146. var min = Math.min(num1.min * num2.min, num1.min * num2.max,
  31147. num1.max * num2.min, num1.max * num2.max);
  31148. var max = Math.max(num1.min * num2.min, num1.min * num2.max,
  31149. num1.max * num2.min, num1.max * num2.max);
  31150. return new AstBinaryOperation('*', num1, num2, min, max);
  31151. }
  31152. function buildSubOperation(num1, num2) {
  31153. if (num2.type === 'literal') {
  31154. // optimization: second operands is a literal...
  31155. if (num2.number === 0) {
  31156. return num1; // ... and it's 0
  31157. } else if (num1.type === 'literal') {
  31158. // ... and first operands is a literal too
  31159. return new AstLiteral(num1.number - num2.number);
  31160. }
  31161. }
  31162. if (num2.type === 'binary' && num2.op === '-' &&
  31163. num1.type === 'literal' && num1.number === 1 &&
  31164. num2.arg1.type === 'literal' && num2.arg1.number === 1) {
  31165. // optimization for case: 1 - (1 - x)
  31166. return num2.arg2;
  31167. }
  31168. return new AstBinaryOperation('-', num1, num2,
  31169. num1.min - num2.max, num1.max - num2.min);
  31170. }
  31171. function buildMinOperation(num1, max) {
  31172. if (num1.min >= max) {
  31173. // optimization: num1 min value is not less than required max
  31174. return new AstLiteral(max); // just returning max
  31175. } else if (num1.max <= max) {
  31176. // optimization: num1 max value is not greater than required max
  31177. return num1; // just returning an argument
  31178. }
  31179. return new AstMin(num1, max);
  31180. }
  31181. function PostScriptCompiler() {}
  31182. PostScriptCompiler.prototype = {
  31183. compile: function PostScriptCompiler_compile(code, domain, range) {
  31184. var stack = [];
  31185. var i, ii;
  31186. var instructions = [];
  31187. var inputSize = domain.length >> 1, outputSize = range.length >> 1;
  31188. var lastRegister = 0;
  31189. var n, j;
  31190. var num1, num2, ast1, ast2, tmpVar, item;
  31191. for (i = 0; i < inputSize; i++) {
  31192. stack.push(new AstArgument(i, domain[i * 2], domain[i * 2 + 1]));
  31193. }
  31194. for (i = 0, ii = code.length; i < ii; i++) {
  31195. item = code[i];
  31196. if (typeof item === 'number') {
  31197. stack.push(new AstLiteral(item));
  31198. continue;
  31199. }
  31200. switch (item) {
  31201. case 'add':
  31202. if (stack.length < 2) {
  31203. return null;
  31204. }
  31205. num2 = stack.pop();
  31206. num1 = stack.pop();
  31207. stack.push(buildAddOperation(num1, num2));
  31208. break;
  31209. case 'cvr':
  31210. if (stack.length < 1) {
  31211. return null;
  31212. }
  31213. break;
  31214. case 'mul':
  31215. if (stack.length < 2) {
  31216. return null;
  31217. }
  31218. num2 = stack.pop();
  31219. num1 = stack.pop();
  31220. stack.push(buildMulOperation(num1, num2));
  31221. break;
  31222. case 'sub':
  31223. if (stack.length < 2) {
  31224. return null;
  31225. }
  31226. num2 = stack.pop();
  31227. num1 = stack.pop();
  31228. stack.push(buildSubOperation(num1, num2));
  31229. break;
  31230. case 'exch':
  31231. if (stack.length < 2) {
  31232. return null;
  31233. }
  31234. ast1 = stack.pop(); ast2 = stack.pop();
  31235. stack.push(ast1, ast2);
  31236. break;
  31237. case 'pop':
  31238. if (stack.length < 1) {
  31239. return null;
  31240. }
  31241. stack.pop();
  31242. break;
  31243. case 'index':
  31244. if (stack.length < 1) {
  31245. return null;
  31246. }
  31247. num1 = stack.pop();
  31248. if (num1.type !== 'literal') {
  31249. return null;
  31250. }
  31251. n = num1.number;
  31252. if (n < 0 || (n|0) !== n || stack.length < n) {
  31253. return null;
  31254. }
  31255. ast1 = stack[stack.length - n - 1];
  31256. if (ast1.type === 'literal' || ast1.type === 'var') {
  31257. stack.push(ast1);
  31258. break;
  31259. }
  31260. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  31261. stack[stack.length - n - 1] = tmpVar;
  31262. stack.push(tmpVar);
  31263. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  31264. break;
  31265. case 'dup':
  31266. if (stack.length < 1) {
  31267. return null;
  31268. }
  31269. if (typeof code[i + 1] === 'number' && code[i + 2] === 'gt' &&
  31270. code[i + 3] === i + 7 && code[i + 4] === 'jz' &&
  31271. code[i + 5] === 'pop' && code[i + 6] === code[i + 1]) {
  31272. // special case of the commands sequence for the min operation
  31273. num1 = stack.pop();
  31274. stack.push(buildMinOperation(num1, code[i + 1]));
  31275. i += 6;
  31276. break;
  31277. }
  31278. ast1 = stack[stack.length - 1];
  31279. if (ast1.type === 'literal' || ast1.type === 'var') {
  31280. // we don't have to save into intermediate variable a literal or
  31281. // variable.
  31282. stack.push(ast1);
  31283. break;
  31284. }
  31285. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  31286. stack[stack.length - 1] = tmpVar;
  31287. stack.push(tmpVar);
  31288. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  31289. break;
  31290. case 'roll':
  31291. if (stack.length < 2) {
  31292. return null;
  31293. }
  31294. num2 = stack.pop();
  31295. num1 = stack.pop();
  31296. if (num2.type !== 'literal' || num1.type !== 'literal') {
  31297. // both roll operands must be numbers
  31298. return null;
  31299. }
  31300. j = num2.number;
  31301. n = num1.number;
  31302. if (n <= 0 || (n|0) !== n || (j|0) !== j || stack.length < n) {
  31303. // ... and integers
  31304. return null;
  31305. }
  31306. j = ((j % n) + n) % n;
  31307. if (j === 0) {
  31308. break; // just skipping -- there are nothing to rotate
  31309. }
  31310. Array.prototype.push.apply(stack,
  31311. stack.splice(stack.length - n, n - j));
  31312. break;
  31313. default:
  31314. return null; // unsupported operator
  31315. }
  31316. }
  31317. if (stack.length !== outputSize) {
  31318. return null;
  31319. }
  31320. var result = [];
  31321. instructions.forEach(function (instruction) {
  31322. var statementBuilder = new ExpressionBuilderVisitor();
  31323. instruction.visit(statementBuilder);
  31324. result.push(statementBuilder.toString());
  31325. });
  31326. stack.forEach(function (expr, i) {
  31327. var statementBuilder = new ExpressionBuilderVisitor();
  31328. expr.visit(statementBuilder);
  31329. var min = range[i * 2], max = range[i * 2 + 1];
  31330. var out = [statementBuilder.toString()];
  31331. if (min > expr.min) {
  31332. out.unshift('Math.max(', min, ', ');
  31333. out.push(')');
  31334. }
  31335. if (max < expr.max) {
  31336. out.unshift('Math.min(', max, ', ');
  31337. out.push(')');
  31338. }
  31339. out.unshift('dest[destOffset + ', i, '] = ');
  31340. out.push(';');
  31341. result.push(out.join(''));
  31342. });
  31343. return result.join('\n');
  31344. }
  31345. };
  31346. return PostScriptCompiler;
  31347. })();
  31348. exports.isPDFFunction = isPDFFunction;
  31349. exports.PDFFunction = PDFFunction;
  31350. exports.PostScriptEvaluator = PostScriptEvaluator;
  31351. exports.PostScriptCompiler = PostScriptCompiler;
  31352. }));
  31353. (function (root, factory) {
  31354. {
  31355. factory((root.pdfjsCoreColorSpace = {}), root.pdfjsSharedUtil,
  31356. root.pdfjsCorePrimitives, root.pdfjsCoreFunction, root.pdfjsCoreStream);
  31357. }
  31358. }(this, function (exports, sharedUtil, corePrimitives, coreFunction,
  31359. coreStream) {
  31360. var error = sharedUtil.error;
  31361. var info = sharedUtil.info;
  31362. var isArray = sharedUtil.isArray;
  31363. var isString = sharedUtil.isString;
  31364. var shadow = sharedUtil.shadow;
  31365. var warn = sharedUtil.warn;
  31366. var isDict = corePrimitives.isDict;
  31367. var isName = corePrimitives.isName;
  31368. var isStream = corePrimitives.isStream;
  31369. var PDFFunction = coreFunction.PDFFunction;
  31370. var coreImage; // see _setCoreImage below
  31371. var PDFImage; // = coreImage.PDFImage;
  31372. var ColorSpace = (function ColorSpaceClosure() {
  31373. // Constructor should define this.numComps, this.defaultColor, this.name
  31374. function ColorSpace() {
  31375. error('should not call ColorSpace constructor');
  31376. }
  31377. ColorSpace.prototype = {
  31378. /**
  31379. * Converts the color value to the RGB color. The color components are
  31380. * located in the src array starting from the srcOffset. Returns the array
  31381. * of the rgb components, each value ranging from [0,255].
  31382. */
  31383. getRgb: function ColorSpace_getRgb(src, srcOffset) {
  31384. var rgb = new Uint8Array(3);
  31385. this.getRgbItem(src, srcOffset, rgb, 0);
  31386. return rgb;
  31387. },
  31388. /**
  31389. * Converts the color value to the RGB color, similar to the getRgb method.
  31390. * The result placed into the dest array starting from the destOffset.
  31391. */
  31392. getRgbItem: function ColorSpace_getRgbItem(src, srcOffset,
  31393. dest, destOffset) {
  31394. error('Should not call ColorSpace.getRgbItem');
  31395. },
  31396. /**
  31397. * Converts the specified number of the color values to the RGB colors.
  31398. * The colors are located in the src array starting from the srcOffset.
  31399. * The result is placed into the dest array starting from the destOffset.
  31400. * The src array items shall be in [0,2^bits) range, the dest array items
  31401. * will be in [0,255] range. alpha01 indicates how many alpha components
  31402. * there are in the dest array; it will be either 0 (RGB array) or 1 (RGBA
  31403. * array).
  31404. */
  31405. getRgbBuffer: function ColorSpace_getRgbBuffer(src, srcOffset, count,
  31406. dest, destOffset, bits,
  31407. alpha01) {
  31408. error('Should not call ColorSpace.getRgbBuffer');
  31409. },
  31410. /**
  31411. * Determines the number of bytes required to store the result of the
  31412. * conversion done by the getRgbBuffer method. As in getRgbBuffer,
  31413. * |alpha01| is either 0 (RGB output) or 1 (RGBA output).
  31414. */
  31415. getOutputLength: function ColorSpace_getOutputLength(inputLength,
  31416. alpha01) {
  31417. error('Should not call ColorSpace.getOutputLength');
  31418. },
  31419. /**
  31420. * Returns true if source data will be equal the result/output data.
  31421. */
  31422. isPassthrough: function ColorSpace_isPassthrough(bits) {
  31423. return false;
  31424. },
  31425. /**
  31426. * Fills in the RGB colors in the destination buffer. alpha01 indicates
  31427. * how many alpha components there are in the dest array; it will be either
  31428. * 0 (RGB array) or 1 (RGBA array).
  31429. */
  31430. fillRgb: function ColorSpace_fillRgb(dest, originalWidth,
  31431. originalHeight, width, height,
  31432. actualHeight, bpc, comps, alpha01) {
  31433. var count = originalWidth * originalHeight;
  31434. var rgbBuf = null;
  31435. var numComponentColors = 1 << bpc;
  31436. var needsResizing = originalHeight !== height || originalWidth !== width;
  31437. var i, ii;
  31438. if (this.isPassthrough(bpc)) {
  31439. rgbBuf = comps;
  31440. } else if (this.numComps === 1 && count > numComponentColors &&
  31441. this.name !== 'DeviceGray' && this.name !== 'DeviceRGB') {
  31442. // Optimization: create a color map when there is just one component and
  31443. // we are converting more colors than the size of the color map. We
  31444. // don't build the map if the colorspace is gray or rgb since those
  31445. // methods are faster than building a map. This mainly offers big speed
  31446. // ups for indexed and alternate colorspaces.
  31447. //
  31448. // TODO it may be worth while to cache the color map. While running
  31449. // testing I never hit a cache so I will leave that out for now (perhaps
  31450. // we are reparsing colorspaces too much?).
  31451. var allColors = bpc <= 8 ? new Uint8Array(numComponentColors) :
  31452. new Uint16Array(numComponentColors);
  31453. var key;
  31454. for (i = 0; i < numComponentColors; i++) {
  31455. allColors[i] = i;
  31456. }
  31457. var colorMap = new Uint8Array(numComponentColors * 3);
  31458. this.getRgbBuffer(allColors, 0, numComponentColors, colorMap, 0, bpc,
  31459. /* alpha01 = */ 0);
  31460. var destPos, rgbPos;
  31461. if (!needsResizing) {
  31462. // Fill in the RGB values directly into |dest|.
  31463. destPos = 0;
  31464. for (i = 0; i < count; ++i) {
  31465. key = comps[i] * 3;
  31466. dest[destPos++] = colorMap[key];
  31467. dest[destPos++] = colorMap[key + 1];
  31468. dest[destPos++] = colorMap[key + 2];
  31469. destPos += alpha01;
  31470. }
  31471. } else {
  31472. rgbBuf = new Uint8Array(count * 3);
  31473. rgbPos = 0;
  31474. for (i = 0; i < count; ++i) {
  31475. key = comps[i] * 3;
  31476. rgbBuf[rgbPos++] = colorMap[key];
  31477. rgbBuf[rgbPos++] = colorMap[key + 1];
  31478. rgbBuf[rgbPos++] = colorMap[key + 2];
  31479. }
  31480. }
  31481. } else {
  31482. if (!needsResizing) {
  31483. // Fill in the RGB values directly into |dest|.
  31484. this.getRgbBuffer(comps, 0, width * actualHeight, dest, 0, bpc,
  31485. alpha01);
  31486. } else {
  31487. rgbBuf = new Uint8Array(count * 3);
  31488. this.getRgbBuffer(comps, 0, count, rgbBuf, 0, bpc,
  31489. /* alpha01 = */ 0);
  31490. }
  31491. }
  31492. if (rgbBuf) {
  31493. if (needsResizing) {
  31494. PDFImage.resize(rgbBuf, bpc, 3, originalWidth, originalHeight, width,
  31495. height, dest, alpha01);
  31496. } else {
  31497. rgbPos = 0;
  31498. destPos = 0;
  31499. for (i = 0, ii = width * actualHeight; i < ii; i++) {
  31500. dest[destPos++] = rgbBuf[rgbPos++];
  31501. dest[destPos++] = rgbBuf[rgbPos++];
  31502. dest[destPos++] = rgbBuf[rgbPos++];
  31503. destPos += alpha01;
  31504. }
  31505. }
  31506. }
  31507. },
  31508. /**
  31509. * True if the colorspace has components in the default range of [0, 1].
  31510. * This should be true for all colorspaces except for lab color spaces
  31511. * which are [0,100], [-128, 127], [-128, 127].
  31512. */
  31513. usesZeroToOneRange: true
  31514. };
  31515. ColorSpace.parse = function ColorSpace_parse(cs, xref, res) {
  31516. var IR = ColorSpace.parseToIR(cs, xref, res);
  31517. if (IR instanceof AlternateCS) {
  31518. return IR;
  31519. }
  31520. return ColorSpace.fromIR(IR);
  31521. };
  31522. ColorSpace.fromIR = function ColorSpace_fromIR(IR) {
  31523. var name = isArray(IR) ? IR[0] : IR;
  31524. var whitePoint, blackPoint, gamma;
  31525. switch (name) {
  31526. case 'DeviceGrayCS':
  31527. return this.singletons.gray;
  31528. case 'DeviceRgbCS':
  31529. return this.singletons.rgb;
  31530. case 'DeviceCmykCS':
  31531. return this.singletons.cmyk;
  31532. case 'CalGrayCS':
  31533. whitePoint = IR[1].WhitePoint;
  31534. blackPoint = IR[1].BlackPoint;
  31535. gamma = IR[1].Gamma;
  31536. return new CalGrayCS(whitePoint, blackPoint, gamma);
  31537. case 'CalRGBCS':
  31538. whitePoint = IR[1].WhitePoint;
  31539. blackPoint = IR[1].BlackPoint;
  31540. gamma = IR[1].Gamma;
  31541. var matrix = IR[1].Matrix;
  31542. return new CalRGBCS(whitePoint, blackPoint, gamma, matrix);
  31543. case 'PatternCS':
  31544. var basePatternCS = IR[1];
  31545. if (basePatternCS) {
  31546. basePatternCS = ColorSpace.fromIR(basePatternCS);
  31547. }
  31548. return new PatternCS(basePatternCS);
  31549. case 'IndexedCS':
  31550. var baseIndexedCS = IR[1];
  31551. var hiVal = IR[2];
  31552. var lookup = IR[3];
  31553. return new IndexedCS(ColorSpace.fromIR(baseIndexedCS), hiVal, lookup);
  31554. case 'AlternateCS':
  31555. var numComps = IR[1];
  31556. var alt = IR[2];
  31557. var tintFnIR = IR[3];
  31558. return new AlternateCS(numComps, ColorSpace.fromIR(alt),
  31559. PDFFunction.fromIR(tintFnIR));
  31560. case 'LabCS':
  31561. whitePoint = IR[1].WhitePoint;
  31562. blackPoint = IR[1].BlackPoint;
  31563. var range = IR[1].Range;
  31564. return new LabCS(whitePoint, blackPoint, range);
  31565. default:
  31566. error('Unknown name ' + name);
  31567. }
  31568. return null;
  31569. };
  31570. ColorSpace.parseToIR = function ColorSpace_parseToIR(cs, xref, res) {
  31571. if (isName(cs)) {
  31572. var colorSpaces = res.get('ColorSpace');
  31573. if (isDict(colorSpaces)) {
  31574. var refcs = colorSpaces.get(cs.name);
  31575. if (refcs) {
  31576. cs = refcs;
  31577. }
  31578. }
  31579. }
  31580. cs = xref.fetchIfRef(cs);
  31581. var mode;
  31582. if (isName(cs)) {
  31583. mode = cs.name;
  31584. this.mode = mode;
  31585. switch (mode) {
  31586. case 'DeviceGray':
  31587. case 'G':
  31588. return 'DeviceGrayCS';
  31589. case 'DeviceRGB':
  31590. case 'RGB':
  31591. return 'DeviceRgbCS';
  31592. case 'DeviceCMYK':
  31593. case 'CMYK':
  31594. return 'DeviceCmykCS';
  31595. case 'Pattern':
  31596. return ['PatternCS', null];
  31597. default:
  31598. error('unrecognized colorspace ' + mode);
  31599. }
  31600. } else if (isArray(cs)) {
  31601. mode = xref.fetchIfRef(cs[0]).name;
  31602. this.mode = mode;
  31603. var numComps, params, alt;
  31604. switch (mode) {
  31605. case 'DeviceGray':
  31606. case 'G':
  31607. return 'DeviceGrayCS';
  31608. case 'DeviceRGB':
  31609. case 'RGB':
  31610. return 'DeviceRgbCS';
  31611. case 'DeviceCMYK':
  31612. case 'CMYK':
  31613. return 'DeviceCmykCS';
  31614. case 'CalGray':
  31615. params = xref.fetchIfRef(cs[1]).getAll();
  31616. return ['CalGrayCS', params];
  31617. case 'CalRGB':
  31618. params = xref.fetchIfRef(cs[1]).getAll();
  31619. return ['CalRGBCS', params];
  31620. case 'ICCBased':
  31621. var stream = xref.fetchIfRef(cs[1]);
  31622. var dict = stream.dict;
  31623. numComps = dict.get('N');
  31624. alt = dict.get('Alternate');
  31625. if (alt) {
  31626. var altIR = ColorSpace.parseToIR(alt, xref, res);
  31627. // Parse the /Alternate CS to ensure that the number of components
  31628. // are correct, and also (indirectly) that it is not a PatternCS.
  31629. var altCS = ColorSpace.fromIR(altIR);
  31630. if (altCS.numComps === numComps) {
  31631. return altIR;
  31632. }
  31633. warn('ICCBased color space: Ignoring incorrect /Alternate entry.');
  31634. }
  31635. if (numComps === 1) {
  31636. return 'DeviceGrayCS';
  31637. } else if (numComps === 3) {
  31638. return 'DeviceRgbCS';
  31639. } else if (numComps === 4) {
  31640. return 'DeviceCmykCS';
  31641. }
  31642. break;
  31643. case 'Pattern':
  31644. var basePatternCS = cs[1] || null;
  31645. if (basePatternCS) {
  31646. basePatternCS = ColorSpace.parseToIR(basePatternCS, xref, res);
  31647. }
  31648. return ['PatternCS', basePatternCS];
  31649. case 'Indexed':
  31650. case 'I':
  31651. var baseIndexedCS = ColorSpace.parseToIR(cs[1], xref, res);
  31652. var hiVal = xref.fetchIfRef(cs[2]) + 1;
  31653. var lookup = xref.fetchIfRef(cs[3]);
  31654. if (isStream(lookup)) {
  31655. lookup = lookup.getBytes();
  31656. }
  31657. return ['IndexedCS', baseIndexedCS, hiVal, lookup];
  31658. case 'Separation':
  31659. case 'DeviceN':
  31660. var name = xref.fetchIfRef(cs[1]);
  31661. numComps = 1;
  31662. if (isName(name)) {
  31663. numComps = 1;
  31664. } else if (isArray(name)) {
  31665. numComps = name.length;
  31666. }
  31667. alt = ColorSpace.parseToIR(cs[2], xref, res);
  31668. var tintFnIR = PDFFunction.getIR(xref, xref.fetchIfRef(cs[3]));
  31669. return ['AlternateCS', numComps, alt, tintFnIR];
  31670. case 'Lab':
  31671. params = xref.fetchIfRef(cs[1]).getAll();
  31672. return ['LabCS', params];
  31673. default:
  31674. error('unimplemented color space object "' + mode + '"');
  31675. }
  31676. } else {
  31677. error('unrecognized color space object: "' + cs + '"');
  31678. }
  31679. return null;
  31680. };
  31681. /**
  31682. * Checks if a decode map matches the default decode map for a color space.
  31683. * This handles the general decode maps where there are two values per
  31684. * component. e.g. [0, 1, 0, 1, 0, 1] for a RGB color.
  31685. * This does not handle Lab, Indexed, or Pattern decode maps since they are
  31686. * slightly different.
  31687. * @param {Array} decode Decode map (usually from an image).
  31688. * @param {Number} n Number of components the color space has.
  31689. */
  31690. ColorSpace.isDefaultDecode = function ColorSpace_isDefaultDecode(decode, n) {
  31691. if (!isArray(decode)) {
  31692. return true;
  31693. }
  31694. if (n * 2 !== decode.length) {
  31695. warn('The decode map is not the correct length');
  31696. return true;
  31697. }
  31698. for (var i = 0, ii = decode.length; i < ii; i += 2) {
  31699. if (decode[i] !== 0 || decode[i + 1] !== 1) {
  31700. return false;
  31701. }
  31702. }
  31703. return true;
  31704. };
  31705. ColorSpace.singletons = {
  31706. get gray() {
  31707. return shadow(this, 'gray', new DeviceGrayCS());
  31708. },
  31709. get rgb() {
  31710. return shadow(this, 'rgb', new DeviceRgbCS());
  31711. },
  31712. get cmyk() {
  31713. return shadow(this, 'cmyk', new DeviceCmykCS());
  31714. }
  31715. };
  31716. return ColorSpace;
  31717. })();
  31718. /**
  31719. * Alternate color space handles both Separation and DeviceN color spaces. A
  31720. * Separation color space is actually just a DeviceN with one color component.
  31721. * Both color spaces use a tinting function to convert colors to a base color
  31722. * space.
  31723. */
  31724. var AlternateCS = (function AlternateCSClosure() {
  31725. function AlternateCS(numComps, base, tintFn) {
  31726. this.name = 'Alternate';
  31727. this.numComps = numComps;
  31728. this.defaultColor = new Float32Array(numComps);
  31729. for (var i = 0; i < numComps; ++i) {
  31730. this.defaultColor[i] = 1;
  31731. }
  31732. this.base = base;
  31733. this.tintFn = tintFn;
  31734. this.tmpBuf = new Float32Array(base.numComps);
  31735. }
  31736. AlternateCS.prototype = {
  31737. getRgb: ColorSpace.prototype.getRgb,
  31738. getRgbItem: function AlternateCS_getRgbItem(src, srcOffset,
  31739. dest, destOffset) {
  31740. var tmpBuf = this.tmpBuf;
  31741. this.tintFn(src, srcOffset, tmpBuf, 0);
  31742. this.base.getRgbItem(tmpBuf, 0, dest, destOffset);
  31743. },
  31744. getRgbBuffer: function AlternateCS_getRgbBuffer(src, srcOffset, count,
  31745. dest, destOffset, bits,
  31746. alpha01) {
  31747. var tintFn = this.tintFn;
  31748. var base = this.base;
  31749. var scale = 1 / ((1 << bits) - 1);
  31750. var baseNumComps = base.numComps;
  31751. var usesZeroToOneRange = base.usesZeroToOneRange;
  31752. var isPassthrough = (base.isPassthrough(8) || !usesZeroToOneRange) &&
  31753. alpha01 === 0;
  31754. var pos = isPassthrough ? destOffset : 0;
  31755. var baseBuf = isPassthrough ? dest : new Uint8Array(baseNumComps * count);
  31756. var numComps = this.numComps;
  31757. var scaled = new Float32Array(numComps);
  31758. var tinted = new Float32Array(baseNumComps);
  31759. var i, j;
  31760. if (usesZeroToOneRange) {
  31761. for (i = 0; i < count; i++) {
  31762. for (j = 0; j < numComps; j++) {
  31763. scaled[j] = src[srcOffset++] * scale;
  31764. }
  31765. tintFn(scaled, 0, tinted, 0);
  31766. for (j = 0; j < baseNumComps; j++) {
  31767. baseBuf[pos++] = tinted[j] * 255;
  31768. }
  31769. }
  31770. } else {
  31771. for (i = 0; i < count; i++) {
  31772. for (j = 0; j < numComps; j++) {
  31773. scaled[j] = src[srcOffset++] * scale;
  31774. }
  31775. tintFn(scaled, 0, tinted, 0);
  31776. base.getRgbItem(tinted, 0, baseBuf, pos);
  31777. pos += baseNumComps;
  31778. }
  31779. }
  31780. if (!isPassthrough) {
  31781. base.getRgbBuffer(baseBuf, 0, count, dest, destOffset, 8, alpha01);
  31782. }
  31783. },
  31784. getOutputLength: function AlternateCS_getOutputLength(inputLength,
  31785. alpha01) {
  31786. return this.base.getOutputLength(inputLength *
  31787. this.base.numComps / this.numComps,
  31788. alpha01);
  31789. },
  31790. isPassthrough: ColorSpace.prototype.isPassthrough,
  31791. fillRgb: ColorSpace.prototype.fillRgb,
  31792. isDefaultDecode: function AlternateCS_isDefaultDecode(decodeMap) {
  31793. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  31794. },
  31795. usesZeroToOneRange: true
  31796. };
  31797. return AlternateCS;
  31798. })();
  31799. var PatternCS = (function PatternCSClosure() {
  31800. function PatternCS(baseCS) {
  31801. this.name = 'Pattern';
  31802. this.base = baseCS;
  31803. }
  31804. PatternCS.prototype = {};
  31805. return PatternCS;
  31806. })();
  31807. var IndexedCS = (function IndexedCSClosure() {
  31808. function IndexedCS(base, highVal, lookup) {
  31809. this.name = 'Indexed';
  31810. this.numComps = 1;
  31811. this.defaultColor = new Uint8Array([0]);
  31812. this.base = base;
  31813. this.highVal = highVal;
  31814. var baseNumComps = base.numComps;
  31815. var length = baseNumComps * highVal;
  31816. var lookupArray;
  31817. if (isStream(lookup)) {
  31818. lookupArray = new Uint8Array(length);
  31819. var bytes = lookup.getBytes(length);
  31820. lookupArray.set(bytes);
  31821. } else if (isString(lookup)) {
  31822. lookupArray = new Uint8Array(length);
  31823. for (var i = 0; i < length; ++i) {
  31824. lookupArray[i] = lookup.charCodeAt(i);
  31825. }
  31826. } else if (lookup instanceof Uint8Array || lookup instanceof Array) {
  31827. lookupArray = lookup;
  31828. } else {
  31829. error('Unrecognized lookup table: ' + lookup);
  31830. }
  31831. this.lookup = lookupArray;
  31832. }
  31833. IndexedCS.prototype = {
  31834. getRgb: ColorSpace.prototype.getRgb,
  31835. getRgbItem: function IndexedCS_getRgbItem(src, srcOffset,
  31836. dest, destOffset) {
  31837. var numComps = this.base.numComps;
  31838. var start = src[srcOffset] * numComps;
  31839. this.base.getRgbItem(this.lookup, start, dest, destOffset);
  31840. },
  31841. getRgbBuffer: function IndexedCS_getRgbBuffer(src, srcOffset, count,
  31842. dest, destOffset, bits,
  31843. alpha01) {
  31844. var base = this.base;
  31845. var numComps = base.numComps;
  31846. var outputDelta = base.getOutputLength(numComps, alpha01);
  31847. var lookup = this.lookup;
  31848. for (var i = 0; i < count; ++i) {
  31849. var lookupPos = src[srcOffset++] * numComps;
  31850. base.getRgbBuffer(lookup, lookupPos, 1, dest, destOffset, 8, alpha01);
  31851. destOffset += outputDelta;
  31852. }
  31853. },
  31854. getOutputLength: function IndexedCS_getOutputLength(inputLength, alpha01) {
  31855. return this.base.getOutputLength(inputLength * this.base.numComps,
  31856. alpha01);
  31857. },
  31858. isPassthrough: ColorSpace.prototype.isPassthrough,
  31859. fillRgb: ColorSpace.prototype.fillRgb,
  31860. isDefaultDecode: function IndexedCS_isDefaultDecode(decodeMap) {
  31861. // indexed color maps shouldn't be changed
  31862. return true;
  31863. },
  31864. usesZeroToOneRange: true
  31865. };
  31866. return IndexedCS;
  31867. })();
  31868. var DeviceGrayCS = (function DeviceGrayCSClosure() {
  31869. function DeviceGrayCS() {
  31870. this.name = 'DeviceGray';
  31871. this.numComps = 1;
  31872. this.defaultColor = new Float32Array([0]);
  31873. }
  31874. DeviceGrayCS.prototype = {
  31875. getRgb: ColorSpace.prototype.getRgb,
  31876. getRgbItem: function DeviceGrayCS_getRgbItem(src, srcOffset,
  31877. dest, destOffset) {
  31878. var c = (src[srcOffset] * 255) | 0;
  31879. c = c < 0 ? 0 : c > 255 ? 255 : c;
  31880. dest[destOffset] = dest[destOffset + 1] = dest[destOffset + 2] = c;
  31881. },
  31882. getRgbBuffer: function DeviceGrayCS_getRgbBuffer(src, srcOffset, count,
  31883. dest, destOffset, bits,
  31884. alpha01) {
  31885. var scale = 255 / ((1 << bits) - 1);
  31886. var j = srcOffset, q = destOffset;
  31887. for (var i = 0; i < count; ++i) {
  31888. var c = (scale * src[j++]) | 0;
  31889. dest[q++] = c;
  31890. dest[q++] = c;
  31891. dest[q++] = c;
  31892. q += alpha01;
  31893. }
  31894. },
  31895. getOutputLength: function DeviceGrayCS_getOutputLength(inputLength,
  31896. alpha01) {
  31897. return inputLength * (3 + alpha01);
  31898. },
  31899. isPassthrough: ColorSpace.prototype.isPassthrough,
  31900. fillRgb: ColorSpace.prototype.fillRgb,
  31901. isDefaultDecode: function DeviceGrayCS_isDefaultDecode(decodeMap) {
  31902. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  31903. },
  31904. usesZeroToOneRange: true
  31905. };
  31906. return DeviceGrayCS;
  31907. })();
  31908. var DeviceRgbCS = (function DeviceRgbCSClosure() {
  31909. function DeviceRgbCS() {
  31910. this.name = 'DeviceRGB';
  31911. this.numComps = 3;
  31912. this.defaultColor = new Float32Array([0, 0, 0]);
  31913. }
  31914. DeviceRgbCS.prototype = {
  31915. getRgb: ColorSpace.prototype.getRgb,
  31916. getRgbItem: function DeviceRgbCS_getRgbItem(src, srcOffset,
  31917. dest, destOffset) {
  31918. var r = (src[srcOffset] * 255) | 0;
  31919. var g = (src[srcOffset + 1] * 255) | 0;
  31920. var b = (src[srcOffset + 2] * 255) | 0;
  31921. dest[destOffset] = r < 0 ? 0 : r > 255 ? 255 : r;
  31922. dest[destOffset + 1] = g < 0 ? 0 : g > 255 ? 255 : g;
  31923. dest[destOffset + 2] = b < 0 ? 0 : b > 255 ? 255 : b;
  31924. },
  31925. getRgbBuffer: function DeviceRgbCS_getRgbBuffer(src, srcOffset, count,
  31926. dest, destOffset, bits,
  31927. alpha01) {
  31928. if (bits === 8 && alpha01 === 0) {
  31929. dest.set(src.subarray(srcOffset, srcOffset + count * 3), destOffset);
  31930. return;
  31931. }
  31932. var scale = 255 / ((1 << bits) - 1);
  31933. var j = srcOffset, q = destOffset;
  31934. for (var i = 0; i < count; ++i) {
  31935. dest[q++] = (scale * src[j++]) | 0;
  31936. dest[q++] = (scale * src[j++]) | 0;
  31937. dest[q++] = (scale * src[j++]) | 0;
  31938. q += alpha01;
  31939. }
  31940. },
  31941. getOutputLength: function DeviceRgbCS_getOutputLength(inputLength,
  31942. alpha01) {
  31943. return (inputLength * (3 + alpha01) / 3) | 0;
  31944. },
  31945. isPassthrough: function DeviceRgbCS_isPassthrough(bits) {
  31946. return bits === 8;
  31947. },
  31948. fillRgb: ColorSpace.prototype.fillRgb,
  31949. isDefaultDecode: function DeviceRgbCS_isDefaultDecode(decodeMap) {
  31950. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  31951. },
  31952. usesZeroToOneRange: true
  31953. };
  31954. return DeviceRgbCS;
  31955. })();
  31956. var DeviceCmykCS = (function DeviceCmykCSClosure() {
  31957. // The coefficients below was found using numerical analysis: the method of
  31958. // steepest descent for the sum((f_i - color_value_i)^2) for r/g/b colors,
  31959. // where color_value is the tabular value from the table of sampled RGB colors
  31960. // from CMYK US Web Coated (SWOP) colorspace, and f_i is the corresponding
  31961. // CMYK color conversion using the estimation below:
  31962. // f(A, B,.. N) = Acc+Bcm+Ccy+Dck+c+Fmm+Gmy+Hmk+Im+Jyy+Kyk+Ly+Mkk+Nk+255
  31963. function convertToRgb(src, srcOffset, srcScale, dest, destOffset) {
  31964. var c = src[srcOffset + 0] * srcScale;
  31965. var m = src[srcOffset + 1] * srcScale;
  31966. var y = src[srcOffset + 2] * srcScale;
  31967. var k = src[srcOffset + 3] * srcScale;
  31968. var r =
  31969. (c * (-4.387332384609988 * c + 54.48615194189176 * m +
  31970. 18.82290502165302 * y + 212.25662451639585 * k +
  31971. -285.2331026137004) +
  31972. m * (1.7149763477362134 * m - 5.6096736904047315 * y +
  31973. -17.873870861415444 * k - 5.497006427196366) +
  31974. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  31975. 17.5119270841813) +
  31976. k * (-21.86122147463605 * k - 189.48180835922747) + 255) | 0;
  31977. var g =
  31978. (c * (8.841041422036149 * c + 60.118027045597366 * m +
  31979. 6.871425592049007 * y + 31.159100130055922 * k +
  31980. -79.2970844816548) +
  31981. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  31982. 131.35250912493976 * k - 190.9453302588951) +
  31983. y * (4.444339102852739 * y + 9.8632861493405 * k - 24.86741582555878) +
  31984. k * (-20.737325471181034 * k - 187.80453709719578) + 255) | 0;
  31985. var b =
  31986. (c * (0.8842522430003296 * c + 8.078677503112928 * m +
  31987. 30.89978309703729 * y - 0.23883238689178934 * k +
  31988. -14.183576799673286) +
  31989. m * (10.49593273432072 * m + 63.02378494754052 * y +
  31990. 50.606957656360734 * k - 112.23884253719248) +
  31991. y * (0.03296041114873217 * y + 115.60384449646641 * k +
  31992. -193.58209356861505) +
  31993. k * (-22.33816807309886 * k - 180.12613974708367) + 255) | 0;
  31994. dest[destOffset] = r > 255 ? 255 : r < 0 ? 0 : r;
  31995. dest[destOffset + 1] = g > 255 ? 255 : g < 0 ? 0 : g;
  31996. dest[destOffset + 2] = b > 255 ? 255 : b < 0 ? 0 : b;
  31997. }
  31998. function DeviceCmykCS() {
  31999. this.name = 'DeviceCMYK';
  32000. this.numComps = 4;
  32001. this.defaultColor = new Float32Array([0, 0, 0, 1]);
  32002. }
  32003. DeviceCmykCS.prototype = {
  32004. getRgb: ColorSpace.prototype.getRgb,
  32005. getRgbItem: function DeviceCmykCS_getRgbItem(src, srcOffset,
  32006. dest, destOffset) {
  32007. convertToRgb(src, srcOffset, 1, dest, destOffset);
  32008. },
  32009. getRgbBuffer: function DeviceCmykCS_getRgbBuffer(src, srcOffset, count,
  32010. dest, destOffset, bits,
  32011. alpha01) {
  32012. var scale = 1 / ((1 << bits) - 1);
  32013. for (var i = 0; i < count; i++) {
  32014. convertToRgb(src, srcOffset, scale, dest, destOffset);
  32015. srcOffset += 4;
  32016. destOffset += 3 + alpha01;
  32017. }
  32018. },
  32019. getOutputLength: function DeviceCmykCS_getOutputLength(inputLength,
  32020. alpha01) {
  32021. return (inputLength / 4 * (3 + alpha01)) | 0;
  32022. },
  32023. isPassthrough: ColorSpace.prototype.isPassthrough,
  32024. fillRgb: ColorSpace.prototype.fillRgb,
  32025. isDefaultDecode: function DeviceCmykCS_isDefaultDecode(decodeMap) {
  32026. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  32027. },
  32028. usesZeroToOneRange: true
  32029. };
  32030. return DeviceCmykCS;
  32031. })();
  32032. //
  32033. // CalGrayCS: Based on "PDF Reference, Sixth Ed", p.245
  32034. //
  32035. var CalGrayCS = (function CalGrayCSClosure() {
  32036. function CalGrayCS(whitePoint, blackPoint, gamma) {
  32037. this.name = 'CalGray';
  32038. this.numComps = 1;
  32039. this.defaultColor = new Float32Array([0]);
  32040. if (!whitePoint) {
  32041. error('WhitePoint missing - required for color space CalGray');
  32042. }
  32043. blackPoint = blackPoint || [0, 0, 0];
  32044. gamma = gamma || 1;
  32045. // Translate arguments to spec variables.
  32046. this.XW = whitePoint[0];
  32047. this.YW = whitePoint[1];
  32048. this.ZW = whitePoint[2];
  32049. this.XB = blackPoint[0];
  32050. this.YB = blackPoint[1];
  32051. this.ZB = blackPoint[2];
  32052. this.G = gamma;
  32053. // Validate variables as per spec.
  32054. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  32055. error('Invalid WhitePoint components for ' + this.name +
  32056. ', no fallback available');
  32057. }
  32058. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  32059. info('Invalid BlackPoint for ' + this.name + ', falling back to default');
  32060. this.XB = this.YB = this.ZB = 0;
  32061. }
  32062. if (this.XB !== 0 || this.YB !== 0 || this.ZB !== 0) {
  32063. warn(this.name + ', BlackPoint: XB: ' + this.XB + ', YB: ' + this.YB +
  32064. ', ZB: ' + this.ZB + ', only default values are supported.');
  32065. }
  32066. if (this.G < 1) {
  32067. info('Invalid Gamma: ' + this.G + ' for ' + this.name +
  32068. ', falling back to default');
  32069. this.G = 1;
  32070. }
  32071. }
  32072. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  32073. // A represents a gray component of a calibrated gray space.
  32074. // A <---> AG in the spec
  32075. var A = src[srcOffset] * scale;
  32076. var AG = Math.pow(A, cs.G);
  32077. // Computes L as per spec. ( = cs.YW * AG )
  32078. // Except if other than default BlackPoint values are used.
  32079. var L = cs.YW * AG;
  32080. // http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html, Ch 4.
  32081. // Convert values to rgb range [0, 255].
  32082. var val = Math.max(295.8 * Math.pow(L, 0.333333333333333333) - 40.8, 0) | 0;
  32083. dest[destOffset] = val;
  32084. dest[destOffset + 1] = val;
  32085. dest[destOffset + 2] = val;
  32086. }
  32087. CalGrayCS.prototype = {
  32088. getRgb: ColorSpace.prototype.getRgb,
  32089. getRgbItem: function CalGrayCS_getRgbItem(src, srcOffset,
  32090. dest, destOffset) {
  32091. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  32092. },
  32093. getRgbBuffer: function CalGrayCS_getRgbBuffer(src, srcOffset, count,
  32094. dest, destOffset, bits,
  32095. alpha01) {
  32096. var scale = 1 / ((1 << bits) - 1);
  32097. for (var i = 0; i < count; ++i) {
  32098. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  32099. srcOffset += 1;
  32100. destOffset += 3 + alpha01;
  32101. }
  32102. },
  32103. getOutputLength: function CalGrayCS_getOutputLength(inputLength, alpha01) {
  32104. return inputLength * (3 + alpha01);
  32105. },
  32106. isPassthrough: ColorSpace.prototype.isPassthrough,
  32107. fillRgb: ColorSpace.prototype.fillRgb,
  32108. isDefaultDecode: function CalGrayCS_isDefaultDecode(decodeMap) {
  32109. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  32110. },
  32111. usesZeroToOneRange: true
  32112. };
  32113. return CalGrayCS;
  32114. })();
  32115. //
  32116. // CalRGBCS: Based on "PDF Reference, Sixth Ed", p.247
  32117. //
  32118. var CalRGBCS = (function CalRGBCSClosure() {
  32119. // See http://www.brucelindbloom.com/index.html?Eqn_ChromAdapt.html for these
  32120. // matrices.
  32121. var BRADFORD_SCALE_MATRIX = new Float32Array([
  32122. 0.8951, 0.2664, -0.1614,
  32123. -0.7502, 1.7135, 0.0367,
  32124. 0.0389, -0.0685, 1.0296]);
  32125. var BRADFORD_SCALE_INVERSE_MATRIX = new Float32Array([
  32126. 0.9869929, -0.1470543, 0.1599627,
  32127. 0.4323053, 0.5183603, 0.0492912,
  32128. -0.0085287, 0.0400428, 0.9684867]);
  32129. // See http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html.
  32130. var SRGB_D65_XYZ_TO_RGB_MATRIX = new Float32Array([
  32131. 3.2404542, -1.5371385, -0.4985314,
  32132. -0.9692660, 1.8760108, 0.0415560,
  32133. 0.0556434, -0.2040259, 1.0572252]);
  32134. var FLAT_WHITEPOINT_MATRIX = new Float32Array([1, 1, 1]);
  32135. var tempNormalizeMatrix = new Float32Array(3);
  32136. var tempConvertMatrix1 = new Float32Array(3);
  32137. var tempConvertMatrix2 = new Float32Array(3);
  32138. var DECODE_L_CONSTANT = Math.pow(((8 + 16) / 116), 3) / 8.0;
  32139. function CalRGBCS(whitePoint, blackPoint, gamma, matrix) {
  32140. this.name = 'CalRGB';
  32141. this.numComps = 3;
  32142. this.defaultColor = new Float32Array(3);
  32143. if (!whitePoint) {
  32144. error('WhitePoint missing - required for color space CalRGB');
  32145. }
  32146. blackPoint = blackPoint || new Float32Array(3);
  32147. gamma = gamma || new Float32Array([1, 1, 1]);
  32148. matrix = matrix || new Float32Array([1, 0, 0, 0, 1, 0, 0, 0, 1]);
  32149. // Translate arguments to spec variables.
  32150. var XW = whitePoint[0];
  32151. var YW = whitePoint[1];
  32152. var ZW = whitePoint[2];
  32153. this.whitePoint = whitePoint;
  32154. var XB = blackPoint[0];
  32155. var YB = blackPoint[1];
  32156. var ZB = blackPoint[2];
  32157. this.blackPoint = blackPoint;
  32158. this.GR = gamma[0];
  32159. this.GG = gamma[1];
  32160. this.GB = gamma[2];
  32161. this.MXA = matrix[0];
  32162. this.MYA = matrix[1];
  32163. this.MZA = matrix[2];
  32164. this.MXB = matrix[3];
  32165. this.MYB = matrix[4];
  32166. this.MZB = matrix[5];
  32167. this.MXC = matrix[6];
  32168. this.MYC = matrix[7];
  32169. this.MZC = matrix[8];
  32170. // Validate variables as per spec.
  32171. if (XW < 0 || ZW < 0 || YW !== 1) {
  32172. error('Invalid WhitePoint components for ' + this.name +
  32173. ', no fallback available');
  32174. }
  32175. if (XB < 0 || YB < 0 || ZB < 0) {
  32176. info('Invalid BlackPoint for ' + this.name + ' [' + XB + ', ' + YB +
  32177. ', ' + ZB + '], falling back to default');
  32178. this.blackPoint = new Float32Array(3);
  32179. }
  32180. if (this.GR < 0 || this.GG < 0 || this.GB < 0) {
  32181. info('Invalid Gamma [' + this.GR + ', ' + this.GG + ', ' + this.GB +
  32182. '] for ' + this.name + ', falling back to default');
  32183. this.GR = this.GG = this.GB = 1;
  32184. }
  32185. if (this.MXA < 0 || this.MYA < 0 || this.MZA < 0 ||
  32186. this.MXB < 0 || this.MYB < 0 || this.MZB < 0 ||
  32187. this.MXC < 0 || this.MYC < 0 || this.MZC < 0) {
  32188. info('Invalid Matrix for ' + this.name + ' [' +
  32189. this.MXA + ', ' + this.MYA + ', ' + this.MZA +
  32190. this.MXB + ', ' + this.MYB + ', ' + this.MZB +
  32191. this.MXC + ', ' + this.MYC + ', ' + this.MZC +
  32192. '], falling back to default');
  32193. this.MXA = this.MYB = this.MZC = 1;
  32194. this.MXB = this.MYA = this.MZA = this.MXC = this.MYC = this.MZB = 0;
  32195. }
  32196. }
  32197. function matrixProduct(a, b, result) {
  32198. result[0] = a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
  32199. result[1] = a[3] * b[0] + a[4] * b[1] + a[5] * b[2];
  32200. result[2] = a[6] * b[0] + a[7] * b[1] + a[8] * b[2];
  32201. }
  32202. function convertToFlat(sourceWhitePoint, LMS, result) {
  32203. result[0] = LMS[0] * 1 / sourceWhitePoint[0];
  32204. result[1] = LMS[1] * 1 / sourceWhitePoint[1];
  32205. result[2] = LMS[2] * 1 / sourceWhitePoint[2];
  32206. }
  32207. function convertToD65(sourceWhitePoint, LMS, result) {
  32208. var D65X = 0.95047;
  32209. var D65Y = 1;
  32210. var D65Z = 1.08883;
  32211. result[0] = LMS[0] * D65X / sourceWhitePoint[0];
  32212. result[1] = LMS[1] * D65Y / sourceWhitePoint[1];
  32213. result[2] = LMS[2] * D65Z / sourceWhitePoint[2];
  32214. }
  32215. function sRGBTransferFunction(color) {
  32216. // See http://en.wikipedia.org/wiki/SRGB.
  32217. if (color <= 0.0031308){
  32218. return adjustToRange(0, 1, 12.92 * color);
  32219. }
  32220. return adjustToRange(0, 1, (1 + 0.055) * Math.pow(color, 1 / 2.4) - 0.055);
  32221. }
  32222. function adjustToRange(min, max, value) {
  32223. return Math.max(min, Math.min(max, value));
  32224. }
  32225. function decodeL(L) {
  32226. if (L < 0) {
  32227. return -decodeL(-L);
  32228. }
  32229. if (L > 8.0) {
  32230. return Math.pow(((L + 16) / 116), 3);
  32231. }
  32232. return L * DECODE_L_CONSTANT;
  32233. }
  32234. function compensateBlackPoint(sourceBlackPoint, XYZ_Flat, result) {
  32235. // In case the blackPoint is already the default blackPoint then there is
  32236. // no need to do compensation.
  32237. if (sourceBlackPoint[0] === 0 &&
  32238. sourceBlackPoint[1] === 0 &&
  32239. sourceBlackPoint[2] === 0) {
  32240. result[0] = XYZ_Flat[0];
  32241. result[1] = XYZ_Flat[1];
  32242. result[2] = XYZ_Flat[2];
  32243. return;
  32244. }
  32245. // For the blackPoint calculation details, please see
  32246. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  32247. // AdobeBPC.pdf.
  32248. // The destination blackPoint is the default blackPoint [0, 0, 0].
  32249. var zeroDecodeL = decodeL(0);
  32250. var X_DST = zeroDecodeL;
  32251. var X_SRC = decodeL(sourceBlackPoint[0]);
  32252. var Y_DST = zeroDecodeL;
  32253. var Y_SRC = decodeL(sourceBlackPoint[1]);
  32254. var Z_DST = zeroDecodeL;
  32255. var Z_SRC = decodeL(sourceBlackPoint[2]);
  32256. var X_Scale = (1 - X_DST) / (1 - X_SRC);
  32257. var X_Offset = 1 - X_Scale;
  32258. var Y_Scale = (1 - Y_DST) / (1 - Y_SRC);
  32259. var Y_Offset = 1 - Y_Scale;
  32260. var Z_Scale = (1 - Z_DST) / (1 - Z_SRC);
  32261. var Z_Offset = 1 - Z_Scale;
  32262. result[0] = XYZ_Flat[0] * X_Scale + X_Offset;
  32263. result[1] = XYZ_Flat[1] * Y_Scale + Y_Offset;
  32264. result[2] = XYZ_Flat[2] * Z_Scale + Z_Offset;
  32265. }
  32266. function normalizeWhitePointToFlat(sourceWhitePoint, XYZ_In, result) {
  32267. // In case the whitePoint is already flat then there is no need to do
  32268. // normalization.
  32269. if (sourceWhitePoint[0] === 1 && sourceWhitePoint[2] === 1) {
  32270. result[0] = XYZ_In[0];
  32271. result[1] = XYZ_In[1];
  32272. result[2] = XYZ_In[2];
  32273. return;
  32274. }
  32275. var LMS = result;
  32276. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  32277. var LMS_Flat = tempNormalizeMatrix;
  32278. convertToFlat(sourceWhitePoint, LMS, LMS_Flat);
  32279. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_Flat, result);
  32280. }
  32281. function normalizeWhitePointToD65(sourceWhitePoint, XYZ_In, result) {
  32282. var LMS = result;
  32283. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  32284. var LMS_D65 = tempNormalizeMatrix;
  32285. convertToD65(sourceWhitePoint, LMS, LMS_D65);
  32286. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_D65, result);
  32287. }
  32288. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  32289. // A, B and C represent a red, green and blue components of a calibrated
  32290. // rgb space.
  32291. var A = adjustToRange(0, 1, src[srcOffset] * scale);
  32292. var B = adjustToRange(0, 1, src[srcOffset + 1] * scale);
  32293. var C = adjustToRange(0, 1, src[srcOffset + 2] * scale);
  32294. // A <---> AGR in the spec
  32295. // B <---> BGG in the spec
  32296. // C <---> CGB in the spec
  32297. var AGR = Math.pow(A, cs.GR);
  32298. var BGG = Math.pow(B, cs.GG);
  32299. var CGB = Math.pow(C, cs.GB);
  32300. // Computes intermediate variables L, M, N as per spec.
  32301. // To decode X, Y, Z values map L, M, N directly to them.
  32302. var X = cs.MXA * AGR + cs.MXB * BGG + cs.MXC * CGB;
  32303. var Y = cs.MYA * AGR + cs.MYB * BGG + cs.MYC * CGB;
  32304. var Z = cs.MZA * AGR + cs.MZB * BGG + cs.MZC * CGB;
  32305. // The following calculations are based on this document:
  32306. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  32307. // AdobeBPC.pdf.
  32308. var XYZ = tempConvertMatrix1;
  32309. XYZ[0] = X;
  32310. XYZ[1] = Y;
  32311. XYZ[2] = Z;
  32312. var XYZ_Flat = tempConvertMatrix2;
  32313. normalizeWhitePointToFlat(cs.whitePoint, XYZ, XYZ_Flat);
  32314. var XYZ_Black = tempConvertMatrix1;
  32315. compensateBlackPoint(cs.blackPoint, XYZ_Flat, XYZ_Black);
  32316. var XYZ_D65 = tempConvertMatrix2;
  32317. normalizeWhitePointToD65(FLAT_WHITEPOINT_MATRIX, XYZ_Black, XYZ_D65);
  32318. var SRGB = tempConvertMatrix1;
  32319. matrixProduct(SRGB_D65_XYZ_TO_RGB_MATRIX, XYZ_D65, SRGB);
  32320. var sR = sRGBTransferFunction(SRGB[0]);
  32321. var sG = sRGBTransferFunction(SRGB[1]);
  32322. var sB = sRGBTransferFunction(SRGB[2]);
  32323. // Convert the values to rgb range [0, 255].
  32324. dest[destOffset] = Math.round(sR * 255);
  32325. dest[destOffset + 1] = Math.round(sG * 255);
  32326. dest[destOffset + 2] = Math.round(sB * 255);
  32327. }
  32328. CalRGBCS.prototype = {
  32329. getRgb: function CalRGBCS_getRgb(src, srcOffset) {
  32330. var rgb = new Uint8Array(3);
  32331. this.getRgbItem(src, srcOffset, rgb, 0);
  32332. return rgb;
  32333. },
  32334. getRgbItem: function CalRGBCS_getRgbItem(src, srcOffset,
  32335. dest, destOffset) {
  32336. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  32337. },
  32338. getRgbBuffer: function CalRGBCS_getRgbBuffer(src, srcOffset, count,
  32339. dest, destOffset, bits,
  32340. alpha01) {
  32341. var scale = 1 / ((1 << bits) - 1);
  32342. for (var i = 0; i < count; ++i) {
  32343. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  32344. srcOffset += 3;
  32345. destOffset += 3 + alpha01;
  32346. }
  32347. },
  32348. getOutputLength: function CalRGBCS_getOutputLength(inputLength, alpha01) {
  32349. return (inputLength * (3 + alpha01) / 3) | 0;
  32350. },
  32351. isPassthrough: ColorSpace.prototype.isPassthrough,
  32352. fillRgb: ColorSpace.prototype.fillRgb,
  32353. isDefaultDecode: function CalRGBCS_isDefaultDecode(decodeMap) {
  32354. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  32355. },
  32356. usesZeroToOneRange: true
  32357. };
  32358. return CalRGBCS;
  32359. })();
  32360. //
  32361. // LabCS: Based on "PDF Reference, Sixth Ed", p.250
  32362. //
  32363. var LabCS = (function LabCSClosure() {
  32364. function LabCS(whitePoint, blackPoint, range) {
  32365. this.name = 'Lab';
  32366. this.numComps = 3;
  32367. this.defaultColor = new Float32Array([0, 0, 0]);
  32368. if (!whitePoint) {
  32369. error('WhitePoint missing - required for color space Lab');
  32370. }
  32371. blackPoint = blackPoint || [0, 0, 0];
  32372. range = range || [-100, 100, -100, 100];
  32373. // Translate args to spec variables
  32374. this.XW = whitePoint[0];
  32375. this.YW = whitePoint[1];
  32376. this.ZW = whitePoint[2];
  32377. this.amin = range[0];
  32378. this.amax = range[1];
  32379. this.bmin = range[2];
  32380. this.bmax = range[3];
  32381. // These are here just for completeness - the spec doesn't offer any
  32382. // formulas that use BlackPoint in Lab
  32383. this.XB = blackPoint[0];
  32384. this.YB = blackPoint[1];
  32385. this.ZB = blackPoint[2];
  32386. // Validate vars as per spec
  32387. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  32388. error('Invalid WhitePoint components, no fallback available');
  32389. }
  32390. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  32391. info('Invalid BlackPoint, falling back to default');
  32392. this.XB = this.YB = this.ZB = 0;
  32393. }
  32394. if (this.amin > this.amax || this.bmin > this.bmax) {
  32395. info('Invalid Range, falling back to defaults');
  32396. this.amin = -100;
  32397. this.amax = 100;
  32398. this.bmin = -100;
  32399. this.bmax = 100;
  32400. }
  32401. }
  32402. // Function g(x) from spec
  32403. function fn_g(x) {
  32404. if (x >= 6 / 29) {
  32405. return x * x * x;
  32406. } else {
  32407. return (108 / 841) * (x - 4 / 29);
  32408. }
  32409. }
  32410. function decode(value, high1, low2, high2) {
  32411. return low2 + (value) * (high2 - low2) / (high1);
  32412. }
  32413. // If decoding is needed maxVal should be 2^bits per component - 1.
  32414. function convertToRgb(cs, src, srcOffset, maxVal, dest, destOffset) {
  32415. // XXX: Lab input is in the range of [0, 100], [amin, amax], [bmin, bmax]
  32416. // not the usual [0, 1]. If a command like setFillColor is used the src
  32417. // values will already be within the correct range. However, if we are
  32418. // converting an image we have to map the values to the correct range given
  32419. // above.
  32420. // Ls,as,bs <---> L*,a*,b* in the spec
  32421. var Ls = src[srcOffset];
  32422. var as = src[srcOffset + 1];
  32423. var bs = src[srcOffset + 2];
  32424. if (maxVal !== false) {
  32425. Ls = decode(Ls, maxVal, 0, 100);
  32426. as = decode(as, maxVal, cs.amin, cs.amax);
  32427. bs = decode(bs, maxVal, cs.bmin, cs.bmax);
  32428. }
  32429. // Adjust limits of 'as' and 'bs'
  32430. as = as > cs.amax ? cs.amax : as < cs.amin ? cs.amin : as;
  32431. bs = bs > cs.bmax ? cs.bmax : bs < cs.bmin ? cs.bmin : bs;
  32432. // Computes intermediate variables X,Y,Z as per spec
  32433. var M = (Ls + 16) / 116;
  32434. var L = M + (as / 500);
  32435. var N = M - (bs / 200);
  32436. var X = cs.XW * fn_g(L);
  32437. var Y = cs.YW * fn_g(M);
  32438. var Z = cs.ZW * fn_g(N);
  32439. var r, g, b;
  32440. // Using different conversions for D50 and D65 white points,
  32441. // per http://www.color.org/srgb.pdf
  32442. if (cs.ZW < 1) {
  32443. // Assuming D50 (X=0.9642, Y=1.00, Z=0.8249)
  32444. r = X * 3.1339 + Y * -1.6170 + Z * -0.4906;
  32445. g = X * -0.9785 + Y * 1.9160 + Z * 0.0333;
  32446. b = X * 0.0720 + Y * -0.2290 + Z * 1.4057;
  32447. } else {
  32448. // Assuming D65 (X=0.9505, Y=1.00, Z=1.0888)
  32449. r = X * 3.2406 + Y * -1.5372 + Z * -0.4986;
  32450. g = X * -0.9689 + Y * 1.8758 + Z * 0.0415;
  32451. b = X * 0.0557 + Y * -0.2040 + Z * 1.0570;
  32452. }
  32453. // clamp color values to [0,1] range then convert to [0,255] range.
  32454. dest[destOffset] = r <= 0 ? 0 : r >= 1 ? 255 : Math.sqrt(r) * 255 | 0;
  32455. dest[destOffset + 1] = g <= 0 ? 0 : g >= 1 ? 255 : Math.sqrt(g) * 255 | 0;
  32456. dest[destOffset + 2] = b <= 0 ? 0 : b >= 1 ? 255 : Math.sqrt(b) * 255 | 0;
  32457. }
  32458. LabCS.prototype = {
  32459. getRgb: ColorSpace.prototype.getRgb,
  32460. getRgbItem: function LabCS_getRgbItem(src, srcOffset, dest, destOffset) {
  32461. convertToRgb(this, src, srcOffset, false, dest, destOffset);
  32462. },
  32463. getRgbBuffer: function LabCS_getRgbBuffer(src, srcOffset, count,
  32464. dest, destOffset, bits,
  32465. alpha01) {
  32466. var maxVal = (1 << bits) - 1;
  32467. for (var i = 0; i < count; i++) {
  32468. convertToRgb(this, src, srcOffset, maxVal, dest, destOffset);
  32469. srcOffset += 3;
  32470. destOffset += 3 + alpha01;
  32471. }
  32472. },
  32473. getOutputLength: function LabCS_getOutputLength(inputLength, alpha01) {
  32474. return (inputLength * (3 + alpha01) / 3) | 0;
  32475. },
  32476. isPassthrough: ColorSpace.prototype.isPassthrough,
  32477. fillRgb: ColorSpace.prototype.fillRgb,
  32478. isDefaultDecode: function LabCS_isDefaultDecode(decodeMap) {
  32479. // XXX: Decoding is handled with the lab conversion because of the strange
  32480. // ranges that are used.
  32481. return true;
  32482. },
  32483. usesZeroToOneRange: false
  32484. };
  32485. return LabCS;
  32486. })();
  32487. // TODO refactor to remove dependency on image.js
  32488. function _setCoreImage(coreImage_) {
  32489. coreImage = coreImage_;
  32490. PDFImage = coreImage_.PDFImage;
  32491. }
  32492. exports._setCoreImage = _setCoreImage;
  32493. exports.ColorSpace = ColorSpace;
  32494. // TODO refactor to remove dependency on colorspace.js
  32495. coreStream._setCoreColorSpace(exports);
  32496. }));
  32497. (function (root, factory) {
  32498. {
  32499. factory((root.pdfjsCoreImage = {}), root.pdfjsSharedUtil,
  32500. root.pdfjsCorePrimitives, root.pdfjsCoreColorSpace, root.pdfjsCoreStream,
  32501. root.pdfjsCoreJpx);
  32502. }
  32503. }(this, function (exports, sharedUtil, corePrimitives, coreColorSpace,
  32504. coreStream, coreJpx) {
  32505. var ImageKind = sharedUtil.ImageKind;
  32506. var assert = sharedUtil.assert;
  32507. var error = sharedUtil.error;
  32508. var info = sharedUtil.info;
  32509. var isArray = sharedUtil.isArray;
  32510. var warn = sharedUtil.warn;
  32511. var Name = corePrimitives.Name;
  32512. var isStream = corePrimitives.isStream;
  32513. var ColorSpace = coreColorSpace.ColorSpace;
  32514. var DecodeStream = coreStream.DecodeStream;
  32515. var Stream = coreStream.Stream;
  32516. var JpegStream = coreStream.JpegStream;
  32517. var JpxImage = coreJpx.JpxImage;
  32518. var PDFImage = (function PDFImageClosure() {
  32519. /**
  32520. * Decode the image in the main thread if it supported. Resovles the promise
  32521. * when the image data is ready.
  32522. */
  32523. function handleImageData(handler, xref, res, image) {
  32524. if (image instanceof JpegStream && image.isNativelyDecodable(xref, res)) {
  32525. // For natively supported jpegs send them to the main thread for decoding.
  32526. var dict = image.dict;
  32527. var colorSpace = dict.get('ColorSpace', 'CS');
  32528. colorSpace = ColorSpace.parse(colorSpace, xref, res);
  32529. var numComps = colorSpace.numComps;
  32530. var decodePromise = handler.sendWithPromise('JpegDecode',
  32531. [image.getIR(), numComps]);
  32532. return decodePromise.then(function (message) {
  32533. var data = message.data;
  32534. return new Stream(data, 0, data.length, image.dict);
  32535. });
  32536. } else {
  32537. return Promise.resolve(image);
  32538. }
  32539. }
  32540. /**
  32541. * Decode and clamp a value. The formula is different from the spec because we
  32542. * don't decode to float range [0,1], we decode it in the [0,max] range.
  32543. */
  32544. function decodeAndClamp(value, addend, coefficient, max) {
  32545. value = addend + value * coefficient;
  32546. // Clamp the value to the range
  32547. return (value < 0 ? 0 : (value > max ? max : value));
  32548. }
  32549. function PDFImage(xref, res, image, inline, smask, mask, isMask) {
  32550. this.image = image;
  32551. var dict = image.dict;
  32552. if (dict.has('Filter')) {
  32553. var filter = dict.get('Filter').name;
  32554. if (filter === 'JPXDecode') {
  32555. var jpxImage = new JpxImage();
  32556. jpxImage.parseImageProperties(image.stream);
  32557. image.stream.reset();
  32558. image.bitsPerComponent = jpxImage.bitsPerComponent;
  32559. image.numComps = jpxImage.componentsCount;
  32560. } else if (filter === 'JBIG2Decode') {
  32561. image.bitsPerComponent = 1;
  32562. image.numComps = 1;
  32563. }
  32564. }
  32565. // TODO cache rendered images?
  32566. this.width = dict.get('Width', 'W');
  32567. this.height = dict.get('Height', 'H');
  32568. if (this.width < 1 || this.height < 1) {
  32569. error('Invalid image width: ' + this.width + ' or height: ' +
  32570. this.height);
  32571. }
  32572. this.interpolate = dict.get('Interpolate', 'I') || false;
  32573. this.imageMask = dict.get('ImageMask', 'IM') || false;
  32574. this.matte = dict.get('Matte') || false;
  32575. var bitsPerComponent = image.bitsPerComponent;
  32576. if (!bitsPerComponent) {
  32577. bitsPerComponent = dict.get('BitsPerComponent', 'BPC');
  32578. if (!bitsPerComponent) {
  32579. if (this.imageMask) {
  32580. bitsPerComponent = 1;
  32581. } else {
  32582. error('Bits per component missing in image: ' + this.imageMask);
  32583. }
  32584. }
  32585. }
  32586. this.bpc = bitsPerComponent;
  32587. if (!this.imageMask) {
  32588. var colorSpace = dict.get('ColorSpace', 'CS');
  32589. if (!colorSpace) {
  32590. info('JPX images (which do not require color spaces)');
  32591. switch (image.numComps) {
  32592. case 1:
  32593. colorSpace = Name.get('DeviceGray');
  32594. break;
  32595. case 3:
  32596. colorSpace = Name.get('DeviceRGB');
  32597. break;
  32598. case 4:
  32599. colorSpace = Name.get('DeviceCMYK');
  32600. break;
  32601. default:
  32602. error('JPX images with ' + this.numComps +
  32603. ' color components not supported.');
  32604. }
  32605. }
  32606. this.colorSpace = ColorSpace.parse(colorSpace, xref, res);
  32607. this.numComps = this.colorSpace.numComps;
  32608. }
  32609. this.decode = dict.get('Decode', 'D');
  32610. this.needsDecode = false;
  32611. if (this.decode &&
  32612. ((this.colorSpace && !this.colorSpace.isDefaultDecode(this.decode)) ||
  32613. (isMask && !ColorSpace.isDefaultDecode(this.decode, 1)))) {
  32614. this.needsDecode = true;
  32615. // Do some preprocessing to avoid more math.
  32616. var max = (1 << bitsPerComponent) - 1;
  32617. this.decodeCoefficients = [];
  32618. this.decodeAddends = [];
  32619. for (var i = 0, j = 0; i < this.decode.length; i += 2, ++j) {
  32620. var dmin = this.decode[i];
  32621. var dmax = this.decode[i + 1];
  32622. this.decodeCoefficients[j] = dmax - dmin;
  32623. this.decodeAddends[j] = max * dmin;
  32624. }
  32625. }
  32626. if (smask) {
  32627. this.smask = new PDFImage(xref, res, smask, false);
  32628. } else if (mask) {
  32629. if (isStream(mask)) {
  32630. var maskDict = mask.dict, imageMask = maskDict.get('ImageMask', 'IM');
  32631. if (!imageMask) {
  32632. warn('Ignoring /Mask in image without /ImageMask.');
  32633. } else {
  32634. this.mask = new PDFImage(xref, res, mask, false, null, null, true);
  32635. }
  32636. } else {
  32637. // Color key mask (just an array).
  32638. this.mask = mask;
  32639. }
  32640. }
  32641. }
  32642. /**
  32643. * Handles processing of image data and returns the Promise that is resolved
  32644. * with a PDFImage when the image is ready to be used.
  32645. */
  32646. PDFImage.buildImage = function PDFImage_buildImage(handler, xref,
  32647. res, image, inline) {
  32648. var imagePromise = handleImageData(handler, xref, res, image);
  32649. var smaskPromise;
  32650. var maskPromise;
  32651. var smask = image.dict.get('SMask');
  32652. var mask = image.dict.get('Mask');
  32653. if (smask) {
  32654. smaskPromise = handleImageData(handler, xref, res, smask);
  32655. maskPromise = Promise.resolve(null);
  32656. } else {
  32657. smaskPromise = Promise.resolve(null);
  32658. if (mask) {
  32659. if (isStream(mask)) {
  32660. maskPromise = handleImageData(handler, xref, res, mask);
  32661. } else if (isArray(mask)) {
  32662. maskPromise = Promise.resolve(mask);
  32663. } else {
  32664. warn('Unsupported mask format.');
  32665. maskPromise = Promise.resolve(null);
  32666. }
  32667. } else {
  32668. maskPromise = Promise.resolve(null);
  32669. }
  32670. }
  32671. return Promise.all([imagePromise, smaskPromise, maskPromise]).then(
  32672. function(results) {
  32673. var imageData = results[0];
  32674. var smaskData = results[1];
  32675. var maskData = results[2];
  32676. return new PDFImage(xref, res, imageData, inline, smaskData, maskData);
  32677. });
  32678. };
  32679. /**
  32680. * Resize an image using the nearest neighbor algorithm. Currently only
  32681. * supports one and three component images.
  32682. * @param {TypedArray} pixels The original image with one component.
  32683. * @param {Number} bpc Number of bits per component.
  32684. * @param {Number} components Number of color components, 1 or 3 is supported.
  32685. * @param {Number} w1 Original width.
  32686. * @param {Number} h1 Original height.
  32687. * @param {Number} w2 New width.
  32688. * @param {Number} h2 New height.
  32689. * @param {TypedArray} dest (Optional) The destination buffer.
  32690. * @param {Number} alpha01 (Optional) Size reserved for the alpha channel.
  32691. * @return {TypedArray} Resized image data.
  32692. */
  32693. PDFImage.resize = function PDFImage_resize(pixels, bpc, components,
  32694. w1, h1, w2, h2, dest, alpha01) {
  32695. if (components !== 1 && components !== 3) {
  32696. error('Unsupported component count for resizing.');
  32697. }
  32698. var length = w2 * h2 * components;
  32699. var temp = dest ? dest : (bpc <= 8 ? new Uint8Array(length) :
  32700. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  32701. var xRatio = w1 / w2;
  32702. var yRatio = h1 / h2;
  32703. var i, j, py, newIndex = 0, oldIndex;
  32704. var xScaled = new Uint16Array(w2);
  32705. var w1Scanline = w1 * components;
  32706. if (alpha01 !== 1) {
  32707. alpha01 = 0;
  32708. }
  32709. for (j = 0; j < w2; j++) {
  32710. xScaled[j] = Math.floor(j * xRatio) * components;
  32711. }
  32712. if (components === 1) {
  32713. for (i = 0; i < h2; i++) {
  32714. py = Math.floor(i * yRatio) * w1Scanline;
  32715. for (j = 0; j < w2; j++) {
  32716. oldIndex = py + xScaled[j];
  32717. temp[newIndex++] = pixels[oldIndex];
  32718. }
  32719. }
  32720. } else if (components === 3) {
  32721. for (i = 0; i < h2; i++) {
  32722. py = Math.floor(i * yRatio) * w1Scanline;
  32723. for (j = 0; j < w2; j++) {
  32724. oldIndex = py + xScaled[j];
  32725. temp[newIndex++] = pixels[oldIndex++];
  32726. temp[newIndex++] = pixels[oldIndex++];
  32727. temp[newIndex++] = pixels[oldIndex++];
  32728. newIndex += alpha01;
  32729. }
  32730. }
  32731. }
  32732. return temp;
  32733. };
  32734. PDFImage.createMask =
  32735. function PDFImage_createMask(imgArray, width, height,
  32736. imageIsFromDecodeStream, inverseDecode) {
  32737. // |imgArray| might not contain full data for every pixel of the mask, so
  32738. // we need to distinguish between |computedLength| and |actualLength|.
  32739. // In particular, if inverseDecode is true, then the array we return must
  32740. // have a length of |computedLength|.
  32741. var computedLength = ((width + 7) >> 3) * height;
  32742. var actualLength = imgArray.byteLength;
  32743. var haveFullData = computedLength === actualLength;
  32744. var data, i;
  32745. if (imageIsFromDecodeStream && (!inverseDecode || haveFullData)) {
  32746. // imgArray came from a DecodeStream and its data is in an appropriate
  32747. // form, so we can just transfer it.
  32748. data = imgArray;
  32749. } else if (!inverseDecode) {
  32750. data = new Uint8Array(actualLength);
  32751. data.set(imgArray);
  32752. } else {
  32753. data = new Uint8Array(computedLength);
  32754. data.set(imgArray);
  32755. for (i = actualLength; i < computedLength; i++) {
  32756. data[i] = 0xff;
  32757. }
  32758. }
  32759. // If necessary, invert the original mask data (but not any extra we might
  32760. // have added above). It's safe to modify the array -- whether it's the
  32761. // original or a copy, we're about to transfer it anyway, so nothing else
  32762. // in this thread can be relying on its contents.
  32763. if (inverseDecode) {
  32764. for (i = 0; i < actualLength; i++) {
  32765. data[i] = ~data[i];
  32766. }
  32767. }
  32768. return {data: data, width: width, height: height};
  32769. };
  32770. PDFImage.prototype = {
  32771. get drawWidth() {
  32772. return Math.max(this.width,
  32773. this.smask && this.smask.width || 0,
  32774. this.mask && this.mask.width || 0);
  32775. },
  32776. get drawHeight() {
  32777. return Math.max(this.height,
  32778. this.smask && this.smask.height || 0,
  32779. this.mask && this.mask.height || 0);
  32780. },
  32781. decodeBuffer: function PDFImage_decodeBuffer(buffer) {
  32782. var bpc = this.bpc;
  32783. var numComps = this.numComps;
  32784. var decodeAddends = this.decodeAddends;
  32785. var decodeCoefficients = this.decodeCoefficients;
  32786. var max = (1 << bpc) - 1;
  32787. var i, ii;
  32788. if (bpc === 1) {
  32789. // If the buffer needed decode that means it just needs to be inverted.
  32790. for (i = 0, ii = buffer.length; i < ii; i++) {
  32791. buffer[i] = +!(buffer[i]);
  32792. }
  32793. return;
  32794. }
  32795. var index = 0;
  32796. for (i = 0, ii = this.width * this.height; i < ii; i++) {
  32797. for (var j = 0; j < numComps; j++) {
  32798. buffer[index] = decodeAndClamp(buffer[index], decodeAddends[j],
  32799. decodeCoefficients[j], max);
  32800. index++;
  32801. }
  32802. }
  32803. },
  32804. getComponents: function PDFImage_getComponents(buffer) {
  32805. var bpc = this.bpc;
  32806. // This image doesn't require any extra work.
  32807. if (bpc === 8) {
  32808. return buffer;
  32809. }
  32810. var width = this.width;
  32811. var height = this.height;
  32812. var numComps = this.numComps;
  32813. var length = width * height * numComps;
  32814. var bufferPos = 0;
  32815. var output = (bpc <= 8 ? new Uint8Array(length) :
  32816. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  32817. var rowComps = width * numComps;
  32818. var max = (1 << bpc) - 1;
  32819. var i = 0, ii, buf;
  32820. if (bpc === 1) {
  32821. // Optimization for reading 1 bpc images.
  32822. var mask, loop1End, loop2End;
  32823. for (var j = 0; j < height; j++) {
  32824. loop1End = i + (rowComps & ~7);
  32825. loop2End = i + rowComps;
  32826. // unroll loop for all full bytes
  32827. while (i < loop1End) {
  32828. buf = buffer[bufferPos++];
  32829. output[i] = (buf >> 7) & 1;
  32830. output[i + 1] = (buf >> 6) & 1;
  32831. output[i + 2] = (buf >> 5) & 1;
  32832. output[i + 3] = (buf >> 4) & 1;
  32833. output[i + 4] = (buf >> 3) & 1;
  32834. output[i + 5] = (buf >> 2) & 1;
  32835. output[i + 6] = (buf >> 1) & 1;
  32836. output[i + 7] = buf & 1;
  32837. i += 8;
  32838. }
  32839. // handle remaing bits
  32840. if (i < loop2End) {
  32841. buf = buffer[bufferPos++];
  32842. mask = 128;
  32843. while (i < loop2End) {
  32844. output[i++] = +!!(buf & mask);
  32845. mask >>= 1;
  32846. }
  32847. }
  32848. }
  32849. } else {
  32850. // The general case that handles all other bpc values.
  32851. var bits = 0;
  32852. buf = 0;
  32853. for (i = 0, ii = length; i < ii; ++i) {
  32854. if (i % rowComps === 0) {
  32855. buf = 0;
  32856. bits = 0;
  32857. }
  32858. while (bits < bpc) {
  32859. buf = (buf << 8) | buffer[bufferPos++];
  32860. bits += 8;
  32861. }
  32862. var remainingBits = bits - bpc;
  32863. var value = buf >> remainingBits;
  32864. output[i] = (value < 0 ? 0 : (value > max ? max : value));
  32865. buf = buf & ((1 << remainingBits) - 1);
  32866. bits = remainingBits;
  32867. }
  32868. }
  32869. return output;
  32870. },
  32871. fillOpacity: function PDFImage_fillOpacity(rgbaBuf, width, height,
  32872. actualHeight, image) {
  32873. var smask = this.smask;
  32874. var mask = this.mask;
  32875. var alphaBuf, sw, sh, i, ii, j;
  32876. if (smask) {
  32877. sw = smask.width;
  32878. sh = smask.height;
  32879. alphaBuf = new Uint8Array(sw * sh);
  32880. smask.fillGrayBuffer(alphaBuf);
  32881. if (sw !== width || sh !== height) {
  32882. alphaBuf = PDFImage.resize(alphaBuf, smask.bpc, 1, sw, sh, width,
  32883. height);
  32884. }
  32885. } else if (mask) {
  32886. if (mask instanceof PDFImage) {
  32887. sw = mask.width;
  32888. sh = mask.height;
  32889. alphaBuf = new Uint8Array(sw * sh);
  32890. mask.numComps = 1;
  32891. mask.fillGrayBuffer(alphaBuf);
  32892. // Need to invert values in rgbaBuf
  32893. for (i = 0, ii = sw * sh; i < ii; ++i) {
  32894. alphaBuf[i] = 255 - alphaBuf[i];
  32895. }
  32896. if (sw !== width || sh !== height) {
  32897. alphaBuf = PDFImage.resize(alphaBuf, mask.bpc, 1, sw, sh, width,
  32898. height);
  32899. }
  32900. } else if (isArray(mask)) {
  32901. // Color key mask: if any of the compontents are outside the range
  32902. // then they should be painted.
  32903. alphaBuf = new Uint8Array(width * height);
  32904. var numComps = this.numComps;
  32905. for (i = 0, ii = width * height; i < ii; ++i) {
  32906. var opacity = 0;
  32907. var imageOffset = i * numComps;
  32908. for (j = 0; j < numComps; ++j) {
  32909. var color = image[imageOffset + j];
  32910. var maskOffset = j * 2;
  32911. if (color < mask[maskOffset] || color > mask[maskOffset + 1]) {
  32912. opacity = 255;
  32913. break;
  32914. }
  32915. }
  32916. alphaBuf[i] = opacity;
  32917. }
  32918. } else {
  32919. error('Unknown mask format.');
  32920. }
  32921. }
  32922. if (alphaBuf) {
  32923. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  32924. rgbaBuf[j] = alphaBuf[i];
  32925. }
  32926. } else {
  32927. // No mask.
  32928. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  32929. rgbaBuf[j] = 255;
  32930. }
  32931. }
  32932. },
  32933. undoPreblend: function PDFImage_undoPreblend(buffer, width, height) {
  32934. var matte = this.smask && this.smask.matte;
  32935. if (!matte) {
  32936. return;
  32937. }
  32938. var matteRgb = this.colorSpace.getRgb(matte, 0);
  32939. var matteR = matteRgb[0];
  32940. var matteG = matteRgb[1];
  32941. var matteB = matteRgb[2];
  32942. var length = width * height * 4;
  32943. var r, g, b;
  32944. for (var i = 0; i < length; i += 4) {
  32945. var alpha = buffer[i + 3];
  32946. if (alpha === 0) {
  32947. // according formula we have to get Infinity in all components
  32948. // making it white (typical paper color) should be okay
  32949. buffer[i] = 255;
  32950. buffer[i + 1] = 255;
  32951. buffer[i + 2] = 255;
  32952. continue;
  32953. }
  32954. var k = 255 / alpha;
  32955. r = (buffer[i] - matteR) * k + matteR;
  32956. g = (buffer[i + 1] - matteG) * k + matteG;
  32957. b = (buffer[i + 2] - matteB) * k + matteB;
  32958. buffer[i] = r <= 0 ? 0 : r >= 255 ? 255 : r | 0;
  32959. buffer[i + 1] = g <= 0 ? 0 : g >= 255 ? 255 : g | 0;
  32960. buffer[i + 2] = b <= 0 ? 0 : b >= 255 ? 255 : b | 0;
  32961. }
  32962. },
  32963. createImageData: function PDFImage_createImageData(forceRGBA) {
  32964. var drawWidth = this.drawWidth;
  32965. var drawHeight = this.drawHeight;
  32966. var imgData = { // other fields are filled in below
  32967. width: drawWidth,
  32968. height: drawHeight
  32969. };
  32970. var numComps = this.numComps;
  32971. var originalWidth = this.width;
  32972. var originalHeight = this.height;
  32973. var bpc = this.bpc;
  32974. // Rows start at byte boundary.
  32975. var rowBytes = (originalWidth * numComps * bpc + 7) >> 3;
  32976. var imgArray;
  32977. if (!forceRGBA) {
  32978. // If it is a 1-bit-per-pixel grayscale (i.e. black-and-white) image
  32979. // without any complications, we pass a same-sized copy to the main
  32980. // thread rather than expanding by 32x to RGBA form. This saves *lots*
  32981. // of memory for many scanned documents. It's also much faster.
  32982. //
  32983. // Similarly, if it is a 24-bit-per pixel RGB image without any
  32984. // complications, we avoid expanding by 1.333x to RGBA form.
  32985. var kind;
  32986. if (this.colorSpace.name === 'DeviceGray' && bpc === 1) {
  32987. kind = ImageKind.GRAYSCALE_1BPP;
  32988. } else if (this.colorSpace.name === 'DeviceRGB' && bpc === 8 &&
  32989. !this.needsDecode) {
  32990. kind = ImageKind.RGB_24BPP;
  32991. }
  32992. if (kind && !this.smask && !this.mask &&
  32993. drawWidth === originalWidth && drawHeight === originalHeight) {
  32994. imgData.kind = kind;
  32995. imgArray = this.getImageBytes(originalHeight * rowBytes);
  32996. // If imgArray came from a DecodeStream, we're safe to transfer it
  32997. // (and thus neuter it) because it will constitute the entire
  32998. // DecodeStream's data. But if it came from a Stream, we need to
  32999. // copy it because it'll only be a portion of the Stream's data, and
  33000. // the rest will be read later on.
  33001. if (this.image instanceof DecodeStream) {
  33002. imgData.data = imgArray;
  33003. } else {
  33004. var newArray = new Uint8Array(imgArray.length);
  33005. newArray.set(imgArray);
  33006. imgData.data = newArray;
  33007. }
  33008. if (this.needsDecode) {
  33009. // Invert the buffer (which must be grayscale if we reached here).
  33010. assert(kind === ImageKind.GRAYSCALE_1BPP);
  33011. var buffer = imgData.data;
  33012. for (var i = 0, ii = buffer.length; i < ii; i++) {
  33013. buffer[i] ^= 0xff;
  33014. }
  33015. }
  33016. return imgData;
  33017. }
  33018. if (this.image instanceof JpegStream && !this.smask && !this.mask &&
  33019. (this.colorSpace.name === 'DeviceGray' ||
  33020. this.colorSpace.name === 'DeviceRGB' ||
  33021. this.colorSpace.name === 'DeviceCMYK')) {
  33022. imgData.kind = ImageKind.RGB_24BPP;
  33023. imgData.data = this.getImageBytes(originalHeight * rowBytes,
  33024. drawWidth, drawHeight, true);
  33025. return imgData;
  33026. }
  33027. }
  33028. imgArray = this.getImageBytes(originalHeight * rowBytes);
  33029. // imgArray can be incomplete (e.g. after CCITT fax encoding).
  33030. var actualHeight = 0 | (imgArray.length / rowBytes *
  33031. drawHeight / originalHeight);
  33032. var comps = this.getComponents(imgArray);
  33033. // If opacity data is present, use RGBA_32BPP form. Otherwise, use the
  33034. // more compact RGB_24BPP form if allowable.
  33035. var alpha01, maybeUndoPreblend;
  33036. if (!forceRGBA && !this.smask && !this.mask) {
  33037. imgData.kind = ImageKind.RGB_24BPP;
  33038. imgData.data = new Uint8Array(drawWidth * drawHeight * 3);
  33039. alpha01 = 0;
  33040. maybeUndoPreblend = false;
  33041. } else {
  33042. imgData.kind = ImageKind.RGBA_32BPP;
  33043. imgData.data = new Uint8Array(drawWidth * drawHeight * 4);
  33044. alpha01 = 1;
  33045. maybeUndoPreblend = true;
  33046. // Color key masking (opacity) must be performed before decoding.
  33047. this.fillOpacity(imgData.data, drawWidth, drawHeight, actualHeight,
  33048. comps);
  33049. }
  33050. if (this.needsDecode) {
  33051. this.decodeBuffer(comps);
  33052. }
  33053. this.colorSpace.fillRgb(imgData.data, originalWidth, originalHeight,
  33054. drawWidth, drawHeight, actualHeight, bpc, comps,
  33055. alpha01);
  33056. if (maybeUndoPreblend) {
  33057. this.undoPreblend(imgData.data, drawWidth, actualHeight);
  33058. }
  33059. return imgData;
  33060. },
  33061. fillGrayBuffer: function PDFImage_fillGrayBuffer(buffer) {
  33062. var numComps = this.numComps;
  33063. if (numComps !== 1) {
  33064. error('Reading gray scale from a color image: ' + numComps);
  33065. }
  33066. var width = this.width;
  33067. var height = this.height;
  33068. var bpc = this.bpc;
  33069. // rows start at byte boundary
  33070. var rowBytes = (width * numComps * bpc + 7) >> 3;
  33071. var imgArray = this.getImageBytes(height * rowBytes);
  33072. var comps = this.getComponents(imgArray);
  33073. var i, length;
  33074. if (bpc === 1) {
  33075. // inline decoding (= inversion) for 1 bpc images
  33076. length = width * height;
  33077. if (this.needsDecode) {
  33078. // invert and scale to {0, 255}
  33079. for (i = 0; i < length; ++i) {
  33080. buffer[i] = (comps[i] - 1) & 255;
  33081. }
  33082. } else {
  33083. // scale to {0, 255}
  33084. for (i = 0; i < length; ++i) {
  33085. buffer[i] = (-comps[i]) & 255;
  33086. }
  33087. }
  33088. return;
  33089. }
  33090. if (this.needsDecode) {
  33091. this.decodeBuffer(comps);
  33092. }
  33093. length = width * height;
  33094. // we aren't using a colorspace so we need to scale the value
  33095. var scale = 255 / ((1 << bpc) - 1);
  33096. for (i = 0; i < length; ++i) {
  33097. buffer[i] = (scale * comps[i]) | 0;
  33098. }
  33099. },
  33100. getImageBytes: function PDFImage_getImageBytes(length,
  33101. drawWidth, drawHeight,
  33102. forceRGB) {
  33103. this.image.reset();
  33104. this.image.drawWidth = drawWidth || this.width;
  33105. this.image.drawHeight = drawHeight || this.height;
  33106. this.image.forceRGB = !!forceRGB;
  33107. return this.image.getBytes(length);
  33108. }
  33109. };
  33110. return PDFImage;
  33111. })();
  33112. exports.PDFImage = PDFImage;
  33113. // TODO refactor to remove dependency on colorspace.js
  33114. coreColorSpace._setCoreImage(exports);
  33115. }));
  33116. (function (root, factory) {
  33117. {
  33118. factory((root.pdfjsCorePattern = {}), root.pdfjsSharedUtil,
  33119. root.pdfjsCorePrimitives, root.pdfjsCoreFunction,
  33120. root.pdfjsCoreColorSpace);
  33121. }
  33122. }(this, function (exports, sharedUtil, corePrimitives, coreFunction,
  33123. coreColorSpace) {
  33124. var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  33125. var MissingDataException = sharedUtil.MissingDataException;
  33126. var Util = sharedUtil.Util;
  33127. var assert = sharedUtil.assert;
  33128. var error = sharedUtil.error;
  33129. var info = sharedUtil.info;
  33130. var warn = sharedUtil.warn;
  33131. var isStream = corePrimitives.isStream;
  33132. var PDFFunction = coreFunction.PDFFunction;
  33133. var ColorSpace = coreColorSpace.ColorSpace;
  33134. var ShadingType = {
  33135. FUNCTION_BASED: 1,
  33136. AXIAL: 2,
  33137. RADIAL: 3,
  33138. FREE_FORM_MESH: 4,
  33139. LATTICE_FORM_MESH: 5,
  33140. COONS_PATCH_MESH: 6,
  33141. TENSOR_PATCH_MESH: 7
  33142. };
  33143. var Pattern = (function PatternClosure() {
  33144. // Constructor should define this.getPattern
  33145. function Pattern() {
  33146. error('should not call Pattern constructor');
  33147. }
  33148. Pattern.prototype = {
  33149. // Input: current Canvas context
  33150. // Output: the appropriate fillStyle or strokeStyle
  33151. getPattern: function Pattern_getPattern(ctx) {
  33152. error('Should not call Pattern.getStyle: ' + ctx);
  33153. }
  33154. };
  33155. Pattern.parseShading = function Pattern_parseShading(shading, matrix, xref,
  33156. res, handler) {
  33157. var dict = isStream(shading) ? shading.dict : shading;
  33158. var type = dict.get('ShadingType');
  33159. try {
  33160. switch (type) {
  33161. case ShadingType.AXIAL:
  33162. case ShadingType.RADIAL:
  33163. // Both radial and axial shadings are handled by RadialAxial shading.
  33164. return new Shadings.RadialAxial(dict, matrix, xref, res);
  33165. case ShadingType.FREE_FORM_MESH:
  33166. case ShadingType.LATTICE_FORM_MESH:
  33167. case ShadingType.COONS_PATCH_MESH:
  33168. case ShadingType.TENSOR_PATCH_MESH:
  33169. return new Shadings.Mesh(shading, matrix, xref, res);
  33170. default:
  33171. throw new Error('Unsupported ShadingType: ' + type);
  33172. }
  33173. } catch (ex) {
  33174. if (ex instanceof MissingDataException) {
  33175. throw ex;
  33176. }
  33177. handler.send('UnsupportedFeature',
  33178. {featureId: UNSUPPORTED_FEATURES.shadingPattern});
  33179. warn(ex);
  33180. return new Shadings.Dummy();
  33181. }
  33182. };
  33183. return Pattern;
  33184. })();
  33185. var Shadings = {};
  33186. // A small number to offset the first/last color stops so we can insert ones to
  33187. // support extend. Number.MIN_VALUE appears to be too small and breaks the
  33188. // extend. 1e-7 works in FF but chrome seems to use an even smaller sized number
  33189. // internally so we have to go bigger.
  33190. Shadings.SMALL_NUMBER = 1e-2;
  33191. // Radial and axial shading have very similar implementations
  33192. // If needed, the implementations can be broken into two classes
  33193. Shadings.RadialAxial = (function RadialAxialClosure() {
  33194. function RadialAxial(dict, matrix, xref, res) {
  33195. this.matrix = matrix;
  33196. this.coordsArr = dict.get('Coords');
  33197. this.shadingType = dict.get('ShadingType');
  33198. this.type = 'Pattern';
  33199. var cs = dict.get('ColorSpace', 'CS');
  33200. cs = ColorSpace.parse(cs, xref, res);
  33201. this.cs = cs;
  33202. var t0 = 0.0, t1 = 1.0;
  33203. if (dict.has('Domain')) {
  33204. var domainArr = dict.get('Domain');
  33205. t0 = domainArr[0];
  33206. t1 = domainArr[1];
  33207. }
  33208. var extendStart = false, extendEnd = false;
  33209. if (dict.has('Extend')) {
  33210. var extendArr = dict.get('Extend');
  33211. extendStart = extendArr[0];
  33212. extendEnd = extendArr[1];
  33213. }
  33214. if (this.shadingType === ShadingType.RADIAL &&
  33215. (!extendStart || !extendEnd)) {
  33216. // Radial gradient only currently works if either circle is fully within
  33217. // the other circle.
  33218. var x1 = this.coordsArr[0];
  33219. var y1 = this.coordsArr[1];
  33220. var r1 = this.coordsArr[2];
  33221. var x2 = this.coordsArr[3];
  33222. var y2 = this.coordsArr[4];
  33223. var r2 = this.coordsArr[5];
  33224. var distance = Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
  33225. if (r1 <= r2 + distance &&
  33226. r2 <= r1 + distance) {
  33227. warn('Unsupported radial gradient.');
  33228. }
  33229. }
  33230. this.extendStart = extendStart;
  33231. this.extendEnd = extendEnd;
  33232. var fnObj = dict.get('Function');
  33233. var fn = PDFFunction.parseArray(xref, fnObj);
  33234. // 10 samples seems good enough for now, but probably won't work
  33235. // if there are sharp color changes. Ideally, we would implement
  33236. // the spec faithfully and add lossless optimizations.
  33237. var diff = t1 - t0;
  33238. var step = diff / 10;
  33239. var colorStops = this.colorStops = [];
  33240. // Protect against bad domains so we don't end up in an infinte loop below.
  33241. if (t0 >= t1 || step <= 0) {
  33242. // Acrobat doesn't seem to handle these cases so we'll ignore for
  33243. // now.
  33244. info('Bad shading domain.');
  33245. return;
  33246. }
  33247. var color = new Float32Array(cs.numComps), ratio = new Float32Array(1);
  33248. var rgbColor;
  33249. for (var i = t0; i <= t1; i += step) {
  33250. ratio[0] = i;
  33251. fn(ratio, 0, color, 0);
  33252. rgbColor = cs.getRgb(color, 0);
  33253. var cssColor = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  33254. colorStops.push([(i - t0) / diff, cssColor]);
  33255. }
  33256. var background = 'transparent';
  33257. if (dict.has('Background')) {
  33258. rgbColor = cs.getRgb(dict.get('Background'), 0);
  33259. background = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  33260. }
  33261. if (!extendStart) {
  33262. // Insert a color stop at the front and offset the first real color stop
  33263. // so it doesn't conflict with the one we insert.
  33264. colorStops.unshift([0, background]);
  33265. colorStops[1][0] += Shadings.SMALL_NUMBER;
  33266. }
  33267. if (!extendEnd) {
  33268. // Same idea as above in extendStart but for the end.
  33269. colorStops[colorStops.length - 1][0] -= Shadings.SMALL_NUMBER;
  33270. colorStops.push([1, background]);
  33271. }
  33272. this.colorStops = colorStops;
  33273. }
  33274. RadialAxial.prototype = {
  33275. getIR: function RadialAxial_getIR() {
  33276. var coordsArr = this.coordsArr;
  33277. var shadingType = this.shadingType;
  33278. var type, p0, p1, r0, r1;
  33279. if (shadingType === ShadingType.AXIAL) {
  33280. p0 = [coordsArr[0], coordsArr[1]];
  33281. p1 = [coordsArr[2], coordsArr[3]];
  33282. r0 = null;
  33283. r1 = null;
  33284. type = 'axial';
  33285. } else if (shadingType === ShadingType.RADIAL) {
  33286. p0 = [coordsArr[0], coordsArr[1]];
  33287. p1 = [coordsArr[3], coordsArr[4]];
  33288. r0 = coordsArr[2];
  33289. r1 = coordsArr[5];
  33290. type = 'radial';
  33291. } else {
  33292. error('getPattern type unknown: ' + shadingType);
  33293. }
  33294. var matrix = this.matrix;
  33295. if (matrix) {
  33296. p0 = Util.applyTransform(p0, matrix);
  33297. p1 = Util.applyTransform(p1, matrix);
  33298. if (shadingType === ShadingType.RADIAL) {
  33299. var scale = Util.singularValueDecompose2dScale(matrix);
  33300. r0 *= scale[0];
  33301. r1 *= scale[1];
  33302. }
  33303. }
  33304. return ['RadialAxial', type, this.colorStops, p0, p1, r0, r1];
  33305. }
  33306. };
  33307. return RadialAxial;
  33308. })();
  33309. // All mesh shading. For now, they will be presented as set of the triangles
  33310. // to be drawn on the canvas and rgb color for each vertex.
  33311. Shadings.Mesh = (function MeshClosure() {
  33312. function MeshStreamReader(stream, context) {
  33313. this.stream = stream;
  33314. this.context = context;
  33315. this.buffer = 0;
  33316. this.bufferLength = 0;
  33317. var numComps = context.numComps;
  33318. this.tmpCompsBuf = new Float32Array(numComps);
  33319. var csNumComps = context.colorSpace.numComps;
  33320. this.tmpCsCompsBuf = context.colorFn ? new Float32Array(csNumComps) :
  33321. this.tmpCompsBuf;
  33322. }
  33323. MeshStreamReader.prototype = {
  33324. get hasData() {
  33325. if (this.stream.end) {
  33326. return this.stream.pos < this.stream.end;
  33327. }
  33328. if (this.bufferLength > 0) {
  33329. return true;
  33330. }
  33331. var nextByte = this.stream.getByte();
  33332. if (nextByte < 0) {
  33333. return false;
  33334. }
  33335. this.buffer = nextByte;
  33336. this.bufferLength = 8;
  33337. return true;
  33338. },
  33339. readBits: function MeshStreamReader_readBits(n) {
  33340. var buffer = this.buffer;
  33341. var bufferLength = this.bufferLength;
  33342. if (n === 32) {
  33343. if (bufferLength === 0) {
  33344. return ((this.stream.getByte() << 24) |
  33345. (this.stream.getByte() << 16) | (this.stream.getByte() << 8) |
  33346. this.stream.getByte()) >>> 0;
  33347. }
  33348. buffer = (buffer << 24) | (this.stream.getByte() << 16) |
  33349. (this.stream.getByte() << 8) | this.stream.getByte();
  33350. var nextByte = this.stream.getByte();
  33351. this.buffer = nextByte & ((1 << bufferLength) - 1);
  33352. return ((buffer << (8 - bufferLength)) |
  33353. ((nextByte & 0xFF) >> bufferLength)) >>> 0;
  33354. }
  33355. if (n === 8 && bufferLength === 0) {
  33356. return this.stream.getByte();
  33357. }
  33358. while (bufferLength < n) {
  33359. buffer = (buffer << 8) | this.stream.getByte();
  33360. bufferLength += 8;
  33361. }
  33362. bufferLength -= n;
  33363. this.bufferLength = bufferLength;
  33364. this.buffer = buffer & ((1 << bufferLength) - 1);
  33365. return buffer >> bufferLength;
  33366. },
  33367. align: function MeshStreamReader_align() {
  33368. this.buffer = 0;
  33369. this.bufferLength = 0;
  33370. },
  33371. readFlag: function MeshStreamReader_readFlag() {
  33372. return this.readBits(this.context.bitsPerFlag);
  33373. },
  33374. readCoordinate: function MeshStreamReader_readCoordinate() {
  33375. var bitsPerCoordinate = this.context.bitsPerCoordinate;
  33376. var xi = this.readBits(bitsPerCoordinate);
  33377. var yi = this.readBits(bitsPerCoordinate);
  33378. var decode = this.context.decode;
  33379. var scale = bitsPerCoordinate < 32 ? 1 / ((1 << bitsPerCoordinate) - 1) :
  33380. 2.3283064365386963e-10; // 2 ^ -32
  33381. return [
  33382. xi * scale * (decode[1] - decode[0]) + decode[0],
  33383. yi * scale * (decode[3] - decode[2]) + decode[2]
  33384. ];
  33385. },
  33386. readComponents: function MeshStreamReader_readComponents() {
  33387. var numComps = this.context.numComps;
  33388. var bitsPerComponent = this.context.bitsPerComponent;
  33389. var scale = bitsPerComponent < 32 ? 1 / ((1 << bitsPerComponent) - 1) :
  33390. 2.3283064365386963e-10; // 2 ^ -32
  33391. var decode = this.context.decode;
  33392. var components = this.tmpCompsBuf;
  33393. for (var i = 0, j = 4; i < numComps; i++, j += 2) {
  33394. var ci = this.readBits(bitsPerComponent);
  33395. components[i] = ci * scale * (decode[j + 1] - decode[j]) + decode[j];
  33396. }
  33397. var color = this.tmpCsCompsBuf;
  33398. if (this.context.colorFn) {
  33399. this.context.colorFn(components, 0, color, 0);
  33400. }
  33401. return this.context.colorSpace.getRgb(color, 0);
  33402. }
  33403. };
  33404. function decodeType4Shading(mesh, reader) {
  33405. var coords = mesh.coords;
  33406. var colors = mesh.colors;
  33407. var operators = [];
  33408. var ps = []; // not maintaining cs since that will match ps
  33409. var verticesLeft = 0; // assuming we have all data to start a new triangle
  33410. while (reader.hasData) {
  33411. var f = reader.readFlag();
  33412. var coord = reader.readCoordinate();
  33413. var color = reader.readComponents();
  33414. if (verticesLeft === 0) { // ignoring flags if we started a triangle
  33415. assert(0 <= f && f <= 2, 'Unknown type4 flag');
  33416. switch (f) {
  33417. case 0:
  33418. verticesLeft = 3;
  33419. break;
  33420. case 1:
  33421. ps.push(ps[ps.length - 2], ps[ps.length - 1]);
  33422. verticesLeft = 1;
  33423. break;
  33424. case 2:
  33425. ps.push(ps[ps.length - 3], ps[ps.length - 1]);
  33426. verticesLeft = 1;
  33427. break;
  33428. }
  33429. operators.push(f);
  33430. }
  33431. ps.push(coords.length);
  33432. coords.push(coord);
  33433. colors.push(color);
  33434. verticesLeft--;
  33435. reader.align();
  33436. }
  33437. mesh.figures.push({
  33438. type: 'triangles',
  33439. coords: new Int32Array(ps),
  33440. colors: new Int32Array(ps),
  33441. });
  33442. }
  33443. function decodeType5Shading(mesh, reader, verticesPerRow) {
  33444. var coords = mesh.coords;
  33445. var colors = mesh.colors;
  33446. var ps = []; // not maintaining cs since that will match ps
  33447. while (reader.hasData) {
  33448. var coord = reader.readCoordinate();
  33449. var color = reader.readComponents();
  33450. ps.push(coords.length);
  33451. coords.push(coord);
  33452. colors.push(color);
  33453. }
  33454. mesh.figures.push({
  33455. type: 'lattice',
  33456. coords: new Int32Array(ps),
  33457. colors: new Int32Array(ps),
  33458. verticesPerRow: verticesPerRow
  33459. });
  33460. }
  33461. var MIN_SPLIT_PATCH_CHUNKS_AMOUNT = 3;
  33462. var MAX_SPLIT_PATCH_CHUNKS_AMOUNT = 20;
  33463. var TRIANGLE_DENSITY = 20; // count of triangles per entire mesh bounds
  33464. var getB = (function getBClosure() {
  33465. function buildB(count) {
  33466. var lut = [];
  33467. for (var i = 0; i <= count; i++) {
  33468. var t = i / count, t_ = 1 - t;
  33469. lut.push(new Float32Array([t_ * t_ * t_, 3 * t * t_ * t_,
  33470. 3 * t * t * t_, t * t * t]));
  33471. }
  33472. return lut;
  33473. }
  33474. var cache = [];
  33475. return function getB(count) {
  33476. if (!cache[count]) {
  33477. cache[count] = buildB(count);
  33478. }
  33479. return cache[count];
  33480. };
  33481. })();
  33482. function buildFigureFromPatch(mesh, index) {
  33483. var figure = mesh.figures[index];
  33484. assert(figure.type === 'patch', 'Unexpected patch mesh figure');
  33485. var coords = mesh.coords, colors = mesh.colors;
  33486. var pi = figure.coords;
  33487. var ci = figure.colors;
  33488. var figureMinX = Math.min(coords[pi[0]][0], coords[pi[3]][0],
  33489. coords[pi[12]][0], coords[pi[15]][0]);
  33490. var figureMinY = Math.min(coords[pi[0]][1], coords[pi[3]][1],
  33491. coords[pi[12]][1], coords[pi[15]][1]);
  33492. var figureMaxX = Math.max(coords[pi[0]][0], coords[pi[3]][0],
  33493. coords[pi[12]][0], coords[pi[15]][0]);
  33494. var figureMaxY = Math.max(coords[pi[0]][1], coords[pi[3]][1],
  33495. coords[pi[12]][1], coords[pi[15]][1]);
  33496. var splitXBy = Math.ceil((figureMaxX - figureMinX) * TRIANGLE_DENSITY /
  33497. (mesh.bounds[2] - mesh.bounds[0]));
  33498. splitXBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  33499. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitXBy));
  33500. var splitYBy = Math.ceil((figureMaxY - figureMinY) * TRIANGLE_DENSITY /
  33501. (mesh.bounds[3] - mesh.bounds[1]));
  33502. splitYBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  33503. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitYBy));
  33504. var verticesPerRow = splitXBy + 1;
  33505. var figureCoords = new Int32Array((splitYBy + 1) * verticesPerRow);
  33506. var figureColors = new Int32Array((splitYBy + 1) * verticesPerRow);
  33507. var k = 0;
  33508. var cl = new Uint8Array(3), cr = new Uint8Array(3);
  33509. var c0 = colors[ci[0]], c1 = colors[ci[1]],
  33510. c2 = colors[ci[2]], c3 = colors[ci[3]];
  33511. var bRow = getB(splitYBy), bCol = getB(splitXBy);
  33512. for (var row = 0; row <= splitYBy; row++) {
  33513. cl[0] = ((c0[0] * (splitYBy - row) + c2[0] * row) / splitYBy) | 0;
  33514. cl[1] = ((c0[1] * (splitYBy - row) + c2[1] * row) / splitYBy) | 0;
  33515. cl[2] = ((c0[2] * (splitYBy - row) + c2[2] * row) / splitYBy) | 0;
  33516. cr[0] = ((c1[0] * (splitYBy - row) + c3[0] * row) / splitYBy) | 0;
  33517. cr[1] = ((c1[1] * (splitYBy - row) + c3[1] * row) / splitYBy) | 0;
  33518. cr[2] = ((c1[2] * (splitYBy - row) + c3[2] * row) / splitYBy) | 0;
  33519. for (var col = 0; col <= splitXBy; col++, k++) {
  33520. if ((row === 0 || row === splitYBy) &&
  33521. (col === 0 || col === splitXBy)) {
  33522. continue;
  33523. }
  33524. var x = 0, y = 0;
  33525. var q = 0;
  33526. for (var i = 0; i <= 3; i++) {
  33527. for (var j = 0; j <= 3; j++, q++) {
  33528. var m = bRow[row][i] * bCol[col][j];
  33529. x += coords[pi[q]][0] * m;
  33530. y += coords[pi[q]][1] * m;
  33531. }
  33532. }
  33533. figureCoords[k] = coords.length;
  33534. coords.push([x, y]);
  33535. figureColors[k] = colors.length;
  33536. var newColor = new Uint8Array(3);
  33537. newColor[0] = ((cl[0] * (splitXBy - col) + cr[0] * col) / splitXBy) | 0;
  33538. newColor[1] = ((cl[1] * (splitXBy - col) + cr[1] * col) / splitXBy) | 0;
  33539. newColor[2] = ((cl[2] * (splitXBy - col) + cr[2] * col) / splitXBy) | 0;
  33540. colors.push(newColor);
  33541. }
  33542. }
  33543. figureCoords[0] = pi[0];
  33544. figureColors[0] = ci[0];
  33545. figureCoords[splitXBy] = pi[3];
  33546. figureColors[splitXBy] = ci[1];
  33547. figureCoords[verticesPerRow * splitYBy] = pi[12];
  33548. figureColors[verticesPerRow * splitYBy] = ci[2];
  33549. figureCoords[verticesPerRow * splitYBy + splitXBy] = pi[15];
  33550. figureColors[verticesPerRow * splitYBy + splitXBy] = ci[3];
  33551. mesh.figures[index] = {
  33552. type: 'lattice',
  33553. coords: figureCoords,
  33554. colors: figureColors,
  33555. verticesPerRow: verticesPerRow
  33556. };
  33557. }
  33558. function decodeType6Shading(mesh, reader) {
  33559. // A special case of Type 7. The p11, p12, p21, p22 automatically filled
  33560. var coords = mesh.coords;
  33561. var colors = mesh.colors;
  33562. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  33563. var cs = new Int32Array(4); // c00, c30, c03, c33
  33564. while (reader.hasData) {
  33565. var f = reader.readFlag();
  33566. assert(0 <= f && f <= 3, 'Unknown type6 flag');
  33567. var i, ii;
  33568. var pi = coords.length;
  33569. for (i = 0, ii = (f !== 0 ? 8 : 12); i < ii; i++) {
  33570. coords.push(reader.readCoordinate());
  33571. }
  33572. var ci = colors.length;
  33573. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  33574. colors.push(reader.readComponents());
  33575. }
  33576. var tmp1, tmp2, tmp3, tmp4;
  33577. switch (f) {
  33578. case 0:
  33579. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  33580. ps[ 8] = pi + 2; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 7;
  33581. ps[ 4] = pi + 1; /* calculated below */ ps[ 7] = pi + 8;
  33582. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  33583. cs[2] = ci + 1; cs[3] = ci + 2;
  33584. cs[0] = ci; cs[1] = ci + 3;
  33585. break;
  33586. case 1:
  33587. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  33588. ps[12] = tmp4; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  33589. ps[ 8] = tmp3; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 3;
  33590. ps[ 4] = tmp2; /* calculated below */ ps[ 7] = pi + 4;
  33591. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  33592. tmp1 = cs[2]; tmp2 = cs[3];
  33593. cs[2] = tmp2; cs[3] = ci;
  33594. cs[0] = tmp1; cs[1] = ci + 1;
  33595. break;
  33596. case 2:
  33597. tmp1 = ps[15];
  33598. tmp2 = ps[11];
  33599. ps[12] = ps[3]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  33600. ps[ 8] = ps[7]; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 3;
  33601. ps[ 4] = tmp2; /* calculated below */ ps[ 7] = pi + 4;
  33602. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  33603. tmp1 = cs[3];
  33604. cs[2] = cs[1]; cs[3] = ci;
  33605. cs[0] = tmp1; cs[1] = ci + 1;
  33606. break;
  33607. case 3:
  33608. ps[12] = ps[0]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  33609. ps[ 8] = ps[1]; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 3;
  33610. ps[ 4] = ps[2]; /* calculated below */ ps[ 7] = pi + 4;
  33611. ps[ 0] = ps[3]; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  33612. cs[2] = cs[0]; cs[3] = ci;
  33613. cs[0] = cs[1]; cs[1] = ci + 1;
  33614. break;
  33615. }
  33616. // set p11, p12, p21, p22
  33617. ps[5] = coords.length;
  33618. coords.push([
  33619. (-4 * coords[ps[0]][0] - coords[ps[15]][0] +
  33620. 6 * (coords[ps[4]][0] + coords[ps[1]][0]) -
  33621. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  33622. 3 * (coords[ps[13]][0] + coords[ps[7]][0])) / 9,
  33623. (-4 * coords[ps[0]][1] - coords[ps[15]][1] +
  33624. 6 * (coords[ps[4]][1] + coords[ps[1]][1]) -
  33625. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  33626. 3 * (coords[ps[13]][1] + coords[ps[7]][1])) / 9
  33627. ]);
  33628. ps[6] = coords.length;
  33629. coords.push([
  33630. (-4 * coords[ps[3]][0] - coords[ps[12]][0] +
  33631. 6 * (coords[ps[2]][0] + coords[ps[7]][0]) -
  33632. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  33633. 3 * (coords[ps[4]][0] + coords[ps[14]][0])) / 9,
  33634. (-4 * coords[ps[3]][1] - coords[ps[12]][1] +
  33635. 6 * (coords[ps[2]][1] + coords[ps[7]][1]) -
  33636. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  33637. 3 * (coords[ps[4]][1] + coords[ps[14]][1])) / 9
  33638. ]);
  33639. ps[9] = coords.length;
  33640. coords.push([
  33641. (-4 * coords[ps[12]][0] - coords[ps[3]][0] +
  33642. 6 * (coords[ps[8]][0] + coords[ps[13]][0]) -
  33643. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  33644. 3 * (coords[ps[11]][0] + coords[ps[1]][0])) / 9,
  33645. (-4 * coords[ps[12]][1] - coords[ps[3]][1] +
  33646. 6 * (coords[ps[8]][1] + coords[ps[13]][1]) -
  33647. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  33648. 3 * (coords[ps[11]][1] + coords[ps[1]][1])) / 9
  33649. ]);
  33650. ps[10] = coords.length;
  33651. coords.push([
  33652. (-4 * coords[ps[15]][0] - coords[ps[0]][0] +
  33653. 6 * (coords[ps[11]][0] + coords[ps[14]][0]) -
  33654. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  33655. 3 * (coords[ps[2]][0] + coords[ps[8]][0])) / 9,
  33656. (-4 * coords[ps[15]][1] - coords[ps[0]][1] +
  33657. 6 * (coords[ps[11]][1] + coords[ps[14]][1]) -
  33658. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  33659. 3 * (coords[ps[2]][1] + coords[ps[8]][1])) / 9
  33660. ]);
  33661. mesh.figures.push({
  33662. type: 'patch',
  33663. coords: new Int32Array(ps), // making copies of ps and cs
  33664. colors: new Int32Array(cs)
  33665. });
  33666. }
  33667. }
  33668. function decodeType7Shading(mesh, reader) {
  33669. var coords = mesh.coords;
  33670. var colors = mesh.colors;
  33671. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  33672. var cs = new Int32Array(4); // c00, c30, c03, c33
  33673. while (reader.hasData) {
  33674. var f = reader.readFlag();
  33675. assert(0 <= f && f <= 3, 'Unknown type7 flag');
  33676. var i, ii;
  33677. var pi = coords.length;
  33678. for (i = 0, ii = (f !== 0 ? 12 : 16); i < ii; i++) {
  33679. coords.push(reader.readCoordinate());
  33680. }
  33681. var ci = colors.length;
  33682. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  33683. colors.push(reader.readComponents());
  33684. }
  33685. var tmp1, tmp2, tmp3, tmp4;
  33686. switch (f) {
  33687. case 0:
  33688. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  33689. ps[ 8] = pi + 2; ps[ 9] = pi + 13; ps[10] = pi + 14; ps[11] = pi + 7;
  33690. ps[ 4] = pi + 1; ps[ 5] = pi + 12; ps[ 6] = pi + 15; ps[ 7] = pi + 8;
  33691. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  33692. cs[2] = ci + 1; cs[3] = ci + 2;
  33693. cs[0] = ci; cs[1] = ci + 3;
  33694. break;
  33695. case 1:
  33696. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  33697. ps[12] = tmp4; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  33698. ps[ 8] = tmp3; ps[ 9] = pi + 9; ps[10] = pi + 10; ps[11] = pi + 3;
  33699. ps[ 4] = tmp2; ps[ 5] = pi + 8; ps[ 6] = pi + 11; ps[ 7] = pi + 4;
  33700. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  33701. tmp1 = cs[2]; tmp2 = cs[3];
  33702. cs[2] = tmp2; cs[3] = ci;
  33703. cs[0] = tmp1; cs[1] = ci + 1;
  33704. break;
  33705. case 2:
  33706. tmp1 = ps[15];
  33707. tmp2 = ps[11];
  33708. ps[12] = ps[3]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  33709. ps[ 8] = ps[7]; ps[ 9] = pi + 9; ps[10] = pi + 10; ps[11] = pi + 3;
  33710. ps[ 4] = tmp2; ps[ 5] = pi + 8; ps[ 6] = pi + 11; ps[ 7] = pi + 4;
  33711. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  33712. tmp1 = cs[3];
  33713. cs[2] = cs[1]; cs[3] = ci;
  33714. cs[0] = tmp1; cs[1] = ci + 1;
  33715. break;
  33716. case 3:
  33717. ps[12] = ps[0]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  33718. ps[ 8] = ps[1]; ps[ 9] = pi + 9; ps[10] = pi + 10; ps[11] = pi + 3;
  33719. ps[ 4] = ps[2]; ps[ 5] = pi + 8; ps[ 6] = pi + 11; ps[ 7] = pi + 4;
  33720. ps[ 0] = ps[3]; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  33721. cs[2] = cs[0]; cs[3] = ci;
  33722. cs[0] = cs[1]; cs[1] = ci + 1;
  33723. break;
  33724. }
  33725. mesh.figures.push({
  33726. type: 'patch',
  33727. coords: new Int32Array(ps), // making copies of ps and cs
  33728. colors: new Int32Array(cs)
  33729. });
  33730. }
  33731. }
  33732. function updateBounds(mesh) {
  33733. var minX = mesh.coords[0][0], minY = mesh.coords[0][1],
  33734. maxX = minX, maxY = minY;
  33735. for (var i = 1, ii = mesh.coords.length; i < ii; i++) {
  33736. var x = mesh.coords[i][0], y = mesh.coords[i][1];
  33737. minX = minX > x ? x : minX;
  33738. minY = minY > y ? y : minY;
  33739. maxX = maxX < x ? x : maxX;
  33740. maxY = maxY < y ? y : maxY;
  33741. }
  33742. mesh.bounds = [minX, minY, maxX, maxY];
  33743. }
  33744. function packData(mesh) {
  33745. var i, ii, j, jj;
  33746. var coords = mesh.coords;
  33747. var coordsPacked = new Float32Array(coords.length * 2);
  33748. for (i = 0, j = 0, ii = coords.length; i < ii; i++) {
  33749. var xy = coords[i];
  33750. coordsPacked[j++] = xy[0];
  33751. coordsPacked[j++] = xy[1];
  33752. }
  33753. mesh.coords = coordsPacked;
  33754. var colors = mesh.colors;
  33755. var colorsPacked = new Uint8Array(colors.length * 3);
  33756. for (i = 0, j = 0, ii = colors.length; i < ii; i++) {
  33757. var c = colors[i];
  33758. colorsPacked[j++] = c[0];
  33759. colorsPacked[j++] = c[1];
  33760. colorsPacked[j++] = c[2];
  33761. }
  33762. mesh.colors = colorsPacked;
  33763. var figures = mesh.figures;
  33764. for (i = 0, ii = figures.length; i < ii; i++) {
  33765. var figure = figures[i], ps = figure.coords, cs = figure.colors;
  33766. for (j = 0, jj = ps.length; j < jj; j++) {
  33767. ps[j] *= 2;
  33768. cs[j] *= 3;
  33769. }
  33770. }
  33771. }
  33772. function Mesh(stream, matrix, xref, res) {
  33773. assert(isStream(stream), 'Mesh data is not a stream');
  33774. var dict = stream.dict;
  33775. this.matrix = matrix;
  33776. this.shadingType = dict.get('ShadingType');
  33777. this.type = 'Pattern';
  33778. this.bbox = dict.get('BBox');
  33779. var cs = dict.get('ColorSpace', 'CS');
  33780. cs = ColorSpace.parse(cs, xref, res);
  33781. this.cs = cs;
  33782. this.background = dict.has('Background') ?
  33783. cs.getRgb(dict.get('Background'), 0) : null;
  33784. var fnObj = dict.get('Function');
  33785. var fn = fnObj ? PDFFunction.parseArray(xref, fnObj) : null;
  33786. this.coords = [];
  33787. this.colors = [];
  33788. this.figures = [];
  33789. var decodeContext = {
  33790. bitsPerCoordinate: dict.get('BitsPerCoordinate'),
  33791. bitsPerComponent: dict.get('BitsPerComponent'),
  33792. bitsPerFlag: dict.get('BitsPerFlag'),
  33793. decode: dict.get('Decode'),
  33794. colorFn: fn,
  33795. colorSpace: cs,
  33796. numComps: fn ? 1 : cs.numComps
  33797. };
  33798. var reader = new MeshStreamReader(stream, decodeContext);
  33799. var patchMesh = false;
  33800. switch (this.shadingType) {
  33801. case ShadingType.FREE_FORM_MESH:
  33802. decodeType4Shading(this, reader);
  33803. break;
  33804. case ShadingType.LATTICE_FORM_MESH:
  33805. var verticesPerRow = dict.get('VerticesPerRow') | 0;
  33806. assert(verticesPerRow >= 2, 'Invalid VerticesPerRow');
  33807. decodeType5Shading(this, reader, verticesPerRow);
  33808. break;
  33809. case ShadingType.COONS_PATCH_MESH:
  33810. decodeType6Shading(this, reader);
  33811. patchMesh = true;
  33812. break;
  33813. case ShadingType.TENSOR_PATCH_MESH:
  33814. decodeType7Shading(this, reader);
  33815. patchMesh = true;
  33816. break;
  33817. default:
  33818. error('Unsupported mesh type.');
  33819. break;
  33820. }
  33821. if (patchMesh) {
  33822. // dirty bounds calculation for determining, how dense shall be triangles
  33823. updateBounds(this);
  33824. for (var i = 0, ii = this.figures.length; i < ii; i++) {
  33825. buildFigureFromPatch(this, i);
  33826. }
  33827. }
  33828. // calculate bounds
  33829. updateBounds(this);
  33830. packData(this);
  33831. }
  33832. Mesh.prototype = {
  33833. getIR: function Mesh_getIR() {
  33834. return ['Mesh', this.shadingType, this.coords, this.colors, this.figures,
  33835. this.bounds, this.matrix, this.bbox, this.background];
  33836. }
  33837. };
  33838. return Mesh;
  33839. })();
  33840. Shadings.Dummy = (function DummyClosure() {
  33841. function Dummy() {
  33842. this.type = 'Pattern';
  33843. }
  33844. Dummy.prototype = {
  33845. getIR: function Dummy_getIR() {
  33846. return ['Dummy'];
  33847. }
  33848. };
  33849. return Dummy;
  33850. })();
  33851. function getTilingPatternIR(operatorList, dict, args) {
  33852. var matrix = dict.get('Matrix');
  33853. var bbox = dict.get('BBox');
  33854. var xstep = dict.get('XStep');
  33855. var ystep = dict.get('YStep');
  33856. var paintType = dict.get('PaintType');
  33857. var tilingType = dict.get('TilingType');
  33858. return [
  33859. 'TilingPattern', args, operatorList, matrix, bbox, xstep, ystep,
  33860. paintType, tilingType
  33861. ];
  33862. }
  33863. exports.Pattern = Pattern;
  33864. exports.getTilingPatternIR = getTilingPatternIR;
  33865. }));
  33866. (function (root, factory) {
  33867. {
  33868. factory((root.pdfjsCoreEvaluator = {}), root.pdfjsSharedUtil,
  33869. root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreParser,
  33870. root.pdfjsCoreImage, root.pdfjsCoreColorSpace, root.pdfjsCoreMurmurHash3,
  33871. root.pdfjsCoreFonts, root.pdfjsCoreFunction, root.pdfjsCorePattern,
  33872. root.pdfjsCoreCMap, root.pdfjsCoreMetrics, root.pdfjsCoreBidi);
  33873. }
  33874. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreParser,
  33875. coreImage, coreColorSpace, coreMurmurHash3, coreFonts,
  33876. coreFunction, corePattern, coreCMap, coreMetrics, coreBidi) {
  33877. var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
  33878. var IDENTITY_MATRIX = sharedUtil.IDENTITY_MATRIX;
  33879. var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  33880. var ImageKind = sharedUtil.ImageKind;
  33881. var OPS = sharedUtil.OPS;
  33882. var TextRenderingMode = sharedUtil.TextRenderingMode;
  33883. var Util = sharedUtil.Util;
  33884. var assert = sharedUtil.assert;
  33885. var createPromiseCapability = sharedUtil.createPromiseCapability;
  33886. var error = sharedUtil.error;
  33887. var info = sharedUtil.info;
  33888. var isArray = sharedUtil.isArray;
  33889. var isNum = sharedUtil.isNum;
  33890. var isString = sharedUtil.isString;
  33891. var warn = sharedUtil.warn;
  33892. var Dict = corePrimitives.Dict;
  33893. var Name = corePrimitives.Name;
  33894. var isCmd = corePrimitives.isCmd;
  33895. var isDict = corePrimitives.isDict;
  33896. var isName = corePrimitives.isName;
  33897. var isRef = corePrimitives.isRef;
  33898. var isStream = corePrimitives.isStream;
  33899. var DecodeStream = coreStream.DecodeStream;
  33900. var JpegStream = coreStream.JpegStream;
  33901. var Lexer = coreParser.Lexer;
  33902. var Parser = coreParser.Parser;
  33903. var isEOF = coreParser.isEOF;
  33904. var PDFImage = coreImage.PDFImage;
  33905. var ColorSpace = coreColorSpace.ColorSpace;
  33906. var MurmurHash3_64 = coreMurmurHash3.MurmurHash3_64;
  33907. var Encodings = coreFonts.Encodings;
  33908. var ErrorFont = coreFonts.ErrorFont;
  33909. var FontFlags = coreFonts.FontFlags;
  33910. var Font = coreFonts.Font;
  33911. var IdentityToUnicodeMap = coreFonts.IdentityToUnicodeMap;
  33912. var NormalizedUnicodes = coreFonts.NormalizedUnicodes;
  33913. var ToUnicodeMap = coreFonts.ToUnicodeMap;
  33914. var getFontType = coreFonts.getFontType;
  33915. var reverseIfRtl = coreFonts.reverseIfRtl;
  33916. var serifFonts = coreFonts.serifFonts;
  33917. var symbolsFonts = coreFonts.symbolsFonts;
  33918. var stdFontMap = coreFonts.stdFontMap;
  33919. var isPDFFunction = coreFunction.isPDFFunction;
  33920. var PDFFunction = coreFunction.PDFFunction;
  33921. var Pattern = corePattern.Pattern;
  33922. var getTilingPatternIR = corePattern.getTilingPatternIR;
  33923. var CMapFactory = coreCMap.CMapFactory;
  33924. var IdentityCMap = coreCMap.IdentityCMap;
  33925. var Metrics = coreMetrics.Metrics;
  33926. var bidi = coreBidi.bidi;
  33927. var PartialEvaluator = (function PartialEvaluatorClosure() {
  33928. function PartialEvaluator(pdfManager, xref, handler, pageIndex,
  33929. uniquePrefix, idCounters, fontCache) {
  33930. this.pdfManager = pdfManager;
  33931. this.xref = xref;
  33932. this.handler = handler;
  33933. this.pageIndex = pageIndex;
  33934. this.uniquePrefix = uniquePrefix;
  33935. this.idCounters = idCounters;
  33936. this.fontCache = fontCache;
  33937. }
  33938. // Trying to minimize Date.now() usage and check every 100 time
  33939. var TIME_SLOT_DURATION_MS = 20;
  33940. var CHECK_TIME_EVERY = 100;
  33941. function TimeSlotManager() {
  33942. this.reset();
  33943. }
  33944. TimeSlotManager.prototype = {
  33945. check: function TimeSlotManager_check() {
  33946. if (++this.checked < CHECK_TIME_EVERY) {
  33947. return false;
  33948. }
  33949. this.checked = 0;
  33950. return this.endTime <= Date.now();
  33951. },
  33952. reset: function TimeSlotManager_reset() {
  33953. this.endTime = Date.now() + TIME_SLOT_DURATION_MS;
  33954. this.checked = 0;
  33955. }
  33956. };
  33957. var deferred = Promise.resolve();
  33958. var TILING_PATTERN = 1, SHADING_PATTERN = 2;
  33959. PartialEvaluator.prototype = {
  33960. hasBlendModes: function PartialEvaluator_hasBlendModes(resources) {
  33961. if (!isDict(resources)) {
  33962. return false;
  33963. }
  33964. var processed = Object.create(null);
  33965. if (resources.objId) {
  33966. processed[resources.objId] = true;
  33967. }
  33968. var nodes = [resources];
  33969. while (nodes.length) {
  33970. var key;
  33971. var node = nodes.shift();
  33972. // First check the current resources for blend modes.
  33973. var graphicStates = node.get('ExtGState');
  33974. if (isDict(graphicStates)) {
  33975. graphicStates = graphicStates.getAll();
  33976. for (key in graphicStates) {
  33977. var graphicState = graphicStates[key];
  33978. var bm = graphicState['BM'];
  33979. if (isName(bm) && bm.name !== 'Normal') {
  33980. return true;
  33981. }
  33982. }
  33983. }
  33984. // Descend into the XObjects to look for more resources and blend modes.
  33985. var xObjects = node.get('XObject');
  33986. if (!isDict(xObjects)) {
  33987. continue;
  33988. }
  33989. xObjects = xObjects.getAll();
  33990. for (key in xObjects) {
  33991. var xObject = xObjects[key];
  33992. if (!isStream(xObject)) {
  33993. continue;
  33994. }
  33995. if (xObject.dict.objId) {
  33996. if (processed[xObject.dict.objId]) {
  33997. // stream has objId and is processed already
  33998. continue;
  33999. }
  34000. processed[xObject.dict.objId] = true;
  34001. }
  34002. var xResources = xObject.dict.get('Resources');
  34003. // Checking objId to detect an infinite loop.
  34004. if (isDict(xResources) &&
  34005. (!xResources.objId || !processed[xResources.objId])) {
  34006. nodes.push(xResources);
  34007. if (xResources.objId) {
  34008. processed[xResources.objId] = true;
  34009. }
  34010. }
  34011. }
  34012. }
  34013. return false;
  34014. },
  34015. buildFormXObject: function PartialEvaluator_buildFormXObject(resources,
  34016. xobj, smask,
  34017. operatorList,
  34018. task,
  34019. initialState) {
  34020. var matrix = xobj.dict.getArray('Matrix');
  34021. var bbox = xobj.dict.getArray('BBox');
  34022. var group = xobj.dict.get('Group');
  34023. if (group) {
  34024. var groupOptions = {
  34025. matrix: matrix,
  34026. bbox: bbox,
  34027. smask: smask,
  34028. isolated: false,
  34029. knockout: false
  34030. };
  34031. var groupSubtype = group.get('S');
  34032. var colorSpace;
  34033. if (isName(groupSubtype) && groupSubtype.name === 'Transparency') {
  34034. groupOptions.isolated = (group.get('I') || false);
  34035. groupOptions.knockout = (group.get('K') || false);
  34036. colorSpace = (group.has('CS') ?
  34037. ColorSpace.parse(group.get('CS'), this.xref, resources) : null);
  34038. }
  34039. if (smask && smask.backdrop) {
  34040. colorSpace = colorSpace || ColorSpace.singletons.rgb;
  34041. smask.backdrop = colorSpace.getRgb(smask.backdrop, 0);
  34042. }
  34043. operatorList.addOp(OPS.beginGroup, [groupOptions]);
  34044. }
  34045. operatorList.addOp(OPS.paintFormXObjectBegin, [matrix, bbox]);
  34046. return this.getOperatorList(xobj, task,
  34047. (xobj.dict.get('Resources') || resources), operatorList, initialState).
  34048. then(function () {
  34049. operatorList.addOp(OPS.paintFormXObjectEnd, []);
  34050. if (group) {
  34051. operatorList.addOp(OPS.endGroup, [groupOptions]);
  34052. }
  34053. });
  34054. },
  34055. buildPaintImageXObject:
  34056. function PartialEvaluator_buildPaintImageXObject(resources, image,
  34057. inline, operatorList,
  34058. cacheKey, imageCache) {
  34059. var self = this;
  34060. var dict = image.dict;
  34061. var w = dict.get('Width', 'W');
  34062. var h = dict.get('Height', 'H');
  34063. if (!(w && isNum(w)) || !(h && isNum(h))) {
  34064. warn('Image dimensions are missing, or not numbers.');
  34065. return;
  34066. }
  34067. if (PDFJS.maxImageSize !== -1 && w * h > PDFJS.maxImageSize) {
  34068. warn('Image exceeded maximum allowed size and was removed.');
  34069. return;
  34070. }
  34071. var imageMask = (dict.get('ImageMask', 'IM') || false);
  34072. var imgData, args;
  34073. if (imageMask) {
  34074. // This depends on a tmpCanvas being filled with the
  34075. // current fillStyle, such that processing the pixel
  34076. // data can't be done here. Instead of creating a
  34077. // complete PDFImage, only read the information needed
  34078. // for later.
  34079. var width = dict.get('Width', 'W');
  34080. var height = dict.get('Height', 'H');
  34081. var bitStrideLength = (width + 7) >> 3;
  34082. var imgArray = image.getBytes(bitStrideLength * height);
  34083. var decode = dict.get('Decode', 'D');
  34084. var inverseDecode = (!!decode && decode[0] > 0);
  34085. imgData = PDFImage.createMask(imgArray, width, height,
  34086. image instanceof DecodeStream,
  34087. inverseDecode);
  34088. imgData.cached = true;
  34089. args = [imgData];
  34090. operatorList.addOp(OPS.paintImageMaskXObject, args);
  34091. if (cacheKey) {
  34092. imageCache[cacheKey] = {
  34093. fn: OPS.paintImageMaskXObject,
  34094. args: args
  34095. };
  34096. }
  34097. return;
  34098. }
  34099. var softMask = (dict.get('SMask', 'SM') || false);
  34100. var mask = (dict.get('Mask') || false);
  34101. var SMALL_IMAGE_DIMENSIONS = 200;
  34102. // Inlining small images into the queue as RGB data
  34103. if (inline && !softMask && !mask && !(image instanceof JpegStream) &&
  34104. (w + h) < SMALL_IMAGE_DIMENSIONS) {
  34105. var imageObj = new PDFImage(this.xref, resources, image,
  34106. inline, null, null);
  34107. // We force the use of RGBA_32BPP images here, because we can't handle
  34108. // any other kind.
  34109. imgData = imageObj.createImageData(/* forceRGBA = */ true);
  34110. operatorList.addOp(OPS.paintInlineImageXObject, [imgData]);
  34111. return;
  34112. }
  34113. // If there is no imageMask, create the PDFImage and a lot
  34114. // of image processing can be done here.
  34115. var uniquePrefix = (this.uniquePrefix || '');
  34116. var objId = 'img_' + uniquePrefix + (++this.idCounters.obj);
  34117. operatorList.addDependency(objId);
  34118. args = [objId, w, h];
  34119. if (!softMask && !mask && image instanceof JpegStream &&
  34120. image.isNativelySupported(this.xref, resources)) {
  34121. // These JPEGs don't need any more processing so we can just send it.
  34122. operatorList.addOp(OPS.paintJpegXObject, args);
  34123. this.handler.send('obj',
  34124. [objId, this.pageIndex, 'JpegStream', image.getIR()]);
  34125. return;
  34126. }
  34127. PDFImage.buildImage(self.handler, self.xref, resources, image, inline).
  34128. then(function(imageObj) {
  34129. var imgData = imageObj.createImageData(/* forceRGBA = */ false);
  34130. self.handler.send('obj', [objId, self.pageIndex, 'Image', imgData],
  34131. [imgData.data.buffer]);
  34132. }).then(undefined, function (reason) {
  34133. warn('Unable to decode image: ' + reason);
  34134. self.handler.send('obj', [objId, self.pageIndex, 'Image', null]);
  34135. });
  34136. operatorList.addOp(OPS.paintImageXObject, args);
  34137. if (cacheKey) {
  34138. imageCache[cacheKey] = {
  34139. fn: OPS.paintImageXObject,
  34140. args: args
  34141. };
  34142. }
  34143. },
  34144. handleSMask: function PartialEvaluator_handleSmask(smask, resources,
  34145. operatorList, task,
  34146. stateManager) {
  34147. var smaskContent = smask.get('G');
  34148. var smaskOptions = {
  34149. subtype: smask.get('S').name,
  34150. backdrop: smask.get('BC')
  34151. };
  34152. // The SMask might have a alpha/luminosity value transfer function --
  34153. // we will build a map of integer values in range 0..255 to be fast.
  34154. var transferObj = smask.get('TR');
  34155. if (isPDFFunction(transferObj)) {
  34156. var transferFn = PDFFunction.parse(this.xref, transferObj);
  34157. var transferMap = new Uint8Array(256);
  34158. var tmp = new Float32Array(1);
  34159. for (var i = 0; i < 255; i++) {
  34160. tmp[0] = i / 255;
  34161. transferFn(tmp, 0, tmp, 0);
  34162. transferMap[i] = (tmp[0] * 255) | 0;
  34163. }
  34164. smaskOptions.transferMap = transferMap;
  34165. }
  34166. return this.buildFormXObject(resources, smaskContent, smaskOptions,
  34167. operatorList, task, stateManager.state.clone());
  34168. },
  34169. handleTilingType:
  34170. function PartialEvaluator_handleTilingType(fn, args, resources,
  34171. pattern, patternDict,
  34172. operatorList, task) {
  34173. // Create an IR of the pattern code.
  34174. var tilingOpList = new OperatorList();
  34175. // Merge the available resources, to prevent issues when the patternDict
  34176. // is missing some /Resources entries (fixes issue6541.pdf).
  34177. var resourcesArray = [patternDict.get('Resources'), resources];
  34178. var patternResources = Dict.merge(this.xref, resourcesArray);
  34179. return this.getOperatorList(pattern, task, patternResources,
  34180. tilingOpList).then(function () {
  34181. // Add the dependencies to the parent operator list so they are
  34182. // resolved before sub operator list is executed synchronously.
  34183. operatorList.addDependencies(tilingOpList.dependencies);
  34184. operatorList.addOp(fn, getTilingPatternIR({
  34185. fnArray: tilingOpList.fnArray,
  34186. argsArray: tilingOpList.argsArray
  34187. }, patternDict, args));
  34188. });
  34189. },
  34190. handleSetFont:
  34191. function PartialEvaluator_handleSetFont(resources, fontArgs, fontRef,
  34192. operatorList, task, state) {
  34193. // TODO(mack): Not needed?
  34194. var fontName;
  34195. if (fontArgs) {
  34196. fontArgs = fontArgs.slice();
  34197. fontName = fontArgs[0].name;
  34198. }
  34199. var self = this;
  34200. return this.loadFont(fontName, fontRef, this.xref, resources).then(
  34201. function (translated) {
  34202. if (!translated.font.isType3Font) {
  34203. return translated;
  34204. }
  34205. return translated.loadType3Data(self, resources, operatorList, task).
  34206. then(function () {
  34207. return translated;
  34208. }, function (reason) {
  34209. // Error in the font data -- sending unsupported feature notification.
  34210. self.handler.send('UnsupportedFeature',
  34211. {featureId: UNSUPPORTED_FEATURES.font});
  34212. return new TranslatedFont('g_font_error',
  34213. new ErrorFont('Type3 font load error: ' + reason), translated.font);
  34214. });
  34215. }).then(function (translated) {
  34216. state.font = translated.font;
  34217. translated.send(self.handler);
  34218. return translated.loadedName;
  34219. });
  34220. },
  34221. handleText: function PartialEvaluator_handleText(chars, state) {
  34222. var font = state.font;
  34223. var glyphs = font.charsToGlyphs(chars);
  34224. var isAddToPathSet = !!(state.textRenderingMode &
  34225. TextRenderingMode.ADD_TO_PATH_FLAG);
  34226. if (font.data && (isAddToPathSet || PDFJS.disableFontFace)) {
  34227. var buildPath = function (fontChar) {
  34228. if (!font.renderer.hasBuiltPath(fontChar)) {
  34229. var path = font.renderer.getPathJs(fontChar);
  34230. this.handler.send('commonobj', [
  34231. font.loadedName + '_path_' + fontChar,
  34232. 'FontPath',
  34233. path
  34234. ]);
  34235. }
  34236. }.bind(this);
  34237. for (var i = 0, ii = glyphs.length; i < ii; i++) {
  34238. var glyph = glyphs[i];
  34239. buildPath(glyph.fontChar);
  34240. // If the glyph has an accent we need to build a path for its
  34241. // fontChar too, otherwise CanvasGraphics_paintChar will fail.
  34242. var accent = glyph.accent;
  34243. if (accent && accent.fontChar) {
  34244. buildPath(accent.fontChar);
  34245. }
  34246. }
  34247. }
  34248. return glyphs;
  34249. },
  34250. setGState: function PartialEvaluator_setGState(resources, gState,
  34251. operatorList, task,
  34252. xref, stateManager) {
  34253. // This array holds the converted/processed state data.
  34254. var gStateObj = [];
  34255. var gStateMap = gState.map;
  34256. var self = this;
  34257. var promise = Promise.resolve();
  34258. for (var key in gStateMap) {
  34259. var value = gStateMap[key];
  34260. switch (key) {
  34261. case 'Type':
  34262. break;
  34263. case 'LW':
  34264. case 'LC':
  34265. case 'LJ':
  34266. case 'ML':
  34267. case 'D':
  34268. case 'RI':
  34269. case 'FL':
  34270. case 'CA':
  34271. case 'ca':
  34272. gStateObj.push([key, value]);
  34273. break;
  34274. case 'Font':
  34275. promise = promise.then(function () {
  34276. return self.handleSetFont(resources, null, value[0], operatorList,
  34277. task, stateManager.state).
  34278. then(function (loadedName) {
  34279. operatorList.addDependency(loadedName);
  34280. gStateObj.push([key, [loadedName, value[1]]]);
  34281. });
  34282. });
  34283. break;
  34284. case 'BM':
  34285. gStateObj.push([key, value]);
  34286. break;
  34287. case 'SMask':
  34288. if (isName(value) && value.name === 'None') {
  34289. gStateObj.push([key, false]);
  34290. break;
  34291. }
  34292. var dict = xref.fetchIfRef(value);
  34293. if (isDict(dict)) {
  34294. promise = promise.then(function () {
  34295. return self.handleSMask(dict, resources, operatorList,
  34296. task, stateManager);
  34297. });
  34298. gStateObj.push([key, true]);
  34299. } else {
  34300. warn('Unsupported SMask type');
  34301. }
  34302. break;
  34303. // Only generate info log messages for the following since
  34304. // they are unlikely to have a big impact on the rendering.
  34305. case 'OP':
  34306. case 'op':
  34307. case 'OPM':
  34308. case 'BG':
  34309. case 'BG2':
  34310. case 'UCR':
  34311. case 'UCR2':
  34312. case 'TR':
  34313. case 'TR2':
  34314. case 'HT':
  34315. case 'SM':
  34316. case 'SA':
  34317. case 'AIS':
  34318. case 'TK':
  34319. // TODO implement these operators.
  34320. info('graphic state operator ' + key);
  34321. break;
  34322. default:
  34323. info('Unknown graphic state operator ' + key);
  34324. break;
  34325. }
  34326. }
  34327. return promise.then(function () {
  34328. if (gStateObj.length >= 0) {
  34329. operatorList.addOp(OPS.setGState, [gStateObj]);
  34330. }
  34331. });
  34332. },
  34333. loadFont: function PartialEvaluator_loadFont(fontName, font, xref,
  34334. resources) {
  34335. function errorFont() {
  34336. return Promise.resolve(new TranslatedFont('g_font_error',
  34337. new ErrorFont('Font ' + fontName + ' is not available'), font));
  34338. }
  34339. var fontRef;
  34340. if (font) { // Loading by ref.
  34341. assert(isRef(font));
  34342. fontRef = font;
  34343. } else { // Loading by name.
  34344. var fontRes = resources.get('Font');
  34345. if (fontRes) {
  34346. fontRef = fontRes.getRaw(fontName);
  34347. } else {
  34348. warn('fontRes not available');
  34349. return errorFont();
  34350. }
  34351. }
  34352. if (!fontRef) {
  34353. warn('fontRef not available');
  34354. return errorFont();
  34355. }
  34356. if (this.fontCache.has(fontRef)) {
  34357. return this.fontCache.get(fontRef);
  34358. }
  34359. font = xref.fetchIfRef(fontRef);
  34360. if (!isDict(font)) {
  34361. return errorFont();
  34362. }
  34363. // We are holding font.translated references just for fontRef that are not
  34364. // dictionaries (Dict). See explanation below.
  34365. if (font.translated) {
  34366. return font.translated;
  34367. }
  34368. var fontCapability = createPromiseCapability();
  34369. var preEvaluatedFont = this.preEvaluateFont(font, xref);
  34370. var descriptor = preEvaluatedFont.descriptor;
  34371. var fontID = fontRef.num + '_' + fontRef.gen;
  34372. if (isDict(descriptor)) {
  34373. if (!descriptor.fontAliases) {
  34374. descriptor.fontAliases = Object.create(null);
  34375. }
  34376. var fontAliases = descriptor.fontAliases;
  34377. var hash = preEvaluatedFont.hash;
  34378. if (fontAliases[hash]) {
  34379. var aliasFontRef = fontAliases[hash].aliasRef;
  34380. if (aliasFontRef && this.fontCache.has(aliasFontRef)) {
  34381. this.fontCache.putAlias(fontRef, aliasFontRef);
  34382. return this.fontCache.get(fontRef);
  34383. }
  34384. }
  34385. if (!fontAliases[hash]) {
  34386. fontAliases[hash] = {
  34387. fontID: Font.getFontID()
  34388. };
  34389. }
  34390. fontAliases[hash].aliasRef = fontRef;
  34391. fontID = fontAliases[hash].fontID;
  34392. }
  34393. // Workaround for bad PDF generators that don't reference fonts
  34394. // properly, i.e. by not using an object identifier.
  34395. // Check if the fontRef is a Dict (as opposed to a standard object),
  34396. // in which case we don't cache the font and instead reference it by
  34397. // fontName in font.loadedName below.
  34398. var fontRefIsDict = isDict(fontRef);
  34399. if (!fontRefIsDict) {
  34400. this.fontCache.put(fontRef, fontCapability.promise);
  34401. }
  34402. // Keep track of each font we translated so the caller can
  34403. // load them asynchronously before calling display on a page.
  34404. font.loadedName = 'g_' + this.pdfManager.docId + '_f' + (fontRefIsDict ?
  34405. fontName.replace(/\W/g, '') : fontID);
  34406. font.translated = fontCapability.promise;
  34407. // TODO move promises into translate font
  34408. var translatedPromise;
  34409. try {
  34410. translatedPromise = Promise.resolve(
  34411. this.translateFont(preEvaluatedFont, xref));
  34412. } catch (e) {
  34413. translatedPromise = Promise.reject(e);
  34414. }
  34415. var self = this;
  34416. translatedPromise.then(function (translatedFont) {
  34417. if (translatedFont.fontType !== undefined) {
  34418. var xrefFontStats = xref.stats.fontTypes;
  34419. xrefFontStats[translatedFont.fontType] = true;
  34420. }
  34421. fontCapability.resolve(new TranslatedFont(font.loadedName,
  34422. translatedFont, font));
  34423. }, function (reason) {
  34424. // TODO fontCapability.reject?
  34425. // Error in the font data -- sending unsupported feature notification.
  34426. self.handler.send('UnsupportedFeature',
  34427. {featureId: UNSUPPORTED_FEATURES.font});
  34428. try {
  34429. // error, but it's still nice to have font type reported
  34430. var descriptor = preEvaluatedFont.descriptor;
  34431. var fontFile3 = descriptor && descriptor.get('FontFile3');
  34432. var subtype = fontFile3 && fontFile3.get('Subtype');
  34433. var fontType = getFontType(preEvaluatedFont.type,
  34434. subtype && subtype.name);
  34435. var xrefFontStats = xref.stats.fontTypes;
  34436. xrefFontStats[fontType] = true;
  34437. } catch (ex) { }
  34438. fontCapability.resolve(new TranslatedFont(font.loadedName,
  34439. new ErrorFont(reason instanceof Error ? reason.message : reason),
  34440. font));
  34441. });
  34442. return fontCapability.promise;
  34443. },
  34444. buildPath: function PartialEvaluator_buildPath(operatorList, fn, args) {
  34445. var lastIndex = operatorList.length - 1;
  34446. if (!args) {
  34447. args = [];
  34448. }
  34449. if (lastIndex < 0 ||
  34450. operatorList.fnArray[lastIndex] !== OPS.constructPath) {
  34451. operatorList.addOp(OPS.constructPath, [[fn], args]);
  34452. } else {
  34453. var opArgs = operatorList.argsArray[lastIndex];
  34454. opArgs[0].push(fn);
  34455. Array.prototype.push.apply(opArgs[1], args);
  34456. }
  34457. },
  34458. handleColorN: function PartialEvaluator_handleColorN(operatorList, fn, args,
  34459. cs, patterns, resources, task, xref) {
  34460. // compile tiling patterns
  34461. var patternName = args[args.length - 1];
  34462. // SCN/scn applies patterns along with normal colors
  34463. var pattern;
  34464. if (isName(patternName) &&
  34465. (pattern = patterns.get(patternName.name))) {
  34466. var dict = (isStream(pattern) ? pattern.dict : pattern);
  34467. var typeNum = dict.get('PatternType');
  34468. if (typeNum === TILING_PATTERN) {
  34469. var color = cs.base ? cs.base.getRgb(args, 0) : null;
  34470. return this.handleTilingType(fn, color, resources, pattern,
  34471. dict, operatorList, task);
  34472. } else if (typeNum === SHADING_PATTERN) {
  34473. var shading = dict.get('Shading');
  34474. var matrix = dict.get('Matrix');
  34475. pattern = Pattern.parseShading(shading, matrix, xref, resources,
  34476. this.handler);
  34477. operatorList.addOp(fn, pattern.getIR());
  34478. return Promise.resolve();
  34479. } else {
  34480. return Promise.reject('Unknown PatternType: ' + typeNum);
  34481. }
  34482. }
  34483. // TODO shall we fail here?
  34484. operatorList.addOp(fn, args);
  34485. return Promise.resolve();
  34486. },
  34487. getOperatorList: function PartialEvaluator_getOperatorList(stream,
  34488. task,
  34489. resources,
  34490. operatorList,
  34491. initialState) {
  34492. var self = this;
  34493. var xref = this.xref;
  34494. var imageCache = {};
  34495. assert(operatorList);
  34496. resources = (resources || Dict.empty);
  34497. var xobjs = (resources.get('XObject') || Dict.empty);
  34498. var patterns = (resources.get('Pattern') || Dict.empty);
  34499. var stateManager = new StateManager(initialState || new EvalState());
  34500. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  34501. var timeSlotManager = new TimeSlotManager();
  34502. return new Promise(function next(resolve, reject) {
  34503. task.ensureNotTerminated();
  34504. timeSlotManager.reset();
  34505. var stop, operation = {}, i, ii, cs;
  34506. while (!(stop = timeSlotManager.check())) {
  34507. // The arguments parsed by read() are used beyond this loop, so we
  34508. // cannot reuse the same array on each iteration. Therefore we pass
  34509. // in |null| as the initial value (see the comment on
  34510. // EvaluatorPreprocessor_read() for why).
  34511. operation.args = null;
  34512. if (!(preprocessor.read(operation))) {
  34513. break;
  34514. }
  34515. var args = operation.args;
  34516. var fn = operation.fn;
  34517. switch (fn | 0) {
  34518. case OPS.paintXObject:
  34519. if (args[0].code) {
  34520. break;
  34521. }
  34522. // eagerly compile XForm objects
  34523. var name = args[0].name;
  34524. if (!name) {
  34525. warn('XObject must be referred to by name.');
  34526. continue;
  34527. }
  34528. if (imageCache[name] !== undefined) {
  34529. operatorList.addOp(imageCache[name].fn, imageCache[name].args);
  34530. args = null;
  34531. continue;
  34532. }
  34533. var xobj = xobjs.get(name);
  34534. if (xobj) {
  34535. assert(isStream(xobj), 'XObject should be a stream');
  34536. var type = xobj.dict.get('Subtype');
  34537. assert(isName(type),
  34538. 'XObject should have a Name subtype');
  34539. if (type.name === 'Form') {
  34540. stateManager.save();
  34541. return self.buildFormXObject(resources, xobj, null,
  34542. operatorList, task,
  34543. stateManager.state.clone()).
  34544. then(function () {
  34545. stateManager.restore();
  34546. next(resolve, reject);
  34547. }, reject);
  34548. } else if (type.name === 'Image') {
  34549. self.buildPaintImageXObject(resources, xobj, false,
  34550. operatorList, name, imageCache);
  34551. args = null;
  34552. continue;
  34553. } else if (type.name === 'PS') {
  34554. // PostScript XObjects are unused when viewing documents.
  34555. // See section 4.7.1 of Adobe's PDF reference.
  34556. info('Ignored XObject subtype PS');
  34557. continue;
  34558. } else {
  34559. error('Unhandled XObject subtype ' + type.name);
  34560. }
  34561. }
  34562. break;
  34563. case OPS.setFont:
  34564. var fontSize = args[1];
  34565. // eagerly collect all fonts
  34566. return self.handleSetFont(resources, args, null, operatorList,
  34567. task, stateManager.state).
  34568. then(function (loadedName) {
  34569. operatorList.addDependency(loadedName);
  34570. operatorList.addOp(OPS.setFont, [loadedName, fontSize]);
  34571. next(resolve, reject);
  34572. }, reject);
  34573. case OPS.endInlineImage:
  34574. var cacheKey = args[0].cacheKey;
  34575. if (cacheKey) {
  34576. var cacheEntry = imageCache[cacheKey];
  34577. if (cacheEntry !== undefined) {
  34578. operatorList.addOp(cacheEntry.fn, cacheEntry.args);
  34579. args = null;
  34580. continue;
  34581. }
  34582. }
  34583. self.buildPaintImageXObject(resources, args[0], true,
  34584. operatorList, cacheKey, imageCache);
  34585. args = null;
  34586. continue;
  34587. case OPS.showText:
  34588. args[0] = self.handleText(args[0], stateManager.state);
  34589. break;
  34590. case OPS.showSpacedText:
  34591. var arr = args[0];
  34592. var combinedGlyphs = [];
  34593. var arrLength = arr.length;
  34594. var state = stateManager.state;
  34595. for (i = 0; i < arrLength; ++i) {
  34596. var arrItem = arr[i];
  34597. if (isString(arrItem)) {
  34598. Array.prototype.push.apply(combinedGlyphs,
  34599. self.handleText(arrItem, state));
  34600. } else if (isNum(arrItem)) {
  34601. combinedGlyphs.push(arrItem);
  34602. }
  34603. }
  34604. args[0] = combinedGlyphs;
  34605. fn = OPS.showText;
  34606. break;
  34607. case OPS.nextLineShowText:
  34608. operatorList.addOp(OPS.nextLine);
  34609. args[0] = self.handleText(args[0], stateManager.state);
  34610. fn = OPS.showText;
  34611. break;
  34612. case OPS.nextLineSetSpacingShowText:
  34613. operatorList.addOp(OPS.nextLine);
  34614. operatorList.addOp(OPS.setWordSpacing, [args.shift()]);
  34615. operatorList.addOp(OPS.setCharSpacing, [args.shift()]);
  34616. args[0] = self.handleText(args[0], stateManager.state);
  34617. fn = OPS.showText;
  34618. break;
  34619. case OPS.setTextRenderingMode:
  34620. stateManager.state.textRenderingMode = args[0];
  34621. break;
  34622. case OPS.setFillColorSpace:
  34623. stateManager.state.fillColorSpace =
  34624. ColorSpace.parse(args[0], xref, resources);
  34625. continue;
  34626. case OPS.setStrokeColorSpace:
  34627. stateManager.state.strokeColorSpace =
  34628. ColorSpace.parse(args[0], xref, resources);
  34629. continue;
  34630. case OPS.setFillColor:
  34631. cs = stateManager.state.fillColorSpace;
  34632. args = cs.getRgb(args, 0);
  34633. fn = OPS.setFillRGBColor;
  34634. break;
  34635. case OPS.setStrokeColor:
  34636. cs = stateManager.state.strokeColorSpace;
  34637. args = cs.getRgb(args, 0);
  34638. fn = OPS.setStrokeRGBColor;
  34639. break;
  34640. case OPS.setFillGray:
  34641. stateManager.state.fillColorSpace = ColorSpace.singletons.gray;
  34642. args = ColorSpace.singletons.gray.getRgb(args, 0);
  34643. fn = OPS.setFillRGBColor;
  34644. break;
  34645. case OPS.setStrokeGray:
  34646. stateManager.state.strokeColorSpace = ColorSpace.singletons.gray;
  34647. args = ColorSpace.singletons.gray.getRgb(args, 0);
  34648. fn = OPS.setStrokeRGBColor;
  34649. break;
  34650. case OPS.setFillCMYKColor:
  34651. stateManager.state.fillColorSpace = ColorSpace.singletons.cmyk;
  34652. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  34653. fn = OPS.setFillRGBColor;
  34654. break;
  34655. case OPS.setStrokeCMYKColor:
  34656. stateManager.state.strokeColorSpace = ColorSpace.singletons.cmyk;
  34657. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  34658. fn = OPS.setStrokeRGBColor;
  34659. break;
  34660. case OPS.setFillRGBColor:
  34661. stateManager.state.fillColorSpace = ColorSpace.singletons.rgb;
  34662. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  34663. break;
  34664. case OPS.setStrokeRGBColor:
  34665. stateManager.state.strokeColorSpace = ColorSpace.singletons.rgb;
  34666. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  34667. break;
  34668. case OPS.setFillColorN:
  34669. cs = stateManager.state.fillColorSpace;
  34670. if (cs.name === 'Pattern') {
  34671. return self.handleColorN(operatorList, OPS.setFillColorN,
  34672. args, cs, patterns, resources, task, xref).then(function() {
  34673. next(resolve, reject);
  34674. }, reject);
  34675. }
  34676. args = cs.getRgb(args, 0);
  34677. fn = OPS.setFillRGBColor;
  34678. break;
  34679. case OPS.setStrokeColorN:
  34680. cs = stateManager.state.strokeColorSpace;
  34681. if (cs.name === 'Pattern') {
  34682. return self.handleColorN(operatorList, OPS.setStrokeColorN,
  34683. args, cs, patterns, resources, task, xref).then(function() {
  34684. next(resolve, reject);
  34685. }, reject);
  34686. }
  34687. args = cs.getRgb(args, 0);
  34688. fn = OPS.setStrokeRGBColor;
  34689. break;
  34690. case OPS.shadingFill:
  34691. var shadingRes = resources.get('Shading');
  34692. if (!shadingRes) {
  34693. error('No shading resource found');
  34694. }
  34695. var shading = shadingRes.get(args[0].name);
  34696. if (!shading) {
  34697. error('No shading object found');
  34698. }
  34699. var shadingFill = Pattern.parseShading(shading, null, xref,
  34700. resources, self.handler);
  34701. var patternIR = shadingFill.getIR();
  34702. args = [patternIR];
  34703. fn = OPS.shadingFill;
  34704. break;
  34705. case OPS.setGState:
  34706. var dictName = args[0];
  34707. var extGState = resources.get('ExtGState');
  34708. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  34709. break;
  34710. }
  34711. var gState = extGState.get(dictName.name);
  34712. return self.setGState(resources, gState, operatorList, task,
  34713. xref, stateManager).then(function() {
  34714. next(resolve, reject);
  34715. }, reject);
  34716. case OPS.moveTo:
  34717. case OPS.lineTo:
  34718. case OPS.curveTo:
  34719. case OPS.curveTo2:
  34720. case OPS.curveTo3:
  34721. case OPS.closePath:
  34722. self.buildPath(operatorList, fn, args);
  34723. continue;
  34724. case OPS.rectangle:
  34725. self.buildPath(operatorList, fn, args);
  34726. continue;
  34727. case OPS.markPoint:
  34728. case OPS.markPointProps:
  34729. case OPS.beginMarkedContent:
  34730. case OPS.beginMarkedContentProps:
  34731. case OPS.endMarkedContent:
  34732. case OPS.beginCompat:
  34733. case OPS.endCompat:
  34734. // Ignore operators where the corresponding handlers are known to
  34735. // be no-op in CanvasGraphics (display/canvas.js). This prevents
  34736. // serialization errors and is also a bit more efficient.
  34737. // We could also try to serialize all objects in a general way,
  34738. // e.g. as done in https://github.com/mozilla/pdf.js/pull/6266,
  34739. // but doing so is meaningless without knowing the semantics.
  34740. continue;
  34741. default:
  34742. // Note: Let's hope that the ignored operator does not have any
  34743. // non-serializable arguments, otherwise postMessage will throw
  34744. // "An object could not be cloned.".
  34745. }
  34746. operatorList.addOp(fn, args);
  34747. }
  34748. if (stop) {
  34749. deferred.then(function () {
  34750. next(resolve, reject);
  34751. }, reject);
  34752. return;
  34753. }
  34754. // Some PDFs don't close all restores inside object/form.
  34755. // Closing those for them.
  34756. for (i = 0, ii = preprocessor.savedStatesDepth; i < ii; i++) {
  34757. operatorList.addOp(OPS.restore, []);
  34758. }
  34759. resolve();
  34760. });
  34761. },
  34762. getTextContent:
  34763. function PartialEvaluator_getTextContent(stream, task, resources,
  34764. stateManager,
  34765. normalizeWhitespace) {
  34766. stateManager = (stateManager || new StateManager(new TextState()));
  34767. var WhitespaceRegexp = /\s/g;
  34768. var textContent = {
  34769. items: [],
  34770. styles: Object.create(null)
  34771. };
  34772. var textContentItem = {
  34773. initialized: false,
  34774. str: [],
  34775. width: 0,
  34776. height: 0,
  34777. vertical: false,
  34778. lastAdvanceWidth: 0,
  34779. lastAdvanceHeight: 0,
  34780. textAdvanceScale: 0,
  34781. spaceWidth: 0,
  34782. fakeSpaceMin: Infinity,
  34783. fakeMultiSpaceMin: Infinity,
  34784. fakeMultiSpaceMax: -0,
  34785. textRunBreakAllowed: false,
  34786. transform: null,
  34787. fontName: null
  34788. };
  34789. var SPACE_FACTOR = 0.3;
  34790. var MULTI_SPACE_FACTOR = 1.5;
  34791. var MULTI_SPACE_FACTOR_MAX = 4;
  34792. var self = this;
  34793. var xref = this.xref;
  34794. resources = (xref.fetchIfRef(resources) || Dict.empty);
  34795. // The xobj is parsed iff it's needed, e.g. if there is a `DO` cmd.
  34796. var xobjs = null;
  34797. var xobjsCache = {};
  34798. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  34799. var textState;
  34800. function ensureTextContentItem() {
  34801. if (textContentItem.initialized) {
  34802. return textContentItem;
  34803. }
  34804. var font = textState.font;
  34805. if (!(font.loadedName in textContent.styles)) {
  34806. textContent.styles[font.loadedName] = {
  34807. fontFamily: font.fallbackName,
  34808. ascent: font.ascent,
  34809. descent: font.descent,
  34810. vertical: font.vertical
  34811. };
  34812. }
  34813. textContentItem.fontName = font.loadedName;
  34814. // 9.4.4 Text Space Details
  34815. var tsm = [textState.fontSize * textState.textHScale, 0,
  34816. 0, textState.fontSize,
  34817. 0, textState.textRise];
  34818. if (font.isType3Font &&
  34819. textState.fontMatrix !== FONT_IDENTITY_MATRIX &&
  34820. textState.fontSize === 1) {
  34821. var glyphHeight = font.bbox[3] - font.bbox[1];
  34822. if (glyphHeight > 0) {
  34823. glyphHeight = glyphHeight * textState.fontMatrix[3];
  34824. tsm[3] *= glyphHeight;
  34825. }
  34826. }
  34827. var trm = Util.transform(textState.ctm,
  34828. Util.transform(textState.textMatrix, tsm));
  34829. textContentItem.transform = trm;
  34830. if (!font.vertical) {
  34831. textContentItem.width = 0;
  34832. textContentItem.height = Math.sqrt(trm[2] * trm[2] + trm[3] * trm[3]);
  34833. textContentItem.vertical = false;
  34834. } else {
  34835. textContentItem.width = Math.sqrt(trm[0] * trm[0] + trm[1] * trm[1]);
  34836. textContentItem.height = 0;
  34837. textContentItem.vertical = true;
  34838. }
  34839. var a = textState.textLineMatrix[0];
  34840. var b = textState.textLineMatrix[1];
  34841. var scaleLineX = Math.sqrt(a * a + b * b);
  34842. a = textState.ctm[0];
  34843. b = textState.ctm[1];
  34844. var scaleCtmX = Math.sqrt(a * a + b * b);
  34845. textContentItem.textAdvanceScale = scaleCtmX * scaleLineX;
  34846. textContentItem.lastAdvanceWidth = 0;
  34847. textContentItem.lastAdvanceHeight = 0;
  34848. var spaceWidth = font.spaceWidth / 1000 * textState.fontSize;
  34849. if (spaceWidth) {
  34850. textContentItem.spaceWidth = spaceWidth;
  34851. textContentItem.fakeSpaceMin = spaceWidth * SPACE_FACTOR;
  34852. textContentItem.fakeMultiSpaceMin = spaceWidth * MULTI_SPACE_FACTOR;
  34853. textContentItem.fakeMultiSpaceMax =
  34854. spaceWidth * MULTI_SPACE_FACTOR_MAX;
  34855. // It's okay for monospace fonts to fake as much space as needed.
  34856. textContentItem.textRunBreakAllowed = !font.isMonospace;
  34857. } else {
  34858. textContentItem.spaceWidth = 0;
  34859. textContentItem.fakeSpaceMin = Infinity;
  34860. textContentItem.fakeMultiSpaceMin = Infinity;
  34861. textContentItem.fakeMultiSpaceMax = 0;
  34862. textContentItem.textRunBreakAllowed = false;
  34863. }
  34864. textContentItem.initialized = true;
  34865. return textContentItem;
  34866. }
  34867. function replaceWhitespace(str) {
  34868. // Replaces all whitespaces with standard spaces (0x20), to avoid
  34869. // alignment issues between the textLayer and the canvas if the text
  34870. // contains e.g. tabs (fixes issue6612.pdf).
  34871. var i = 0, ii = str.length, code;
  34872. while (i < ii && (code = str.charCodeAt(i)) >= 0x20 && code <= 0x7F) {
  34873. i++;
  34874. }
  34875. return (i < ii ? str.replace(WhitespaceRegexp, ' ') : str);
  34876. }
  34877. function runBidiTransform(textChunk) {
  34878. var str = textChunk.str.join('');
  34879. var bidiResult = PDFJS.bidi(str, -1, textChunk.vertical);
  34880. return {
  34881. str: (normalizeWhitespace ? replaceWhitespace(bidiResult.str) :
  34882. bidiResult.str),
  34883. dir: bidiResult.dir,
  34884. width: textChunk.width,
  34885. height: textChunk.height,
  34886. transform: textChunk.transform,
  34887. fontName: textChunk.fontName
  34888. };
  34889. }
  34890. function handleSetFont(fontName, fontRef) {
  34891. return self.loadFont(fontName, fontRef, xref, resources).
  34892. then(function (translated) {
  34893. textState.font = translated.font;
  34894. textState.fontMatrix = translated.font.fontMatrix ||
  34895. FONT_IDENTITY_MATRIX;
  34896. });
  34897. }
  34898. function buildTextContentItem(chars) {
  34899. var font = textState.font;
  34900. var textChunk = ensureTextContentItem();
  34901. var width = 0;
  34902. var height = 0;
  34903. var glyphs = font.charsToGlyphs(chars);
  34904. var defaultVMetrics = font.defaultVMetrics;
  34905. for (var i = 0; i < glyphs.length; i++) {
  34906. var glyph = glyphs[i];
  34907. var vMetricX = null;
  34908. var vMetricY = null;
  34909. var glyphWidth = null;
  34910. if (font.vertical) {
  34911. if (glyph.vmetric) {
  34912. glyphWidth = glyph.vmetric[0];
  34913. vMetricX = glyph.vmetric[1];
  34914. vMetricY = glyph.vmetric[2];
  34915. } else {
  34916. glyphWidth = glyph.width;
  34917. vMetricX = glyph.width * 0.5;
  34918. vMetricY = defaultVMetrics[2];
  34919. }
  34920. } else {
  34921. glyphWidth = glyph.width;
  34922. }
  34923. var glyphUnicode = glyph.unicode;
  34924. if (NormalizedUnicodes[glyphUnicode] !== undefined) {
  34925. glyphUnicode = NormalizedUnicodes[glyphUnicode];
  34926. }
  34927. glyphUnicode = reverseIfRtl(glyphUnicode);
  34928. // The following will calculate the x and y of the individual glyphs.
  34929. // if (font.vertical) {
  34930. // tsm[4] -= vMetricX * Math.abs(textState.fontSize) *
  34931. // textState.fontMatrix[0];
  34932. // tsm[5] -= vMetricY * textState.fontSize *
  34933. // textState.fontMatrix[0];
  34934. // }
  34935. // var trm = Util.transform(textState.textMatrix, tsm);
  34936. // var pt = Util.applyTransform([trm[4], trm[5]], textState.ctm);
  34937. // var x = pt[0];
  34938. // var y = pt[1];
  34939. var charSpacing = textState.charSpacing;
  34940. if (glyph.isSpace) {
  34941. var wordSpacing = textState.wordSpacing;
  34942. charSpacing += wordSpacing;
  34943. if (wordSpacing > 0) {
  34944. addFakeSpaces(wordSpacing, textChunk.str);
  34945. }
  34946. }
  34947. var tx = 0;
  34948. var ty = 0;
  34949. if (!font.vertical) {
  34950. var w0 = glyphWidth * textState.fontMatrix[0];
  34951. tx = (w0 * textState.fontSize + charSpacing) *
  34952. textState.textHScale;
  34953. width += tx;
  34954. } else {
  34955. var w1 = glyphWidth * textState.fontMatrix[0];
  34956. ty = w1 * textState.fontSize + charSpacing;
  34957. height += ty;
  34958. }
  34959. textState.translateTextMatrix(tx, ty);
  34960. textChunk.str.push(glyphUnicode);
  34961. }
  34962. if (!font.vertical) {
  34963. textChunk.lastAdvanceWidth = width;
  34964. textChunk.width += width * textChunk.textAdvanceScale;
  34965. } else {
  34966. textChunk.lastAdvanceHeight = height;
  34967. textChunk.height += Math.abs(height * textChunk.textAdvanceScale);
  34968. }
  34969. return textChunk;
  34970. }
  34971. function addFakeSpaces(width, strBuf) {
  34972. if (width < textContentItem.fakeSpaceMin) {
  34973. return;
  34974. }
  34975. if (width < textContentItem.fakeMultiSpaceMin) {
  34976. strBuf.push(' ');
  34977. return;
  34978. }
  34979. var fakeSpaces = Math.round(width / textContentItem.spaceWidth);
  34980. while (fakeSpaces-- > 0) {
  34981. strBuf.push(' ');
  34982. }
  34983. }
  34984. function flushTextContentItem() {
  34985. if (!textContentItem.initialized) {
  34986. return;
  34987. }
  34988. textContent.items.push(runBidiTransform(textContentItem));
  34989. textContentItem.initialized = false;
  34990. textContentItem.str.length = 0;
  34991. }
  34992. var timeSlotManager = new TimeSlotManager();
  34993. return new Promise(function next(resolve, reject) {
  34994. task.ensureNotTerminated();
  34995. timeSlotManager.reset();
  34996. var stop, operation = {}, args = [];
  34997. while (!(stop = timeSlotManager.check())) {
  34998. // The arguments parsed by read() are not used beyond this loop, so
  34999. // we can reuse the same array on every iteration, thus avoiding
  35000. // unnecessary allocations.
  35001. args.length = 0;
  35002. operation.args = args;
  35003. if (!(preprocessor.read(operation))) {
  35004. break;
  35005. }
  35006. textState = stateManager.state;
  35007. var fn = operation.fn;
  35008. args = operation.args;
  35009. var advance;
  35010. switch (fn | 0) {
  35011. case OPS.setFont:
  35012. flushTextContentItem();
  35013. textState.fontSize = args[1];
  35014. return handleSetFont(args[0].name).then(function() {
  35015. next(resolve, reject);
  35016. }, reject);
  35017. case OPS.setTextRise:
  35018. flushTextContentItem();
  35019. textState.textRise = args[0];
  35020. break;
  35021. case OPS.setHScale:
  35022. flushTextContentItem();
  35023. textState.textHScale = args[0] / 100;
  35024. break;
  35025. case OPS.setLeading:
  35026. flushTextContentItem();
  35027. textState.leading = args[0];
  35028. break;
  35029. case OPS.moveText:
  35030. // Optimization to treat same line movement as advance
  35031. var isSameTextLine = !textState.font ? false :
  35032. ((textState.font.vertical ? args[0] : args[1]) === 0);
  35033. advance = args[0] - args[1];
  35034. if (isSameTextLine && textContentItem.initialized &&
  35035. advance > 0 &&
  35036. advance <= textContentItem.fakeMultiSpaceMax) {
  35037. textState.translateTextLineMatrix(args[0], args[1]);
  35038. textContentItem.width +=
  35039. (args[0] - textContentItem.lastAdvanceWidth);
  35040. textContentItem.height +=
  35041. (args[1] - textContentItem.lastAdvanceHeight);
  35042. var diff = (args[0] - textContentItem.lastAdvanceWidth) -
  35043. (args[1] - textContentItem.lastAdvanceHeight);
  35044. addFakeSpaces(diff, textContentItem.str);
  35045. break;
  35046. }
  35047. flushTextContentItem();
  35048. textState.translateTextLineMatrix(args[0], args[1]);
  35049. textState.textMatrix = textState.textLineMatrix.slice();
  35050. break;
  35051. case OPS.setLeadingMoveText:
  35052. flushTextContentItem();
  35053. textState.leading = -args[1];
  35054. textState.translateTextLineMatrix(args[0], args[1]);
  35055. textState.textMatrix = textState.textLineMatrix.slice();
  35056. break;
  35057. case OPS.nextLine:
  35058. flushTextContentItem();
  35059. textState.carriageReturn();
  35060. break;
  35061. case OPS.setTextMatrix:
  35062. flushTextContentItem();
  35063. textState.setTextMatrix(args[0], args[1], args[2], args[3],
  35064. args[4], args[5]);
  35065. textState.setTextLineMatrix(args[0], args[1], args[2], args[3],
  35066. args[4], args[5]);
  35067. break;
  35068. case OPS.setCharSpacing:
  35069. textState.charSpacing = args[0];
  35070. break;
  35071. case OPS.setWordSpacing:
  35072. textState.wordSpacing = args[0];
  35073. break;
  35074. case OPS.beginText:
  35075. flushTextContentItem();
  35076. textState.textMatrix = IDENTITY_MATRIX.slice();
  35077. textState.textLineMatrix = IDENTITY_MATRIX.slice();
  35078. break;
  35079. case OPS.showSpacedText:
  35080. var items = args[0];
  35081. var offset;
  35082. for (var j = 0, jj = items.length; j < jj; j++) {
  35083. if (typeof items[j] === 'string') {
  35084. buildTextContentItem(items[j]);
  35085. } else {
  35086. ensureTextContentItem();
  35087. // PDF Specification 5.3.2 states:
  35088. // The number is expressed in thousandths of a unit of text
  35089. // space.
  35090. // This amount is subtracted from the current horizontal or
  35091. // vertical coordinate, depending on the writing mode.
  35092. // In the default coordinate system, a positive adjustment
  35093. // has the effect of moving the next glyph painted either to
  35094. // the left or down by the given amount.
  35095. advance = items[j] * textState.fontSize / 1000;
  35096. var breakTextRun = false;
  35097. if (textState.font.vertical) {
  35098. offset = advance *
  35099. (textState.textHScale * textState.textMatrix[2] +
  35100. textState.textMatrix[3]);
  35101. textState.translateTextMatrix(0, advance);
  35102. breakTextRun = textContentItem.textRunBreakAllowed &&
  35103. advance > textContentItem.fakeMultiSpaceMax;
  35104. if (!breakTextRun) {
  35105. // Value needs to be added to height to paint down.
  35106. textContentItem.height += offset;
  35107. }
  35108. } else {
  35109. advance = -advance;
  35110. offset = advance * (
  35111. textState.textHScale * textState.textMatrix[0] +
  35112. textState.textMatrix[1]);
  35113. textState.translateTextMatrix(advance, 0);
  35114. breakTextRun = textContentItem.textRunBreakAllowed &&
  35115. advance > textContentItem.fakeMultiSpaceMax;
  35116. if (!breakTextRun) {
  35117. // Value needs to be subtracted from width to paint left.
  35118. textContentItem.width += offset;
  35119. }
  35120. }
  35121. if (breakTextRun) {
  35122. flushTextContentItem();
  35123. } else if (advance > 0) {
  35124. addFakeSpaces(advance, textContentItem.str);
  35125. }
  35126. }
  35127. }
  35128. break;
  35129. case OPS.showText:
  35130. buildTextContentItem(args[0]);
  35131. break;
  35132. case OPS.nextLineShowText:
  35133. flushTextContentItem();
  35134. textState.carriageReturn();
  35135. buildTextContentItem(args[0]);
  35136. break;
  35137. case OPS.nextLineSetSpacingShowText:
  35138. flushTextContentItem();
  35139. textState.wordSpacing = args[0];
  35140. textState.charSpacing = args[1];
  35141. textState.carriageReturn();
  35142. buildTextContentItem(args[2]);
  35143. break;
  35144. case OPS.paintXObject:
  35145. flushTextContentItem();
  35146. if (args[0].code) {
  35147. break;
  35148. }
  35149. if (!xobjs) {
  35150. xobjs = (resources.get('XObject') || Dict.empty);
  35151. }
  35152. var name = args[0].name;
  35153. if (xobjsCache.key === name) {
  35154. if (xobjsCache.texts) {
  35155. Util.appendToArray(textContent.items, xobjsCache.texts.items);
  35156. Util.extendObj(textContent.styles, xobjsCache.texts.styles);
  35157. }
  35158. break;
  35159. }
  35160. var xobj = xobjs.get(name);
  35161. if (!xobj) {
  35162. break;
  35163. }
  35164. assert(isStream(xobj), 'XObject should be a stream');
  35165. var type = xobj.dict.get('Subtype');
  35166. assert(isName(type),
  35167. 'XObject should have a Name subtype');
  35168. if ('Form' !== type.name) {
  35169. xobjsCache.key = name;
  35170. xobjsCache.texts = null;
  35171. break;
  35172. }
  35173. stateManager.save();
  35174. var matrix = xobj.dict.get('Matrix');
  35175. if (isArray(matrix) && matrix.length === 6) {
  35176. stateManager.transform(matrix);
  35177. }
  35178. return self.getTextContent(xobj, task,
  35179. xobj.dict.get('Resources') || resources, stateManager,
  35180. normalizeWhitespace).then(function (formTextContent) {
  35181. Util.appendToArray(textContent.items, formTextContent.items);
  35182. Util.extendObj(textContent.styles, formTextContent.styles);
  35183. stateManager.restore();
  35184. xobjsCache.key = name;
  35185. xobjsCache.texts = formTextContent;
  35186. next(resolve, reject);
  35187. }, reject);
  35188. case OPS.setGState:
  35189. flushTextContentItem();
  35190. var dictName = args[0];
  35191. var extGState = resources.get('ExtGState');
  35192. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  35193. break;
  35194. }
  35195. var gsStateMap = extGState.get(dictName.name);
  35196. var gsStateFont = null;
  35197. for (var key in gsStateMap) {
  35198. if (key === 'Font') {
  35199. assert(!gsStateFont);
  35200. gsStateFont = gsStateMap[key];
  35201. }
  35202. }
  35203. if (gsStateFont) {
  35204. textState.fontSize = gsStateFont[1];
  35205. return handleSetFont(gsStateFont[0]).then(function() {
  35206. next(resolve, reject);
  35207. }, reject);
  35208. }
  35209. break;
  35210. } // switch
  35211. } // while
  35212. if (stop) {
  35213. deferred.then(function () {
  35214. next(resolve, reject);
  35215. }, reject);
  35216. return;
  35217. }
  35218. flushTextContentItem();
  35219. resolve(textContent);
  35220. });
  35221. },
  35222. extractDataStructures: function
  35223. partialEvaluatorExtractDataStructures(dict, baseDict,
  35224. xref, properties) {
  35225. // 9.10.2
  35226. var toUnicode = (dict.get('ToUnicode') || baseDict.get('ToUnicode'));
  35227. if (toUnicode) {
  35228. properties.toUnicode = this.readToUnicode(toUnicode);
  35229. }
  35230. if (properties.composite) {
  35231. // CIDSystemInfo helps to match CID to glyphs
  35232. var cidSystemInfo = dict.get('CIDSystemInfo');
  35233. if (isDict(cidSystemInfo)) {
  35234. properties.cidSystemInfo = {
  35235. registry: cidSystemInfo.get('Registry'),
  35236. ordering: cidSystemInfo.get('Ordering'),
  35237. supplement: cidSystemInfo.get('Supplement')
  35238. };
  35239. }
  35240. var cidToGidMap = dict.get('CIDToGIDMap');
  35241. if (isStream(cidToGidMap)) {
  35242. properties.cidToGidMap = this.readCidToGidMap(cidToGidMap);
  35243. }
  35244. }
  35245. // Based on 9.6.6 of the spec the encoding can come from multiple places
  35246. // and depends on the font type. The base encoding and differences are
  35247. // read here, but the encoding that is actually used is chosen during
  35248. // glyph mapping in the font.
  35249. // TODO: Loading the built in encoding in the font would allow the
  35250. // differences to be merged in here not require us to hold on to it.
  35251. var differences = [];
  35252. var baseEncodingName = null;
  35253. var encoding;
  35254. if (dict.has('Encoding')) {
  35255. encoding = dict.get('Encoding');
  35256. if (isDict(encoding)) {
  35257. baseEncodingName = encoding.get('BaseEncoding');
  35258. baseEncodingName = (isName(baseEncodingName) ?
  35259. baseEncodingName.name : null);
  35260. // Load the differences between the base and original
  35261. if (encoding.has('Differences')) {
  35262. var diffEncoding = encoding.get('Differences');
  35263. var index = 0;
  35264. for (var j = 0, jj = diffEncoding.length; j < jj; j++) {
  35265. var data = diffEncoding[j];
  35266. if (isNum(data)) {
  35267. index = data;
  35268. } else if (isName(data)) {
  35269. differences[index++] = data.name;
  35270. } else if (isRef(data)) {
  35271. diffEncoding[j--] = xref.fetch(data);
  35272. continue;
  35273. } else {
  35274. error('Invalid entry in \'Differences\' array: ' + data);
  35275. }
  35276. }
  35277. }
  35278. } else if (isName(encoding)) {
  35279. baseEncodingName = encoding.name;
  35280. } else {
  35281. error('Encoding is not a Name nor a Dict');
  35282. }
  35283. // According to table 114 if the encoding is a named encoding it must be
  35284. // one of these predefined encodings.
  35285. if ((baseEncodingName !== 'MacRomanEncoding' &&
  35286. baseEncodingName !== 'MacExpertEncoding' &&
  35287. baseEncodingName !== 'WinAnsiEncoding')) {
  35288. baseEncodingName = null;
  35289. }
  35290. }
  35291. if (baseEncodingName) {
  35292. properties.defaultEncoding = Encodings[baseEncodingName].slice();
  35293. } else {
  35294. encoding = (properties.type === 'TrueType' ?
  35295. Encodings.WinAnsiEncoding : Encodings.StandardEncoding);
  35296. // The Symbolic attribute can be misused for regular fonts
  35297. // Heuristic: we have to check if the font is a standard one also
  35298. if (!!(properties.flags & FontFlags.Symbolic)) {
  35299. encoding = Encodings.MacRomanEncoding;
  35300. if (!properties.file) {
  35301. if (/Symbol/i.test(properties.name)) {
  35302. encoding = Encodings.SymbolSetEncoding;
  35303. } else if (/Dingbats/i.test(properties.name)) {
  35304. encoding = Encodings.ZapfDingbatsEncoding;
  35305. }
  35306. }
  35307. }
  35308. properties.defaultEncoding = encoding;
  35309. }
  35310. properties.differences = differences;
  35311. properties.baseEncodingName = baseEncodingName;
  35312. properties.dict = dict;
  35313. },
  35314. readToUnicode: function PartialEvaluator_readToUnicode(toUnicode) {
  35315. var cmap, cmapObj = toUnicode;
  35316. if (isName(cmapObj)) {
  35317. cmap = CMapFactory.create(cmapObj,
  35318. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  35319. if (cmap instanceof IdentityCMap) {
  35320. return new IdentityToUnicodeMap(0, 0xFFFF);
  35321. }
  35322. return new ToUnicodeMap(cmap.getMap());
  35323. } else if (isStream(cmapObj)) {
  35324. cmap = CMapFactory.create(cmapObj,
  35325. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  35326. if (cmap instanceof IdentityCMap) {
  35327. return new IdentityToUnicodeMap(0, 0xFFFF);
  35328. }
  35329. var map = new Array(cmap.length);
  35330. // Convert UTF-16BE
  35331. // NOTE: cmap can be a sparse array, so use forEach instead of for(;;)
  35332. // to iterate over all keys.
  35333. cmap.forEach(function(charCode, token) {
  35334. var str = [];
  35335. for (var k = 0; k < token.length; k += 2) {
  35336. var w1 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  35337. if ((w1 & 0xF800) !== 0xD800) { // w1 < 0xD800 || w1 > 0xDFFF
  35338. str.push(w1);
  35339. continue;
  35340. }
  35341. k += 2;
  35342. var w2 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  35343. str.push(((w1 & 0x3ff) << 10) + (w2 & 0x3ff) + 0x10000);
  35344. }
  35345. map[charCode] = String.fromCharCode.apply(String, str);
  35346. });
  35347. return new ToUnicodeMap(map);
  35348. }
  35349. return null;
  35350. },
  35351. readCidToGidMap: function PartialEvaluator_readCidToGidMap(cidToGidStream) {
  35352. // Extract the encoding from the CIDToGIDMap
  35353. var glyphsData = cidToGidStream.getBytes();
  35354. // Set encoding 0 to later verify the font has an encoding
  35355. var result = [];
  35356. for (var j = 0, jj = glyphsData.length; j < jj; j++) {
  35357. var glyphID = (glyphsData[j++] << 8) | glyphsData[j];
  35358. if (glyphID === 0) {
  35359. continue;
  35360. }
  35361. var code = j >> 1;
  35362. result[code] = glyphID;
  35363. }
  35364. return result;
  35365. },
  35366. extractWidths: function PartialEvaluator_extractWidths(dict, xref,
  35367. descriptor,
  35368. properties) {
  35369. var glyphsWidths = [];
  35370. var defaultWidth = 0;
  35371. var glyphsVMetrics = [];
  35372. var defaultVMetrics;
  35373. var i, ii, j, jj, start, code, widths;
  35374. if (properties.composite) {
  35375. defaultWidth = dict.get('DW') || 1000;
  35376. widths = dict.get('W');
  35377. if (widths) {
  35378. for (i = 0, ii = widths.length; i < ii; i++) {
  35379. start = widths[i++];
  35380. code = xref.fetchIfRef(widths[i]);
  35381. if (isArray(code)) {
  35382. for (j = 0, jj = code.length; j < jj; j++) {
  35383. glyphsWidths[start++] = code[j];
  35384. }
  35385. } else {
  35386. var width = widths[++i];
  35387. for (j = start; j <= code; j++) {
  35388. glyphsWidths[j] = width;
  35389. }
  35390. }
  35391. }
  35392. }
  35393. if (properties.vertical) {
  35394. var vmetrics = (dict.get('DW2') || [880, -1000]);
  35395. defaultVMetrics = [vmetrics[1], defaultWidth * 0.5, vmetrics[0]];
  35396. vmetrics = dict.get('W2');
  35397. if (vmetrics) {
  35398. for (i = 0, ii = vmetrics.length; i < ii; i++) {
  35399. start = vmetrics[i++];
  35400. code = xref.fetchIfRef(vmetrics[i]);
  35401. if (isArray(code)) {
  35402. for (j = 0, jj = code.length; j < jj; j++) {
  35403. glyphsVMetrics[start++] = [code[j++], code[j++], code[j]];
  35404. }
  35405. } else {
  35406. var vmetric = [vmetrics[++i], vmetrics[++i], vmetrics[++i]];
  35407. for (j = start; j <= code; j++) {
  35408. glyphsVMetrics[j] = vmetric;
  35409. }
  35410. }
  35411. }
  35412. }
  35413. }
  35414. } else {
  35415. var firstChar = properties.firstChar;
  35416. widths = dict.get('Widths');
  35417. if (widths) {
  35418. j = firstChar;
  35419. for (i = 0, ii = widths.length; i < ii; i++) {
  35420. glyphsWidths[j++] = widths[i];
  35421. }
  35422. defaultWidth = (parseFloat(descriptor.get('MissingWidth')) || 0);
  35423. } else {
  35424. // Trying get the BaseFont metrics (see comment above).
  35425. var baseFontName = dict.get('BaseFont');
  35426. if (isName(baseFontName)) {
  35427. var metrics = this.getBaseFontMetrics(baseFontName.name);
  35428. glyphsWidths = this.buildCharCodeToWidth(metrics.widths,
  35429. properties);
  35430. defaultWidth = metrics.defaultWidth;
  35431. }
  35432. }
  35433. }
  35434. // Heuristic: detection of monospace font by checking all non-zero widths
  35435. var isMonospace = true;
  35436. var firstWidth = defaultWidth;
  35437. for (var glyph in glyphsWidths) {
  35438. var glyphWidth = glyphsWidths[glyph];
  35439. if (!glyphWidth) {
  35440. continue;
  35441. }
  35442. if (!firstWidth) {
  35443. firstWidth = glyphWidth;
  35444. continue;
  35445. }
  35446. if (firstWidth !== glyphWidth) {
  35447. isMonospace = false;
  35448. break;
  35449. }
  35450. }
  35451. if (isMonospace) {
  35452. properties.flags |= FontFlags.FixedPitch;
  35453. }
  35454. properties.defaultWidth = defaultWidth;
  35455. properties.widths = glyphsWidths;
  35456. properties.defaultVMetrics = defaultVMetrics;
  35457. properties.vmetrics = glyphsVMetrics;
  35458. },
  35459. isSerifFont: function PartialEvaluator_isSerifFont(baseFontName) {
  35460. // Simulating descriptor flags attribute
  35461. var fontNameWoStyle = baseFontName.split('-')[0];
  35462. return (fontNameWoStyle in serifFonts) ||
  35463. (fontNameWoStyle.search(/serif/gi) !== -1);
  35464. },
  35465. getBaseFontMetrics: function PartialEvaluator_getBaseFontMetrics(name) {
  35466. var defaultWidth = 0;
  35467. var widths = [];
  35468. var monospace = false;
  35469. var lookupName = (stdFontMap[name] || name);
  35470. if (!(lookupName in Metrics)) {
  35471. // Use default fonts for looking up font metrics if the passed
  35472. // font is not a base font
  35473. if (this.isSerifFont(name)) {
  35474. lookupName = 'Times-Roman';
  35475. } else {
  35476. lookupName = 'Helvetica';
  35477. }
  35478. }
  35479. var glyphWidths = Metrics[lookupName];
  35480. if (isNum(glyphWidths)) {
  35481. defaultWidth = glyphWidths;
  35482. monospace = true;
  35483. } else {
  35484. widths = glyphWidths;
  35485. }
  35486. return {
  35487. defaultWidth: defaultWidth,
  35488. monospace: monospace,
  35489. widths: widths
  35490. };
  35491. },
  35492. buildCharCodeToWidth:
  35493. function PartialEvaluator_bulildCharCodeToWidth(widthsByGlyphName,
  35494. properties) {
  35495. var widths = Object.create(null);
  35496. var differences = properties.differences;
  35497. var encoding = properties.defaultEncoding;
  35498. for (var charCode = 0; charCode < 256; charCode++) {
  35499. if (charCode in differences &&
  35500. widthsByGlyphName[differences[charCode]]) {
  35501. widths[charCode] = widthsByGlyphName[differences[charCode]];
  35502. continue;
  35503. }
  35504. if (charCode in encoding && widthsByGlyphName[encoding[charCode]]) {
  35505. widths[charCode] = widthsByGlyphName[encoding[charCode]];
  35506. continue;
  35507. }
  35508. }
  35509. return widths;
  35510. },
  35511. preEvaluateFont: function PartialEvaluator_preEvaluateFont(dict, xref) {
  35512. var baseDict = dict;
  35513. var type = dict.get('Subtype');
  35514. assert(isName(type), 'invalid font Subtype');
  35515. var composite = false;
  35516. var uint8array;
  35517. if (type.name === 'Type0') {
  35518. // If font is a composite
  35519. // - get the descendant font
  35520. // - set the type according to the descendant font
  35521. // - get the FontDescriptor from the descendant font
  35522. var df = dict.get('DescendantFonts');
  35523. if (!df) {
  35524. error('Descendant fonts are not specified');
  35525. }
  35526. dict = (isArray(df) ? xref.fetchIfRef(df[0]) : df);
  35527. type = dict.get('Subtype');
  35528. assert(isName(type), 'invalid font Subtype');
  35529. composite = true;
  35530. }
  35531. var descriptor = dict.get('FontDescriptor');
  35532. if (descriptor) {
  35533. var hash = new MurmurHash3_64();
  35534. var encoding = baseDict.getRaw('Encoding');
  35535. if (isName(encoding)) {
  35536. hash.update(encoding.name);
  35537. } else if (isRef(encoding)) {
  35538. hash.update(encoding.num + '_' + encoding.gen);
  35539. } else if (isDict(encoding)) {
  35540. var keys = encoding.getKeys();
  35541. for (var i = 0, ii = keys.length; i < ii; i++) {
  35542. var entry = encoding.getRaw(keys[i]);
  35543. if (isName(entry)) {
  35544. hash.update(entry.name);
  35545. } else if (isRef(entry)) {
  35546. hash.update(entry.num + '_' + entry.gen);
  35547. } else if (isArray(entry)) { // 'Differences' entry.
  35548. // Ideally we should check the contents of the array, but to avoid
  35549. // parsing it here and then again in |extractDataStructures|,
  35550. // we only use the array length for now (fixes bug1157493.pdf).
  35551. hash.update(entry.length.toString());
  35552. }
  35553. }
  35554. }
  35555. var toUnicode = dict.get('ToUnicode') || baseDict.get('ToUnicode');
  35556. if (isStream(toUnicode)) {
  35557. var stream = toUnicode.str || toUnicode;
  35558. uint8array = stream.buffer ?
  35559. new Uint8Array(stream.buffer.buffer, 0, stream.bufferLength) :
  35560. new Uint8Array(stream.bytes.buffer,
  35561. stream.start, stream.end - stream.start);
  35562. hash.update(uint8array);
  35563. } else if (isName(toUnicode)) {
  35564. hash.update(toUnicode.name);
  35565. }
  35566. var widths = dict.get('Widths') || baseDict.get('Widths');
  35567. if (widths) {
  35568. uint8array = new Uint8Array(new Uint32Array(widths).buffer);
  35569. hash.update(uint8array);
  35570. }
  35571. }
  35572. return {
  35573. descriptor: descriptor,
  35574. dict: dict,
  35575. baseDict: baseDict,
  35576. composite: composite,
  35577. type: type.name,
  35578. hash: hash ? hash.hexdigest() : ''
  35579. };
  35580. },
  35581. translateFont: function PartialEvaluator_translateFont(preEvaluatedFont,
  35582. xref) {
  35583. var baseDict = preEvaluatedFont.baseDict;
  35584. var dict = preEvaluatedFont.dict;
  35585. var composite = preEvaluatedFont.composite;
  35586. var descriptor = preEvaluatedFont.descriptor;
  35587. var type = preEvaluatedFont.type;
  35588. var maxCharIndex = (composite ? 0xFFFF : 0xFF);
  35589. var properties;
  35590. if (!descriptor) {
  35591. if (type === 'Type3') {
  35592. // FontDescriptor is only required for Type3 fonts when the document
  35593. // is a tagged pdf. Create a barbebones one to get by.
  35594. descriptor = new Dict(null);
  35595. descriptor.set('FontName', Name.get(type));
  35596. descriptor.set('FontBBox', dict.get('FontBBox'));
  35597. } else {
  35598. // Before PDF 1.5 if the font was one of the base 14 fonts, having a
  35599. // FontDescriptor was not required.
  35600. // This case is here for compatibility.
  35601. var baseFontName = dict.get('BaseFont');
  35602. if (!isName(baseFontName)) {
  35603. error('Base font is not specified');
  35604. }
  35605. // Using base font name as a font name.
  35606. baseFontName = baseFontName.name.replace(/[,_]/g, '-');
  35607. var metrics = this.getBaseFontMetrics(baseFontName);
  35608. // Simulating descriptor flags attribute
  35609. var fontNameWoStyle = baseFontName.split('-')[0];
  35610. var flags =
  35611. (this.isSerifFont(fontNameWoStyle) ? FontFlags.Serif : 0) |
  35612. (metrics.monospace ? FontFlags.FixedPitch : 0) |
  35613. (symbolsFonts[fontNameWoStyle] ? FontFlags.Symbolic :
  35614. FontFlags.Nonsymbolic);
  35615. properties = {
  35616. type: type,
  35617. name: baseFontName,
  35618. widths: metrics.widths,
  35619. defaultWidth: metrics.defaultWidth,
  35620. flags: flags,
  35621. firstChar: 0,
  35622. lastChar: maxCharIndex
  35623. };
  35624. this.extractDataStructures(dict, dict, xref, properties);
  35625. properties.widths = this.buildCharCodeToWidth(metrics.widths,
  35626. properties);
  35627. return new Font(baseFontName, null, properties);
  35628. }
  35629. }
  35630. // According to the spec if 'FontDescriptor' is declared, 'FirstChar',
  35631. // 'LastChar' and 'Widths' should exist too, but some PDF encoders seem
  35632. // to ignore this rule when a variant of a standart font is used.
  35633. // TODO Fill the width array depending on which of the base font this is
  35634. // a variant.
  35635. var firstChar = (dict.get('FirstChar') || 0);
  35636. var lastChar = (dict.get('LastChar') || maxCharIndex);
  35637. var fontName = descriptor.get('FontName');
  35638. var baseFont = dict.get('BaseFont');
  35639. // Some bad PDFs have a string as the font name.
  35640. if (isString(fontName)) {
  35641. fontName = Name.get(fontName);
  35642. }
  35643. if (isString(baseFont)) {
  35644. baseFont = Name.get(baseFont);
  35645. }
  35646. if (type !== 'Type3') {
  35647. var fontNameStr = fontName && fontName.name;
  35648. var baseFontStr = baseFont && baseFont.name;
  35649. if (fontNameStr !== baseFontStr) {
  35650. info('The FontDescriptor\'s FontName is "' + fontNameStr +
  35651. '" but should be the same as the Font\'s BaseFont "' +
  35652. baseFontStr + '"');
  35653. // Workaround for cases where e.g. fontNameStr = 'Arial' and
  35654. // baseFontStr = 'Arial,Bold' (needed when no font file is embedded).
  35655. if (fontNameStr && baseFontStr &&
  35656. baseFontStr.indexOf(fontNameStr) === 0) {
  35657. fontName = baseFont;
  35658. }
  35659. }
  35660. }
  35661. fontName = (fontName || baseFont);
  35662. assert(isName(fontName), 'invalid font name');
  35663. var fontFile = descriptor.get('FontFile', 'FontFile2', 'FontFile3');
  35664. if (fontFile) {
  35665. if (fontFile.dict) {
  35666. var subtype = fontFile.dict.get('Subtype');
  35667. if (subtype) {
  35668. subtype = subtype.name;
  35669. }
  35670. var length1 = fontFile.dict.get('Length1');
  35671. var length2 = fontFile.dict.get('Length2');
  35672. }
  35673. }
  35674. properties = {
  35675. type: type,
  35676. name: fontName.name,
  35677. subtype: subtype,
  35678. file: fontFile,
  35679. length1: length1,
  35680. length2: length2,
  35681. loadedName: baseDict.loadedName,
  35682. composite: composite,
  35683. wideChars: composite,
  35684. fixedPitch: false,
  35685. fontMatrix: (dict.get('FontMatrix') || FONT_IDENTITY_MATRIX),
  35686. firstChar: firstChar || 0,
  35687. lastChar: (lastChar || maxCharIndex),
  35688. bbox: descriptor.get('FontBBox'),
  35689. ascent: descriptor.get('Ascent'),
  35690. descent: descriptor.get('Descent'),
  35691. xHeight: descriptor.get('XHeight'),
  35692. capHeight: descriptor.get('CapHeight'),
  35693. flags: descriptor.get('Flags'),
  35694. italicAngle: descriptor.get('ItalicAngle'),
  35695. coded: false
  35696. };
  35697. if (composite) {
  35698. var cidEncoding = baseDict.get('Encoding');
  35699. if (isName(cidEncoding)) {
  35700. properties.cidEncoding = cidEncoding.name;
  35701. }
  35702. properties.cMap = CMapFactory.create(cidEncoding,
  35703. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  35704. properties.vertical = properties.cMap.vertical;
  35705. }
  35706. this.extractDataStructures(dict, baseDict, xref, properties);
  35707. this.extractWidths(dict, xref, descriptor, properties);
  35708. if (type === 'Type3') {
  35709. properties.isType3Font = true;
  35710. }
  35711. return new Font(fontName.name, fontFile, properties);
  35712. }
  35713. };
  35714. return PartialEvaluator;
  35715. })();
  35716. var TranslatedFont = (function TranslatedFontClosure() {
  35717. function TranslatedFont(loadedName, font, dict) {
  35718. this.loadedName = loadedName;
  35719. this.font = font;
  35720. this.dict = dict;
  35721. this.type3Loaded = null;
  35722. this.sent = false;
  35723. }
  35724. TranslatedFont.prototype = {
  35725. send: function (handler) {
  35726. if (this.sent) {
  35727. return;
  35728. }
  35729. var fontData = this.font.exportData();
  35730. handler.send('commonobj', [
  35731. this.loadedName,
  35732. 'Font',
  35733. fontData
  35734. ]);
  35735. this.sent = true;
  35736. },
  35737. loadType3Data: function (evaluator, resources, parentOperatorList, task) {
  35738. assert(this.font.isType3Font);
  35739. if (this.type3Loaded) {
  35740. return this.type3Loaded;
  35741. }
  35742. var translatedFont = this.font;
  35743. var loadCharProcsPromise = Promise.resolve();
  35744. var charProcs = this.dict.get('CharProcs').getAll();
  35745. var fontResources = this.dict.get('Resources') || resources;
  35746. var charProcKeys = Object.keys(charProcs);
  35747. var charProcOperatorList = {};
  35748. for (var i = 0, n = charProcKeys.length; i < n; ++i) {
  35749. loadCharProcsPromise = loadCharProcsPromise.then(function (key) {
  35750. var glyphStream = charProcs[key];
  35751. var operatorList = new OperatorList();
  35752. return evaluator.getOperatorList(glyphStream, task, fontResources,
  35753. operatorList).then(function () {
  35754. charProcOperatorList[key] = operatorList.getIR();
  35755. // Add the dependencies to the parent operator list so they are
  35756. // resolved before sub operator list is executed synchronously.
  35757. parentOperatorList.addDependencies(operatorList.dependencies);
  35758. }, function (reason) {
  35759. warn('Type3 font resource \"' + key + '\" is not available');
  35760. var operatorList = new OperatorList();
  35761. charProcOperatorList[key] = operatorList.getIR();
  35762. });
  35763. }.bind(this, charProcKeys[i]));
  35764. }
  35765. this.type3Loaded = loadCharProcsPromise.then(function () {
  35766. translatedFont.charProcOperatorList = charProcOperatorList;
  35767. });
  35768. return this.type3Loaded;
  35769. }
  35770. };
  35771. return TranslatedFont;
  35772. })();
  35773. var OperatorList = (function OperatorListClosure() {
  35774. var CHUNK_SIZE = 1000;
  35775. var CHUNK_SIZE_ABOUT = CHUNK_SIZE - 5; // close to chunk size
  35776. function getTransfers(queue) {
  35777. var transfers = [];
  35778. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  35779. for (var i = 0, ii = queue.length; i < ii; i++) {
  35780. switch (fnArray[i]) {
  35781. case OPS.paintInlineImageXObject:
  35782. case OPS.paintInlineImageXObjectGroup:
  35783. case OPS.paintImageMaskXObject:
  35784. var arg = argsArray[i][0]; // first param in imgData
  35785. if (!arg.cached) {
  35786. transfers.push(arg.data.buffer);
  35787. }
  35788. break;
  35789. }
  35790. }
  35791. return transfers;
  35792. }
  35793. function OperatorList(intent, messageHandler, pageIndex) {
  35794. this.messageHandler = messageHandler;
  35795. this.fnArray = [];
  35796. this.argsArray = [];
  35797. this.dependencies = {};
  35798. this._totalLength = 0;
  35799. this.pageIndex = pageIndex;
  35800. this.intent = intent;
  35801. }
  35802. OperatorList.prototype = {
  35803. get length() {
  35804. return this.argsArray.length;
  35805. },
  35806. /**
  35807. * @returns {number} The total length of the entire operator list,
  35808. * since `this.length === 0` after flushing.
  35809. */
  35810. get totalLength() {
  35811. return (this._totalLength + this.length);
  35812. },
  35813. addOp: function(fn, args) {
  35814. this.fnArray.push(fn);
  35815. this.argsArray.push(args);
  35816. if (this.messageHandler) {
  35817. if (this.fnArray.length >= CHUNK_SIZE) {
  35818. this.flush();
  35819. } else if (this.fnArray.length >= CHUNK_SIZE_ABOUT &&
  35820. (fn === OPS.restore || fn === OPS.endText)) {
  35821. // heuristic to flush on boundary of restore or endText
  35822. this.flush();
  35823. }
  35824. }
  35825. },
  35826. addDependency: function(dependency) {
  35827. if (dependency in this.dependencies) {
  35828. return;
  35829. }
  35830. this.dependencies[dependency] = true;
  35831. this.addOp(OPS.dependency, [dependency]);
  35832. },
  35833. addDependencies: function(dependencies) {
  35834. for (var key in dependencies) {
  35835. this.addDependency(key);
  35836. }
  35837. },
  35838. addOpList: function(opList) {
  35839. Util.extendObj(this.dependencies, opList.dependencies);
  35840. for (var i = 0, ii = opList.length; i < ii; i++) {
  35841. this.addOp(opList.fnArray[i], opList.argsArray[i]);
  35842. }
  35843. },
  35844. getIR: function() {
  35845. return {
  35846. fnArray: this.fnArray,
  35847. argsArray: this.argsArray,
  35848. length: this.length
  35849. };
  35850. },
  35851. flush: function(lastChunk) {
  35852. if (this.intent !== 'oplist') {
  35853. new QueueOptimizer().optimize(this);
  35854. }
  35855. var transfers = getTransfers(this);
  35856. var length = this.length;
  35857. this._totalLength += length;
  35858. this.messageHandler.send('RenderPageChunk', {
  35859. operatorList: {
  35860. fnArray: this.fnArray,
  35861. argsArray: this.argsArray,
  35862. lastChunk: lastChunk,
  35863. length: length
  35864. },
  35865. pageIndex: this.pageIndex,
  35866. intent: this.intent
  35867. }, transfers);
  35868. this.dependencies = {};
  35869. this.fnArray.length = 0;
  35870. this.argsArray.length = 0;
  35871. }
  35872. };
  35873. return OperatorList;
  35874. })();
  35875. var StateManager = (function StateManagerClosure() {
  35876. function StateManager(initialState) {
  35877. this.state = initialState;
  35878. this.stateStack = [];
  35879. }
  35880. StateManager.prototype = {
  35881. save: function () {
  35882. var old = this.state;
  35883. this.stateStack.push(this.state);
  35884. this.state = old.clone();
  35885. },
  35886. restore: function () {
  35887. var prev = this.stateStack.pop();
  35888. if (prev) {
  35889. this.state = prev;
  35890. }
  35891. },
  35892. transform: function (args) {
  35893. this.state.ctm = Util.transform(this.state.ctm, args);
  35894. }
  35895. };
  35896. return StateManager;
  35897. })();
  35898. var TextState = (function TextStateClosure() {
  35899. function TextState() {
  35900. this.ctm = new Float32Array(IDENTITY_MATRIX);
  35901. this.fontSize = 0;
  35902. this.font = null;
  35903. this.fontMatrix = FONT_IDENTITY_MATRIX;
  35904. this.textMatrix = IDENTITY_MATRIX.slice();
  35905. this.textLineMatrix = IDENTITY_MATRIX.slice();
  35906. this.charSpacing = 0;
  35907. this.wordSpacing = 0;
  35908. this.leading = 0;
  35909. this.textHScale = 1;
  35910. this.textRise = 0;
  35911. }
  35912. TextState.prototype = {
  35913. setTextMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  35914. var m = this.textMatrix;
  35915. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  35916. },
  35917. setTextLineMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  35918. var m = this.textLineMatrix;
  35919. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  35920. },
  35921. translateTextMatrix: function TextState_translateTextMatrix(x, y) {
  35922. var m = this.textMatrix;
  35923. m[4] = m[0] * x + m[2] * y + m[4];
  35924. m[5] = m[1] * x + m[3] * y + m[5];
  35925. },
  35926. translateTextLineMatrix: function TextState_translateTextMatrix(x, y) {
  35927. var m = this.textLineMatrix;
  35928. m[4] = m[0] * x + m[2] * y + m[4];
  35929. m[5] = m[1] * x + m[3] * y + m[5];
  35930. },
  35931. calcRenderMatrix: function TextState_calcRendeMatrix(ctm) {
  35932. // 9.4.4 Text Space Details
  35933. var tsm = [this.fontSize * this.textHScale, 0,
  35934. 0, this.fontSize,
  35935. 0, this.textRise];
  35936. return Util.transform(ctm, Util.transform(this.textMatrix, tsm));
  35937. },
  35938. carriageReturn: function TextState_carriageReturn() {
  35939. this.translateTextLineMatrix(0, -this.leading);
  35940. this.textMatrix = this.textLineMatrix.slice();
  35941. },
  35942. clone: function TextState_clone() {
  35943. var clone = Object.create(this);
  35944. clone.textMatrix = this.textMatrix.slice();
  35945. clone.textLineMatrix = this.textLineMatrix.slice();
  35946. clone.fontMatrix = this.fontMatrix.slice();
  35947. return clone;
  35948. }
  35949. };
  35950. return TextState;
  35951. })();
  35952. var EvalState = (function EvalStateClosure() {
  35953. function EvalState() {
  35954. this.ctm = new Float32Array(IDENTITY_MATRIX);
  35955. this.font = null;
  35956. this.textRenderingMode = TextRenderingMode.FILL;
  35957. this.fillColorSpace = ColorSpace.singletons.gray;
  35958. this.strokeColorSpace = ColorSpace.singletons.gray;
  35959. }
  35960. EvalState.prototype = {
  35961. clone: function CanvasExtraState_clone() {
  35962. return Object.create(this);
  35963. },
  35964. };
  35965. return EvalState;
  35966. })();
  35967. var EvaluatorPreprocessor = (function EvaluatorPreprocessorClosure() {
  35968. // Specifies properties for each command
  35969. //
  35970. // If variableArgs === true: [0, `numArgs`] expected
  35971. // If variableArgs === false: exactly `numArgs` expected
  35972. var OP_MAP = {
  35973. // Graphic state
  35974. w: { id: OPS.setLineWidth, numArgs: 1, variableArgs: false },
  35975. J: { id: OPS.setLineCap, numArgs: 1, variableArgs: false },
  35976. j: { id: OPS.setLineJoin, numArgs: 1, variableArgs: false },
  35977. M: { id: OPS.setMiterLimit, numArgs: 1, variableArgs: false },
  35978. d: { id: OPS.setDash, numArgs: 2, variableArgs: false },
  35979. ri: { id: OPS.setRenderingIntent, numArgs: 1, variableArgs: false },
  35980. i: { id: OPS.setFlatness, numArgs: 1, variableArgs: false },
  35981. gs: { id: OPS.setGState, numArgs: 1, variableArgs: false },
  35982. q: { id: OPS.save, numArgs: 0, variableArgs: false },
  35983. Q: { id: OPS.restore, numArgs: 0, variableArgs: false },
  35984. cm: { id: OPS.transform, numArgs: 6, variableArgs: false },
  35985. // Path
  35986. m: { id: OPS.moveTo, numArgs: 2, variableArgs: false },
  35987. l: { id: OPS.lineTo, numArgs: 2, variableArgs: false },
  35988. c: { id: OPS.curveTo, numArgs: 6, variableArgs: false },
  35989. v: { id: OPS.curveTo2, numArgs: 4, variableArgs: false },
  35990. y: { id: OPS.curveTo3, numArgs: 4, variableArgs: false },
  35991. h: { id: OPS.closePath, numArgs: 0, variableArgs: false },
  35992. re: { id: OPS.rectangle, numArgs: 4, variableArgs: false },
  35993. S: { id: OPS.stroke, numArgs: 0, variableArgs: false },
  35994. s: { id: OPS.closeStroke, numArgs: 0, variableArgs: false },
  35995. f: { id: OPS.fill, numArgs: 0, variableArgs: false },
  35996. F: { id: OPS.fill, numArgs: 0, variableArgs: false },
  35997. 'f*': { id: OPS.eoFill, numArgs: 0, variableArgs: false },
  35998. B: { id: OPS.fillStroke, numArgs: 0, variableArgs: false },
  35999. 'B*': { id: OPS.eoFillStroke, numArgs: 0, variableArgs: false },
  36000. b: { id: OPS.closeFillStroke, numArgs: 0, variableArgs: false },
  36001. 'b*': { id: OPS.closeEOFillStroke, numArgs: 0, variableArgs: false },
  36002. n: { id: OPS.endPath, numArgs: 0, variableArgs: false },
  36003. // Clipping
  36004. W: { id: OPS.clip, numArgs: 0, variableArgs: false },
  36005. 'W*': { id: OPS.eoClip, numArgs: 0, variableArgs: false },
  36006. // Text
  36007. BT: { id: OPS.beginText, numArgs: 0, variableArgs: false },
  36008. ET: { id: OPS.endText, numArgs: 0, variableArgs: false },
  36009. Tc: { id: OPS.setCharSpacing, numArgs: 1, variableArgs: false },
  36010. Tw: { id: OPS.setWordSpacing, numArgs: 1, variableArgs: false },
  36011. Tz: { id: OPS.setHScale, numArgs: 1, variableArgs: false },
  36012. TL: { id: OPS.setLeading, numArgs: 1, variableArgs: false },
  36013. Tf: { id: OPS.setFont, numArgs: 2, variableArgs: false },
  36014. Tr: { id: OPS.setTextRenderingMode, numArgs: 1, variableArgs: false },
  36015. Ts: { id: OPS.setTextRise, numArgs: 1, variableArgs: false },
  36016. Td: { id: OPS.moveText, numArgs: 2, variableArgs: false },
  36017. TD: { id: OPS.setLeadingMoveText, numArgs: 2, variableArgs: false },
  36018. Tm: { id: OPS.setTextMatrix, numArgs: 6, variableArgs: false },
  36019. 'T*': { id: OPS.nextLine, numArgs: 0, variableArgs: false },
  36020. Tj: { id: OPS.showText, numArgs: 1, variableArgs: false },
  36021. TJ: { id: OPS.showSpacedText, numArgs: 1, variableArgs: false },
  36022. '\'': { id: OPS.nextLineShowText, numArgs: 1, variableArgs: false },
  36023. '"': { id: OPS.nextLineSetSpacingShowText, numArgs: 3,
  36024. variableArgs: false },
  36025. // Type3 fonts
  36026. d0: { id: OPS.setCharWidth, numArgs: 2, variableArgs: false },
  36027. d1: { id: OPS.setCharWidthAndBounds, numArgs: 6, variableArgs: false },
  36028. // Color
  36029. CS: { id: OPS.setStrokeColorSpace, numArgs: 1, variableArgs: false },
  36030. cs: { id: OPS.setFillColorSpace, numArgs: 1, variableArgs: false },
  36031. SC: { id: OPS.setStrokeColor, numArgs: 4, variableArgs: true },
  36032. SCN: { id: OPS.setStrokeColorN, numArgs: 33, variableArgs: true },
  36033. sc: { id: OPS.setFillColor, numArgs: 4, variableArgs: true },
  36034. scn: { id: OPS.setFillColorN, numArgs: 33, variableArgs: true },
  36035. G: { id: OPS.setStrokeGray, numArgs: 1, variableArgs: false },
  36036. g: { id: OPS.setFillGray, numArgs: 1, variableArgs: false },
  36037. RG: { id: OPS.setStrokeRGBColor, numArgs: 3, variableArgs: false },
  36038. rg: { id: OPS.setFillRGBColor, numArgs: 3, variableArgs: false },
  36039. K: { id: OPS.setStrokeCMYKColor, numArgs: 4, variableArgs: false },
  36040. k: { id: OPS.setFillCMYKColor, numArgs: 4, variableArgs: false },
  36041. // Shading
  36042. sh: { id: OPS.shadingFill, numArgs: 1, variableArgs: false },
  36043. // Images
  36044. BI: { id: OPS.beginInlineImage, numArgs: 0, variableArgs: false },
  36045. ID: { id: OPS.beginImageData, numArgs: 0, variableArgs: false },
  36046. EI: { id: OPS.endInlineImage, numArgs: 1, variableArgs: false },
  36047. // XObjects
  36048. Do: { id: OPS.paintXObject, numArgs: 1, variableArgs: false },
  36049. MP: { id: OPS.markPoint, numArgs: 1, variableArgs: false },
  36050. DP: { id: OPS.markPointProps, numArgs: 2, variableArgs: false },
  36051. BMC: { id: OPS.beginMarkedContent, numArgs: 1, variableArgs: false },
  36052. BDC: { id: OPS.beginMarkedContentProps, numArgs: 2,
  36053. variableArgs: false },
  36054. EMC: { id: OPS.endMarkedContent, numArgs: 0, variableArgs: false },
  36055. // Compatibility
  36056. BX: { id: OPS.beginCompat, numArgs: 0, variableArgs: false },
  36057. EX: { id: OPS.endCompat, numArgs: 0, variableArgs: false },
  36058. // (reserved partial commands for the lexer)
  36059. BM: null,
  36060. BD: null,
  36061. 'true': null,
  36062. fa: null,
  36063. fal: null,
  36064. fals: null,
  36065. 'false': null,
  36066. nu: null,
  36067. nul: null,
  36068. 'null': null
  36069. };
  36070. function EvaluatorPreprocessor(stream, xref, stateManager) {
  36071. // TODO(mduan): pass array of knownCommands rather than OP_MAP
  36072. // dictionary
  36073. this.parser = new Parser(new Lexer(stream, OP_MAP), false, xref);
  36074. this.stateManager = stateManager;
  36075. this.nonProcessedArgs = [];
  36076. }
  36077. EvaluatorPreprocessor.prototype = {
  36078. get savedStatesDepth() {
  36079. return this.stateManager.stateStack.length;
  36080. },
  36081. // |operation| is an object with two fields:
  36082. //
  36083. // - |fn| is an out param.
  36084. //
  36085. // - |args| is an inout param. On entry, it should have one of two values.
  36086. //
  36087. // - An empty array. This indicates that the caller is providing the
  36088. // array in which the args will be stored in. The caller should use
  36089. // this value if it can reuse a single array for each call to read().
  36090. //
  36091. // - |null|. This indicates that the caller needs this function to create
  36092. // the array in which any args are stored in. If there are zero args,
  36093. // this function will leave |operation.args| as |null| (thus avoiding
  36094. // allocations that would occur if we used an empty array to represent
  36095. // zero arguments). Otherwise, it will replace |null| with a new array
  36096. // containing the arguments. The caller should use this value if it
  36097. // cannot reuse an array for each call to read().
  36098. //
  36099. // These two modes are present because this function is very hot and so
  36100. // avoiding allocations where possible is worthwhile.
  36101. //
  36102. read: function EvaluatorPreprocessor_read(operation) {
  36103. var args = operation.args;
  36104. while (true) {
  36105. var obj = this.parser.getObj();
  36106. if (isCmd(obj)) {
  36107. var cmd = obj.cmd;
  36108. // Check that the command is valid
  36109. var opSpec = OP_MAP[cmd];
  36110. if (!opSpec) {
  36111. warn('Unknown command "' + cmd + '"');
  36112. continue;
  36113. }
  36114. var fn = opSpec.id;
  36115. var numArgs = opSpec.numArgs;
  36116. var argsLength = args !== null ? args.length : 0;
  36117. if (!opSpec.variableArgs) {
  36118. // Postscript commands can be nested, e.g. /F2 /GS2 gs 5.711 Tf
  36119. if (argsLength !== numArgs) {
  36120. var nonProcessedArgs = this.nonProcessedArgs;
  36121. while (argsLength > numArgs) {
  36122. nonProcessedArgs.push(args.shift());
  36123. argsLength--;
  36124. }
  36125. while (argsLength < numArgs && nonProcessedArgs.length !== 0) {
  36126. if (!args) {
  36127. args = [];
  36128. }
  36129. args.unshift(nonProcessedArgs.pop());
  36130. argsLength++;
  36131. }
  36132. }
  36133. if (argsLength < numArgs) {
  36134. // If we receive too few args, it's not possible to possible
  36135. // to execute the command, so skip the command
  36136. info('Command ' + fn + ': because expected ' +
  36137. numArgs + ' args, but received ' + argsLength +
  36138. ' args; skipping');
  36139. args = null;
  36140. continue;
  36141. }
  36142. } else if (argsLength > numArgs) {
  36143. info('Command ' + fn + ': expected [0,' + numArgs +
  36144. '] args, but received ' + argsLength + ' args');
  36145. }
  36146. // TODO figure out how to type-check vararg functions
  36147. this.preprocessCommand(fn, args);
  36148. operation.fn = fn;
  36149. operation.args = args;
  36150. return true;
  36151. } else {
  36152. if (isEOF(obj)) {
  36153. return false; // no more commands
  36154. }
  36155. // argument
  36156. if (obj !== null) {
  36157. if (!args) {
  36158. args = [];
  36159. }
  36160. args.push((obj instanceof Dict ? obj.getAll() : obj));
  36161. assert(args.length <= 33, 'Too many arguments');
  36162. }
  36163. }
  36164. }
  36165. },
  36166. preprocessCommand:
  36167. function EvaluatorPreprocessor_preprocessCommand(fn, args) {
  36168. switch (fn | 0) {
  36169. case OPS.save:
  36170. this.stateManager.save();
  36171. break;
  36172. case OPS.restore:
  36173. this.stateManager.restore();
  36174. break;
  36175. case OPS.transform:
  36176. this.stateManager.transform(args);
  36177. break;
  36178. }
  36179. }
  36180. };
  36181. return EvaluatorPreprocessor;
  36182. })();
  36183. var QueueOptimizer = (function QueueOptimizerClosure() {
  36184. function addState(parentState, pattern, fn) {
  36185. var state = parentState;
  36186. for (var i = 0, ii = pattern.length - 1; i < ii; i++) {
  36187. var item = pattern[i];
  36188. state = (state[item] || (state[item] = []));
  36189. }
  36190. state[pattern[pattern.length - 1]] = fn;
  36191. }
  36192. function handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  36193. argsArray) {
  36194. // Handles special case of mainly LaTeX documents which use image masks to
  36195. // draw lines with the current fill style.
  36196. // 'count' groups of (save, transform, paintImageMaskXObject, restore)+
  36197. // have been found at iFirstSave.
  36198. var iFirstPIMXO = iFirstSave + 2;
  36199. for (var i = 0; i < count; i++) {
  36200. var arg = argsArray[iFirstPIMXO + 4 * i];
  36201. var imageMask = arg.length === 1 && arg[0];
  36202. if (imageMask && imageMask.width === 1 && imageMask.height === 1 &&
  36203. (!imageMask.data.length ||
  36204. (imageMask.data.length === 1 && imageMask.data[0] === 0))) {
  36205. fnArray[iFirstPIMXO + 4 * i] = OPS.paintSolidColorImageMask;
  36206. continue;
  36207. }
  36208. break;
  36209. }
  36210. return count - i;
  36211. }
  36212. var InitialState = [];
  36213. // This replaces (save, transform, paintInlineImageXObject, restore)+
  36214. // sequences with one |paintInlineImageXObjectGroup| operation.
  36215. addState(InitialState,
  36216. [OPS.save, OPS.transform, OPS.paintInlineImageXObject, OPS.restore],
  36217. function foundInlineImageGroup(context) {
  36218. var MIN_IMAGES_IN_INLINE_IMAGES_BLOCK = 10;
  36219. var MAX_IMAGES_IN_INLINE_IMAGES_BLOCK = 200;
  36220. var MAX_WIDTH = 1000;
  36221. var IMAGE_PADDING = 1;
  36222. var fnArray = context.fnArray, argsArray = context.argsArray;
  36223. var curr = context.iCurr;
  36224. var iFirstSave = curr - 3;
  36225. var iFirstTransform = curr - 2;
  36226. var iFirstPIIXO = curr - 1;
  36227. // Look for the quartets.
  36228. var i = iFirstSave + 4;
  36229. var ii = fnArray.length;
  36230. while (i + 3 < ii) {
  36231. if (fnArray[i] !== OPS.save ||
  36232. fnArray[i + 1] !== OPS.transform ||
  36233. fnArray[i + 2] !== OPS.paintInlineImageXObject ||
  36234. fnArray[i + 3] !== OPS.restore) {
  36235. break; // ops don't match
  36236. }
  36237. i += 4;
  36238. }
  36239. // At this point, i is the index of the first op past the last valid
  36240. // quartet.
  36241. var count = Math.min((i - iFirstSave) / 4,
  36242. MAX_IMAGES_IN_INLINE_IMAGES_BLOCK);
  36243. if (count < MIN_IMAGES_IN_INLINE_IMAGES_BLOCK) {
  36244. return i;
  36245. }
  36246. // assuming that heights of those image is too small (~1 pixel)
  36247. // packing as much as possible by lines
  36248. var maxX = 0;
  36249. var map = [], maxLineHeight = 0;
  36250. var currentX = IMAGE_PADDING, currentY = IMAGE_PADDING;
  36251. var q;
  36252. for (q = 0; q < count; q++) {
  36253. var transform = argsArray[iFirstTransform + (q << 2)];
  36254. var img = argsArray[iFirstPIIXO + (q << 2)][0];
  36255. if (currentX + img.width > MAX_WIDTH) {
  36256. // starting new line
  36257. maxX = Math.max(maxX, currentX);
  36258. currentY += maxLineHeight + 2 * IMAGE_PADDING;
  36259. currentX = 0;
  36260. maxLineHeight = 0;
  36261. }
  36262. map.push({
  36263. transform: transform,
  36264. x: currentX, y: currentY,
  36265. w: img.width, h: img.height
  36266. });
  36267. currentX += img.width + 2 * IMAGE_PADDING;
  36268. maxLineHeight = Math.max(maxLineHeight, img.height);
  36269. }
  36270. var imgWidth = Math.max(maxX, currentX) + IMAGE_PADDING;
  36271. var imgHeight = currentY + maxLineHeight + IMAGE_PADDING;
  36272. var imgData = new Uint8Array(imgWidth * imgHeight * 4);
  36273. var imgRowSize = imgWidth << 2;
  36274. for (q = 0; q < count; q++) {
  36275. var data = argsArray[iFirstPIIXO + (q << 2)][0].data;
  36276. // Copy image by lines and extends pixels into padding.
  36277. var rowSize = map[q].w << 2;
  36278. var dataOffset = 0;
  36279. var offset = (map[q].x + map[q].y * imgWidth) << 2;
  36280. imgData.set(data.subarray(0, rowSize), offset - imgRowSize);
  36281. for (var k = 0, kk = map[q].h; k < kk; k++) {
  36282. imgData.set(data.subarray(dataOffset, dataOffset + rowSize), offset);
  36283. dataOffset += rowSize;
  36284. offset += imgRowSize;
  36285. }
  36286. imgData.set(data.subarray(dataOffset - rowSize, dataOffset), offset);
  36287. while (offset >= 0) {
  36288. data[offset - 4] = data[offset];
  36289. data[offset - 3] = data[offset + 1];
  36290. data[offset - 2] = data[offset + 2];
  36291. data[offset - 1] = data[offset + 3];
  36292. data[offset + rowSize] = data[offset + rowSize - 4];
  36293. data[offset + rowSize + 1] = data[offset + rowSize - 3];
  36294. data[offset + rowSize + 2] = data[offset + rowSize - 2];
  36295. data[offset + rowSize + 3] = data[offset + rowSize - 1];
  36296. offset -= imgRowSize;
  36297. }
  36298. }
  36299. // Replace queue items.
  36300. fnArray.splice(iFirstSave, count * 4, OPS.paintInlineImageXObjectGroup);
  36301. argsArray.splice(iFirstSave, count * 4,
  36302. [{ width: imgWidth, height: imgHeight, kind: ImageKind.RGBA_32BPP,
  36303. data: imgData }, map]);
  36304. return iFirstSave + 1;
  36305. });
  36306. // This replaces (save, transform, paintImageMaskXObject, restore)+
  36307. // sequences with one |paintImageMaskXObjectGroup| or one
  36308. // |paintImageMaskXObjectRepeat| operation.
  36309. addState(InitialState,
  36310. [OPS.save, OPS.transform, OPS.paintImageMaskXObject, OPS.restore],
  36311. function foundImageMaskGroup(context) {
  36312. var MIN_IMAGES_IN_MASKS_BLOCK = 10;
  36313. var MAX_IMAGES_IN_MASKS_BLOCK = 100;
  36314. var MAX_SAME_IMAGES_IN_MASKS_BLOCK = 1000;
  36315. var fnArray = context.fnArray, argsArray = context.argsArray;
  36316. var curr = context.iCurr;
  36317. var iFirstSave = curr - 3;
  36318. var iFirstTransform = curr - 2;
  36319. var iFirstPIMXO = curr - 1;
  36320. // Look for the quartets.
  36321. var i = iFirstSave + 4;
  36322. var ii = fnArray.length;
  36323. while (i + 3 < ii) {
  36324. if (fnArray[i] !== OPS.save ||
  36325. fnArray[i + 1] !== OPS.transform ||
  36326. fnArray[i + 2] !== OPS.paintImageMaskXObject ||
  36327. fnArray[i + 3] !== OPS.restore) {
  36328. break; // ops don't match
  36329. }
  36330. i += 4;
  36331. }
  36332. // At this point, i is the index of the first op past the last valid
  36333. // quartet.
  36334. var count = (i - iFirstSave) / 4;
  36335. count = handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  36336. argsArray);
  36337. if (count < MIN_IMAGES_IN_MASKS_BLOCK) {
  36338. return i;
  36339. }
  36340. var q;
  36341. var isSameImage = false;
  36342. var iTransform, transformArgs;
  36343. var firstPIMXOArg0 = argsArray[iFirstPIMXO][0];
  36344. if (argsArray[iFirstTransform][1] === 0 &&
  36345. argsArray[iFirstTransform][2] === 0) {
  36346. isSameImage = true;
  36347. var firstTransformArg0 = argsArray[iFirstTransform][0];
  36348. var firstTransformArg3 = argsArray[iFirstTransform][3];
  36349. iTransform = iFirstTransform + 4;
  36350. var iPIMXO = iFirstPIMXO + 4;
  36351. for (q = 1; q < count; q++, iTransform += 4, iPIMXO += 4) {
  36352. transformArgs = argsArray[iTransform];
  36353. if (argsArray[iPIMXO][0] !== firstPIMXOArg0 ||
  36354. transformArgs[0] !== firstTransformArg0 ||
  36355. transformArgs[1] !== 0 ||
  36356. transformArgs[2] !== 0 ||
  36357. transformArgs[3] !== firstTransformArg3) {
  36358. if (q < MIN_IMAGES_IN_MASKS_BLOCK) {
  36359. isSameImage = false;
  36360. } else {
  36361. count = q;
  36362. }
  36363. break; // different image or transform
  36364. }
  36365. }
  36366. }
  36367. if (isSameImage) {
  36368. count = Math.min(count, MAX_SAME_IMAGES_IN_MASKS_BLOCK);
  36369. var positions = new Float32Array(count * 2);
  36370. iTransform = iFirstTransform;
  36371. for (q = 0; q < count; q++, iTransform += 4) {
  36372. transformArgs = argsArray[iTransform];
  36373. positions[(q << 1)] = transformArgs[4];
  36374. positions[(q << 1) + 1] = transformArgs[5];
  36375. }
  36376. // Replace queue items.
  36377. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectRepeat);
  36378. argsArray.splice(iFirstSave, count * 4,
  36379. [firstPIMXOArg0, firstTransformArg0, firstTransformArg3, positions]);
  36380. } else {
  36381. count = Math.min(count, MAX_IMAGES_IN_MASKS_BLOCK);
  36382. var images = [];
  36383. for (q = 0; q < count; q++) {
  36384. transformArgs = argsArray[iFirstTransform + (q << 2)];
  36385. var maskParams = argsArray[iFirstPIMXO + (q << 2)][0];
  36386. images.push({ data: maskParams.data, width: maskParams.width,
  36387. height: maskParams.height,
  36388. transform: transformArgs });
  36389. }
  36390. // Replace queue items.
  36391. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectGroup);
  36392. argsArray.splice(iFirstSave, count * 4, [images]);
  36393. }
  36394. return iFirstSave + 1;
  36395. });
  36396. // This replaces (save, transform, paintImageXObject, restore)+ sequences
  36397. // with one paintImageXObjectRepeat operation, if the |transform| and
  36398. // |paintImageXObjectRepeat| ops are appropriate.
  36399. addState(InitialState,
  36400. [OPS.save, OPS.transform, OPS.paintImageXObject, OPS.restore],
  36401. function (context) {
  36402. var MIN_IMAGES_IN_BLOCK = 3;
  36403. var MAX_IMAGES_IN_BLOCK = 1000;
  36404. var fnArray = context.fnArray, argsArray = context.argsArray;
  36405. var curr = context.iCurr;
  36406. var iFirstSave = curr - 3;
  36407. var iFirstTransform = curr - 2;
  36408. var iFirstPIXO = curr - 1;
  36409. var iFirstRestore = curr;
  36410. if (argsArray[iFirstTransform][1] !== 0 ||
  36411. argsArray[iFirstTransform][2] !== 0) {
  36412. return iFirstRestore + 1; // transform has the wrong form
  36413. }
  36414. // Look for the quartets.
  36415. var firstPIXOArg0 = argsArray[iFirstPIXO][0];
  36416. var firstTransformArg0 = argsArray[iFirstTransform][0];
  36417. var firstTransformArg3 = argsArray[iFirstTransform][3];
  36418. var i = iFirstSave + 4;
  36419. var ii = fnArray.length;
  36420. while (i + 3 < ii) {
  36421. if (fnArray[i] !== OPS.save ||
  36422. fnArray[i + 1] !== OPS.transform ||
  36423. fnArray[i + 2] !== OPS.paintImageXObject ||
  36424. fnArray[i + 3] !== OPS.restore) {
  36425. break; // ops don't match
  36426. }
  36427. if (argsArray[i + 1][0] !== firstTransformArg0 ||
  36428. argsArray[i + 1][1] !== 0 ||
  36429. argsArray[i + 1][2] !== 0 ||
  36430. argsArray[i + 1][3] !== firstTransformArg3) {
  36431. break; // transforms don't match
  36432. }
  36433. if (argsArray[i + 2][0] !== firstPIXOArg0) {
  36434. break; // images don't match
  36435. }
  36436. i += 4;
  36437. }
  36438. // At this point, i is the index of the first op past the last valid
  36439. // quartet.
  36440. var count = Math.min((i - iFirstSave) / 4, MAX_IMAGES_IN_BLOCK);
  36441. if (count < MIN_IMAGES_IN_BLOCK) {
  36442. return i;
  36443. }
  36444. // Extract the (x,y) positions from all of the matching transforms.
  36445. var positions = new Float32Array(count * 2);
  36446. var iTransform = iFirstTransform;
  36447. for (var q = 0; q < count; q++, iTransform += 4) {
  36448. var transformArgs = argsArray[iTransform];
  36449. positions[(q << 1)] = transformArgs[4];
  36450. positions[(q << 1) + 1] = transformArgs[5];
  36451. }
  36452. // Replace queue items.
  36453. var args = [firstPIXOArg0, firstTransformArg0, firstTransformArg3,
  36454. positions];
  36455. fnArray.splice(iFirstSave, count * 4, OPS.paintImageXObjectRepeat);
  36456. argsArray.splice(iFirstSave, count * 4, args);
  36457. return iFirstSave + 1;
  36458. });
  36459. // This replaces (beginText, setFont, setTextMatrix, showText, endText)+
  36460. // sequences with (beginText, setFont, (setTextMatrix, showText)+, endText)+
  36461. // sequences, if the font for each one is the same.
  36462. addState(InitialState,
  36463. [OPS.beginText, OPS.setFont, OPS.setTextMatrix, OPS.showText, OPS.endText],
  36464. function (context) {
  36465. var MIN_CHARS_IN_BLOCK = 3;
  36466. var MAX_CHARS_IN_BLOCK = 1000;
  36467. var fnArray = context.fnArray, argsArray = context.argsArray;
  36468. var curr = context.iCurr;
  36469. var iFirstBeginText = curr - 4;
  36470. var iFirstSetFont = curr - 3;
  36471. var iFirstSetTextMatrix = curr - 2;
  36472. var iFirstShowText = curr - 1;
  36473. var iFirstEndText = curr;
  36474. // Look for the quintets.
  36475. var firstSetFontArg0 = argsArray[iFirstSetFont][0];
  36476. var firstSetFontArg1 = argsArray[iFirstSetFont][1];
  36477. var i = iFirstBeginText + 5;
  36478. var ii = fnArray.length;
  36479. while (i + 4 < ii) {
  36480. if (fnArray[i] !== OPS.beginText ||
  36481. fnArray[i + 1] !== OPS.setFont ||
  36482. fnArray[i + 2] !== OPS.setTextMatrix ||
  36483. fnArray[i + 3] !== OPS.showText ||
  36484. fnArray[i + 4] !== OPS.endText) {
  36485. break; // ops don't match
  36486. }
  36487. if (argsArray[i + 1][0] !== firstSetFontArg0 ||
  36488. argsArray[i + 1][1] !== firstSetFontArg1) {
  36489. break; // fonts don't match
  36490. }
  36491. i += 5;
  36492. }
  36493. // At this point, i is the index of the first op past the last valid
  36494. // quintet.
  36495. var count = Math.min(((i - iFirstBeginText) / 5), MAX_CHARS_IN_BLOCK);
  36496. if (count < MIN_CHARS_IN_BLOCK) {
  36497. return i;
  36498. }
  36499. // If the preceding quintet is (<something>, setFont, setTextMatrix,
  36500. // showText, endText), include that as well. (E.g. <something> might be
  36501. // |dependency|.)
  36502. var iFirst = iFirstBeginText;
  36503. if (iFirstBeginText >= 4 &&
  36504. fnArray[iFirstBeginText - 4] === fnArray[iFirstSetFont] &&
  36505. fnArray[iFirstBeginText - 3] === fnArray[iFirstSetTextMatrix] &&
  36506. fnArray[iFirstBeginText - 2] === fnArray[iFirstShowText] &&
  36507. fnArray[iFirstBeginText - 1] === fnArray[iFirstEndText] &&
  36508. argsArray[iFirstBeginText - 4][0] === firstSetFontArg0 &&
  36509. argsArray[iFirstBeginText - 4][1] === firstSetFontArg1) {
  36510. count++;
  36511. iFirst -= 5;
  36512. }
  36513. // Remove (endText, beginText, setFont) trios.
  36514. var iEndText = iFirst + 4;
  36515. for (var q = 1; q < count; q++) {
  36516. fnArray.splice(iEndText, 3);
  36517. argsArray.splice(iEndText, 3);
  36518. iEndText += 2;
  36519. }
  36520. return iEndText + 1;
  36521. });
  36522. function QueueOptimizer() {}
  36523. QueueOptimizer.prototype = {
  36524. optimize: function QueueOptimizer_optimize(queue) {
  36525. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  36526. var context = {
  36527. iCurr: 0,
  36528. fnArray: fnArray,
  36529. argsArray: argsArray
  36530. };
  36531. var state;
  36532. var i = 0, ii = fnArray.length;
  36533. while (i < ii) {
  36534. state = (state || InitialState)[fnArray[i]];
  36535. if (typeof state === 'function') { // we found some handler
  36536. context.iCurr = i;
  36537. // state() returns the index of the first non-matching op (if we
  36538. // didn't match) or the first op past the modified ops (if we did
  36539. // match and replace).
  36540. i = state(context);
  36541. state = undefined; // reset the state machine
  36542. ii = context.fnArray.length;
  36543. } else {
  36544. i++;
  36545. }
  36546. }
  36547. }
  36548. };
  36549. return QueueOptimizer;
  36550. })();
  36551. exports.OperatorList = OperatorList;
  36552. exports.PartialEvaluator = PartialEvaluator;
  36553. }));
  36554. (function (root, factory) {
  36555. {
  36556. factory((root.pdfjsCoreAnnotation = {}), root.pdfjsSharedUtil,
  36557. root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreColorSpace,
  36558. root.pdfjsCoreObj, root.pdfjsCoreEvaluator);
  36559. }
  36560. }(this, function (exports, sharedUtil, corePrimitives, coreStream,
  36561. coreColorSpace, coreObj, coreEvaluator) {
  36562. var AnnotationBorderStyleType = sharedUtil.AnnotationBorderStyleType;
  36563. var AnnotationFlag = sharedUtil.AnnotationFlag;
  36564. var AnnotationType = sharedUtil.AnnotationType;
  36565. var OPS = sharedUtil.OPS;
  36566. var Util = sharedUtil.Util;
  36567. var isArray = sharedUtil.isArray;
  36568. var isInt = sharedUtil.isInt;
  36569. var isValidUrl = sharedUtil.isValidUrl;
  36570. var stringToBytes = sharedUtil.stringToBytes;
  36571. var stringToPDFString = sharedUtil.stringToPDFString;
  36572. var stringToUTF8String = sharedUtil.stringToUTF8String;
  36573. var warn = sharedUtil.warn;
  36574. var Dict = corePrimitives.Dict;
  36575. var isDict = corePrimitives.isDict;
  36576. var isName = corePrimitives.isName;
  36577. var Stream = coreStream.Stream;
  36578. var ColorSpace = coreColorSpace.ColorSpace;
  36579. var ObjectLoader = coreObj.ObjectLoader;
  36580. var OperatorList = coreEvaluator.OperatorList;
  36581. /**
  36582. * @class
  36583. * @alias AnnotationFactory
  36584. */
  36585. function AnnotationFactory() {}
  36586. AnnotationFactory.prototype = /** @lends AnnotationFactory.prototype */ {
  36587. /**
  36588. * @param {XRef} xref
  36589. * @param {Object} ref
  36590. * @returns {Annotation}
  36591. */
  36592. create: function AnnotationFactory_create(xref, ref) {
  36593. var dict = xref.fetchIfRef(ref);
  36594. if (!isDict(dict)) {
  36595. return;
  36596. }
  36597. // Determine the annotation's subtype.
  36598. var subtype = dict.get('Subtype');
  36599. subtype = isName(subtype) ? subtype.name : '';
  36600. // Return the right annotation object based on the subtype and field type.
  36601. var parameters = {
  36602. dict: dict,
  36603. ref: ref
  36604. };
  36605. switch (subtype) {
  36606. case 'Link':
  36607. return new LinkAnnotation(parameters);
  36608. case 'Text':
  36609. return new TextAnnotation(parameters);
  36610. case 'Widget':
  36611. var fieldType = Util.getInheritableProperty(dict, 'FT');
  36612. if (isName(fieldType) && fieldType.name === 'Tx') {
  36613. return new TextWidgetAnnotation(parameters);
  36614. }
  36615. return new WidgetAnnotation(parameters);
  36616. case 'Popup':
  36617. return new PopupAnnotation(parameters);
  36618. case 'Highlight':
  36619. return new HighlightAnnotation(parameters);
  36620. case 'Underline':
  36621. return new UnderlineAnnotation(parameters);
  36622. case 'Squiggly':
  36623. return new SquigglyAnnotation(parameters);
  36624. case 'StrikeOut':
  36625. return new StrikeOutAnnotation(parameters);
  36626. default:
  36627. warn('Unimplemented annotation type "' + subtype + '", ' +
  36628. 'falling back to base annotation');
  36629. return new Annotation(parameters);
  36630. }
  36631. }
  36632. };
  36633. var Annotation = (function AnnotationClosure() {
  36634. // 12.5.5: Algorithm: Appearance streams
  36635. function getTransformMatrix(rect, bbox, matrix) {
  36636. var bounds = Util.getAxialAlignedBoundingBox(bbox, matrix);
  36637. var minX = bounds[0];
  36638. var minY = bounds[1];
  36639. var maxX = bounds[2];
  36640. var maxY = bounds[3];
  36641. if (minX === maxX || minY === maxY) {
  36642. // From real-life file, bbox was [0, 0, 0, 0]. In this case,
  36643. // just apply the transform for rect
  36644. return [1, 0, 0, 1, rect[0], rect[1]];
  36645. }
  36646. var xRatio = (rect[2] - rect[0]) / (maxX - minX);
  36647. var yRatio = (rect[3] - rect[1]) / (maxY - minY);
  36648. return [
  36649. xRatio,
  36650. 0,
  36651. 0,
  36652. yRatio,
  36653. rect[0] - minX * xRatio,
  36654. rect[1] - minY * yRatio
  36655. ];
  36656. }
  36657. function getDefaultAppearance(dict) {
  36658. var appearanceState = dict.get('AP');
  36659. if (!isDict(appearanceState)) {
  36660. return;
  36661. }
  36662. var appearance;
  36663. var appearances = appearanceState.get('N');
  36664. if (isDict(appearances)) {
  36665. var as = dict.get('AS');
  36666. if (as && appearances.has(as.name)) {
  36667. appearance = appearances.get(as.name);
  36668. }
  36669. } else {
  36670. appearance = appearances;
  36671. }
  36672. return appearance;
  36673. }
  36674. function Annotation(params) {
  36675. var dict = params.dict;
  36676. this.setFlags(dict.get('F'));
  36677. this.setRectangle(dict.get('Rect'));
  36678. this.setColor(dict.get('C'));
  36679. this.setBorderStyle(dict);
  36680. this.appearance = getDefaultAppearance(dict);
  36681. // Expose public properties using a data object.
  36682. this.data = {};
  36683. this.data.id = params.ref.toString();
  36684. this.data.subtype = dict.get('Subtype').name;
  36685. this.data.annotationFlags = this.flags;
  36686. this.data.rect = this.rectangle;
  36687. this.data.color = this.color;
  36688. this.data.borderStyle = this.borderStyle;
  36689. this.data.hasAppearance = !!this.appearance;
  36690. }
  36691. Annotation.prototype = {
  36692. /**
  36693. * @return {boolean}
  36694. */
  36695. get viewable() {
  36696. if (this.flags) {
  36697. return !this.hasFlag(AnnotationFlag.INVISIBLE) &&
  36698. !this.hasFlag(AnnotationFlag.HIDDEN) &&
  36699. !this.hasFlag(AnnotationFlag.NOVIEW);
  36700. }
  36701. return true;
  36702. },
  36703. /**
  36704. * @return {boolean}
  36705. */
  36706. get printable() {
  36707. if (this.flags) {
  36708. return this.hasFlag(AnnotationFlag.PRINT) &&
  36709. !this.hasFlag(AnnotationFlag.INVISIBLE) &&
  36710. !this.hasFlag(AnnotationFlag.HIDDEN);
  36711. }
  36712. return false;
  36713. },
  36714. /**
  36715. * Set the flags.
  36716. *
  36717. * @public
  36718. * @memberof Annotation
  36719. * @param {number} flags - Unsigned 32-bit integer specifying annotation
  36720. * characteristics
  36721. * @see {@link shared/util.js}
  36722. */
  36723. setFlags: function Annotation_setFlags(flags) {
  36724. if (isInt(flags)) {
  36725. this.flags = flags;
  36726. } else {
  36727. this.flags = 0;
  36728. }
  36729. },
  36730. /**
  36731. * Check if a provided flag is set.
  36732. *
  36733. * @public
  36734. * @memberof Annotation
  36735. * @param {number} flag - Hexadecimal representation for an annotation
  36736. * characteristic
  36737. * @return {boolean}
  36738. * @see {@link shared/util.js}
  36739. */
  36740. hasFlag: function Annotation_hasFlag(flag) {
  36741. if (this.flags) {
  36742. return (this.flags & flag) > 0;
  36743. }
  36744. return false;
  36745. },
  36746. /**
  36747. * Set the rectangle.
  36748. *
  36749. * @public
  36750. * @memberof Annotation
  36751. * @param {Array} rectangle - The rectangle array with exactly four entries
  36752. */
  36753. setRectangle: function Annotation_setRectangle(rectangle) {
  36754. if (isArray(rectangle) && rectangle.length === 4) {
  36755. this.rectangle = Util.normalizeRect(rectangle);
  36756. } else {
  36757. this.rectangle = [0, 0, 0, 0];
  36758. }
  36759. },
  36760. /**
  36761. * Set the color and take care of color space conversion.
  36762. *
  36763. * @public
  36764. * @memberof Annotation
  36765. * @param {Array} color - The color array containing either 0
  36766. * (transparent), 1 (grayscale), 3 (RGB) or
  36767. * 4 (CMYK) elements
  36768. */
  36769. setColor: function Annotation_setColor(color) {
  36770. var rgbColor = new Uint8Array(3); // Black in RGB color space (default)
  36771. if (!isArray(color)) {
  36772. this.color = rgbColor;
  36773. return;
  36774. }
  36775. switch (color.length) {
  36776. case 0: // Transparent, which we indicate with a null value
  36777. this.color = null;
  36778. break;
  36779. case 1: // Convert grayscale to RGB
  36780. ColorSpace.singletons.gray.getRgbItem(color, 0, rgbColor, 0);
  36781. this.color = rgbColor;
  36782. break;
  36783. case 3: // Convert RGB percentages to RGB
  36784. ColorSpace.singletons.rgb.getRgbItem(color, 0, rgbColor, 0);
  36785. this.color = rgbColor;
  36786. break;
  36787. case 4: // Convert CMYK to RGB
  36788. ColorSpace.singletons.cmyk.getRgbItem(color, 0, rgbColor, 0);
  36789. this.color = rgbColor;
  36790. break;
  36791. default:
  36792. this.color = rgbColor;
  36793. break;
  36794. }
  36795. },
  36796. /**
  36797. * Set the border style (as AnnotationBorderStyle object).
  36798. *
  36799. * @public
  36800. * @memberof Annotation
  36801. * @param {Dict} borderStyle - The border style dictionary
  36802. */
  36803. setBorderStyle: function Annotation_setBorderStyle(borderStyle) {
  36804. this.borderStyle = new AnnotationBorderStyle();
  36805. if (!isDict(borderStyle)) {
  36806. return;
  36807. }
  36808. if (borderStyle.has('BS')) {
  36809. var dict = borderStyle.get('BS');
  36810. var dictType;
  36811. if (!dict.has('Type') || (isName(dictType = dict.get('Type')) &&
  36812. dictType.name === 'Border')) {
  36813. this.borderStyle.setWidth(dict.get('W'));
  36814. this.borderStyle.setStyle(dict.get('S'));
  36815. this.borderStyle.setDashArray(dict.get('D'));
  36816. }
  36817. } else if (borderStyle.has('Border')) {
  36818. var array = borderStyle.get('Border');
  36819. if (isArray(array) && array.length >= 3) {
  36820. this.borderStyle.setHorizontalCornerRadius(array[0]);
  36821. this.borderStyle.setVerticalCornerRadius(array[1]);
  36822. this.borderStyle.setWidth(array[2]);
  36823. if (array.length === 4) { // Dash array available
  36824. this.borderStyle.setDashArray(array[3]);
  36825. }
  36826. }
  36827. } else {
  36828. // There are no border entries in the dictionary. According to the
  36829. // specification, we should draw a solid border of width 1 in that
  36830. // case, but Adobe Reader did not implement that part of the
  36831. // specification and instead draws no border at all, so we do the same.
  36832. // See also https://github.com/mozilla/pdf.js/issues/6179.
  36833. this.borderStyle.setWidth(0);
  36834. }
  36835. },
  36836. loadResources: function Annotation_loadResources(keys) {
  36837. return new Promise(function (resolve, reject) {
  36838. this.appearance.dict.getAsync('Resources').then(function (resources) {
  36839. if (!resources) {
  36840. resolve();
  36841. return;
  36842. }
  36843. var objectLoader = new ObjectLoader(resources.map,
  36844. keys,
  36845. resources.xref);
  36846. objectLoader.load().then(function() {
  36847. resolve(resources);
  36848. }, reject);
  36849. }, reject);
  36850. }.bind(this));
  36851. },
  36852. getOperatorList: function Annotation_getOperatorList(evaluator, task) {
  36853. if (!this.appearance) {
  36854. return Promise.resolve(new OperatorList());
  36855. }
  36856. var data = this.data;
  36857. var appearanceDict = this.appearance.dict;
  36858. var resourcesPromise = this.loadResources([
  36859. 'ExtGState',
  36860. 'ColorSpace',
  36861. 'Pattern',
  36862. 'Shading',
  36863. 'XObject',
  36864. 'Font'
  36865. // ProcSet
  36866. // Properties
  36867. ]);
  36868. var bbox = appearanceDict.get('BBox') || [0, 0, 1, 1];
  36869. var matrix = appearanceDict.get('Matrix') || [1, 0, 0, 1, 0 ,0];
  36870. var transform = getTransformMatrix(data.rect, bbox, matrix);
  36871. var self = this;
  36872. return resourcesPromise.then(function(resources) {
  36873. var opList = new OperatorList();
  36874. opList.addOp(OPS.beginAnnotation, [data.rect, transform, matrix]);
  36875. return evaluator.getOperatorList(self.appearance, task,
  36876. resources, opList).
  36877. then(function () {
  36878. opList.addOp(OPS.endAnnotation, []);
  36879. self.appearance.reset();
  36880. return opList;
  36881. });
  36882. });
  36883. }
  36884. };
  36885. Annotation.appendToOperatorList = function Annotation_appendToOperatorList(
  36886. annotations, opList, partialEvaluator, task, intent) {
  36887. var annotationPromises = [];
  36888. for (var i = 0, n = annotations.length; i < n; ++i) {
  36889. if ((intent === 'display' && annotations[i].viewable) ||
  36890. (intent === 'print' && annotations[i].printable)) {
  36891. annotationPromises.push(
  36892. annotations[i].getOperatorList(partialEvaluator, task));
  36893. }
  36894. }
  36895. return Promise.all(annotationPromises).then(function(operatorLists) {
  36896. opList.addOp(OPS.beginAnnotations, []);
  36897. for (var i = 0, n = operatorLists.length; i < n; ++i) {
  36898. opList.addOpList(operatorLists[i]);
  36899. }
  36900. opList.addOp(OPS.endAnnotations, []);
  36901. });
  36902. };
  36903. return Annotation;
  36904. })();
  36905. /**
  36906. * Contains all data regarding an annotation's border style.
  36907. *
  36908. * @class
  36909. */
  36910. var AnnotationBorderStyle = (function AnnotationBorderStyleClosure() {
  36911. /**
  36912. * @constructor
  36913. * @private
  36914. */
  36915. function AnnotationBorderStyle() {
  36916. this.width = 1;
  36917. this.style = AnnotationBorderStyleType.SOLID;
  36918. this.dashArray = [3];
  36919. this.horizontalCornerRadius = 0;
  36920. this.verticalCornerRadius = 0;
  36921. }
  36922. AnnotationBorderStyle.prototype = {
  36923. /**
  36924. * Set the width.
  36925. *
  36926. * @public
  36927. * @memberof AnnotationBorderStyle
  36928. * @param {integer} width - The width
  36929. */
  36930. setWidth: function AnnotationBorderStyle_setWidth(width) {
  36931. if (width === (width | 0)) {
  36932. this.width = width;
  36933. }
  36934. },
  36935. /**
  36936. * Set the style.
  36937. *
  36938. * @public
  36939. * @memberof AnnotationBorderStyle
  36940. * @param {Object} style - The style object
  36941. * @see {@link shared/util.js}
  36942. */
  36943. setStyle: function AnnotationBorderStyle_setStyle(style) {
  36944. if (!style) {
  36945. return;
  36946. }
  36947. switch (style.name) {
  36948. case 'S':
  36949. this.style = AnnotationBorderStyleType.SOLID;
  36950. break;
  36951. case 'D':
  36952. this.style = AnnotationBorderStyleType.DASHED;
  36953. break;
  36954. case 'B':
  36955. this.style = AnnotationBorderStyleType.BEVELED;
  36956. break;
  36957. case 'I':
  36958. this.style = AnnotationBorderStyleType.INSET;
  36959. break;
  36960. case 'U':
  36961. this.style = AnnotationBorderStyleType.UNDERLINE;
  36962. break;
  36963. default:
  36964. break;
  36965. }
  36966. },
  36967. /**
  36968. * Set the dash array.
  36969. *
  36970. * @public
  36971. * @memberof AnnotationBorderStyle
  36972. * @param {Array} dashArray - The dash array with at least one element
  36973. */
  36974. setDashArray: function AnnotationBorderStyle_setDashArray(dashArray) {
  36975. // We validate the dash array, but we do not use it because CSS does not
  36976. // allow us to change spacing of dashes. For more information, visit
  36977. // http://www.w3.org/TR/css3-background/#the-border-style.
  36978. if (isArray(dashArray) && dashArray.length > 0) {
  36979. // According to the PDF specification: the elements in a dashArray
  36980. // shall be numbers that are nonnegative and not all equal to zero.
  36981. var isValid = true;
  36982. var allZeros = true;
  36983. for (var i = 0, len = dashArray.length; i < len; i++) {
  36984. var element = dashArray[i];
  36985. var validNumber = (+element >= 0);
  36986. if (!validNumber) {
  36987. isValid = false;
  36988. break;
  36989. } else if (element > 0) {
  36990. allZeros = false;
  36991. }
  36992. }
  36993. if (isValid && !allZeros) {
  36994. this.dashArray = dashArray;
  36995. } else {
  36996. this.width = 0; // Adobe behavior when the array is invalid.
  36997. }
  36998. } else if (dashArray) {
  36999. this.width = 0; // Adobe behavior when the array is invalid.
  37000. }
  37001. },
  37002. /**
  37003. * Set the horizontal corner radius (from a Border dictionary).
  37004. *
  37005. * @public
  37006. * @memberof AnnotationBorderStyle
  37007. * @param {integer} radius - The horizontal corner radius
  37008. */
  37009. setHorizontalCornerRadius:
  37010. function AnnotationBorderStyle_setHorizontalCornerRadius(radius) {
  37011. if (radius === (radius | 0)) {
  37012. this.horizontalCornerRadius = radius;
  37013. }
  37014. },
  37015. /**
  37016. * Set the vertical corner radius (from a Border dictionary).
  37017. *
  37018. * @public
  37019. * @memberof AnnotationBorderStyle
  37020. * @param {integer} radius - The vertical corner radius
  37021. */
  37022. setVerticalCornerRadius:
  37023. function AnnotationBorderStyle_setVerticalCornerRadius(radius) {
  37024. if (radius === (radius | 0)) {
  37025. this.verticalCornerRadius = radius;
  37026. }
  37027. }
  37028. };
  37029. return AnnotationBorderStyle;
  37030. })();
  37031. var WidgetAnnotation = (function WidgetAnnotationClosure() {
  37032. function WidgetAnnotation(params) {
  37033. Annotation.call(this, params);
  37034. var dict = params.dict;
  37035. var data = this.data;
  37036. data.annotationType = AnnotationType.WIDGET;
  37037. data.fieldValue = stringToPDFString(
  37038. Util.getInheritableProperty(dict, 'V') || '');
  37039. data.alternativeText = stringToPDFString(dict.get('TU') || '');
  37040. data.defaultAppearance = Util.getInheritableProperty(dict, 'DA') || '';
  37041. var fieldType = Util.getInheritableProperty(dict, 'FT');
  37042. data.fieldType = isName(fieldType) ? fieldType.name : '';
  37043. data.fieldFlags = Util.getInheritableProperty(dict, 'Ff') || 0;
  37044. this.fieldResources = Util.getInheritableProperty(dict, 'DR') || Dict.empty;
  37045. // Hide unsupported Widget signatures.
  37046. if (data.fieldType === 'Sig') {
  37047. warn('unimplemented annotation type: Widget signature');
  37048. this.setFlags(AnnotationFlag.HIDDEN);
  37049. }
  37050. // Building the full field name by collecting the field and
  37051. // its ancestors 'T' data and joining them using '.'.
  37052. var fieldName = [];
  37053. var namedItem = dict;
  37054. var ref = params.ref;
  37055. while (namedItem) {
  37056. var parent = namedItem.get('Parent');
  37057. var parentRef = namedItem.getRaw('Parent');
  37058. var name = namedItem.get('T');
  37059. if (name) {
  37060. fieldName.unshift(stringToPDFString(name));
  37061. } else if (parent && ref) {
  37062. // The field name is absent, that means more than one field
  37063. // with the same name may exist. Replacing the empty name
  37064. // with the '`' plus index in the parent's 'Kids' array.
  37065. // This is not in the PDF spec but necessary to id the
  37066. // the input controls.
  37067. var kids = parent.get('Kids');
  37068. var j, jj;
  37069. for (j = 0, jj = kids.length; j < jj; j++) {
  37070. var kidRef = kids[j];
  37071. if (kidRef.num === ref.num && kidRef.gen === ref.gen) {
  37072. break;
  37073. }
  37074. }
  37075. fieldName.unshift('`' + j);
  37076. }
  37077. namedItem = parent;
  37078. ref = parentRef;
  37079. }
  37080. data.fullName = fieldName.join('.');
  37081. }
  37082. Util.inherit(WidgetAnnotation, Annotation, {});
  37083. return WidgetAnnotation;
  37084. })();
  37085. var TextWidgetAnnotation = (function TextWidgetAnnotationClosure() {
  37086. function TextWidgetAnnotation(params) {
  37087. WidgetAnnotation.call(this, params);
  37088. this.data.textAlignment = Util.getInheritableProperty(params.dict, 'Q');
  37089. this.data.hasHtml = !this.data.hasAppearance && !!this.data.fieldValue;
  37090. }
  37091. Util.inherit(TextWidgetAnnotation, WidgetAnnotation, {
  37092. getOperatorList: function TextWidgetAnnotation_getOperatorList(evaluator,
  37093. task) {
  37094. if (this.appearance) {
  37095. return Annotation.prototype.getOperatorList.call(this, evaluator, task);
  37096. }
  37097. var opList = new OperatorList();
  37098. var data = this.data;
  37099. // Even if there is an appearance stream, ignore it. This is the
  37100. // behaviour used by Adobe Reader.
  37101. if (!data.defaultAppearance) {
  37102. return Promise.resolve(opList);
  37103. }
  37104. var stream = new Stream(stringToBytes(data.defaultAppearance));
  37105. return evaluator.getOperatorList(stream, task,
  37106. this.fieldResources, opList).
  37107. then(function () {
  37108. return opList;
  37109. });
  37110. }
  37111. });
  37112. return TextWidgetAnnotation;
  37113. })();
  37114. var TextAnnotation = (function TextAnnotationClosure() {
  37115. var DEFAULT_ICON_SIZE = 22; // px
  37116. function TextAnnotation(parameters) {
  37117. Annotation.call(this, parameters);
  37118. this.data.annotationType = AnnotationType.TEXT;
  37119. this.data.hasHtml = true;
  37120. var dict = parameters.dict;
  37121. if (this.data.hasAppearance) {
  37122. this.data.name = 'NoIcon';
  37123. } else {
  37124. this.data.rect[1] = this.data.rect[3] - DEFAULT_ICON_SIZE;
  37125. this.data.rect[2] = this.data.rect[0] + DEFAULT_ICON_SIZE;
  37126. this.data.name = dict.has('Name') ? dict.get('Name').name : 'Note';
  37127. }
  37128. if (!dict.has('C')) {
  37129. // Fall back to the default background color.
  37130. this.data.color = null;
  37131. }
  37132. this.data.hasPopup = dict.has('Popup');
  37133. if (!this.data.hasPopup) {
  37134. // There is no associated Popup annotation, so the Text annotation
  37135. // must create its own popup.
  37136. this.data.title = stringToPDFString(dict.get('T') || '');
  37137. this.data.contents = stringToPDFString(dict.get('Contents') || '');
  37138. this.data.hasHtml = (this.data.title || this.data.contents);
  37139. }
  37140. }
  37141. Util.inherit(TextAnnotation, Annotation, {});
  37142. return TextAnnotation;
  37143. })();
  37144. var LinkAnnotation = (function LinkAnnotationClosure() {
  37145. function LinkAnnotation(params) {
  37146. Annotation.call(this, params);
  37147. var dict = params.dict;
  37148. var data = this.data;
  37149. data.annotationType = AnnotationType.LINK;
  37150. data.hasHtml = true;
  37151. var action = dict.get('A');
  37152. if (action && isDict(action)) {
  37153. var linkType = action.get('S').name;
  37154. if (linkType === 'URI') {
  37155. var url = action.get('URI');
  37156. if (isName(url)) {
  37157. // Some bad PDFs do not put parentheses around relative URLs.
  37158. url = '/' + url.name;
  37159. } else if (url) {
  37160. url = addDefaultProtocolToUrl(url);
  37161. }
  37162. // TODO: pdf spec mentions urls can be relative to a Base
  37163. // entry in the dictionary.
  37164. if (!isValidUrl(url, false)) {
  37165. url = '';
  37166. }
  37167. // According to ISO 32000-1:2008, section 12.6.4.7,
  37168. // URI should to be encoded in 7-bit ASCII.
  37169. // Some bad PDFs may have URIs in UTF-8 encoding, see Bugzilla 1122280.
  37170. try {
  37171. data.url = stringToUTF8String(url);
  37172. } catch (e) {
  37173. // Fall back to a simple copy.
  37174. data.url = url;
  37175. }
  37176. } else if (linkType === 'GoTo') {
  37177. data.dest = action.get('D');
  37178. } else if (linkType === 'GoToR') {
  37179. var urlDict = action.get('F');
  37180. if (isDict(urlDict)) {
  37181. // We assume that the 'url' is a Filspec dictionary
  37182. // and fetch the url without checking any further
  37183. url = urlDict.get('F') || '';
  37184. }
  37185. // TODO: pdf reference says that GoToR
  37186. // can also have 'NewWindow' attribute
  37187. if (!isValidUrl(url, false)) {
  37188. url = '';
  37189. }
  37190. data.url = url;
  37191. data.dest = action.get('D');
  37192. } else if (linkType === 'Named') {
  37193. data.action = action.get('N').name;
  37194. } else {
  37195. warn('unrecognized link type: ' + linkType);
  37196. }
  37197. } else if (dict.has('Dest')) {
  37198. // simple destination link
  37199. var dest = dict.get('Dest');
  37200. data.dest = isName(dest) ? dest.name : dest;
  37201. }
  37202. }
  37203. // Lets URLs beginning with 'www.' default to using the 'http://' protocol.
  37204. function addDefaultProtocolToUrl(url) {
  37205. if (url && url.indexOf('www.') === 0) {
  37206. return ('http://' + url);
  37207. }
  37208. return url;
  37209. }
  37210. Util.inherit(LinkAnnotation, Annotation, {});
  37211. return LinkAnnotation;
  37212. })();
  37213. var PopupAnnotation = (function PopupAnnotationClosure() {
  37214. function PopupAnnotation(parameters) {
  37215. Annotation.call(this, parameters);
  37216. this.data.annotationType = AnnotationType.POPUP;
  37217. var dict = parameters.dict;
  37218. var parentItem = dict.get('Parent');
  37219. if (!parentItem) {
  37220. warn('Popup annotation has a missing or invalid parent annotation.');
  37221. return;
  37222. }
  37223. this.data.parentId = dict.getRaw('Parent').toString();
  37224. this.data.title = stringToPDFString(parentItem.get('T') || '');
  37225. this.data.contents = stringToPDFString(parentItem.get('Contents') || '');
  37226. if (!parentItem.has('C')) {
  37227. // Fall back to the default background color.
  37228. this.data.color = null;
  37229. } else {
  37230. this.setColor(parentItem.get('C'));
  37231. this.data.color = this.color;
  37232. }
  37233. this.data.hasHtml = (this.data.title || this.data.contents);
  37234. }
  37235. Util.inherit(PopupAnnotation, Annotation, {});
  37236. return PopupAnnotation;
  37237. })();
  37238. var HighlightAnnotation = (function HighlightAnnotationClosure() {
  37239. function HighlightAnnotation(parameters) {
  37240. Annotation.call(this, parameters);
  37241. this.data.annotationType = AnnotationType.HIGHLIGHT;
  37242. this.data.hasHtml = true;
  37243. // PDF viewers completely ignore any border styles.
  37244. this.data.borderStyle.setWidth(0);
  37245. }
  37246. Util.inherit(HighlightAnnotation, Annotation, {});
  37247. return HighlightAnnotation;
  37248. })();
  37249. var UnderlineAnnotation = (function UnderlineAnnotationClosure() {
  37250. function UnderlineAnnotation(parameters) {
  37251. Annotation.call(this, parameters);
  37252. this.data.annotationType = AnnotationType.UNDERLINE;
  37253. this.data.hasHtml = true;
  37254. // PDF viewers completely ignore any border styles.
  37255. this.data.borderStyle.setWidth(0);
  37256. }
  37257. Util.inherit(UnderlineAnnotation, Annotation, {});
  37258. return UnderlineAnnotation;
  37259. })();
  37260. var SquigglyAnnotation = (function SquigglyAnnotationClosure() {
  37261. function SquigglyAnnotation(parameters) {
  37262. Annotation.call(this, parameters);
  37263. this.data.annotationType = AnnotationType.SQUIGGLY;
  37264. this.data.hasHtml = true;
  37265. // PDF viewers completely ignore any border styles.
  37266. this.data.borderStyle.setWidth(0);
  37267. }
  37268. Util.inherit(SquigglyAnnotation, Annotation, {});
  37269. return SquigglyAnnotation;
  37270. })();
  37271. var StrikeOutAnnotation = (function StrikeOutAnnotationClosure() {
  37272. function StrikeOutAnnotation(parameters) {
  37273. Annotation.call(this, parameters);
  37274. this.data.annotationType = AnnotationType.STRIKEOUT;
  37275. this.data.hasHtml = true;
  37276. // PDF viewers completely ignore any border styles.
  37277. this.data.borderStyle.setWidth(0);
  37278. }
  37279. Util.inherit(StrikeOutAnnotation, Annotation, {});
  37280. return StrikeOutAnnotation;
  37281. })();
  37282. exports.Annotation = Annotation;
  37283. exports.AnnotationBorderStyle = AnnotationBorderStyle;
  37284. exports.AnnotationFactory = AnnotationFactory;
  37285. }));
  37286. (function (root, factory) {
  37287. {
  37288. factory((root.pdfjsCoreDocument = {}), root.pdfjsSharedUtil,
  37289. root.pdfjsCorePrimitives, root.pdfjsCoreStream,
  37290. root.pdfjsCoreObj, root.pdfjsCoreParser, root.pdfjsCoreCrypto,
  37291. root.pdfjsCoreEvaluator, root.pdfjsCoreAnnotation);
  37292. }
  37293. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreObj,
  37294. coreParser, coreCrypto, coreEvaluator, coreAnnotation) {
  37295. var MissingDataException = sharedUtil.MissingDataException;
  37296. var Util = sharedUtil.Util;
  37297. var assert = sharedUtil.assert;
  37298. var error = sharedUtil.error;
  37299. var info = sharedUtil.info;
  37300. var isArray = sharedUtil.isArray;
  37301. var isArrayBuffer = sharedUtil.isArrayBuffer;
  37302. var isString = sharedUtil.isString;
  37303. var shadow = sharedUtil.shadow;
  37304. var stringToBytes = sharedUtil.stringToBytes;
  37305. var stringToPDFString = sharedUtil.stringToPDFString;
  37306. var warn = sharedUtil.warn;
  37307. var Dict = corePrimitives.Dict;
  37308. var isDict = corePrimitives.isDict;
  37309. var isName = corePrimitives.isName;
  37310. var isStream = corePrimitives.isStream;
  37311. var NullStream = coreStream.NullStream;
  37312. var Stream = coreStream.Stream;
  37313. var StreamsSequenceStream = coreStream.StreamsSequenceStream;
  37314. var Catalog = coreObj.Catalog;
  37315. var ObjectLoader = coreObj.ObjectLoader;
  37316. var XRef = coreObj.XRef;
  37317. var Lexer = coreParser.Lexer;
  37318. var Linearization = coreParser.Linearization;
  37319. var calculateMD5 = coreCrypto.calculateMD5;
  37320. var OperatorList = coreEvaluator.OperatorList;
  37321. var PartialEvaluator = coreEvaluator.PartialEvaluator;
  37322. var Annotation = coreAnnotation.Annotation;
  37323. var AnnotationFactory = coreAnnotation.AnnotationFactory;
  37324. var Page = (function PageClosure() {
  37325. var LETTER_SIZE_MEDIABOX = [0, 0, 612, 792];
  37326. function Page(pdfManager, xref, pageIndex, pageDict, ref, fontCache) {
  37327. this.pdfManager = pdfManager;
  37328. this.pageIndex = pageIndex;
  37329. this.pageDict = pageDict;
  37330. this.xref = xref;
  37331. this.ref = ref;
  37332. this.fontCache = fontCache;
  37333. this.idCounters = {
  37334. obj: 0
  37335. };
  37336. this.resourcesPromise = null;
  37337. }
  37338. Page.prototype = {
  37339. getPageProp: function Page_getPageProp(key) {
  37340. return this.pageDict.get(key);
  37341. },
  37342. getInheritedPageProp: function Page_getInheritedPageProp(key) {
  37343. var dict = this.pageDict, valueArray = null, loopCount = 0;
  37344. var MAX_LOOP_COUNT = 100;
  37345. // Always walk up the entire parent chain, to be able to find
  37346. // e.g. \Resources placed on multiple levels of the tree.
  37347. while (dict) {
  37348. var value = dict.get(key);
  37349. if (value) {
  37350. if (!valueArray) {
  37351. valueArray = [];
  37352. }
  37353. valueArray.push(value);
  37354. }
  37355. if (++loopCount > MAX_LOOP_COUNT) {
  37356. warn('Page_getInheritedPageProp: maximum loop count exceeded.');
  37357. break;
  37358. }
  37359. dict = dict.get('Parent');
  37360. }
  37361. if (!valueArray) {
  37362. return Dict.empty;
  37363. }
  37364. if (valueArray.length === 1 || !isDict(valueArray[0]) ||
  37365. loopCount > MAX_LOOP_COUNT) {
  37366. return valueArray[0];
  37367. }
  37368. return Dict.merge(this.xref, valueArray);
  37369. },
  37370. get content() {
  37371. return this.getPageProp('Contents');
  37372. },
  37373. get resources() {
  37374. // For robustness: The spec states that a \Resources entry has to be
  37375. // present, but can be empty. Some document omit it still, in this case
  37376. // we return an empty dictionary.
  37377. return shadow(this, 'resources', this.getInheritedPageProp('Resources'));
  37378. },
  37379. get mediaBox() {
  37380. var obj = this.getInheritedPageProp('MediaBox');
  37381. // Reset invalid media box to letter size.
  37382. if (!isArray(obj) || obj.length !== 4) {
  37383. obj = LETTER_SIZE_MEDIABOX;
  37384. }
  37385. return shadow(this, 'mediaBox', obj);
  37386. },
  37387. get view() {
  37388. var mediaBox = this.mediaBox;
  37389. var cropBox = this.getInheritedPageProp('CropBox');
  37390. if (!isArray(cropBox) || cropBox.length !== 4) {
  37391. return shadow(this, 'view', mediaBox);
  37392. }
  37393. // From the spec, 6th ed., p.963:
  37394. // "The crop, bleed, trim, and art boxes should not ordinarily
  37395. // extend beyond the boundaries of the media box. If they do, they are
  37396. // effectively reduced to their intersection with the media box."
  37397. cropBox = Util.intersect(cropBox, mediaBox);
  37398. if (!cropBox) {
  37399. return shadow(this, 'view', mediaBox);
  37400. }
  37401. return shadow(this, 'view', cropBox);
  37402. },
  37403. get rotate() {
  37404. var rotate = this.getInheritedPageProp('Rotate') || 0;
  37405. // Normalize rotation so it's a multiple of 90 and between 0 and 270
  37406. if (rotate % 90 !== 0) {
  37407. rotate = 0;
  37408. } else if (rotate >= 360) {
  37409. rotate = rotate % 360;
  37410. } else if (rotate < 0) {
  37411. // The spec doesn't cover negatives, assume its counterclockwise
  37412. // rotation. The following is the other implementation of modulo.
  37413. rotate = ((rotate % 360) + 360) % 360;
  37414. }
  37415. return shadow(this, 'rotate', rotate);
  37416. },
  37417. getContentStream: function Page_getContentStream() {
  37418. var content = this.content;
  37419. var stream;
  37420. if (isArray(content)) {
  37421. // fetching items
  37422. var xref = this.xref;
  37423. var i, n = content.length;
  37424. var streams = [];
  37425. for (i = 0; i < n; ++i) {
  37426. streams.push(xref.fetchIfRef(content[i]));
  37427. }
  37428. stream = new StreamsSequenceStream(streams);
  37429. } else if (isStream(content)) {
  37430. stream = content;
  37431. } else {
  37432. // replacing non-existent page content with empty one
  37433. stream = new NullStream();
  37434. }
  37435. return stream;
  37436. },
  37437. loadResources: function Page_loadResources(keys) {
  37438. if (!this.resourcesPromise) {
  37439. // TODO: add async getInheritedPageProp and remove this.
  37440. this.resourcesPromise = this.pdfManager.ensure(this, 'resources');
  37441. }
  37442. return this.resourcesPromise.then(function resourceSuccess() {
  37443. var objectLoader = new ObjectLoader(this.resources.map,
  37444. keys,
  37445. this.xref);
  37446. return objectLoader.load();
  37447. }.bind(this));
  37448. },
  37449. getOperatorList: function Page_getOperatorList(handler, task, intent) {
  37450. var self = this;
  37451. var pdfManager = this.pdfManager;
  37452. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  37453. []);
  37454. var resourcesPromise = this.loadResources([
  37455. 'ExtGState',
  37456. 'ColorSpace',
  37457. 'Pattern',
  37458. 'Shading',
  37459. 'XObject',
  37460. 'Font'
  37461. // ProcSet
  37462. // Properties
  37463. ]);
  37464. var partialEvaluator = new PartialEvaluator(pdfManager, this.xref,
  37465. handler, this.pageIndex,
  37466. 'p' + this.pageIndex + '_',
  37467. this.idCounters,
  37468. this.fontCache);
  37469. var dataPromises = Promise.all([contentStreamPromise, resourcesPromise]);
  37470. var pageListPromise = dataPromises.then(function(data) {
  37471. var contentStream = data[0];
  37472. var opList = new OperatorList(intent, handler, self.pageIndex);
  37473. handler.send('StartRenderPage', {
  37474. transparency: partialEvaluator.hasBlendModes(self.resources),
  37475. pageIndex: self.pageIndex,
  37476. intent: intent
  37477. });
  37478. return partialEvaluator.getOperatorList(contentStream, task,
  37479. self.resources, opList).then(function () {
  37480. return opList;
  37481. });
  37482. });
  37483. var annotationsPromise = pdfManager.ensure(this, 'annotations');
  37484. return Promise.all([pageListPromise, annotationsPromise]).then(
  37485. function(datas) {
  37486. var pageOpList = datas[0];
  37487. var annotations = datas[1];
  37488. if (annotations.length === 0) {
  37489. pageOpList.flush(true);
  37490. return pageOpList;
  37491. }
  37492. var annotationsReadyPromise = Annotation.appendToOperatorList(
  37493. annotations, pageOpList, partialEvaluator, task, intent);
  37494. return annotationsReadyPromise.then(function () {
  37495. pageOpList.flush(true);
  37496. return pageOpList;
  37497. });
  37498. });
  37499. },
  37500. extractTextContent: function Page_extractTextContent(task,
  37501. normalizeWhitespace) {
  37502. var handler = {
  37503. on: function nullHandlerOn() {},
  37504. send: function nullHandlerSend() {}
  37505. };
  37506. var self = this;
  37507. var pdfManager = this.pdfManager;
  37508. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  37509. []);
  37510. var resourcesPromise = this.loadResources([
  37511. 'ExtGState',
  37512. 'XObject',
  37513. 'Font'
  37514. ]);
  37515. var dataPromises = Promise.all([contentStreamPromise,
  37516. resourcesPromise]);
  37517. return dataPromises.then(function(data) {
  37518. var contentStream = data[0];
  37519. var partialEvaluator = new PartialEvaluator(pdfManager, self.xref,
  37520. handler, self.pageIndex,
  37521. 'p' + self.pageIndex + '_',
  37522. self.idCounters,
  37523. self.fontCache);
  37524. return partialEvaluator.getTextContent(contentStream,
  37525. task,
  37526. self.resources,
  37527. /* stateManager = */ null,
  37528. normalizeWhitespace);
  37529. });
  37530. },
  37531. getAnnotationsData: function Page_getAnnotationsData(intent) {
  37532. var annotations = this.annotations;
  37533. var annotationsData = [];
  37534. for (var i = 0, n = annotations.length; i < n; ++i) {
  37535. if (intent) {
  37536. if (!(intent === 'display' && annotations[i].viewable) &&
  37537. !(intent === 'print' && annotations[i].printable)) {
  37538. continue;
  37539. }
  37540. }
  37541. annotationsData.push(annotations[i].data);
  37542. }
  37543. return annotationsData;
  37544. },
  37545. get annotations() {
  37546. var annotations = [];
  37547. var annotationRefs = this.getInheritedPageProp('Annots') || [];
  37548. var annotationFactory = new AnnotationFactory();
  37549. for (var i = 0, n = annotationRefs.length; i < n; ++i) {
  37550. var annotationRef = annotationRefs[i];
  37551. var annotation = annotationFactory.create(this.xref, annotationRef);
  37552. if (annotation) {
  37553. annotations.push(annotation);
  37554. }
  37555. }
  37556. return shadow(this, 'annotations', annotations);
  37557. }
  37558. };
  37559. return Page;
  37560. })();
  37561. /**
  37562. * The `PDFDocument` holds all the data of the PDF file. Compared to the
  37563. * `PDFDoc`, this one doesn't have any job management code.
  37564. * Right now there exists one PDFDocument on the main thread + one object
  37565. * for each worker. If there is no worker support enabled, there are two
  37566. * `PDFDocument` objects on the main thread created.
  37567. */
  37568. var PDFDocument = (function PDFDocumentClosure() {
  37569. var FINGERPRINT_FIRST_BYTES = 1024;
  37570. var EMPTY_FINGERPRINT = '\x00\x00\x00\x00\x00\x00\x00' +
  37571. '\x00\x00\x00\x00\x00\x00\x00\x00\x00';
  37572. function PDFDocument(pdfManager, arg, password) {
  37573. if (isStream(arg)) {
  37574. init.call(this, pdfManager, arg, password);
  37575. } else if (isArrayBuffer(arg)) {
  37576. init.call(this, pdfManager, new Stream(arg), password);
  37577. } else {
  37578. error('PDFDocument: Unknown argument type');
  37579. }
  37580. }
  37581. function init(pdfManager, stream, password) {
  37582. assert(stream.length > 0, 'stream must have data');
  37583. this.pdfManager = pdfManager;
  37584. this.stream = stream;
  37585. var xref = new XRef(this.stream, password, pdfManager);
  37586. this.xref = xref;
  37587. }
  37588. function find(stream, needle, limit, backwards) {
  37589. var pos = stream.pos;
  37590. var end = stream.end;
  37591. var strBuf = [];
  37592. if (pos + limit > end) {
  37593. limit = end - pos;
  37594. }
  37595. for (var n = 0; n < limit; ++n) {
  37596. strBuf.push(String.fromCharCode(stream.getByte()));
  37597. }
  37598. var str = strBuf.join('');
  37599. stream.pos = pos;
  37600. var index = backwards ? str.lastIndexOf(needle) : str.indexOf(needle);
  37601. if (index === -1) {
  37602. return false; /* not found */
  37603. }
  37604. stream.pos += index;
  37605. return true; /* found */
  37606. }
  37607. var DocumentInfoValidators = {
  37608. get entries() {
  37609. // Lazily build this since all the validation functions below are not
  37610. // defined until after this file loads.
  37611. return shadow(this, 'entries', {
  37612. Title: isString,
  37613. Author: isString,
  37614. Subject: isString,
  37615. Keywords: isString,
  37616. Creator: isString,
  37617. Producer: isString,
  37618. CreationDate: isString,
  37619. ModDate: isString,
  37620. Trapped: isName
  37621. });
  37622. }
  37623. };
  37624. PDFDocument.prototype = {
  37625. parse: function PDFDocument_parse(recoveryMode) {
  37626. this.setup(recoveryMode);
  37627. var version = this.catalog.catDict.get('Version');
  37628. if (isName(version)) {
  37629. this.pdfFormatVersion = version.name;
  37630. }
  37631. try {
  37632. // checking if AcroForm is present
  37633. this.acroForm = this.catalog.catDict.get('AcroForm');
  37634. if (this.acroForm) {
  37635. this.xfa = this.acroForm.get('XFA');
  37636. var fields = this.acroForm.get('Fields');
  37637. if ((!fields || !isArray(fields) || fields.length === 0) &&
  37638. !this.xfa) {
  37639. // no fields and no XFA -- not a form (?)
  37640. this.acroForm = null;
  37641. }
  37642. }
  37643. } catch (ex) {
  37644. info('Something wrong with AcroForm entry');
  37645. this.acroForm = null;
  37646. }
  37647. },
  37648. get linearization() {
  37649. var linearization = null;
  37650. if (this.stream.length) {
  37651. try {
  37652. linearization = Linearization.create(this.stream);
  37653. } catch (err) {
  37654. if (err instanceof MissingDataException) {
  37655. throw err;
  37656. }
  37657. info(err);
  37658. }
  37659. }
  37660. // shadow the prototype getter with a data property
  37661. return shadow(this, 'linearization', linearization);
  37662. },
  37663. get startXRef() {
  37664. var stream = this.stream;
  37665. var startXRef = 0;
  37666. var linearization = this.linearization;
  37667. if (linearization) {
  37668. // Find end of first obj.
  37669. stream.reset();
  37670. if (find(stream, 'endobj', 1024)) {
  37671. startXRef = stream.pos + 6;
  37672. }
  37673. } else {
  37674. // Find startxref by jumping backward from the end of the file.
  37675. var step = 1024;
  37676. var found = false, pos = stream.end;
  37677. while (!found && pos > 0) {
  37678. pos -= step - 'startxref'.length;
  37679. if (pos < 0) {
  37680. pos = 0;
  37681. }
  37682. stream.pos = pos;
  37683. found = find(stream, 'startxref', step, true);
  37684. }
  37685. if (found) {
  37686. stream.skip(9);
  37687. var ch;
  37688. do {
  37689. ch = stream.getByte();
  37690. } while (Lexer.isSpace(ch));
  37691. var str = '';
  37692. while (ch >= 0x20 && ch <= 0x39) { // < '9'
  37693. str += String.fromCharCode(ch);
  37694. ch = stream.getByte();
  37695. }
  37696. startXRef = parseInt(str, 10);
  37697. if (isNaN(startXRef)) {
  37698. startXRef = 0;
  37699. }
  37700. }
  37701. }
  37702. // shadow the prototype getter with a data property
  37703. return shadow(this, 'startXRef', startXRef);
  37704. },
  37705. get mainXRefEntriesOffset() {
  37706. var mainXRefEntriesOffset = 0;
  37707. var linearization = this.linearization;
  37708. if (linearization) {
  37709. mainXRefEntriesOffset = linearization.mainXRefEntriesOffset;
  37710. }
  37711. // shadow the prototype getter with a data property
  37712. return shadow(this, 'mainXRefEntriesOffset', mainXRefEntriesOffset);
  37713. },
  37714. // Find the header, remove leading garbage and setup the stream
  37715. // starting from the header.
  37716. checkHeader: function PDFDocument_checkHeader() {
  37717. var stream = this.stream;
  37718. stream.reset();
  37719. if (find(stream, '%PDF-', 1024)) {
  37720. // Found the header, trim off any garbage before it.
  37721. stream.moveStart();
  37722. // Reading file format version
  37723. var MAX_VERSION_LENGTH = 12;
  37724. var version = '', ch;
  37725. while ((ch = stream.getByte()) > 0x20) { // SPACE
  37726. if (version.length >= MAX_VERSION_LENGTH) {
  37727. break;
  37728. }
  37729. version += String.fromCharCode(ch);
  37730. }
  37731. if (!this.pdfFormatVersion) {
  37732. // removing "%PDF-"-prefix
  37733. this.pdfFormatVersion = version.substring(5);
  37734. }
  37735. return;
  37736. }
  37737. // May not be a PDF file, continue anyway.
  37738. },
  37739. parseStartXRef: function PDFDocument_parseStartXRef() {
  37740. var startXRef = this.startXRef;
  37741. this.xref.setStartXRef(startXRef);
  37742. },
  37743. setup: function PDFDocument_setup(recoveryMode) {
  37744. this.xref.parse(recoveryMode);
  37745. var self = this;
  37746. var pageFactory = {
  37747. createPage: function (pageIndex, dict, ref, fontCache) {
  37748. return new Page(self.pdfManager, self.xref, pageIndex, dict, ref,
  37749. fontCache);
  37750. }
  37751. };
  37752. this.catalog = new Catalog(this.pdfManager, this.xref, pageFactory);
  37753. },
  37754. get numPages() {
  37755. var linearization = this.linearization;
  37756. var num = linearization ? linearization.numPages : this.catalog.numPages;
  37757. // shadow the prototype getter
  37758. return shadow(this, 'numPages', num);
  37759. },
  37760. get documentInfo() {
  37761. var docInfo = {
  37762. PDFFormatVersion: this.pdfFormatVersion,
  37763. IsAcroFormPresent: !!this.acroForm,
  37764. IsXFAPresent: !!this.xfa
  37765. };
  37766. var infoDict;
  37767. try {
  37768. infoDict = this.xref.trailer.get('Info');
  37769. } catch (err) {
  37770. info('The document information dictionary is invalid.');
  37771. }
  37772. if (infoDict) {
  37773. var validEntries = DocumentInfoValidators.entries;
  37774. // Only fill the document info with valid entries from the spec.
  37775. for (var key in validEntries) {
  37776. if (infoDict.has(key)) {
  37777. var value = infoDict.get(key);
  37778. // Make sure the value conforms to the spec.
  37779. if (validEntries[key](value)) {
  37780. docInfo[key] = (typeof value !== 'string' ?
  37781. value : stringToPDFString(value));
  37782. } else {
  37783. info('Bad value in document info for "' + key + '"');
  37784. }
  37785. }
  37786. }
  37787. }
  37788. return shadow(this, 'documentInfo', docInfo);
  37789. },
  37790. get fingerprint() {
  37791. var xref = this.xref, hash, fileID = '';
  37792. var idArray = xref.trailer.get('ID');
  37793. if (idArray && isArray(idArray) && idArray[0] && isString(idArray[0]) &&
  37794. idArray[0] !== EMPTY_FINGERPRINT) {
  37795. hash = stringToBytes(idArray[0]);
  37796. } else {
  37797. if (this.stream.ensureRange) {
  37798. this.stream.ensureRange(0,
  37799. Math.min(FINGERPRINT_FIRST_BYTES, this.stream.end));
  37800. }
  37801. hash = calculateMD5(this.stream.bytes.subarray(0,
  37802. FINGERPRINT_FIRST_BYTES), 0, FINGERPRINT_FIRST_BYTES);
  37803. }
  37804. for (var i = 0, n = hash.length; i < n; i++) {
  37805. var hex = hash[i].toString(16);
  37806. fileID += hex.length === 1 ? '0' + hex : hex;
  37807. }
  37808. return shadow(this, 'fingerprint', fileID);
  37809. },
  37810. getPage: function PDFDocument_getPage(pageIndex) {
  37811. return this.catalog.getPage(pageIndex);
  37812. },
  37813. cleanup: function PDFDocument_cleanup() {
  37814. return this.catalog.cleanup();
  37815. }
  37816. };
  37817. return PDFDocument;
  37818. })();
  37819. exports.Page = Page;
  37820. exports.PDFDocument = PDFDocument;
  37821. }));
  37822. (function (root, factory) {
  37823. {
  37824. factory((root.pdfjsCorePdfManager = {}), root.pdfjsSharedUtil,
  37825. root.pdfjsCoreStream, root.pdfjsCoreChunkedStream,
  37826. root.pdfjsCoreDocument);
  37827. }
  37828. }(this, function (exports, sharedUtil, coreStream, coreChunkedStream,
  37829. coreDocument) {
  37830. var NotImplementedException = sharedUtil.NotImplementedException;
  37831. var MissingDataException = sharedUtil.MissingDataException;
  37832. var createPromiseCapability = sharedUtil.createPromiseCapability;
  37833. var Util = sharedUtil.Util;
  37834. var Stream = coreStream.Stream;
  37835. var ChunkedStreamManager = coreChunkedStream.ChunkedStreamManager;
  37836. var PDFDocument = coreDocument.PDFDocument;
  37837. var BasePdfManager = (function BasePdfManagerClosure() {
  37838. function BasePdfManager() {
  37839. throw new Error('Cannot initialize BaseManagerManager');
  37840. }
  37841. BasePdfManager.prototype = {
  37842. get docId() {
  37843. return this._docId;
  37844. },
  37845. onLoadedStream: function BasePdfManager_onLoadedStream() {
  37846. throw new NotImplementedException();
  37847. },
  37848. ensureDoc: function BasePdfManager_ensureDoc(prop, args) {
  37849. return this.ensure(this.pdfDocument, prop, args);
  37850. },
  37851. ensureXRef: function BasePdfManager_ensureXRef(prop, args) {
  37852. return this.ensure(this.pdfDocument.xref, prop, args);
  37853. },
  37854. ensureCatalog: function BasePdfManager_ensureCatalog(prop, args) {
  37855. return this.ensure(this.pdfDocument.catalog, prop, args);
  37856. },
  37857. getPage: function BasePdfManager_getPage(pageIndex) {
  37858. return this.pdfDocument.getPage(pageIndex);
  37859. },
  37860. cleanup: function BasePdfManager_cleanup() {
  37861. return this.pdfDocument.cleanup();
  37862. },
  37863. ensure: function BasePdfManager_ensure(obj, prop, args) {
  37864. return new NotImplementedException();
  37865. },
  37866. requestRange: function BasePdfManager_requestRange(begin, end) {
  37867. return new NotImplementedException();
  37868. },
  37869. requestLoadedStream: function BasePdfManager_requestLoadedStream() {
  37870. return new NotImplementedException();
  37871. },
  37872. sendProgressiveData: function BasePdfManager_sendProgressiveData(chunk) {
  37873. return new NotImplementedException();
  37874. },
  37875. updatePassword: function BasePdfManager_updatePassword(password) {
  37876. this.pdfDocument.xref.password = this.password = password;
  37877. if (this._passwordChangedCapability) {
  37878. this._passwordChangedCapability.resolve();
  37879. }
  37880. },
  37881. passwordChanged: function BasePdfManager_passwordChanged() {
  37882. this._passwordChangedCapability = createPromiseCapability();
  37883. return this._passwordChangedCapability.promise;
  37884. },
  37885. terminate: function BasePdfManager_terminate() {
  37886. return new NotImplementedException();
  37887. }
  37888. };
  37889. return BasePdfManager;
  37890. })();
  37891. var LocalPdfManager = (function LocalPdfManagerClosure() {
  37892. function LocalPdfManager(docId, data, password) {
  37893. this._docId = docId;
  37894. var stream = new Stream(data);
  37895. this.pdfDocument = new PDFDocument(this, stream, password);
  37896. this._loadedStreamCapability = createPromiseCapability();
  37897. this._loadedStreamCapability.resolve(stream);
  37898. }
  37899. Util.inherit(LocalPdfManager, BasePdfManager, {
  37900. ensure: function LocalPdfManager_ensure(obj, prop, args) {
  37901. return new Promise(function (resolve, reject) {
  37902. try {
  37903. var value = obj[prop];
  37904. var result;
  37905. if (typeof value === 'function') {
  37906. result = value.apply(obj, args);
  37907. } else {
  37908. result = value;
  37909. }
  37910. resolve(result);
  37911. } catch (e) {
  37912. reject(e);
  37913. }
  37914. });
  37915. },
  37916. requestRange: function LocalPdfManager_requestRange(begin, end) {
  37917. return Promise.resolve();
  37918. },
  37919. requestLoadedStream: function LocalPdfManager_requestLoadedStream() {
  37920. return;
  37921. },
  37922. onLoadedStream: function LocalPdfManager_onLoadedStream() {
  37923. return this._loadedStreamCapability.promise;
  37924. },
  37925. terminate: function LocalPdfManager_terminate() {
  37926. return;
  37927. }
  37928. });
  37929. return LocalPdfManager;
  37930. })();
  37931. var NetworkPdfManager = (function NetworkPdfManagerClosure() {
  37932. function NetworkPdfManager(docId, args, msgHandler) {
  37933. this._docId = docId;
  37934. this.msgHandler = msgHandler;
  37935. var params = {
  37936. msgHandler: msgHandler,
  37937. httpHeaders: args.httpHeaders,
  37938. withCredentials: args.withCredentials,
  37939. chunkedViewerLoading: args.chunkedViewerLoading,
  37940. disableAutoFetch: args.disableAutoFetch,
  37941. initialData: args.initialData
  37942. };
  37943. this.streamManager = new ChunkedStreamManager(args.length,
  37944. args.rangeChunkSize,
  37945. args.url, params);
  37946. this.pdfDocument = new PDFDocument(this, this.streamManager.getStream(),
  37947. args.password);
  37948. }
  37949. Util.inherit(NetworkPdfManager, BasePdfManager, {
  37950. ensure: function NetworkPdfManager_ensure(obj, prop, args) {
  37951. var pdfManager = this;
  37952. return new Promise(function (resolve, reject) {
  37953. function ensureHelper() {
  37954. try {
  37955. var result;
  37956. var value = obj[prop];
  37957. if (typeof value === 'function') {
  37958. result = value.apply(obj, args);
  37959. } else {
  37960. result = value;
  37961. }
  37962. resolve(result);
  37963. } catch(e) {
  37964. if (!(e instanceof MissingDataException)) {
  37965. reject(e);
  37966. return;
  37967. }
  37968. pdfManager.streamManager.requestRange(e.begin, e.end).
  37969. then(ensureHelper, reject);
  37970. }
  37971. }
  37972. ensureHelper();
  37973. });
  37974. },
  37975. requestRange: function NetworkPdfManager_requestRange(begin, end) {
  37976. return this.streamManager.requestRange(begin, end);
  37977. },
  37978. requestLoadedStream: function NetworkPdfManager_requestLoadedStream() {
  37979. this.streamManager.requestAllChunks();
  37980. },
  37981. sendProgressiveData:
  37982. function NetworkPdfManager_sendProgressiveData(chunk) {
  37983. this.streamManager.onReceiveData({ chunk: chunk });
  37984. },
  37985. onLoadedStream: function NetworkPdfManager_onLoadedStream() {
  37986. return this.streamManager.onLoadedStream();
  37987. },
  37988. terminate: function NetworkPdfManager_terminate() {
  37989. this.streamManager.abort();
  37990. }
  37991. });
  37992. return NetworkPdfManager;
  37993. })();
  37994. exports.LocalPdfManager = LocalPdfManager;
  37995. exports.NetworkPdfManager = NetworkPdfManager;
  37996. }));
  37997. (function (root, factory) {
  37998. {
  37999. factory((root.pdfjsCoreWorker = {}), root.pdfjsSharedUtil,
  38000. root.pdfjsCorePrimitives, root.pdfjsCorePdfManager,
  38001. root.pdfjsSharedGlobal);
  38002. }
  38003. }(this, function (exports, sharedUtil, corePrimitives, corePdfManager,
  38004. sharedGlobal) {
  38005. var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  38006. var InvalidPDFException = sharedUtil.InvalidPDFException;
  38007. var MessageHandler = sharedUtil.MessageHandler;
  38008. var MissingPDFException = sharedUtil.MissingPDFException;
  38009. var UnexpectedResponseException = sharedUtil.UnexpectedResponseException;
  38010. var PasswordException = sharedUtil.PasswordException;
  38011. var PasswordResponses = sharedUtil.PasswordResponses;
  38012. var UnknownErrorException = sharedUtil.UnknownErrorException;
  38013. var XRefParseException = sharedUtil.XRefParseException;
  38014. var createPromiseCapability = sharedUtil.createPromiseCapability;
  38015. var error = sharedUtil.error;
  38016. var info = sharedUtil.info;
  38017. var isInt = sharedUtil.isInt;
  38018. var warn = sharedUtil.warn;
  38019. var Ref = corePrimitives.Ref;
  38020. var LocalPdfManager = corePdfManager.LocalPdfManager;
  38021. var NetworkPdfManager = corePdfManager.NetworkPdfManager;
  38022. var globalScope = sharedGlobal.globalScope;
  38023. var PDFJS = sharedGlobal.PDFJS;
  38024. var WorkerTask = (function WorkerTaskClosure() {
  38025. function WorkerTask(name) {
  38026. this.name = name;
  38027. this.terminated = false;
  38028. this._capability = createPromiseCapability();
  38029. }
  38030. WorkerTask.prototype = {
  38031. get finished() {
  38032. return this._capability.promise;
  38033. },
  38034. finish: function () {
  38035. this._capability.resolve();
  38036. },
  38037. terminate: function () {
  38038. this.terminated = true;
  38039. },
  38040. ensureNotTerminated: function () {
  38041. if (this.terminated) {
  38042. throw new Error('Worker task was terminated');
  38043. }
  38044. }
  38045. };
  38046. return WorkerTask;
  38047. })();
  38048. var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
  38049. setup: function wphSetup(handler, port) {
  38050. var testMessageProcessed = false;
  38051. handler.on('test', function wphSetupTest(data) {
  38052. if (testMessageProcessed) {
  38053. return; // we already processed 'test' message once
  38054. }
  38055. testMessageProcessed = true;
  38056. // check if Uint8Array can be sent to worker
  38057. if (!(data instanceof Uint8Array)) {
  38058. handler.send('test', 'main', false);
  38059. return;
  38060. }
  38061. // making sure postMessage transfers are working
  38062. var supportTransfers = data[0] === 255;
  38063. handler.postMessageTransfers = supportTransfers;
  38064. // check if the response property is supported by xhr
  38065. var xhr = new XMLHttpRequest();
  38066. var responseExists = 'response' in xhr;
  38067. // check if the property is actually implemented
  38068. try {
  38069. var dummy = xhr.responseType;
  38070. } catch (e) {
  38071. responseExists = false;
  38072. }
  38073. if (!responseExists) {
  38074. handler.send('test', false);
  38075. return;
  38076. }
  38077. handler.send('test', {
  38078. supportTypedArray: true,
  38079. supportTransfers: supportTransfers
  38080. });
  38081. });
  38082. handler.on('GetDocRequest', function wphSetupDoc(data) {
  38083. return WorkerMessageHandler.createDocumentHandler(data, port);
  38084. });
  38085. },
  38086. createDocumentHandler: function wphCreateDocumentHandler(docParams, port) {
  38087. // This context is actually holds references on pdfManager and handler,
  38088. // until the latter is destroyed.
  38089. var pdfManager;
  38090. var terminated = false;
  38091. var cancelXHRs = null;
  38092. var WorkerTasks = [];
  38093. var docId = docParams.docId;
  38094. var workerHandlerName = docParams.docId + '_worker';
  38095. var handler = new MessageHandler(workerHandlerName, docId, port);
  38096. function ensureNotTerminated() {
  38097. if (terminated) {
  38098. throw new Error('Worker was terminated');
  38099. }
  38100. }
  38101. function startWorkerTask(task) {
  38102. WorkerTasks.push(task);
  38103. }
  38104. function finishWorkerTask(task) {
  38105. task.finish();
  38106. var i = WorkerTasks.indexOf(task);
  38107. WorkerTasks.splice(i, 1);
  38108. }
  38109. function loadDocument(recoveryMode) {
  38110. var loadDocumentCapability = createPromiseCapability();
  38111. var parseSuccess = function parseSuccess() {
  38112. var numPagesPromise = pdfManager.ensureDoc('numPages');
  38113. var fingerprintPromise = pdfManager.ensureDoc('fingerprint');
  38114. var encryptedPromise = pdfManager.ensureXRef('encrypt');
  38115. Promise.all([numPagesPromise, fingerprintPromise,
  38116. encryptedPromise]).then(function onDocReady(results) {
  38117. var doc = {
  38118. numPages: results[0],
  38119. fingerprint: results[1],
  38120. encrypted: !!results[2],
  38121. };
  38122. loadDocumentCapability.resolve(doc);
  38123. },
  38124. parseFailure);
  38125. };
  38126. var parseFailure = function parseFailure(e) {
  38127. loadDocumentCapability.reject(e);
  38128. };
  38129. pdfManager.ensureDoc('checkHeader', []).then(function() {
  38130. pdfManager.ensureDoc('parseStartXRef', []).then(function() {
  38131. pdfManager.ensureDoc('parse', [recoveryMode]).then(
  38132. parseSuccess, parseFailure);
  38133. }, parseFailure);
  38134. }, parseFailure);
  38135. return loadDocumentCapability.promise;
  38136. }
  38137. function getPdfManager(data) {
  38138. var pdfManagerCapability = createPromiseCapability();
  38139. var pdfManager;
  38140. var source = data.source;
  38141. var disableRange = data.disableRange;
  38142. if (source.data) {
  38143. try {
  38144. pdfManager = new LocalPdfManager(docId, source.data, source.password);
  38145. pdfManagerCapability.resolve(pdfManager);
  38146. } catch (ex) {
  38147. pdfManagerCapability.reject(ex);
  38148. }
  38149. return pdfManagerCapability.promise;
  38150. } else if (source.chunkedViewerLoading) {
  38151. try {
  38152. pdfManager = new NetworkPdfManager(docId, source, handler);
  38153. pdfManagerCapability.resolve(pdfManager);
  38154. } catch (ex) {
  38155. pdfManagerCapability.reject(ex);
  38156. }
  38157. return pdfManagerCapability.promise;
  38158. }
  38159. var networkManager = new NetworkManager(source.url, {
  38160. httpHeaders: source.httpHeaders,
  38161. withCredentials: source.withCredentials
  38162. });
  38163. var cachedChunks = [];
  38164. var fullRequestXhrId = networkManager.requestFull({
  38165. onHeadersReceived: function onHeadersReceived() {
  38166. if (disableRange) {
  38167. return;
  38168. }
  38169. var fullRequestXhr = networkManager.getRequestXhr(fullRequestXhrId);
  38170. if (fullRequestXhr.getResponseHeader('Accept-Ranges') !== 'bytes') {
  38171. return;
  38172. }
  38173. var contentEncoding =
  38174. fullRequestXhr.getResponseHeader('Content-Encoding') || 'identity';
  38175. if (contentEncoding !== 'identity') {
  38176. return;
  38177. }
  38178. var length = fullRequestXhr.getResponseHeader('Content-Length');
  38179. length = parseInt(length, 10);
  38180. if (!isInt(length)) {
  38181. return;
  38182. }
  38183. source.length = length;
  38184. if (length <= 2 * source.rangeChunkSize) {
  38185. // The file size is smaller than the size of two chunks, so it does
  38186. // not make any sense to abort the request and retry with a range
  38187. // request.
  38188. return;
  38189. }
  38190. if (networkManager.isStreamingRequest(fullRequestXhrId)) {
  38191. // We can continue fetching when progressive loading is enabled,
  38192. // and we don't need the autoFetch feature.
  38193. source.disableAutoFetch = true;
  38194. } else {
  38195. // NOTE: by cancelling the full request, and then issuing range
  38196. // requests, there will be an issue for sites where you can only
  38197. // request the pdf once. However, if this is the case, then the
  38198. // server should not be returning that it can support range
  38199. // requests.
  38200. networkManager.abortRequest(fullRequestXhrId);
  38201. }
  38202. try {
  38203. pdfManager = new NetworkPdfManager(docId, source, handler);
  38204. pdfManagerCapability.resolve(pdfManager);
  38205. } catch (ex) {
  38206. pdfManagerCapability.reject(ex);
  38207. }
  38208. cancelXHRs = null;
  38209. },
  38210. onProgressiveData: source.disableStream ? null :
  38211. function onProgressiveData(chunk) {
  38212. if (!pdfManager) {
  38213. cachedChunks.push(chunk);
  38214. return;
  38215. }
  38216. pdfManager.sendProgressiveData(chunk);
  38217. },
  38218. onDone: function onDone(args) {
  38219. if (pdfManager) {
  38220. return; // already processed
  38221. }
  38222. var pdfFile;
  38223. if (args === null) {
  38224. // TODO add some streaming manager, e.g. for unknown length files.
  38225. // The data was returned in the onProgressiveData, combining...
  38226. var pdfFileLength = 0, pos = 0;
  38227. cachedChunks.forEach(function (chunk) {
  38228. pdfFileLength += chunk.byteLength;
  38229. });
  38230. if (source.length && pdfFileLength !== source.length) {
  38231. warn('reported HTTP length is different from actual');
  38232. }
  38233. var pdfFileArray = new Uint8Array(pdfFileLength);
  38234. cachedChunks.forEach(function (chunk) {
  38235. pdfFileArray.set(new Uint8Array(chunk), pos);
  38236. pos += chunk.byteLength;
  38237. });
  38238. pdfFile = pdfFileArray.buffer;
  38239. } else {
  38240. pdfFile = args.chunk;
  38241. }
  38242. // the data is array, instantiating directly from it
  38243. try {
  38244. pdfManager = new LocalPdfManager(docId, pdfFile, source.password);
  38245. pdfManagerCapability.resolve(pdfManager);
  38246. } catch (ex) {
  38247. pdfManagerCapability.reject(ex);
  38248. }
  38249. cancelXHRs = null;
  38250. },
  38251. onError: function onError(status) {
  38252. var exception;
  38253. if (status === 404 || status === 0 && /^file:/.test(source.url)) {
  38254. exception = new MissingPDFException('Missing PDF "' +
  38255. source.url + '".');
  38256. handler.send('MissingPDF', exception);
  38257. } else {
  38258. exception = new UnexpectedResponseException(
  38259. 'Unexpected server response (' + status +
  38260. ') while retrieving PDF "' + source.url + '".', status);
  38261. handler.send('UnexpectedResponse', exception);
  38262. }
  38263. cancelXHRs = null;
  38264. },
  38265. onProgress: function onProgress(evt) {
  38266. handler.send('DocProgress', {
  38267. loaded: evt.loaded,
  38268. total: evt.lengthComputable ? evt.total : source.length
  38269. });
  38270. }
  38271. });
  38272. cancelXHRs = function () {
  38273. networkManager.abortRequest(fullRequestXhrId);
  38274. };
  38275. return pdfManagerCapability.promise;
  38276. }
  38277. var setupDoc = function(data) {
  38278. var onSuccess = function(doc) {
  38279. ensureNotTerminated();
  38280. handler.send('GetDoc', { pdfInfo: doc });
  38281. };
  38282. var onFailure = function(e) {
  38283. if (e instanceof PasswordException) {
  38284. if (e.code === PasswordResponses.NEED_PASSWORD) {
  38285. handler.send('NeedPassword', e);
  38286. } else if (e.code === PasswordResponses.INCORRECT_PASSWORD) {
  38287. handler.send('IncorrectPassword', e);
  38288. }
  38289. } else if (e instanceof InvalidPDFException) {
  38290. handler.send('InvalidPDF', e);
  38291. } else if (e instanceof MissingPDFException) {
  38292. handler.send('MissingPDF', e);
  38293. } else if (e instanceof UnexpectedResponseException) {
  38294. handler.send('UnexpectedResponse', e);
  38295. } else {
  38296. handler.send('UnknownError',
  38297. new UnknownErrorException(e.message, e.toString()));
  38298. }
  38299. };
  38300. ensureNotTerminated();
  38301. PDFJS.maxImageSize = data.maxImageSize === undefined ?
  38302. -1 : data.maxImageSize;
  38303. PDFJS.disableFontFace = data.disableFontFace;
  38304. PDFJS.disableCreateObjectURL = data.disableCreateObjectURL;
  38305. PDFJS.verbosity = data.verbosity;
  38306. PDFJS.cMapUrl = data.cMapUrl === undefined ?
  38307. null : data.cMapUrl;
  38308. PDFJS.cMapPacked = data.cMapPacked === true;
  38309. getPdfManager(data).then(function (newPdfManager) {
  38310. if (terminated) {
  38311. // We were in a process of setting up the manager, but it got
  38312. // terminated in the middle.
  38313. newPdfManager.terminate();
  38314. throw new Error('Worker was terminated');
  38315. }
  38316. pdfManager = newPdfManager;
  38317. handler.send('PDFManagerReady', null);
  38318. pdfManager.onLoadedStream().then(function(stream) {
  38319. handler.send('DataLoaded', { length: stream.bytes.byteLength });
  38320. });
  38321. }).then(function pdfManagerReady() {
  38322. ensureNotTerminated();
  38323. loadDocument(false).then(onSuccess, function loadFailure(ex) {
  38324. ensureNotTerminated();
  38325. // Try again with recoveryMode == true
  38326. if (!(ex instanceof XRefParseException)) {
  38327. if (ex instanceof PasswordException) {
  38328. // after password exception prepare to receive a new password
  38329. // to repeat loading
  38330. pdfManager.passwordChanged().then(pdfManagerReady);
  38331. }
  38332. onFailure(ex);
  38333. return;
  38334. }
  38335. pdfManager.requestLoadedStream();
  38336. pdfManager.onLoadedStream().then(function() {
  38337. ensureNotTerminated();
  38338. loadDocument(true).then(onSuccess, onFailure);
  38339. });
  38340. }, onFailure);
  38341. }, onFailure);
  38342. };
  38343. handler.on('GetPage', function wphSetupGetPage(data) {
  38344. return pdfManager.getPage(data.pageIndex).then(function(page) {
  38345. var rotatePromise = pdfManager.ensure(page, 'rotate');
  38346. var refPromise = pdfManager.ensure(page, 'ref');
  38347. var viewPromise = pdfManager.ensure(page, 'view');
  38348. return Promise.all([rotatePromise, refPromise, viewPromise]).then(
  38349. function(results) {
  38350. return {
  38351. rotate: results[0],
  38352. ref: results[1],
  38353. view: results[2]
  38354. };
  38355. });
  38356. });
  38357. });
  38358. handler.on('GetPageIndex', function wphSetupGetPageIndex(data) {
  38359. var ref = new Ref(data.ref.num, data.ref.gen);
  38360. var catalog = pdfManager.pdfDocument.catalog;
  38361. return catalog.getPageIndex(ref);
  38362. });
  38363. handler.on('GetDestinations',
  38364. function wphSetupGetDestinations(data) {
  38365. return pdfManager.ensureCatalog('destinations');
  38366. }
  38367. );
  38368. handler.on('GetDestination',
  38369. function wphSetupGetDestination(data) {
  38370. return pdfManager.ensureCatalog('getDestination', [data.id]);
  38371. }
  38372. );
  38373. handler.on('GetAttachments',
  38374. function wphSetupGetAttachments(data) {
  38375. return pdfManager.ensureCatalog('attachments');
  38376. }
  38377. );
  38378. handler.on('GetJavaScript',
  38379. function wphSetupGetJavaScript(data) {
  38380. return pdfManager.ensureCatalog('javaScript');
  38381. }
  38382. );
  38383. handler.on('GetOutline',
  38384. function wphSetupGetOutline(data) {
  38385. return pdfManager.ensureCatalog('documentOutline');
  38386. }
  38387. );
  38388. handler.on('GetMetadata',
  38389. function wphSetupGetMetadata(data) {
  38390. return Promise.all([pdfManager.ensureDoc('documentInfo'),
  38391. pdfManager.ensureCatalog('metadata')]);
  38392. }
  38393. );
  38394. handler.on('GetData', function wphSetupGetData(data) {
  38395. pdfManager.requestLoadedStream();
  38396. return pdfManager.onLoadedStream().then(function(stream) {
  38397. return stream.bytes;
  38398. });
  38399. });
  38400. handler.on('GetStats',
  38401. function wphSetupGetStats(data) {
  38402. return pdfManager.pdfDocument.xref.stats;
  38403. }
  38404. );
  38405. handler.on('UpdatePassword', function wphSetupUpdatePassword(data) {
  38406. pdfManager.updatePassword(data);
  38407. });
  38408. handler.on('GetAnnotations', function wphSetupGetAnnotations(data) {
  38409. return pdfManager.getPage(data.pageIndex).then(function(page) {
  38410. return pdfManager.ensure(page, 'getAnnotationsData', [data.intent]);
  38411. });
  38412. });
  38413. handler.on('RenderPageRequest', function wphSetupRenderPage(data) {
  38414. var pageIndex = data.pageIndex;
  38415. pdfManager.getPage(pageIndex).then(function(page) {
  38416. var task = new WorkerTask('RenderPageRequest: page ' + pageIndex);
  38417. startWorkerTask(task);
  38418. var pageNum = pageIndex + 1;
  38419. var start = Date.now();
  38420. // Pre compile the pdf page and fetch the fonts/images.
  38421. page.getOperatorList(handler, task, data.intent).then(
  38422. function(operatorList) {
  38423. finishWorkerTask(task);
  38424. info('page=' + pageNum + ' - getOperatorList: time=' +
  38425. (Date.now() - start) + 'ms, len=' + operatorList.totalLength);
  38426. }, function(e) {
  38427. finishWorkerTask(task);
  38428. if (task.terminated) {
  38429. return; // ignoring errors from the terminated thread
  38430. }
  38431. // For compatibility with older behavior, generating unknown
  38432. // unsupported feature notification on errors.
  38433. handler.send('UnsupportedFeature',
  38434. {featureId: UNSUPPORTED_FEATURES.unknown});
  38435. var minimumStackMessage =
  38436. 'worker.js: while trying to getPage() and getOperatorList()';
  38437. var wrappedException;
  38438. // Turn the error into an obj that can be serialized
  38439. if (typeof e === 'string') {
  38440. wrappedException = {
  38441. message: e,
  38442. stack: minimumStackMessage
  38443. };
  38444. } else if (typeof e === 'object') {
  38445. wrappedException = {
  38446. message: e.message || e.toString(),
  38447. stack: e.stack || minimumStackMessage
  38448. };
  38449. } else {
  38450. wrappedException = {
  38451. message: 'Unknown exception type: ' + (typeof e),
  38452. stack: minimumStackMessage
  38453. };
  38454. }
  38455. handler.send('PageError', {
  38456. pageNum: pageNum,
  38457. error: wrappedException,
  38458. intent: data.intent
  38459. });
  38460. });
  38461. });
  38462. }, this);
  38463. handler.on('GetTextContent', function wphExtractText(data) {
  38464. var pageIndex = data.pageIndex;
  38465. var normalizeWhitespace = data.normalizeWhitespace;
  38466. return pdfManager.getPage(pageIndex).then(function(page) {
  38467. var task = new WorkerTask('GetTextContent: page ' + pageIndex);
  38468. startWorkerTask(task);
  38469. var pageNum = pageIndex + 1;
  38470. var start = Date.now();
  38471. return page.extractTextContent(task, normalizeWhitespace).then(
  38472. function(textContent) {
  38473. finishWorkerTask(task);
  38474. info('text indexing: page=' + pageNum + ' - time=' +
  38475. (Date.now() - start) + 'ms');
  38476. return textContent;
  38477. }, function (reason) {
  38478. finishWorkerTask(task);
  38479. if (task.terminated) {
  38480. return; // ignoring errors from the terminated thread
  38481. }
  38482. throw reason;
  38483. });
  38484. });
  38485. });
  38486. handler.on('Cleanup', function wphCleanup(data) {
  38487. return pdfManager.cleanup();
  38488. });
  38489. handler.on('Terminate', function wphTerminate(data) {
  38490. terminated = true;
  38491. if (pdfManager) {
  38492. pdfManager.terminate();
  38493. pdfManager = null;
  38494. }
  38495. if (cancelXHRs) {
  38496. cancelXHRs();
  38497. }
  38498. var waitOn = [];
  38499. WorkerTasks.forEach(function (task) {
  38500. waitOn.push(task.finished);
  38501. task.terminate();
  38502. });
  38503. return Promise.all(waitOn).then(function () {
  38504. // Notice that even if we destroying handler, resolved response promise
  38505. // must be sent back.
  38506. handler.destroy();
  38507. handler = null;
  38508. });
  38509. });
  38510. handler.on('Ready', function wphReady(data) {
  38511. setupDoc(docParams);
  38512. docParams = null; // we don't need docParams anymore -- saving memory.
  38513. });
  38514. return workerHandlerName;
  38515. }
  38516. };
  38517. function initializeWorker() {
  38518. if (!('console' in globalScope)) {
  38519. var consoleTimer = {};
  38520. var workerConsole = {
  38521. log: function log() {
  38522. var args = Array.prototype.slice.call(arguments);
  38523. globalScope.postMessage({
  38524. targetName: 'main',
  38525. action: 'console_log',
  38526. data: args
  38527. });
  38528. },
  38529. error: function error() {
  38530. var args = Array.prototype.slice.call(arguments);
  38531. globalScope.postMessage({
  38532. targetName: 'main',
  38533. action: 'console_error',
  38534. data: args
  38535. });
  38536. throw 'pdf.js execution error';
  38537. },
  38538. time: function time(name) {
  38539. consoleTimer[name] = Date.now();
  38540. },
  38541. timeEnd: function timeEnd(name) {
  38542. var time = consoleTimer[name];
  38543. if (!time) {
  38544. error('Unknown timer name ' + name);
  38545. }
  38546. this.log('Timer:', name, Date.now() - time);
  38547. }
  38548. };
  38549. globalScope.console = workerConsole;
  38550. }
  38551. var handler = new MessageHandler('worker', 'main', self);
  38552. WorkerMessageHandler.setup(handler, self);
  38553. handler.send('ready', null);
  38554. }
  38555. // Worker thread (and not node.js)?
  38556. if (typeof window === 'undefined' &&
  38557. !(typeof module !== 'undefined' && module.require)) {
  38558. initializeWorker();
  38559. }
  38560. exports.WorkerTask = WorkerTask;
  38561. exports.WorkerMessageHandler = WorkerMessageHandler;
  38562. }));
  38563. }).call((typeof window === 'undefined') ? this : window);
  38564. if (!PDFJS.workerSrc && typeof document !== 'undefined') {
  38565. // workerSrc is not set -- using last script url to define default location
  38566. PDFJS.workerSrc = (function () {
  38567. 'use strict';
  38568. var pdfJsSrc = document.currentScript.src;
  38569. return pdfJsSrc && pdfJsSrc.replace(/\.js$/i, '.worker.js');
  38570. })();
  38571. }