pdf.worker.js 1.3 MB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385213862138721388213892139021391213922139321394213952139621397213982139921400214012140221403214042140521406214072140821409214102141121412214132141421415214162141721418214192142021421214222142321424214252142621427214282142921430214312143221433214342143521436214372143821439214402144121442214432144421445214462144721448214492145021451214522145321454214552145621457214582145921460214612146221463214642146521466214672146821469214702147121472214732147421475214762147721478214792148021481214822148321484214852148621487214882148921490214912149221493214942149521496214972149821499215002150121502215032150421505215062150721508215092151021511215122151321514215152151621517215182151921520215212152221523215242152521526215272152821529215302153121532215332153421535215362153721538215392154021541215422154321544215452154621547215482154921550215512155221553215542155521556215572155821559215602156121562215632156421565215662156721568215692157021571215722157321574215752157621577215782157921580215812158221583215842158521586215872158821589215902159121592215932159421595215962159721598215992160021601216022160321604216052160621607216082160921610216112161221613216142161521616216172161821619216202162121622216232162421625216262162721628216292163021631216322163321634216352163621637216382163921640216412164221643216442164521646216472164821649216502165121652216532165421655216562165721658216592166021661216622166321664216652166621667216682166921670216712167221673216742167521676216772167821679216802168121682216832168421685216862168721688216892169021691216922169321694216952169621697216982169921700217012170221703217042170521706217072170821709217102171121712217132171421715217162171721718217192172021721217222172321724217252172621727217282172921730217312173221733217342173521736217372173821739217402174121742217432174421745217462174721748217492175021751217522175321754217552175621757217582175921760217612176221763217642176521766217672176821769217702177121772217732177421775217762177721778217792178021781217822178321784217852178621787217882178921790217912179221793217942179521796217972179821799218002180121802218032180421805218062180721808218092181021811218122181321814218152181621817218182181921820218212182221823218242182521826218272182821829218302183121832218332183421835218362183721838218392184021841218422184321844218452184621847218482184921850218512185221853218542185521856218572185821859218602186121862218632186421865218662186721868218692187021871218722187321874218752187621877218782187921880218812188221883218842188521886218872188821889218902189121892218932189421895218962189721898218992190021901219022190321904219052190621907219082190921910219112191221913219142191521916219172191821919219202192121922219232192421925219262192721928219292193021931219322193321934219352193621937219382193921940219412194221943219442194521946219472194821949219502195121952219532195421955219562195721958219592196021961219622196321964219652196621967219682196921970219712197221973219742197521976219772197821979219802198121982219832198421985219862198721988219892199021991219922199321994219952199621997219982199922000220012200222003220042200522006220072200822009220102201122012220132201422015220162201722018220192202022021220222202322024220252202622027220282202922030220312203222033220342203522036220372203822039220402204122042220432204422045220462204722048220492205022051220522205322054220552205622057220582205922060220612206222063220642206522066220672206822069220702207122072220732207422075220762207722078220792208022081220822208322084220852208622087220882208922090220912209222093220942209522096220972209822099221002210122102221032210422105221062210722108221092211022111221122211322114221152211622117221182211922120221212212222123221242212522126221272212822129221302213122132221332213422135221362213722138221392214022141221422214322144221452214622147221482214922150221512215222153221542215522156221572215822159221602216122162221632216422165221662216722168221692217022171221722217322174221752217622177221782217922180221812218222183221842218522186221872218822189221902219122192221932219422195221962219722198221992220022201222022220322204222052220622207222082220922210222112221222213222142221522216222172221822219222202222122222222232222422225222262222722228222292223022231222322223322234222352223622237222382223922240222412224222243222442224522246222472224822249222502225122252222532225422255222562225722258222592226022261222622226322264222652226622267222682226922270222712227222273222742227522276222772227822279222802228122282222832228422285222862228722288222892229022291222922229322294222952229622297222982229922300223012230222303223042230522306223072230822309223102231122312223132231422315223162231722318223192232022321223222232322324223252232622327223282232922330223312233222333223342233522336223372233822339223402234122342223432234422345223462234722348223492235022351223522235322354223552235622357223582235922360223612236222363223642236522366223672236822369223702237122372223732237422375223762237722378223792238022381223822238322384223852238622387223882238922390223912239222393223942239522396223972239822399224002240122402224032240422405224062240722408224092241022411224122241322414224152241622417224182241922420224212242222423224242242522426224272242822429224302243122432224332243422435224362243722438224392244022441224422244322444224452244622447224482244922450224512245222453224542245522456224572245822459224602246122462224632246422465224662246722468224692247022471224722247322474224752247622477224782247922480224812248222483224842248522486224872248822489224902249122492224932249422495224962249722498224992250022501225022250322504225052250622507225082250922510225112251222513225142251522516225172251822519225202252122522225232252422525225262252722528225292253022531225322253322534225352253622537225382253922540225412254222543225442254522546225472254822549225502255122552225532255422555225562255722558225592256022561225622256322564225652256622567225682256922570225712257222573225742257522576225772257822579225802258122582225832258422585225862258722588225892259022591225922259322594225952259622597225982259922600226012260222603226042260522606226072260822609226102261122612226132261422615226162261722618226192262022621226222262322624226252262622627226282262922630226312263222633226342263522636226372263822639226402264122642226432264422645226462264722648226492265022651226522265322654226552265622657226582265922660226612266222663226642266522666226672266822669226702267122672226732267422675226762267722678226792268022681226822268322684226852268622687226882268922690226912269222693226942269522696226972269822699227002270122702227032270422705227062270722708227092271022711227122271322714227152271622717227182271922720227212272222723227242272522726227272272822729227302273122732227332273422735227362273722738227392274022741227422274322744227452274622747227482274922750227512275222753227542275522756227572275822759227602276122762227632276422765227662276722768227692277022771227722277322774227752277622777227782277922780227812278222783227842278522786227872278822789227902279122792227932279422795227962279722798227992280022801228022280322804228052280622807228082280922810228112281222813228142281522816228172281822819228202282122822228232282422825228262282722828228292283022831228322283322834228352283622837228382283922840228412284222843228442284522846228472284822849228502285122852228532285422855228562285722858228592286022861228622286322864228652286622867228682286922870228712287222873228742287522876228772287822879228802288122882228832288422885228862288722888228892289022891228922289322894228952289622897228982289922900229012290222903229042290522906229072290822909229102291122912229132291422915229162291722918229192292022921229222292322924229252292622927229282292922930229312293222933229342293522936229372293822939229402294122942229432294422945229462294722948229492295022951229522295322954229552295622957229582295922960229612296222963229642296522966229672296822969229702297122972229732297422975229762297722978229792298022981229822298322984229852298622987229882298922990229912299222993229942299522996229972299822999230002300123002230032300423005230062300723008230092301023011230122301323014230152301623017230182301923020230212302223023230242302523026230272302823029230302303123032230332303423035230362303723038230392304023041230422304323044230452304623047230482304923050230512305223053230542305523056230572305823059230602306123062230632306423065230662306723068230692307023071230722307323074230752307623077230782307923080230812308223083230842308523086230872308823089230902309123092230932309423095230962309723098230992310023101231022310323104231052310623107231082310923110231112311223113231142311523116231172311823119231202312123122231232312423125231262312723128231292313023131231322313323134231352313623137231382313923140231412314223143231442314523146231472314823149231502315123152231532315423155231562315723158231592316023161231622316323164231652316623167231682316923170231712317223173231742317523176231772317823179231802318123182231832318423185231862318723188231892319023191231922319323194231952319623197231982319923200232012320223203232042320523206232072320823209232102321123212232132321423215232162321723218232192322023221232222322323224232252322623227232282322923230232312323223233232342323523236232372323823239232402324123242232432324423245232462324723248232492325023251232522325323254232552325623257232582325923260232612326223263232642326523266232672326823269232702327123272232732327423275232762327723278232792328023281232822328323284232852328623287232882328923290232912329223293232942329523296232972329823299233002330123302233032330423305233062330723308233092331023311233122331323314233152331623317233182331923320233212332223323233242332523326233272332823329233302333123332233332333423335233362333723338233392334023341233422334323344233452334623347233482334923350233512335223353233542335523356233572335823359233602336123362233632336423365233662336723368233692337023371233722337323374233752337623377233782337923380233812338223383233842338523386233872338823389233902339123392233932339423395233962339723398233992340023401234022340323404234052340623407234082340923410234112341223413234142341523416234172341823419234202342123422234232342423425234262342723428234292343023431234322343323434234352343623437234382343923440234412344223443234442344523446234472344823449234502345123452234532345423455234562345723458234592346023461234622346323464234652346623467234682346923470234712347223473234742347523476234772347823479234802348123482234832348423485234862348723488234892349023491234922349323494234952349623497234982349923500235012350223503235042350523506235072350823509235102351123512235132351423515235162351723518235192352023521235222352323524235252352623527235282352923530235312353223533235342353523536235372353823539235402354123542235432354423545235462354723548235492355023551235522355323554235552355623557235582355923560235612356223563235642356523566235672356823569235702357123572235732357423575235762357723578235792358023581235822358323584235852358623587235882358923590235912359223593235942359523596235972359823599236002360123602236032360423605236062360723608236092361023611236122361323614236152361623617236182361923620236212362223623236242362523626236272362823629236302363123632236332363423635236362363723638236392364023641236422364323644236452364623647236482364923650236512365223653236542365523656236572365823659236602366123662236632366423665236662366723668236692367023671236722367323674236752367623677236782367923680236812368223683236842368523686236872368823689236902369123692236932369423695236962369723698236992370023701237022370323704237052370623707237082370923710237112371223713237142371523716237172371823719237202372123722237232372423725237262372723728237292373023731237322373323734237352373623737237382373923740237412374223743237442374523746237472374823749237502375123752237532375423755237562375723758237592376023761237622376323764237652376623767237682376923770237712377223773237742377523776237772377823779237802378123782237832378423785237862378723788237892379023791237922379323794237952379623797237982379923800238012380223803238042380523806238072380823809238102381123812238132381423815238162381723818238192382023821238222382323824238252382623827238282382923830238312383223833238342383523836238372383823839238402384123842238432384423845238462384723848238492385023851238522385323854238552385623857238582385923860238612386223863238642386523866238672386823869238702387123872238732387423875238762387723878238792388023881238822388323884238852388623887238882388923890238912389223893238942389523896238972389823899239002390123902239032390423905239062390723908239092391023911239122391323914239152391623917239182391923920239212392223923239242392523926239272392823929239302393123932239332393423935239362393723938239392394023941239422394323944239452394623947239482394923950239512395223953239542395523956239572395823959239602396123962239632396423965239662396723968239692397023971239722397323974239752397623977239782397923980239812398223983239842398523986239872398823989239902399123992239932399423995239962399723998239992400024001240022400324004240052400624007240082400924010240112401224013240142401524016240172401824019240202402124022240232402424025240262402724028240292403024031240322403324034240352403624037240382403924040240412404224043240442404524046240472404824049240502405124052240532405424055240562405724058240592406024061240622406324064240652406624067240682406924070240712407224073240742407524076240772407824079240802408124082240832408424085240862408724088240892409024091240922409324094240952409624097240982409924100241012410224103241042410524106241072410824109241102411124112241132411424115241162411724118241192412024121241222412324124241252412624127241282412924130241312413224133241342413524136241372413824139241402414124142241432414424145241462414724148241492415024151241522415324154241552415624157241582415924160241612416224163241642416524166241672416824169241702417124172241732417424175241762417724178241792418024181241822418324184241852418624187241882418924190241912419224193241942419524196241972419824199242002420124202242032420424205242062420724208242092421024211242122421324214242152421624217242182421924220242212422224223242242422524226242272422824229242302423124232242332423424235242362423724238242392424024241242422424324244242452424624247242482424924250242512425224253242542425524256242572425824259242602426124262242632426424265242662426724268242692427024271242722427324274242752427624277242782427924280242812428224283242842428524286242872428824289242902429124292242932429424295242962429724298242992430024301243022430324304243052430624307243082430924310243112431224313243142431524316243172431824319243202432124322243232432424325243262432724328243292433024331243322433324334243352433624337243382433924340243412434224343243442434524346243472434824349243502435124352243532435424355243562435724358243592436024361243622436324364243652436624367243682436924370243712437224373243742437524376243772437824379243802438124382243832438424385243862438724388243892439024391243922439324394243952439624397243982439924400244012440224403244042440524406244072440824409244102441124412244132441424415244162441724418244192442024421244222442324424244252442624427244282442924430244312443224433244342443524436244372443824439244402444124442244432444424445244462444724448244492445024451244522445324454244552445624457244582445924460244612446224463244642446524466244672446824469244702447124472244732447424475244762447724478244792448024481244822448324484244852448624487244882448924490244912449224493244942449524496244972449824499245002450124502245032450424505245062450724508245092451024511245122451324514245152451624517245182451924520245212452224523245242452524526245272452824529245302453124532245332453424535245362453724538245392454024541245422454324544245452454624547245482454924550245512455224553245542455524556245572455824559245602456124562245632456424565245662456724568245692457024571245722457324574245752457624577245782457924580245812458224583245842458524586245872458824589245902459124592245932459424595245962459724598245992460024601246022460324604246052460624607246082460924610246112461224613246142461524616246172461824619246202462124622246232462424625246262462724628246292463024631246322463324634246352463624637246382463924640246412464224643246442464524646246472464824649246502465124652246532465424655246562465724658246592466024661246622466324664246652466624667246682466924670246712467224673246742467524676246772467824679246802468124682246832468424685246862468724688246892469024691246922469324694246952469624697246982469924700247012470224703247042470524706247072470824709247102471124712247132471424715247162471724718247192472024721247222472324724247252472624727247282472924730247312473224733247342473524736247372473824739247402474124742247432474424745247462474724748247492475024751247522475324754247552475624757247582475924760247612476224763247642476524766247672476824769247702477124772247732477424775247762477724778247792478024781247822478324784247852478624787247882478924790247912479224793247942479524796247972479824799248002480124802248032480424805248062480724808248092481024811248122481324814248152481624817248182481924820248212482224823248242482524826248272482824829248302483124832248332483424835248362483724838248392484024841248422484324844248452484624847248482484924850248512485224853248542485524856248572485824859248602486124862248632486424865248662486724868248692487024871248722487324874248752487624877248782487924880248812488224883248842488524886248872488824889248902489124892248932489424895248962489724898248992490024901249022490324904249052490624907249082490924910249112491224913249142491524916249172491824919249202492124922249232492424925249262492724928249292493024931249322493324934249352493624937249382493924940249412494224943249442494524946249472494824949249502495124952249532495424955249562495724958249592496024961249622496324964249652496624967249682496924970249712497224973249742497524976249772497824979249802498124982249832498424985249862498724988249892499024991249922499324994249952499624997249982499925000250012500225003250042500525006250072500825009250102501125012250132501425015250162501725018250192502025021250222502325024250252502625027250282502925030250312503225033250342503525036250372503825039250402504125042250432504425045250462504725048250492505025051250522505325054250552505625057250582505925060250612506225063250642506525066250672506825069250702507125072250732507425075250762507725078250792508025081250822508325084250852508625087250882508925090250912509225093250942509525096250972509825099251002510125102251032510425105251062510725108251092511025111251122511325114251152511625117251182511925120251212512225123251242512525126251272512825129251302513125132251332513425135251362513725138251392514025141251422514325144251452514625147251482514925150251512515225153251542515525156251572515825159251602516125162251632516425165251662516725168251692517025171251722517325174251752517625177251782517925180251812518225183251842518525186251872518825189251902519125192251932519425195251962519725198251992520025201252022520325204252052520625207252082520925210252112521225213252142521525216252172521825219252202522125222252232522425225252262522725228252292523025231252322523325234252352523625237252382523925240252412524225243252442524525246252472524825249252502525125252252532525425255252562525725258252592526025261252622526325264252652526625267252682526925270252712527225273252742527525276252772527825279252802528125282252832528425285252862528725288252892529025291252922529325294252952529625297252982529925300253012530225303253042530525306253072530825309253102531125312253132531425315253162531725318253192532025321253222532325324253252532625327253282532925330253312533225333253342533525336253372533825339253402534125342253432534425345253462534725348253492535025351253522535325354253552535625357253582535925360253612536225363253642536525366253672536825369253702537125372253732537425375253762537725378253792538025381253822538325384253852538625387253882538925390253912539225393253942539525396253972539825399254002540125402254032540425405254062540725408254092541025411254122541325414254152541625417254182541925420254212542225423254242542525426254272542825429254302543125432254332543425435254362543725438254392544025441254422544325444254452544625447254482544925450254512545225453254542545525456254572545825459254602546125462254632546425465254662546725468254692547025471254722547325474254752547625477254782547925480254812548225483254842548525486254872548825489254902549125492254932549425495254962549725498254992550025501255022550325504255052550625507255082550925510255112551225513255142551525516255172551825519255202552125522255232552425525255262552725528255292553025531255322553325534255352553625537255382553925540255412554225543255442554525546255472554825549255502555125552255532555425555255562555725558255592556025561255622556325564255652556625567255682556925570255712557225573255742557525576255772557825579255802558125582255832558425585255862558725588255892559025591255922559325594255952559625597255982559925600256012560225603256042560525606256072560825609256102561125612256132561425615256162561725618256192562025621256222562325624256252562625627256282562925630256312563225633256342563525636256372563825639256402564125642256432564425645256462564725648256492565025651256522565325654256552565625657256582565925660256612566225663256642566525666256672566825669256702567125672256732567425675256762567725678256792568025681256822568325684256852568625687256882568925690256912569225693256942569525696256972569825699257002570125702257032570425705257062570725708257092571025711257122571325714257152571625717257182571925720257212572225723257242572525726257272572825729257302573125732257332573425735257362573725738257392574025741257422574325744257452574625747257482574925750257512575225753257542575525756257572575825759257602576125762257632576425765257662576725768257692577025771257722577325774257752577625777257782577925780257812578225783257842578525786257872578825789257902579125792257932579425795257962579725798257992580025801258022580325804258052580625807258082580925810258112581225813258142581525816258172581825819258202582125822258232582425825258262582725828258292583025831258322583325834258352583625837258382583925840258412584225843258442584525846258472584825849258502585125852258532585425855258562585725858258592586025861258622586325864258652586625867258682586925870258712587225873258742587525876258772587825879258802588125882258832588425885258862588725888258892589025891258922589325894258952589625897258982589925900259012590225903259042590525906259072590825909259102591125912259132591425915259162591725918259192592025921259222592325924259252592625927259282592925930259312593225933259342593525936259372593825939259402594125942259432594425945259462594725948259492595025951259522595325954259552595625957259582595925960259612596225963259642596525966259672596825969259702597125972259732597425975259762597725978259792598025981259822598325984259852598625987259882598925990259912599225993259942599525996259972599825999260002600126002260032600426005260062600726008260092601026011260122601326014260152601626017260182601926020260212602226023260242602526026260272602826029260302603126032260332603426035260362603726038260392604026041260422604326044260452604626047260482604926050260512605226053260542605526056260572605826059260602606126062260632606426065260662606726068260692607026071260722607326074260752607626077260782607926080260812608226083260842608526086260872608826089260902609126092260932609426095260962609726098260992610026101261022610326104261052610626107261082610926110261112611226113261142611526116261172611826119261202612126122261232612426125261262612726128261292613026131261322613326134261352613626137261382613926140261412614226143261442614526146261472614826149261502615126152261532615426155261562615726158261592616026161261622616326164261652616626167261682616926170261712617226173261742617526176261772617826179261802618126182261832618426185261862618726188261892619026191261922619326194261952619626197261982619926200262012620226203262042620526206262072620826209262102621126212262132621426215262162621726218262192622026221262222622326224262252622626227262282622926230262312623226233262342623526236262372623826239262402624126242262432624426245262462624726248262492625026251262522625326254262552625626257262582625926260262612626226263262642626526266262672626826269262702627126272262732627426275262762627726278262792628026281262822628326284262852628626287262882628926290262912629226293262942629526296262972629826299263002630126302263032630426305263062630726308263092631026311263122631326314263152631626317263182631926320263212632226323263242632526326263272632826329263302633126332263332633426335263362633726338263392634026341263422634326344263452634626347263482634926350263512635226353263542635526356263572635826359263602636126362263632636426365263662636726368263692637026371263722637326374263752637626377263782637926380263812638226383263842638526386263872638826389263902639126392263932639426395263962639726398263992640026401264022640326404264052640626407264082640926410264112641226413264142641526416264172641826419264202642126422264232642426425264262642726428264292643026431264322643326434264352643626437264382643926440264412644226443264442644526446264472644826449264502645126452264532645426455264562645726458264592646026461264622646326464264652646626467264682646926470264712647226473264742647526476264772647826479264802648126482264832648426485264862648726488264892649026491264922649326494264952649626497264982649926500265012650226503265042650526506265072650826509265102651126512265132651426515265162651726518265192652026521265222652326524265252652626527265282652926530265312653226533265342653526536265372653826539265402654126542265432654426545265462654726548265492655026551265522655326554265552655626557265582655926560265612656226563265642656526566265672656826569265702657126572265732657426575265762657726578265792658026581265822658326584265852658626587265882658926590265912659226593265942659526596265972659826599266002660126602266032660426605266062660726608266092661026611266122661326614266152661626617266182661926620266212662226623266242662526626266272662826629266302663126632266332663426635266362663726638266392664026641266422664326644266452664626647266482664926650266512665226653266542665526656266572665826659266602666126662266632666426665266662666726668266692667026671266722667326674266752667626677266782667926680266812668226683266842668526686266872668826689266902669126692266932669426695266962669726698266992670026701267022670326704267052670626707267082670926710267112671226713267142671526716267172671826719267202672126722267232672426725267262672726728267292673026731267322673326734267352673626737267382673926740267412674226743267442674526746267472674826749267502675126752267532675426755267562675726758267592676026761267622676326764267652676626767267682676926770267712677226773267742677526776267772677826779267802678126782267832678426785267862678726788267892679026791267922679326794267952679626797267982679926800268012680226803268042680526806268072680826809268102681126812268132681426815268162681726818268192682026821268222682326824268252682626827268282682926830268312683226833268342683526836268372683826839268402684126842268432684426845268462684726848268492685026851268522685326854268552685626857268582685926860268612686226863268642686526866268672686826869268702687126872268732687426875268762687726878268792688026881268822688326884268852688626887268882688926890268912689226893268942689526896268972689826899269002690126902269032690426905269062690726908269092691026911269122691326914269152691626917269182691926920269212692226923269242692526926269272692826929269302693126932269332693426935269362693726938269392694026941269422694326944269452694626947269482694926950269512695226953269542695526956269572695826959269602696126962269632696426965269662696726968269692697026971269722697326974269752697626977269782697926980269812698226983269842698526986269872698826989269902699126992269932699426995269962699726998269992700027001270022700327004270052700627007270082700927010270112701227013270142701527016270172701827019270202702127022270232702427025270262702727028270292703027031270322703327034270352703627037270382703927040270412704227043270442704527046270472704827049270502705127052270532705427055270562705727058270592706027061270622706327064270652706627067270682706927070270712707227073270742707527076270772707827079270802708127082270832708427085270862708727088270892709027091270922709327094270952709627097270982709927100271012710227103271042710527106271072710827109271102711127112271132711427115271162711727118271192712027121271222712327124271252712627127271282712927130271312713227133271342713527136271372713827139271402714127142271432714427145271462714727148271492715027151271522715327154271552715627157271582715927160271612716227163271642716527166271672716827169271702717127172271732717427175271762717727178271792718027181271822718327184271852718627187271882718927190271912719227193271942719527196271972719827199272002720127202272032720427205272062720727208272092721027211272122721327214272152721627217272182721927220272212722227223272242722527226272272722827229272302723127232272332723427235272362723727238272392724027241272422724327244272452724627247272482724927250272512725227253272542725527256272572725827259272602726127262272632726427265272662726727268272692727027271272722727327274272752727627277272782727927280272812728227283272842728527286272872728827289272902729127292272932729427295272962729727298272992730027301273022730327304273052730627307273082730927310273112731227313273142731527316273172731827319273202732127322273232732427325273262732727328273292733027331273322733327334273352733627337273382733927340273412734227343273442734527346273472734827349273502735127352273532735427355273562735727358273592736027361273622736327364273652736627367273682736927370273712737227373273742737527376273772737827379273802738127382273832738427385273862738727388273892739027391273922739327394273952739627397273982739927400274012740227403274042740527406274072740827409274102741127412274132741427415274162741727418274192742027421274222742327424274252742627427274282742927430274312743227433274342743527436274372743827439274402744127442274432744427445274462744727448274492745027451274522745327454274552745627457274582745927460274612746227463274642746527466274672746827469274702747127472274732747427475274762747727478274792748027481274822748327484274852748627487274882748927490274912749227493274942749527496274972749827499275002750127502275032750427505275062750727508275092751027511275122751327514275152751627517275182751927520275212752227523275242752527526275272752827529275302753127532275332753427535275362753727538275392754027541275422754327544275452754627547275482754927550275512755227553275542755527556275572755827559275602756127562275632756427565275662756727568275692757027571275722757327574275752757627577275782757927580275812758227583275842758527586275872758827589275902759127592275932759427595275962759727598275992760027601276022760327604276052760627607276082760927610276112761227613276142761527616276172761827619276202762127622276232762427625276262762727628276292763027631276322763327634276352763627637276382763927640276412764227643276442764527646276472764827649276502765127652276532765427655276562765727658276592766027661276622766327664276652766627667276682766927670276712767227673276742767527676276772767827679276802768127682276832768427685276862768727688276892769027691276922769327694276952769627697276982769927700277012770227703277042770527706277072770827709277102771127712277132771427715277162771727718277192772027721277222772327724277252772627727277282772927730277312773227733277342773527736277372773827739277402774127742277432774427745277462774727748277492775027751277522775327754277552775627757277582775927760277612776227763277642776527766277672776827769277702777127772277732777427775277762777727778277792778027781277822778327784277852778627787277882778927790277912779227793277942779527796277972779827799278002780127802278032780427805278062780727808278092781027811278122781327814278152781627817278182781927820278212782227823278242782527826278272782827829278302783127832278332783427835278362783727838278392784027841278422784327844278452784627847278482784927850278512785227853278542785527856278572785827859278602786127862278632786427865278662786727868278692787027871278722787327874278752787627877278782787927880278812788227883278842788527886278872788827889278902789127892278932789427895278962789727898278992790027901279022790327904279052790627907279082790927910279112791227913279142791527916279172791827919279202792127922279232792427925279262792727928279292793027931279322793327934279352793627937279382793927940279412794227943279442794527946279472794827949279502795127952279532795427955279562795727958279592796027961279622796327964279652796627967279682796927970279712797227973279742797527976279772797827979279802798127982279832798427985279862798727988279892799027991279922799327994279952799627997279982799928000280012800228003280042800528006280072800828009280102801128012280132801428015280162801728018280192802028021280222802328024280252802628027280282802928030280312803228033280342803528036280372803828039280402804128042280432804428045280462804728048280492805028051280522805328054280552805628057280582805928060280612806228063280642806528066280672806828069280702807128072280732807428075280762807728078280792808028081280822808328084280852808628087280882808928090280912809228093280942809528096280972809828099281002810128102281032810428105281062810728108281092811028111281122811328114281152811628117281182811928120281212812228123281242812528126281272812828129281302813128132281332813428135281362813728138281392814028141281422814328144281452814628147281482814928150281512815228153281542815528156281572815828159281602816128162281632816428165281662816728168281692817028171281722817328174281752817628177281782817928180281812818228183281842818528186281872818828189281902819128192281932819428195281962819728198281992820028201282022820328204282052820628207282082820928210282112821228213282142821528216282172821828219282202822128222282232822428225282262822728228282292823028231282322823328234282352823628237282382823928240282412824228243282442824528246282472824828249282502825128252282532825428255282562825728258282592826028261282622826328264282652826628267282682826928270282712827228273282742827528276282772827828279282802828128282282832828428285282862828728288282892829028291282922829328294282952829628297282982829928300283012830228303283042830528306283072830828309283102831128312283132831428315283162831728318283192832028321283222832328324283252832628327283282832928330283312833228333283342833528336283372833828339283402834128342283432834428345283462834728348283492835028351283522835328354283552835628357283582835928360283612836228363283642836528366283672836828369283702837128372283732837428375283762837728378283792838028381283822838328384283852838628387283882838928390283912839228393283942839528396283972839828399284002840128402284032840428405284062840728408284092841028411284122841328414284152841628417284182841928420284212842228423284242842528426284272842828429284302843128432284332843428435284362843728438284392844028441284422844328444284452844628447284482844928450284512845228453284542845528456284572845828459284602846128462284632846428465284662846728468284692847028471284722847328474284752847628477284782847928480284812848228483284842848528486284872848828489284902849128492284932849428495284962849728498284992850028501285022850328504285052850628507285082850928510285112851228513285142851528516285172851828519285202852128522285232852428525285262852728528285292853028531285322853328534285352853628537285382853928540285412854228543285442854528546285472854828549285502855128552285532855428555285562855728558285592856028561285622856328564285652856628567285682856928570285712857228573285742857528576285772857828579285802858128582285832858428585285862858728588285892859028591285922859328594285952859628597285982859928600286012860228603286042860528606286072860828609286102861128612286132861428615286162861728618286192862028621286222862328624286252862628627286282862928630286312863228633286342863528636286372863828639286402864128642286432864428645286462864728648286492865028651286522865328654286552865628657286582865928660286612866228663286642866528666286672866828669286702867128672286732867428675286762867728678286792868028681286822868328684286852868628687286882868928690286912869228693286942869528696286972869828699287002870128702287032870428705287062870728708287092871028711287122871328714287152871628717287182871928720287212872228723287242872528726287272872828729287302873128732287332873428735287362873728738287392874028741287422874328744287452874628747287482874928750287512875228753287542875528756287572875828759287602876128762287632876428765287662876728768287692877028771287722877328774287752877628777287782877928780287812878228783287842878528786287872878828789287902879128792287932879428795287962879728798287992880028801288022880328804288052880628807288082880928810288112881228813288142881528816288172881828819288202882128822288232882428825288262882728828288292883028831288322883328834288352883628837288382883928840288412884228843288442884528846288472884828849288502885128852288532885428855288562885728858288592886028861288622886328864288652886628867288682886928870288712887228873288742887528876288772887828879288802888128882288832888428885288862888728888288892889028891288922889328894288952889628897288982889928900289012890228903289042890528906289072890828909289102891128912289132891428915289162891728918289192892028921289222892328924289252892628927289282892928930289312893228933289342893528936289372893828939289402894128942289432894428945289462894728948289492895028951289522895328954289552895628957289582895928960289612896228963289642896528966289672896828969289702897128972289732897428975289762897728978289792898028981289822898328984289852898628987289882898928990289912899228993289942899528996289972899828999290002900129002290032900429005290062900729008290092901029011290122901329014290152901629017290182901929020290212902229023290242902529026290272902829029290302903129032290332903429035290362903729038290392904029041290422904329044290452904629047290482904929050290512905229053290542905529056290572905829059290602906129062290632906429065290662906729068290692907029071290722907329074290752907629077290782907929080290812908229083290842908529086290872908829089290902909129092290932909429095290962909729098290992910029101291022910329104291052910629107291082910929110291112911229113291142911529116291172911829119291202912129122291232912429125291262912729128291292913029131291322913329134291352913629137291382913929140291412914229143291442914529146291472914829149291502915129152291532915429155291562915729158291592916029161291622916329164291652916629167291682916929170291712917229173291742917529176291772917829179291802918129182291832918429185291862918729188291892919029191291922919329194291952919629197291982919929200292012920229203292042920529206292072920829209292102921129212292132921429215292162921729218292192922029221292222922329224292252922629227292282922929230292312923229233292342923529236292372923829239292402924129242292432924429245292462924729248292492925029251292522925329254292552925629257292582925929260292612926229263292642926529266292672926829269292702927129272292732927429275292762927729278292792928029281292822928329284292852928629287292882928929290292912929229293292942929529296292972929829299293002930129302293032930429305293062930729308293092931029311293122931329314293152931629317293182931929320293212932229323293242932529326293272932829329293302933129332293332933429335293362933729338293392934029341293422934329344293452934629347293482934929350293512935229353293542935529356293572935829359293602936129362293632936429365293662936729368293692937029371293722937329374293752937629377293782937929380293812938229383293842938529386293872938829389293902939129392293932939429395293962939729398293992940029401294022940329404294052940629407294082940929410294112941229413294142941529416294172941829419294202942129422294232942429425294262942729428294292943029431294322943329434294352943629437294382943929440294412944229443294442944529446294472944829449294502945129452294532945429455294562945729458294592946029461294622946329464294652946629467294682946929470294712947229473294742947529476294772947829479294802948129482294832948429485294862948729488294892949029491294922949329494294952949629497294982949929500295012950229503295042950529506295072950829509295102951129512295132951429515295162951729518295192952029521295222952329524295252952629527295282952929530295312953229533295342953529536295372953829539295402954129542295432954429545295462954729548295492955029551295522955329554295552955629557295582955929560295612956229563295642956529566295672956829569295702957129572295732957429575295762957729578295792958029581295822958329584295852958629587295882958929590295912959229593295942959529596295972959829599296002960129602296032960429605296062960729608296092961029611296122961329614296152961629617296182961929620296212962229623296242962529626296272962829629296302963129632296332963429635296362963729638296392964029641296422964329644296452964629647296482964929650296512965229653296542965529656296572965829659296602966129662296632966429665296662966729668296692967029671296722967329674296752967629677296782967929680296812968229683296842968529686296872968829689296902969129692296932969429695296962969729698296992970029701297022970329704297052970629707297082970929710297112971229713297142971529716297172971829719297202972129722297232972429725297262972729728297292973029731297322973329734297352973629737297382973929740297412974229743297442974529746297472974829749297502975129752297532975429755297562975729758297592976029761297622976329764297652976629767297682976929770297712977229773297742977529776297772977829779297802978129782297832978429785297862978729788297892979029791297922979329794297952979629797297982979929800298012980229803298042980529806298072980829809298102981129812298132981429815298162981729818298192982029821298222982329824298252982629827298282982929830298312983229833298342983529836298372983829839298402984129842298432984429845298462984729848298492985029851298522985329854298552985629857298582985929860298612986229863298642986529866298672986829869298702987129872298732987429875298762987729878298792988029881298822988329884298852988629887298882988929890298912989229893298942989529896298972989829899299002990129902299032990429905299062990729908299092991029911299122991329914299152991629917299182991929920299212992229923299242992529926299272992829929299302993129932299332993429935299362993729938299392994029941299422994329944299452994629947299482994929950299512995229953299542995529956299572995829959299602996129962299632996429965299662996729968299692997029971299722997329974299752997629977299782997929980299812998229983299842998529986299872998829989299902999129992299932999429995299962999729998299993000030001300023000330004300053000630007300083000930010300113001230013300143001530016300173001830019300203002130022300233002430025300263002730028300293003030031300323003330034300353003630037300383003930040300413004230043300443004530046300473004830049300503005130052300533005430055300563005730058300593006030061300623006330064300653006630067300683006930070300713007230073300743007530076300773007830079300803008130082300833008430085300863008730088300893009030091300923009330094300953009630097300983009930100301013010230103301043010530106301073010830109301103011130112301133011430115301163011730118301193012030121301223012330124301253012630127301283012930130301313013230133301343013530136301373013830139301403014130142301433014430145301463014730148301493015030151301523015330154301553015630157301583015930160301613016230163301643016530166301673016830169301703017130172301733017430175301763017730178301793018030181301823018330184301853018630187301883018930190301913019230193301943019530196301973019830199302003020130202302033020430205302063020730208302093021030211302123021330214302153021630217302183021930220302213022230223302243022530226302273022830229302303023130232302333023430235302363023730238302393024030241302423024330244302453024630247302483024930250302513025230253302543025530256302573025830259302603026130262302633026430265302663026730268302693027030271302723027330274302753027630277302783027930280302813028230283302843028530286302873028830289302903029130292302933029430295302963029730298302993030030301303023030330304303053030630307303083030930310303113031230313303143031530316303173031830319303203032130322303233032430325303263032730328303293033030331303323033330334303353033630337303383033930340303413034230343303443034530346303473034830349303503035130352303533035430355303563035730358303593036030361303623036330364303653036630367303683036930370303713037230373303743037530376303773037830379303803038130382303833038430385303863038730388303893039030391303923039330394303953039630397303983039930400304013040230403304043040530406304073040830409304103041130412304133041430415304163041730418304193042030421304223042330424304253042630427304283042930430304313043230433304343043530436304373043830439304403044130442304433044430445304463044730448304493045030451304523045330454304553045630457304583045930460304613046230463304643046530466304673046830469304703047130472304733047430475304763047730478304793048030481304823048330484304853048630487304883048930490304913049230493304943049530496304973049830499305003050130502305033050430505305063050730508305093051030511305123051330514305153051630517305183051930520305213052230523305243052530526305273052830529305303053130532305333053430535305363053730538305393054030541305423054330544305453054630547305483054930550305513055230553305543055530556305573055830559305603056130562305633056430565305663056730568305693057030571305723057330574305753057630577305783057930580305813058230583305843058530586305873058830589305903059130592305933059430595305963059730598305993060030601306023060330604306053060630607306083060930610306113061230613306143061530616306173061830619306203062130622306233062430625306263062730628306293063030631306323063330634306353063630637306383063930640306413064230643306443064530646306473064830649306503065130652306533065430655306563065730658306593066030661306623066330664306653066630667306683066930670306713067230673306743067530676306773067830679306803068130682306833068430685306863068730688306893069030691306923069330694306953069630697306983069930700307013070230703307043070530706307073070830709307103071130712307133071430715307163071730718307193072030721307223072330724307253072630727307283072930730307313073230733307343073530736307373073830739307403074130742307433074430745307463074730748307493075030751307523075330754307553075630757307583075930760307613076230763307643076530766307673076830769307703077130772307733077430775307763077730778307793078030781307823078330784307853078630787307883078930790307913079230793307943079530796307973079830799308003080130802308033080430805308063080730808308093081030811308123081330814308153081630817308183081930820308213082230823308243082530826308273082830829308303083130832308333083430835308363083730838308393084030841308423084330844308453084630847308483084930850308513085230853308543085530856308573085830859308603086130862308633086430865308663086730868308693087030871308723087330874308753087630877308783087930880308813088230883308843088530886308873088830889308903089130892308933089430895308963089730898308993090030901309023090330904309053090630907309083090930910309113091230913309143091530916309173091830919309203092130922309233092430925309263092730928309293093030931309323093330934309353093630937309383093930940309413094230943309443094530946309473094830949309503095130952309533095430955309563095730958309593096030961309623096330964309653096630967309683096930970309713097230973309743097530976309773097830979309803098130982309833098430985309863098730988309893099030991309923099330994309953099630997309983099931000310013100231003310043100531006310073100831009310103101131012310133101431015310163101731018310193102031021310223102331024310253102631027310283102931030310313103231033310343103531036310373103831039310403104131042310433104431045310463104731048310493105031051310523105331054310553105631057310583105931060310613106231063310643106531066310673106831069310703107131072310733107431075310763107731078310793108031081310823108331084310853108631087310883108931090310913109231093310943109531096310973109831099311003110131102311033110431105311063110731108311093111031111311123111331114311153111631117311183111931120311213112231123311243112531126311273112831129311303113131132311333113431135311363113731138311393114031141311423114331144311453114631147311483114931150311513115231153311543115531156311573115831159311603116131162311633116431165311663116731168311693117031171311723117331174311753117631177311783117931180311813118231183311843118531186311873118831189311903119131192311933119431195311963119731198311993120031201312023120331204312053120631207312083120931210312113121231213312143121531216312173121831219312203122131222312233122431225312263122731228312293123031231312323123331234312353123631237312383123931240312413124231243312443124531246312473124831249312503125131252312533125431255312563125731258312593126031261312623126331264312653126631267312683126931270312713127231273312743127531276312773127831279312803128131282312833128431285312863128731288312893129031291312923129331294312953129631297312983129931300313013130231303313043130531306313073130831309313103131131312313133131431315313163131731318313193132031321313223132331324313253132631327313283132931330313313133231333313343133531336313373133831339313403134131342313433134431345313463134731348313493135031351313523135331354313553135631357313583135931360313613136231363313643136531366313673136831369313703137131372313733137431375313763137731378313793138031381313823138331384313853138631387313883138931390313913139231393313943139531396313973139831399314003140131402314033140431405314063140731408314093141031411314123141331414314153141631417314183141931420314213142231423314243142531426314273142831429314303143131432314333143431435314363143731438314393144031441314423144331444314453144631447314483144931450314513145231453314543145531456314573145831459314603146131462314633146431465314663146731468314693147031471314723147331474314753147631477314783147931480314813148231483314843148531486314873148831489314903149131492314933149431495314963149731498314993150031501315023150331504315053150631507315083150931510315113151231513315143151531516315173151831519315203152131522315233152431525315263152731528315293153031531315323153331534315353153631537315383153931540315413154231543315443154531546315473154831549315503155131552315533155431555315563155731558315593156031561315623156331564315653156631567315683156931570315713157231573315743157531576315773157831579315803158131582315833158431585315863158731588315893159031591315923159331594315953159631597315983159931600316013160231603316043160531606316073160831609316103161131612316133161431615316163161731618316193162031621316223162331624316253162631627316283162931630316313163231633316343163531636316373163831639316403164131642316433164431645316463164731648316493165031651316523165331654316553165631657316583165931660316613166231663316643166531666316673166831669316703167131672316733167431675316763167731678316793168031681316823168331684316853168631687316883168931690316913169231693316943169531696316973169831699317003170131702317033170431705317063170731708317093171031711317123171331714317153171631717317183171931720317213172231723317243172531726317273172831729317303173131732317333173431735317363173731738317393174031741317423174331744317453174631747317483174931750317513175231753317543175531756317573175831759317603176131762317633176431765317663176731768317693177031771317723177331774317753177631777317783177931780317813178231783317843178531786317873178831789317903179131792317933179431795317963179731798317993180031801318023180331804318053180631807318083180931810318113181231813318143181531816318173181831819318203182131822318233182431825318263182731828318293183031831318323183331834318353183631837318383183931840318413184231843318443184531846318473184831849318503185131852318533185431855318563185731858318593186031861318623186331864318653186631867318683186931870318713187231873318743187531876318773187831879318803188131882318833188431885318863188731888318893189031891318923189331894318953189631897318983189931900319013190231903319043190531906319073190831909319103191131912319133191431915319163191731918319193192031921319223192331924319253192631927319283192931930319313193231933319343193531936319373193831939319403194131942319433194431945319463194731948319493195031951319523195331954319553195631957319583195931960319613196231963319643196531966319673196831969319703197131972319733197431975319763197731978319793198031981319823198331984319853198631987319883198931990319913199231993319943199531996319973199831999320003200132002320033200432005320063200732008320093201032011320123201332014320153201632017320183201932020320213202232023320243202532026320273202832029320303203132032320333203432035320363203732038320393204032041320423204332044320453204632047320483204932050320513205232053320543205532056320573205832059320603206132062320633206432065320663206732068320693207032071320723207332074320753207632077320783207932080320813208232083320843208532086320873208832089320903209132092320933209432095320963209732098320993210032101321023210332104321053210632107321083210932110321113211232113321143211532116321173211832119321203212132122321233212432125321263212732128321293213032131321323213332134321353213632137321383213932140321413214232143321443214532146321473214832149321503215132152321533215432155321563215732158321593216032161321623216332164321653216632167321683216932170321713217232173321743217532176321773217832179321803218132182321833218432185321863218732188321893219032191321923219332194321953219632197321983219932200322013220232203322043220532206322073220832209322103221132212322133221432215322163221732218322193222032221322223222332224322253222632227322283222932230322313223232233322343223532236322373223832239322403224132242322433224432245322463224732248322493225032251322523225332254322553225632257322583225932260322613226232263322643226532266322673226832269322703227132272322733227432275322763227732278322793228032281322823228332284322853228632287322883228932290322913229232293322943229532296322973229832299323003230132302323033230432305323063230732308323093231032311323123231332314323153231632317323183231932320323213232232323323243232532326323273232832329323303233132332323333233432335323363233732338323393234032341323423234332344323453234632347323483234932350323513235232353323543235532356323573235832359323603236132362323633236432365323663236732368323693237032371323723237332374323753237632377323783237932380323813238232383323843238532386323873238832389323903239132392323933239432395323963239732398323993240032401324023240332404324053240632407324083240932410324113241232413324143241532416324173241832419324203242132422324233242432425324263242732428324293243032431324323243332434324353243632437324383243932440324413244232443324443244532446324473244832449324503245132452324533245432455324563245732458324593246032461324623246332464324653246632467324683246932470324713247232473324743247532476324773247832479324803248132482324833248432485324863248732488324893249032491324923249332494324953249632497324983249932500325013250232503325043250532506325073250832509325103251132512325133251432515325163251732518325193252032521325223252332524325253252632527325283252932530325313253232533325343253532536325373253832539325403254132542325433254432545325463254732548325493255032551325523255332554325553255632557325583255932560325613256232563325643256532566325673256832569325703257132572325733257432575325763257732578325793258032581325823258332584325853258632587325883258932590325913259232593325943259532596325973259832599326003260132602326033260432605326063260732608326093261032611326123261332614326153261632617326183261932620326213262232623326243262532626326273262832629326303263132632326333263432635326363263732638326393264032641326423264332644326453264632647326483264932650326513265232653326543265532656326573265832659326603266132662326633266432665326663266732668326693267032671326723267332674326753267632677326783267932680326813268232683326843268532686326873268832689326903269132692326933269432695326963269732698326993270032701327023270332704327053270632707327083270932710327113271232713327143271532716327173271832719327203272132722327233272432725327263272732728327293273032731327323273332734327353273632737327383273932740327413274232743327443274532746327473274832749327503275132752327533275432755327563275732758327593276032761327623276332764327653276632767327683276932770327713277232773327743277532776327773277832779327803278132782327833278432785327863278732788327893279032791327923279332794327953279632797327983279932800328013280232803328043280532806328073280832809328103281132812328133281432815328163281732818328193282032821328223282332824328253282632827328283282932830328313283232833328343283532836328373283832839328403284132842328433284432845328463284732848328493285032851328523285332854328553285632857328583285932860328613286232863328643286532866328673286832869328703287132872328733287432875328763287732878328793288032881328823288332884328853288632887328883288932890328913289232893328943289532896328973289832899329003290132902329033290432905329063290732908329093291032911329123291332914329153291632917329183291932920329213292232923329243292532926329273292832929329303293132932329333293432935329363293732938329393294032941329423294332944329453294632947329483294932950329513295232953329543295532956329573295832959329603296132962329633296432965329663296732968329693297032971329723297332974329753297632977329783297932980329813298232983329843298532986329873298832989329903299132992329933299432995329963299732998329993300033001330023300333004330053300633007330083300933010330113301233013330143301533016330173301833019330203302133022330233302433025330263302733028330293303033031330323303333034330353303633037330383303933040330413304233043330443304533046330473304833049330503305133052330533305433055330563305733058330593306033061330623306333064330653306633067330683306933070330713307233073330743307533076330773307833079330803308133082330833308433085330863308733088330893309033091330923309333094330953309633097330983309933100331013310233103331043310533106331073310833109331103311133112331133311433115331163311733118331193312033121331223312333124331253312633127331283312933130331313313233133331343313533136331373313833139331403314133142331433314433145331463314733148331493315033151331523315333154331553315633157331583315933160331613316233163331643316533166331673316833169331703317133172331733317433175331763317733178331793318033181331823318333184331853318633187331883318933190331913319233193331943319533196331973319833199332003320133202332033320433205332063320733208332093321033211332123321333214332153321633217332183321933220332213322233223332243322533226332273322833229332303323133232332333323433235332363323733238332393324033241332423324333244332453324633247332483324933250332513325233253332543325533256332573325833259332603326133262332633326433265332663326733268332693327033271332723327333274332753327633277332783327933280332813328233283332843328533286332873328833289332903329133292332933329433295332963329733298332993330033301333023330333304333053330633307333083330933310333113331233313333143331533316333173331833319333203332133322333233332433325333263332733328333293333033331333323333333334333353333633337333383333933340333413334233343333443334533346333473334833349333503335133352333533335433355333563335733358333593336033361333623336333364333653336633367333683336933370333713337233373333743337533376333773337833379333803338133382333833338433385333863338733388333893339033391333923339333394333953339633397333983339933400334013340233403334043340533406334073340833409334103341133412334133341433415334163341733418334193342033421334223342333424334253342633427334283342933430334313343233433334343343533436334373343833439334403344133442334433344433445334463344733448334493345033451334523345333454334553345633457334583345933460334613346233463334643346533466334673346833469334703347133472334733347433475334763347733478334793348033481334823348333484334853348633487334883348933490334913349233493334943349533496334973349833499335003350133502335033350433505335063350733508335093351033511335123351333514335153351633517335183351933520335213352233523335243352533526335273352833529335303353133532335333353433535335363353733538335393354033541335423354333544335453354633547335483354933550335513355233553335543355533556335573355833559335603356133562335633356433565335663356733568335693357033571335723357333574335753357633577335783357933580335813358233583335843358533586335873358833589335903359133592335933359433595335963359733598335993360033601336023360333604336053360633607336083360933610336113361233613336143361533616336173361833619336203362133622336233362433625336263362733628336293363033631336323363333634336353363633637336383363933640336413364233643336443364533646336473364833649336503365133652336533365433655336563365733658336593366033661336623366333664336653366633667336683366933670336713367233673336743367533676336773367833679336803368133682336833368433685336863368733688336893369033691336923369333694336953369633697336983369933700337013370233703337043370533706337073370833709337103371133712337133371433715337163371733718337193372033721337223372333724337253372633727337283372933730337313373233733337343373533736337373373833739337403374133742337433374433745337463374733748337493375033751337523375333754337553375633757337583375933760337613376233763337643376533766337673376833769337703377133772337733377433775337763377733778337793378033781337823378333784337853378633787337883378933790337913379233793337943379533796337973379833799338003380133802338033380433805338063380733808338093381033811338123381333814338153381633817338183381933820338213382233823338243382533826338273382833829338303383133832338333383433835338363383733838338393384033841338423384333844338453384633847338483384933850338513385233853338543385533856338573385833859338603386133862338633386433865338663386733868338693387033871338723387333874338753387633877338783387933880338813388233883338843388533886338873388833889338903389133892338933389433895338963389733898338993390033901339023390333904339053390633907339083390933910339113391233913339143391533916339173391833919339203392133922339233392433925339263392733928339293393033931339323393333934339353393633937339383393933940339413394233943339443394533946339473394833949339503395133952339533395433955339563395733958339593396033961339623396333964339653396633967339683396933970339713397233973339743397533976339773397833979339803398133982339833398433985339863398733988339893399033991339923399333994339953399633997339983399934000340013400234003340043400534006340073400834009340103401134012340133401434015340163401734018340193402034021340223402334024340253402634027340283402934030340313403234033340343403534036340373403834039340403404134042340433404434045340463404734048340493405034051340523405334054340553405634057340583405934060340613406234063340643406534066340673406834069340703407134072340733407434075340763407734078340793408034081340823408334084340853408634087340883408934090340913409234093340943409534096340973409834099341003410134102341033410434105341063410734108341093411034111341123411334114341153411634117341183411934120341213412234123341243412534126341273412834129341303413134132341333413434135341363413734138341393414034141341423414334144341453414634147341483414934150341513415234153341543415534156341573415834159341603416134162341633416434165341663416734168341693417034171341723417334174341753417634177341783417934180341813418234183341843418534186341873418834189341903419134192341933419434195341963419734198341993420034201342023420334204342053420634207342083420934210342113421234213342143421534216342173421834219342203422134222342233422434225342263422734228342293423034231342323423334234342353423634237342383423934240342413424234243342443424534246342473424834249342503425134252342533425434255342563425734258342593426034261342623426334264342653426634267342683426934270342713427234273342743427534276342773427834279342803428134282342833428434285342863428734288342893429034291342923429334294342953429634297342983429934300343013430234303343043430534306343073430834309343103431134312343133431434315343163431734318343193432034321343223432334324343253432634327343283432934330343313433234333343343433534336343373433834339343403434134342343433434434345343463434734348343493435034351343523435334354343553435634357343583435934360343613436234363343643436534366343673436834369343703437134372343733437434375343763437734378343793438034381343823438334384343853438634387343883438934390343913439234393343943439534396343973439834399344003440134402344033440434405344063440734408344093441034411344123441334414344153441634417344183441934420344213442234423344243442534426344273442834429344303443134432344333443434435344363443734438344393444034441344423444334444344453444634447344483444934450344513445234453344543445534456344573445834459344603446134462344633446434465344663446734468344693447034471344723447334474344753447634477344783447934480344813448234483344843448534486344873448834489344903449134492344933449434495344963449734498344993450034501345023450334504345053450634507345083450934510345113451234513345143451534516345173451834519345203452134522345233452434525345263452734528345293453034531345323453334534345353453634537345383453934540345413454234543345443454534546345473454834549345503455134552345533455434555345563455734558345593456034561345623456334564345653456634567345683456934570345713457234573345743457534576345773457834579345803458134582345833458434585345863458734588345893459034591345923459334594345953459634597345983459934600346013460234603346043460534606346073460834609346103461134612346133461434615346163461734618346193462034621346223462334624346253462634627346283462934630346313463234633346343463534636346373463834639346403464134642346433464434645346463464734648346493465034651346523465334654346553465634657346583465934660346613466234663346643466534666346673466834669346703467134672346733467434675346763467734678346793468034681346823468334684346853468634687346883468934690346913469234693346943469534696346973469834699347003470134702347033470434705347063470734708347093471034711347123471334714347153471634717347183471934720347213472234723347243472534726347273472834729347303473134732347333473434735347363473734738347393474034741347423474334744347453474634747347483474934750347513475234753347543475534756347573475834759347603476134762347633476434765347663476734768347693477034771347723477334774347753477634777347783477934780347813478234783347843478534786347873478834789347903479134792347933479434795347963479734798347993480034801348023480334804348053480634807348083480934810348113481234813348143481534816348173481834819348203482134822348233482434825348263482734828348293483034831348323483334834348353483634837348383483934840348413484234843348443484534846348473484834849348503485134852348533485434855348563485734858348593486034861348623486334864348653486634867348683486934870348713487234873348743487534876348773487834879348803488134882348833488434885348863488734888348893489034891348923489334894348953489634897348983489934900349013490234903349043490534906349073490834909349103491134912349133491434915349163491734918349193492034921349223492334924349253492634927349283492934930349313493234933349343493534936349373493834939349403494134942349433494434945349463494734948349493495034951349523495334954349553495634957349583495934960349613496234963349643496534966349673496834969349703497134972349733497434975349763497734978349793498034981349823498334984349853498634987349883498934990349913499234993349943499534996349973499834999350003500135002350033500435005350063500735008350093501035011350123501335014350153501635017350183501935020350213502235023350243502535026350273502835029350303503135032350333503435035350363503735038350393504035041350423504335044350453504635047350483504935050350513505235053350543505535056350573505835059350603506135062350633506435065350663506735068350693507035071350723507335074350753507635077350783507935080350813508235083350843508535086350873508835089350903509135092350933509435095350963509735098350993510035101351023510335104351053510635107351083510935110351113511235113351143511535116351173511835119351203512135122351233512435125351263512735128351293513035131351323513335134351353513635137351383513935140351413514235143351443514535146351473514835149351503515135152351533515435155351563515735158351593516035161351623516335164351653516635167351683516935170351713517235173351743517535176351773517835179351803518135182351833518435185351863518735188351893519035191351923519335194351953519635197351983519935200352013520235203352043520535206352073520835209352103521135212352133521435215352163521735218352193522035221352223522335224352253522635227352283522935230352313523235233352343523535236352373523835239352403524135242352433524435245352463524735248352493525035251352523525335254352553525635257352583525935260352613526235263352643526535266352673526835269352703527135272352733527435275352763527735278352793528035281352823528335284352853528635287352883528935290352913529235293352943529535296352973529835299353003530135302353033530435305353063530735308353093531035311353123531335314353153531635317353183531935320353213532235323353243532535326353273532835329353303533135332353333533435335353363533735338353393534035341353423534335344353453534635347353483534935350353513535235353353543535535356353573535835359353603536135362353633536435365353663536735368353693537035371353723537335374353753537635377353783537935380353813538235383353843538535386353873538835389353903539135392353933539435395353963539735398353993540035401354023540335404354053540635407354083540935410354113541235413354143541535416354173541835419354203542135422354233542435425354263542735428354293543035431354323543335434354353543635437354383543935440354413544235443354443544535446354473544835449354503545135452354533545435455354563545735458354593546035461354623546335464354653546635467354683546935470354713547235473354743547535476354773547835479354803548135482354833548435485354863548735488354893549035491354923549335494354953549635497354983549935500355013550235503355043550535506355073550835509355103551135512355133551435515355163551735518355193552035521355223552335524355253552635527355283552935530355313553235533355343553535536355373553835539355403554135542355433554435545355463554735548355493555035551355523555335554355553555635557355583555935560355613556235563355643556535566355673556835569355703557135572355733557435575355763557735578355793558035581355823558335584355853558635587355883558935590355913559235593355943559535596355973559835599356003560135602356033560435605356063560735608356093561035611356123561335614356153561635617356183561935620356213562235623356243562535626356273562835629356303563135632356333563435635356363563735638356393564035641356423564335644356453564635647356483564935650356513565235653356543565535656356573565835659356603566135662356633566435665356663566735668356693567035671356723567335674356753567635677356783567935680356813568235683356843568535686356873568835689356903569135692356933569435695356963569735698356993570035701357023570335704357053570635707357083570935710357113571235713357143571535716357173571835719357203572135722357233572435725357263572735728357293573035731357323573335734357353573635737357383573935740357413574235743357443574535746357473574835749357503575135752357533575435755357563575735758357593576035761357623576335764357653576635767357683576935770357713577235773357743577535776357773577835779357803578135782357833578435785357863578735788357893579035791357923579335794357953579635797357983579935800358013580235803358043580535806358073580835809358103581135812358133581435815358163581735818358193582035821358223582335824358253582635827358283582935830358313583235833358343583535836358373583835839358403584135842358433584435845358463584735848358493585035851358523585335854358553585635857358583585935860358613586235863358643586535866358673586835869358703587135872358733587435875358763587735878358793588035881358823588335884358853588635887358883588935890358913589235893358943589535896358973589835899359003590135902359033590435905359063590735908359093591035911359123591335914359153591635917359183591935920359213592235923359243592535926359273592835929359303593135932359333593435935359363593735938359393594035941359423594335944359453594635947359483594935950359513595235953359543595535956359573595835959359603596135962359633596435965359663596735968359693597035971359723597335974359753597635977359783597935980359813598235983359843598535986359873598835989359903599135992359933599435995359963599735998359993600036001360023600336004360053600636007360083600936010360113601236013360143601536016360173601836019360203602136022360233602436025360263602736028360293603036031360323603336034360353603636037360383603936040360413604236043360443604536046360473604836049360503605136052360533605436055360563605736058360593606036061360623606336064360653606636067360683606936070360713607236073360743607536076360773607836079360803608136082360833608436085360863608736088360893609036091360923609336094360953609636097360983609936100361013610236103361043610536106361073610836109361103611136112361133611436115361163611736118361193612036121361223612336124361253612636127361283612936130361313613236133361343613536136361373613836139361403614136142361433614436145361463614736148361493615036151361523615336154361553615636157361583615936160361613616236163361643616536166361673616836169361703617136172361733617436175361763617736178361793618036181361823618336184361853618636187361883618936190361913619236193361943619536196361973619836199362003620136202362033620436205362063620736208362093621036211362123621336214362153621636217362183621936220362213622236223362243622536226362273622836229362303623136232362333623436235362363623736238362393624036241362423624336244362453624636247362483624936250362513625236253362543625536256362573625836259362603626136262362633626436265362663626736268362693627036271362723627336274362753627636277362783627936280362813628236283362843628536286362873628836289362903629136292362933629436295362963629736298362993630036301363023630336304363053630636307363083630936310363113631236313363143631536316363173631836319363203632136322363233632436325363263632736328363293633036331363323633336334363353633636337363383633936340363413634236343363443634536346363473634836349363503635136352363533635436355363563635736358363593636036361363623636336364363653636636367363683636936370363713637236373363743637536376363773637836379363803638136382363833638436385363863638736388363893639036391363923639336394363953639636397363983639936400364013640236403364043640536406364073640836409364103641136412364133641436415364163641736418364193642036421364223642336424364253642636427364283642936430364313643236433364343643536436364373643836439364403644136442364433644436445364463644736448364493645036451364523645336454364553645636457364583645936460364613646236463364643646536466364673646836469364703647136472364733647436475364763647736478364793648036481364823648336484364853648636487364883648936490364913649236493364943649536496364973649836499365003650136502365033650436505365063650736508365093651036511365123651336514365153651636517365183651936520365213652236523365243652536526365273652836529365303653136532365333653436535365363653736538365393654036541365423654336544365453654636547365483654936550365513655236553365543655536556365573655836559365603656136562365633656436565365663656736568365693657036571365723657336574365753657636577365783657936580365813658236583365843658536586365873658836589365903659136592365933659436595365963659736598365993660036601366023660336604366053660636607366083660936610366113661236613366143661536616366173661836619366203662136622366233662436625366263662736628366293663036631366323663336634366353663636637366383663936640366413664236643366443664536646366473664836649366503665136652366533665436655366563665736658366593666036661366623666336664366653666636667366683666936670366713667236673366743667536676366773667836679366803668136682366833668436685366863668736688366893669036691366923669336694366953669636697366983669936700367013670236703367043670536706367073670836709367103671136712367133671436715367163671736718367193672036721367223672336724367253672636727367283672936730367313673236733367343673536736367373673836739367403674136742367433674436745367463674736748367493675036751367523675336754367553675636757367583675936760367613676236763367643676536766367673676836769367703677136772367733677436775367763677736778367793678036781367823678336784367853678636787367883678936790367913679236793367943679536796367973679836799368003680136802368033680436805368063680736808368093681036811368123681336814368153681636817368183681936820368213682236823368243682536826368273682836829368303683136832368333683436835368363683736838368393684036841368423684336844368453684636847368483684936850368513685236853368543685536856368573685836859368603686136862368633686436865368663686736868368693687036871368723687336874368753687636877368783687936880368813688236883368843688536886368873688836889368903689136892368933689436895368963689736898368993690036901369023690336904369053690636907369083690936910369113691236913369143691536916369173691836919369203692136922369233692436925369263692736928369293693036931369323693336934369353693636937369383693936940369413694236943369443694536946369473694836949369503695136952369533695436955369563695736958369593696036961369623696336964369653696636967369683696936970369713697236973369743697536976369773697836979369803698136982369833698436985369863698736988369893699036991369923699336994369953699636997369983699937000370013700237003370043700537006370073700837009370103701137012370133701437015370163701737018370193702037021370223702337024370253702637027370283702937030370313703237033370343703537036370373703837039370403704137042370433704437045370463704737048370493705037051370523705337054370553705637057370583705937060370613706237063370643706537066370673706837069370703707137072370733707437075370763707737078370793708037081370823708337084370853708637087370883708937090370913709237093370943709537096370973709837099371003710137102371033710437105371063710737108371093711037111371123711337114371153711637117371183711937120371213712237123371243712537126371273712837129371303713137132371333713437135371363713737138371393714037141371423714337144371453714637147371483714937150371513715237153371543715537156371573715837159371603716137162371633716437165371663716737168371693717037171371723717337174371753717637177371783717937180371813718237183371843718537186371873718837189371903719137192371933719437195371963719737198371993720037201372023720337204372053720637207372083720937210372113721237213372143721537216372173721837219372203722137222372233722437225372263722737228372293723037231372323723337234372353723637237372383723937240372413724237243372443724537246372473724837249372503725137252372533725437255372563725737258372593726037261372623726337264372653726637267372683726937270372713727237273372743727537276372773727837279372803728137282372833728437285372863728737288372893729037291372923729337294372953729637297372983729937300373013730237303373043730537306373073730837309373103731137312373133731437315373163731737318373193732037321373223732337324373253732637327373283732937330373313733237333373343733537336373373733837339373403734137342373433734437345373463734737348373493735037351373523735337354373553735637357373583735937360373613736237363373643736537366373673736837369373703737137372373733737437375373763737737378373793738037381373823738337384373853738637387373883738937390373913739237393373943739537396373973739837399374003740137402374033740437405374063740737408374093741037411374123741337414374153741637417374183741937420374213742237423374243742537426374273742837429374303743137432374333743437435374363743737438374393744037441374423744337444374453744637447374483744937450374513745237453374543745537456374573745837459374603746137462374633746437465374663746737468374693747037471374723747337474374753747637477374783747937480374813748237483374843748537486374873748837489374903749137492374933749437495374963749737498374993750037501375023750337504375053750637507375083750937510375113751237513375143751537516375173751837519375203752137522375233752437525375263752737528375293753037531375323753337534375353753637537375383753937540375413754237543375443754537546375473754837549375503755137552375533755437555375563755737558375593756037561375623756337564375653756637567375683756937570375713757237573375743757537576375773757837579375803758137582375833758437585375863758737588375893759037591375923759337594375953759637597375983759937600376013760237603376043760537606376073760837609376103761137612376133761437615376163761737618376193762037621376223762337624376253762637627376283762937630376313763237633376343763537636376373763837639376403764137642376433764437645376463764737648376493765037651376523765337654376553765637657376583765937660376613766237663376643766537666376673766837669376703767137672376733767437675376763767737678376793768037681376823768337684376853768637687376883768937690376913769237693376943769537696376973769837699377003770137702377033770437705377063770737708377093771037711377123771337714377153771637717377183771937720377213772237723377243772537726377273772837729377303773137732377333773437735377363773737738377393774037741377423774337744377453774637747377483774937750377513775237753377543775537756377573775837759377603776137762377633776437765377663776737768377693777037771377723777337774377753777637777377783777937780377813778237783377843778537786377873778837789377903779137792377933779437795377963779737798377993780037801378023780337804378053780637807378083780937810378113781237813378143781537816378173781837819378203782137822378233782437825378263782737828378293783037831378323783337834378353783637837378383783937840378413784237843378443784537846378473784837849378503785137852378533785437855378563785737858378593786037861378623786337864378653786637867378683786937870378713787237873378743787537876378773787837879378803788137882378833788437885378863788737888378893789037891378923789337894378953789637897378983789937900379013790237903379043790537906379073790837909379103791137912379133791437915379163791737918379193792037921379223792337924379253792637927379283792937930379313793237933379343793537936379373793837939379403794137942379433794437945379463794737948379493795037951379523795337954379553795637957379583795937960379613796237963379643796537966379673796837969379703797137972379733797437975379763797737978379793798037981379823798337984379853798637987379883798937990379913799237993379943799537996379973799837999380003800138002380033800438005380063800738008380093801038011380123801338014380153801638017380183801938020380213802238023380243802538026380273802838029380303803138032380333803438035380363803738038380393804038041380423804338044380453804638047380483804938050380513805238053380543805538056380573805838059380603806138062380633806438065380663806738068380693807038071380723807338074380753807638077380783807938080380813808238083380843808538086380873808838089380903809138092380933809438095380963809738098380993810038101381023810338104381053810638107381083810938110381113811238113381143811538116381173811838119381203812138122381233812438125381263812738128381293813038131381323813338134381353813638137381383813938140381413814238143381443814538146381473814838149381503815138152381533815438155381563815738158381593816038161381623816338164381653816638167381683816938170381713817238173381743817538176381773817838179381803818138182381833818438185381863818738188381893819038191381923819338194381953819638197381983819938200382013820238203382043820538206382073820838209382103821138212382133821438215382163821738218382193822038221382223822338224382253822638227382283822938230382313823238233382343823538236382373823838239382403824138242382433824438245382463824738248382493825038251382523825338254382553825638257382583825938260382613826238263382643826538266382673826838269382703827138272382733827438275382763827738278382793828038281382823828338284382853828638287382883828938290382913829238293382943829538296382973829838299383003830138302383033830438305383063830738308383093831038311383123831338314383153831638317383183831938320383213832238323383243832538326383273832838329383303833138332383333833438335383363833738338383393834038341383423834338344383453834638347383483834938350383513835238353383543835538356383573835838359383603836138362383633836438365383663836738368383693837038371383723837338374383753837638377383783837938380383813838238383383843838538386383873838838389383903839138392383933839438395383963839738398383993840038401384023840338404384053840638407384083840938410384113841238413384143841538416384173841838419384203842138422384233842438425384263842738428384293843038431384323843338434384353843638437384383843938440384413844238443384443844538446384473844838449384503845138452384533845438455384563845738458384593846038461384623846338464384653846638467384683846938470384713847238473384743847538476384773847838479384803848138482384833848438485384863848738488384893849038491384923849338494384953849638497384983849938500385013850238503385043850538506385073850838509385103851138512385133851438515385163851738518385193852038521385223852338524385253852638527385283852938530385313853238533385343853538536385373853838539385403854138542385433854438545385463854738548385493855038551385523855338554385553855638557385583855938560385613856238563385643856538566385673856838569385703857138572385733857438575385763857738578385793858038581385823858338584385853858638587385883858938590385913859238593385943859538596385973859838599386003860138602386033860438605386063860738608386093861038611386123861338614386153861638617386183861938620386213862238623386243862538626386273862838629386303863138632386333863438635386363863738638386393864038641386423864338644386453864638647386483864938650386513865238653386543865538656386573865838659386603866138662386633866438665386663866738668386693867038671386723867338674386753867638677386783867938680386813868238683386843868538686386873868838689386903869138692386933869438695386963869738698386993870038701387023870338704387053870638707387083870938710387113871238713387143871538716387173871838719387203872138722387233872438725387263872738728387293873038731387323873338734387353873638737387383873938740387413874238743387443874538746387473874838749387503875138752387533875438755387563875738758387593876038761387623876338764387653876638767387683876938770387713877238773387743877538776387773877838779387803878138782387833878438785387863878738788387893879038791387923879338794387953879638797387983879938800388013880238803388043880538806388073880838809388103881138812388133881438815388163881738818388193882038821388223882338824388253882638827388283882938830388313883238833388343883538836388373883838839388403884138842388433884438845388463884738848388493885038851388523885338854388553885638857388583885938860388613886238863388643886538866388673886838869388703887138872388733887438875388763887738878388793888038881388823888338884388853888638887388883888938890388913889238893388943889538896388973889838899389003890138902389033890438905389063890738908389093891038911389123891338914389153891638917389183891938920389213892238923389243892538926389273892838929389303893138932389333893438935389363893738938389393894038941389423894338944389453894638947389483894938950389513895238953389543895538956389573895838959389603896138962389633896438965389663896738968389693897038971389723897338974389753897638977389783897938980389813898238983389843898538986389873898838989389903899138992389933899438995389963899738998389993900039001390023900339004390053900639007390083900939010390113901239013390143901539016390173901839019390203902139022390233902439025390263902739028390293903039031390323903339034390353903639037390383903939040390413904239043390443904539046390473904839049390503905139052390533905439055390563905739058390593906039061390623906339064390653906639067390683906939070390713907239073390743907539076390773907839079390803908139082390833908439085390863908739088390893909039091390923909339094390953909639097390983909939100391013910239103391043910539106391073910839109391103911139112391133911439115391163911739118391193912039121391223912339124391253912639127391283912939130391313913239133391343913539136391373913839139391403914139142391433914439145391463914739148391493915039151391523915339154391553915639157391583915939160391613916239163391643916539166391673916839169391703917139172391733917439175391763917739178391793918039181391823918339184391853918639187391883918939190391913919239193391943919539196391973919839199392003920139202392033920439205392063920739208392093921039211392123921339214392153921639217392183921939220392213922239223392243922539226392273922839229392303923139232392333923439235392363923739238392393924039241392423924339244392453924639247392483924939250392513925239253392543925539256392573925839259392603926139262392633926439265392663926739268392693927039271392723927339274392753927639277392783927939280392813928239283392843928539286392873928839289392903929139292392933929439295392963929739298392993930039301393023930339304393053930639307393083930939310393113931239313393143931539316393173931839319393203932139322393233932439325393263932739328393293933039331393323933339334393353933639337393383933939340393413934239343393443934539346393473934839349393503935139352393533935439355393563935739358393593936039361393623936339364393653936639367393683936939370393713937239373393743937539376393773937839379393803938139382393833938439385393863938739388393893939039391393923939339394393953939639397393983939939400394013940239403394043940539406394073940839409394103941139412394133941439415394163941739418394193942039421394223942339424394253942639427394283942939430394313943239433394343943539436394373943839439394403944139442394433944439445394463944739448394493945039451394523945339454394553945639457394583945939460394613946239463394643946539466394673946839469394703947139472394733947439475394763947739478394793948039481394823948339484394853948639487394883948939490394913949239493394943949539496394973949839499395003950139502395033950439505395063950739508395093951039511395123951339514395153951639517395183951939520395213952239523395243952539526395273952839529395303953139532395333953439535395363953739538395393954039541395423954339544395453954639547395483954939550395513955239553395543955539556395573955839559395603956139562395633956439565395663956739568395693957039571395723957339574395753957639577395783957939580395813958239583395843958539586395873958839589395903959139592395933959439595395963959739598395993960039601396023960339604396053960639607396083960939610396113961239613396143961539616396173961839619396203962139622396233962439625396263962739628396293963039631396323963339634396353963639637396383963939640396413964239643396443964539646396473964839649396503965139652396533965439655396563965739658396593966039661396623966339664396653966639667396683966939670396713967239673396743967539676396773967839679396803968139682396833968439685396863968739688396893969039691396923969339694396953969639697396983969939700397013970239703397043970539706397073970839709397103971139712397133971439715397163971739718397193972039721397223972339724397253972639727397283972939730397313973239733397343973539736397373973839739397403974139742397433974439745397463974739748397493975039751397523975339754397553975639757397583975939760397613976239763397643976539766397673976839769397703977139772397733977439775397763977739778397793978039781397823978339784397853978639787397883978939790397913979239793397943979539796397973979839799398003980139802398033980439805398063980739808398093981039811398123981339814398153981639817398183981939820398213982239823398243982539826398273982839829398303983139832398333983439835398363983739838398393984039841398423984339844398453984639847398483984939850398513985239853398543985539856398573985839859398603986139862398633986439865398663986739868398693987039871398723987339874398753987639877398783987939880398813988239883398843988539886398873988839889398903989139892398933989439895398963989739898398993990039901399023990339904399053990639907399083990939910399113991239913399143991539916399173991839919399203992139922399233992439925399263992739928399293993039931399323993339934399353993639937399383993939940399413994239943399443994539946399473994839949399503995139952399533995439955399563995739958399593996039961399623996339964399653996639967399683996939970399713997239973399743997539976399773997839979399803998139982399833998439985399863998739988399893999039991399923999339994399953999639997399983999940000400014000240003400044000540006400074000840009400104001140012400134001440015400164001740018400194002040021400224002340024400254002640027400284002940030400314003240033400344003540036400374003840039400404004140042400434004440045400464004740048400494005040051400524005340054400554005640057400584005940060400614006240063400644006540066400674006840069400704007140072400734007440075400764007740078400794008040081400824008340084400854008640087400884008940090400914009240093400944009540096400974009840099401004010140102401034010440105401064010740108401094011040111401124011340114401154011640117401184011940120401214012240123401244012540126401274012840129401304013140132401334013440135401364013740138401394014040141401424014340144401454014640147401484014940150401514015240153401544015540156401574015840159401604016140162401634016440165401664016740168401694017040171401724017340174401754017640177401784017940180401814018240183401844018540186401874018840189401904019140192401934019440195401964019740198401994020040201402024020340204402054020640207402084020940210402114021240213402144021540216402174021840219402204022140222402234022440225402264022740228402294023040231402324023340234402354023640237402384023940240402414024240243402444024540246402474024840249402504025140252402534025440255402564025740258402594026040261402624026340264402654026640267402684026940270402714027240273402744027540276402774027840279402804028140282402834028440285402864028740288402894029040291402924029340294402954029640297402984029940300403014030240303403044030540306403074030840309403104031140312403134031440315403164031740318403194032040321403224032340324403254032640327403284032940330403314033240333403344033540336403374033840339403404034140342403434034440345403464034740348403494035040351403524035340354403554035640357403584035940360403614036240363403644036540366403674036840369403704037140372403734037440375403764037740378403794038040381403824038340384403854038640387403884038940390403914039240393403944039540396403974039840399404004040140402404034040440405404064040740408404094041040411404124041340414404154041640417404184041940420404214042240423404244042540426404274042840429404304043140432404334043440435404364043740438404394044040441404424044340444404454044640447404484044940450404514045240453404544045540456404574045840459404604046140462404634046440465404664046740468404694047040471404724047340474404754047640477404784047940480404814048240483404844048540486404874048840489404904049140492404934049440495404964049740498404994050040501405024050340504405054050640507405084050940510405114051240513405144051540516405174051840519405204052140522405234052440525405264052740528405294053040531405324053340534405354053640537405384053940540405414054240543405444054540546405474054840549405504055140552405534055440555405564055740558405594056040561405624056340564405654056640567405684056940570405714057240573405744057540576405774057840579405804058140582405834058440585405864058740588405894059040591405924059340594405954059640597405984059940600406014060240603406044060540606406074060840609406104061140612406134061440615406164061740618406194062040621406224062340624406254062640627406284062940630406314063240633406344063540636406374063840639406404064140642406434064440645406464064740648406494065040651406524065340654406554065640657406584065940660406614066240663406644066540666406674066840669406704067140672406734067440675406764067740678406794068040681406824068340684406854068640687406884068940690406914069240693406944069540696406974069840699407004070140702407034070440705407064070740708407094071040711407124071340714407154071640717407184071940720407214072240723407244072540726407274072840729407304073140732407334073440735407364073740738407394074040741407424074340744407454074640747407484074940750407514075240753407544075540756407574075840759407604076140762407634076440765407664076740768407694077040771407724077340774407754077640777407784077940780407814078240783407844078540786407874078840789407904079140792407934079440795407964079740798407994080040801408024080340804408054080640807408084080940810408114081240813408144081540816408174081840819408204082140822408234082440825408264082740828408294083040831408324083340834408354083640837408384083940840408414084240843408444084540846408474084840849408504085140852408534085440855408564085740858408594086040861408624086340864408654086640867408684086940870408714087240873408744087540876408774087840879408804088140882408834088440885408864088740888408894089040891408924089340894408954089640897408984089940900409014090240903409044090540906409074090840909409104091140912409134091440915409164091740918409194092040921409224092340924409254092640927409284092940930409314093240933409344093540936409374093840939409404094140942409434094440945409464094740948409494095040951409524095340954409554095640957409584095940960409614096240963409644096540966409674096840969409704097140972409734097440975409764097740978409794098040981409824098340984409854098640987409884098940990409914099240993409944099540996409974099840999410004100141002410034100441005410064100741008410094101041011410124101341014410154101641017410184101941020410214102241023410244102541026410274102841029410304103141032410334103441035410364103741038410394104041041410424104341044410454104641047410484104941050410514105241053410544105541056410574105841059410604106141062410634106441065410664106741068410694107041071410724107341074410754107641077410784107941080410814108241083410844108541086410874108841089410904109141092410934109441095410964109741098410994110041101411024110341104411054110641107411084110941110411114111241113411144111541116411174111841119411204112141122411234112441125411264112741128411294113041131411324113341134411354113641137411384113941140411414114241143411444114541146411474114841149411504115141152411534115441155411564115741158411594116041161411624116341164411654116641167411684116941170411714117241173411744117541176411774117841179411804118141182411834118441185411864118741188411894119041191411924119341194411954119641197411984119941200412014120241203412044120541206412074120841209412104121141212412134121441215412164121741218412194122041221412224122341224412254122641227412284122941230412314123241233412344123541236412374123841239412404124141242412434124441245412464124741248412494125041251412524125341254412554125641257412584125941260412614126241263412644126541266412674126841269412704127141272412734127441275412764127741278412794128041281412824128341284412854128641287412884128941290412914129241293412944129541296412974129841299413004130141302413034130441305413064130741308413094131041311413124131341314413154131641317413184131941320413214132241323413244132541326413274132841329413304133141332413334133441335413364133741338413394134041341413424134341344413454134641347413484134941350413514135241353413544135541356413574135841359413604136141362413634136441365413664136741368413694137041371413724137341374413754137641377413784137941380413814138241383413844138541386413874138841389413904139141392413934139441395413964139741398413994140041401414024140341404414054140641407414084140941410414114141241413414144141541416414174141841419414204142141422414234142441425414264142741428414294143041431414324143341434414354143641437414384143941440414414144241443414444144541446414474144841449414504145141452414534145441455414564145741458414594146041461414624146341464414654146641467414684146941470414714147241473414744147541476414774147841479414804148141482414834148441485414864148741488414894149041491414924149341494414954149641497414984149941500415014150241503415044150541506415074150841509415104151141512415134151441515415164151741518415194152041521415224152341524415254152641527415284152941530415314153241533415344153541536415374153841539415404154141542415434154441545415464154741548415494155041551415524155341554415554155641557415584155941560415614156241563415644156541566415674156841569415704157141572415734157441575415764157741578415794158041581415824158341584415854158641587415884158941590415914159241593415944159541596415974159841599416004160141602416034160441605416064160741608416094161041611416124161341614416154161641617416184161941620416214162241623416244162541626416274162841629416304163141632416334163441635416364163741638416394164041641416424164341644416454164641647416484164941650416514165241653416544165541656416574165841659416604166141662416634166441665416664166741668416694167041671416724167341674416754167641677416784167941680416814168241683416844168541686416874168841689416904169141692416934169441695416964169741698416994170041701417024170341704417054170641707417084170941710417114171241713417144171541716417174171841719417204172141722417234172441725417264172741728417294173041731417324173341734417354173641737417384173941740417414174241743417444174541746417474174841749417504175141752417534175441755417564175741758417594176041761417624176341764417654176641767417684176941770417714177241773417744177541776417774177841779417804178141782417834178441785417864178741788417894179041791417924179341794417954179641797417984179941800418014180241803418044180541806418074180841809418104181141812418134181441815418164181741818418194182041821418224182341824418254182641827418284182941830418314183241833418344183541836418374183841839418404184141842418434184441845418464184741848418494185041851418524185341854418554185641857418584185941860418614186241863418644186541866418674186841869418704187141872418734187441875418764187741878418794188041881418824188341884418854188641887418884188941890418914189241893418944189541896418974189841899419004190141902419034190441905419064190741908419094191041911419124191341914419154191641917419184191941920419214192241923419244192541926419274192841929419304193141932419334193441935419364193741938419394194041941419424194341944419454194641947419484194941950419514195241953419544195541956419574195841959419604196141962419634196441965419664196741968419694197041971419724197341974419754197641977419784197941980419814198241983419844198541986419874198841989419904199141992419934199441995419964199741998419994200042001420024200342004420054200642007420084200942010420114201242013420144201542016420174201842019420204202142022420234202442025420264202742028420294203042031420324203342034
  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. /* umdutils ignore */
  17. (function (root, factory) {
  18. 'use strict';
  19. if (typeof define === 'function' && define.amd) {
  20. define('pdfjs-dist/build/pdf.worker', ['exports'], factory);
  21. } else if (typeof exports !== 'undefined') {
  22. factory(exports);
  23. } else {
  24. factory((root.pdfjsDistBuildPdfWorker = {}));
  25. }
  26. }(this, function (exports) {
  27. // Use strict in our context only - users might not want it
  28. 'use strict';
  29. var pdfjsVersion = '1.4.20';
  30. var pdfjsBuild = 'b15f335';
  31. var pdfjsFilePath =
  32. typeof document !== 'undefined' && document.currentScript ?
  33. document.currentScript.src : null;
  34. var pdfjsLibs = {};
  35. (function pdfjsWrapper() {
  36. (function (root, factory) {
  37. {
  38. factory((root.pdfjsCoreArithmeticDecoder = {}));
  39. }
  40. }(this, function (exports) {
  41. /* This class implements the QM Coder decoding as defined in
  42. * JPEG 2000 Part I Final Committee Draft Version 1.0
  43. * Annex C.3 Arithmetic decoding procedure
  44. * available at http://www.jpeg.org/public/fcd15444-1.pdf
  45. *
  46. * The arithmetic decoder is used in conjunction with context models to decode
  47. * JPEG2000 and JBIG2 streams.
  48. */
  49. var ArithmeticDecoder = (function ArithmeticDecoderClosure() {
  50. // Table C-2
  51. var QeTable = [
  52. {qe: 0x5601, nmps: 1, nlps: 1, switchFlag: 1},
  53. {qe: 0x3401, nmps: 2, nlps: 6, switchFlag: 0},
  54. {qe: 0x1801, nmps: 3, nlps: 9, switchFlag: 0},
  55. {qe: 0x0AC1, nmps: 4, nlps: 12, switchFlag: 0},
  56. {qe: 0x0521, nmps: 5, nlps: 29, switchFlag: 0},
  57. {qe: 0x0221, nmps: 38, nlps: 33, switchFlag: 0},
  58. {qe: 0x5601, nmps: 7, nlps: 6, switchFlag: 1},
  59. {qe: 0x5401, nmps: 8, nlps: 14, switchFlag: 0},
  60. {qe: 0x4801, nmps: 9, nlps: 14, switchFlag: 0},
  61. {qe: 0x3801, nmps: 10, nlps: 14, switchFlag: 0},
  62. {qe: 0x3001, nmps: 11, nlps: 17, switchFlag: 0},
  63. {qe: 0x2401, nmps: 12, nlps: 18, switchFlag: 0},
  64. {qe: 0x1C01, nmps: 13, nlps: 20, switchFlag: 0},
  65. {qe: 0x1601, nmps: 29, nlps: 21, switchFlag: 0},
  66. {qe: 0x5601, nmps: 15, nlps: 14, switchFlag: 1},
  67. {qe: 0x5401, nmps: 16, nlps: 14, switchFlag: 0},
  68. {qe: 0x5101, nmps: 17, nlps: 15, switchFlag: 0},
  69. {qe: 0x4801, nmps: 18, nlps: 16, switchFlag: 0},
  70. {qe: 0x3801, nmps: 19, nlps: 17, switchFlag: 0},
  71. {qe: 0x3401, nmps: 20, nlps: 18, switchFlag: 0},
  72. {qe: 0x3001, nmps: 21, nlps: 19, switchFlag: 0},
  73. {qe: 0x2801, nmps: 22, nlps: 19, switchFlag: 0},
  74. {qe: 0x2401, nmps: 23, nlps: 20, switchFlag: 0},
  75. {qe: 0x2201, nmps: 24, nlps: 21, switchFlag: 0},
  76. {qe: 0x1C01, nmps: 25, nlps: 22, switchFlag: 0},
  77. {qe: 0x1801, nmps: 26, nlps: 23, switchFlag: 0},
  78. {qe: 0x1601, nmps: 27, nlps: 24, switchFlag: 0},
  79. {qe: 0x1401, nmps: 28, nlps: 25, switchFlag: 0},
  80. {qe: 0x1201, nmps: 29, nlps: 26, switchFlag: 0},
  81. {qe: 0x1101, nmps: 30, nlps: 27, switchFlag: 0},
  82. {qe: 0x0AC1, nmps: 31, nlps: 28, switchFlag: 0},
  83. {qe: 0x09C1, nmps: 32, nlps: 29, switchFlag: 0},
  84. {qe: 0x08A1, nmps: 33, nlps: 30, switchFlag: 0},
  85. {qe: 0x0521, nmps: 34, nlps: 31, switchFlag: 0},
  86. {qe: 0x0441, nmps: 35, nlps: 32, switchFlag: 0},
  87. {qe: 0x02A1, nmps: 36, nlps: 33, switchFlag: 0},
  88. {qe: 0x0221, nmps: 37, nlps: 34, switchFlag: 0},
  89. {qe: 0x0141, nmps: 38, nlps: 35, switchFlag: 0},
  90. {qe: 0x0111, nmps: 39, nlps: 36, switchFlag: 0},
  91. {qe: 0x0085, nmps: 40, nlps: 37, switchFlag: 0},
  92. {qe: 0x0049, nmps: 41, nlps: 38, switchFlag: 0},
  93. {qe: 0x0025, nmps: 42, nlps: 39, switchFlag: 0},
  94. {qe: 0x0015, nmps: 43, nlps: 40, switchFlag: 0},
  95. {qe: 0x0009, nmps: 44, nlps: 41, switchFlag: 0},
  96. {qe: 0x0005, nmps: 45, nlps: 42, switchFlag: 0},
  97. {qe: 0x0001, nmps: 45, nlps: 43, switchFlag: 0},
  98. {qe: 0x5601, nmps: 46, nlps: 46, switchFlag: 0}
  99. ];
  100. // C.3.5 Initialisation of the decoder (INITDEC)
  101. function ArithmeticDecoder(data, start, end) {
  102. this.data = data;
  103. this.bp = start;
  104. this.dataEnd = end;
  105. this.chigh = data[start];
  106. this.clow = 0;
  107. this.byteIn();
  108. this.chigh = ((this.chigh << 7) & 0xFFFF) | ((this.clow >> 9) & 0x7F);
  109. this.clow = (this.clow << 7) & 0xFFFF;
  110. this.ct -= 7;
  111. this.a = 0x8000;
  112. }
  113. ArithmeticDecoder.prototype = {
  114. // C.3.4 Compressed data input (BYTEIN)
  115. byteIn: function ArithmeticDecoder_byteIn() {
  116. var data = this.data;
  117. var bp = this.bp;
  118. if (data[bp] === 0xFF) {
  119. var b1 = data[bp + 1];
  120. if (b1 > 0x8F) {
  121. this.clow += 0xFF00;
  122. this.ct = 8;
  123. } else {
  124. bp++;
  125. this.clow += (data[bp] << 9);
  126. this.ct = 7;
  127. this.bp = bp;
  128. }
  129. } else {
  130. bp++;
  131. this.clow += bp < this.dataEnd ? (data[bp] << 8) : 0xFF00;
  132. this.ct = 8;
  133. this.bp = bp;
  134. }
  135. if (this.clow > 0xFFFF) {
  136. this.chigh += (this.clow >> 16);
  137. this.clow &= 0xFFFF;
  138. }
  139. },
  140. // C.3.2 Decoding a decision (DECODE)
  141. readBit: function ArithmeticDecoder_readBit(contexts, pos) {
  142. // contexts are packed into 1 byte:
  143. // highest 7 bits carry cx.index, lowest bit carries cx.mps
  144. var cx_index = contexts[pos] >> 1, cx_mps = contexts[pos] & 1;
  145. var qeTableIcx = QeTable[cx_index];
  146. var qeIcx = qeTableIcx.qe;
  147. var d;
  148. var a = this.a - qeIcx;
  149. if (this.chigh < qeIcx) {
  150. // exchangeLps
  151. if (a < qeIcx) {
  152. a = qeIcx;
  153. d = cx_mps;
  154. cx_index = qeTableIcx.nmps;
  155. } else {
  156. a = qeIcx;
  157. d = 1 ^ cx_mps;
  158. if (qeTableIcx.switchFlag === 1) {
  159. cx_mps = d;
  160. }
  161. cx_index = qeTableIcx.nlps;
  162. }
  163. } else {
  164. this.chigh -= qeIcx;
  165. if ((a & 0x8000) !== 0) {
  166. this.a = a;
  167. return cx_mps;
  168. }
  169. // exchangeMps
  170. if (a < qeIcx) {
  171. d = 1 ^ cx_mps;
  172. if (qeTableIcx.switchFlag === 1) {
  173. cx_mps = d;
  174. }
  175. cx_index = qeTableIcx.nlps;
  176. } else {
  177. d = cx_mps;
  178. cx_index = qeTableIcx.nmps;
  179. }
  180. }
  181. // C.3.3 renormD;
  182. do {
  183. if (this.ct === 0) {
  184. this.byteIn();
  185. }
  186. a <<= 1;
  187. this.chigh = ((this.chigh << 1) & 0xFFFF) | ((this.clow >> 15) & 1);
  188. this.clow = (this.clow << 1) & 0xFFFF;
  189. this.ct--;
  190. } while ((a & 0x8000) === 0);
  191. this.a = a;
  192. contexts[pos] = cx_index << 1 | cx_mps;
  193. return d;
  194. }
  195. };
  196. return ArithmeticDecoder;
  197. })();
  198. exports.ArithmeticDecoder = ArithmeticDecoder;
  199. }));
  200. (function (root, factory) {
  201. {
  202. factory((root.pdfjsCoreCharsets = {}));
  203. }
  204. }(this, function (exports) {
  205. var ISOAdobeCharset = [
  206. '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar',
  207. 'percent', 'ampersand', 'quoteright', 'parenleft', 'parenright',
  208. 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash', 'zero',
  209. 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  210. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question',
  211. 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
  212. 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
  213. 'bracketleft', 'backslash', 'bracketright', 'asciicircum', 'underscore',
  214. 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
  215. 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
  216. 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
  217. 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  218. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  219. 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
  220. 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase',
  221. 'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis',
  222. 'perthousand', 'questiondown', 'grave', 'acute', 'circumflex', 'tilde',
  223. 'macron', 'breve', 'dotaccent', 'dieresis', 'ring', 'cedilla',
  224. 'hungarumlaut', 'ogonek', 'caron', 'emdash', 'AE', 'ordfeminine',
  225. 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae', 'dotlessi', 'lslash',
  226. 'oslash', 'oe', 'germandbls', 'onesuperior', 'logicalnot', 'mu',
  227. 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn', 'onequarter',
  228. 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters', 'twosuperior',
  229. 'registered', 'minus', 'eth', 'multiply', 'threesuperior', 'copyright',
  230. 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring', 'Atilde',
  231. 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave', 'Iacute',
  232. 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute', 'Ocircumflex',
  233. 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute', 'Ucircumflex',
  234. 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron', 'aacute',
  235. 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde', 'ccedilla',
  236. 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute', 'icircumflex',
  237. 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex', 'odieresis',
  238. 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex', 'udieresis',
  239. 'ugrave', 'yacute', 'ydieresis', 'zcaron'
  240. ];
  241. var ExpertCharset = [
  242. '.notdef', 'space', 'exclamsmall', 'Hungarumlautsmall', 'dollaroldstyle',
  243. 'dollarsuperior', 'ampersandsmall', 'Acutesmall', 'parenleftsuperior',
  244. 'parenrightsuperior', 'twodotenleader', 'onedotenleader', 'comma',
  245. 'hyphen', 'period', 'fraction', 'zerooldstyle', 'oneoldstyle',
  246. 'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle',
  247. 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle',
  248. 'colon', 'semicolon', 'commasuperior', 'threequartersemdash',
  249. 'periodsuperior', 'questionsmall', 'asuperior', 'bsuperior',
  250. 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',
  251. 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  252. 'tsuperior', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior',
  253. 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall',
  254. 'Asmall', 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall',
  255. 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall',
  256. 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall',
  257. 'Vsmall', 'Wsmall', 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary',
  258. 'onefitted', 'rupiah', 'Tildesmall', 'exclamdownsmall', 'centoldstyle',
  259. 'Lslashsmall', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall',
  260. 'Brevesmall', 'Caronsmall', 'Dotaccentsmall', 'Macronsmall',
  261. 'figuredash', 'hypheninferior', 'Ogoneksmall', 'Ringsmall',
  262. 'Cedillasmall', 'onequarter', 'onehalf', 'threequarters',
  263. 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths',
  264. 'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'onesuperior',
  265. 'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',
  266. 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',
  267. 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior',
  268. 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior',
  269. 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior',
  270. 'periodinferior', 'commainferior', 'Agravesmall', 'Aacutesmall',
  271. 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall', 'Aringsmall',
  272. 'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall',
  273. 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall',
  274. 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall',
  275. 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall',
  276. 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall',
  277. 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall',
  278. 'Ydieresissmall'
  279. ];
  280. var ExpertSubsetCharset = [
  281. '.notdef', 'space', 'dollaroldstyle', 'dollarsuperior',
  282. 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  283. 'onedotenleader', 'comma', 'hyphen', 'period', 'fraction',
  284. 'zerooldstyle', 'oneoldstyle', 'twooldstyle', 'threeoldstyle',
  285. 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle',
  286. 'eightoldstyle', 'nineoldstyle', 'colon', 'semicolon', 'commasuperior',
  287. 'threequartersemdash', 'periodsuperior', 'asuperior', 'bsuperior',
  288. 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',
  289. 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  290. 'tsuperior', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior',
  291. 'parenrightinferior', 'hyphensuperior', 'colonmonetary', 'onefitted',
  292. 'rupiah', 'centoldstyle', 'figuredash', 'hypheninferior', 'onequarter',
  293. 'onehalf', 'threequarters', 'oneeighth', 'threeeighths', 'fiveeighths',
  294. 'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'onesuperior',
  295. 'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',
  296. 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',
  297. 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior',
  298. 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior',
  299. 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior',
  300. 'periodinferior', 'commainferior'
  301. ];
  302. exports.ISOAdobeCharset = ISOAdobeCharset;
  303. exports.ExpertCharset = ExpertCharset;
  304. exports.ExpertSubsetCharset = ExpertSubsetCharset;
  305. }));
  306. (function (root, factory) {
  307. {
  308. factory((root.pdfjsCoreGlyphList = {}));
  309. }
  310. }(this, function (exports) {
  311. var GlyphsUnicode = {
  312. A: 0x0041,
  313. AE: 0x00C6,
  314. AEacute: 0x01FC,
  315. AEmacron: 0x01E2,
  316. AEsmall: 0xF7E6,
  317. Aacute: 0x00C1,
  318. Aacutesmall: 0xF7E1,
  319. Abreve: 0x0102,
  320. Abreveacute: 0x1EAE,
  321. Abrevecyrillic: 0x04D0,
  322. Abrevedotbelow: 0x1EB6,
  323. Abrevegrave: 0x1EB0,
  324. Abrevehookabove: 0x1EB2,
  325. Abrevetilde: 0x1EB4,
  326. Acaron: 0x01CD,
  327. Acircle: 0x24B6,
  328. Acircumflex: 0x00C2,
  329. Acircumflexacute: 0x1EA4,
  330. Acircumflexdotbelow: 0x1EAC,
  331. Acircumflexgrave: 0x1EA6,
  332. Acircumflexhookabove: 0x1EA8,
  333. Acircumflexsmall: 0xF7E2,
  334. Acircumflextilde: 0x1EAA,
  335. Acute: 0xF6C9,
  336. Acutesmall: 0xF7B4,
  337. Acyrillic: 0x0410,
  338. Adblgrave: 0x0200,
  339. Adieresis: 0x00C4,
  340. Adieresiscyrillic: 0x04D2,
  341. Adieresismacron: 0x01DE,
  342. Adieresissmall: 0xF7E4,
  343. Adotbelow: 0x1EA0,
  344. Adotmacron: 0x01E0,
  345. Agrave: 0x00C0,
  346. Agravesmall: 0xF7E0,
  347. Ahookabove: 0x1EA2,
  348. Aiecyrillic: 0x04D4,
  349. Ainvertedbreve: 0x0202,
  350. Alpha: 0x0391,
  351. Alphatonos: 0x0386,
  352. Amacron: 0x0100,
  353. Amonospace: 0xFF21,
  354. Aogonek: 0x0104,
  355. Aring: 0x00C5,
  356. Aringacute: 0x01FA,
  357. Aringbelow: 0x1E00,
  358. Aringsmall: 0xF7E5,
  359. Asmall: 0xF761,
  360. Atilde: 0x00C3,
  361. Atildesmall: 0xF7E3,
  362. Aybarmenian: 0x0531,
  363. B: 0x0042,
  364. Bcircle: 0x24B7,
  365. Bdotaccent: 0x1E02,
  366. Bdotbelow: 0x1E04,
  367. Becyrillic: 0x0411,
  368. Benarmenian: 0x0532,
  369. Beta: 0x0392,
  370. Bhook: 0x0181,
  371. Blinebelow: 0x1E06,
  372. Bmonospace: 0xFF22,
  373. Brevesmall: 0xF6F4,
  374. Bsmall: 0xF762,
  375. Btopbar: 0x0182,
  376. C: 0x0043,
  377. Caarmenian: 0x053E,
  378. Cacute: 0x0106,
  379. Caron: 0xF6CA,
  380. Caronsmall: 0xF6F5,
  381. Ccaron: 0x010C,
  382. Ccedilla: 0x00C7,
  383. Ccedillaacute: 0x1E08,
  384. Ccedillasmall: 0xF7E7,
  385. Ccircle: 0x24B8,
  386. Ccircumflex: 0x0108,
  387. Cdot: 0x010A,
  388. Cdotaccent: 0x010A,
  389. Cedillasmall: 0xF7B8,
  390. Chaarmenian: 0x0549,
  391. Cheabkhasiancyrillic: 0x04BC,
  392. Checyrillic: 0x0427,
  393. Chedescenderabkhasiancyrillic: 0x04BE,
  394. Chedescendercyrillic: 0x04B6,
  395. Chedieresiscyrillic: 0x04F4,
  396. Cheharmenian: 0x0543,
  397. Chekhakassiancyrillic: 0x04CB,
  398. Cheverticalstrokecyrillic: 0x04B8,
  399. Chi: 0x03A7,
  400. Chook: 0x0187,
  401. Circumflexsmall: 0xF6F6,
  402. Cmonospace: 0xFF23,
  403. Coarmenian: 0x0551,
  404. Csmall: 0xF763,
  405. D: 0x0044,
  406. DZ: 0x01F1,
  407. DZcaron: 0x01C4,
  408. Daarmenian: 0x0534,
  409. Dafrican: 0x0189,
  410. Dcaron: 0x010E,
  411. Dcedilla: 0x1E10,
  412. Dcircle: 0x24B9,
  413. Dcircumflexbelow: 0x1E12,
  414. Dcroat: 0x0110,
  415. Ddotaccent: 0x1E0A,
  416. Ddotbelow: 0x1E0C,
  417. Decyrillic: 0x0414,
  418. Deicoptic: 0x03EE,
  419. Delta: 0x2206,
  420. Deltagreek: 0x0394,
  421. Dhook: 0x018A,
  422. Dieresis: 0xF6CB,
  423. DieresisAcute: 0xF6CC,
  424. DieresisGrave: 0xF6CD,
  425. Dieresissmall: 0xF7A8,
  426. Digammagreek: 0x03DC,
  427. Djecyrillic: 0x0402,
  428. Dlinebelow: 0x1E0E,
  429. Dmonospace: 0xFF24,
  430. Dotaccentsmall: 0xF6F7,
  431. Dslash: 0x0110,
  432. Dsmall: 0xF764,
  433. Dtopbar: 0x018B,
  434. Dz: 0x01F2,
  435. Dzcaron: 0x01C5,
  436. Dzeabkhasiancyrillic: 0x04E0,
  437. Dzecyrillic: 0x0405,
  438. Dzhecyrillic: 0x040F,
  439. E: 0x0045,
  440. Eacute: 0x00C9,
  441. Eacutesmall: 0xF7E9,
  442. Ebreve: 0x0114,
  443. Ecaron: 0x011A,
  444. Ecedillabreve: 0x1E1C,
  445. Echarmenian: 0x0535,
  446. Ecircle: 0x24BA,
  447. Ecircumflex: 0x00CA,
  448. Ecircumflexacute: 0x1EBE,
  449. Ecircumflexbelow: 0x1E18,
  450. Ecircumflexdotbelow: 0x1EC6,
  451. Ecircumflexgrave: 0x1EC0,
  452. Ecircumflexhookabove: 0x1EC2,
  453. Ecircumflexsmall: 0xF7EA,
  454. Ecircumflextilde: 0x1EC4,
  455. Ecyrillic: 0x0404,
  456. Edblgrave: 0x0204,
  457. Edieresis: 0x00CB,
  458. Edieresissmall: 0xF7EB,
  459. Edot: 0x0116,
  460. Edotaccent: 0x0116,
  461. Edotbelow: 0x1EB8,
  462. Efcyrillic: 0x0424,
  463. Egrave: 0x00C8,
  464. Egravesmall: 0xF7E8,
  465. Eharmenian: 0x0537,
  466. Ehookabove: 0x1EBA,
  467. Eightroman: 0x2167,
  468. Einvertedbreve: 0x0206,
  469. Eiotifiedcyrillic: 0x0464,
  470. Elcyrillic: 0x041B,
  471. Elevenroman: 0x216A,
  472. Emacron: 0x0112,
  473. Emacronacute: 0x1E16,
  474. Emacrongrave: 0x1E14,
  475. Emcyrillic: 0x041C,
  476. Emonospace: 0xFF25,
  477. Encyrillic: 0x041D,
  478. Endescendercyrillic: 0x04A2,
  479. Eng: 0x014A,
  480. Enghecyrillic: 0x04A4,
  481. Enhookcyrillic: 0x04C7,
  482. Eogonek: 0x0118,
  483. Eopen: 0x0190,
  484. Epsilon: 0x0395,
  485. Epsilontonos: 0x0388,
  486. Ercyrillic: 0x0420,
  487. Ereversed: 0x018E,
  488. Ereversedcyrillic: 0x042D,
  489. Escyrillic: 0x0421,
  490. Esdescendercyrillic: 0x04AA,
  491. Esh: 0x01A9,
  492. Esmall: 0xF765,
  493. Eta: 0x0397,
  494. Etarmenian: 0x0538,
  495. Etatonos: 0x0389,
  496. Eth: 0x00D0,
  497. Ethsmall: 0xF7F0,
  498. Etilde: 0x1EBC,
  499. Etildebelow: 0x1E1A,
  500. Euro: 0x20AC,
  501. Ezh: 0x01B7,
  502. Ezhcaron: 0x01EE,
  503. Ezhreversed: 0x01B8,
  504. F: 0x0046,
  505. Fcircle: 0x24BB,
  506. Fdotaccent: 0x1E1E,
  507. Feharmenian: 0x0556,
  508. Feicoptic: 0x03E4,
  509. Fhook: 0x0191,
  510. Fitacyrillic: 0x0472,
  511. Fiveroman: 0x2164,
  512. Fmonospace: 0xFF26,
  513. Fourroman: 0x2163,
  514. Fsmall: 0xF766,
  515. G: 0x0047,
  516. GBsquare: 0x3387,
  517. Gacute: 0x01F4,
  518. Gamma: 0x0393,
  519. Gammaafrican: 0x0194,
  520. Gangiacoptic: 0x03EA,
  521. Gbreve: 0x011E,
  522. Gcaron: 0x01E6,
  523. Gcedilla: 0x0122,
  524. Gcircle: 0x24BC,
  525. Gcircumflex: 0x011C,
  526. Gcommaaccent: 0x0122,
  527. Gdot: 0x0120,
  528. Gdotaccent: 0x0120,
  529. Gecyrillic: 0x0413,
  530. Ghadarmenian: 0x0542,
  531. Ghemiddlehookcyrillic: 0x0494,
  532. Ghestrokecyrillic: 0x0492,
  533. Gheupturncyrillic: 0x0490,
  534. Ghook: 0x0193,
  535. Gimarmenian: 0x0533,
  536. Gjecyrillic: 0x0403,
  537. Gmacron: 0x1E20,
  538. Gmonospace: 0xFF27,
  539. Grave: 0xF6CE,
  540. Gravesmall: 0xF760,
  541. Gsmall: 0xF767,
  542. Gsmallhook: 0x029B,
  543. Gstroke: 0x01E4,
  544. H: 0x0048,
  545. H18533: 0x25CF,
  546. H18543: 0x25AA,
  547. H18551: 0x25AB,
  548. H22073: 0x25A1,
  549. HPsquare: 0x33CB,
  550. Haabkhasiancyrillic: 0x04A8,
  551. Hadescendercyrillic: 0x04B2,
  552. Hardsigncyrillic: 0x042A,
  553. Hbar: 0x0126,
  554. Hbrevebelow: 0x1E2A,
  555. Hcedilla: 0x1E28,
  556. Hcircle: 0x24BD,
  557. Hcircumflex: 0x0124,
  558. Hdieresis: 0x1E26,
  559. Hdotaccent: 0x1E22,
  560. Hdotbelow: 0x1E24,
  561. Hmonospace: 0xFF28,
  562. Hoarmenian: 0x0540,
  563. Horicoptic: 0x03E8,
  564. Hsmall: 0xF768,
  565. Hungarumlaut: 0xF6CF,
  566. Hungarumlautsmall: 0xF6F8,
  567. Hzsquare: 0x3390,
  568. I: 0x0049,
  569. IAcyrillic: 0x042F,
  570. IJ: 0x0132,
  571. IUcyrillic: 0x042E,
  572. Iacute: 0x00CD,
  573. Iacutesmall: 0xF7ED,
  574. Ibreve: 0x012C,
  575. Icaron: 0x01CF,
  576. Icircle: 0x24BE,
  577. Icircumflex: 0x00CE,
  578. Icircumflexsmall: 0xF7EE,
  579. Icyrillic: 0x0406,
  580. Idblgrave: 0x0208,
  581. Idieresis: 0x00CF,
  582. Idieresisacute: 0x1E2E,
  583. Idieresiscyrillic: 0x04E4,
  584. Idieresissmall: 0xF7EF,
  585. Idot: 0x0130,
  586. Idotaccent: 0x0130,
  587. Idotbelow: 0x1ECA,
  588. Iebrevecyrillic: 0x04D6,
  589. Iecyrillic: 0x0415,
  590. Ifraktur: 0x2111,
  591. Igrave: 0x00CC,
  592. Igravesmall: 0xF7EC,
  593. Ihookabove: 0x1EC8,
  594. Iicyrillic: 0x0418,
  595. Iinvertedbreve: 0x020A,
  596. Iishortcyrillic: 0x0419,
  597. Imacron: 0x012A,
  598. Imacroncyrillic: 0x04E2,
  599. Imonospace: 0xFF29,
  600. Iniarmenian: 0x053B,
  601. Iocyrillic: 0x0401,
  602. Iogonek: 0x012E,
  603. Iota: 0x0399,
  604. Iotaafrican: 0x0196,
  605. Iotadieresis: 0x03AA,
  606. Iotatonos: 0x038A,
  607. Ismall: 0xF769,
  608. Istroke: 0x0197,
  609. Itilde: 0x0128,
  610. Itildebelow: 0x1E2C,
  611. Izhitsacyrillic: 0x0474,
  612. Izhitsadblgravecyrillic: 0x0476,
  613. J: 0x004A,
  614. Jaarmenian: 0x0541,
  615. Jcircle: 0x24BF,
  616. Jcircumflex: 0x0134,
  617. Jecyrillic: 0x0408,
  618. Jheharmenian: 0x054B,
  619. Jmonospace: 0xFF2A,
  620. Jsmall: 0xF76A,
  621. K: 0x004B,
  622. KBsquare: 0x3385,
  623. KKsquare: 0x33CD,
  624. Kabashkircyrillic: 0x04A0,
  625. Kacute: 0x1E30,
  626. Kacyrillic: 0x041A,
  627. Kadescendercyrillic: 0x049A,
  628. Kahookcyrillic: 0x04C3,
  629. Kappa: 0x039A,
  630. Kastrokecyrillic: 0x049E,
  631. Kaverticalstrokecyrillic: 0x049C,
  632. Kcaron: 0x01E8,
  633. Kcedilla: 0x0136,
  634. Kcircle: 0x24C0,
  635. Kcommaaccent: 0x0136,
  636. Kdotbelow: 0x1E32,
  637. Keharmenian: 0x0554,
  638. Kenarmenian: 0x053F,
  639. Khacyrillic: 0x0425,
  640. Kheicoptic: 0x03E6,
  641. Khook: 0x0198,
  642. Kjecyrillic: 0x040C,
  643. Klinebelow: 0x1E34,
  644. Kmonospace: 0xFF2B,
  645. Koppacyrillic: 0x0480,
  646. Koppagreek: 0x03DE,
  647. Ksicyrillic: 0x046E,
  648. Ksmall: 0xF76B,
  649. L: 0x004C,
  650. LJ: 0x01C7,
  651. LL: 0xF6BF,
  652. Lacute: 0x0139,
  653. Lambda: 0x039B,
  654. Lcaron: 0x013D,
  655. Lcedilla: 0x013B,
  656. Lcircle: 0x24C1,
  657. Lcircumflexbelow: 0x1E3C,
  658. Lcommaaccent: 0x013B,
  659. Ldot: 0x013F,
  660. Ldotaccent: 0x013F,
  661. Ldotbelow: 0x1E36,
  662. Ldotbelowmacron: 0x1E38,
  663. Liwnarmenian: 0x053C,
  664. Lj: 0x01C8,
  665. Ljecyrillic: 0x0409,
  666. Llinebelow: 0x1E3A,
  667. Lmonospace: 0xFF2C,
  668. Lslash: 0x0141,
  669. Lslashsmall: 0xF6F9,
  670. Lsmall: 0xF76C,
  671. M: 0x004D,
  672. MBsquare: 0x3386,
  673. Macron: 0xF6D0,
  674. Macronsmall: 0xF7AF,
  675. Macute: 0x1E3E,
  676. Mcircle: 0x24C2,
  677. Mdotaccent: 0x1E40,
  678. Mdotbelow: 0x1E42,
  679. Menarmenian: 0x0544,
  680. Mmonospace: 0xFF2D,
  681. Msmall: 0xF76D,
  682. Mturned: 0x019C,
  683. Mu: 0x039C,
  684. N: 0x004E,
  685. NJ: 0x01CA,
  686. Nacute: 0x0143,
  687. Ncaron: 0x0147,
  688. Ncedilla: 0x0145,
  689. Ncircle: 0x24C3,
  690. Ncircumflexbelow: 0x1E4A,
  691. Ncommaaccent: 0x0145,
  692. Ndotaccent: 0x1E44,
  693. Ndotbelow: 0x1E46,
  694. Nhookleft: 0x019D,
  695. Nineroman: 0x2168,
  696. Nj: 0x01CB,
  697. Njecyrillic: 0x040A,
  698. Nlinebelow: 0x1E48,
  699. Nmonospace: 0xFF2E,
  700. Nowarmenian: 0x0546,
  701. Nsmall: 0xF76E,
  702. Ntilde: 0x00D1,
  703. Ntildesmall: 0xF7F1,
  704. Nu: 0x039D,
  705. O: 0x004F,
  706. OE: 0x0152,
  707. OEsmall: 0xF6FA,
  708. Oacute: 0x00D3,
  709. Oacutesmall: 0xF7F3,
  710. Obarredcyrillic: 0x04E8,
  711. Obarreddieresiscyrillic: 0x04EA,
  712. Obreve: 0x014E,
  713. Ocaron: 0x01D1,
  714. Ocenteredtilde: 0x019F,
  715. Ocircle: 0x24C4,
  716. Ocircumflex: 0x00D4,
  717. Ocircumflexacute: 0x1ED0,
  718. Ocircumflexdotbelow: 0x1ED8,
  719. Ocircumflexgrave: 0x1ED2,
  720. Ocircumflexhookabove: 0x1ED4,
  721. Ocircumflexsmall: 0xF7F4,
  722. Ocircumflextilde: 0x1ED6,
  723. Ocyrillic: 0x041E,
  724. Odblacute: 0x0150,
  725. Odblgrave: 0x020C,
  726. Odieresis: 0x00D6,
  727. Odieresiscyrillic: 0x04E6,
  728. Odieresissmall: 0xF7F6,
  729. Odotbelow: 0x1ECC,
  730. Ogoneksmall: 0xF6FB,
  731. Ograve: 0x00D2,
  732. Ogravesmall: 0xF7F2,
  733. Oharmenian: 0x0555,
  734. Ohm: 0x2126,
  735. Ohookabove: 0x1ECE,
  736. Ohorn: 0x01A0,
  737. Ohornacute: 0x1EDA,
  738. Ohorndotbelow: 0x1EE2,
  739. Ohorngrave: 0x1EDC,
  740. Ohornhookabove: 0x1EDE,
  741. Ohorntilde: 0x1EE0,
  742. Ohungarumlaut: 0x0150,
  743. Oi: 0x01A2,
  744. Oinvertedbreve: 0x020E,
  745. Omacron: 0x014C,
  746. Omacronacute: 0x1E52,
  747. Omacrongrave: 0x1E50,
  748. Omega: 0x2126,
  749. Omegacyrillic: 0x0460,
  750. Omegagreek: 0x03A9,
  751. Omegaroundcyrillic: 0x047A,
  752. Omegatitlocyrillic: 0x047C,
  753. Omegatonos: 0x038F,
  754. Omicron: 0x039F,
  755. Omicrontonos: 0x038C,
  756. Omonospace: 0xFF2F,
  757. Oneroman: 0x2160,
  758. Oogonek: 0x01EA,
  759. Oogonekmacron: 0x01EC,
  760. Oopen: 0x0186,
  761. Oslash: 0x00D8,
  762. Oslashacute: 0x01FE,
  763. Oslashsmall: 0xF7F8,
  764. Osmall: 0xF76F,
  765. Ostrokeacute: 0x01FE,
  766. Otcyrillic: 0x047E,
  767. Otilde: 0x00D5,
  768. Otildeacute: 0x1E4C,
  769. Otildedieresis: 0x1E4E,
  770. Otildesmall: 0xF7F5,
  771. P: 0x0050,
  772. Pacute: 0x1E54,
  773. Pcircle: 0x24C5,
  774. Pdotaccent: 0x1E56,
  775. Pecyrillic: 0x041F,
  776. Peharmenian: 0x054A,
  777. Pemiddlehookcyrillic: 0x04A6,
  778. Phi: 0x03A6,
  779. Phook: 0x01A4,
  780. Pi: 0x03A0,
  781. Piwrarmenian: 0x0553,
  782. Pmonospace: 0xFF30,
  783. Psi: 0x03A8,
  784. Psicyrillic: 0x0470,
  785. Psmall: 0xF770,
  786. Q: 0x0051,
  787. Qcircle: 0x24C6,
  788. Qmonospace: 0xFF31,
  789. Qsmall: 0xF771,
  790. R: 0x0052,
  791. Raarmenian: 0x054C,
  792. Racute: 0x0154,
  793. Rcaron: 0x0158,
  794. Rcedilla: 0x0156,
  795. Rcircle: 0x24C7,
  796. Rcommaaccent: 0x0156,
  797. Rdblgrave: 0x0210,
  798. Rdotaccent: 0x1E58,
  799. Rdotbelow: 0x1E5A,
  800. Rdotbelowmacron: 0x1E5C,
  801. Reharmenian: 0x0550,
  802. Rfraktur: 0x211C,
  803. Rho: 0x03A1,
  804. Ringsmall: 0xF6FC,
  805. Rinvertedbreve: 0x0212,
  806. Rlinebelow: 0x1E5E,
  807. Rmonospace: 0xFF32,
  808. Rsmall: 0xF772,
  809. Rsmallinverted: 0x0281,
  810. Rsmallinvertedsuperior: 0x02B6,
  811. S: 0x0053,
  812. SF010000: 0x250C,
  813. SF020000: 0x2514,
  814. SF030000: 0x2510,
  815. SF040000: 0x2518,
  816. SF050000: 0x253C,
  817. SF060000: 0x252C,
  818. SF070000: 0x2534,
  819. SF080000: 0x251C,
  820. SF090000: 0x2524,
  821. SF100000: 0x2500,
  822. SF110000: 0x2502,
  823. SF190000: 0x2561,
  824. SF200000: 0x2562,
  825. SF210000: 0x2556,
  826. SF220000: 0x2555,
  827. SF230000: 0x2563,
  828. SF240000: 0x2551,
  829. SF250000: 0x2557,
  830. SF260000: 0x255D,
  831. SF270000: 0x255C,
  832. SF280000: 0x255B,
  833. SF360000: 0x255E,
  834. SF370000: 0x255F,
  835. SF380000: 0x255A,
  836. SF390000: 0x2554,
  837. SF400000: 0x2569,
  838. SF410000: 0x2566,
  839. SF420000: 0x2560,
  840. SF430000: 0x2550,
  841. SF440000: 0x256C,
  842. SF450000: 0x2567,
  843. SF460000: 0x2568,
  844. SF470000: 0x2564,
  845. SF480000: 0x2565,
  846. SF490000: 0x2559,
  847. SF500000: 0x2558,
  848. SF510000: 0x2552,
  849. SF520000: 0x2553,
  850. SF530000: 0x256B,
  851. SF540000: 0x256A,
  852. Sacute: 0x015A,
  853. Sacutedotaccent: 0x1E64,
  854. Sampigreek: 0x03E0,
  855. Scaron: 0x0160,
  856. Scarondotaccent: 0x1E66,
  857. Scaronsmall: 0xF6FD,
  858. Scedilla: 0x015E,
  859. Schwa: 0x018F,
  860. Schwacyrillic: 0x04D8,
  861. Schwadieresiscyrillic: 0x04DA,
  862. Scircle: 0x24C8,
  863. Scircumflex: 0x015C,
  864. Scommaaccent: 0x0218,
  865. Sdotaccent: 0x1E60,
  866. Sdotbelow: 0x1E62,
  867. Sdotbelowdotaccent: 0x1E68,
  868. Seharmenian: 0x054D,
  869. Sevenroman: 0x2166,
  870. Shaarmenian: 0x0547,
  871. Shacyrillic: 0x0428,
  872. Shchacyrillic: 0x0429,
  873. Sheicoptic: 0x03E2,
  874. Shhacyrillic: 0x04BA,
  875. Shimacoptic: 0x03EC,
  876. Sigma: 0x03A3,
  877. Sixroman: 0x2165,
  878. Smonospace: 0xFF33,
  879. Softsigncyrillic: 0x042C,
  880. Ssmall: 0xF773,
  881. Stigmagreek: 0x03DA,
  882. T: 0x0054,
  883. Tau: 0x03A4,
  884. Tbar: 0x0166,
  885. Tcaron: 0x0164,
  886. Tcedilla: 0x0162,
  887. Tcircle: 0x24C9,
  888. Tcircumflexbelow: 0x1E70,
  889. Tcommaaccent: 0x0162,
  890. Tdotaccent: 0x1E6A,
  891. Tdotbelow: 0x1E6C,
  892. Tecyrillic: 0x0422,
  893. Tedescendercyrillic: 0x04AC,
  894. Tenroman: 0x2169,
  895. Tetsecyrillic: 0x04B4,
  896. Theta: 0x0398,
  897. Thook: 0x01AC,
  898. Thorn: 0x00DE,
  899. Thornsmall: 0xF7FE,
  900. Threeroman: 0x2162,
  901. Tildesmall: 0xF6FE,
  902. Tiwnarmenian: 0x054F,
  903. Tlinebelow: 0x1E6E,
  904. Tmonospace: 0xFF34,
  905. Toarmenian: 0x0539,
  906. Tonefive: 0x01BC,
  907. Tonesix: 0x0184,
  908. Tonetwo: 0x01A7,
  909. Tretroflexhook: 0x01AE,
  910. Tsecyrillic: 0x0426,
  911. Tshecyrillic: 0x040B,
  912. Tsmall: 0xF774,
  913. Twelveroman: 0x216B,
  914. Tworoman: 0x2161,
  915. U: 0x0055,
  916. Uacute: 0x00DA,
  917. Uacutesmall: 0xF7FA,
  918. Ubreve: 0x016C,
  919. Ucaron: 0x01D3,
  920. Ucircle: 0x24CA,
  921. Ucircumflex: 0x00DB,
  922. Ucircumflexbelow: 0x1E76,
  923. Ucircumflexsmall: 0xF7FB,
  924. Ucyrillic: 0x0423,
  925. Udblacute: 0x0170,
  926. Udblgrave: 0x0214,
  927. Udieresis: 0x00DC,
  928. Udieresisacute: 0x01D7,
  929. Udieresisbelow: 0x1E72,
  930. Udieresiscaron: 0x01D9,
  931. Udieresiscyrillic: 0x04F0,
  932. Udieresisgrave: 0x01DB,
  933. Udieresismacron: 0x01D5,
  934. Udieresissmall: 0xF7FC,
  935. Udotbelow: 0x1EE4,
  936. Ugrave: 0x00D9,
  937. Ugravesmall: 0xF7F9,
  938. Uhookabove: 0x1EE6,
  939. Uhorn: 0x01AF,
  940. Uhornacute: 0x1EE8,
  941. Uhorndotbelow: 0x1EF0,
  942. Uhorngrave: 0x1EEA,
  943. Uhornhookabove: 0x1EEC,
  944. Uhorntilde: 0x1EEE,
  945. Uhungarumlaut: 0x0170,
  946. Uhungarumlautcyrillic: 0x04F2,
  947. Uinvertedbreve: 0x0216,
  948. Ukcyrillic: 0x0478,
  949. Umacron: 0x016A,
  950. Umacroncyrillic: 0x04EE,
  951. Umacrondieresis: 0x1E7A,
  952. Umonospace: 0xFF35,
  953. Uogonek: 0x0172,
  954. Upsilon: 0x03A5,
  955. Upsilon1: 0x03D2,
  956. Upsilonacutehooksymbolgreek: 0x03D3,
  957. Upsilonafrican: 0x01B1,
  958. Upsilondieresis: 0x03AB,
  959. Upsilondieresishooksymbolgreek: 0x03D4,
  960. Upsilonhooksymbol: 0x03D2,
  961. Upsilontonos: 0x038E,
  962. Uring: 0x016E,
  963. Ushortcyrillic: 0x040E,
  964. Usmall: 0xF775,
  965. Ustraightcyrillic: 0x04AE,
  966. Ustraightstrokecyrillic: 0x04B0,
  967. Utilde: 0x0168,
  968. Utildeacute: 0x1E78,
  969. Utildebelow: 0x1E74,
  970. V: 0x0056,
  971. Vcircle: 0x24CB,
  972. Vdotbelow: 0x1E7E,
  973. Vecyrillic: 0x0412,
  974. Vewarmenian: 0x054E,
  975. Vhook: 0x01B2,
  976. Vmonospace: 0xFF36,
  977. Voarmenian: 0x0548,
  978. Vsmall: 0xF776,
  979. Vtilde: 0x1E7C,
  980. W: 0x0057,
  981. Wacute: 0x1E82,
  982. Wcircle: 0x24CC,
  983. Wcircumflex: 0x0174,
  984. Wdieresis: 0x1E84,
  985. Wdotaccent: 0x1E86,
  986. Wdotbelow: 0x1E88,
  987. Wgrave: 0x1E80,
  988. Wmonospace: 0xFF37,
  989. Wsmall: 0xF777,
  990. X: 0x0058,
  991. Xcircle: 0x24CD,
  992. Xdieresis: 0x1E8C,
  993. Xdotaccent: 0x1E8A,
  994. Xeharmenian: 0x053D,
  995. Xi: 0x039E,
  996. Xmonospace: 0xFF38,
  997. Xsmall: 0xF778,
  998. Y: 0x0059,
  999. Yacute: 0x00DD,
  1000. Yacutesmall: 0xF7FD,
  1001. Yatcyrillic: 0x0462,
  1002. Ycircle: 0x24CE,
  1003. Ycircumflex: 0x0176,
  1004. Ydieresis: 0x0178,
  1005. Ydieresissmall: 0xF7FF,
  1006. Ydotaccent: 0x1E8E,
  1007. Ydotbelow: 0x1EF4,
  1008. Yericyrillic: 0x042B,
  1009. Yerudieresiscyrillic: 0x04F8,
  1010. Ygrave: 0x1EF2,
  1011. Yhook: 0x01B3,
  1012. Yhookabove: 0x1EF6,
  1013. Yiarmenian: 0x0545,
  1014. Yicyrillic: 0x0407,
  1015. Yiwnarmenian: 0x0552,
  1016. Ymonospace: 0xFF39,
  1017. Ysmall: 0xF779,
  1018. Ytilde: 0x1EF8,
  1019. Yusbigcyrillic: 0x046A,
  1020. Yusbigiotifiedcyrillic: 0x046C,
  1021. Yuslittlecyrillic: 0x0466,
  1022. Yuslittleiotifiedcyrillic: 0x0468,
  1023. Z: 0x005A,
  1024. Zaarmenian: 0x0536,
  1025. Zacute: 0x0179,
  1026. Zcaron: 0x017D,
  1027. Zcaronsmall: 0xF6FF,
  1028. Zcircle: 0x24CF,
  1029. Zcircumflex: 0x1E90,
  1030. Zdot: 0x017B,
  1031. Zdotaccent: 0x017B,
  1032. Zdotbelow: 0x1E92,
  1033. Zecyrillic: 0x0417,
  1034. Zedescendercyrillic: 0x0498,
  1035. Zedieresiscyrillic: 0x04DE,
  1036. Zeta: 0x0396,
  1037. Zhearmenian: 0x053A,
  1038. Zhebrevecyrillic: 0x04C1,
  1039. Zhecyrillic: 0x0416,
  1040. Zhedescendercyrillic: 0x0496,
  1041. Zhedieresiscyrillic: 0x04DC,
  1042. Zlinebelow: 0x1E94,
  1043. Zmonospace: 0xFF3A,
  1044. Zsmall: 0xF77A,
  1045. Zstroke: 0x01B5,
  1046. a: 0x0061,
  1047. aabengali: 0x0986,
  1048. aacute: 0x00E1,
  1049. aadeva: 0x0906,
  1050. aagujarati: 0x0A86,
  1051. aagurmukhi: 0x0A06,
  1052. aamatragurmukhi: 0x0A3E,
  1053. aarusquare: 0x3303,
  1054. aavowelsignbengali: 0x09BE,
  1055. aavowelsigndeva: 0x093E,
  1056. aavowelsigngujarati: 0x0ABE,
  1057. abbreviationmarkarmenian: 0x055F,
  1058. abbreviationsigndeva: 0x0970,
  1059. abengali: 0x0985,
  1060. abopomofo: 0x311A,
  1061. abreve: 0x0103,
  1062. abreveacute: 0x1EAF,
  1063. abrevecyrillic: 0x04D1,
  1064. abrevedotbelow: 0x1EB7,
  1065. abrevegrave: 0x1EB1,
  1066. abrevehookabove: 0x1EB3,
  1067. abrevetilde: 0x1EB5,
  1068. acaron: 0x01CE,
  1069. acircle: 0x24D0,
  1070. acircumflex: 0x00E2,
  1071. acircumflexacute: 0x1EA5,
  1072. acircumflexdotbelow: 0x1EAD,
  1073. acircumflexgrave: 0x1EA7,
  1074. acircumflexhookabove: 0x1EA9,
  1075. acircumflextilde: 0x1EAB,
  1076. acute: 0x00B4,
  1077. acutebelowcmb: 0x0317,
  1078. acutecmb: 0x0301,
  1079. acutecomb: 0x0301,
  1080. acutedeva: 0x0954,
  1081. acutelowmod: 0x02CF,
  1082. acutetonecmb: 0x0341,
  1083. acyrillic: 0x0430,
  1084. adblgrave: 0x0201,
  1085. addakgurmukhi: 0x0A71,
  1086. adeva: 0x0905,
  1087. adieresis: 0x00E4,
  1088. adieresiscyrillic: 0x04D3,
  1089. adieresismacron: 0x01DF,
  1090. adotbelow: 0x1EA1,
  1091. adotmacron: 0x01E1,
  1092. ae: 0x00E6,
  1093. aeacute: 0x01FD,
  1094. aekorean: 0x3150,
  1095. aemacron: 0x01E3,
  1096. afii00208: 0x2015,
  1097. afii08941: 0x20A4,
  1098. afii10017: 0x0410,
  1099. afii10018: 0x0411,
  1100. afii10019: 0x0412,
  1101. afii10020: 0x0413,
  1102. afii10021: 0x0414,
  1103. afii10022: 0x0415,
  1104. afii10023: 0x0401,
  1105. afii10024: 0x0416,
  1106. afii10025: 0x0417,
  1107. afii10026: 0x0418,
  1108. afii10027: 0x0419,
  1109. afii10028: 0x041A,
  1110. afii10029: 0x041B,
  1111. afii10030: 0x041C,
  1112. afii10031: 0x041D,
  1113. afii10032: 0x041E,
  1114. afii10033: 0x041F,
  1115. afii10034: 0x0420,
  1116. afii10035: 0x0421,
  1117. afii10036: 0x0422,
  1118. afii10037: 0x0423,
  1119. afii10038: 0x0424,
  1120. afii10039: 0x0425,
  1121. afii10040: 0x0426,
  1122. afii10041: 0x0427,
  1123. afii10042: 0x0428,
  1124. afii10043: 0x0429,
  1125. afii10044: 0x042A,
  1126. afii10045: 0x042B,
  1127. afii10046: 0x042C,
  1128. afii10047: 0x042D,
  1129. afii10048: 0x042E,
  1130. afii10049: 0x042F,
  1131. afii10050: 0x0490,
  1132. afii10051: 0x0402,
  1133. afii10052: 0x0403,
  1134. afii10053: 0x0404,
  1135. afii10054: 0x0405,
  1136. afii10055: 0x0406,
  1137. afii10056: 0x0407,
  1138. afii10057: 0x0408,
  1139. afii10058: 0x0409,
  1140. afii10059: 0x040A,
  1141. afii10060: 0x040B,
  1142. afii10061: 0x040C,
  1143. afii10062: 0x040E,
  1144. afii10063: 0xF6C4,
  1145. afii10064: 0xF6C5,
  1146. afii10065: 0x0430,
  1147. afii10066: 0x0431,
  1148. afii10067: 0x0432,
  1149. afii10068: 0x0433,
  1150. afii10069: 0x0434,
  1151. afii10070: 0x0435,
  1152. afii10071: 0x0451,
  1153. afii10072: 0x0436,
  1154. afii10073: 0x0437,
  1155. afii10074: 0x0438,
  1156. afii10075: 0x0439,
  1157. afii10076: 0x043A,
  1158. afii10077: 0x043B,
  1159. afii10078: 0x043C,
  1160. afii10079: 0x043D,
  1161. afii10080: 0x043E,
  1162. afii10081: 0x043F,
  1163. afii10082: 0x0440,
  1164. afii10083: 0x0441,
  1165. afii10084: 0x0442,
  1166. afii10085: 0x0443,
  1167. afii10086: 0x0444,
  1168. afii10087: 0x0445,
  1169. afii10088: 0x0446,
  1170. afii10089: 0x0447,
  1171. afii10090: 0x0448,
  1172. afii10091: 0x0449,
  1173. afii10092: 0x044A,
  1174. afii10093: 0x044B,
  1175. afii10094: 0x044C,
  1176. afii10095: 0x044D,
  1177. afii10096: 0x044E,
  1178. afii10097: 0x044F,
  1179. afii10098: 0x0491,
  1180. afii10099: 0x0452,
  1181. afii10100: 0x0453,
  1182. afii10101: 0x0454,
  1183. afii10102: 0x0455,
  1184. afii10103: 0x0456,
  1185. afii10104: 0x0457,
  1186. afii10105: 0x0458,
  1187. afii10106: 0x0459,
  1188. afii10107: 0x045A,
  1189. afii10108: 0x045B,
  1190. afii10109: 0x045C,
  1191. afii10110: 0x045E,
  1192. afii10145: 0x040F,
  1193. afii10146: 0x0462,
  1194. afii10147: 0x0472,
  1195. afii10148: 0x0474,
  1196. afii10192: 0xF6C6,
  1197. afii10193: 0x045F,
  1198. afii10194: 0x0463,
  1199. afii10195: 0x0473,
  1200. afii10196: 0x0475,
  1201. afii10831: 0xF6C7,
  1202. afii10832: 0xF6C8,
  1203. afii10846: 0x04D9,
  1204. afii299: 0x200E,
  1205. afii300: 0x200F,
  1206. afii301: 0x200D,
  1207. afii57381: 0x066A,
  1208. afii57388: 0x060C,
  1209. afii57392: 0x0660,
  1210. afii57393: 0x0661,
  1211. afii57394: 0x0662,
  1212. afii57395: 0x0663,
  1213. afii57396: 0x0664,
  1214. afii57397: 0x0665,
  1215. afii57398: 0x0666,
  1216. afii57399: 0x0667,
  1217. afii57400: 0x0668,
  1218. afii57401: 0x0669,
  1219. afii57403: 0x061B,
  1220. afii57407: 0x061F,
  1221. afii57409: 0x0621,
  1222. afii57410: 0x0622,
  1223. afii57411: 0x0623,
  1224. afii57412: 0x0624,
  1225. afii57413: 0x0625,
  1226. afii57414: 0x0626,
  1227. afii57415: 0x0627,
  1228. afii57416: 0x0628,
  1229. afii57417: 0x0629,
  1230. afii57418: 0x062A,
  1231. afii57419: 0x062B,
  1232. afii57420: 0x062C,
  1233. afii57421: 0x062D,
  1234. afii57422: 0x062E,
  1235. afii57423: 0x062F,
  1236. afii57424: 0x0630,
  1237. afii57425: 0x0631,
  1238. afii57426: 0x0632,
  1239. afii57427: 0x0633,
  1240. afii57428: 0x0634,
  1241. afii57429: 0x0635,
  1242. afii57430: 0x0636,
  1243. afii57431: 0x0637,
  1244. afii57432: 0x0638,
  1245. afii57433: 0x0639,
  1246. afii57434: 0x063A,
  1247. afii57440: 0x0640,
  1248. afii57441: 0x0641,
  1249. afii57442: 0x0642,
  1250. afii57443: 0x0643,
  1251. afii57444: 0x0644,
  1252. afii57445: 0x0645,
  1253. afii57446: 0x0646,
  1254. afii57448: 0x0648,
  1255. afii57449: 0x0649,
  1256. afii57450: 0x064A,
  1257. afii57451: 0x064B,
  1258. afii57452: 0x064C,
  1259. afii57453: 0x064D,
  1260. afii57454: 0x064E,
  1261. afii57455: 0x064F,
  1262. afii57456: 0x0650,
  1263. afii57457: 0x0651,
  1264. afii57458: 0x0652,
  1265. afii57470: 0x0647,
  1266. afii57505: 0x06A4,
  1267. afii57506: 0x067E,
  1268. afii57507: 0x0686,
  1269. afii57508: 0x0698,
  1270. afii57509: 0x06AF,
  1271. afii57511: 0x0679,
  1272. afii57512: 0x0688,
  1273. afii57513: 0x0691,
  1274. afii57514: 0x06BA,
  1275. afii57519: 0x06D2,
  1276. afii57534: 0x06D5,
  1277. afii57636: 0x20AA,
  1278. afii57645: 0x05BE,
  1279. afii57658: 0x05C3,
  1280. afii57664: 0x05D0,
  1281. afii57665: 0x05D1,
  1282. afii57666: 0x05D2,
  1283. afii57667: 0x05D3,
  1284. afii57668: 0x05D4,
  1285. afii57669: 0x05D5,
  1286. afii57670: 0x05D6,
  1287. afii57671: 0x05D7,
  1288. afii57672: 0x05D8,
  1289. afii57673: 0x05D9,
  1290. afii57674: 0x05DA,
  1291. afii57675: 0x05DB,
  1292. afii57676: 0x05DC,
  1293. afii57677: 0x05DD,
  1294. afii57678: 0x05DE,
  1295. afii57679: 0x05DF,
  1296. afii57680: 0x05E0,
  1297. afii57681: 0x05E1,
  1298. afii57682: 0x05E2,
  1299. afii57683: 0x05E3,
  1300. afii57684: 0x05E4,
  1301. afii57685: 0x05E5,
  1302. afii57686: 0x05E6,
  1303. afii57687: 0x05E7,
  1304. afii57688: 0x05E8,
  1305. afii57689: 0x05E9,
  1306. afii57690: 0x05EA,
  1307. afii57694: 0xFB2A,
  1308. afii57695: 0xFB2B,
  1309. afii57700: 0xFB4B,
  1310. afii57705: 0xFB1F,
  1311. afii57716: 0x05F0,
  1312. afii57717: 0x05F1,
  1313. afii57718: 0x05F2,
  1314. afii57723: 0xFB35,
  1315. afii57793: 0x05B4,
  1316. afii57794: 0x05B5,
  1317. afii57795: 0x05B6,
  1318. afii57796: 0x05BB,
  1319. afii57797: 0x05B8,
  1320. afii57798: 0x05B7,
  1321. afii57799: 0x05B0,
  1322. afii57800: 0x05B2,
  1323. afii57801: 0x05B1,
  1324. afii57802: 0x05B3,
  1325. afii57803: 0x05C2,
  1326. afii57804: 0x05C1,
  1327. afii57806: 0x05B9,
  1328. afii57807: 0x05BC,
  1329. afii57839: 0x05BD,
  1330. afii57841: 0x05BF,
  1331. afii57842: 0x05C0,
  1332. afii57929: 0x02BC,
  1333. afii61248: 0x2105,
  1334. afii61289: 0x2113,
  1335. afii61352: 0x2116,
  1336. afii61573: 0x202C,
  1337. afii61574: 0x202D,
  1338. afii61575: 0x202E,
  1339. afii61664: 0x200C,
  1340. afii63167: 0x066D,
  1341. afii64937: 0x02BD,
  1342. agrave: 0x00E0,
  1343. agujarati: 0x0A85,
  1344. agurmukhi: 0x0A05,
  1345. ahiragana: 0x3042,
  1346. ahookabove: 0x1EA3,
  1347. aibengali: 0x0990,
  1348. aibopomofo: 0x311E,
  1349. aideva: 0x0910,
  1350. aiecyrillic: 0x04D5,
  1351. aigujarati: 0x0A90,
  1352. aigurmukhi: 0x0A10,
  1353. aimatragurmukhi: 0x0A48,
  1354. ainarabic: 0x0639,
  1355. ainfinalarabic: 0xFECA,
  1356. aininitialarabic: 0xFECB,
  1357. ainmedialarabic: 0xFECC,
  1358. ainvertedbreve: 0x0203,
  1359. aivowelsignbengali: 0x09C8,
  1360. aivowelsigndeva: 0x0948,
  1361. aivowelsigngujarati: 0x0AC8,
  1362. akatakana: 0x30A2,
  1363. akatakanahalfwidth: 0xFF71,
  1364. akorean: 0x314F,
  1365. alef: 0x05D0,
  1366. alefarabic: 0x0627,
  1367. alefdageshhebrew: 0xFB30,
  1368. aleffinalarabic: 0xFE8E,
  1369. alefhamzaabovearabic: 0x0623,
  1370. alefhamzaabovefinalarabic: 0xFE84,
  1371. alefhamzabelowarabic: 0x0625,
  1372. alefhamzabelowfinalarabic: 0xFE88,
  1373. alefhebrew: 0x05D0,
  1374. aleflamedhebrew: 0xFB4F,
  1375. alefmaddaabovearabic: 0x0622,
  1376. alefmaddaabovefinalarabic: 0xFE82,
  1377. alefmaksuraarabic: 0x0649,
  1378. alefmaksurafinalarabic: 0xFEF0,
  1379. alefmaksurainitialarabic: 0xFEF3,
  1380. alefmaksuramedialarabic: 0xFEF4,
  1381. alefpatahhebrew: 0xFB2E,
  1382. alefqamatshebrew: 0xFB2F,
  1383. aleph: 0x2135,
  1384. allequal: 0x224C,
  1385. alpha: 0x03B1,
  1386. alphatonos: 0x03AC,
  1387. amacron: 0x0101,
  1388. amonospace: 0xFF41,
  1389. ampersand: 0x0026,
  1390. ampersandmonospace: 0xFF06,
  1391. ampersandsmall: 0xF726,
  1392. amsquare: 0x33C2,
  1393. anbopomofo: 0x3122,
  1394. angbopomofo: 0x3124,
  1395. angbracketleft: 0x3008, // This glyph is missing from Adobe's original list.
  1396. angbracketright: 0x3009, // This glyph is missing from Adobe's original list.
  1397. angkhankhuthai: 0x0E5A,
  1398. angle: 0x2220,
  1399. anglebracketleft: 0x3008,
  1400. anglebracketleftvertical: 0xFE3F,
  1401. anglebracketright: 0x3009,
  1402. anglebracketrightvertical: 0xFE40,
  1403. angleleft: 0x2329,
  1404. angleright: 0x232A,
  1405. angstrom: 0x212B,
  1406. anoteleia: 0x0387,
  1407. anudattadeva: 0x0952,
  1408. anusvarabengali: 0x0982,
  1409. anusvaradeva: 0x0902,
  1410. anusvaragujarati: 0x0A82,
  1411. aogonek: 0x0105,
  1412. apaatosquare: 0x3300,
  1413. aparen: 0x249C,
  1414. apostrophearmenian: 0x055A,
  1415. apostrophemod: 0x02BC,
  1416. apple: 0xF8FF,
  1417. approaches: 0x2250,
  1418. approxequal: 0x2248,
  1419. approxequalorimage: 0x2252,
  1420. approximatelyequal: 0x2245,
  1421. araeaekorean: 0x318E,
  1422. araeakorean: 0x318D,
  1423. arc: 0x2312,
  1424. arighthalfring: 0x1E9A,
  1425. aring: 0x00E5,
  1426. aringacute: 0x01FB,
  1427. aringbelow: 0x1E01,
  1428. arrowboth: 0x2194,
  1429. arrowdashdown: 0x21E3,
  1430. arrowdashleft: 0x21E0,
  1431. arrowdashright: 0x21E2,
  1432. arrowdashup: 0x21E1,
  1433. arrowdblboth: 0x21D4,
  1434. arrowdbldown: 0x21D3,
  1435. arrowdblleft: 0x21D0,
  1436. arrowdblright: 0x21D2,
  1437. arrowdblup: 0x21D1,
  1438. arrowdown: 0x2193,
  1439. arrowdownleft: 0x2199,
  1440. arrowdownright: 0x2198,
  1441. arrowdownwhite: 0x21E9,
  1442. arrowheaddownmod: 0x02C5,
  1443. arrowheadleftmod: 0x02C2,
  1444. arrowheadrightmod: 0x02C3,
  1445. arrowheadupmod: 0x02C4,
  1446. arrowhorizex: 0xF8E7,
  1447. arrowleft: 0x2190,
  1448. arrowleftdbl: 0x21D0,
  1449. arrowleftdblstroke: 0x21CD,
  1450. arrowleftoverright: 0x21C6,
  1451. arrowleftwhite: 0x21E6,
  1452. arrowright: 0x2192,
  1453. arrowrightdblstroke: 0x21CF,
  1454. arrowrightheavy: 0x279E,
  1455. arrowrightoverleft: 0x21C4,
  1456. arrowrightwhite: 0x21E8,
  1457. arrowtableft: 0x21E4,
  1458. arrowtabright: 0x21E5,
  1459. arrowup: 0x2191,
  1460. arrowupdn: 0x2195,
  1461. arrowupdnbse: 0x21A8,
  1462. arrowupdownbase: 0x21A8,
  1463. arrowupleft: 0x2196,
  1464. arrowupleftofdown: 0x21C5,
  1465. arrowupright: 0x2197,
  1466. arrowupwhite: 0x21E7,
  1467. arrowvertex: 0xF8E6,
  1468. asciicircum: 0x005E,
  1469. asciicircummonospace: 0xFF3E,
  1470. asciitilde: 0x007E,
  1471. asciitildemonospace: 0xFF5E,
  1472. ascript: 0x0251,
  1473. ascriptturned: 0x0252,
  1474. asmallhiragana: 0x3041,
  1475. asmallkatakana: 0x30A1,
  1476. asmallkatakanahalfwidth: 0xFF67,
  1477. asterisk: 0x002A,
  1478. asteriskaltonearabic: 0x066D,
  1479. asteriskarabic: 0x066D,
  1480. asteriskmath: 0x2217,
  1481. asteriskmonospace: 0xFF0A,
  1482. asterisksmall: 0xFE61,
  1483. asterism: 0x2042,
  1484. asuperior: 0xF6E9,
  1485. asymptoticallyequal: 0x2243,
  1486. at: 0x0040,
  1487. atilde: 0x00E3,
  1488. atmonospace: 0xFF20,
  1489. atsmall: 0xFE6B,
  1490. aturned: 0x0250,
  1491. aubengali: 0x0994,
  1492. aubopomofo: 0x3120,
  1493. audeva: 0x0914,
  1494. augujarati: 0x0A94,
  1495. augurmukhi: 0x0A14,
  1496. aulengthmarkbengali: 0x09D7,
  1497. aumatragurmukhi: 0x0A4C,
  1498. auvowelsignbengali: 0x09CC,
  1499. auvowelsigndeva: 0x094C,
  1500. auvowelsigngujarati: 0x0ACC,
  1501. avagrahadeva: 0x093D,
  1502. aybarmenian: 0x0561,
  1503. ayin: 0x05E2,
  1504. ayinaltonehebrew: 0xFB20,
  1505. ayinhebrew: 0x05E2,
  1506. b: 0x0062,
  1507. babengali: 0x09AC,
  1508. backslash: 0x005C,
  1509. backslashmonospace: 0xFF3C,
  1510. badeva: 0x092C,
  1511. bagujarati: 0x0AAC,
  1512. bagurmukhi: 0x0A2C,
  1513. bahiragana: 0x3070,
  1514. bahtthai: 0x0E3F,
  1515. bakatakana: 0x30D0,
  1516. bar: 0x007C,
  1517. barmonospace: 0xFF5C,
  1518. bbopomofo: 0x3105,
  1519. bcircle: 0x24D1,
  1520. bdotaccent: 0x1E03,
  1521. bdotbelow: 0x1E05,
  1522. beamedsixteenthnotes: 0x266C,
  1523. because: 0x2235,
  1524. becyrillic: 0x0431,
  1525. beharabic: 0x0628,
  1526. behfinalarabic: 0xFE90,
  1527. behinitialarabic: 0xFE91,
  1528. behiragana: 0x3079,
  1529. behmedialarabic: 0xFE92,
  1530. behmeeminitialarabic: 0xFC9F,
  1531. behmeemisolatedarabic: 0xFC08,
  1532. behnoonfinalarabic: 0xFC6D,
  1533. bekatakana: 0x30D9,
  1534. benarmenian: 0x0562,
  1535. bet: 0x05D1,
  1536. beta: 0x03B2,
  1537. betasymbolgreek: 0x03D0,
  1538. betdagesh: 0xFB31,
  1539. betdageshhebrew: 0xFB31,
  1540. bethebrew: 0x05D1,
  1541. betrafehebrew: 0xFB4C,
  1542. bhabengali: 0x09AD,
  1543. bhadeva: 0x092D,
  1544. bhagujarati: 0x0AAD,
  1545. bhagurmukhi: 0x0A2D,
  1546. bhook: 0x0253,
  1547. bihiragana: 0x3073,
  1548. bikatakana: 0x30D3,
  1549. bilabialclick: 0x0298,
  1550. bindigurmukhi: 0x0A02,
  1551. birusquare: 0x3331,
  1552. blackcircle: 0x25CF,
  1553. blackdiamond: 0x25C6,
  1554. blackdownpointingtriangle: 0x25BC,
  1555. blackleftpointingpointer: 0x25C4,
  1556. blackleftpointingtriangle: 0x25C0,
  1557. blacklenticularbracketleft: 0x3010,
  1558. blacklenticularbracketleftvertical: 0xFE3B,
  1559. blacklenticularbracketright: 0x3011,
  1560. blacklenticularbracketrightvertical: 0xFE3C,
  1561. blacklowerlefttriangle: 0x25E3,
  1562. blacklowerrighttriangle: 0x25E2,
  1563. blackrectangle: 0x25AC,
  1564. blackrightpointingpointer: 0x25BA,
  1565. blackrightpointingtriangle: 0x25B6,
  1566. blacksmallsquare: 0x25AA,
  1567. blacksmilingface: 0x263B,
  1568. blacksquare: 0x25A0,
  1569. blackstar: 0x2605,
  1570. blackupperlefttriangle: 0x25E4,
  1571. blackupperrighttriangle: 0x25E5,
  1572. blackuppointingsmalltriangle: 0x25B4,
  1573. blackuppointingtriangle: 0x25B2,
  1574. blank: 0x2423,
  1575. blinebelow: 0x1E07,
  1576. block: 0x2588,
  1577. bmonospace: 0xFF42,
  1578. bobaimaithai: 0x0E1A,
  1579. bohiragana: 0x307C,
  1580. bokatakana: 0x30DC,
  1581. bparen: 0x249D,
  1582. bqsquare: 0x33C3,
  1583. braceex: 0xF8F4,
  1584. braceleft: 0x007B,
  1585. braceleftbt: 0xF8F3,
  1586. braceleftmid: 0xF8F2,
  1587. braceleftmonospace: 0xFF5B,
  1588. braceleftsmall: 0xFE5B,
  1589. bracelefttp: 0xF8F1,
  1590. braceleftvertical: 0xFE37,
  1591. braceright: 0x007D,
  1592. bracerightbt: 0xF8FE,
  1593. bracerightmid: 0xF8FD,
  1594. bracerightmonospace: 0xFF5D,
  1595. bracerightsmall: 0xFE5C,
  1596. bracerighttp: 0xF8FC,
  1597. bracerightvertical: 0xFE38,
  1598. bracketleft: 0x005B,
  1599. bracketleftbt: 0xF8F0,
  1600. bracketleftex: 0xF8EF,
  1601. bracketleftmonospace: 0xFF3B,
  1602. bracketlefttp: 0xF8EE,
  1603. bracketright: 0x005D,
  1604. bracketrightbt: 0xF8FB,
  1605. bracketrightex: 0xF8FA,
  1606. bracketrightmonospace: 0xFF3D,
  1607. bracketrighttp: 0xF8F9,
  1608. breve: 0x02D8,
  1609. brevebelowcmb: 0x032E,
  1610. brevecmb: 0x0306,
  1611. breveinvertedbelowcmb: 0x032F,
  1612. breveinvertedcmb: 0x0311,
  1613. breveinverteddoublecmb: 0x0361,
  1614. bridgebelowcmb: 0x032A,
  1615. bridgeinvertedbelowcmb: 0x033A,
  1616. brokenbar: 0x00A6,
  1617. bstroke: 0x0180,
  1618. bsuperior: 0xF6EA,
  1619. btopbar: 0x0183,
  1620. buhiragana: 0x3076,
  1621. bukatakana: 0x30D6,
  1622. bullet: 0x2022,
  1623. bulletinverse: 0x25D8,
  1624. bulletoperator: 0x2219,
  1625. bullseye: 0x25CE,
  1626. c: 0x0063,
  1627. caarmenian: 0x056E,
  1628. cabengali: 0x099A,
  1629. cacute: 0x0107,
  1630. cadeva: 0x091A,
  1631. cagujarati: 0x0A9A,
  1632. cagurmukhi: 0x0A1A,
  1633. calsquare: 0x3388,
  1634. candrabindubengali: 0x0981,
  1635. candrabinducmb: 0x0310,
  1636. candrabindudeva: 0x0901,
  1637. candrabindugujarati: 0x0A81,
  1638. capslock: 0x21EA,
  1639. careof: 0x2105,
  1640. caron: 0x02C7,
  1641. caronbelowcmb: 0x032C,
  1642. caroncmb: 0x030C,
  1643. carriagereturn: 0x21B5,
  1644. cbopomofo: 0x3118,
  1645. ccaron: 0x010D,
  1646. ccedilla: 0x00E7,
  1647. ccedillaacute: 0x1E09,
  1648. ccircle: 0x24D2,
  1649. ccircumflex: 0x0109,
  1650. ccurl: 0x0255,
  1651. cdot: 0x010B,
  1652. cdotaccent: 0x010B,
  1653. cdsquare: 0x33C5,
  1654. cedilla: 0x00B8,
  1655. cedillacmb: 0x0327,
  1656. cent: 0x00A2,
  1657. centigrade: 0x2103,
  1658. centinferior: 0xF6DF,
  1659. centmonospace: 0xFFE0,
  1660. centoldstyle: 0xF7A2,
  1661. centsuperior: 0xF6E0,
  1662. chaarmenian: 0x0579,
  1663. chabengali: 0x099B,
  1664. chadeva: 0x091B,
  1665. chagujarati: 0x0A9B,
  1666. chagurmukhi: 0x0A1B,
  1667. chbopomofo: 0x3114,
  1668. cheabkhasiancyrillic: 0x04BD,
  1669. checkmark: 0x2713,
  1670. checyrillic: 0x0447,
  1671. chedescenderabkhasiancyrillic: 0x04BF,
  1672. chedescendercyrillic: 0x04B7,
  1673. chedieresiscyrillic: 0x04F5,
  1674. cheharmenian: 0x0573,
  1675. chekhakassiancyrillic: 0x04CC,
  1676. cheverticalstrokecyrillic: 0x04B9,
  1677. chi: 0x03C7,
  1678. chieuchacirclekorean: 0x3277,
  1679. chieuchaparenkorean: 0x3217,
  1680. chieuchcirclekorean: 0x3269,
  1681. chieuchkorean: 0x314A,
  1682. chieuchparenkorean: 0x3209,
  1683. chochangthai: 0x0E0A,
  1684. chochanthai: 0x0E08,
  1685. chochingthai: 0x0E09,
  1686. chochoethai: 0x0E0C,
  1687. chook: 0x0188,
  1688. cieucacirclekorean: 0x3276,
  1689. cieucaparenkorean: 0x3216,
  1690. cieuccirclekorean: 0x3268,
  1691. cieuckorean: 0x3148,
  1692. cieucparenkorean: 0x3208,
  1693. cieucuparenkorean: 0x321C,
  1694. circle: 0x25CB,
  1695. circlecopyrt: 0x00A9, // This glyph is missing from Adobe's original list.
  1696. circlemultiply: 0x2297,
  1697. circleot: 0x2299,
  1698. circleplus: 0x2295,
  1699. circlepostalmark: 0x3036,
  1700. circlewithlefthalfblack: 0x25D0,
  1701. circlewithrighthalfblack: 0x25D1,
  1702. circumflex: 0x02C6,
  1703. circumflexbelowcmb: 0x032D,
  1704. circumflexcmb: 0x0302,
  1705. clear: 0x2327,
  1706. clickalveolar: 0x01C2,
  1707. clickdental: 0x01C0,
  1708. clicklateral: 0x01C1,
  1709. clickretroflex: 0x01C3,
  1710. club: 0x2663,
  1711. clubsuitblack: 0x2663,
  1712. clubsuitwhite: 0x2667,
  1713. cmcubedsquare: 0x33A4,
  1714. cmonospace: 0xFF43,
  1715. cmsquaredsquare: 0x33A0,
  1716. coarmenian: 0x0581,
  1717. colon: 0x003A,
  1718. colonmonetary: 0x20A1,
  1719. colonmonospace: 0xFF1A,
  1720. colonsign: 0x20A1,
  1721. colonsmall: 0xFE55,
  1722. colontriangularhalfmod: 0x02D1,
  1723. colontriangularmod: 0x02D0,
  1724. comma: 0x002C,
  1725. commaabovecmb: 0x0313,
  1726. commaaboverightcmb: 0x0315,
  1727. commaaccent: 0xF6C3,
  1728. commaarabic: 0x060C,
  1729. commaarmenian: 0x055D,
  1730. commainferior: 0xF6E1,
  1731. commamonospace: 0xFF0C,
  1732. commareversedabovecmb: 0x0314,
  1733. commareversedmod: 0x02BD,
  1734. commasmall: 0xFE50,
  1735. commasuperior: 0xF6E2,
  1736. commaturnedabovecmb: 0x0312,
  1737. commaturnedmod: 0x02BB,
  1738. compass: 0x263C,
  1739. congruent: 0x2245,
  1740. contourintegral: 0x222E,
  1741. control: 0x2303,
  1742. controlACK: 0x0006,
  1743. controlBEL: 0x0007,
  1744. controlBS: 0x0008,
  1745. controlCAN: 0x0018,
  1746. controlCR: 0x000D,
  1747. controlDC1: 0x0011,
  1748. controlDC2: 0x0012,
  1749. controlDC3: 0x0013,
  1750. controlDC4: 0x0014,
  1751. controlDEL: 0x007F,
  1752. controlDLE: 0x0010,
  1753. controlEM: 0x0019,
  1754. controlENQ: 0x0005,
  1755. controlEOT: 0x0004,
  1756. controlESC: 0x001B,
  1757. controlETB: 0x0017,
  1758. controlETX: 0x0003,
  1759. controlFF: 0x000C,
  1760. controlFS: 0x001C,
  1761. controlGS: 0x001D,
  1762. controlHT: 0x0009,
  1763. controlLF: 0x000A,
  1764. controlNAK: 0x0015,
  1765. controlRS: 0x001E,
  1766. controlSI: 0x000F,
  1767. controlSO: 0x000E,
  1768. controlSOT: 0x0002,
  1769. controlSTX: 0x0001,
  1770. controlSUB: 0x001A,
  1771. controlSYN: 0x0016,
  1772. controlUS: 0x001F,
  1773. controlVT: 0x000B,
  1774. copyright: 0x00A9,
  1775. copyrightsans: 0xF8E9,
  1776. copyrightserif: 0xF6D9,
  1777. cornerbracketleft: 0x300C,
  1778. cornerbracketlefthalfwidth: 0xFF62,
  1779. cornerbracketleftvertical: 0xFE41,
  1780. cornerbracketright: 0x300D,
  1781. cornerbracketrighthalfwidth: 0xFF63,
  1782. cornerbracketrightvertical: 0xFE42,
  1783. corporationsquare: 0x337F,
  1784. cosquare: 0x33C7,
  1785. coverkgsquare: 0x33C6,
  1786. cparen: 0x249E,
  1787. cruzeiro: 0x20A2,
  1788. cstretched: 0x0297,
  1789. curlyand: 0x22CF,
  1790. curlyor: 0x22CE,
  1791. currency: 0x00A4,
  1792. cyrBreve: 0xF6D1,
  1793. cyrFlex: 0xF6D2,
  1794. cyrbreve: 0xF6D4,
  1795. cyrflex: 0xF6D5,
  1796. d: 0x0064,
  1797. daarmenian: 0x0564,
  1798. dabengali: 0x09A6,
  1799. dadarabic: 0x0636,
  1800. dadeva: 0x0926,
  1801. dadfinalarabic: 0xFEBE,
  1802. dadinitialarabic: 0xFEBF,
  1803. dadmedialarabic: 0xFEC0,
  1804. dagesh: 0x05BC,
  1805. dageshhebrew: 0x05BC,
  1806. dagger: 0x2020,
  1807. daggerdbl: 0x2021,
  1808. dagujarati: 0x0AA6,
  1809. dagurmukhi: 0x0A26,
  1810. dahiragana: 0x3060,
  1811. dakatakana: 0x30C0,
  1812. dalarabic: 0x062F,
  1813. dalet: 0x05D3,
  1814. daletdagesh: 0xFB33,
  1815. daletdageshhebrew: 0xFB33,
  1816. dalethebrew: 0x05D3,
  1817. dalfinalarabic: 0xFEAA,
  1818. dammaarabic: 0x064F,
  1819. dammalowarabic: 0x064F,
  1820. dammatanaltonearabic: 0x064C,
  1821. dammatanarabic: 0x064C,
  1822. danda: 0x0964,
  1823. dargahebrew: 0x05A7,
  1824. dargalefthebrew: 0x05A7,
  1825. dasiapneumatacyrilliccmb: 0x0485,
  1826. dblGrave: 0xF6D3,
  1827. dblanglebracketleft: 0x300A,
  1828. dblanglebracketleftvertical: 0xFE3D,
  1829. dblanglebracketright: 0x300B,
  1830. dblanglebracketrightvertical: 0xFE3E,
  1831. dblarchinvertedbelowcmb: 0x032B,
  1832. dblarrowleft: 0x21D4,
  1833. dblarrowright: 0x21D2,
  1834. dbldanda: 0x0965,
  1835. dblgrave: 0xF6D6,
  1836. dblgravecmb: 0x030F,
  1837. dblintegral: 0x222C,
  1838. dbllowline: 0x2017,
  1839. dbllowlinecmb: 0x0333,
  1840. dbloverlinecmb: 0x033F,
  1841. dblprimemod: 0x02BA,
  1842. dblverticalbar: 0x2016,
  1843. dblverticallineabovecmb: 0x030E,
  1844. dbopomofo: 0x3109,
  1845. dbsquare: 0x33C8,
  1846. dcaron: 0x010F,
  1847. dcedilla: 0x1E11,
  1848. dcircle: 0x24D3,
  1849. dcircumflexbelow: 0x1E13,
  1850. dcroat: 0x0111,
  1851. ddabengali: 0x09A1,
  1852. ddadeva: 0x0921,
  1853. ddagujarati: 0x0AA1,
  1854. ddagurmukhi: 0x0A21,
  1855. ddalarabic: 0x0688,
  1856. ddalfinalarabic: 0xFB89,
  1857. dddhadeva: 0x095C,
  1858. ddhabengali: 0x09A2,
  1859. ddhadeva: 0x0922,
  1860. ddhagujarati: 0x0AA2,
  1861. ddhagurmukhi: 0x0A22,
  1862. ddotaccent: 0x1E0B,
  1863. ddotbelow: 0x1E0D,
  1864. decimalseparatorarabic: 0x066B,
  1865. decimalseparatorpersian: 0x066B,
  1866. decyrillic: 0x0434,
  1867. degree: 0x00B0,
  1868. dehihebrew: 0x05AD,
  1869. dehiragana: 0x3067,
  1870. deicoptic: 0x03EF,
  1871. dekatakana: 0x30C7,
  1872. deleteleft: 0x232B,
  1873. deleteright: 0x2326,
  1874. delta: 0x03B4,
  1875. deltaturned: 0x018D,
  1876. denominatorminusonenumeratorbengali: 0x09F8,
  1877. dezh: 0x02A4,
  1878. dhabengali: 0x09A7,
  1879. dhadeva: 0x0927,
  1880. dhagujarati: 0x0AA7,
  1881. dhagurmukhi: 0x0A27,
  1882. dhook: 0x0257,
  1883. dialytikatonos: 0x0385,
  1884. dialytikatonoscmb: 0x0344,
  1885. diamond: 0x2666,
  1886. diamondsuitwhite: 0x2662,
  1887. dieresis: 0x00A8,
  1888. dieresisacute: 0xF6D7,
  1889. dieresisbelowcmb: 0x0324,
  1890. dieresiscmb: 0x0308,
  1891. dieresisgrave: 0xF6D8,
  1892. dieresistonos: 0x0385,
  1893. dihiragana: 0x3062,
  1894. dikatakana: 0x30C2,
  1895. dittomark: 0x3003,
  1896. divide: 0x00F7,
  1897. divides: 0x2223,
  1898. divisionslash: 0x2215,
  1899. djecyrillic: 0x0452,
  1900. dkshade: 0x2593,
  1901. dlinebelow: 0x1E0F,
  1902. dlsquare: 0x3397,
  1903. dmacron: 0x0111,
  1904. dmonospace: 0xFF44,
  1905. dnblock: 0x2584,
  1906. dochadathai: 0x0E0E,
  1907. dodekthai: 0x0E14,
  1908. dohiragana: 0x3069,
  1909. dokatakana: 0x30C9,
  1910. dollar: 0x0024,
  1911. dollarinferior: 0xF6E3,
  1912. dollarmonospace: 0xFF04,
  1913. dollaroldstyle: 0xF724,
  1914. dollarsmall: 0xFE69,
  1915. dollarsuperior: 0xF6E4,
  1916. dong: 0x20AB,
  1917. dorusquare: 0x3326,
  1918. dotaccent: 0x02D9,
  1919. dotaccentcmb: 0x0307,
  1920. dotbelowcmb: 0x0323,
  1921. dotbelowcomb: 0x0323,
  1922. dotkatakana: 0x30FB,
  1923. dotlessi: 0x0131,
  1924. dotlessj: 0xF6BE,
  1925. dotlessjstrokehook: 0x0284,
  1926. dotmath: 0x22C5,
  1927. dottedcircle: 0x25CC,
  1928. doubleyodpatah: 0xFB1F,
  1929. doubleyodpatahhebrew: 0xFB1F,
  1930. downtackbelowcmb: 0x031E,
  1931. downtackmod: 0x02D5,
  1932. dparen: 0x249F,
  1933. dsuperior: 0xF6EB,
  1934. dtail: 0x0256,
  1935. dtopbar: 0x018C,
  1936. duhiragana: 0x3065,
  1937. dukatakana: 0x30C5,
  1938. dz: 0x01F3,
  1939. dzaltone: 0x02A3,
  1940. dzcaron: 0x01C6,
  1941. dzcurl: 0x02A5,
  1942. dzeabkhasiancyrillic: 0x04E1,
  1943. dzecyrillic: 0x0455,
  1944. dzhecyrillic: 0x045F,
  1945. e: 0x0065,
  1946. eacute: 0x00E9,
  1947. earth: 0x2641,
  1948. ebengali: 0x098F,
  1949. ebopomofo: 0x311C,
  1950. ebreve: 0x0115,
  1951. ecandradeva: 0x090D,
  1952. ecandragujarati: 0x0A8D,
  1953. ecandravowelsigndeva: 0x0945,
  1954. ecandravowelsigngujarati: 0x0AC5,
  1955. ecaron: 0x011B,
  1956. ecedillabreve: 0x1E1D,
  1957. echarmenian: 0x0565,
  1958. echyiwnarmenian: 0x0587,
  1959. ecircle: 0x24D4,
  1960. ecircumflex: 0x00EA,
  1961. ecircumflexacute: 0x1EBF,
  1962. ecircumflexbelow: 0x1E19,
  1963. ecircumflexdotbelow: 0x1EC7,
  1964. ecircumflexgrave: 0x1EC1,
  1965. ecircumflexhookabove: 0x1EC3,
  1966. ecircumflextilde: 0x1EC5,
  1967. ecyrillic: 0x0454,
  1968. edblgrave: 0x0205,
  1969. edeva: 0x090F,
  1970. edieresis: 0x00EB,
  1971. edot: 0x0117,
  1972. edotaccent: 0x0117,
  1973. edotbelow: 0x1EB9,
  1974. eegurmukhi: 0x0A0F,
  1975. eematragurmukhi: 0x0A47,
  1976. efcyrillic: 0x0444,
  1977. egrave: 0x00E8,
  1978. egujarati: 0x0A8F,
  1979. eharmenian: 0x0567,
  1980. ehbopomofo: 0x311D,
  1981. ehiragana: 0x3048,
  1982. ehookabove: 0x1EBB,
  1983. eibopomofo: 0x311F,
  1984. eight: 0x0038,
  1985. eightarabic: 0x0668,
  1986. eightbengali: 0x09EE,
  1987. eightcircle: 0x2467,
  1988. eightcircleinversesansserif: 0x2791,
  1989. eightdeva: 0x096E,
  1990. eighteencircle: 0x2471,
  1991. eighteenparen: 0x2485,
  1992. eighteenperiod: 0x2499,
  1993. eightgujarati: 0x0AEE,
  1994. eightgurmukhi: 0x0A6E,
  1995. eighthackarabic: 0x0668,
  1996. eighthangzhou: 0x3028,
  1997. eighthnotebeamed: 0x266B,
  1998. eightideographicparen: 0x3227,
  1999. eightinferior: 0x2088,
  2000. eightmonospace: 0xFF18,
  2001. eightoldstyle: 0xF738,
  2002. eightparen: 0x247B,
  2003. eightperiod: 0x248F,
  2004. eightpersian: 0x06F8,
  2005. eightroman: 0x2177,
  2006. eightsuperior: 0x2078,
  2007. eightthai: 0x0E58,
  2008. einvertedbreve: 0x0207,
  2009. eiotifiedcyrillic: 0x0465,
  2010. ekatakana: 0x30A8,
  2011. ekatakanahalfwidth: 0xFF74,
  2012. ekonkargurmukhi: 0x0A74,
  2013. ekorean: 0x3154,
  2014. elcyrillic: 0x043B,
  2015. element: 0x2208,
  2016. elevencircle: 0x246A,
  2017. elevenparen: 0x247E,
  2018. elevenperiod: 0x2492,
  2019. elevenroman: 0x217A,
  2020. ellipsis: 0x2026,
  2021. ellipsisvertical: 0x22EE,
  2022. emacron: 0x0113,
  2023. emacronacute: 0x1E17,
  2024. emacrongrave: 0x1E15,
  2025. emcyrillic: 0x043C,
  2026. emdash: 0x2014,
  2027. emdashvertical: 0xFE31,
  2028. emonospace: 0xFF45,
  2029. emphasismarkarmenian: 0x055B,
  2030. emptyset: 0x2205,
  2031. enbopomofo: 0x3123,
  2032. encyrillic: 0x043D,
  2033. endash: 0x2013,
  2034. endashvertical: 0xFE32,
  2035. endescendercyrillic: 0x04A3,
  2036. eng: 0x014B,
  2037. engbopomofo: 0x3125,
  2038. enghecyrillic: 0x04A5,
  2039. enhookcyrillic: 0x04C8,
  2040. enspace: 0x2002,
  2041. eogonek: 0x0119,
  2042. eokorean: 0x3153,
  2043. eopen: 0x025B,
  2044. eopenclosed: 0x029A,
  2045. eopenreversed: 0x025C,
  2046. eopenreversedclosed: 0x025E,
  2047. eopenreversedhook: 0x025D,
  2048. eparen: 0x24A0,
  2049. epsilon: 0x03B5,
  2050. epsilontonos: 0x03AD,
  2051. equal: 0x003D,
  2052. equalmonospace: 0xFF1D,
  2053. equalsmall: 0xFE66,
  2054. equalsuperior: 0x207C,
  2055. equivalence: 0x2261,
  2056. erbopomofo: 0x3126,
  2057. ercyrillic: 0x0440,
  2058. ereversed: 0x0258,
  2059. ereversedcyrillic: 0x044D,
  2060. escyrillic: 0x0441,
  2061. esdescendercyrillic: 0x04AB,
  2062. esh: 0x0283,
  2063. eshcurl: 0x0286,
  2064. eshortdeva: 0x090E,
  2065. eshortvowelsigndeva: 0x0946,
  2066. eshreversedloop: 0x01AA,
  2067. eshsquatreversed: 0x0285,
  2068. esmallhiragana: 0x3047,
  2069. esmallkatakana: 0x30A7,
  2070. esmallkatakanahalfwidth: 0xFF6A,
  2071. estimated: 0x212E,
  2072. esuperior: 0xF6EC,
  2073. eta: 0x03B7,
  2074. etarmenian: 0x0568,
  2075. etatonos: 0x03AE,
  2076. eth: 0x00F0,
  2077. etilde: 0x1EBD,
  2078. etildebelow: 0x1E1B,
  2079. etnahtafoukhhebrew: 0x0591,
  2080. etnahtafoukhlefthebrew: 0x0591,
  2081. etnahtahebrew: 0x0591,
  2082. etnahtalefthebrew: 0x0591,
  2083. eturned: 0x01DD,
  2084. eukorean: 0x3161,
  2085. euro: 0x20AC,
  2086. evowelsignbengali: 0x09C7,
  2087. evowelsigndeva: 0x0947,
  2088. evowelsigngujarati: 0x0AC7,
  2089. exclam: 0x0021,
  2090. exclamarmenian: 0x055C,
  2091. exclamdbl: 0x203C,
  2092. exclamdown: 0x00A1,
  2093. exclamdownsmall: 0xF7A1,
  2094. exclammonospace: 0xFF01,
  2095. exclamsmall: 0xF721,
  2096. existential: 0x2203,
  2097. ezh: 0x0292,
  2098. ezhcaron: 0x01EF,
  2099. ezhcurl: 0x0293,
  2100. ezhreversed: 0x01B9,
  2101. ezhtail: 0x01BA,
  2102. f: 0x0066,
  2103. fadeva: 0x095E,
  2104. fagurmukhi: 0x0A5E,
  2105. fahrenheit: 0x2109,
  2106. fathaarabic: 0x064E,
  2107. fathalowarabic: 0x064E,
  2108. fathatanarabic: 0x064B,
  2109. fbopomofo: 0x3108,
  2110. fcircle: 0x24D5,
  2111. fdotaccent: 0x1E1F,
  2112. feharabic: 0x0641,
  2113. feharmenian: 0x0586,
  2114. fehfinalarabic: 0xFED2,
  2115. fehinitialarabic: 0xFED3,
  2116. fehmedialarabic: 0xFED4,
  2117. feicoptic: 0x03E5,
  2118. female: 0x2640,
  2119. ff: 0xFB00,
  2120. ffi: 0xFB03,
  2121. ffl: 0xFB04,
  2122. fi: 0xFB01,
  2123. fifteencircle: 0x246E,
  2124. fifteenparen: 0x2482,
  2125. fifteenperiod: 0x2496,
  2126. figuredash: 0x2012,
  2127. filledbox: 0x25A0,
  2128. filledrect: 0x25AC,
  2129. finalkaf: 0x05DA,
  2130. finalkafdagesh: 0xFB3A,
  2131. finalkafdageshhebrew: 0xFB3A,
  2132. finalkafhebrew: 0x05DA,
  2133. finalmem: 0x05DD,
  2134. finalmemhebrew: 0x05DD,
  2135. finalnun: 0x05DF,
  2136. finalnunhebrew: 0x05DF,
  2137. finalpe: 0x05E3,
  2138. finalpehebrew: 0x05E3,
  2139. finaltsadi: 0x05E5,
  2140. finaltsadihebrew: 0x05E5,
  2141. firsttonechinese: 0x02C9,
  2142. fisheye: 0x25C9,
  2143. fitacyrillic: 0x0473,
  2144. five: 0x0035,
  2145. fivearabic: 0x0665,
  2146. fivebengali: 0x09EB,
  2147. fivecircle: 0x2464,
  2148. fivecircleinversesansserif: 0x278E,
  2149. fivedeva: 0x096B,
  2150. fiveeighths: 0x215D,
  2151. fivegujarati: 0x0AEB,
  2152. fivegurmukhi: 0x0A6B,
  2153. fivehackarabic: 0x0665,
  2154. fivehangzhou: 0x3025,
  2155. fiveideographicparen: 0x3224,
  2156. fiveinferior: 0x2085,
  2157. fivemonospace: 0xFF15,
  2158. fiveoldstyle: 0xF735,
  2159. fiveparen: 0x2478,
  2160. fiveperiod: 0x248C,
  2161. fivepersian: 0x06F5,
  2162. fiveroman: 0x2174,
  2163. fivesuperior: 0x2075,
  2164. fivethai: 0x0E55,
  2165. fl: 0xFB02,
  2166. florin: 0x0192,
  2167. fmonospace: 0xFF46,
  2168. fmsquare: 0x3399,
  2169. fofanthai: 0x0E1F,
  2170. fofathai: 0x0E1D,
  2171. fongmanthai: 0x0E4F,
  2172. forall: 0x2200,
  2173. four: 0x0034,
  2174. fourarabic: 0x0664,
  2175. fourbengali: 0x09EA,
  2176. fourcircle: 0x2463,
  2177. fourcircleinversesansserif: 0x278D,
  2178. fourdeva: 0x096A,
  2179. fourgujarati: 0x0AEA,
  2180. fourgurmukhi: 0x0A6A,
  2181. fourhackarabic: 0x0664,
  2182. fourhangzhou: 0x3024,
  2183. fourideographicparen: 0x3223,
  2184. fourinferior: 0x2084,
  2185. fourmonospace: 0xFF14,
  2186. fournumeratorbengali: 0x09F7,
  2187. fouroldstyle: 0xF734,
  2188. fourparen: 0x2477,
  2189. fourperiod: 0x248B,
  2190. fourpersian: 0x06F4,
  2191. fourroman: 0x2173,
  2192. foursuperior: 0x2074,
  2193. fourteencircle: 0x246D,
  2194. fourteenparen: 0x2481,
  2195. fourteenperiod: 0x2495,
  2196. fourthai: 0x0E54,
  2197. fourthtonechinese: 0x02CB,
  2198. fparen: 0x24A1,
  2199. fraction: 0x2044,
  2200. franc: 0x20A3,
  2201. g: 0x0067,
  2202. gabengali: 0x0997,
  2203. gacute: 0x01F5,
  2204. gadeva: 0x0917,
  2205. gafarabic: 0x06AF,
  2206. gaffinalarabic: 0xFB93,
  2207. gafinitialarabic: 0xFB94,
  2208. gafmedialarabic: 0xFB95,
  2209. gagujarati: 0x0A97,
  2210. gagurmukhi: 0x0A17,
  2211. gahiragana: 0x304C,
  2212. gakatakana: 0x30AC,
  2213. gamma: 0x03B3,
  2214. gammalatinsmall: 0x0263,
  2215. gammasuperior: 0x02E0,
  2216. gangiacoptic: 0x03EB,
  2217. gbopomofo: 0x310D,
  2218. gbreve: 0x011F,
  2219. gcaron: 0x01E7,
  2220. gcedilla: 0x0123,
  2221. gcircle: 0x24D6,
  2222. gcircumflex: 0x011D,
  2223. gcommaaccent: 0x0123,
  2224. gdot: 0x0121,
  2225. gdotaccent: 0x0121,
  2226. gecyrillic: 0x0433,
  2227. gehiragana: 0x3052,
  2228. gekatakana: 0x30B2,
  2229. geometricallyequal: 0x2251,
  2230. gereshaccenthebrew: 0x059C,
  2231. gereshhebrew: 0x05F3,
  2232. gereshmuqdamhebrew: 0x059D,
  2233. germandbls: 0x00DF,
  2234. gershayimaccenthebrew: 0x059E,
  2235. gershayimhebrew: 0x05F4,
  2236. getamark: 0x3013,
  2237. ghabengali: 0x0998,
  2238. ghadarmenian: 0x0572,
  2239. ghadeva: 0x0918,
  2240. ghagujarati: 0x0A98,
  2241. ghagurmukhi: 0x0A18,
  2242. ghainarabic: 0x063A,
  2243. ghainfinalarabic: 0xFECE,
  2244. ghaininitialarabic: 0xFECF,
  2245. ghainmedialarabic: 0xFED0,
  2246. ghemiddlehookcyrillic: 0x0495,
  2247. ghestrokecyrillic: 0x0493,
  2248. gheupturncyrillic: 0x0491,
  2249. ghhadeva: 0x095A,
  2250. ghhagurmukhi: 0x0A5A,
  2251. ghook: 0x0260,
  2252. ghzsquare: 0x3393,
  2253. gihiragana: 0x304E,
  2254. gikatakana: 0x30AE,
  2255. gimarmenian: 0x0563,
  2256. gimel: 0x05D2,
  2257. gimeldagesh: 0xFB32,
  2258. gimeldageshhebrew: 0xFB32,
  2259. gimelhebrew: 0x05D2,
  2260. gjecyrillic: 0x0453,
  2261. glottalinvertedstroke: 0x01BE,
  2262. glottalstop: 0x0294,
  2263. glottalstopinverted: 0x0296,
  2264. glottalstopmod: 0x02C0,
  2265. glottalstopreversed: 0x0295,
  2266. glottalstopreversedmod: 0x02C1,
  2267. glottalstopreversedsuperior: 0x02E4,
  2268. glottalstopstroke: 0x02A1,
  2269. glottalstopstrokereversed: 0x02A2,
  2270. gmacron: 0x1E21,
  2271. gmonospace: 0xFF47,
  2272. gohiragana: 0x3054,
  2273. gokatakana: 0x30B4,
  2274. gparen: 0x24A2,
  2275. gpasquare: 0x33AC,
  2276. gradient: 0x2207,
  2277. grave: 0x0060,
  2278. gravebelowcmb: 0x0316,
  2279. gravecmb: 0x0300,
  2280. gravecomb: 0x0300,
  2281. gravedeva: 0x0953,
  2282. gravelowmod: 0x02CE,
  2283. gravemonospace: 0xFF40,
  2284. gravetonecmb: 0x0340,
  2285. greater: 0x003E,
  2286. greaterequal: 0x2265,
  2287. greaterequalorless: 0x22DB,
  2288. greatermonospace: 0xFF1E,
  2289. greaterorequivalent: 0x2273,
  2290. greaterorless: 0x2277,
  2291. greateroverequal: 0x2267,
  2292. greatersmall: 0xFE65,
  2293. gscript: 0x0261,
  2294. gstroke: 0x01E5,
  2295. guhiragana: 0x3050,
  2296. guillemotleft: 0x00AB,
  2297. guillemotright: 0x00BB,
  2298. guilsinglleft: 0x2039,
  2299. guilsinglright: 0x203A,
  2300. gukatakana: 0x30B0,
  2301. guramusquare: 0x3318,
  2302. gysquare: 0x33C9,
  2303. h: 0x0068,
  2304. haabkhasiancyrillic: 0x04A9,
  2305. haaltonearabic: 0x06C1,
  2306. habengali: 0x09B9,
  2307. hadescendercyrillic: 0x04B3,
  2308. hadeva: 0x0939,
  2309. hagujarati: 0x0AB9,
  2310. hagurmukhi: 0x0A39,
  2311. haharabic: 0x062D,
  2312. hahfinalarabic: 0xFEA2,
  2313. hahinitialarabic: 0xFEA3,
  2314. hahiragana: 0x306F,
  2315. hahmedialarabic: 0xFEA4,
  2316. haitusquare: 0x332A,
  2317. hakatakana: 0x30CF,
  2318. hakatakanahalfwidth: 0xFF8A,
  2319. halantgurmukhi: 0x0A4D,
  2320. hamzaarabic: 0x0621,
  2321. hamzalowarabic: 0x0621,
  2322. hangulfiller: 0x3164,
  2323. hardsigncyrillic: 0x044A,
  2324. harpoonleftbarbup: 0x21BC,
  2325. harpoonrightbarbup: 0x21C0,
  2326. hasquare: 0x33CA,
  2327. hatafpatah: 0x05B2,
  2328. hatafpatah16: 0x05B2,
  2329. hatafpatah23: 0x05B2,
  2330. hatafpatah2f: 0x05B2,
  2331. hatafpatahhebrew: 0x05B2,
  2332. hatafpatahnarrowhebrew: 0x05B2,
  2333. hatafpatahquarterhebrew: 0x05B2,
  2334. hatafpatahwidehebrew: 0x05B2,
  2335. hatafqamats: 0x05B3,
  2336. hatafqamats1b: 0x05B3,
  2337. hatafqamats28: 0x05B3,
  2338. hatafqamats34: 0x05B3,
  2339. hatafqamatshebrew: 0x05B3,
  2340. hatafqamatsnarrowhebrew: 0x05B3,
  2341. hatafqamatsquarterhebrew: 0x05B3,
  2342. hatafqamatswidehebrew: 0x05B3,
  2343. hatafsegol: 0x05B1,
  2344. hatafsegol17: 0x05B1,
  2345. hatafsegol24: 0x05B1,
  2346. hatafsegol30: 0x05B1,
  2347. hatafsegolhebrew: 0x05B1,
  2348. hatafsegolnarrowhebrew: 0x05B1,
  2349. hatafsegolquarterhebrew: 0x05B1,
  2350. hatafsegolwidehebrew: 0x05B1,
  2351. hbar: 0x0127,
  2352. hbopomofo: 0x310F,
  2353. hbrevebelow: 0x1E2B,
  2354. hcedilla: 0x1E29,
  2355. hcircle: 0x24D7,
  2356. hcircumflex: 0x0125,
  2357. hdieresis: 0x1E27,
  2358. hdotaccent: 0x1E23,
  2359. hdotbelow: 0x1E25,
  2360. he: 0x05D4,
  2361. heart: 0x2665,
  2362. heartsuitblack: 0x2665,
  2363. heartsuitwhite: 0x2661,
  2364. hedagesh: 0xFB34,
  2365. hedageshhebrew: 0xFB34,
  2366. hehaltonearabic: 0x06C1,
  2367. heharabic: 0x0647,
  2368. hehebrew: 0x05D4,
  2369. hehfinalaltonearabic: 0xFBA7,
  2370. hehfinalalttwoarabic: 0xFEEA,
  2371. hehfinalarabic: 0xFEEA,
  2372. hehhamzaabovefinalarabic: 0xFBA5,
  2373. hehhamzaaboveisolatedarabic: 0xFBA4,
  2374. hehinitialaltonearabic: 0xFBA8,
  2375. hehinitialarabic: 0xFEEB,
  2376. hehiragana: 0x3078,
  2377. hehmedialaltonearabic: 0xFBA9,
  2378. hehmedialarabic: 0xFEEC,
  2379. heiseierasquare: 0x337B,
  2380. hekatakana: 0x30D8,
  2381. hekatakanahalfwidth: 0xFF8D,
  2382. hekutaarusquare: 0x3336,
  2383. henghook: 0x0267,
  2384. herutusquare: 0x3339,
  2385. het: 0x05D7,
  2386. hethebrew: 0x05D7,
  2387. hhook: 0x0266,
  2388. hhooksuperior: 0x02B1,
  2389. hieuhacirclekorean: 0x327B,
  2390. hieuhaparenkorean: 0x321B,
  2391. hieuhcirclekorean: 0x326D,
  2392. hieuhkorean: 0x314E,
  2393. hieuhparenkorean: 0x320D,
  2394. hihiragana: 0x3072,
  2395. hikatakana: 0x30D2,
  2396. hikatakanahalfwidth: 0xFF8B,
  2397. hiriq: 0x05B4,
  2398. hiriq14: 0x05B4,
  2399. hiriq21: 0x05B4,
  2400. hiriq2d: 0x05B4,
  2401. hiriqhebrew: 0x05B4,
  2402. hiriqnarrowhebrew: 0x05B4,
  2403. hiriqquarterhebrew: 0x05B4,
  2404. hiriqwidehebrew: 0x05B4,
  2405. hlinebelow: 0x1E96,
  2406. hmonospace: 0xFF48,
  2407. hoarmenian: 0x0570,
  2408. hohipthai: 0x0E2B,
  2409. hohiragana: 0x307B,
  2410. hokatakana: 0x30DB,
  2411. hokatakanahalfwidth: 0xFF8E,
  2412. holam: 0x05B9,
  2413. holam19: 0x05B9,
  2414. holam26: 0x05B9,
  2415. holam32: 0x05B9,
  2416. holamhebrew: 0x05B9,
  2417. holamnarrowhebrew: 0x05B9,
  2418. holamquarterhebrew: 0x05B9,
  2419. holamwidehebrew: 0x05B9,
  2420. honokhukthai: 0x0E2E,
  2421. hookabovecomb: 0x0309,
  2422. hookcmb: 0x0309,
  2423. hookpalatalizedbelowcmb: 0x0321,
  2424. hookretroflexbelowcmb: 0x0322,
  2425. hoonsquare: 0x3342,
  2426. horicoptic: 0x03E9,
  2427. horizontalbar: 0x2015,
  2428. horncmb: 0x031B,
  2429. hotsprings: 0x2668,
  2430. house: 0x2302,
  2431. hparen: 0x24A3,
  2432. hsuperior: 0x02B0,
  2433. hturned: 0x0265,
  2434. huhiragana: 0x3075,
  2435. huiitosquare: 0x3333,
  2436. hukatakana: 0x30D5,
  2437. hukatakanahalfwidth: 0xFF8C,
  2438. hungarumlaut: 0x02DD,
  2439. hungarumlautcmb: 0x030B,
  2440. hv: 0x0195,
  2441. hyphen: 0x002D,
  2442. hypheninferior: 0xF6E5,
  2443. hyphenmonospace: 0xFF0D,
  2444. hyphensmall: 0xFE63,
  2445. hyphensuperior: 0xF6E6,
  2446. hyphentwo: 0x2010,
  2447. i: 0x0069,
  2448. iacute: 0x00ED,
  2449. iacyrillic: 0x044F,
  2450. ibengali: 0x0987,
  2451. ibopomofo: 0x3127,
  2452. ibreve: 0x012D,
  2453. icaron: 0x01D0,
  2454. icircle: 0x24D8,
  2455. icircumflex: 0x00EE,
  2456. icyrillic: 0x0456,
  2457. idblgrave: 0x0209,
  2458. ideographearthcircle: 0x328F,
  2459. ideographfirecircle: 0x328B,
  2460. ideographicallianceparen: 0x323F,
  2461. ideographiccallparen: 0x323A,
  2462. ideographiccentrecircle: 0x32A5,
  2463. ideographicclose: 0x3006,
  2464. ideographiccomma: 0x3001,
  2465. ideographiccommaleft: 0xFF64,
  2466. ideographiccongratulationparen: 0x3237,
  2467. ideographiccorrectcircle: 0x32A3,
  2468. ideographicearthparen: 0x322F,
  2469. ideographicenterpriseparen: 0x323D,
  2470. ideographicexcellentcircle: 0x329D,
  2471. ideographicfestivalparen: 0x3240,
  2472. ideographicfinancialcircle: 0x3296,
  2473. ideographicfinancialparen: 0x3236,
  2474. ideographicfireparen: 0x322B,
  2475. ideographichaveparen: 0x3232,
  2476. ideographichighcircle: 0x32A4,
  2477. ideographiciterationmark: 0x3005,
  2478. ideographiclaborcircle: 0x3298,
  2479. ideographiclaborparen: 0x3238,
  2480. ideographicleftcircle: 0x32A7,
  2481. ideographiclowcircle: 0x32A6,
  2482. ideographicmedicinecircle: 0x32A9,
  2483. ideographicmetalparen: 0x322E,
  2484. ideographicmoonparen: 0x322A,
  2485. ideographicnameparen: 0x3234,
  2486. ideographicperiod: 0x3002,
  2487. ideographicprintcircle: 0x329E,
  2488. ideographicreachparen: 0x3243,
  2489. ideographicrepresentparen: 0x3239,
  2490. ideographicresourceparen: 0x323E,
  2491. ideographicrightcircle: 0x32A8,
  2492. ideographicsecretcircle: 0x3299,
  2493. ideographicselfparen: 0x3242,
  2494. ideographicsocietyparen: 0x3233,
  2495. ideographicspace: 0x3000,
  2496. ideographicspecialparen: 0x3235,
  2497. ideographicstockparen: 0x3231,
  2498. ideographicstudyparen: 0x323B,
  2499. ideographicsunparen: 0x3230,
  2500. ideographicsuperviseparen: 0x323C,
  2501. ideographicwaterparen: 0x322C,
  2502. ideographicwoodparen: 0x322D,
  2503. ideographiczero: 0x3007,
  2504. ideographmetalcircle: 0x328E,
  2505. ideographmooncircle: 0x328A,
  2506. ideographnamecircle: 0x3294,
  2507. ideographsuncircle: 0x3290,
  2508. ideographwatercircle: 0x328C,
  2509. ideographwoodcircle: 0x328D,
  2510. ideva: 0x0907,
  2511. idieresis: 0x00EF,
  2512. idieresisacute: 0x1E2F,
  2513. idieresiscyrillic: 0x04E5,
  2514. idotbelow: 0x1ECB,
  2515. iebrevecyrillic: 0x04D7,
  2516. iecyrillic: 0x0435,
  2517. ieungacirclekorean: 0x3275,
  2518. ieungaparenkorean: 0x3215,
  2519. ieungcirclekorean: 0x3267,
  2520. ieungkorean: 0x3147,
  2521. ieungparenkorean: 0x3207,
  2522. igrave: 0x00EC,
  2523. igujarati: 0x0A87,
  2524. igurmukhi: 0x0A07,
  2525. ihiragana: 0x3044,
  2526. ihookabove: 0x1EC9,
  2527. iibengali: 0x0988,
  2528. iicyrillic: 0x0438,
  2529. iideva: 0x0908,
  2530. iigujarati: 0x0A88,
  2531. iigurmukhi: 0x0A08,
  2532. iimatragurmukhi: 0x0A40,
  2533. iinvertedbreve: 0x020B,
  2534. iishortcyrillic: 0x0439,
  2535. iivowelsignbengali: 0x09C0,
  2536. iivowelsigndeva: 0x0940,
  2537. iivowelsigngujarati: 0x0AC0,
  2538. ij: 0x0133,
  2539. ikatakana: 0x30A4,
  2540. ikatakanahalfwidth: 0xFF72,
  2541. ikorean: 0x3163,
  2542. ilde: 0x02DC,
  2543. iluyhebrew: 0x05AC,
  2544. imacron: 0x012B,
  2545. imacroncyrillic: 0x04E3,
  2546. imageorapproximatelyequal: 0x2253,
  2547. imatragurmukhi: 0x0A3F,
  2548. imonospace: 0xFF49,
  2549. increment: 0x2206,
  2550. infinity: 0x221E,
  2551. iniarmenian: 0x056B,
  2552. integral: 0x222B,
  2553. integralbottom: 0x2321,
  2554. integralbt: 0x2321,
  2555. integralex: 0xF8F5,
  2556. integraltop: 0x2320,
  2557. integraltp: 0x2320,
  2558. intersection: 0x2229,
  2559. intisquare: 0x3305,
  2560. invbullet: 0x25D8,
  2561. invcircle: 0x25D9,
  2562. invsmileface: 0x263B,
  2563. iocyrillic: 0x0451,
  2564. iogonek: 0x012F,
  2565. iota: 0x03B9,
  2566. iotadieresis: 0x03CA,
  2567. iotadieresistonos: 0x0390,
  2568. iotalatin: 0x0269,
  2569. iotatonos: 0x03AF,
  2570. iparen: 0x24A4,
  2571. irigurmukhi: 0x0A72,
  2572. ismallhiragana: 0x3043,
  2573. ismallkatakana: 0x30A3,
  2574. ismallkatakanahalfwidth: 0xFF68,
  2575. issharbengali: 0x09FA,
  2576. istroke: 0x0268,
  2577. isuperior: 0xF6ED,
  2578. iterationhiragana: 0x309D,
  2579. iterationkatakana: 0x30FD,
  2580. itilde: 0x0129,
  2581. itildebelow: 0x1E2D,
  2582. iubopomofo: 0x3129,
  2583. iucyrillic: 0x044E,
  2584. ivowelsignbengali: 0x09BF,
  2585. ivowelsigndeva: 0x093F,
  2586. ivowelsigngujarati: 0x0ABF,
  2587. izhitsacyrillic: 0x0475,
  2588. izhitsadblgravecyrillic: 0x0477,
  2589. j: 0x006A,
  2590. jaarmenian: 0x0571,
  2591. jabengali: 0x099C,
  2592. jadeva: 0x091C,
  2593. jagujarati: 0x0A9C,
  2594. jagurmukhi: 0x0A1C,
  2595. jbopomofo: 0x3110,
  2596. jcaron: 0x01F0,
  2597. jcircle: 0x24D9,
  2598. jcircumflex: 0x0135,
  2599. jcrossedtail: 0x029D,
  2600. jdotlessstroke: 0x025F,
  2601. jecyrillic: 0x0458,
  2602. jeemarabic: 0x062C,
  2603. jeemfinalarabic: 0xFE9E,
  2604. jeeminitialarabic: 0xFE9F,
  2605. jeemmedialarabic: 0xFEA0,
  2606. jeharabic: 0x0698,
  2607. jehfinalarabic: 0xFB8B,
  2608. jhabengali: 0x099D,
  2609. jhadeva: 0x091D,
  2610. jhagujarati: 0x0A9D,
  2611. jhagurmukhi: 0x0A1D,
  2612. jheharmenian: 0x057B,
  2613. jis: 0x3004,
  2614. jmonospace: 0xFF4A,
  2615. jparen: 0x24A5,
  2616. jsuperior: 0x02B2,
  2617. k: 0x006B,
  2618. kabashkircyrillic: 0x04A1,
  2619. kabengali: 0x0995,
  2620. kacute: 0x1E31,
  2621. kacyrillic: 0x043A,
  2622. kadescendercyrillic: 0x049B,
  2623. kadeva: 0x0915,
  2624. kaf: 0x05DB,
  2625. kafarabic: 0x0643,
  2626. kafdagesh: 0xFB3B,
  2627. kafdageshhebrew: 0xFB3B,
  2628. kaffinalarabic: 0xFEDA,
  2629. kafhebrew: 0x05DB,
  2630. kafinitialarabic: 0xFEDB,
  2631. kafmedialarabic: 0xFEDC,
  2632. kafrafehebrew: 0xFB4D,
  2633. kagujarati: 0x0A95,
  2634. kagurmukhi: 0x0A15,
  2635. kahiragana: 0x304B,
  2636. kahookcyrillic: 0x04C4,
  2637. kakatakana: 0x30AB,
  2638. kakatakanahalfwidth: 0xFF76,
  2639. kappa: 0x03BA,
  2640. kappasymbolgreek: 0x03F0,
  2641. kapyeounmieumkorean: 0x3171,
  2642. kapyeounphieuphkorean: 0x3184,
  2643. kapyeounpieupkorean: 0x3178,
  2644. kapyeounssangpieupkorean: 0x3179,
  2645. karoriisquare: 0x330D,
  2646. kashidaautoarabic: 0x0640,
  2647. kashidaautonosidebearingarabic: 0x0640,
  2648. kasmallkatakana: 0x30F5,
  2649. kasquare: 0x3384,
  2650. kasraarabic: 0x0650,
  2651. kasratanarabic: 0x064D,
  2652. kastrokecyrillic: 0x049F,
  2653. katahiraprolongmarkhalfwidth: 0xFF70,
  2654. kaverticalstrokecyrillic: 0x049D,
  2655. kbopomofo: 0x310E,
  2656. kcalsquare: 0x3389,
  2657. kcaron: 0x01E9,
  2658. kcedilla: 0x0137,
  2659. kcircle: 0x24DA,
  2660. kcommaaccent: 0x0137,
  2661. kdotbelow: 0x1E33,
  2662. keharmenian: 0x0584,
  2663. kehiragana: 0x3051,
  2664. kekatakana: 0x30B1,
  2665. kekatakanahalfwidth: 0xFF79,
  2666. kenarmenian: 0x056F,
  2667. kesmallkatakana: 0x30F6,
  2668. kgreenlandic: 0x0138,
  2669. khabengali: 0x0996,
  2670. khacyrillic: 0x0445,
  2671. khadeva: 0x0916,
  2672. khagujarati: 0x0A96,
  2673. khagurmukhi: 0x0A16,
  2674. khaharabic: 0x062E,
  2675. khahfinalarabic: 0xFEA6,
  2676. khahinitialarabic: 0xFEA7,
  2677. khahmedialarabic: 0xFEA8,
  2678. kheicoptic: 0x03E7,
  2679. khhadeva: 0x0959,
  2680. khhagurmukhi: 0x0A59,
  2681. khieukhacirclekorean: 0x3278,
  2682. khieukhaparenkorean: 0x3218,
  2683. khieukhcirclekorean: 0x326A,
  2684. khieukhkorean: 0x314B,
  2685. khieukhparenkorean: 0x320A,
  2686. khokhaithai: 0x0E02,
  2687. khokhonthai: 0x0E05,
  2688. khokhuatthai: 0x0E03,
  2689. khokhwaithai: 0x0E04,
  2690. khomutthai: 0x0E5B,
  2691. khook: 0x0199,
  2692. khorakhangthai: 0x0E06,
  2693. khzsquare: 0x3391,
  2694. kihiragana: 0x304D,
  2695. kikatakana: 0x30AD,
  2696. kikatakanahalfwidth: 0xFF77,
  2697. kiroguramusquare: 0x3315,
  2698. kiromeetorusquare: 0x3316,
  2699. kirosquare: 0x3314,
  2700. kiyeokacirclekorean: 0x326E,
  2701. kiyeokaparenkorean: 0x320E,
  2702. kiyeokcirclekorean: 0x3260,
  2703. kiyeokkorean: 0x3131,
  2704. kiyeokparenkorean: 0x3200,
  2705. kiyeoksioskorean: 0x3133,
  2706. kjecyrillic: 0x045C,
  2707. klinebelow: 0x1E35,
  2708. klsquare: 0x3398,
  2709. kmcubedsquare: 0x33A6,
  2710. kmonospace: 0xFF4B,
  2711. kmsquaredsquare: 0x33A2,
  2712. kohiragana: 0x3053,
  2713. kohmsquare: 0x33C0,
  2714. kokaithai: 0x0E01,
  2715. kokatakana: 0x30B3,
  2716. kokatakanahalfwidth: 0xFF7A,
  2717. kooposquare: 0x331E,
  2718. koppacyrillic: 0x0481,
  2719. koreanstandardsymbol: 0x327F,
  2720. koroniscmb: 0x0343,
  2721. kparen: 0x24A6,
  2722. kpasquare: 0x33AA,
  2723. ksicyrillic: 0x046F,
  2724. ktsquare: 0x33CF,
  2725. kturned: 0x029E,
  2726. kuhiragana: 0x304F,
  2727. kukatakana: 0x30AF,
  2728. kukatakanahalfwidth: 0xFF78,
  2729. kvsquare: 0x33B8,
  2730. kwsquare: 0x33BE,
  2731. l: 0x006C,
  2732. labengali: 0x09B2,
  2733. lacute: 0x013A,
  2734. ladeva: 0x0932,
  2735. lagujarati: 0x0AB2,
  2736. lagurmukhi: 0x0A32,
  2737. lakkhangyaothai: 0x0E45,
  2738. lamaleffinalarabic: 0xFEFC,
  2739. lamalefhamzaabovefinalarabic: 0xFEF8,
  2740. lamalefhamzaaboveisolatedarabic: 0xFEF7,
  2741. lamalefhamzabelowfinalarabic: 0xFEFA,
  2742. lamalefhamzabelowisolatedarabic: 0xFEF9,
  2743. lamalefisolatedarabic: 0xFEFB,
  2744. lamalefmaddaabovefinalarabic: 0xFEF6,
  2745. lamalefmaddaaboveisolatedarabic: 0xFEF5,
  2746. lamarabic: 0x0644,
  2747. lambda: 0x03BB,
  2748. lambdastroke: 0x019B,
  2749. lamed: 0x05DC,
  2750. lameddagesh: 0xFB3C,
  2751. lameddageshhebrew: 0xFB3C,
  2752. lamedhebrew: 0x05DC,
  2753. lamfinalarabic: 0xFEDE,
  2754. lamhahinitialarabic: 0xFCCA,
  2755. laminitialarabic: 0xFEDF,
  2756. lamjeeminitialarabic: 0xFCC9,
  2757. lamkhahinitialarabic: 0xFCCB,
  2758. lamlamhehisolatedarabic: 0xFDF2,
  2759. lammedialarabic: 0xFEE0,
  2760. lammeemhahinitialarabic: 0xFD88,
  2761. lammeeminitialarabic: 0xFCCC,
  2762. largecircle: 0x25EF,
  2763. lbar: 0x019A,
  2764. lbelt: 0x026C,
  2765. lbopomofo: 0x310C,
  2766. lcaron: 0x013E,
  2767. lcedilla: 0x013C,
  2768. lcircle: 0x24DB,
  2769. lcircumflexbelow: 0x1E3D,
  2770. lcommaaccent: 0x013C,
  2771. ldot: 0x0140,
  2772. ldotaccent: 0x0140,
  2773. ldotbelow: 0x1E37,
  2774. ldotbelowmacron: 0x1E39,
  2775. leftangleabovecmb: 0x031A,
  2776. lefttackbelowcmb: 0x0318,
  2777. less: 0x003C,
  2778. lessequal: 0x2264,
  2779. lessequalorgreater: 0x22DA,
  2780. lessmonospace: 0xFF1C,
  2781. lessorequivalent: 0x2272,
  2782. lessorgreater: 0x2276,
  2783. lessoverequal: 0x2266,
  2784. lesssmall: 0xFE64,
  2785. lezh: 0x026E,
  2786. lfblock: 0x258C,
  2787. lhookretroflex: 0x026D,
  2788. lira: 0x20A4,
  2789. liwnarmenian: 0x056C,
  2790. lj: 0x01C9,
  2791. ljecyrillic: 0x0459,
  2792. ll: 0xF6C0,
  2793. lladeva: 0x0933,
  2794. llagujarati: 0x0AB3,
  2795. llinebelow: 0x1E3B,
  2796. llladeva: 0x0934,
  2797. llvocalicbengali: 0x09E1,
  2798. llvocalicdeva: 0x0961,
  2799. llvocalicvowelsignbengali: 0x09E3,
  2800. llvocalicvowelsigndeva: 0x0963,
  2801. lmiddletilde: 0x026B,
  2802. lmonospace: 0xFF4C,
  2803. lmsquare: 0x33D0,
  2804. lochulathai: 0x0E2C,
  2805. logicaland: 0x2227,
  2806. logicalnot: 0x00AC,
  2807. logicalnotreversed: 0x2310,
  2808. logicalor: 0x2228,
  2809. lolingthai: 0x0E25,
  2810. longs: 0x017F,
  2811. lowlinecenterline: 0xFE4E,
  2812. lowlinecmb: 0x0332,
  2813. lowlinedashed: 0xFE4D,
  2814. lozenge: 0x25CA,
  2815. lparen: 0x24A7,
  2816. lslash: 0x0142,
  2817. lsquare: 0x2113,
  2818. lsuperior: 0xF6EE,
  2819. ltshade: 0x2591,
  2820. luthai: 0x0E26,
  2821. lvocalicbengali: 0x098C,
  2822. lvocalicdeva: 0x090C,
  2823. lvocalicvowelsignbengali: 0x09E2,
  2824. lvocalicvowelsigndeva: 0x0962,
  2825. lxsquare: 0x33D3,
  2826. m: 0x006D,
  2827. mabengali: 0x09AE,
  2828. macron: 0x00AF,
  2829. macronbelowcmb: 0x0331,
  2830. macroncmb: 0x0304,
  2831. macronlowmod: 0x02CD,
  2832. macronmonospace: 0xFFE3,
  2833. macute: 0x1E3F,
  2834. madeva: 0x092E,
  2835. magujarati: 0x0AAE,
  2836. magurmukhi: 0x0A2E,
  2837. mahapakhhebrew: 0x05A4,
  2838. mahapakhlefthebrew: 0x05A4,
  2839. mahiragana: 0x307E,
  2840. maichattawalowleftthai: 0xF895,
  2841. maichattawalowrightthai: 0xF894,
  2842. maichattawathai: 0x0E4B,
  2843. maichattawaupperleftthai: 0xF893,
  2844. maieklowleftthai: 0xF88C,
  2845. maieklowrightthai: 0xF88B,
  2846. maiekthai: 0x0E48,
  2847. maiekupperleftthai: 0xF88A,
  2848. maihanakatleftthai: 0xF884,
  2849. maihanakatthai: 0x0E31,
  2850. maitaikhuleftthai: 0xF889,
  2851. maitaikhuthai: 0x0E47,
  2852. maitholowleftthai: 0xF88F,
  2853. maitholowrightthai: 0xF88E,
  2854. maithothai: 0x0E49,
  2855. maithoupperleftthai: 0xF88D,
  2856. maitrilowleftthai: 0xF892,
  2857. maitrilowrightthai: 0xF891,
  2858. maitrithai: 0x0E4A,
  2859. maitriupperleftthai: 0xF890,
  2860. maiyamokthai: 0x0E46,
  2861. makatakana: 0x30DE,
  2862. makatakanahalfwidth: 0xFF8F,
  2863. male: 0x2642,
  2864. mansyonsquare: 0x3347,
  2865. maqafhebrew: 0x05BE,
  2866. mars: 0x2642,
  2867. masoracirclehebrew: 0x05AF,
  2868. masquare: 0x3383,
  2869. mbopomofo: 0x3107,
  2870. mbsquare: 0x33D4,
  2871. mcircle: 0x24DC,
  2872. mcubedsquare: 0x33A5,
  2873. mdotaccent: 0x1E41,
  2874. mdotbelow: 0x1E43,
  2875. meemarabic: 0x0645,
  2876. meemfinalarabic: 0xFEE2,
  2877. meeminitialarabic: 0xFEE3,
  2878. meemmedialarabic: 0xFEE4,
  2879. meemmeeminitialarabic: 0xFCD1,
  2880. meemmeemisolatedarabic: 0xFC48,
  2881. meetorusquare: 0x334D,
  2882. mehiragana: 0x3081,
  2883. meizierasquare: 0x337E,
  2884. mekatakana: 0x30E1,
  2885. mekatakanahalfwidth: 0xFF92,
  2886. mem: 0x05DE,
  2887. memdagesh: 0xFB3E,
  2888. memdageshhebrew: 0xFB3E,
  2889. memhebrew: 0x05DE,
  2890. menarmenian: 0x0574,
  2891. merkhahebrew: 0x05A5,
  2892. merkhakefulahebrew: 0x05A6,
  2893. merkhakefulalefthebrew: 0x05A6,
  2894. merkhalefthebrew: 0x05A5,
  2895. mhook: 0x0271,
  2896. mhzsquare: 0x3392,
  2897. middledotkatakanahalfwidth: 0xFF65,
  2898. middot: 0x00B7,
  2899. mieumacirclekorean: 0x3272,
  2900. mieumaparenkorean: 0x3212,
  2901. mieumcirclekorean: 0x3264,
  2902. mieumkorean: 0x3141,
  2903. mieumpansioskorean: 0x3170,
  2904. mieumparenkorean: 0x3204,
  2905. mieumpieupkorean: 0x316E,
  2906. mieumsioskorean: 0x316F,
  2907. mihiragana: 0x307F,
  2908. mikatakana: 0x30DF,
  2909. mikatakanahalfwidth: 0xFF90,
  2910. minus: 0x2212,
  2911. minusbelowcmb: 0x0320,
  2912. minuscircle: 0x2296,
  2913. minusmod: 0x02D7,
  2914. minusplus: 0x2213,
  2915. minute: 0x2032,
  2916. miribaarusquare: 0x334A,
  2917. mirisquare: 0x3349,
  2918. mlonglegturned: 0x0270,
  2919. mlsquare: 0x3396,
  2920. mmcubedsquare: 0x33A3,
  2921. mmonospace: 0xFF4D,
  2922. mmsquaredsquare: 0x339F,
  2923. mohiragana: 0x3082,
  2924. mohmsquare: 0x33C1,
  2925. mokatakana: 0x30E2,
  2926. mokatakanahalfwidth: 0xFF93,
  2927. molsquare: 0x33D6,
  2928. momathai: 0x0E21,
  2929. moverssquare: 0x33A7,
  2930. moverssquaredsquare: 0x33A8,
  2931. mparen: 0x24A8,
  2932. mpasquare: 0x33AB,
  2933. mssquare: 0x33B3,
  2934. msuperior: 0xF6EF,
  2935. mturned: 0x026F,
  2936. mu: 0x00B5,
  2937. mu1: 0x00B5,
  2938. muasquare: 0x3382,
  2939. muchgreater: 0x226B,
  2940. muchless: 0x226A,
  2941. mufsquare: 0x338C,
  2942. mugreek: 0x03BC,
  2943. mugsquare: 0x338D,
  2944. muhiragana: 0x3080,
  2945. mukatakana: 0x30E0,
  2946. mukatakanahalfwidth: 0xFF91,
  2947. mulsquare: 0x3395,
  2948. multiply: 0x00D7,
  2949. mumsquare: 0x339B,
  2950. munahhebrew: 0x05A3,
  2951. munahlefthebrew: 0x05A3,
  2952. musicalnote: 0x266A,
  2953. musicalnotedbl: 0x266B,
  2954. musicflatsign: 0x266D,
  2955. musicsharpsign: 0x266F,
  2956. mussquare: 0x33B2,
  2957. muvsquare: 0x33B6,
  2958. muwsquare: 0x33BC,
  2959. mvmegasquare: 0x33B9,
  2960. mvsquare: 0x33B7,
  2961. mwmegasquare: 0x33BF,
  2962. mwsquare: 0x33BD,
  2963. n: 0x006E,
  2964. nabengali: 0x09A8,
  2965. nabla: 0x2207,
  2966. nacute: 0x0144,
  2967. nadeva: 0x0928,
  2968. nagujarati: 0x0AA8,
  2969. nagurmukhi: 0x0A28,
  2970. nahiragana: 0x306A,
  2971. nakatakana: 0x30CA,
  2972. nakatakanahalfwidth: 0xFF85,
  2973. napostrophe: 0x0149,
  2974. nasquare: 0x3381,
  2975. nbopomofo: 0x310B,
  2976. nbspace: 0x00A0,
  2977. ncaron: 0x0148,
  2978. ncedilla: 0x0146,
  2979. ncircle: 0x24DD,
  2980. ncircumflexbelow: 0x1E4B,
  2981. ncommaaccent: 0x0146,
  2982. ndotaccent: 0x1E45,
  2983. ndotbelow: 0x1E47,
  2984. nehiragana: 0x306D,
  2985. nekatakana: 0x30CD,
  2986. nekatakanahalfwidth: 0xFF88,
  2987. newsheqelsign: 0x20AA,
  2988. nfsquare: 0x338B,
  2989. ngabengali: 0x0999,
  2990. ngadeva: 0x0919,
  2991. ngagujarati: 0x0A99,
  2992. ngagurmukhi: 0x0A19,
  2993. ngonguthai: 0x0E07,
  2994. nhiragana: 0x3093,
  2995. nhookleft: 0x0272,
  2996. nhookretroflex: 0x0273,
  2997. nieunacirclekorean: 0x326F,
  2998. nieunaparenkorean: 0x320F,
  2999. nieuncieuckorean: 0x3135,
  3000. nieuncirclekorean: 0x3261,
  3001. nieunhieuhkorean: 0x3136,
  3002. nieunkorean: 0x3134,
  3003. nieunpansioskorean: 0x3168,
  3004. nieunparenkorean: 0x3201,
  3005. nieunsioskorean: 0x3167,
  3006. nieuntikeutkorean: 0x3166,
  3007. nihiragana: 0x306B,
  3008. nikatakana: 0x30CB,
  3009. nikatakanahalfwidth: 0xFF86,
  3010. nikhahitleftthai: 0xF899,
  3011. nikhahitthai: 0x0E4D,
  3012. nine: 0x0039,
  3013. ninearabic: 0x0669,
  3014. ninebengali: 0x09EF,
  3015. ninecircle: 0x2468,
  3016. ninecircleinversesansserif: 0x2792,
  3017. ninedeva: 0x096F,
  3018. ninegujarati: 0x0AEF,
  3019. ninegurmukhi: 0x0A6F,
  3020. ninehackarabic: 0x0669,
  3021. ninehangzhou: 0x3029,
  3022. nineideographicparen: 0x3228,
  3023. nineinferior: 0x2089,
  3024. ninemonospace: 0xFF19,
  3025. nineoldstyle: 0xF739,
  3026. nineparen: 0x247C,
  3027. nineperiod: 0x2490,
  3028. ninepersian: 0x06F9,
  3029. nineroman: 0x2178,
  3030. ninesuperior: 0x2079,
  3031. nineteencircle: 0x2472,
  3032. nineteenparen: 0x2486,
  3033. nineteenperiod: 0x249A,
  3034. ninethai: 0x0E59,
  3035. nj: 0x01CC,
  3036. njecyrillic: 0x045A,
  3037. nkatakana: 0x30F3,
  3038. nkatakanahalfwidth: 0xFF9D,
  3039. nlegrightlong: 0x019E,
  3040. nlinebelow: 0x1E49,
  3041. nmonospace: 0xFF4E,
  3042. nmsquare: 0x339A,
  3043. nnabengali: 0x09A3,
  3044. nnadeva: 0x0923,
  3045. nnagujarati: 0x0AA3,
  3046. nnagurmukhi: 0x0A23,
  3047. nnnadeva: 0x0929,
  3048. nohiragana: 0x306E,
  3049. nokatakana: 0x30CE,
  3050. nokatakanahalfwidth: 0xFF89,
  3051. nonbreakingspace: 0x00A0,
  3052. nonenthai: 0x0E13,
  3053. nonuthai: 0x0E19,
  3054. noonarabic: 0x0646,
  3055. noonfinalarabic: 0xFEE6,
  3056. noonghunnaarabic: 0x06BA,
  3057. noonghunnafinalarabic: 0xFB9F,
  3058. nooninitialarabic: 0xFEE7,
  3059. noonjeeminitialarabic: 0xFCD2,
  3060. noonjeemisolatedarabic: 0xFC4B,
  3061. noonmedialarabic: 0xFEE8,
  3062. noonmeeminitialarabic: 0xFCD5,
  3063. noonmeemisolatedarabic: 0xFC4E,
  3064. noonnoonfinalarabic: 0xFC8D,
  3065. notcontains: 0x220C,
  3066. notelement: 0x2209,
  3067. notelementof: 0x2209,
  3068. notequal: 0x2260,
  3069. notgreater: 0x226F,
  3070. notgreaternorequal: 0x2271,
  3071. notgreaternorless: 0x2279,
  3072. notidentical: 0x2262,
  3073. notless: 0x226E,
  3074. notlessnorequal: 0x2270,
  3075. notparallel: 0x2226,
  3076. notprecedes: 0x2280,
  3077. notsubset: 0x2284,
  3078. notsucceeds: 0x2281,
  3079. notsuperset: 0x2285,
  3080. nowarmenian: 0x0576,
  3081. nparen: 0x24A9,
  3082. nssquare: 0x33B1,
  3083. nsuperior: 0x207F,
  3084. ntilde: 0x00F1,
  3085. nu: 0x03BD,
  3086. nuhiragana: 0x306C,
  3087. nukatakana: 0x30CC,
  3088. nukatakanahalfwidth: 0xFF87,
  3089. nuktabengali: 0x09BC,
  3090. nuktadeva: 0x093C,
  3091. nuktagujarati: 0x0ABC,
  3092. nuktagurmukhi: 0x0A3C,
  3093. numbersign: 0x0023,
  3094. numbersignmonospace: 0xFF03,
  3095. numbersignsmall: 0xFE5F,
  3096. numeralsigngreek: 0x0374,
  3097. numeralsignlowergreek: 0x0375,
  3098. numero: 0x2116,
  3099. nun: 0x05E0,
  3100. nundagesh: 0xFB40,
  3101. nundageshhebrew: 0xFB40,
  3102. nunhebrew: 0x05E0,
  3103. nvsquare: 0x33B5,
  3104. nwsquare: 0x33BB,
  3105. nyabengali: 0x099E,
  3106. nyadeva: 0x091E,
  3107. nyagujarati: 0x0A9E,
  3108. nyagurmukhi: 0x0A1E,
  3109. o: 0x006F,
  3110. oacute: 0x00F3,
  3111. oangthai: 0x0E2D,
  3112. obarred: 0x0275,
  3113. obarredcyrillic: 0x04E9,
  3114. obarreddieresiscyrillic: 0x04EB,
  3115. obengali: 0x0993,
  3116. obopomofo: 0x311B,
  3117. obreve: 0x014F,
  3118. ocandradeva: 0x0911,
  3119. ocandragujarati: 0x0A91,
  3120. ocandravowelsigndeva: 0x0949,
  3121. ocandravowelsigngujarati: 0x0AC9,
  3122. ocaron: 0x01D2,
  3123. ocircle: 0x24DE,
  3124. ocircumflex: 0x00F4,
  3125. ocircumflexacute: 0x1ED1,
  3126. ocircumflexdotbelow: 0x1ED9,
  3127. ocircumflexgrave: 0x1ED3,
  3128. ocircumflexhookabove: 0x1ED5,
  3129. ocircumflextilde: 0x1ED7,
  3130. ocyrillic: 0x043E,
  3131. odblacute: 0x0151,
  3132. odblgrave: 0x020D,
  3133. odeva: 0x0913,
  3134. odieresis: 0x00F6,
  3135. odieresiscyrillic: 0x04E7,
  3136. odotbelow: 0x1ECD,
  3137. oe: 0x0153,
  3138. oekorean: 0x315A,
  3139. ogonek: 0x02DB,
  3140. ogonekcmb: 0x0328,
  3141. ograve: 0x00F2,
  3142. ogujarati: 0x0A93,
  3143. oharmenian: 0x0585,
  3144. ohiragana: 0x304A,
  3145. ohookabove: 0x1ECF,
  3146. ohorn: 0x01A1,
  3147. ohornacute: 0x1EDB,
  3148. ohorndotbelow: 0x1EE3,
  3149. ohorngrave: 0x1EDD,
  3150. ohornhookabove: 0x1EDF,
  3151. ohorntilde: 0x1EE1,
  3152. ohungarumlaut: 0x0151,
  3153. oi: 0x01A3,
  3154. oinvertedbreve: 0x020F,
  3155. okatakana: 0x30AA,
  3156. okatakanahalfwidth: 0xFF75,
  3157. okorean: 0x3157,
  3158. olehebrew: 0x05AB,
  3159. omacron: 0x014D,
  3160. omacronacute: 0x1E53,
  3161. omacrongrave: 0x1E51,
  3162. omdeva: 0x0950,
  3163. omega: 0x03C9,
  3164. omega1: 0x03D6,
  3165. omegacyrillic: 0x0461,
  3166. omegalatinclosed: 0x0277,
  3167. omegaroundcyrillic: 0x047B,
  3168. omegatitlocyrillic: 0x047D,
  3169. omegatonos: 0x03CE,
  3170. omgujarati: 0x0AD0,
  3171. omicron: 0x03BF,
  3172. omicrontonos: 0x03CC,
  3173. omonospace: 0xFF4F,
  3174. one: 0x0031,
  3175. onearabic: 0x0661,
  3176. onebengali: 0x09E7,
  3177. onecircle: 0x2460,
  3178. onecircleinversesansserif: 0x278A,
  3179. onedeva: 0x0967,
  3180. onedotenleader: 0x2024,
  3181. oneeighth: 0x215B,
  3182. onefitted: 0xF6DC,
  3183. onegujarati: 0x0AE7,
  3184. onegurmukhi: 0x0A67,
  3185. onehackarabic: 0x0661,
  3186. onehalf: 0x00BD,
  3187. onehangzhou: 0x3021,
  3188. oneideographicparen: 0x3220,
  3189. oneinferior: 0x2081,
  3190. onemonospace: 0xFF11,
  3191. onenumeratorbengali: 0x09F4,
  3192. oneoldstyle: 0xF731,
  3193. oneparen: 0x2474,
  3194. oneperiod: 0x2488,
  3195. onepersian: 0x06F1,
  3196. onequarter: 0x00BC,
  3197. oneroman: 0x2170,
  3198. onesuperior: 0x00B9,
  3199. onethai: 0x0E51,
  3200. onethird: 0x2153,
  3201. oogonek: 0x01EB,
  3202. oogonekmacron: 0x01ED,
  3203. oogurmukhi: 0x0A13,
  3204. oomatragurmukhi: 0x0A4B,
  3205. oopen: 0x0254,
  3206. oparen: 0x24AA,
  3207. openbullet: 0x25E6,
  3208. option: 0x2325,
  3209. ordfeminine: 0x00AA,
  3210. ordmasculine: 0x00BA,
  3211. orthogonal: 0x221F,
  3212. oshortdeva: 0x0912,
  3213. oshortvowelsigndeva: 0x094A,
  3214. oslash: 0x00F8,
  3215. oslashacute: 0x01FF,
  3216. osmallhiragana: 0x3049,
  3217. osmallkatakana: 0x30A9,
  3218. osmallkatakanahalfwidth: 0xFF6B,
  3219. ostrokeacute: 0x01FF,
  3220. osuperior: 0xF6F0,
  3221. otcyrillic: 0x047F,
  3222. otilde: 0x00F5,
  3223. otildeacute: 0x1E4D,
  3224. otildedieresis: 0x1E4F,
  3225. oubopomofo: 0x3121,
  3226. overline: 0x203E,
  3227. overlinecenterline: 0xFE4A,
  3228. overlinecmb: 0x0305,
  3229. overlinedashed: 0xFE49,
  3230. overlinedblwavy: 0xFE4C,
  3231. overlinewavy: 0xFE4B,
  3232. overscore: 0x00AF,
  3233. ovowelsignbengali: 0x09CB,
  3234. ovowelsigndeva: 0x094B,
  3235. ovowelsigngujarati: 0x0ACB,
  3236. p: 0x0070,
  3237. paampssquare: 0x3380,
  3238. paasentosquare: 0x332B,
  3239. pabengali: 0x09AA,
  3240. pacute: 0x1E55,
  3241. padeva: 0x092A,
  3242. pagedown: 0x21DF,
  3243. pageup: 0x21DE,
  3244. pagujarati: 0x0AAA,
  3245. pagurmukhi: 0x0A2A,
  3246. pahiragana: 0x3071,
  3247. paiyannoithai: 0x0E2F,
  3248. pakatakana: 0x30D1,
  3249. palatalizationcyrilliccmb: 0x0484,
  3250. palochkacyrillic: 0x04C0,
  3251. pansioskorean: 0x317F,
  3252. paragraph: 0x00B6,
  3253. parallel: 0x2225,
  3254. parenleft: 0x0028,
  3255. parenleftaltonearabic: 0xFD3E,
  3256. parenleftbt: 0xF8ED,
  3257. parenleftex: 0xF8EC,
  3258. parenleftinferior: 0x208D,
  3259. parenleftmonospace: 0xFF08,
  3260. parenleftsmall: 0xFE59,
  3261. parenleftsuperior: 0x207D,
  3262. parenlefttp: 0xF8EB,
  3263. parenleftvertical: 0xFE35,
  3264. parenright: 0x0029,
  3265. parenrightaltonearabic: 0xFD3F,
  3266. parenrightbt: 0xF8F8,
  3267. parenrightex: 0xF8F7,
  3268. parenrightinferior: 0x208E,
  3269. parenrightmonospace: 0xFF09,
  3270. parenrightsmall: 0xFE5A,
  3271. parenrightsuperior: 0x207E,
  3272. parenrighttp: 0xF8F6,
  3273. parenrightvertical: 0xFE36,
  3274. partialdiff: 0x2202,
  3275. paseqhebrew: 0x05C0,
  3276. pashtahebrew: 0x0599,
  3277. pasquare: 0x33A9,
  3278. patah: 0x05B7,
  3279. patah11: 0x05B7,
  3280. patah1d: 0x05B7,
  3281. patah2a: 0x05B7,
  3282. patahhebrew: 0x05B7,
  3283. patahnarrowhebrew: 0x05B7,
  3284. patahquarterhebrew: 0x05B7,
  3285. patahwidehebrew: 0x05B7,
  3286. pazerhebrew: 0x05A1,
  3287. pbopomofo: 0x3106,
  3288. pcircle: 0x24DF,
  3289. pdotaccent: 0x1E57,
  3290. pe: 0x05E4,
  3291. pecyrillic: 0x043F,
  3292. pedagesh: 0xFB44,
  3293. pedageshhebrew: 0xFB44,
  3294. peezisquare: 0x333B,
  3295. pefinaldageshhebrew: 0xFB43,
  3296. peharabic: 0x067E,
  3297. peharmenian: 0x057A,
  3298. pehebrew: 0x05E4,
  3299. pehfinalarabic: 0xFB57,
  3300. pehinitialarabic: 0xFB58,
  3301. pehiragana: 0x307A,
  3302. pehmedialarabic: 0xFB59,
  3303. pekatakana: 0x30DA,
  3304. pemiddlehookcyrillic: 0x04A7,
  3305. perafehebrew: 0xFB4E,
  3306. percent: 0x0025,
  3307. percentarabic: 0x066A,
  3308. percentmonospace: 0xFF05,
  3309. percentsmall: 0xFE6A,
  3310. period: 0x002E,
  3311. periodarmenian: 0x0589,
  3312. periodcentered: 0x00B7,
  3313. periodhalfwidth: 0xFF61,
  3314. periodinferior: 0xF6E7,
  3315. periodmonospace: 0xFF0E,
  3316. periodsmall: 0xFE52,
  3317. periodsuperior: 0xF6E8,
  3318. perispomenigreekcmb: 0x0342,
  3319. perpendicular: 0x22A5,
  3320. perthousand: 0x2030,
  3321. peseta: 0x20A7,
  3322. pfsquare: 0x338A,
  3323. phabengali: 0x09AB,
  3324. phadeva: 0x092B,
  3325. phagujarati: 0x0AAB,
  3326. phagurmukhi: 0x0A2B,
  3327. phi: 0x03C6,
  3328. phi1: 0x03D5,
  3329. phieuphacirclekorean: 0x327A,
  3330. phieuphaparenkorean: 0x321A,
  3331. phieuphcirclekorean: 0x326C,
  3332. phieuphkorean: 0x314D,
  3333. phieuphparenkorean: 0x320C,
  3334. philatin: 0x0278,
  3335. phinthuthai: 0x0E3A,
  3336. phisymbolgreek: 0x03D5,
  3337. phook: 0x01A5,
  3338. phophanthai: 0x0E1E,
  3339. phophungthai: 0x0E1C,
  3340. phosamphaothai: 0x0E20,
  3341. pi: 0x03C0,
  3342. pieupacirclekorean: 0x3273,
  3343. pieupaparenkorean: 0x3213,
  3344. pieupcieuckorean: 0x3176,
  3345. pieupcirclekorean: 0x3265,
  3346. pieupkiyeokkorean: 0x3172,
  3347. pieupkorean: 0x3142,
  3348. pieupparenkorean: 0x3205,
  3349. pieupsioskiyeokkorean: 0x3174,
  3350. pieupsioskorean: 0x3144,
  3351. pieupsiostikeutkorean: 0x3175,
  3352. pieupthieuthkorean: 0x3177,
  3353. pieuptikeutkorean: 0x3173,
  3354. pihiragana: 0x3074,
  3355. pikatakana: 0x30D4,
  3356. pisymbolgreek: 0x03D6,
  3357. piwrarmenian: 0x0583,
  3358. plus: 0x002B,
  3359. plusbelowcmb: 0x031F,
  3360. pluscircle: 0x2295,
  3361. plusminus: 0x00B1,
  3362. plusmod: 0x02D6,
  3363. plusmonospace: 0xFF0B,
  3364. plussmall: 0xFE62,
  3365. plussuperior: 0x207A,
  3366. pmonospace: 0xFF50,
  3367. pmsquare: 0x33D8,
  3368. pohiragana: 0x307D,
  3369. pointingindexdownwhite: 0x261F,
  3370. pointingindexleftwhite: 0x261C,
  3371. pointingindexrightwhite: 0x261E,
  3372. pointingindexupwhite: 0x261D,
  3373. pokatakana: 0x30DD,
  3374. poplathai: 0x0E1B,
  3375. postalmark: 0x3012,
  3376. postalmarkface: 0x3020,
  3377. pparen: 0x24AB,
  3378. precedes: 0x227A,
  3379. prescription: 0x211E,
  3380. primemod: 0x02B9,
  3381. primereversed: 0x2035,
  3382. product: 0x220F,
  3383. projective: 0x2305,
  3384. prolongedkana: 0x30FC,
  3385. propellor: 0x2318,
  3386. propersubset: 0x2282,
  3387. propersuperset: 0x2283,
  3388. proportion: 0x2237,
  3389. proportional: 0x221D,
  3390. psi: 0x03C8,
  3391. psicyrillic: 0x0471,
  3392. psilipneumatacyrilliccmb: 0x0486,
  3393. pssquare: 0x33B0,
  3394. puhiragana: 0x3077,
  3395. pukatakana: 0x30D7,
  3396. pvsquare: 0x33B4,
  3397. pwsquare: 0x33BA,
  3398. q: 0x0071,
  3399. qadeva: 0x0958,
  3400. qadmahebrew: 0x05A8,
  3401. qafarabic: 0x0642,
  3402. qaffinalarabic: 0xFED6,
  3403. qafinitialarabic: 0xFED7,
  3404. qafmedialarabic: 0xFED8,
  3405. qamats: 0x05B8,
  3406. qamats10: 0x05B8,
  3407. qamats1a: 0x05B8,
  3408. qamats1c: 0x05B8,
  3409. qamats27: 0x05B8,
  3410. qamats29: 0x05B8,
  3411. qamats33: 0x05B8,
  3412. qamatsde: 0x05B8,
  3413. qamatshebrew: 0x05B8,
  3414. qamatsnarrowhebrew: 0x05B8,
  3415. qamatsqatanhebrew: 0x05B8,
  3416. qamatsqatannarrowhebrew: 0x05B8,
  3417. qamatsqatanquarterhebrew: 0x05B8,
  3418. qamatsqatanwidehebrew: 0x05B8,
  3419. qamatsquarterhebrew: 0x05B8,
  3420. qamatswidehebrew: 0x05B8,
  3421. qarneyparahebrew: 0x059F,
  3422. qbopomofo: 0x3111,
  3423. qcircle: 0x24E0,
  3424. qhook: 0x02A0,
  3425. qmonospace: 0xFF51,
  3426. qof: 0x05E7,
  3427. qofdagesh: 0xFB47,
  3428. qofdageshhebrew: 0xFB47,
  3429. qofhebrew: 0x05E7,
  3430. qparen: 0x24AC,
  3431. quarternote: 0x2669,
  3432. qubuts: 0x05BB,
  3433. qubuts18: 0x05BB,
  3434. qubuts25: 0x05BB,
  3435. qubuts31: 0x05BB,
  3436. qubutshebrew: 0x05BB,
  3437. qubutsnarrowhebrew: 0x05BB,
  3438. qubutsquarterhebrew: 0x05BB,
  3439. qubutswidehebrew: 0x05BB,
  3440. question: 0x003F,
  3441. questionarabic: 0x061F,
  3442. questionarmenian: 0x055E,
  3443. questiondown: 0x00BF,
  3444. questiondownsmall: 0xF7BF,
  3445. questiongreek: 0x037E,
  3446. questionmonospace: 0xFF1F,
  3447. questionsmall: 0xF73F,
  3448. quotedbl: 0x0022,
  3449. quotedblbase: 0x201E,
  3450. quotedblleft: 0x201C,
  3451. quotedblmonospace: 0xFF02,
  3452. quotedblprime: 0x301E,
  3453. quotedblprimereversed: 0x301D,
  3454. quotedblright: 0x201D,
  3455. quoteleft: 0x2018,
  3456. quoteleftreversed: 0x201B,
  3457. quotereversed: 0x201B,
  3458. quoteright: 0x2019,
  3459. quoterightn: 0x0149,
  3460. quotesinglbase: 0x201A,
  3461. quotesingle: 0x0027,
  3462. quotesinglemonospace: 0xFF07,
  3463. r: 0x0072,
  3464. raarmenian: 0x057C,
  3465. rabengali: 0x09B0,
  3466. racute: 0x0155,
  3467. radeva: 0x0930,
  3468. radical: 0x221A,
  3469. radicalex: 0xF8E5,
  3470. radoverssquare: 0x33AE,
  3471. radoverssquaredsquare: 0x33AF,
  3472. radsquare: 0x33AD,
  3473. rafe: 0x05BF,
  3474. rafehebrew: 0x05BF,
  3475. ragujarati: 0x0AB0,
  3476. ragurmukhi: 0x0A30,
  3477. rahiragana: 0x3089,
  3478. rakatakana: 0x30E9,
  3479. rakatakanahalfwidth: 0xFF97,
  3480. ralowerdiagonalbengali: 0x09F1,
  3481. ramiddlediagonalbengali: 0x09F0,
  3482. ramshorn: 0x0264,
  3483. ratio: 0x2236,
  3484. rbopomofo: 0x3116,
  3485. rcaron: 0x0159,
  3486. rcedilla: 0x0157,
  3487. rcircle: 0x24E1,
  3488. rcommaaccent: 0x0157,
  3489. rdblgrave: 0x0211,
  3490. rdotaccent: 0x1E59,
  3491. rdotbelow: 0x1E5B,
  3492. rdotbelowmacron: 0x1E5D,
  3493. referencemark: 0x203B,
  3494. reflexsubset: 0x2286,
  3495. reflexsuperset: 0x2287,
  3496. registered: 0x00AE,
  3497. registersans: 0xF8E8,
  3498. registerserif: 0xF6DA,
  3499. reharabic: 0x0631,
  3500. reharmenian: 0x0580,
  3501. rehfinalarabic: 0xFEAE,
  3502. rehiragana: 0x308C,
  3503. rekatakana: 0x30EC,
  3504. rekatakanahalfwidth: 0xFF9A,
  3505. resh: 0x05E8,
  3506. reshdageshhebrew: 0xFB48,
  3507. reshhebrew: 0x05E8,
  3508. reversedtilde: 0x223D,
  3509. reviahebrew: 0x0597,
  3510. reviamugrashhebrew: 0x0597,
  3511. revlogicalnot: 0x2310,
  3512. rfishhook: 0x027E,
  3513. rfishhookreversed: 0x027F,
  3514. rhabengali: 0x09DD,
  3515. rhadeva: 0x095D,
  3516. rho: 0x03C1,
  3517. rhook: 0x027D,
  3518. rhookturned: 0x027B,
  3519. rhookturnedsuperior: 0x02B5,
  3520. rhosymbolgreek: 0x03F1,
  3521. rhotichookmod: 0x02DE,
  3522. rieulacirclekorean: 0x3271,
  3523. rieulaparenkorean: 0x3211,
  3524. rieulcirclekorean: 0x3263,
  3525. rieulhieuhkorean: 0x3140,
  3526. rieulkiyeokkorean: 0x313A,
  3527. rieulkiyeoksioskorean: 0x3169,
  3528. rieulkorean: 0x3139,
  3529. rieulmieumkorean: 0x313B,
  3530. rieulpansioskorean: 0x316C,
  3531. rieulparenkorean: 0x3203,
  3532. rieulphieuphkorean: 0x313F,
  3533. rieulpieupkorean: 0x313C,
  3534. rieulpieupsioskorean: 0x316B,
  3535. rieulsioskorean: 0x313D,
  3536. rieulthieuthkorean: 0x313E,
  3537. rieultikeutkorean: 0x316A,
  3538. rieulyeorinhieuhkorean: 0x316D,
  3539. rightangle: 0x221F,
  3540. righttackbelowcmb: 0x0319,
  3541. righttriangle: 0x22BF,
  3542. rihiragana: 0x308A,
  3543. rikatakana: 0x30EA,
  3544. rikatakanahalfwidth: 0xFF98,
  3545. ring: 0x02DA,
  3546. ringbelowcmb: 0x0325,
  3547. ringcmb: 0x030A,
  3548. ringhalfleft: 0x02BF,
  3549. ringhalfleftarmenian: 0x0559,
  3550. ringhalfleftbelowcmb: 0x031C,
  3551. ringhalfleftcentered: 0x02D3,
  3552. ringhalfright: 0x02BE,
  3553. ringhalfrightbelowcmb: 0x0339,
  3554. ringhalfrightcentered: 0x02D2,
  3555. rinvertedbreve: 0x0213,
  3556. rittorusquare: 0x3351,
  3557. rlinebelow: 0x1E5F,
  3558. rlongleg: 0x027C,
  3559. rlonglegturned: 0x027A,
  3560. rmonospace: 0xFF52,
  3561. rohiragana: 0x308D,
  3562. rokatakana: 0x30ED,
  3563. rokatakanahalfwidth: 0xFF9B,
  3564. roruathai: 0x0E23,
  3565. rparen: 0x24AD,
  3566. rrabengali: 0x09DC,
  3567. rradeva: 0x0931,
  3568. rragurmukhi: 0x0A5C,
  3569. rreharabic: 0x0691,
  3570. rrehfinalarabic: 0xFB8D,
  3571. rrvocalicbengali: 0x09E0,
  3572. rrvocalicdeva: 0x0960,
  3573. rrvocalicgujarati: 0x0AE0,
  3574. rrvocalicvowelsignbengali: 0x09C4,
  3575. rrvocalicvowelsigndeva: 0x0944,
  3576. rrvocalicvowelsigngujarati: 0x0AC4,
  3577. rsuperior: 0xF6F1,
  3578. rtblock: 0x2590,
  3579. rturned: 0x0279,
  3580. rturnedsuperior: 0x02B4,
  3581. ruhiragana: 0x308B,
  3582. rukatakana: 0x30EB,
  3583. rukatakanahalfwidth: 0xFF99,
  3584. rupeemarkbengali: 0x09F2,
  3585. rupeesignbengali: 0x09F3,
  3586. rupiah: 0xF6DD,
  3587. ruthai: 0x0E24,
  3588. rvocalicbengali: 0x098B,
  3589. rvocalicdeva: 0x090B,
  3590. rvocalicgujarati: 0x0A8B,
  3591. rvocalicvowelsignbengali: 0x09C3,
  3592. rvocalicvowelsigndeva: 0x0943,
  3593. rvocalicvowelsigngujarati: 0x0AC3,
  3594. s: 0x0073,
  3595. sabengali: 0x09B8,
  3596. sacute: 0x015B,
  3597. sacutedotaccent: 0x1E65,
  3598. sadarabic: 0x0635,
  3599. sadeva: 0x0938,
  3600. sadfinalarabic: 0xFEBA,
  3601. sadinitialarabic: 0xFEBB,
  3602. sadmedialarabic: 0xFEBC,
  3603. sagujarati: 0x0AB8,
  3604. sagurmukhi: 0x0A38,
  3605. sahiragana: 0x3055,
  3606. sakatakana: 0x30B5,
  3607. sakatakanahalfwidth: 0xFF7B,
  3608. sallallahoualayhewasallamarabic: 0xFDFA,
  3609. samekh: 0x05E1,
  3610. samekhdagesh: 0xFB41,
  3611. samekhdageshhebrew: 0xFB41,
  3612. samekhhebrew: 0x05E1,
  3613. saraaathai: 0x0E32,
  3614. saraaethai: 0x0E41,
  3615. saraaimaimalaithai: 0x0E44,
  3616. saraaimaimuanthai: 0x0E43,
  3617. saraamthai: 0x0E33,
  3618. saraathai: 0x0E30,
  3619. saraethai: 0x0E40,
  3620. saraiileftthai: 0xF886,
  3621. saraiithai: 0x0E35,
  3622. saraileftthai: 0xF885,
  3623. saraithai: 0x0E34,
  3624. saraothai: 0x0E42,
  3625. saraueeleftthai: 0xF888,
  3626. saraueethai: 0x0E37,
  3627. saraueleftthai: 0xF887,
  3628. sarauethai: 0x0E36,
  3629. sarauthai: 0x0E38,
  3630. sarauuthai: 0x0E39,
  3631. sbopomofo: 0x3119,
  3632. scaron: 0x0161,
  3633. scarondotaccent: 0x1E67,
  3634. scedilla: 0x015F,
  3635. schwa: 0x0259,
  3636. schwacyrillic: 0x04D9,
  3637. schwadieresiscyrillic: 0x04DB,
  3638. schwahook: 0x025A,
  3639. scircle: 0x24E2,
  3640. scircumflex: 0x015D,
  3641. scommaaccent: 0x0219,
  3642. sdotaccent: 0x1E61,
  3643. sdotbelow: 0x1E63,
  3644. sdotbelowdotaccent: 0x1E69,
  3645. seagullbelowcmb: 0x033C,
  3646. second: 0x2033,
  3647. secondtonechinese: 0x02CA,
  3648. section: 0x00A7,
  3649. seenarabic: 0x0633,
  3650. seenfinalarabic: 0xFEB2,
  3651. seeninitialarabic: 0xFEB3,
  3652. seenmedialarabic: 0xFEB4,
  3653. segol: 0x05B6,
  3654. segol13: 0x05B6,
  3655. segol1f: 0x05B6,
  3656. segol2c: 0x05B6,
  3657. segolhebrew: 0x05B6,
  3658. segolnarrowhebrew: 0x05B6,
  3659. segolquarterhebrew: 0x05B6,
  3660. segoltahebrew: 0x0592,
  3661. segolwidehebrew: 0x05B6,
  3662. seharmenian: 0x057D,
  3663. sehiragana: 0x305B,
  3664. sekatakana: 0x30BB,
  3665. sekatakanahalfwidth: 0xFF7E,
  3666. semicolon: 0x003B,
  3667. semicolonarabic: 0x061B,
  3668. semicolonmonospace: 0xFF1B,
  3669. semicolonsmall: 0xFE54,
  3670. semivoicedmarkkana: 0x309C,
  3671. semivoicedmarkkanahalfwidth: 0xFF9F,
  3672. sentisquare: 0x3322,
  3673. sentosquare: 0x3323,
  3674. seven: 0x0037,
  3675. sevenarabic: 0x0667,
  3676. sevenbengali: 0x09ED,
  3677. sevencircle: 0x2466,
  3678. sevencircleinversesansserif: 0x2790,
  3679. sevendeva: 0x096D,
  3680. seveneighths: 0x215E,
  3681. sevengujarati: 0x0AED,
  3682. sevengurmukhi: 0x0A6D,
  3683. sevenhackarabic: 0x0667,
  3684. sevenhangzhou: 0x3027,
  3685. sevenideographicparen: 0x3226,
  3686. seveninferior: 0x2087,
  3687. sevenmonospace: 0xFF17,
  3688. sevenoldstyle: 0xF737,
  3689. sevenparen: 0x247A,
  3690. sevenperiod: 0x248E,
  3691. sevenpersian: 0x06F7,
  3692. sevenroman: 0x2176,
  3693. sevensuperior: 0x2077,
  3694. seventeencircle: 0x2470,
  3695. seventeenparen: 0x2484,
  3696. seventeenperiod: 0x2498,
  3697. seventhai: 0x0E57,
  3698. sfthyphen: 0x00AD,
  3699. shaarmenian: 0x0577,
  3700. shabengali: 0x09B6,
  3701. shacyrillic: 0x0448,
  3702. shaddaarabic: 0x0651,
  3703. shaddadammaarabic: 0xFC61,
  3704. shaddadammatanarabic: 0xFC5E,
  3705. shaddafathaarabic: 0xFC60,
  3706. shaddakasraarabic: 0xFC62,
  3707. shaddakasratanarabic: 0xFC5F,
  3708. shade: 0x2592,
  3709. shadedark: 0x2593,
  3710. shadelight: 0x2591,
  3711. shademedium: 0x2592,
  3712. shadeva: 0x0936,
  3713. shagujarati: 0x0AB6,
  3714. shagurmukhi: 0x0A36,
  3715. shalshelethebrew: 0x0593,
  3716. shbopomofo: 0x3115,
  3717. shchacyrillic: 0x0449,
  3718. sheenarabic: 0x0634,
  3719. sheenfinalarabic: 0xFEB6,
  3720. sheeninitialarabic: 0xFEB7,
  3721. sheenmedialarabic: 0xFEB8,
  3722. sheicoptic: 0x03E3,
  3723. sheqel: 0x20AA,
  3724. sheqelhebrew: 0x20AA,
  3725. sheva: 0x05B0,
  3726. sheva115: 0x05B0,
  3727. sheva15: 0x05B0,
  3728. sheva22: 0x05B0,
  3729. sheva2e: 0x05B0,
  3730. shevahebrew: 0x05B0,
  3731. shevanarrowhebrew: 0x05B0,
  3732. shevaquarterhebrew: 0x05B0,
  3733. shevawidehebrew: 0x05B0,
  3734. shhacyrillic: 0x04BB,
  3735. shimacoptic: 0x03ED,
  3736. shin: 0x05E9,
  3737. shindagesh: 0xFB49,
  3738. shindageshhebrew: 0xFB49,
  3739. shindageshshindot: 0xFB2C,
  3740. shindageshshindothebrew: 0xFB2C,
  3741. shindageshsindot: 0xFB2D,
  3742. shindageshsindothebrew: 0xFB2D,
  3743. shindothebrew: 0x05C1,
  3744. shinhebrew: 0x05E9,
  3745. shinshindot: 0xFB2A,
  3746. shinshindothebrew: 0xFB2A,
  3747. shinsindot: 0xFB2B,
  3748. shinsindothebrew: 0xFB2B,
  3749. shook: 0x0282,
  3750. sigma: 0x03C3,
  3751. sigma1: 0x03C2,
  3752. sigmafinal: 0x03C2,
  3753. sigmalunatesymbolgreek: 0x03F2,
  3754. sihiragana: 0x3057,
  3755. sikatakana: 0x30B7,
  3756. sikatakanahalfwidth: 0xFF7C,
  3757. siluqhebrew: 0x05BD,
  3758. siluqlefthebrew: 0x05BD,
  3759. similar: 0x223C,
  3760. sindothebrew: 0x05C2,
  3761. siosacirclekorean: 0x3274,
  3762. siosaparenkorean: 0x3214,
  3763. sioscieuckorean: 0x317E,
  3764. sioscirclekorean: 0x3266,
  3765. sioskiyeokkorean: 0x317A,
  3766. sioskorean: 0x3145,
  3767. siosnieunkorean: 0x317B,
  3768. siosparenkorean: 0x3206,
  3769. siospieupkorean: 0x317D,
  3770. siostikeutkorean: 0x317C,
  3771. six: 0x0036,
  3772. sixarabic: 0x0666,
  3773. sixbengali: 0x09EC,
  3774. sixcircle: 0x2465,
  3775. sixcircleinversesansserif: 0x278F,
  3776. sixdeva: 0x096C,
  3777. sixgujarati: 0x0AEC,
  3778. sixgurmukhi: 0x0A6C,
  3779. sixhackarabic: 0x0666,
  3780. sixhangzhou: 0x3026,
  3781. sixideographicparen: 0x3225,
  3782. sixinferior: 0x2086,
  3783. sixmonospace: 0xFF16,
  3784. sixoldstyle: 0xF736,
  3785. sixparen: 0x2479,
  3786. sixperiod: 0x248D,
  3787. sixpersian: 0x06F6,
  3788. sixroman: 0x2175,
  3789. sixsuperior: 0x2076,
  3790. sixteencircle: 0x246F,
  3791. sixteencurrencydenominatorbengali: 0x09F9,
  3792. sixteenparen: 0x2483,
  3793. sixteenperiod: 0x2497,
  3794. sixthai: 0x0E56,
  3795. slash: 0x002F,
  3796. slashmonospace: 0xFF0F,
  3797. slong: 0x017F,
  3798. slongdotaccent: 0x1E9B,
  3799. smileface: 0x263A,
  3800. smonospace: 0xFF53,
  3801. sofpasuqhebrew: 0x05C3,
  3802. softhyphen: 0x00AD,
  3803. softsigncyrillic: 0x044C,
  3804. sohiragana: 0x305D,
  3805. sokatakana: 0x30BD,
  3806. sokatakanahalfwidth: 0xFF7F,
  3807. soliduslongoverlaycmb: 0x0338,
  3808. solidusshortoverlaycmb: 0x0337,
  3809. sorusithai: 0x0E29,
  3810. sosalathai: 0x0E28,
  3811. sosothai: 0x0E0B,
  3812. sosuathai: 0x0E2A,
  3813. space: 0x0020,
  3814. spacehackarabic: 0x0020,
  3815. spade: 0x2660,
  3816. spadesuitblack: 0x2660,
  3817. spadesuitwhite: 0x2664,
  3818. sparen: 0x24AE,
  3819. squarebelowcmb: 0x033B,
  3820. squarecc: 0x33C4,
  3821. squarecm: 0x339D,
  3822. squarediagonalcrosshatchfill: 0x25A9,
  3823. squarehorizontalfill: 0x25A4,
  3824. squarekg: 0x338F,
  3825. squarekm: 0x339E,
  3826. squarekmcapital: 0x33CE,
  3827. squareln: 0x33D1,
  3828. squarelog: 0x33D2,
  3829. squaremg: 0x338E,
  3830. squaremil: 0x33D5,
  3831. squaremm: 0x339C,
  3832. squaremsquared: 0x33A1,
  3833. squareorthogonalcrosshatchfill: 0x25A6,
  3834. squareupperlefttolowerrightfill: 0x25A7,
  3835. squareupperrighttolowerleftfill: 0x25A8,
  3836. squareverticalfill: 0x25A5,
  3837. squarewhitewithsmallblack: 0x25A3,
  3838. srsquare: 0x33DB,
  3839. ssabengali: 0x09B7,
  3840. ssadeva: 0x0937,
  3841. ssagujarati: 0x0AB7,
  3842. ssangcieuckorean: 0x3149,
  3843. ssanghieuhkorean: 0x3185,
  3844. ssangieungkorean: 0x3180,
  3845. ssangkiyeokkorean: 0x3132,
  3846. ssangnieunkorean: 0x3165,
  3847. ssangpieupkorean: 0x3143,
  3848. ssangsioskorean: 0x3146,
  3849. ssangtikeutkorean: 0x3138,
  3850. ssuperior: 0xF6F2,
  3851. sterling: 0x00A3,
  3852. sterlingmonospace: 0xFFE1,
  3853. strokelongoverlaycmb: 0x0336,
  3854. strokeshortoverlaycmb: 0x0335,
  3855. subset: 0x2282,
  3856. subsetnotequal: 0x228A,
  3857. subsetorequal: 0x2286,
  3858. succeeds: 0x227B,
  3859. suchthat: 0x220B,
  3860. suhiragana: 0x3059,
  3861. sukatakana: 0x30B9,
  3862. sukatakanahalfwidth: 0xFF7D,
  3863. sukunarabic: 0x0652,
  3864. summation: 0x2211,
  3865. sun: 0x263C,
  3866. superset: 0x2283,
  3867. supersetnotequal: 0x228B,
  3868. supersetorequal: 0x2287,
  3869. svsquare: 0x33DC,
  3870. syouwaerasquare: 0x337C,
  3871. t: 0x0074,
  3872. tabengali: 0x09A4,
  3873. tackdown: 0x22A4,
  3874. tackleft: 0x22A3,
  3875. tadeva: 0x0924,
  3876. tagujarati: 0x0AA4,
  3877. tagurmukhi: 0x0A24,
  3878. taharabic: 0x0637,
  3879. tahfinalarabic: 0xFEC2,
  3880. tahinitialarabic: 0xFEC3,
  3881. tahiragana: 0x305F,
  3882. tahmedialarabic: 0xFEC4,
  3883. taisyouerasquare: 0x337D,
  3884. takatakana: 0x30BF,
  3885. takatakanahalfwidth: 0xFF80,
  3886. tatweelarabic: 0x0640,
  3887. tau: 0x03C4,
  3888. tav: 0x05EA,
  3889. tavdages: 0xFB4A,
  3890. tavdagesh: 0xFB4A,
  3891. tavdageshhebrew: 0xFB4A,
  3892. tavhebrew: 0x05EA,
  3893. tbar: 0x0167,
  3894. tbopomofo: 0x310A,
  3895. tcaron: 0x0165,
  3896. tccurl: 0x02A8,
  3897. tcedilla: 0x0163,
  3898. tcheharabic: 0x0686,
  3899. tchehfinalarabic: 0xFB7B,
  3900. tchehinitialarabic: 0xFB7C,
  3901. tchehmedialarabic: 0xFB7D,
  3902. tcircle: 0x24E3,
  3903. tcircumflexbelow: 0x1E71,
  3904. tcommaaccent: 0x0163,
  3905. tdieresis: 0x1E97,
  3906. tdotaccent: 0x1E6B,
  3907. tdotbelow: 0x1E6D,
  3908. tecyrillic: 0x0442,
  3909. tedescendercyrillic: 0x04AD,
  3910. teharabic: 0x062A,
  3911. tehfinalarabic: 0xFE96,
  3912. tehhahinitialarabic: 0xFCA2,
  3913. tehhahisolatedarabic: 0xFC0C,
  3914. tehinitialarabic: 0xFE97,
  3915. tehiragana: 0x3066,
  3916. tehjeeminitialarabic: 0xFCA1,
  3917. tehjeemisolatedarabic: 0xFC0B,
  3918. tehmarbutaarabic: 0x0629,
  3919. tehmarbutafinalarabic: 0xFE94,
  3920. tehmedialarabic: 0xFE98,
  3921. tehmeeminitialarabic: 0xFCA4,
  3922. tehmeemisolatedarabic: 0xFC0E,
  3923. tehnoonfinalarabic: 0xFC73,
  3924. tekatakana: 0x30C6,
  3925. tekatakanahalfwidth: 0xFF83,
  3926. telephone: 0x2121,
  3927. telephoneblack: 0x260E,
  3928. telishagedolahebrew: 0x05A0,
  3929. telishaqetanahebrew: 0x05A9,
  3930. tencircle: 0x2469,
  3931. tenideographicparen: 0x3229,
  3932. tenparen: 0x247D,
  3933. tenperiod: 0x2491,
  3934. tenroman: 0x2179,
  3935. tesh: 0x02A7,
  3936. tet: 0x05D8,
  3937. tetdagesh: 0xFB38,
  3938. tetdageshhebrew: 0xFB38,
  3939. tethebrew: 0x05D8,
  3940. tetsecyrillic: 0x04B5,
  3941. tevirhebrew: 0x059B,
  3942. tevirlefthebrew: 0x059B,
  3943. thabengali: 0x09A5,
  3944. thadeva: 0x0925,
  3945. thagujarati: 0x0AA5,
  3946. thagurmukhi: 0x0A25,
  3947. thalarabic: 0x0630,
  3948. thalfinalarabic: 0xFEAC,
  3949. thanthakhatlowleftthai: 0xF898,
  3950. thanthakhatlowrightthai: 0xF897,
  3951. thanthakhatthai: 0x0E4C,
  3952. thanthakhatupperleftthai: 0xF896,
  3953. theharabic: 0x062B,
  3954. thehfinalarabic: 0xFE9A,
  3955. thehinitialarabic: 0xFE9B,
  3956. thehmedialarabic: 0xFE9C,
  3957. thereexists: 0x2203,
  3958. therefore: 0x2234,
  3959. theta: 0x03B8,
  3960. theta1: 0x03D1,
  3961. thetasymbolgreek: 0x03D1,
  3962. thieuthacirclekorean: 0x3279,
  3963. thieuthaparenkorean: 0x3219,
  3964. thieuthcirclekorean: 0x326B,
  3965. thieuthkorean: 0x314C,
  3966. thieuthparenkorean: 0x320B,
  3967. thirteencircle: 0x246C,
  3968. thirteenparen: 0x2480,
  3969. thirteenperiod: 0x2494,
  3970. thonangmonthothai: 0x0E11,
  3971. thook: 0x01AD,
  3972. thophuthaothai: 0x0E12,
  3973. thorn: 0x00FE,
  3974. thothahanthai: 0x0E17,
  3975. thothanthai: 0x0E10,
  3976. thothongthai: 0x0E18,
  3977. thothungthai: 0x0E16,
  3978. thousandcyrillic: 0x0482,
  3979. thousandsseparatorarabic: 0x066C,
  3980. thousandsseparatorpersian: 0x066C,
  3981. three: 0x0033,
  3982. threearabic: 0x0663,
  3983. threebengali: 0x09E9,
  3984. threecircle: 0x2462,
  3985. threecircleinversesansserif: 0x278C,
  3986. threedeva: 0x0969,
  3987. threeeighths: 0x215C,
  3988. threegujarati: 0x0AE9,
  3989. threegurmukhi: 0x0A69,
  3990. threehackarabic: 0x0663,
  3991. threehangzhou: 0x3023,
  3992. threeideographicparen: 0x3222,
  3993. threeinferior: 0x2083,
  3994. threemonospace: 0xFF13,
  3995. threenumeratorbengali: 0x09F6,
  3996. threeoldstyle: 0xF733,
  3997. threeparen: 0x2476,
  3998. threeperiod: 0x248A,
  3999. threepersian: 0x06F3,
  4000. threequarters: 0x00BE,
  4001. threequartersemdash: 0xF6DE,
  4002. threeroman: 0x2172,
  4003. threesuperior: 0x00B3,
  4004. threethai: 0x0E53,
  4005. thzsquare: 0x3394,
  4006. tihiragana: 0x3061,
  4007. tikatakana: 0x30C1,
  4008. tikatakanahalfwidth: 0xFF81,
  4009. tikeutacirclekorean: 0x3270,
  4010. tikeutaparenkorean: 0x3210,
  4011. tikeutcirclekorean: 0x3262,
  4012. tikeutkorean: 0x3137,
  4013. tikeutparenkorean: 0x3202,
  4014. tilde: 0x02DC,
  4015. tildebelowcmb: 0x0330,
  4016. tildecmb: 0x0303,
  4017. tildecomb: 0x0303,
  4018. tildedoublecmb: 0x0360,
  4019. tildeoperator: 0x223C,
  4020. tildeoverlaycmb: 0x0334,
  4021. tildeverticalcmb: 0x033E,
  4022. timescircle: 0x2297,
  4023. tipehahebrew: 0x0596,
  4024. tipehalefthebrew: 0x0596,
  4025. tippigurmukhi: 0x0A70,
  4026. titlocyrilliccmb: 0x0483,
  4027. tiwnarmenian: 0x057F,
  4028. tlinebelow: 0x1E6F,
  4029. tmonospace: 0xFF54,
  4030. toarmenian: 0x0569,
  4031. tohiragana: 0x3068,
  4032. tokatakana: 0x30C8,
  4033. tokatakanahalfwidth: 0xFF84,
  4034. tonebarextrahighmod: 0x02E5,
  4035. tonebarextralowmod: 0x02E9,
  4036. tonebarhighmod: 0x02E6,
  4037. tonebarlowmod: 0x02E8,
  4038. tonebarmidmod: 0x02E7,
  4039. tonefive: 0x01BD,
  4040. tonesix: 0x0185,
  4041. tonetwo: 0x01A8,
  4042. tonos: 0x0384,
  4043. tonsquare: 0x3327,
  4044. topatakthai: 0x0E0F,
  4045. tortoiseshellbracketleft: 0x3014,
  4046. tortoiseshellbracketleftsmall: 0xFE5D,
  4047. tortoiseshellbracketleftvertical: 0xFE39,
  4048. tortoiseshellbracketright: 0x3015,
  4049. tortoiseshellbracketrightsmall: 0xFE5E,
  4050. tortoiseshellbracketrightvertical: 0xFE3A,
  4051. totaothai: 0x0E15,
  4052. tpalatalhook: 0x01AB,
  4053. tparen: 0x24AF,
  4054. trademark: 0x2122,
  4055. trademarksans: 0xF8EA,
  4056. trademarkserif: 0xF6DB,
  4057. tretroflexhook: 0x0288,
  4058. triagdn: 0x25BC,
  4059. triaglf: 0x25C4,
  4060. triagrt: 0x25BA,
  4061. triagup: 0x25B2,
  4062. ts: 0x02A6,
  4063. tsadi: 0x05E6,
  4064. tsadidagesh: 0xFB46,
  4065. tsadidageshhebrew: 0xFB46,
  4066. tsadihebrew: 0x05E6,
  4067. tsecyrillic: 0x0446,
  4068. tsere: 0x05B5,
  4069. tsere12: 0x05B5,
  4070. tsere1e: 0x05B5,
  4071. tsere2b: 0x05B5,
  4072. tserehebrew: 0x05B5,
  4073. tserenarrowhebrew: 0x05B5,
  4074. tserequarterhebrew: 0x05B5,
  4075. tserewidehebrew: 0x05B5,
  4076. tshecyrillic: 0x045B,
  4077. tsuperior: 0xF6F3,
  4078. ttabengali: 0x099F,
  4079. ttadeva: 0x091F,
  4080. ttagujarati: 0x0A9F,
  4081. ttagurmukhi: 0x0A1F,
  4082. tteharabic: 0x0679,
  4083. ttehfinalarabic: 0xFB67,
  4084. ttehinitialarabic: 0xFB68,
  4085. ttehmedialarabic: 0xFB69,
  4086. tthabengali: 0x09A0,
  4087. tthadeva: 0x0920,
  4088. tthagujarati: 0x0AA0,
  4089. tthagurmukhi: 0x0A20,
  4090. tturned: 0x0287,
  4091. tuhiragana: 0x3064,
  4092. tukatakana: 0x30C4,
  4093. tukatakanahalfwidth: 0xFF82,
  4094. tusmallhiragana: 0x3063,
  4095. tusmallkatakana: 0x30C3,
  4096. tusmallkatakanahalfwidth: 0xFF6F,
  4097. twelvecircle: 0x246B,
  4098. twelveparen: 0x247F,
  4099. twelveperiod: 0x2493,
  4100. twelveroman: 0x217B,
  4101. twentycircle: 0x2473,
  4102. twentyhangzhou: 0x5344,
  4103. twentyparen: 0x2487,
  4104. twentyperiod: 0x249B,
  4105. two: 0x0032,
  4106. twoarabic: 0x0662,
  4107. twobengali: 0x09E8,
  4108. twocircle: 0x2461,
  4109. twocircleinversesansserif: 0x278B,
  4110. twodeva: 0x0968,
  4111. twodotenleader: 0x2025,
  4112. twodotleader: 0x2025,
  4113. twodotleadervertical: 0xFE30,
  4114. twogujarati: 0x0AE8,
  4115. twogurmukhi: 0x0A68,
  4116. twohackarabic: 0x0662,
  4117. twohangzhou: 0x3022,
  4118. twoideographicparen: 0x3221,
  4119. twoinferior: 0x2082,
  4120. twomonospace: 0xFF12,
  4121. twonumeratorbengali: 0x09F5,
  4122. twooldstyle: 0xF732,
  4123. twoparen: 0x2475,
  4124. twoperiod: 0x2489,
  4125. twopersian: 0x06F2,
  4126. tworoman: 0x2171,
  4127. twostroke: 0x01BB,
  4128. twosuperior: 0x00B2,
  4129. twothai: 0x0E52,
  4130. twothirds: 0x2154,
  4131. u: 0x0075,
  4132. uacute: 0x00FA,
  4133. ubar: 0x0289,
  4134. ubengali: 0x0989,
  4135. ubopomofo: 0x3128,
  4136. ubreve: 0x016D,
  4137. ucaron: 0x01D4,
  4138. ucircle: 0x24E4,
  4139. ucircumflex: 0x00FB,
  4140. ucircumflexbelow: 0x1E77,
  4141. ucyrillic: 0x0443,
  4142. udattadeva: 0x0951,
  4143. udblacute: 0x0171,
  4144. udblgrave: 0x0215,
  4145. udeva: 0x0909,
  4146. udieresis: 0x00FC,
  4147. udieresisacute: 0x01D8,
  4148. udieresisbelow: 0x1E73,
  4149. udieresiscaron: 0x01DA,
  4150. udieresiscyrillic: 0x04F1,
  4151. udieresisgrave: 0x01DC,
  4152. udieresismacron: 0x01D6,
  4153. udotbelow: 0x1EE5,
  4154. ugrave: 0x00F9,
  4155. ugujarati: 0x0A89,
  4156. ugurmukhi: 0x0A09,
  4157. uhiragana: 0x3046,
  4158. uhookabove: 0x1EE7,
  4159. uhorn: 0x01B0,
  4160. uhornacute: 0x1EE9,
  4161. uhorndotbelow: 0x1EF1,
  4162. uhorngrave: 0x1EEB,
  4163. uhornhookabove: 0x1EED,
  4164. uhorntilde: 0x1EEF,
  4165. uhungarumlaut: 0x0171,
  4166. uhungarumlautcyrillic: 0x04F3,
  4167. uinvertedbreve: 0x0217,
  4168. ukatakana: 0x30A6,
  4169. ukatakanahalfwidth: 0xFF73,
  4170. ukcyrillic: 0x0479,
  4171. ukorean: 0x315C,
  4172. umacron: 0x016B,
  4173. umacroncyrillic: 0x04EF,
  4174. umacrondieresis: 0x1E7B,
  4175. umatragurmukhi: 0x0A41,
  4176. umonospace: 0xFF55,
  4177. underscore: 0x005F,
  4178. underscoredbl: 0x2017,
  4179. underscoremonospace: 0xFF3F,
  4180. underscorevertical: 0xFE33,
  4181. underscorewavy: 0xFE4F,
  4182. union: 0x222A,
  4183. universal: 0x2200,
  4184. uogonek: 0x0173,
  4185. uparen: 0x24B0,
  4186. upblock: 0x2580,
  4187. upperdothebrew: 0x05C4,
  4188. upsilon: 0x03C5,
  4189. upsilondieresis: 0x03CB,
  4190. upsilondieresistonos: 0x03B0,
  4191. upsilonlatin: 0x028A,
  4192. upsilontonos: 0x03CD,
  4193. uptackbelowcmb: 0x031D,
  4194. uptackmod: 0x02D4,
  4195. uragurmukhi: 0x0A73,
  4196. uring: 0x016F,
  4197. ushortcyrillic: 0x045E,
  4198. usmallhiragana: 0x3045,
  4199. usmallkatakana: 0x30A5,
  4200. usmallkatakanahalfwidth: 0xFF69,
  4201. ustraightcyrillic: 0x04AF,
  4202. ustraightstrokecyrillic: 0x04B1,
  4203. utilde: 0x0169,
  4204. utildeacute: 0x1E79,
  4205. utildebelow: 0x1E75,
  4206. uubengali: 0x098A,
  4207. uudeva: 0x090A,
  4208. uugujarati: 0x0A8A,
  4209. uugurmukhi: 0x0A0A,
  4210. uumatragurmukhi: 0x0A42,
  4211. uuvowelsignbengali: 0x09C2,
  4212. uuvowelsigndeva: 0x0942,
  4213. uuvowelsigngujarati: 0x0AC2,
  4214. uvowelsignbengali: 0x09C1,
  4215. uvowelsigndeva: 0x0941,
  4216. uvowelsigngujarati: 0x0AC1,
  4217. v: 0x0076,
  4218. vadeva: 0x0935,
  4219. vagujarati: 0x0AB5,
  4220. vagurmukhi: 0x0A35,
  4221. vakatakana: 0x30F7,
  4222. vav: 0x05D5,
  4223. vavdagesh: 0xFB35,
  4224. vavdagesh65: 0xFB35,
  4225. vavdageshhebrew: 0xFB35,
  4226. vavhebrew: 0x05D5,
  4227. vavholam: 0xFB4B,
  4228. vavholamhebrew: 0xFB4B,
  4229. vavvavhebrew: 0x05F0,
  4230. vavyodhebrew: 0x05F1,
  4231. vcircle: 0x24E5,
  4232. vdotbelow: 0x1E7F,
  4233. vecyrillic: 0x0432,
  4234. veharabic: 0x06A4,
  4235. vehfinalarabic: 0xFB6B,
  4236. vehinitialarabic: 0xFB6C,
  4237. vehmedialarabic: 0xFB6D,
  4238. vekatakana: 0x30F9,
  4239. venus: 0x2640,
  4240. verticalbar: 0x007C,
  4241. verticallineabovecmb: 0x030D,
  4242. verticallinebelowcmb: 0x0329,
  4243. verticallinelowmod: 0x02CC,
  4244. verticallinemod: 0x02C8,
  4245. vewarmenian: 0x057E,
  4246. vhook: 0x028B,
  4247. vikatakana: 0x30F8,
  4248. viramabengali: 0x09CD,
  4249. viramadeva: 0x094D,
  4250. viramagujarati: 0x0ACD,
  4251. visargabengali: 0x0983,
  4252. visargadeva: 0x0903,
  4253. visargagujarati: 0x0A83,
  4254. vmonospace: 0xFF56,
  4255. voarmenian: 0x0578,
  4256. voicediterationhiragana: 0x309E,
  4257. voicediterationkatakana: 0x30FE,
  4258. voicedmarkkana: 0x309B,
  4259. voicedmarkkanahalfwidth: 0xFF9E,
  4260. vokatakana: 0x30FA,
  4261. vparen: 0x24B1,
  4262. vtilde: 0x1E7D,
  4263. vturned: 0x028C,
  4264. vuhiragana: 0x3094,
  4265. vukatakana: 0x30F4,
  4266. w: 0x0077,
  4267. wacute: 0x1E83,
  4268. waekorean: 0x3159,
  4269. wahiragana: 0x308F,
  4270. wakatakana: 0x30EF,
  4271. wakatakanahalfwidth: 0xFF9C,
  4272. wakorean: 0x3158,
  4273. wasmallhiragana: 0x308E,
  4274. wasmallkatakana: 0x30EE,
  4275. wattosquare: 0x3357,
  4276. wavedash: 0x301C,
  4277. wavyunderscorevertical: 0xFE34,
  4278. wawarabic: 0x0648,
  4279. wawfinalarabic: 0xFEEE,
  4280. wawhamzaabovearabic: 0x0624,
  4281. wawhamzaabovefinalarabic: 0xFE86,
  4282. wbsquare: 0x33DD,
  4283. wcircle: 0x24E6,
  4284. wcircumflex: 0x0175,
  4285. wdieresis: 0x1E85,
  4286. wdotaccent: 0x1E87,
  4287. wdotbelow: 0x1E89,
  4288. wehiragana: 0x3091,
  4289. weierstrass: 0x2118,
  4290. wekatakana: 0x30F1,
  4291. wekorean: 0x315E,
  4292. weokorean: 0x315D,
  4293. wgrave: 0x1E81,
  4294. whitebullet: 0x25E6,
  4295. whitecircle: 0x25CB,
  4296. whitecircleinverse: 0x25D9,
  4297. whitecornerbracketleft: 0x300E,
  4298. whitecornerbracketleftvertical: 0xFE43,
  4299. whitecornerbracketright: 0x300F,
  4300. whitecornerbracketrightvertical: 0xFE44,
  4301. whitediamond: 0x25C7,
  4302. whitediamondcontainingblacksmalldiamond: 0x25C8,
  4303. whitedownpointingsmalltriangle: 0x25BF,
  4304. whitedownpointingtriangle: 0x25BD,
  4305. whiteleftpointingsmalltriangle: 0x25C3,
  4306. whiteleftpointingtriangle: 0x25C1,
  4307. whitelenticularbracketleft: 0x3016,
  4308. whitelenticularbracketright: 0x3017,
  4309. whiterightpointingsmalltriangle: 0x25B9,
  4310. whiterightpointingtriangle: 0x25B7,
  4311. whitesmallsquare: 0x25AB,
  4312. whitesmilingface: 0x263A,
  4313. whitesquare: 0x25A1,
  4314. whitestar: 0x2606,
  4315. whitetelephone: 0x260F,
  4316. whitetortoiseshellbracketleft: 0x3018,
  4317. whitetortoiseshellbracketright: 0x3019,
  4318. whiteuppointingsmalltriangle: 0x25B5,
  4319. whiteuppointingtriangle: 0x25B3,
  4320. wihiragana: 0x3090,
  4321. wikatakana: 0x30F0,
  4322. wikorean: 0x315F,
  4323. wmonospace: 0xFF57,
  4324. wohiragana: 0x3092,
  4325. wokatakana: 0x30F2,
  4326. wokatakanahalfwidth: 0xFF66,
  4327. won: 0x20A9,
  4328. wonmonospace: 0xFFE6,
  4329. wowaenthai: 0x0E27,
  4330. wparen: 0x24B2,
  4331. wring: 0x1E98,
  4332. wsuperior: 0x02B7,
  4333. wturned: 0x028D,
  4334. wynn: 0x01BF,
  4335. x: 0x0078,
  4336. xabovecmb: 0x033D,
  4337. xbopomofo: 0x3112,
  4338. xcircle: 0x24E7,
  4339. xdieresis: 0x1E8D,
  4340. xdotaccent: 0x1E8B,
  4341. xeharmenian: 0x056D,
  4342. xi: 0x03BE,
  4343. xmonospace: 0xFF58,
  4344. xparen: 0x24B3,
  4345. xsuperior: 0x02E3,
  4346. y: 0x0079,
  4347. yaadosquare: 0x334E,
  4348. yabengali: 0x09AF,
  4349. yacute: 0x00FD,
  4350. yadeva: 0x092F,
  4351. yaekorean: 0x3152,
  4352. yagujarati: 0x0AAF,
  4353. yagurmukhi: 0x0A2F,
  4354. yahiragana: 0x3084,
  4355. yakatakana: 0x30E4,
  4356. yakatakanahalfwidth: 0xFF94,
  4357. yakorean: 0x3151,
  4358. yamakkanthai: 0x0E4E,
  4359. yasmallhiragana: 0x3083,
  4360. yasmallkatakana: 0x30E3,
  4361. yasmallkatakanahalfwidth: 0xFF6C,
  4362. yatcyrillic: 0x0463,
  4363. ycircle: 0x24E8,
  4364. ycircumflex: 0x0177,
  4365. ydieresis: 0x00FF,
  4366. ydotaccent: 0x1E8F,
  4367. ydotbelow: 0x1EF5,
  4368. yeharabic: 0x064A,
  4369. yehbarreearabic: 0x06D2,
  4370. yehbarreefinalarabic: 0xFBAF,
  4371. yehfinalarabic: 0xFEF2,
  4372. yehhamzaabovearabic: 0x0626,
  4373. yehhamzaabovefinalarabic: 0xFE8A,
  4374. yehhamzaaboveinitialarabic: 0xFE8B,
  4375. yehhamzaabovemedialarabic: 0xFE8C,
  4376. yehinitialarabic: 0xFEF3,
  4377. yehmedialarabic: 0xFEF4,
  4378. yehmeeminitialarabic: 0xFCDD,
  4379. yehmeemisolatedarabic: 0xFC58,
  4380. yehnoonfinalarabic: 0xFC94,
  4381. yehthreedotsbelowarabic: 0x06D1,
  4382. yekorean: 0x3156,
  4383. yen: 0x00A5,
  4384. yenmonospace: 0xFFE5,
  4385. yeokorean: 0x3155,
  4386. yeorinhieuhkorean: 0x3186,
  4387. yerahbenyomohebrew: 0x05AA,
  4388. yerahbenyomolefthebrew: 0x05AA,
  4389. yericyrillic: 0x044B,
  4390. yerudieresiscyrillic: 0x04F9,
  4391. yesieungkorean: 0x3181,
  4392. yesieungpansioskorean: 0x3183,
  4393. yesieungsioskorean: 0x3182,
  4394. yetivhebrew: 0x059A,
  4395. ygrave: 0x1EF3,
  4396. yhook: 0x01B4,
  4397. yhookabove: 0x1EF7,
  4398. yiarmenian: 0x0575,
  4399. yicyrillic: 0x0457,
  4400. yikorean: 0x3162,
  4401. yinyang: 0x262F,
  4402. yiwnarmenian: 0x0582,
  4403. ymonospace: 0xFF59,
  4404. yod: 0x05D9,
  4405. yoddagesh: 0xFB39,
  4406. yoddageshhebrew: 0xFB39,
  4407. yodhebrew: 0x05D9,
  4408. yodyodhebrew: 0x05F2,
  4409. yodyodpatahhebrew: 0xFB1F,
  4410. yohiragana: 0x3088,
  4411. yoikorean: 0x3189,
  4412. yokatakana: 0x30E8,
  4413. yokatakanahalfwidth: 0xFF96,
  4414. yokorean: 0x315B,
  4415. yosmallhiragana: 0x3087,
  4416. yosmallkatakana: 0x30E7,
  4417. yosmallkatakanahalfwidth: 0xFF6E,
  4418. yotgreek: 0x03F3,
  4419. yoyaekorean: 0x3188,
  4420. yoyakorean: 0x3187,
  4421. yoyakthai: 0x0E22,
  4422. yoyingthai: 0x0E0D,
  4423. yparen: 0x24B4,
  4424. ypogegrammeni: 0x037A,
  4425. ypogegrammenigreekcmb: 0x0345,
  4426. yr: 0x01A6,
  4427. yring: 0x1E99,
  4428. ysuperior: 0x02B8,
  4429. ytilde: 0x1EF9,
  4430. yturned: 0x028E,
  4431. yuhiragana: 0x3086,
  4432. yuikorean: 0x318C,
  4433. yukatakana: 0x30E6,
  4434. yukatakanahalfwidth: 0xFF95,
  4435. yukorean: 0x3160,
  4436. yusbigcyrillic: 0x046B,
  4437. yusbigiotifiedcyrillic: 0x046D,
  4438. yuslittlecyrillic: 0x0467,
  4439. yuslittleiotifiedcyrillic: 0x0469,
  4440. yusmallhiragana: 0x3085,
  4441. yusmallkatakana: 0x30E5,
  4442. yusmallkatakanahalfwidth: 0xFF6D,
  4443. yuyekorean: 0x318B,
  4444. yuyeokorean: 0x318A,
  4445. yyabengali: 0x09DF,
  4446. yyadeva: 0x095F,
  4447. z: 0x007A,
  4448. zaarmenian: 0x0566,
  4449. zacute: 0x017A,
  4450. zadeva: 0x095B,
  4451. zagurmukhi: 0x0A5B,
  4452. zaharabic: 0x0638,
  4453. zahfinalarabic: 0xFEC6,
  4454. zahinitialarabic: 0xFEC7,
  4455. zahiragana: 0x3056,
  4456. zahmedialarabic: 0xFEC8,
  4457. zainarabic: 0x0632,
  4458. zainfinalarabic: 0xFEB0,
  4459. zakatakana: 0x30B6,
  4460. zaqefgadolhebrew: 0x0595,
  4461. zaqefqatanhebrew: 0x0594,
  4462. zarqahebrew: 0x0598,
  4463. zayin: 0x05D6,
  4464. zayindagesh: 0xFB36,
  4465. zayindageshhebrew: 0xFB36,
  4466. zayinhebrew: 0x05D6,
  4467. zbopomofo: 0x3117,
  4468. zcaron: 0x017E,
  4469. zcircle: 0x24E9,
  4470. zcircumflex: 0x1E91,
  4471. zcurl: 0x0291,
  4472. zdot: 0x017C,
  4473. zdotaccent: 0x017C,
  4474. zdotbelow: 0x1E93,
  4475. zecyrillic: 0x0437,
  4476. zedescendercyrillic: 0x0499,
  4477. zedieresiscyrillic: 0x04DF,
  4478. zehiragana: 0x305C,
  4479. zekatakana: 0x30BC,
  4480. zero: 0x0030,
  4481. zeroarabic: 0x0660,
  4482. zerobengali: 0x09E6,
  4483. zerodeva: 0x0966,
  4484. zerogujarati: 0x0AE6,
  4485. zerogurmukhi: 0x0A66,
  4486. zerohackarabic: 0x0660,
  4487. zeroinferior: 0x2080,
  4488. zeromonospace: 0xFF10,
  4489. zerooldstyle: 0xF730,
  4490. zeropersian: 0x06F0,
  4491. zerosuperior: 0x2070,
  4492. zerothai: 0x0E50,
  4493. zerowidthjoiner: 0xFEFF,
  4494. zerowidthnonjoiner: 0x200C,
  4495. zerowidthspace: 0x200B,
  4496. zeta: 0x03B6,
  4497. zhbopomofo: 0x3113,
  4498. zhearmenian: 0x056A,
  4499. zhebrevecyrillic: 0x04C2,
  4500. zhecyrillic: 0x0436,
  4501. zhedescendercyrillic: 0x0497,
  4502. zhedieresiscyrillic: 0x04DD,
  4503. zihiragana: 0x3058,
  4504. zikatakana: 0x30B8,
  4505. zinorhebrew: 0x05AE,
  4506. zlinebelow: 0x1E95,
  4507. zmonospace: 0xFF5A,
  4508. zohiragana: 0x305E,
  4509. zokatakana: 0x30BE,
  4510. zparen: 0x24B5,
  4511. zretroflexhook: 0x0290,
  4512. zstroke: 0x01B6,
  4513. zuhiragana: 0x305A,
  4514. zukatakana: 0x30BA,
  4515. '.notdef': 0x0000
  4516. };
  4517. var DingbatsGlyphsUnicode = {
  4518. space: 0x0020,
  4519. a1: 0x2701,
  4520. a2: 0x2702,
  4521. a202: 0x2703,
  4522. a3: 0x2704,
  4523. a4: 0x260E,
  4524. a5: 0x2706,
  4525. a119: 0x2707,
  4526. a118: 0x2708,
  4527. a117: 0x2709,
  4528. a11: 0x261B,
  4529. a12: 0x261E,
  4530. a13: 0x270C,
  4531. a14: 0x270D,
  4532. a15: 0x270E,
  4533. a16: 0x270F,
  4534. a105: 0x2710,
  4535. a17: 0x2711,
  4536. a18: 0x2712,
  4537. a19: 0x2713,
  4538. a20: 0x2714,
  4539. a21: 0x2715,
  4540. a22: 0x2716,
  4541. a23: 0x2717,
  4542. a24: 0x2718,
  4543. a25: 0x2719,
  4544. a26: 0x271A,
  4545. a27: 0x271B,
  4546. a28: 0x271C,
  4547. a6: 0x271D,
  4548. a7: 0x271E,
  4549. a8: 0x271F,
  4550. a9: 0x2720,
  4551. a10: 0x2721,
  4552. a29: 0x2722,
  4553. a30: 0x2723,
  4554. a31: 0x2724,
  4555. a32: 0x2725,
  4556. a33: 0x2726,
  4557. a34: 0x2727,
  4558. a35: 0x2605,
  4559. a36: 0x2729,
  4560. a37: 0x272A,
  4561. a38: 0x272B,
  4562. a39: 0x272C,
  4563. a40: 0x272D,
  4564. a41: 0x272E,
  4565. a42: 0x272F,
  4566. a43: 0x2730,
  4567. a44: 0x2731,
  4568. a45: 0x2732,
  4569. a46: 0x2733,
  4570. a47: 0x2734,
  4571. a48: 0x2735,
  4572. a49: 0x2736,
  4573. a50: 0x2737,
  4574. a51: 0x2738,
  4575. a52: 0x2739,
  4576. a53: 0x273A,
  4577. a54: 0x273B,
  4578. a55: 0x273C,
  4579. a56: 0x273D,
  4580. a57: 0x273E,
  4581. a58: 0x273F,
  4582. a59: 0x2740,
  4583. a60: 0x2741,
  4584. a61: 0x2742,
  4585. a62: 0x2743,
  4586. a63: 0x2744,
  4587. a64: 0x2745,
  4588. a65: 0x2746,
  4589. a66: 0x2747,
  4590. a67: 0x2748,
  4591. a68: 0x2749,
  4592. a69: 0x274A,
  4593. a70: 0x274B,
  4594. a71: 0x25CF,
  4595. a72: 0x274D,
  4596. a73: 0x25A0,
  4597. a74: 0x274F,
  4598. a203: 0x2750,
  4599. a75: 0x2751,
  4600. a204: 0x2752,
  4601. a76: 0x25B2,
  4602. a77: 0x25BC,
  4603. a78: 0x25C6,
  4604. a79: 0x2756,
  4605. a81: 0x25D7,
  4606. a82: 0x2758,
  4607. a83: 0x2759,
  4608. a84: 0x275A,
  4609. a97: 0x275B,
  4610. a98: 0x275C,
  4611. a99: 0x275D,
  4612. a100: 0x275E,
  4613. a101: 0x2761,
  4614. a102: 0x2762,
  4615. a103: 0x2763,
  4616. a104: 0x2764,
  4617. a106: 0x2765,
  4618. a107: 0x2766,
  4619. a108: 0x2767,
  4620. a112: 0x2663,
  4621. a111: 0x2666,
  4622. a110: 0x2665,
  4623. a109: 0x2660,
  4624. a120: 0x2460,
  4625. a121: 0x2461,
  4626. a122: 0x2462,
  4627. a123: 0x2463,
  4628. a124: 0x2464,
  4629. a125: 0x2465,
  4630. a126: 0x2466,
  4631. a127: 0x2467,
  4632. a128: 0x2468,
  4633. a129: 0x2469,
  4634. a130: 0x2776,
  4635. a131: 0x2777,
  4636. a132: 0x2778,
  4637. a133: 0x2779,
  4638. a134: 0x277A,
  4639. a135: 0x277B,
  4640. a136: 0x277C,
  4641. a137: 0x277D,
  4642. a138: 0x277E,
  4643. a139: 0x277F,
  4644. a140: 0x2780,
  4645. a141: 0x2781,
  4646. a142: 0x2782,
  4647. a143: 0x2783,
  4648. a144: 0x2784,
  4649. a145: 0x2785,
  4650. a146: 0x2786,
  4651. a147: 0x2787,
  4652. a148: 0x2788,
  4653. a149: 0x2789,
  4654. a150: 0x278A,
  4655. a151: 0x278B,
  4656. a152: 0x278C,
  4657. a153: 0x278D,
  4658. a154: 0x278E,
  4659. a155: 0x278F,
  4660. a156: 0x2790,
  4661. a157: 0x2791,
  4662. a158: 0x2792,
  4663. a159: 0x2793,
  4664. a160: 0x2794,
  4665. a161: 0x2192,
  4666. a163: 0x2194,
  4667. a164: 0x2195,
  4668. a196: 0x2798,
  4669. a165: 0x2799,
  4670. a192: 0x279A,
  4671. a166: 0x279B,
  4672. a167: 0x279C,
  4673. a168: 0x279D,
  4674. a169: 0x279E,
  4675. a170: 0x279F,
  4676. a171: 0x27A0,
  4677. a172: 0x27A1,
  4678. a173: 0x27A2,
  4679. a162: 0x27A3,
  4680. a174: 0x27A4,
  4681. a175: 0x27A5,
  4682. a176: 0x27A6,
  4683. a177: 0x27A7,
  4684. a178: 0x27A8,
  4685. a179: 0x27A9,
  4686. a193: 0x27AA,
  4687. a180: 0x27AB,
  4688. a199: 0x27AC,
  4689. a181: 0x27AD,
  4690. a200: 0x27AE,
  4691. a182: 0x27AF,
  4692. a201: 0x27B1,
  4693. a183: 0x27B2,
  4694. a184: 0x27B3,
  4695. a197: 0x27B4,
  4696. a185: 0x27B5,
  4697. a194: 0x27B6,
  4698. a198: 0x27B7,
  4699. a186: 0x27B8,
  4700. a195: 0x27B9,
  4701. a187: 0x27BA,
  4702. a188: 0x27BB,
  4703. a189: 0x27BC,
  4704. a190: 0x27BD,
  4705. a191: 0x27BE,
  4706. a89: 0x2768, // 0xF8D7
  4707. a90: 0x2769, // 0xF8D8
  4708. a93: 0x276A, // 0xF8D9
  4709. a94: 0x276B, // 0xF8DA
  4710. a91: 0x276C, // 0xF8DB
  4711. a92: 0x276D, // 0xF8DC
  4712. a205: 0x276E, // 0xF8DD
  4713. a85: 0x276F, // 0xF8DE
  4714. a206: 0x2770, // 0xF8DF
  4715. a86: 0x2771, // 0xF8E0
  4716. a87: 0x2772, // 0xF8E1
  4717. a88: 0x2773, // 0xF8E2
  4718. a95: 0x2774, // 0xF8E3
  4719. a96: 0x2775, // 0xF8E4
  4720. '.notdef': 0x0000
  4721. };
  4722. exports.GlyphsUnicode = GlyphsUnicode;
  4723. exports.DingbatsGlyphsUnicode = DingbatsGlyphsUnicode;
  4724. }));
  4725. (function (root, factory) {
  4726. {
  4727. factory((root.pdfjsCoreJpg = {}));
  4728. }
  4729. }(this, function (exports) {
  4730. /*
  4731. This code was forked from https://github.com/notmasteryet/jpgjs. The original
  4732. version was created by github user notmasteryet
  4733. - The JPEG specification can be found in the ITU CCITT Recommendation T.81
  4734. (www.w3.org/Graphics/JPEG/itu-t81.pdf)
  4735. - The JFIF specification can be found in the JPEG File Interchange Format
  4736. (www.w3.org/Graphics/JPEG/jfif3.pdf)
  4737. - The Adobe Application-Specific JPEG markers in the Supporting the DCT Filters
  4738. in PostScript Level 2, Technical Note #5116
  4739. (partners.adobe.com/public/developer/en/ps/sdk/5116.DCT_Filter.pdf)
  4740. */
  4741. var JpegImage = (function jpegImage() {
  4742. var dctZigZag = new Uint8Array([
  4743. 0,
  4744. 1, 8,
  4745. 16, 9, 2,
  4746. 3, 10, 17, 24,
  4747. 32, 25, 18, 11, 4,
  4748. 5, 12, 19, 26, 33, 40,
  4749. 48, 41, 34, 27, 20, 13, 6,
  4750. 7, 14, 21, 28, 35, 42, 49, 56,
  4751. 57, 50, 43, 36, 29, 22, 15,
  4752. 23, 30, 37, 44, 51, 58,
  4753. 59, 52, 45, 38, 31,
  4754. 39, 46, 53, 60,
  4755. 61, 54, 47,
  4756. 55, 62,
  4757. 63
  4758. ]);
  4759. var dctCos1 = 4017; // cos(pi/16)
  4760. var dctSin1 = 799; // sin(pi/16)
  4761. var dctCos3 = 3406; // cos(3*pi/16)
  4762. var dctSin3 = 2276; // sin(3*pi/16)
  4763. var dctCos6 = 1567; // cos(6*pi/16)
  4764. var dctSin6 = 3784; // sin(6*pi/16)
  4765. var dctSqrt2 = 5793; // sqrt(2)
  4766. var dctSqrt1d2 = 2896; // sqrt(2) / 2
  4767. function constructor() {
  4768. }
  4769. function buildHuffmanTable(codeLengths, values) {
  4770. var k = 0, code = [], i, j, length = 16;
  4771. while (length > 0 && !codeLengths[length - 1]) {
  4772. length--;
  4773. }
  4774. code.push({children: [], index: 0});
  4775. var p = code[0], q;
  4776. for (i = 0; i < length; i++) {
  4777. for (j = 0; j < codeLengths[i]; j++) {
  4778. p = code.pop();
  4779. p.children[p.index] = values[k];
  4780. while (p.index > 0) {
  4781. p = code.pop();
  4782. }
  4783. p.index++;
  4784. code.push(p);
  4785. while (code.length <= i) {
  4786. code.push(q = {children: [], index: 0});
  4787. p.children[p.index] = q.children;
  4788. p = q;
  4789. }
  4790. k++;
  4791. }
  4792. if (i + 1 < length) {
  4793. // p here points to last code
  4794. code.push(q = {children: [], index: 0});
  4795. p.children[p.index] = q.children;
  4796. p = q;
  4797. }
  4798. }
  4799. return code[0].children;
  4800. }
  4801. function getBlockBufferOffset(component, row, col) {
  4802. return 64 * ((component.blocksPerLine + 1) * row + col);
  4803. }
  4804. function decodeScan(data, offset, frame, components, resetInterval,
  4805. spectralStart, spectralEnd, successivePrev, successive) {
  4806. var mcusPerLine = frame.mcusPerLine;
  4807. var progressive = frame.progressive;
  4808. var startOffset = offset, bitsData = 0, bitsCount = 0;
  4809. function readBit() {
  4810. if (bitsCount > 0) {
  4811. bitsCount--;
  4812. return (bitsData >> bitsCount) & 1;
  4813. }
  4814. bitsData = data[offset++];
  4815. if (bitsData === 0xFF) {
  4816. var nextByte = data[offset++];
  4817. if (nextByte) {
  4818. throw 'unexpected marker: ' +
  4819. ((bitsData << 8) | nextByte).toString(16);
  4820. }
  4821. // unstuff 0
  4822. }
  4823. bitsCount = 7;
  4824. return bitsData >>> 7;
  4825. }
  4826. function decodeHuffman(tree) {
  4827. var node = tree;
  4828. while (true) {
  4829. node = node[readBit()];
  4830. if (typeof node === 'number') {
  4831. return node;
  4832. }
  4833. if (typeof node !== 'object') {
  4834. throw 'invalid huffman sequence';
  4835. }
  4836. }
  4837. }
  4838. function receive(length) {
  4839. var n = 0;
  4840. while (length > 0) {
  4841. n = (n << 1) | readBit();
  4842. length--;
  4843. }
  4844. return n;
  4845. }
  4846. function receiveAndExtend(length) {
  4847. if (length === 1) {
  4848. return readBit() === 1 ? 1 : -1;
  4849. }
  4850. var n = receive(length);
  4851. if (n >= 1 << (length - 1)) {
  4852. return n;
  4853. }
  4854. return n + (-1 << length) + 1;
  4855. }
  4856. function decodeBaseline(component, offset) {
  4857. var t = decodeHuffman(component.huffmanTableDC);
  4858. var diff = t === 0 ? 0 : receiveAndExtend(t);
  4859. component.blockData[offset] = (component.pred += diff);
  4860. var k = 1;
  4861. while (k < 64) {
  4862. var rs = decodeHuffman(component.huffmanTableAC);
  4863. var s = rs & 15, r = rs >> 4;
  4864. if (s === 0) {
  4865. if (r < 15) {
  4866. break;
  4867. }
  4868. k += 16;
  4869. continue;
  4870. }
  4871. k += r;
  4872. var z = dctZigZag[k];
  4873. component.blockData[offset + z] = receiveAndExtend(s);
  4874. k++;
  4875. }
  4876. }
  4877. function decodeDCFirst(component, offset) {
  4878. var t = decodeHuffman(component.huffmanTableDC);
  4879. var diff = t === 0 ? 0 : (receiveAndExtend(t) << successive);
  4880. component.blockData[offset] = (component.pred += diff);
  4881. }
  4882. function decodeDCSuccessive(component, offset) {
  4883. component.blockData[offset] |= readBit() << successive;
  4884. }
  4885. var eobrun = 0;
  4886. function decodeACFirst(component, offset) {
  4887. if (eobrun > 0) {
  4888. eobrun--;
  4889. return;
  4890. }
  4891. var k = spectralStart, e = spectralEnd;
  4892. while (k <= e) {
  4893. var rs = decodeHuffman(component.huffmanTableAC);
  4894. var s = rs & 15, r = rs >> 4;
  4895. if (s === 0) {
  4896. if (r < 15) {
  4897. eobrun = receive(r) + (1 << r) - 1;
  4898. break;
  4899. }
  4900. k += 16;
  4901. continue;
  4902. }
  4903. k += r;
  4904. var z = dctZigZag[k];
  4905. component.blockData[offset + z] =
  4906. receiveAndExtend(s) * (1 << successive);
  4907. k++;
  4908. }
  4909. }
  4910. var successiveACState = 0, successiveACNextValue;
  4911. function decodeACSuccessive(component, offset) {
  4912. var k = spectralStart;
  4913. var e = spectralEnd;
  4914. var r = 0;
  4915. var s;
  4916. var rs;
  4917. while (k <= e) {
  4918. var z = dctZigZag[k];
  4919. switch (successiveACState) {
  4920. case 0: // initial state
  4921. rs = decodeHuffman(component.huffmanTableAC);
  4922. s = rs & 15;
  4923. r = rs >> 4;
  4924. if (s === 0) {
  4925. if (r < 15) {
  4926. eobrun = receive(r) + (1 << r);
  4927. successiveACState = 4;
  4928. } else {
  4929. r = 16;
  4930. successiveACState = 1;
  4931. }
  4932. } else {
  4933. if (s !== 1) {
  4934. throw 'invalid ACn encoding';
  4935. }
  4936. successiveACNextValue = receiveAndExtend(s);
  4937. successiveACState = r ? 2 : 3;
  4938. }
  4939. continue;
  4940. case 1: // skipping r zero items
  4941. case 2:
  4942. if (component.blockData[offset + z]) {
  4943. component.blockData[offset + z] += (readBit() << successive);
  4944. } else {
  4945. r--;
  4946. if (r === 0) {
  4947. successiveACState = successiveACState === 2 ? 3 : 0;
  4948. }
  4949. }
  4950. break;
  4951. case 3: // set value for a zero item
  4952. if (component.blockData[offset + z]) {
  4953. component.blockData[offset + z] += (readBit() << successive);
  4954. } else {
  4955. component.blockData[offset + z] =
  4956. successiveACNextValue << successive;
  4957. successiveACState = 0;
  4958. }
  4959. break;
  4960. case 4: // eob
  4961. if (component.blockData[offset + z]) {
  4962. component.blockData[offset + z] += (readBit() << successive);
  4963. }
  4964. break;
  4965. }
  4966. k++;
  4967. }
  4968. if (successiveACState === 4) {
  4969. eobrun--;
  4970. if (eobrun === 0) {
  4971. successiveACState = 0;
  4972. }
  4973. }
  4974. }
  4975. function decodeMcu(component, decode, mcu, row, col) {
  4976. var mcuRow = (mcu / mcusPerLine) | 0;
  4977. var mcuCol = mcu % mcusPerLine;
  4978. var blockRow = mcuRow * component.v + row;
  4979. var blockCol = mcuCol * component.h + col;
  4980. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  4981. decode(component, offset);
  4982. }
  4983. function decodeBlock(component, decode, mcu) {
  4984. var blockRow = (mcu / component.blocksPerLine) | 0;
  4985. var blockCol = mcu % component.blocksPerLine;
  4986. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  4987. decode(component, offset);
  4988. }
  4989. var componentsLength = components.length;
  4990. var component, i, j, k, n;
  4991. var decodeFn;
  4992. if (progressive) {
  4993. if (spectralStart === 0) {
  4994. decodeFn = successivePrev === 0 ? decodeDCFirst : decodeDCSuccessive;
  4995. } else {
  4996. decodeFn = successivePrev === 0 ? decodeACFirst : decodeACSuccessive;
  4997. }
  4998. } else {
  4999. decodeFn = decodeBaseline;
  5000. }
  5001. var mcu = 0, marker;
  5002. var mcuExpected;
  5003. if (componentsLength === 1) {
  5004. mcuExpected = components[0].blocksPerLine * components[0].blocksPerColumn;
  5005. } else {
  5006. mcuExpected = mcusPerLine * frame.mcusPerColumn;
  5007. }
  5008. if (!resetInterval) {
  5009. resetInterval = mcuExpected;
  5010. }
  5011. var h, v;
  5012. while (mcu < mcuExpected) {
  5013. // reset interval stuff
  5014. for (i = 0; i < componentsLength; i++) {
  5015. components[i].pred = 0;
  5016. }
  5017. eobrun = 0;
  5018. if (componentsLength === 1) {
  5019. component = components[0];
  5020. for (n = 0; n < resetInterval; n++) {
  5021. decodeBlock(component, decodeFn, mcu);
  5022. mcu++;
  5023. }
  5024. } else {
  5025. for (n = 0; n < resetInterval; n++) {
  5026. for (i = 0; i < componentsLength; i++) {
  5027. component = components[i];
  5028. h = component.h;
  5029. v = component.v;
  5030. for (j = 0; j < v; j++) {
  5031. for (k = 0; k < h; k++) {
  5032. decodeMcu(component, decodeFn, mcu, j, k);
  5033. }
  5034. }
  5035. }
  5036. mcu++;
  5037. }
  5038. }
  5039. // find marker
  5040. bitsCount = 0;
  5041. marker = (data[offset] << 8) | data[offset + 1];
  5042. if (marker <= 0xFF00) {
  5043. throw 'marker was not found';
  5044. }
  5045. if (marker >= 0xFFD0 && marker <= 0xFFD7) { // RSTx
  5046. offset += 2;
  5047. } else {
  5048. break;
  5049. }
  5050. }
  5051. return offset - startOffset;
  5052. }
  5053. // A port of poppler's IDCT method which in turn is taken from:
  5054. // Christoph Loeffler, Adriaan Ligtenberg, George S. Moschytz,
  5055. // 'Practical Fast 1-D DCT Algorithms with 11 Multiplications',
  5056. // IEEE Intl. Conf. on Acoustics, Speech & Signal Processing, 1989,
  5057. // 988-991.
  5058. function quantizeAndInverse(component, blockBufferOffset, p) {
  5059. var qt = component.quantizationTable, blockData = component.blockData;
  5060. var v0, v1, v2, v3, v4, v5, v6, v7;
  5061. var p0, p1, p2, p3, p4, p5, p6, p7;
  5062. var t;
  5063. // inverse DCT on rows
  5064. for (var row = 0; row < 64; row += 8) {
  5065. // gather block data
  5066. p0 = blockData[blockBufferOffset + row];
  5067. p1 = blockData[blockBufferOffset + row + 1];
  5068. p2 = blockData[blockBufferOffset + row + 2];
  5069. p3 = blockData[blockBufferOffset + row + 3];
  5070. p4 = blockData[blockBufferOffset + row + 4];
  5071. p5 = blockData[blockBufferOffset + row + 5];
  5072. p6 = blockData[blockBufferOffset + row + 6];
  5073. p7 = blockData[blockBufferOffset + row + 7];
  5074. // dequant p0
  5075. p0 *= qt[row];
  5076. // check for all-zero AC coefficients
  5077. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  5078. t = (dctSqrt2 * p0 + 512) >> 10;
  5079. p[row] = t;
  5080. p[row + 1] = t;
  5081. p[row + 2] = t;
  5082. p[row + 3] = t;
  5083. p[row + 4] = t;
  5084. p[row + 5] = t;
  5085. p[row + 6] = t;
  5086. p[row + 7] = t;
  5087. continue;
  5088. }
  5089. // dequant p1 ... p7
  5090. p1 *= qt[row + 1];
  5091. p2 *= qt[row + 2];
  5092. p3 *= qt[row + 3];
  5093. p4 *= qt[row + 4];
  5094. p5 *= qt[row + 5];
  5095. p6 *= qt[row + 6];
  5096. p7 *= qt[row + 7];
  5097. // stage 4
  5098. v0 = (dctSqrt2 * p0 + 128) >> 8;
  5099. v1 = (dctSqrt2 * p4 + 128) >> 8;
  5100. v2 = p2;
  5101. v3 = p6;
  5102. v4 = (dctSqrt1d2 * (p1 - p7) + 128) >> 8;
  5103. v7 = (dctSqrt1d2 * (p1 + p7) + 128) >> 8;
  5104. v5 = p3 << 4;
  5105. v6 = p5 << 4;
  5106. // stage 3
  5107. v0 = (v0 + v1 + 1) >> 1;
  5108. v1 = v0 - v1;
  5109. t = (v2 * dctSin6 + v3 * dctCos6 + 128) >> 8;
  5110. v2 = (v2 * dctCos6 - v3 * dctSin6 + 128) >> 8;
  5111. v3 = t;
  5112. v4 = (v4 + v6 + 1) >> 1;
  5113. v6 = v4 - v6;
  5114. v7 = (v7 + v5 + 1) >> 1;
  5115. v5 = v7 - v5;
  5116. // stage 2
  5117. v0 = (v0 + v3 + 1) >> 1;
  5118. v3 = v0 - v3;
  5119. v1 = (v1 + v2 + 1) >> 1;
  5120. v2 = v1 - v2;
  5121. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  5122. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  5123. v7 = t;
  5124. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  5125. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  5126. v6 = t;
  5127. // stage 1
  5128. p[row] = v0 + v7;
  5129. p[row + 7] = v0 - v7;
  5130. p[row + 1] = v1 + v6;
  5131. p[row + 6] = v1 - v6;
  5132. p[row + 2] = v2 + v5;
  5133. p[row + 5] = v2 - v5;
  5134. p[row + 3] = v3 + v4;
  5135. p[row + 4] = v3 - v4;
  5136. }
  5137. // inverse DCT on columns
  5138. for (var col = 0; col < 8; ++col) {
  5139. p0 = p[col];
  5140. p1 = p[col + 8];
  5141. p2 = p[col + 16];
  5142. p3 = p[col + 24];
  5143. p4 = p[col + 32];
  5144. p5 = p[col + 40];
  5145. p6 = p[col + 48];
  5146. p7 = p[col + 56];
  5147. // check for all-zero AC coefficients
  5148. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  5149. t = (dctSqrt2 * p0 + 8192) >> 14;
  5150. // convert to 8 bit
  5151. t = (t < -2040) ? 0 : (t >= 2024) ? 255 : (t + 2056) >> 4;
  5152. blockData[blockBufferOffset + col] = t;
  5153. blockData[blockBufferOffset + col + 8] = t;
  5154. blockData[blockBufferOffset + col + 16] = t;
  5155. blockData[blockBufferOffset + col + 24] = t;
  5156. blockData[blockBufferOffset + col + 32] = t;
  5157. blockData[blockBufferOffset + col + 40] = t;
  5158. blockData[blockBufferOffset + col + 48] = t;
  5159. blockData[blockBufferOffset + col + 56] = t;
  5160. continue;
  5161. }
  5162. // stage 4
  5163. v0 = (dctSqrt2 * p0 + 2048) >> 12;
  5164. v1 = (dctSqrt2 * p4 + 2048) >> 12;
  5165. v2 = p2;
  5166. v3 = p6;
  5167. v4 = (dctSqrt1d2 * (p1 - p7) + 2048) >> 12;
  5168. v7 = (dctSqrt1d2 * (p1 + p7) + 2048) >> 12;
  5169. v5 = p3;
  5170. v6 = p5;
  5171. // stage 3
  5172. // Shift v0 by 128.5 << 5 here, so we don't need to shift p0...p7 when
  5173. // converting to UInt8 range later.
  5174. v0 = ((v0 + v1 + 1) >> 1) + 4112;
  5175. v1 = v0 - v1;
  5176. t = (v2 * dctSin6 + v3 * dctCos6 + 2048) >> 12;
  5177. v2 = (v2 * dctCos6 - v3 * dctSin6 + 2048) >> 12;
  5178. v3 = t;
  5179. v4 = (v4 + v6 + 1) >> 1;
  5180. v6 = v4 - v6;
  5181. v7 = (v7 + v5 + 1) >> 1;
  5182. v5 = v7 - v5;
  5183. // stage 2
  5184. v0 = (v0 + v3 + 1) >> 1;
  5185. v3 = v0 - v3;
  5186. v1 = (v1 + v2 + 1) >> 1;
  5187. v2 = v1 - v2;
  5188. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  5189. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  5190. v7 = t;
  5191. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  5192. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  5193. v6 = t;
  5194. // stage 1
  5195. p0 = v0 + v7;
  5196. p7 = v0 - v7;
  5197. p1 = v1 + v6;
  5198. p6 = v1 - v6;
  5199. p2 = v2 + v5;
  5200. p5 = v2 - v5;
  5201. p3 = v3 + v4;
  5202. p4 = v3 - v4;
  5203. // convert to 8-bit integers
  5204. p0 = (p0 < 16) ? 0 : (p0 >= 4080) ? 255 : p0 >> 4;
  5205. p1 = (p1 < 16) ? 0 : (p1 >= 4080) ? 255 : p1 >> 4;
  5206. p2 = (p2 < 16) ? 0 : (p2 >= 4080) ? 255 : p2 >> 4;
  5207. p3 = (p3 < 16) ? 0 : (p3 >= 4080) ? 255 : p3 >> 4;
  5208. p4 = (p4 < 16) ? 0 : (p4 >= 4080) ? 255 : p4 >> 4;
  5209. p5 = (p5 < 16) ? 0 : (p5 >= 4080) ? 255 : p5 >> 4;
  5210. p6 = (p6 < 16) ? 0 : (p6 >= 4080) ? 255 : p6 >> 4;
  5211. p7 = (p7 < 16) ? 0 : (p7 >= 4080) ? 255 : p7 >> 4;
  5212. // store block data
  5213. blockData[blockBufferOffset + col] = p0;
  5214. blockData[blockBufferOffset + col + 8] = p1;
  5215. blockData[blockBufferOffset + col + 16] = p2;
  5216. blockData[blockBufferOffset + col + 24] = p3;
  5217. blockData[blockBufferOffset + col + 32] = p4;
  5218. blockData[blockBufferOffset + col + 40] = p5;
  5219. blockData[blockBufferOffset + col + 48] = p6;
  5220. blockData[blockBufferOffset + col + 56] = p7;
  5221. }
  5222. }
  5223. function buildComponentData(frame, component) {
  5224. var blocksPerLine = component.blocksPerLine;
  5225. var blocksPerColumn = component.blocksPerColumn;
  5226. var computationBuffer = new Int16Array(64);
  5227. for (var blockRow = 0; blockRow < blocksPerColumn; blockRow++) {
  5228. for (var blockCol = 0; blockCol < blocksPerLine; blockCol++) {
  5229. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  5230. quantizeAndInverse(component, offset, computationBuffer);
  5231. }
  5232. }
  5233. return component.blockData;
  5234. }
  5235. function clamp0to255(a) {
  5236. return a <= 0 ? 0 : a >= 255 ? 255 : a;
  5237. }
  5238. constructor.prototype = {
  5239. parse: function parse(data) {
  5240. function readUint16() {
  5241. var value = (data[offset] << 8) | data[offset + 1];
  5242. offset += 2;
  5243. return value;
  5244. }
  5245. function readDataBlock() {
  5246. var length = readUint16();
  5247. var array = data.subarray(offset, offset + length - 2);
  5248. offset += array.length;
  5249. return array;
  5250. }
  5251. function prepareComponents(frame) {
  5252. var mcusPerLine = Math.ceil(frame.samplesPerLine / 8 / frame.maxH);
  5253. var mcusPerColumn = Math.ceil(frame.scanLines / 8 / frame.maxV);
  5254. for (var i = 0; i < frame.components.length; i++) {
  5255. component = frame.components[i];
  5256. var blocksPerLine = Math.ceil(Math.ceil(frame.samplesPerLine / 8) *
  5257. component.h / frame.maxH);
  5258. var blocksPerColumn = Math.ceil(Math.ceil(frame.scanLines / 8) *
  5259. component.v / frame.maxV);
  5260. var blocksPerLineForMcu = mcusPerLine * component.h;
  5261. var blocksPerColumnForMcu = mcusPerColumn * component.v;
  5262. var blocksBufferSize = 64 * blocksPerColumnForMcu *
  5263. (blocksPerLineForMcu + 1);
  5264. component.blockData = new Int16Array(blocksBufferSize);
  5265. component.blocksPerLine = blocksPerLine;
  5266. component.blocksPerColumn = blocksPerColumn;
  5267. }
  5268. frame.mcusPerLine = mcusPerLine;
  5269. frame.mcusPerColumn = mcusPerColumn;
  5270. }
  5271. var offset = 0;
  5272. var jfif = null;
  5273. var adobe = null;
  5274. var frame, resetInterval;
  5275. var quantizationTables = [];
  5276. var huffmanTablesAC = [], huffmanTablesDC = [];
  5277. var fileMarker = readUint16();
  5278. if (fileMarker !== 0xFFD8) { // SOI (Start of Image)
  5279. throw 'SOI not found';
  5280. }
  5281. fileMarker = readUint16();
  5282. while (fileMarker !== 0xFFD9) { // EOI (End of image)
  5283. var i, j, l;
  5284. switch(fileMarker) {
  5285. case 0xFFE0: // APP0 (Application Specific)
  5286. case 0xFFE1: // APP1
  5287. case 0xFFE2: // APP2
  5288. case 0xFFE3: // APP3
  5289. case 0xFFE4: // APP4
  5290. case 0xFFE5: // APP5
  5291. case 0xFFE6: // APP6
  5292. case 0xFFE7: // APP7
  5293. case 0xFFE8: // APP8
  5294. case 0xFFE9: // APP9
  5295. case 0xFFEA: // APP10
  5296. case 0xFFEB: // APP11
  5297. case 0xFFEC: // APP12
  5298. case 0xFFED: // APP13
  5299. case 0xFFEE: // APP14
  5300. case 0xFFEF: // APP15
  5301. case 0xFFFE: // COM (Comment)
  5302. var appData = readDataBlock();
  5303. if (fileMarker === 0xFFE0) {
  5304. if (appData[0] === 0x4A && appData[1] === 0x46 &&
  5305. appData[2] === 0x49 && appData[3] === 0x46 &&
  5306. appData[4] === 0) { // 'JFIF\x00'
  5307. jfif = {
  5308. version: { major: appData[5], minor: appData[6] },
  5309. densityUnits: appData[7],
  5310. xDensity: (appData[8] << 8) | appData[9],
  5311. yDensity: (appData[10] << 8) | appData[11],
  5312. thumbWidth: appData[12],
  5313. thumbHeight: appData[13],
  5314. thumbData: appData.subarray(14, 14 +
  5315. 3 * appData[12] * appData[13])
  5316. };
  5317. }
  5318. }
  5319. // TODO APP1 - Exif
  5320. if (fileMarker === 0xFFEE) {
  5321. if (appData[0] === 0x41 && appData[1] === 0x64 &&
  5322. appData[2] === 0x6F && appData[3] === 0x62 &&
  5323. appData[4] === 0x65) { // 'Adobe'
  5324. adobe = {
  5325. version: (appData[5] << 8) | appData[6],
  5326. flags0: (appData[7] << 8) | appData[8],
  5327. flags1: (appData[9] << 8) | appData[10],
  5328. transformCode: appData[11]
  5329. };
  5330. }
  5331. }
  5332. break;
  5333. case 0xFFDB: // DQT (Define Quantization Tables)
  5334. var quantizationTablesLength = readUint16();
  5335. var quantizationTablesEnd = quantizationTablesLength + offset - 2;
  5336. var z;
  5337. while (offset < quantizationTablesEnd) {
  5338. var quantizationTableSpec = data[offset++];
  5339. var tableData = new Uint16Array(64);
  5340. if ((quantizationTableSpec >> 4) === 0) { // 8 bit values
  5341. for (j = 0; j < 64; j++) {
  5342. z = dctZigZag[j];
  5343. tableData[z] = data[offset++];
  5344. }
  5345. } else if ((quantizationTableSpec >> 4) === 1) { //16 bit
  5346. for (j = 0; j < 64; j++) {
  5347. z = dctZigZag[j];
  5348. tableData[z] = readUint16();
  5349. }
  5350. } else {
  5351. throw 'DQT: invalid table spec';
  5352. }
  5353. quantizationTables[quantizationTableSpec & 15] = tableData;
  5354. }
  5355. break;
  5356. case 0xFFC0: // SOF0 (Start of Frame, Baseline DCT)
  5357. case 0xFFC1: // SOF1 (Start of Frame, Extended DCT)
  5358. case 0xFFC2: // SOF2 (Start of Frame, Progressive DCT)
  5359. if (frame) {
  5360. throw 'Only single frame JPEGs supported';
  5361. }
  5362. readUint16(); // skip data length
  5363. frame = {};
  5364. frame.extended = (fileMarker === 0xFFC1);
  5365. frame.progressive = (fileMarker === 0xFFC2);
  5366. frame.precision = data[offset++];
  5367. frame.scanLines = readUint16();
  5368. frame.samplesPerLine = readUint16();
  5369. frame.components = [];
  5370. frame.componentIds = {};
  5371. var componentsCount = data[offset++], componentId;
  5372. var maxH = 0, maxV = 0;
  5373. for (i = 0; i < componentsCount; i++) {
  5374. componentId = data[offset];
  5375. var h = data[offset + 1] >> 4;
  5376. var v = data[offset + 1] & 15;
  5377. if (maxH < h) {
  5378. maxH = h;
  5379. }
  5380. if (maxV < v) {
  5381. maxV = v;
  5382. }
  5383. var qId = data[offset + 2];
  5384. l = frame.components.push({
  5385. h: h,
  5386. v: v,
  5387. quantizationTable: quantizationTables[qId]
  5388. });
  5389. frame.componentIds[componentId] = l - 1;
  5390. offset += 3;
  5391. }
  5392. frame.maxH = maxH;
  5393. frame.maxV = maxV;
  5394. prepareComponents(frame);
  5395. break;
  5396. case 0xFFC4: // DHT (Define Huffman Tables)
  5397. var huffmanLength = readUint16();
  5398. for (i = 2; i < huffmanLength;) {
  5399. var huffmanTableSpec = data[offset++];
  5400. var codeLengths = new Uint8Array(16);
  5401. var codeLengthSum = 0;
  5402. for (j = 0; j < 16; j++, offset++) {
  5403. codeLengthSum += (codeLengths[j] = data[offset]);
  5404. }
  5405. var huffmanValues = new Uint8Array(codeLengthSum);
  5406. for (j = 0; j < codeLengthSum; j++, offset++) {
  5407. huffmanValues[j] = data[offset];
  5408. }
  5409. i += 17 + codeLengthSum;
  5410. ((huffmanTableSpec >> 4) === 0 ?
  5411. huffmanTablesDC : huffmanTablesAC)[huffmanTableSpec & 15] =
  5412. buildHuffmanTable(codeLengths, huffmanValues);
  5413. }
  5414. break;
  5415. case 0xFFDD: // DRI (Define Restart Interval)
  5416. readUint16(); // skip data length
  5417. resetInterval = readUint16();
  5418. break;
  5419. case 0xFFDA: // SOS (Start of Scan)
  5420. var scanLength = readUint16();
  5421. var selectorsCount = data[offset++];
  5422. var components = [], component;
  5423. for (i = 0; i < selectorsCount; i++) {
  5424. var componentIndex = frame.componentIds[data[offset++]];
  5425. component = frame.components[componentIndex];
  5426. var tableSpec = data[offset++];
  5427. component.huffmanTableDC = huffmanTablesDC[tableSpec >> 4];
  5428. component.huffmanTableAC = huffmanTablesAC[tableSpec & 15];
  5429. components.push(component);
  5430. }
  5431. var spectralStart = data[offset++];
  5432. var spectralEnd = data[offset++];
  5433. var successiveApproximation = data[offset++];
  5434. var processed = decodeScan(data, offset,
  5435. frame, components, resetInterval,
  5436. spectralStart, spectralEnd,
  5437. successiveApproximation >> 4, successiveApproximation & 15);
  5438. offset += processed;
  5439. break;
  5440. case 0xFFFF: // Fill bytes
  5441. if (data[offset] !== 0xFF) { // Avoid skipping a valid marker.
  5442. offset--;
  5443. }
  5444. break;
  5445. default:
  5446. if (data[offset - 3] === 0xFF &&
  5447. data[offset - 2] >= 0xC0 && data[offset - 2] <= 0xFE) {
  5448. // could be incorrect encoding -- last 0xFF byte of the previous
  5449. // block was eaten by the encoder
  5450. offset -= 3;
  5451. break;
  5452. }
  5453. throw 'unknown JPEG marker ' + fileMarker.toString(16);
  5454. }
  5455. fileMarker = readUint16();
  5456. }
  5457. this.width = frame.samplesPerLine;
  5458. this.height = frame.scanLines;
  5459. this.jfif = jfif;
  5460. this.adobe = adobe;
  5461. this.components = [];
  5462. for (i = 0; i < frame.components.length; i++) {
  5463. component = frame.components[i];
  5464. this.components.push({
  5465. output: buildComponentData(frame, component),
  5466. scaleX: component.h / frame.maxH,
  5467. scaleY: component.v / frame.maxV,
  5468. blocksPerLine: component.blocksPerLine,
  5469. blocksPerColumn: component.blocksPerColumn
  5470. });
  5471. }
  5472. this.numComponents = this.components.length;
  5473. },
  5474. _getLinearizedBlockData: function getLinearizedBlockData(width, height) {
  5475. var scaleX = this.width / width, scaleY = this.height / height;
  5476. var component, componentScaleX, componentScaleY, blocksPerScanline;
  5477. var x, y, i, j, k;
  5478. var index;
  5479. var offset = 0;
  5480. var output;
  5481. var numComponents = this.components.length;
  5482. var dataLength = width * height * numComponents;
  5483. var data = new Uint8Array(dataLength);
  5484. var xScaleBlockOffset = new Uint32Array(width);
  5485. var mask3LSB = 0xfffffff8; // used to clear the 3 LSBs
  5486. for (i = 0; i < numComponents; i++) {
  5487. component = this.components[i];
  5488. componentScaleX = component.scaleX * scaleX;
  5489. componentScaleY = component.scaleY * scaleY;
  5490. offset = i;
  5491. output = component.output;
  5492. blocksPerScanline = (component.blocksPerLine + 1) << 3;
  5493. // precalculate the xScaleBlockOffset
  5494. for (x = 0; x < width; x++) {
  5495. j = 0 | (x * componentScaleX);
  5496. xScaleBlockOffset[x] = ((j & mask3LSB) << 3) | (j & 7);
  5497. }
  5498. // linearize the blocks of the component
  5499. for (y = 0; y < height; y++) {
  5500. j = 0 | (y * componentScaleY);
  5501. index = blocksPerScanline * (j & mask3LSB) | ((j & 7) << 3);
  5502. for (x = 0; x < width; x++) {
  5503. data[offset] = output[index + xScaleBlockOffset[x]];
  5504. offset += numComponents;
  5505. }
  5506. }
  5507. }
  5508. // decodeTransform contains pairs of multiplier (-256..256) and additive
  5509. var transform = this.decodeTransform;
  5510. if (transform) {
  5511. for (i = 0; i < dataLength;) {
  5512. for (j = 0, k = 0; j < numComponents; j++, i++, k += 2) {
  5513. data[i] = ((data[i] * transform[k]) >> 8) + transform[k + 1];
  5514. }
  5515. }
  5516. }
  5517. return data;
  5518. },
  5519. _isColorConversionNeeded: function isColorConversionNeeded() {
  5520. if (this.adobe && this.adobe.transformCode) {
  5521. // The adobe transform marker overrides any previous setting
  5522. return true;
  5523. } else if (this.numComponents === 3) {
  5524. return true;
  5525. } else {
  5526. return false;
  5527. }
  5528. },
  5529. _convertYccToRgb: function convertYccToRgb(data) {
  5530. var Y, Cb, Cr;
  5531. for (var i = 0, length = data.length; i < length; i += 3) {
  5532. Y = data[i ];
  5533. Cb = data[i + 1];
  5534. Cr = data[i + 2];
  5535. data[i ] = clamp0to255(Y - 179.456 + 1.402 * Cr);
  5536. data[i + 1] = clamp0to255(Y + 135.459 - 0.344 * Cb - 0.714 * Cr);
  5537. data[i + 2] = clamp0to255(Y - 226.816 + 1.772 * Cb);
  5538. }
  5539. return data;
  5540. },
  5541. _convertYcckToRgb: function convertYcckToRgb(data) {
  5542. var Y, Cb, Cr, k;
  5543. var offset = 0;
  5544. for (var i = 0, length = data.length; i < length; i += 4) {
  5545. Y = data[i];
  5546. Cb = data[i + 1];
  5547. Cr = data[i + 2];
  5548. k = data[i + 3];
  5549. var r = -122.67195406894 +
  5550. Cb * (-6.60635669420364e-5 * Cb + 0.000437130475926232 * Cr -
  5551. 5.4080610064599e-5 * Y + 0.00048449797120281 * k -
  5552. 0.154362151871126) +
  5553. Cr * (-0.000957964378445773 * Cr + 0.000817076911346625 * Y -
  5554. 0.00477271405408747 * k + 1.53380253221734) +
  5555. Y * (0.000961250184130688 * Y - 0.00266257332283933 * k +
  5556. 0.48357088451265) +
  5557. k * (-0.000336197177618394 * k + 0.484791561490776);
  5558. var g = 107.268039397724 +
  5559. Cb * (2.19927104525741e-5 * Cb - 0.000640992018297945 * Cr +
  5560. 0.000659397001245577 * Y + 0.000426105652938837 * k -
  5561. 0.176491792462875) +
  5562. Cr * (-0.000778269941513683 * Cr + 0.00130872261408275 * Y +
  5563. 0.000770482631801132 * k - 0.151051492775562) +
  5564. Y * (0.00126935368114843 * Y - 0.00265090189010898 * k +
  5565. 0.25802910206845) +
  5566. k * (-0.000318913117588328 * k - 0.213742400323665);
  5567. var b = -20.810012546947 +
  5568. Cb * (-0.000570115196973677 * Cb - 2.63409051004589e-5 * Cr +
  5569. 0.0020741088115012 * Y - 0.00288260236853442 * k +
  5570. 0.814272968359295) +
  5571. Cr * (-1.53496057440975e-5 * Cr - 0.000132689043961446 * Y +
  5572. 0.000560833691242812 * k - 0.195152027534049) +
  5573. Y * (0.00174418132927582 * Y - 0.00255243321439347 * k +
  5574. 0.116935020465145) +
  5575. k * (-0.000343531996510555 * k + 0.24165260232407);
  5576. data[offset++] = clamp0to255(r);
  5577. data[offset++] = clamp0to255(g);
  5578. data[offset++] = clamp0to255(b);
  5579. }
  5580. return data;
  5581. },
  5582. _convertYcckToCmyk: function convertYcckToCmyk(data) {
  5583. var Y, Cb, Cr;
  5584. for (var i = 0, length = data.length; i < length; i += 4) {
  5585. Y = data[i];
  5586. Cb = data[i + 1];
  5587. Cr = data[i + 2];
  5588. data[i ] = clamp0to255(434.456 - Y - 1.402 * Cr);
  5589. data[i + 1] = clamp0to255(119.541 - Y + 0.344 * Cb + 0.714 * Cr);
  5590. data[i + 2] = clamp0to255(481.816 - Y - 1.772 * Cb);
  5591. // K in data[i + 3] is unchanged
  5592. }
  5593. return data;
  5594. },
  5595. _convertCmykToRgb: function convertCmykToRgb(data) {
  5596. var c, m, y, k;
  5597. var offset = 0;
  5598. var min = -255 * 255 * 255;
  5599. var scale = 1 / 255 / 255;
  5600. for (var i = 0, length = data.length; i < length; i += 4) {
  5601. c = data[i];
  5602. m = data[i + 1];
  5603. y = data[i + 2];
  5604. k = data[i + 3];
  5605. var r =
  5606. c * (-4.387332384609988 * c + 54.48615194189176 * m +
  5607. 18.82290502165302 * y + 212.25662451639585 * k -
  5608. 72734.4411664936) +
  5609. m * (1.7149763477362134 * m - 5.6096736904047315 * y -
  5610. 17.873870861415444 * k - 1401.7366389350734) +
  5611. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  5612. 4465.541406466231) -
  5613. k * (21.86122147463605 * k + 48317.86113160301);
  5614. var g =
  5615. c * (8.841041422036149 * c + 60.118027045597366 * m +
  5616. 6.871425592049007 * y + 31.159100130055922 * k -
  5617. 20220.756542821975) +
  5618. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  5619. 131.35250912493976 * k - 48691.05921601825) +
  5620. y * (4.444339102852739 * y + 9.8632861493405 * k -
  5621. 6341.191035517494) -
  5622. k * (20.737325471181034 * k + 47890.15695978492);
  5623. var b =
  5624. c * (0.8842522430003296 * c + 8.078677503112928 * m +
  5625. 30.89978309703729 * y - 0.23883238689178934 * k -
  5626. 3616.812083916688) +
  5627. m * (10.49593273432072 * m + 63.02378494754052 * y +
  5628. 50.606957656360734 * k - 28620.90484698408) +
  5629. y * (0.03296041114873217 * y + 115.60384449646641 * k -
  5630. 49363.43385999684) -
  5631. k * (22.33816807309886 * k + 45932.16563550634);
  5632. data[offset++] = r >= 0 ? 255 : r <= min ? 0 : 255 + r * scale | 0;
  5633. data[offset++] = g >= 0 ? 255 : g <= min ? 0 : 255 + g * scale | 0;
  5634. data[offset++] = b >= 0 ? 255 : b <= min ? 0 : 255 + b * scale | 0;
  5635. }
  5636. return data;
  5637. },
  5638. getData: function getData(width, height, forceRGBoutput) {
  5639. if (this.numComponents > 4) {
  5640. throw 'Unsupported color mode';
  5641. }
  5642. // type of data: Uint8Array(width * height * numComponents)
  5643. var data = this._getLinearizedBlockData(width, height);
  5644. if (this.numComponents === 3) {
  5645. return this._convertYccToRgb(data);
  5646. } else if (this.numComponents === 4) {
  5647. if (this._isColorConversionNeeded()) {
  5648. if (forceRGBoutput) {
  5649. return this._convertYcckToRgb(data);
  5650. } else {
  5651. return this._convertYcckToCmyk(data);
  5652. }
  5653. } else if (forceRGBoutput) {
  5654. return this._convertCmykToRgb(data);
  5655. }
  5656. }
  5657. return data;
  5658. }
  5659. };
  5660. return constructor;
  5661. })();
  5662. exports.JpegImage = JpegImage;
  5663. }));
  5664. (function (root, factory) {
  5665. {
  5666. factory((root.pdfjsCoreMetrics = {}));
  5667. }
  5668. }(this, function (exports) {
  5669. // The Metrics object contains glyph widths (in glyph space units).
  5670. // As per PDF spec, for most fonts (Type 3 being an exception) a glyph
  5671. // space unit corresponds to 1/1000th of text space unit.
  5672. var Metrics = {
  5673. 'Courier': 600,
  5674. 'Courier-Bold': 600,
  5675. 'Courier-BoldOblique': 600,
  5676. 'Courier-Oblique': 600,
  5677. 'Helvetica' : {
  5678. 'space': 278,
  5679. 'exclam': 278,
  5680. 'quotedbl': 355,
  5681. 'numbersign': 556,
  5682. 'dollar': 556,
  5683. 'percent': 889,
  5684. 'ampersand': 667,
  5685. 'quoteright': 222,
  5686. 'parenleft': 333,
  5687. 'parenright': 333,
  5688. 'asterisk': 389,
  5689. 'plus': 584,
  5690. 'comma': 278,
  5691. 'hyphen': 333,
  5692. 'period': 278,
  5693. 'slash': 278,
  5694. 'zero': 556,
  5695. 'one': 556,
  5696. 'two': 556,
  5697. 'three': 556,
  5698. 'four': 556,
  5699. 'five': 556,
  5700. 'six': 556,
  5701. 'seven': 556,
  5702. 'eight': 556,
  5703. 'nine': 556,
  5704. 'colon': 278,
  5705. 'semicolon': 278,
  5706. 'less': 584,
  5707. 'equal': 584,
  5708. 'greater': 584,
  5709. 'question': 556,
  5710. 'at': 1015,
  5711. 'A': 667,
  5712. 'B': 667,
  5713. 'C': 722,
  5714. 'D': 722,
  5715. 'E': 667,
  5716. 'F': 611,
  5717. 'G': 778,
  5718. 'H': 722,
  5719. 'I': 278,
  5720. 'J': 500,
  5721. 'K': 667,
  5722. 'L': 556,
  5723. 'M': 833,
  5724. 'N': 722,
  5725. 'O': 778,
  5726. 'P': 667,
  5727. 'Q': 778,
  5728. 'R': 722,
  5729. 'S': 667,
  5730. 'T': 611,
  5731. 'U': 722,
  5732. 'V': 667,
  5733. 'W': 944,
  5734. 'X': 667,
  5735. 'Y': 667,
  5736. 'Z': 611,
  5737. 'bracketleft': 278,
  5738. 'backslash': 278,
  5739. 'bracketright': 278,
  5740. 'asciicircum': 469,
  5741. 'underscore': 556,
  5742. 'quoteleft': 222,
  5743. 'a': 556,
  5744. 'b': 556,
  5745. 'c': 500,
  5746. 'd': 556,
  5747. 'e': 556,
  5748. 'f': 278,
  5749. 'g': 556,
  5750. 'h': 556,
  5751. 'i': 222,
  5752. 'j': 222,
  5753. 'k': 500,
  5754. 'l': 222,
  5755. 'm': 833,
  5756. 'n': 556,
  5757. 'o': 556,
  5758. 'p': 556,
  5759. 'q': 556,
  5760. 'r': 333,
  5761. 's': 500,
  5762. 't': 278,
  5763. 'u': 556,
  5764. 'v': 500,
  5765. 'w': 722,
  5766. 'x': 500,
  5767. 'y': 500,
  5768. 'z': 500,
  5769. 'braceleft': 334,
  5770. 'bar': 260,
  5771. 'braceright': 334,
  5772. 'asciitilde': 584,
  5773. 'exclamdown': 333,
  5774. 'cent': 556,
  5775. 'sterling': 556,
  5776. 'fraction': 167,
  5777. 'yen': 556,
  5778. 'florin': 556,
  5779. 'section': 556,
  5780. 'currency': 556,
  5781. 'quotesingle': 191,
  5782. 'quotedblleft': 333,
  5783. 'guillemotleft': 556,
  5784. 'guilsinglleft': 333,
  5785. 'guilsinglright': 333,
  5786. 'fi': 500,
  5787. 'fl': 500,
  5788. 'endash': 556,
  5789. 'dagger': 556,
  5790. 'daggerdbl': 556,
  5791. 'periodcentered': 278,
  5792. 'paragraph': 537,
  5793. 'bullet': 350,
  5794. 'quotesinglbase': 222,
  5795. 'quotedblbase': 333,
  5796. 'quotedblright': 333,
  5797. 'guillemotright': 556,
  5798. 'ellipsis': 1000,
  5799. 'perthousand': 1000,
  5800. 'questiondown': 611,
  5801. 'grave': 333,
  5802. 'acute': 333,
  5803. 'circumflex': 333,
  5804. 'tilde': 333,
  5805. 'macron': 333,
  5806. 'breve': 333,
  5807. 'dotaccent': 333,
  5808. 'dieresis': 333,
  5809. 'ring': 333,
  5810. 'cedilla': 333,
  5811. 'hungarumlaut': 333,
  5812. 'ogonek': 333,
  5813. 'caron': 333,
  5814. 'emdash': 1000,
  5815. 'AE': 1000,
  5816. 'ordfeminine': 370,
  5817. 'Lslash': 556,
  5818. 'Oslash': 778,
  5819. 'OE': 1000,
  5820. 'ordmasculine': 365,
  5821. 'ae': 889,
  5822. 'dotlessi': 278,
  5823. 'lslash': 222,
  5824. 'oslash': 611,
  5825. 'oe': 944,
  5826. 'germandbls': 611,
  5827. 'Idieresis': 278,
  5828. 'eacute': 556,
  5829. 'abreve': 556,
  5830. 'uhungarumlaut': 556,
  5831. 'ecaron': 556,
  5832. 'Ydieresis': 667,
  5833. 'divide': 584,
  5834. 'Yacute': 667,
  5835. 'Acircumflex': 667,
  5836. 'aacute': 556,
  5837. 'Ucircumflex': 722,
  5838. 'yacute': 500,
  5839. 'scommaaccent': 500,
  5840. 'ecircumflex': 556,
  5841. 'Uring': 722,
  5842. 'Udieresis': 722,
  5843. 'aogonek': 556,
  5844. 'Uacute': 722,
  5845. 'uogonek': 556,
  5846. 'Edieresis': 667,
  5847. 'Dcroat': 722,
  5848. 'commaaccent': 250,
  5849. 'copyright': 737,
  5850. 'Emacron': 667,
  5851. 'ccaron': 500,
  5852. 'aring': 556,
  5853. 'Ncommaaccent': 722,
  5854. 'lacute': 222,
  5855. 'agrave': 556,
  5856. 'Tcommaaccent': 611,
  5857. 'Cacute': 722,
  5858. 'atilde': 556,
  5859. 'Edotaccent': 667,
  5860. 'scaron': 500,
  5861. 'scedilla': 500,
  5862. 'iacute': 278,
  5863. 'lozenge': 471,
  5864. 'Rcaron': 722,
  5865. 'Gcommaaccent': 778,
  5866. 'ucircumflex': 556,
  5867. 'acircumflex': 556,
  5868. 'Amacron': 667,
  5869. 'rcaron': 333,
  5870. 'ccedilla': 500,
  5871. 'Zdotaccent': 611,
  5872. 'Thorn': 667,
  5873. 'Omacron': 778,
  5874. 'Racute': 722,
  5875. 'Sacute': 667,
  5876. 'dcaron': 643,
  5877. 'Umacron': 722,
  5878. 'uring': 556,
  5879. 'threesuperior': 333,
  5880. 'Ograve': 778,
  5881. 'Agrave': 667,
  5882. 'Abreve': 667,
  5883. 'multiply': 584,
  5884. 'uacute': 556,
  5885. 'Tcaron': 611,
  5886. 'partialdiff': 476,
  5887. 'ydieresis': 500,
  5888. 'Nacute': 722,
  5889. 'icircumflex': 278,
  5890. 'Ecircumflex': 667,
  5891. 'adieresis': 556,
  5892. 'edieresis': 556,
  5893. 'cacute': 500,
  5894. 'nacute': 556,
  5895. 'umacron': 556,
  5896. 'Ncaron': 722,
  5897. 'Iacute': 278,
  5898. 'plusminus': 584,
  5899. 'brokenbar': 260,
  5900. 'registered': 737,
  5901. 'Gbreve': 778,
  5902. 'Idotaccent': 278,
  5903. 'summation': 600,
  5904. 'Egrave': 667,
  5905. 'racute': 333,
  5906. 'omacron': 556,
  5907. 'Zacute': 611,
  5908. 'Zcaron': 611,
  5909. 'greaterequal': 549,
  5910. 'Eth': 722,
  5911. 'Ccedilla': 722,
  5912. 'lcommaaccent': 222,
  5913. 'tcaron': 317,
  5914. 'eogonek': 556,
  5915. 'Uogonek': 722,
  5916. 'Aacute': 667,
  5917. 'Adieresis': 667,
  5918. 'egrave': 556,
  5919. 'zacute': 500,
  5920. 'iogonek': 222,
  5921. 'Oacute': 778,
  5922. 'oacute': 556,
  5923. 'amacron': 556,
  5924. 'sacute': 500,
  5925. 'idieresis': 278,
  5926. 'Ocircumflex': 778,
  5927. 'Ugrave': 722,
  5928. 'Delta': 612,
  5929. 'thorn': 556,
  5930. 'twosuperior': 333,
  5931. 'Odieresis': 778,
  5932. 'mu': 556,
  5933. 'igrave': 278,
  5934. 'ohungarumlaut': 556,
  5935. 'Eogonek': 667,
  5936. 'dcroat': 556,
  5937. 'threequarters': 834,
  5938. 'Scedilla': 667,
  5939. 'lcaron': 299,
  5940. 'Kcommaaccent': 667,
  5941. 'Lacute': 556,
  5942. 'trademark': 1000,
  5943. 'edotaccent': 556,
  5944. 'Igrave': 278,
  5945. 'Imacron': 278,
  5946. 'Lcaron': 556,
  5947. 'onehalf': 834,
  5948. 'lessequal': 549,
  5949. 'ocircumflex': 556,
  5950. 'ntilde': 556,
  5951. 'Uhungarumlaut': 722,
  5952. 'Eacute': 667,
  5953. 'emacron': 556,
  5954. 'gbreve': 556,
  5955. 'onequarter': 834,
  5956. 'Scaron': 667,
  5957. 'Scommaaccent': 667,
  5958. 'Ohungarumlaut': 778,
  5959. 'degree': 400,
  5960. 'ograve': 556,
  5961. 'Ccaron': 722,
  5962. 'ugrave': 556,
  5963. 'radical': 453,
  5964. 'Dcaron': 722,
  5965. 'rcommaaccent': 333,
  5966. 'Ntilde': 722,
  5967. 'otilde': 556,
  5968. 'Rcommaaccent': 722,
  5969. 'Lcommaaccent': 556,
  5970. 'Atilde': 667,
  5971. 'Aogonek': 667,
  5972. 'Aring': 667,
  5973. 'Otilde': 778,
  5974. 'zdotaccent': 500,
  5975. 'Ecaron': 667,
  5976. 'Iogonek': 278,
  5977. 'kcommaaccent': 500,
  5978. 'minus': 584,
  5979. 'Icircumflex': 278,
  5980. 'ncaron': 556,
  5981. 'tcommaaccent': 278,
  5982. 'logicalnot': 584,
  5983. 'odieresis': 556,
  5984. 'udieresis': 556,
  5985. 'notequal': 549,
  5986. 'gcommaaccent': 556,
  5987. 'eth': 556,
  5988. 'zcaron': 500,
  5989. 'ncommaaccent': 556,
  5990. 'onesuperior': 333,
  5991. 'imacron': 278,
  5992. 'Euro': 556
  5993. },
  5994. 'Helvetica-Bold': {
  5995. 'space': 278,
  5996. 'exclam': 333,
  5997. 'quotedbl': 474,
  5998. 'numbersign': 556,
  5999. 'dollar': 556,
  6000. 'percent': 889,
  6001. 'ampersand': 722,
  6002. 'quoteright': 278,
  6003. 'parenleft': 333,
  6004. 'parenright': 333,
  6005. 'asterisk': 389,
  6006. 'plus': 584,
  6007. 'comma': 278,
  6008. 'hyphen': 333,
  6009. 'period': 278,
  6010. 'slash': 278,
  6011. 'zero': 556,
  6012. 'one': 556,
  6013. 'two': 556,
  6014. 'three': 556,
  6015. 'four': 556,
  6016. 'five': 556,
  6017. 'six': 556,
  6018. 'seven': 556,
  6019. 'eight': 556,
  6020. 'nine': 556,
  6021. 'colon': 333,
  6022. 'semicolon': 333,
  6023. 'less': 584,
  6024. 'equal': 584,
  6025. 'greater': 584,
  6026. 'question': 611,
  6027. 'at': 975,
  6028. 'A': 722,
  6029. 'B': 722,
  6030. 'C': 722,
  6031. 'D': 722,
  6032. 'E': 667,
  6033. 'F': 611,
  6034. 'G': 778,
  6035. 'H': 722,
  6036. 'I': 278,
  6037. 'J': 556,
  6038. 'K': 722,
  6039. 'L': 611,
  6040. 'M': 833,
  6041. 'N': 722,
  6042. 'O': 778,
  6043. 'P': 667,
  6044. 'Q': 778,
  6045. 'R': 722,
  6046. 'S': 667,
  6047. 'T': 611,
  6048. 'U': 722,
  6049. 'V': 667,
  6050. 'W': 944,
  6051. 'X': 667,
  6052. 'Y': 667,
  6053. 'Z': 611,
  6054. 'bracketleft': 333,
  6055. 'backslash': 278,
  6056. 'bracketright': 333,
  6057. 'asciicircum': 584,
  6058. 'underscore': 556,
  6059. 'quoteleft': 278,
  6060. 'a': 556,
  6061. 'b': 611,
  6062. 'c': 556,
  6063. 'd': 611,
  6064. 'e': 556,
  6065. 'f': 333,
  6066. 'g': 611,
  6067. 'h': 611,
  6068. 'i': 278,
  6069. 'j': 278,
  6070. 'k': 556,
  6071. 'l': 278,
  6072. 'm': 889,
  6073. 'n': 611,
  6074. 'o': 611,
  6075. 'p': 611,
  6076. 'q': 611,
  6077. 'r': 389,
  6078. 's': 556,
  6079. 't': 333,
  6080. 'u': 611,
  6081. 'v': 556,
  6082. 'w': 778,
  6083. 'x': 556,
  6084. 'y': 556,
  6085. 'z': 500,
  6086. 'braceleft': 389,
  6087. 'bar': 280,
  6088. 'braceright': 389,
  6089. 'asciitilde': 584,
  6090. 'exclamdown': 333,
  6091. 'cent': 556,
  6092. 'sterling': 556,
  6093. 'fraction': 167,
  6094. 'yen': 556,
  6095. 'florin': 556,
  6096. 'section': 556,
  6097. 'currency': 556,
  6098. 'quotesingle': 238,
  6099. 'quotedblleft': 500,
  6100. 'guillemotleft': 556,
  6101. 'guilsinglleft': 333,
  6102. 'guilsinglright': 333,
  6103. 'fi': 611,
  6104. 'fl': 611,
  6105. 'endash': 556,
  6106. 'dagger': 556,
  6107. 'daggerdbl': 556,
  6108. 'periodcentered': 278,
  6109. 'paragraph': 556,
  6110. 'bullet': 350,
  6111. 'quotesinglbase': 278,
  6112. 'quotedblbase': 500,
  6113. 'quotedblright': 500,
  6114. 'guillemotright': 556,
  6115. 'ellipsis': 1000,
  6116. 'perthousand': 1000,
  6117. 'questiondown': 611,
  6118. 'grave': 333,
  6119. 'acute': 333,
  6120. 'circumflex': 333,
  6121. 'tilde': 333,
  6122. 'macron': 333,
  6123. 'breve': 333,
  6124. 'dotaccent': 333,
  6125. 'dieresis': 333,
  6126. 'ring': 333,
  6127. 'cedilla': 333,
  6128. 'hungarumlaut': 333,
  6129. 'ogonek': 333,
  6130. 'caron': 333,
  6131. 'emdash': 1000,
  6132. 'AE': 1000,
  6133. 'ordfeminine': 370,
  6134. 'Lslash': 611,
  6135. 'Oslash': 778,
  6136. 'OE': 1000,
  6137. 'ordmasculine': 365,
  6138. 'ae': 889,
  6139. 'dotlessi': 278,
  6140. 'lslash': 278,
  6141. 'oslash': 611,
  6142. 'oe': 944,
  6143. 'germandbls': 611,
  6144. 'Idieresis': 278,
  6145. 'eacute': 556,
  6146. 'abreve': 556,
  6147. 'uhungarumlaut': 611,
  6148. 'ecaron': 556,
  6149. 'Ydieresis': 667,
  6150. 'divide': 584,
  6151. 'Yacute': 667,
  6152. 'Acircumflex': 722,
  6153. 'aacute': 556,
  6154. 'Ucircumflex': 722,
  6155. 'yacute': 556,
  6156. 'scommaaccent': 556,
  6157. 'ecircumflex': 556,
  6158. 'Uring': 722,
  6159. 'Udieresis': 722,
  6160. 'aogonek': 556,
  6161. 'Uacute': 722,
  6162. 'uogonek': 611,
  6163. 'Edieresis': 667,
  6164. 'Dcroat': 722,
  6165. 'commaaccent': 250,
  6166. 'copyright': 737,
  6167. 'Emacron': 667,
  6168. 'ccaron': 556,
  6169. 'aring': 556,
  6170. 'Ncommaaccent': 722,
  6171. 'lacute': 278,
  6172. 'agrave': 556,
  6173. 'Tcommaaccent': 611,
  6174. 'Cacute': 722,
  6175. 'atilde': 556,
  6176. 'Edotaccent': 667,
  6177. 'scaron': 556,
  6178. 'scedilla': 556,
  6179. 'iacute': 278,
  6180. 'lozenge': 494,
  6181. 'Rcaron': 722,
  6182. 'Gcommaaccent': 778,
  6183. 'ucircumflex': 611,
  6184. 'acircumflex': 556,
  6185. 'Amacron': 722,
  6186. 'rcaron': 389,
  6187. 'ccedilla': 556,
  6188. 'Zdotaccent': 611,
  6189. 'Thorn': 667,
  6190. 'Omacron': 778,
  6191. 'Racute': 722,
  6192. 'Sacute': 667,
  6193. 'dcaron': 743,
  6194. 'Umacron': 722,
  6195. 'uring': 611,
  6196. 'threesuperior': 333,
  6197. 'Ograve': 778,
  6198. 'Agrave': 722,
  6199. 'Abreve': 722,
  6200. 'multiply': 584,
  6201. 'uacute': 611,
  6202. 'Tcaron': 611,
  6203. 'partialdiff': 494,
  6204. 'ydieresis': 556,
  6205. 'Nacute': 722,
  6206. 'icircumflex': 278,
  6207. 'Ecircumflex': 667,
  6208. 'adieresis': 556,
  6209. 'edieresis': 556,
  6210. 'cacute': 556,
  6211. 'nacute': 611,
  6212. 'umacron': 611,
  6213. 'Ncaron': 722,
  6214. 'Iacute': 278,
  6215. 'plusminus': 584,
  6216. 'brokenbar': 280,
  6217. 'registered': 737,
  6218. 'Gbreve': 778,
  6219. 'Idotaccent': 278,
  6220. 'summation': 600,
  6221. 'Egrave': 667,
  6222. 'racute': 389,
  6223. 'omacron': 611,
  6224. 'Zacute': 611,
  6225. 'Zcaron': 611,
  6226. 'greaterequal': 549,
  6227. 'Eth': 722,
  6228. 'Ccedilla': 722,
  6229. 'lcommaaccent': 278,
  6230. 'tcaron': 389,
  6231. 'eogonek': 556,
  6232. 'Uogonek': 722,
  6233. 'Aacute': 722,
  6234. 'Adieresis': 722,
  6235. 'egrave': 556,
  6236. 'zacute': 500,
  6237. 'iogonek': 278,
  6238. 'Oacute': 778,
  6239. 'oacute': 611,
  6240. 'amacron': 556,
  6241. 'sacute': 556,
  6242. 'idieresis': 278,
  6243. 'Ocircumflex': 778,
  6244. 'Ugrave': 722,
  6245. 'Delta': 612,
  6246. 'thorn': 611,
  6247. 'twosuperior': 333,
  6248. 'Odieresis': 778,
  6249. 'mu': 611,
  6250. 'igrave': 278,
  6251. 'ohungarumlaut': 611,
  6252. 'Eogonek': 667,
  6253. 'dcroat': 611,
  6254. 'threequarters': 834,
  6255. 'Scedilla': 667,
  6256. 'lcaron': 400,
  6257. 'Kcommaaccent': 722,
  6258. 'Lacute': 611,
  6259. 'trademark': 1000,
  6260. 'edotaccent': 556,
  6261. 'Igrave': 278,
  6262. 'Imacron': 278,
  6263. 'Lcaron': 611,
  6264. 'onehalf': 834,
  6265. 'lessequal': 549,
  6266. 'ocircumflex': 611,
  6267. 'ntilde': 611,
  6268. 'Uhungarumlaut': 722,
  6269. 'Eacute': 667,
  6270. 'emacron': 556,
  6271. 'gbreve': 611,
  6272. 'onequarter': 834,
  6273. 'Scaron': 667,
  6274. 'Scommaaccent': 667,
  6275. 'Ohungarumlaut': 778,
  6276. 'degree': 400,
  6277. 'ograve': 611,
  6278. 'Ccaron': 722,
  6279. 'ugrave': 611,
  6280. 'radical': 549,
  6281. 'Dcaron': 722,
  6282. 'rcommaaccent': 389,
  6283. 'Ntilde': 722,
  6284. 'otilde': 611,
  6285. 'Rcommaaccent': 722,
  6286. 'Lcommaaccent': 611,
  6287. 'Atilde': 722,
  6288. 'Aogonek': 722,
  6289. 'Aring': 722,
  6290. 'Otilde': 778,
  6291. 'zdotaccent': 500,
  6292. 'Ecaron': 667,
  6293. 'Iogonek': 278,
  6294. 'kcommaaccent': 556,
  6295. 'minus': 584,
  6296. 'Icircumflex': 278,
  6297. 'ncaron': 611,
  6298. 'tcommaaccent': 333,
  6299. 'logicalnot': 584,
  6300. 'odieresis': 611,
  6301. 'udieresis': 611,
  6302. 'notequal': 549,
  6303. 'gcommaaccent': 611,
  6304. 'eth': 611,
  6305. 'zcaron': 500,
  6306. 'ncommaaccent': 611,
  6307. 'onesuperior': 333,
  6308. 'imacron': 278,
  6309. 'Euro': 556
  6310. },
  6311. 'Helvetica-BoldOblique': {
  6312. 'space': 278,
  6313. 'exclam': 333,
  6314. 'quotedbl': 474,
  6315. 'numbersign': 556,
  6316. 'dollar': 556,
  6317. 'percent': 889,
  6318. 'ampersand': 722,
  6319. 'quoteright': 278,
  6320. 'parenleft': 333,
  6321. 'parenright': 333,
  6322. 'asterisk': 389,
  6323. 'plus': 584,
  6324. 'comma': 278,
  6325. 'hyphen': 333,
  6326. 'period': 278,
  6327. 'slash': 278,
  6328. 'zero': 556,
  6329. 'one': 556,
  6330. 'two': 556,
  6331. 'three': 556,
  6332. 'four': 556,
  6333. 'five': 556,
  6334. 'six': 556,
  6335. 'seven': 556,
  6336. 'eight': 556,
  6337. 'nine': 556,
  6338. 'colon': 333,
  6339. 'semicolon': 333,
  6340. 'less': 584,
  6341. 'equal': 584,
  6342. 'greater': 584,
  6343. 'question': 611,
  6344. 'at': 975,
  6345. 'A': 722,
  6346. 'B': 722,
  6347. 'C': 722,
  6348. 'D': 722,
  6349. 'E': 667,
  6350. 'F': 611,
  6351. 'G': 778,
  6352. 'H': 722,
  6353. 'I': 278,
  6354. 'J': 556,
  6355. 'K': 722,
  6356. 'L': 611,
  6357. 'M': 833,
  6358. 'N': 722,
  6359. 'O': 778,
  6360. 'P': 667,
  6361. 'Q': 778,
  6362. 'R': 722,
  6363. 'S': 667,
  6364. 'T': 611,
  6365. 'U': 722,
  6366. 'V': 667,
  6367. 'W': 944,
  6368. 'X': 667,
  6369. 'Y': 667,
  6370. 'Z': 611,
  6371. 'bracketleft': 333,
  6372. 'backslash': 278,
  6373. 'bracketright': 333,
  6374. 'asciicircum': 584,
  6375. 'underscore': 556,
  6376. 'quoteleft': 278,
  6377. 'a': 556,
  6378. 'b': 611,
  6379. 'c': 556,
  6380. 'd': 611,
  6381. 'e': 556,
  6382. 'f': 333,
  6383. 'g': 611,
  6384. 'h': 611,
  6385. 'i': 278,
  6386. 'j': 278,
  6387. 'k': 556,
  6388. 'l': 278,
  6389. 'm': 889,
  6390. 'n': 611,
  6391. 'o': 611,
  6392. 'p': 611,
  6393. 'q': 611,
  6394. 'r': 389,
  6395. 's': 556,
  6396. 't': 333,
  6397. 'u': 611,
  6398. 'v': 556,
  6399. 'w': 778,
  6400. 'x': 556,
  6401. 'y': 556,
  6402. 'z': 500,
  6403. 'braceleft': 389,
  6404. 'bar': 280,
  6405. 'braceright': 389,
  6406. 'asciitilde': 584,
  6407. 'exclamdown': 333,
  6408. 'cent': 556,
  6409. 'sterling': 556,
  6410. 'fraction': 167,
  6411. 'yen': 556,
  6412. 'florin': 556,
  6413. 'section': 556,
  6414. 'currency': 556,
  6415. 'quotesingle': 238,
  6416. 'quotedblleft': 500,
  6417. 'guillemotleft': 556,
  6418. 'guilsinglleft': 333,
  6419. 'guilsinglright': 333,
  6420. 'fi': 611,
  6421. 'fl': 611,
  6422. 'endash': 556,
  6423. 'dagger': 556,
  6424. 'daggerdbl': 556,
  6425. 'periodcentered': 278,
  6426. 'paragraph': 556,
  6427. 'bullet': 350,
  6428. 'quotesinglbase': 278,
  6429. 'quotedblbase': 500,
  6430. 'quotedblright': 500,
  6431. 'guillemotright': 556,
  6432. 'ellipsis': 1000,
  6433. 'perthousand': 1000,
  6434. 'questiondown': 611,
  6435. 'grave': 333,
  6436. 'acute': 333,
  6437. 'circumflex': 333,
  6438. 'tilde': 333,
  6439. 'macron': 333,
  6440. 'breve': 333,
  6441. 'dotaccent': 333,
  6442. 'dieresis': 333,
  6443. 'ring': 333,
  6444. 'cedilla': 333,
  6445. 'hungarumlaut': 333,
  6446. 'ogonek': 333,
  6447. 'caron': 333,
  6448. 'emdash': 1000,
  6449. 'AE': 1000,
  6450. 'ordfeminine': 370,
  6451. 'Lslash': 611,
  6452. 'Oslash': 778,
  6453. 'OE': 1000,
  6454. 'ordmasculine': 365,
  6455. 'ae': 889,
  6456. 'dotlessi': 278,
  6457. 'lslash': 278,
  6458. 'oslash': 611,
  6459. 'oe': 944,
  6460. 'germandbls': 611,
  6461. 'Idieresis': 278,
  6462. 'eacute': 556,
  6463. 'abreve': 556,
  6464. 'uhungarumlaut': 611,
  6465. 'ecaron': 556,
  6466. 'Ydieresis': 667,
  6467. 'divide': 584,
  6468. 'Yacute': 667,
  6469. 'Acircumflex': 722,
  6470. 'aacute': 556,
  6471. 'Ucircumflex': 722,
  6472. 'yacute': 556,
  6473. 'scommaaccent': 556,
  6474. 'ecircumflex': 556,
  6475. 'Uring': 722,
  6476. 'Udieresis': 722,
  6477. 'aogonek': 556,
  6478. 'Uacute': 722,
  6479. 'uogonek': 611,
  6480. 'Edieresis': 667,
  6481. 'Dcroat': 722,
  6482. 'commaaccent': 250,
  6483. 'copyright': 737,
  6484. 'Emacron': 667,
  6485. 'ccaron': 556,
  6486. 'aring': 556,
  6487. 'Ncommaaccent': 722,
  6488. 'lacute': 278,
  6489. 'agrave': 556,
  6490. 'Tcommaaccent': 611,
  6491. 'Cacute': 722,
  6492. 'atilde': 556,
  6493. 'Edotaccent': 667,
  6494. 'scaron': 556,
  6495. 'scedilla': 556,
  6496. 'iacute': 278,
  6497. 'lozenge': 494,
  6498. 'Rcaron': 722,
  6499. 'Gcommaaccent': 778,
  6500. 'ucircumflex': 611,
  6501. 'acircumflex': 556,
  6502. 'Amacron': 722,
  6503. 'rcaron': 389,
  6504. 'ccedilla': 556,
  6505. 'Zdotaccent': 611,
  6506. 'Thorn': 667,
  6507. 'Omacron': 778,
  6508. 'Racute': 722,
  6509. 'Sacute': 667,
  6510. 'dcaron': 743,
  6511. 'Umacron': 722,
  6512. 'uring': 611,
  6513. 'threesuperior': 333,
  6514. 'Ograve': 778,
  6515. 'Agrave': 722,
  6516. 'Abreve': 722,
  6517. 'multiply': 584,
  6518. 'uacute': 611,
  6519. 'Tcaron': 611,
  6520. 'partialdiff': 494,
  6521. 'ydieresis': 556,
  6522. 'Nacute': 722,
  6523. 'icircumflex': 278,
  6524. 'Ecircumflex': 667,
  6525. 'adieresis': 556,
  6526. 'edieresis': 556,
  6527. 'cacute': 556,
  6528. 'nacute': 611,
  6529. 'umacron': 611,
  6530. 'Ncaron': 722,
  6531. 'Iacute': 278,
  6532. 'plusminus': 584,
  6533. 'brokenbar': 280,
  6534. 'registered': 737,
  6535. 'Gbreve': 778,
  6536. 'Idotaccent': 278,
  6537. 'summation': 600,
  6538. 'Egrave': 667,
  6539. 'racute': 389,
  6540. 'omacron': 611,
  6541. 'Zacute': 611,
  6542. 'Zcaron': 611,
  6543. 'greaterequal': 549,
  6544. 'Eth': 722,
  6545. 'Ccedilla': 722,
  6546. 'lcommaaccent': 278,
  6547. 'tcaron': 389,
  6548. 'eogonek': 556,
  6549. 'Uogonek': 722,
  6550. 'Aacute': 722,
  6551. 'Adieresis': 722,
  6552. 'egrave': 556,
  6553. 'zacute': 500,
  6554. 'iogonek': 278,
  6555. 'Oacute': 778,
  6556. 'oacute': 611,
  6557. 'amacron': 556,
  6558. 'sacute': 556,
  6559. 'idieresis': 278,
  6560. 'Ocircumflex': 778,
  6561. 'Ugrave': 722,
  6562. 'Delta': 612,
  6563. 'thorn': 611,
  6564. 'twosuperior': 333,
  6565. 'Odieresis': 778,
  6566. 'mu': 611,
  6567. 'igrave': 278,
  6568. 'ohungarumlaut': 611,
  6569. 'Eogonek': 667,
  6570. 'dcroat': 611,
  6571. 'threequarters': 834,
  6572. 'Scedilla': 667,
  6573. 'lcaron': 400,
  6574. 'Kcommaaccent': 722,
  6575. 'Lacute': 611,
  6576. 'trademark': 1000,
  6577. 'edotaccent': 556,
  6578. 'Igrave': 278,
  6579. 'Imacron': 278,
  6580. 'Lcaron': 611,
  6581. 'onehalf': 834,
  6582. 'lessequal': 549,
  6583. 'ocircumflex': 611,
  6584. 'ntilde': 611,
  6585. 'Uhungarumlaut': 722,
  6586. 'Eacute': 667,
  6587. 'emacron': 556,
  6588. 'gbreve': 611,
  6589. 'onequarter': 834,
  6590. 'Scaron': 667,
  6591. 'Scommaaccent': 667,
  6592. 'Ohungarumlaut': 778,
  6593. 'degree': 400,
  6594. 'ograve': 611,
  6595. 'Ccaron': 722,
  6596. 'ugrave': 611,
  6597. 'radical': 549,
  6598. 'Dcaron': 722,
  6599. 'rcommaaccent': 389,
  6600. 'Ntilde': 722,
  6601. 'otilde': 611,
  6602. 'Rcommaaccent': 722,
  6603. 'Lcommaaccent': 611,
  6604. 'Atilde': 722,
  6605. 'Aogonek': 722,
  6606. 'Aring': 722,
  6607. 'Otilde': 778,
  6608. 'zdotaccent': 500,
  6609. 'Ecaron': 667,
  6610. 'Iogonek': 278,
  6611. 'kcommaaccent': 556,
  6612. 'minus': 584,
  6613. 'Icircumflex': 278,
  6614. 'ncaron': 611,
  6615. 'tcommaaccent': 333,
  6616. 'logicalnot': 584,
  6617. 'odieresis': 611,
  6618. 'udieresis': 611,
  6619. 'notequal': 549,
  6620. 'gcommaaccent': 611,
  6621. 'eth': 611,
  6622. 'zcaron': 500,
  6623. 'ncommaaccent': 611,
  6624. 'onesuperior': 333,
  6625. 'imacron': 278,
  6626. 'Euro': 556
  6627. },
  6628. 'Helvetica-Oblique' : {
  6629. 'space': 278,
  6630. 'exclam': 278,
  6631. 'quotedbl': 355,
  6632. 'numbersign': 556,
  6633. 'dollar': 556,
  6634. 'percent': 889,
  6635. 'ampersand': 667,
  6636. 'quoteright': 222,
  6637. 'parenleft': 333,
  6638. 'parenright': 333,
  6639. 'asterisk': 389,
  6640. 'plus': 584,
  6641. 'comma': 278,
  6642. 'hyphen': 333,
  6643. 'period': 278,
  6644. 'slash': 278,
  6645. 'zero': 556,
  6646. 'one': 556,
  6647. 'two': 556,
  6648. 'three': 556,
  6649. 'four': 556,
  6650. 'five': 556,
  6651. 'six': 556,
  6652. 'seven': 556,
  6653. 'eight': 556,
  6654. 'nine': 556,
  6655. 'colon': 278,
  6656. 'semicolon': 278,
  6657. 'less': 584,
  6658. 'equal': 584,
  6659. 'greater': 584,
  6660. 'question': 556,
  6661. 'at': 1015,
  6662. 'A': 667,
  6663. 'B': 667,
  6664. 'C': 722,
  6665. 'D': 722,
  6666. 'E': 667,
  6667. 'F': 611,
  6668. 'G': 778,
  6669. 'H': 722,
  6670. 'I': 278,
  6671. 'J': 500,
  6672. 'K': 667,
  6673. 'L': 556,
  6674. 'M': 833,
  6675. 'N': 722,
  6676. 'O': 778,
  6677. 'P': 667,
  6678. 'Q': 778,
  6679. 'R': 722,
  6680. 'S': 667,
  6681. 'T': 611,
  6682. 'U': 722,
  6683. 'V': 667,
  6684. 'W': 944,
  6685. 'X': 667,
  6686. 'Y': 667,
  6687. 'Z': 611,
  6688. 'bracketleft': 278,
  6689. 'backslash': 278,
  6690. 'bracketright': 278,
  6691. 'asciicircum': 469,
  6692. 'underscore': 556,
  6693. 'quoteleft': 222,
  6694. 'a': 556,
  6695. 'b': 556,
  6696. 'c': 500,
  6697. 'd': 556,
  6698. 'e': 556,
  6699. 'f': 278,
  6700. 'g': 556,
  6701. 'h': 556,
  6702. 'i': 222,
  6703. 'j': 222,
  6704. 'k': 500,
  6705. 'l': 222,
  6706. 'm': 833,
  6707. 'n': 556,
  6708. 'o': 556,
  6709. 'p': 556,
  6710. 'q': 556,
  6711. 'r': 333,
  6712. 's': 500,
  6713. 't': 278,
  6714. 'u': 556,
  6715. 'v': 500,
  6716. 'w': 722,
  6717. 'x': 500,
  6718. 'y': 500,
  6719. 'z': 500,
  6720. 'braceleft': 334,
  6721. 'bar': 260,
  6722. 'braceright': 334,
  6723. 'asciitilde': 584,
  6724. 'exclamdown': 333,
  6725. 'cent': 556,
  6726. 'sterling': 556,
  6727. 'fraction': 167,
  6728. 'yen': 556,
  6729. 'florin': 556,
  6730. 'section': 556,
  6731. 'currency': 556,
  6732. 'quotesingle': 191,
  6733. 'quotedblleft': 333,
  6734. 'guillemotleft': 556,
  6735. 'guilsinglleft': 333,
  6736. 'guilsinglright': 333,
  6737. 'fi': 500,
  6738. 'fl': 500,
  6739. 'endash': 556,
  6740. 'dagger': 556,
  6741. 'daggerdbl': 556,
  6742. 'periodcentered': 278,
  6743. 'paragraph': 537,
  6744. 'bullet': 350,
  6745. 'quotesinglbase': 222,
  6746. 'quotedblbase': 333,
  6747. 'quotedblright': 333,
  6748. 'guillemotright': 556,
  6749. 'ellipsis': 1000,
  6750. 'perthousand': 1000,
  6751. 'questiondown': 611,
  6752. 'grave': 333,
  6753. 'acute': 333,
  6754. 'circumflex': 333,
  6755. 'tilde': 333,
  6756. 'macron': 333,
  6757. 'breve': 333,
  6758. 'dotaccent': 333,
  6759. 'dieresis': 333,
  6760. 'ring': 333,
  6761. 'cedilla': 333,
  6762. 'hungarumlaut': 333,
  6763. 'ogonek': 333,
  6764. 'caron': 333,
  6765. 'emdash': 1000,
  6766. 'AE': 1000,
  6767. 'ordfeminine': 370,
  6768. 'Lslash': 556,
  6769. 'Oslash': 778,
  6770. 'OE': 1000,
  6771. 'ordmasculine': 365,
  6772. 'ae': 889,
  6773. 'dotlessi': 278,
  6774. 'lslash': 222,
  6775. 'oslash': 611,
  6776. 'oe': 944,
  6777. 'germandbls': 611,
  6778. 'Idieresis': 278,
  6779. 'eacute': 556,
  6780. 'abreve': 556,
  6781. 'uhungarumlaut': 556,
  6782. 'ecaron': 556,
  6783. 'Ydieresis': 667,
  6784. 'divide': 584,
  6785. 'Yacute': 667,
  6786. 'Acircumflex': 667,
  6787. 'aacute': 556,
  6788. 'Ucircumflex': 722,
  6789. 'yacute': 500,
  6790. 'scommaaccent': 500,
  6791. 'ecircumflex': 556,
  6792. 'Uring': 722,
  6793. 'Udieresis': 722,
  6794. 'aogonek': 556,
  6795. 'Uacute': 722,
  6796. 'uogonek': 556,
  6797. 'Edieresis': 667,
  6798. 'Dcroat': 722,
  6799. 'commaaccent': 250,
  6800. 'copyright': 737,
  6801. 'Emacron': 667,
  6802. 'ccaron': 500,
  6803. 'aring': 556,
  6804. 'Ncommaaccent': 722,
  6805. 'lacute': 222,
  6806. 'agrave': 556,
  6807. 'Tcommaaccent': 611,
  6808. 'Cacute': 722,
  6809. 'atilde': 556,
  6810. 'Edotaccent': 667,
  6811. 'scaron': 500,
  6812. 'scedilla': 500,
  6813. 'iacute': 278,
  6814. 'lozenge': 471,
  6815. 'Rcaron': 722,
  6816. 'Gcommaaccent': 778,
  6817. 'ucircumflex': 556,
  6818. 'acircumflex': 556,
  6819. 'Amacron': 667,
  6820. 'rcaron': 333,
  6821. 'ccedilla': 500,
  6822. 'Zdotaccent': 611,
  6823. 'Thorn': 667,
  6824. 'Omacron': 778,
  6825. 'Racute': 722,
  6826. 'Sacute': 667,
  6827. 'dcaron': 643,
  6828. 'Umacron': 722,
  6829. 'uring': 556,
  6830. 'threesuperior': 333,
  6831. 'Ograve': 778,
  6832. 'Agrave': 667,
  6833. 'Abreve': 667,
  6834. 'multiply': 584,
  6835. 'uacute': 556,
  6836. 'Tcaron': 611,
  6837. 'partialdiff': 476,
  6838. 'ydieresis': 500,
  6839. 'Nacute': 722,
  6840. 'icircumflex': 278,
  6841. 'Ecircumflex': 667,
  6842. 'adieresis': 556,
  6843. 'edieresis': 556,
  6844. 'cacute': 500,
  6845. 'nacute': 556,
  6846. 'umacron': 556,
  6847. 'Ncaron': 722,
  6848. 'Iacute': 278,
  6849. 'plusminus': 584,
  6850. 'brokenbar': 260,
  6851. 'registered': 737,
  6852. 'Gbreve': 778,
  6853. 'Idotaccent': 278,
  6854. 'summation': 600,
  6855. 'Egrave': 667,
  6856. 'racute': 333,
  6857. 'omacron': 556,
  6858. 'Zacute': 611,
  6859. 'Zcaron': 611,
  6860. 'greaterequal': 549,
  6861. 'Eth': 722,
  6862. 'Ccedilla': 722,
  6863. 'lcommaaccent': 222,
  6864. 'tcaron': 317,
  6865. 'eogonek': 556,
  6866. 'Uogonek': 722,
  6867. 'Aacute': 667,
  6868. 'Adieresis': 667,
  6869. 'egrave': 556,
  6870. 'zacute': 500,
  6871. 'iogonek': 222,
  6872. 'Oacute': 778,
  6873. 'oacute': 556,
  6874. 'amacron': 556,
  6875. 'sacute': 500,
  6876. 'idieresis': 278,
  6877. 'Ocircumflex': 778,
  6878. 'Ugrave': 722,
  6879. 'Delta': 612,
  6880. 'thorn': 556,
  6881. 'twosuperior': 333,
  6882. 'Odieresis': 778,
  6883. 'mu': 556,
  6884. 'igrave': 278,
  6885. 'ohungarumlaut': 556,
  6886. 'Eogonek': 667,
  6887. 'dcroat': 556,
  6888. 'threequarters': 834,
  6889. 'Scedilla': 667,
  6890. 'lcaron': 299,
  6891. 'Kcommaaccent': 667,
  6892. 'Lacute': 556,
  6893. 'trademark': 1000,
  6894. 'edotaccent': 556,
  6895. 'Igrave': 278,
  6896. 'Imacron': 278,
  6897. 'Lcaron': 556,
  6898. 'onehalf': 834,
  6899. 'lessequal': 549,
  6900. 'ocircumflex': 556,
  6901. 'ntilde': 556,
  6902. 'Uhungarumlaut': 722,
  6903. 'Eacute': 667,
  6904. 'emacron': 556,
  6905. 'gbreve': 556,
  6906. 'onequarter': 834,
  6907. 'Scaron': 667,
  6908. 'Scommaaccent': 667,
  6909. 'Ohungarumlaut': 778,
  6910. 'degree': 400,
  6911. 'ograve': 556,
  6912. 'Ccaron': 722,
  6913. 'ugrave': 556,
  6914. 'radical': 453,
  6915. 'Dcaron': 722,
  6916. 'rcommaaccent': 333,
  6917. 'Ntilde': 722,
  6918. 'otilde': 556,
  6919. 'Rcommaaccent': 722,
  6920. 'Lcommaaccent': 556,
  6921. 'Atilde': 667,
  6922. 'Aogonek': 667,
  6923. 'Aring': 667,
  6924. 'Otilde': 778,
  6925. 'zdotaccent': 500,
  6926. 'Ecaron': 667,
  6927. 'Iogonek': 278,
  6928. 'kcommaaccent': 500,
  6929. 'minus': 584,
  6930. 'Icircumflex': 278,
  6931. 'ncaron': 556,
  6932. 'tcommaaccent': 278,
  6933. 'logicalnot': 584,
  6934. 'odieresis': 556,
  6935. 'udieresis': 556,
  6936. 'notequal': 549,
  6937. 'gcommaaccent': 556,
  6938. 'eth': 556,
  6939. 'zcaron': 500,
  6940. 'ncommaaccent': 556,
  6941. 'onesuperior': 333,
  6942. 'imacron': 278,
  6943. 'Euro': 556
  6944. },
  6945. 'Symbol': {
  6946. 'space': 250,
  6947. 'exclam': 333,
  6948. 'universal': 713,
  6949. 'numbersign': 500,
  6950. 'existential': 549,
  6951. 'percent': 833,
  6952. 'ampersand': 778,
  6953. 'suchthat': 439,
  6954. 'parenleft': 333,
  6955. 'parenright': 333,
  6956. 'asteriskmath': 500,
  6957. 'plus': 549,
  6958. 'comma': 250,
  6959. 'minus': 549,
  6960. 'period': 250,
  6961. 'slash': 278,
  6962. 'zero': 500,
  6963. 'one': 500,
  6964. 'two': 500,
  6965. 'three': 500,
  6966. 'four': 500,
  6967. 'five': 500,
  6968. 'six': 500,
  6969. 'seven': 500,
  6970. 'eight': 500,
  6971. 'nine': 500,
  6972. 'colon': 278,
  6973. 'semicolon': 278,
  6974. 'less': 549,
  6975. 'equal': 549,
  6976. 'greater': 549,
  6977. 'question': 444,
  6978. 'congruent': 549,
  6979. 'Alpha': 722,
  6980. 'Beta': 667,
  6981. 'Chi': 722,
  6982. 'Delta': 612,
  6983. 'Epsilon': 611,
  6984. 'Phi': 763,
  6985. 'Gamma': 603,
  6986. 'Eta': 722,
  6987. 'Iota': 333,
  6988. 'theta1': 631,
  6989. 'Kappa': 722,
  6990. 'Lambda': 686,
  6991. 'Mu': 889,
  6992. 'Nu': 722,
  6993. 'Omicron': 722,
  6994. 'Pi': 768,
  6995. 'Theta': 741,
  6996. 'Rho': 556,
  6997. 'Sigma': 592,
  6998. 'Tau': 611,
  6999. 'Upsilon': 690,
  7000. 'sigma1': 439,
  7001. 'Omega': 768,
  7002. 'Xi': 645,
  7003. 'Psi': 795,
  7004. 'Zeta': 611,
  7005. 'bracketleft': 333,
  7006. 'therefore': 863,
  7007. 'bracketright': 333,
  7008. 'perpendicular': 658,
  7009. 'underscore': 500,
  7010. 'radicalex': 500,
  7011. 'alpha': 631,
  7012. 'beta': 549,
  7013. 'chi': 549,
  7014. 'delta': 494,
  7015. 'epsilon': 439,
  7016. 'phi': 521,
  7017. 'gamma': 411,
  7018. 'eta': 603,
  7019. 'iota': 329,
  7020. 'phi1': 603,
  7021. 'kappa': 549,
  7022. 'lambda': 549,
  7023. 'mu': 576,
  7024. 'nu': 521,
  7025. 'omicron': 549,
  7026. 'pi': 549,
  7027. 'theta': 521,
  7028. 'rho': 549,
  7029. 'sigma': 603,
  7030. 'tau': 439,
  7031. 'upsilon': 576,
  7032. 'omega1': 713,
  7033. 'omega': 686,
  7034. 'xi': 493,
  7035. 'psi': 686,
  7036. 'zeta': 494,
  7037. 'braceleft': 480,
  7038. 'bar': 200,
  7039. 'braceright': 480,
  7040. 'similar': 549,
  7041. 'Euro': 750,
  7042. 'Upsilon1': 620,
  7043. 'minute': 247,
  7044. 'lessequal': 549,
  7045. 'fraction': 167,
  7046. 'infinity': 713,
  7047. 'florin': 500,
  7048. 'club': 753,
  7049. 'diamond': 753,
  7050. 'heart': 753,
  7051. 'spade': 753,
  7052. 'arrowboth': 1042,
  7053. 'arrowleft': 987,
  7054. 'arrowup': 603,
  7055. 'arrowright': 987,
  7056. 'arrowdown': 603,
  7057. 'degree': 400,
  7058. 'plusminus': 549,
  7059. 'second': 411,
  7060. 'greaterequal': 549,
  7061. 'multiply': 549,
  7062. 'proportional': 713,
  7063. 'partialdiff': 494,
  7064. 'bullet': 460,
  7065. 'divide': 549,
  7066. 'notequal': 549,
  7067. 'equivalence': 549,
  7068. 'approxequal': 549,
  7069. 'ellipsis': 1000,
  7070. 'arrowvertex': 603,
  7071. 'arrowhorizex': 1000,
  7072. 'carriagereturn': 658,
  7073. 'aleph': 823,
  7074. 'Ifraktur': 686,
  7075. 'Rfraktur': 795,
  7076. 'weierstrass': 987,
  7077. 'circlemultiply': 768,
  7078. 'circleplus': 768,
  7079. 'emptyset': 823,
  7080. 'intersection': 768,
  7081. 'union': 768,
  7082. 'propersuperset': 713,
  7083. 'reflexsuperset': 713,
  7084. 'notsubset': 713,
  7085. 'propersubset': 713,
  7086. 'reflexsubset': 713,
  7087. 'element': 713,
  7088. 'notelement': 713,
  7089. 'angle': 768,
  7090. 'gradient': 713,
  7091. 'registerserif': 790,
  7092. 'copyrightserif': 790,
  7093. 'trademarkserif': 890,
  7094. 'product': 823,
  7095. 'radical': 549,
  7096. 'dotmath': 250,
  7097. 'logicalnot': 713,
  7098. 'logicaland': 603,
  7099. 'logicalor': 603,
  7100. 'arrowdblboth': 1042,
  7101. 'arrowdblleft': 987,
  7102. 'arrowdblup': 603,
  7103. 'arrowdblright': 987,
  7104. 'arrowdbldown': 603,
  7105. 'lozenge': 494,
  7106. 'angleleft': 329,
  7107. 'registersans': 790,
  7108. 'copyrightsans': 790,
  7109. 'trademarksans': 786,
  7110. 'summation': 713,
  7111. 'parenlefttp': 384,
  7112. 'parenleftex': 384,
  7113. 'parenleftbt': 384,
  7114. 'bracketlefttp': 384,
  7115. 'bracketleftex': 384,
  7116. 'bracketleftbt': 384,
  7117. 'bracelefttp': 494,
  7118. 'braceleftmid': 494,
  7119. 'braceleftbt': 494,
  7120. 'braceex': 494,
  7121. 'angleright': 329,
  7122. 'integral': 274,
  7123. 'integraltp': 686,
  7124. 'integralex': 686,
  7125. 'integralbt': 686,
  7126. 'parenrighttp': 384,
  7127. 'parenrightex': 384,
  7128. 'parenrightbt': 384,
  7129. 'bracketrighttp': 384,
  7130. 'bracketrightex': 384,
  7131. 'bracketrightbt': 384,
  7132. 'bracerighttp': 494,
  7133. 'bracerightmid': 494,
  7134. 'bracerightbt': 494,
  7135. 'apple': 790
  7136. },
  7137. 'Times-Roman': {
  7138. 'space': 250,
  7139. 'exclam': 333,
  7140. 'quotedbl': 408,
  7141. 'numbersign': 500,
  7142. 'dollar': 500,
  7143. 'percent': 833,
  7144. 'ampersand': 778,
  7145. 'quoteright': 333,
  7146. 'parenleft': 333,
  7147. 'parenright': 333,
  7148. 'asterisk': 500,
  7149. 'plus': 564,
  7150. 'comma': 250,
  7151. 'hyphen': 333,
  7152. 'period': 250,
  7153. 'slash': 278,
  7154. 'zero': 500,
  7155. 'one': 500,
  7156. 'two': 500,
  7157. 'three': 500,
  7158. 'four': 500,
  7159. 'five': 500,
  7160. 'six': 500,
  7161. 'seven': 500,
  7162. 'eight': 500,
  7163. 'nine': 500,
  7164. 'colon': 278,
  7165. 'semicolon': 278,
  7166. 'less': 564,
  7167. 'equal': 564,
  7168. 'greater': 564,
  7169. 'question': 444,
  7170. 'at': 921,
  7171. 'A': 722,
  7172. 'B': 667,
  7173. 'C': 667,
  7174. 'D': 722,
  7175. 'E': 611,
  7176. 'F': 556,
  7177. 'G': 722,
  7178. 'H': 722,
  7179. 'I': 333,
  7180. 'J': 389,
  7181. 'K': 722,
  7182. 'L': 611,
  7183. 'M': 889,
  7184. 'N': 722,
  7185. 'O': 722,
  7186. 'P': 556,
  7187. 'Q': 722,
  7188. 'R': 667,
  7189. 'S': 556,
  7190. 'T': 611,
  7191. 'U': 722,
  7192. 'V': 722,
  7193. 'W': 944,
  7194. 'X': 722,
  7195. 'Y': 722,
  7196. 'Z': 611,
  7197. 'bracketleft': 333,
  7198. 'backslash': 278,
  7199. 'bracketright': 333,
  7200. 'asciicircum': 469,
  7201. 'underscore': 500,
  7202. 'quoteleft': 333,
  7203. 'a': 444,
  7204. 'b': 500,
  7205. 'c': 444,
  7206. 'd': 500,
  7207. 'e': 444,
  7208. 'f': 333,
  7209. 'g': 500,
  7210. 'h': 500,
  7211. 'i': 278,
  7212. 'j': 278,
  7213. 'k': 500,
  7214. 'l': 278,
  7215. 'm': 778,
  7216. 'n': 500,
  7217. 'o': 500,
  7218. 'p': 500,
  7219. 'q': 500,
  7220. 'r': 333,
  7221. 's': 389,
  7222. 't': 278,
  7223. 'u': 500,
  7224. 'v': 500,
  7225. 'w': 722,
  7226. 'x': 500,
  7227. 'y': 500,
  7228. 'z': 444,
  7229. 'braceleft': 480,
  7230. 'bar': 200,
  7231. 'braceright': 480,
  7232. 'asciitilde': 541,
  7233. 'exclamdown': 333,
  7234. 'cent': 500,
  7235. 'sterling': 500,
  7236. 'fraction': 167,
  7237. 'yen': 500,
  7238. 'florin': 500,
  7239. 'section': 500,
  7240. 'currency': 500,
  7241. 'quotesingle': 180,
  7242. 'quotedblleft': 444,
  7243. 'guillemotleft': 500,
  7244. 'guilsinglleft': 333,
  7245. 'guilsinglright': 333,
  7246. 'fi': 556,
  7247. 'fl': 556,
  7248. 'endash': 500,
  7249. 'dagger': 500,
  7250. 'daggerdbl': 500,
  7251. 'periodcentered': 250,
  7252. 'paragraph': 453,
  7253. 'bullet': 350,
  7254. 'quotesinglbase': 333,
  7255. 'quotedblbase': 444,
  7256. 'quotedblright': 444,
  7257. 'guillemotright': 500,
  7258. 'ellipsis': 1000,
  7259. 'perthousand': 1000,
  7260. 'questiondown': 444,
  7261. 'grave': 333,
  7262. 'acute': 333,
  7263. 'circumflex': 333,
  7264. 'tilde': 333,
  7265. 'macron': 333,
  7266. 'breve': 333,
  7267. 'dotaccent': 333,
  7268. 'dieresis': 333,
  7269. 'ring': 333,
  7270. 'cedilla': 333,
  7271. 'hungarumlaut': 333,
  7272. 'ogonek': 333,
  7273. 'caron': 333,
  7274. 'emdash': 1000,
  7275. 'AE': 889,
  7276. 'ordfeminine': 276,
  7277. 'Lslash': 611,
  7278. 'Oslash': 722,
  7279. 'OE': 889,
  7280. 'ordmasculine': 310,
  7281. 'ae': 667,
  7282. 'dotlessi': 278,
  7283. 'lslash': 278,
  7284. 'oslash': 500,
  7285. 'oe': 722,
  7286. 'germandbls': 500,
  7287. 'Idieresis': 333,
  7288. 'eacute': 444,
  7289. 'abreve': 444,
  7290. 'uhungarumlaut': 500,
  7291. 'ecaron': 444,
  7292. 'Ydieresis': 722,
  7293. 'divide': 564,
  7294. 'Yacute': 722,
  7295. 'Acircumflex': 722,
  7296. 'aacute': 444,
  7297. 'Ucircumflex': 722,
  7298. 'yacute': 500,
  7299. 'scommaaccent': 389,
  7300. 'ecircumflex': 444,
  7301. 'Uring': 722,
  7302. 'Udieresis': 722,
  7303. 'aogonek': 444,
  7304. 'Uacute': 722,
  7305. 'uogonek': 500,
  7306. 'Edieresis': 611,
  7307. 'Dcroat': 722,
  7308. 'commaaccent': 250,
  7309. 'copyright': 760,
  7310. 'Emacron': 611,
  7311. 'ccaron': 444,
  7312. 'aring': 444,
  7313. 'Ncommaaccent': 722,
  7314. 'lacute': 278,
  7315. 'agrave': 444,
  7316. 'Tcommaaccent': 611,
  7317. 'Cacute': 667,
  7318. 'atilde': 444,
  7319. 'Edotaccent': 611,
  7320. 'scaron': 389,
  7321. 'scedilla': 389,
  7322. 'iacute': 278,
  7323. 'lozenge': 471,
  7324. 'Rcaron': 667,
  7325. 'Gcommaaccent': 722,
  7326. 'ucircumflex': 500,
  7327. 'acircumflex': 444,
  7328. 'Amacron': 722,
  7329. 'rcaron': 333,
  7330. 'ccedilla': 444,
  7331. 'Zdotaccent': 611,
  7332. 'Thorn': 556,
  7333. 'Omacron': 722,
  7334. 'Racute': 667,
  7335. 'Sacute': 556,
  7336. 'dcaron': 588,
  7337. 'Umacron': 722,
  7338. 'uring': 500,
  7339. 'threesuperior': 300,
  7340. 'Ograve': 722,
  7341. 'Agrave': 722,
  7342. 'Abreve': 722,
  7343. 'multiply': 564,
  7344. 'uacute': 500,
  7345. 'Tcaron': 611,
  7346. 'partialdiff': 476,
  7347. 'ydieresis': 500,
  7348. 'Nacute': 722,
  7349. 'icircumflex': 278,
  7350. 'Ecircumflex': 611,
  7351. 'adieresis': 444,
  7352. 'edieresis': 444,
  7353. 'cacute': 444,
  7354. 'nacute': 500,
  7355. 'umacron': 500,
  7356. 'Ncaron': 722,
  7357. 'Iacute': 333,
  7358. 'plusminus': 564,
  7359. 'brokenbar': 200,
  7360. 'registered': 760,
  7361. 'Gbreve': 722,
  7362. 'Idotaccent': 333,
  7363. 'summation': 600,
  7364. 'Egrave': 611,
  7365. 'racute': 333,
  7366. 'omacron': 500,
  7367. 'Zacute': 611,
  7368. 'Zcaron': 611,
  7369. 'greaterequal': 549,
  7370. 'Eth': 722,
  7371. 'Ccedilla': 667,
  7372. 'lcommaaccent': 278,
  7373. 'tcaron': 326,
  7374. 'eogonek': 444,
  7375. 'Uogonek': 722,
  7376. 'Aacute': 722,
  7377. 'Adieresis': 722,
  7378. 'egrave': 444,
  7379. 'zacute': 444,
  7380. 'iogonek': 278,
  7381. 'Oacute': 722,
  7382. 'oacute': 500,
  7383. 'amacron': 444,
  7384. 'sacute': 389,
  7385. 'idieresis': 278,
  7386. 'Ocircumflex': 722,
  7387. 'Ugrave': 722,
  7388. 'Delta': 612,
  7389. 'thorn': 500,
  7390. 'twosuperior': 300,
  7391. 'Odieresis': 722,
  7392. 'mu': 500,
  7393. 'igrave': 278,
  7394. 'ohungarumlaut': 500,
  7395. 'Eogonek': 611,
  7396. 'dcroat': 500,
  7397. 'threequarters': 750,
  7398. 'Scedilla': 556,
  7399. 'lcaron': 344,
  7400. 'Kcommaaccent': 722,
  7401. 'Lacute': 611,
  7402. 'trademark': 980,
  7403. 'edotaccent': 444,
  7404. 'Igrave': 333,
  7405. 'Imacron': 333,
  7406. 'Lcaron': 611,
  7407. 'onehalf': 750,
  7408. 'lessequal': 549,
  7409. 'ocircumflex': 500,
  7410. 'ntilde': 500,
  7411. 'Uhungarumlaut': 722,
  7412. 'Eacute': 611,
  7413. 'emacron': 444,
  7414. 'gbreve': 500,
  7415. 'onequarter': 750,
  7416. 'Scaron': 556,
  7417. 'Scommaaccent': 556,
  7418. 'Ohungarumlaut': 722,
  7419. 'degree': 400,
  7420. 'ograve': 500,
  7421. 'Ccaron': 667,
  7422. 'ugrave': 500,
  7423. 'radical': 453,
  7424. 'Dcaron': 722,
  7425. 'rcommaaccent': 333,
  7426. 'Ntilde': 722,
  7427. 'otilde': 500,
  7428. 'Rcommaaccent': 667,
  7429. 'Lcommaaccent': 611,
  7430. 'Atilde': 722,
  7431. 'Aogonek': 722,
  7432. 'Aring': 722,
  7433. 'Otilde': 722,
  7434. 'zdotaccent': 444,
  7435. 'Ecaron': 611,
  7436. 'Iogonek': 333,
  7437. 'kcommaaccent': 500,
  7438. 'minus': 564,
  7439. 'Icircumflex': 333,
  7440. 'ncaron': 500,
  7441. 'tcommaaccent': 278,
  7442. 'logicalnot': 564,
  7443. 'odieresis': 500,
  7444. 'udieresis': 500,
  7445. 'notequal': 549,
  7446. 'gcommaaccent': 500,
  7447. 'eth': 500,
  7448. 'zcaron': 444,
  7449. 'ncommaaccent': 500,
  7450. 'onesuperior': 300,
  7451. 'imacron': 278,
  7452. 'Euro': 500
  7453. },
  7454. 'Times-Bold': {
  7455. 'space': 250,
  7456. 'exclam': 333,
  7457. 'quotedbl': 555,
  7458. 'numbersign': 500,
  7459. 'dollar': 500,
  7460. 'percent': 1000,
  7461. 'ampersand': 833,
  7462. 'quoteright': 333,
  7463. 'parenleft': 333,
  7464. 'parenright': 333,
  7465. 'asterisk': 500,
  7466. 'plus': 570,
  7467. 'comma': 250,
  7468. 'hyphen': 333,
  7469. 'period': 250,
  7470. 'slash': 278,
  7471. 'zero': 500,
  7472. 'one': 500,
  7473. 'two': 500,
  7474. 'three': 500,
  7475. 'four': 500,
  7476. 'five': 500,
  7477. 'six': 500,
  7478. 'seven': 500,
  7479. 'eight': 500,
  7480. 'nine': 500,
  7481. 'colon': 333,
  7482. 'semicolon': 333,
  7483. 'less': 570,
  7484. 'equal': 570,
  7485. 'greater': 570,
  7486. 'question': 500,
  7487. 'at': 930,
  7488. 'A': 722,
  7489. 'B': 667,
  7490. 'C': 722,
  7491. 'D': 722,
  7492. 'E': 667,
  7493. 'F': 611,
  7494. 'G': 778,
  7495. 'H': 778,
  7496. 'I': 389,
  7497. 'J': 500,
  7498. 'K': 778,
  7499. 'L': 667,
  7500. 'M': 944,
  7501. 'N': 722,
  7502. 'O': 778,
  7503. 'P': 611,
  7504. 'Q': 778,
  7505. 'R': 722,
  7506. 'S': 556,
  7507. 'T': 667,
  7508. 'U': 722,
  7509. 'V': 722,
  7510. 'W': 1000,
  7511. 'X': 722,
  7512. 'Y': 722,
  7513. 'Z': 667,
  7514. 'bracketleft': 333,
  7515. 'backslash': 278,
  7516. 'bracketright': 333,
  7517. 'asciicircum': 581,
  7518. 'underscore': 500,
  7519. 'quoteleft': 333,
  7520. 'a': 500,
  7521. 'b': 556,
  7522. 'c': 444,
  7523. 'd': 556,
  7524. 'e': 444,
  7525. 'f': 333,
  7526. 'g': 500,
  7527. 'h': 556,
  7528. 'i': 278,
  7529. 'j': 333,
  7530. 'k': 556,
  7531. 'l': 278,
  7532. 'm': 833,
  7533. 'n': 556,
  7534. 'o': 500,
  7535. 'p': 556,
  7536. 'q': 556,
  7537. 'r': 444,
  7538. 's': 389,
  7539. 't': 333,
  7540. 'u': 556,
  7541. 'v': 500,
  7542. 'w': 722,
  7543. 'x': 500,
  7544. 'y': 500,
  7545. 'z': 444,
  7546. 'braceleft': 394,
  7547. 'bar': 220,
  7548. 'braceright': 394,
  7549. 'asciitilde': 520,
  7550. 'exclamdown': 333,
  7551. 'cent': 500,
  7552. 'sterling': 500,
  7553. 'fraction': 167,
  7554. 'yen': 500,
  7555. 'florin': 500,
  7556. 'section': 500,
  7557. 'currency': 500,
  7558. 'quotesingle': 278,
  7559. 'quotedblleft': 500,
  7560. 'guillemotleft': 500,
  7561. 'guilsinglleft': 333,
  7562. 'guilsinglright': 333,
  7563. 'fi': 556,
  7564. 'fl': 556,
  7565. 'endash': 500,
  7566. 'dagger': 500,
  7567. 'daggerdbl': 500,
  7568. 'periodcentered': 250,
  7569. 'paragraph': 540,
  7570. 'bullet': 350,
  7571. 'quotesinglbase': 333,
  7572. 'quotedblbase': 500,
  7573. 'quotedblright': 500,
  7574. 'guillemotright': 500,
  7575. 'ellipsis': 1000,
  7576. 'perthousand': 1000,
  7577. 'questiondown': 500,
  7578. 'grave': 333,
  7579. 'acute': 333,
  7580. 'circumflex': 333,
  7581. 'tilde': 333,
  7582. 'macron': 333,
  7583. 'breve': 333,
  7584. 'dotaccent': 333,
  7585. 'dieresis': 333,
  7586. 'ring': 333,
  7587. 'cedilla': 333,
  7588. 'hungarumlaut': 333,
  7589. 'ogonek': 333,
  7590. 'caron': 333,
  7591. 'emdash': 1000,
  7592. 'AE': 1000,
  7593. 'ordfeminine': 300,
  7594. 'Lslash': 667,
  7595. 'Oslash': 778,
  7596. 'OE': 1000,
  7597. 'ordmasculine': 330,
  7598. 'ae': 722,
  7599. 'dotlessi': 278,
  7600. 'lslash': 278,
  7601. 'oslash': 500,
  7602. 'oe': 722,
  7603. 'germandbls': 556,
  7604. 'Idieresis': 389,
  7605. 'eacute': 444,
  7606. 'abreve': 500,
  7607. 'uhungarumlaut': 556,
  7608. 'ecaron': 444,
  7609. 'Ydieresis': 722,
  7610. 'divide': 570,
  7611. 'Yacute': 722,
  7612. 'Acircumflex': 722,
  7613. 'aacute': 500,
  7614. 'Ucircumflex': 722,
  7615. 'yacute': 500,
  7616. 'scommaaccent': 389,
  7617. 'ecircumflex': 444,
  7618. 'Uring': 722,
  7619. 'Udieresis': 722,
  7620. 'aogonek': 500,
  7621. 'Uacute': 722,
  7622. 'uogonek': 556,
  7623. 'Edieresis': 667,
  7624. 'Dcroat': 722,
  7625. 'commaaccent': 250,
  7626. 'copyright': 747,
  7627. 'Emacron': 667,
  7628. 'ccaron': 444,
  7629. 'aring': 500,
  7630. 'Ncommaaccent': 722,
  7631. 'lacute': 278,
  7632. 'agrave': 500,
  7633. 'Tcommaaccent': 667,
  7634. 'Cacute': 722,
  7635. 'atilde': 500,
  7636. 'Edotaccent': 667,
  7637. 'scaron': 389,
  7638. 'scedilla': 389,
  7639. 'iacute': 278,
  7640. 'lozenge': 494,
  7641. 'Rcaron': 722,
  7642. 'Gcommaaccent': 778,
  7643. 'ucircumflex': 556,
  7644. 'acircumflex': 500,
  7645. 'Amacron': 722,
  7646. 'rcaron': 444,
  7647. 'ccedilla': 444,
  7648. 'Zdotaccent': 667,
  7649. 'Thorn': 611,
  7650. 'Omacron': 778,
  7651. 'Racute': 722,
  7652. 'Sacute': 556,
  7653. 'dcaron': 672,
  7654. 'Umacron': 722,
  7655. 'uring': 556,
  7656. 'threesuperior': 300,
  7657. 'Ograve': 778,
  7658. 'Agrave': 722,
  7659. 'Abreve': 722,
  7660. 'multiply': 570,
  7661. 'uacute': 556,
  7662. 'Tcaron': 667,
  7663. 'partialdiff': 494,
  7664. 'ydieresis': 500,
  7665. 'Nacute': 722,
  7666. 'icircumflex': 278,
  7667. 'Ecircumflex': 667,
  7668. 'adieresis': 500,
  7669. 'edieresis': 444,
  7670. 'cacute': 444,
  7671. 'nacute': 556,
  7672. 'umacron': 556,
  7673. 'Ncaron': 722,
  7674. 'Iacute': 389,
  7675. 'plusminus': 570,
  7676. 'brokenbar': 220,
  7677. 'registered': 747,
  7678. 'Gbreve': 778,
  7679. 'Idotaccent': 389,
  7680. 'summation': 600,
  7681. 'Egrave': 667,
  7682. 'racute': 444,
  7683. 'omacron': 500,
  7684. 'Zacute': 667,
  7685. 'Zcaron': 667,
  7686. 'greaterequal': 549,
  7687. 'Eth': 722,
  7688. 'Ccedilla': 722,
  7689. 'lcommaaccent': 278,
  7690. 'tcaron': 416,
  7691. 'eogonek': 444,
  7692. 'Uogonek': 722,
  7693. 'Aacute': 722,
  7694. 'Adieresis': 722,
  7695. 'egrave': 444,
  7696. 'zacute': 444,
  7697. 'iogonek': 278,
  7698. 'Oacute': 778,
  7699. 'oacute': 500,
  7700. 'amacron': 500,
  7701. 'sacute': 389,
  7702. 'idieresis': 278,
  7703. 'Ocircumflex': 778,
  7704. 'Ugrave': 722,
  7705. 'Delta': 612,
  7706. 'thorn': 556,
  7707. 'twosuperior': 300,
  7708. 'Odieresis': 778,
  7709. 'mu': 556,
  7710. 'igrave': 278,
  7711. 'ohungarumlaut': 500,
  7712. 'Eogonek': 667,
  7713. 'dcroat': 556,
  7714. 'threequarters': 750,
  7715. 'Scedilla': 556,
  7716. 'lcaron': 394,
  7717. 'Kcommaaccent': 778,
  7718. 'Lacute': 667,
  7719. 'trademark': 1000,
  7720. 'edotaccent': 444,
  7721. 'Igrave': 389,
  7722. 'Imacron': 389,
  7723. 'Lcaron': 667,
  7724. 'onehalf': 750,
  7725. 'lessequal': 549,
  7726. 'ocircumflex': 500,
  7727. 'ntilde': 556,
  7728. 'Uhungarumlaut': 722,
  7729. 'Eacute': 667,
  7730. 'emacron': 444,
  7731. 'gbreve': 500,
  7732. 'onequarter': 750,
  7733. 'Scaron': 556,
  7734. 'Scommaaccent': 556,
  7735. 'Ohungarumlaut': 778,
  7736. 'degree': 400,
  7737. 'ograve': 500,
  7738. 'Ccaron': 722,
  7739. 'ugrave': 556,
  7740. 'radical': 549,
  7741. 'Dcaron': 722,
  7742. 'rcommaaccent': 444,
  7743. 'Ntilde': 722,
  7744. 'otilde': 500,
  7745. 'Rcommaaccent': 722,
  7746. 'Lcommaaccent': 667,
  7747. 'Atilde': 722,
  7748. 'Aogonek': 722,
  7749. 'Aring': 722,
  7750. 'Otilde': 778,
  7751. 'zdotaccent': 444,
  7752. 'Ecaron': 667,
  7753. 'Iogonek': 389,
  7754. 'kcommaaccent': 556,
  7755. 'minus': 570,
  7756. 'Icircumflex': 389,
  7757. 'ncaron': 556,
  7758. 'tcommaaccent': 333,
  7759. 'logicalnot': 570,
  7760. 'odieresis': 500,
  7761. 'udieresis': 556,
  7762. 'notequal': 549,
  7763. 'gcommaaccent': 500,
  7764. 'eth': 500,
  7765. 'zcaron': 444,
  7766. 'ncommaaccent': 556,
  7767. 'onesuperior': 300,
  7768. 'imacron': 278,
  7769. 'Euro': 500
  7770. },
  7771. 'Times-BoldItalic': {
  7772. 'space': 250,
  7773. 'exclam': 389,
  7774. 'quotedbl': 555,
  7775. 'numbersign': 500,
  7776. 'dollar': 500,
  7777. 'percent': 833,
  7778. 'ampersand': 778,
  7779. 'quoteright': 333,
  7780. 'parenleft': 333,
  7781. 'parenright': 333,
  7782. 'asterisk': 500,
  7783. 'plus': 570,
  7784. 'comma': 250,
  7785. 'hyphen': 333,
  7786. 'period': 250,
  7787. 'slash': 278,
  7788. 'zero': 500,
  7789. 'one': 500,
  7790. 'two': 500,
  7791. 'three': 500,
  7792. 'four': 500,
  7793. 'five': 500,
  7794. 'six': 500,
  7795. 'seven': 500,
  7796. 'eight': 500,
  7797. 'nine': 500,
  7798. 'colon': 333,
  7799. 'semicolon': 333,
  7800. 'less': 570,
  7801. 'equal': 570,
  7802. 'greater': 570,
  7803. 'question': 500,
  7804. 'at': 832,
  7805. 'A': 667,
  7806. 'B': 667,
  7807. 'C': 667,
  7808. 'D': 722,
  7809. 'E': 667,
  7810. 'F': 667,
  7811. 'G': 722,
  7812. 'H': 778,
  7813. 'I': 389,
  7814. 'J': 500,
  7815. 'K': 667,
  7816. 'L': 611,
  7817. 'M': 889,
  7818. 'N': 722,
  7819. 'O': 722,
  7820. 'P': 611,
  7821. 'Q': 722,
  7822. 'R': 667,
  7823. 'S': 556,
  7824. 'T': 611,
  7825. 'U': 722,
  7826. 'V': 667,
  7827. 'W': 889,
  7828. 'X': 667,
  7829. 'Y': 611,
  7830. 'Z': 611,
  7831. 'bracketleft': 333,
  7832. 'backslash': 278,
  7833. 'bracketright': 333,
  7834. 'asciicircum': 570,
  7835. 'underscore': 500,
  7836. 'quoteleft': 333,
  7837. 'a': 500,
  7838. 'b': 500,
  7839. 'c': 444,
  7840. 'd': 500,
  7841. 'e': 444,
  7842. 'f': 333,
  7843. 'g': 500,
  7844. 'h': 556,
  7845. 'i': 278,
  7846. 'j': 278,
  7847. 'k': 500,
  7848. 'l': 278,
  7849. 'm': 778,
  7850. 'n': 556,
  7851. 'o': 500,
  7852. 'p': 500,
  7853. 'q': 500,
  7854. 'r': 389,
  7855. 's': 389,
  7856. 't': 278,
  7857. 'u': 556,
  7858. 'v': 444,
  7859. 'w': 667,
  7860. 'x': 500,
  7861. 'y': 444,
  7862. 'z': 389,
  7863. 'braceleft': 348,
  7864. 'bar': 220,
  7865. 'braceright': 348,
  7866. 'asciitilde': 570,
  7867. 'exclamdown': 389,
  7868. 'cent': 500,
  7869. 'sterling': 500,
  7870. 'fraction': 167,
  7871. 'yen': 500,
  7872. 'florin': 500,
  7873. 'section': 500,
  7874. 'currency': 500,
  7875. 'quotesingle': 278,
  7876. 'quotedblleft': 500,
  7877. 'guillemotleft': 500,
  7878. 'guilsinglleft': 333,
  7879. 'guilsinglright': 333,
  7880. 'fi': 556,
  7881. 'fl': 556,
  7882. 'endash': 500,
  7883. 'dagger': 500,
  7884. 'daggerdbl': 500,
  7885. 'periodcentered': 250,
  7886. 'paragraph': 500,
  7887. 'bullet': 350,
  7888. 'quotesinglbase': 333,
  7889. 'quotedblbase': 500,
  7890. 'quotedblright': 500,
  7891. 'guillemotright': 500,
  7892. 'ellipsis': 1000,
  7893. 'perthousand': 1000,
  7894. 'questiondown': 500,
  7895. 'grave': 333,
  7896. 'acute': 333,
  7897. 'circumflex': 333,
  7898. 'tilde': 333,
  7899. 'macron': 333,
  7900. 'breve': 333,
  7901. 'dotaccent': 333,
  7902. 'dieresis': 333,
  7903. 'ring': 333,
  7904. 'cedilla': 333,
  7905. 'hungarumlaut': 333,
  7906. 'ogonek': 333,
  7907. 'caron': 333,
  7908. 'emdash': 1000,
  7909. 'AE': 944,
  7910. 'ordfeminine': 266,
  7911. 'Lslash': 611,
  7912. 'Oslash': 722,
  7913. 'OE': 944,
  7914. 'ordmasculine': 300,
  7915. 'ae': 722,
  7916. 'dotlessi': 278,
  7917. 'lslash': 278,
  7918. 'oslash': 500,
  7919. 'oe': 722,
  7920. 'germandbls': 500,
  7921. 'Idieresis': 389,
  7922. 'eacute': 444,
  7923. 'abreve': 500,
  7924. 'uhungarumlaut': 556,
  7925. 'ecaron': 444,
  7926. 'Ydieresis': 611,
  7927. 'divide': 570,
  7928. 'Yacute': 611,
  7929. 'Acircumflex': 667,
  7930. 'aacute': 500,
  7931. 'Ucircumflex': 722,
  7932. 'yacute': 444,
  7933. 'scommaaccent': 389,
  7934. 'ecircumflex': 444,
  7935. 'Uring': 722,
  7936. 'Udieresis': 722,
  7937. 'aogonek': 500,
  7938. 'Uacute': 722,
  7939. 'uogonek': 556,
  7940. 'Edieresis': 667,
  7941. 'Dcroat': 722,
  7942. 'commaaccent': 250,
  7943. 'copyright': 747,
  7944. 'Emacron': 667,
  7945. 'ccaron': 444,
  7946. 'aring': 500,
  7947. 'Ncommaaccent': 722,
  7948. 'lacute': 278,
  7949. 'agrave': 500,
  7950. 'Tcommaaccent': 611,
  7951. 'Cacute': 667,
  7952. 'atilde': 500,
  7953. 'Edotaccent': 667,
  7954. 'scaron': 389,
  7955. 'scedilla': 389,
  7956. 'iacute': 278,
  7957. 'lozenge': 494,
  7958. 'Rcaron': 667,
  7959. 'Gcommaaccent': 722,
  7960. 'ucircumflex': 556,
  7961. 'acircumflex': 500,
  7962. 'Amacron': 667,
  7963. 'rcaron': 389,
  7964. 'ccedilla': 444,
  7965. 'Zdotaccent': 611,
  7966. 'Thorn': 611,
  7967. 'Omacron': 722,
  7968. 'Racute': 667,
  7969. 'Sacute': 556,
  7970. 'dcaron': 608,
  7971. 'Umacron': 722,
  7972. 'uring': 556,
  7973. 'threesuperior': 300,
  7974. 'Ograve': 722,
  7975. 'Agrave': 667,
  7976. 'Abreve': 667,
  7977. 'multiply': 570,
  7978. 'uacute': 556,
  7979. 'Tcaron': 611,
  7980. 'partialdiff': 494,
  7981. 'ydieresis': 444,
  7982. 'Nacute': 722,
  7983. 'icircumflex': 278,
  7984. 'Ecircumflex': 667,
  7985. 'adieresis': 500,
  7986. 'edieresis': 444,
  7987. 'cacute': 444,
  7988. 'nacute': 556,
  7989. 'umacron': 556,
  7990. 'Ncaron': 722,
  7991. 'Iacute': 389,
  7992. 'plusminus': 570,
  7993. 'brokenbar': 220,
  7994. 'registered': 747,
  7995. 'Gbreve': 722,
  7996. 'Idotaccent': 389,
  7997. 'summation': 600,
  7998. 'Egrave': 667,
  7999. 'racute': 389,
  8000. 'omacron': 500,
  8001. 'Zacute': 611,
  8002. 'Zcaron': 611,
  8003. 'greaterequal': 549,
  8004. 'Eth': 722,
  8005. 'Ccedilla': 667,
  8006. 'lcommaaccent': 278,
  8007. 'tcaron': 366,
  8008. 'eogonek': 444,
  8009. 'Uogonek': 722,
  8010. 'Aacute': 667,
  8011. 'Adieresis': 667,
  8012. 'egrave': 444,
  8013. 'zacute': 389,
  8014. 'iogonek': 278,
  8015. 'Oacute': 722,
  8016. 'oacute': 500,
  8017. 'amacron': 500,
  8018. 'sacute': 389,
  8019. 'idieresis': 278,
  8020. 'Ocircumflex': 722,
  8021. 'Ugrave': 722,
  8022. 'Delta': 612,
  8023. 'thorn': 500,
  8024. 'twosuperior': 300,
  8025. 'Odieresis': 722,
  8026. 'mu': 576,
  8027. 'igrave': 278,
  8028. 'ohungarumlaut': 500,
  8029. 'Eogonek': 667,
  8030. 'dcroat': 500,
  8031. 'threequarters': 750,
  8032. 'Scedilla': 556,
  8033. 'lcaron': 382,
  8034. 'Kcommaaccent': 667,
  8035. 'Lacute': 611,
  8036. 'trademark': 1000,
  8037. 'edotaccent': 444,
  8038. 'Igrave': 389,
  8039. 'Imacron': 389,
  8040. 'Lcaron': 611,
  8041. 'onehalf': 750,
  8042. 'lessequal': 549,
  8043. 'ocircumflex': 500,
  8044. 'ntilde': 556,
  8045. 'Uhungarumlaut': 722,
  8046. 'Eacute': 667,
  8047. 'emacron': 444,
  8048. 'gbreve': 500,
  8049. 'onequarter': 750,
  8050. 'Scaron': 556,
  8051. 'Scommaaccent': 556,
  8052. 'Ohungarumlaut': 722,
  8053. 'degree': 400,
  8054. 'ograve': 500,
  8055. 'Ccaron': 667,
  8056. 'ugrave': 556,
  8057. 'radical': 549,
  8058. 'Dcaron': 722,
  8059. 'rcommaaccent': 389,
  8060. 'Ntilde': 722,
  8061. 'otilde': 500,
  8062. 'Rcommaaccent': 667,
  8063. 'Lcommaaccent': 611,
  8064. 'Atilde': 667,
  8065. 'Aogonek': 667,
  8066. 'Aring': 667,
  8067. 'Otilde': 722,
  8068. 'zdotaccent': 389,
  8069. 'Ecaron': 667,
  8070. 'Iogonek': 389,
  8071. 'kcommaaccent': 500,
  8072. 'minus': 606,
  8073. 'Icircumflex': 389,
  8074. 'ncaron': 556,
  8075. 'tcommaaccent': 278,
  8076. 'logicalnot': 606,
  8077. 'odieresis': 500,
  8078. 'udieresis': 556,
  8079. 'notequal': 549,
  8080. 'gcommaaccent': 500,
  8081. 'eth': 500,
  8082. 'zcaron': 389,
  8083. 'ncommaaccent': 556,
  8084. 'onesuperior': 300,
  8085. 'imacron': 278,
  8086. 'Euro': 500
  8087. },
  8088. 'Times-Italic': {
  8089. 'space': 250,
  8090. 'exclam': 333,
  8091. 'quotedbl': 420,
  8092. 'numbersign': 500,
  8093. 'dollar': 500,
  8094. 'percent': 833,
  8095. 'ampersand': 778,
  8096. 'quoteright': 333,
  8097. 'parenleft': 333,
  8098. 'parenright': 333,
  8099. 'asterisk': 500,
  8100. 'plus': 675,
  8101. 'comma': 250,
  8102. 'hyphen': 333,
  8103. 'period': 250,
  8104. 'slash': 278,
  8105. 'zero': 500,
  8106. 'one': 500,
  8107. 'two': 500,
  8108. 'three': 500,
  8109. 'four': 500,
  8110. 'five': 500,
  8111. 'six': 500,
  8112. 'seven': 500,
  8113. 'eight': 500,
  8114. 'nine': 500,
  8115. 'colon': 333,
  8116. 'semicolon': 333,
  8117. 'less': 675,
  8118. 'equal': 675,
  8119. 'greater': 675,
  8120. 'question': 500,
  8121. 'at': 920,
  8122. 'A': 611,
  8123. 'B': 611,
  8124. 'C': 667,
  8125. 'D': 722,
  8126. 'E': 611,
  8127. 'F': 611,
  8128. 'G': 722,
  8129. 'H': 722,
  8130. 'I': 333,
  8131. 'J': 444,
  8132. 'K': 667,
  8133. 'L': 556,
  8134. 'M': 833,
  8135. 'N': 667,
  8136. 'O': 722,
  8137. 'P': 611,
  8138. 'Q': 722,
  8139. 'R': 611,
  8140. 'S': 500,
  8141. 'T': 556,
  8142. 'U': 722,
  8143. 'V': 611,
  8144. 'W': 833,
  8145. 'X': 611,
  8146. 'Y': 556,
  8147. 'Z': 556,
  8148. 'bracketleft': 389,
  8149. 'backslash': 278,
  8150. 'bracketright': 389,
  8151. 'asciicircum': 422,
  8152. 'underscore': 500,
  8153. 'quoteleft': 333,
  8154. 'a': 500,
  8155. 'b': 500,
  8156. 'c': 444,
  8157. 'd': 500,
  8158. 'e': 444,
  8159. 'f': 278,
  8160. 'g': 500,
  8161. 'h': 500,
  8162. 'i': 278,
  8163. 'j': 278,
  8164. 'k': 444,
  8165. 'l': 278,
  8166. 'm': 722,
  8167. 'n': 500,
  8168. 'o': 500,
  8169. 'p': 500,
  8170. 'q': 500,
  8171. 'r': 389,
  8172. 's': 389,
  8173. 't': 278,
  8174. 'u': 500,
  8175. 'v': 444,
  8176. 'w': 667,
  8177. 'x': 444,
  8178. 'y': 444,
  8179. 'z': 389,
  8180. 'braceleft': 400,
  8181. 'bar': 275,
  8182. 'braceright': 400,
  8183. 'asciitilde': 541,
  8184. 'exclamdown': 389,
  8185. 'cent': 500,
  8186. 'sterling': 500,
  8187. 'fraction': 167,
  8188. 'yen': 500,
  8189. 'florin': 500,
  8190. 'section': 500,
  8191. 'currency': 500,
  8192. 'quotesingle': 214,
  8193. 'quotedblleft': 556,
  8194. 'guillemotleft': 500,
  8195. 'guilsinglleft': 333,
  8196. 'guilsinglright': 333,
  8197. 'fi': 500,
  8198. 'fl': 500,
  8199. 'endash': 500,
  8200. 'dagger': 500,
  8201. 'daggerdbl': 500,
  8202. 'periodcentered': 250,
  8203. 'paragraph': 523,
  8204. 'bullet': 350,
  8205. 'quotesinglbase': 333,
  8206. 'quotedblbase': 556,
  8207. 'quotedblright': 556,
  8208. 'guillemotright': 500,
  8209. 'ellipsis': 889,
  8210. 'perthousand': 1000,
  8211. 'questiondown': 500,
  8212. 'grave': 333,
  8213. 'acute': 333,
  8214. 'circumflex': 333,
  8215. 'tilde': 333,
  8216. 'macron': 333,
  8217. 'breve': 333,
  8218. 'dotaccent': 333,
  8219. 'dieresis': 333,
  8220. 'ring': 333,
  8221. 'cedilla': 333,
  8222. 'hungarumlaut': 333,
  8223. 'ogonek': 333,
  8224. 'caron': 333,
  8225. 'emdash': 889,
  8226. 'AE': 889,
  8227. 'ordfeminine': 276,
  8228. 'Lslash': 556,
  8229. 'Oslash': 722,
  8230. 'OE': 944,
  8231. 'ordmasculine': 310,
  8232. 'ae': 667,
  8233. 'dotlessi': 278,
  8234. 'lslash': 278,
  8235. 'oslash': 500,
  8236. 'oe': 667,
  8237. 'germandbls': 500,
  8238. 'Idieresis': 333,
  8239. 'eacute': 444,
  8240. 'abreve': 500,
  8241. 'uhungarumlaut': 500,
  8242. 'ecaron': 444,
  8243. 'Ydieresis': 556,
  8244. 'divide': 675,
  8245. 'Yacute': 556,
  8246. 'Acircumflex': 611,
  8247. 'aacute': 500,
  8248. 'Ucircumflex': 722,
  8249. 'yacute': 444,
  8250. 'scommaaccent': 389,
  8251. 'ecircumflex': 444,
  8252. 'Uring': 722,
  8253. 'Udieresis': 722,
  8254. 'aogonek': 500,
  8255. 'Uacute': 722,
  8256. 'uogonek': 500,
  8257. 'Edieresis': 611,
  8258. 'Dcroat': 722,
  8259. 'commaaccent': 250,
  8260. 'copyright': 760,
  8261. 'Emacron': 611,
  8262. 'ccaron': 444,
  8263. 'aring': 500,
  8264. 'Ncommaaccent': 667,
  8265. 'lacute': 278,
  8266. 'agrave': 500,
  8267. 'Tcommaaccent': 556,
  8268. 'Cacute': 667,
  8269. 'atilde': 500,
  8270. 'Edotaccent': 611,
  8271. 'scaron': 389,
  8272. 'scedilla': 389,
  8273. 'iacute': 278,
  8274. 'lozenge': 471,
  8275. 'Rcaron': 611,
  8276. 'Gcommaaccent': 722,
  8277. 'ucircumflex': 500,
  8278. 'acircumflex': 500,
  8279. 'Amacron': 611,
  8280. 'rcaron': 389,
  8281. 'ccedilla': 444,
  8282. 'Zdotaccent': 556,
  8283. 'Thorn': 611,
  8284. 'Omacron': 722,
  8285. 'Racute': 611,
  8286. 'Sacute': 500,
  8287. 'dcaron': 544,
  8288. 'Umacron': 722,
  8289. 'uring': 500,
  8290. 'threesuperior': 300,
  8291. 'Ograve': 722,
  8292. 'Agrave': 611,
  8293. 'Abreve': 611,
  8294. 'multiply': 675,
  8295. 'uacute': 500,
  8296. 'Tcaron': 556,
  8297. 'partialdiff': 476,
  8298. 'ydieresis': 444,
  8299. 'Nacute': 667,
  8300. 'icircumflex': 278,
  8301. 'Ecircumflex': 611,
  8302. 'adieresis': 500,
  8303. 'edieresis': 444,
  8304. 'cacute': 444,
  8305. 'nacute': 500,
  8306. 'umacron': 500,
  8307. 'Ncaron': 667,
  8308. 'Iacute': 333,
  8309. 'plusminus': 675,
  8310. 'brokenbar': 275,
  8311. 'registered': 760,
  8312. 'Gbreve': 722,
  8313. 'Idotaccent': 333,
  8314. 'summation': 600,
  8315. 'Egrave': 611,
  8316. 'racute': 389,
  8317. 'omacron': 500,
  8318. 'Zacute': 556,
  8319. 'Zcaron': 556,
  8320. 'greaterequal': 549,
  8321. 'Eth': 722,
  8322. 'Ccedilla': 667,
  8323. 'lcommaaccent': 278,
  8324. 'tcaron': 300,
  8325. 'eogonek': 444,
  8326. 'Uogonek': 722,
  8327. 'Aacute': 611,
  8328. 'Adieresis': 611,
  8329. 'egrave': 444,
  8330. 'zacute': 389,
  8331. 'iogonek': 278,
  8332. 'Oacute': 722,
  8333. 'oacute': 500,
  8334. 'amacron': 500,
  8335. 'sacute': 389,
  8336. 'idieresis': 278,
  8337. 'Ocircumflex': 722,
  8338. 'Ugrave': 722,
  8339. 'Delta': 612,
  8340. 'thorn': 500,
  8341. 'twosuperior': 300,
  8342. 'Odieresis': 722,
  8343. 'mu': 500,
  8344. 'igrave': 278,
  8345. 'ohungarumlaut': 500,
  8346. 'Eogonek': 611,
  8347. 'dcroat': 500,
  8348. 'threequarters': 750,
  8349. 'Scedilla': 500,
  8350. 'lcaron': 300,
  8351. 'Kcommaaccent': 667,
  8352. 'Lacute': 556,
  8353. 'trademark': 980,
  8354. 'edotaccent': 444,
  8355. 'Igrave': 333,
  8356. 'Imacron': 333,
  8357. 'Lcaron': 611,
  8358. 'onehalf': 750,
  8359. 'lessequal': 549,
  8360. 'ocircumflex': 500,
  8361. 'ntilde': 500,
  8362. 'Uhungarumlaut': 722,
  8363. 'Eacute': 611,
  8364. 'emacron': 444,
  8365. 'gbreve': 500,
  8366. 'onequarter': 750,
  8367. 'Scaron': 500,
  8368. 'Scommaaccent': 500,
  8369. 'Ohungarumlaut': 722,
  8370. 'degree': 400,
  8371. 'ograve': 500,
  8372. 'Ccaron': 667,
  8373. 'ugrave': 500,
  8374. 'radical': 453,
  8375. 'Dcaron': 722,
  8376. 'rcommaaccent': 389,
  8377. 'Ntilde': 667,
  8378. 'otilde': 500,
  8379. 'Rcommaaccent': 611,
  8380. 'Lcommaaccent': 556,
  8381. 'Atilde': 611,
  8382. 'Aogonek': 611,
  8383. 'Aring': 611,
  8384. 'Otilde': 722,
  8385. 'zdotaccent': 389,
  8386. 'Ecaron': 611,
  8387. 'Iogonek': 333,
  8388. 'kcommaaccent': 444,
  8389. 'minus': 675,
  8390. 'Icircumflex': 333,
  8391. 'ncaron': 500,
  8392. 'tcommaaccent': 278,
  8393. 'logicalnot': 675,
  8394. 'odieresis': 500,
  8395. 'udieresis': 500,
  8396. 'notequal': 549,
  8397. 'gcommaaccent': 500,
  8398. 'eth': 500,
  8399. 'zcaron': 389,
  8400. 'ncommaaccent': 500,
  8401. 'onesuperior': 300,
  8402. 'imacron': 278,
  8403. 'Euro': 500
  8404. },
  8405. 'ZapfDingbats': {
  8406. 'space': 278,
  8407. 'a1': 974,
  8408. 'a2': 961,
  8409. 'a202': 974,
  8410. 'a3': 980,
  8411. 'a4': 719,
  8412. 'a5': 789,
  8413. 'a119': 790,
  8414. 'a118': 791,
  8415. 'a117': 690,
  8416. 'a11': 960,
  8417. 'a12': 939,
  8418. 'a13': 549,
  8419. 'a14': 855,
  8420. 'a15': 911,
  8421. 'a16': 933,
  8422. 'a105': 911,
  8423. 'a17': 945,
  8424. 'a18': 974,
  8425. 'a19': 755,
  8426. 'a20': 846,
  8427. 'a21': 762,
  8428. 'a22': 761,
  8429. 'a23': 571,
  8430. 'a24': 677,
  8431. 'a25': 763,
  8432. 'a26': 760,
  8433. 'a27': 759,
  8434. 'a28': 754,
  8435. 'a6': 494,
  8436. 'a7': 552,
  8437. 'a8': 537,
  8438. 'a9': 577,
  8439. 'a10': 692,
  8440. 'a29': 786,
  8441. 'a30': 788,
  8442. 'a31': 788,
  8443. 'a32': 790,
  8444. 'a33': 793,
  8445. 'a34': 794,
  8446. 'a35': 816,
  8447. 'a36': 823,
  8448. 'a37': 789,
  8449. 'a38': 841,
  8450. 'a39': 823,
  8451. 'a40': 833,
  8452. 'a41': 816,
  8453. 'a42': 831,
  8454. 'a43': 923,
  8455. 'a44': 744,
  8456. 'a45': 723,
  8457. 'a46': 749,
  8458. 'a47': 790,
  8459. 'a48': 792,
  8460. 'a49': 695,
  8461. 'a50': 776,
  8462. 'a51': 768,
  8463. 'a52': 792,
  8464. 'a53': 759,
  8465. 'a54': 707,
  8466. 'a55': 708,
  8467. 'a56': 682,
  8468. 'a57': 701,
  8469. 'a58': 826,
  8470. 'a59': 815,
  8471. 'a60': 789,
  8472. 'a61': 789,
  8473. 'a62': 707,
  8474. 'a63': 687,
  8475. 'a64': 696,
  8476. 'a65': 689,
  8477. 'a66': 786,
  8478. 'a67': 787,
  8479. 'a68': 713,
  8480. 'a69': 791,
  8481. 'a70': 785,
  8482. 'a71': 791,
  8483. 'a72': 873,
  8484. 'a73': 761,
  8485. 'a74': 762,
  8486. 'a203': 762,
  8487. 'a75': 759,
  8488. 'a204': 759,
  8489. 'a76': 892,
  8490. 'a77': 892,
  8491. 'a78': 788,
  8492. 'a79': 784,
  8493. 'a81': 438,
  8494. 'a82': 138,
  8495. 'a83': 277,
  8496. 'a84': 415,
  8497. 'a97': 392,
  8498. 'a98': 392,
  8499. 'a99': 668,
  8500. 'a100': 668,
  8501. 'a89': 390,
  8502. 'a90': 390,
  8503. 'a93': 317,
  8504. 'a94': 317,
  8505. 'a91': 276,
  8506. 'a92': 276,
  8507. 'a205': 509,
  8508. 'a85': 509,
  8509. 'a206': 410,
  8510. 'a86': 410,
  8511. 'a87': 234,
  8512. 'a88': 234,
  8513. 'a95': 334,
  8514. 'a96': 334,
  8515. 'a101': 732,
  8516. 'a102': 544,
  8517. 'a103': 544,
  8518. 'a104': 910,
  8519. 'a106': 667,
  8520. 'a107': 760,
  8521. 'a108': 760,
  8522. 'a112': 776,
  8523. 'a111': 595,
  8524. 'a110': 694,
  8525. 'a109': 626,
  8526. 'a120': 788,
  8527. 'a121': 788,
  8528. 'a122': 788,
  8529. 'a123': 788,
  8530. 'a124': 788,
  8531. 'a125': 788,
  8532. 'a126': 788,
  8533. 'a127': 788,
  8534. 'a128': 788,
  8535. 'a129': 788,
  8536. 'a130': 788,
  8537. 'a131': 788,
  8538. 'a132': 788,
  8539. 'a133': 788,
  8540. 'a134': 788,
  8541. 'a135': 788,
  8542. 'a136': 788,
  8543. 'a137': 788,
  8544. 'a138': 788,
  8545. 'a139': 788,
  8546. 'a140': 788,
  8547. 'a141': 788,
  8548. 'a142': 788,
  8549. 'a143': 788,
  8550. 'a144': 788,
  8551. 'a145': 788,
  8552. 'a146': 788,
  8553. 'a147': 788,
  8554. 'a148': 788,
  8555. 'a149': 788,
  8556. 'a150': 788,
  8557. 'a151': 788,
  8558. 'a152': 788,
  8559. 'a153': 788,
  8560. 'a154': 788,
  8561. 'a155': 788,
  8562. 'a156': 788,
  8563. 'a157': 788,
  8564. 'a158': 788,
  8565. 'a159': 788,
  8566. 'a160': 894,
  8567. 'a161': 838,
  8568. 'a163': 1016,
  8569. 'a164': 458,
  8570. 'a196': 748,
  8571. 'a165': 924,
  8572. 'a192': 748,
  8573. 'a166': 918,
  8574. 'a167': 927,
  8575. 'a168': 928,
  8576. 'a169': 928,
  8577. 'a170': 834,
  8578. 'a171': 873,
  8579. 'a172': 828,
  8580. 'a173': 924,
  8581. 'a162': 924,
  8582. 'a174': 917,
  8583. 'a175': 930,
  8584. 'a176': 931,
  8585. 'a177': 463,
  8586. 'a178': 883,
  8587. 'a179': 836,
  8588. 'a193': 836,
  8589. 'a180': 867,
  8590. 'a199': 867,
  8591. 'a181': 696,
  8592. 'a200': 696,
  8593. 'a182': 874,
  8594. 'a201': 874,
  8595. 'a183': 760,
  8596. 'a184': 946,
  8597. 'a197': 771,
  8598. 'a185': 865,
  8599. 'a194': 771,
  8600. 'a198': 888,
  8601. 'a186': 967,
  8602. 'a195': 888,
  8603. 'a187': 831,
  8604. 'a188': 873,
  8605. 'a189': 927,
  8606. 'a190': 970,
  8607. 'a191': 918
  8608. }
  8609. };
  8610. exports.Metrics = Metrics;
  8611. }));
  8612. var NetworkManager = (function NetworkManagerClosure() {
  8613. var OK_RESPONSE = 200;
  8614. var PARTIAL_CONTENT_RESPONSE = 206;
  8615. function NetworkManager(url, args) {
  8616. this.url = url;
  8617. args = args || {};
  8618. this.isHttp = /^https?:/i.test(url);
  8619. this.httpHeaders = (this.isHttp && args.httpHeaders) || {};
  8620. this.withCredentials = args.withCredentials || false;
  8621. this.getXhr = args.getXhr ||
  8622. function NetworkManager_getXhr() {
  8623. return new XMLHttpRequest();
  8624. };
  8625. this.currXhrId = 0;
  8626. this.pendingRequests = {};
  8627. this.loadedRequests = {};
  8628. }
  8629. function getArrayBuffer(xhr) {
  8630. var data = xhr.response;
  8631. if (typeof data !== 'string') {
  8632. return data;
  8633. }
  8634. var length = data.length;
  8635. var array = new Uint8Array(length);
  8636. for (var i = 0; i < length; i++) {
  8637. array[i] = data.charCodeAt(i) & 0xFF;
  8638. }
  8639. return array.buffer;
  8640. }
  8641. var supportsMozChunked = (function supportsMozChunkedClosure() {
  8642. try {
  8643. var x = new XMLHttpRequest();
  8644. // Firefox 37- required .open() to be called before setting responseType.
  8645. // https://bugzilla.mozilla.org/show_bug.cgi?id=707484
  8646. // Even though the URL is not visited, .open() could fail if the URL is
  8647. // blocked, e.g. via the connect-src CSP directive or the NoScript addon.
  8648. // When this error occurs, this feature detection method will mistakenly
  8649. // report that moz-chunked-arraybuffer is not supported in Firefox 37-.
  8650. x.open('GET', 'https://example.com');
  8651. x.responseType = 'moz-chunked-arraybuffer';
  8652. return x.responseType === 'moz-chunked-arraybuffer';
  8653. } catch (e) {
  8654. return false;
  8655. }
  8656. })();
  8657. NetworkManager.prototype = {
  8658. requestRange: function NetworkManager_requestRange(begin, end, listeners) {
  8659. var args = {
  8660. begin: begin,
  8661. end: end
  8662. };
  8663. for (var prop in listeners) {
  8664. args[prop] = listeners[prop];
  8665. }
  8666. return this.request(args);
  8667. },
  8668. requestFull: function NetworkManager_requestFull(listeners) {
  8669. return this.request(listeners);
  8670. },
  8671. request: function NetworkManager_request(args) {
  8672. var xhr = this.getXhr();
  8673. var xhrId = this.currXhrId++;
  8674. var pendingRequest = this.pendingRequests[xhrId] = {
  8675. xhr: xhr
  8676. };
  8677. xhr.open('GET', this.url);
  8678. xhr.withCredentials = this.withCredentials;
  8679. for (var property in this.httpHeaders) {
  8680. var value = this.httpHeaders[property];
  8681. if (typeof value === 'undefined') {
  8682. continue;
  8683. }
  8684. xhr.setRequestHeader(property, value);
  8685. }
  8686. if (this.isHttp && 'begin' in args && 'end' in args) {
  8687. var rangeStr = args.begin + '-' + (args.end - 1);
  8688. xhr.setRequestHeader('Range', 'bytes=' + rangeStr);
  8689. pendingRequest.expectedStatus = 206;
  8690. } else {
  8691. pendingRequest.expectedStatus = 200;
  8692. }
  8693. var useMozChunkedLoading = supportsMozChunked && !!args.onProgressiveData;
  8694. if (useMozChunkedLoading) {
  8695. xhr.responseType = 'moz-chunked-arraybuffer';
  8696. pendingRequest.onProgressiveData = args.onProgressiveData;
  8697. pendingRequest.mozChunked = true;
  8698. } else {
  8699. xhr.responseType = 'arraybuffer';
  8700. }
  8701. if (args.onError) {
  8702. xhr.onerror = function(evt) {
  8703. args.onError(xhr.status);
  8704. };
  8705. }
  8706. xhr.onreadystatechange = this.onStateChange.bind(this, xhrId);
  8707. xhr.onprogress = this.onProgress.bind(this, xhrId);
  8708. pendingRequest.onHeadersReceived = args.onHeadersReceived;
  8709. pendingRequest.onDone = args.onDone;
  8710. pendingRequest.onError = args.onError;
  8711. pendingRequest.onProgress = args.onProgress;
  8712. xhr.send(null);
  8713. return xhrId;
  8714. },
  8715. onProgress: function NetworkManager_onProgress(xhrId, evt) {
  8716. var pendingRequest = this.pendingRequests[xhrId];
  8717. if (!pendingRequest) {
  8718. // Maybe abortRequest was called...
  8719. return;
  8720. }
  8721. if (pendingRequest.mozChunked) {
  8722. var chunk = getArrayBuffer(pendingRequest.xhr);
  8723. pendingRequest.onProgressiveData(chunk);
  8724. }
  8725. var onProgress = pendingRequest.onProgress;
  8726. if (onProgress) {
  8727. onProgress(evt);
  8728. }
  8729. },
  8730. onStateChange: function NetworkManager_onStateChange(xhrId, evt) {
  8731. var pendingRequest = this.pendingRequests[xhrId];
  8732. if (!pendingRequest) {
  8733. // Maybe abortRequest was called...
  8734. return;
  8735. }
  8736. var xhr = pendingRequest.xhr;
  8737. if (xhr.readyState >= 2 && pendingRequest.onHeadersReceived) {
  8738. pendingRequest.onHeadersReceived();
  8739. delete pendingRequest.onHeadersReceived;
  8740. }
  8741. if (xhr.readyState !== 4) {
  8742. return;
  8743. }
  8744. if (!(xhrId in this.pendingRequests)) {
  8745. // The XHR request might have been aborted in onHeadersReceived()
  8746. // callback, in which case we should abort request
  8747. return;
  8748. }
  8749. delete this.pendingRequests[xhrId];
  8750. // success status == 0 can be on ftp, file and other protocols
  8751. if (xhr.status === 0 && this.isHttp) {
  8752. if (pendingRequest.onError) {
  8753. pendingRequest.onError(xhr.status);
  8754. }
  8755. return;
  8756. }
  8757. var xhrStatus = xhr.status || OK_RESPONSE;
  8758. // From http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35.2:
  8759. // "A server MAY ignore the Range header". This means it's possible to
  8760. // get a 200 rather than a 206 response from a range request.
  8761. var ok_response_on_range_request =
  8762. xhrStatus === OK_RESPONSE &&
  8763. pendingRequest.expectedStatus === PARTIAL_CONTENT_RESPONSE;
  8764. if (!ok_response_on_range_request &&
  8765. xhrStatus !== pendingRequest.expectedStatus) {
  8766. if (pendingRequest.onError) {
  8767. pendingRequest.onError(xhr.status);
  8768. }
  8769. return;
  8770. }
  8771. this.loadedRequests[xhrId] = true;
  8772. var chunk = getArrayBuffer(xhr);
  8773. if (xhrStatus === PARTIAL_CONTENT_RESPONSE) {
  8774. var rangeHeader = xhr.getResponseHeader('Content-Range');
  8775. var matches = /bytes (\d+)-(\d+)\/(\d+)/.exec(rangeHeader);
  8776. var begin = parseInt(matches[1], 10);
  8777. pendingRequest.onDone({
  8778. begin: begin,
  8779. chunk: chunk
  8780. });
  8781. } else if (pendingRequest.onProgressiveData) {
  8782. pendingRequest.onDone(null);
  8783. } else if (chunk) {
  8784. pendingRequest.onDone({
  8785. begin: 0,
  8786. chunk: chunk
  8787. });
  8788. } else if (pendingRequest.onError) {
  8789. pendingRequest.onError(xhr.status);
  8790. }
  8791. },
  8792. hasPendingRequests: function NetworkManager_hasPendingRequests() {
  8793. for (var xhrId in this.pendingRequests) {
  8794. return true;
  8795. }
  8796. return false;
  8797. },
  8798. getRequestXhr: function NetworkManager_getXhr(xhrId) {
  8799. return this.pendingRequests[xhrId].xhr;
  8800. },
  8801. isStreamingRequest: function NetworkManager_isStreamingRequest(xhrId) {
  8802. return !!(this.pendingRequests[xhrId].onProgressiveData);
  8803. },
  8804. isPendingRequest: function NetworkManager_isPendingRequest(xhrId) {
  8805. return xhrId in this.pendingRequests;
  8806. },
  8807. isLoadedRequest: function NetworkManager_isLoadedRequest(xhrId) {
  8808. return xhrId in this.loadedRequests;
  8809. },
  8810. abortAllRequests: function NetworkManager_abortAllRequests() {
  8811. for (var xhrId in this.pendingRequests) {
  8812. this.abortRequest(xhrId | 0);
  8813. }
  8814. },
  8815. abortRequest: function NetworkManager_abortRequest(xhrId) {
  8816. var xhr = this.pendingRequests[xhrId].xhr;
  8817. delete this.pendingRequests[xhrId];
  8818. xhr.abort();
  8819. }
  8820. };
  8821. return NetworkManager;
  8822. })();
  8823. (function (root, factory) {
  8824. {
  8825. factory((root.pdfjsCoreNetwork = {}));
  8826. }
  8827. }(this, function (exports) {
  8828. exports.NetworkManager = NetworkManager;
  8829. }));
  8830. (function (root, factory) {
  8831. {
  8832. factory((root.pdfjsSharedGlobal = {}));
  8833. }
  8834. }(this, function (exports) {
  8835. var globalScope = (typeof window !== 'undefined') ? window :
  8836. (typeof global !== 'undefined') ? global :
  8837. (typeof self !== 'undefined') ? self : this;
  8838. var isWorker = (typeof window === 'undefined');
  8839. // The global PDFJS object exposes the API
  8840. // In production, it will be declared outside a global wrapper
  8841. // In development, it will be declared here
  8842. if (!globalScope.PDFJS) {
  8843. globalScope.PDFJS = {};
  8844. }
  8845. if (typeof pdfjsVersion !== 'undefined') {
  8846. globalScope.PDFJS.version = pdfjsVersion;
  8847. }
  8848. if (typeof pdfjsVersion !== 'undefined') {
  8849. globalScope.PDFJS.build = pdfjsBuild;
  8850. }
  8851. globalScope.PDFJS.pdfBug = false;
  8852. exports.globalScope = globalScope;
  8853. exports.isWorker = isWorker;
  8854. exports.PDFJS = globalScope.PDFJS;
  8855. }));
  8856. (function (root, factory) {
  8857. {
  8858. factory((root.pdfjsCoreBidi = {}), root.pdfjsSharedGlobal);
  8859. }
  8860. }(this, function (exports, sharedGlobal) {
  8861. var PDFJS = sharedGlobal.PDFJS;
  8862. var bidi = PDFJS.bidi = (function bidiClosure() {
  8863. // Character types for symbols from 0000 to 00FF.
  8864. var baseTypes = [
  8865. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'S', 'B', 'S', 'WS',
  8866. 'B', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  8867. 'BN', 'BN', 'B', 'B', 'B', 'S', 'WS', 'ON', 'ON', 'ET', 'ET', 'ET', 'ON',
  8868. 'ON', 'ON', 'ON', 'ON', 'ON', 'CS', 'ON', 'CS', 'ON', 'EN', 'EN', 'EN',
  8869. 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'ON', 'ON', 'ON', 'ON', 'ON',
  8870. 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  8871. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'ON', 'ON',
  8872. 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  8873. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  8874. 'L', 'ON', 'ON', 'ON', 'ON', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'B', 'BN',
  8875. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  8876. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  8877. 'BN', 'CS', 'ON', 'ET', 'ET', 'ET', 'ET', 'ON', 'ON', 'ON', 'ON', 'L', 'ON',
  8878. 'ON', 'ON', 'ON', 'ON', 'ET', 'ET', 'EN', 'EN', 'ON', 'L', 'ON', 'ON', 'ON',
  8879. 'EN', 'L', 'ON', 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  8880. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  8881. 'L', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  8882. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  8883. 'L', 'L', 'L', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L'
  8884. ];
  8885. // Character types for symbols from 0600 to 06FF
  8886. var arabicTypes = [
  8887. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  8888. 'CS', 'AL', 'ON', 'ON', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL',
  8889. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  8890. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  8891. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  8892. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  8893. 'AL', 'AL', 'AL', 'AL', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM',
  8894. 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'AL', 'AL',
  8895. 'AL', 'AL', 'AL', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN',
  8896. 'AN', 'ET', 'AN', 'AN', 'AL', 'AL', 'AL', 'NSM', 'AL', 'AL', 'AL', 'AL',
  8897. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  8898. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  8899. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  8900. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  8901. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  8902. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  8903. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  8904. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  8905. 'AL', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM',
  8906. 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'ON', 'NSM',
  8907. 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  8908. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL'
  8909. ];
  8910. function isOdd(i) {
  8911. return (i & 1) !== 0;
  8912. }
  8913. function isEven(i) {
  8914. return (i & 1) === 0;
  8915. }
  8916. function findUnequal(arr, start, value) {
  8917. for (var j = start, jj = arr.length; j < jj; ++j) {
  8918. if (arr[j] !== value) {
  8919. return j;
  8920. }
  8921. }
  8922. return j;
  8923. }
  8924. function setValues(arr, start, end, value) {
  8925. for (var j = start; j < end; ++j) {
  8926. arr[j] = value;
  8927. }
  8928. }
  8929. function reverseValues(arr, start, end) {
  8930. for (var i = start, j = end - 1; i < j; ++i, --j) {
  8931. var temp = arr[i];
  8932. arr[i] = arr[j];
  8933. arr[j] = temp;
  8934. }
  8935. }
  8936. function createBidiText(str, isLTR, vertical) {
  8937. return {
  8938. str: str,
  8939. dir: (vertical ? 'ttb' : (isLTR ? 'ltr' : 'rtl'))
  8940. };
  8941. }
  8942. // These are used in bidi(), which is called frequently. We re-use them on
  8943. // each call to avoid unnecessary allocations.
  8944. var chars = [];
  8945. var types = [];
  8946. function bidi(str, startLevel, vertical) {
  8947. var isLTR = true;
  8948. var strLength = str.length;
  8949. if (strLength === 0 || vertical) {
  8950. return createBidiText(str, isLTR, vertical);
  8951. }
  8952. // Get types and fill arrays
  8953. chars.length = strLength;
  8954. types.length = strLength;
  8955. var numBidi = 0;
  8956. var i, ii;
  8957. for (i = 0; i < strLength; ++i) {
  8958. chars[i] = str.charAt(i);
  8959. var charCode = str.charCodeAt(i);
  8960. var charType = 'L';
  8961. if (charCode <= 0x00ff) {
  8962. charType = baseTypes[charCode];
  8963. } else if (0x0590 <= charCode && charCode <= 0x05f4) {
  8964. charType = 'R';
  8965. } else if (0x0600 <= charCode && charCode <= 0x06ff) {
  8966. charType = arabicTypes[charCode & 0xff];
  8967. } else if (0x0700 <= charCode && charCode <= 0x08AC) {
  8968. charType = 'AL';
  8969. }
  8970. if (charType === 'R' || charType === 'AL' || charType === 'AN') {
  8971. numBidi++;
  8972. }
  8973. types[i] = charType;
  8974. }
  8975. // Detect the bidi method
  8976. // - If there are no rtl characters then no bidi needed
  8977. // - If less than 30% chars are rtl then string is primarily ltr
  8978. // - If more than 30% chars are rtl then string is primarily rtl
  8979. if (numBidi === 0) {
  8980. isLTR = true;
  8981. return createBidiText(str, isLTR);
  8982. }
  8983. if (startLevel === -1) {
  8984. if ((strLength / numBidi) < 0.3) {
  8985. isLTR = true;
  8986. startLevel = 0;
  8987. } else {
  8988. isLTR = false;
  8989. startLevel = 1;
  8990. }
  8991. }
  8992. var levels = [];
  8993. for (i = 0; i < strLength; ++i) {
  8994. levels[i] = startLevel;
  8995. }
  8996. /*
  8997. X1-X10: skip most of this, since we are NOT doing the embeddings.
  8998. */
  8999. var e = (isOdd(startLevel) ? 'R' : 'L');
  9000. var sor = e;
  9001. var eor = sor;
  9002. /*
  9003. W1. Examine each non-spacing mark (NSM) in the level run, and change the
  9004. type of the NSM to the type of the previous character. If the NSM is at the
  9005. start of the level run, it will get the type of sor.
  9006. */
  9007. var lastType = sor;
  9008. for (i = 0; i < strLength; ++i) {
  9009. if (types[i] === 'NSM') {
  9010. types[i] = lastType;
  9011. } else {
  9012. lastType = types[i];
  9013. }
  9014. }
  9015. /*
  9016. W2. Search backwards from each instance of a European number until the
  9017. first strong type (R, L, AL, or sor) is found. If an AL is found, change
  9018. the type of the European number to Arabic number.
  9019. */
  9020. lastType = sor;
  9021. var t;
  9022. for (i = 0; i < strLength; ++i) {
  9023. t = types[i];
  9024. if (t === 'EN') {
  9025. types[i] = (lastType === 'AL') ? 'AN' : 'EN';
  9026. } else if (t === 'R' || t === 'L' || t === 'AL') {
  9027. lastType = t;
  9028. }
  9029. }
  9030. /*
  9031. W3. Change all ALs to R.
  9032. */
  9033. for (i = 0; i < strLength; ++i) {
  9034. t = types[i];
  9035. if (t === 'AL') {
  9036. types[i] = 'R';
  9037. }
  9038. }
  9039. /*
  9040. W4. A single European separator between two European numbers changes to a
  9041. European number. A single common separator between two numbers of the same
  9042. type changes to that type:
  9043. */
  9044. for (i = 1; i < strLength - 1; ++i) {
  9045. if (types[i] === 'ES' && types[i - 1] === 'EN' && types[i + 1] === 'EN') {
  9046. types[i] = 'EN';
  9047. }
  9048. if (types[i] === 'CS' &&
  9049. (types[i - 1] === 'EN' || types[i - 1] === 'AN') &&
  9050. types[i + 1] === types[i - 1]) {
  9051. types[i] = types[i - 1];
  9052. }
  9053. }
  9054. /*
  9055. W5. A sequence of European terminators adjacent to European numbers changes
  9056. to all European numbers:
  9057. */
  9058. for (i = 0; i < strLength; ++i) {
  9059. if (types[i] === 'EN') {
  9060. // do before
  9061. var j;
  9062. for (j = i - 1; j >= 0; --j) {
  9063. if (types[j] !== 'ET') {
  9064. break;
  9065. }
  9066. types[j] = 'EN';
  9067. }
  9068. // do after
  9069. for (j = i + 1; j < strLength; --j) {
  9070. if (types[j] !== 'ET') {
  9071. break;
  9072. }
  9073. types[j] = 'EN';
  9074. }
  9075. }
  9076. }
  9077. /*
  9078. W6. Otherwise, separators and terminators change to Other Neutral:
  9079. */
  9080. for (i = 0; i < strLength; ++i) {
  9081. t = types[i];
  9082. if (t === 'WS' || t === 'ES' || t === 'ET' || t === 'CS') {
  9083. types[i] = 'ON';
  9084. }
  9085. }
  9086. /*
  9087. W7. Search backwards from each instance of a European number until the
  9088. first strong type (R, L, or sor) is found. If an L is found, then change
  9089. the type of the European number to L.
  9090. */
  9091. lastType = sor;
  9092. for (i = 0; i < strLength; ++i) {
  9093. t = types[i];
  9094. if (t === 'EN') {
  9095. types[i] = ((lastType === 'L') ? 'L' : 'EN');
  9096. } else if (t === 'R' || t === 'L') {
  9097. lastType = t;
  9098. }
  9099. }
  9100. /*
  9101. N1. A sequence of neutrals takes the direction of the surrounding strong
  9102. text if the text on both sides has the same direction. European and Arabic
  9103. numbers are treated as though they were R. Start-of-level-run (sor) and
  9104. end-of-level-run (eor) are used at level run boundaries.
  9105. */
  9106. for (i = 0; i < strLength; ++i) {
  9107. if (types[i] === 'ON') {
  9108. var end = findUnequal(types, i + 1, 'ON');
  9109. var before = sor;
  9110. if (i > 0) {
  9111. before = types[i - 1];
  9112. }
  9113. var after = eor;
  9114. if (end + 1 < strLength) {
  9115. after = types[end + 1];
  9116. }
  9117. if (before !== 'L') {
  9118. before = 'R';
  9119. }
  9120. if (after !== 'L') {
  9121. after = 'R';
  9122. }
  9123. if (before === after) {
  9124. setValues(types, i, end, before);
  9125. }
  9126. i = end - 1; // reset to end (-1 so next iteration is ok)
  9127. }
  9128. }
  9129. /*
  9130. N2. Any remaining neutrals take the embedding direction.
  9131. */
  9132. for (i = 0; i < strLength; ++i) {
  9133. if (types[i] === 'ON') {
  9134. types[i] = e;
  9135. }
  9136. }
  9137. /*
  9138. I1. For all characters with an even (left-to-right) embedding direction,
  9139. those of type R go up one level and those of type AN or EN go up two
  9140. levels.
  9141. I2. For all characters with an odd (right-to-left) embedding direction,
  9142. those of type L, EN or AN go up one level.
  9143. */
  9144. for (i = 0; i < strLength; ++i) {
  9145. t = types[i];
  9146. if (isEven(levels[i])) {
  9147. if (t === 'R') {
  9148. levels[i] += 1;
  9149. } else if (t === 'AN' || t === 'EN') {
  9150. levels[i] += 2;
  9151. }
  9152. } else { // isOdd
  9153. if (t === 'L' || t === 'AN' || t === 'EN') {
  9154. levels[i] += 1;
  9155. }
  9156. }
  9157. }
  9158. /*
  9159. L1. On each line, reset the embedding level of the following characters to
  9160. the paragraph embedding level:
  9161. segment separators,
  9162. paragraph separators,
  9163. any sequence of whitespace characters preceding a segment separator or
  9164. paragraph separator, and any sequence of white space characters at the end
  9165. of the line.
  9166. */
  9167. // don't bother as text is only single line
  9168. /*
  9169. L2. From the highest level found in the text to the lowest odd level on
  9170. each line, reverse any contiguous sequence of characters that are at that
  9171. level or higher.
  9172. */
  9173. // find highest level & lowest odd level
  9174. var highestLevel = -1;
  9175. var lowestOddLevel = 99;
  9176. var level;
  9177. for (i = 0, ii = levels.length; i < ii; ++i) {
  9178. level = levels[i];
  9179. if (highestLevel < level) {
  9180. highestLevel = level;
  9181. }
  9182. if (lowestOddLevel > level && isOdd(level)) {
  9183. lowestOddLevel = level;
  9184. }
  9185. }
  9186. // now reverse between those limits
  9187. for (level = highestLevel; level >= lowestOddLevel; --level) {
  9188. // find segments to reverse
  9189. var start = -1;
  9190. for (i = 0, ii = levels.length; i < ii; ++i) {
  9191. if (levels[i] < level) {
  9192. if (start >= 0) {
  9193. reverseValues(chars, start, i);
  9194. start = -1;
  9195. }
  9196. } else if (start < 0) {
  9197. start = i;
  9198. }
  9199. }
  9200. if (start >= 0) {
  9201. reverseValues(chars, start, levels.length);
  9202. }
  9203. }
  9204. /*
  9205. L3. Combining marks applied to a right-to-left base character will at this
  9206. point precede their base character. If the rendering engine expects them to
  9207. follow the base characters in the final display process, then the ordering
  9208. of the marks and the base character must be reversed.
  9209. */
  9210. // don't bother for now
  9211. /*
  9212. L4. A character that possesses the mirrored property as specified by
  9213. Section 4.7, Mirrored, must be depicted by a mirrored glyph if the resolved
  9214. directionality of that character is R.
  9215. */
  9216. // don't mirror as characters are already mirrored in the pdf
  9217. // Finally, return string
  9218. for (i = 0, ii = chars.length; i < ii; ++i) {
  9219. var ch = chars[i];
  9220. if (ch === '<' || ch === '>') {
  9221. chars[i] = '';
  9222. }
  9223. }
  9224. return createBidiText(chars.join(''), isLTR);
  9225. }
  9226. return bidi;
  9227. })();
  9228. exports.bidi = bidi;
  9229. }));
  9230. (function (root, factory) {
  9231. {
  9232. factory((root.pdfjsSharedUtil = {}), root.pdfjsSharedGlobal);
  9233. }
  9234. }(this, function (exports, sharedGlobal) {
  9235. var PDFJS = sharedGlobal.PDFJS;
  9236. var globalScope = sharedGlobal.globalScope;
  9237. var FONT_IDENTITY_MATRIX = [0.001, 0, 0, 0.001, 0, 0];
  9238. var TextRenderingMode = {
  9239. FILL: 0,
  9240. STROKE: 1,
  9241. FILL_STROKE: 2,
  9242. INVISIBLE: 3,
  9243. FILL_ADD_TO_PATH: 4,
  9244. STROKE_ADD_TO_PATH: 5,
  9245. FILL_STROKE_ADD_TO_PATH: 6,
  9246. ADD_TO_PATH: 7,
  9247. FILL_STROKE_MASK: 3,
  9248. ADD_TO_PATH_FLAG: 4
  9249. };
  9250. var ImageKind = {
  9251. GRAYSCALE_1BPP: 1,
  9252. RGB_24BPP: 2,
  9253. RGBA_32BPP: 3
  9254. };
  9255. var AnnotationType = {
  9256. TEXT: 1,
  9257. LINK: 2,
  9258. FREETEXT: 3,
  9259. LINE: 4,
  9260. SQUARE: 5,
  9261. CIRCLE: 6,
  9262. POLYGON: 7,
  9263. POLYLINE: 8,
  9264. HIGHLIGHT: 9,
  9265. UNDERLINE: 10,
  9266. SQUIGGLY: 11,
  9267. STRIKEOUT: 12,
  9268. STAMP: 13,
  9269. CARET: 14,
  9270. INK: 15,
  9271. POPUP: 16,
  9272. FILEATTACHMENT: 17,
  9273. SOUND: 18,
  9274. MOVIE: 19,
  9275. WIDGET: 20,
  9276. SCREEN: 21,
  9277. PRINTERMARK: 22,
  9278. TRAPNET: 23,
  9279. WATERMARK: 24,
  9280. THREED: 25,
  9281. REDACT: 26
  9282. };
  9283. var AnnotationFlag = {
  9284. INVISIBLE: 0x01,
  9285. HIDDEN: 0x02,
  9286. PRINT: 0x04,
  9287. NOZOOM: 0x08,
  9288. NOROTATE: 0x10,
  9289. NOVIEW: 0x20,
  9290. READONLY: 0x40,
  9291. LOCKED: 0x80,
  9292. TOGGLENOVIEW: 0x100,
  9293. LOCKEDCONTENTS: 0x200
  9294. };
  9295. var AnnotationBorderStyleType = {
  9296. SOLID: 1,
  9297. DASHED: 2,
  9298. BEVELED: 3,
  9299. INSET: 4,
  9300. UNDERLINE: 5
  9301. };
  9302. var StreamType = {
  9303. UNKNOWN: 0,
  9304. FLATE: 1,
  9305. LZW: 2,
  9306. DCT: 3,
  9307. JPX: 4,
  9308. JBIG: 5,
  9309. A85: 6,
  9310. AHX: 7,
  9311. CCF: 8,
  9312. RL: 9
  9313. };
  9314. var FontType = {
  9315. UNKNOWN: 0,
  9316. TYPE1: 1,
  9317. TYPE1C: 2,
  9318. CIDFONTTYPE0: 3,
  9319. CIDFONTTYPE0C: 4,
  9320. TRUETYPE: 5,
  9321. CIDFONTTYPE2: 6,
  9322. TYPE3: 7,
  9323. OPENTYPE: 8,
  9324. TYPE0: 9,
  9325. MMTYPE1: 10
  9326. };
  9327. PDFJS.VERBOSITY_LEVELS = {
  9328. errors: 0,
  9329. warnings: 1,
  9330. infos: 5
  9331. };
  9332. // All the possible operations for an operator list.
  9333. var OPS = PDFJS.OPS = {
  9334. // Intentionally start from 1 so it is easy to spot bad operators that will be
  9335. // 0's.
  9336. dependency: 1,
  9337. setLineWidth: 2,
  9338. setLineCap: 3,
  9339. setLineJoin: 4,
  9340. setMiterLimit: 5,
  9341. setDash: 6,
  9342. setRenderingIntent: 7,
  9343. setFlatness: 8,
  9344. setGState: 9,
  9345. save: 10,
  9346. restore: 11,
  9347. transform: 12,
  9348. moveTo: 13,
  9349. lineTo: 14,
  9350. curveTo: 15,
  9351. curveTo2: 16,
  9352. curveTo3: 17,
  9353. closePath: 18,
  9354. rectangle: 19,
  9355. stroke: 20,
  9356. closeStroke: 21,
  9357. fill: 22,
  9358. eoFill: 23,
  9359. fillStroke: 24,
  9360. eoFillStroke: 25,
  9361. closeFillStroke: 26,
  9362. closeEOFillStroke: 27,
  9363. endPath: 28,
  9364. clip: 29,
  9365. eoClip: 30,
  9366. beginText: 31,
  9367. endText: 32,
  9368. setCharSpacing: 33,
  9369. setWordSpacing: 34,
  9370. setHScale: 35,
  9371. setLeading: 36,
  9372. setFont: 37,
  9373. setTextRenderingMode: 38,
  9374. setTextRise: 39,
  9375. moveText: 40,
  9376. setLeadingMoveText: 41,
  9377. setTextMatrix: 42,
  9378. nextLine: 43,
  9379. showText: 44,
  9380. showSpacedText: 45,
  9381. nextLineShowText: 46,
  9382. nextLineSetSpacingShowText: 47,
  9383. setCharWidth: 48,
  9384. setCharWidthAndBounds: 49,
  9385. setStrokeColorSpace: 50,
  9386. setFillColorSpace: 51,
  9387. setStrokeColor: 52,
  9388. setStrokeColorN: 53,
  9389. setFillColor: 54,
  9390. setFillColorN: 55,
  9391. setStrokeGray: 56,
  9392. setFillGray: 57,
  9393. setStrokeRGBColor: 58,
  9394. setFillRGBColor: 59,
  9395. setStrokeCMYKColor: 60,
  9396. setFillCMYKColor: 61,
  9397. shadingFill: 62,
  9398. beginInlineImage: 63,
  9399. beginImageData: 64,
  9400. endInlineImage: 65,
  9401. paintXObject: 66,
  9402. markPoint: 67,
  9403. markPointProps: 68,
  9404. beginMarkedContent: 69,
  9405. beginMarkedContentProps: 70,
  9406. endMarkedContent: 71,
  9407. beginCompat: 72,
  9408. endCompat: 73,
  9409. paintFormXObjectBegin: 74,
  9410. paintFormXObjectEnd: 75,
  9411. beginGroup: 76,
  9412. endGroup: 77,
  9413. beginAnnotations: 78,
  9414. endAnnotations: 79,
  9415. beginAnnotation: 80,
  9416. endAnnotation: 81,
  9417. paintJpegXObject: 82,
  9418. paintImageMaskXObject: 83,
  9419. paintImageMaskXObjectGroup: 84,
  9420. paintImageXObject: 85,
  9421. paintInlineImageXObject: 86,
  9422. paintInlineImageXObjectGroup: 87,
  9423. paintImageXObjectRepeat: 88,
  9424. paintImageMaskXObjectRepeat: 89,
  9425. paintSolidColorImageMask: 90,
  9426. constructPath: 91
  9427. };
  9428. // A notice for devs. These are good for things that are helpful to devs, such
  9429. // as warning that Workers were disabled, which is important to devs but not
  9430. // end users.
  9431. function info(msg) {
  9432. if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.infos) {
  9433. console.log('Info: ' + msg);
  9434. }
  9435. }
  9436. // Non-fatal warnings.
  9437. function warn(msg) {
  9438. if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.warnings) {
  9439. console.log('Warning: ' + msg);
  9440. }
  9441. }
  9442. // Deprecated API function -- treated as warnings.
  9443. function deprecated(details) {
  9444. warn('Deprecated API usage: ' + details);
  9445. }
  9446. // Fatal errors that should trigger the fallback UI and halt execution by
  9447. // throwing an exception.
  9448. function error(msg) {
  9449. if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.errors) {
  9450. console.log('Error: ' + msg);
  9451. console.log(backtrace());
  9452. }
  9453. throw new Error(msg);
  9454. }
  9455. function backtrace() {
  9456. try {
  9457. throw new Error();
  9458. } catch (e) {
  9459. return e.stack ? e.stack.split('\n').slice(2).join('\n') : '';
  9460. }
  9461. }
  9462. function assert(cond, msg) {
  9463. if (!cond) {
  9464. error(msg);
  9465. }
  9466. }
  9467. var UNSUPPORTED_FEATURES = PDFJS.UNSUPPORTED_FEATURES = {
  9468. unknown: 'unknown',
  9469. forms: 'forms',
  9470. javaScript: 'javaScript',
  9471. smask: 'smask',
  9472. shadingPattern: 'shadingPattern',
  9473. font: 'font'
  9474. };
  9475. // Combines two URLs. The baseUrl shall be absolute URL. If the url is an
  9476. // absolute URL, it will be returned as is.
  9477. function combineUrl(baseUrl, url) {
  9478. if (!url) {
  9479. return baseUrl;
  9480. }
  9481. return new URL(url, baseUrl).href;
  9482. }
  9483. // Validates if URL is safe and allowed, e.g. to avoid XSS.
  9484. function isValidUrl(url, allowRelative) {
  9485. if (!url) {
  9486. return false;
  9487. }
  9488. // RFC 3986 (http://tools.ietf.org/html/rfc3986#section-3.1)
  9489. // scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
  9490. var protocol = /^[a-z][a-z0-9+\-.]*(?=:)/i.exec(url);
  9491. if (!protocol) {
  9492. return allowRelative;
  9493. }
  9494. protocol = protocol[0].toLowerCase();
  9495. switch (protocol) {
  9496. case 'http':
  9497. case 'https':
  9498. case 'ftp':
  9499. case 'mailto':
  9500. case 'tel':
  9501. return true;
  9502. default:
  9503. return false;
  9504. }
  9505. }
  9506. PDFJS.isValidUrl = isValidUrl;
  9507. /**
  9508. * Adds various attributes (href, title, target, rel) to hyperlinks.
  9509. * @param {HTMLLinkElement} link - The link element.
  9510. * @param {Object} params - An object with the properties:
  9511. * @param {string} params.url - An absolute URL.
  9512. */
  9513. function addLinkAttributes(link, params) {
  9514. var url = params && params.url;
  9515. link.href = link.title = (url ? removeNullCharacters(url) : '');
  9516. if (url) {
  9517. if (isExternalLinkTargetSet()) {
  9518. link.target = LinkTargetStringMap[PDFJS.externalLinkTarget];
  9519. }
  9520. // Strip referrer from the URL.
  9521. link.rel = PDFJS.externalLinkRel;
  9522. }
  9523. }
  9524. PDFJS.addLinkAttributes = addLinkAttributes;
  9525. function shadow(obj, prop, value) {
  9526. Object.defineProperty(obj, prop, { value: value,
  9527. enumerable: true,
  9528. configurable: true,
  9529. writable: false });
  9530. return value;
  9531. }
  9532. PDFJS.shadow = shadow;
  9533. var LinkTarget = PDFJS.LinkTarget = {
  9534. NONE: 0, // Default value.
  9535. SELF: 1,
  9536. BLANK: 2,
  9537. PARENT: 3,
  9538. TOP: 4,
  9539. };
  9540. var LinkTargetStringMap = [
  9541. '',
  9542. '_self',
  9543. '_blank',
  9544. '_parent',
  9545. '_top'
  9546. ];
  9547. function isExternalLinkTargetSet() {
  9548. if (PDFJS.openExternalLinksInNewWindow) {
  9549. deprecated('PDFJS.openExternalLinksInNewWindow, please use ' +
  9550. '"PDFJS.externalLinkTarget = PDFJS.LinkTarget.BLANK" instead.');
  9551. if (PDFJS.externalLinkTarget === LinkTarget.NONE) {
  9552. PDFJS.externalLinkTarget = LinkTarget.BLANK;
  9553. }
  9554. // Reset the deprecated parameter, to suppress further warnings.
  9555. PDFJS.openExternalLinksInNewWindow = false;
  9556. }
  9557. switch (PDFJS.externalLinkTarget) {
  9558. case LinkTarget.NONE:
  9559. return false;
  9560. case LinkTarget.SELF:
  9561. case LinkTarget.BLANK:
  9562. case LinkTarget.PARENT:
  9563. case LinkTarget.TOP:
  9564. return true;
  9565. }
  9566. warn('PDFJS.externalLinkTarget is invalid: ' + PDFJS.externalLinkTarget);
  9567. // Reset the external link target, to suppress further warnings.
  9568. PDFJS.externalLinkTarget = LinkTarget.NONE;
  9569. return false;
  9570. }
  9571. PDFJS.isExternalLinkTargetSet = isExternalLinkTargetSet;
  9572. var PasswordResponses = PDFJS.PasswordResponses = {
  9573. NEED_PASSWORD: 1,
  9574. INCORRECT_PASSWORD: 2
  9575. };
  9576. var PasswordException = (function PasswordExceptionClosure() {
  9577. function PasswordException(msg, code) {
  9578. this.name = 'PasswordException';
  9579. this.message = msg;
  9580. this.code = code;
  9581. }
  9582. PasswordException.prototype = new Error();
  9583. PasswordException.constructor = PasswordException;
  9584. return PasswordException;
  9585. })();
  9586. PDFJS.PasswordException = PasswordException;
  9587. var UnknownErrorException = (function UnknownErrorExceptionClosure() {
  9588. function UnknownErrorException(msg, details) {
  9589. this.name = 'UnknownErrorException';
  9590. this.message = msg;
  9591. this.details = details;
  9592. }
  9593. UnknownErrorException.prototype = new Error();
  9594. UnknownErrorException.constructor = UnknownErrorException;
  9595. return UnknownErrorException;
  9596. })();
  9597. PDFJS.UnknownErrorException = UnknownErrorException;
  9598. var InvalidPDFException = (function InvalidPDFExceptionClosure() {
  9599. function InvalidPDFException(msg) {
  9600. this.name = 'InvalidPDFException';
  9601. this.message = msg;
  9602. }
  9603. InvalidPDFException.prototype = new Error();
  9604. InvalidPDFException.constructor = InvalidPDFException;
  9605. return InvalidPDFException;
  9606. })();
  9607. PDFJS.InvalidPDFException = InvalidPDFException;
  9608. var MissingPDFException = (function MissingPDFExceptionClosure() {
  9609. function MissingPDFException(msg) {
  9610. this.name = 'MissingPDFException';
  9611. this.message = msg;
  9612. }
  9613. MissingPDFException.prototype = new Error();
  9614. MissingPDFException.constructor = MissingPDFException;
  9615. return MissingPDFException;
  9616. })();
  9617. PDFJS.MissingPDFException = MissingPDFException;
  9618. var UnexpectedResponseException =
  9619. (function UnexpectedResponseExceptionClosure() {
  9620. function UnexpectedResponseException(msg, status) {
  9621. this.name = 'UnexpectedResponseException';
  9622. this.message = msg;
  9623. this.status = status;
  9624. }
  9625. UnexpectedResponseException.prototype = new Error();
  9626. UnexpectedResponseException.constructor = UnexpectedResponseException;
  9627. return UnexpectedResponseException;
  9628. })();
  9629. PDFJS.UnexpectedResponseException = UnexpectedResponseException;
  9630. var NotImplementedException = (function NotImplementedExceptionClosure() {
  9631. function NotImplementedException(msg) {
  9632. this.message = msg;
  9633. }
  9634. NotImplementedException.prototype = new Error();
  9635. NotImplementedException.prototype.name = 'NotImplementedException';
  9636. NotImplementedException.constructor = NotImplementedException;
  9637. return NotImplementedException;
  9638. })();
  9639. var MissingDataException = (function MissingDataExceptionClosure() {
  9640. function MissingDataException(begin, end) {
  9641. this.begin = begin;
  9642. this.end = end;
  9643. this.message = 'Missing data [' + begin + ', ' + end + ')';
  9644. }
  9645. MissingDataException.prototype = new Error();
  9646. MissingDataException.prototype.name = 'MissingDataException';
  9647. MissingDataException.constructor = MissingDataException;
  9648. return MissingDataException;
  9649. })();
  9650. var XRefParseException = (function XRefParseExceptionClosure() {
  9651. function XRefParseException(msg) {
  9652. this.message = msg;
  9653. }
  9654. XRefParseException.prototype = new Error();
  9655. XRefParseException.prototype.name = 'XRefParseException';
  9656. XRefParseException.constructor = XRefParseException;
  9657. return XRefParseException;
  9658. })();
  9659. var NullCharactersRegExp = /\x00/g;
  9660. function removeNullCharacters(str) {
  9661. if (typeof str !== 'string') {
  9662. warn('The argument for removeNullCharacters must be a string.');
  9663. return str;
  9664. }
  9665. return str.replace(NullCharactersRegExp, '');
  9666. }
  9667. PDFJS.removeNullCharacters = removeNullCharacters;
  9668. function bytesToString(bytes) {
  9669. assert(bytes !== null && typeof bytes === 'object' &&
  9670. bytes.length !== undefined, 'Invalid argument for bytesToString');
  9671. var length = bytes.length;
  9672. var MAX_ARGUMENT_COUNT = 8192;
  9673. if (length < MAX_ARGUMENT_COUNT) {
  9674. return String.fromCharCode.apply(null, bytes);
  9675. }
  9676. var strBuf = [];
  9677. for (var i = 0; i < length; i += MAX_ARGUMENT_COUNT) {
  9678. var chunkEnd = Math.min(i + MAX_ARGUMENT_COUNT, length);
  9679. var chunk = bytes.subarray(i, chunkEnd);
  9680. strBuf.push(String.fromCharCode.apply(null, chunk));
  9681. }
  9682. return strBuf.join('');
  9683. }
  9684. function stringToBytes(str) {
  9685. assert(typeof str === 'string', 'Invalid argument for stringToBytes');
  9686. var length = str.length;
  9687. var bytes = new Uint8Array(length);
  9688. for (var i = 0; i < length; ++i) {
  9689. bytes[i] = str.charCodeAt(i) & 0xFF;
  9690. }
  9691. return bytes;
  9692. }
  9693. function string32(value) {
  9694. return String.fromCharCode((value >> 24) & 0xff, (value >> 16) & 0xff,
  9695. (value >> 8) & 0xff, value & 0xff);
  9696. }
  9697. function log2(x) {
  9698. var n = 1, i = 0;
  9699. while (x > n) {
  9700. n <<= 1;
  9701. i++;
  9702. }
  9703. return i;
  9704. }
  9705. function readInt8(data, start) {
  9706. return (data[start] << 24) >> 24;
  9707. }
  9708. function readUint16(data, offset) {
  9709. return (data[offset] << 8) | data[offset + 1];
  9710. }
  9711. function readUint32(data, offset) {
  9712. return ((data[offset] << 24) | (data[offset + 1] << 16) |
  9713. (data[offset + 2] << 8) | data[offset + 3]) >>> 0;
  9714. }
  9715. // Lazy test the endianness of the platform
  9716. // NOTE: This will be 'true' for simulated TypedArrays
  9717. function isLittleEndian() {
  9718. var buffer8 = new Uint8Array(2);
  9719. buffer8[0] = 1;
  9720. var buffer16 = new Uint16Array(buffer8.buffer);
  9721. return (buffer16[0] === 1);
  9722. }
  9723. Object.defineProperty(PDFJS, 'isLittleEndian', {
  9724. configurable: true,
  9725. get: function PDFJS_isLittleEndian() {
  9726. return shadow(PDFJS, 'isLittleEndian', isLittleEndian());
  9727. }
  9728. });
  9729. // Lazy test if the userAgent support CanvasTypedArrays
  9730. function hasCanvasTypedArrays() {
  9731. var canvas = document.createElement('canvas');
  9732. canvas.width = canvas.height = 1;
  9733. var ctx = canvas.getContext('2d');
  9734. var imageData = ctx.createImageData(1, 1);
  9735. return (typeof imageData.data.buffer !== 'undefined');
  9736. }
  9737. Object.defineProperty(PDFJS, 'hasCanvasTypedArrays', {
  9738. configurable: true,
  9739. get: function PDFJS_hasCanvasTypedArrays() {
  9740. return shadow(PDFJS, 'hasCanvasTypedArrays', hasCanvasTypedArrays());
  9741. }
  9742. });
  9743. var Uint32ArrayView = (function Uint32ArrayViewClosure() {
  9744. function Uint32ArrayView(buffer, length) {
  9745. this.buffer = buffer;
  9746. this.byteLength = buffer.length;
  9747. this.length = length === undefined ? (this.byteLength >> 2) : length;
  9748. ensureUint32ArrayViewProps(this.length);
  9749. }
  9750. Uint32ArrayView.prototype = Object.create(null);
  9751. var uint32ArrayViewSetters = 0;
  9752. function createUint32ArrayProp(index) {
  9753. return {
  9754. get: function () {
  9755. var buffer = this.buffer, offset = index << 2;
  9756. return (buffer[offset] | (buffer[offset + 1] << 8) |
  9757. (buffer[offset + 2] << 16) | (buffer[offset + 3] << 24)) >>> 0;
  9758. },
  9759. set: function (value) {
  9760. var buffer = this.buffer, offset = index << 2;
  9761. buffer[offset] = value & 255;
  9762. buffer[offset + 1] = (value >> 8) & 255;
  9763. buffer[offset + 2] = (value >> 16) & 255;
  9764. buffer[offset + 3] = (value >>> 24) & 255;
  9765. }
  9766. };
  9767. }
  9768. function ensureUint32ArrayViewProps(length) {
  9769. while (uint32ArrayViewSetters < length) {
  9770. Object.defineProperty(Uint32ArrayView.prototype,
  9771. uint32ArrayViewSetters,
  9772. createUint32ArrayProp(uint32ArrayViewSetters));
  9773. uint32ArrayViewSetters++;
  9774. }
  9775. }
  9776. return Uint32ArrayView;
  9777. })();
  9778. exports.Uint32ArrayView = Uint32ArrayView;
  9779. var IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0];
  9780. var Util = PDFJS.Util = (function UtilClosure() {
  9781. function Util() {}
  9782. var rgbBuf = ['rgb(', 0, ',', 0, ',', 0, ')'];
  9783. // makeCssRgb() can be called thousands of times. Using |rgbBuf| avoids
  9784. // creating many intermediate strings.
  9785. Util.makeCssRgb = function Util_makeCssRgb(r, g, b) {
  9786. rgbBuf[1] = r;
  9787. rgbBuf[3] = g;
  9788. rgbBuf[5] = b;
  9789. return rgbBuf.join('');
  9790. };
  9791. // Concatenates two transformation matrices together and returns the result.
  9792. Util.transform = function Util_transform(m1, m2) {
  9793. return [
  9794. m1[0] * m2[0] + m1[2] * m2[1],
  9795. m1[1] * m2[0] + m1[3] * m2[1],
  9796. m1[0] * m2[2] + m1[2] * m2[3],
  9797. m1[1] * m2[2] + m1[3] * m2[3],
  9798. m1[0] * m2[4] + m1[2] * m2[5] + m1[4],
  9799. m1[1] * m2[4] + m1[3] * m2[5] + m1[5]
  9800. ];
  9801. };
  9802. // For 2d affine transforms
  9803. Util.applyTransform = function Util_applyTransform(p, m) {
  9804. var xt = p[0] * m[0] + p[1] * m[2] + m[4];
  9805. var yt = p[0] * m[1] + p[1] * m[3] + m[5];
  9806. return [xt, yt];
  9807. };
  9808. Util.applyInverseTransform = function Util_applyInverseTransform(p, m) {
  9809. var d = m[0] * m[3] - m[1] * m[2];
  9810. var xt = (p[0] * m[3] - p[1] * m[2] + m[2] * m[5] - m[4] * m[3]) / d;
  9811. var yt = (-p[0] * m[1] + p[1] * m[0] + m[4] * m[1] - m[5] * m[0]) / d;
  9812. return [xt, yt];
  9813. };
  9814. // Applies the transform to the rectangle and finds the minimum axially
  9815. // aligned bounding box.
  9816. Util.getAxialAlignedBoundingBox =
  9817. function Util_getAxialAlignedBoundingBox(r, m) {
  9818. var p1 = Util.applyTransform(r, m);
  9819. var p2 = Util.applyTransform(r.slice(2, 4), m);
  9820. var p3 = Util.applyTransform([r[0], r[3]], m);
  9821. var p4 = Util.applyTransform([r[2], r[1]], m);
  9822. return [
  9823. Math.min(p1[0], p2[0], p3[0], p4[0]),
  9824. Math.min(p1[1], p2[1], p3[1], p4[1]),
  9825. Math.max(p1[0], p2[0], p3[0], p4[0]),
  9826. Math.max(p1[1], p2[1], p3[1], p4[1])
  9827. ];
  9828. };
  9829. Util.inverseTransform = function Util_inverseTransform(m) {
  9830. var d = m[0] * m[3] - m[1] * m[2];
  9831. return [m[3] / d, -m[1] / d, -m[2] / d, m[0] / d,
  9832. (m[2] * m[5] - m[4] * m[3]) / d, (m[4] * m[1] - m[5] * m[0]) / d];
  9833. };
  9834. // Apply a generic 3d matrix M on a 3-vector v:
  9835. // | a b c | | X |
  9836. // | d e f | x | Y |
  9837. // | g h i | | Z |
  9838. // M is assumed to be serialized as [a,b,c,d,e,f,g,h,i],
  9839. // with v as [X,Y,Z]
  9840. Util.apply3dTransform = function Util_apply3dTransform(m, v) {
  9841. return [
  9842. m[0] * v[0] + m[1] * v[1] + m[2] * v[2],
  9843. m[3] * v[0] + m[4] * v[1] + m[5] * v[2],
  9844. m[6] * v[0] + m[7] * v[1] + m[8] * v[2]
  9845. ];
  9846. };
  9847. // This calculation uses Singular Value Decomposition.
  9848. // The SVD can be represented with formula A = USV. We are interested in the
  9849. // matrix S here because it represents the scale values.
  9850. Util.singularValueDecompose2dScale =
  9851. function Util_singularValueDecompose2dScale(m) {
  9852. var transpose = [m[0], m[2], m[1], m[3]];
  9853. // Multiply matrix m with its transpose.
  9854. var a = m[0] * transpose[0] + m[1] * transpose[2];
  9855. var b = m[0] * transpose[1] + m[1] * transpose[3];
  9856. var c = m[2] * transpose[0] + m[3] * transpose[2];
  9857. var d = m[2] * transpose[1] + m[3] * transpose[3];
  9858. // Solve the second degree polynomial to get roots.
  9859. var first = (a + d) / 2;
  9860. var second = Math.sqrt((a + d) * (a + d) - 4 * (a * d - c * b)) / 2;
  9861. var sx = first + second || 1;
  9862. var sy = first - second || 1;
  9863. // Scale values are the square roots of the eigenvalues.
  9864. return [Math.sqrt(sx), Math.sqrt(sy)];
  9865. };
  9866. // Normalize rectangle rect=[x1, y1, x2, y2] so that (x1,y1) < (x2,y2)
  9867. // For coordinate systems whose origin lies in the bottom-left, this
  9868. // means normalization to (BL,TR) ordering. For systems with origin in the
  9869. // top-left, this means (TL,BR) ordering.
  9870. Util.normalizeRect = function Util_normalizeRect(rect) {
  9871. var r = rect.slice(0); // clone rect
  9872. if (rect[0] > rect[2]) {
  9873. r[0] = rect[2];
  9874. r[2] = rect[0];
  9875. }
  9876. if (rect[1] > rect[3]) {
  9877. r[1] = rect[3];
  9878. r[3] = rect[1];
  9879. }
  9880. return r;
  9881. };
  9882. // Returns a rectangle [x1, y1, x2, y2] corresponding to the
  9883. // intersection of rect1 and rect2. If no intersection, returns 'false'
  9884. // The rectangle coordinates of rect1, rect2 should be [x1, y1, x2, y2]
  9885. Util.intersect = function Util_intersect(rect1, rect2) {
  9886. function compare(a, b) {
  9887. return a - b;
  9888. }
  9889. // Order points along the axes
  9890. var orderedX = [rect1[0], rect1[2], rect2[0], rect2[2]].sort(compare),
  9891. orderedY = [rect1[1], rect1[3], rect2[1], rect2[3]].sort(compare),
  9892. result = [];
  9893. rect1 = Util.normalizeRect(rect1);
  9894. rect2 = Util.normalizeRect(rect2);
  9895. // X: first and second points belong to different rectangles?
  9896. if ((orderedX[0] === rect1[0] && orderedX[1] === rect2[0]) ||
  9897. (orderedX[0] === rect2[0] && orderedX[1] === rect1[0])) {
  9898. // Intersection must be between second and third points
  9899. result[0] = orderedX[1];
  9900. result[2] = orderedX[2];
  9901. } else {
  9902. return false;
  9903. }
  9904. // Y: first and second points belong to different rectangles?
  9905. if ((orderedY[0] === rect1[1] && orderedY[1] === rect2[1]) ||
  9906. (orderedY[0] === rect2[1] && orderedY[1] === rect1[1])) {
  9907. // Intersection must be between second and third points
  9908. result[1] = orderedY[1];
  9909. result[3] = orderedY[2];
  9910. } else {
  9911. return false;
  9912. }
  9913. return result;
  9914. };
  9915. Util.sign = function Util_sign(num) {
  9916. return num < 0 ? -1 : 1;
  9917. };
  9918. var ROMAN_NUMBER_MAP = [
  9919. '', 'C', 'CC', 'CCC', 'CD', 'D', 'DC', 'DCC', 'DCCC', 'CM',
  9920. '', 'X', 'XX', 'XXX', 'XL', 'L', 'LX', 'LXX', 'LXXX', 'XC',
  9921. '', 'I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX'
  9922. ];
  9923. /**
  9924. * Converts positive integers to (upper case) Roman numerals.
  9925. * @param {integer} number - The number that should be converted.
  9926. * @param {boolean} lowerCase - Indicates if the result should be converted
  9927. * to lower case letters. The default is false.
  9928. * @return {string} The resulting Roman number.
  9929. */
  9930. Util.toRoman = function Util_toRoman(number, lowerCase) {
  9931. assert(isInt(number) && number > 0,
  9932. 'The number should be a positive integer.');
  9933. var pos, romanBuf = [];
  9934. // Thousands
  9935. while (number >= 1000) {
  9936. number -= 1000;
  9937. romanBuf.push('M');
  9938. }
  9939. // Hundreds
  9940. pos = (number / 100) | 0;
  9941. number %= 100;
  9942. romanBuf.push(ROMAN_NUMBER_MAP[pos]);
  9943. // Tens
  9944. pos = (number / 10) | 0;
  9945. number %= 10;
  9946. romanBuf.push(ROMAN_NUMBER_MAP[10 + pos]);
  9947. // Ones
  9948. romanBuf.push(ROMAN_NUMBER_MAP[20 + number]);
  9949. var romanStr = romanBuf.join('');
  9950. return (lowerCase ? romanStr.toLowerCase() : romanStr);
  9951. };
  9952. Util.appendToArray = function Util_appendToArray(arr1, arr2) {
  9953. Array.prototype.push.apply(arr1, arr2);
  9954. };
  9955. Util.prependToArray = function Util_prependToArray(arr1, arr2) {
  9956. Array.prototype.unshift.apply(arr1, arr2);
  9957. };
  9958. Util.extendObj = function extendObj(obj1, obj2) {
  9959. for (var key in obj2) {
  9960. obj1[key] = obj2[key];
  9961. }
  9962. };
  9963. Util.getInheritableProperty = function Util_getInheritableProperty(dict,
  9964. name) {
  9965. while (dict && !dict.has(name)) {
  9966. dict = dict.get('Parent');
  9967. }
  9968. if (!dict) {
  9969. return null;
  9970. }
  9971. return dict.get(name);
  9972. };
  9973. Util.inherit = function Util_inherit(sub, base, prototype) {
  9974. sub.prototype = Object.create(base.prototype);
  9975. sub.prototype.constructor = sub;
  9976. for (var prop in prototype) {
  9977. sub.prototype[prop] = prototype[prop];
  9978. }
  9979. };
  9980. Util.loadScript = function Util_loadScript(src, callback) {
  9981. var script = document.createElement('script');
  9982. var loaded = false;
  9983. script.setAttribute('src', src);
  9984. if (callback) {
  9985. script.onload = function() {
  9986. if (!loaded) {
  9987. callback();
  9988. }
  9989. loaded = true;
  9990. };
  9991. }
  9992. document.getElementsByTagName('head')[0].appendChild(script);
  9993. };
  9994. return Util;
  9995. })();
  9996. /**
  9997. * PDF page viewport created based on scale, rotation and offset.
  9998. * @class
  9999. * @alias PDFJS.PageViewport
  10000. */
  10001. var PageViewport = PDFJS.PageViewport = (function PageViewportClosure() {
  10002. /**
  10003. * @constructor
  10004. * @private
  10005. * @param viewBox {Array} xMin, yMin, xMax and yMax coordinates.
  10006. * @param scale {number} scale of the viewport.
  10007. * @param rotation {number} rotations of the viewport in degrees.
  10008. * @param offsetX {number} offset X
  10009. * @param offsetY {number} offset Y
  10010. * @param dontFlip {boolean} if true, axis Y will not be flipped.
  10011. */
  10012. function PageViewport(viewBox, scale, rotation, offsetX, offsetY, dontFlip) {
  10013. this.viewBox = viewBox;
  10014. this.scale = scale;
  10015. this.rotation = rotation;
  10016. this.offsetX = offsetX;
  10017. this.offsetY = offsetY;
  10018. // creating transform to convert pdf coordinate system to the normal
  10019. // canvas like coordinates taking in account scale and rotation
  10020. var centerX = (viewBox[2] + viewBox[0]) / 2;
  10021. var centerY = (viewBox[3] + viewBox[1]) / 2;
  10022. var rotateA, rotateB, rotateC, rotateD;
  10023. rotation = rotation % 360;
  10024. rotation = rotation < 0 ? rotation + 360 : rotation;
  10025. switch (rotation) {
  10026. case 180:
  10027. rotateA = -1; rotateB = 0; rotateC = 0; rotateD = 1;
  10028. break;
  10029. case 90:
  10030. rotateA = 0; rotateB = 1; rotateC = 1; rotateD = 0;
  10031. break;
  10032. case 270:
  10033. rotateA = 0; rotateB = -1; rotateC = -1; rotateD = 0;
  10034. break;
  10035. //case 0:
  10036. default:
  10037. rotateA = 1; rotateB = 0; rotateC = 0; rotateD = -1;
  10038. break;
  10039. }
  10040. if (dontFlip) {
  10041. rotateC = -rotateC; rotateD = -rotateD;
  10042. }
  10043. var offsetCanvasX, offsetCanvasY;
  10044. var width, height;
  10045. if (rotateA === 0) {
  10046. offsetCanvasX = Math.abs(centerY - viewBox[1]) * scale + offsetX;
  10047. offsetCanvasY = Math.abs(centerX - viewBox[0]) * scale + offsetY;
  10048. width = Math.abs(viewBox[3] - viewBox[1]) * scale;
  10049. height = Math.abs(viewBox[2] - viewBox[0]) * scale;
  10050. } else {
  10051. offsetCanvasX = Math.abs(centerX - viewBox[0]) * scale + offsetX;
  10052. offsetCanvasY = Math.abs(centerY - viewBox[1]) * scale + offsetY;
  10053. width = Math.abs(viewBox[2] - viewBox[0]) * scale;
  10054. height = Math.abs(viewBox[3] - viewBox[1]) * scale;
  10055. }
  10056. // creating transform for the following operations:
  10057. // translate(-centerX, -centerY), rotate and flip vertically,
  10058. // scale, and translate(offsetCanvasX, offsetCanvasY)
  10059. this.transform = [
  10060. rotateA * scale,
  10061. rotateB * scale,
  10062. rotateC * scale,
  10063. rotateD * scale,
  10064. offsetCanvasX - rotateA * scale * centerX - rotateC * scale * centerY,
  10065. offsetCanvasY - rotateB * scale * centerX - rotateD * scale * centerY
  10066. ];
  10067. this.width = width;
  10068. this.height = height;
  10069. this.fontScale = scale;
  10070. }
  10071. PageViewport.prototype = /** @lends PDFJS.PageViewport.prototype */ {
  10072. /**
  10073. * Clones viewport with additional properties.
  10074. * @param args {Object} (optional) If specified, may contain the 'scale' or
  10075. * 'rotation' properties to override the corresponding properties in
  10076. * the cloned viewport.
  10077. * @returns {PDFJS.PageViewport} Cloned viewport.
  10078. */
  10079. clone: function PageViewPort_clone(args) {
  10080. args = args || {};
  10081. var scale = 'scale' in args ? args.scale : this.scale;
  10082. var rotation = 'rotation' in args ? args.rotation : this.rotation;
  10083. return new PageViewport(this.viewBox.slice(), scale, rotation,
  10084. this.offsetX, this.offsetY, args.dontFlip);
  10085. },
  10086. /**
  10087. * Converts PDF point to the viewport coordinates. For examples, useful for
  10088. * converting PDF location into canvas pixel coordinates.
  10089. * @param x {number} X coordinate.
  10090. * @param y {number} Y coordinate.
  10091. * @returns {Object} Object that contains 'x' and 'y' properties of the
  10092. * point in the viewport coordinate space.
  10093. * @see {@link convertToPdfPoint}
  10094. * @see {@link convertToViewportRectangle}
  10095. */
  10096. convertToViewportPoint: function PageViewport_convertToViewportPoint(x, y) {
  10097. return Util.applyTransform([x, y], this.transform);
  10098. },
  10099. /**
  10100. * Converts PDF rectangle to the viewport coordinates.
  10101. * @param rect {Array} xMin, yMin, xMax and yMax coordinates.
  10102. * @returns {Array} Contains corresponding coordinates of the rectangle
  10103. * in the viewport coordinate space.
  10104. * @see {@link convertToViewportPoint}
  10105. */
  10106. convertToViewportRectangle:
  10107. function PageViewport_convertToViewportRectangle(rect) {
  10108. var tl = Util.applyTransform([rect[0], rect[1]], this.transform);
  10109. var br = Util.applyTransform([rect[2], rect[3]], this.transform);
  10110. return [tl[0], tl[1], br[0], br[1]];
  10111. },
  10112. /**
  10113. * Converts viewport coordinates to the PDF location. For examples, useful
  10114. * for converting canvas pixel location into PDF one.
  10115. * @param x {number} X coordinate.
  10116. * @param y {number} Y coordinate.
  10117. * @returns {Object} Object that contains 'x' and 'y' properties of the
  10118. * point in the PDF coordinate space.
  10119. * @see {@link convertToViewportPoint}
  10120. */
  10121. convertToPdfPoint: function PageViewport_convertToPdfPoint(x, y) {
  10122. return Util.applyInverseTransform([x, y], this.transform);
  10123. }
  10124. };
  10125. return PageViewport;
  10126. })();
  10127. var PDFStringTranslateTable = [
  10128. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  10129. 0x2D8, 0x2C7, 0x2C6, 0x2D9, 0x2DD, 0x2DB, 0x2DA, 0x2DC, 0, 0, 0, 0, 0, 0, 0,
  10130. 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,
  10131. 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,
  10132. 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,
  10133. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x2022, 0x2020, 0x2021, 0x2026, 0x2014,
  10134. 0x2013, 0x192, 0x2044, 0x2039, 0x203A, 0x2212, 0x2030, 0x201E, 0x201C,
  10135. 0x201D, 0x2018, 0x2019, 0x201A, 0x2122, 0xFB01, 0xFB02, 0x141, 0x152, 0x160,
  10136. 0x178, 0x17D, 0x131, 0x142, 0x153, 0x161, 0x17E, 0, 0x20AC
  10137. ];
  10138. function stringToPDFString(str) {
  10139. var i, n = str.length, strBuf = [];
  10140. if (str[0] === '\xFE' && str[1] === '\xFF') {
  10141. // UTF16BE BOM
  10142. for (i = 2; i < n; i += 2) {
  10143. strBuf.push(String.fromCharCode(
  10144. (str.charCodeAt(i) << 8) | str.charCodeAt(i + 1)));
  10145. }
  10146. } else {
  10147. for (i = 0; i < n; ++i) {
  10148. var code = PDFStringTranslateTable[str.charCodeAt(i)];
  10149. strBuf.push(code ? String.fromCharCode(code) : str.charAt(i));
  10150. }
  10151. }
  10152. return strBuf.join('');
  10153. }
  10154. function stringToUTF8String(str) {
  10155. return decodeURIComponent(escape(str));
  10156. }
  10157. function utf8StringToString(str) {
  10158. return unescape(encodeURIComponent(str));
  10159. }
  10160. function isEmptyObj(obj) {
  10161. for (var key in obj) {
  10162. return false;
  10163. }
  10164. return true;
  10165. }
  10166. function isBool(v) {
  10167. return typeof v === 'boolean';
  10168. }
  10169. function isInt(v) {
  10170. return typeof v === 'number' && ((v | 0) === v);
  10171. }
  10172. function isNum(v) {
  10173. return typeof v === 'number';
  10174. }
  10175. function isString(v) {
  10176. return typeof v === 'string';
  10177. }
  10178. function isArray(v) {
  10179. return v instanceof Array;
  10180. }
  10181. function isArrayBuffer(v) {
  10182. return typeof v === 'object' && v !== null && v.byteLength !== undefined;
  10183. }
  10184. /**
  10185. * Promise Capability object.
  10186. *
  10187. * @typedef {Object} PromiseCapability
  10188. * @property {Promise} promise - A promise object.
  10189. * @property {function} resolve - Fullfills the promise.
  10190. * @property {function} reject - Rejects the promise.
  10191. */
  10192. /**
  10193. * Creates a promise capability object.
  10194. * @alias PDFJS.createPromiseCapability
  10195. *
  10196. * @return {PromiseCapability} A capability object contains:
  10197. * - a Promise, resolve and reject methods.
  10198. */
  10199. function createPromiseCapability() {
  10200. var capability = {};
  10201. capability.promise = new Promise(function (resolve, reject) {
  10202. capability.resolve = resolve;
  10203. capability.reject = reject;
  10204. });
  10205. return capability;
  10206. }
  10207. PDFJS.createPromiseCapability = createPromiseCapability;
  10208. /**
  10209. * Polyfill for Promises:
  10210. * The following promise implementation tries to generally implement the
  10211. * Promise/A+ spec. Some notable differences from other promise libaries are:
  10212. * - There currently isn't a seperate deferred and promise object.
  10213. * - Unhandled rejections eventually show an error if they aren't handled.
  10214. *
  10215. * Based off of the work in:
  10216. * https://bugzilla.mozilla.org/show_bug.cgi?id=810490
  10217. */
  10218. (function PromiseClosure() {
  10219. if (globalScope.Promise) {
  10220. // Promises existing in the DOM/Worker, checking presence of all/resolve
  10221. if (typeof globalScope.Promise.all !== 'function') {
  10222. globalScope.Promise.all = function (iterable) {
  10223. var count = 0, results = [], resolve, reject;
  10224. var promise = new globalScope.Promise(function (resolve_, reject_) {
  10225. resolve = resolve_;
  10226. reject = reject_;
  10227. });
  10228. iterable.forEach(function (p, i) {
  10229. count++;
  10230. p.then(function (result) {
  10231. results[i] = result;
  10232. count--;
  10233. if (count === 0) {
  10234. resolve(results);
  10235. }
  10236. }, reject);
  10237. });
  10238. if (count === 0) {
  10239. resolve(results);
  10240. }
  10241. return promise;
  10242. };
  10243. }
  10244. if (typeof globalScope.Promise.resolve !== 'function') {
  10245. globalScope.Promise.resolve = function (value) {
  10246. return new globalScope.Promise(function (resolve) { resolve(value); });
  10247. };
  10248. }
  10249. if (typeof globalScope.Promise.reject !== 'function') {
  10250. globalScope.Promise.reject = function (reason) {
  10251. return new globalScope.Promise(function (resolve, reject) {
  10252. reject(reason);
  10253. });
  10254. };
  10255. }
  10256. if (typeof globalScope.Promise.prototype.catch !== 'function') {
  10257. globalScope.Promise.prototype.catch = function (onReject) {
  10258. return globalScope.Promise.prototype.then(undefined, onReject);
  10259. };
  10260. }
  10261. return;
  10262. }
  10263. var STATUS_PENDING = 0;
  10264. var STATUS_RESOLVED = 1;
  10265. var STATUS_REJECTED = 2;
  10266. // In an attempt to avoid silent exceptions, unhandled rejections are
  10267. // tracked and if they aren't handled in a certain amount of time an
  10268. // error is logged.
  10269. var REJECTION_TIMEOUT = 500;
  10270. var HandlerManager = {
  10271. handlers: [],
  10272. running: false,
  10273. unhandledRejections: [],
  10274. pendingRejectionCheck: false,
  10275. scheduleHandlers: function scheduleHandlers(promise) {
  10276. if (promise._status === STATUS_PENDING) {
  10277. return;
  10278. }
  10279. this.handlers = this.handlers.concat(promise._handlers);
  10280. promise._handlers = [];
  10281. if (this.running) {
  10282. return;
  10283. }
  10284. this.running = true;
  10285. setTimeout(this.runHandlers.bind(this), 0);
  10286. },
  10287. runHandlers: function runHandlers() {
  10288. var RUN_TIMEOUT = 1; // ms
  10289. var timeoutAt = Date.now() + RUN_TIMEOUT;
  10290. while (this.handlers.length > 0) {
  10291. var handler = this.handlers.shift();
  10292. var nextStatus = handler.thisPromise._status;
  10293. var nextValue = handler.thisPromise._value;
  10294. try {
  10295. if (nextStatus === STATUS_RESOLVED) {
  10296. if (typeof handler.onResolve === 'function') {
  10297. nextValue = handler.onResolve(nextValue);
  10298. }
  10299. } else if (typeof handler.onReject === 'function') {
  10300. nextValue = handler.onReject(nextValue);
  10301. nextStatus = STATUS_RESOLVED;
  10302. if (handler.thisPromise._unhandledRejection) {
  10303. this.removeUnhandeledRejection(handler.thisPromise);
  10304. }
  10305. }
  10306. } catch (ex) {
  10307. nextStatus = STATUS_REJECTED;
  10308. nextValue = ex;
  10309. }
  10310. handler.nextPromise._updateStatus(nextStatus, nextValue);
  10311. if (Date.now() >= timeoutAt) {
  10312. break;
  10313. }
  10314. }
  10315. if (this.handlers.length > 0) {
  10316. setTimeout(this.runHandlers.bind(this), 0);
  10317. return;
  10318. }
  10319. this.running = false;
  10320. },
  10321. addUnhandledRejection: function addUnhandledRejection(promise) {
  10322. this.unhandledRejections.push({
  10323. promise: promise,
  10324. time: Date.now()
  10325. });
  10326. this.scheduleRejectionCheck();
  10327. },
  10328. removeUnhandeledRejection: function removeUnhandeledRejection(promise) {
  10329. promise._unhandledRejection = false;
  10330. for (var i = 0; i < this.unhandledRejections.length; i++) {
  10331. if (this.unhandledRejections[i].promise === promise) {
  10332. this.unhandledRejections.splice(i);
  10333. i--;
  10334. }
  10335. }
  10336. },
  10337. scheduleRejectionCheck: function scheduleRejectionCheck() {
  10338. if (this.pendingRejectionCheck) {
  10339. return;
  10340. }
  10341. this.pendingRejectionCheck = true;
  10342. setTimeout(function rejectionCheck() {
  10343. this.pendingRejectionCheck = false;
  10344. var now = Date.now();
  10345. for (var i = 0; i < this.unhandledRejections.length; i++) {
  10346. if (now - this.unhandledRejections[i].time > REJECTION_TIMEOUT) {
  10347. var unhandled = this.unhandledRejections[i].promise._value;
  10348. var msg = 'Unhandled rejection: ' + unhandled;
  10349. if (unhandled.stack) {
  10350. msg += '\n' + unhandled.stack;
  10351. }
  10352. warn(msg);
  10353. this.unhandledRejections.splice(i);
  10354. i--;
  10355. }
  10356. }
  10357. if (this.unhandledRejections.length) {
  10358. this.scheduleRejectionCheck();
  10359. }
  10360. }.bind(this), REJECTION_TIMEOUT);
  10361. }
  10362. };
  10363. function Promise(resolver) {
  10364. this._status = STATUS_PENDING;
  10365. this._handlers = [];
  10366. try {
  10367. resolver.call(this, this._resolve.bind(this), this._reject.bind(this));
  10368. } catch (e) {
  10369. this._reject(e);
  10370. }
  10371. }
  10372. /**
  10373. * Builds a promise that is resolved when all the passed in promises are
  10374. * resolved.
  10375. * @param {array} array of data and/or promises to wait for.
  10376. * @return {Promise} New dependant promise.
  10377. */
  10378. Promise.all = function Promise_all(promises) {
  10379. var resolveAll, rejectAll;
  10380. var deferred = new Promise(function (resolve, reject) {
  10381. resolveAll = resolve;
  10382. rejectAll = reject;
  10383. });
  10384. var unresolved = promises.length;
  10385. var results = [];
  10386. if (unresolved === 0) {
  10387. resolveAll(results);
  10388. return deferred;
  10389. }
  10390. function reject(reason) {
  10391. if (deferred._status === STATUS_REJECTED) {
  10392. return;
  10393. }
  10394. results = [];
  10395. rejectAll(reason);
  10396. }
  10397. for (var i = 0, ii = promises.length; i < ii; ++i) {
  10398. var promise = promises[i];
  10399. var resolve = (function(i) {
  10400. return function(value) {
  10401. if (deferred._status === STATUS_REJECTED) {
  10402. return;
  10403. }
  10404. results[i] = value;
  10405. unresolved--;
  10406. if (unresolved === 0) {
  10407. resolveAll(results);
  10408. }
  10409. };
  10410. })(i);
  10411. if (Promise.isPromise(promise)) {
  10412. promise.then(resolve, reject);
  10413. } else {
  10414. resolve(promise);
  10415. }
  10416. }
  10417. return deferred;
  10418. };
  10419. /**
  10420. * Checks if the value is likely a promise (has a 'then' function).
  10421. * @return {boolean} true if value is thenable
  10422. */
  10423. Promise.isPromise = function Promise_isPromise(value) {
  10424. return value && typeof value.then === 'function';
  10425. };
  10426. /**
  10427. * Creates resolved promise
  10428. * @param value resolve value
  10429. * @returns {Promise}
  10430. */
  10431. Promise.resolve = function Promise_resolve(value) {
  10432. return new Promise(function (resolve) { resolve(value); });
  10433. };
  10434. /**
  10435. * Creates rejected promise
  10436. * @param reason rejection value
  10437. * @returns {Promise}
  10438. */
  10439. Promise.reject = function Promise_reject(reason) {
  10440. return new Promise(function (resolve, reject) { reject(reason); });
  10441. };
  10442. Promise.prototype = {
  10443. _status: null,
  10444. _value: null,
  10445. _handlers: null,
  10446. _unhandledRejection: null,
  10447. _updateStatus: function Promise__updateStatus(status, value) {
  10448. if (this._status === STATUS_RESOLVED ||
  10449. this._status === STATUS_REJECTED) {
  10450. return;
  10451. }
  10452. if (status === STATUS_RESOLVED &&
  10453. Promise.isPromise(value)) {
  10454. value.then(this._updateStatus.bind(this, STATUS_RESOLVED),
  10455. this._updateStatus.bind(this, STATUS_REJECTED));
  10456. return;
  10457. }
  10458. this._status = status;
  10459. this._value = value;
  10460. if (status === STATUS_REJECTED && this._handlers.length === 0) {
  10461. this._unhandledRejection = true;
  10462. HandlerManager.addUnhandledRejection(this);
  10463. }
  10464. HandlerManager.scheduleHandlers(this);
  10465. },
  10466. _resolve: function Promise_resolve(value) {
  10467. this._updateStatus(STATUS_RESOLVED, value);
  10468. },
  10469. _reject: function Promise_reject(reason) {
  10470. this._updateStatus(STATUS_REJECTED, reason);
  10471. },
  10472. then: function Promise_then(onResolve, onReject) {
  10473. var nextPromise = new Promise(function (resolve, reject) {
  10474. this.resolve = resolve;
  10475. this.reject = reject;
  10476. });
  10477. this._handlers.push({
  10478. thisPromise: this,
  10479. onResolve: onResolve,
  10480. onReject: onReject,
  10481. nextPromise: nextPromise
  10482. });
  10483. HandlerManager.scheduleHandlers(this);
  10484. return nextPromise;
  10485. },
  10486. catch: function Promise_catch(onReject) {
  10487. return this.then(undefined, onReject);
  10488. }
  10489. };
  10490. globalScope.Promise = Promise;
  10491. })();
  10492. var StatTimer = (function StatTimerClosure() {
  10493. function rpad(str, pad, length) {
  10494. while (str.length < length) {
  10495. str += pad;
  10496. }
  10497. return str;
  10498. }
  10499. function StatTimer() {
  10500. this.started = {};
  10501. this.times = [];
  10502. this.enabled = true;
  10503. }
  10504. StatTimer.prototype = {
  10505. time: function StatTimer_time(name) {
  10506. if (!this.enabled) {
  10507. return;
  10508. }
  10509. if (name in this.started) {
  10510. warn('Timer is already running for ' + name);
  10511. }
  10512. this.started[name] = Date.now();
  10513. },
  10514. timeEnd: function StatTimer_timeEnd(name) {
  10515. if (!this.enabled) {
  10516. return;
  10517. }
  10518. if (!(name in this.started)) {
  10519. warn('Timer has not been started for ' + name);
  10520. }
  10521. this.times.push({
  10522. 'name': name,
  10523. 'start': this.started[name],
  10524. 'end': Date.now()
  10525. });
  10526. // Remove timer from started so it can be called again.
  10527. delete this.started[name];
  10528. },
  10529. toString: function StatTimer_toString() {
  10530. var i, ii;
  10531. var times = this.times;
  10532. var out = '';
  10533. // Find the longest name for padding purposes.
  10534. var longest = 0;
  10535. for (i = 0, ii = times.length; i < ii; ++i) {
  10536. var name = times[i]['name'];
  10537. if (name.length > longest) {
  10538. longest = name.length;
  10539. }
  10540. }
  10541. for (i = 0, ii = times.length; i < ii; ++i) {
  10542. var span = times[i];
  10543. var duration = span.end - span.start;
  10544. out += rpad(span['name'], ' ', longest) + ' ' + duration + 'ms\n';
  10545. }
  10546. return out;
  10547. }
  10548. };
  10549. return StatTimer;
  10550. })();
  10551. PDFJS.createBlob = function createBlob(data, contentType) {
  10552. if (typeof Blob !== 'undefined') {
  10553. return new Blob([data], { type: contentType });
  10554. }
  10555. // Blob builder is deprecated in FF14 and removed in FF18.
  10556. var bb = new MozBlobBuilder();
  10557. bb.append(data);
  10558. return bb.getBlob(contentType);
  10559. };
  10560. PDFJS.createObjectURL = (function createObjectURLClosure() {
  10561. // Blob/createObjectURL is not available, falling back to data schema.
  10562. var digits =
  10563. 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
  10564. return function createObjectURL(data, contentType) {
  10565. if (!PDFJS.disableCreateObjectURL &&
  10566. typeof URL !== 'undefined' && URL.createObjectURL) {
  10567. var blob = PDFJS.createBlob(data, contentType);
  10568. return URL.createObjectURL(blob);
  10569. }
  10570. var buffer = 'data:' + contentType + ';base64,';
  10571. for (var i = 0, ii = data.length; i < ii; i += 3) {
  10572. var b1 = data[i] & 0xFF;
  10573. var b2 = data[i + 1] & 0xFF;
  10574. var b3 = data[i + 2] & 0xFF;
  10575. var d1 = b1 >> 2, d2 = ((b1 & 3) << 4) | (b2 >> 4);
  10576. var d3 = i + 1 < ii ? ((b2 & 0xF) << 2) | (b3 >> 6) : 64;
  10577. var d4 = i + 2 < ii ? (b3 & 0x3F) : 64;
  10578. buffer += digits[d1] + digits[d2] + digits[d3] + digits[d4];
  10579. }
  10580. return buffer;
  10581. };
  10582. })();
  10583. function MessageHandler(sourceName, targetName, comObj) {
  10584. this.sourceName = sourceName;
  10585. this.targetName = targetName;
  10586. this.comObj = comObj;
  10587. this.callbackIndex = 1;
  10588. this.postMessageTransfers = true;
  10589. var callbacksCapabilities = this.callbacksCapabilities = {};
  10590. var ah = this.actionHandler = {};
  10591. this._onComObjOnMessage = function messageHandlerComObjOnMessage(event) {
  10592. var data = event.data;
  10593. if (data.targetName !== this.sourceName) {
  10594. return;
  10595. }
  10596. if (data.isReply) {
  10597. var callbackId = data.callbackId;
  10598. if (data.callbackId in callbacksCapabilities) {
  10599. var callback = callbacksCapabilities[callbackId];
  10600. delete callbacksCapabilities[callbackId];
  10601. if ('error' in data) {
  10602. callback.reject(data.error);
  10603. } else {
  10604. callback.resolve(data.data);
  10605. }
  10606. } else {
  10607. error('Cannot resolve callback ' + callbackId);
  10608. }
  10609. } else if (data.action in ah) {
  10610. var action = ah[data.action];
  10611. if (data.callbackId) {
  10612. var sourceName = this.sourceName;
  10613. var targetName = data.sourceName;
  10614. Promise.resolve().then(function () {
  10615. return action[0].call(action[1], data.data);
  10616. }).then(function (result) {
  10617. comObj.postMessage({
  10618. sourceName: sourceName,
  10619. targetName: targetName,
  10620. isReply: true,
  10621. callbackId: data.callbackId,
  10622. data: result
  10623. });
  10624. }, function (reason) {
  10625. if (reason instanceof Error) {
  10626. // Serialize error to avoid "DataCloneError"
  10627. reason = reason + '';
  10628. }
  10629. comObj.postMessage({
  10630. sourceName: sourceName,
  10631. targetName: targetName,
  10632. isReply: true,
  10633. callbackId: data.callbackId,
  10634. error: reason
  10635. });
  10636. });
  10637. } else {
  10638. action[0].call(action[1], data.data);
  10639. }
  10640. } else {
  10641. error('Unknown action from worker: ' + data.action);
  10642. }
  10643. }.bind(this);
  10644. comObj.addEventListener('message', this._onComObjOnMessage);
  10645. }
  10646. MessageHandler.prototype = {
  10647. on: function messageHandlerOn(actionName, handler, scope) {
  10648. var ah = this.actionHandler;
  10649. if (ah[actionName]) {
  10650. error('There is already an actionName called "' + actionName + '"');
  10651. }
  10652. ah[actionName] = [handler, scope];
  10653. },
  10654. /**
  10655. * Sends a message to the comObj to invoke the action with the supplied data.
  10656. * @param {String} actionName Action to call.
  10657. * @param {JSON} data JSON data to send.
  10658. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers
  10659. */
  10660. send: function messageHandlerSend(actionName, data, transfers) {
  10661. var message = {
  10662. sourceName: this.sourceName,
  10663. targetName: this.targetName,
  10664. action: actionName,
  10665. data: data
  10666. };
  10667. this.postMessage(message, transfers);
  10668. },
  10669. /**
  10670. * Sends a message to the comObj to invoke the action with the supplied data.
  10671. * Expects that other side will callback with the response.
  10672. * @param {String} actionName Action to call.
  10673. * @param {JSON} data JSON data to send.
  10674. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers.
  10675. * @returns {Promise} Promise to be resolved with response data.
  10676. */
  10677. sendWithPromise:
  10678. function messageHandlerSendWithPromise(actionName, data, transfers) {
  10679. var callbackId = this.callbackIndex++;
  10680. var message = {
  10681. sourceName: this.sourceName,
  10682. targetName: this.targetName,
  10683. action: actionName,
  10684. data: data,
  10685. callbackId: callbackId
  10686. };
  10687. var capability = createPromiseCapability();
  10688. this.callbacksCapabilities[callbackId] = capability;
  10689. try {
  10690. this.postMessage(message, transfers);
  10691. } catch (e) {
  10692. capability.reject(e);
  10693. }
  10694. return capability.promise;
  10695. },
  10696. /**
  10697. * Sends raw message to the comObj.
  10698. * @private
  10699. * @param message {Object} Raw message.
  10700. * @param transfers List of transfers/ArrayBuffers, or undefined.
  10701. */
  10702. postMessage: function (message, transfers) {
  10703. if (transfers && this.postMessageTransfers) {
  10704. this.comObj.postMessage(message, transfers);
  10705. } else {
  10706. this.comObj.postMessage(message);
  10707. }
  10708. },
  10709. destroy: function () {
  10710. this.comObj.removeEventListener('message', this._onComObjOnMessage);
  10711. }
  10712. };
  10713. function loadJpegStream(id, imageUrl, objs) {
  10714. var img = new Image();
  10715. img.onload = (function loadJpegStream_onloadClosure() {
  10716. objs.resolve(id, img);
  10717. });
  10718. img.onerror = (function loadJpegStream_onerrorClosure() {
  10719. objs.resolve(id, null);
  10720. warn('Error during JPEG image loading');
  10721. });
  10722. img.src = imageUrl;
  10723. }
  10724. // Polyfill from https://github.com/Polymer/URL
  10725. /* Any copyright is dedicated to the Public Domain.
  10726. * http://creativecommons.org/publicdomain/zero/1.0/ */
  10727. (function checkURLConstructor(scope) {
  10728. /* jshint ignore:start */
  10729. // feature detect for URL constructor
  10730. var hasWorkingUrl = false;
  10731. try {
  10732. if (typeof URL === 'function' &&
  10733. typeof URL.prototype === 'object' &&
  10734. ('origin' in URL.prototype)) {
  10735. var u = new URL('b', 'http://a');
  10736. u.pathname = 'c%20d';
  10737. hasWorkingUrl = u.href === 'http://a/c%20d';
  10738. }
  10739. } catch(e) { }
  10740. if (hasWorkingUrl)
  10741. return;
  10742. var relative = Object.create(null);
  10743. relative['ftp'] = 21;
  10744. relative['file'] = 0;
  10745. relative['gopher'] = 70;
  10746. relative['http'] = 80;
  10747. relative['https'] = 443;
  10748. relative['ws'] = 80;
  10749. relative['wss'] = 443;
  10750. var relativePathDotMapping = Object.create(null);
  10751. relativePathDotMapping['%2e'] = '.';
  10752. relativePathDotMapping['.%2e'] = '..';
  10753. relativePathDotMapping['%2e.'] = '..';
  10754. relativePathDotMapping['%2e%2e'] = '..';
  10755. function isRelativeScheme(scheme) {
  10756. return relative[scheme] !== undefined;
  10757. }
  10758. function invalid() {
  10759. clear.call(this);
  10760. this._isInvalid = true;
  10761. }
  10762. function IDNAToASCII(h) {
  10763. if ('' == h) {
  10764. invalid.call(this)
  10765. }
  10766. // XXX
  10767. return h.toLowerCase()
  10768. }
  10769. function percentEscape(c) {
  10770. var unicode = c.charCodeAt(0);
  10771. if (unicode > 0x20 &&
  10772. unicode < 0x7F &&
  10773. // " # < > ? `
  10774. [0x22, 0x23, 0x3C, 0x3E, 0x3F, 0x60].indexOf(unicode) == -1
  10775. ) {
  10776. return c;
  10777. }
  10778. return encodeURIComponent(c);
  10779. }
  10780. function percentEscapeQuery(c) {
  10781. // XXX This actually needs to encode c using encoding and then
  10782. // convert the bytes one-by-one.
  10783. var unicode = c.charCodeAt(0);
  10784. if (unicode > 0x20 &&
  10785. unicode < 0x7F &&
  10786. // " # < > ` (do not escape '?')
  10787. [0x22, 0x23, 0x3C, 0x3E, 0x60].indexOf(unicode) == -1
  10788. ) {
  10789. return c;
  10790. }
  10791. return encodeURIComponent(c);
  10792. }
  10793. var EOF = undefined,
  10794. ALPHA = /[a-zA-Z]/,
  10795. ALPHANUMERIC = /[a-zA-Z0-9\+\-\.]/;
  10796. function parse(input, stateOverride, base) {
  10797. function err(message) {
  10798. errors.push(message)
  10799. }
  10800. var state = stateOverride || 'scheme start',
  10801. cursor = 0,
  10802. buffer = '',
  10803. seenAt = false,
  10804. seenBracket = false,
  10805. errors = [];
  10806. loop: while ((input[cursor - 1] != EOF || cursor == 0) && !this._isInvalid) {
  10807. var c = input[cursor];
  10808. switch (state) {
  10809. case 'scheme start':
  10810. if (c && ALPHA.test(c)) {
  10811. buffer += c.toLowerCase(); // ASCII-safe
  10812. state = 'scheme';
  10813. } else if (!stateOverride) {
  10814. buffer = '';
  10815. state = 'no scheme';
  10816. continue;
  10817. } else {
  10818. err('Invalid scheme.');
  10819. break loop;
  10820. }
  10821. break;
  10822. case 'scheme':
  10823. if (c && ALPHANUMERIC.test(c)) {
  10824. buffer += c.toLowerCase(); // ASCII-safe
  10825. } else if (':' == c) {
  10826. this._scheme = buffer;
  10827. buffer = '';
  10828. if (stateOverride) {
  10829. break loop;
  10830. }
  10831. if (isRelativeScheme(this._scheme)) {
  10832. this._isRelative = true;
  10833. }
  10834. if ('file' == this._scheme) {
  10835. state = 'relative';
  10836. } else if (this._isRelative && base && base._scheme == this._scheme) {
  10837. state = 'relative or authority';
  10838. } else if (this._isRelative) {
  10839. state = 'authority first slash';
  10840. } else {
  10841. state = 'scheme data';
  10842. }
  10843. } else if (!stateOverride) {
  10844. buffer = '';
  10845. cursor = 0;
  10846. state = 'no scheme';
  10847. continue;
  10848. } else if (EOF == c) {
  10849. break loop;
  10850. } else {
  10851. err('Code point not allowed in scheme: ' + c)
  10852. break loop;
  10853. }
  10854. break;
  10855. case 'scheme data':
  10856. if ('?' == c) {
  10857. this._query = '?';
  10858. state = 'query';
  10859. } else if ('#' == c) {
  10860. this._fragment = '#';
  10861. state = 'fragment';
  10862. } else {
  10863. // XXX error handling
  10864. if (EOF != c && '\t' != c && '\n' != c && '\r' != c) {
  10865. this._schemeData += percentEscape(c);
  10866. }
  10867. }
  10868. break;
  10869. case 'no scheme':
  10870. if (!base || !(isRelativeScheme(base._scheme))) {
  10871. err('Missing scheme.');
  10872. invalid.call(this);
  10873. } else {
  10874. state = 'relative';
  10875. continue;
  10876. }
  10877. break;
  10878. case 'relative or authority':
  10879. if ('/' == c && '/' == input[cursor+1]) {
  10880. state = 'authority ignore slashes';
  10881. } else {
  10882. err('Expected /, got: ' + c);
  10883. state = 'relative';
  10884. continue
  10885. }
  10886. break;
  10887. case 'relative':
  10888. this._isRelative = true;
  10889. if ('file' != this._scheme)
  10890. this._scheme = base._scheme;
  10891. if (EOF == c) {
  10892. this._host = base._host;
  10893. this._port = base._port;
  10894. this._path = base._path.slice();
  10895. this._query = base._query;
  10896. this._username = base._username;
  10897. this._password = base._password;
  10898. break loop;
  10899. } else if ('/' == c || '\\' == c) {
  10900. if ('\\' == c)
  10901. err('\\ is an invalid code point.');
  10902. state = 'relative slash';
  10903. } else if ('?' == c) {
  10904. this._host = base._host;
  10905. this._port = base._port;
  10906. this._path = base._path.slice();
  10907. this._query = '?';
  10908. this._username = base._username;
  10909. this._password = base._password;
  10910. state = 'query';
  10911. } else if ('#' == c) {
  10912. this._host = base._host;
  10913. this._port = base._port;
  10914. this._path = base._path.slice();
  10915. this._query = base._query;
  10916. this._fragment = '#';
  10917. this._username = base._username;
  10918. this._password = base._password;
  10919. state = 'fragment';
  10920. } else {
  10921. var nextC = input[cursor+1]
  10922. var nextNextC = input[cursor+2]
  10923. if (
  10924. 'file' != this._scheme || !ALPHA.test(c) ||
  10925. (nextC != ':' && nextC != '|') ||
  10926. (EOF != nextNextC && '/' != nextNextC && '\\' != nextNextC && '?' != nextNextC && '#' != nextNextC)) {
  10927. this._host = base._host;
  10928. this._port = base._port;
  10929. this._username = base._username;
  10930. this._password = base._password;
  10931. this._path = base._path.slice();
  10932. this._path.pop();
  10933. }
  10934. state = 'relative path';
  10935. continue;
  10936. }
  10937. break;
  10938. case 'relative slash':
  10939. if ('/' == c || '\\' == c) {
  10940. if ('\\' == c) {
  10941. err('\\ is an invalid code point.');
  10942. }
  10943. if ('file' == this._scheme) {
  10944. state = 'file host';
  10945. } else {
  10946. state = 'authority ignore slashes';
  10947. }
  10948. } else {
  10949. if ('file' != this._scheme) {
  10950. this._host = base._host;
  10951. this._port = base._port;
  10952. this._username = base._username;
  10953. this._password = base._password;
  10954. }
  10955. state = 'relative path';
  10956. continue;
  10957. }
  10958. break;
  10959. case 'authority first slash':
  10960. if ('/' == c) {
  10961. state = 'authority second slash';
  10962. } else {
  10963. err("Expected '/', got: " + c);
  10964. state = 'authority ignore slashes';
  10965. continue;
  10966. }
  10967. break;
  10968. case 'authority second slash':
  10969. state = 'authority ignore slashes';
  10970. if ('/' != c) {
  10971. err("Expected '/', got: " + c);
  10972. continue;
  10973. }
  10974. break;
  10975. case 'authority ignore slashes':
  10976. if ('/' != c && '\\' != c) {
  10977. state = 'authority';
  10978. continue;
  10979. } else {
  10980. err('Expected authority, got: ' + c);
  10981. }
  10982. break;
  10983. case 'authority':
  10984. if ('@' == c) {
  10985. if (seenAt) {
  10986. err('@ already seen.');
  10987. buffer += '%40';
  10988. }
  10989. seenAt = true;
  10990. for (var i = 0; i < buffer.length; i++) {
  10991. var cp = buffer[i];
  10992. if ('\t' == cp || '\n' == cp || '\r' == cp) {
  10993. err('Invalid whitespace in authority.');
  10994. continue;
  10995. }
  10996. // XXX check URL code points
  10997. if (':' == cp && null === this._password) {
  10998. this._password = '';
  10999. continue;
  11000. }
  11001. var tempC = percentEscape(cp);
  11002. (null !== this._password) ? this._password += tempC : this._username += tempC;
  11003. }
  11004. buffer = '';
  11005. } else if (EOF == c || '/' == c || '\\' == c || '?' == c || '#' == c) {
  11006. cursor -= buffer.length;
  11007. buffer = '';
  11008. state = 'host';
  11009. continue;
  11010. } else {
  11011. buffer += c;
  11012. }
  11013. break;
  11014. case 'file host':
  11015. if (EOF == c || '/' == c || '\\' == c || '?' == c || '#' == c) {
  11016. if (buffer.length == 2 && ALPHA.test(buffer[0]) && (buffer[1] == ':' || buffer[1] == '|')) {
  11017. state = 'relative path';
  11018. } else if (buffer.length == 0) {
  11019. state = 'relative path start';
  11020. } else {
  11021. this._host = IDNAToASCII.call(this, buffer);
  11022. buffer = '';
  11023. state = 'relative path start';
  11024. }
  11025. continue;
  11026. } else if ('\t' == c || '\n' == c || '\r' == c) {
  11027. err('Invalid whitespace in file host.');
  11028. } else {
  11029. buffer += c;
  11030. }
  11031. break;
  11032. case 'host':
  11033. case 'hostname':
  11034. if (':' == c && !seenBracket) {
  11035. // XXX host parsing
  11036. this._host = IDNAToASCII.call(this, buffer);
  11037. buffer = '';
  11038. state = 'port';
  11039. if ('hostname' == stateOverride) {
  11040. break loop;
  11041. }
  11042. } else if (EOF == c || '/' == c || '\\' == c || '?' == c || '#' == c) {
  11043. this._host = IDNAToASCII.call(this, buffer);
  11044. buffer = '';
  11045. state = 'relative path start';
  11046. if (stateOverride) {
  11047. break loop;
  11048. }
  11049. continue;
  11050. } else if ('\t' != c && '\n' != c && '\r' != c) {
  11051. if ('[' == c) {
  11052. seenBracket = true;
  11053. } else if (']' == c) {
  11054. seenBracket = false;
  11055. }
  11056. buffer += c;
  11057. } else {
  11058. err('Invalid code point in host/hostname: ' + c);
  11059. }
  11060. break;
  11061. case 'port':
  11062. if (/[0-9]/.test(c)) {
  11063. buffer += c;
  11064. } else if (EOF == c || '/' == c || '\\' == c || '?' == c || '#' == c || stateOverride) {
  11065. if ('' != buffer) {
  11066. var temp = parseInt(buffer, 10);
  11067. if (temp != relative[this._scheme]) {
  11068. this._port = temp + '';
  11069. }
  11070. buffer = '';
  11071. }
  11072. if (stateOverride) {
  11073. break loop;
  11074. }
  11075. state = 'relative path start';
  11076. continue;
  11077. } else if ('\t' == c || '\n' == c || '\r' == c) {
  11078. err('Invalid code point in port: ' + c);
  11079. } else {
  11080. invalid.call(this);
  11081. }
  11082. break;
  11083. case 'relative path start':
  11084. if ('\\' == c)
  11085. err("'\\' not allowed in path.");
  11086. state = 'relative path';
  11087. if ('/' != c && '\\' != c) {
  11088. continue;
  11089. }
  11090. break;
  11091. case 'relative path':
  11092. if (EOF == c || '/' == c || '\\' == c || (!stateOverride && ('?' == c || '#' == c))) {
  11093. if ('\\' == c) {
  11094. err('\\ not allowed in relative path.');
  11095. }
  11096. var tmp;
  11097. if (tmp = relativePathDotMapping[buffer.toLowerCase()]) {
  11098. buffer = tmp;
  11099. }
  11100. if ('..' == buffer) {
  11101. this._path.pop();
  11102. if ('/' != c && '\\' != c) {
  11103. this._path.push('');
  11104. }
  11105. } else if ('.' == buffer && '/' != c && '\\' != c) {
  11106. this._path.push('');
  11107. } else if ('.' != buffer) {
  11108. if ('file' == this._scheme && this._path.length == 0 && buffer.length == 2 && ALPHA.test(buffer[0]) && buffer[1] == '|') {
  11109. buffer = buffer[0] + ':';
  11110. }
  11111. this._path.push(buffer);
  11112. }
  11113. buffer = '';
  11114. if ('?' == c) {
  11115. this._query = '?';
  11116. state = 'query';
  11117. } else if ('#' == c) {
  11118. this._fragment = '#';
  11119. state = 'fragment';
  11120. }
  11121. } else if ('\t' != c && '\n' != c && '\r' != c) {
  11122. buffer += percentEscape(c);
  11123. }
  11124. break;
  11125. case 'query':
  11126. if (!stateOverride && '#' == c) {
  11127. this._fragment = '#';
  11128. state = 'fragment';
  11129. } else if (EOF != c && '\t' != c && '\n' != c && '\r' != c) {
  11130. this._query += percentEscapeQuery(c);
  11131. }
  11132. break;
  11133. case 'fragment':
  11134. if (EOF != c && '\t' != c && '\n' != c && '\r' != c) {
  11135. this._fragment += c;
  11136. }
  11137. break;
  11138. }
  11139. cursor++;
  11140. }
  11141. }
  11142. function clear() {
  11143. this._scheme = '';
  11144. this._schemeData = '';
  11145. this._username = '';
  11146. this._password = null;
  11147. this._host = '';
  11148. this._port = '';
  11149. this._path = [];
  11150. this._query = '';
  11151. this._fragment = '';
  11152. this._isInvalid = false;
  11153. this._isRelative = false;
  11154. }
  11155. // Does not process domain names or IP addresses.
  11156. // Does not handle encoding for the query parameter.
  11157. function jURL(url, base /* , encoding */) {
  11158. if (base !== undefined && !(base instanceof jURL))
  11159. base = new jURL(String(base));
  11160. this._url = url;
  11161. clear.call(this);
  11162. var input = url.replace(/^[ \t\r\n\f]+|[ \t\r\n\f]+$/g, '');
  11163. // encoding = encoding || 'utf-8'
  11164. parse.call(this, input, null, base);
  11165. }
  11166. jURL.prototype = {
  11167. toString: function() {
  11168. return this.href;
  11169. },
  11170. get href() {
  11171. if (this._isInvalid)
  11172. return this._url;
  11173. var authority = '';
  11174. if ('' != this._username || null != this._password) {
  11175. authority = this._username +
  11176. (null != this._password ? ':' + this._password : '') + '@';
  11177. }
  11178. return this.protocol +
  11179. (this._isRelative ? '//' + authority + this.host : '') +
  11180. this.pathname + this._query + this._fragment;
  11181. },
  11182. set href(href) {
  11183. clear.call(this);
  11184. parse.call(this, href);
  11185. },
  11186. get protocol() {
  11187. return this._scheme + ':';
  11188. },
  11189. set protocol(protocol) {
  11190. if (this._isInvalid)
  11191. return;
  11192. parse.call(this, protocol + ':', 'scheme start');
  11193. },
  11194. get host() {
  11195. return this._isInvalid ? '' : this._port ?
  11196. this._host + ':' + this._port : this._host;
  11197. },
  11198. set host(host) {
  11199. if (this._isInvalid || !this._isRelative)
  11200. return;
  11201. parse.call(this, host, 'host');
  11202. },
  11203. get hostname() {
  11204. return this._host;
  11205. },
  11206. set hostname(hostname) {
  11207. if (this._isInvalid || !this._isRelative)
  11208. return;
  11209. parse.call(this, hostname, 'hostname');
  11210. },
  11211. get port() {
  11212. return this._port;
  11213. },
  11214. set port(port) {
  11215. if (this._isInvalid || !this._isRelative)
  11216. return;
  11217. parse.call(this, port, 'port');
  11218. },
  11219. get pathname() {
  11220. return this._isInvalid ? '' : this._isRelative ?
  11221. '/' + this._path.join('/') : this._schemeData;
  11222. },
  11223. set pathname(pathname) {
  11224. if (this._isInvalid || !this._isRelative)
  11225. return;
  11226. this._path = [];
  11227. parse.call(this, pathname, 'relative path start');
  11228. },
  11229. get search() {
  11230. return this._isInvalid || !this._query || '?' == this._query ?
  11231. '' : this._query;
  11232. },
  11233. set search(search) {
  11234. if (this._isInvalid || !this._isRelative)
  11235. return;
  11236. this._query = '?';
  11237. if ('?' == search[0])
  11238. search = search.slice(1);
  11239. parse.call(this, search, 'query');
  11240. },
  11241. get hash() {
  11242. return this._isInvalid || !this._fragment || '#' == this._fragment ?
  11243. '' : this._fragment;
  11244. },
  11245. set hash(hash) {
  11246. if (this._isInvalid)
  11247. return;
  11248. this._fragment = '#';
  11249. if ('#' == hash[0])
  11250. hash = hash.slice(1);
  11251. parse.call(this, hash, 'fragment');
  11252. },
  11253. get origin() {
  11254. var host;
  11255. if (this._isInvalid || !this._scheme) {
  11256. return '';
  11257. }
  11258. // javascript: Gecko returns String(""), WebKit/Blink String("null")
  11259. // Gecko throws error for "data://"
  11260. // data: Gecko returns "", Blink returns "data://", WebKit returns "null"
  11261. // Gecko returns String("") for file: mailto:
  11262. // WebKit/Blink returns String("SCHEME://") for file: mailto:
  11263. switch (this._scheme) {
  11264. case 'data':
  11265. case 'file':
  11266. case 'javascript':
  11267. case 'mailto':
  11268. return 'null';
  11269. }
  11270. host = this.host;
  11271. if (!host) {
  11272. return '';
  11273. }
  11274. return this._scheme + '://' + host;
  11275. }
  11276. };
  11277. // Copy over the static methods
  11278. var OriginalURL = scope.URL;
  11279. if (OriginalURL) {
  11280. jURL.createObjectURL = function(blob) {
  11281. // IE extension allows a second optional options argument.
  11282. // http://msdn.microsoft.com/en-us/library/ie/hh772302(v=vs.85).aspx
  11283. return OriginalURL.createObjectURL.apply(OriginalURL, arguments);
  11284. };
  11285. jURL.revokeObjectURL = function(url) {
  11286. OriginalURL.revokeObjectURL(url);
  11287. };
  11288. }
  11289. scope.URL = jURL;
  11290. /* jshint ignore:end */
  11291. })(globalScope);
  11292. exports.FONT_IDENTITY_MATRIX = FONT_IDENTITY_MATRIX;
  11293. exports.IDENTITY_MATRIX = IDENTITY_MATRIX;
  11294. exports.OPS = OPS;
  11295. exports.UNSUPPORTED_FEATURES = UNSUPPORTED_FEATURES;
  11296. exports.AnnotationBorderStyleType = AnnotationBorderStyleType;
  11297. exports.AnnotationFlag = AnnotationFlag;
  11298. exports.AnnotationType = AnnotationType;
  11299. exports.FontType = FontType;
  11300. exports.ImageKind = ImageKind;
  11301. exports.InvalidPDFException = InvalidPDFException;
  11302. exports.LinkTarget = LinkTarget;
  11303. exports.LinkTargetStringMap = LinkTargetStringMap;
  11304. exports.MessageHandler = MessageHandler;
  11305. exports.MissingDataException = MissingDataException;
  11306. exports.MissingPDFException = MissingPDFException;
  11307. exports.NotImplementedException = NotImplementedException;
  11308. exports.PasswordException = PasswordException;
  11309. exports.PasswordResponses = PasswordResponses;
  11310. exports.StatTimer = StatTimer;
  11311. exports.StreamType = StreamType;
  11312. exports.TextRenderingMode = TextRenderingMode;
  11313. exports.UnexpectedResponseException = UnexpectedResponseException;
  11314. exports.UnknownErrorException = UnknownErrorException;
  11315. exports.Util = Util;
  11316. exports.XRefParseException = XRefParseException;
  11317. exports.assert = assert;
  11318. exports.bytesToString = bytesToString;
  11319. exports.combineUrl = combineUrl;
  11320. exports.createPromiseCapability = createPromiseCapability;
  11321. exports.deprecated = deprecated;
  11322. exports.error = error;
  11323. exports.info = info;
  11324. exports.isArray = isArray;
  11325. exports.isArrayBuffer = isArrayBuffer;
  11326. exports.isBool = isBool;
  11327. exports.isEmptyObj = isEmptyObj;
  11328. exports.isExternalLinkTargetSet = isExternalLinkTargetSet;
  11329. exports.isInt = isInt;
  11330. exports.isNum = isNum;
  11331. exports.isString = isString;
  11332. exports.isValidUrl = isValidUrl;
  11333. exports.addLinkAttributes = addLinkAttributes;
  11334. exports.loadJpegStream = loadJpegStream;
  11335. exports.log2 = log2;
  11336. exports.readInt8 = readInt8;
  11337. exports.readUint16 = readUint16;
  11338. exports.readUint32 = readUint32;
  11339. exports.removeNullCharacters = removeNullCharacters;
  11340. exports.shadow = shadow;
  11341. exports.string32 = string32;
  11342. exports.stringToBytes = stringToBytes;
  11343. exports.stringToPDFString = stringToPDFString;
  11344. exports.stringToUTF8String = stringToUTF8String;
  11345. exports.utf8StringToString = utf8StringToString;
  11346. exports.warn = warn;
  11347. }));
  11348. (function (root, factory) {
  11349. {
  11350. factory((root.pdfjsCoreChunkedStream = {}), root.pdfjsSharedUtil);
  11351. }
  11352. }(this, function (exports, sharedUtil) {
  11353. var MissingDataException = sharedUtil.MissingDataException;
  11354. var assert = sharedUtil.assert;
  11355. var createPromiseCapability = sharedUtil.createPromiseCapability;
  11356. var isInt = sharedUtil.isInt;
  11357. var isEmptyObj = sharedUtil.isEmptyObj;
  11358. var ChunkedStream = (function ChunkedStreamClosure() {
  11359. function ChunkedStream(length, chunkSize, manager) {
  11360. this.bytes = new Uint8Array(length);
  11361. this.start = 0;
  11362. this.pos = 0;
  11363. this.end = length;
  11364. this.chunkSize = chunkSize;
  11365. this.loadedChunks = [];
  11366. this.numChunksLoaded = 0;
  11367. this.numChunks = Math.ceil(length / chunkSize);
  11368. this.manager = manager;
  11369. this.progressiveDataLength = 0;
  11370. this.lastSuccessfulEnsureByteChunk = -1; // a single-entry cache
  11371. }
  11372. // required methods for a stream. if a particular stream does not
  11373. // implement these, an error should be thrown
  11374. ChunkedStream.prototype = {
  11375. getMissingChunks: function ChunkedStream_getMissingChunks() {
  11376. var chunks = [];
  11377. for (var chunk = 0, n = this.numChunks; chunk < n; ++chunk) {
  11378. if (!this.loadedChunks[chunk]) {
  11379. chunks.push(chunk);
  11380. }
  11381. }
  11382. return chunks;
  11383. },
  11384. getBaseStreams: function ChunkedStream_getBaseStreams() {
  11385. return [this];
  11386. },
  11387. allChunksLoaded: function ChunkedStream_allChunksLoaded() {
  11388. return this.numChunksLoaded === this.numChunks;
  11389. },
  11390. onReceiveData: function ChunkedStream_onReceiveData(begin, chunk) {
  11391. var end = begin + chunk.byteLength;
  11392. assert(begin % this.chunkSize === 0, 'Bad begin offset: ' + begin);
  11393. // Using this.length is inaccurate here since this.start can be moved
  11394. // See ChunkedStream.moveStart()
  11395. var length = this.bytes.length;
  11396. assert(end % this.chunkSize === 0 || end === length,
  11397. 'Bad end offset: ' + end);
  11398. this.bytes.set(new Uint8Array(chunk), begin);
  11399. var chunkSize = this.chunkSize;
  11400. var beginChunk = Math.floor(begin / chunkSize);
  11401. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  11402. var curChunk;
  11403. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  11404. if (!this.loadedChunks[curChunk]) {
  11405. this.loadedChunks[curChunk] = true;
  11406. ++this.numChunksLoaded;
  11407. }
  11408. }
  11409. },
  11410. onReceiveProgressiveData:
  11411. function ChunkedStream_onReceiveProgressiveData(data) {
  11412. var position = this.progressiveDataLength;
  11413. var beginChunk = Math.floor(position / this.chunkSize);
  11414. this.bytes.set(new Uint8Array(data), position);
  11415. position += data.byteLength;
  11416. this.progressiveDataLength = position;
  11417. var endChunk = position >= this.end ? this.numChunks :
  11418. Math.floor(position / this.chunkSize);
  11419. var curChunk;
  11420. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  11421. if (!this.loadedChunks[curChunk]) {
  11422. this.loadedChunks[curChunk] = true;
  11423. ++this.numChunksLoaded;
  11424. }
  11425. }
  11426. },
  11427. ensureByte: function ChunkedStream_ensureByte(pos) {
  11428. var chunk = Math.floor(pos / this.chunkSize);
  11429. if (chunk === this.lastSuccessfulEnsureByteChunk) {
  11430. return;
  11431. }
  11432. if (!this.loadedChunks[chunk]) {
  11433. throw new MissingDataException(pos, pos + 1);
  11434. }
  11435. this.lastSuccessfulEnsureByteChunk = chunk;
  11436. },
  11437. ensureRange: function ChunkedStream_ensureRange(begin, end) {
  11438. if (begin >= end) {
  11439. return;
  11440. }
  11441. if (end <= this.progressiveDataLength) {
  11442. return;
  11443. }
  11444. var chunkSize = this.chunkSize;
  11445. var beginChunk = Math.floor(begin / chunkSize);
  11446. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  11447. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  11448. if (!this.loadedChunks[chunk]) {
  11449. throw new MissingDataException(begin, end);
  11450. }
  11451. }
  11452. },
  11453. nextEmptyChunk: function ChunkedStream_nextEmptyChunk(beginChunk) {
  11454. var chunk, numChunks = this.numChunks;
  11455. for (var i = 0; i < numChunks; ++i) {
  11456. chunk = (beginChunk + i) % numChunks; // Wrap around to beginning
  11457. if (!this.loadedChunks[chunk]) {
  11458. return chunk;
  11459. }
  11460. }
  11461. return null;
  11462. },
  11463. hasChunk: function ChunkedStream_hasChunk(chunk) {
  11464. return !!this.loadedChunks[chunk];
  11465. },
  11466. get length() {
  11467. return this.end - this.start;
  11468. },
  11469. get isEmpty() {
  11470. return this.length === 0;
  11471. },
  11472. getByte: function ChunkedStream_getByte() {
  11473. var pos = this.pos;
  11474. if (pos >= this.end) {
  11475. return -1;
  11476. }
  11477. this.ensureByte(pos);
  11478. return this.bytes[this.pos++];
  11479. },
  11480. getUint16: function ChunkedStream_getUint16() {
  11481. var b0 = this.getByte();
  11482. var b1 = this.getByte();
  11483. if (b0 === -1 || b1 === -1) {
  11484. return -1;
  11485. }
  11486. return (b0 << 8) + b1;
  11487. },
  11488. getInt32: function ChunkedStream_getInt32() {
  11489. var b0 = this.getByte();
  11490. var b1 = this.getByte();
  11491. var b2 = this.getByte();
  11492. var b3 = this.getByte();
  11493. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  11494. },
  11495. // returns subarray of original buffer
  11496. // should only be read
  11497. getBytes: function ChunkedStream_getBytes(length) {
  11498. var bytes = this.bytes;
  11499. var pos = this.pos;
  11500. var strEnd = this.end;
  11501. if (!length) {
  11502. this.ensureRange(pos, strEnd);
  11503. return bytes.subarray(pos, strEnd);
  11504. }
  11505. var end = pos + length;
  11506. if (end > strEnd) {
  11507. end = strEnd;
  11508. }
  11509. this.ensureRange(pos, end);
  11510. this.pos = end;
  11511. return bytes.subarray(pos, end);
  11512. },
  11513. peekByte: function ChunkedStream_peekByte() {
  11514. var peekedByte = this.getByte();
  11515. this.pos--;
  11516. return peekedByte;
  11517. },
  11518. peekBytes: function ChunkedStream_peekBytes(length) {
  11519. var bytes = this.getBytes(length);
  11520. this.pos -= bytes.length;
  11521. return bytes;
  11522. },
  11523. getByteRange: function ChunkedStream_getBytes(begin, end) {
  11524. this.ensureRange(begin, end);
  11525. return this.bytes.subarray(begin, end);
  11526. },
  11527. skip: function ChunkedStream_skip(n) {
  11528. if (!n) {
  11529. n = 1;
  11530. }
  11531. this.pos += n;
  11532. },
  11533. reset: function ChunkedStream_reset() {
  11534. this.pos = this.start;
  11535. },
  11536. moveStart: function ChunkedStream_moveStart() {
  11537. this.start = this.pos;
  11538. },
  11539. makeSubStream: function ChunkedStream_makeSubStream(start, length, dict) {
  11540. this.ensureRange(start, start + length);
  11541. function ChunkedStreamSubstream() {}
  11542. ChunkedStreamSubstream.prototype = Object.create(this);
  11543. ChunkedStreamSubstream.prototype.getMissingChunks = function() {
  11544. var chunkSize = this.chunkSize;
  11545. var beginChunk = Math.floor(this.start / chunkSize);
  11546. var endChunk = Math.floor((this.end - 1) / chunkSize) + 1;
  11547. var missingChunks = [];
  11548. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  11549. if (!this.loadedChunks[chunk]) {
  11550. missingChunks.push(chunk);
  11551. }
  11552. }
  11553. return missingChunks;
  11554. };
  11555. var subStream = new ChunkedStreamSubstream();
  11556. subStream.pos = subStream.start = start;
  11557. subStream.end = start + length || this.end;
  11558. subStream.dict = dict;
  11559. return subStream;
  11560. },
  11561. isStream: true
  11562. };
  11563. return ChunkedStream;
  11564. })();
  11565. var ChunkedStreamManager = (function ChunkedStreamManagerClosure() {
  11566. function ChunkedStreamManager(length, chunkSize, url, args) {
  11567. this.stream = new ChunkedStream(length, chunkSize, this);
  11568. this.length = length;
  11569. this.chunkSize = chunkSize;
  11570. this.url = url;
  11571. this.disableAutoFetch = args.disableAutoFetch;
  11572. var msgHandler = this.msgHandler = args.msgHandler;
  11573. if (args.chunkedViewerLoading) {
  11574. msgHandler.on('OnDataRange', this.onReceiveData.bind(this));
  11575. msgHandler.on('OnDataProgress', this.onProgress.bind(this));
  11576. this.sendRequest = function ChunkedStreamManager_sendRequest(begin, end) {
  11577. msgHandler.send('RequestDataRange', { begin: begin, end: end });
  11578. };
  11579. } else {
  11580. var getXhr = function getXhr() {
  11581. return new XMLHttpRequest();
  11582. };
  11583. this.networkManager = new NetworkManager(this.url, {
  11584. getXhr: getXhr,
  11585. httpHeaders: args.httpHeaders,
  11586. withCredentials: args.withCredentials
  11587. });
  11588. this.sendRequest = function ChunkedStreamManager_sendRequest(begin, end) {
  11589. this.networkManager.requestRange(begin, end, {
  11590. onDone: this.onReceiveData.bind(this),
  11591. onProgress: this.onProgress.bind(this)
  11592. });
  11593. };
  11594. }
  11595. this.currRequestId = 0;
  11596. this.chunksNeededByRequest = {};
  11597. this.requestsByChunk = {};
  11598. this.promisesByRequest = {};
  11599. this.progressiveDataLength = 0;
  11600. this._loadedStreamCapability = createPromiseCapability();
  11601. if (args.initialData) {
  11602. this.onReceiveData({chunk: args.initialData});
  11603. }
  11604. }
  11605. ChunkedStreamManager.prototype = {
  11606. onLoadedStream: function ChunkedStreamManager_getLoadedStream() {
  11607. return this._loadedStreamCapability.promise;
  11608. },
  11609. // Get all the chunks that are not yet loaded and groups them into
  11610. // contiguous ranges to load in as few requests as possible
  11611. requestAllChunks: function ChunkedStreamManager_requestAllChunks() {
  11612. var missingChunks = this.stream.getMissingChunks();
  11613. this._requestChunks(missingChunks);
  11614. return this._loadedStreamCapability.promise;
  11615. },
  11616. _requestChunks: function ChunkedStreamManager_requestChunks(chunks) {
  11617. var requestId = this.currRequestId++;
  11618. var chunksNeeded;
  11619. var i, ii;
  11620. this.chunksNeededByRequest[requestId] = chunksNeeded = {};
  11621. for (i = 0, ii = chunks.length; i < ii; i++) {
  11622. if (!this.stream.hasChunk(chunks[i])) {
  11623. chunksNeeded[chunks[i]] = true;
  11624. }
  11625. }
  11626. if (isEmptyObj(chunksNeeded)) {
  11627. return Promise.resolve();
  11628. }
  11629. var capability = createPromiseCapability();
  11630. this.promisesByRequest[requestId] = capability;
  11631. var chunksToRequest = [];
  11632. for (var chunk in chunksNeeded) {
  11633. chunk = chunk | 0;
  11634. if (!(chunk in this.requestsByChunk)) {
  11635. this.requestsByChunk[chunk] = [];
  11636. chunksToRequest.push(chunk);
  11637. }
  11638. this.requestsByChunk[chunk].push(requestId);
  11639. }
  11640. if (!chunksToRequest.length) {
  11641. return capability.promise;
  11642. }
  11643. var groupedChunksToRequest = this.groupChunks(chunksToRequest);
  11644. for (i = 0; i < groupedChunksToRequest.length; ++i) {
  11645. var groupedChunk = groupedChunksToRequest[i];
  11646. var begin = groupedChunk.beginChunk * this.chunkSize;
  11647. var end = Math.min(groupedChunk.endChunk * this.chunkSize, this.length);
  11648. this.sendRequest(begin, end);
  11649. }
  11650. return capability.promise;
  11651. },
  11652. getStream: function ChunkedStreamManager_getStream() {
  11653. return this.stream;
  11654. },
  11655. // Loads any chunks in the requested range that are not yet loaded
  11656. requestRange: function ChunkedStreamManager_requestRange(begin, end) {
  11657. end = Math.min(end, this.length);
  11658. var beginChunk = this.getBeginChunk(begin);
  11659. var endChunk = this.getEndChunk(end);
  11660. var chunks = [];
  11661. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  11662. chunks.push(chunk);
  11663. }
  11664. return this._requestChunks(chunks);
  11665. },
  11666. requestRanges: function ChunkedStreamManager_requestRanges(ranges) {
  11667. ranges = ranges || [];
  11668. var chunksToRequest = [];
  11669. for (var i = 0; i < ranges.length; i++) {
  11670. var beginChunk = this.getBeginChunk(ranges[i].begin);
  11671. var endChunk = this.getEndChunk(ranges[i].end);
  11672. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  11673. if (chunksToRequest.indexOf(chunk) < 0) {
  11674. chunksToRequest.push(chunk);
  11675. }
  11676. }
  11677. }
  11678. chunksToRequest.sort(function(a, b) { return a - b; });
  11679. return this._requestChunks(chunksToRequest);
  11680. },
  11681. // Groups a sorted array of chunks into as few contiguous larger
  11682. // chunks as possible
  11683. groupChunks: function ChunkedStreamManager_groupChunks(chunks) {
  11684. var groupedChunks = [];
  11685. var beginChunk = -1;
  11686. var prevChunk = -1;
  11687. for (var i = 0; i < chunks.length; ++i) {
  11688. var chunk = chunks[i];
  11689. if (beginChunk < 0) {
  11690. beginChunk = chunk;
  11691. }
  11692. if (prevChunk >= 0 && prevChunk + 1 !== chunk) {
  11693. groupedChunks.push({ beginChunk: beginChunk,
  11694. endChunk: prevChunk + 1 });
  11695. beginChunk = chunk;
  11696. }
  11697. if (i + 1 === chunks.length) {
  11698. groupedChunks.push({ beginChunk: beginChunk,
  11699. endChunk: chunk + 1 });
  11700. }
  11701. prevChunk = chunk;
  11702. }
  11703. return groupedChunks;
  11704. },
  11705. onProgress: function ChunkedStreamManager_onProgress(args) {
  11706. var bytesLoaded = (this.stream.numChunksLoaded * this.chunkSize +
  11707. args.loaded);
  11708. this.msgHandler.send('DocProgress', {
  11709. loaded: bytesLoaded,
  11710. total: this.length
  11711. });
  11712. },
  11713. onReceiveData: function ChunkedStreamManager_onReceiveData(args) {
  11714. var chunk = args.chunk;
  11715. var isProgressive = args.begin === undefined;
  11716. var begin = isProgressive ? this.progressiveDataLength : args.begin;
  11717. var end = begin + chunk.byteLength;
  11718. var beginChunk = Math.floor(begin / this.chunkSize);
  11719. var endChunk = end < this.length ? Math.floor(end / this.chunkSize) :
  11720. Math.ceil(end / this.chunkSize);
  11721. if (isProgressive) {
  11722. this.stream.onReceiveProgressiveData(chunk);
  11723. this.progressiveDataLength = end;
  11724. } else {
  11725. this.stream.onReceiveData(begin, chunk);
  11726. }
  11727. if (this.stream.allChunksLoaded()) {
  11728. this._loadedStreamCapability.resolve(this.stream);
  11729. }
  11730. var loadedRequests = [];
  11731. var i, requestId;
  11732. for (chunk = beginChunk; chunk < endChunk; ++chunk) {
  11733. // The server might return more chunks than requested
  11734. var requestIds = this.requestsByChunk[chunk] || [];
  11735. delete this.requestsByChunk[chunk];
  11736. for (i = 0; i < requestIds.length; ++i) {
  11737. requestId = requestIds[i];
  11738. var chunksNeeded = this.chunksNeededByRequest[requestId];
  11739. if (chunk in chunksNeeded) {
  11740. delete chunksNeeded[chunk];
  11741. }
  11742. if (!isEmptyObj(chunksNeeded)) {
  11743. continue;
  11744. }
  11745. loadedRequests.push(requestId);
  11746. }
  11747. }
  11748. // If there are no pending requests, automatically fetch the next
  11749. // unfetched chunk of the PDF
  11750. if (!this.disableAutoFetch && isEmptyObj(this.requestsByChunk)) {
  11751. var nextEmptyChunk;
  11752. if (this.stream.numChunksLoaded === 1) {
  11753. // This is a special optimization so that after fetching the first
  11754. // chunk, rather than fetching the second chunk, we fetch the last
  11755. // chunk.
  11756. var lastChunk = this.stream.numChunks - 1;
  11757. if (!this.stream.hasChunk(lastChunk)) {
  11758. nextEmptyChunk = lastChunk;
  11759. }
  11760. } else {
  11761. nextEmptyChunk = this.stream.nextEmptyChunk(endChunk);
  11762. }
  11763. if (isInt(nextEmptyChunk)) {
  11764. this._requestChunks([nextEmptyChunk]);
  11765. }
  11766. }
  11767. for (i = 0; i < loadedRequests.length; ++i) {
  11768. requestId = loadedRequests[i];
  11769. var capability = this.promisesByRequest[requestId];
  11770. delete this.promisesByRequest[requestId];
  11771. capability.resolve();
  11772. }
  11773. this.msgHandler.send('DocProgress', {
  11774. loaded: this.stream.numChunksLoaded * this.chunkSize,
  11775. total: this.length
  11776. });
  11777. },
  11778. onError: function ChunkedStreamManager_onError(err) {
  11779. this._loadedStreamCapability.reject(err);
  11780. },
  11781. getBeginChunk: function ChunkedStreamManager_getBeginChunk(begin) {
  11782. var chunk = Math.floor(begin / this.chunkSize);
  11783. return chunk;
  11784. },
  11785. getEndChunk: function ChunkedStreamManager_getEndChunk(end) {
  11786. var chunk = Math.floor((end - 1) / this.chunkSize) + 1;
  11787. return chunk;
  11788. },
  11789. abort: function ChunkedStreamManager_abort() {
  11790. if (this.networkManager) {
  11791. this.networkManager.abortAllRequests();
  11792. }
  11793. for(var requestId in this.promisesByRequest) {
  11794. var capability = this.promisesByRequest[requestId];
  11795. capability.reject(new Error('Request was aborted'));
  11796. }
  11797. }
  11798. };
  11799. return ChunkedStreamManager;
  11800. })();
  11801. exports.ChunkedStream = ChunkedStream;
  11802. exports.ChunkedStreamManager = ChunkedStreamManager;
  11803. }));
  11804. (function (root, factory) {
  11805. {
  11806. factory((root.pdfjsCoreJbig2 = {}), root.pdfjsSharedUtil,
  11807. root.pdfjsCoreArithmeticDecoder);
  11808. }
  11809. }(this, function (exports, sharedUtil, coreArithmeticDecoder) {
  11810. var error = sharedUtil.error;
  11811. var log2 = sharedUtil.log2;
  11812. var readInt8 = sharedUtil.readInt8;
  11813. var readUint16 = sharedUtil.readUint16;
  11814. var readUint32 = sharedUtil.readUint32;
  11815. var shadow = sharedUtil.shadow;
  11816. var ArithmeticDecoder = coreArithmeticDecoder.ArithmeticDecoder;
  11817. var Jbig2Image = (function Jbig2ImageClosure() {
  11818. // Utility data structures
  11819. function ContextCache() {}
  11820. ContextCache.prototype = {
  11821. getContexts: function(id) {
  11822. if (id in this) {
  11823. return this[id];
  11824. }
  11825. return (this[id] = new Int8Array(1 << 16));
  11826. }
  11827. };
  11828. function DecodingContext(data, start, end) {
  11829. this.data = data;
  11830. this.start = start;
  11831. this.end = end;
  11832. }
  11833. DecodingContext.prototype = {
  11834. get decoder() {
  11835. var decoder = new ArithmeticDecoder(this.data, this.start, this.end);
  11836. return shadow(this, 'decoder', decoder);
  11837. },
  11838. get contextCache() {
  11839. var cache = new ContextCache();
  11840. return shadow(this, 'contextCache', cache);
  11841. }
  11842. };
  11843. // Annex A. Arithmetic Integer Decoding Procedure
  11844. // A.2 Procedure for decoding values
  11845. function decodeInteger(contextCache, procedure, decoder) {
  11846. var contexts = contextCache.getContexts(procedure);
  11847. var prev = 1;
  11848. function readBits(length) {
  11849. var v = 0;
  11850. for (var i = 0; i < length; i++) {
  11851. var bit = decoder.readBit(contexts, prev);
  11852. prev = (prev < 256 ? (prev << 1) | bit :
  11853. (((prev << 1) | bit) & 511) | 256);
  11854. v = (v << 1) | bit;
  11855. }
  11856. return v >>> 0;
  11857. }
  11858. var sign = readBits(1);
  11859. var value = readBits(1) ?
  11860. (readBits(1) ?
  11861. (readBits(1) ?
  11862. (readBits(1) ?
  11863. (readBits(1) ?
  11864. (readBits(32) + 4436) :
  11865. readBits(12) + 340) :
  11866. readBits(8) + 84) :
  11867. readBits(6) + 20) :
  11868. readBits(4) + 4) :
  11869. readBits(2);
  11870. return (sign === 0 ? value : (value > 0 ? -value : null));
  11871. }
  11872. // A.3 The IAID decoding procedure
  11873. function decodeIAID(contextCache, decoder, codeLength) {
  11874. var contexts = contextCache.getContexts('IAID');
  11875. var prev = 1;
  11876. for (var i = 0; i < codeLength; i++) {
  11877. var bit = decoder.readBit(contexts, prev);
  11878. prev = (prev << 1) | bit;
  11879. }
  11880. if (codeLength < 31) {
  11881. return prev & ((1 << codeLength) - 1);
  11882. }
  11883. return prev & 0x7FFFFFFF;
  11884. }
  11885. // 7.3 Segment types
  11886. var SegmentTypes = [
  11887. 'SymbolDictionary', null, null, null, 'IntermediateTextRegion', null,
  11888. 'ImmediateTextRegion', 'ImmediateLosslessTextRegion', null, null, null,
  11889. null, null, null, null, null, 'patternDictionary', null, null, null,
  11890. 'IntermediateHalftoneRegion', null, 'ImmediateHalftoneRegion',
  11891. 'ImmediateLosslessHalftoneRegion', null, null, null, null, null, null, null,
  11892. null, null, null, null, null, 'IntermediateGenericRegion', null,
  11893. 'ImmediateGenericRegion', 'ImmediateLosslessGenericRegion',
  11894. 'IntermediateGenericRefinementRegion', null,
  11895. 'ImmediateGenericRefinementRegion',
  11896. 'ImmediateLosslessGenericRefinementRegion', null, null, null, null,
  11897. 'PageInformation', 'EndOfPage', 'EndOfStripe', 'EndOfFile', 'Profiles',
  11898. 'Tables', null, null, null, null, null, null, null, null,
  11899. 'Extension'
  11900. ];
  11901. var CodingTemplates = [
  11902. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  11903. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: 2, y: -1},
  11904. {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  11905. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: 2, y: -2},
  11906. {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1},
  11907. {x: 2, y: -1}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  11908. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  11909. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -2, y: 0},
  11910. {x: -1, y: 0}],
  11911. [{x: -3, y: -1}, {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1},
  11912. {x: 1, y: -1}, {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}]
  11913. ];
  11914. var RefinementTemplates = [
  11915. {
  11916. coding: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  11917. reference: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}, {x: 0, y: 0},
  11918. {x: 1, y: 0}, {x: -1, y: 1}, {x: 0, y: 1}, {x: 1, y: 1}]
  11919. },
  11920. {
  11921. coding: [{x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  11922. reference: [{x: 0, y: -1}, {x: -1, y: 0}, {x: 0, y: 0}, {x: 1, y: 0},
  11923. {x: 0, y: 1}, {x: 1, y: 1}]
  11924. }
  11925. ];
  11926. // See 6.2.5.7 Decoding the bitmap.
  11927. var ReusedContexts = [
  11928. 0x9B25, // 10011 0110010 0101
  11929. 0x0795, // 0011 110010 101
  11930. 0x00E5, // 001 11001 01
  11931. 0x0195 // 011001 0101
  11932. ];
  11933. var RefinementReusedContexts = [
  11934. 0x0020, // '000' + '0' (coding) + '00010000' + '0' (reference)
  11935. 0x0008 // '0000' + '001000'
  11936. ];
  11937. function decodeBitmapTemplate0(width, height, decodingContext) {
  11938. var decoder = decodingContext.decoder;
  11939. var contexts = decodingContext.contextCache.getContexts('GB');
  11940. var contextLabel, i, j, pixel, row, row1, row2, bitmap = [];
  11941. // ...ooooo....
  11942. // ..ooooooo... Context template for current pixel (X)
  11943. // .ooooX...... (concatenate values of 'o'-pixels to get contextLabel)
  11944. var OLD_PIXEL_MASK = 0x7BF7; // 01111 0111111 0111
  11945. for (i = 0; i < height; i++) {
  11946. row = bitmap[i] = new Uint8Array(width);
  11947. row1 = (i < 1) ? row : bitmap[i - 1];
  11948. row2 = (i < 2) ? row : bitmap[i - 2];
  11949. // At the beginning of each row:
  11950. // Fill contextLabel with pixels that are above/right of (X)
  11951. contextLabel = (row2[0] << 13) | (row2[1] << 12) | (row2[2] << 11) |
  11952. (row1[0] << 7) | (row1[1] << 6) | (row1[2] << 5) |
  11953. (row1[3] << 4);
  11954. for (j = 0; j < width; j++) {
  11955. row[j] = pixel = decoder.readBit(contexts, contextLabel);
  11956. // At each pixel: Clear contextLabel pixels that are shifted
  11957. // out of the context, then add new ones.
  11958. contextLabel = ((contextLabel & OLD_PIXEL_MASK) << 1) |
  11959. (j + 3 < width ? row2[j + 3] << 11 : 0) |
  11960. (j + 4 < width ? row1[j + 4] << 4 : 0) | pixel;
  11961. }
  11962. }
  11963. return bitmap;
  11964. }
  11965. // 6.2 Generic Region Decoding Procedure
  11966. function decodeBitmap(mmr, width, height, templateIndex, prediction, skip, at,
  11967. decodingContext) {
  11968. if (mmr) {
  11969. error('JBIG2 error: MMR encoding is not supported');
  11970. }
  11971. // Use optimized version for the most common case
  11972. if (templateIndex === 0 && !skip && !prediction && at.length === 4 &&
  11973. at[0].x === 3 && at[0].y === -1 && at[1].x === -3 && at[1].y === -1 &&
  11974. at[2].x === 2 && at[2].y === -2 && at[3].x === -2 && at[3].y === -2) {
  11975. return decodeBitmapTemplate0(width, height, decodingContext);
  11976. }
  11977. var useskip = !!skip;
  11978. var template = CodingTemplates[templateIndex].concat(at);
  11979. // Sorting is non-standard, and it is not required. But sorting increases
  11980. // the number of template bits that can be reused from the previous
  11981. // contextLabel in the main loop.
  11982. template.sort(function (a, b) {
  11983. return (a.y - b.y) || (a.x - b.x);
  11984. });
  11985. var templateLength = template.length;
  11986. var templateX = new Int8Array(templateLength);
  11987. var templateY = new Int8Array(templateLength);
  11988. var changingTemplateEntries = [];
  11989. var reuseMask = 0, minX = 0, maxX = 0, minY = 0;
  11990. var c, k;
  11991. for (k = 0; k < templateLength; k++) {
  11992. templateX[k] = template[k].x;
  11993. templateY[k] = template[k].y;
  11994. minX = Math.min(minX, template[k].x);
  11995. maxX = Math.max(maxX, template[k].x);
  11996. minY = Math.min(minY, template[k].y);
  11997. // Check if the template pixel appears in two consecutive context labels,
  11998. // so it can be reused. Otherwise, we add it to the list of changing
  11999. // template entries.
  12000. if (k < templateLength - 1 &&
  12001. template[k].y === template[k + 1].y &&
  12002. template[k].x === template[k + 1].x - 1) {
  12003. reuseMask |= 1 << (templateLength - 1 - k);
  12004. } else {
  12005. changingTemplateEntries.push(k);
  12006. }
  12007. }
  12008. var changingEntriesLength = changingTemplateEntries.length;
  12009. var changingTemplateX = new Int8Array(changingEntriesLength);
  12010. var changingTemplateY = new Int8Array(changingEntriesLength);
  12011. var changingTemplateBit = new Uint16Array(changingEntriesLength);
  12012. for (c = 0; c < changingEntriesLength; c++) {
  12013. k = changingTemplateEntries[c];
  12014. changingTemplateX[c] = template[k].x;
  12015. changingTemplateY[c] = template[k].y;
  12016. changingTemplateBit[c] = 1 << (templateLength - 1 - k);
  12017. }
  12018. // Get the safe bounding box edges from the width, height, minX, maxX, minY
  12019. var sbb_left = -minX;
  12020. var sbb_top = -minY;
  12021. var sbb_right = width - maxX;
  12022. var pseudoPixelContext = ReusedContexts[templateIndex];
  12023. var row = new Uint8Array(width);
  12024. var bitmap = [];
  12025. var decoder = decodingContext.decoder;
  12026. var contexts = decodingContext.contextCache.getContexts('GB');
  12027. var ltp = 0, j, i0, j0, contextLabel = 0, bit, shift;
  12028. for (var i = 0; i < height; i++) {
  12029. if (prediction) {
  12030. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  12031. ltp ^= sltp;
  12032. if (ltp) {
  12033. bitmap.push(row); // duplicate previous row
  12034. continue;
  12035. }
  12036. }
  12037. row = new Uint8Array(row);
  12038. bitmap.push(row);
  12039. for (j = 0; j < width; j++) {
  12040. if (useskip && skip[i][j]) {
  12041. row[j] = 0;
  12042. continue;
  12043. }
  12044. // Are we in the middle of a scanline, so we can reuse contextLabel
  12045. // bits?
  12046. if (j >= sbb_left && j < sbb_right && i >= sbb_top) {
  12047. // If yes, we can just shift the bits that are reusable and only
  12048. // fetch the remaining ones.
  12049. contextLabel = (contextLabel << 1) & reuseMask;
  12050. for (k = 0; k < changingEntriesLength; k++) {
  12051. i0 = i + changingTemplateY[k];
  12052. j0 = j + changingTemplateX[k];
  12053. bit = bitmap[i0][j0];
  12054. if (bit) {
  12055. bit = changingTemplateBit[k];
  12056. contextLabel |= bit;
  12057. }
  12058. }
  12059. } else {
  12060. // compute the contextLabel from scratch
  12061. contextLabel = 0;
  12062. shift = templateLength - 1;
  12063. for (k = 0; k < templateLength; k++, shift--) {
  12064. j0 = j + templateX[k];
  12065. if (j0 >= 0 && j0 < width) {
  12066. i0 = i + templateY[k];
  12067. if (i0 >= 0) {
  12068. bit = bitmap[i0][j0];
  12069. if (bit) {
  12070. contextLabel |= bit << shift;
  12071. }
  12072. }
  12073. }
  12074. }
  12075. }
  12076. var pixel = decoder.readBit(contexts, contextLabel);
  12077. row[j] = pixel;
  12078. }
  12079. }
  12080. return bitmap;
  12081. }
  12082. // 6.3.2 Generic Refinement Region Decoding Procedure
  12083. function decodeRefinement(width, height, templateIndex, referenceBitmap,
  12084. offsetX, offsetY, prediction, at,
  12085. decodingContext) {
  12086. var codingTemplate = RefinementTemplates[templateIndex].coding;
  12087. if (templateIndex === 0) {
  12088. codingTemplate = codingTemplate.concat([at[0]]);
  12089. }
  12090. var codingTemplateLength = codingTemplate.length;
  12091. var codingTemplateX = new Int32Array(codingTemplateLength);
  12092. var codingTemplateY = new Int32Array(codingTemplateLength);
  12093. var k;
  12094. for (k = 0; k < codingTemplateLength; k++) {
  12095. codingTemplateX[k] = codingTemplate[k].x;
  12096. codingTemplateY[k] = codingTemplate[k].y;
  12097. }
  12098. var referenceTemplate = RefinementTemplates[templateIndex].reference;
  12099. if (templateIndex === 0) {
  12100. referenceTemplate = referenceTemplate.concat([at[1]]);
  12101. }
  12102. var referenceTemplateLength = referenceTemplate.length;
  12103. var referenceTemplateX = new Int32Array(referenceTemplateLength);
  12104. var referenceTemplateY = new Int32Array(referenceTemplateLength);
  12105. for (k = 0; k < referenceTemplateLength; k++) {
  12106. referenceTemplateX[k] = referenceTemplate[k].x;
  12107. referenceTemplateY[k] = referenceTemplate[k].y;
  12108. }
  12109. var referenceWidth = referenceBitmap[0].length;
  12110. var referenceHeight = referenceBitmap.length;
  12111. var pseudoPixelContext = RefinementReusedContexts[templateIndex];
  12112. var bitmap = [];
  12113. var decoder = decodingContext.decoder;
  12114. var contexts = decodingContext.contextCache.getContexts('GR');
  12115. var ltp = 0;
  12116. for (var i = 0; i < height; i++) {
  12117. if (prediction) {
  12118. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  12119. ltp ^= sltp;
  12120. if (ltp) {
  12121. error('JBIG2 error: prediction is not supported');
  12122. }
  12123. }
  12124. var row = new Uint8Array(width);
  12125. bitmap.push(row);
  12126. for (var j = 0; j < width; j++) {
  12127. var i0, j0;
  12128. var contextLabel = 0;
  12129. for (k = 0; k < codingTemplateLength; k++) {
  12130. i0 = i + codingTemplateY[k];
  12131. j0 = j + codingTemplateX[k];
  12132. if (i0 < 0 || j0 < 0 || j0 >= width) {
  12133. contextLabel <<= 1; // out of bound pixel
  12134. } else {
  12135. contextLabel = (contextLabel << 1) | bitmap[i0][j0];
  12136. }
  12137. }
  12138. for (k = 0; k < referenceTemplateLength; k++) {
  12139. i0 = i + referenceTemplateY[k] + offsetY;
  12140. j0 = j + referenceTemplateX[k] + offsetX;
  12141. if (i0 < 0 || i0 >= referenceHeight || j0 < 0 ||
  12142. j0 >= referenceWidth) {
  12143. contextLabel <<= 1; // out of bound pixel
  12144. } else {
  12145. contextLabel = (contextLabel << 1) | referenceBitmap[i0][j0];
  12146. }
  12147. }
  12148. var pixel = decoder.readBit(contexts, contextLabel);
  12149. row[j] = pixel;
  12150. }
  12151. }
  12152. return bitmap;
  12153. }
  12154. // 6.5.5 Decoding the symbol dictionary
  12155. function decodeSymbolDictionary(huffman, refinement, symbols,
  12156. numberOfNewSymbols, numberOfExportedSymbols,
  12157. huffmanTables, templateIndex, at,
  12158. refinementTemplateIndex, refinementAt,
  12159. decodingContext) {
  12160. if (huffman) {
  12161. error('JBIG2 error: huffman is not supported');
  12162. }
  12163. var newSymbols = [];
  12164. var currentHeight = 0;
  12165. var symbolCodeLength = log2(symbols.length + numberOfNewSymbols);
  12166. var decoder = decodingContext.decoder;
  12167. var contextCache = decodingContext.contextCache;
  12168. while (newSymbols.length < numberOfNewSymbols) {
  12169. var deltaHeight = decodeInteger(contextCache, 'IADH', decoder); // 6.5.6
  12170. currentHeight += deltaHeight;
  12171. var currentWidth = 0;
  12172. var totalWidth = 0;
  12173. while (true) {
  12174. var deltaWidth = decodeInteger(contextCache, 'IADW', decoder); // 6.5.7
  12175. if (deltaWidth === null) {
  12176. break; // OOB
  12177. }
  12178. currentWidth += deltaWidth;
  12179. totalWidth += currentWidth;
  12180. var bitmap;
  12181. if (refinement) {
  12182. // 6.5.8.2 Refinement/aggregate-coded symbol bitmap
  12183. var numberOfInstances = decodeInteger(contextCache, 'IAAI', decoder);
  12184. if (numberOfInstances > 1) {
  12185. bitmap = decodeTextRegion(huffman, refinement,
  12186. currentWidth, currentHeight, 0,
  12187. numberOfInstances, 1, //strip size
  12188. symbols.concat(newSymbols),
  12189. symbolCodeLength,
  12190. 0, //transposed
  12191. 0, //ds offset
  12192. 1, //top left 7.4.3.1.1
  12193. 0, //OR operator
  12194. huffmanTables,
  12195. refinementTemplateIndex, refinementAt,
  12196. decodingContext);
  12197. } else {
  12198. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  12199. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  12200. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  12201. var symbol = (symbolId < symbols.length ? symbols[symbolId] :
  12202. newSymbols[symbolId - symbols.length]);
  12203. bitmap = decodeRefinement(currentWidth, currentHeight,
  12204. refinementTemplateIndex, symbol, rdx, rdy, false, refinementAt,
  12205. decodingContext);
  12206. }
  12207. } else {
  12208. // 6.5.8.1 Direct-coded symbol bitmap
  12209. bitmap = decodeBitmap(false, currentWidth, currentHeight,
  12210. templateIndex, false, null, at, decodingContext);
  12211. }
  12212. newSymbols.push(bitmap);
  12213. }
  12214. }
  12215. // 6.5.10 Exported symbols
  12216. var exportedSymbols = [];
  12217. var flags = [], currentFlag = false;
  12218. var totalSymbolsLength = symbols.length + numberOfNewSymbols;
  12219. while (flags.length < totalSymbolsLength) {
  12220. var runLength = decodeInteger(contextCache, 'IAEX', decoder);
  12221. while (runLength--) {
  12222. flags.push(currentFlag);
  12223. }
  12224. currentFlag = !currentFlag;
  12225. }
  12226. for (var i = 0, ii = symbols.length; i < ii; i++) {
  12227. if (flags[i]) {
  12228. exportedSymbols.push(symbols[i]);
  12229. }
  12230. }
  12231. for (var j = 0; j < numberOfNewSymbols; i++, j++) {
  12232. if (flags[i]) {
  12233. exportedSymbols.push(newSymbols[j]);
  12234. }
  12235. }
  12236. return exportedSymbols;
  12237. }
  12238. function decodeTextRegion(huffman, refinement, width, height,
  12239. defaultPixelValue, numberOfSymbolInstances,
  12240. stripSize, inputSymbols, symbolCodeLength,
  12241. transposed, dsOffset, referenceCorner,
  12242. combinationOperator, huffmanTables,
  12243. refinementTemplateIndex, refinementAt,
  12244. decodingContext) {
  12245. if (huffman) {
  12246. error('JBIG2 error: huffman is not supported');
  12247. }
  12248. // Prepare bitmap
  12249. var bitmap = [];
  12250. var i, row;
  12251. for (i = 0; i < height; i++) {
  12252. row = new Uint8Array(width);
  12253. if (defaultPixelValue) {
  12254. for (var j = 0; j < width; j++) {
  12255. row[j] = defaultPixelValue;
  12256. }
  12257. }
  12258. bitmap.push(row);
  12259. }
  12260. var decoder = decodingContext.decoder;
  12261. var contextCache = decodingContext.contextCache;
  12262. var stripT = -decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  12263. var firstS = 0;
  12264. i = 0;
  12265. while (i < numberOfSymbolInstances) {
  12266. var deltaT = decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  12267. stripT += deltaT;
  12268. var deltaFirstS = decodeInteger(contextCache, 'IAFS', decoder); // 6.4.7
  12269. firstS += deltaFirstS;
  12270. var currentS = firstS;
  12271. do {
  12272. var currentT = (stripSize === 1 ? 0 :
  12273. decodeInteger(contextCache, 'IAIT', decoder)); // 6.4.9
  12274. var t = stripSize * stripT + currentT;
  12275. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  12276. var applyRefinement = (refinement &&
  12277. decodeInteger(contextCache, 'IARI', decoder));
  12278. var symbolBitmap = inputSymbols[symbolId];
  12279. var symbolWidth = symbolBitmap[0].length;
  12280. var symbolHeight = symbolBitmap.length;
  12281. if (applyRefinement) {
  12282. var rdw = decodeInteger(contextCache, 'IARDW', decoder); // 6.4.11.1
  12283. var rdh = decodeInteger(contextCache, 'IARDH', decoder); // 6.4.11.2
  12284. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  12285. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  12286. symbolWidth += rdw;
  12287. symbolHeight += rdh;
  12288. symbolBitmap = decodeRefinement(symbolWidth, symbolHeight,
  12289. refinementTemplateIndex, symbolBitmap, (rdw >> 1) + rdx,
  12290. (rdh >> 1) + rdy, false, refinementAt,
  12291. decodingContext);
  12292. }
  12293. var offsetT = t - ((referenceCorner & 1) ? 0 : symbolHeight);
  12294. var offsetS = currentS - ((referenceCorner & 2) ? symbolWidth : 0);
  12295. var s2, t2, symbolRow;
  12296. if (transposed) {
  12297. // Place Symbol Bitmap from T1,S1
  12298. for (s2 = 0; s2 < symbolHeight; s2++) {
  12299. row = bitmap[offsetS + s2];
  12300. if (!row) {
  12301. continue;
  12302. }
  12303. symbolRow = symbolBitmap[s2];
  12304. // To ignore Parts of Symbol bitmap which goes
  12305. // outside bitmap region
  12306. var maxWidth = Math.min(width - offsetT, symbolWidth);
  12307. switch (combinationOperator) {
  12308. case 0: // OR
  12309. for (t2 = 0; t2 < maxWidth; t2++) {
  12310. row[offsetT + t2] |= symbolRow[t2];
  12311. }
  12312. break;
  12313. case 2: // XOR
  12314. for (t2 = 0; t2 < maxWidth; t2++) {
  12315. row[offsetT + t2] ^= symbolRow[t2];
  12316. }
  12317. break;
  12318. default:
  12319. error('JBIG2 error: operator ' + combinationOperator +
  12320. ' is not supported');
  12321. }
  12322. }
  12323. currentS += symbolHeight - 1;
  12324. } else {
  12325. for (t2 = 0; t2 < symbolHeight; t2++) {
  12326. row = bitmap[offsetT + t2];
  12327. if (!row) {
  12328. continue;
  12329. }
  12330. symbolRow = symbolBitmap[t2];
  12331. switch (combinationOperator) {
  12332. case 0: // OR
  12333. for (s2 = 0; s2 < symbolWidth; s2++) {
  12334. row[offsetS + s2] |= symbolRow[s2];
  12335. }
  12336. break;
  12337. case 2: // XOR
  12338. for (s2 = 0; s2 < symbolWidth; s2++) {
  12339. row[offsetS + s2] ^= symbolRow[s2];
  12340. }
  12341. break;
  12342. default:
  12343. error('JBIG2 error: operator ' + combinationOperator +
  12344. ' is not supported');
  12345. }
  12346. }
  12347. currentS += symbolWidth - 1;
  12348. }
  12349. i++;
  12350. var deltaS = decodeInteger(contextCache, 'IADS', decoder); // 6.4.8
  12351. if (deltaS === null) {
  12352. break; // OOB
  12353. }
  12354. currentS += deltaS + dsOffset;
  12355. } while (true);
  12356. }
  12357. return bitmap;
  12358. }
  12359. function readSegmentHeader(data, start) {
  12360. var segmentHeader = {};
  12361. segmentHeader.number = readUint32(data, start);
  12362. var flags = data[start + 4];
  12363. var segmentType = flags & 0x3F;
  12364. if (!SegmentTypes[segmentType]) {
  12365. error('JBIG2 error: invalid segment type: ' + segmentType);
  12366. }
  12367. segmentHeader.type = segmentType;
  12368. segmentHeader.typeName = SegmentTypes[segmentType];
  12369. segmentHeader.deferredNonRetain = !!(flags & 0x80);
  12370. var pageAssociationFieldSize = !!(flags & 0x40);
  12371. var referredFlags = data[start + 5];
  12372. var referredToCount = (referredFlags >> 5) & 7;
  12373. var retainBits = [referredFlags & 31];
  12374. var position = start + 6;
  12375. if (referredFlags === 7) {
  12376. referredToCount = readUint32(data, position - 1) & 0x1FFFFFFF;
  12377. position += 3;
  12378. var bytes = (referredToCount + 7) >> 3;
  12379. retainBits[0] = data[position++];
  12380. while (--bytes > 0) {
  12381. retainBits.push(data[position++]);
  12382. }
  12383. } else if (referredFlags === 5 || referredFlags === 6) {
  12384. error('JBIG2 error: invalid referred-to flags');
  12385. }
  12386. segmentHeader.retainBits = retainBits;
  12387. var referredToSegmentNumberSize = (segmentHeader.number <= 256 ? 1 :
  12388. (segmentHeader.number <= 65536 ? 2 : 4));
  12389. var referredTo = [];
  12390. var i, ii;
  12391. for (i = 0; i < referredToCount; i++) {
  12392. var number = (referredToSegmentNumberSize === 1 ? data[position] :
  12393. (referredToSegmentNumberSize === 2 ? readUint16(data, position) :
  12394. readUint32(data, position)));
  12395. referredTo.push(number);
  12396. position += referredToSegmentNumberSize;
  12397. }
  12398. segmentHeader.referredTo = referredTo;
  12399. if (!pageAssociationFieldSize) {
  12400. segmentHeader.pageAssociation = data[position++];
  12401. } else {
  12402. segmentHeader.pageAssociation = readUint32(data, position);
  12403. position += 4;
  12404. }
  12405. segmentHeader.length = readUint32(data, position);
  12406. position += 4;
  12407. if (segmentHeader.length === 0xFFFFFFFF) {
  12408. // 7.2.7 Segment data length, unknown segment length
  12409. if (segmentType === 38) { // ImmediateGenericRegion
  12410. var genericRegionInfo = readRegionSegmentInformation(data, position);
  12411. var genericRegionSegmentFlags = data[position +
  12412. RegionSegmentInformationFieldLength];
  12413. var genericRegionMmr = !!(genericRegionSegmentFlags & 1);
  12414. // searching for the segment end
  12415. var searchPatternLength = 6;
  12416. var searchPattern = new Uint8Array(searchPatternLength);
  12417. if (!genericRegionMmr) {
  12418. searchPattern[0] = 0xFF;
  12419. searchPattern[1] = 0xAC;
  12420. }
  12421. searchPattern[2] = (genericRegionInfo.height >>> 24) & 0xFF;
  12422. searchPattern[3] = (genericRegionInfo.height >> 16) & 0xFF;
  12423. searchPattern[4] = (genericRegionInfo.height >> 8) & 0xFF;
  12424. searchPattern[5] = genericRegionInfo.height & 0xFF;
  12425. for (i = position, ii = data.length; i < ii; i++) {
  12426. var j = 0;
  12427. while (j < searchPatternLength && searchPattern[j] === data[i + j]) {
  12428. j++;
  12429. }
  12430. if (j === searchPatternLength) {
  12431. segmentHeader.length = i + searchPatternLength;
  12432. break;
  12433. }
  12434. }
  12435. if (segmentHeader.length === 0xFFFFFFFF) {
  12436. error('JBIG2 error: segment end was not found');
  12437. }
  12438. } else {
  12439. error('JBIG2 error: invalid unknown segment length');
  12440. }
  12441. }
  12442. segmentHeader.headerEnd = position;
  12443. return segmentHeader;
  12444. }
  12445. function readSegments(header, data, start, end) {
  12446. var segments = [];
  12447. var position = start;
  12448. while (position < end) {
  12449. var segmentHeader = readSegmentHeader(data, position);
  12450. position = segmentHeader.headerEnd;
  12451. var segment = {
  12452. header: segmentHeader,
  12453. data: data
  12454. };
  12455. if (!header.randomAccess) {
  12456. segment.start = position;
  12457. position += segmentHeader.length;
  12458. segment.end = position;
  12459. }
  12460. segments.push(segment);
  12461. if (segmentHeader.type === 51) {
  12462. break; // end of file is found
  12463. }
  12464. }
  12465. if (header.randomAccess) {
  12466. for (var i = 0, ii = segments.length; i < ii; i++) {
  12467. segments[i].start = position;
  12468. position += segments[i].header.length;
  12469. segments[i].end = position;
  12470. }
  12471. }
  12472. return segments;
  12473. }
  12474. // 7.4.1 Region segment information field
  12475. function readRegionSegmentInformation(data, start) {
  12476. return {
  12477. width: readUint32(data, start),
  12478. height: readUint32(data, start + 4),
  12479. x: readUint32(data, start + 8),
  12480. y: readUint32(data, start + 12),
  12481. combinationOperator: data[start + 16] & 7
  12482. };
  12483. }
  12484. var RegionSegmentInformationFieldLength = 17;
  12485. function processSegment(segment, visitor) {
  12486. var header = segment.header;
  12487. var data = segment.data, position = segment.start, end = segment.end;
  12488. var args, at, i, atLength;
  12489. switch (header.type) {
  12490. case 0: // SymbolDictionary
  12491. // 7.4.2 Symbol dictionary segment syntax
  12492. var dictionary = {};
  12493. var dictionaryFlags = readUint16(data, position); // 7.4.2.1.1
  12494. dictionary.huffman = !!(dictionaryFlags & 1);
  12495. dictionary.refinement = !!(dictionaryFlags & 2);
  12496. dictionary.huffmanDHSelector = (dictionaryFlags >> 2) & 3;
  12497. dictionary.huffmanDWSelector = (dictionaryFlags >> 4) & 3;
  12498. dictionary.bitmapSizeSelector = (dictionaryFlags >> 6) & 1;
  12499. dictionary.aggregationInstancesSelector = (dictionaryFlags >> 7) & 1;
  12500. dictionary.bitmapCodingContextUsed = !!(dictionaryFlags & 256);
  12501. dictionary.bitmapCodingContextRetained = !!(dictionaryFlags & 512);
  12502. dictionary.template = (dictionaryFlags >> 10) & 3;
  12503. dictionary.refinementTemplate = (dictionaryFlags >> 12) & 1;
  12504. position += 2;
  12505. if (!dictionary.huffman) {
  12506. atLength = dictionary.template === 0 ? 4 : 1;
  12507. at = [];
  12508. for (i = 0; i < atLength; i++) {
  12509. at.push({
  12510. x: readInt8(data, position),
  12511. y: readInt8(data, position + 1)
  12512. });
  12513. position += 2;
  12514. }
  12515. dictionary.at = at;
  12516. }
  12517. if (dictionary.refinement && !dictionary.refinementTemplate) {
  12518. at = [];
  12519. for (i = 0; i < 2; i++) {
  12520. at.push({
  12521. x: readInt8(data, position),
  12522. y: readInt8(data, position + 1)
  12523. });
  12524. position += 2;
  12525. }
  12526. dictionary.refinementAt = at;
  12527. }
  12528. dictionary.numberOfExportedSymbols = readUint32(data, position);
  12529. position += 4;
  12530. dictionary.numberOfNewSymbols = readUint32(data, position);
  12531. position += 4;
  12532. args = [dictionary, header.number, header.referredTo,
  12533. data, position, end];
  12534. break;
  12535. case 6: // ImmediateTextRegion
  12536. case 7: // ImmediateLosslessTextRegion
  12537. var textRegion = {};
  12538. textRegion.info = readRegionSegmentInformation(data, position);
  12539. position += RegionSegmentInformationFieldLength;
  12540. var textRegionSegmentFlags = readUint16(data, position);
  12541. position += 2;
  12542. textRegion.huffman = !!(textRegionSegmentFlags & 1);
  12543. textRegion.refinement = !!(textRegionSegmentFlags & 2);
  12544. textRegion.stripSize = 1 << ((textRegionSegmentFlags >> 2) & 3);
  12545. textRegion.referenceCorner = (textRegionSegmentFlags >> 4) & 3;
  12546. textRegion.transposed = !!(textRegionSegmentFlags & 64);
  12547. textRegion.combinationOperator = (textRegionSegmentFlags >> 7) & 3;
  12548. textRegion.defaultPixelValue = (textRegionSegmentFlags >> 9) & 1;
  12549. textRegion.dsOffset = (textRegionSegmentFlags << 17) >> 27;
  12550. textRegion.refinementTemplate = (textRegionSegmentFlags >> 15) & 1;
  12551. if (textRegion.huffman) {
  12552. var textRegionHuffmanFlags = readUint16(data, position);
  12553. position += 2;
  12554. textRegion.huffmanFS = (textRegionHuffmanFlags) & 3;
  12555. textRegion.huffmanDS = (textRegionHuffmanFlags >> 2) & 3;
  12556. textRegion.huffmanDT = (textRegionHuffmanFlags >> 4) & 3;
  12557. textRegion.huffmanRefinementDW = (textRegionHuffmanFlags >> 6) & 3;
  12558. textRegion.huffmanRefinementDH = (textRegionHuffmanFlags >> 8) & 3;
  12559. textRegion.huffmanRefinementDX = (textRegionHuffmanFlags >> 10) & 3;
  12560. textRegion.huffmanRefinementDY = (textRegionHuffmanFlags >> 12) & 3;
  12561. textRegion.huffmanRefinementSizeSelector =
  12562. !!(textRegionHuffmanFlags & 14);
  12563. }
  12564. if (textRegion.refinement && !textRegion.refinementTemplate) {
  12565. at = [];
  12566. for (i = 0; i < 2; i++) {
  12567. at.push({
  12568. x: readInt8(data, position),
  12569. y: readInt8(data, position + 1)
  12570. });
  12571. position += 2;
  12572. }
  12573. textRegion.refinementAt = at;
  12574. }
  12575. textRegion.numberOfSymbolInstances = readUint32(data, position);
  12576. position += 4;
  12577. // TODO 7.4.3.1.7 Symbol ID Huffman table decoding
  12578. if (textRegion.huffman) {
  12579. error('JBIG2 error: huffman is not supported');
  12580. }
  12581. args = [textRegion, header.referredTo, data, position, end];
  12582. break;
  12583. case 38: // ImmediateGenericRegion
  12584. case 39: // ImmediateLosslessGenericRegion
  12585. var genericRegion = {};
  12586. genericRegion.info = readRegionSegmentInformation(data, position);
  12587. position += RegionSegmentInformationFieldLength;
  12588. var genericRegionSegmentFlags = data[position++];
  12589. genericRegion.mmr = !!(genericRegionSegmentFlags & 1);
  12590. genericRegion.template = (genericRegionSegmentFlags >> 1) & 3;
  12591. genericRegion.prediction = !!(genericRegionSegmentFlags & 8);
  12592. if (!genericRegion.mmr) {
  12593. atLength = genericRegion.template === 0 ? 4 : 1;
  12594. at = [];
  12595. for (i = 0; i < atLength; i++) {
  12596. at.push({
  12597. x: readInt8(data, position),
  12598. y: readInt8(data, position + 1)
  12599. });
  12600. position += 2;
  12601. }
  12602. genericRegion.at = at;
  12603. }
  12604. args = [genericRegion, data, position, end];
  12605. break;
  12606. case 48: // PageInformation
  12607. var pageInfo = {
  12608. width: readUint32(data, position),
  12609. height: readUint32(data, position + 4),
  12610. resolutionX: readUint32(data, position + 8),
  12611. resolutionY: readUint32(data, position + 12)
  12612. };
  12613. if (pageInfo.height === 0xFFFFFFFF) {
  12614. delete pageInfo.height;
  12615. }
  12616. var pageSegmentFlags = data[position + 16];
  12617. var pageStripingInformation = readUint16(data, position + 17);
  12618. pageInfo.lossless = !!(pageSegmentFlags & 1);
  12619. pageInfo.refinement = !!(pageSegmentFlags & 2);
  12620. pageInfo.defaultPixelValue = (pageSegmentFlags >> 2) & 1;
  12621. pageInfo.combinationOperator = (pageSegmentFlags >> 3) & 3;
  12622. pageInfo.requiresBuffer = !!(pageSegmentFlags & 32);
  12623. pageInfo.combinationOperatorOverride = !!(pageSegmentFlags & 64);
  12624. args = [pageInfo];
  12625. break;
  12626. case 49: // EndOfPage
  12627. break;
  12628. case 50: // EndOfStripe
  12629. break;
  12630. case 51: // EndOfFile
  12631. break;
  12632. case 62: // 7.4.15 defines 2 extension types which
  12633. // are comments and can be ignored.
  12634. break;
  12635. default:
  12636. error('JBIG2 error: segment type ' + header.typeName + '(' +
  12637. header.type + ') is not implemented');
  12638. }
  12639. var callbackName = 'on' + header.typeName;
  12640. if (callbackName in visitor) {
  12641. visitor[callbackName].apply(visitor, args);
  12642. }
  12643. }
  12644. function processSegments(segments, visitor) {
  12645. for (var i = 0, ii = segments.length; i < ii; i++) {
  12646. processSegment(segments[i], visitor);
  12647. }
  12648. }
  12649. function parseJbig2(data, start, end) {
  12650. var position = start;
  12651. if (data[position] !== 0x97 || data[position + 1] !== 0x4A ||
  12652. data[position + 2] !== 0x42 || data[position + 3] !== 0x32 ||
  12653. data[position + 4] !== 0x0D || data[position + 5] !== 0x0A ||
  12654. data[position + 6] !== 0x1A || data[position + 7] !== 0x0A) {
  12655. error('JBIG2 error: invalid header');
  12656. }
  12657. var header = {};
  12658. position += 8;
  12659. var flags = data[position++];
  12660. header.randomAccess = !(flags & 1);
  12661. if (!(flags & 2)) {
  12662. header.numberOfPages = readUint32(data, position);
  12663. position += 4;
  12664. }
  12665. var segments = readSegments(header, data, position, end);
  12666. error('Not implemented');
  12667. // processSegments(segments, new SimpleSegmentVisitor());
  12668. }
  12669. function parseJbig2Chunks(chunks) {
  12670. var visitor = new SimpleSegmentVisitor();
  12671. for (var i = 0, ii = chunks.length; i < ii; i++) {
  12672. var chunk = chunks[i];
  12673. var segments = readSegments({}, chunk.data, chunk.start, chunk.end);
  12674. processSegments(segments, visitor);
  12675. }
  12676. return visitor.buffer;
  12677. }
  12678. function SimpleSegmentVisitor() {}
  12679. SimpleSegmentVisitor.prototype = {
  12680. onPageInformation: function SimpleSegmentVisitor_onPageInformation(info) {
  12681. this.currentPageInfo = info;
  12682. var rowSize = (info.width + 7) >> 3;
  12683. var buffer = new Uint8Array(rowSize * info.height);
  12684. // The contents of ArrayBuffers are initialized to 0.
  12685. // Fill the buffer with 0xFF only if info.defaultPixelValue is set
  12686. if (info.defaultPixelValue) {
  12687. for (var i = 0, ii = buffer.length; i < ii; i++) {
  12688. buffer[i] = 0xFF;
  12689. }
  12690. }
  12691. this.buffer = buffer;
  12692. },
  12693. drawBitmap: function SimpleSegmentVisitor_drawBitmap(regionInfo, bitmap) {
  12694. var pageInfo = this.currentPageInfo;
  12695. var width = regionInfo.width, height = regionInfo.height;
  12696. var rowSize = (pageInfo.width + 7) >> 3;
  12697. var combinationOperator = pageInfo.combinationOperatorOverride ?
  12698. regionInfo.combinationOperator : pageInfo.combinationOperator;
  12699. var buffer = this.buffer;
  12700. var mask0 = 128 >> (regionInfo.x & 7);
  12701. var offset0 = regionInfo.y * rowSize + (regionInfo.x >> 3);
  12702. var i, j, mask, offset;
  12703. switch (combinationOperator) {
  12704. case 0: // OR
  12705. for (i = 0; i < height; i++) {
  12706. mask = mask0;
  12707. offset = offset0;
  12708. for (j = 0; j < width; j++) {
  12709. if (bitmap[i][j]) {
  12710. buffer[offset] |= mask;
  12711. }
  12712. mask >>= 1;
  12713. if (!mask) {
  12714. mask = 128;
  12715. offset++;
  12716. }
  12717. }
  12718. offset0 += rowSize;
  12719. }
  12720. break;
  12721. case 2: // XOR
  12722. for (i = 0; i < height; i++) {
  12723. mask = mask0;
  12724. offset = offset0;
  12725. for (j = 0; j < width; j++) {
  12726. if (bitmap[i][j]) {
  12727. buffer[offset] ^= mask;
  12728. }
  12729. mask >>= 1;
  12730. if (!mask) {
  12731. mask = 128;
  12732. offset++;
  12733. }
  12734. }
  12735. offset0 += rowSize;
  12736. }
  12737. break;
  12738. default:
  12739. error('JBIG2 error: operator ' + combinationOperator +
  12740. ' is not supported');
  12741. }
  12742. },
  12743. onImmediateGenericRegion:
  12744. function SimpleSegmentVisitor_onImmediateGenericRegion(region, data,
  12745. start, end) {
  12746. var regionInfo = region.info;
  12747. var decodingContext = new DecodingContext(data, start, end);
  12748. var bitmap = decodeBitmap(region.mmr, regionInfo.width, regionInfo.height,
  12749. region.template, region.prediction, null,
  12750. region.at, decodingContext);
  12751. this.drawBitmap(regionInfo, bitmap);
  12752. },
  12753. onImmediateLosslessGenericRegion:
  12754. function SimpleSegmentVisitor_onImmediateLosslessGenericRegion() {
  12755. this.onImmediateGenericRegion.apply(this, arguments);
  12756. },
  12757. onSymbolDictionary:
  12758. function SimpleSegmentVisitor_onSymbolDictionary(dictionary,
  12759. currentSegment,
  12760. referredSegments,
  12761. data, start, end) {
  12762. var huffmanTables;
  12763. if (dictionary.huffman) {
  12764. error('JBIG2 error: huffman is not supported');
  12765. }
  12766. // Combines exported symbols from all referred segments
  12767. var symbols = this.symbols;
  12768. if (!symbols) {
  12769. this.symbols = symbols = {};
  12770. }
  12771. var inputSymbols = [];
  12772. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  12773. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  12774. }
  12775. var decodingContext = new DecodingContext(data, start, end);
  12776. symbols[currentSegment] = decodeSymbolDictionary(dictionary.huffman,
  12777. dictionary.refinement, inputSymbols, dictionary.numberOfNewSymbols,
  12778. dictionary.numberOfExportedSymbols, huffmanTables,
  12779. dictionary.template, dictionary.at,
  12780. dictionary.refinementTemplate, dictionary.refinementAt,
  12781. decodingContext);
  12782. },
  12783. onImmediateTextRegion:
  12784. function SimpleSegmentVisitor_onImmediateTextRegion(region,
  12785. referredSegments,
  12786. data, start, end) {
  12787. var regionInfo = region.info;
  12788. var huffmanTables;
  12789. // Combines exported symbols from all referred segments
  12790. var symbols = this.symbols;
  12791. var inputSymbols = [];
  12792. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  12793. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  12794. }
  12795. var symbolCodeLength = log2(inputSymbols.length);
  12796. var decodingContext = new DecodingContext(data, start, end);
  12797. var bitmap = decodeTextRegion(region.huffman, region.refinement,
  12798. regionInfo.width, regionInfo.height, region.defaultPixelValue,
  12799. region.numberOfSymbolInstances, region.stripSize, inputSymbols,
  12800. symbolCodeLength, region.transposed, region.dsOffset,
  12801. region.referenceCorner, region.combinationOperator, huffmanTables,
  12802. region.refinementTemplate, region.refinementAt, decodingContext);
  12803. this.drawBitmap(regionInfo, bitmap);
  12804. },
  12805. onImmediateLosslessTextRegion:
  12806. function SimpleSegmentVisitor_onImmediateLosslessTextRegion() {
  12807. this.onImmediateTextRegion.apply(this, arguments);
  12808. }
  12809. };
  12810. function Jbig2Image() {}
  12811. Jbig2Image.prototype = {
  12812. parseChunks: function Jbig2Image_parseChunks(chunks) {
  12813. return parseJbig2Chunks(chunks);
  12814. }
  12815. };
  12816. return Jbig2Image;
  12817. })();
  12818. exports.Jbig2Image = Jbig2Image;
  12819. }));
  12820. (function (root, factory) {
  12821. {
  12822. factory((root.pdfjsCoreJpx = {}), root.pdfjsSharedUtil,
  12823. root.pdfjsCoreArithmeticDecoder);
  12824. }
  12825. }(this, function (exports, sharedUtil, coreArithmeticDecoder) {
  12826. var info = sharedUtil.info;
  12827. var log2 = sharedUtil.log2;
  12828. var readUint16 = sharedUtil.readUint16;
  12829. var readUint32 = sharedUtil.readUint32;
  12830. var warn = sharedUtil.warn;
  12831. var ArithmeticDecoder = coreArithmeticDecoder.ArithmeticDecoder;
  12832. var JpxImage = (function JpxImageClosure() {
  12833. // Table E.1
  12834. var SubbandsGainLog2 = {
  12835. 'LL': 0,
  12836. 'LH': 1,
  12837. 'HL': 1,
  12838. 'HH': 2
  12839. };
  12840. function JpxImage() {
  12841. this.failOnCorruptedImage = false;
  12842. }
  12843. JpxImage.prototype = {
  12844. parse: function JpxImage_parse(data) {
  12845. var head = readUint16(data, 0);
  12846. // No box header, immediate start of codestream (SOC)
  12847. if (head === 0xFF4F) {
  12848. this.parseCodestream(data, 0, data.length);
  12849. return;
  12850. }
  12851. var position = 0, length = data.length;
  12852. while (position < length) {
  12853. var headerSize = 8;
  12854. var lbox = readUint32(data, position);
  12855. var tbox = readUint32(data, position + 4);
  12856. position += headerSize;
  12857. if (lbox === 1) {
  12858. // XLBox: read UInt64 according to spec.
  12859. // JavaScript's int precision of 53 bit should be sufficient here.
  12860. lbox = readUint32(data, position) * 4294967296 +
  12861. readUint32(data, position + 4);
  12862. position += 8;
  12863. headerSize += 8;
  12864. }
  12865. if (lbox === 0) {
  12866. lbox = length - position + headerSize;
  12867. }
  12868. if (lbox < headerSize) {
  12869. throw new Error('JPX Error: Invalid box field size');
  12870. }
  12871. var dataLength = lbox - headerSize;
  12872. var jumpDataLength = true;
  12873. switch (tbox) {
  12874. case 0x6A703268: // 'jp2h'
  12875. jumpDataLength = false; // parsing child boxes
  12876. break;
  12877. case 0x636F6C72: // 'colr'
  12878. // Colorspaces are not used, the CS from the PDF is used.
  12879. var method = data[position];
  12880. if (method === 1) {
  12881. // enumerated colorspace
  12882. var colorspace = readUint32(data, position + 3);
  12883. switch (colorspace) {
  12884. case 16: // this indicates a sRGB colorspace
  12885. case 17: // this indicates a grayscale colorspace
  12886. case 18: // this indicates a YUV colorspace
  12887. break;
  12888. default:
  12889. warn('Unknown colorspace ' + colorspace);
  12890. break;
  12891. }
  12892. } else if (method === 2) {
  12893. info('ICC profile not supported');
  12894. }
  12895. break;
  12896. case 0x6A703263: // 'jp2c'
  12897. this.parseCodestream(data, position, position + dataLength);
  12898. break;
  12899. case 0x6A502020: // 'jP\024\024'
  12900. if (0x0d0a870a !== readUint32(data, position)) {
  12901. warn('Invalid JP2 signature');
  12902. }
  12903. break;
  12904. // The following header types are valid but currently not used:
  12905. case 0x6A501A1A: // 'jP\032\032'
  12906. case 0x66747970: // 'ftyp'
  12907. case 0x72726571: // 'rreq'
  12908. case 0x72657320: // 'res '
  12909. case 0x69686472: // 'ihdr'
  12910. break;
  12911. default:
  12912. var headerType = String.fromCharCode((tbox >> 24) & 0xFF,
  12913. (tbox >> 16) & 0xFF,
  12914. (tbox >> 8) & 0xFF,
  12915. tbox & 0xFF);
  12916. warn('Unsupported header type ' + tbox + ' (' + headerType + ')');
  12917. break;
  12918. }
  12919. if (jumpDataLength) {
  12920. position += dataLength;
  12921. }
  12922. }
  12923. },
  12924. parseImageProperties: function JpxImage_parseImageProperties(stream) {
  12925. var newByte = stream.getByte();
  12926. while (newByte >= 0) {
  12927. var oldByte = newByte;
  12928. newByte = stream.getByte();
  12929. var code = (oldByte << 8) | newByte;
  12930. // Image and tile size (SIZ)
  12931. if (code === 0xFF51) {
  12932. stream.skip(4);
  12933. var Xsiz = stream.getInt32() >>> 0; // Byte 4
  12934. var Ysiz = stream.getInt32() >>> 0; // Byte 8
  12935. var XOsiz = stream.getInt32() >>> 0; // Byte 12
  12936. var YOsiz = stream.getInt32() >>> 0; // Byte 16
  12937. stream.skip(16);
  12938. var Csiz = stream.getUint16(); // Byte 36
  12939. this.width = Xsiz - XOsiz;
  12940. this.height = Ysiz - YOsiz;
  12941. this.componentsCount = Csiz;
  12942. // Results are always returned as Uint8Arrays
  12943. this.bitsPerComponent = 8;
  12944. return;
  12945. }
  12946. }
  12947. throw new Error('JPX Error: No size marker found in JPX stream');
  12948. },
  12949. parseCodestream: function JpxImage_parseCodestream(data, start, end) {
  12950. var context = {};
  12951. try {
  12952. var doNotRecover = false;
  12953. var position = start;
  12954. while (position + 1 < end) {
  12955. var code = readUint16(data, position);
  12956. position += 2;
  12957. var length = 0, j, sqcd, spqcds, spqcdSize, scalarExpounded, tile;
  12958. switch (code) {
  12959. case 0xFF4F: // Start of codestream (SOC)
  12960. context.mainHeader = true;
  12961. break;
  12962. case 0xFFD9: // End of codestream (EOC)
  12963. break;
  12964. case 0xFF51: // Image and tile size (SIZ)
  12965. length = readUint16(data, position);
  12966. var siz = {};
  12967. siz.Xsiz = readUint32(data, position + 4);
  12968. siz.Ysiz = readUint32(data, position + 8);
  12969. siz.XOsiz = readUint32(data, position + 12);
  12970. siz.YOsiz = readUint32(data, position + 16);
  12971. siz.XTsiz = readUint32(data, position + 20);
  12972. siz.YTsiz = readUint32(data, position + 24);
  12973. siz.XTOsiz = readUint32(data, position + 28);
  12974. siz.YTOsiz = readUint32(data, position + 32);
  12975. var componentsCount = readUint16(data, position + 36);
  12976. siz.Csiz = componentsCount;
  12977. var components = [];
  12978. j = position + 38;
  12979. for (var i = 0; i < componentsCount; i++) {
  12980. var component = {
  12981. precision: (data[j] & 0x7F) + 1,
  12982. isSigned: !!(data[j] & 0x80),
  12983. XRsiz: data[j + 1],
  12984. YRsiz: data[j + 1]
  12985. };
  12986. calculateComponentDimensions(component, siz);
  12987. components.push(component);
  12988. }
  12989. context.SIZ = siz;
  12990. context.components = components;
  12991. calculateTileGrids(context, components);
  12992. context.QCC = [];
  12993. context.COC = [];
  12994. break;
  12995. case 0xFF5C: // Quantization default (QCD)
  12996. length = readUint16(data, position);
  12997. var qcd = {};
  12998. j = position + 2;
  12999. sqcd = data[j++];
  13000. switch (sqcd & 0x1F) {
  13001. case 0:
  13002. spqcdSize = 8;
  13003. scalarExpounded = true;
  13004. break;
  13005. case 1:
  13006. spqcdSize = 16;
  13007. scalarExpounded = false;
  13008. break;
  13009. case 2:
  13010. spqcdSize = 16;
  13011. scalarExpounded = true;
  13012. break;
  13013. default:
  13014. throw new Error('JPX Error: Invalid SQcd value ' + sqcd);
  13015. }
  13016. qcd.noQuantization = (spqcdSize === 8);
  13017. qcd.scalarExpounded = scalarExpounded;
  13018. qcd.guardBits = sqcd >> 5;
  13019. spqcds = [];
  13020. while (j < length + position) {
  13021. var spqcd = {};
  13022. if (spqcdSize === 8) {
  13023. spqcd.epsilon = data[j++] >> 3;
  13024. spqcd.mu = 0;
  13025. } else {
  13026. spqcd.epsilon = data[j] >> 3;
  13027. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  13028. j += 2;
  13029. }
  13030. spqcds.push(spqcd);
  13031. }
  13032. qcd.SPqcds = spqcds;
  13033. if (context.mainHeader) {
  13034. context.QCD = qcd;
  13035. } else {
  13036. context.currentTile.QCD = qcd;
  13037. context.currentTile.QCC = [];
  13038. }
  13039. break;
  13040. case 0xFF5D: // Quantization component (QCC)
  13041. length = readUint16(data, position);
  13042. var qcc = {};
  13043. j = position + 2;
  13044. var cqcc;
  13045. if (context.SIZ.Csiz < 257) {
  13046. cqcc = data[j++];
  13047. } else {
  13048. cqcc = readUint16(data, j);
  13049. j += 2;
  13050. }
  13051. sqcd = data[j++];
  13052. switch (sqcd & 0x1F) {
  13053. case 0:
  13054. spqcdSize = 8;
  13055. scalarExpounded = true;
  13056. break;
  13057. case 1:
  13058. spqcdSize = 16;
  13059. scalarExpounded = false;
  13060. break;
  13061. case 2:
  13062. spqcdSize = 16;
  13063. scalarExpounded = true;
  13064. break;
  13065. default:
  13066. throw new Error('JPX Error: Invalid SQcd value ' + sqcd);
  13067. }
  13068. qcc.noQuantization = (spqcdSize === 8);
  13069. qcc.scalarExpounded = scalarExpounded;
  13070. qcc.guardBits = sqcd >> 5;
  13071. spqcds = [];
  13072. while (j < (length + position)) {
  13073. spqcd = {};
  13074. if (spqcdSize === 8) {
  13075. spqcd.epsilon = data[j++] >> 3;
  13076. spqcd.mu = 0;
  13077. } else {
  13078. spqcd.epsilon = data[j] >> 3;
  13079. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  13080. j += 2;
  13081. }
  13082. spqcds.push(spqcd);
  13083. }
  13084. qcc.SPqcds = spqcds;
  13085. if (context.mainHeader) {
  13086. context.QCC[cqcc] = qcc;
  13087. } else {
  13088. context.currentTile.QCC[cqcc] = qcc;
  13089. }
  13090. break;
  13091. case 0xFF52: // Coding style default (COD)
  13092. length = readUint16(data, position);
  13093. var cod = {};
  13094. j = position + 2;
  13095. var scod = data[j++];
  13096. cod.entropyCoderWithCustomPrecincts = !!(scod & 1);
  13097. cod.sopMarkerUsed = !!(scod & 2);
  13098. cod.ephMarkerUsed = !!(scod & 4);
  13099. cod.progressionOrder = data[j++];
  13100. cod.layersCount = readUint16(data, j);
  13101. j += 2;
  13102. cod.multipleComponentTransform = data[j++];
  13103. cod.decompositionLevelsCount = data[j++];
  13104. cod.xcb = (data[j++] & 0xF) + 2;
  13105. cod.ycb = (data[j++] & 0xF) + 2;
  13106. var blockStyle = data[j++];
  13107. cod.selectiveArithmeticCodingBypass = !!(blockStyle & 1);
  13108. cod.resetContextProbabilities = !!(blockStyle & 2);
  13109. cod.terminationOnEachCodingPass = !!(blockStyle & 4);
  13110. cod.verticalyStripe = !!(blockStyle & 8);
  13111. cod.predictableTermination = !!(blockStyle & 16);
  13112. cod.segmentationSymbolUsed = !!(blockStyle & 32);
  13113. cod.reversibleTransformation = data[j++];
  13114. if (cod.entropyCoderWithCustomPrecincts) {
  13115. var precinctsSizes = [];
  13116. while (j < length + position) {
  13117. var precinctsSize = data[j++];
  13118. precinctsSizes.push({
  13119. PPx: precinctsSize & 0xF,
  13120. PPy: precinctsSize >> 4
  13121. });
  13122. }
  13123. cod.precinctsSizes = precinctsSizes;
  13124. }
  13125. var unsupported = [];
  13126. if (cod.selectiveArithmeticCodingBypass) {
  13127. unsupported.push('selectiveArithmeticCodingBypass');
  13128. }
  13129. if (cod.resetContextProbabilities) {
  13130. unsupported.push('resetContextProbabilities');
  13131. }
  13132. if (cod.terminationOnEachCodingPass) {
  13133. unsupported.push('terminationOnEachCodingPass');
  13134. }
  13135. if (cod.verticalyStripe) {
  13136. unsupported.push('verticalyStripe');
  13137. }
  13138. if (cod.predictableTermination) {
  13139. unsupported.push('predictableTermination');
  13140. }
  13141. if (unsupported.length > 0) {
  13142. doNotRecover = true;
  13143. throw new Error('JPX Error: Unsupported COD options (' +
  13144. unsupported.join(', ') + ')');
  13145. }
  13146. if (context.mainHeader) {
  13147. context.COD = cod;
  13148. } else {
  13149. context.currentTile.COD = cod;
  13150. context.currentTile.COC = [];
  13151. }
  13152. break;
  13153. case 0xFF90: // Start of tile-part (SOT)
  13154. length = readUint16(data, position);
  13155. tile = {};
  13156. tile.index = readUint16(data, position + 2);
  13157. tile.length = readUint32(data, position + 4);
  13158. tile.dataEnd = tile.length + position - 2;
  13159. tile.partIndex = data[position + 8];
  13160. tile.partsCount = data[position + 9];
  13161. context.mainHeader = false;
  13162. if (tile.partIndex === 0) {
  13163. // reset component specific settings
  13164. tile.COD = context.COD;
  13165. tile.COC = context.COC.slice(0); // clone of the global COC
  13166. tile.QCD = context.QCD;
  13167. tile.QCC = context.QCC.slice(0); // clone of the global COC
  13168. }
  13169. context.currentTile = tile;
  13170. break;
  13171. case 0xFF93: // Start of data (SOD)
  13172. tile = context.currentTile;
  13173. if (tile.partIndex === 0) {
  13174. initializeTile(context, tile.index);
  13175. buildPackets(context);
  13176. }
  13177. // moving to the end of the data
  13178. length = tile.dataEnd - position;
  13179. parseTilePackets(context, data, position, length);
  13180. break;
  13181. case 0xFF55: // Tile-part lengths, main header (TLM)
  13182. case 0xFF57: // Packet length, main header (PLM)
  13183. case 0xFF58: // Packet length, tile-part header (PLT)
  13184. case 0xFF64: // Comment (COM)
  13185. length = readUint16(data, position);
  13186. // skipping content
  13187. break;
  13188. case 0xFF53: // Coding style component (COC)
  13189. throw new Error('JPX Error: Codestream code 0xFF53 (COC) is ' +
  13190. 'not implemented');
  13191. default:
  13192. throw new Error('JPX Error: Unknown codestream code: ' +
  13193. code.toString(16));
  13194. }
  13195. position += length;
  13196. }
  13197. } catch (e) {
  13198. if (doNotRecover || this.failOnCorruptedImage) {
  13199. throw e;
  13200. } else {
  13201. warn('Trying to recover from ' + e.message);
  13202. }
  13203. }
  13204. this.tiles = transformComponents(context);
  13205. this.width = context.SIZ.Xsiz - context.SIZ.XOsiz;
  13206. this.height = context.SIZ.Ysiz - context.SIZ.YOsiz;
  13207. this.componentsCount = context.SIZ.Csiz;
  13208. }
  13209. };
  13210. function calculateComponentDimensions(component, siz) {
  13211. // Section B.2 Component mapping
  13212. component.x0 = Math.ceil(siz.XOsiz / component.XRsiz);
  13213. component.x1 = Math.ceil(siz.Xsiz / component.XRsiz);
  13214. component.y0 = Math.ceil(siz.YOsiz / component.YRsiz);
  13215. component.y1 = Math.ceil(siz.Ysiz / component.YRsiz);
  13216. component.width = component.x1 - component.x0;
  13217. component.height = component.y1 - component.y0;
  13218. }
  13219. function calculateTileGrids(context, components) {
  13220. var siz = context.SIZ;
  13221. // Section B.3 Division into tile and tile-components
  13222. var tile, tiles = [];
  13223. var numXtiles = Math.ceil((siz.Xsiz - siz.XTOsiz) / siz.XTsiz);
  13224. var numYtiles = Math.ceil((siz.Ysiz - siz.YTOsiz) / siz.YTsiz);
  13225. for (var q = 0; q < numYtiles; q++) {
  13226. for (var p = 0; p < numXtiles; p++) {
  13227. tile = {};
  13228. tile.tx0 = Math.max(siz.XTOsiz + p * siz.XTsiz, siz.XOsiz);
  13229. tile.ty0 = Math.max(siz.YTOsiz + q * siz.YTsiz, siz.YOsiz);
  13230. tile.tx1 = Math.min(siz.XTOsiz + (p + 1) * siz.XTsiz, siz.Xsiz);
  13231. tile.ty1 = Math.min(siz.YTOsiz + (q + 1) * siz.YTsiz, siz.Ysiz);
  13232. tile.width = tile.tx1 - tile.tx0;
  13233. tile.height = tile.ty1 - tile.ty0;
  13234. tile.components = [];
  13235. tiles.push(tile);
  13236. }
  13237. }
  13238. context.tiles = tiles;
  13239. var componentsCount = siz.Csiz;
  13240. for (var i = 0, ii = componentsCount; i < ii; i++) {
  13241. var component = components[i];
  13242. for (var j = 0, jj = tiles.length; j < jj; j++) {
  13243. var tileComponent = {};
  13244. tile = tiles[j];
  13245. tileComponent.tcx0 = Math.ceil(tile.tx0 / component.XRsiz);
  13246. tileComponent.tcy0 = Math.ceil(tile.ty0 / component.YRsiz);
  13247. tileComponent.tcx1 = Math.ceil(tile.tx1 / component.XRsiz);
  13248. tileComponent.tcy1 = Math.ceil(tile.ty1 / component.YRsiz);
  13249. tileComponent.width = tileComponent.tcx1 - tileComponent.tcx0;
  13250. tileComponent.height = tileComponent.tcy1 - tileComponent.tcy0;
  13251. tile.components[i] = tileComponent;
  13252. }
  13253. }
  13254. }
  13255. function getBlocksDimensions(context, component, r) {
  13256. var codOrCoc = component.codingStyleParameters;
  13257. var result = {};
  13258. if (!codOrCoc.entropyCoderWithCustomPrecincts) {
  13259. result.PPx = 15;
  13260. result.PPy = 15;
  13261. } else {
  13262. result.PPx = codOrCoc.precinctsSizes[r].PPx;
  13263. result.PPy = codOrCoc.precinctsSizes[r].PPy;
  13264. }
  13265. // calculate codeblock size as described in section B.7
  13266. result.xcb_ = (r > 0 ? Math.min(codOrCoc.xcb, result.PPx - 1) :
  13267. Math.min(codOrCoc.xcb, result.PPx));
  13268. result.ycb_ = (r > 0 ? Math.min(codOrCoc.ycb, result.PPy - 1) :
  13269. Math.min(codOrCoc.ycb, result.PPy));
  13270. return result;
  13271. }
  13272. function buildPrecincts(context, resolution, dimensions) {
  13273. // Section B.6 Division resolution to precincts
  13274. var precinctWidth = 1 << dimensions.PPx;
  13275. var precinctHeight = 1 << dimensions.PPy;
  13276. // Jasper introduces codeblock groups for mapping each subband codeblocks
  13277. // to precincts. Precinct partition divides a resolution according to width
  13278. // and height parameters. The subband that belongs to the resolution level
  13279. // has a different size than the level, unless it is the zero resolution.
  13280. // From Jasper documentation: jpeg2000.pdf, section K: Tier-2 coding:
  13281. // The precinct partitioning for a particular subband is derived from a
  13282. // partitioning of its parent LL band (i.e., the LL band at the next higher
  13283. // resolution level)... The LL band associated with each resolution level is
  13284. // divided into precincts... Each of the resulting precinct regions is then
  13285. // mapped into its child subbands (if any) at the next lower resolution
  13286. // level. This is accomplished by using the coordinate transformation
  13287. // (u, v) = (ceil(x/2), ceil(y/2)) where (x, y) and (u, v) are the
  13288. // coordinates of a point in the LL band and child subband, respectively.
  13289. var isZeroRes = resolution.resLevel === 0;
  13290. var precinctWidthInSubband = 1 << (dimensions.PPx + (isZeroRes ? 0 : -1));
  13291. var precinctHeightInSubband = 1 << (dimensions.PPy + (isZeroRes ? 0 : -1));
  13292. var numprecinctswide = (resolution.trx1 > resolution.trx0 ?
  13293. Math.ceil(resolution.trx1 / precinctWidth) -
  13294. Math.floor(resolution.trx0 / precinctWidth) : 0);
  13295. var numprecinctshigh = (resolution.try1 > resolution.try0 ?
  13296. Math.ceil(resolution.try1 / precinctHeight) -
  13297. Math.floor(resolution.try0 / precinctHeight) : 0);
  13298. var numprecincts = numprecinctswide * numprecinctshigh;
  13299. resolution.precinctParameters = {
  13300. precinctWidth: precinctWidth,
  13301. precinctHeight: precinctHeight,
  13302. numprecinctswide: numprecinctswide,
  13303. numprecinctshigh: numprecinctshigh,
  13304. numprecincts: numprecincts,
  13305. precinctWidthInSubband: precinctWidthInSubband,
  13306. precinctHeightInSubband: precinctHeightInSubband
  13307. };
  13308. }
  13309. function buildCodeblocks(context, subband, dimensions) {
  13310. // Section B.7 Division sub-band into code-blocks
  13311. var xcb_ = dimensions.xcb_;
  13312. var ycb_ = dimensions.ycb_;
  13313. var codeblockWidth = 1 << xcb_;
  13314. var codeblockHeight = 1 << ycb_;
  13315. var cbx0 = subband.tbx0 >> xcb_;
  13316. var cby0 = subband.tby0 >> ycb_;
  13317. var cbx1 = (subband.tbx1 + codeblockWidth - 1) >> xcb_;
  13318. var cby1 = (subband.tby1 + codeblockHeight - 1) >> ycb_;
  13319. var precinctParameters = subband.resolution.precinctParameters;
  13320. var codeblocks = [];
  13321. var precincts = [];
  13322. var i, j, codeblock, precinctNumber;
  13323. for (j = cby0; j < cby1; j++) {
  13324. for (i = cbx0; i < cbx1; i++) {
  13325. codeblock = {
  13326. cbx: i,
  13327. cby: j,
  13328. tbx0: codeblockWidth * i,
  13329. tby0: codeblockHeight * j,
  13330. tbx1: codeblockWidth * (i + 1),
  13331. tby1: codeblockHeight * (j + 1)
  13332. };
  13333. codeblock.tbx0_ = Math.max(subband.tbx0, codeblock.tbx0);
  13334. codeblock.tby0_ = Math.max(subband.tby0, codeblock.tby0);
  13335. codeblock.tbx1_ = Math.min(subband.tbx1, codeblock.tbx1);
  13336. codeblock.tby1_ = Math.min(subband.tby1, codeblock.tby1);
  13337. // Calculate precinct number for this codeblock, codeblock position
  13338. // should be relative to its subband, use actual dimension and position
  13339. // See comment about codeblock group width and height
  13340. var pi = Math.floor((codeblock.tbx0_ - subband.tbx0) /
  13341. precinctParameters.precinctWidthInSubband);
  13342. var pj = Math.floor((codeblock.tby0_ - subband.tby0) /
  13343. precinctParameters.precinctHeightInSubband);
  13344. precinctNumber = pi + (pj * precinctParameters.numprecinctswide);
  13345. codeblock.precinctNumber = precinctNumber;
  13346. codeblock.subbandType = subband.type;
  13347. codeblock.Lblock = 3;
  13348. if (codeblock.tbx1_ <= codeblock.tbx0_ ||
  13349. codeblock.tby1_ <= codeblock.tby0_) {
  13350. continue;
  13351. }
  13352. codeblocks.push(codeblock);
  13353. // building precinct for the sub-band
  13354. var precinct = precincts[precinctNumber];
  13355. if (precinct !== undefined) {
  13356. if (i < precinct.cbxMin) {
  13357. precinct.cbxMin = i;
  13358. } else if (i > precinct.cbxMax) {
  13359. precinct.cbxMax = i;
  13360. }
  13361. if (j < precinct.cbyMin) {
  13362. precinct.cbxMin = j;
  13363. } else if (j > precinct.cbyMax) {
  13364. precinct.cbyMax = j;
  13365. }
  13366. } else {
  13367. precincts[precinctNumber] = precinct = {
  13368. cbxMin: i,
  13369. cbyMin: j,
  13370. cbxMax: i,
  13371. cbyMax: j
  13372. };
  13373. }
  13374. codeblock.precinct = precinct;
  13375. }
  13376. }
  13377. subband.codeblockParameters = {
  13378. codeblockWidth: xcb_,
  13379. codeblockHeight: ycb_,
  13380. numcodeblockwide: cbx1 - cbx0 + 1,
  13381. numcodeblockhigh: cby1 - cby0 + 1
  13382. };
  13383. subband.codeblocks = codeblocks;
  13384. subband.precincts = precincts;
  13385. }
  13386. function createPacket(resolution, precinctNumber, layerNumber) {
  13387. var precinctCodeblocks = [];
  13388. // Section B.10.8 Order of info in packet
  13389. var subbands = resolution.subbands;
  13390. // sub-bands already ordered in 'LL', 'HL', 'LH', and 'HH' sequence
  13391. for (var i = 0, ii = subbands.length; i < ii; i++) {
  13392. var subband = subbands[i];
  13393. var codeblocks = subband.codeblocks;
  13394. for (var j = 0, jj = codeblocks.length; j < jj; j++) {
  13395. var codeblock = codeblocks[j];
  13396. if (codeblock.precinctNumber !== precinctNumber) {
  13397. continue;
  13398. }
  13399. precinctCodeblocks.push(codeblock);
  13400. }
  13401. }
  13402. return {
  13403. layerNumber: layerNumber,
  13404. codeblocks: precinctCodeblocks
  13405. };
  13406. }
  13407. function LayerResolutionComponentPositionIterator(context) {
  13408. var siz = context.SIZ;
  13409. var tileIndex = context.currentTile.index;
  13410. var tile = context.tiles[tileIndex];
  13411. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  13412. var componentsCount = siz.Csiz;
  13413. var maxDecompositionLevelsCount = 0;
  13414. for (var q = 0; q < componentsCount; q++) {
  13415. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  13416. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  13417. }
  13418. var l = 0, r = 0, i = 0, k = 0;
  13419. this.nextPacket = function JpxImage_nextPacket() {
  13420. // Section B.12.1.1 Layer-resolution-component-position
  13421. for (; l < layersCount; l++) {
  13422. for (; r <= maxDecompositionLevelsCount; r++) {
  13423. for (; i < componentsCount; i++) {
  13424. var component = tile.components[i];
  13425. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  13426. continue;
  13427. }
  13428. var resolution = component.resolutions[r];
  13429. var numprecincts = resolution.precinctParameters.numprecincts;
  13430. for (; k < numprecincts;) {
  13431. var packet = createPacket(resolution, k, l);
  13432. k++;
  13433. return packet;
  13434. }
  13435. k = 0;
  13436. }
  13437. i = 0;
  13438. }
  13439. r = 0;
  13440. }
  13441. throw new Error('JPX Error: Out of packets');
  13442. };
  13443. }
  13444. function ResolutionLayerComponentPositionIterator(context) {
  13445. var siz = context.SIZ;
  13446. var tileIndex = context.currentTile.index;
  13447. var tile = context.tiles[tileIndex];
  13448. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  13449. var componentsCount = siz.Csiz;
  13450. var maxDecompositionLevelsCount = 0;
  13451. for (var q = 0; q < componentsCount; q++) {
  13452. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  13453. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  13454. }
  13455. var r = 0, l = 0, i = 0, k = 0;
  13456. this.nextPacket = function JpxImage_nextPacket() {
  13457. // Section B.12.1.2 Resolution-layer-component-position
  13458. for (; r <= maxDecompositionLevelsCount; r++) {
  13459. for (; l < layersCount; l++) {
  13460. for (; i < componentsCount; i++) {
  13461. var component = tile.components[i];
  13462. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  13463. continue;
  13464. }
  13465. var resolution = component.resolutions[r];
  13466. var numprecincts = resolution.precinctParameters.numprecincts;
  13467. for (; k < numprecincts;) {
  13468. var packet = createPacket(resolution, k, l);
  13469. k++;
  13470. return packet;
  13471. }
  13472. k = 0;
  13473. }
  13474. i = 0;
  13475. }
  13476. l = 0;
  13477. }
  13478. throw new Error('JPX Error: Out of packets');
  13479. };
  13480. }
  13481. function ResolutionPositionComponentLayerIterator(context) {
  13482. var siz = context.SIZ;
  13483. var tileIndex = context.currentTile.index;
  13484. var tile = context.tiles[tileIndex];
  13485. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  13486. var componentsCount = siz.Csiz;
  13487. var l, r, c, p;
  13488. var maxDecompositionLevelsCount = 0;
  13489. for (c = 0; c < componentsCount; c++) {
  13490. var component = tile.components[c];
  13491. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  13492. component.codingStyleParameters.decompositionLevelsCount);
  13493. }
  13494. var maxNumPrecinctsInLevel = new Int32Array(
  13495. maxDecompositionLevelsCount + 1);
  13496. for (r = 0; r <= maxDecompositionLevelsCount; ++r) {
  13497. var maxNumPrecincts = 0;
  13498. for (c = 0; c < componentsCount; ++c) {
  13499. var resolutions = tile.components[c].resolutions;
  13500. if (r < resolutions.length) {
  13501. maxNumPrecincts = Math.max(maxNumPrecincts,
  13502. resolutions[r].precinctParameters.numprecincts);
  13503. }
  13504. }
  13505. maxNumPrecinctsInLevel[r] = maxNumPrecincts;
  13506. }
  13507. l = 0;
  13508. r = 0;
  13509. c = 0;
  13510. p = 0;
  13511. this.nextPacket = function JpxImage_nextPacket() {
  13512. // Section B.12.1.3 Resolution-position-component-layer
  13513. for (; r <= maxDecompositionLevelsCount; r++) {
  13514. for (; p < maxNumPrecinctsInLevel[r]; p++) {
  13515. for (; c < componentsCount; c++) {
  13516. var component = tile.components[c];
  13517. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  13518. continue;
  13519. }
  13520. var resolution = component.resolutions[r];
  13521. var numprecincts = resolution.precinctParameters.numprecincts;
  13522. if (p >= numprecincts) {
  13523. continue;
  13524. }
  13525. for (; l < layersCount;) {
  13526. var packet = createPacket(resolution, p, l);
  13527. l++;
  13528. return packet;
  13529. }
  13530. l = 0;
  13531. }
  13532. c = 0;
  13533. }
  13534. p = 0;
  13535. }
  13536. throw new Error('JPX Error: Out of packets');
  13537. };
  13538. }
  13539. function PositionComponentResolutionLayerIterator(context) {
  13540. var siz = context.SIZ;
  13541. var tileIndex = context.currentTile.index;
  13542. var tile = context.tiles[tileIndex];
  13543. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  13544. var componentsCount = siz.Csiz;
  13545. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  13546. var precinctsIterationSizes = precinctsSizes;
  13547. var l = 0, r = 0, c = 0, px = 0, py = 0;
  13548. this.nextPacket = function JpxImage_nextPacket() {
  13549. // Section B.12.1.4 Position-component-resolution-layer
  13550. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  13551. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  13552. for (; c < componentsCount; c++) {
  13553. var component = tile.components[c];
  13554. var decompositionLevelsCount =
  13555. component.codingStyleParameters.decompositionLevelsCount;
  13556. for (; r <= decompositionLevelsCount; r++) {
  13557. var resolution = component.resolutions[r];
  13558. var sizeInImageScale =
  13559. precinctsSizes.components[c].resolutions[r];
  13560. var k = getPrecinctIndexIfExist(
  13561. px,
  13562. py,
  13563. sizeInImageScale,
  13564. precinctsIterationSizes,
  13565. resolution);
  13566. if (k === null) {
  13567. continue;
  13568. }
  13569. for (; l < layersCount;) {
  13570. var packet = createPacket(resolution, k, l);
  13571. l++;
  13572. return packet;
  13573. }
  13574. l = 0;
  13575. }
  13576. r = 0;
  13577. }
  13578. c = 0;
  13579. }
  13580. px = 0;
  13581. }
  13582. throw new Error('JPX Error: Out of packets');
  13583. };
  13584. }
  13585. function ComponentPositionResolutionLayerIterator(context) {
  13586. var siz = context.SIZ;
  13587. var tileIndex = context.currentTile.index;
  13588. var tile = context.tiles[tileIndex];
  13589. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  13590. var componentsCount = siz.Csiz;
  13591. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  13592. var l = 0, r = 0, c = 0, px = 0, py = 0;
  13593. this.nextPacket = function JpxImage_nextPacket() {
  13594. // Section B.12.1.5 Component-position-resolution-layer
  13595. for (; c < componentsCount; ++c) {
  13596. var component = tile.components[c];
  13597. var precinctsIterationSizes = precinctsSizes.components[c];
  13598. var decompositionLevelsCount =
  13599. component.codingStyleParameters.decompositionLevelsCount;
  13600. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  13601. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  13602. for (; r <= decompositionLevelsCount; r++) {
  13603. var resolution = component.resolutions[r];
  13604. var sizeInImageScale = precinctsIterationSizes.resolutions[r];
  13605. var k = getPrecinctIndexIfExist(
  13606. px,
  13607. py,
  13608. sizeInImageScale,
  13609. precinctsIterationSizes,
  13610. resolution);
  13611. if (k === null) {
  13612. continue;
  13613. }
  13614. for (; l < layersCount;) {
  13615. var packet = createPacket(resolution, k, l);
  13616. l++;
  13617. return packet;
  13618. }
  13619. l = 0;
  13620. }
  13621. r = 0;
  13622. }
  13623. px = 0;
  13624. }
  13625. py = 0;
  13626. }
  13627. throw new Error('JPX Error: Out of packets');
  13628. };
  13629. }
  13630. function getPrecinctIndexIfExist(
  13631. pxIndex, pyIndex, sizeInImageScale, precinctIterationSizes, resolution) {
  13632. var posX = pxIndex * precinctIterationSizes.minWidth;
  13633. var posY = pyIndex * precinctIterationSizes.minHeight;
  13634. if (posX % sizeInImageScale.width !== 0 ||
  13635. posY % sizeInImageScale.height !== 0) {
  13636. return null;
  13637. }
  13638. var startPrecinctRowIndex =
  13639. (posY / sizeInImageScale.width) *
  13640. resolution.precinctParameters.numprecinctswide;
  13641. return (posX / sizeInImageScale.height) + startPrecinctRowIndex;
  13642. }
  13643. function getPrecinctSizesInImageScale(tile) {
  13644. var componentsCount = tile.components.length;
  13645. var minWidth = Number.MAX_VALUE;
  13646. var minHeight = Number.MAX_VALUE;
  13647. var maxNumWide = 0;
  13648. var maxNumHigh = 0;
  13649. var sizePerComponent = new Array(componentsCount);
  13650. for (var c = 0; c < componentsCount; c++) {
  13651. var component = tile.components[c];
  13652. var decompositionLevelsCount =
  13653. component.codingStyleParameters.decompositionLevelsCount;
  13654. var sizePerResolution = new Array(decompositionLevelsCount + 1);
  13655. var minWidthCurrentComponent = Number.MAX_VALUE;
  13656. var minHeightCurrentComponent = Number.MAX_VALUE;
  13657. var maxNumWideCurrentComponent = 0;
  13658. var maxNumHighCurrentComponent = 0;
  13659. var scale = 1;
  13660. for (var r = decompositionLevelsCount; r >= 0; --r) {
  13661. var resolution = component.resolutions[r];
  13662. var widthCurrentResolution =
  13663. scale * resolution.precinctParameters.precinctWidth;
  13664. var heightCurrentResolution =
  13665. scale * resolution.precinctParameters.precinctHeight;
  13666. minWidthCurrentComponent = Math.min(
  13667. minWidthCurrentComponent,
  13668. widthCurrentResolution);
  13669. minHeightCurrentComponent = Math.min(
  13670. minHeightCurrentComponent,
  13671. heightCurrentResolution);
  13672. maxNumWideCurrentComponent = Math.max(maxNumWideCurrentComponent,
  13673. resolution.precinctParameters.numprecinctswide);
  13674. maxNumHighCurrentComponent = Math.max(maxNumHighCurrentComponent,
  13675. resolution.precinctParameters.numprecinctshigh);
  13676. sizePerResolution[r] = {
  13677. width: widthCurrentResolution,
  13678. height: heightCurrentResolution
  13679. };
  13680. scale <<= 1;
  13681. }
  13682. minWidth = Math.min(minWidth, minWidthCurrentComponent);
  13683. minHeight = Math.min(minHeight, minHeightCurrentComponent);
  13684. maxNumWide = Math.max(maxNumWide, maxNumWideCurrentComponent);
  13685. maxNumHigh = Math.max(maxNumHigh, maxNumHighCurrentComponent);
  13686. sizePerComponent[c] = {
  13687. resolutions: sizePerResolution,
  13688. minWidth: minWidthCurrentComponent,
  13689. minHeight: minHeightCurrentComponent,
  13690. maxNumWide: maxNumWideCurrentComponent,
  13691. maxNumHigh: maxNumHighCurrentComponent
  13692. };
  13693. }
  13694. return {
  13695. components: sizePerComponent,
  13696. minWidth: minWidth,
  13697. minHeight: minHeight,
  13698. maxNumWide: maxNumWide,
  13699. maxNumHigh: maxNumHigh
  13700. };
  13701. }
  13702. function buildPackets(context) {
  13703. var siz = context.SIZ;
  13704. var tileIndex = context.currentTile.index;
  13705. var tile = context.tiles[tileIndex];
  13706. var componentsCount = siz.Csiz;
  13707. // Creating resolutions and sub-bands for each component
  13708. for (var c = 0; c < componentsCount; c++) {
  13709. var component = tile.components[c];
  13710. var decompositionLevelsCount =
  13711. component.codingStyleParameters.decompositionLevelsCount;
  13712. // Section B.5 Resolution levels and sub-bands
  13713. var resolutions = [];
  13714. var subbands = [];
  13715. for (var r = 0; r <= decompositionLevelsCount; r++) {
  13716. var blocksDimensions = getBlocksDimensions(context, component, r);
  13717. var resolution = {};
  13718. var scale = 1 << (decompositionLevelsCount - r);
  13719. resolution.trx0 = Math.ceil(component.tcx0 / scale);
  13720. resolution.try0 = Math.ceil(component.tcy0 / scale);
  13721. resolution.trx1 = Math.ceil(component.tcx1 / scale);
  13722. resolution.try1 = Math.ceil(component.tcy1 / scale);
  13723. resolution.resLevel = r;
  13724. buildPrecincts(context, resolution, blocksDimensions);
  13725. resolutions.push(resolution);
  13726. var subband;
  13727. if (r === 0) {
  13728. // one sub-band (LL) with last decomposition
  13729. subband = {};
  13730. subband.type = 'LL';
  13731. subband.tbx0 = Math.ceil(component.tcx0 / scale);
  13732. subband.tby0 = Math.ceil(component.tcy0 / scale);
  13733. subband.tbx1 = Math.ceil(component.tcx1 / scale);
  13734. subband.tby1 = Math.ceil(component.tcy1 / scale);
  13735. subband.resolution = resolution;
  13736. buildCodeblocks(context, subband, blocksDimensions);
  13737. subbands.push(subband);
  13738. resolution.subbands = [subband];
  13739. } else {
  13740. var bscale = 1 << (decompositionLevelsCount - r + 1);
  13741. var resolutionSubbands = [];
  13742. // three sub-bands (HL, LH and HH) with rest of decompositions
  13743. subband = {};
  13744. subband.type = 'HL';
  13745. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  13746. subband.tby0 = Math.ceil(component.tcy0 / bscale);
  13747. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  13748. subband.tby1 = Math.ceil(component.tcy1 / bscale);
  13749. subband.resolution = resolution;
  13750. buildCodeblocks(context, subband, blocksDimensions);
  13751. subbands.push(subband);
  13752. resolutionSubbands.push(subband);
  13753. subband = {};
  13754. subband.type = 'LH';
  13755. subband.tbx0 = Math.ceil(component.tcx0 / bscale);
  13756. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  13757. subband.tbx1 = Math.ceil(component.tcx1 / bscale);
  13758. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  13759. subband.resolution = resolution;
  13760. buildCodeblocks(context, subband, blocksDimensions);
  13761. subbands.push(subband);
  13762. resolutionSubbands.push(subband);
  13763. subband = {};
  13764. subband.type = 'HH';
  13765. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  13766. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  13767. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  13768. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  13769. subband.resolution = resolution;
  13770. buildCodeblocks(context, subband, blocksDimensions);
  13771. subbands.push(subband);
  13772. resolutionSubbands.push(subband);
  13773. resolution.subbands = resolutionSubbands;
  13774. }
  13775. }
  13776. component.resolutions = resolutions;
  13777. component.subbands = subbands;
  13778. }
  13779. // Generate the packets sequence
  13780. var progressionOrder = tile.codingStyleDefaultParameters.progressionOrder;
  13781. switch (progressionOrder) {
  13782. case 0:
  13783. tile.packetsIterator =
  13784. new LayerResolutionComponentPositionIterator(context);
  13785. break;
  13786. case 1:
  13787. tile.packetsIterator =
  13788. new ResolutionLayerComponentPositionIterator(context);
  13789. break;
  13790. case 2:
  13791. tile.packetsIterator =
  13792. new ResolutionPositionComponentLayerIterator(context);
  13793. break;
  13794. case 3:
  13795. tile.packetsIterator =
  13796. new PositionComponentResolutionLayerIterator(context);
  13797. break;
  13798. case 4:
  13799. tile.packetsIterator =
  13800. new ComponentPositionResolutionLayerIterator(context);
  13801. break;
  13802. default:
  13803. throw new Error('JPX Error: Unsupported progression order ' +
  13804. progressionOrder);
  13805. }
  13806. }
  13807. function parseTilePackets(context, data, offset, dataLength) {
  13808. var position = 0;
  13809. var buffer, bufferSize = 0, skipNextBit = false;
  13810. function readBits(count) {
  13811. while (bufferSize < count) {
  13812. var b = data[offset + position];
  13813. position++;
  13814. if (skipNextBit) {
  13815. buffer = (buffer << 7) | b;
  13816. bufferSize += 7;
  13817. skipNextBit = false;
  13818. } else {
  13819. buffer = (buffer << 8) | b;
  13820. bufferSize += 8;
  13821. }
  13822. if (b === 0xFF) {
  13823. skipNextBit = true;
  13824. }
  13825. }
  13826. bufferSize -= count;
  13827. return (buffer >>> bufferSize) & ((1 << count) - 1);
  13828. }
  13829. function skipMarkerIfEqual(value) {
  13830. if (data[offset + position - 1] === 0xFF &&
  13831. data[offset + position] === value) {
  13832. skipBytes(1);
  13833. return true;
  13834. } else if (data[offset + position] === 0xFF &&
  13835. data[offset + position + 1] === value) {
  13836. skipBytes(2);
  13837. return true;
  13838. }
  13839. return false;
  13840. }
  13841. function skipBytes(count) {
  13842. position += count;
  13843. }
  13844. function alignToByte() {
  13845. bufferSize = 0;
  13846. if (skipNextBit) {
  13847. position++;
  13848. skipNextBit = false;
  13849. }
  13850. }
  13851. function readCodingpasses() {
  13852. if (readBits(1) === 0) {
  13853. return 1;
  13854. }
  13855. if (readBits(1) === 0) {
  13856. return 2;
  13857. }
  13858. var value = readBits(2);
  13859. if (value < 3) {
  13860. return value + 3;
  13861. }
  13862. value = readBits(5);
  13863. if (value < 31) {
  13864. return value + 6;
  13865. }
  13866. value = readBits(7);
  13867. return value + 37;
  13868. }
  13869. var tileIndex = context.currentTile.index;
  13870. var tile = context.tiles[tileIndex];
  13871. var sopMarkerUsed = context.COD.sopMarkerUsed;
  13872. var ephMarkerUsed = context.COD.ephMarkerUsed;
  13873. var packetsIterator = tile.packetsIterator;
  13874. while (position < dataLength) {
  13875. alignToByte();
  13876. if (sopMarkerUsed && skipMarkerIfEqual(0x91)) {
  13877. // Skip also marker segment length and packet sequence ID
  13878. skipBytes(4);
  13879. }
  13880. var packet = packetsIterator.nextPacket();
  13881. if (!readBits(1)) {
  13882. continue;
  13883. }
  13884. var layerNumber = packet.layerNumber;
  13885. var queue = [], codeblock;
  13886. for (var i = 0, ii = packet.codeblocks.length; i < ii; i++) {
  13887. codeblock = packet.codeblocks[i];
  13888. var precinct = codeblock.precinct;
  13889. var codeblockColumn = codeblock.cbx - precinct.cbxMin;
  13890. var codeblockRow = codeblock.cby - precinct.cbyMin;
  13891. var codeblockIncluded = false;
  13892. var firstTimeInclusion = false;
  13893. var valueReady;
  13894. if (codeblock['included'] !== undefined) {
  13895. codeblockIncluded = !!readBits(1);
  13896. } else {
  13897. // reading inclusion tree
  13898. precinct = codeblock.precinct;
  13899. var inclusionTree, zeroBitPlanesTree;
  13900. if (precinct['inclusionTree'] !== undefined) {
  13901. inclusionTree = precinct.inclusionTree;
  13902. } else {
  13903. // building inclusion and zero bit-planes trees
  13904. var width = precinct.cbxMax - precinct.cbxMin + 1;
  13905. var height = precinct.cbyMax - precinct.cbyMin + 1;
  13906. inclusionTree = new InclusionTree(width, height, layerNumber);
  13907. zeroBitPlanesTree = new TagTree(width, height);
  13908. precinct.inclusionTree = inclusionTree;
  13909. precinct.zeroBitPlanesTree = zeroBitPlanesTree;
  13910. }
  13911. if (inclusionTree.reset(codeblockColumn, codeblockRow, layerNumber)) {
  13912. while (true) {
  13913. if (readBits(1)) {
  13914. valueReady = !inclusionTree.nextLevel();
  13915. if (valueReady) {
  13916. codeblock.included = true;
  13917. codeblockIncluded = firstTimeInclusion = true;
  13918. break;
  13919. }
  13920. } else {
  13921. inclusionTree.incrementValue(layerNumber);
  13922. break;
  13923. }
  13924. }
  13925. }
  13926. }
  13927. if (!codeblockIncluded) {
  13928. continue;
  13929. }
  13930. if (firstTimeInclusion) {
  13931. zeroBitPlanesTree = precinct.zeroBitPlanesTree;
  13932. zeroBitPlanesTree.reset(codeblockColumn, codeblockRow);
  13933. while (true) {
  13934. if (readBits(1)) {
  13935. valueReady = !zeroBitPlanesTree.nextLevel();
  13936. if (valueReady) {
  13937. break;
  13938. }
  13939. } else {
  13940. zeroBitPlanesTree.incrementValue();
  13941. }
  13942. }
  13943. codeblock.zeroBitPlanes = zeroBitPlanesTree.value;
  13944. }
  13945. var codingpasses = readCodingpasses();
  13946. while (readBits(1)) {
  13947. codeblock.Lblock++;
  13948. }
  13949. var codingpassesLog2 = log2(codingpasses);
  13950. // rounding down log2
  13951. var bits = ((codingpasses < (1 << codingpassesLog2)) ?
  13952. codingpassesLog2 - 1 : codingpassesLog2) + codeblock.Lblock;
  13953. var codedDataLength = readBits(bits);
  13954. queue.push({
  13955. codeblock: codeblock,
  13956. codingpasses: codingpasses,
  13957. dataLength: codedDataLength
  13958. });
  13959. }
  13960. alignToByte();
  13961. if (ephMarkerUsed) {
  13962. skipMarkerIfEqual(0x92);
  13963. }
  13964. while (queue.length > 0) {
  13965. var packetItem = queue.shift();
  13966. codeblock = packetItem.codeblock;
  13967. if (codeblock['data'] === undefined) {
  13968. codeblock.data = [];
  13969. }
  13970. codeblock.data.push({
  13971. data: data,
  13972. start: offset + position,
  13973. end: offset + position + packetItem.dataLength,
  13974. codingpasses: packetItem.codingpasses
  13975. });
  13976. position += packetItem.dataLength;
  13977. }
  13978. }
  13979. return position;
  13980. }
  13981. function copyCoefficients(coefficients, levelWidth, levelHeight, subband,
  13982. delta, mb, reversible, segmentationSymbolUsed) {
  13983. var x0 = subband.tbx0;
  13984. var y0 = subband.tby0;
  13985. var width = subband.tbx1 - subband.tbx0;
  13986. var codeblocks = subband.codeblocks;
  13987. var right = subband.type.charAt(0) === 'H' ? 1 : 0;
  13988. var bottom = subband.type.charAt(1) === 'H' ? levelWidth : 0;
  13989. for (var i = 0, ii = codeblocks.length; i < ii; ++i) {
  13990. var codeblock = codeblocks[i];
  13991. var blockWidth = codeblock.tbx1_ - codeblock.tbx0_;
  13992. var blockHeight = codeblock.tby1_ - codeblock.tby0_;
  13993. if (blockWidth === 0 || blockHeight === 0) {
  13994. continue;
  13995. }
  13996. if (codeblock['data'] === undefined) {
  13997. continue;
  13998. }
  13999. var bitModel, currentCodingpassType;
  14000. bitModel = new BitModel(blockWidth, blockHeight, codeblock.subbandType,
  14001. codeblock.zeroBitPlanes, mb);
  14002. currentCodingpassType = 2; // first bit plane starts from cleanup
  14003. // collect data
  14004. var data = codeblock.data, totalLength = 0, codingpasses = 0;
  14005. var j, jj, dataItem;
  14006. for (j = 0, jj = data.length; j < jj; j++) {
  14007. dataItem = data[j];
  14008. totalLength += dataItem.end - dataItem.start;
  14009. codingpasses += dataItem.codingpasses;
  14010. }
  14011. var encodedData = new Uint8Array(totalLength);
  14012. var position = 0;
  14013. for (j = 0, jj = data.length; j < jj; j++) {
  14014. dataItem = data[j];
  14015. var chunk = dataItem.data.subarray(dataItem.start, dataItem.end);
  14016. encodedData.set(chunk, position);
  14017. position += chunk.length;
  14018. }
  14019. // decoding the item
  14020. var decoder = new ArithmeticDecoder(encodedData, 0, totalLength);
  14021. bitModel.setDecoder(decoder);
  14022. for (j = 0; j < codingpasses; j++) {
  14023. switch (currentCodingpassType) {
  14024. case 0:
  14025. bitModel.runSignificancePropogationPass();
  14026. break;
  14027. case 1:
  14028. bitModel.runMagnitudeRefinementPass();
  14029. break;
  14030. case 2:
  14031. bitModel.runCleanupPass();
  14032. if (segmentationSymbolUsed) {
  14033. bitModel.checkSegmentationSymbol();
  14034. }
  14035. break;
  14036. }
  14037. currentCodingpassType = (currentCodingpassType + 1) % 3;
  14038. }
  14039. var offset = (codeblock.tbx0_ - x0) + (codeblock.tby0_ - y0) * width;
  14040. var sign = bitModel.coefficentsSign;
  14041. var magnitude = bitModel.coefficentsMagnitude;
  14042. var bitsDecoded = bitModel.bitsDecoded;
  14043. var magnitudeCorrection = reversible ? 0 : 0.5;
  14044. var k, n, nb;
  14045. position = 0;
  14046. // Do the interleaving of Section F.3.3 here, so we do not need
  14047. // to copy later. LL level is not interleaved, just copied.
  14048. var interleave = (subband.type !== 'LL');
  14049. for (j = 0; j < blockHeight; j++) {
  14050. var row = (offset / width) | 0; // row in the non-interleaved subband
  14051. var levelOffset = 2 * row * (levelWidth - width) + right + bottom;
  14052. for (k = 0; k < blockWidth; k++) {
  14053. n = magnitude[position];
  14054. if (n !== 0) {
  14055. n = (n + magnitudeCorrection) * delta;
  14056. if (sign[position] !== 0) {
  14057. n = -n;
  14058. }
  14059. nb = bitsDecoded[position];
  14060. var pos = interleave ? (levelOffset + (offset << 1)) : offset;
  14061. if (reversible && (nb >= mb)) {
  14062. coefficients[pos] = n;
  14063. } else {
  14064. coefficients[pos] = n * (1 << (mb - nb));
  14065. }
  14066. }
  14067. offset++;
  14068. position++;
  14069. }
  14070. offset += width - blockWidth;
  14071. }
  14072. }
  14073. }
  14074. function transformTile(context, tile, c) {
  14075. var component = tile.components[c];
  14076. var codingStyleParameters = component.codingStyleParameters;
  14077. var quantizationParameters = component.quantizationParameters;
  14078. var decompositionLevelsCount =
  14079. codingStyleParameters.decompositionLevelsCount;
  14080. var spqcds = quantizationParameters.SPqcds;
  14081. var scalarExpounded = quantizationParameters.scalarExpounded;
  14082. var guardBits = quantizationParameters.guardBits;
  14083. var segmentationSymbolUsed = codingStyleParameters.segmentationSymbolUsed;
  14084. var precision = context.components[c].precision;
  14085. var reversible = codingStyleParameters.reversibleTransformation;
  14086. var transform = (reversible ? new ReversibleTransform() :
  14087. new IrreversibleTransform());
  14088. var subbandCoefficients = [];
  14089. var b = 0;
  14090. for (var i = 0; i <= decompositionLevelsCount; i++) {
  14091. var resolution = component.resolutions[i];
  14092. var width = resolution.trx1 - resolution.trx0;
  14093. var height = resolution.try1 - resolution.try0;
  14094. // Allocate space for the whole sublevel.
  14095. var coefficients = new Float32Array(width * height);
  14096. for (var j = 0, jj = resolution.subbands.length; j < jj; j++) {
  14097. var mu, epsilon;
  14098. if (!scalarExpounded) {
  14099. // formula E-5
  14100. mu = spqcds[0].mu;
  14101. epsilon = spqcds[0].epsilon + (i > 0 ? 1 - i : 0);
  14102. } else {
  14103. mu = spqcds[b].mu;
  14104. epsilon = spqcds[b].epsilon;
  14105. b++;
  14106. }
  14107. var subband = resolution.subbands[j];
  14108. var gainLog2 = SubbandsGainLog2[subband.type];
  14109. // calulate quantization coefficient (Section E.1.1.1)
  14110. var delta = (reversible ? 1 :
  14111. Math.pow(2, precision + gainLog2 - epsilon) * (1 + mu / 2048));
  14112. var mb = (guardBits + epsilon - 1);
  14113. // In the first resolution level, copyCoefficients will fill the
  14114. // whole array with coefficients. In the succeding passes,
  14115. // copyCoefficients will consecutively fill in the values that belong
  14116. // to the interleaved positions of the HL, LH, and HH coefficients.
  14117. // The LL coefficients will then be interleaved in Transform.iterate().
  14118. copyCoefficients(coefficients, width, height, subband, delta, mb,
  14119. reversible, segmentationSymbolUsed);
  14120. }
  14121. subbandCoefficients.push({
  14122. width: width,
  14123. height: height,
  14124. items: coefficients
  14125. });
  14126. }
  14127. var result = transform.calculate(subbandCoefficients,
  14128. component.tcx0, component.tcy0);
  14129. return {
  14130. left: component.tcx0,
  14131. top: component.tcy0,
  14132. width: result.width,
  14133. height: result.height,
  14134. items: result.items
  14135. };
  14136. }
  14137. function transformComponents(context) {
  14138. var siz = context.SIZ;
  14139. var components = context.components;
  14140. var componentsCount = siz.Csiz;
  14141. var resultImages = [];
  14142. for (var i = 0, ii = context.tiles.length; i < ii; i++) {
  14143. var tile = context.tiles[i];
  14144. var transformedTiles = [];
  14145. var c;
  14146. for (c = 0; c < componentsCount; c++) {
  14147. transformedTiles[c] = transformTile(context, tile, c);
  14148. }
  14149. var tile0 = transformedTiles[0];
  14150. var out = new Uint8Array(tile0.items.length * componentsCount);
  14151. var result = {
  14152. left: tile0.left,
  14153. top: tile0.top,
  14154. width: tile0.width,
  14155. height: tile0.height,
  14156. items: out
  14157. };
  14158. // Section G.2.2 Inverse multi component transform
  14159. var shift, offset, max, min, maxK;
  14160. var pos = 0, j, jj, y0, y1, y2, r, g, b, k, val;
  14161. if (tile.codingStyleDefaultParameters.multipleComponentTransform) {
  14162. var fourComponents = componentsCount === 4;
  14163. var y0items = transformedTiles[0].items;
  14164. var y1items = transformedTiles[1].items;
  14165. var y2items = transformedTiles[2].items;
  14166. var y3items = fourComponents ? transformedTiles[3].items : null;
  14167. // HACK: The multiple component transform formulas below assume that
  14168. // all components have the same precision. With this in mind, we
  14169. // compute shift and offset only once.
  14170. shift = components[0].precision - 8;
  14171. offset = (128 << shift) + 0.5;
  14172. max = 255 * (1 << shift);
  14173. maxK = max * 0.5;
  14174. min = -maxK;
  14175. var component0 = tile.components[0];
  14176. var alpha01 = componentsCount - 3;
  14177. jj = y0items.length;
  14178. if (!component0.codingStyleParameters.reversibleTransformation) {
  14179. // inverse irreversible multiple component transform
  14180. for (j = 0; j < jj; j++, pos += alpha01) {
  14181. y0 = y0items[j] + offset;
  14182. y1 = y1items[j];
  14183. y2 = y2items[j];
  14184. r = y0 + 1.402 * y2;
  14185. g = y0 - 0.34413 * y1 - 0.71414 * y2;
  14186. b = y0 + 1.772 * y1;
  14187. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  14188. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  14189. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  14190. }
  14191. } else {
  14192. // inverse reversible multiple component transform
  14193. for (j = 0; j < jj; j++, pos += alpha01) {
  14194. y0 = y0items[j] + offset;
  14195. y1 = y1items[j];
  14196. y2 = y2items[j];
  14197. g = y0 - ((y2 + y1) >> 2);
  14198. r = g + y2;
  14199. b = g + y1;
  14200. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  14201. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  14202. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  14203. }
  14204. }
  14205. if (fourComponents) {
  14206. for (j = 0, pos = 3; j < jj; j++, pos += 4) {
  14207. k = y3items[j];
  14208. out[pos] = k <= min ? 0 : k >= maxK ? 255 : (k + offset) >> shift;
  14209. }
  14210. }
  14211. } else { // no multi-component transform
  14212. for (c = 0; c < componentsCount; c++) {
  14213. var items = transformedTiles[c].items;
  14214. shift = components[c].precision - 8;
  14215. offset = (128 << shift) + 0.5;
  14216. max = (127.5 * (1 << shift));
  14217. min = -max;
  14218. for (pos = c, j = 0, jj = items.length; j < jj; j++) {
  14219. val = items[j];
  14220. out[pos] = val <= min ? 0 :
  14221. val >= max ? 255 : (val + offset) >> shift;
  14222. pos += componentsCount;
  14223. }
  14224. }
  14225. }
  14226. resultImages.push(result);
  14227. }
  14228. return resultImages;
  14229. }
  14230. function initializeTile(context, tileIndex) {
  14231. var siz = context.SIZ;
  14232. var componentsCount = siz.Csiz;
  14233. var tile = context.tiles[tileIndex];
  14234. for (var c = 0; c < componentsCount; c++) {
  14235. var component = tile.components[c];
  14236. var qcdOrQcc = (context.currentTile.QCC[c] !== undefined ?
  14237. context.currentTile.QCC[c] : context.currentTile.QCD);
  14238. component.quantizationParameters = qcdOrQcc;
  14239. var codOrCoc = (context.currentTile.COC[c] !== undefined ?
  14240. context.currentTile.COC[c] : context.currentTile.COD);
  14241. component.codingStyleParameters = codOrCoc;
  14242. }
  14243. tile.codingStyleDefaultParameters = context.currentTile.COD;
  14244. }
  14245. // Section B.10.2 Tag trees
  14246. var TagTree = (function TagTreeClosure() {
  14247. function TagTree(width, height) {
  14248. var levelsLength = log2(Math.max(width, height)) + 1;
  14249. this.levels = [];
  14250. for (var i = 0; i < levelsLength; i++) {
  14251. var level = {
  14252. width: width,
  14253. height: height,
  14254. items: []
  14255. };
  14256. this.levels.push(level);
  14257. width = Math.ceil(width / 2);
  14258. height = Math.ceil(height / 2);
  14259. }
  14260. }
  14261. TagTree.prototype = {
  14262. reset: function TagTree_reset(i, j) {
  14263. var currentLevel = 0, value = 0, level;
  14264. while (currentLevel < this.levels.length) {
  14265. level = this.levels[currentLevel];
  14266. var index = i + j * level.width;
  14267. if (level.items[index] !== undefined) {
  14268. value = level.items[index];
  14269. break;
  14270. }
  14271. level.index = index;
  14272. i >>= 1;
  14273. j >>= 1;
  14274. currentLevel++;
  14275. }
  14276. currentLevel--;
  14277. level = this.levels[currentLevel];
  14278. level.items[level.index] = value;
  14279. this.currentLevel = currentLevel;
  14280. delete this.value;
  14281. },
  14282. incrementValue: function TagTree_incrementValue() {
  14283. var level = this.levels[this.currentLevel];
  14284. level.items[level.index]++;
  14285. },
  14286. nextLevel: function TagTree_nextLevel() {
  14287. var currentLevel = this.currentLevel;
  14288. var level = this.levels[currentLevel];
  14289. var value = level.items[level.index];
  14290. currentLevel--;
  14291. if (currentLevel < 0) {
  14292. this.value = value;
  14293. return false;
  14294. }
  14295. this.currentLevel = currentLevel;
  14296. level = this.levels[currentLevel];
  14297. level.items[level.index] = value;
  14298. return true;
  14299. }
  14300. };
  14301. return TagTree;
  14302. })();
  14303. var InclusionTree = (function InclusionTreeClosure() {
  14304. function InclusionTree(width, height, defaultValue) {
  14305. var levelsLength = log2(Math.max(width, height)) + 1;
  14306. this.levels = [];
  14307. for (var i = 0; i < levelsLength; i++) {
  14308. var items = new Uint8Array(width * height);
  14309. for (var j = 0, jj = items.length; j < jj; j++) {
  14310. items[j] = defaultValue;
  14311. }
  14312. var level = {
  14313. width: width,
  14314. height: height,
  14315. items: items
  14316. };
  14317. this.levels.push(level);
  14318. width = Math.ceil(width / 2);
  14319. height = Math.ceil(height / 2);
  14320. }
  14321. }
  14322. InclusionTree.prototype = {
  14323. reset: function InclusionTree_reset(i, j, stopValue) {
  14324. var currentLevel = 0;
  14325. while (currentLevel < this.levels.length) {
  14326. var level = this.levels[currentLevel];
  14327. var index = i + j * level.width;
  14328. level.index = index;
  14329. var value = level.items[index];
  14330. if (value === 0xFF) {
  14331. break;
  14332. }
  14333. if (value > stopValue) {
  14334. this.currentLevel = currentLevel;
  14335. // already know about this one, propagating the value to top levels
  14336. this.propagateValues();
  14337. return false;
  14338. }
  14339. i >>= 1;
  14340. j >>= 1;
  14341. currentLevel++;
  14342. }
  14343. this.currentLevel = currentLevel - 1;
  14344. return true;
  14345. },
  14346. incrementValue: function InclusionTree_incrementValue(stopValue) {
  14347. var level = this.levels[this.currentLevel];
  14348. level.items[level.index] = stopValue + 1;
  14349. this.propagateValues();
  14350. },
  14351. propagateValues: function InclusionTree_propagateValues() {
  14352. var levelIndex = this.currentLevel;
  14353. var level = this.levels[levelIndex];
  14354. var currentValue = level.items[level.index];
  14355. while (--levelIndex >= 0) {
  14356. level = this.levels[levelIndex];
  14357. level.items[level.index] = currentValue;
  14358. }
  14359. },
  14360. nextLevel: function InclusionTree_nextLevel() {
  14361. var currentLevel = this.currentLevel;
  14362. var level = this.levels[currentLevel];
  14363. var value = level.items[level.index];
  14364. level.items[level.index] = 0xFF;
  14365. currentLevel--;
  14366. if (currentLevel < 0) {
  14367. return false;
  14368. }
  14369. this.currentLevel = currentLevel;
  14370. level = this.levels[currentLevel];
  14371. level.items[level.index] = value;
  14372. return true;
  14373. }
  14374. };
  14375. return InclusionTree;
  14376. })();
  14377. // Section D. Coefficient bit modeling
  14378. var BitModel = (function BitModelClosure() {
  14379. var UNIFORM_CONTEXT = 17;
  14380. var RUNLENGTH_CONTEXT = 18;
  14381. // Table D-1
  14382. // The index is binary presentation: 0dddvvhh, ddd - sum of Di (0..4),
  14383. // vv - sum of Vi (0..2), and hh - sum of Hi (0..2)
  14384. var LLAndLHContextsLabel = new Uint8Array([
  14385. 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,
  14386. 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,
  14387. 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
  14388. ]);
  14389. var HLContextLabel = new Uint8Array([
  14390. 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,
  14391. 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,
  14392. 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
  14393. ]);
  14394. var HHContextLabel = new Uint8Array([
  14395. 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,
  14396. 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,
  14397. 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
  14398. ]);
  14399. function BitModel(width, height, subband, zeroBitPlanes, mb) {
  14400. this.width = width;
  14401. this.height = height;
  14402. this.contextLabelTable = (subband === 'HH' ? HHContextLabel :
  14403. (subband === 'HL' ? HLContextLabel : LLAndLHContextsLabel));
  14404. var coefficientCount = width * height;
  14405. // coefficients outside the encoding region treated as insignificant
  14406. // add border state cells for significanceState
  14407. this.neighborsSignificance = new Uint8Array(coefficientCount);
  14408. this.coefficentsSign = new Uint8Array(coefficientCount);
  14409. this.coefficentsMagnitude = mb > 14 ? new Uint32Array(coefficientCount) :
  14410. mb > 6 ? new Uint16Array(coefficientCount) :
  14411. new Uint8Array(coefficientCount);
  14412. this.processingFlags = new Uint8Array(coefficientCount);
  14413. var bitsDecoded = new Uint8Array(coefficientCount);
  14414. if (zeroBitPlanes !== 0) {
  14415. for (var i = 0; i < coefficientCount; i++) {
  14416. bitsDecoded[i] = zeroBitPlanes;
  14417. }
  14418. }
  14419. this.bitsDecoded = bitsDecoded;
  14420. this.reset();
  14421. }
  14422. BitModel.prototype = {
  14423. setDecoder: function BitModel_setDecoder(decoder) {
  14424. this.decoder = decoder;
  14425. },
  14426. reset: function BitModel_reset() {
  14427. // We have 17 contexts that are accessed via context labels,
  14428. // plus the uniform and runlength context.
  14429. this.contexts = new Int8Array(19);
  14430. // Contexts are packed into 1 byte:
  14431. // highest 7 bits carry the index, lowest bit carries mps
  14432. this.contexts[0] = (4 << 1) | 0;
  14433. this.contexts[UNIFORM_CONTEXT] = (46 << 1) | 0;
  14434. this.contexts[RUNLENGTH_CONTEXT] = (3 << 1) | 0;
  14435. },
  14436. setNeighborsSignificance:
  14437. function BitModel_setNeighborsSignificance(row, column, index) {
  14438. var neighborsSignificance = this.neighborsSignificance;
  14439. var width = this.width, height = this.height;
  14440. var left = (column > 0);
  14441. var right = (column + 1 < width);
  14442. var i;
  14443. if (row > 0) {
  14444. i = index - width;
  14445. if (left) {
  14446. neighborsSignificance[i - 1] += 0x10;
  14447. }
  14448. if (right) {
  14449. neighborsSignificance[i + 1] += 0x10;
  14450. }
  14451. neighborsSignificance[i] += 0x04;
  14452. }
  14453. if (row + 1 < height) {
  14454. i = index + width;
  14455. if (left) {
  14456. neighborsSignificance[i - 1] += 0x10;
  14457. }
  14458. if (right) {
  14459. neighborsSignificance[i + 1] += 0x10;
  14460. }
  14461. neighborsSignificance[i] += 0x04;
  14462. }
  14463. if (left) {
  14464. neighborsSignificance[index - 1] += 0x01;
  14465. }
  14466. if (right) {
  14467. neighborsSignificance[index + 1] += 0x01;
  14468. }
  14469. neighborsSignificance[index] |= 0x80;
  14470. },
  14471. runSignificancePropogationPass:
  14472. function BitModel_runSignificancePropogationPass() {
  14473. var decoder = this.decoder;
  14474. var width = this.width, height = this.height;
  14475. var coefficentsMagnitude = this.coefficentsMagnitude;
  14476. var coefficentsSign = this.coefficentsSign;
  14477. var neighborsSignificance = this.neighborsSignificance;
  14478. var processingFlags = this.processingFlags;
  14479. var contexts = this.contexts;
  14480. var labels = this.contextLabelTable;
  14481. var bitsDecoded = this.bitsDecoded;
  14482. var processedInverseMask = ~1;
  14483. var processedMask = 1;
  14484. var firstMagnitudeBitMask = 2;
  14485. for (var i0 = 0; i0 < height; i0 += 4) {
  14486. for (var j = 0; j < width; j++) {
  14487. var index = i0 * width + j;
  14488. for (var i1 = 0; i1 < 4; i1++, index += width) {
  14489. var i = i0 + i1;
  14490. if (i >= height) {
  14491. break;
  14492. }
  14493. // clear processed flag first
  14494. processingFlags[index] &= processedInverseMask;
  14495. if (coefficentsMagnitude[index] ||
  14496. !neighborsSignificance[index]) {
  14497. continue;
  14498. }
  14499. var contextLabel = labels[neighborsSignificance[index]];
  14500. var decision = decoder.readBit(contexts, contextLabel);
  14501. if (decision) {
  14502. var sign = this.decodeSignBit(i, j, index);
  14503. coefficentsSign[index] = sign;
  14504. coefficentsMagnitude[index] = 1;
  14505. this.setNeighborsSignificance(i, j, index);
  14506. processingFlags[index] |= firstMagnitudeBitMask;
  14507. }
  14508. bitsDecoded[index]++;
  14509. processingFlags[index] |= processedMask;
  14510. }
  14511. }
  14512. }
  14513. },
  14514. decodeSignBit: function BitModel_decodeSignBit(row, column, index) {
  14515. var width = this.width, height = this.height;
  14516. var coefficentsMagnitude = this.coefficentsMagnitude;
  14517. var coefficentsSign = this.coefficentsSign;
  14518. var contribution, sign0, sign1, significance1;
  14519. var contextLabel, decoded;
  14520. // calculate horizontal contribution
  14521. significance1 = (column > 0 && coefficentsMagnitude[index - 1] !== 0);
  14522. if (column + 1 < width && coefficentsMagnitude[index + 1] !== 0) {
  14523. sign1 = coefficentsSign[index + 1];
  14524. if (significance1) {
  14525. sign0 = coefficentsSign[index - 1];
  14526. contribution = 1 - sign1 - sign0;
  14527. } else {
  14528. contribution = 1 - sign1 - sign1;
  14529. }
  14530. } else if (significance1) {
  14531. sign0 = coefficentsSign[index - 1];
  14532. contribution = 1 - sign0 - sign0;
  14533. } else {
  14534. contribution = 0;
  14535. }
  14536. var horizontalContribution = 3 * contribution;
  14537. // calculate vertical contribution and combine with the horizontal
  14538. significance1 = (row > 0 && coefficentsMagnitude[index - width] !== 0);
  14539. if (row + 1 < height && coefficentsMagnitude[index + width] !== 0) {
  14540. sign1 = coefficentsSign[index + width];
  14541. if (significance1) {
  14542. sign0 = coefficentsSign[index - width];
  14543. contribution = 1 - sign1 - sign0 + horizontalContribution;
  14544. } else {
  14545. contribution = 1 - sign1 - sign1 + horizontalContribution;
  14546. }
  14547. } else if (significance1) {
  14548. sign0 = coefficentsSign[index - width];
  14549. contribution = 1 - sign0 - sign0 + horizontalContribution;
  14550. } else {
  14551. contribution = horizontalContribution;
  14552. }
  14553. if (contribution >= 0) {
  14554. contextLabel = 9 + contribution;
  14555. decoded = this.decoder.readBit(this.contexts, contextLabel);
  14556. } else {
  14557. contextLabel = 9 - contribution;
  14558. decoded = this.decoder.readBit(this.contexts, contextLabel) ^ 1;
  14559. }
  14560. return decoded;
  14561. },
  14562. runMagnitudeRefinementPass:
  14563. function BitModel_runMagnitudeRefinementPass() {
  14564. var decoder = this.decoder;
  14565. var width = this.width, height = this.height;
  14566. var coefficentsMagnitude = this.coefficentsMagnitude;
  14567. var neighborsSignificance = this.neighborsSignificance;
  14568. var contexts = this.contexts;
  14569. var bitsDecoded = this.bitsDecoded;
  14570. var processingFlags = this.processingFlags;
  14571. var processedMask = 1;
  14572. var firstMagnitudeBitMask = 2;
  14573. var length = width * height;
  14574. var width4 = width * 4;
  14575. for (var index0 = 0, indexNext; index0 < length; index0 = indexNext) {
  14576. indexNext = Math.min(length, index0 + width4);
  14577. for (var j = 0; j < width; j++) {
  14578. for (var index = index0 + j; index < indexNext; index += width) {
  14579. // significant but not those that have just become
  14580. if (!coefficentsMagnitude[index] ||
  14581. (processingFlags[index] & processedMask) !== 0) {
  14582. continue;
  14583. }
  14584. var contextLabel = 16;
  14585. if ((processingFlags[index] & firstMagnitudeBitMask) !== 0) {
  14586. processingFlags[index] ^= firstMagnitudeBitMask;
  14587. // first refinement
  14588. var significance = neighborsSignificance[index] & 127;
  14589. contextLabel = significance === 0 ? 15 : 14;
  14590. }
  14591. var bit = decoder.readBit(contexts, contextLabel);
  14592. coefficentsMagnitude[index] =
  14593. (coefficentsMagnitude[index] << 1) | bit;
  14594. bitsDecoded[index]++;
  14595. processingFlags[index] |= processedMask;
  14596. }
  14597. }
  14598. }
  14599. },
  14600. runCleanupPass: function BitModel_runCleanupPass() {
  14601. var decoder = this.decoder;
  14602. var width = this.width, height = this.height;
  14603. var neighborsSignificance = this.neighborsSignificance;
  14604. var coefficentsMagnitude = this.coefficentsMagnitude;
  14605. var coefficentsSign = this.coefficentsSign;
  14606. var contexts = this.contexts;
  14607. var labels = this.contextLabelTable;
  14608. var bitsDecoded = this.bitsDecoded;
  14609. var processingFlags = this.processingFlags;
  14610. var processedMask = 1;
  14611. var firstMagnitudeBitMask = 2;
  14612. var oneRowDown = width;
  14613. var twoRowsDown = width * 2;
  14614. var threeRowsDown = width * 3;
  14615. var iNext;
  14616. for (var i0 = 0; i0 < height; i0 = iNext) {
  14617. iNext = Math.min(i0 + 4, height);
  14618. var indexBase = i0 * width;
  14619. var checkAllEmpty = i0 + 3 < height;
  14620. for (var j = 0; j < width; j++) {
  14621. var index0 = indexBase + j;
  14622. // using the property: labels[neighborsSignificance[index]] === 0
  14623. // when neighborsSignificance[index] === 0
  14624. var allEmpty = (checkAllEmpty &&
  14625. processingFlags[index0] === 0 &&
  14626. processingFlags[index0 + oneRowDown] === 0 &&
  14627. processingFlags[index0 + twoRowsDown] === 0 &&
  14628. processingFlags[index0 + threeRowsDown] === 0 &&
  14629. neighborsSignificance[index0] === 0 &&
  14630. neighborsSignificance[index0 + oneRowDown] === 0 &&
  14631. neighborsSignificance[index0 + twoRowsDown] === 0 &&
  14632. neighborsSignificance[index0 + threeRowsDown] === 0);
  14633. var i1 = 0, index = index0;
  14634. var i = i0, sign;
  14635. if (allEmpty) {
  14636. var hasSignificantCoefficent =
  14637. decoder.readBit(contexts, RUNLENGTH_CONTEXT);
  14638. if (!hasSignificantCoefficent) {
  14639. bitsDecoded[index0]++;
  14640. bitsDecoded[index0 + oneRowDown]++;
  14641. bitsDecoded[index0 + twoRowsDown]++;
  14642. bitsDecoded[index0 + threeRowsDown]++;
  14643. continue; // next column
  14644. }
  14645. i1 = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  14646. decoder.readBit(contexts, UNIFORM_CONTEXT);
  14647. if (i1 !== 0) {
  14648. i = i0 + i1;
  14649. index += i1 * width;
  14650. }
  14651. sign = this.decodeSignBit(i, j, index);
  14652. coefficentsSign[index] = sign;
  14653. coefficentsMagnitude[index] = 1;
  14654. this.setNeighborsSignificance(i, j, index);
  14655. processingFlags[index] |= firstMagnitudeBitMask;
  14656. index = index0;
  14657. for (var i2 = i0; i2 <= i; i2++, index += width) {
  14658. bitsDecoded[index]++;
  14659. }
  14660. i1++;
  14661. }
  14662. for (i = i0 + i1; i < iNext; i++, index += width) {
  14663. if (coefficentsMagnitude[index] ||
  14664. (processingFlags[index] & processedMask) !== 0) {
  14665. continue;
  14666. }
  14667. var contextLabel = labels[neighborsSignificance[index]];
  14668. var decision = decoder.readBit(contexts, contextLabel);
  14669. if (decision === 1) {
  14670. sign = this.decodeSignBit(i, j, index);
  14671. coefficentsSign[index] = sign;
  14672. coefficentsMagnitude[index] = 1;
  14673. this.setNeighborsSignificance(i, j, index);
  14674. processingFlags[index] |= firstMagnitudeBitMask;
  14675. }
  14676. bitsDecoded[index]++;
  14677. }
  14678. }
  14679. }
  14680. },
  14681. checkSegmentationSymbol: function BitModel_checkSegmentationSymbol() {
  14682. var decoder = this.decoder;
  14683. var contexts = this.contexts;
  14684. var symbol = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 3) |
  14685. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 2) |
  14686. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  14687. decoder.readBit(contexts, UNIFORM_CONTEXT);
  14688. if (symbol !== 0xA) {
  14689. throw new Error('JPX Error: Invalid segmentation symbol');
  14690. }
  14691. }
  14692. };
  14693. return BitModel;
  14694. })();
  14695. // Section F, Discrete wavelet transformation
  14696. var Transform = (function TransformClosure() {
  14697. function Transform() {}
  14698. Transform.prototype.calculate =
  14699. function transformCalculate(subbands, u0, v0) {
  14700. var ll = subbands[0];
  14701. for (var i = 1, ii = subbands.length; i < ii; i++) {
  14702. ll = this.iterate(ll, subbands[i], u0, v0);
  14703. }
  14704. return ll;
  14705. };
  14706. Transform.prototype.extend = function extend(buffer, offset, size) {
  14707. // Section F.3.7 extending... using max extension of 4
  14708. var i1 = offset - 1, j1 = offset + 1;
  14709. var i2 = offset + size - 2, j2 = offset + size;
  14710. buffer[i1--] = buffer[j1++];
  14711. buffer[j2++] = buffer[i2--];
  14712. buffer[i1--] = buffer[j1++];
  14713. buffer[j2++] = buffer[i2--];
  14714. buffer[i1--] = buffer[j1++];
  14715. buffer[j2++] = buffer[i2--];
  14716. buffer[i1] = buffer[j1];
  14717. buffer[j2] = buffer[i2];
  14718. };
  14719. Transform.prototype.iterate = function Transform_iterate(ll, hl_lh_hh,
  14720. u0, v0) {
  14721. var llWidth = ll.width, llHeight = ll.height, llItems = ll.items;
  14722. var width = hl_lh_hh.width;
  14723. var height = hl_lh_hh.height;
  14724. var items = hl_lh_hh.items;
  14725. var i, j, k, l, u, v;
  14726. // Interleave LL according to Section F.3.3
  14727. for (k = 0, i = 0; i < llHeight; i++) {
  14728. l = i * 2 * width;
  14729. for (j = 0; j < llWidth; j++, k++, l += 2) {
  14730. items[l] = llItems[k];
  14731. }
  14732. }
  14733. // The LL band is not needed anymore.
  14734. llItems = ll.items = null;
  14735. var bufferPadding = 4;
  14736. var rowBuffer = new Float32Array(width + 2 * bufferPadding);
  14737. // Section F.3.4 HOR_SR
  14738. if (width === 1) {
  14739. // if width = 1, when u0 even keep items as is, when odd divide by 2
  14740. if ((u0 & 1) !== 0) {
  14741. for (v = 0, k = 0; v < height; v++, k += width) {
  14742. items[k] *= 0.5;
  14743. }
  14744. }
  14745. } else {
  14746. for (v = 0, k = 0; v < height; v++, k += width) {
  14747. rowBuffer.set(items.subarray(k, k + width), bufferPadding);
  14748. this.extend(rowBuffer, bufferPadding, width);
  14749. this.filter(rowBuffer, bufferPadding, width);
  14750. items.set(
  14751. rowBuffer.subarray(bufferPadding, bufferPadding + width),
  14752. k);
  14753. }
  14754. }
  14755. // Accesses to the items array can take long, because it may not fit into
  14756. // CPU cache and has to be fetched from main memory. Since subsequent
  14757. // accesses to the items array are not local when reading columns, we
  14758. // have a cache miss every time. To reduce cache misses, get up to
  14759. // 'numBuffers' items at a time and store them into the individual
  14760. // buffers. The colBuffers should be small enough to fit into CPU cache.
  14761. var numBuffers = 16;
  14762. var colBuffers = [];
  14763. for (i = 0; i < numBuffers; i++) {
  14764. colBuffers.push(new Float32Array(height + 2 * bufferPadding));
  14765. }
  14766. var b, currentBuffer = 0;
  14767. ll = bufferPadding + height;
  14768. // Section F.3.5 VER_SR
  14769. if (height === 1) {
  14770. // if height = 1, when v0 even keep items as is, when odd divide by 2
  14771. if ((v0 & 1) !== 0) {
  14772. for (u = 0; u < width; u++) {
  14773. items[u] *= 0.5;
  14774. }
  14775. }
  14776. } else {
  14777. for (u = 0; u < width; u++) {
  14778. // if we ran out of buffers, copy several image columns at once
  14779. if (currentBuffer === 0) {
  14780. numBuffers = Math.min(width - u, numBuffers);
  14781. for (k = u, l = bufferPadding; l < ll; k += width, l++) {
  14782. for (b = 0; b < numBuffers; b++) {
  14783. colBuffers[b][l] = items[k + b];
  14784. }
  14785. }
  14786. currentBuffer = numBuffers;
  14787. }
  14788. currentBuffer--;
  14789. var buffer = colBuffers[currentBuffer];
  14790. this.extend(buffer, bufferPadding, height);
  14791. this.filter(buffer, bufferPadding, height);
  14792. // If this is last buffer in this group of buffers, flush all buffers.
  14793. if (currentBuffer === 0) {
  14794. k = u - numBuffers + 1;
  14795. for (l = bufferPadding; l < ll; k += width, l++) {
  14796. for (b = 0; b < numBuffers; b++) {
  14797. items[k + b] = colBuffers[b][l];
  14798. }
  14799. }
  14800. }
  14801. }
  14802. }
  14803. return {
  14804. width: width,
  14805. height: height,
  14806. items: items
  14807. };
  14808. };
  14809. return Transform;
  14810. })();
  14811. // Section 3.8.2 Irreversible 9-7 filter
  14812. var IrreversibleTransform = (function IrreversibleTransformClosure() {
  14813. function IrreversibleTransform() {
  14814. Transform.call(this);
  14815. }
  14816. IrreversibleTransform.prototype = Object.create(Transform.prototype);
  14817. IrreversibleTransform.prototype.filter =
  14818. function irreversibleTransformFilter(x, offset, length) {
  14819. var len = length >> 1;
  14820. offset = offset | 0;
  14821. var j, n, current, next;
  14822. var alpha = -1.586134342059924;
  14823. var beta = -0.052980118572961;
  14824. var gamma = 0.882911075530934;
  14825. var delta = 0.443506852043971;
  14826. var K = 1.230174104914001;
  14827. var K_ = 1 / K;
  14828. // step 1 is combined with step 3
  14829. // step 2
  14830. j = offset - 3;
  14831. for (n = len + 4; n--; j += 2) {
  14832. x[j] *= K_;
  14833. }
  14834. // step 1 & 3
  14835. j = offset - 2;
  14836. current = delta * x[j -1];
  14837. for (n = len + 3; n--; j += 2) {
  14838. next = delta * x[j + 1];
  14839. x[j] = K * x[j] - current - next;
  14840. if (n--) {
  14841. j += 2;
  14842. current = delta * x[j + 1];
  14843. x[j] = K * x[j] - current - next;
  14844. } else {
  14845. break;
  14846. }
  14847. }
  14848. // step 4
  14849. j = offset - 1;
  14850. current = gamma * x[j - 1];
  14851. for (n = len + 2; n--; j += 2) {
  14852. next = gamma * x[j + 1];
  14853. x[j] -= current + next;
  14854. if (n--) {
  14855. j += 2;
  14856. current = gamma * x[j + 1];
  14857. x[j] -= current + next;
  14858. } else {
  14859. break;
  14860. }
  14861. }
  14862. // step 5
  14863. j = offset;
  14864. current = beta * x[j - 1];
  14865. for (n = len + 1; n--; j += 2) {
  14866. next = beta * x[j + 1];
  14867. x[j] -= current + next;
  14868. if (n--) {
  14869. j += 2;
  14870. current = beta * x[j + 1];
  14871. x[j] -= current + next;
  14872. } else {
  14873. break;
  14874. }
  14875. }
  14876. // step 6
  14877. if (len !== 0) {
  14878. j = offset + 1;
  14879. current = alpha * x[j - 1];
  14880. for (n = len; n--; j += 2) {
  14881. next = alpha * x[j + 1];
  14882. x[j] -= current + next;
  14883. if (n--) {
  14884. j += 2;
  14885. current = alpha * x[j + 1];
  14886. x[j] -= current + next;
  14887. } else {
  14888. break;
  14889. }
  14890. }
  14891. }
  14892. };
  14893. return IrreversibleTransform;
  14894. })();
  14895. // Section 3.8.1 Reversible 5-3 filter
  14896. var ReversibleTransform = (function ReversibleTransformClosure() {
  14897. function ReversibleTransform() {
  14898. Transform.call(this);
  14899. }
  14900. ReversibleTransform.prototype = Object.create(Transform.prototype);
  14901. ReversibleTransform.prototype.filter =
  14902. function reversibleTransformFilter(x, offset, length) {
  14903. var len = length >> 1;
  14904. offset = offset | 0;
  14905. var j, n;
  14906. for (j = offset, n = len + 1; n--; j += 2) {
  14907. x[j] -= (x[j - 1] + x[j + 1] + 2) >> 2;
  14908. }
  14909. for (j = offset + 1, n = len; n--; j += 2) {
  14910. x[j] += (x[j - 1] + x[j + 1]) >> 1;
  14911. }
  14912. };
  14913. return ReversibleTransform;
  14914. })();
  14915. return JpxImage;
  14916. })();
  14917. exports.JpxImage = JpxImage;
  14918. }));
  14919. (function (root, factory) {
  14920. {
  14921. factory((root.pdfjsCoreMurmurHash3 = {}), root.pdfjsSharedUtil);
  14922. }
  14923. }(this, function (exports, sharedUtil) {
  14924. var Uint32ArrayView = sharedUtil.Uint32ArrayView;
  14925. var MurmurHash3_64 = (function MurmurHash3_64Closure (seed) {
  14926. // Workaround for missing math precison in JS.
  14927. var MASK_HIGH = 0xffff0000;
  14928. var MASK_LOW = 0xffff;
  14929. function MurmurHash3_64 (seed) {
  14930. var SEED = 0xc3d2e1f0;
  14931. this.h1 = seed ? seed & 0xffffffff : SEED;
  14932. this.h2 = seed ? seed & 0xffffffff : SEED;
  14933. }
  14934. var alwaysUseUint32ArrayView = false;
  14935. // old webkits have issues with non-aligned arrays
  14936. try {
  14937. new Uint32Array(new Uint8Array(5).buffer, 0, 1);
  14938. } catch (e) {
  14939. alwaysUseUint32ArrayView = true;
  14940. }
  14941. MurmurHash3_64.prototype = {
  14942. update: function MurmurHash3_64_update(input) {
  14943. var useUint32ArrayView = alwaysUseUint32ArrayView;
  14944. var i;
  14945. if (typeof input === 'string') {
  14946. var data = new Uint8Array(input.length * 2);
  14947. var length = 0;
  14948. for (i = 0; i < input.length; i++) {
  14949. var code = input.charCodeAt(i);
  14950. if (code <= 0xff) {
  14951. data[length++] = code;
  14952. }
  14953. else {
  14954. data[length++] = code >>> 8;
  14955. data[length++] = code & 0xff;
  14956. }
  14957. }
  14958. } else if (input instanceof Uint8Array) {
  14959. data = input;
  14960. length = data.length;
  14961. } else if (typeof input === 'object' && ('length' in input)) {
  14962. // processing regular arrays as well, e.g. for IE9
  14963. data = input;
  14964. length = data.length;
  14965. useUint32ArrayView = true;
  14966. } else {
  14967. throw new Error('Wrong data format in MurmurHash3_64_update. ' +
  14968. 'Input must be a string or array.');
  14969. }
  14970. var blockCounts = length >> 2;
  14971. var tailLength = length - blockCounts * 4;
  14972. // we don't care about endianness here
  14973. var dataUint32 = useUint32ArrayView ?
  14974. new Uint32ArrayView(data, blockCounts) :
  14975. new Uint32Array(data.buffer, 0, blockCounts);
  14976. var k1 = 0;
  14977. var k2 = 0;
  14978. var h1 = this.h1;
  14979. var h2 = this.h2;
  14980. var C1 = 0xcc9e2d51;
  14981. var C2 = 0x1b873593;
  14982. var C1_LOW = C1 & MASK_LOW;
  14983. var C2_LOW = C2 & MASK_LOW;
  14984. for (i = 0; i < blockCounts; i++) {
  14985. if (i & 1) {
  14986. k1 = dataUint32[i];
  14987. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  14988. k1 = k1 << 15 | k1 >>> 17;
  14989. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  14990. h1 ^= k1;
  14991. h1 = h1 << 13 | h1 >>> 19;
  14992. h1 = h1 * 5 + 0xe6546b64;
  14993. } else {
  14994. k2 = dataUint32[i];
  14995. k2 = (k2 * C1 & MASK_HIGH) | (k2 * C1_LOW & MASK_LOW);
  14996. k2 = k2 << 15 | k2 >>> 17;
  14997. k2 = (k2 * C2 & MASK_HIGH) | (k2 * C2_LOW & MASK_LOW);
  14998. h2 ^= k2;
  14999. h2 = h2 << 13 | h2 >>> 19;
  15000. h2 = h2 * 5 + 0xe6546b64;
  15001. }
  15002. }
  15003. k1 = 0;
  15004. switch (tailLength) {
  15005. case 3:
  15006. k1 ^= data[blockCounts * 4 + 2] << 16;
  15007. /* falls through */
  15008. case 2:
  15009. k1 ^= data[blockCounts * 4 + 1] << 8;
  15010. /* falls through */
  15011. case 1:
  15012. k1 ^= data[blockCounts * 4];
  15013. /* falls through */
  15014. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  15015. k1 = k1 << 15 | k1 >>> 17;
  15016. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  15017. if (blockCounts & 1) {
  15018. h1 ^= k1;
  15019. } else {
  15020. h2 ^= k1;
  15021. }
  15022. }
  15023. this.h1 = h1;
  15024. this.h2 = h2;
  15025. return this;
  15026. },
  15027. hexdigest: function MurmurHash3_64_hexdigest () {
  15028. var h1 = this.h1;
  15029. var h2 = this.h2;
  15030. h1 ^= h2 >>> 1;
  15031. h1 = (h1 * 0xed558ccd & MASK_HIGH) | (h1 * 0x8ccd & MASK_LOW);
  15032. h2 = (h2 * 0xff51afd7 & MASK_HIGH) |
  15033. (((h2 << 16 | h1 >>> 16) * 0xafd7ed55 & MASK_HIGH) >>> 16);
  15034. h1 ^= h2 >>> 1;
  15035. h1 = (h1 * 0x1a85ec53 & MASK_HIGH) | (h1 * 0xec53 & MASK_LOW);
  15036. h2 = (h2 * 0xc4ceb9fe & MASK_HIGH) |
  15037. (((h2 << 16 | h1 >>> 16) * 0xb9fe1a85 & MASK_HIGH) >>> 16);
  15038. h1 ^= h2 >>> 1;
  15039. for (var i = 0, arr = [h1, h2], str = ''; i < arr.length; i++) {
  15040. var hex = (arr[i] >>> 0).toString(16);
  15041. while (hex.length < 8) {
  15042. hex = '0' + hex;
  15043. }
  15044. str += hex;
  15045. }
  15046. return str;
  15047. }
  15048. };
  15049. return MurmurHash3_64;
  15050. })();
  15051. exports.MurmurHash3_64 = MurmurHash3_64;
  15052. }));
  15053. (function (root, factory) {
  15054. {
  15055. factory((root.pdfjsCorePrimitives = {}), root.pdfjsSharedUtil);
  15056. }
  15057. }(this, function (exports, sharedUtil) {
  15058. var isArray = sharedUtil.isArray;
  15059. var Name = (function NameClosure() {
  15060. function Name(name) {
  15061. this.name = name;
  15062. }
  15063. Name.prototype = {};
  15064. var nameCache = {};
  15065. Name.get = function Name_get(name) {
  15066. var nameValue = nameCache[name];
  15067. return (nameValue ? nameValue : (nameCache[name] = new Name(name)));
  15068. };
  15069. return Name;
  15070. })();
  15071. var Cmd = (function CmdClosure() {
  15072. function Cmd(cmd) {
  15073. this.cmd = cmd;
  15074. }
  15075. Cmd.prototype = {};
  15076. var cmdCache = {};
  15077. Cmd.get = function Cmd_get(cmd) {
  15078. var cmdValue = cmdCache[cmd];
  15079. return (cmdValue ? cmdValue : (cmdCache[cmd] = new Cmd(cmd)));
  15080. };
  15081. return Cmd;
  15082. })();
  15083. var Dict = (function DictClosure() {
  15084. var nonSerializable = function nonSerializableClosure() {
  15085. return nonSerializable; // creating closure on some variable
  15086. };
  15087. var GETALL_DICTIONARY_TYPES_WHITELIST = {
  15088. 'Background': true,
  15089. 'ExtGState': true,
  15090. 'Halftone': true,
  15091. 'Layout': true,
  15092. 'Mask': true,
  15093. 'Pagination': true,
  15094. 'Printing': true
  15095. };
  15096. function isRecursionAllowedFor(dict) {
  15097. if (!isName(dict.Type)) {
  15098. return true;
  15099. }
  15100. var dictType = dict.Type.name;
  15101. return GETALL_DICTIONARY_TYPES_WHITELIST[dictType] === true;
  15102. }
  15103. // xref is optional
  15104. function Dict(xref) {
  15105. // Map should only be used internally, use functions below to access.
  15106. this.map = Object.create(null);
  15107. this.xref = xref;
  15108. this.objId = null;
  15109. this.__nonSerializable__ = nonSerializable; // disable cloning of the Dict
  15110. }
  15111. Dict.prototype = {
  15112. assignXref: function Dict_assignXref(newXref) {
  15113. this.xref = newXref;
  15114. },
  15115. // automatically dereferences Ref objects
  15116. get: function Dict_get(key1, key2, key3) {
  15117. var value;
  15118. var xref = this.xref;
  15119. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  15120. typeof key2 === 'undefined') {
  15121. return xref ? xref.fetchIfRef(value) : value;
  15122. }
  15123. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  15124. typeof key3 === 'undefined') {
  15125. return xref ? xref.fetchIfRef(value) : value;
  15126. }
  15127. value = this.map[key3] || null;
  15128. return xref ? xref.fetchIfRef(value) : value;
  15129. },
  15130. // Same as get(), but returns a promise and uses fetchIfRefAsync().
  15131. getAsync: function Dict_getAsync(key1, key2, key3) {
  15132. var value;
  15133. var xref = this.xref;
  15134. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  15135. typeof key2 === 'undefined') {
  15136. if (xref) {
  15137. return xref.fetchIfRefAsync(value);
  15138. }
  15139. return Promise.resolve(value);
  15140. }
  15141. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  15142. typeof key3 === 'undefined') {
  15143. if (xref) {
  15144. return xref.fetchIfRefAsync(value);
  15145. }
  15146. return Promise.resolve(value);
  15147. }
  15148. value = this.map[key3] || null;
  15149. if (xref) {
  15150. return xref.fetchIfRefAsync(value);
  15151. }
  15152. return Promise.resolve(value);
  15153. },
  15154. // Same as get(), but dereferences all elements if the result is an Array.
  15155. getArray: function Dict_getArray(key1, key2, key3) {
  15156. var value = this.get(key1, key2, key3);
  15157. var xref = this.xref;
  15158. if (!isArray(value) || !xref) {
  15159. return value;
  15160. }
  15161. value = value.slice(); // Ensure that we don't modify the Dict data.
  15162. for (var i = 0, ii = value.length; i < ii; i++) {
  15163. if (!isRef(value[i])) {
  15164. continue;
  15165. }
  15166. value[i] = xref.fetch(value[i]);
  15167. }
  15168. return value;
  15169. },
  15170. // no dereferencing
  15171. getRaw: function Dict_getRaw(key) {
  15172. return this.map[key];
  15173. },
  15174. // creates new map and dereferences all Refs
  15175. getAll: function Dict_getAll() {
  15176. var all = Object.create(null);
  15177. var queue = null;
  15178. var key, obj;
  15179. for (key in this.map) {
  15180. obj = this.get(key);
  15181. if (obj instanceof Dict) {
  15182. if (isRecursionAllowedFor(obj)) {
  15183. (queue || (queue = [])).push({target: all, key: key, obj: obj});
  15184. } else {
  15185. all[key] = this.getRaw(key);
  15186. }
  15187. } else {
  15188. all[key] = obj;
  15189. }
  15190. }
  15191. if (!queue) {
  15192. return all;
  15193. }
  15194. // trying to take cyclic references into the account
  15195. var processed = Object.create(null);
  15196. while (queue.length > 0) {
  15197. var item = queue.shift();
  15198. var itemObj = item.obj;
  15199. var objId = itemObj.objId;
  15200. if (objId && objId in processed) {
  15201. item.target[item.key] = processed[objId];
  15202. continue;
  15203. }
  15204. var dereferenced = Object.create(null);
  15205. for (key in itemObj.map) {
  15206. obj = itemObj.get(key);
  15207. if (obj instanceof Dict) {
  15208. if (isRecursionAllowedFor(obj)) {
  15209. queue.push({target: dereferenced, key: key, obj: obj});
  15210. } else {
  15211. dereferenced[key] = itemObj.getRaw(key);
  15212. }
  15213. } else {
  15214. dereferenced[key] = obj;
  15215. }
  15216. }
  15217. if (objId) {
  15218. processed[objId] = dereferenced;
  15219. }
  15220. item.target[item.key] = dereferenced;
  15221. }
  15222. return all;
  15223. },
  15224. getKeys: function Dict_getKeys() {
  15225. return Object.keys(this.map);
  15226. },
  15227. set: function Dict_set(key, value) {
  15228. this.map[key] = value;
  15229. },
  15230. has: function Dict_has(key) {
  15231. return key in this.map;
  15232. },
  15233. forEach: function Dict_forEach(callback) {
  15234. for (var key in this.map) {
  15235. callback(key, this.get(key));
  15236. }
  15237. }
  15238. };
  15239. Dict.empty = new Dict(null);
  15240. Dict.merge = function Dict_merge(xref, dictArray) {
  15241. var mergedDict = new Dict(xref);
  15242. for (var i = 0, ii = dictArray.length; i < ii; i++) {
  15243. var dict = dictArray[i];
  15244. if (!isDict(dict)) {
  15245. continue;
  15246. }
  15247. for (var keyName in dict.map) {
  15248. if (mergedDict.map[keyName]) {
  15249. continue;
  15250. }
  15251. mergedDict.map[keyName] = dict.map[keyName];
  15252. }
  15253. }
  15254. return mergedDict;
  15255. };
  15256. return Dict;
  15257. })();
  15258. var Ref = (function RefClosure() {
  15259. function Ref(num, gen) {
  15260. this.num = num;
  15261. this.gen = gen;
  15262. }
  15263. Ref.prototype = {
  15264. toString: function Ref_toString() {
  15265. // This function is hot, so we make the string as compact as possible.
  15266. // |this.gen| is almost always zero, so we treat that case specially.
  15267. var str = this.num + 'R';
  15268. if (this.gen !== 0) {
  15269. str += this.gen;
  15270. }
  15271. return str;
  15272. }
  15273. };
  15274. return Ref;
  15275. })();
  15276. // The reference is identified by number and generation.
  15277. // This structure stores only one instance of the reference.
  15278. var RefSet = (function RefSetClosure() {
  15279. function RefSet() {
  15280. this.dict = {};
  15281. }
  15282. RefSet.prototype = {
  15283. has: function RefSet_has(ref) {
  15284. return ref.toString() in this.dict;
  15285. },
  15286. put: function RefSet_put(ref) {
  15287. this.dict[ref.toString()] = true;
  15288. },
  15289. remove: function RefSet_remove(ref) {
  15290. delete this.dict[ref.toString()];
  15291. }
  15292. };
  15293. return RefSet;
  15294. })();
  15295. var RefSetCache = (function RefSetCacheClosure() {
  15296. function RefSetCache() {
  15297. this.dict = Object.create(null);
  15298. }
  15299. RefSetCache.prototype = {
  15300. get: function RefSetCache_get(ref) {
  15301. return this.dict[ref.toString()];
  15302. },
  15303. has: function RefSetCache_has(ref) {
  15304. return ref.toString() in this.dict;
  15305. },
  15306. put: function RefSetCache_put(ref, obj) {
  15307. this.dict[ref.toString()] = obj;
  15308. },
  15309. putAlias: function RefSetCache_putAlias(ref, aliasRef) {
  15310. this.dict[ref.toString()] = this.get(aliasRef);
  15311. },
  15312. forEach: function RefSetCache_forEach(fn, thisArg) {
  15313. for (var i in this.dict) {
  15314. fn.call(thisArg, this.dict[i]);
  15315. }
  15316. },
  15317. clear: function RefSetCache_clear() {
  15318. this.dict = Object.create(null);
  15319. }
  15320. };
  15321. return RefSetCache;
  15322. })();
  15323. function isName(v) {
  15324. return v instanceof Name;
  15325. }
  15326. function isCmd(v, cmd) {
  15327. return v instanceof Cmd && (cmd === undefined || v.cmd === cmd);
  15328. }
  15329. function isDict(v, type) {
  15330. if (!(v instanceof Dict)) {
  15331. return false;
  15332. }
  15333. if (!type) {
  15334. return true;
  15335. }
  15336. var dictType = v.get('Type');
  15337. return isName(dictType) && dictType.name === type;
  15338. }
  15339. function isRef(v) {
  15340. return v instanceof Ref;
  15341. }
  15342. function isStream(v) {
  15343. return typeof v === 'object' && v !== null && v.getBytes !== undefined;
  15344. }
  15345. exports.Cmd = Cmd;
  15346. exports.Dict = Dict;
  15347. exports.Name = Name;
  15348. exports.Ref = Ref;
  15349. exports.RefSet = RefSet;
  15350. exports.RefSetCache = RefSetCache;
  15351. exports.isCmd = isCmd;
  15352. exports.isDict = isDict;
  15353. exports.isName = isName;
  15354. exports.isRef = isRef;
  15355. exports.isStream = isStream;
  15356. }));
  15357. (function (root, factory) {
  15358. {
  15359. factory((root.pdfjsCoreStream = {}), root.pdfjsSharedUtil,
  15360. root.pdfjsCorePrimitives, root.pdfjsCoreJbig2, root.pdfjsCoreJpg,
  15361. root.pdfjsCoreJpx);
  15362. }
  15363. }(this, function (exports, sharedUtil, corePrimitives, coreJbig2, coreJpg,
  15364. coreJpx) {
  15365. var Util = sharedUtil.Util;
  15366. var error = sharedUtil.error;
  15367. var info = sharedUtil.info;
  15368. var isArray = sharedUtil.isArray;
  15369. var shadow = sharedUtil.shadow;
  15370. var warn = sharedUtil.warn;
  15371. var Dict = corePrimitives.Dict;
  15372. var Jbig2Image = coreJbig2.Jbig2Image;
  15373. var JpegImage = coreJpg.JpegImage;
  15374. var JpxImage = coreJpx.JpxImage;
  15375. var coreParser; // see _setCoreParser below
  15376. var EOF; // = coreParser.EOF;
  15377. var Lexer; // = coreParser.Lexer;
  15378. var coreColorSpace; // see _setCoreColorSpace below
  15379. var ColorSpace; // = coreColorSpace.ColorSpace;
  15380. var Stream = (function StreamClosure() {
  15381. function Stream(arrayBuffer, start, length, dict) {
  15382. this.bytes = (arrayBuffer instanceof Uint8Array ?
  15383. arrayBuffer : new Uint8Array(arrayBuffer));
  15384. this.start = start || 0;
  15385. this.pos = this.start;
  15386. this.end = (start + length) || this.bytes.length;
  15387. this.dict = dict;
  15388. }
  15389. // required methods for a stream. if a particular stream does not
  15390. // implement these, an error should be thrown
  15391. Stream.prototype = {
  15392. get length() {
  15393. return this.end - this.start;
  15394. },
  15395. get isEmpty() {
  15396. return this.length === 0;
  15397. },
  15398. getByte: function Stream_getByte() {
  15399. if (this.pos >= this.end) {
  15400. return -1;
  15401. }
  15402. return this.bytes[this.pos++];
  15403. },
  15404. getUint16: function Stream_getUint16() {
  15405. var b0 = this.getByte();
  15406. var b1 = this.getByte();
  15407. if (b0 === -1 || b1 === -1) {
  15408. return -1;
  15409. }
  15410. return (b0 << 8) + b1;
  15411. },
  15412. getInt32: function Stream_getInt32() {
  15413. var b0 = this.getByte();
  15414. var b1 = this.getByte();
  15415. var b2 = this.getByte();
  15416. var b3 = this.getByte();
  15417. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  15418. },
  15419. // returns subarray of original buffer
  15420. // should only be read
  15421. getBytes: function Stream_getBytes(length) {
  15422. var bytes = this.bytes;
  15423. var pos = this.pos;
  15424. var strEnd = this.end;
  15425. if (!length) {
  15426. return bytes.subarray(pos, strEnd);
  15427. }
  15428. var end = pos + length;
  15429. if (end > strEnd) {
  15430. end = strEnd;
  15431. }
  15432. this.pos = end;
  15433. return bytes.subarray(pos, end);
  15434. },
  15435. peekByte: function Stream_peekByte() {
  15436. var peekedByte = this.getByte();
  15437. this.pos--;
  15438. return peekedByte;
  15439. },
  15440. peekBytes: function Stream_peekBytes(length) {
  15441. var bytes = this.getBytes(length);
  15442. this.pos -= bytes.length;
  15443. return bytes;
  15444. },
  15445. skip: function Stream_skip(n) {
  15446. if (!n) {
  15447. n = 1;
  15448. }
  15449. this.pos += n;
  15450. },
  15451. reset: function Stream_reset() {
  15452. this.pos = this.start;
  15453. },
  15454. moveStart: function Stream_moveStart() {
  15455. this.start = this.pos;
  15456. },
  15457. makeSubStream: function Stream_makeSubStream(start, length, dict) {
  15458. return new Stream(this.bytes.buffer, start, length, dict);
  15459. },
  15460. isStream: true
  15461. };
  15462. return Stream;
  15463. })();
  15464. var StringStream = (function StringStreamClosure() {
  15465. function StringStream(str) {
  15466. var length = str.length;
  15467. var bytes = new Uint8Array(length);
  15468. for (var n = 0; n < length; ++n) {
  15469. bytes[n] = str.charCodeAt(n);
  15470. }
  15471. Stream.call(this, bytes);
  15472. }
  15473. StringStream.prototype = Stream.prototype;
  15474. return StringStream;
  15475. })();
  15476. // super class for the decoding streams
  15477. var DecodeStream = (function DecodeStreamClosure() {
  15478. // Lots of DecodeStreams are created whose buffers are never used. For these
  15479. // we share a single empty buffer. This is (a) space-efficient and (b) avoids
  15480. // having special cases that would be required if we used |null| for an empty
  15481. // buffer.
  15482. var emptyBuffer = new Uint8Array(0);
  15483. function DecodeStream(maybeMinBufferLength) {
  15484. this.pos = 0;
  15485. this.bufferLength = 0;
  15486. this.eof = false;
  15487. this.buffer = emptyBuffer;
  15488. this.minBufferLength = 512;
  15489. if (maybeMinBufferLength) {
  15490. // Compute the first power of two that is as big as maybeMinBufferLength.
  15491. while (this.minBufferLength < maybeMinBufferLength) {
  15492. this.minBufferLength *= 2;
  15493. }
  15494. }
  15495. }
  15496. DecodeStream.prototype = {
  15497. get isEmpty() {
  15498. while (!this.eof && this.bufferLength === 0) {
  15499. this.readBlock();
  15500. }
  15501. return this.bufferLength === 0;
  15502. },
  15503. ensureBuffer: function DecodeStream_ensureBuffer(requested) {
  15504. var buffer = this.buffer;
  15505. if (requested <= buffer.byteLength) {
  15506. return buffer;
  15507. }
  15508. var size = this.minBufferLength;
  15509. while (size < requested) {
  15510. size *= 2;
  15511. }
  15512. var buffer2 = new Uint8Array(size);
  15513. buffer2.set(buffer);
  15514. return (this.buffer = buffer2);
  15515. },
  15516. getByte: function DecodeStream_getByte() {
  15517. var pos = this.pos;
  15518. while (this.bufferLength <= pos) {
  15519. if (this.eof) {
  15520. return -1;
  15521. }
  15522. this.readBlock();
  15523. }
  15524. return this.buffer[this.pos++];
  15525. },
  15526. getUint16: function DecodeStream_getUint16() {
  15527. var b0 = this.getByte();
  15528. var b1 = this.getByte();
  15529. if (b0 === -1 || b1 === -1) {
  15530. return -1;
  15531. }
  15532. return (b0 << 8) + b1;
  15533. },
  15534. getInt32: function DecodeStream_getInt32() {
  15535. var b0 = this.getByte();
  15536. var b1 = this.getByte();
  15537. var b2 = this.getByte();
  15538. var b3 = this.getByte();
  15539. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  15540. },
  15541. getBytes: function DecodeStream_getBytes(length) {
  15542. var end, pos = this.pos;
  15543. if (length) {
  15544. this.ensureBuffer(pos + length);
  15545. end = pos + length;
  15546. while (!this.eof && this.bufferLength < end) {
  15547. this.readBlock();
  15548. }
  15549. var bufEnd = this.bufferLength;
  15550. if (end > bufEnd) {
  15551. end = bufEnd;
  15552. }
  15553. } else {
  15554. while (!this.eof) {
  15555. this.readBlock();
  15556. }
  15557. end = this.bufferLength;
  15558. }
  15559. this.pos = end;
  15560. return this.buffer.subarray(pos, end);
  15561. },
  15562. peekByte: function DecodeStream_peekByte() {
  15563. var peekedByte = this.getByte();
  15564. this.pos--;
  15565. return peekedByte;
  15566. },
  15567. peekBytes: function DecodeStream_peekBytes(length) {
  15568. var bytes = this.getBytes(length);
  15569. this.pos -= bytes.length;
  15570. return bytes;
  15571. },
  15572. makeSubStream: function DecodeStream_makeSubStream(start, length, dict) {
  15573. var end = start + length;
  15574. while (this.bufferLength <= end && !this.eof) {
  15575. this.readBlock();
  15576. }
  15577. return new Stream(this.buffer, start, length, dict);
  15578. },
  15579. skip: function DecodeStream_skip(n) {
  15580. if (!n) {
  15581. n = 1;
  15582. }
  15583. this.pos += n;
  15584. },
  15585. reset: function DecodeStream_reset() {
  15586. this.pos = 0;
  15587. },
  15588. getBaseStreams: function DecodeStream_getBaseStreams() {
  15589. if (this.str && this.str.getBaseStreams) {
  15590. return this.str.getBaseStreams();
  15591. }
  15592. return [];
  15593. }
  15594. };
  15595. return DecodeStream;
  15596. })();
  15597. var StreamsSequenceStream = (function StreamsSequenceStreamClosure() {
  15598. function StreamsSequenceStream(streams) {
  15599. this.streams = streams;
  15600. DecodeStream.call(this, /* maybeLength = */ null);
  15601. }
  15602. StreamsSequenceStream.prototype = Object.create(DecodeStream.prototype);
  15603. StreamsSequenceStream.prototype.readBlock =
  15604. function streamSequenceStreamReadBlock() {
  15605. var streams = this.streams;
  15606. if (streams.length === 0) {
  15607. this.eof = true;
  15608. return;
  15609. }
  15610. var stream = streams.shift();
  15611. var chunk = stream.getBytes();
  15612. var bufferLength = this.bufferLength;
  15613. var newLength = bufferLength + chunk.length;
  15614. var buffer = this.ensureBuffer(newLength);
  15615. buffer.set(chunk, bufferLength);
  15616. this.bufferLength = newLength;
  15617. };
  15618. StreamsSequenceStream.prototype.getBaseStreams =
  15619. function StreamsSequenceStream_getBaseStreams() {
  15620. var baseStreams = [];
  15621. for (var i = 0, ii = this.streams.length; i < ii; i++) {
  15622. var stream = this.streams[i];
  15623. if (stream.getBaseStreams) {
  15624. Util.appendToArray(baseStreams, stream.getBaseStreams());
  15625. }
  15626. }
  15627. return baseStreams;
  15628. };
  15629. return StreamsSequenceStream;
  15630. })();
  15631. var FlateStream = (function FlateStreamClosure() {
  15632. var codeLenCodeMap = new Int32Array([
  15633. 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
  15634. ]);
  15635. var lengthDecode = new Int32Array([
  15636. 0x00003, 0x00004, 0x00005, 0x00006, 0x00007, 0x00008, 0x00009, 0x0000a,
  15637. 0x1000b, 0x1000d, 0x1000f, 0x10011, 0x20013, 0x20017, 0x2001b, 0x2001f,
  15638. 0x30023, 0x3002b, 0x30033, 0x3003b, 0x40043, 0x40053, 0x40063, 0x40073,
  15639. 0x50083, 0x500a3, 0x500c3, 0x500e3, 0x00102, 0x00102, 0x00102
  15640. ]);
  15641. var distDecode = new Int32Array([
  15642. 0x00001, 0x00002, 0x00003, 0x00004, 0x10005, 0x10007, 0x20009, 0x2000d,
  15643. 0x30011, 0x30019, 0x40021, 0x40031, 0x50041, 0x50061, 0x60081, 0x600c1,
  15644. 0x70101, 0x70181, 0x80201, 0x80301, 0x90401, 0x90601, 0xa0801, 0xa0c01,
  15645. 0xb1001, 0xb1801, 0xc2001, 0xc3001, 0xd4001, 0xd6001
  15646. ]);
  15647. var fixedLitCodeTab = [new Int32Array([
  15648. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c0,
  15649. 0x70108, 0x80060, 0x80020, 0x900a0, 0x80000, 0x80080, 0x80040, 0x900e0,
  15650. 0x70104, 0x80058, 0x80018, 0x90090, 0x70114, 0x80078, 0x80038, 0x900d0,
  15651. 0x7010c, 0x80068, 0x80028, 0x900b0, 0x80008, 0x80088, 0x80048, 0x900f0,
  15652. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c8,
  15653. 0x7010a, 0x80064, 0x80024, 0x900a8, 0x80004, 0x80084, 0x80044, 0x900e8,
  15654. 0x70106, 0x8005c, 0x8001c, 0x90098, 0x70116, 0x8007c, 0x8003c, 0x900d8,
  15655. 0x7010e, 0x8006c, 0x8002c, 0x900b8, 0x8000c, 0x8008c, 0x8004c, 0x900f8,
  15656. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c4,
  15657. 0x70109, 0x80062, 0x80022, 0x900a4, 0x80002, 0x80082, 0x80042, 0x900e4,
  15658. 0x70105, 0x8005a, 0x8001a, 0x90094, 0x70115, 0x8007a, 0x8003a, 0x900d4,
  15659. 0x7010d, 0x8006a, 0x8002a, 0x900b4, 0x8000a, 0x8008a, 0x8004a, 0x900f4,
  15660. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cc,
  15661. 0x7010b, 0x80066, 0x80026, 0x900ac, 0x80006, 0x80086, 0x80046, 0x900ec,
  15662. 0x70107, 0x8005e, 0x8001e, 0x9009c, 0x70117, 0x8007e, 0x8003e, 0x900dc,
  15663. 0x7010f, 0x8006e, 0x8002e, 0x900bc, 0x8000e, 0x8008e, 0x8004e, 0x900fc,
  15664. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c2,
  15665. 0x70108, 0x80061, 0x80021, 0x900a2, 0x80001, 0x80081, 0x80041, 0x900e2,
  15666. 0x70104, 0x80059, 0x80019, 0x90092, 0x70114, 0x80079, 0x80039, 0x900d2,
  15667. 0x7010c, 0x80069, 0x80029, 0x900b2, 0x80009, 0x80089, 0x80049, 0x900f2,
  15668. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900ca,
  15669. 0x7010a, 0x80065, 0x80025, 0x900aa, 0x80005, 0x80085, 0x80045, 0x900ea,
  15670. 0x70106, 0x8005d, 0x8001d, 0x9009a, 0x70116, 0x8007d, 0x8003d, 0x900da,
  15671. 0x7010e, 0x8006d, 0x8002d, 0x900ba, 0x8000d, 0x8008d, 0x8004d, 0x900fa,
  15672. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c6,
  15673. 0x70109, 0x80063, 0x80023, 0x900a6, 0x80003, 0x80083, 0x80043, 0x900e6,
  15674. 0x70105, 0x8005b, 0x8001b, 0x90096, 0x70115, 0x8007b, 0x8003b, 0x900d6,
  15675. 0x7010d, 0x8006b, 0x8002b, 0x900b6, 0x8000b, 0x8008b, 0x8004b, 0x900f6,
  15676. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900ce,
  15677. 0x7010b, 0x80067, 0x80027, 0x900ae, 0x80007, 0x80087, 0x80047, 0x900ee,
  15678. 0x70107, 0x8005f, 0x8001f, 0x9009e, 0x70117, 0x8007f, 0x8003f, 0x900de,
  15679. 0x7010f, 0x8006f, 0x8002f, 0x900be, 0x8000f, 0x8008f, 0x8004f, 0x900fe,
  15680. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c1,
  15681. 0x70108, 0x80060, 0x80020, 0x900a1, 0x80000, 0x80080, 0x80040, 0x900e1,
  15682. 0x70104, 0x80058, 0x80018, 0x90091, 0x70114, 0x80078, 0x80038, 0x900d1,
  15683. 0x7010c, 0x80068, 0x80028, 0x900b1, 0x80008, 0x80088, 0x80048, 0x900f1,
  15684. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c9,
  15685. 0x7010a, 0x80064, 0x80024, 0x900a9, 0x80004, 0x80084, 0x80044, 0x900e9,
  15686. 0x70106, 0x8005c, 0x8001c, 0x90099, 0x70116, 0x8007c, 0x8003c, 0x900d9,
  15687. 0x7010e, 0x8006c, 0x8002c, 0x900b9, 0x8000c, 0x8008c, 0x8004c, 0x900f9,
  15688. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c5,
  15689. 0x70109, 0x80062, 0x80022, 0x900a5, 0x80002, 0x80082, 0x80042, 0x900e5,
  15690. 0x70105, 0x8005a, 0x8001a, 0x90095, 0x70115, 0x8007a, 0x8003a, 0x900d5,
  15691. 0x7010d, 0x8006a, 0x8002a, 0x900b5, 0x8000a, 0x8008a, 0x8004a, 0x900f5,
  15692. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cd,
  15693. 0x7010b, 0x80066, 0x80026, 0x900ad, 0x80006, 0x80086, 0x80046, 0x900ed,
  15694. 0x70107, 0x8005e, 0x8001e, 0x9009d, 0x70117, 0x8007e, 0x8003e, 0x900dd,
  15695. 0x7010f, 0x8006e, 0x8002e, 0x900bd, 0x8000e, 0x8008e, 0x8004e, 0x900fd,
  15696. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c3,
  15697. 0x70108, 0x80061, 0x80021, 0x900a3, 0x80001, 0x80081, 0x80041, 0x900e3,
  15698. 0x70104, 0x80059, 0x80019, 0x90093, 0x70114, 0x80079, 0x80039, 0x900d3,
  15699. 0x7010c, 0x80069, 0x80029, 0x900b3, 0x80009, 0x80089, 0x80049, 0x900f3,
  15700. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900cb,
  15701. 0x7010a, 0x80065, 0x80025, 0x900ab, 0x80005, 0x80085, 0x80045, 0x900eb,
  15702. 0x70106, 0x8005d, 0x8001d, 0x9009b, 0x70116, 0x8007d, 0x8003d, 0x900db,
  15703. 0x7010e, 0x8006d, 0x8002d, 0x900bb, 0x8000d, 0x8008d, 0x8004d, 0x900fb,
  15704. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c7,
  15705. 0x70109, 0x80063, 0x80023, 0x900a7, 0x80003, 0x80083, 0x80043, 0x900e7,
  15706. 0x70105, 0x8005b, 0x8001b, 0x90097, 0x70115, 0x8007b, 0x8003b, 0x900d7,
  15707. 0x7010d, 0x8006b, 0x8002b, 0x900b7, 0x8000b, 0x8008b, 0x8004b, 0x900f7,
  15708. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900cf,
  15709. 0x7010b, 0x80067, 0x80027, 0x900af, 0x80007, 0x80087, 0x80047, 0x900ef,
  15710. 0x70107, 0x8005f, 0x8001f, 0x9009f, 0x70117, 0x8007f, 0x8003f, 0x900df,
  15711. 0x7010f, 0x8006f, 0x8002f, 0x900bf, 0x8000f, 0x8008f, 0x8004f, 0x900ff
  15712. ]), 9];
  15713. var fixedDistCodeTab = [new Int32Array([
  15714. 0x50000, 0x50010, 0x50008, 0x50018, 0x50004, 0x50014, 0x5000c, 0x5001c,
  15715. 0x50002, 0x50012, 0x5000a, 0x5001a, 0x50006, 0x50016, 0x5000e, 0x00000,
  15716. 0x50001, 0x50011, 0x50009, 0x50019, 0x50005, 0x50015, 0x5000d, 0x5001d,
  15717. 0x50003, 0x50013, 0x5000b, 0x5001b, 0x50007, 0x50017, 0x5000f, 0x00000
  15718. ]), 5];
  15719. function FlateStream(str, maybeLength) {
  15720. this.str = str;
  15721. this.dict = str.dict;
  15722. var cmf = str.getByte();
  15723. var flg = str.getByte();
  15724. if (cmf === -1 || flg === -1) {
  15725. error('Invalid header in flate stream: ' + cmf + ', ' + flg);
  15726. }
  15727. if ((cmf & 0x0f) !== 0x08) {
  15728. error('Unknown compression method in flate stream: ' + cmf + ', ' + flg);
  15729. }
  15730. if ((((cmf << 8) + flg) % 31) !== 0) {
  15731. error('Bad FCHECK in flate stream: ' + cmf + ', ' + flg);
  15732. }
  15733. if (flg & 0x20) {
  15734. error('FDICT bit set in flate stream: ' + cmf + ', ' + flg);
  15735. }
  15736. this.codeSize = 0;
  15737. this.codeBuf = 0;
  15738. DecodeStream.call(this, maybeLength);
  15739. }
  15740. FlateStream.prototype = Object.create(DecodeStream.prototype);
  15741. FlateStream.prototype.getBits = function FlateStream_getBits(bits) {
  15742. var str = this.str;
  15743. var codeSize = this.codeSize;
  15744. var codeBuf = this.codeBuf;
  15745. var b;
  15746. while (codeSize < bits) {
  15747. if ((b = str.getByte()) === -1) {
  15748. error('Bad encoding in flate stream');
  15749. }
  15750. codeBuf |= b << codeSize;
  15751. codeSize += 8;
  15752. }
  15753. b = codeBuf & ((1 << bits) - 1);
  15754. this.codeBuf = codeBuf >> bits;
  15755. this.codeSize = codeSize -= bits;
  15756. return b;
  15757. };
  15758. FlateStream.prototype.getCode = function FlateStream_getCode(table) {
  15759. var str = this.str;
  15760. var codes = table[0];
  15761. var maxLen = table[1];
  15762. var codeSize = this.codeSize;
  15763. var codeBuf = this.codeBuf;
  15764. var b;
  15765. while (codeSize < maxLen) {
  15766. if ((b = str.getByte()) === -1) {
  15767. // premature end of stream. code might however still be valid.
  15768. // codeSize < codeLen check below guards against incomplete codeVal.
  15769. break;
  15770. }
  15771. codeBuf |= (b << codeSize);
  15772. codeSize += 8;
  15773. }
  15774. var code = codes[codeBuf & ((1 << maxLen) - 1)];
  15775. var codeLen = code >> 16;
  15776. var codeVal = code & 0xffff;
  15777. if (codeLen < 1 || codeSize < codeLen) {
  15778. error('Bad encoding in flate stream');
  15779. }
  15780. this.codeBuf = (codeBuf >> codeLen);
  15781. this.codeSize = (codeSize - codeLen);
  15782. return codeVal;
  15783. };
  15784. FlateStream.prototype.generateHuffmanTable =
  15785. function flateStreamGenerateHuffmanTable(lengths) {
  15786. var n = lengths.length;
  15787. // find max code length
  15788. var maxLen = 0;
  15789. var i;
  15790. for (i = 0; i < n; ++i) {
  15791. if (lengths[i] > maxLen) {
  15792. maxLen = lengths[i];
  15793. }
  15794. }
  15795. // build the table
  15796. var size = 1 << maxLen;
  15797. var codes = new Int32Array(size);
  15798. for (var len = 1, code = 0, skip = 2;
  15799. len <= maxLen;
  15800. ++len, code <<= 1, skip <<= 1) {
  15801. for (var val = 0; val < n; ++val) {
  15802. if (lengths[val] === len) {
  15803. // bit-reverse the code
  15804. var code2 = 0;
  15805. var t = code;
  15806. for (i = 0; i < len; ++i) {
  15807. code2 = (code2 << 1) | (t & 1);
  15808. t >>= 1;
  15809. }
  15810. // fill the table entries
  15811. for (i = code2; i < size; i += skip) {
  15812. codes[i] = (len << 16) | val;
  15813. }
  15814. ++code;
  15815. }
  15816. }
  15817. }
  15818. return [codes, maxLen];
  15819. };
  15820. FlateStream.prototype.readBlock = function FlateStream_readBlock() {
  15821. var buffer, len;
  15822. var str = this.str;
  15823. // read block header
  15824. var hdr = this.getBits(3);
  15825. if (hdr & 1) {
  15826. this.eof = true;
  15827. }
  15828. hdr >>= 1;
  15829. if (hdr === 0) { // uncompressed block
  15830. var b;
  15831. if ((b = str.getByte()) === -1) {
  15832. error('Bad block header in flate stream');
  15833. }
  15834. var blockLen = b;
  15835. if ((b = str.getByte()) === -1) {
  15836. error('Bad block header in flate stream');
  15837. }
  15838. blockLen |= (b << 8);
  15839. if ((b = str.getByte()) === -1) {
  15840. error('Bad block header in flate stream');
  15841. }
  15842. var check = b;
  15843. if ((b = str.getByte()) === -1) {
  15844. error('Bad block header in flate stream');
  15845. }
  15846. check |= (b << 8);
  15847. if (check !== (~blockLen & 0xffff) &&
  15848. (blockLen !== 0 || check !== 0)) {
  15849. // Ignoring error for bad "empty" block (see issue 1277)
  15850. error('Bad uncompressed block length in flate stream');
  15851. }
  15852. this.codeBuf = 0;
  15853. this.codeSize = 0;
  15854. var bufferLength = this.bufferLength;
  15855. buffer = this.ensureBuffer(bufferLength + blockLen);
  15856. var end = bufferLength + blockLen;
  15857. this.bufferLength = end;
  15858. if (blockLen === 0) {
  15859. if (str.peekByte() === -1) {
  15860. this.eof = true;
  15861. }
  15862. } else {
  15863. for (var n = bufferLength; n < end; ++n) {
  15864. if ((b = str.getByte()) === -1) {
  15865. this.eof = true;
  15866. break;
  15867. }
  15868. buffer[n] = b;
  15869. }
  15870. }
  15871. return;
  15872. }
  15873. var litCodeTable;
  15874. var distCodeTable;
  15875. if (hdr === 1) { // compressed block, fixed codes
  15876. litCodeTable = fixedLitCodeTab;
  15877. distCodeTable = fixedDistCodeTab;
  15878. } else if (hdr === 2) { // compressed block, dynamic codes
  15879. var numLitCodes = this.getBits(5) + 257;
  15880. var numDistCodes = this.getBits(5) + 1;
  15881. var numCodeLenCodes = this.getBits(4) + 4;
  15882. // build the code lengths code table
  15883. var codeLenCodeLengths = new Uint8Array(codeLenCodeMap.length);
  15884. var i;
  15885. for (i = 0; i < numCodeLenCodes; ++i) {
  15886. codeLenCodeLengths[codeLenCodeMap[i]] = this.getBits(3);
  15887. }
  15888. var codeLenCodeTab = this.generateHuffmanTable(codeLenCodeLengths);
  15889. // build the literal and distance code tables
  15890. len = 0;
  15891. i = 0;
  15892. var codes = numLitCodes + numDistCodes;
  15893. var codeLengths = new Uint8Array(codes);
  15894. var bitsLength, bitsOffset, what;
  15895. while (i < codes) {
  15896. var code = this.getCode(codeLenCodeTab);
  15897. if (code === 16) {
  15898. bitsLength = 2; bitsOffset = 3; what = len;
  15899. } else if (code === 17) {
  15900. bitsLength = 3; bitsOffset = 3; what = (len = 0);
  15901. } else if (code === 18) {
  15902. bitsLength = 7; bitsOffset = 11; what = (len = 0);
  15903. } else {
  15904. codeLengths[i++] = len = code;
  15905. continue;
  15906. }
  15907. var repeatLength = this.getBits(bitsLength) + bitsOffset;
  15908. while (repeatLength-- > 0) {
  15909. codeLengths[i++] = what;
  15910. }
  15911. }
  15912. litCodeTable =
  15913. this.generateHuffmanTable(codeLengths.subarray(0, numLitCodes));
  15914. distCodeTable =
  15915. this.generateHuffmanTable(codeLengths.subarray(numLitCodes, codes));
  15916. } else {
  15917. error('Unknown block type in flate stream');
  15918. }
  15919. buffer = this.buffer;
  15920. var limit = buffer ? buffer.length : 0;
  15921. var pos = this.bufferLength;
  15922. while (true) {
  15923. var code1 = this.getCode(litCodeTable);
  15924. if (code1 < 256) {
  15925. if (pos + 1 >= limit) {
  15926. buffer = this.ensureBuffer(pos + 1);
  15927. limit = buffer.length;
  15928. }
  15929. buffer[pos++] = code1;
  15930. continue;
  15931. }
  15932. if (code1 === 256) {
  15933. this.bufferLength = pos;
  15934. return;
  15935. }
  15936. code1 -= 257;
  15937. code1 = lengthDecode[code1];
  15938. var code2 = code1 >> 16;
  15939. if (code2 > 0) {
  15940. code2 = this.getBits(code2);
  15941. }
  15942. len = (code1 & 0xffff) + code2;
  15943. code1 = this.getCode(distCodeTable);
  15944. code1 = distDecode[code1];
  15945. code2 = code1 >> 16;
  15946. if (code2 > 0) {
  15947. code2 = this.getBits(code2);
  15948. }
  15949. var dist = (code1 & 0xffff) + code2;
  15950. if (pos + len >= limit) {
  15951. buffer = this.ensureBuffer(pos + len);
  15952. limit = buffer.length;
  15953. }
  15954. for (var k = 0; k < len; ++k, ++pos) {
  15955. buffer[pos] = buffer[pos - dist];
  15956. }
  15957. }
  15958. };
  15959. return FlateStream;
  15960. })();
  15961. var PredictorStream = (function PredictorStreamClosure() {
  15962. function PredictorStream(str, maybeLength, params) {
  15963. var predictor = this.predictor = params.get('Predictor') || 1;
  15964. if (predictor <= 1) {
  15965. return str; // no prediction
  15966. }
  15967. if (predictor !== 2 && (predictor < 10 || predictor > 15)) {
  15968. error('Unsupported predictor: ' + predictor);
  15969. }
  15970. if (predictor === 2) {
  15971. this.readBlock = this.readBlockTiff;
  15972. } else {
  15973. this.readBlock = this.readBlockPng;
  15974. }
  15975. this.str = str;
  15976. this.dict = str.dict;
  15977. var colors = this.colors = params.get('Colors') || 1;
  15978. var bits = this.bits = params.get('BitsPerComponent') || 8;
  15979. var columns = this.columns = params.get('Columns') || 1;
  15980. this.pixBytes = (colors * bits + 7) >> 3;
  15981. this.rowBytes = (columns * colors * bits + 7) >> 3;
  15982. DecodeStream.call(this, maybeLength);
  15983. return this;
  15984. }
  15985. PredictorStream.prototype = Object.create(DecodeStream.prototype);
  15986. PredictorStream.prototype.readBlockTiff =
  15987. function predictorStreamReadBlockTiff() {
  15988. var rowBytes = this.rowBytes;
  15989. var bufferLength = this.bufferLength;
  15990. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  15991. var bits = this.bits;
  15992. var colors = this.colors;
  15993. var rawBytes = this.str.getBytes(rowBytes);
  15994. this.eof = !rawBytes.length;
  15995. if (this.eof) {
  15996. return;
  15997. }
  15998. var inbuf = 0, outbuf = 0;
  15999. var inbits = 0, outbits = 0;
  16000. var pos = bufferLength;
  16001. var i;
  16002. if (bits === 1) {
  16003. for (i = 0; i < rowBytes; ++i) {
  16004. var c = rawBytes[i];
  16005. inbuf = (inbuf << 8) | c;
  16006. // bitwise addition is exclusive or
  16007. // first shift inbuf and then add
  16008. buffer[pos++] = (c ^ (inbuf >> colors)) & 0xFF;
  16009. // truncate inbuf (assumes colors < 16)
  16010. inbuf &= 0xFFFF;
  16011. }
  16012. } else if (bits === 8) {
  16013. for (i = 0; i < colors; ++i) {
  16014. buffer[pos++] = rawBytes[i];
  16015. }
  16016. for (; i < rowBytes; ++i) {
  16017. buffer[pos] = buffer[pos - colors] + rawBytes[i];
  16018. pos++;
  16019. }
  16020. } else {
  16021. var compArray = new Uint8Array(colors + 1);
  16022. var bitMask = (1 << bits) - 1;
  16023. var j = 0, k = bufferLength;
  16024. var columns = this.columns;
  16025. for (i = 0; i < columns; ++i) {
  16026. for (var kk = 0; kk < colors; ++kk) {
  16027. if (inbits < bits) {
  16028. inbuf = (inbuf << 8) | (rawBytes[j++] & 0xFF);
  16029. inbits += 8;
  16030. }
  16031. compArray[kk] = (compArray[kk] +
  16032. (inbuf >> (inbits - bits))) & bitMask;
  16033. inbits -= bits;
  16034. outbuf = (outbuf << bits) | compArray[kk];
  16035. outbits += bits;
  16036. if (outbits >= 8) {
  16037. buffer[k++] = (outbuf >> (outbits - 8)) & 0xFF;
  16038. outbits -= 8;
  16039. }
  16040. }
  16041. }
  16042. if (outbits > 0) {
  16043. buffer[k++] = (outbuf << (8 - outbits)) +
  16044. (inbuf & ((1 << (8 - outbits)) - 1));
  16045. }
  16046. }
  16047. this.bufferLength += rowBytes;
  16048. };
  16049. PredictorStream.prototype.readBlockPng =
  16050. function predictorStreamReadBlockPng() {
  16051. var rowBytes = this.rowBytes;
  16052. var pixBytes = this.pixBytes;
  16053. var predictor = this.str.getByte();
  16054. var rawBytes = this.str.getBytes(rowBytes);
  16055. this.eof = !rawBytes.length;
  16056. if (this.eof) {
  16057. return;
  16058. }
  16059. var bufferLength = this.bufferLength;
  16060. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  16061. var prevRow = buffer.subarray(bufferLength - rowBytes, bufferLength);
  16062. if (prevRow.length === 0) {
  16063. prevRow = new Uint8Array(rowBytes);
  16064. }
  16065. var i, j = bufferLength, up, c;
  16066. switch (predictor) {
  16067. case 0:
  16068. for (i = 0; i < rowBytes; ++i) {
  16069. buffer[j++] = rawBytes[i];
  16070. }
  16071. break;
  16072. case 1:
  16073. for (i = 0; i < pixBytes; ++i) {
  16074. buffer[j++] = rawBytes[i];
  16075. }
  16076. for (; i < rowBytes; ++i) {
  16077. buffer[j] = (buffer[j - pixBytes] + rawBytes[i]) & 0xFF;
  16078. j++;
  16079. }
  16080. break;
  16081. case 2:
  16082. for (i = 0; i < rowBytes; ++i) {
  16083. buffer[j++] = (prevRow[i] + rawBytes[i]) & 0xFF;
  16084. }
  16085. break;
  16086. case 3:
  16087. for (i = 0; i < pixBytes; ++i) {
  16088. buffer[j++] = (prevRow[i] >> 1) + rawBytes[i];
  16089. }
  16090. for (; i < rowBytes; ++i) {
  16091. buffer[j] = (((prevRow[i] + buffer[j - pixBytes]) >> 1) +
  16092. rawBytes[i]) & 0xFF;
  16093. j++;
  16094. }
  16095. break;
  16096. case 4:
  16097. // we need to save the up left pixels values. the simplest way
  16098. // is to create a new buffer
  16099. for (i = 0; i < pixBytes; ++i) {
  16100. up = prevRow[i];
  16101. c = rawBytes[i];
  16102. buffer[j++] = up + c;
  16103. }
  16104. for (; i < rowBytes; ++i) {
  16105. up = prevRow[i];
  16106. var upLeft = prevRow[i - pixBytes];
  16107. var left = buffer[j - pixBytes];
  16108. var p = left + up - upLeft;
  16109. var pa = p - left;
  16110. if (pa < 0) {
  16111. pa = -pa;
  16112. }
  16113. var pb = p - up;
  16114. if (pb < 0) {
  16115. pb = -pb;
  16116. }
  16117. var pc = p - upLeft;
  16118. if (pc < 0) {
  16119. pc = -pc;
  16120. }
  16121. c = rawBytes[i];
  16122. if (pa <= pb && pa <= pc) {
  16123. buffer[j++] = left + c;
  16124. } else if (pb <= pc) {
  16125. buffer[j++] = up + c;
  16126. } else {
  16127. buffer[j++] = upLeft + c;
  16128. }
  16129. }
  16130. break;
  16131. default:
  16132. error('Unsupported predictor: ' + predictor);
  16133. }
  16134. this.bufferLength += rowBytes;
  16135. };
  16136. return PredictorStream;
  16137. })();
  16138. /**
  16139. * Depending on the type of JPEG a JpegStream is handled in different ways. For
  16140. * JPEG's that are supported natively such as DeviceGray and DeviceRGB the image
  16141. * data is stored and then loaded by the browser. For unsupported JPEG's we use
  16142. * a library to decode these images and the stream behaves like all the other
  16143. * DecodeStreams.
  16144. */
  16145. var JpegStream = (function JpegStreamClosure() {
  16146. function JpegStream(stream, maybeLength, dict, xref) {
  16147. // Some images may contain 'junk' before the SOI (start-of-image) marker.
  16148. // Note: this seems to mainly affect inline images.
  16149. var ch;
  16150. while ((ch = stream.getByte()) !== -1) {
  16151. if (ch === 0xFF) { // Find the first byte of the SOI marker (0xFFD8).
  16152. stream.skip(-1); // Reset the stream position to the SOI.
  16153. break;
  16154. }
  16155. }
  16156. this.stream = stream;
  16157. this.maybeLength = maybeLength;
  16158. this.dict = dict;
  16159. DecodeStream.call(this, maybeLength);
  16160. }
  16161. JpegStream.prototype = Object.create(DecodeStream.prototype);
  16162. Object.defineProperty(JpegStream.prototype, 'bytes', {
  16163. get: function JpegStream_bytes() {
  16164. // If this.maybeLength is null, we'll get the entire stream.
  16165. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  16166. },
  16167. configurable: true
  16168. });
  16169. JpegStream.prototype.ensureBuffer = function JpegStream_ensureBuffer(req) {
  16170. if (this.bufferLength) {
  16171. return;
  16172. }
  16173. try {
  16174. var jpegImage = new JpegImage();
  16175. // checking if values needs to be transformed before conversion
  16176. if (this.forceRGB && this.dict && isArray(this.dict.get('Decode'))) {
  16177. var decodeArr = this.dict.get('Decode');
  16178. var bitsPerComponent = this.dict.get('BitsPerComponent') || 8;
  16179. var decodeArrLength = decodeArr.length;
  16180. var transform = new Int32Array(decodeArrLength);
  16181. var transformNeeded = false;
  16182. var maxValue = (1 << bitsPerComponent) - 1;
  16183. for (var i = 0; i < decodeArrLength; i += 2) {
  16184. transform[i] = ((decodeArr[i + 1] - decodeArr[i]) * 256) | 0;
  16185. transform[i + 1] = (decodeArr[i] * maxValue) | 0;
  16186. if (transform[i] !== 256 || transform[i + 1] !== 0) {
  16187. transformNeeded = true;
  16188. }
  16189. }
  16190. if (transformNeeded) {
  16191. jpegImage.decodeTransform = transform;
  16192. }
  16193. }
  16194. jpegImage.parse(this.bytes);
  16195. var data = jpegImage.getData(this.drawWidth, this.drawHeight,
  16196. this.forceRGB);
  16197. this.buffer = data;
  16198. this.bufferLength = data.length;
  16199. this.eof = true;
  16200. } catch (e) {
  16201. error('JPEG error: ' + e);
  16202. }
  16203. };
  16204. JpegStream.prototype.getBytes = function JpegStream_getBytes(length) {
  16205. this.ensureBuffer();
  16206. return this.buffer;
  16207. };
  16208. JpegStream.prototype.getIR = function JpegStream_getIR() {
  16209. return PDFJS.createObjectURL(this.bytes, 'image/jpeg');
  16210. };
  16211. /**
  16212. * Checks if the image can be decoded and displayed by the browser without any
  16213. * further processing such as color space conversions.
  16214. */
  16215. JpegStream.prototype.isNativelySupported =
  16216. function JpegStream_isNativelySupported(xref, res) {
  16217. var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
  16218. return (cs.name === 'DeviceGray' || cs.name === 'DeviceRGB') &&
  16219. cs.isDefaultDecode(this.dict.get('Decode', 'D'));
  16220. };
  16221. /**
  16222. * Checks if the image can be decoded by the browser.
  16223. */
  16224. JpegStream.prototype.isNativelyDecodable =
  16225. function JpegStream_isNativelyDecodable(xref, res) {
  16226. var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
  16227. return (cs.numComps === 1 || cs.numComps === 3) &&
  16228. cs.isDefaultDecode(this.dict.get('Decode', 'D'));
  16229. };
  16230. return JpegStream;
  16231. })();
  16232. /**
  16233. * For JPEG 2000's we use a library to decode these images and
  16234. * the stream behaves like all the other DecodeStreams.
  16235. */
  16236. var JpxStream = (function JpxStreamClosure() {
  16237. function JpxStream(stream, maybeLength, dict) {
  16238. this.stream = stream;
  16239. this.maybeLength = maybeLength;
  16240. this.dict = dict;
  16241. DecodeStream.call(this, maybeLength);
  16242. }
  16243. JpxStream.prototype = Object.create(DecodeStream.prototype);
  16244. Object.defineProperty(JpxStream.prototype, 'bytes', {
  16245. get: function JpxStream_bytes() {
  16246. // If this.maybeLength is null, we'll get the entire stream.
  16247. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  16248. },
  16249. configurable: true
  16250. });
  16251. JpxStream.prototype.ensureBuffer = function JpxStream_ensureBuffer(req) {
  16252. if (this.bufferLength) {
  16253. return;
  16254. }
  16255. var jpxImage = new JpxImage();
  16256. jpxImage.parse(this.bytes);
  16257. var width = jpxImage.width;
  16258. var height = jpxImage.height;
  16259. var componentsCount = jpxImage.componentsCount;
  16260. var tileCount = jpxImage.tiles.length;
  16261. if (tileCount === 1) {
  16262. this.buffer = jpxImage.tiles[0].items;
  16263. } else {
  16264. var data = new Uint8Array(width * height * componentsCount);
  16265. for (var k = 0; k < tileCount; k++) {
  16266. var tileComponents = jpxImage.tiles[k];
  16267. var tileWidth = tileComponents.width;
  16268. var tileHeight = tileComponents.height;
  16269. var tileLeft = tileComponents.left;
  16270. var tileTop = tileComponents.top;
  16271. var src = tileComponents.items;
  16272. var srcPosition = 0;
  16273. var dataPosition = (width * tileTop + tileLeft) * componentsCount;
  16274. var imgRowSize = width * componentsCount;
  16275. var tileRowSize = tileWidth * componentsCount;
  16276. for (var j = 0; j < tileHeight; j++) {
  16277. var rowBytes = src.subarray(srcPosition, srcPosition + tileRowSize);
  16278. data.set(rowBytes, dataPosition);
  16279. srcPosition += tileRowSize;
  16280. dataPosition += imgRowSize;
  16281. }
  16282. }
  16283. this.buffer = data;
  16284. }
  16285. this.bufferLength = this.buffer.length;
  16286. this.eof = true;
  16287. };
  16288. return JpxStream;
  16289. })();
  16290. /**
  16291. * For JBIG2's we use a library to decode these images and
  16292. * the stream behaves like all the other DecodeStreams.
  16293. */
  16294. var Jbig2Stream = (function Jbig2StreamClosure() {
  16295. function Jbig2Stream(stream, maybeLength, dict) {
  16296. this.stream = stream;
  16297. this.maybeLength = maybeLength;
  16298. this.dict = dict;
  16299. DecodeStream.call(this, maybeLength);
  16300. }
  16301. Jbig2Stream.prototype = Object.create(DecodeStream.prototype);
  16302. Object.defineProperty(Jbig2Stream.prototype, 'bytes', {
  16303. get: function Jbig2Stream_bytes() {
  16304. // If this.maybeLength is null, we'll get the entire stream.
  16305. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  16306. },
  16307. configurable: true
  16308. });
  16309. Jbig2Stream.prototype.ensureBuffer = function Jbig2Stream_ensureBuffer(req) {
  16310. if (this.bufferLength) {
  16311. return;
  16312. }
  16313. var jbig2Image = new Jbig2Image();
  16314. var chunks = [], xref = this.dict.xref;
  16315. var decodeParams = xref.fetchIfRef(this.dict.get('DecodeParms'));
  16316. // According to the PDF specification, DecodeParms can be either
  16317. // a dictionary, or an array whose elements are dictionaries.
  16318. if (isArray(decodeParams)) {
  16319. if (decodeParams.length > 1) {
  16320. warn('JBIG2 - \'DecodeParms\' array with multiple elements ' +
  16321. 'not supported.');
  16322. }
  16323. decodeParams = xref.fetchIfRef(decodeParams[0]);
  16324. }
  16325. if (decodeParams && decodeParams.has('JBIG2Globals')) {
  16326. var globalsStream = decodeParams.get('JBIG2Globals');
  16327. var globals = globalsStream.getBytes();
  16328. chunks.push({data: globals, start: 0, end: globals.length});
  16329. }
  16330. chunks.push({data: this.bytes, start: 0, end: this.bytes.length});
  16331. var data = jbig2Image.parseChunks(chunks);
  16332. var dataLength = data.length;
  16333. // JBIG2 had black as 1 and white as 0, inverting the colors
  16334. for (var i = 0; i < dataLength; i++) {
  16335. data[i] ^= 0xFF;
  16336. }
  16337. this.buffer = data;
  16338. this.bufferLength = dataLength;
  16339. this.eof = true;
  16340. };
  16341. return Jbig2Stream;
  16342. })();
  16343. var DecryptStream = (function DecryptStreamClosure() {
  16344. function DecryptStream(str, maybeLength, decrypt) {
  16345. this.str = str;
  16346. this.dict = str.dict;
  16347. this.decrypt = decrypt;
  16348. this.nextChunk = null;
  16349. this.initialized = false;
  16350. DecodeStream.call(this, maybeLength);
  16351. }
  16352. var chunkSize = 512;
  16353. DecryptStream.prototype = Object.create(DecodeStream.prototype);
  16354. DecryptStream.prototype.readBlock = function DecryptStream_readBlock() {
  16355. var chunk;
  16356. if (this.initialized) {
  16357. chunk = this.nextChunk;
  16358. } else {
  16359. chunk = this.str.getBytes(chunkSize);
  16360. this.initialized = true;
  16361. }
  16362. if (!chunk || chunk.length === 0) {
  16363. this.eof = true;
  16364. return;
  16365. }
  16366. this.nextChunk = this.str.getBytes(chunkSize);
  16367. var hasMoreData = this.nextChunk && this.nextChunk.length > 0;
  16368. var decrypt = this.decrypt;
  16369. chunk = decrypt(chunk, !hasMoreData);
  16370. var bufferLength = this.bufferLength;
  16371. var i, n = chunk.length;
  16372. var buffer = this.ensureBuffer(bufferLength + n);
  16373. for (i = 0; i < n; i++) {
  16374. buffer[bufferLength++] = chunk[i];
  16375. }
  16376. this.bufferLength = bufferLength;
  16377. };
  16378. return DecryptStream;
  16379. })();
  16380. var Ascii85Stream = (function Ascii85StreamClosure() {
  16381. function Ascii85Stream(str, maybeLength) {
  16382. this.str = str;
  16383. this.dict = str.dict;
  16384. this.input = new Uint8Array(5);
  16385. // Most streams increase in size when decoded, but Ascii85 streams
  16386. // typically shrink by ~20%.
  16387. if (maybeLength) {
  16388. maybeLength = 0.8 * maybeLength;
  16389. }
  16390. DecodeStream.call(this, maybeLength);
  16391. }
  16392. Ascii85Stream.prototype = Object.create(DecodeStream.prototype);
  16393. Ascii85Stream.prototype.readBlock = function Ascii85Stream_readBlock() {
  16394. var TILDA_CHAR = 0x7E; // '~'
  16395. var Z_LOWER_CHAR = 0x7A; // 'z'
  16396. var EOF = -1;
  16397. var str = this.str;
  16398. var c = str.getByte();
  16399. while (Lexer.isSpace(c)) {
  16400. c = str.getByte();
  16401. }
  16402. if (c === EOF || c === TILDA_CHAR) {
  16403. this.eof = true;
  16404. return;
  16405. }
  16406. var bufferLength = this.bufferLength, buffer;
  16407. var i;
  16408. // special code for z
  16409. if (c === Z_LOWER_CHAR) {
  16410. buffer = this.ensureBuffer(bufferLength + 4);
  16411. for (i = 0; i < 4; ++i) {
  16412. buffer[bufferLength + i] = 0;
  16413. }
  16414. this.bufferLength += 4;
  16415. } else {
  16416. var input = this.input;
  16417. input[0] = c;
  16418. for (i = 1; i < 5; ++i) {
  16419. c = str.getByte();
  16420. while (Lexer.isSpace(c)) {
  16421. c = str.getByte();
  16422. }
  16423. input[i] = c;
  16424. if (c === EOF || c === TILDA_CHAR) {
  16425. break;
  16426. }
  16427. }
  16428. buffer = this.ensureBuffer(bufferLength + i - 1);
  16429. this.bufferLength += i - 1;
  16430. // partial ending;
  16431. if (i < 5) {
  16432. for (; i < 5; ++i) {
  16433. input[i] = 0x21 + 84;
  16434. }
  16435. this.eof = true;
  16436. }
  16437. var t = 0;
  16438. for (i = 0; i < 5; ++i) {
  16439. t = t * 85 + (input[i] - 0x21);
  16440. }
  16441. for (i = 3; i >= 0; --i) {
  16442. buffer[bufferLength + i] = t & 0xFF;
  16443. t >>= 8;
  16444. }
  16445. }
  16446. };
  16447. return Ascii85Stream;
  16448. })();
  16449. var AsciiHexStream = (function AsciiHexStreamClosure() {
  16450. function AsciiHexStream(str, maybeLength) {
  16451. this.str = str;
  16452. this.dict = str.dict;
  16453. this.firstDigit = -1;
  16454. // Most streams increase in size when decoded, but AsciiHex streams shrink
  16455. // by 50%.
  16456. if (maybeLength) {
  16457. maybeLength = 0.5 * maybeLength;
  16458. }
  16459. DecodeStream.call(this, maybeLength);
  16460. }
  16461. AsciiHexStream.prototype = Object.create(DecodeStream.prototype);
  16462. AsciiHexStream.prototype.readBlock = function AsciiHexStream_readBlock() {
  16463. var UPSTREAM_BLOCK_SIZE = 8000;
  16464. var bytes = this.str.getBytes(UPSTREAM_BLOCK_SIZE);
  16465. if (!bytes.length) {
  16466. this.eof = true;
  16467. return;
  16468. }
  16469. var maxDecodeLength = (bytes.length + 1) >> 1;
  16470. var buffer = this.ensureBuffer(this.bufferLength + maxDecodeLength);
  16471. var bufferLength = this.bufferLength;
  16472. var firstDigit = this.firstDigit;
  16473. for (var i = 0, ii = bytes.length; i < ii; i++) {
  16474. var ch = bytes[i], digit;
  16475. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  16476. digit = ch & 0x0F;
  16477. } else if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  16478. // 'A'-'Z', 'a'-'z'
  16479. digit = (ch & 0x0F) + 9;
  16480. } else if (ch === 0x3E) { // '>'
  16481. this.eof = true;
  16482. break;
  16483. } else { // probably whitespace
  16484. continue; // ignoring
  16485. }
  16486. if (firstDigit < 0) {
  16487. firstDigit = digit;
  16488. } else {
  16489. buffer[bufferLength++] = (firstDigit << 4) | digit;
  16490. firstDigit = -1;
  16491. }
  16492. }
  16493. if (firstDigit >= 0 && this.eof) {
  16494. // incomplete byte
  16495. buffer[bufferLength++] = (firstDigit << 4);
  16496. firstDigit = -1;
  16497. }
  16498. this.firstDigit = firstDigit;
  16499. this.bufferLength = bufferLength;
  16500. };
  16501. return AsciiHexStream;
  16502. })();
  16503. var RunLengthStream = (function RunLengthStreamClosure() {
  16504. function RunLengthStream(str, maybeLength) {
  16505. this.str = str;
  16506. this.dict = str.dict;
  16507. DecodeStream.call(this, maybeLength);
  16508. }
  16509. RunLengthStream.prototype = Object.create(DecodeStream.prototype);
  16510. RunLengthStream.prototype.readBlock = function RunLengthStream_readBlock() {
  16511. // The repeatHeader has following format. The first byte defines type of run
  16512. // and amount of bytes to repeat/copy: n = 0 through 127 - copy next n bytes
  16513. // (in addition to the second byte from the header), n = 129 through 255 -
  16514. // duplicate the second byte from the header (257 - n) times, n = 128 - end.
  16515. var repeatHeader = this.str.getBytes(2);
  16516. if (!repeatHeader || repeatHeader.length < 2 || repeatHeader[0] === 128) {
  16517. this.eof = true;
  16518. return;
  16519. }
  16520. var buffer;
  16521. var bufferLength = this.bufferLength;
  16522. var n = repeatHeader[0];
  16523. if (n < 128) {
  16524. // copy n bytes
  16525. buffer = this.ensureBuffer(bufferLength + n + 1);
  16526. buffer[bufferLength++] = repeatHeader[1];
  16527. if (n > 0) {
  16528. var source = this.str.getBytes(n);
  16529. buffer.set(source, bufferLength);
  16530. bufferLength += n;
  16531. }
  16532. } else {
  16533. n = 257 - n;
  16534. var b = repeatHeader[1];
  16535. buffer = this.ensureBuffer(bufferLength + n + 1);
  16536. for (var i = 0; i < n; i++) {
  16537. buffer[bufferLength++] = b;
  16538. }
  16539. }
  16540. this.bufferLength = bufferLength;
  16541. };
  16542. return RunLengthStream;
  16543. })();
  16544. var CCITTFaxStream = (function CCITTFaxStreamClosure() {
  16545. var ccittEOL = -2;
  16546. var twoDimPass = 0;
  16547. var twoDimHoriz = 1;
  16548. var twoDimVert0 = 2;
  16549. var twoDimVertR1 = 3;
  16550. var twoDimVertL1 = 4;
  16551. var twoDimVertR2 = 5;
  16552. var twoDimVertL2 = 6;
  16553. var twoDimVertR3 = 7;
  16554. var twoDimVertL3 = 8;
  16555. var twoDimTable = [
  16556. [-1, -1], [-1, -1], // 000000x
  16557. [7, twoDimVertL3], // 0000010
  16558. [7, twoDimVertR3], // 0000011
  16559. [6, twoDimVertL2], [6, twoDimVertL2], // 000010x
  16560. [6, twoDimVertR2], [6, twoDimVertR2], // 000011x
  16561. [4, twoDimPass], [4, twoDimPass], // 0001xxx
  16562. [4, twoDimPass], [4, twoDimPass],
  16563. [4, twoDimPass], [4, twoDimPass],
  16564. [4, twoDimPass], [4, twoDimPass],
  16565. [3, twoDimHoriz], [3, twoDimHoriz], // 001xxxx
  16566. [3, twoDimHoriz], [3, twoDimHoriz],
  16567. [3, twoDimHoriz], [3, twoDimHoriz],
  16568. [3, twoDimHoriz], [3, twoDimHoriz],
  16569. [3, twoDimHoriz], [3, twoDimHoriz],
  16570. [3, twoDimHoriz], [3, twoDimHoriz],
  16571. [3, twoDimHoriz], [3, twoDimHoriz],
  16572. [3, twoDimHoriz], [3, twoDimHoriz],
  16573. [3, twoDimVertL1], [3, twoDimVertL1], // 010xxxx
  16574. [3, twoDimVertL1], [3, twoDimVertL1],
  16575. [3, twoDimVertL1], [3, twoDimVertL1],
  16576. [3, twoDimVertL1], [3, twoDimVertL1],
  16577. [3, twoDimVertL1], [3, twoDimVertL1],
  16578. [3, twoDimVertL1], [3, twoDimVertL1],
  16579. [3, twoDimVertL1], [3, twoDimVertL1],
  16580. [3, twoDimVertL1], [3, twoDimVertL1],
  16581. [3, twoDimVertR1], [3, twoDimVertR1], // 011xxxx
  16582. [3, twoDimVertR1], [3, twoDimVertR1],
  16583. [3, twoDimVertR1], [3, twoDimVertR1],
  16584. [3, twoDimVertR1], [3, twoDimVertR1],
  16585. [3, twoDimVertR1], [3, twoDimVertR1],
  16586. [3, twoDimVertR1], [3, twoDimVertR1],
  16587. [3, twoDimVertR1], [3, twoDimVertR1],
  16588. [3, twoDimVertR1], [3, twoDimVertR1],
  16589. [1, twoDimVert0], [1, twoDimVert0], // 1xxxxxx
  16590. [1, twoDimVert0], [1, twoDimVert0],
  16591. [1, twoDimVert0], [1, twoDimVert0],
  16592. [1, twoDimVert0], [1, twoDimVert0],
  16593. [1, twoDimVert0], [1, twoDimVert0],
  16594. [1, twoDimVert0], [1, twoDimVert0],
  16595. [1, twoDimVert0], [1, twoDimVert0],
  16596. [1, twoDimVert0], [1, twoDimVert0],
  16597. [1, twoDimVert0], [1, twoDimVert0],
  16598. [1, twoDimVert0], [1, twoDimVert0],
  16599. [1, twoDimVert0], [1, twoDimVert0],
  16600. [1, twoDimVert0], [1, twoDimVert0],
  16601. [1, twoDimVert0], [1, twoDimVert0],
  16602. [1, twoDimVert0], [1, twoDimVert0],
  16603. [1, twoDimVert0], [1, twoDimVert0],
  16604. [1, twoDimVert0], [1, twoDimVert0],
  16605. [1, twoDimVert0], [1, twoDimVert0],
  16606. [1, twoDimVert0], [1, twoDimVert0],
  16607. [1, twoDimVert0], [1, twoDimVert0],
  16608. [1, twoDimVert0], [1, twoDimVert0],
  16609. [1, twoDimVert0], [1, twoDimVert0],
  16610. [1, twoDimVert0], [1, twoDimVert0],
  16611. [1, twoDimVert0], [1, twoDimVert0],
  16612. [1, twoDimVert0], [1, twoDimVert0],
  16613. [1, twoDimVert0], [1, twoDimVert0],
  16614. [1, twoDimVert0], [1, twoDimVert0],
  16615. [1, twoDimVert0], [1, twoDimVert0],
  16616. [1, twoDimVert0], [1, twoDimVert0],
  16617. [1, twoDimVert0], [1, twoDimVert0],
  16618. [1, twoDimVert0], [1, twoDimVert0],
  16619. [1, twoDimVert0], [1, twoDimVert0],
  16620. [1, twoDimVert0], [1, twoDimVert0]
  16621. ];
  16622. var whiteTable1 = [
  16623. [-1, -1], // 00000
  16624. [12, ccittEOL], // 00001
  16625. [-1, -1], [-1, -1], // 0001x
  16626. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 001xx
  16627. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 010xx
  16628. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 011xx
  16629. [11, 1792], [11, 1792], // 1000x
  16630. [12, 1984], // 10010
  16631. [12, 2048], // 10011
  16632. [12, 2112], // 10100
  16633. [12, 2176], // 10101
  16634. [12, 2240], // 10110
  16635. [12, 2304], // 10111
  16636. [11, 1856], [11, 1856], // 1100x
  16637. [11, 1920], [11, 1920], // 1101x
  16638. [12, 2368], // 11100
  16639. [12, 2432], // 11101
  16640. [12, 2496], // 11110
  16641. [12, 2560] // 11111
  16642. ];
  16643. var whiteTable2 = [
  16644. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000000xx
  16645. [8, 29], [8, 29], // 00000010x
  16646. [8, 30], [8, 30], // 00000011x
  16647. [8, 45], [8, 45], // 00000100x
  16648. [8, 46], [8, 46], // 00000101x
  16649. [7, 22], [7, 22], [7, 22], [7, 22], // 0000011xx
  16650. [7, 23], [7, 23], [7, 23], [7, 23], // 0000100xx
  16651. [8, 47], [8, 47], // 00001010x
  16652. [8, 48], [8, 48], // 00001011x
  16653. [6, 13], [6, 13], [6, 13], [6, 13], // 000011xxx
  16654. [6, 13], [6, 13], [6, 13], [6, 13],
  16655. [7, 20], [7, 20], [7, 20], [7, 20], // 0001000xx
  16656. [8, 33], [8, 33], // 00010010x
  16657. [8, 34], [8, 34], // 00010011x
  16658. [8, 35], [8, 35], // 00010100x
  16659. [8, 36], [8, 36], // 00010101x
  16660. [8, 37], [8, 37], // 00010110x
  16661. [8, 38], [8, 38], // 00010111x
  16662. [7, 19], [7, 19], [7, 19], [7, 19], // 0001100xx
  16663. [8, 31], [8, 31], // 00011010x
  16664. [8, 32], [8, 32], // 00011011x
  16665. [6, 1], [6, 1], [6, 1], [6, 1], // 000111xxx
  16666. [6, 1], [6, 1], [6, 1], [6, 1],
  16667. [6, 12], [6, 12], [6, 12], [6, 12], // 001000xxx
  16668. [6, 12], [6, 12], [6, 12], [6, 12],
  16669. [8, 53], [8, 53], // 00100100x
  16670. [8, 54], [8, 54], // 00100101x
  16671. [7, 26], [7, 26], [7, 26], [7, 26], // 0010011xx
  16672. [8, 39], [8, 39], // 00101000x
  16673. [8, 40], [8, 40], // 00101001x
  16674. [8, 41], [8, 41], // 00101010x
  16675. [8, 42], [8, 42], // 00101011x
  16676. [8, 43], [8, 43], // 00101100x
  16677. [8, 44], [8, 44], // 00101101x
  16678. [7, 21], [7, 21], [7, 21], [7, 21], // 0010111xx
  16679. [7, 28], [7, 28], [7, 28], [7, 28], // 0011000xx
  16680. [8, 61], [8, 61], // 00110010x
  16681. [8, 62], [8, 62], // 00110011x
  16682. [8, 63], [8, 63], // 00110100x
  16683. [8, 0], [8, 0], // 00110101x
  16684. [8, 320], [8, 320], // 00110110x
  16685. [8, 384], [8, 384], // 00110111x
  16686. [5, 10], [5, 10], [5, 10], [5, 10], // 00111xxxx
  16687. [5, 10], [5, 10], [5, 10], [5, 10],
  16688. [5, 10], [5, 10], [5, 10], [5, 10],
  16689. [5, 10], [5, 10], [5, 10], [5, 10],
  16690. [5, 11], [5, 11], [5, 11], [5, 11], // 01000xxxx
  16691. [5, 11], [5, 11], [5, 11], [5, 11],
  16692. [5, 11], [5, 11], [5, 11], [5, 11],
  16693. [5, 11], [5, 11], [5, 11], [5, 11],
  16694. [7, 27], [7, 27], [7, 27], [7, 27], // 0100100xx
  16695. [8, 59], [8, 59], // 01001010x
  16696. [8, 60], [8, 60], // 01001011x
  16697. [9, 1472], // 010011000
  16698. [9, 1536], // 010011001
  16699. [9, 1600], // 010011010
  16700. [9, 1728], // 010011011
  16701. [7, 18], [7, 18], [7, 18], [7, 18], // 0100111xx
  16702. [7, 24], [7, 24], [7, 24], [7, 24], // 0101000xx
  16703. [8, 49], [8, 49], // 01010010x
  16704. [8, 50], [8, 50], // 01010011x
  16705. [8, 51], [8, 51], // 01010100x
  16706. [8, 52], [8, 52], // 01010101x
  16707. [7, 25], [7, 25], [7, 25], [7, 25], // 0101011xx
  16708. [8, 55], [8, 55], // 01011000x
  16709. [8, 56], [8, 56], // 01011001x
  16710. [8, 57], [8, 57], // 01011010x
  16711. [8, 58], [8, 58], // 01011011x
  16712. [6, 192], [6, 192], [6, 192], [6, 192], // 010111xxx
  16713. [6, 192], [6, 192], [6, 192], [6, 192],
  16714. [6, 1664], [6, 1664], [6, 1664], [6, 1664], // 011000xxx
  16715. [6, 1664], [6, 1664], [6, 1664], [6, 1664],
  16716. [8, 448], [8, 448], // 01100100x
  16717. [8, 512], [8, 512], // 01100101x
  16718. [9, 704], // 011001100
  16719. [9, 768], // 011001101
  16720. [8, 640], [8, 640], // 01100111x
  16721. [8, 576], [8, 576], // 01101000x
  16722. [9, 832], // 011010010
  16723. [9, 896], // 011010011
  16724. [9, 960], // 011010100
  16725. [9, 1024], // 011010101
  16726. [9, 1088], // 011010110
  16727. [9, 1152], // 011010111
  16728. [9, 1216], // 011011000
  16729. [9, 1280], // 011011001
  16730. [9, 1344], // 011011010
  16731. [9, 1408], // 011011011
  16732. [7, 256], [7, 256], [7, 256], [7, 256], // 0110111xx
  16733. [4, 2], [4, 2], [4, 2], [4, 2], // 0111xxxxx
  16734. [4, 2], [4, 2], [4, 2], [4, 2],
  16735. [4, 2], [4, 2], [4, 2], [4, 2],
  16736. [4, 2], [4, 2], [4, 2], [4, 2],
  16737. [4, 2], [4, 2], [4, 2], [4, 2],
  16738. [4, 2], [4, 2], [4, 2], [4, 2],
  16739. [4, 2], [4, 2], [4, 2], [4, 2],
  16740. [4, 2], [4, 2], [4, 2], [4, 2],
  16741. [4, 3], [4, 3], [4, 3], [4, 3], // 1000xxxxx
  16742. [4, 3], [4, 3], [4, 3], [4, 3],
  16743. [4, 3], [4, 3], [4, 3], [4, 3],
  16744. [4, 3], [4, 3], [4, 3], [4, 3],
  16745. [4, 3], [4, 3], [4, 3], [4, 3],
  16746. [4, 3], [4, 3], [4, 3], [4, 3],
  16747. [4, 3], [4, 3], [4, 3], [4, 3],
  16748. [4, 3], [4, 3], [4, 3], [4, 3],
  16749. [5, 128], [5, 128], [5, 128], [5, 128], // 10010xxxx
  16750. [5, 128], [5, 128], [5, 128], [5, 128],
  16751. [5, 128], [5, 128], [5, 128], [5, 128],
  16752. [5, 128], [5, 128], [5, 128], [5, 128],
  16753. [5, 8], [5, 8], [5, 8], [5, 8], // 10011xxxx
  16754. [5, 8], [5, 8], [5, 8], [5, 8],
  16755. [5, 8], [5, 8], [5, 8], [5, 8],
  16756. [5, 8], [5, 8], [5, 8], [5, 8],
  16757. [5, 9], [5, 9], [5, 9], [5, 9], // 10100xxxx
  16758. [5, 9], [5, 9], [5, 9], [5, 9],
  16759. [5, 9], [5, 9], [5, 9], [5, 9],
  16760. [5, 9], [5, 9], [5, 9], [5, 9],
  16761. [6, 16], [6, 16], [6, 16], [6, 16], // 101010xxx
  16762. [6, 16], [6, 16], [6, 16], [6, 16],
  16763. [6, 17], [6, 17], [6, 17], [6, 17], // 101011xxx
  16764. [6, 17], [6, 17], [6, 17], [6, 17],
  16765. [4, 4], [4, 4], [4, 4], [4, 4], // 1011xxxxx
  16766. [4, 4], [4, 4], [4, 4], [4, 4],
  16767. [4, 4], [4, 4], [4, 4], [4, 4],
  16768. [4, 4], [4, 4], [4, 4], [4, 4],
  16769. [4, 4], [4, 4], [4, 4], [4, 4],
  16770. [4, 4], [4, 4], [4, 4], [4, 4],
  16771. [4, 4], [4, 4], [4, 4], [4, 4],
  16772. [4, 4], [4, 4], [4, 4], [4, 4],
  16773. [4, 5], [4, 5], [4, 5], [4, 5], // 1100xxxxx
  16774. [4, 5], [4, 5], [4, 5], [4, 5],
  16775. [4, 5], [4, 5], [4, 5], [4, 5],
  16776. [4, 5], [4, 5], [4, 5], [4, 5],
  16777. [4, 5], [4, 5], [4, 5], [4, 5],
  16778. [4, 5], [4, 5], [4, 5], [4, 5],
  16779. [4, 5], [4, 5], [4, 5], [4, 5],
  16780. [4, 5], [4, 5], [4, 5], [4, 5],
  16781. [6, 14], [6, 14], [6, 14], [6, 14], // 110100xxx
  16782. [6, 14], [6, 14], [6, 14], [6, 14],
  16783. [6, 15], [6, 15], [6, 15], [6, 15], // 110101xxx
  16784. [6, 15], [6, 15], [6, 15], [6, 15],
  16785. [5, 64], [5, 64], [5, 64], [5, 64], // 11011xxxx
  16786. [5, 64], [5, 64], [5, 64], [5, 64],
  16787. [5, 64], [5, 64], [5, 64], [5, 64],
  16788. [5, 64], [5, 64], [5, 64], [5, 64],
  16789. [4, 6], [4, 6], [4, 6], [4, 6], // 1110xxxxx
  16790. [4, 6], [4, 6], [4, 6], [4, 6],
  16791. [4, 6], [4, 6], [4, 6], [4, 6],
  16792. [4, 6], [4, 6], [4, 6], [4, 6],
  16793. [4, 6], [4, 6], [4, 6], [4, 6],
  16794. [4, 6], [4, 6], [4, 6], [4, 6],
  16795. [4, 6], [4, 6], [4, 6], [4, 6],
  16796. [4, 6], [4, 6], [4, 6], [4, 6],
  16797. [4, 7], [4, 7], [4, 7], [4, 7], // 1111xxxxx
  16798. [4, 7], [4, 7], [4, 7], [4, 7],
  16799. [4, 7], [4, 7], [4, 7], [4, 7],
  16800. [4, 7], [4, 7], [4, 7], [4, 7],
  16801. [4, 7], [4, 7], [4, 7], [4, 7],
  16802. [4, 7], [4, 7], [4, 7], [4, 7],
  16803. [4, 7], [4, 7], [4, 7], [4, 7],
  16804. [4, 7], [4, 7], [4, 7], [4, 7]
  16805. ];
  16806. var blackTable1 = [
  16807. [-1, -1], [-1, -1], // 000000000000x
  16808. [12, ccittEOL], [12, ccittEOL], // 000000000001x
  16809. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000001xx
  16810. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000010xx
  16811. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000011xx
  16812. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000100xx
  16813. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000101xx
  16814. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000110xx
  16815. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000111xx
  16816. [11, 1792], [11, 1792], [11, 1792], [11, 1792], // 00000001000xx
  16817. [12, 1984], [12, 1984], // 000000010010x
  16818. [12, 2048], [12, 2048], // 000000010011x
  16819. [12, 2112], [12, 2112], // 000000010100x
  16820. [12, 2176], [12, 2176], // 000000010101x
  16821. [12, 2240], [12, 2240], // 000000010110x
  16822. [12, 2304], [12, 2304], // 000000010111x
  16823. [11, 1856], [11, 1856], [11, 1856], [11, 1856], // 00000001100xx
  16824. [11, 1920], [11, 1920], [11, 1920], [11, 1920], // 00000001101xx
  16825. [12, 2368], [12, 2368], // 000000011100x
  16826. [12, 2432], [12, 2432], // 000000011101x
  16827. [12, 2496], [12, 2496], // 000000011110x
  16828. [12, 2560], [12, 2560], // 000000011111x
  16829. [10, 18], [10, 18], [10, 18], [10, 18], // 0000001000xxx
  16830. [10, 18], [10, 18], [10, 18], [10, 18],
  16831. [12, 52], [12, 52], // 000000100100x
  16832. [13, 640], // 0000001001010
  16833. [13, 704], // 0000001001011
  16834. [13, 768], // 0000001001100
  16835. [13, 832], // 0000001001101
  16836. [12, 55], [12, 55], // 000000100111x
  16837. [12, 56], [12, 56], // 000000101000x
  16838. [13, 1280], // 0000001010010
  16839. [13, 1344], // 0000001010011
  16840. [13, 1408], // 0000001010100
  16841. [13, 1472], // 0000001010101
  16842. [12, 59], [12, 59], // 000000101011x
  16843. [12, 60], [12, 60], // 000000101100x
  16844. [13, 1536], // 0000001011010
  16845. [13, 1600], // 0000001011011
  16846. [11, 24], [11, 24], [11, 24], [11, 24], // 00000010111xx
  16847. [11, 25], [11, 25], [11, 25], [11, 25], // 00000011000xx
  16848. [13, 1664], // 0000001100100
  16849. [13, 1728], // 0000001100101
  16850. [12, 320], [12, 320], // 000000110011x
  16851. [12, 384], [12, 384], // 000000110100x
  16852. [12, 448], [12, 448], // 000000110101x
  16853. [13, 512], // 0000001101100
  16854. [13, 576], // 0000001101101
  16855. [12, 53], [12, 53], // 000000110111x
  16856. [12, 54], [12, 54], // 000000111000x
  16857. [13, 896], // 0000001110010
  16858. [13, 960], // 0000001110011
  16859. [13, 1024], // 0000001110100
  16860. [13, 1088], // 0000001110101
  16861. [13, 1152], // 0000001110110
  16862. [13, 1216], // 0000001110111
  16863. [10, 64], [10, 64], [10, 64], [10, 64], // 0000001111xxx
  16864. [10, 64], [10, 64], [10, 64], [10, 64]
  16865. ];
  16866. var blackTable2 = [
  16867. [8, 13], [8, 13], [8, 13], [8, 13], // 00000100xxxx
  16868. [8, 13], [8, 13], [8, 13], [8, 13],
  16869. [8, 13], [8, 13], [8, 13], [8, 13],
  16870. [8, 13], [8, 13], [8, 13], [8, 13],
  16871. [11, 23], [11, 23], // 00000101000x
  16872. [12, 50], // 000001010010
  16873. [12, 51], // 000001010011
  16874. [12, 44], // 000001010100
  16875. [12, 45], // 000001010101
  16876. [12, 46], // 000001010110
  16877. [12, 47], // 000001010111
  16878. [12, 57], // 000001011000
  16879. [12, 58], // 000001011001
  16880. [12, 61], // 000001011010
  16881. [12, 256], // 000001011011
  16882. [10, 16], [10, 16], [10, 16], [10, 16], // 0000010111xx
  16883. [10, 17], [10, 17], [10, 17], [10, 17], // 0000011000xx
  16884. [12, 48], // 000001100100
  16885. [12, 49], // 000001100101
  16886. [12, 62], // 000001100110
  16887. [12, 63], // 000001100111
  16888. [12, 30], // 000001101000
  16889. [12, 31], // 000001101001
  16890. [12, 32], // 000001101010
  16891. [12, 33], // 000001101011
  16892. [12, 40], // 000001101100
  16893. [12, 41], // 000001101101
  16894. [11, 22], [11, 22], // 00000110111x
  16895. [8, 14], [8, 14], [8, 14], [8, 14], // 00000111xxxx
  16896. [8, 14], [8, 14], [8, 14], [8, 14],
  16897. [8, 14], [8, 14], [8, 14], [8, 14],
  16898. [8, 14], [8, 14], [8, 14], [8, 14],
  16899. [7, 10], [7, 10], [7, 10], [7, 10], // 0000100xxxxx
  16900. [7, 10], [7, 10], [7, 10], [7, 10],
  16901. [7, 10], [7, 10], [7, 10], [7, 10],
  16902. [7, 10], [7, 10], [7, 10], [7, 10],
  16903. [7, 10], [7, 10], [7, 10], [7, 10],
  16904. [7, 10], [7, 10], [7, 10], [7, 10],
  16905. [7, 10], [7, 10], [7, 10], [7, 10],
  16906. [7, 10], [7, 10], [7, 10], [7, 10],
  16907. [7, 11], [7, 11], [7, 11], [7, 11], // 0000101xxxxx
  16908. [7, 11], [7, 11], [7, 11], [7, 11],
  16909. [7, 11], [7, 11], [7, 11], [7, 11],
  16910. [7, 11], [7, 11], [7, 11], [7, 11],
  16911. [7, 11], [7, 11], [7, 11], [7, 11],
  16912. [7, 11], [7, 11], [7, 11], [7, 11],
  16913. [7, 11], [7, 11], [7, 11], [7, 11],
  16914. [7, 11], [7, 11], [7, 11], [7, 11],
  16915. [9, 15], [9, 15], [9, 15], [9, 15], // 000011000xxx
  16916. [9, 15], [9, 15], [9, 15], [9, 15],
  16917. [12, 128], // 000011001000
  16918. [12, 192], // 000011001001
  16919. [12, 26], // 000011001010
  16920. [12, 27], // 000011001011
  16921. [12, 28], // 000011001100
  16922. [12, 29], // 000011001101
  16923. [11, 19], [11, 19], // 00001100111x
  16924. [11, 20], [11, 20], // 00001101000x
  16925. [12, 34], // 000011010010
  16926. [12, 35], // 000011010011
  16927. [12, 36], // 000011010100
  16928. [12, 37], // 000011010101
  16929. [12, 38], // 000011010110
  16930. [12, 39], // 000011010111
  16931. [11, 21], [11, 21], // 00001101100x
  16932. [12, 42], // 000011011010
  16933. [12, 43], // 000011011011
  16934. [10, 0], [10, 0], [10, 0], [10, 0], // 0000110111xx
  16935. [7, 12], [7, 12], [7, 12], [7, 12], // 0000111xxxxx
  16936. [7, 12], [7, 12], [7, 12], [7, 12],
  16937. [7, 12], [7, 12], [7, 12], [7, 12],
  16938. [7, 12], [7, 12], [7, 12], [7, 12],
  16939. [7, 12], [7, 12], [7, 12], [7, 12],
  16940. [7, 12], [7, 12], [7, 12], [7, 12],
  16941. [7, 12], [7, 12], [7, 12], [7, 12],
  16942. [7, 12], [7, 12], [7, 12], [7, 12]
  16943. ];
  16944. var blackTable3 = [
  16945. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000xx
  16946. [6, 9], // 000100
  16947. [6, 8], // 000101
  16948. [5, 7], [5, 7], // 00011x
  16949. [4, 6], [4, 6], [4, 6], [4, 6], // 0010xx
  16950. [4, 5], [4, 5], [4, 5], [4, 5], // 0011xx
  16951. [3, 1], [3, 1], [3, 1], [3, 1], // 010xxx
  16952. [3, 1], [3, 1], [3, 1], [3, 1],
  16953. [3, 4], [3, 4], [3, 4], [3, 4], // 011xxx
  16954. [3, 4], [3, 4], [3, 4], [3, 4],
  16955. [2, 3], [2, 3], [2, 3], [2, 3], // 10xxxx
  16956. [2, 3], [2, 3], [2, 3], [2, 3],
  16957. [2, 3], [2, 3], [2, 3], [2, 3],
  16958. [2, 3], [2, 3], [2, 3], [2, 3],
  16959. [2, 2], [2, 2], [2, 2], [2, 2], // 11xxxx
  16960. [2, 2], [2, 2], [2, 2], [2, 2],
  16961. [2, 2], [2, 2], [2, 2], [2, 2],
  16962. [2, 2], [2, 2], [2, 2], [2, 2]
  16963. ];
  16964. function CCITTFaxStream(str, maybeLength, params) {
  16965. this.str = str;
  16966. this.dict = str.dict;
  16967. params = params || Dict.empty;
  16968. this.encoding = params.get('K') || 0;
  16969. this.eoline = params.get('EndOfLine') || false;
  16970. this.byteAlign = params.get('EncodedByteAlign') || false;
  16971. this.columns = params.get('Columns') || 1728;
  16972. this.rows = params.get('Rows') || 0;
  16973. var eoblock = params.get('EndOfBlock');
  16974. if (eoblock === null || eoblock === undefined) {
  16975. eoblock = true;
  16976. }
  16977. this.eoblock = eoblock;
  16978. this.black = params.get('BlackIs1') || false;
  16979. this.codingLine = new Uint32Array(this.columns + 1);
  16980. this.refLine = new Uint32Array(this.columns + 2);
  16981. this.codingLine[0] = this.columns;
  16982. this.codingPos = 0;
  16983. this.row = 0;
  16984. this.nextLine2D = this.encoding < 0;
  16985. this.inputBits = 0;
  16986. this.inputBuf = 0;
  16987. this.outputBits = 0;
  16988. var code1;
  16989. while ((code1 = this.lookBits(12)) === 0) {
  16990. this.eatBits(1);
  16991. }
  16992. if (code1 === 1) {
  16993. this.eatBits(12);
  16994. }
  16995. if (this.encoding > 0) {
  16996. this.nextLine2D = !this.lookBits(1);
  16997. this.eatBits(1);
  16998. }
  16999. DecodeStream.call(this, maybeLength);
  17000. }
  17001. CCITTFaxStream.prototype = Object.create(DecodeStream.prototype);
  17002. CCITTFaxStream.prototype.readBlock = function CCITTFaxStream_readBlock() {
  17003. while (!this.eof) {
  17004. var c = this.lookChar();
  17005. this.ensureBuffer(this.bufferLength + 1);
  17006. this.buffer[this.bufferLength++] = c;
  17007. }
  17008. };
  17009. CCITTFaxStream.prototype.addPixels =
  17010. function ccittFaxStreamAddPixels(a1, blackPixels) {
  17011. var codingLine = this.codingLine;
  17012. var codingPos = this.codingPos;
  17013. if (a1 > codingLine[codingPos]) {
  17014. if (a1 > this.columns) {
  17015. info('row is wrong length');
  17016. this.err = true;
  17017. a1 = this.columns;
  17018. }
  17019. if ((codingPos & 1) ^ blackPixels) {
  17020. ++codingPos;
  17021. }
  17022. codingLine[codingPos] = a1;
  17023. }
  17024. this.codingPos = codingPos;
  17025. };
  17026. CCITTFaxStream.prototype.addPixelsNeg =
  17027. function ccittFaxStreamAddPixelsNeg(a1, blackPixels) {
  17028. var codingLine = this.codingLine;
  17029. var codingPos = this.codingPos;
  17030. if (a1 > codingLine[codingPos]) {
  17031. if (a1 > this.columns) {
  17032. info('row is wrong length');
  17033. this.err = true;
  17034. a1 = this.columns;
  17035. }
  17036. if ((codingPos & 1) ^ blackPixels) {
  17037. ++codingPos;
  17038. }
  17039. codingLine[codingPos] = a1;
  17040. } else if (a1 < codingLine[codingPos]) {
  17041. if (a1 < 0) {
  17042. info('invalid code');
  17043. this.err = true;
  17044. a1 = 0;
  17045. }
  17046. while (codingPos > 0 && a1 < codingLine[codingPos - 1]) {
  17047. --codingPos;
  17048. }
  17049. codingLine[codingPos] = a1;
  17050. }
  17051. this.codingPos = codingPos;
  17052. };
  17053. CCITTFaxStream.prototype.lookChar = function CCITTFaxStream_lookChar() {
  17054. var refLine = this.refLine;
  17055. var codingLine = this.codingLine;
  17056. var columns = this.columns;
  17057. var refPos, blackPixels, bits, i;
  17058. if (this.outputBits === 0) {
  17059. if (this.eof) {
  17060. return null;
  17061. }
  17062. this.err = false;
  17063. var code1, code2, code3;
  17064. if (this.nextLine2D) {
  17065. for (i = 0; codingLine[i] < columns; ++i) {
  17066. refLine[i] = codingLine[i];
  17067. }
  17068. refLine[i++] = columns;
  17069. refLine[i] = columns;
  17070. codingLine[0] = 0;
  17071. this.codingPos = 0;
  17072. refPos = 0;
  17073. blackPixels = 0;
  17074. while (codingLine[this.codingPos] < columns) {
  17075. code1 = this.getTwoDimCode();
  17076. switch (code1) {
  17077. case twoDimPass:
  17078. this.addPixels(refLine[refPos + 1], blackPixels);
  17079. if (refLine[refPos + 1] < columns) {
  17080. refPos += 2;
  17081. }
  17082. break;
  17083. case twoDimHoriz:
  17084. code1 = code2 = 0;
  17085. if (blackPixels) {
  17086. do {
  17087. code1 += (code3 = this.getBlackCode());
  17088. } while (code3 >= 64);
  17089. do {
  17090. code2 += (code3 = this.getWhiteCode());
  17091. } while (code3 >= 64);
  17092. } else {
  17093. do {
  17094. code1 += (code3 = this.getWhiteCode());
  17095. } while (code3 >= 64);
  17096. do {
  17097. code2 += (code3 = this.getBlackCode());
  17098. } while (code3 >= 64);
  17099. }
  17100. this.addPixels(codingLine[this.codingPos] +
  17101. code1, blackPixels);
  17102. if (codingLine[this.codingPos] < columns) {
  17103. this.addPixels(codingLine[this.codingPos] + code2,
  17104. blackPixels ^ 1);
  17105. }
  17106. while (refLine[refPos] <= codingLine[this.codingPos] &&
  17107. refLine[refPos] < columns) {
  17108. refPos += 2;
  17109. }
  17110. break;
  17111. case twoDimVertR3:
  17112. this.addPixels(refLine[refPos] + 3, blackPixels);
  17113. blackPixels ^= 1;
  17114. if (codingLine[this.codingPos] < columns) {
  17115. ++refPos;
  17116. while (refLine[refPos] <= codingLine[this.codingPos] &&
  17117. refLine[refPos] < columns) {
  17118. refPos += 2;
  17119. }
  17120. }
  17121. break;
  17122. case twoDimVertR2:
  17123. this.addPixels(refLine[refPos] + 2, blackPixels);
  17124. blackPixels ^= 1;
  17125. if (codingLine[this.codingPos] < columns) {
  17126. ++refPos;
  17127. while (refLine[refPos] <= codingLine[this.codingPos] &&
  17128. refLine[refPos] < columns) {
  17129. refPos += 2;
  17130. }
  17131. }
  17132. break;
  17133. case twoDimVertR1:
  17134. this.addPixels(refLine[refPos] + 1, blackPixels);
  17135. blackPixels ^= 1;
  17136. if (codingLine[this.codingPos] < columns) {
  17137. ++refPos;
  17138. while (refLine[refPos] <= codingLine[this.codingPos] &&
  17139. refLine[refPos] < columns) {
  17140. refPos += 2;
  17141. }
  17142. }
  17143. break;
  17144. case twoDimVert0:
  17145. this.addPixels(refLine[refPos], blackPixels);
  17146. blackPixels ^= 1;
  17147. if (codingLine[this.codingPos] < columns) {
  17148. ++refPos;
  17149. while (refLine[refPos] <= codingLine[this.codingPos] &&
  17150. refLine[refPos] < columns) {
  17151. refPos += 2;
  17152. }
  17153. }
  17154. break;
  17155. case twoDimVertL3:
  17156. this.addPixelsNeg(refLine[refPos] - 3, blackPixels);
  17157. blackPixels ^= 1;
  17158. if (codingLine[this.codingPos] < columns) {
  17159. if (refPos > 0) {
  17160. --refPos;
  17161. } else {
  17162. ++refPos;
  17163. }
  17164. while (refLine[refPos] <= codingLine[this.codingPos] &&
  17165. refLine[refPos] < columns) {
  17166. refPos += 2;
  17167. }
  17168. }
  17169. break;
  17170. case twoDimVertL2:
  17171. this.addPixelsNeg(refLine[refPos] - 2, blackPixels);
  17172. blackPixels ^= 1;
  17173. if (codingLine[this.codingPos] < columns) {
  17174. if (refPos > 0) {
  17175. --refPos;
  17176. } else {
  17177. ++refPos;
  17178. }
  17179. while (refLine[refPos] <= codingLine[this.codingPos] &&
  17180. refLine[refPos] < columns) {
  17181. refPos += 2;
  17182. }
  17183. }
  17184. break;
  17185. case twoDimVertL1:
  17186. this.addPixelsNeg(refLine[refPos] - 1, blackPixels);
  17187. blackPixels ^= 1;
  17188. if (codingLine[this.codingPos] < columns) {
  17189. if (refPos > 0) {
  17190. --refPos;
  17191. } else {
  17192. ++refPos;
  17193. }
  17194. while (refLine[refPos] <= codingLine[this.codingPos] &&
  17195. refLine[refPos] < columns) {
  17196. refPos += 2;
  17197. }
  17198. }
  17199. break;
  17200. case EOF:
  17201. this.addPixels(columns, 0);
  17202. this.eof = true;
  17203. break;
  17204. default:
  17205. info('bad 2d code');
  17206. this.addPixels(columns, 0);
  17207. this.err = true;
  17208. }
  17209. }
  17210. } else {
  17211. codingLine[0] = 0;
  17212. this.codingPos = 0;
  17213. blackPixels = 0;
  17214. while (codingLine[this.codingPos] < columns) {
  17215. code1 = 0;
  17216. if (blackPixels) {
  17217. do {
  17218. code1 += (code3 = this.getBlackCode());
  17219. } while (code3 >= 64);
  17220. } else {
  17221. do {
  17222. code1 += (code3 = this.getWhiteCode());
  17223. } while (code3 >= 64);
  17224. }
  17225. this.addPixels(codingLine[this.codingPos] + code1, blackPixels);
  17226. blackPixels ^= 1;
  17227. }
  17228. }
  17229. var gotEOL = false;
  17230. if (this.byteAlign) {
  17231. this.inputBits &= ~7;
  17232. }
  17233. if (!this.eoblock && this.row === this.rows - 1) {
  17234. this.eof = true;
  17235. } else {
  17236. code1 = this.lookBits(12);
  17237. if (this.eoline) {
  17238. while (code1 !== EOF && code1 !== 1) {
  17239. this.eatBits(1);
  17240. code1 = this.lookBits(12);
  17241. }
  17242. } else {
  17243. while (code1 === 0) {
  17244. this.eatBits(1);
  17245. code1 = this.lookBits(12);
  17246. }
  17247. }
  17248. if (code1 === 1) {
  17249. this.eatBits(12);
  17250. gotEOL = true;
  17251. } else if (code1 === EOF) {
  17252. this.eof = true;
  17253. }
  17254. }
  17255. if (!this.eof && this.encoding > 0) {
  17256. this.nextLine2D = !this.lookBits(1);
  17257. this.eatBits(1);
  17258. }
  17259. if (this.eoblock && gotEOL && this.byteAlign) {
  17260. code1 = this.lookBits(12);
  17261. if (code1 === 1) {
  17262. this.eatBits(12);
  17263. if (this.encoding > 0) {
  17264. this.lookBits(1);
  17265. this.eatBits(1);
  17266. }
  17267. if (this.encoding >= 0) {
  17268. for (i = 0; i < 4; ++i) {
  17269. code1 = this.lookBits(12);
  17270. if (code1 !== 1) {
  17271. info('bad rtc code: ' + code1);
  17272. }
  17273. this.eatBits(12);
  17274. if (this.encoding > 0) {
  17275. this.lookBits(1);
  17276. this.eatBits(1);
  17277. }
  17278. }
  17279. }
  17280. this.eof = true;
  17281. }
  17282. } else if (this.err && this.eoline) {
  17283. while (true) {
  17284. code1 = this.lookBits(13);
  17285. if (code1 === EOF) {
  17286. this.eof = true;
  17287. return null;
  17288. }
  17289. if ((code1 >> 1) === 1) {
  17290. break;
  17291. }
  17292. this.eatBits(1);
  17293. }
  17294. this.eatBits(12);
  17295. if (this.encoding > 0) {
  17296. this.eatBits(1);
  17297. this.nextLine2D = !(code1 & 1);
  17298. }
  17299. }
  17300. if (codingLine[0] > 0) {
  17301. this.outputBits = codingLine[this.codingPos = 0];
  17302. } else {
  17303. this.outputBits = codingLine[this.codingPos = 1];
  17304. }
  17305. this.row++;
  17306. }
  17307. var c;
  17308. if (this.outputBits >= 8) {
  17309. c = (this.codingPos & 1) ? 0 : 0xFF;
  17310. this.outputBits -= 8;
  17311. if (this.outputBits === 0 && codingLine[this.codingPos] < columns) {
  17312. this.codingPos++;
  17313. this.outputBits = (codingLine[this.codingPos] -
  17314. codingLine[this.codingPos - 1]);
  17315. }
  17316. } else {
  17317. bits = 8;
  17318. c = 0;
  17319. do {
  17320. if (this.outputBits > bits) {
  17321. c <<= bits;
  17322. if (!(this.codingPos & 1)) {
  17323. c |= 0xFF >> (8 - bits);
  17324. }
  17325. this.outputBits -= bits;
  17326. bits = 0;
  17327. } else {
  17328. c <<= this.outputBits;
  17329. if (!(this.codingPos & 1)) {
  17330. c |= 0xFF >> (8 - this.outputBits);
  17331. }
  17332. bits -= this.outputBits;
  17333. this.outputBits = 0;
  17334. if (codingLine[this.codingPos] < columns) {
  17335. this.codingPos++;
  17336. this.outputBits = (codingLine[this.codingPos] -
  17337. codingLine[this.codingPos - 1]);
  17338. } else if (bits > 0) {
  17339. c <<= bits;
  17340. bits = 0;
  17341. }
  17342. }
  17343. } while (bits);
  17344. }
  17345. if (this.black) {
  17346. c ^= 0xFF;
  17347. }
  17348. return c;
  17349. };
  17350. // This functions returns the code found from the table.
  17351. // The start and end parameters set the boundaries for searching the table.
  17352. // The limit parameter is optional. Function returns an array with three
  17353. // values. The first array element indicates whether a valid code is being
  17354. // returned. The second array element is the actual code. The third array
  17355. // element indicates whether EOF was reached.
  17356. CCITTFaxStream.prototype.findTableCode =
  17357. function ccittFaxStreamFindTableCode(start, end, table, limit) {
  17358. var limitValue = limit || 0;
  17359. for (var i = start; i <= end; ++i) {
  17360. var code = this.lookBits(i);
  17361. if (code === EOF) {
  17362. return [true, 1, false];
  17363. }
  17364. if (i < end) {
  17365. code <<= end - i;
  17366. }
  17367. if (!limitValue || code >= limitValue) {
  17368. var p = table[code - limitValue];
  17369. if (p[0] === i) {
  17370. this.eatBits(i);
  17371. return [true, p[1], true];
  17372. }
  17373. }
  17374. }
  17375. return [false, 0, false];
  17376. };
  17377. CCITTFaxStream.prototype.getTwoDimCode =
  17378. function ccittFaxStreamGetTwoDimCode() {
  17379. var code = 0;
  17380. var p;
  17381. if (this.eoblock) {
  17382. code = this.lookBits(7);
  17383. p = twoDimTable[code];
  17384. if (p && p[0] > 0) {
  17385. this.eatBits(p[0]);
  17386. return p[1];
  17387. }
  17388. } else {
  17389. var result = this.findTableCode(1, 7, twoDimTable);
  17390. if (result[0] && result[2]) {
  17391. return result[1];
  17392. }
  17393. }
  17394. info('Bad two dim code');
  17395. return EOF;
  17396. };
  17397. CCITTFaxStream.prototype.getWhiteCode =
  17398. function ccittFaxStreamGetWhiteCode() {
  17399. var code = 0;
  17400. var p;
  17401. if (this.eoblock) {
  17402. code = this.lookBits(12);
  17403. if (code === EOF) {
  17404. return 1;
  17405. }
  17406. if ((code >> 5) === 0) {
  17407. p = whiteTable1[code];
  17408. } else {
  17409. p = whiteTable2[code >> 3];
  17410. }
  17411. if (p[0] > 0) {
  17412. this.eatBits(p[0]);
  17413. return p[1];
  17414. }
  17415. } else {
  17416. var result = this.findTableCode(1, 9, whiteTable2);
  17417. if (result[0]) {
  17418. return result[1];
  17419. }
  17420. result = this.findTableCode(11, 12, whiteTable1);
  17421. if (result[0]) {
  17422. return result[1];
  17423. }
  17424. }
  17425. info('bad white code');
  17426. this.eatBits(1);
  17427. return 1;
  17428. };
  17429. CCITTFaxStream.prototype.getBlackCode =
  17430. function ccittFaxStreamGetBlackCode() {
  17431. var code, p;
  17432. if (this.eoblock) {
  17433. code = this.lookBits(13);
  17434. if (code === EOF) {
  17435. return 1;
  17436. }
  17437. if ((code >> 7) === 0) {
  17438. p = blackTable1[code];
  17439. } else if ((code >> 9) === 0 && (code >> 7) !== 0) {
  17440. p = blackTable2[(code >> 1) - 64];
  17441. } else {
  17442. p = blackTable3[code >> 7];
  17443. }
  17444. if (p[0] > 0) {
  17445. this.eatBits(p[0]);
  17446. return p[1];
  17447. }
  17448. } else {
  17449. var result = this.findTableCode(2, 6, blackTable3);
  17450. if (result[0]) {
  17451. return result[1];
  17452. }
  17453. result = this.findTableCode(7, 12, blackTable2, 64);
  17454. if (result[0]) {
  17455. return result[1];
  17456. }
  17457. result = this.findTableCode(10, 13, blackTable1);
  17458. if (result[0]) {
  17459. return result[1];
  17460. }
  17461. }
  17462. info('bad black code');
  17463. this.eatBits(1);
  17464. return 1;
  17465. };
  17466. CCITTFaxStream.prototype.lookBits = function CCITTFaxStream_lookBits(n) {
  17467. var c;
  17468. while (this.inputBits < n) {
  17469. if ((c = this.str.getByte()) === -1) {
  17470. if (this.inputBits === 0) {
  17471. return EOF;
  17472. }
  17473. return ((this.inputBuf << (n - this.inputBits)) &
  17474. (0xFFFF >> (16 - n)));
  17475. }
  17476. this.inputBuf = (this.inputBuf << 8) + c;
  17477. this.inputBits += 8;
  17478. }
  17479. return (this.inputBuf >> (this.inputBits - n)) & (0xFFFF >> (16 - n));
  17480. };
  17481. CCITTFaxStream.prototype.eatBits = function CCITTFaxStream_eatBits(n) {
  17482. if ((this.inputBits -= n) < 0) {
  17483. this.inputBits = 0;
  17484. }
  17485. };
  17486. return CCITTFaxStream;
  17487. })();
  17488. var LZWStream = (function LZWStreamClosure() {
  17489. function LZWStream(str, maybeLength, earlyChange) {
  17490. this.str = str;
  17491. this.dict = str.dict;
  17492. this.cachedData = 0;
  17493. this.bitsCached = 0;
  17494. var maxLzwDictionarySize = 4096;
  17495. var lzwState = {
  17496. earlyChange: earlyChange,
  17497. codeLength: 9,
  17498. nextCode: 258,
  17499. dictionaryValues: new Uint8Array(maxLzwDictionarySize),
  17500. dictionaryLengths: new Uint16Array(maxLzwDictionarySize),
  17501. dictionaryPrevCodes: new Uint16Array(maxLzwDictionarySize),
  17502. currentSequence: new Uint8Array(maxLzwDictionarySize),
  17503. currentSequenceLength: 0
  17504. };
  17505. for (var i = 0; i < 256; ++i) {
  17506. lzwState.dictionaryValues[i] = i;
  17507. lzwState.dictionaryLengths[i] = 1;
  17508. }
  17509. this.lzwState = lzwState;
  17510. DecodeStream.call(this, maybeLength);
  17511. }
  17512. LZWStream.prototype = Object.create(DecodeStream.prototype);
  17513. LZWStream.prototype.readBits = function LZWStream_readBits(n) {
  17514. var bitsCached = this.bitsCached;
  17515. var cachedData = this.cachedData;
  17516. while (bitsCached < n) {
  17517. var c = this.str.getByte();
  17518. if (c === -1) {
  17519. this.eof = true;
  17520. return null;
  17521. }
  17522. cachedData = (cachedData << 8) | c;
  17523. bitsCached += 8;
  17524. }
  17525. this.bitsCached = (bitsCached -= n);
  17526. this.cachedData = cachedData;
  17527. this.lastCode = null;
  17528. return (cachedData >>> bitsCached) & ((1 << n) - 1);
  17529. };
  17530. LZWStream.prototype.readBlock = function LZWStream_readBlock() {
  17531. var blockSize = 512;
  17532. var estimatedDecodedSize = blockSize * 2, decodedSizeDelta = blockSize;
  17533. var i, j, q;
  17534. var lzwState = this.lzwState;
  17535. if (!lzwState) {
  17536. return; // eof was found
  17537. }
  17538. var earlyChange = lzwState.earlyChange;
  17539. var nextCode = lzwState.nextCode;
  17540. var dictionaryValues = lzwState.dictionaryValues;
  17541. var dictionaryLengths = lzwState.dictionaryLengths;
  17542. var dictionaryPrevCodes = lzwState.dictionaryPrevCodes;
  17543. var codeLength = lzwState.codeLength;
  17544. var prevCode = lzwState.prevCode;
  17545. var currentSequence = lzwState.currentSequence;
  17546. var currentSequenceLength = lzwState.currentSequenceLength;
  17547. var decodedLength = 0;
  17548. var currentBufferLength = this.bufferLength;
  17549. var buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  17550. for (i = 0; i < blockSize; i++) {
  17551. var code = this.readBits(codeLength);
  17552. var hasPrev = currentSequenceLength > 0;
  17553. if (code < 256) {
  17554. currentSequence[0] = code;
  17555. currentSequenceLength = 1;
  17556. } else if (code >= 258) {
  17557. if (code < nextCode) {
  17558. currentSequenceLength = dictionaryLengths[code];
  17559. for (j = currentSequenceLength - 1, q = code; j >= 0; j--) {
  17560. currentSequence[j] = dictionaryValues[q];
  17561. q = dictionaryPrevCodes[q];
  17562. }
  17563. } else {
  17564. currentSequence[currentSequenceLength++] = currentSequence[0];
  17565. }
  17566. } else if (code === 256) {
  17567. codeLength = 9;
  17568. nextCode = 258;
  17569. currentSequenceLength = 0;
  17570. continue;
  17571. } else {
  17572. this.eof = true;
  17573. delete this.lzwState;
  17574. break;
  17575. }
  17576. if (hasPrev) {
  17577. dictionaryPrevCodes[nextCode] = prevCode;
  17578. dictionaryLengths[nextCode] = dictionaryLengths[prevCode] + 1;
  17579. dictionaryValues[nextCode] = currentSequence[0];
  17580. nextCode++;
  17581. codeLength = (nextCode + earlyChange) & (nextCode + earlyChange - 1) ?
  17582. codeLength : Math.min(Math.log(nextCode + earlyChange) /
  17583. 0.6931471805599453 + 1, 12) | 0;
  17584. }
  17585. prevCode = code;
  17586. decodedLength += currentSequenceLength;
  17587. if (estimatedDecodedSize < decodedLength) {
  17588. do {
  17589. estimatedDecodedSize += decodedSizeDelta;
  17590. } while (estimatedDecodedSize < decodedLength);
  17591. buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  17592. }
  17593. for (j = 0; j < currentSequenceLength; j++) {
  17594. buffer[currentBufferLength++] = currentSequence[j];
  17595. }
  17596. }
  17597. lzwState.nextCode = nextCode;
  17598. lzwState.codeLength = codeLength;
  17599. lzwState.prevCode = prevCode;
  17600. lzwState.currentSequenceLength = currentSequenceLength;
  17601. this.bufferLength = currentBufferLength;
  17602. };
  17603. return LZWStream;
  17604. })();
  17605. var NullStream = (function NullStreamClosure() {
  17606. function NullStream() {
  17607. Stream.call(this, new Uint8Array(0));
  17608. }
  17609. NullStream.prototype = Stream.prototype;
  17610. return NullStream;
  17611. })();
  17612. // TODO refactor to remove dependency on parser.js
  17613. function _setCoreParser(coreParser_) {
  17614. coreParser = coreParser_;
  17615. EOF = coreParser_.EOF;
  17616. Lexer = coreParser_.Lexer;
  17617. }
  17618. exports._setCoreParser = _setCoreParser;
  17619. // TODO refactor to remove dependency on colorspace.js
  17620. function _setCoreColorSpace(coreColorSpace_) {
  17621. coreColorSpace = coreColorSpace_;
  17622. ColorSpace = coreColorSpace_.ColorSpace;
  17623. }
  17624. exports._setCoreColorSpace = _setCoreColorSpace;
  17625. exports.Ascii85Stream = Ascii85Stream;
  17626. exports.AsciiHexStream = AsciiHexStream;
  17627. exports.CCITTFaxStream = CCITTFaxStream;
  17628. exports.DecryptStream = DecryptStream;
  17629. exports.DecodeStream = DecodeStream;
  17630. exports.FlateStream = FlateStream;
  17631. exports.Jbig2Stream = Jbig2Stream;
  17632. exports.JpegStream = JpegStream;
  17633. exports.JpxStream = JpxStream;
  17634. exports.NullStream = NullStream;
  17635. exports.PredictorStream = PredictorStream;
  17636. exports.RunLengthStream = RunLengthStream;
  17637. exports.Stream = Stream;
  17638. exports.StreamsSequenceStream = StreamsSequenceStream;
  17639. exports.StringStream = StringStream;
  17640. exports.LZWStream = LZWStream;
  17641. }));
  17642. (function (root, factory) {
  17643. {
  17644. factory((root.pdfjsCoreCrypto = {}), root.pdfjsSharedUtil,
  17645. root.pdfjsCorePrimitives, root.pdfjsCoreStream);
  17646. }
  17647. }(this, function (exports, sharedUtil, corePrimitives, coreStream) {
  17648. var PasswordException = sharedUtil.PasswordException;
  17649. var PasswordResponses = sharedUtil.PasswordResponses;
  17650. var bytesToString = sharedUtil.bytesToString;
  17651. var error = sharedUtil.error;
  17652. var isInt = sharedUtil.isInt;
  17653. var stringToBytes = sharedUtil.stringToBytes;
  17654. var utf8StringToString = sharedUtil.utf8StringToString;
  17655. var warn = sharedUtil.warn;
  17656. var Name = corePrimitives.Name;
  17657. var isName = corePrimitives.isName;
  17658. var isDict = corePrimitives.isDict;
  17659. var DecryptStream = coreStream.DecryptStream;
  17660. var ARCFourCipher = (function ARCFourCipherClosure() {
  17661. function ARCFourCipher(key) {
  17662. this.a = 0;
  17663. this.b = 0;
  17664. var s = new Uint8Array(256);
  17665. var i, j = 0, tmp, keyLength = key.length;
  17666. for (i = 0; i < 256; ++i) {
  17667. s[i] = i;
  17668. }
  17669. for (i = 0; i < 256; ++i) {
  17670. tmp = s[i];
  17671. j = (j + tmp + key[i % keyLength]) & 0xFF;
  17672. s[i] = s[j];
  17673. s[j] = tmp;
  17674. }
  17675. this.s = s;
  17676. }
  17677. ARCFourCipher.prototype = {
  17678. encryptBlock: function ARCFourCipher_encryptBlock(data) {
  17679. var i, n = data.length, tmp, tmp2;
  17680. var a = this.a, b = this.b, s = this.s;
  17681. var output = new Uint8Array(n);
  17682. for (i = 0; i < n; ++i) {
  17683. a = (a + 1) & 0xFF;
  17684. tmp = s[a];
  17685. b = (b + tmp) & 0xFF;
  17686. tmp2 = s[b];
  17687. s[a] = tmp2;
  17688. s[b] = tmp;
  17689. output[i] = data[i] ^ s[(tmp + tmp2) & 0xFF];
  17690. }
  17691. this.a = a;
  17692. this.b = b;
  17693. return output;
  17694. }
  17695. };
  17696. ARCFourCipher.prototype.decryptBlock = ARCFourCipher.prototype.encryptBlock;
  17697. return ARCFourCipher;
  17698. })();
  17699. var calculateMD5 = (function calculateMD5Closure() {
  17700. var r = new Uint8Array([
  17701. 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22,
  17702. 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20,
  17703. 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23,
  17704. 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21]);
  17705. var k = new Int32Array([
  17706. -680876936, -389564586, 606105819, -1044525330, -176418897, 1200080426,
  17707. -1473231341, -45705983, 1770035416, -1958414417, -42063, -1990404162,
  17708. 1804603682, -40341101, -1502002290, 1236535329, -165796510, -1069501632,
  17709. 643717713, -373897302, -701558691, 38016083, -660478335, -405537848,
  17710. 568446438, -1019803690, -187363961, 1163531501, -1444681467, -51403784,
  17711. 1735328473, -1926607734, -378558, -2022574463, 1839030562, -35309556,
  17712. -1530992060, 1272893353, -155497632, -1094730640, 681279174, -358537222,
  17713. -722521979, 76029189, -640364487, -421815835, 530742520, -995338651,
  17714. -198630844, 1126891415, -1416354905, -57434055, 1700485571, -1894986606,
  17715. -1051523, -2054922799, 1873313359, -30611744, -1560198380, 1309151649,
  17716. -145523070, -1120210379, 718787259, -343485551]);
  17717. function hash(data, offset, length) {
  17718. var h0 = 1732584193, h1 = -271733879, h2 = -1732584194, h3 = 271733878;
  17719. // pre-processing
  17720. var paddedLength = (length + 72) & ~63; // data + 9 extra bytes
  17721. var padded = new Uint8Array(paddedLength);
  17722. var i, j, n;
  17723. for (i = 0; i < length; ++i) {
  17724. padded[i] = data[offset++];
  17725. }
  17726. padded[i++] = 0x80;
  17727. n = paddedLength - 8;
  17728. while (i < n) {
  17729. padded[i++] = 0;
  17730. }
  17731. padded[i++] = (length << 3) & 0xFF;
  17732. padded[i++] = (length >> 5) & 0xFF;
  17733. padded[i++] = (length >> 13) & 0xFF;
  17734. padded[i++] = (length >> 21) & 0xFF;
  17735. padded[i++] = (length >>> 29) & 0xFF;
  17736. padded[i++] = 0;
  17737. padded[i++] = 0;
  17738. padded[i++] = 0;
  17739. var w = new Int32Array(16);
  17740. for (i = 0; i < paddedLength;) {
  17741. for (j = 0; j < 16; ++j, i += 4) {
  17742. w[j] = (padded[i] | (padded[i + 1] << 8) |
  17743. (padded[i + 2] << 16) | (padded[i + 3] << 24));
  17744. }
  17745. var a = h0, b = h1, c = h2, d = h3, f, g;
  17746. for (j = 0; j < 64; ++j) {
  17747. if (j < 16) {
  17748. f = (b & c) | ((~b) & d);
  17749. g = j;
  17750. } else if (j < 32) {
  17751. f = (d & b) | ((~d) & c);
  17752. g = (5 * j + 1) & 15;
  17753. } else if (j < 48) {
  17754. f = b ^ c ^ d;
  17755. g = (3 * j + 5) & 15;
  17756. } else {
  17757. f = c ^ (b | (~d));
  17758. g = (7 * j) & 15;
  17759. }
  17760. var tmp = d, rotateArg = (a + f + k[j] + w[g]) | 0, rotate = r[j];
  17761. d = c;
  17762. c = b;
  17763. b = (b + ((rotateArg << rotate) | (rotateArg >>> (32 - rotate)))) | 0;
  17764. a = tmp;
  17765. }
  17766. h0 = (h0 + a) | 0;
  17767. h1 = (h1 + b) | 0;
  17768. h2 = (h2 + c) | 0;
  17769. h3 = (h3 + d) | 0;
  17770. }
  17771. return new Uint8Array([
  17772. h0 & 0xFF, (h0 >> 8) & 0xFF, (h0 >> 16) & 0xFF, (h0 >>> 24) & 0xFF,
  17773. h1 & 0xFF, (h1 >> 8) & 0xFF, (h1 >> 16) & 0xFF, (h1 >>> 24) & 0xFF,
  17774. h2 & 0xFF, (h2 >> 8) & 0xFF, (h2 >> 16) & 0xFF, (h2 >>> 24) & 0xFF,
  17775. h3 & 0xFF, (h3 >> 8) & 0xFF, (h3 >> 16) & 0xFF, (h3 >>> 24) & 0xFF
  17776. ]);
  17777. }
  17778. return hash;
  17779. })();
  17780. var Word64 = (function Word64Closure() {
  17781. function Word64(highInteger, lowInteger) {
  17782. this.high = highInteger | 0;
  17783. this.low = lowInteger | 0;
  17784. }
  17785. Word64.prototype = {
  17786. and: function Word64_and(word) {
  17787. this.high &= word.high;
  17788. this.low &= word.low;
  17789. },
  17790. xor: function Word64_xor(word) {
  17791. this.high ^= word.high;
  17792. this.low ^= word.low;
  17793. },
  17794. or: function Word64_or(word) {
  17795. this.high |= word.high;
  17796. this.low |= word.low;
  17797. },
  17798. shiftRight: function Word64_shiftRight(places) {
  17799. if (places >= 32) {
  17800. this.low = (this.high >>> (places - 32)) | 0;
  17801. this.high = 0;
  17802. } else {
  17803. this.low = (this.low >>> places) | (this.high << (32 - places));
  17804. this.high = (this.high >>> places) | 0;
  17805. }
  17806. },
  17807. shiftLeft: function Word64_shiftLeft(places) {
  17808. if (places >= 32) {
  17809. this.high = this.low << (places - 32);
  17810. this.low = 0;
  17811. } else {
  17812. this.high = (this.high << places) | (this.low >>> (32 - places));
  17813. this.low = this.low << places;
  17814. }
  17815. },
  17816. rotateRight: function Word64_rotateRight(places) {
  17817. var low, high;
  17818. if (places & 32) {
  17819. high = this.low;
  17820. low = this.high;
  17821. } else {
  17822. low = this.low;
  17823. high = this.high;
  17824. }
  17825. places &= 31;
  17826. this.low = (low >>> places) | (high << (32 - places));
  17827. this.high = (high >>> places) | (low << (32 - places));
  17828. },
  17829. not: function Word64_not() {
  17830. this.high = ~this.high;
  17831. this.low = ~this.low;
  17832. },
  17833. add: function Word64_add(word) {
  17834. var lowAdd = (this.low >>> 0) + (word.low >>> 0);
  17835. var highAdd = (this.high >>> 0) + (word.high >>> 0);
  17836. if (lowAdd > 0xFFFFFFFF) {
  17837. highAdd += 1;
  17838. }
  17839. this.low = lowAdd | 0;
  17840. this.high = highAdd | 0;
  17841. },
  17842. copyTo: function Word64_copyTo(bytes, offset) {
  17843. bytes[offset] = (this.high >>> 24) & 0xFF;
  17844. bytes[offset + 1] = (this.high >> 16) & 0xFF;
  17845. bytes[offset + 2] = (this.high >> 8) & 0xFF;
  17846. bytes[offset + 3] = this.high & 0xFF;
  17847. bytes[offset + 4] = (this.low >>> 24) & 0xFF;
  17848. bytes[offset + 5] = (this.low >> 16) & 0xFF;
  17849. bytes[offset + 6] = (this.low >> 8) & 0xFF;
  17850. bytes[offset + 7] = this.low & 0xFF;
  17851. },
  17852. assign: function Word64_assign(word) {
  17853. this.high = word.high;
  17854. this.low = word.low;
  17855. }
  17856. };
  17857. return Word64;
  17858. })();
  17859. var calculateSHA256 = (function calculateSHA256Closure() {
  17860. function rotr(x, n) {
  17861. return (x >>> n) | (x << 32 - n);
  17862. }
  17863. function ch(x, y, z) {
  17864. return (x & y) ^ (~x & z);
  17865. }
  17866. function maj(x, y, z) {
  17867. return (x & y) ^ (x & z) ^ (y & z);
  17868. }
  17869. function sigma(x) {
  17870. return rotr(x, 2) ^ rotr(x, 13) ^ rotr(x, 22);
  17871. }
  17872. function sigmaPrime(x) {
  17873. return rotr(x, 6) ^ rotr(x, 11) ^ rotr(x, 25);
  17874. }
  17875. function littleSigma(x) {
  17876. return rotr(x, 7) ^ rotr(x, 18) ^ x >>> 3;
  17877. }
  17878. function littleSigmaPrime(x) {
  17879. return rotr(x, 17) ^ rotr(x, 19) ^ x >>> 10;
  17880. }
  17881. var k = [0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
  17882. 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
  17883. 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
  17884. 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
  17885. 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
  17886. 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
  17887. 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
  17888. 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
  17889. 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
  17890. 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
  17891. 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
  17892. 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
  17893. 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
  17894. 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
  17895. 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
  17896. 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2];
  17897. function hash(data, offset, length) {
  17898. // initial hash values
  17899. var h0 = 0x6a09e667, h1 = 0xbb67ae85, h2 = 0x3c6ef372,
  17900. h3 = 0xa54ff53a, h4 = 0x510e527f, h5 = 0x9b05688c,
  17901. h6 = 0x1f83d9ab, h7 = 0x5be0cd19;
  17902. // pre-processing
  17903. var paddedLength = Math.ceil((length + 9) / 64) * 64;
  17904. var padded = new Uint8Array(paddedLength);
  17905. var i, j, n;
  17906. for (i = 0; i < length; ++i) {
  17907. padded[i] = data[offset++];
  17908. }
  17909. padded[i++] = 0x80;
  17910. n = paddedLength - 8;
  17911. while (i < n) {
  17912. padded[i++] = 0;
  17913. }
  17914. padded[i++] = 0;
  17915. padded[i++] = 0;
  17916. padded[i++] = 0;
  17917. padded[i++] = (length >>> 29) & 0xFF;
  17918. padded[i++] = (length >> 21) & 0xFF;
  17919. padded[i++] = (length >> 13) & 0xFF;
  17920. padded[i++] = (length >> 5) & 0xFF;
  17921. padded[i++] = (length << 3) & 0xFF;
  17922. var w = new Uint32Array(64);
  17923. // for each 512 bit block
  17924. for (i = 0; i < paddedLength;) {
  17925. for (j = 0; j < 16; ++j) {
  17926. w[j] = (padded[i] << 24 | (padded[i + 1] << 16) |
  17927. (padded[i + 2] << 8) | (padded[i + 3]));
  17928. i += 4;
  17929. }
  17930. for (j = 16; j < 64; ++j) {
  17931. w[j] = littleSigmaPrime(w[j - 2]) + w[j - 7] +
  17932. littleSigma(w[j - 15]) + w[j - 16] | 0;
  17933. }
  17934. var a = h0, b = h1, c = h2, d = h3, e = h4,
  17935. f = h5, g = h6, h = h7, t1, t2;
  17936. for (j = 0; j < 64; ++j) {
  17937. t1 = h + sigmaPrime(e) + ch(e, f, g) + k[j] + w[j];
  17938. t2 = sigma(a) + maj(a, b, c);
  17939. h = g;
  17940. g = f;
  17941. f = e;
  17942. e = (d + t1) | 0;
  17943. d = c;
  17944. c = b;
  17945. b = a;
  17946. a = (t1 + t2) | 0;
  17947. }
  17948. h0 = (h0 + a) | 0;
  17949. h1 = (h1 + b) | 0;
  17950. h2 = (h2 + c) | 0;
  17951. h3 = (h3 + d) | 0;
  17952. h4 = (h4 + e) | 0;
  17953. h5 = (h5 + f) | 0;
  17954. h6 = (h6 + g) | 0;
  17955. h7 = (h7 + h) | 0;
  17956. }
  17957. return new Uint8Array([
  17958. (h0 >> 24) & 0xFF, (h0 >> 16) & 0xFF, (h0 >> 8) & 0xFF, (h0) & 0xFF,
  17959. (h1 >> 24) & 0xFF, (h1 >> 16) & 0xFF, (h1 >> 8) & 0xFF, (h1) & 0xFF,
  17960. (h2 >> 24) & 0xFF, (h2 >> 16) & 0xFF, (h2 >> 8) & 0xFF, (h2) & 0xFF,
  17961. (h3 >> 24) & 0xFF, (h3 >> 16) & 0xFF, (h3 >> 8) & 0xFF, (h3) & 0xFF,
  17962. (h4 >> 24) & 0xFF, (h4 >> 16) & 0xFF, (h4 >> 8) & 0xFF, (h4) & 0xFF,
  17963. (h5 >> 24) & 0xFF, (h5 >> 16) & 0xFF, (h5 >> 8) & 0xFF, (h5) & 0xFF,
  17964. (h6 >> 24) & 0xFF, (h6 >> 16) & 0xFF, (h6 >> 8) & 0xFF, (h6) & 0xFF,
  17965. (h7 >> 24) & 0xFF, (h7 >> 16) & 0xFF, (h7 >> 8) & 0xFF, (h7) & 0xFF
  17966. ]);
  17967. }
  17968. return hash;
  17969. })();
  17970. var calculateSHA512 = (function calculateSHA512Closure() {
  17971. function ch(result, x, y, z, tmp) {
  17972. result.assign(x);
  17973. result.and(y);
  17974. tmp.assign(x);
  17975. tmp.not();
  17976. tmp.and(z);
  17977. result.xor(tmp);
  17978. }
  17979. function maj(result, x, y, z, tmp) {
  17980. result.assign(x);
  17981. result.and(y);
  17982. tmp.assign(x);
  17983. tmp.and(z);
  17984. result.xor(tmp);
  17985. tmp.assign(y);
  17986. tmp.and(z);
  17987. result.xor(tmp);
  17988. }
  17989. function sigma(result, x, tmp) {
  17990. result.assign(x);
  17991. result.rotateRight(28);
  17992. tmp.assign(x);
  17993. tmp.rotateRight(34);
  17994. result.xor(tmp);
  17995. tmp.assign(x);
  17996. tmp.rotateRight(39);
  17997. result.xor(tmp);
  17998. }
  17999. function sigmaPrime(result, x, tmp) {
  18000. result.assign(x);
  18001. result.rotateRight(14);
  18002. tmp.assign(x);
  18003. tmp.rotateRight(18);
  18004. result.xor(tmp);
  18005. tmp.assign(x);
  18006. tmp.rotateRight(41);
  18007. result.xor(tmp);
  18008. }
  18009. function littleSigma(result, x, tmp) {
  18010. result.assign(x);
  18011. result.rotateRight(1);
  18012. tmp.assign(x);
  18013. tmp.rotateRight(8);
  18014. result.xor(tmp);
  18015. tmp.assign(x);
  18016. tmp.shiftRight(7);
  18017. result.xor(tmp);
  18018. }
  18019. function littleSigmaPrime(result, x, tmp) {
  18020. result.assign(x);
  18021. result.rotateRight(19);
  18022. tmp.assign(x);
  18023. tmp.rotateRight(61);
  18024. result.xor(tmp);
  18025. tmp.assign(x);
  18026. tmp.shiftRight(6);
  18027. result.xor(tmp);
  18028. }
  18029. var k = [
  18030. new Word64(0x428a2f98, 0xd728ae22), new Word64(0x71374491, 0x23ef65cd),
  18031. new Word64(0xb5c0fbcf, 0xec4d3b2f), new Word64(0xe9b5dba5, 0x8189dbbc),
  18032. new Word64(0x3956c25b, 0xf348b538), new Word64(0x59f111f1, 0xb605d019),
  18033. new Word64(0x923f82a4, 0xaf194f9b), new Word64(0xab1c5ed5, 0xda6d8118),
  18034. new Word64(0xd807aa98, 0xa3030242), new Word64(0x12835b01, 0x45706fbe),
  18035. new Word64(0x243185be, 0x4ee4b28c), new Word64(0x550c7dc3, 0xd5ffb4e2),
  18036. new Word64(0x72be5d74, 0xf27b896f), new Word64(0x80deb1fe, 0x3b1696b1),
  18037. new Word64(0x9bdc06a7, 0x25c71235), new Word64(0xc19bf174, 0xcf692694),
  18038. new Word64(0xe49b69c1, 0x9ef14ad2), new Word64(0xefbe4786, 0x384f25e3),
  18039. new Word64(0x0fc19dc6, 0x8b8cd5b5), new Word64(0x240ca1cc, 0x77ac9c65),
  18040. new Word64(0x2de92c6f, 0x592b0275), new Word64(0x4a7484aa, 0x6ea6e483),
  18041. new Word64(0x5cb0a9dc, 0xbd41fbd4), new Word64(0x76f988da, 0x831153b5),
  18042. new Word64(0x983e5152, 0xee66dfab), new Word64(0xa831c66d, 0x2db43210),
  18043. new Word64(0xb00327c8, 0x98fb213f), new Word64(0xbf597fc7, 0xbeef0ee4),
  18044. new Word64(0xc6e00bf3, 0x3da88fc2), new Word64(0xd5a79147, 0x930aa725),
  18045. new Word64(0x06ca6351, 0xe003826f), new Word64(0x14292967, 0x0a0e6e70),
  18046. new Word64(0x27b70a85, 0x46d22ffc), new Word64(0x2e1b2138, 0x5c26c926),
  18047. new Word64(0x4d2c6dfc, 0x5ac42aed), new Word64(0x53380d13, 0x9d95b3df),
  18048. new Word64(0x650a7354, 0x8baf63de), new Word64(0x766a0abb, 0x3c77b2a8),
  18049. new Word64(0x81c2c92e, 0x47edaee6), new Word64(0x92722c85, 0x1482353b),
  18050. new Word64(0xa2bfe8a1, 0x4cf10364), new Word64(0xa81a664b, 0xbc423001),
  18051. new Word64(0xc24b8b70, 0xd0f89791), new Word64(0xc76c51a3, 0x0654be30),
  18052. new Word64(0xd192e819, 0xd6ef5218), new Word64(0xd6990624, 0x5565a910),
  18053. new Word64(0xf40e3585, 0x5771202a), new Word64(0x106aa070, 0x32bbd1b8),
  18054. new Word64(0x19a4c116, 0xb8d2d0c8), new Word64(0x1e376c08, 0x5141ab53),
  18055. new Word64(0x2748774c, 0xdf8eeb99), new Word64(0x34b0bcb5, 0xe19b48a8),
  18056. new Word64(0x391c0cb3, 0xc5c95a63), new Word64(0x4ed8aa4a, 0xe3418acb),
  18057. new Word64(0x5b9cca4f, 0x7763e373), new Word64(0x682e6ff3, 0xd6b2b8a3),
  18058. new Word64(0x748f82ee, 0x5defb2fc), new Word64(0x78a5636f, 0x43172f60),
  18059. new Word64(0x84c87814, 0xa1f0ab72), new Word64(0x8cc70208, 0x1a6439ec),
  18060. new Word64(0x90befffa, 0x23631e28), new Word64(0xa4506ceb, 0xde82bde9),
  18061. new Word64(0xbef9a3f7, 0xb2c67915), new Word64(0xc67178f2, 0xe372532b),
  18062. new Word64(0xca273ece, 0xea26619c), new Word64(0xd186b8c7, 0x21c0c207),
  18063. new Word64(0xeada7dd6, 0xcde0eb1e), new Word64(0xf57d4f7f, 0xee6ed178),
  18064. new Word64(0x06f067aa, 0x72176fba), new Word64(0x0a637dc5, 0xa2c898a6),
  18065. new Word64(0x113f9804, 0xbef90dae), new Word64(0x1b710b35, 0x131c471b),
  18066. new Word64(0x28db77f5, 0x23047d84), new Word64(0x32caab7b, 0x40c72493),
  18067. new Word64(0x3c9ebe0a, 0x15c9bebc), new Word64(0x431d67c4, 0x9c100d4c),
  18068. new Word64(0x4cc5d4be, 0xcb3e42b6), new Word64(0x597f299c, 0xfc657e2a),
  18069. new Word64(0x5fcb6fab, 0x3ad6faec), new Word64(0x6c44198c, 0x4a475817)];
  18070. function hash(data, offset, length, mode384) {
  18071. mode384 = !!mode384;
  18072. // initial hash values
  18073. var h0, h1, h2, h3, h4, h5, h6, h7;
  18074. if (!mode384) {
  18075. h0 = new Word64(0x6a09e667, 0xf3bcc908);
  18076. h1 = new Word64(0xbb67ae85, 0x84caa73b);
  18077. h2 = new Word64(0x3c6ef372, 0xfe94f82b);
  18078. h3 = new Word64(0xa54ff53a, 0x5f1d36f1);
  18079. h4 = new Word64(0x510e527f, 0xade682d1);
  18080. h5 = new Word64(0x9b05688c, 0x2b3e6c1f);
  18081. h6 = new Word64(0x1f83d9ab, 0xfb41bd6b);
  18082. h7 = new Word64(0x5be0cd19, 0x137e2179);
  18083. }
  18084. else {
  18085. // SHA384 is exactly the same
  18086. // except with different starting values and a trimmed result
  18087. h0 = new Word64(0xcbbb9d5d, 0xc1059ed8);
  18088. h1 = new Word64(0x629a292a, 0x367cd507);
  18089. h2 = new Word64(0x9159015a, 0x3070dd17);
  18090. h3 = new Word64(0x152fecd8, 0xf70e5939);
  18091. h4 = new Word64(0x67332667, 0xffc00b31);
  18092. h5 = new Word64(0x8eb44a87, 0x68581511);
  18093. h6 = new Word64(0xdb0c2e0d, 0x64f98fa7);
  18094. h7 = new Word64(0x47b5481d, 0xbefa4fa4);
  18095. }
  18096. // pre-processing
  18097. var paddedLength = Math.ceil((length + 17) / 128) * 128;
  18098. var padded = new Uint8Array(paddedLength);
  18099. var i, j, n;
  18100. for (i = 0; i < length; ++i) {
  18101. padded[i] = data[offset++];
  18102. }
  18103. padded[i++] = 0x80;
  18104. n = paddedLength - 16;
  18105. while (i < n) {
  18106. padded[i++] = 0;
  18107. }
  18108. padded[i++] = 0;
  18109. padded[i++] = 0;
  18110. padded[i++] = 0;
  18111. padded[i++] = 0;
  18112. padded[i++] = 0;
  18113. padded[i++] = 0;
  18114. padded[i++] = 0;
  18115. padded[i++] = 0;
  18116. padded[i++] = 0;
  18117. padded[i++] = 0;
  18118. padded[i++] = 0;
  18119. padded[i++] = (length >>> 29) & 0xFF;
  18120. padded[i++] = (length >> 21) & 0xFF;
  18121. padded[i++] = (length >> 13) & 0xFF;
  18122. padded[i++] = (length >> 5) & 0xFF;
  18123. padded[i++] = (length << 3) & 0xFF;
  18124. var w = new Array(80);
  18125. for (i = 0; i < 80; i++) {
  18126. w[i] = new Word64(0, 0);
  18127. }
  18128. var a = new Word64(0, 0), b = new Word64(0, 0), c = new Word64(0, 0);
  18129. var d = new Word64(0, 0), e = new Word64(0, 0), f = new Word64(0, 0);
  18130. var g = new Word64(0, 0), h = new Word64(0, 0);
  18131. var t1 = new Word64(0, 0), t2 = new Word64(0, 0);
  18132. var tmp1 = new Word64(0, 0), tmp2 = new Word64(0, 0), tmp3;
  18133. // for each 1024 bit block
  18134. for (i = 0; i < paddedLength;) {
  18135. for (j = 0; j < 16; ++j) {
  18136. w[j].high = (padded[i] << 24) | (padded[i + 1] << 16) |
  18137. (padded[i + 2] << 8) | (padded[i + 3]);
  18138. w[j].low = (padded[i + 4]) << 24 | (padded[i + 5]) << 16 |
  18139. (padded[i + 6]) << 8 | (padded[i + 7]);
  18140. i += 8;
  18141. }
  18142. for (j = 16; j < 80; ++j) {
  18143. tmp3 = w[j];
  18144. littleSigmaPrime(tmp3, w[j - 2], tmp2);
  18145. tmp3.add(w[j - 7]);
  18146. littleSigma(tmp1, w[j - 15], tmp2);
  18147. tmp3.add(tmp1);
  18148. tmp3.add(w[j - 16]);
  18149. }
  18150. a.assign(h0); b.assign(h1); c.assign(h2); d.assign(h3);
  18151. e.assign(h4); f.assign(h5); g.assign(h6); h.assign(h7);
  18152. for (j = 0; j < 80; ++j) {
  18153. t1.assign(h);
  18154. sigmaPrime(tmp1, e, tmp2);
  18155. t1.add(tmp1);
  18156. ch(tmp1, e, f, g, tmp2);
  18157. t1.add(tmp1);
  18158. t1.add(k[j]);
  18159. t1.add(w[j]);
  18160. sigma(t2, a, tmp2);
  18161. maj(tmp1, a, b, c, tmp2);
  18162. t2.add(tmp1);
  18163. tmp3 = h;
  18164. h = g;
  18165. g = f;
  18166. f = e;
  18167. d.add(t1);
  18168. e = d;
  18169. d = c;
  18170. c = b;
  18171. b = a;
  18172. tmp3.assign(t1);
  18173. tmp3.add(t2);
  18174. a = tmp3;
  18175. }
  18176. h0.add(a);
  18177. h1.add(b);
  18178. h2.add(c);
  18179. h3.add(d);
  18180. h4.add(e);
  18181. h5.add(f);
  18182. h6.add(g);
  18183. h7.add(h);
  18184. }
  18185. var result;
  18186. if (!mode384) {
  18187. result = new Uint8Array(64);
  18188. h0.copyTo(result,0);
  18189. h1.copyTo(result,8);
  18190. h2.copyTo(result,16);
  18191. h3.copyTo(result,24);
  18192. h4.copyTo(result,32);
  18193. h5.copyTo(result,40);
  18194. h6.copyTo(result,48);
  18195. h7.copyTo(result,56);
  18196. }
  18197. else {
  18198. result = new Uint8Array(48);
  18199. h0.copyTo(result,0);
  18200. h1.copyTo(result,8);
  18201. h2.copyTo(result,16);
  18202. h3.copyTo(result,24);
  18203. h4.copyTo(result,32);
  18204. h5.copyTo(result,40);
  18205. }
  18206. return result;
  18207. }
  18208. return hash;
  18209. })();
  18210. var calculateSHA384 = (function calculateSHA384Closure() {
  18211. function hash(data, offset, length) {
  18212. return calculateSHA512(data, offset, length, true);
  18213. }
  18214. return hash;
  18215. })();
  18216. var NullCipher = (function NullCipherClosure() {
  18217. function NullCipher() {
  18218. }
  18219. NullCipher.prototype = {
  18220. decryptBlock: function NullCipher_decryptBlock(data) {
  18221. return data;
  18222. }
  18223. };
  18224. return NullCipher;
  18225. })();
  18226. var AES128Cipher = (function AES128CipherClosure() {
  18227. var rcon = new Uint8Array([
  18228. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  18229. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  18230. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  18231. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  18232. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  18233. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  18234. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  18235. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  18236. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  18237. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  18238. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  18239. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  18240. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  18241. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  18242. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  18243. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  18244. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  18245. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  18246. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  18247. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  18248. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  18249. 0x74, 0xe8, 0xcb, 0x8d]);
  18250. var s = new Uint8Array([
  18251. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  18252. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  18253. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  18254. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  18255. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  18256. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  18257. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  18258. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  18259. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  18260. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  18261. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  18262. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  18263. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  18264. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  18265. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  18266. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  18267. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  18268. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  18269. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  18270. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  18271. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  18272. 0xb0, 0x54, 0xbb, 0x16]);
  18273. var inv_s = new Uint8Array([
  18274. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  18275. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  18276. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  18277. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  18278. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  18279. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  18280. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  18281. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  18282. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  18283. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  18284. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  18285. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  18286. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  18287. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  18288. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  18289. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  18290. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  18291. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  18292. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  18293. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  18294. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  18295. 0x55, 0x21, 0x0c, 0x7d]);
  18296. var mixCol = new Uint8Array(256);
  18297. for (var i = 0; i < 256; i++) {
  18298. if (i < 128) {
  18299. mixCol[i] = i << 1;
  18300. } else {
  18301. mixCol[i] = (i << 1) ^ 0x1b;
  18302. }
  18303. }
  18304. var mix = new Uint32Array([
  18305. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  18306. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  18307. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  18308. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  18309. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  18310. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  18311. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  18312. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  18313. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  18314. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  18315. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  18316. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  18317. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  18318. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  18319. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  18320. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  18321. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  18322. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  18323. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  18324. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  18325. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  18326. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  18327. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  18328. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  18329. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  18330. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  18331. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  18332. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  18333. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  18334. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  18335. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  18336. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  18337. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  18338. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  18339. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  18340. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  18341. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  18342. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  18343. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  18344. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  18345. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  18346. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  18347. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  18348. function expandKey128(cipherKey) {
  18349. var b = 176, result = new Uint8Array(b);
  18350. result.set(cipherKey);
  18351. for (var j = 16, i = 1; j < b; ++i) {
  18352. // RotWord
  18353. var t1 = result[j - 3], t2 = result[j - 2],
  18354. t3 = result[j - 1], t4 = result[j - 4];
  18355. // SubWord
  18356. t1 = s[t1];
  18357. t2 = s[t2];
  18358. t3 = s[t3];
  18359. t4 = s[t4];
  18360. // Rcon
  18361. t1 = t1 ^ rcon[i];
  18362. for (var n = 0; n < 4; ++n) {
  18363. result[j] = (t1 ^= result[j - 16]);
  18364. j++;
  18365. result[j] = (t2 ^= result[j - 16]);
  18366. j++;
  18367. result[j] = (t3 ^= result[j - 16]);
  18368. j++;
  18369. result[j] = (t4 ^= result[j - 16]);
  18370. j++;
  18371. }
  18372. }
  18373. return result;
  18374. }
  18375. function decrypt128(input, key) {
  18376. var state = new Uint8Array(16);
  18377. state.set(input);
  18378. var i, j, k;
  18379. var t, u, v;
  18380. // AddRoundKey
  18381. for (j = 0, k = 160; j < 16; ++j, ++k) {
  18382. state[j] ^= key[k];
  18383. }
  18384. for (i = 9; i >= 1; --i) {
  18385. // InvShiftRows
  18386. t = state[13];
  18387. state[13] = state[9];
  18388. state[9] = state[5];
  18389. state[5] = state[1];
  18390. state[1] = t;
  18391. t = state[14];
  18392. u = state[10];
  18393. state[14] = state[6];
  18394. state[10] = state[2];
  18395. state[6] = t;
  18396. state[2] = u;
  18397. t = state[15];
  18398. u = state[11];
  18399. v = state[7];
  18400. state[15] = state[3];
  18401. state[11] = t;
  18402. state[7] = u;
  18403. state[3] = v;
  18404. // InvSubBytes
  18405. for (j = 0; j < 16; ++j) {
  18406. state[j] = inv_s[state[j]];
  18407. }
  18408. // AddRoundKey
  18409. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  18410. state[j] ^= key[k];
  18411. }
  18412. // InvMixColumns
  18413. for (j = 0; j < 16; j += 4) {
  18414. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  18415. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  18416. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  18417. (s3 >>> 24) ^ (s3 << 8));
  18418. state[j] = (t >>> 24) & 0xFF;
  18419. state[j + 1] = (t >> 16) & 0xFF;
  18420. state[j + 2] = (t >> 8) & 0xFF;
  18421. state[j + 3] = t & 0xFF;
  18422. }
  18423. }
  18424. // InvShiftRows
  18425. t = state[13];
  18426. state[13] = state[9];
  18427. state[9] = state[5];
  18428. state[5] = state[1];
  18429. state[1] = t;
  18430. t = state[14];
  18431. u = state[10];
  18432. state[14] = state[6];
  18433. state[10] = state[2];
  18434. state[6] = t;
  18435. state[2] = u;
  18436. t = state[15];
  18437. u = state[11];
  18438. v = state[7];
  18439. state[15] = state[3];
  18440. state[11] = t;
  18441. state[7] = u;
  18442. state[3] = v;
  18443. for (j = 0; j < 16; ++j) {
  18444. // InvSubBytes
  18445. state[j] = inv_s[state[j]];
  18446. // AddRoundKey
  18447. state[j] ^= key[j];
  18448. }
  18449. return state;
  18450. }
  18451. function encrypt128(input, key) {
  18452. var t, u, v, k;
  18453. var state = new Uint8Array(16);
  18454. state.set(input);
  18455. for (j = 0; j < 16; ++j) {
  18456. // AddRoundKey
  18457. state[j] ^= key[j];
  18458. }
  18459. for (i = 1; i < 10; i++) {
  18460. //SubBytes
  18461. for (j = 0; j < 16; ++j) {
  18462. state[j] = s[state[j]];
  18463. }
  18464. //ShiftRows
  18465. v = state[1];
  18466. state[1] = state[5];
  18467. state[5] = state[9];
  18468. state[9] = state[13];
  18469. state[13] = v;
  18470. v = state[2];
  18471. u = state[6];
  18472. state[2] = state[10];
  18473. state[6] = state[14];
  18474. state[10] = v;
  18475. state[14] = u;
  18476. v = state[3];
  18477. u = state[7];
  18478. t = state[11];
  18479. state[3] = state[15];
  18480. state[7] = v;
  18481. state[11] = u;
  18482. state[15] = t;
  18483. //MixColumns
  18484. for (var j = 0; j < 16; j += 4) {
  18485. var s0 = state[j + 0], s1 = state[j + 1];
  18486. var s2 = state[j + 2], s3 = state[j + 3];
  18487. t = s0 ^ s1 ^ s2 ^ s3;
  18488. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  18489. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  18490. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  18491. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  18492. }
  18493. //AddRoundKey
  18494. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  18495. state[j] ^= key[k];
  18496. }
  18497. }
  18498. //SubBytes
  18499. for (j = 0; j < 16; ++j) {
  18500. state[j] = s[state[j]];
  18501. }
  18502. //ShiftRows
  18503. v = state[1];
  18504. state[1] = state[5];
  18505. state[5] = state[9];
  18506. state[9] = state[13];
  18507. state[13] = v;
  18508. v = state[2];
  18509. u = state[6];
  18510. state[2] = state[10];
  18511. state[6] = state[14];
  18512. state[10] = v;
  18513. state[14] = u;
  18514. v = state[3];
  18515. u = state[7];
  18516. t = state[11];
  18517. state[3] = state[15];
  18518. state[7] = v;
  18519. state[11] = u;
  18520. state[15] = t;
  18521. //AddRoundKey
  18522. for (j = 0, k = 160; j < 16; ++j, ++k) {
  18523. state[j] ^= key[k];
  18524. }
  18525. return state;
  18526. }
  18527. function AES128Cipher(key) {
  18528. this.key = expandKey128(key);
  18529. this.buffer = new Uint8Array(16);
  18530. this.bufferPosition = 0;
  18531. }
  18532. function decryptBlock2(data, finalize) {
  18533. var i, j, ii, sourceLength = data.length,
  18534. buffer = this.buffer, bufferLength = this.bufferPosition,
  18535. result = [], iv = this.iv;
  18536. for (i = 0; i < sourceLength; ++i) {
  18537. buffer[bufferLength] = data[i];
  18538. ++bufferLength;
  18539. if (bufferLength < 16) {
  18540. continue;
  18541. }
  18542. // buffer is full, decrypting
  18543. var plain = decrypt128(buffer, this.key);
  18544. // xor-ing the IV vector to get plain text
  18545. for (j = 0; j < 16; ++j) {
  18546. plain[j] ^= iv[j];
  18547. }
  18548. iv = buffer;
  18549. result.push(plain);
  18550. buffer = new Uint8Array(16);
  18551. bufferLength = 0;
  18552. }
  18553. // saving incomplete buffer
  18554. this.buffer = buffer;
  18555. this.bufferLength = bufferLength;
  18556. this.iv = iv;
  18557. if (result.length === 0) {
  18558. return new Uint8Array([]);
  18559. }
  18560. // combining plain text blocks into one
  18561. var outputLength = 16 * result.length;
  18562. if (finalize) {
  18563. // undo a padding that is described in RFC 2898
  18564. var lastBlock = result[result.length - 1];
  18565. var psLen = lastBlock[15];
  18566. if (psLen <= 16) {
  18567. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  18568. if (lastBlock[i] !== psLen) {
  18569. // Invalid padding, assume that the block has no padding.
  18570. psLen = 0;
  18571. break;
  18572. }
  18573. }
  18574. outputLength -= psLen;
  18575. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  18576. }
  18577. }
  18578. var output = new Uint8Array(outputLength);
  18579. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  18580. output.set(result[i], j);
  18581. }
  18582. return output;
  18583. }
  18584. AES128Cipher.prototype = {
  18585. decryptBlock: function AES128Cipher_decryptBlock(data, finalize) {
  18586. var i, sourceLength = data.length;
  18587. var buffer = this.buffer, bufferLength = this.bufferPosition;
  18588. // waiting for IV values -- they are at the start of the stream
  18589. for (i = 0; bufferLength < 16 && i < sourceLength; ++i, ++bufferLength) {
  18590. buffer[bufferLength] = data[i];
  18591. }
  18592. if (bufferLength < 16) {
  18593. // need more data
  18594. this.bufferLength = bufferLength;
  18595. return new Uint8Array([]);
  18596. }
  18597. this.iv = buffer;
  18598. this.buffer = new Uint8Array(16);
  18599. this.bufferLength = 0;
  18600. // starting decryption
  18601. this.decryptBlock = decryptBlock2;
  18602. return this.decryptBlock(data.subarray(16), finalize);
  18603. },
  18604. encrypt: function AES128Cipher_encrypt(data, iv) {
  18605. var i, j, ii, sourceLength = data.length,
  18606. buffer = this.buffer, bufferLength = this.bufferPosition,
  18607. result = [];
  18608. if (!iv) {
  18609. iv = new Uint8Array(16);
  18610. }
  18611. for (i = 0; i < sourceLength; ++i) {
  18612. buffer[bufferLength] = data[i];
  18613. ++bufferLength;
  18614. if (bufferLength < 16) {
  18615. continue;
  18616. }
  18617. for (j = 0; j < 16; ++j) {
  18618. buffer[j] ^= iv[j];
  18619. }
  18620. // buffer is full, encrypting
  18621. var cipher = encrypt128(buffer, this.key);
  18622. iv = cipher;
  18623. result.push(cipher);
  18624. buffer = new Uint8Array(16);
  18625. bufferLength = 0;
  18626. }
  18627. // saving incomplete buffer
  18628. this.buffer = buffer;
  18629. this.bufferLength = bufferLength;
  18630. this.iv = iv;
  18631. if (result.length === 0) {
  18632. return new Uint8Array([]);
  18633. }
  18634. // combining plain text blocks into one
  18635. var outputLength = 16 * result.length;
  18636. var output = new Uint8Array(outputLength);
  18637. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  18638. output.set(result[i], j);
  18639. }
  18640. return output;
  18641. }
  18642. };
  18643. return AES128Cipher;
  18644. })();
  18645. var AES256Cipher = (function AES256CipherClosure() {
  18646. var rcon = new Uint8Array([
  18647. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  18648. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  18649. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  18650. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  18651. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  18652. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  18653. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  18654. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  18655. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  18656. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  18657. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  18658. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  18659. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  18660. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  18661. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  18662. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  18663. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  18664. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  18665. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  18666. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  18667. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  18668. 0x74, 0xe8, 0xcb, 0x8d]);
  18669. var s = new Uint8Array([
  18670. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  18671. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  18672. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  18673. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  18674. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  18675. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  18676. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  18677. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  18678. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  18679. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  18680. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  18681. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  18682. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  18683. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  18684. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  18685. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  18686. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  18687. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  18688. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  18689. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  18690. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  18691. 0xb0, 0x54, 0xbb, 0x16]);
  18692. var inv_s = new Uint8Array([
  18693. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  18694. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  18695. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  18696. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  18697. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  18698. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  18699. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  18700. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  18701. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  18702. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  18703. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  18704. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  18705. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  18706. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  18707. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  18708. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  18709. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  18710. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  18711. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  18712. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  18713. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  18714. 0x55, 0x21, 0x0c, 0x7d]);
  18715. var mixCol = new Uint8Array(256);
  18716. for (var i = 0; i < 256; i++) {
  18717. if (i < 128) {
  18718. mixCol[i] = i << 1;
  18719. } else {
  18720. mixCol[i] = (i << 1) ^ 0x1b;
  18721. }
  18722. }
  18723. var mix = new Uint32Array([
  18724. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  18725. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  18726. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  18727. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  18728. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  18729. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  18730. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  18731. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  18732. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  18733. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  18734. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  18735. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  18736. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  18737. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  18738. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  18739. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  18740. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  18741. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  18742. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  18743. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  18744. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  18745. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  18746. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  18747. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  18748. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  18749. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  18750. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  18751. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  18752. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  18753. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  18754. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  18755. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  18756. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  18757. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  18758. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  18759. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  18760. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  18761. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  18762. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  18763. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  18764. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  18765. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  18766. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  18767. function expandKey256(cipherKey) {
  18768. var b = 240, result = new Uint8Array(b);
  18769. var r = 1;
  18770. result.set(cipherKey);
  18771. for (var j = 32, i = 1; j < b; ++i) {
  18772. if (j % 32 === 16) {
  18773. t1 = s[t1];
  18774. t2 = s[t2];
  18775. t3 = s[t3];
  18776. t4 = s[t4];
  18777. } else if (j % 32 === 0) {
  18778. // RotWord
  18779. var t1 = result[j - 3], t2 = result[j - 2],
  18780. t3 = result[j - 1], t4 = result[j - 4];
  18781. // SubWord
  18782. t1 = s[t1];
  18783. t2 = s[t2];
  18784. t3 = s[t3];
  18785. t4 = s[t4];
  18786. // Rcon
  18787. t1 = t1 ^ r;
  18788. if ((r <<= 1) >= 256) {
  18789. r = (r ^ 0x1b) & 0xFF;
  18790. }
  18791. }
  18792. for (var n = 0; n < 4; ++n) {
  18793. result[j] = (t1 ^= result[j - 32]);
  18794. j++;
  18795. result[j] = (t2 ^= result[j - 32]);
  18796. j++;
  18797. result[j] = (t3 ^= result[j - 32]);
  18798. j++;
  18799. result[j] = (t4 ^= result[j - 32]);
  18800. j++;
  18801. }
  18802. }
  18803. return result;
  18804. }
  18805. function decrypt256(input, key) {
  18806. var state = new Uint8Array(16);
  18807. state.set(input);
  18808. var i, j, k;
  18809. var t, u, v;
  18810. // AddRoundKey
  18811. for (j = 0, k = 224; j < 16; ++j, ++k) {
  18812. state[j] ^= key[k];
  18813. }
  18814. for (i = 13; i >= 1; --i) {
  18815. // InvShiftRows
  18816. t = state[13];
  18817. state[13] = state[9];
  18818. state[9] = state[5];
  18819. state[5] = state[1];
  18820. state[1] = t;
  18821. t = state[14];
  18822. u = state[10];
  18823. state[14] = state[6];
  18824. state[10] = state[2];
  18825. state[6] = t;
  18826. state[2] = u;
  18827. t = state[15];
  18828. u = state[11];
  18829. v = state[7];
  18830. state[15] = state[3];
  18831. state[11] = t;
  18832. state[7] = u;
  18833. state[3] = v;
  18834. // InvSubBytes
  18835. for (j = 0; j < 16; ++j) {
  18836. state[j] = inv_s[state[j]];
  18837. }
  18838. // AddRoundKey
  18839. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  18840. state[j] ^= key[k];
  18841. }
  18842. // InvMixColumns
  18843. for (j = 0; j < 16; j += 4) {
  18844. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  18845. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  18846. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  18847. (s3 >>> 24) ^ (s3 << 8));
  18848. state[j] = (t >>> 24) & 0xFF;
  18849. state[j + 1] = (t >> 16) & 0xFF;
  18850. state[j + 2] = (t >> 8) & 0xFF;
  18851. state[j + 3] = t & 0xFF;
  18852. }
  18853. }
  18854. // InvShiftRows
  18855. t = state[13];
  18856. state[13] = state[9];
  18857. state[9] = state[5];
  18858. state[5] = state[1];
  18859. state[1] = t;
  18860. t = state[14];
  18861. u = state[10];
  18862. state[14] = state[6];
  18863. state[10] = state[2];
  18864. state[6] = t;
  18865. state[2] = u;
  18866. t = state[15];
  18867. u = state[11];
  18868. v = state[7];
  18869. state[15] = state[3];
  18870. state[11] = t;
  18871. state[7] = u;
  18872. state[3] = v;
  18873. for (j = 0; j < 16; ++j) {
  18874. // InvSubBytes
  18875. state[j] = inv_s[state[j]];
  18876. // AddRoundKey
  18877. state[j] ^= key[j];
  18878. }
  18879. return state;
  18880. }
  18881. function encrypt256(input, key) {
  18882. var t, u, v, k;
  18883. var state = new Uint8Array(16);
  18884. state.set(input);
  18885. for (j = 0; j < 16; ++j) {
  18886. // AddRoundKey
  18887. state[j] ^= key[j];
  18888. }
  18889. for (i = 1; i < 14; i++) {
  18890. //SubBytes
  18891. for (j = 0; j < 16; ++j) {
  18892. state[j] = s[state[j]];
  18893. }
  18894. //ShiftRows
  18895. v = state[1];
  18896. state[1] = state[5];
  18897. state[5] = state[9];
  18898. state[9] = state[13];
  18899. state[13] = v;
  18900. v = state[2];
  18901. u = state[6];
  18902. state[2] = state[10];
  18903. state[6] = state[14];
  18904. state[10] = v;
  18905. state[14] = u;
  18906. v = state[3];
  18907. u = state[7];
  18908. t = state[11];
  18909. state[3] = state[15];
  18910. state[7] = v;
  18911. state[11] = u;
  18912. state[15] = t;
  18913. //MixColumns
  18914. for (var j = 0; j < 16; j += 4) {
  18915. var s0 = state[j + 0], s1 = state[j + 1];
  18916. var s2 = state[j + 2], s3 = state[j + 3];
  18917. t = s0 ^ s1 ^ s2 ^ s3;
  18918. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  18919. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  18920. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  18921. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  18922. }
  18923. //AddRoundKey
  18924. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  18925. state[j] ^= key[k];
  18926. }
  18927. }
  18928. //SubBytes
  18929. for (j = 0; j < 16; ++j) {
  18930. state[j] = s[state[j]];
  18931. }
  18932. //ShiftRows
  18933. v = state[1];
  18934. state[1] = state[5];
  18935. state[5] = state[9];
  18936. state[9] = state[13];
  18937. state[13] = v;
  18938. v = state[2];
  18939. u = state[6];
  18940. state[2] = state[10];
  18941. state[6] = state[14];
  18942. state[10] = v;
  18943. state[14] = u;
  18944. v = state[3];
  18945. u = state[7];
  18946. t = state[11];
  18947. state[3] = state[15];
  18948. state[7] = v;
  18949. state[11] = u;
  18950. state[15] = t;
  18951. //AddRoundKey
  18952. for (j = 0, k = 224; j < 16; ++j, ++k) {
  18953. state[j] ^= key[k];
  18954. }
  18955. return state;
  18956. }
  18957. function AES256Cipher(key) {
  18958. this.key = expandKey256(key);
  18959. this.buffer = new Uint8Array(16);
  18960. this.bufferPosition = 0;
  18961. }
  18962. function decryptBlock2(data, finalize) {
  18963. var i, j, ii, sourceLength = data.length,
  18964. buffer = this.buffer, bufferLength = this.bufferPosition,
  18965. result = [], iv = this.iv;
  18966. for (i = 0; i < sourceLength; ++i) {
  18967. buffer[bufferLength] = data[i];
  18968. ++bufferLength;
  18969. if (bufferLength < 16) {
  18970. continue;
  18971. }
  18972. // buffer is full, decrypting
  18973. var plain = decrypt256(buffer, this.key);
  18974. // xor-ing the IV vector to get plain text
  18975. for (j = 0; j < 16; ++j) {
  18976. plain[j] ^= iv[j];
  18977. }
  18978. iv = buffer;
  18979. result.push(plain);
  18980. buffer = new Uint8Array(16);
  18981. bufferLength = 0;
  18982. }
  18983. // saving incomplete buffer
  18984. this.buffer = buffer;
  18985. this.bufferLength = bufferLength;
  18986. this.iv = iv;
  18987. if (result.length === 0) {
  18988. return new Uint8Array([]);
  18989. }
  18990. // combining plain text blocks into one
  18991. var outputLength = 16 * result.length;
  18992. if (finalize) {
  18993. // undo a padding that is described in RFC 2898
  18994. var lastBlock = result[result.length - 1];
  18995. var psLen = lastBlock[15];
  18996. if (psLen <= 16) {
  18997. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  18998. if (lastBlock[i] !== psLen) {
  18999. // Invalid padding, assume that the block has no padding.
  19000. psLen = 0;
  19001. break;
  19002. }
  19003. }
  19004. outputLength -= psLen;
  19005. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  19006. }
  19007. }
  19008. var output = new Uint8Array(outputLength);
  19009. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  19010. output.set(result[i], j);
  19011. }
  19012. return output;
  19013. }
  19014. AES256Cipher.prototype = {
  19015. decryptBlock: function AES256Cipher_decryptBlock(data, finalize, iv) {
  19016. var i, sourceLength = data.length;
  19017. var buffer = this.buffer, bufferLength = this.bufferPosition;
  19018. // if not supplied an IV wait for IV values
  19019. // they are at the start of the stream
  19020. if (iv) {
  19021. this.iv = iv;
  19022. } else {
  19023. for (i = 0; bufferLength < 16 &&
  19024. i < sourceLength; ++i, ++bufferLength) {
  19025. buffer[bufferLength] = data[i];
  19026. }
  19027. if (bufferLength < 16) {
  19028. //need more data
  19029. this.bufferLength = bufferLength;
  19030. return new Uint8Array([]);
  19031. }
  19032. this.iv = buffer;
  19033. data = data.subarray(16);
  19034. }
  19035. this.buffer = new Uint8Array(16);
  19036. this.bufferLength = 0;
  19037. // starting decryption
  19038. this.decryptBlock = decryptBlock2;
  19039. return this.decryptBlock(data, finalize);
  19040. },
  19041. encrypt: function AES256Cipher_encrypt(data, iv) {
  19042. var i, j, ii, sourceLength = data.length,
  19043. buffer = this.buffer, bufferLength = this.bufferPosition,
  19044. result = [];
  19045. if (!iv) {
  19046. iv = new Uint8Array(16);
  19047. }
  19048. for (i = 0; i < sourceLength; ++i) {
  19049. buffer[bufferLength] = data[i];
  19050. ++bufferLength;
  19051. if (bufferLength < 16) {
  19052. continue;
  19053. }
  19054. for (j = 0; j < 16; ++j) {
  19055. buffer[j] ^= iv[j];
  19056. }
  19057. // buffer is full, encrypting
  19058. var cipher = encrypt256(buffer, this.key);
  19059. this.iv = cipher;
  19060. result.push(cipher);
  19061. buffer = new Uint8Array(16);
  19062. bufferLength = 0;
  19063. }
  19064. // saving incomplete buffer
  19065. this.buffer = buffer;
  19066. this.bufferLength = bufferLength;
  19067. this.iv = iv;
  19068. if (result.length === 0) {
  19069. return new Uint8Array([]);
  19070. }
  19071. // combining plain text blocks into one
  19072. var outputLength = 16 * result.length;
  19073. var output = new Uint8Array(outputLength);
  19074. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  19075. output.set(result[i], j);
  19076. }
  19077. return output;
  19078. }
  19079. };
  19080. return AES256Cipher;
  19081. })();
  19082. var PDF17 = (function PDF17Closure() {
  19083. function compareByteArrays(array1, array2) {
  19084. if (array1.length !== array2.length) {
  19085. return false;
  19086. }
  19087. for (var i = 0; i < array1.length; i++) {
  19088. if (array1[i] !== array2[i]) {
  19089. return false;
  19090. }
  19091. }
  19092. return true;
  19093. }
  19094. function PDF17() {
  19095. }
  19096. PDF17.prototype = {
  19097. checkOwnerPassword: function PDF17_checkOwnerPassword(password,
  19098. ownerValidationSalt,
  19099. userBytes,
  19100. ownerPassword) {
  19101. var hashData = new Uint8Array(password.length + 56);
  19102. hashData.set(password, 0);
  19103. hashData.set(ownerValidationSalt, password.length);
  19104. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  19105. var result = calculateSHA256(hashData, 0, hashData.length);
  19106. return compareByteArrays(result, ownerPassword);
  19107. },
  19108. checkUserPassword: function PDF17_checkUserPassword(password,
  19109. userValidationSalt,
  19110. userPassword) {
  19111. var hashData = new Uint8Array(password.length + 8);
  19112. hashData.set(password, 0);
  19113. hashData.set(userValidationSalt, password.length);
  19114. var result = calculateSHA256(hashData, 0, hashData.length);
  19115. return compareByteArrays(result, userPassword);
  19116. },
  19117. getOwnerKey: function PDF17_getOwnerKey(password, ownerKeySalt, userBytes,
  19118. ownerEncryption) {
  19119. var hashData = new Uint8Array(password.length + 56);
  19120. hashData.set(password, 0);
  19121. hashData.set(ownerKeySalt, password.length);
  19122. hashData.set(userBytes, password.length + ownerKeySalt.length);
  19123. var key = calculateSHA256(hashData, 0, hashData.length);
  19124. var cipher = new AES256Cipher(key);
  19125. return cipher.decryptBlock(ownerEncryption,
  19126. false,
  19127. new Uint8Array(16));
  19128. },
  19129. getUserKey: function PDF17_getUserKey(password, userKeySalt,
  19130. userEncryption) {
  19131. var hashData = new Uint8Array(password.length + 8);
  19132. hashData.set(password, 0);
  19133. hashData.set(userKeySalt, password.length);
  19134. //key is the decryption key for the UE string
  19135. var key = calculateSHA256(hashData, 0, hashData.length);
  19136. var cipher = new AES256Cipher(key);
  19137. return cipher.decryptBlock(userEncryption,
  19138. false,
  19139. new Uint8Array(16));
  19140. }
  19141. };
  19142. return PDF17;
  19143. })();
  19144. var PDF20 = (function PDF20Closure() {
  19145. function concatArrays(array1, array2) {
  19146. var t = new Uint8Array(array1.length + array2.length);
  19147. t.set(array1, 0);
  19148. t.set(array2, array1.length);
  19149. return t;
  19150. }
  19151. function calculatePDF20Hash(password, input, userBytes) {
  19152. //This refers to Algorithm 2.B as defined in ISO 32000-2
  19153. var k = calculateSHA256(input, 0, input.length).subarray(0, 32);
  19154. var e = [0];
  19155. var i = 0;
  19156. while (i < 64 || e[e.length - 1] > i - 32) {
  19157. var arrayLength = password.length + k.length + userBytes.length;
  19158. var k1 = new Uint8Array(arrayLength * 64);
  19159. var array = concatArrays(password, k);
  19160. array = concatArrays(array, userBytes);
  19161. for (var j = 0, pos = 0; j < 64; j++, pos += arrayLength) {
  19162. k1.set(array, pos);
  19163. }
  19164. //AES128 CBC NO PADDING with
  19165. //first 16 bytes of k as the key and the second 16 as the iv.
  19166. var cipher = new AES128Cipher(k.subarray(0, 16));
  19167. e = cipher.encrypt(k1, k.subarray(16, 32));
  19168. //Now we have to take the first 16 bytes of an unsigned
  19169. //big endian integer... and compute the remainder
  19170. //modulo 3.... That is a fairly large number and
  19171. //JavaScript isn't going to handle that well...
  19172. //So we're using a trick that allows us to perform
  19173. //modulo math byte by byte
  19174. var remainder = 0;
  19175. for (var z = 0; z < 16; z++) {
  19176. remainder *= (256 % 3);
  19177. remainder %= 3;
  19178. remainder += ((e[z] >>> 0) % 3);
  19179. remainder %= 3;
  19180. }
  19181. if (remainder === 0) {
  19182. k = calculateSHA256(e, 0, e.length);
  19183. }
  19184. else if (remainder === 1) {
  19185. k = calculateSHA384(e, 0, e.length);
  19186. }
  19187. else if (remainder === 2) {
  19188. k = calculateSHA512(e, 0, e.length);
  19189. }
  19190. i++;
  19191. }
  19192. return k.subarray(0, 32);
  19193. }
  19194. function PDF20() {
  19195. }
  19196. function compareByteArrays(array1, array2) {
  19197. if (array1.length !== array2.length) {
  19198. return false;
  19199. }
  19200. for (var i = 0; i < array1.length; i++) {
  19201. if (array1[i] !== array2[i]) {
  19202. return false;
  19203. }
  19204. }
  19205. return true;
  19206. }
  19207. PDF20.prototype = {
  19208. hash: function PDF20_hash(password, concatBytes, userBytes) {
  19209. return calculatePDF20Hash(password, concatBytes, userBytes);
  19210. },
  19211. checkOwnerPassword: function PDF20_checkOwnerPassword(password,
  19212. ownerValidationSalt,
  19213. userBytes,
  19214. ownerPassword) {
  19215. var hashData = new Uint8Array(password.length + 56);
  19216. hashData.set(password, 0);
  19217. hashData.set(ownerValidationSalt, password.length);
  19218. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  19219. var result = calculatePDF20Hash(password, hashData, userBytes);
  19220. return compareByteArrays(result, ownerPassword);
  19221. },
  19222. checkUserPassword: function PDF20_checkUserPassword(password,
  19223. userValidationSalt,
  19224. userPassword) {
  19225. var hashData = new Uint8Array(password.length + 8);
  19226. hashData.set(password, 0);
  19227. hashData.set(userValidationSalt, password.length);
  19228. var result = calculatePDF20Hash(password, hashData, []);
  19229. return compareByteArrays(result, userPassword);
  19230. },
  19231. getOwnerKey: function PDF20_getOwnerKey(password, ownerKeySalt, userBytes,
  19232. ownerEncryption) {
  19233. var hashData = new Uint8Array(password.length + 56);
  19234. hashData.set(password, 0);
  19235. hashData.set(ownerKeySalt, password.length);
  19236. hashData.set(userBytes, password.length + ownerKeySalt.length);
  19237. var key = calculatePDF20Hash(password, hashData, userBytes);
  19238. var cipher = new AES256Cipher(key);
  19239. return cipher.decryptBlock(ownerEncryption,
  19240. false,
  19241. new Uint8Array(16));
  19242. },
  19243. getUserKey: function PDF20_getUserKey(password, userKeySalt,
  19244. userEncryption) {
  19245. var hashData = new Uint8Array(password.length + 8);
  19246. hashData.set(password, 0);
  19247. hashData.set(userKeySalt, password.length);
  19248. //key is the decryption key for the UE string
  19249. var key = calculatePDF20Hash(password, hashData, []);
  19250. var cipher = new AES256Cipher(key);
  19251. return cipher.decryptBlock(userEncryption,
  19252. false,
  19253. new Uint8Array(16));
  19254. }
  19255. };
  19256. return PDF20;
  19257. })();
  19258. var CipherTransform = (function CipherTransformClosure() {
  19259. function CipherTransform(stringCipherConstructor, streamCipherConstructor) {
  19260. this.stringCipherConstructor = stringCipherConstructor;
  19261. this.streamCipherConstructor = streamCipherConstructor;
  19262. }
  19263. CipherTransform.prototype = {
  19264. createStream: function CipherTransform_createStream(stream, length) {
  19265. var cipher = new this.streamCipherConstructor();
  19266. return new DecryptStream(stream, length,
  19267. function cipherTransformDecryptStream(data, finalize) {
  19268. return cipher.decryptBlock(data, finalize);
  19269. }
  19270. );
  19271. },
  19272. decryptString: function CipherTransform_decryptString(s) {
  19273. var cipher = new this.stringCipherConstructor();
  19274. var data = stringToBytes(s);
  19275. data = cipher.decryptBlock(data, true);
  19276. return bytesToString(data);
  19277. }
  19278. };
  19279. return CipherTransform;
  19280. })();
  19281. var CipherTransformFactory = (function CipherTransformFactoryClosure() {
  19282. var defaultPasswordBytes = new Uint8Array([
  19283. 0x28, 0xBF, 0x4E, 0x5E, 0x4E, 0x75, 0x8A, 0x41,
  19284. 0x64, 0x00, 0x4E, 0x56, 0xFF, 0xFA, 0x01, 0x08,
  19285. 0x2E, 0x2E, 0x00, 0xB6, 0xD0, 0x68, 0x3E, 0x80,
  19286. 0x2F, 0x0C, 0xA9, 0xFE, 0x64, 0x53, 0x69, 0x7A]);
  19287. function createEncryptionKey20(revision, password, ownerPassword,
  19288. ownerValidationSalt, ownerKeySalt, uBytes,
  19289. userPassword, userValidationSalt, userKeySalt,
  19290. ownerEncryption, userEncryption, perms) {
  19291. if (password) {
  19292. var passwordLength = Math.min(127, password.length);
  19293. password = password.subarray(0, passwordLength);
  19294. } else {
  19295. password = [];
  19296. }
  19297. var pdfAlgorithm;
  19298. if (revision === 6) {
  19299. pdfAlgorithm = new PDF20();
  19300. } else {
  19301. pdfAlgorithm = new PDF17();
  19302. }
  19303. if (pdfAlgorithm) {
  19304. if (pdfAlgorithm.checkUserPassword(password, userValidationSalt,
  19305. userPassword)) {
  19306. return pdfAlgorithm.getUserKey(password, userKeySalt, userEncryption);
  19307. } else if (password.length && pdfAlgorithm.checkOwnerPassword(password,
  19308. ownerValidationSalt,
  19309. uBytes,
  19310. ownerPassword)) {
  19311. return pdfAlgorithm.getOwnerKey(password, ownerKeySalt, uBytes,
  19312. ownerEncryption);
  19313. }
  19314. }
  19315. return null;
  19316. }
  19317. function prepareKeyData(fileId, password, ownerPassword, userPassword,
  19318. flags, revision, keyLength, encryptMetadata) {
  19319. var hashDataSize = 40 + ownerPassword.length + fileId.length;
  19320. var hashData = new Uint8Array(hashDataSize), i = 0, j, n;
  19321. if (password) {
  19322. n = Math.min(32, password.length);
  19323. for (; i < n; ++i) {
  19324. hashData[i] = password[i];
  19325. }
  19326. }
  19327. j = 0;
  19328. while (i < 32) {
  19329. hashData[i++] = defaultPasswordBytes[j++];
  19330. }
  19331. // as now the padded password in the hashData[0..i]
  19332. for (j = 0, n = ownerPassword.length; j < n; ++j) {
  19333. hashData[i++] = ownerPassword[j];
  19334. }
  19335. hashData[i++] = flags & 0xFF;
  19336. hashData[i++] = (flags >> 8) & 0xFF;
  19337. hashData[i++] = (flags >> 16) & 0xFF;
  19338. hashData[i++] = (flags >>> 24) & 0xFF;
  19339. for (j = 0, n = fileId.length; j < n; ++j) {
  19340. hashData[i++] = fileId[j];
  19341. }
  19342. if (revision >= 4 && !encryptMetadata) {
  19343. hashData[i++] = 0xFF;
  19344. hashData[i++] = 0xFF;
  19345. hashData[i++] = 0xFF;
  19346. hashData[i++] = 0xFF;
  19347. }
  19348. var hash = calculateMD5(hashData, 0, i);
  19349. var keyLengthInBytes = keyLength >> 3;
  19350. if (revision >= 3) {
  19351. for (j = 0; j < 50; ++j) {
  19352. hash = calculateMD5(hash, 0, keyLengthInBytes);
  19353. }
  19354. }
  19355. var encryptionKey = hash.subarray(0, keyLengthInBytes);
  19356. var cipher, checkData;
  19357. if (revision >= 3) {
  19358. for (i = 0; i < 32; ++i) {
  19359. hashData[i] = defaultPasswordBytes[i];
  19360. }
  19361. for (j = 0, n = fileId.length; j < n; ++j) {
  19362. hashData[i++] = fileId[j];
  19363. }
  19364. cipher = new ARCFourCipher(encryptionKey);
  19365. checkData = cipher.encryptBlock(calculateMD5(hashData, 0, i));
  19366. n = encryptionKey.length;
  19367. var derivedKey = new Uint8Array(n), k;
  19368. for (j = 1; j <= 19; ++j) {
  19369. for (k = 0; k < n; ++k) {
  19370. derivedKey[k] = encryptionKey[k] ^ j;
  19371. }
  19372. cipher = new ARCFourCipher(derivedKey);
  19373. checkData = cipher.encryptBlock(checkData);
  19374. }
  19375. for (j = 0, n = checkData.length; j < n; ++j) {
  19376. if (userPassword[j] !== checkData[j]) {
  19377. return null;
  19378. }
  19379. }
  19380. } else {
  19381. cipher = new ARCFourCipher(encryptionKey);
  19382. checkData = cipher.encryptBlock(defaultPasswordBytes);
  19383. for (j = 0, n = checkData.length; j < n; ++j) {
  19384. if (userPassword[j] !== checkData[j]) {
  19385. return null;
  19386. }
  19387. }
  19388. }
  19389. return encryptionKey;
  19390. }
  19391. function decodeUserPassword(password, ownerPassword, revision, keyLength) {
  19392. var hashData = new Uint8Array(32), i = 0, j, n;
  19393. n = Math.min(32, password.length);
  19394. for (; i < n; ++i) {
  19395. hashData[i] = password[i];
  19396. }
  19397. j = 0;
  19398. while (i < 32) {
  19399. hashData[i++] = defaultPasswordBytes[j++];
  19400. }
  19401. var hash = calculateMD5(hashData, 0, i);
  19402. var keyLengthInBytes = keyLength >> 3;
  19403. if (revision >= 3) {
  19404. for (j = 0; j < 50; ++j) {
  19405. hash = calculateMD5(hash, 0, hash.length);
  19406. }
  19407. }
  19408. var cipher, userPassword;
  19409. if (revision >= 3) {
  19410. userPassword = ownerPassword;
  19411. var derivedKey = new Uint8Array(keyLengthInBytes), k;
  19412. for (j = 19; j >= 0; j--) {
  19413. for (k = 0; k < keyLengthInBytes; ++k) {
  19414. derivedKey[k] = hash[k] ^ j;
  19415. }
  19416. cipher = new ARCFourCipher(derivedKey);
  19417. userPassword = cipher.encryptBlock(userPassword);
  19418. }
  19419. } else {
  19420. cipher = new ARCFourCipher(hash.subarray(0, keyLengthInBytes));
  19421. userPassword = cipher.encryptBlock(ownerPassword);
  19422. }
  19423. return userPassword;
  19424. }
  19425. var identityName = Name.get('Identity');
  19426. function CipherTransformFactory(dict, fileId, password) {
  19427. var filter = dict.get('Filter');
  19428. if (!isName(filter) || filter.name !== 'Standard') {
  19429. error('unknown encryption method');
  19430. }
  19431. this.dict = dict;
  19432. var algorithm = dict.get('V');
  19433. if (!isInt(algorithm) ||
  19434. (algorithm !== 1 && algorithm !== 2 && algorithm !== 4 &&
  19435. algorithm !== 5)) {
  19436. error('unsupported encryption algorithm');
  19437. }
  19438. this.algorithm = algorithm;
  19439. var keyLength = dict.get('Length');
  19440. if (!keyLength) {
  19441. // Spec asks to rely on encryption dictionary's Length entry, however
  19442. // some PDFs don't have it. Trying to recover.
  19443. if (algorithm <= 3) {
  19444. // For 1 and 2 it's fixed to 40-bit, for 3 40-bit is a minimal value.
  19445. keyLength = 40;
  19446. } else {
  19447. // Trying to find default handler -- it usually has Length.
  19448. var cfDict = dict.get('CF');
  19449. var streamCryptoName = dict.get('StmF');
  19450. if (isDict(cfDict) && isName(streamCryptoName)) {
  19451. var handlerDict = cfDict.get(streamCryptoName.name);
  19452. keyLength = (handlerDict && handlerDict.get('Length')) || 128;
  19453. if (keyLength < 40) {
  19454. // Sometimes it's incorrect value of bits, generators specify bytes.
  19455. keyLength <<= 3;
  19456. }
  19457. }
  19458. }
  19459. }
  19460. if (!isInt(keyLength) ||
  19461. keyLength < 40 || (keyLength % 8) !== 0) {
  19462. error('invalid key length');
  19463. }
  19464. // prepare keys
  19465. var ownerPassword = stringToBytes(dict.get('O')).subarray(0, 32);
  19466. var userPassword = stringToBytes(dict.get('U')).subarray(0, 32);
  19467. var flags = dict.get('P');
  19468. var revision = dict.get('R');
  19469. // meaningful when V is 4 or 5
  19470. var encryptMetadata = ((algorithm === 4 || algorithm === 5) &&
  19471. dict.get('EncryptMetadata') !== false);
  19472. this.encryptMetadata = encryptMetadata;
  19473. var fileIdBytes = stringToBytes(fileId);
  19474. var passwordBytes;
  19475. if (password) {
  19476. if (revision === 6) {
  19477. try {
  19478. password = utf8StringToString(password);
  19479. } catch (ex) {
  19480. warn('CipherTransformFactory: ' +
  19481. 'Unable to convert UTF8 encoded password.');
  19482. }
  19483. }
  19484. passwordBytes = stringToBytes(password);
  19485. }
  19486. var encryptionKey;
  19487. if (algorithm !== 5) {
  19488. encryptionKey = prepareKeyData(fileIdBytes, passwordBytes,
  19489. ownerPassword, userPassword, flags,
  19490. revision, keyLength, encryptMetadata);
  19491. }
  19492. else {
  19493. var ownerValidationSalt = stringToBytes(dict.get('O')).subarray(32, 40);
  19494. var ownerKeySalt = stringToBytes(dict.get('O')).subarray(40, 48);
  19495. var uBytes = stringToBytes(dict.get('U')).subarray(0, 48);
  19496. var userValidationSalt = stringToBytes(dict.get('U')).subarray(32, 40);
  19497. var userKeySalt = stringToBytes(dict.get('U')).subarray(40, 48);
  19498. var ownerEncryption = stringToBytes(dict.get('OE'));
  19499. var userEncryption = stringToBytes(dict.get('UE'));
  19500. var perms = stringToBytes(dict.get('Perms'));
  19501. encryptionKey =
  19502. createEncryptionKey20(revision, passwordBytes,
  19503. ownerPassword, ownerValidationSalt,
  19504. ownerKeySalt, uBytes,
  19505. userPassword, userValidationSalt,
  19506. userKeySalt, ownerEncryption,
  19507. userEncryption, perms);
  19508. }
  19509. if (!encryptionKey && !password) {
  19510. throw new PasswordException('No password given',
  19511. PasswordResponses.NEED_PASSWORD);
  19512. } else if (!encryptionKey && password) {
  19513. // Attempting use the password as an owner password
  19514. var decodedPassword = decodeUserPassword(passwordBytes, ownerPassword,
  19515. revision, keyLength);
  19516. encryptionKey = prepareKeyData(fileIdBytes, decodedPassword,
  19517. ownerPassword, userPassword, flags,
  19518. revision, keyLength, encryptMetadata);
  19519. }
  19520. if (!encryptionKey) {
  19521. throw new PasswordException('Incorrect Password',
  19522. PasswordResponses.INCORRECT_PASSWORD);
  19523. }
  19524. this.encryptionKey = encryptionKey;
  19525. if (algorithm >= 4) {
  19526. this.cf = dict.get('CF');
  19527. this.stmf = dict.get('StmF') || identityName;
  19528. this.strf = dict.get('StrF') || identityName;
  19529. this.eff = dict.get('EFF') || this.stmf;
  19530. }
  19531. }
  19532. function buildObjectKey(num, gen, encryptionKey, isAes) {
  19533. var key = new Uint8Array(encryptionKey.length + 9), i, n;
  19534. for (i = 0, n = encryptionKey.length; i < n; ++i) {
  19535. key[i] = encryptionKey[i];
  19536. }
  19537. key[i++] = num & 0xFF;
  19538. key[i++] = (num >> 8) & 0xFF;
  19539. key[i++] = (num >> 16) & 0xFF;
  19540. key[i++] = gen & 0xFF;
  19541. key[i++] = (gen >> 8) & 0xFF;
  19542. if (isAes) {
  19543. key[i++] = 0x73;
  19544. key[i++] = 0x41;
  19545. key[i++] = 0x6C;
  19546. key[i++] = 0x54;
  19547. }
  19548. var hash = calculateMD5(key, 0, i);
  19549. return hash.subarray(0, Math.min(encryptionKey.length + 5, 16));
  19550. }
  19551. function buildCipherConstructor(cf, name, num, gen, key) {
  19552. var cryptFilter = cf.get(name.name);
  19553. var cfm;
  19554. if (cryptFilter !== null && cryptFilter !== undefined) {
  19555. cfm = cryptFilter.get('CFM');
  19556. }
  19557. if (!cfm || cfm.name === 'None') {
  19558. return function cipherTransformFactoryBuildCipherConstructorNone() {
  19559. return new NullCipher();
  19560. };
  19561. }
  19562. if ('V2' === cfm.name) {
  19563. return function cipherTransformFactoryBuildCipherConstructorV2() {
  19564. return new ARCFourCipher(buildObjectKey(num, gen, key, false));
  19565. };
  19566. }
  19567. if ('AESV2' === cfm.name) {
  19568. return function cipherTransformFactoryBuildCipherConstructorAESV2() {
  19569. return new AES128Cipher(buildObjectKey(num, gen, key, true));
  19570. };
  19571. }
  19572. if ('AESV3' === cfm.name) {
  19573. return function cipherTransformFactoryBuildCipherConstructorAESV3() {
  19574. return new AES256Cipher(key);
  19575. };
  19576. }
  19577. error('Unknown crypto method');
  19578. }
  19579. CipherTransformFactory.prototype = {
  19580. createCipherTransform:
  19581. function CipherTransformFactory_createCipherTransform(num, gen) {
  19582. if (this.algorithm === 4 || this.algorithm === 5) {
  19583. return new CipherTransform(
  19584. buildCipherConstructor(this.cf, this.stmf,
  19585. num, gen, this.encryptionKey),
  19586. buildCipherConstructor(this.cf, this.strf,
  19587. num, gen, this.encryptionKey));
  19588. }
  19589. // algorithms 1 and 2
  19590. var key = buildObjectKey(num, gen, this.encryptionKey, false);
  19591. var cipherConstructor = function buildCipherCipherConstructor() {
  19592. return new ARCFourCipher(key);
  19593. };
  19594. return new CipherTransform(cipherConstructor, cipherConstructor);
  19595. }
  19596. };
  19597. return CipherTransformFactory;
  19598. })();
  19599. exports.AES128Cipher = AES128Cipher;
  19600. exports.AES256Cipher = AES256Cipher;
  19601. exports.ARCFourCipher = ARCFourCipher;
  19602. exports.CipherTransformFactory = CipherTransformFactory;
  19603. exports.PDF17 = PDF17;
  19604. exports.PDF20 = PDF20;
  19605. exports.calculateMD5 = calculateMD5;
  19606. exports.calculateSHA256 = calculateSHA256;
  19607. exports.calculateSHA384 = calculateSHA384;
  19608. exports.calculateSHA512 = calculateSHA512;
  19609. }));
  19610. (function (root, factory) {
  19611. {
  19612. factory((root.pdfjsCoreFontRenderer = {}), root.pdfjsSharedUtil,
  19613. root.pdfjsCoreStream, root.pdfjsCoreGlyphList);
  19614. }
  19615. }(this, function (exports, sharedUtil, coreStream, coreGlyphList) {
  19616. var Util = sharedUtil.Util;
  19617. var bytesToString = sharedUtil.bytesToString;
  19618. var error = sharedUtil.error;
  19619. var Stream = coreStream.Stream;
  19620. var GlyphsUnicode = coreGlyphList.GlyphsUnicode;
  19621. var coreFonts; // see _setCoreFonts below
  19622. var CFFParser; // = coreFonts.CFFParser;
  19623. var Encodings; // = coreFonts.Encodings;
  19624. var FontRendererFactory = (function FontRendererFactoryClosure() {
  19625. function getLong(data, offset) {
  19626. return (data[offset] << 24) | (data[offset + 1] << 16) |
  19627. (data[offset + 2] << 8) | data[offset + 3];
  19628. }
  19629. function getUshort(data, offset) {
  19630. return (data[offset] << 8) | data[offset + 1];
  19631. }
  19632. function parseCmap(data, start, end) {
  19633. var offset = (getUshort(data, start + 2) === 1 ?
  19634. getLong(data, start + 8) : getLong(data, start + 16));
  19635. var format = getUshort(data, start + offset);
  19636. var length, ranges, p, i;
  19637. if (format === 4) {
  19638. length = getUshort(data, start + offset + 2);
  19639. var segCount = getUshort(data, start + offset + 6) >> 1;
  19640. p = start + offset + 14;
  19641. ranges = [];
  19642. for (i = 0; i < segCount; i++, p += 2) {
  19643. ranges[i] = {end: getUshort(data, p)};
  19644. }
  19645. p += 2;
  19646. for (i = 0; i < segCount; i++, p += 2) {
  19647. ranges[i].start = getUshort(data, p);
  19648. }
  19649. for (i = 0; i < segCount; i++, p += 2) {
  19650. ranges[i].idDelta = getUshort(data, p);
  19651. }
  19652. for (i = 0; i < segCount; i++, p += 2) {
  19653. var idOffset = getUshort(data, p);
  19654. if (idOffset === 0) {
  19655. continue;
  19656. }
  19657. ranges[i].ids = [];
  19658. for (var j = 0, jj = ranges[i].end - ranges[i].start + 1; j < jj; j++) {
  19659. ranges[i].ids[j] = getUshort(data, p + idOffset);
  19660. idOffset += 2;
  19661. }
  19662. }
  19663. return ranges;
  19664. } else if (format === 12) {
  19665. length = getLong(data, start + offset + 4);
  19666. var groups = getLong(data, start + offset + 12);
  19667. p = start + offset + 16;
  19668. ranges = [];
  19669. for (i = 0; i < groups; i++) {
  19670. ranges.push({
  19671. start: getLong(data, p),
  19672. end: getLong(data, p + 4),
  19673. idDelta: getLong(data, p + 8) - getLong(data, p)
  19674. });
  19675. p += 12;
  19676. }
  19677. return ranges;
  19678. }
  19679. error('not supported cmap: ' + format);
  19680. }
  19681. function parseCff(data, start, end) {
  19682. var properties = {};
  19683. var parser = new CFFParser(new Stream(data, start, end - start),
  19684. properties);
  19685. var cff = parser.parse();
  19686. return {
  19687. glyphs: cff.charStrings.objects,
  19688. subrs: (cff.topDict.privateDict && cff.topDict.privateDict.subrsIndex &&
  19689. cff.topDict.privateDict.subrsIndex.objects),
  19690. gsubrs: cff.globalSubrIndex && cff.globalSubrIndex.objects
  19691. };
  19692. }
  19693. function parseGlyfTable(glyf, loca, isGlyphLocationsLong) {
  19694. var itemSize, itemDecode;
  19695. if (isGlyphLocationsLong) {
  19696. itemSize = 4;
  19697. itemDecode = function fontItemDecodeLong(data, offset) {
  19698. return (data[offset] << 24) | (data[offset + 1] << 16) |
  19699. (data[offset + 2] << 8) | data[offset + 3];
  19700. };
  19701. } else {
  19702. itemSize = 2;
  19703. itemDecode = function fontItemDecode(data, offset) {
  19704. return (data[offset] << 9) | (data[offset + 1] << 1);
  19705. };
  19706. }
  19707. var glyphs = [];
  19708. var startOffset = itemDecode(loca, 0);
  19709. for (var j = itemSize; j < loca.length; j += itemSize) {
  19710. var endOffset = itemDecode(loca, j);
  19711. glyphs.push(glyf.subarray(startOffset, endOffset));
  19712. startOffset = endOffset;
  19713. }
  19714. return glyphs;
  19715. }
  19716. function lookupCmap(ranges, unicode) {
  19717. var code = unicode.charCodeAt(0);
  19718. var l = 0, r = ranges.length - 1;
  19719. while (l < r) {
  19720. var c = (l + r + 1) >> 1;
  19721. if (code < ranges[c].start) {
  19722. r = c - 1;
  19723. } else {
  19724. l = c;
  19725. }
  19726. }
  19727. if (ranges[l].start <= code && code <= ranges[l].end) {
  19728. return (ranges[l].idDelta + (ranges[l].ids ?
  19729. ranges[l].ids[code - ranges[l].start] : code)) & 0xFFFF;
  19730. }
  19731. return 0;
  19732. }
  19733. function compileGlyf(code, cmds, font) {
  19734. function moveTo(x, y) {
  19735. cmds.push({cmd: 'moveTo', args: [x, y]});
  19736. }
  19737. function lineTo(x, y) {
  19738. cmds.push({cmd: 'lineTo', args: [x, y]});
  19739. }
  19740. function quadraticCurveTo(xa, ya, x, y) {
  19741. cmds.push({cmd: 'quadraticCurveTo', args: [xa, ya, x, y]});
  19742. }
  19743. var i = 0;
  19744. var numberOfContours = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  19745. var flags;
  19746. var x = 0, y = 0;
  19747. i += 10;
  19748. if (numberOfContours < 0) {
  19749. // composite glyph
  19750. do {
  19751. flags = (code[i] << 8) | code[i + 1];
  19752. var glyphIndex = (code[i + 2] << 8) | code[i + 3];
  19753. i += 4;
  19754. var arg1, arg2;
  19755. if ((flags & 0x01)) {
  19756. arg1 = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  19757. arg2 = ((code[i + 2] << 24) | (code[i + 3] << 16)) >> 16;
  19758. i += 4;
  19759. } else {
  19760. arg1 = code[i++]; arg2 = code[i++];
  19761. }
  19762. if ((flags & 0x02)) {
  19763. x = arg1;
  19764. y = arg2;
  19765. } else {
  19766. x = 0; y = 0; // TODO "they are points" ?
  19767. }
  19768. var scaleX = 1, scaleY = 1, scale01 = 0, scale10 = 0;
  19769. if ((flags & 0x08)) {
  19770. scaleX =
  19771. scaleY = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  19772. i += 2;
  19773. } else if ((flags & 0x40)) {
  19774. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  19775. scaleY = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  19776. i += 4;
  19777. } else if ((flags & 0x80)) {
  19778. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  19779. scale01 = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  19780. scale10 = ((code[i + 4] << 24) | (code[i + 5] << 16)) / 1073741824;
  19781. scaleY = ((code[i + 6] << 24) | (code[i + 7] << 16)) / 1073741824;
  19782. i += 8;
  19783. }
  19784. var subglyph = font.glyphs[glyphIndex];
  19785. if (subglyph) {
  19786. cmds.push({cmd: 'save'});
  19787. cmds.push({cmd: 'transform',
  19788. args: [scaleX, scale01, scale10, scaleY, x, y]});
  19789. compileGlyf(subglyph, cmds, font);
  19790. cmds.push({cmd: 'restore'});
  19791. }
  19792. } while ((flags & 0x20));
  19793. } else {
  19794. // simple glyph
  19795. var endPtsOfContours = [];
  19796. var j, jj;
  19797. for (j = 0; j < numberOfContours; j++) {
  19798. endPtsOfContours.push((code[i] << 8) | code[i + 1]);
  19799. i += 2;
  19800. }
  19801. var instructionLength = (code[i] << 8) | code[i + 1];
  19802. i += 2 + instructionLength; // skipping the instructions
  19803. var numberOfPoints = endPtsOfContours[endPtsOfContours.length - 1] + 1;
  19804. var points = [];
  19805. while (points.length < numberOfPoints) {
  19806. flags = code[i++];
  19807. var repeat = 1;
  19808. if ((flags & 0x08)) {
  19809. repeat += code[i++];
  19810. }
  19811. while (repeat-- > 0) {
  19812. points.push({flags: flags});
  19813. }
  19814. }
  19815. for (j = 0; j < numberOfPoints; j++) {
  19816. switch (points[j].flags & 0x12) {
  19817. case 0x00:
  19818. x += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  19819. i += 2;
  19820. break;
  19821. case 0x02:
  19822. x -= code[i++];
  19823. break;
  19824. case 0x12:
  19825. x += code[i++];
  19826. break;
  19827. }
  19828. points[j].x = x;
  19829. }
  19830. for (j = 0; j < numberOfPoints; j++) {
  19831. switch (points[j].flags & 0x24) {
  19832. case 0x00:
  19833. y += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  19834. i += 2;
  19835. break;
  19836. case 0x04:
  19837. y -= code[i++];
  19838. break;
  19839. case 0x24:
  19840. y += code[i++];
  19841. break;
  19842. }
  19843. points[j].y = y;
  19844. }
  19845. var startPoint = 0;
  19846. for (i = 0; i < numberOfContours; i++) {
  19847. var endPoint = endPtsOfContours[i];
  19848. // contours might have implicit points, which is located in the middle
  19849. // between two neighboring off-curve points
  19850. var contour = points.slice(startPoint, endPoint + 1);
  19851. if ((contour[0].flags & 1)) {
  19852. contour.push(contour[0]); // using start point at the contour end
  19853. } else if ((contour[contour.length - 1].flags & 1)) {
  19854. // first is off-curve point, trying to use one from the end
  19855. contour.unshift(contour[contour.length - 1]);
  19856. } else {
  19857. // start and end are off-curve points, creating implicit one
  19858. var p = {
  19859. flags: 1,
  19860. x: (contour[0].x + contour[contour.length - 1].x) / 2,
  19861. y: (contour[0].y + contour[contour.length - 1].y) / 2
  19862. };
  19863. contour.unshift(p);
  19864. contour.push(p);
  19865. }
  19866. moveTo(contour[0].x, contour[0].y);
  19867. for (j = 1, jj = contour.length; j < jj; j++) {
  19868. if ((contour[j].flags & 1)) {
  19869. lineTo(contour[j].x, contour[j].y);
  19870. } else if ((contour[j + 1].flags & 1)){
  19871. quadraticCurveTo(contour[j].x, contour[j].y,
  19872. contour[j + 1].x, contour[j + 1].y);
  19873. j++;
  19874. } else {
  19875. quadraticCurveTo(contour[j].x, contour[j].y,
  19876. (contour[j].x + contour[j + 1].x) / 2,
  19877. (contour[j].y + contour[j + 1].y) / 2);
  19878. }
  19879. }
  19880. startPoint = endPoint + 1;
  19881. }
  19882. }
  19883. }
  19884. function compileCharString(code, cmds, font) {
  19885. var stack = [];
  19886. var x = 0, y = 0;
  19887. var stems = 0;
  19888. function moveTo(x, y) {
  19889. cmds.push({cmd: 'moveTo', args: [x, y]});
  19890. }
  19891. function lineTo(x, y) {
  19892. cmds.push({cmd: 'lineTo', args: [x, y]});
  19893. }
  19894. function bezierCurveTo(x1, y1, x2, y2, x, y) {
  19895. cmds.push({cmd: 'bezierCurveTo', args: [x1, y1, x2, y2, x, y]});
  19896. }
  19897. function parse(code) {
  19898. var i = 0;
  19899. while (i < code.length) {
  19900. var stackClean = false;
  19901. var v = code[i++];
  19902. var xa, xb, ya, yb, y1, y2, y3, n, subrCode;
  19903. switch (v) {
  19904. case 1: // hstem
  19905. stems += stack.length >> 1;
  19906. stackClean = true;
  19907. break;
  19908. case 3: // vstem
  19909. stems += stack.length >> 1;
  19910. stackClean = true;
  19911. break;
  19912. case 4: // vmoveto
  19913. y += stack.pop();
  19914. moveTo(x, y);
  19915. stackClean = true;
  19916. break;
  19917. case 5: // rlineto
  19918. while (stack.length > 0) {
  19919. x += stack.shift();
  19920. y += stack.shift();
  19921. lineTo(x, y);
  19922. }
  19923. break;
  19924. case 6: // hlineto
  19925. while (stack.length > 0) {
  19926. x += stack.shift();
  19927. lineTo(x, y);
  19928. if (stack.length === 0) {
  19929. break;
  19930. }
  19931. y += stack.shift();
  19932. lineTo(x, y);
  19933. }
  19934. break;
  19935. case 7: // vlineto
  19936. while (stack.length > 0) {
  19937. y += stack.shift();
  19938. lineTo(x, y);
  19939. if (stack.length === 0) {
  19940. break;
  19941. }
  19942. x += stack.shift();
  19943. lineTo(x, y);
  19944. }
  19945. break;
  19946. case 8: // rrcurveto
  19947. while (stack.length > 0) {
  19948. xa = x + stack.shift(); ya = y + stack.shift();
  19949. xb = xa + stack.shift(); yb = ya + stack.shift();
  19950. x = xb + stack.shift(); y = yb + stack.shift();
  19951. bezierCurveTo(xa, ya, xb, yb, x, y);
  19952. }
  19953. break;
  19954. case 10: // callsubr
  19955. n = stack.pop() + font.subrsBias;
  19956. subrCode = font.subrs[n];
  19957. if (subrCode) {
  19958. parse(subrCode);
  19959. }
  19960. break;
  19961. case 11: // return
  19962. return;
  19963. case 12:
  19964. v = code[i++];
  19965. switch (v) {
  19966. case 34: // flex
  19967. xa = x + stack.shift();
  19968. xb = xa + stack.shift(); y1 = y + stack.shift();
  19969. x = xb + stack.shift();
  19970. bezierCurveTo(xa, y, xb, y1, x, y1);
  19971. xa = x + stack.shift();
  19972. xb = xa + stack.shift();
  19973. x = xb + stack.shift();
  19974. bezierCurveTo(xa, y1, xb, y, x, y);
  19975. break;
  19976. case 35: // flex
  19977. xa = x + stack.shift(); ya = y + stack.shift();
  19978. xb = xa + stack.shift(); yb = ya + stack.shift();
  19979. x = xb + stack.shift(); y = yb + stack.shift();
  19980. bezierCurveTo(xa, ya, xb, yb, x, y);
  19981. xa = x + stack.shift(); ya = y + stack.shift();
  19982. xb = xa + stack.shift(); yb = ya + stack.shift();
  19983. x = xb + stack.shift(); y = yb + stack.shift();
  19984. bezierCurveTo(xa, ya, xb, yb, x, y);
  19985. stack.pop(); // fd
  19986. break;
  19987. case 36: // hflex1
  19988. xa = x + stack.shift(); y1 = y + stack.shift();
  19989. xb = xa + stack.shift(); y2 = y1 + stack.shift();
  19990. x = xb + stack.shift();
  19991. bezierCurveTo(xa, y1, xb, y2, x, y2);
  19992. xa = x + stack.shift();
  19993. xb = xa + stack.shift(); y3 = y2 + stack.shift();
  19994. x = xb + stack.shift();
  19995. bezierCurveTo(xa, y2, xb, y3, x, y);
  19996. break;
  19997. case 37: // flex1
  19998. var x0 = x, y0 = y;
  19999. xa = x + stack.shift(); ya = y + stack.shift();
  20000. xb = xa + stack.shift(); yb = ya + stack.shift();
  20001. x = xb + stack.shift(); y = yb + stack.shift();
  20002. bezierCurveTo(xa, ya, xb, yb, x, y);
  20003. xa = x + stack.shift(); ya = y + stack.shift();
  20004. xb = xa + stack.shift(); yb = ya + stack.shift();
  20005. x = xb; y = yb;
  20006. if (Math.abs(x - x0) > Math.abs(y - y0)) {
  20007. x += stack.shift();
  20008. } else {
  20009. y += stack.shift();
  20010. }
  20011. bezierCurveTo(xa, ya, xb, yb, x, y);
  20012. break;
  20013. default:
  20014. error('unknown operator: 12 ' + v);
  20015. }
  20016. break;
  20017. case 14: // endchar
  20018. if (stack.length >= 4) {
  20019. var achar = stack.pop();
  20020. var bchar = stack.pop();
  20021. y = stack.pop();
  20022. x = stack.pop();
  20023. cmds.push({cmd: 'save'});
  20024. cmds.push({cmd: 'translate', args: [x, y]});
  20025. var gid = lookupCmap(font.cmap, String.fromCharCode(
  20026. font.glyphNameMap[Encodings.StandardEncoding[achar]]));
  20027. compileCharString(font.glyphs[gid], cmds, font);
  20028. cmds.push({cmd: 'restore'});
  20029. gid = lookupCmap(font.cmap, String.fromCharCode(
  20030. font.glyphNameMap[Encodings.StandardEncoding[bchar]]));
  20031. compileCharString(font.glyphs[gid], cmds, font);
  20032. }
  20033. return;
  20034. case 18: // hstemhm
  20035. stems += stack.length >> 1;
  20036. stackClean = true;
  20037. break;
  20038. case 19: // hintmask
  20039. stems += stack.length >> 1;
  20040. i += (stems + 7) >> 3;
  20041. stackClean = true;
  20042. break;
  20043. case 20: // cntrmask
  20044. stems += stack.length >> 1;
  20045. i += (stems + 7) >> 3;
  20046. stackClean = true;
  20047. break;
  20048. case 21: // rmoveto
  20049. y += stack.pop();
  20050. x += stack.pop();
  20051. moveTo(x, y);
  20052. stackClean = true;
  20053. break;
  20054. case 22: // hmoveto
  20055. x += stack.pop();
  20056. moveTo(x, y);
  20057. stackClean = true;
  20058. break;
  20059. case 23: // vstemhm
  20060. stems += stack.length >> 1;
  20061. stackClean = true;
  20062. break;
  20063. case 24: // rcurveline
  20064. while (stack.length > 2) {
  20065. xa = x + stack.shift(); ya = y + stack.shift();
  20066. xb = xa + stack.shift(); yb = ya + stack.shift();
  20067. x = xb + stack.shift(); y = yb + stack.shift();
  20068. bezierCurveTo(xa, ya, xb, yb, x, y);
  20069. }
  20070. x += stack.shift();
  20071. y += stack.shift();
  20072. lineTo(x, y);
  20073. break;
  20074. case 25: // rlinecurve
  20075. while (stack.length > 6) {
  20076. x += stack.shift();
  20077. y += stack.shift();
  20078. lineTo(x, y);
  20079. }
  20080. xa = x + stack.shift(); ya = y + stack.shift();
  20081. xb = xa + stack.shift(); yb = ya + stack.shift();
  20082. x = xb + stack.shift(); y = yb + stack.shift();
  20083. bezierCurveTo(xa, ya, xb, yb, x, y);
  20084. break;
  20085. case 26: // vvcurveto
  20086. if (stack.length % 2) {
  20087. x += stack.shift();
  20088. }
  20089. while (stack.length > 0) {
  20090. xa = x; ya = y + stack.shift();
  20091. xb = xa + stack.shift(); yb = ya + stack.shift();
  20092. x = xb; y = yb + stack.shift();
  20093. bezierCurveTo(xa, ya, xb, yb, x, y);
  20094. }
  20095. break;
  20096. case 27: // hhcurveto
  20097. if (stack.length % 2) {
  20098. y += stack.shift();
  20099. }
  20100. while (stack.length > 0) {
  20101. xa = x + stack.shift(); ya = y;
  20102. xb = xa + stack.shift(); yb = ya + stack.shift();
  20103. x = xb + stack.shift(); y = yb;
  20104. bezierCurveTo(xa, ya, xb, yb, x, y);
  20105. }
  20106. break;
  20107. case 28:
  20108. stack.push(((code[i] << 24) | (code[i + 1] << 16)) >> 16);
  20109. i += 2;
  20110. break;
  20111. case 29: // callgsubr
  20112. n = stack.pop() + font.gsubrsBias;
  20113. subrCode = font.gsubrs[n];
  20114. if (subrCode) {
  20115. parse(subrCode);
  20116. }
  20117. break;
  20118. case 30: // vhcurveto
  20119. while (stack.length > 0) {
  20120. xa = x; ya = y + stack.shift();
  20121. xb = xa + stack.shift(); yb = ya + stack.shift();
  20122. x = xb + stack.shift();
  20123. y = yb + (stack.length === 1 ? stack.shift() : 0);
  20124. bezierCurveTo(xa, ya, xb, yb, x, y);
  20125. if (stack.length === 0) {
  20126. break;
  20127. }
  20128. xa = x + stack.shift(); ya = y;
  20129. xb = xa + stack.shift(); yb = ya + stack.shift();
  20130. y = yb + stack.shift();
  20131. x = xb + (stack.length === 1 ? stack.shift() : 0);
  20132. bezierCurveTo(xa, ya, xb, yb, x, y);
  20133. }
  20134. break;
  20135. case 31: // hvcurveto
  20136. while (stack.length > 0) {
  20137. xa = x + stack.shift(); ya = y;
  20138. xb = xa + stack.shift(); yb = ya + stack.shift();
  20139. y = yb + stack.shift();
  20140. x = xb + (stack.length === 1 ? stack.shift() : 0);
  20141. bezierCurveTo(xa, ya, xb, yb, x, y);
  20142. if (stack.length === 0) {
  20143. break;
  20144. }
  20145. xa = x; ya = y + stack.shift();
  20146. xb = xa + stack.shift(); yb = ya + stack.shift();
  20147. x = xb + stack.shift();
  20148. y = yb + (stack.length === 1 ? stack.shift() : 0);
  20149. bezierCurveTo(xa, ya, xb, yb, x, y);
  20150. }
  20151. break;
  20152. default:
  20153. if (v < 32) {
  20154. error('unknown operator: ' + v);
  20155. }
  20156. if (v < 247) {
  20157. stack.push(v - 139);
  20158. } else if (v < 251) {
  20159. stack.push((v - 247) * 256 + code[i++] + 108);
  20160. } else if (v < 255) {
  20161. stack.push(-(v - 251) * 256 - code[i++] - 108);
  20162. } else {
  20163. stack.push(((code[i] << 24) | (code[i + 1] << 16) |
  20164. (code[i + 2] << 8) | code[i + 3]) / 65536);
  20165. i += 4;
  20166. }
  20167. break;
  20168. }
  20169. if (stackClean) {
  20170. stack.length = 0;
  20171. }
  20172. }
  20173. }
  20174. parse(code);
  20175. }
  20176. var noop = '';
  20177. function CompiledFont(fontMatrix) {
  20178. this.compiledGlyphs = {};
  20179. this.fontMatrix = fontMatrix;
  20180. }
  20181. CompiledFont.prototype = {
  20182. getPathJs: function (unicode) {
  20183. var gid = lookupCmap(this.cmap, unicode);
  20184. var fn = this.compiledGlyphs[gid];
  20185. if (!fn) {
  20186. this.compiledGlyphs[gid] = fn = this.compileGlyph(this.glyphs[gid]);
  20187. }
  20188. return fn;
  20189. },
  20190. compileGlyph: function (code) {
  20191. if (!code || code.length === 0 || code[0] === 14) {
  20192. return noop;
  20193. }
  20194. var cmds = [];
  20195. cmds.push({cmd: 'save'});
  20196. cmds.push({cmd: 'transform', args: this.fontMatrix.slice()});
  20197. cmds.push({cmd: 'scale', args: ['size', '-size']});
  20198. this.compileGlyphImpl(code, cmds);
  20199. cmds.push({cmd: 'restore'});
  20200. return cmds;
  20201. },
  20202. compileGlyphImpl: function () {
  20203. error('Children classes should implement this.');
  20204. },
  20205. hasBuiltPath: function (unicode) {
  20206. var gid = lookupCmap(this.cmap, unicode);
  20207. return gid in this.compiledGlyphs;
  20208. }
  20209. };
  20210. function TrueTypeCompiled(glyphs, cmap, fontMatrix) {
  20211. fontMatrix = fontMatrix || [0.000488, 0, 0, 0.000488, 0, 0];
  20212. CompiledFont.call(this, fontMatrix);
  20213. this.glyphs = glyphs;
  20214. this.cmap = cmap;
  20215. this.compiledGlyphs = [];
  20216. }
  20217. Util.inherit(TrueTypeCompiled, CompiledFont, {
  20218. compileGlyphImpl: function (code, cmds) {
  20219. compileGlyf(code, cmds, this);
  20220. }
  20221. });
  20222. function Type2Compiled(cffInfo, cmap, fontMatrix, glyphNameMap) {
  20223. fontMatrix = fontMatrix || [0.001, 0, 0, 0.001, 0, 0];
  20224. CompiledFont.call(this, fontMatrix);
  20225. this.glyphs = cffInfo.glyphs;
  20226. this.gsubrs = cffInfo.gsubrs || [];
  20227. this.subrs = cffInfo.subrs || [];
  20228. this.cmap = cmap;
  20229. this.glyphNameMap = glyphNameMap || GlyphsUnicode;
  20230. this.compiledGlyphs = [];
  20231. this.gsubrsBias = (this.gsubrs.length < 1240 ?
  20232. 107 : (this.gsubrs.length < 33900 ? 1131 : 32768));
  20233. this.subrsBias = (this.subrs.length < 1240 ?
  20234. 107 : (this.subrs.length < 33900 ? 1131 : 32768));
  20235. }
  20236. Util.inherit(Type2Compiled, CompiledFont, {
  20237. compileGlyphImpl: function (code, cmds) {
  20238. compileCharString(code, cmds, this);
  20239. }
  20240. });
  20241. return {
  20242. create: function FontRendererFactory_create(font) {
  20243. var data = new Uint8Array(font.data);
  20244. var cmap, glyf, loca, cff, indexToLocFormat, unitsPerEm;
  20245. var numTables = getUshort(data, 4);
  20246. for (var i = 0, p = 12; i < numTables; i++, p += 16) {
  20247. var tag = bytesToString(data.subarray(p, p + 4));
  20248. var offset = getLong(data, p + 8);
  20249. var length = getLong(data, p + 12);
  20250. switch (tag) {
  20251. case 'cmap':
  20252. cmap = parseCmap(data, offset, offset + length);
  20253. break;
  20254. case 'glyf':
  20255. glyf = data.subarray(offset, offset + length);
  20256. break;
  20257. case 'loca':
  20258. loca = data.subarray(offset, offset + length);
  20259. break;
  20260. case 'head':
  20261. unitsPerEm = getUshort(data, offset + 18);
  20262. indexToLocFormat = getUshort(data, offset + 50);
  20263. break;
  20264. case 'CFF ':
  20265. cff = parseCff(data, offset, offset + length);
  20266. break;
  20267. }
  20268. }
  20269. if (glyf) {
  20270. var fontMatrix = (!unitsPerEm ? font.fontMatrix :
  20271. [1 / unitsPerEm, 0, 0, 1 / unitsPerEm, 0, 0]);
  20272. return new TrueTypeCompiled(
  20273. parseGlyfTable(glyf, loca, indexToLocFormat), cmap, fontMatrix);
  20274. } else {
  20275. return new Type2Compiled(cff, cmap, font.fontMatrix, font.glyphNameMap);
  20276. }
  20277. }
  20278. };
  20279. })();
  20280. // TODO refactor to remove cyclic dependency on fonts.js
  20281. function _setCoreFonts(coreFonts_) {
  20282. coreFonts = coreFonts_;
  20283. Encodings = coreFonts_.Encodings;
  20284. CFFParser = coreFonts_.CFFParser;
  20285. }
  20286. exports._setCoreFonts = _setCoreFonts;
  20287. exports.FontRendererFactory = FontRendererFactory;
  20288. }));
  20289. (function (root, factory) {
  20290. {
  20291. factory((root.pdfjsCoreParser = {}), root.pdfjsSharedUtil,
  20292. root.pdfjsCorePrimitives, root.pdfjsCoreStream);
  20293. }
  20294. }(this, function (exports, sharedUtil, corePrimitives, coreStream) {
  20295. var MissingDataException = sharedUtil.MissingDataException;
  20296. var StreamType = sharedUtil.StreamType;
  20297. var assert = sharedUtil.assert;
  20298. var error = sharedUtil.error;
  20299. var info = sharedUtil.info;
  20300. var isArray = sharedUtil.isArray;
  20301. var isInt = sharedUtil.isInt;
  20302. var isNum = sharedUtil.isNum;
  20303. var isString = sharedUtil.isString;
  20304. var warn = sharedUtil.warn;
  20305. var Cmd = corePrimitives.Cmd;
  20306. var Dict = corePrimitives.Dict;
  20307. var Name = corePrimitives.Name;
  20308. var Ref = corePrimitives.Ref;
  20309. var isCmd = corePrimitives.isCmd;
  20310. var isDict = corePrimitives.isDict;
  20311. var isName = corePrimitives.isName;
  20312. var Ascii85Stream = coreStream.Ascii85Stream;
  20313. var AsciiHexStream = coreStream.AsciiHexStream;
  20314. var CCITTFaxStream = coreStream.CCITTFaxStream;
  20315. var FlateStream = coreStream.FlateStream;
  20316. var Jbig2Stream = coreStream.Jbig2Stream;
  20317. var JpegStream = coreStream.JpegStream;
  20318. var JpxStream = coreStream.JpxStream;
  20319. var LZWStream = coreStream.LZWStream;
  20320. var NullStream = coreStream.NullStream;
  20321. var PredictorStream = coreStream.PredictorStream;
  20322. var RunLengthStream = coreStream.RunLengthStream;
  20323. var EOF = {};
  20324. function isEOF(v) {
  20325. return (v === EOF);
  20326. }
  20327. var MAX_LENGTH_TO_CACHE = 1000;
  20328. var Parser = (function ParserClosure() {
  20329. function Parser(lexer, allowStreams, xref) {
  20330. this.lexer = lexer;
  20331. this.allowStreams = allowStreams;
  20332. this.xref = xref;
  20333. this.imageCache = {};
  20334. this.refill();
  20335. }
  20336. Parser.prototype = {
  20337. refill: function Parser_refill() {
  20338. this.buf1 = this.lexer.getObj();
  20339. this.buf2 = this.lexer.getObj();
  20340. },
  20341. shift: function Parser_shift() {
  20342. if (isCmd(this.buf2, 'ID')) {
  20343. this.buf1 = this.buf2;
  20344. this.buf2 = null;
  20345. } else {
  20346. this.buf1 = this.buf2;
  20347. this.buf2 = this.lexer.getObj();
  20348. }
  20349. },
  20350. tryShift: function Parser_tryShift() {
  20351. try {
  20352. this.shift();
  20353. return true;
  20354. } catch (e) {
  20355. if (e instanceof MissingDataException) {
  20356. throw e;
  20357. }
  20358. // Upon failure, the caller should reset this.lexer.pos to a known good
  20359. // state and call this.shift() twice to reset the buffers.
  20360. return false;
  20361. }
  20362. },
  20363. getObj: function Parser_getObj(cipherTransform) {
  20364. var buf1 = this.buf1;
  20365. this.shift();
  20366. if (buf1 instanceof Cmd) {
  20367. switch (buf1.cmd) {
  20368. case 'BI': // inline image
  20369. return this.makeInlineImage(cipherTransform);
  20370. case '[': // array
  20371. var array = [];
  20372. while (!isCmd(this.buf1, ']') && !isEOF(this.buf1)) {
  20373. array.push(this.getObj(cipherTransform));
  20374. }
  20375. if (isEOF(this.buf1)) {
  20376. error('End of file inside array');
  20377. }
  20378. this.shift();
  20379. return array;
  20380. case '<<': // dictionary or stream
  20381. var dict = new Dict(this.xref);
  20382. while (!isCmd(this.buf1, '>>') && !isEOF(this.buf1)) {
  20383. if (!isName(this.buf1)) {
  20384. info('Malformed dictionary: key must be a name object');
  20385. this.shift();
  20386. continue;
  20387. }
  20388. var key = this.buf1.name;
  20389. this.shift();
  20390. if (isEOF(this.buf1)) {
  20391. break;
  20392. }
  20393. dict.set(key, this.getObj(cipherTransform));
  20394. }
  20395. if (isEOF(this.buf1)) {
  20396. error('End of file inside dictionary');
  20397. }
  20398. // Stream objects are not allowed inside content streams or
  20399. // object streams.
  20400. if (isCmd(this.buf2, 'stream')) {
  20401. return (this.allowStreams ?
  20402. this.makeStream(dict, cipherTransform) : dict);
  20403. }
  20404. this.shift();
  20405. return dict;
  20406. default: // simple object
  20407. return buf1;
  20408. }
  20409. }
  20410. if (isInt(buf1)) { // indirect reference or integer
  20411. var num = buf1;
  20412. if (isInt(this.buf1) && isCmd(this.buf2, 'R')) {
  20413. var ref = new Ref(num, this.buf1);
  20414. this.shift();
  20415. this.shift();
  20416. return ref;
  20417. }
  20418. return num;
  20419. }
  20420. if (isString(buf1)) { // string
  20421. var str = buf1;
  20422. if (cipherTransform) {
  20423. str = cipherTransform.decryptString(str);
  20424. }
  20425. return str;
  20426. }
  20427. // simple object
  20428. return buf1;
  20429. },
  20430. /**
  20431. * Find the end of the stream by searching for the /EI\s/.
  20432. * @returns {number} The inline stream length.
  20433. */
  20434. findDefaultInlineStreamEnd:
  20435. function Parser_findDefaultInlineStreamEnd(stream) {
  20436. var E = 0x45, I = 0x49, SPACE = 0x20, LF = 0xA, CR = 0xD;
  20437. var startPos = stream.pos, state = 0, ch, i, n, followingBytes;
  20438. while ((ch = stream.getByte()) !== -1) {
  20439. if (state === 0) {
  20440. state = (ch === E) ? 1 : 0;
  20441. } else if (state === 1) {
  20442. state = (ch === I) ? 2 : 0;
  20443. } else {
  20444. assert(state === 2);
  20445. if (ch === SPACE || ch === LF || ch === CR) {
  20446. // Let's check the next five bytes are ASCII... just be sure.
  20447. n = 5;
  20448. followingBytes = stream.peekBytes(n);
  20449. for (i = 0; i < n; i++) {
  20450. ch = followingBytes[i];
  20451. if (ch !== LF && ch !== CR && (ch < SPACE || ch > 0x7F)) {
  20452. // Not a LF, CR, SPACE or any visible ASCII character, i.e.
  20453. // it's binary stuff. Resetting the state.
  20454. state = 0;
  20455. break;
  20456. }
  20457. }
  20458. if (state === 2) {
  20459. break; // Finished!
  20460. }
  20461. } else {
  20462. state = 0;
  20463. }
  20464. }
  20465. }
  20466. return ((stream.pos - 4) - startPos);
  20467. },
  20468. /**
  20469. * Find the EOI (end-of-image) marker 0xFFD9 of the stream.
  20470. * @returns {number} The inline stream length.
  20471. */
  20472. findDCTDecodeInlineStreamEnd:
  20473. function Parser_findDCTDecodeInlineStreamEnd(stream) {
  20474. var startPos = stream.pos, foundEOI = false, b, markerLength, length;
  20475. while ((b = stream.getByte()) !== -1) {
  20476. if (b !== 0xFF) { // Not a valid marker.
  20477. continue;
  20478. }
  20479. switch (stream.getByte()) {
  20480. case 0x00: // Byte stuffing.
  20481. // 0xFF00 appears to be a very common byte sequence in JPEG images.
  20482. break;
  20483. case 0xFF: // Fill byte.
  20484. // Avoid skipping a valid marker, resetting the stream position.
  20485. stream.skip(-1);
  20486. break;
  20487. case 0xD9: // EOI
  20488. foundEOI = true;
  20489. break;
  20490. case 0xC0: // SOF0
  20491. case 0xC1: // SOF1
  20492. case 0xC2: // SOF2
  20493. case 0xC3: // SOF3
  20494. case 0xC5: // SOF5
  20495. case 0xC6: // SOF6
  20496. case 0xC7: // SOF7
  20497. case 0xC9: // SOF9
  20498. case 0xCA: // SOF10
  20499. case 0xCB: // SOF11
  20500. case 0xCD: // SOF13
  20501. case 0xCE: // SOF14
  20502. case 0xCF: // SOF15
  20503. case 0xC4: // DHT
  20504. case 0xCC: // DAC
  20505. case 0xDA: // SOS
  20506. case 0xDB: // DQT
  20507. case 0xDC: // DNL
  20508. case 0xDD: // DRI
  20509. case 0xDE: // DHP
  20510. case 0xDF: // EXP
  20511. case 0xE0: // APP0
  20512. case 0xE1: // APP1
  20513. case 0xE2: // APP2
  20514. case 0xE3: // APP3
  20515. case 0xE4: // APP4
  20516. case 0xE5: // APP5
  20517. case 0xE6: // APP6
  20518. case 0xE7: // APP7
  20519. case 0xE8: // APP8
  20520. case 0xE9: // APP9
  20521. case 0xEA: // APP10
  20522. case 0xEB: // APP11
  20523. case 0xEC: // APP12
  20524. case 0xED: // APP13
  20525. case 0xEE: // APP14
  20526. case 0xEF: // APP15
  20527. case 0xFE: // COM
  20528. // The marker should be followed by the length of the segment.
  20529. markerLength = stream.getUint16();
  20530. if (markerLength > 2) {
  20531. // |markerLength| contains the byte length of the marker segment,
  20532. // including its own length (2 bytes) and excluding the marker.
  20533. stream.skip(markerLength - 2); // Jump to the next marker.
  20534. } else {
  20535. // The marker length is invalid, resetting the stream position.
  20536. stream.skip(-2);
  20537. }
  20538. break;
  20539. }
  20540. if (foundEOI) {
  20541. break;
  20542. }
  20543. }
  20544. length = stream.pos - startPos;
  20545. if (b === -1) {
  20546. warn('Inline DCTDecode image stream: ' +
  20547. 'EOI marker not found, searching for /EI/ instead.');
  20548. stream.skip(-length); // Reset the stream position.
  20549. return this.findDefaultInlineStreamEnd(stream);
  20550. }
  20551. this.inlineStreamSkipEI(stream);
  20552. return length;
  20553. },
  20554. /**
  20555. * Find the EOD (end-of-data) marker '~>' (i.e. TILDE + GT) of the stream.
  20556. * @returns {number} The inline stream length.
  20557. */
  20558. findASCII85DecodeInlineStreamEnd:
  20559. function Parser_findASCII85DecodeInlineStreamEnd(stream) {
  20560. var TILDE = 0x7E, GT = 0x3E;
  20561. var startPos = stream.pos, ch, length;
  20562. while ((ch = stream.getByte()) !== -1) {
  20563. if (ch === TILDE && stream.peekByte() === GT) {
  20564. stream.skip();
  20565. break;
  20566. }
  20567. }
  20568. length = stream.pos - startPos;
  20569. if (ch === -1) {
  20570. warn('Inline ASCII85Decode image stream: ' +
  20571. 'EOD marker not found, searching for /EI/ instead.');
  20572. stream.skip(-length); // Reset the stream position.
  20573. return this.findDefaultInlineStreamEnd(stream);
  20574. }
  20575. this.inlineStreamSkipEI(stream);
  20576. return length;
  20577. },
  20578. /**
  20579. * Find the EOD (end-of-data) marker '>' (i.e. GT) of the stream.
  20580. * @returns {number} The inline stream length.
  20581. */
  20582. findASCIIHexDecodeInlineStreamEnd:
  20583. function Parser_findASCIIHexDecodeInlineStreamEnd(stream) {
  20584. var GT = 0x3E;
  20585. var startPos = stream.pos, ch, length;
  20586. while ((ch = stream.getByte()) !== -1) {
  20587. if (ch === GT) {
  20588. break;
  20589. }
  20590. }
  20591. length = stream.pos - startPos;
  20592. if (ch === -1) {
  20593. warn('Inline ASCIIHexDecode image stream: ' +
  20594. 'EOD marker not found, searching for /EI/ instead.');
  20595. stream.skip(-length); // Reset the stream position.
  20596. return this.findDefaultInlineStreamEnd(stream);
  20597. }
  20598. this.inlineStreamSkipEI(stream);
  20599. return length;
  20600. },
  20601. /**
  20602. * Skip over the /EI/ for streams where we search for an EOD marker.
  20603. */
  20604. inlineStreamSkipEI: function Parser_inlineStreamSkipEI(stream) {
  20605. var E = 0x45, I = 0x49;
  20606. var state = 0, ch;
  20607. while ((ch = stream.getByte()) !== -1) {
  20608. if (state === 0) {
  20609. state = (ch === E) ? 1 : 0;
  20610. } else if (state === 1) {
  20611. state = (ch === I) ? 2 : 0;
  20612. } else if (state === 2) {
  20613. break;
  20614. }
  20615. }
  20616. },
  20617. makeInlineImage: function Parser_makeInlineImage(cipherTransform) {
  20618. var lexer = this.lexer;
  20619. var stream = lexer.stream;
  20620. // Parse dictionary.
  20621. var dict = new Dict(this.xref);
  20622. while (!isCmd(this.buf1, 'ID') && !isEOF(this.buf1)) {
  20623. if (!isName(this.buf1)) {
  20624. error('Dictionary key must be a name object');
  20625. }
  20626. var key = this.buf1.name;
  20627. this.shift();
  20628. if (isEOF(this.buf1)) {
  20629. break;
  20630. }
  20631. dict.set(key, this.getObj(cipherTransform));
  20632. }
  20633. // Extract the name of the first (i.e. the current) image filter.
  20634. var filter = dict.get('Filter', 'F'), filterName;
  20635. if (isName(filter)) {
  20636. filterName = filter.name;
  20637. } else if (isArray(filter) && isName(filter[0])) {
  20638. filterName = filter[0].name;
  20639. }
  20640. // Parse image stream.
  20641. var startPos = stream.pos, length, i, ii;
  20642. if (filterName === 'DCTDecode' || filterName === 'DCT') {
  20643. length = this.findDCTDecodeInlineStreamEnd(stream);
  20644. } else if (filterName === 'ASCII85Decide' || filterName === 'A85') {
  20645. length = this.findASCII85DecodeInlineStreamEnd(stream);
  20646. } else if (filterName === 'ASCIIHexDecode' || filterName === 'AHx') {
  20647. length = this.findASCIIHexDecodeInlineStreamEnd(stream);
  20648. } else {
  20649. length = this.findDefaultInlineStreamEnd(stream);
  20650. }
  20651. var imageStream = stream.makeSubStream(startPos, length, dict);
  20652. // Cache all images below the MAX_LENGTH_TO_CACHE threshold by their
  20653. // adler32 checksum.
  20654. var adler32;
  20655. if (length < MAX_LENGTH_TO_CACHE) {
  20656. var imageBytes = imageStream.getBytes();
  20657. imageStream.reset();
  20658. var a = 1;
  20659. var b = 0;
  20660. for (i = 0, ii = imageBytes.length; i < ii; ++i) {
  20661. // No modulo required in the loop if imageBytes.length < 5552.
  20662. a += imageBytes[i] & 0xff;
  20663. b += a;
  20664. }
  20665. adler32 = ((b % 65521) << 16) | (a % 65521);
  20666. if (this.imageCache.adler32 === adler32) {
  20667. this.buf2 = Cmd.get('EI');
  20668. this.shift();
  20669. this.imageCache[adler32].reset();
  20670. return this.imageCache[adler32];
  20671. }
  20672. }
  20673. if (cipherTransform) {
  20674. imageStream = cipherTransform.createStream(imageStream, length);
  20675. }
  20676. imageStream = this.filter(imageStream, dict, length);
  20677. imageStream.dict = dict;
  20678. if (adler32 !== undefined) {
  20679. imageStream.cacheKey = 'inline_' + length + '_' + adler32;
  20680. this.imageCache[adler32] = imageStream;
  20681. }
  20682. this.buf2 = Cmd.get('EI');
  20683. this.shift();
  20684. return imageStream;
  20685. },
  20686. makeStream: function Parser_makeStream(dict, cipherTransform) {
  20687. var lexer = this.lexer;
  20688. var stream = lexer.stream;
  20689. // get stream start position
  20690. lexer.skipToNextLine();
  20691. var pos = stream.pos - 1;
  20692. // get length
  20693. var length = dict.get('Length');
  20694. if (!isInt(length)) {
  20695. info('Bad ' + length + ' attribute in stream');
  20696. length = 0;
  20697. }
  20698. // skip over the stream data
  20699. stream.pos = pos + length;
  20700. lexer.nextChar();
  20701. // Shift '>>' and check whether the new object marks the end of the stream
  20702. if (this.tryShift() && isCmd(this.buf2, 'endstream')) {
  20703. this.shift(); // 'stream'
  20704. } else {
  20705. // bad stream length, scanning for endstream
  20706. stream.pos = pos;
  20707. var SCAN_BLOCK_SIZE = 2048;
  20708. var ENDSTREAM_SIGNATURE_LENGTH = 9;
  20709. var ENDSTREAM_SIGNATURE = [0x65, 0x6E, 0x64, 0x73, 0x74, 0x72, 0x65,
  20710. 0x61, 0x6D];
  20711. var skipped = 0, found = false, i, j;
  20712. while (stream.pos < stream.end) {
  20713. var scanBytes = stream.peekBytes(SCAN_BLOCK_SIZE);
  20714. var scanLength = scanBytes.length - ENDSTREAM_SIGNATURE_LENGTH;
  20715. if (scanLength <= 0) {
  20716. break;
  20717. }
  20718. found = false;
  20719. i = 0;
  20720. while (i < scanLength) {
  20721. j = 0;
  20722. while (j < ENDSTREAM_SIGNATURE_LENGTH &&
  20723. scanBytes[i + j] === ENDSTREAM_SIGNATURE[j]) {
  20724. j++;
  20725. }
  20726. if (j >= ENDSTREAM_SIGNATURE_LENGTH) {
  20727. found = true;
  20728. break;
  20729. }
  20730. i++;
  20731. }
  20732. if (found) {
  20733. skipped += i;
  20734. stream.pos += i;
  20735. break;
  20736. }
  20737. skipped += scanLength;
  20738. stream.pos += scanLength;
  20739. }
  20740. if (!found) {
  20741. error('Missing endstream');
  20742. }
  20743. length = skipped;
  20744. lexer.nextChar();
  20745. this.shift();
  20746. this.shift();
  20747. }
  20748. this.shift(); // 'endstream'
  20749. stream = stream.makeSubStream(pos, length, dict);
  20750. if (cipherTransform) {
  20751. stream = cipherTransform.createStream(stream, length);
  20752. }
  20753. stream = this.filter(stream, dict, length);
  20754. stream.dict = dict;
  20755. return stream;
  20756. },
  20757. filter: function Parser_filter(stream, dict, length) {
  20758. var filter = dict.get('Filter', 'F');
  20759. var params = dict.get('DecodeParms', 'DP');
  20760. if (isName(filter)) {
  20761. return this.makeFilter(stream, filter.name, length, params);
  20762. }
  20763. var maybeLength = length;
  20764. if (isArray(filter)) {
  20765. var filterArray = filter;
  20766. var paramsArray = params;
  20767. for (var i = 0, ii = filterArray.length; i < ii; ++i) {
  20768. filter = filterArray[i];
  20769. if (!isName(filter)) {
  20770. error('Bad filter name: ' + filter);
  20771. }
  20772. params = null;
  20773. if (isArray(paramsArray) && (i in paramsArray)) {
  20774. params = paramsArray[i];
  20775. }
  20776. stream = this.makeFilter(stream, filter.name, maybeLength, params);
  20777. // after the first stream the length variable is invalid
  20778. maybeLength = null;
  20779. }
  20780. }
  20781. return stream;
  20782. },
  20783. makeFilter: function Parser_makeFilter(stream, name, maybeLength, params) {
  20784. if (stream.dict.get('Length') === 0 && !maybeLength) {
  20785. warn('Empty "' + name + '" stream.');
  20786. return new NullStream(stream);
  20787. }
  20788. try {
  20789. if (params && this.xref) {
  20790. params = this.xref.fetchIfRef(params);
  20791. }
  20792. var xrefStreamStats = this.xref.stats.streamTypes;
  20793. if (name === 'FlateDecode' || name === 'Fl') {
  20794. xrefStreamStats[StreamType.FLATE] = true;
  20795. if (params) {
  20796. return new PredictorStream(new FlateStream(stream, maybeLength),
  20797. maybeLength, params);
  20798. }
  20799. return new FlateStream(stream, maybeLength);
  20800. }
  20801. if (name === 'LZWDecode' || name === 'LZW') {
  20802. xrefStreamStats[StreamType.LZW] = true;
  20803. var earlyChange = 1;
  20804. if (params) {
  20805. if (params.has('EarlyChange')) {
  20806. earlyChange = params.get('EarlyChange');
  20807. }
  20808. return new PredictorStream(
  20809. new LZWStream(stream, maybeLength, earlyChange),
  20810. maybeLength, params);
  20811. }
  20812. return new LZWStream(stream, maybeLength, earlyChange);
  20813. }
  20814. if (name === 'DCTDecode' || name === 'DCT') {
  20815. xrefStreamStats[StreamType.DCT] = true;
  20816. return new JpegStream(stream, maybeLength, stream.dict, this.xref);
  20817. }
  20818. if (name === 'JPXDecode' || name === 'JPX') {
  20819. xrefStreamStats[StreamType.JPX] = true;
  20820. return new JpxStream(stream, maybeLength, stream.dict);
  20821. }
  20822. if (name === 'ASCII85Decode' || name === 'A85') {
  20823. xrefStreamStats[StreamType.A85] = true;
  20824. return new Ascii85Stream(stream, maybeLength);
  20825. }
  20826. if (name === 'ASCIIHexDecode' || name === 'AHx') {
  20827. xrefStreamStats[StreamType.AHX] = true;
  20828. return new AsciiHexStream(stream, maybeLength);
  20829. }
  20830. if (name === 'CCITTFaxDecode' || name === 'CCF') {
  20831. xrefStreamStats[StreamType.CCF] = true;
  20832. return new CCITTFaxStream(stream, maybeLength, params);
  20833. }
  20834. if (name === 'RunLengthDecode' || name === 'RL') {
  20835. xrefStreamStats[StreamType.RL] = true;
  20836. return new RunLengthStream(stream, maybeLength);
  20837. }
  20838. if (name === 'JBIG2Decode') {
  20839. xrefStreamStats[StreamType.JBIG] = true;
  20840. return new Jbig2Stream(stream, maybeLength, stream.dict);
  20841. }
  20842. warn('filter "' + name + '" not supported yet');
  20843. return stream;
  20844. } catch (ex) {
  20845. if (ex instanceof MissingDataException) {
  20846. throw ex;
  20847. }
  20848. warn('Invalid stream: \"' + ex + '\"');
  20849. return new NullStream(stream);
  20850. }
  20851. }
  20852. };
  20853. return Parser;
  20854. })();
  20855. var Lexer = (function LexerClosure() {
  20856. function Lexer(stream, knownCommands) {
  20857. this.stream = stream;
  20858. this.nextChar();
  20859. // While lexing, we build up many strings one char at a time. Using += for
  20860. // this can result in lots of garbage strings. It's better to build an
  20861. // array of single-char strings and then join() them together at the end.
  20862. // And reusing a single array (i.e. |this.strBuf|) over and over for this
  20863. // purpose uses less memory than using a new array for each string.
  20864. this.strBuf = [];
  20865. // The PDFs might have "glued" commands with other commands, operands or
  20866. // literals, e.g. "q1". The knownCommands is a dictionary of the valid
  20867. // commands and their prefixes. The prefixes are built the following way:
  20868. // if there a command that is a prefix of the other valid command or
  20869. // literal (e.g. 'f' and 'false') the following prefixes must be included,
  20870. // 'fa', 'fal', 'fals'. The prefixes are not needed, if the command has no
  20871. // other commands or literals as a prefix. The knowCommands is optional.
  20872. this.knownCommands = knownCommands;
  20873. }
  20874. Lexer.isSpace = function Lexer_isSpace(ch) {
  20875. // Space is one of the following characters: SPACE, TAB, CR or LF.
  20876. return (ch === 0x20 || ch === 0x09 || ch === 0x0D || ch === 0x0A);
  20877. };
  20878. // A '1' in this array means the character is white space. A '1' or
  20879. // '2' means the character ends a name or command.
  20880. var specialChars = [
  20881. 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, // 0x
  20882. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 1x
  20883. 1, 0, 0, 0, 0, 2, 0, 0, 2, 2, 0, 0, 0, 0, 0, 2, // 2x
  20884. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, // 3x
  20885. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 4x
  20886. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 5x
  20887. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 6x
  20888. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 7x
  20889. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 8x
  20890. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 9x
  20891. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ax
  20892. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // bx
  20893. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // cx
  20894. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // dx
  20895. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ex
  20896. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 // fx
  20897. ];
  20898. function toHexDigit(ch) {
  20899. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  20900. return ch & 0x0F;
  20901. }
  20902. if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  20903. // 'A'-'F', 'a'-'f'
  20904. return (ch & 0x0F) + 9;
  20905. }
  20906. return -1;
  20907. }
  20908. Lexer.prototype = {
  20909. nextChar: function Lexer_nextChar() {
  20910. return (this.currentChar = this.stream.getByte());
  20911. },
  20912. peekChar: function Lexer_peekChar() {
  20913. return this.stream.peekByte();
  20914. },
  20915. getNumber: function Lexer_getNumber() {
  20916. var ch = this.currentChar;
  20917. var eNotation = false;
  20918. var divideBy = 0; // different from 0 if it's a floating point value
  20919. var sign = 1;
  20920. if (ch === 0x2D) { // '-'
  20921. sign = -1;
  20922. ch = this.nextChar();
  20923. if (ch === 0x2D) { // '-'
  20924. // Ignore double negative (this is consistent with Adobe Reader).
  20925. ch = this.nextChar();
  20926. }
  20927. } else if (ch === 0x2B) { // '+'
  20928. ch = this.nextChar();
  20929. }
  20930. if (ch === 0x2E) { // '.'
  20931. divideBy = 10;
  20932. ch = this.nextChar();
  20933. }
  20934. if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  20935. error('Invalid number: ' + String.fromCharCode(ch));
  20936. return 0;
  20937. }
  20938. var baseValue = ch - 0x30; // '0'
  20939. var powerValue = 0;
  20940. var powerValueSign = 1;
  20941. while ((ch = this.nextChar()) >= 0) {
  20942. if (0x30 <= ch && ch <= 0x39) { // '0' - '9'
  20943. var currentDigit = ch - 0x30; // '0'
  20944. if (eNotation) { // We are after an 'e' or 'E'
  20945. powerValue = powerValue * 10 + currentDigit;
  20946. } else {
  20947. if (divideBy !== 0) { // We are after a point
  20948. divideBy *= 10;
  20949. }
  20950. baseValue = baseValue * 10 + currentDigit;
  20951. }
  20952. } else if (ch === 0x2E) { // '.'
  20953. if (divideBy === 0) {
  20954. divideBy = 1;
  20955. } else {
  20956. // A number can have only one '.'
  20957. break;
  20958. }
  20959. } else if (ch === 0x2D) { // '-'
  20960. // ignore minus signs in the middle of numbers to match
  20961. // Adobe's behavior
  20962. warn('Badly formated number');
  20963. } else if (ch === 0x45 || ch === 0x65) { // 'E', 'e'
  20964. // 'E' can be either a scientific notation or the beginning of a new
  20965. // operator
  20966. ch = this.peekChar();
  20967. if (ch === 0x2B || ch === 0x2D) { // '+', '-'
  20968. powerValueSign = (ch === 0x2D) ? -1 : 1;
  20969. this.nextChar(); // Consume the sign character
  20970. } else if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  20971. // The 'E' must be the beginning of a new operator
  20972. break;
  20973. }
  20974. eNotation = true;
  20975. } else {
  20976. // the last character doesn't belong to us
  20977. break;
  20978. }
  20979. }
  20980. if (divideBy !== 0) {
  20981. baseValue /= divideBy;
  20982. }
  20983. if (eNotation) {
  20984. baseValue *= Math.pow(10, powerValueSign * powerValue);
  20985. }
  20986. return sign * baseValue;
  20987. },
  20988. getString: function Lexer_getString() {
  20989. var numParen = 1;
  20990. var done = false;
  20991. var strBuf = this.strBuf;
  20992. strBuf.length = 0;
  20993. var ch = this.nextChar();
  20994. while (true) {
  20995. var charBuffered = false;
  20996. switch (ch | 0) {
  20997. case -1:
  20998. warn('Unterminated string');
  20999. done = true;
  21000. break;
  21001. case 0x28: // '('
  21002. ++numParen;
  21003. strBuf.push('(');
  21004. break;
  21005. case 0x29: // ')'
  21006. if (--numParen === 0) {
  21007. this.nextChar(); // consume strings ')'
  21008. done = true;
  21009. } else {
  21010. strBuf.push(')');
  21011. }
  21012. break;
  21013. case 0x5C: // '\\'
  21014. ch = this.nextChar();
  21015. switch (ch) {
  21016. case -1:
  21017. warn('Unterminated string');
  21018. done = true;
  21019. break;
  21020. case 0x6E: // 'n'
  21021. strBuf.push('\n');
  21022. break;
  21023. case 0x72: // 'r'
  21024. strBuf.push('\r');
  21025. break;
  21026. case 0x74: // 't'
  21027. strBuf.push('\t');
  21028. break;
  21029. case 0x62: // 'b'
  21030. strBuf.push('\b');
  21031. break;
  21032. case 0x66: // 'f'
  21033. strBuf.push('\f');
  21034. break;
  21035. case 0x5C: // '\'
  21036. case 0x28: // '('
  21037. case 0x29: // ')'
  21038. strBuf.push(String.fromCharCode(ch));
  21039. break;
  21040. case 0x30: case 0x31: case 0x32: case 0x33: // '0'-'3'
  21041. case 0x34: case 0x35: case 0x36: case 0x37: // '4'-'7'
  21042. var x = ch & 0x0F;
  21043. ch = this.nextChar();
  21044. charBuffered = true;
  21045. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  21046. x = (x << 3) + (ch & 0x0F);
  21047. ch = this.nextChar();
  21048. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  21049. charBuffered = false;
  21050. x = (x << 3) + (ch & 0x0F);
  21051. }
  21052. }
  21053. strBuf.push(String.fromCharCode(x));
  21054. break;
  21055. case 0x0D: // CR
  21056. if (this.peekChar() === 0x0A) { // LF
  21057. this.nextChar();
  21058. }
  21059. break;
  21060. case 0x0A: // LF
  21061. break;
  21062. default:
  21063. strBuf.push(String.fromCharCode(ch));
  21064. break;
  21065. }
  21066. break;
  21067. default:
  21068. strBuf.push(String.fromCharCode(ch));
  21069. break;
  21070. }
  21071. if (done) {
  21072. break;
  21073. }
  21074. if (!charBuffered) {
  21075. ch = this.nextChar();
  21076. }
  21077. }
  21078. return strBuf.join('');
  21079. },
  21080. getName: function Lexer_getName() {
  21081. var ch, previousCh;
  21082. var strBuf = this.strBuf;
  21083. strBuf.length = 0;
  21084. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  21085. if (ch === 0x23) { // '#'
  21086. ch = this.nextChar();
  21087. if (specialChars[ch]) {
  21088. warn('Lexer_getName: ' +
  21089. 'NUMBER SIGN (#) should be followed by a hexadecimal number.');
  21090. strBuf.push('#');
  21091. break;
  21092. }
  21093. var x = toHexDigit(ch);
  21094. if (x !== -1) {
  21095. previousCh = ch;
  21096. ch = this.nextChar();
  21097. var x2 = toHexDigit(ch);
  21098. if (x2 === -1) {
  21099. warn('Lexer_getName: Illegal digit (' +
  21100. String.fromCharCode(ch) +') in hexadecimal number.');
  21101. strBuf.push('#', String.fromCharCode(previousCh));
  21102. if (specialChars[ch]) {
  21103. break;
  21104. }
  21105. strBuf.push(String.fromCharCode(ch));
  21106. continue;
  21107. }
  21108. strBuf.push(String.fromCharCode((x << 4) | x2));
  21109. } else {
  21110. strBuf.push('#', String.fromCharCode(ch));
  21111. }
  21112. } else {
  21113. strBuf.push(String.fromCharCode(ch));
  21114. }
  21115. }
  21116. if (strBuf.length > 127) {
  21117. warn('name token is longer than allowed by the spec: ' + strBuf.length);
  21118. }
  21119. return Name.get(strBuf.join(''));
  21120. },
  21121. getHexString: function Lexer_getHexString() {
  21122. var strBuf = this.strBuf;
  21123. strBuf.length = 0;
  21124. var ch = this.currentChar;
  21125. var isFirstHex = true;
  21126. var firstDigit;
  21127. var secondDigit;
  21128. while (true) {
  21129. if (ch < 0) {
  21130. warn('Unterminated hex string');
  21131. break;
  21132. } else if (ch === 0x3E) { // '>'
  21133. this.nextChar();
  21134. break;
  21135. } else if (specialChars[ch] === 1) {
  21136. ch = this.nextChar();
  21137. continue;
  21138. } else {
  21139. if (isFirstHex) {
  21140. firstDigit = toHexDigit(ch);
  21141. if (firstDigit === -1) {
  21142. warn('Ignoring invalid character "' + ch + '" in hex string');
  21143. ch = this.nextChar();
  21144. continue;
  21145. }
  21146. } else {
  21147. secondDigit = toHexDigit(ch);
  21148. if (secondDigit === -1) {
  21149. warn('Ignoring invalid character "' + ch + '" in hex string');
  21150. ch = this.nextChar();
  21151. continue;
  21152. }
  21153. strBuf.push(String.fromCharCode((firstDigit << 4) | secondDigit));
  21154. }
  21155. isFirstHex = !isFirstHex;
  21156. ch = this.nextChar();
  21157. }
  21158. }
  21159. return strBuf.join('');
  21160. },
  21161. getObj: function Lexer_getObj() {
  21162. // skip whitespace and comments
  21163. var comment = false;
  21164. var ch = this.currentChar;
  21165. while (true) {
  21166. if (ch < 0) {
  21167. return EOF;
  21168. }
  21169. if (comment) {
  21170. if (ch === 0x0A || ch === 0x0D) { // LF, CR
  21171. comment = false;
  21172. }
  21173. } else if (ch === 0x25) { // '%'
  21174. comment = true;
  21175. } else if (specialChars[ch] !== 1) {
  21176. break;
  21177. }
  21178. ch = this.nextChar();
  21179. }
  21180. // start reading token
  21181. switch (ch | 0) {
  21182. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  21183. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  21184. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  21185. return this.getNumber();
  21186. case 0x28: // '('
  21187. return this.getString();
  21188. case 0x2F: // '/'
  21189. return this.getName();
  21190. // array punctuation
  21191. case 0x5B: // '['
  21192. this.nextChar();
  21193. return Cmd.get('[');
  21194. case 0x5D: // ']'
  21195. this.nextChar();
  21196. return Cmd.get(']');
  21197. // hex string or dict punctuation
  21198. case 0x3C: // '<'
  21199. ch = this.nextChar();
  21200. if (ch === 0x3C) {
  21201. // dict punctuation
  21202. this.nextChar();
  21203. return Cmd.get('<<');
  21204. }
  21205. return this.getHexString();
  21206. // dict punctuation
  21207. case 0x3E: // '>'
  21208. ch = this.nextChar();
  21209. if (ch === 0x3E) {
  21210. this.nextChar();
  21211. return Cmd.get('>>');
  21212. }
  21213. return Cmd.get('>');
  21214. case 0x7B: // '{'
  21215. this.nextChar();
  21216. return Cmd.get('{');
  21217. case 0x7D: // '}'
  21218. this.nextChar();
  21219. return Cmd.get('}');
  21220. case 0x29: // ')'
  21221. error('Illegal character: ' + ch);
  21222. break;
  21223. }
  21224. // command
  21225. var str = String.fromCharCode(ch);
  21226. var knownCommands = this.knownCommands;
  21227. var knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  21228. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  21229. // stop if known command is found and next character does not make
  21230. // the str a command
  21231. var possibleCommand = str + String.fromCharCode(ch);
  21232. if (knownCommandFound && knownCommands[possibleCommand] === undefined) {
  21233. break;
  21234. }
  21235. if (str.length === 128) {
  21236. error('Command token too long: ' + str.length);
  21237. }
  21238. str = possibleCommand;
  21239. knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  21240. }
  21241. if (str === 'true') {
  21242. return true;
  21243. }
  21244. if (str === 'false') {
  21245. return false;
  21246. }
  21247. if (str === 'null') {
  21248. return null;
  21249. }
  21250. return Cmd.get(str);
  21251. },
  21252. skipToNextLine: function Lexer_skipToNextLine() {
  21253. var ch = this.currentChar;
  21254. while (ch >= 0) {
  21255. if (ch === 0x0D) { // CR
  21256. ch = this.nextChar();
  21257. if (ch === 0x0A) { // LF
  21258. this.nextChar();
  21259. }
  21260. break;
  21261. } else if (ch === 0x0A) { // LF
  21262. this.nextChar();
  21263. break;
  21264. }
  21265. ch = this.nextChar();
  21266. }
  21267. }
  21268. };
  21269. return Lexer;
  21270. })();
  21271. var Linearization = {
  21272. create: function LinearizationCreate(stream) {
  21273. function getInt(name, allowZeroValue) {
  21274. var obj = linDict.get(name);
  21275. if (isInt(obj) && (allowZeroValue ? obj >= 0 : obj > 0)) {
  21276. return obj;
  21277. }
  21278. throw new Error('The "' + name + '" parameter in the linearization ' +
  21279. 'dictionary is invalid.');
  21280. }
  21281. function getHints() {
  21282. var hints = linDict.get('H'), hintsLength, item;
  21283. if (isArray(hints) &&
  21284. ((hintsLength = hints.length) === 2 || hintsLength === 4)) {
  21285. for (var index = 0; index < hintsLength; index++) {
  21286. if (!(isInt(item = hints[index]) && item > 0)) {
  21287. throw new Error('Hint (' + index +
  21288. ') in the linearization dictionary is invalid.');
  21289. }
  21290. }
  21291. return hints;
  21292. }
  21293. throw new Error('Hint array in the linearization dictionary is invalid.');
  21294. }
  21295. var parser = new Parser(new Lexer(stream), false, null);
  21296. var obj1 = parser.getObj();
  21297. var obj2 = parser.getObj();
  21298. var obj3 = parser.getObj();
  21299. var linDict = parser.getObj();
  21300. var obj, length;
  21301. if (!(isInt(obj1) && isInt(obj2) && isCmd(obj3, 'obj') && isDict(linDict) &&
  21302. isNum(obj = linDict.get('Linearized')) && obj > 0)) {
  21303. return null; // No valid linearization dictionary found.
  21304. } else if ((length = getInt('L')) !== stream.length) {
  21305. throw new Error('The "L" parameter in the linearization dictionary ' +
  21306. 'does not equal the stream length.');
  21307. }
  21308. return {
  21309. length: length,
  21310. hints: getHints(),
  21311. objectNumberFirst: getInt('O'),
  21312. endFirst: getInt('E'),
  21313. numPages: getInt('N'),
  21314. mainXRefEntriesOffset: getInt('T'),
  21315. pageFirst: (linDict.has('P') ? getInt('P', true) : 0)
  21316. };
  21317. }
  21318. };
  21319. exports.EOF = EOF;
  21320. exports.Lexer = Lexer;
  21321. exports.Linearization = Linearization;
  21322. exports.Parser = Parser;
  21323. exports.isEOF = isEOF;
  21324. // TODO refactor to remove dependency on stream.js
  21325. coreStream._setCoreParser(exports);
  21326. }));
  21327. (function (root, factory) {
  21328. {
  21329. factory((root.pdfjsCoreCMap = {}), root.pdfjsSharedUtil,
  21330. root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreParser);
  21331. }
  21332. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreParser) {
  21333. var Util = sharedUtil.Util;
  21334. var assert = sharedUtil.assert;
  21335. var error = sharedUtil.error;
  21336. var isInt = sharedUtil.isInt;
  21337. var isString = sharedUtil.isString;
  21338. var warn = sharedUtil.warn;
  21339. var isName = corePrimitives.isName;
  21340. var isCmd = corePrimitives.isCmd;
  21341. var isStream = corePrimitives.isStream;
  21342. var StringStream = coreStream.StringStream;
  21343. var Lexer = coreParser.Lexer;
  21344. var isEOF = coreParser.isEOF;
  21345. var BUILT_IN_CMAPS = [
  21346. // << Start unicode maps.
  21347. 'Adobe-GB1-UCS2',
  21348. 'Adobe-CNS1-UCS2',
  21349. 'Adobe-Japan1-UCS2',
  21350. 'Adobe-Korea1-UCS2',
  21351. // >> End unicode maps.
  21352. '78-EUC-H',
  21353. '78-EUC-V',
  21354. '78-H',
  21355. '78-RKSJ-H',
  21356. '78-RKSJ-V',
  21357. '78-V',
  21358. '78ms-RKSJ-H',
  21359. '78ms-RKSJ-V',
  21360. '83pv-RKSJ-H',
  21361. '90ms-RKSJ-H',
  21362. '90ms-RKSJ-V',
  21363. '90msp-RKSJ-H',
  21364. '90msp-RKSJ-V',
  21365. '90pv-RKSJ-H',
  21366. '90pv-RKSJ-V',
  21367. 'Add-H',
  21368. 'Add-RKSJ-H',
  21369. 'Add-RKSJ-V',
  21370. 'Add-V',
  21371. 'Adobe-CNS1-0',
  21372. 'Adobe-CNS1-1',
  21373. 'Adobe-CNS1-2',
  21374. 'Adobe-CNS1-3',
  21375. 'Adobe-CNS1-4',
  21376. 'Adobe-CNS1-5',
  21377. 'Adobe-CNS1-6',
  21378. 'Adobe-GB1-0',
  21379. 'Adobe-GB1-1',
  21380. 'Adobe-GB1-2',
  21381. 'Adobe-GB1-3',
  21382. 'Adobe-GB1-4',
  21383. 'Adobe-GB1-5',
  21384. 'Adobe-Japan1-0',
  21385. 'Adobe-Japan1-1',
  21386. 'Adobe-Japan1-2',
  21387. 'Adobe-Japan1-3',
  21388. 'Adobe-Japan1-4',
  21389. 'Adobe-Japan1-5',
  21390. 'Adobe-Japan1-6',
  21391. 'Adobe-Korea1-0',
  21392. 'Adobe-Korea1-1',
  21393. 'Adobe-Korea1-2',
  21394. 'B5-H',
  21395. 'B5-V',
  21396. 'B5pc-H',
  21397. 'B5pc-V',
  21398. 'CNS-EUC-H',
  21399. 'CNS-EUC-V',
  21400. 'CNS1-H',
  21401. 'CNS1-V',
  21402. 'CNS2-H',
  21403. 'CNS2-V',
  21404. 'ETHK-B5-H',
  21405. 'ETHK-B5-V',
  21406. 'ETen-B5-H',
  21407. 'ETen-B5-V',
  21408. 'ETenms-B5-H',
  21409. 'ETenms-B5-V',
  21410. 'EUC-H',
  21411. 'EUC-V',
  21412. 'Ext-H',
  21413. 'Ext-RKSJ-H',
  21414. 'Ext-RKSJ-V',
  21415. 'Ext-V',
  21416. 'GB-EUC-H',
  21417. 'GB-EUC-V',
  21418. 'GB-H',
  21419. 'GB-V',
  21420. 'GBK-EUC-H',
  21421. 'GBK-EUC-V',
  21422. 'GBK2K-H',
  21423. 'GBK2K-V',
  21424. 'GBKp-EUC-H',
  21425. 'GBKp-EUC-V',
  21426. 'GBT-EUC-H',
  21427. 'GBT-EUC-V',
  21428. 'GBT-H',
  21429. 'GBT-V',
  21430. 'GBTpc-EUC-H',
  21431. 'GBTpc-EUC-V',
  21432. 'GBpc-EUC-H',
  21433. 'GBpc-EUC-V',
  21434. 'H',
  21435. 'HKdla-B5-H',
  21436. 'HKdla-B5-V',
  21437. 'HKdlb-B5-H',
  21438. 'HKdlb-B5-V',
  21439. 'HKgccs-B5-H',
  21440. 'HKgccs-B5-V',
  21441. 'HKm314-B5-H',
  21442. 'HKm314-B5-V',
  21443. 'HKm471-B5-H',
  21444. 'HKm471-B5-V',
  21445. 'HKscs-B5-H',
  21446. 'HKscs-B5-V',
  21447. 'Hankaku',
  21448. 'Hiragana',
  21449. 'KSC-EUC-H',
  21450. 'KSC-EUC-V',
  21451. 'KSC-H',
  21452. 'KSC-Johab-H',
  21453. 'KSC-Johab-V',
  21454. 'KSC-V',
  21455. 'KSCms-UHC-H',
  21456. 'KSCms-UHC-HW-H',
  21457. 'KSCms-UHC-HW-V',
  21458. 'KSCms-UHC-V',
  21459. 'KSCpc-EUC-H',
  21460. 'KSCpc-EUC-V',
  21461. 'Katakana',
  21462. 'NWP-H',
  21463. 'NWP-V',
  21464. 'RKSJ-H',
  21465. 'RKSJ-V',
  21466. 'Roman',
  21467. 'UniCNS-UCS2-H',
  21468. 'UniCNS-UCS2-V',
  21469. 'UniCNS-UTF16-H',
  21470. 'UniCNS-UTF16-V',
  21471. 'UniCNS-UTF32-H',
  21472. 'UniCNS-UTF32-V',
  21473. 'UniCNS-UTF8-H',
  21474. 'UniCNS-UTF8-V',
  21475. 'UniGB-UCS2-H',
  21476. 'UniGB-UCS2-V',
  21477. 'UniGB-UTF16-H',
  21478. 'UniGB-UTF16-V',
  21479. 'UniGB-UTF32-H',
  21480. 'UniGB-UTF32-V',
  21481. 'UniGB-UTF8-H',
  21482. 'UniGB-UTF8-V',
  21483. 'UniJIS-UCS2-H',
  21484. 'UniJIS-UCS2-HW-H',
  21485. 'UniJIS-UCS2-HW-V',
  21486. 'UniJIS-UCS2-V',
  21487. 'UniJIS-UTF16-H',
  21488. 'UniJIS-UTF16-V',
  21489. 'UniJIS-UTF32-H',
  21490. 'UniJIS-UTF32-V',
  21491. 'UniJIS-UTF8-H',
  21492. 'UniJIS-UTF8-V',
  21493. 'UniJIS2004-UTF16-H',
  21494. 'UniJIS2004-UTF16-V',
  21495. 'UniJIS2004-UTF32-H',
  21496. 'UniJIS2004-UTF32-V',
  21497. 'UniJIS2004-UTF8-H',
  21498. 'UniJIS2004-UTF8-V',
  21499. 'UniJISPro-UCS2-HW-V',
  21500. 'UniJISPro-UCS2-V',
  21501. 'UniJISPro-UTF8-V',
  21502. 'UniJISX0213-UTF32-H',
  21503. 'UniJISX0213-UTF32-V',
  21504. 'UniJISX02132004-UTF32-H',
  21505. 'UniJISX02132004-UTF32-V',
  21506. 'UniKS-UCS2-H',
  21507. 'UniKS-UCS2-V',
  21508. 'UniKS-UTF16-H',
  21509. 'UniKS-UTF16-V',
  21510. 'UniKS-UTF32-H',
  21511. 'UniKS-UTF32-V',
  21512. 'UniKS-UTF8-H',
  21513. 'UniKS-UTF8-V',
  21514. 'V',
  21515. 'WP-Symbol'];
  21516. // CMap, not to be confused with TrueType's cmap.
  21517. var CMap = (function CMapClosure() {
  21518. function CMap(builtInCMap) {
  21519. // Codespace ranges are stored as follows:
  21520. // [[1BytePairs], [2BytePairs], [3BytePairs], [4BytePairs]]
  21521. // where nBytePairs are ranges e.g. [low1, high1, low2, high2, ...]
  21522. this.codespaceRanges = [[], [], [], []];
  21523. this.numCodespaceRanges = 0;
  21524. // Map entries have one of two forms.
  21525. // - cid chars are 16-bit unsigned integers, stored as integers.
  21526. // - bf chars are variable-length byte sequences, stored as strings, with
  21527. // one byte per character.
  21528. this._map = [];
  21529. this.name = '';
  21530. this.vertical = false;
  21531. this.useCMap = null;
  21532. this.builtInCMap = builtInCMap;
  21533. }
  21534. CMap.prototype = {
  21535. addCodespaceRange: function(n, low, high) {
  21536. this.codespaceRanges[n - 1].push(low, high);
  21537. this.numCodespaceRanges++;
  21538. },
  21539. mapCidRange: function(low, high, dstLow) {
  21540. while (low <= high) {
  21541. this._map[low++] = dstLow++;
  21542. }
  21543. },
  21544. mapBfRange: function(low, high, dstLow) {
  21545. var lastByte = dstLow.length - 1;
  21546. while (low <= high) {
  21547. this._map[low++] = dstLow;
  21548. // Only the last byte has to be incremented.
  21549. dstLow = dstLow.substr(0, lastByte) +
  21550. String.fromCharCode(dstLow.charCodeAt(lastByte) + 1);
  21551. }
  21552. },
  21553. mapBfRangeToArray: function(low, high, array) {
  21554. var i = 0, ii = array.length;
  21555. while (low <= high && i < ii) {
  21556. this._map[low] = array[i++];
  21557. ++low;
  21558. }
  21559. },
  21560. // This is used for both bf and cid chars.
  21561. mapOne: function(src, dst) {
  21562. this._map[src] = dst;
  21563. },
  21564. lookup: function(code) {
  21565. return this._map[code];
  21566. },
  21567. contains: function(code) {
  21568. return this._map[code] !== undefined;
  21569. },
  21570. forEach: function(callback) {
  21571. // Most maps have fewer than 65536 entries, and for those we use normal
  21572. // array iteration. But really sparse tables are possible -- e.g. with
  21573. // indices in the *billions*. For such tables we use for..in, which isn't
  21574. // ideal because it stringifies the indices for all present elements, but
  21575. // it does avoid iterating over every undefined entry.
  21576. var map = this._map;
  21577. var length = map.length;
  21578. var i;
  21579. if (length <= 0x10000) {
  21580. for (i = 0; i < length; i++) {
  21581. if (map[i] !== undefined) {
  21582. callback(i, map[i]);
  21583. }
  21584. }
  21585. } else {
  21586. for (i in this._map) {
  21587. callback(i, map[i]);
  21588. }
  21589. }
  21590. },
  21591. charCodeOf: function(value) {
  21592. return this._map.indexOf(value);
  21593. },
  21594. getMap: function() {
  21595. return this._map;
  21596. },
  21597. readCharCode: function(str, offset, out) {
  21598. var c = 0;
  21599. var codespaceRanges = this.codespaceRanges;
  21600. var codespaceRangesLen = this.codespaceRanges.length;
  21601. // 9.7.6.2 CMap Mapping
  21602. // The code length is at most 4.
  21603. for (var n = 0; n < codespaceRangesLen; n++) {
  21604. c = ((c << 8) | str.charCodeAt(offset + n)) >>> 0;
  21605. // Check each codespace range to see if it falls within.
  21606. var codespaceRange = codespaceRanges[n];
  21607. for (var k = 0, kk = codespaceRange.length; k < kk;) {
  21608. var low = codespaceRange[k++];
  21609. var high = codespaceRange[k++];
  21610. if (c >= low && c <= high) {
  21611. out.charcode = c;
  21612. out.length = n + 1;
  21613. return;
  21614. }
  21615. }
  21616. }
  21617. out.charcode = 0;
  21618. out.length = 1;
  21619. },
  21620. get length() {
  21621. return this._map.length;
  21622. },
  21623. get isIdentityCMap() {
  21624. if (!(this.name === 'Identity-H' || this.name === 'Identity-V')) {
  21625. return false;
  21626. }
  21627. if (this._map.length !== 0x10000) {
  21628. return false;
  21629. }
  21630. for (var i = 0; i < 0x10000; i++) {
  21631. if (this._map[i] !== i) {
  21632. return false;
  21633. }
  21634. }
  21635. return true;
  21636. }
  21637. };
  21638. return CMap;
  21639. })();
  21640. // A special case of CMap, where the _map array implicitly has a length of
  21641. // 65536 and each element is equal to its index.
  21642. var IdentityCMap = (function IdentityCMapClosure() {
  21643. function IdentityCMap(vertical, n) {
  21644. CMap.call(this);
  21645. this.vertical = vertical;
  21646. this.addCodespaceRange(n, 0, 0xffff);
  21647. }
  21648. Util.inherit(IdentityCMap, CMap, {});
  21649. IdentityCMap.prototype = {
  21650. addCodespaceRange: CMap.prototype.addCodespaceRange,
  21651. mapCidRange: function(low, high, dstLow) {
  21652. error('should not call mapCidRange');
  21653. },
  21654. mapBfRange: function(low, high, dstLow) {
  21655. error('should not call mapBfRange');
  21656. },
  21657. mapBfRangeToArray: function(low, high, array) {
  21658. error('should not call mapBfRangeToArray');
  21659. },
  21660. mapOne: function(src, dst) {
  21661. error('should not call mapCidOne');
  21662. },
  21663. lookup: function(code) {
  21664. return (isInt(code) && code <= 0xffff) ? code : undefined;
  21665. },
  21666. contains: function(code) {
  21667. return isInt(code) && code <= 0xffff;
  21668. },
  21669. forEach: function(callback) {
  21670. for (var i = 0; i <= 0xffff; i++) {
  21671. callback(i, i);
  21672. }
  21673. },
  21674. charCodeOf: function(value) {
  21675. return (isInt(value) && value <= 0xffff) ? value : -1;
  21676. },
  21677. getMap: function() {
  21678. // Sometimes identity maps must be instantiated, but it's rare.
  21679. var map = new Array(0x10000);
  21680. for (var i = 0; i <= 0xffff; i++) {
  21681. map[i] = i;
  21682. }
  21683. return map;
  21684. },
  21685. readCharCode: CMap.prototype.readCharCode,
  21686. get length() {
  21687. return 0x10000;
  21688. },
  21689. get isIdentityCMap() {
  21690. error('should not access .isIdentityCMap');
  21691. }
  21692. };
  21693. return IdentityCMap;
  21694. })();
  21695. var BinaryCMapReader = (function BinaryCMapReaderClosure() {
  21696. function fetchBinaryData(url) {
  21697. var nonBinaryRequest = PDFJS.disableWorker;
  21698. var request = new XMLHttpRequest();
  21699. request.open('GET', url, false);
  21700. if (!nonBinaryRequest) {
  21701. try {
  21702. request.responseType = 'arraybuffer';
  21703. nonBinaryRequest = request.responseType !== 'arraybuffer';
  21704. } catch (e) {
  21705. nonBinaryRequest = true;
  21706. }
  21707. }
  21708. if (nonBinaryRequest && request.overrideMimeType) {
  21709. request.overrideMimeType('text/plain; charset=x-user-defined');
  21710. }
  21711. request.send(null);
  21712. if (nonBinaryRequest ? !request.responseText : !request.response) {
  21713. error('Unable to get binary cMap at: ' + url);
  21714. }
  21715. if (nonBinaryRequest) {
  21716. var data = Array.prototype.map.call(request.responseText, function (ch) {
  21717. return ch.charCodeAt(0) & 255;
  21718. });
  21719. return new Uint8Array(data);
  21720. }
  21721. return new Uint8Array(request.response);
  21722. }
  21723. function hexToInt(a, size) {
  21724. var n = 0;
  21725. for (var i = 0; i <= size; i++) {
  21726. n = (n << 8) | a[i];
  21727. }
  21728. return n >>> 0;
  21729. }
  21730. function hexToStr(a, size) {
  21731. // This code is hot. Special-case some common values to avoid creating an
  21732. // object with subarray().
  21733. if (size === 1) {
  21734. return String.fromCharCode(a[0], a[1]);
  21735. }
  21736. if (size === 3) {
  21737. return String.fromCharCode(a[0], a[1], a[2], a[3]);
  21738. }
  21739. return String.fromCharCode.apply(null, a.subarray(0, size + 1));
  21740. }
  21741. function addHex(a, b, size) {
  21742. var c = 0;
  21743. for (var i = size; i >= 0; i--) {
  21744. c += a[i] + b[i];
  21745. a[i] = c & 255;
  21746. c >>= 8;
  21747. }
  21748. }
  21749. function incHex(a, size) {
  21750. var c = 1;
  21751. for (var i = size; i >= 0 && c > 0; i--) {
  21752. c += a[i];
  21753. a[i] = c & 255;
  21754. c >>= 8;
  21755. }
  21756. }
  21757. var MAX_NUM_SIZE = 16;
  21758. var MAX_ENCODED_NUM_SIZE = 19; // ceil(MAX_NUM_SIZE * 7 / 8)
  21759. function BinaryCMapStream(data) {
  21760. this.buffer = data;
  21761. this.pos = 0;
  21762. this.end = data.length;
  21763. this.tmpBuf = new Uint8Array(MAX_ENCODED_NUM_SIZE);
  21764. }
  21765. BinaryCMapStream.prototype = {
  21766. readByte: function () {
  21767. if (this.pos >= this.end) {
  21768. return -1;
  21769. }
  21770. return this.buffer[this.pos++];
  21771. },
  21772. readNumber: function () {
  21773. var n = 0;
  21774. var last;
  21775. do {
  21776. var b = this.readByte();
  21777. if (b < 0) {
  21778. error('unexpected EOF in bcmap');
  21779. }
  21780. last = !(b & 0x80);
  21781. n = (n << 7) | (b & 0x7F);
  21782. } while (!last);
  21783. return n;
  21784. },
  21785. readSigned: function () {
  21786. var n = this.readNumber();
  21787. return (n & 1) ? ~(n >>> 1) : n >>> 1;
  21788. },
  21789. readHex: function (num, size) {
  21790. num.set(this.buffer.subarray(this.pos,
  21791. this.pos + size + 1));
  21792. this.pos += size + 1;
  21793. },
  21794. readHexNumber: function (num, size) {
  21795. var last;
  21796. var stack = this.tmpBuf, sp = 0;
  21797. do {
  21798. var b = this.readByte();
  21799. if (b < 0) {
  21800. error('unexpected EOF in bcmap');
  21801. }
  21802. last = !(b & 0x80);
  21803. stack[sp++] = b & 0x7F;
  21804. } while (!last);
  21805. var i = size, buffer = 0, bufferSize = 0;
  21806. while (i >= 0) {
  21807. while (bufferSize < 8 && stack.length > 0) {
  21808. buffer = (stack[--sp] << bufferSize) | buffer;
  21809. bufferSize += 7;
  21810. }
  21811. num[i] = buffer & 255;
  21812. i--;
  21813. buffer >>= 8;
  21814. bufferSize -= 8;
  21815. }
  21816. },
  21817. readHexSigned: function (num, size) {
  21818. this.readHexNumber(num, size);
  21819. var sign = num[size] & 1 ? 255 : 0;
  21820. var c = 0;
  21821. for (var i = 0; i <= size; i++) {
  21822. c = ((c & 1) << 8) | num[i];
  21823. num[i] = (c >> 1) ^ sign;
  21824. }
  21825. },
  21826. readString: function () {
  21827. var len = this.readNumber();
  21828. var s = '';
  21829. for (var i = 0; i < len; i++) {
  21830. s += String.fromCharCode(this.readNumber());
  21831. }
  21832. return s;
  21833. }
  21834. };
  21835. function processBinaryCMap(url, cMap, extend) {
  21836. var data = fetchBinaryData(url);
  21837. var stream = new BinaryCMapStream(data);
  21838. var header = stream.readByte();
  21839. cMap.vertical = !!(header & 1);
  21840. var useCMap = null;
  21841. var start = new Uint8Array(MAX_NUM_SIZE);
  21842. var end = new Uint8Array(MAX_NUM_SIZE);
  21843. var char = new Uint8Array(MAX_NUM_SIZE);
  21844. var charCode = new Uint8Array(MAX_NUM_SIZE);
  21845. var tmp = new Uint8Array(MAX_NUM_SIZE);
  21846. var code;
  21847. var b;
  21848. while ((b = stream.readByte()) >= 0) {
  21849. var type = b >> 5;
  21850. if (type === 7) { // metadata, e.g. comment or usecmap
  21851. switch (b & 0x1F) {
  21852. case 0:
  21853. stream.readString(); // skipping comment
  21854. break;
  21855. case 1:
  21856. useCMap = stream.readString();
  21857. break;
  21858. }
  21859. continue;
  21860. }
  21861. var sequence = !!(b & 0x10);
  21862. var dataSize = b & 15;
  21863. assert(dataSize + 1 <= MAX_NUM_SIZE);
  21864. var ucs2DataSize = 1;
  21865. var subitemsCount = stream.readNumber();
  21866. var i;
  21867. switch (type) {
  21868. case 0: // codespacerange
  21869. stream.readHex(start, dataSize);
  21870. stream.readHexNumber(end, dataSize);
  21871. addHex(end, start, dataSize);
  21872. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  21873. hexToInt(end, dataSize));
  21874. for (i = 1; i < subitemsCount; i++) {
  21875. incHex(end, dataSize);
  21876. stream.readHexNumber(start, dataSize);
  21877. addHex(start, end, dataSize);
  21878. stream.readHexNumber(end, dataSize);
  21879. addHex(end, start, dataSize);
  21880. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  21881. hexToInt(end, dataSize));
  21882. }
  21883. break;
  21884. case 1: // notdefrange
  21885. stream.readHex(start, dataSize);
  21886. stream.readHexNumber(end, dataSize);
  21887. addHex(end, start, dataSize);
  21888. code = stream.readNumber();
  21889. // undefined range, skipping
  21890. for (i = 1; i < subitemsCount; i++) {
  21891. incHex(end, dataSize);
  21892. stream.readHexNumber(start, dataSize);
  21893. addHex(start, end, dataSize);
  21894. stream.readHexNumber(end, dataSize);
  21895. addHex(end, start, dataSize);
  21896. code = stream.readNumber();
  21897. // nop
  21898. }
  21899. break;
  21900. case 2: // cidchar
  21901. stream.readHex(char, dataSize);
  21902. code = stream.readNumber();
  21903. cMap.mapOne(hexToInt(char, dataSize), code);
  21904. for (i = 1; i < subitemsCount; i++) {
  21905. incHex(char, dataSize);
  21906. if (!sequence) {
  21907. stream.readHexNumber(tmp, dataSize);
  21908. addHex(char, tmp, dataSize);
  21909. }
  21910. code = stream.readSigned() + (code + 1);
  21911. cMap.mapOne(hexToInt(char, dataSize), code);
  21912. }
  21913. break;
  21914. case 3: // cidrange
  21915. stream.readHex(start, dataSize);
  21916. stream.readHexNumber(end, dataSize);
  21917. addHex(end, start, dataSize);
  21918. code = stream.readNumber();
  21919. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  21920. code);
  21921. for (i = 1; i < subitemsCount; i++) {
  21922. incHex(end, dataSize);
  21923. if (!sequence) {
  21924. stream.readHexNumber(start, dataSize);
  21925. addHex(start, end, dataSize);
  21926. } else {
  21927. start.set(end);
  21928. }
  21929. stream.readHexNumber(end, dataSize);
  21930. addHex(end, start, dataSize);
  21931. code = stream.readNumber();
  21932. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  21933. code);
  21934. }
  21935. break;
  21936. case 4: // bfchar
  21937. stream.readHex(char, ucs2DataSize);
  21938. stream.readHex(charCode, dataSize);
  21939. cMap.mapOne(hexToInt(char, ucs2DataSize),
  21940. hexToStr(charCode, dataSize));
  21941. for (i = 1; i < subitemsCount; i++) {
  21942. incHex(char, ucs2DataSize);
  21943. if (!sequence) {
  21944. stream.readHexNumber(tmp, ucs2DataSize);
  21945. addHex(char, tmp, ucs2DataSize);
  21946. }
  21947. incHex(charCode, dataSize);
  21948. stream.readHexSigned(tmp, dataSize);
  21949. addHex(charCode, tmp, dataSize);
  21950. cMap.mapOne(hexToInt(char, ucs2DataSize),
  21951. hexToStr(charCode, dataSize));
  21952. }
  21953. break;
  21954. case 5: // bfrange
  21955. stream.readHex(start, ucs2DataSize);
  21956. stream.readHexNumber(end, ucs2DataSize);
  21957. addHex(end, start, ucs2DataSize);
  21958. stream.readHex(charCode, dataSize);
  21959. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  21960. hexToInt(end, ucs2DataSize),
  21961. hexToStr(charCode, dataSize));
  21962. for (i = 1; i < subitemsCount; i++) {
  21963. incHex(end, ucs2DataSize);
  21964. if (!sequence) {
  21965. stream.readHexNumber(start, ucs2DataSize);
  21966. addHex(start, end, ucs2DataSize);
  21967. } else {
  21968. start.set(end);
  21969. }
  21970. stream.readHexNumber(end, ucs2DataSize);
  21971. addHex(end, start, ucs2DataSize);
  21972. stream.readHex(charCode, dataSize);
  21973. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  21974. hexToInt(end, ucs2DataSize),
  21975. hexToStr(charCode, dataSize));
  21976. }
  21977. break;
  21978. default:
  21979. error('Unknown type: ' + type);
  21980. break;
  21981. }
  21982. }
  21983. if (useCMap) {
  21984. extend(useCMap);
  21985. }
  21986. return cMap;
  21987. }
  21988. function BinaryCMapReader() {}
  21989. BinaryCMapReader.prototype = {
  21990. read: processBinaryCMap
  21991. };
  21992. return BinaryCMapReader;
  21993. })();
  21994. var CMapFactory = (function CMapFactoryClosure() {
  21995. function strToInt(str) {
  21996. var a = 0;
  21997. for (var i = 0; i < str.length; i++) {
  21998. a = (a << 8) | str.charCodeAt(i);
  21999. }
  22000. return a >>> 0;
  22001. }
  22002. function expectString(obj) {
  22003. if (!isString(obj)) {
  22004. error('Malformed CMap: expected string.');
  22005. }
  22006. }
  22007. function expectInt(obj) {
  22008. if (!isInt(obj)) {
  22009. error('Malformed CMap: expected int.');
  22010. }
  22011. }
  22012. function parseBfChar(cMap, lexer) {
  22013. while (true) {
  22014. var obj = lexer.getObj();
  22015. if (isEOF(obj)) {
  22016. break;
  22017. }
  22018. if (isCmd(obj, 'endbfchar')) {
  22019. return;
  22020. }
  22021. expectString(obj);
  22022. var src = strToInt(obj);
  22023. obj = lexer.getObj();
  22024. // TODO are /dstName used?
  22025. expectString(obj);
  22026. var dst = obj;
  22027. cMap.mapOne(src, dst);
  22028. }
  22029. }
  22030. function parseBfRange(cMap, lexer) {
  22031. while (true) {
  22032. var obj = lexer.getObj();
  22033. if (isEOF(obj)) {
  22034. break;
  22035. }
  22036. if (isCmd(obj, 'endbfrange')) {
  22037. return;
  22038. }
  22039. expectString(obj);
  22040. var low = strToInt(obj);
  22041. obj = lexer.getObj();
  22042. expectString(obj);
  22043. var high = strToInt(obj);
  22044. obj = lexer.getObj();
  22045. if (isInt(obj) || isString(obj)) {
  22046. var dstLow = isInt(obj) ? String.fromCharCode(obj) : obj;
  22047. cMap.mapBfRange(low, high, dstLow);
  22048. } else if (isCmd(obj, '[')) {
  22049. obj = lexer.getObj();
  22050. var array = [];
  22051. while (!isCmd(obj, ']') && !isEOF(obj)) {
  22052. array.push(obj);
  22053. obj = lexer.getObj();
  22054. }
  22055. cMap.mapBfRangeToArray(low, high, array);
  22056. } else {
  22057. break;
  22058. }
  22059. }
  22060. error('Invalid bf range.');
  22061. }
  22062. function parseCidChar(cMap, lexer) {
  22063. while (true) {
  22064. var obj = lexer.getObj();
  22065. if (isEOF(obj)) {
  22066. break;
  22067. }
  22068. if (isCmd(obj, 'endcidchar')) {
  22069. return;
  22070. }
  22071. expectString(obj);
  22072. var src = strToInt(obj);
  22073. obj = lexer.getObj();
  22074. expectInt(obj);
  22075. var dst = obj;
  22076. cMap.mapOne(src, dst);
  22077. }
  22078. }
  22079. function parseCidRange(cMap, lexer) {
  22080. while (true) {
  22081. var obj = lexer.getObj();
  22082. if (isEOF(obj)) {
  22083. break;
  22084. }
  22085. if (isCmd(obj, 'endcidrange')) {
  22086. return;
  22087. }
  22088. expectString(obj);
  22089. var low = strToInt(obj);
  22090. obj = lexer.getObj();
  22091. expectString(obj);
  22092. var high = strToInt(obj);
  22093. obj = lexer.getObj();
  22094. expectInt(obj);
  22095. var dstLow = obj;
  22096. cMap.mapCidRange(low, high, dstLow);
  22097. }
  22098. }
  22099. function parseCodespaceRange(cMap, lexer) {
  22100. while (true) {
  22101. var obj = lexer.getObj();
  22102. if (isEOF(obj)) {
  22103. break;
  22104. }
  22105. if (isCmd(obj, 'endcodespacerange')) {
  22106. return;
  22107. }
  22108. if (!isString(obj)) {
  22109. break;
  22110. }
  22111. var low = strToInt(obj);
  22112. obj = lexer.getObj();
  22113. if (!isString(obj)) {
  22114. break;
  22115. }
  22116. var high = strToInt(obj);
  22117. cMap.addCodespaceRange(obj.length, low, high);
  22118. }
  22119. error('Invalid codespace range.');
  22120. }
  22121. function parseWMode(cMap, lexer) {
  22122. var obj = lexer.getObj();
  22123. if (isInt(obj)) {
  22124. cMap.vertical = !!obj;
  22125. }
  22126. }
  22127. function parseCMapName(cMap, lexer) {
  22128. var obj = lexer.getObj();
  22129. if (isName(obj) && isString(obj.name)) {
  22130. cMap.name = obj.name;
  22131. }
  22132. }
  22133. function parseCMap(cMap, lexer, builtInCMapParams, useCMap) {
  22134. var previous;
  22135. var embededUseCMap;
  22136. objLoop: while (true) {
  22137. var obj = lexer.getObj();
  22138. if (isEOF(obj)) {
  22139. break;
  22140. } else if (isName(obj)) {
  22141. if (obj.name === 'WMode') {
  22142. parseWMode(cMap, lexer);
  22143. } else if (obj.name === 'CMapName') {
  22144. parseCMapName(cMap, lexer);
  22145. }
  22146. previous = obj;
  22147. } else if (isCmd(obj)) {
  22148. switch (obj.cmd) {
  22149. case 'endcmap':
  22150. break objLoop;
  22151. case 'usecmap':
  22152. if (isName(previous)) {
  22153. embededUseCMap = previous.name;
  22154. }
  22155. break;
  22156. case 'begincodespacerange':
  22157. parseCodespaceRange(cMap, lexer);
  22158. break;
  22159. case 'beginbfchar':
  22160. parseBfChar(cMap, lexer);
  22161. break;
  22162. case 'begincidchar':
  22163. parseCidChar(cMap, lexer);
  22164. break;
  22165. case 'beginbfrange':
  22166. parseBfRange(cMap, lexer);
  22167. break;
  22168. case 'begincidrange':
  22169. parseCidRange(cMap, lexer);
  22170. break;
  22171. }
  22172. }
  22173. }
  22174. if (!useCMap && embededUseCMap) {
  22175. // Load the usecmap definition from the file only if there wasn't one
  22176. // specified.
  22177. useCMap = embededUseCMap;
  22178. }
  22179. if (useCMap) {
  22180. extendCMap(cMap, builtInCMapParams, useCMap);
  22181. }
  22182. }
  22183. function extendCMap(cMap, builtInCMapParams, useCMap) {
  22184. cMap.useCMap = createBuiltInCMap(useCMap, builtInCMapParams);
  22185. // If there aren't any code space ranges defined clone all the parent ones
  22186. // into this cMap.
  22187. if (cMap.numCodespaceRanges === 0) {
  22188. var useCodespaceRanges = cMap.useCMap.codespaceRanges;
  22189. for (var i = 0; i < useCodespaceRanges.length; i++) {
  22190. cMap.codespaceRanges[i] = useCodespaceRanges[i].slice();
  22191. }
  22192. cMap.numCodespaceRanges = cMap.useCMap.numCodespaceRanges;
  22193. }
  22194. // Merge the map into the current one, making sure not to override
  22195. // any previously defined entries.
  22196. cMap.useCMap.forEach(function(key, value) {
  22197. if (!cMap.contains(key)) {
  22198. cMap.mapOne(key, cMap.useCMap.lookup(key));
  22199. }
  22200. });
  22201. }
  22202. function parseBinaryCMap(name, builtInCMapParams) {
  22203. var url = builtInCMapParams.url + name + '.bcmap';
  22204. var cMap = new CMap(true);
  22205. new BinaryCMapReader().read(url, cMap, function (useCMap) {
  22206. extendCMap(cMap, builtInCMapParams, useCMap);
  22207. });
  22208. return cMap;
  22209. }
  22210. function createBuiltInCMap(name, builtInCMapParams) {
  22211. if (name === 'Identity-H') {
  22212. return new IdentityCMap(false, 2);
  22213. } else if (name === 'Identity-V') {
  22214. return new IdentityCMap(true, 2);
  22215. }
  22216. if (BUILT_IN_CMAPS.indexOf(name) === -1) {
  22217. error('Unknown cMap name: ' + name);
  22218. }
  22219. assert(builtInCMapParams, 'built-in cMap parameters are not provided');
  22220. if (builtInCMapParams.packed) {
  22221. return parseBinaryCMap(name, builtInCMapParams);
  22222. }
  22223. var request = new XMLHttpRequest();
  22224. var url = builtInCMapParams.url + name;
  22225. request.open('GET', url, false);
  22226. request.send(null);
  22227. if (!request.responseText) {
  22228. error('Unable to get cMap at: ' + url);
  22229. }
  22230. var cMap = new CMap(true);
  22231. var lexer = new Lexer(new StringStream(request.responseText));
  22232. parseCMap(cMap, lexer, builtInCMapParams, null);
  22233. return cMap;
  22234. }
  22235. return {
  22236. create: function (encoding, builtInCMapParams, useCMap) {
  22237. if (isName(encoding)) {
  22238. return createBuiltInCMap(encoding.name, builtInCMapParams);
  22239. } else if (isStream(encoding)) {
  22240. var cMap = new CMap();
  22241. var lexer = new Lexer(encoding);
  22242. try {
  22243. parseCMap(cMap, lexer, builtInCMapParams, useCMap);
  22244. } catch (e) {
  22245. warn('Invalid CMap data. ' + e);
  22246. }
  22247. if (cMap.isIdentityCMap) {
  22248. return createBuiltInCMap(cMap.name, builtInCMapParams);
  22249. }
  22250. return cMap;
  22251. }
  22252. error('Encoding required.');
  22253. }
  22254. };
  22255. })();
  22256. exports.CMap = CMap;
  22257. exports.CMapFactory = CMapFactory;
  22258. exports.IdentityCMap = IdentityCMap;
  22259. }));
  22260. (function (root, factory) {
  22261. {
  22262. factory((root.pdfjsCoreObj = {}), root.pdfjsSharedUtil,
  22263. root.pdfjsCorePrimitives, root.pdfjsCoreCrypto, root.pdfjsCoreParser,
  22264. root.pdfjsCoreChunkedStream);
  22265. }
  22266. }(this, function (exports, sharedUtil, corePrimitives, coreCrypto, coreParser,
  22267. coreChunkedStream) {
  22268. var InvalidPDFException = sharedUtil.InvalidPDFException;
  22269. var MissingDataException = sharedUtil.MissingDataException;
  22270. var XRefParseException = sharedUtil.XRefParseException;
  22271. var assert = sharedUtil.assert;
  22272. var bytesToString = sharedUtil.bytesToString;
  22273. var createPromiseCapability = sharedUtil.createPromiseCapability;
  22274. var error = sharedUtil.error;
  22275. var info = sharedUtil.info;
  22276. var isArray = sharedUtil.isArray;
  22277. var isInt = sharedUtil.isInt;
  22278. var isString = sharedUtil.isString;
  22279. var shadow = sharedUtil.shadow;
  22280. var stringToPDFString = sharedUtil.stringToPDFString;
  22281. var stringToUTF8String = sharedUtil.stringToUTF8String;
  22282. var warn = sharedUtil.warn;
  22283. var isValidUrl = sharedUtil.isValidUrl;
  22284. var Util = sharedUtil.Util;
  22285. var Ref = corePrimitives.Ref;
  22286. var RefSet = corePrimitives.RefSet;
  22287. var RefSetCache = corePrimitives.RefSetCache;
  22288. var isName = corePrimitives.isName;
  22289. var isCmd = corePrimitives.isCmd;
  22290. var isDict = corePrimitives.isDict;
  22291. var isRef = corePrimitives.isRef;
  22292. var isStream = corePrimitives.isStream;
  22293. var CipherTransformFactory = coreCrypto.CipherTransformFactory;
  22294. var Lexer = coreParser.Lexer;
  22295. var Parser = coreParser.Parser;
  22296. var ChunkedStream = coreChunkedStream.ChunkedStream;
  22297. var Catalog = (function CatalogClosure() {
  22298. function Catalog(pdfManager, xref, pageFactory) {
  22299. this.pdfManager = pdfManager;
  22300. this.xref = xref;
  22301. this.catDict = xref.getCatalogObj();
  22302. this.fontCache = new RefSetCache();
  22303. assert(isDict(this.catDict),
  22304. 'catalog object is not a dictionary');
  22305. // TODO refactor to move getPage() to the PDFDocument.
  22306. this.pageFactory = pageFactory;
  22307. this.pagePromises = [];
  22308. }
  22309. Catalog.prototype = {
  22310. get metadata() {
  22311. var streamRef = this.catDict.getRaw('Metadata');
  22312. if (!isRef(streamRef)) {
  22313. return shadow(this, 'metadata', null);
  22314. }
  22315. var encryptMetadata = (!this.xref.encrypt ? false :
  22316. this.xref.encrypt.encryptMetadata);
  22317. var stream = this.xref.fetch(streamRef, !encryptMetadata);
  22318. var metadata;
  22319. if (stream && isDict(stream.dict)) {
  22320. var type = stream.dict.get('Type');
  22321. var subtype = stream.dict.get('Subtype');
  22322. if (isName(type) && isName(subtype) &&
  22323. type.name === 'Metadata' && subtype.name === 'XML') {
  22324. // XXX: This should examine the charset the XML document defines,
  22325. // however since there are currently no real means to decode
  22326. // arbitrary charsets, let's just hope that the author of the PDF
  22327. // was reasonable enough to stick with the XML default charset,
  22328. // which is UTF-8.
  22329. try {
  22330. metadata = stringToUTF8String(bytesToString(stream.getBytes()));
  22331. } catch (e) {
  22332. info('Skipping invalid metadata.');
  22333. }
  22334. }
  22335. }
  22336. return shadow(this, 'metadata', metadata);
  22337. },
  22338. get toplevelPagesDict() {
  22339. var pagesObj = this.catDict.get('Pages');
  22340. assert(isDict(pagesObj), 'invalid top-level pages dictionary');
  22341. // shadow the prototype getter
  22342. return shadow(this, 'toplevelPagesDict', pagesObj);
  22343. },
  22344. get documentOutline() {
  22345. var obj = null;
  22346. try {
  22347. obj = this.readDocumentOutline();
  22348. } catch (ex) {
  22349. if (ex instanceof MissingDataException) {
  22350. throw ex;
  22351. }
  22352. warn('Unable to read document outline');
  22353. }
  22354. return shadow(this, 'documentOutline', obj);
  22355. },
  22356. readDocumentOutline: function Catalog_readDocumentOutline() {
  22357. var xref = this.xref;
  22358. var obj = this.catDict.get('Outlines');
  22359. var root = { items: [] };
  22360. if (isDict(obj)) {
  22361. obj = obj.getRaw('First');
  22362. var processed = new RefSet();
  22363. if (isRef(obj)) {
  22364. var queue = [{obj: obj, parent: root}];
  22365. // to avoid recursion keeping track of the items
  22366. // in the processed dictionary
  22367. processed.put(obj);
  22368. while (queue.length > 0) {
  22369. var i = queue.shift();
  22370. var outlineDict = xref.fetchIfRef(i.obj);
  22371. if (outlineDict === null) {
  22372. continue;
  22373. }
  22374. if (!outlineDict.has('Title')) {
  22375. error('Invalid outline item');
  22376. }
  22377. var actionDict = outlineDict.get('A'), dest = null, url = null;
  22378. if (actionDict) {
  22379. var destEntry = actionDict.get('D');
  22380. if (destEntry) {
  22381. dest = destEntry;
  22382. } else {
  22383. var uriEntry = actionDict.get('URI');
  22384. if (isString(uriEntry) && isValidUrl(uriEntry, false)) {
  22385. url = uriEntry;
  22386. }
  22387. }
  22388. } else if (outlineDict.has('Dest')) {
  22389. dest = outlineDict.getRaw('Dest');
  22390. if (isName(dest)) {
  22391. dest = dest.name;
  22392. }
  22393. }
  22394. var title = outlineDict.get('Title');
  22395. var outlineItem = {
  22396. dest: dest,
  22397. url: url,
  22398. title: stringToPDFString(title),
  22399. color: outlineDict.get('C') || [0, 0, 0],
  22400. count: outlineDict.get('Count'),
  22401. bold: !!(outlineDict.get('F') & 2),
  22402. italic: !!(outlineDict.get('F') & 1),
  22403. items: []
  22404. };
  22405. i.parent.items.push(outlineItem);
  22406. obj = outlineDict.getRaw('First');
  22407. if (isRef(obj) && !processed.has(obj)) {
  22408. queue.push({obj: obj, parent: outlineItem});
  22409. processed.put(obj);
  22410. }
  22411. obj = outlineDict.getRaw('Next');
  22412. if (isRef(obj) && !processed.has(obj)) {
  22413. queue.push({obj: obj, parent: i.parent});
  22414. processed.put(obj);
  22415. }
  22416. }
  22417. }
  22418. }
  22419. return (root.items.length > 0 ? root.items : null);
  22420. },
  22421. get numPages() {
  22422. var obj = this.toplevelPagesDict.get('Count');
  22423. assert(
  22424. isInt(obj),
  22425. 'page count in top level pages object is not an integer'
  22426. );
  22427. // shadow the prototype getter
  22428. return shadow(this, 'num', obj);
  22429. },
  22430. get destinations() {
  22431. function fetchDestination(dest) {
  22432. return isDict(dest) ? dest.get('D') : dest;
  22433. }
  22434. var xref = this.xref;
  22435. var dests = {}, nameTreeRef, nameDictionaryRef;
  22436. var obj = this.catDict.get('Names');
  22437. if (obj && obj.has('Dests')) {
  22438. nameTreeRef = obj.getRaw('Dests');
  22439. } else if (this.catDict.has('Dests')) {
  22440. nameDictionaryRef = this.catDict.get('Dests');
  22441. }
  22442. if (nameDictionaryRef) {
  22443. // reading simple destination dictionary
  22444. obj = nameDictionaryRef;
  22445. obj.forEach(function catalogForEach(key, value) {
  22446. if (!value) {
  22447. return;
  22448. }
  22449. dests[key] = fetchDestination(value);
  22450. });
  22451. }
  22452. if (nameTreeRef) {
  22453. var nameTree = new NameTree(nameTreeRef, xref);
  22454. var names = nameTree.getAll();
  22455. for (var name in names) {
  22456. if (!names.hasOwnProperty(name)) {
  22457. continue;
  22458. }
  22459. dests[name] = fetchDestination(names[name]);
  22460. }
  22461. }
  22462. return shadow(this, 'destinations', dests);
  22463. },
  22464. getDestination: function Catalog_getDestination(destinationId) {
  22465. function fetchDestination(dest) {
  22466. return isDict(dest) ? dest.get('D') : dest;
  22467. }
  22468. var xref = this.xref;
  22469. var dest = null, nameTreeRef, nameDictionaryRef;
  22470. var obj = this.catDict.get('Names');
  22471. if (obj && obj.has('Dests')) {
  22472. nameTreeRef = obj.getRaw('Dests');
  22473. } else if (this.catDict.has('Dests')) {
  22474. nameDictionaryRef = this.catDict.get('Dests');
  22475. }
  22476. if (nameDictionaryRef) { // Simple destination dictionary.
  22477. var value = nameDictionaryRef.get(destinationId);
  22478. if (value) {
  22479. dest = fetchDestination(value);
  22480. }
  22481. }
  22482. if (nameTreeRef) {
  22483. var nameTree = new NameTree(nameTreeRef, xref);
  22484. dest = fetchDestination(nameTree.get(destinationId));
  22485. }
  22486. return dest;
  22487. },
  22488. get pageLabels() {
  22489. var obj = null;
  22490. try {
  22491. obj = this.readPageLabels();
  22492. } catch (ex) {
  22493. if (ex instanceof MissingDataException) {
  22494. throw ex;
  22495. }
  22496. warn('Unable to read page labels.');
  22497. }
  22498. return shadow(this, 'pageLabels', obj);
  22499. },
  22500. readPageLabels: function Catalog_readPageLabels() {
  22501. var obj = this.catDict.getRaw('PageLabels');
  22502. if (!obj) {
  22503. return null;
  22504. }
  22505. var pageLabels = new Array(this.numPages);
  22506. var style = null;
  22507. var prefix = '';
  22508. var start = 1;
  22509. var numberTree = new NumberTree(obj, this.xref);
  22510. var nums = numberTree.getAll();
  22511. var currentLabel = '', currentIndex = 1;
  22512. for (var i = 0, ii = this.numPages; i < ii; i++) {
  22513. if (nums.hasOwnProperty(i)) {
  22514. var labelDict = nums[i];
  22515. assert(isDict(labelDict), 'The PageLabel is not a dictionary.');
  22516. var type = labelDict.get('Type');
  22517. assert(!type || (isName(type) && type.name === 'PageLabel'),
  22518. 'Invalid type in PageLabel dictionary.');
  22519. var s = labelDict.get('S');
  22520. assert(!s || isName(s), 'Invalid style in PageLabel dictionary.');
  22521. style = (s ? s.name : null);
  22522. prefix = labelDict.get('P') || '';
  22523. assert(isString(prefix), 'Invalid prefix in PageLabel dictionary.');
  22524. start = labelDict.get('St') || 1;
  22525. assert(isInt(start), 'Invalid start in PageLabel dictionary.');
  22526. currentIndex = start;
  22527. }
  22528. switch (style) {
  22529. case 'D':
  22530. currentLabel = currentIndex;
  22531. break;
  22532. case 'R':
  22533. case 'r':
  22534. currentLabel = Util.toRoman(currentIndex, style === 'r');
  22535. break;
  22536. case 'A':
  22537. case 'a':
  22538. var LIMIT = 26; // Use only the characters A--Z, or a--z.
  22539. var A_UPPER_CASE = 0x41, A_LOWER_CASE = 0x61;
  22540. var baseCharCode = (style === 'a' ? A_LOWER_CASE : A_UPPER_CASE);
  22541. var letterIndex = currentIndex - 1;
  22542. var character = String.fromCharCode(baseCharCode +
  22543. (letterIndex % LIMIT));
  22544. var charBuf = [];
  22545. for (var j = 0, jj = (letterIndex / LIMIT) | 0; j <= jj; j++) {
  22546. charBuf.push(character);
  22547. }
  22548. currentLabel = charBuf.join('');
  22549. break;
  22550. default:
  22551. assert(!style,
  22552. 'Invalid style "' + style + '" in PageLabel dictionary.');
  22553. }
  22554. pageLabels[i] = prefix + currentLabel;
  22555. currentLabel = '';
  22556. currentIndex++;
  22557. }
  22558. return pageLabels;
  22559. },
  22560. get attachments() {
  22561. var xref = this.xref;
  22562. var attachments = null, nameTreeRef;
  22563. var obj = this.catDict.get('Names');
  22564. if (obj) {
  22565. nameTreeRef = obj.getRaw('EmbeddedFiles');
  22566. }
  22567. if (nameTreeRef) {
  22568. var nameTree = new NameTree(nameTreeRef, xref);
  22569. var names = nameTree.getAll();
  22570. for (var name in names) {
  22571. if (!names.hasOwnProperty(name)) {
  22572. continue;
  22573. }
  22574. var fs = new FileSpec(names[name], xref);
  22575. if (!attachments) {
  22576. attachments = {};
  22577. }
  22578. attachments[stringToPDFString(name)] = fs.serializable;
  22579. }
  22580. }
  22581. return shadow(this, 'attachments', attachments);
  22582. },
  22583. get javaScript() {
  22584. var xref = this.xref;
  22585. var obj = this.catDict.get('Names');
  22586. var javaScript = [];
  22587. function appendIfJavaScriptDict(jsDict) {
  22588. var type = jsDict.get('S');
  22589. if (!isName(type) || type.name !== 'JavaScript') {
  22590. return;
  22591. }
  22592. var js = jsDict.get('JS');
  22593. if (isStream(js)) {
  22594. js = bytesToString(js.getBytes());
  22595. } else if (!isString(js)) {
  22596. return;
  22597. }
  22598. javaScript.push(stringToPDFString(js));
  22599. }
  22600. if (obj && obj.has('JavaScript')) {
  22601. var nameTree = new NameTree(obj.getRaw('JavaScript'), xref);
  22602. var names = nameTree.getAll();
  22603. for (var name in names) {
  22604. if (!names.hasOwnProperty(name)) {
  22605. continue;
  22606. }
  22607. // We don't really use the JavaScript right now. This code is
  22608. // defensive so we don't cause errors on document load.
  22609. var jsDict = names[name];
  22610. if (isDict(jsDict)) {
  22611. appendIfJavaScriptDict(jsDict);
  22612. }
  22613. }
  22614. }
  22615. // Append OpenAction actions to javaScript array
  22616. var openactionDict = this.catDict.get('OpenAction');
  22617. if (isDict(openactionDict, 'Action')) {
  22618. var actionType = openactionDict.get('S');
  22619. if (isName(actionType) && actionType.name === 'Named') {
  22620. // The named Print action is not a part of the PDF 1.7 specification,
  22621. // but is supported by many PDF readers/writers (including Adobe's).
  22622. var action = openactionDict.get('N');
  22623. if (isName(action) && action.name === 'Print') {
  22624. javaScript.push('print({});');
  22625. }
  22626. } else {
  22627. appendIfJavaScriptDict(openactionDict);
  22628. }
  22629. }
  22630. return shadow(this, 'javaScript', javaScript);
  22631. },
  22632. cleanup: function Catalog_cleanup() {
  22633. var promises = [];
  22634. this.fontCache.forEach(function (promise) {
  22635. promises.push(promise);
  22636. });
  22637. return Promise.all(promises).then(function (translatedFonts) {
  22638. for (var i = 0, ii = translatedFonts.length; i < ii; i++) {
  22639. var font = translatedFonts[i].dict;
  22640. delete font.translated;
  22641. }
  22642. this.fontCache.clear();
  22643. }.bind(this));
  22644. },
  22645. getPage: function Catalog_getPage(pageIndex) {
  22646. if (!(pageIndex in this.pagePromises)) {
  22647. this.pagePromises[pageIndex] = this.getPageDict(pageIndex).then(
  22648. function (a) {
  22649. var dict = a[0];
  22650. var ref = a[1];
  22651. return this.pageFactory.createPage(pageIndex, dict, ref,
  22652. this.fontCache);
  22653. }.bind(this)
  22654. );
  22655. }
  22656. return this.pagePromises[pageIndex];
  22657. },
  22658. getPageDict: function Catalog_getPageDict(pageIndex) {
  22659. var capability = createPromiseCapability();
  22660. var nodesToVisit = [this.catDict.getRaw('Pages')];
  22661. var currentPageIndex = 0;
  22662. var xref = this.xref;
  22663. var checkAllKids = false;
  22664. function next() {
  22665. while (nodesToVisit.length) {
  22666. var currentNode = nodesToVisit.pop();
  22667. if (isRef(currentNode)) {
  22668. xref.fetchAsync(currentNode).then(function (obj) {
  22669. if (isDict(obj, 'Page') || (isDict(obj) && !obj.has('Kids'))) {
  22670. if (pageIndex === currentPageIndex) {
  22671. capability.resolve([obj, currentNode]);
  22672. } else {
  22673. currentPageIndex++;
  22674. next();
  22675. }
  22676. return;
  22677. }
  22678. nodesToVisit.push(obj);
  22679. next();
  22680. }, capability.reject);
  22681. return;
  22682. }
  22683. // Must be a child page dictionary.
  22684. assert(
  22685. isDict(currentNode),
  22686. 'page dictionary kid reference points to wrong type of object'
  22687. );
  22688. var count = currentNode.get('Count');
  22689. // If the current node doesn't have any children, avoid getting stuck
  22690. // in an empty node further down in the tree (see issue5644.pdf).
  22691. if (count === 0) {
  22692. checkAllKids = true;
  22693. }
  22694. // Skip nodes where the page can't be.
  22695. if (currentPageIndex + count <= pageIndex) {
  22696. currentPageIndex += count;
  22697. continue;
  22698. }
  22699. var kids = currentNode.get('Kids');
  22700. assert(isArray(kids), 'page dictionary kids object is not an array');
  22701. if (!checkAllKids && count === kids.length) {
  22702. // Nodes that don't have the page have been skipped and this is the
  22703. // bottom of the tree which means the page requested must be a
  22704. // descendant of this pages node. Ideally we would just resolve the
  22705. // promise with the page ref here, but there is the case where more
  22706. // pages nodes could link to single a page (see issue 3666 pdf). To
  22707. // handle this push it back on the queue so if it is a pages node it
  22708. // will be descended into.
  22709. nodesToVisit = [kids[pageIndex - currentPageIndex]];
  22710. currentPageIndex = pageIndex;
  22711. continue;
  22712. } else {
  22713. for (var last = kids.length - 1; last >= 0; last--) {
  22714. nodesToVisit.push(kids[last]);
  22715. }
  22716. }
  22717. }
  22718. capability.reject('Page index ' + pageIndex + ' not found.');
  22719. }
  22720. next();
  22721. return capability.promise;
  22722. },
  22723. getPageIndex: function Catalog_getPageIndex(ref) {
  22724. // The page tree nodes have the count of all the leaves below them. To get
  22725. // how many pages are before we just have to walk up the tree and keep
  22726. // adding the count of siblings to the left of the node.
  22727. var xref = this.xref;
  22728. function pagesBeforeRef(kidRef) {
  22729. var total = 0;
  22730. var parentRef;
  22731. return xref.fetchAsync(kidRef).then(function (node) {
  22732. if (!node) {
  22733. return null;
  22734. }
  22735. parentRef = node.getRaw('Parent');
  22736. return node.getAsync('Parent');
  22737. }).then(function (parent) {
  22738. if (!parent) {
  22739. return null;
  22740. }
  22741. return parent.getAsync('Kids');
  22742. }).then(function (kids) {
  22743. if (!kids) {
  22744. return null;
  22745. }
  22746. var kidPromises = [];
  22747. var found = false;
  22748. for (var i = 0; i < kids.length; i++) {
  22749. var kid = kids[i];
  22750. assert(isRef(kid), 'kids must be a ref');
  22751. if (kid.num === kidRef.num) {
  22752. found = true;
  22753. break;
  22754. }
  22755. kidPromises.push(xref.fetchAsync(kid).then(function (kid) {
  22756. if (kid.has('Count')) {
  22757. var count = kid.get('Count');
  22758. total += count;
  22759. } else { // page leaf node
  22760. total++;
  22761. }
  22762. }));
  22763. }
  22764. if (!found) {
  22765. error('kid ref not found in parents kids');
  22766. }
  22767. return Promise.all(kidPromises).then(function () {
  22768. return [total, parentRef];
  22769. });
  22770. });
  22771. }
  22772. var total = 0;
  22773. function next(ref) {
  22774. return pagesBeforeRef(ref).then(function (args) {
  22775. if (!args) {
  22776. return total;
  22777. }
  22778. var count = args[0];
  22779. var parentRef = args[1];
  22780. total += count;
  22781. return next(parentRef);
  22782. });
  22783. }
  22784. return next(ref);
  22785. }
  22786. };
  22787. return Catalog;
  22788. })();
  22789. var XRef = (function XRefClosure() {
  22790. function XRef(stream, password) {
  22791. this.stream = stream;
  22792. this.entries = [];
  22793. this.xrefstms = {};
  22794. // prepare the XRef cache
  22795. this.cache = [];
  22796. this.password = password;
  22797. this.stats = {
  22798. streamTypes: [],
  22799. fontTypes: []
  22800. };
  22801. }
  22802. XRef.prototype = {
  22803. setStartXRef: function XRef_setStartXRef(startXRef) {
  22804. // Store the starting positions of xref tables as we process them
  22805. // so we can recover from missing data errors
  22806. this.startXRefQueue = [startXRef];
  22807. },
  22808. parse: function XRef_parse(recoveryMode) {
  22809. var trailerDict;
  22810. if (!recoveryMode) {
  22811. trailerDict = this.readXRef();
  22812. } else {
  22813. warn('Indexing all PDF objects');
  22814. trailerDict = this.indexObjects();
  22815. }
  22816. trailerDict.assignXref(this);
  22817. this.trailer = trailerDict;
  22818. var encrypt = trailerDict.get('Encrypt');
  22819. if (encrypt) {
  22820. var ids = trailerDict.get('ID');
  22821. var fileId = (ids && ids.length) ? ids[0] : '';
  22822. this.encrypt = new CipherTransformFactory(encrypt, fileId,
  22823. this.password);
  22824. }
  22825. // get the root dictionary (catalog) object
  22826. if (!(this.root = trailerDict.get('Root'))) {
  22827. error('Invalid root reference');
  22828. }
  22829. },
  22830. processXRefTable: function XRef_processXRefTable(parser) {
  22831. if (!('tableState' in this)) {
  22832. // Stores state of the table as we process it so we can resume
  22833. // from middle of table in case of missing data error
  22834. this.tableState = {
  22835. entryNum: 0,
  22836. streamPos: parser.lexer.stream.pos,
  22837. parserBuf1: parser.buf1,
  22838. parserBuf2: parser.buf2
  22839. };
  22840. }
  22841. var obj = this.readXRefTable(parser);
  22842. // Sanity check
  22843. if (!isCmd(obj, 'trailer')) {
  22844. error('Invalid XRef table: could not find trailer dictionary');
  22845. }
  22846. // Read trailer dictionary, e.g.
  22847. // trailer
  22848. // << /Size 22
  22849. // /Root 20R
  22850. // /Info 10R
  22851. // /ID [ <81b14aafa313db63dbd6f981e49f94f4> ]
  22852. // >>
  22853. // The parser goes through the entire stream << ... >> and provides
  22854. // a getter interface for the key-value table
  22855. var dict = parser.getObj();
  22856. // The pdflib PDF generator can generate a nested trailer dictionary
  22857. if (!isDict(dict) && dict.dict) {
  22858. dict = dict.dict;
  22859. }
  22860. if (!isDict(dict)) {
  22861. error('Invalid XRef table: could not parse trailer dictionary');
  22862. }
  22863. delete this.tableState;
  22864. return dict;
  22865. },
  22866. readXRefTable: function XRef_readXRefTable(parser) {
  22867. // Example of cross-reference table:
  22868. // xref
  22869. // 0 1 <-- subsection header (first obj #, obj count)
  22870. // 0000000000 65535 f <-- actual object (offset, generation #, f/n)
  22871. // 23 2 <-- subsection header ... and so on ...
  22872. // 0000025518 00002 n
  22873. // 0000025635 00000 n
  22874. // trailer
  22875. // ...
  22876. var stream = parser.lexer.stream;
  22877. var tableState = this.tableState;
  22878. stream.pos = tableState.streamPos;
  22879. parser.buf1 = tableState.parserBuf1;
  22880. parser.buf2 = tableState.parserBuf2;
  22881. // Outer loop is over subsection headers
  22882. var obj;
  22883. while (true) {
  22884. if (!('firstEntryNum' in tableState) || !('entryCount' in tableState)) {
  22885. if (isCmd(obj = parser.getObj(), 'trailer')) {
  22886. break;
  22887. }
  22888. tableState.firstEntryNum = obj;
  22889. tableState.entryCount = parser.getObj();
  22890. }
  22891. var first = tableState.firstEntryNum;
  22892. var count = tableState.entryCount;
  22893. if (!isInt(first) || !isInt(count)) {
  22894. error('Invalid XRef table: wrong types in subsection header');
  22895. }
  22896. // Inner loop is over objects themselves
  22897. for (var i = tableState.entryNum; i < count; i++) {
  22898. tableState.streamPos = stream.pos;
  22899. tableState.entryNum = i;
  22900. tableState.parserBuf1 = parser.buf1;
  22901. tableState.parserBuf2 = parser.buf2;
  22902. var entry = {};
  22903. entry.offset = parser.getObj();
  22904. entry.gen = parser.getObj();
  22905. var type = parser.getObj();
  22906. if (isCmd(type, 'f')) {
  22907. entry.free = true;
  22908. } else if (isCmd(type, 'n')) {
  22909. entry.uncompressed = true;
  22910. }
  22911. // Validate entry obj
  22912. if (!isInt(entry.offset) || !isInt(entry.gen) ||
  22913. !(entry.free || entry.uncompressed)) {
  22914. error('Invalid entry in XRef subsection: ' + first + ', ' + count);
  22915. }
  22916. if (!this.entries[i + first]) {
  22917. this.entries[i + first] = entry;
  22918. }
  22919. }
  22920. tableState.entryNum = 0;
  22921. tableState.streamPos = stream.pos;
  22922. tableState.parserBuf1 = parser.buf1;
  22923. tableState.parserBuf2 = parser.buf2;
  22924. delete tableState.firstEntryNum;
  22925. delete tableState.entryCount;
  22926. }
  22927. // Per issue 3248: hp scanners generate bad XRef
  22928. if (first === 1 && this.entries[1] && this.entries[1].free) {
  22929. // shifting the entries
  22930. this.entries.shift();
  22931. }
  22932. // Sanity check: as per spec, first object must be free
  22933. if (this.entries[0] && !this.entries[0].free) {
  22934. error('Invalid XRef table: unexpected first object');
  22935. }
  22936. return obj;
  22937. },
  22938. processXRefStream: function XRef_processXRefStream(stream) {
  22939. if (!('streamState' in this)) {
  22940. // Stores state of the stream as we process it so we can resume
  22941. // from middle of stream in case of missing data error
  22942. var streamParameters = stream.dict;
  22943. var byteWidths = streamParameters.get('W');
  22944. var range = streamParameters.get('Index');
  22945. if (!range) {
  22946. range = [0, streamParameters.get('Size')];
  22947. }
  22948. this.streamState = {
  22949. entryRanges: range,
  22950. byteWidths: byteWidths,
  22951. entryNum: 0,
  22952. streamPos: stream.pos
  22953. };
  22954. }
  22955. this.readXRefStream(stream);
  22956. delete this.streamState;
  22957. return stream.dict;
  22958. },
  22959. readXRefStream: function XRef_readXRefStream(stream) {
  22960. var i, j;
  22961. var streamState = this.streamState;
  22962. stream.pos = streamState.streamPos;
  22963. var byteWidths = streamState.byteWidths;
  22964. var typeFieldWidth = byteWidths[0];
  22965. var offsetFieldWidth = byteWidths[1];
  22966. var generationFieldWidth = byteWidths[2];
  22967. var entryRanges = streamState.entryRanges;
  22968. while (entryRanges.length > 0) {
  22969. var first = entryRanges[0];
  22970. var n = entryRanges[1];
  22971. if (!isInt(first) || !isInt(n)) {
  22972. error('Invalid XRef range fields: ' + first + ', ' + n);
  22973. }
  22974. if (!isInt(typeFieldWidth) || !isInt(offsetFieldWidth) ||
  22975. !isInt(generationFieldWidth)) {
  22976. error('Invalid XRef entry fields length: ' + first + ', ' + n);
  22977. }
  22978. for (i = streamState.entryNum; i < n; ++i) {
  22979. streamState.entryNum = i;
  22980. streamState.streamPos = stream.pos;
  22981. var type = 0, offset = 0, generation = 0;
  22982. for (j = 0; j < typeFieldWidth; ++j) {
  22983. type = (type << 8) | stream.getByte();
  22984. }
  22985. // if type field is absent, its default value is 1
  22986. if (typeFieldWidth === 0) {
  22987. type = 1;
  22988. }
  22989. for (j = 0; j < offsetFieldWidth; ++j) {
  22990. offset = (offset << 8) | stream.getByte();
  22991. }
  22992. for (j = 0; j < generationFieldWidth; ++j) {
  22993. generation = (generation << 8) | stream.getByte();
  22994. }
  22995. var entry = {};
  22996. entry.offset = offset;
  22997. entry.gen = generation;
  22998. switch (type) {
  22999. case 0:
  23000. entry.free = true;
  23001. break;
  23002. case 1:
  23003. entry.uncompressed = true;
  23004. break;
  23005. case 2:
  23006. break;
  23007. default:
  23008. error('Invalid XRef entry type: ' + type);
  23009. }
  23010. if (!this.entries[first + i]) {
  23011. this.entries[first + i] = entry;
  23012. }
  23013. }
  23014. streamState.entryNum = 0;
  23015. streamState.streamPos = stream.pos;
  23016. entryRanges.splice(0, 2);
  23017. }
  23018. },
  23019. indexObjects: function XRef_indexObjects() {
  23020. // Simple scan through the PDF content to find objects,
  23021. // trailers and XRef streams.
  23022. var TAB = 0x9, LF = 0xA, CR = 0xD, SPACE = 0x20;
  23023. var PERCENT = 0x25, LT = 0x3C;
  23024. function readToken(data, offset) {
  23025. var token = '', ch = data[offset];
  23026. while (ch !== LF && ch !== CR && ch !== LT) {
  23027. if (++offset >= data.length) {
  23028. break;
  23029. }
  23030. token += String.fromCharCode(ch);
  23031. ch = data[offset];
  23032. }
  23033. return token;
  23034. }
  23035. function skipUntil(data, offset, what) {
  23036. var length = what.length, dataLength = data.length;
  23037. var skipped = 0;
  23038. // finding byte sequence
  23039. while (offset < dataLength) {
  23040. var i = 0;
  23041. while (i < length && data[offset + i] === what[i]) {
  23042. ++i;
  23043. }
  23044. if (i >= length) {
  23045. break; // sequence found
  23046. }
  23047. offset++;
  23048. skipped++;
  23049. }
  23050. return skipped;
  23051. }
  23052. var objRegExp = /^(\d+)\s+(\d+)\s+obj\b/;
  23053. var trailerBytes = new Uint8Array([116, 114, 97, 105, 108, 101, 114]);
  23054. var startxrefBytes = new Uint8Array([115, 116, 97, 114, 116, 120, 114,
  23055. 101, 102]);
  23056. var endobjBytes = new Uint8Array([101, 110, 100, 111, 98, 106]);
  23057. var xrefBytes = new Uint8Array([47, 88, 82, 101, 102]);
  23058. // Clear out any existing entries, since they may be bogus.
  23059. this.entries.length = 0;
  23060. var stream = this.stream;
  23061. stream.pos = 0;
  23062. var buffer = stream.getBytes();
  23063. var position = stream.start, length = buffer.length;
  23064. var trailers = [], xrefStms = [];
  23065. while (position < length) {
  23066. var ch = buffer[position];
  23067. if (ch === TAB || ch === LF || ch === CR || ch === SPACE) {
  23068. ++position;
  23069. continue;
  23070. }
  23071. if (ch === PERCENT) { // %-comment
  23072. do {
  23073. ++position;
  23074. if (position >= length) {
  23075. break;
  23076. }
  23077. ch = buffer[position];
  23078. } while (ch !== LF && ch !== CR);
  23079. continue;
  23080. }
  23081. var token = readToken(buffer, position);
  23082. var m;
  23083. if (token.indexOf('xref') === 0 &&
  23084. (token.length === 4 || /\s/.test(token[4]))) {
  23085. position += skipUntil(buffer, position, trailerBytes);
  23086. trailers.push(position);
  23087. position += skipUntil(buffer, position, startxrefBytes);
  23088. } else if ((m = objRegExp.exec(token))) {
  23089. if (typeof this.entries[m[1]] === 'undefined') {
  23090. this.entries[m[1]] = {
  23091. offset: position - stream.start,
  23092. gen: m[2] | 0,
  23093. uncompressed: true
  23094. };
  23095. }
  23096. var contentLength = skipUntil(buffer, position, endobjBytes) + 7;
  23097. var content = buffer.subarray(position, position + contentLength);
  23098. // checking XRef stream suspect
  23099. // (it shall have '/XRef' and next char is not a letter)
  23100. var xrefTagOffset = skipUntil(content, 0, xrefBytes);
  23101. if (xrefTagOffset < contentLength &&
  23102. content[xrefTagOffset + 5] < 64) {
  23103. xrefStms.push(position - stream.start);
  23104. this.xrefstms[position - stream.start] = 1; // Avoid recursion
  23105. }
  23106. position += contentLength;
  23107. } else if (token.indexOf('trailer') === 0 &&
  23108. (token.length === 7 || /\s/.test(token[7]))) {
  23109. trailers.push(position);
  23110. position += skipUntil(buffer, position, startxrefBytes);
  23111. } else {
  23112. position += token.length + 1;
  23113. }
  23114. }
  23115. // reading XRef streams
  23116. var i, ii;
  23117. for (i = 0, ii = xrefStms.length; i < ii; ++i) {
  23118. this.startXRefQueue.push(xrefStms[i]);
  23119. this.readXRef(/* recoveryMode */ true);
  23120. }
  23121. // finding main trailer
  23122. var dict;
  23123. for (i = 0, ii = trailers.length; i < ii; ++i) {
  23124. stream.pos = trailers[i];
  23125. var parser = new Parser(new Lexer(stream), true, this);
  23126. var obj = parser.getObj();
  23127. if (!isCmd(obj, 'trailer')) {
  23128. continue;
  23129. }
  23130. // read the trailer dictionary
  23131. if (!isDict(dict = parser.getObj())) {
  23132. continue;
  23133. }
  23134. // taking the first one with 'ID'
  23135. if (dict.has('ID')) {
  23136. return dict;
  23137. }
  23138. }
  23139. // no tailer with 'ID', taking last one (if exists)
  23140. if (dict) {
  23141. return dict;
  23142. }
  23143. // nothing helps
  23144. // calling error() would reject worker with an UnknownErrorException.
  23145. throw new InvalidPDFException('Invalid PDF structure');
  23146. },
  23147. readXRef: function XRef_readXRef(recoveryMode) {
  23148. var stream = this.stream;
  23149. try {
  23150. while (this.startXRefQueue.length) {
  23151. var startXRef = this.startXRefQueue[0];
  23152. stream.pos = startXRef + stream.start;
  23153. var parser = new Parser(new Lexer(stream), true, this);
  23154. var obj = parser.getObj();
  23155. var dict;
  23156. // Get dictionary
  23157. if (isCmd(obj, 'xref')) {
  23158. // Parse end-of-file XRef
  23159. dict = this.processXRefTable(parser);
  23160. if (!this.topDict) {
  23161. this.topDict = dict;
  23162. }
  23163. // Recursively get other XRefs 'XRefStm', if any
  23164. obj = dict.get('XRefStm');
  23165. if (isInt(obj)) {
  23166. var pos = obj;
  23167. // ignore previously loaded xref streams
  23168. // (possible infinite recursion)
  23169. if (!(pos in this.xrefstms)) {
  23170. this.xrefstms[pos] = 1;
  23171. this.startXRefQueue.push(pos);
  23172. }
  23173. }
  23174. } else if (isInt(obj)) {
  23175. // Parse in-stream XRef
  23176. if (!isInt(parser.getObj()) ||
  23177. !isCmd(parser.getObj(), 'obj') ||
  23178. !isStream(obj = parser.getObj())) {
  23179. error('Invalid XRef stream');
  23180. }
  23181. dict = this.processXRefStream(obj);
  23182. if (!this.topDict) {
  23183. this.topDict = dict;
  23184. }
  23185. if (!dict) {
  23186. error('Failed to read XRef stream');
  23187. }
  23188. } else {
  23189. error('Invalid XRef stream header');
  23190. }
  23191. // Recursively get previous dictionary, if any
  23192. obj = dict.get('Prev');
  23193. if (isInt(obj)) {
  23194. this.startXRefQueue.push(obj);
  23195. } else if (isRef(obj)) {
  23196. // The spec says Prev must not be a reference, i.e. "/Prev NNN"
  23197. // This is a fallback for non-compliant PDFs, i.e. "/Prev NNN 0 R"
  23198. this.startXRefQueue.push(obj.num);
  23199. }
  23200. this.startXRefQueue.shift();
  23201. }
  23202. return this.topDict;
  23203. } catch (e) {
  23204. if (e instanceof MissingDataException) {
  23205. throw e;
  23206. }
  23207. info('(while reading XRef): ' + e);
  23208. }
  23209. if (recoveryMode) {
  23210. return;
  23211. }
  23212. throw new XRefParseException();
  23213. },
  23214. getEntry: function XRef_getEntry(i) {
  23215. var xrefEntry = this.entries[i];
  23216. if (xrefEntry && !xrefEntry.free && xrefEntry.offset) {
  23217. return xrefEntry;
  23218. }
  23219. return null;
  23220. },
  23221. fetchIfRef: function XRef_fetchIfRef(obj) {
  23222. if (!isRef(obj)) {
  23223. return obj;
  23224. }
  23225. return this.fetch(obj);
  23226. },
  23227. fetch: function XRef_fetch(ref, suppressEncryption) {
  23228. assert(isRef(ref), 'ref object is not a reference');
  23229. var num = ref.num;
  23230. if (num in this.cache) {
  23231. var cacheEntry = this.cache[num];
  23232. return cacheEntry;
  23233. }
  23234. var xrefEntry = this.getEntry(num);
  23235. // the referenced entry can be free
  23236. if (xrefEntry === null) {
  23237. return (this.cache[num] = null);
  23238. }
  23239. if (xrefEntry.uncompressed) {
  23240. xrefEntry = this.fetchUncompressed(ref, xrefEntry, suppressEncryption);
  23241. } else {
  23242. xrefEntry = this.fetchCompressed(xrefEntry, suppressEncryption);
  23243. }
  23244. if (isDict(xrefEntry)){
  23245. xrefEntry.objId = ref.toString();
  23246. } else if (isStream(xrefEntry)) {
  23247. xrefEntry.dict.objId = ref.toString();
  23248. }
  23249. return xrefEntry;
  23250. },
  23251. fetchUncompressed: function XRef_fetchUncompressed(ref, xrefEntry,
  23252. suppressEncryption) {
  23253. var gen = ref.gen;
  23254. var num = ref.num;
  23255. if (xrefEntry.gen !== gen) {
  23256. error('inconsistent generation in XRef');
  23257. }
  23258. var stream = this.stream.makeSubStream(xrefEntry.offset +
  23259. this.stream.start);
  23260. var parser = new Parser(new Lexer(stream), true, this);
  23261. var obj1 = parser.getObj();
  23262. var obj2 = parser.getObj();
  23263. var obj3 = parser.getObj();
  23264. if (!isInt(obj1) || parseInt(obj1, 10) !== num ||
  23265. !isInt(obj2) || parseInt(obj2, 10) !== gen ||
  23266. !isCmd(obj3)) {
  23267. error('bad XRef entry');
  23268. }
  23269. if (!isCmd(obj3, 'obj')) {
  23270. // some bad PDFs use "obj1234" and really mean 1234
  23271. if (obj3.cmd.indexOf('obj') === 0) {
  23272. num = parseInt(obj3.cmd.substring(3), 10);
  23273. if (!isNaN(num)) {
  23274. return num;
  23275. }
  23276. }
  23277. error('bad XRef entry');
  23278. }
  23279. if (this.encrypt && !suppressEncryption) {
  23280. xrefEntry = parser.getObj(this.encrypt.createCipherTransform(num, gen));
  23281. } else {
  23282. xrefEntry = parser.getObj();
  23283. }
  23284. if (!isStream(xrefEntry)) {
  23285. this.cache[num] = xrefEntry;
  23286. }
  23287. return xrefEntry;
  23288. },
  23289. fetchCompressed: function XRef_fetchCompressed(xrefEntry,
  23290. suppressEncryption) {
  23291. var tableOffset = xrefEntry.offset;
  23292. var stream = this.fetch(new Ref(tableOffset, 0));
  23293. if (!isStream(stream)) {
  23294. error('bad ObjStm stream');
  23295. }
  23296. var first = stream.dict.get('First');
  23297. var n = stream.dict.get('N');
  23298. if (!isInt(first) || !isInt(n)) {
  23299. error('invalid first and n parameters for ObjStm stream');
  23300. }
  23301. var parser = new Parser(new Lexer(stream), false, this);
  23302. parser.allowStreams = true;
  23303. var i, entries = [], num, nums = [];
  23304. // read the object numbers to populate cache
  23305. for (i = 0; i < n; ++i) {
  23306. num = parser.getObj();
  23307. if (!isInt(num)) {
  23308. error('invalid object number in the ObjStm stream: ' + num);
  23309. }
  23310. nums.push(num);
  23311. var offset = parser.getObj();
  23312. if (!isInt(offset)) {
  23313. error('invalid object offset in the ObjStm stream: ' + offset);
  23314. }
  23315. }
  23316. // read stream objects for cache
  23317. for (i = 0; i < n; ++i) {
  23318. entries.push(parser.getObj());
  23319. num = nums[i];
  23320. var entry = this.entries[num];
  23321. if (entry && entry.offset === tableOffset && entry.gen === i) {
  23322. this.cache[num] = entries[i];
  23323. }
  23324. }
  23325. xrefEntry = entries[xrefEntry.gen];
  23326. if (xrefEntry === undefined) {
  23327. error('bad XRef entry for compressed object');
  23328. }
  23329. return xrefEntry;
  23330. },
  23331. fetchIfRefAsync: function XRef_fetchIfRefAsync(obj) {
  23332. if (!isRef(obj)) {
  23333. return Promise.resolve(obj);
  23334. }
  23335. return this.fetchAsync(obj);
  23336. },
  23337. fetchAsync: function XRef_fetchAsync(ref, suppressEncryption) {
  23338. var streamManager = this.stream.manager;
  23339. var xref = this;
  23340. return new Promise(function tryFetch(resolve, reject) {
  23341. try {
  23342. resolve(xref.fetch(ref, suppressEncryption));
  23343. } catch (e) {
  23344. if (e instanceof MissingDataException) {
  23345. streamManager.requestRange(e.begin, e.end).then(function () {
  23346. tryFetch(resolve, reject);
  23347. }, reject);
  23348. return;
  23349. }
  23350. reject(e);
  23351. }
  23352. });
  23353. },
  23354. getCatalogObj: function XRef_getCatalogObj() {
  23355. return this.root;
  23356. }
  23357. };
  23358. return XRef;
  23359. })();
  23360. /**
  23361. * A NameTree/NumberTree is like a Dict but has some advantageous properties,
  23362. * see the specification (7.9.6 and 7.9.7) for additional details.
  23363. * TODO: implement all the Dict functions and make this more efficient.
  23364. */
  23365. var NameOrNumberTree = (function NameOrNumberTreeClosure() {
  23366. function NameOrNumberTree(root, xref) {
  23367. throw new Error('Cannot initialize NameOrNumberTree.');
  23368. }
  23369. NameOrNumberTree.prototype = {
  23370. getAll: function NameOrNumberTree_getAll() {
  23371. var dict = {};
  23372. if (!this.root) {
  23373. return dict;
  23374. }
  23375. var xref = this.xref;
  23376. // Reading Name/Number tree.
  23377. var processed = new RefSet();
  23378. processed.put(this.root);
  23379. var queue = [this.root];
  23380. while (queue.length > 0) {
  23381. var i, n;
  23382. var obj = xref.fetchIfRef(queue.shift());
  23383. if (!isDict(obj)) {
  23384. continue;
  23385. }
  23386. if (obj.has('Kids')) {
  23387. var kids = obj.get('Kids');
  23388. for (i = 0, n = kids.length; i < n; i++) {
  23389. var kid = kids[i];
  23390. assert(!processed.has(kid),
  23391. 'Duplicate entry in "' + this._type + '" tree.');
  23392. queue.push(kid);
  23393. processed.put(kid);
  23394. }
  23395. continue;
  23396. }
  23397. var entries = obj.get(this._type);
  23398. if (isArray(entries)) {
  23399. for (i = 0, n = entries.length; i < n; i += 2) {
  23400. dict[xref.fetchIfRef(entries[i])] = xref.fetchIfRef(entries[i + 1]);
  23401. }
  23402. }
  23403. }
  23404. return dict;
  23405. },
  23406. get: function NameOrNumberTree_get(key) {
  23407. if (!this.root) {
  23408. return null;
  23409. }
  23410. var xref = this.xref;
  23411. var kidsOrEntries = xref.fetchIfRef(this.root);
  23412. var loopCount = 0;
  23413. var MAX_LEVELS = 10;
  23414. var l, r, m;
  23415. // Perform a binary search to quickly find the entry that
  23416. // contains the key we are looking for.
  23417. while (kidsOrEntries.has('Kids')) {
  23418. if (++loopCount > MAX_LEVELS) {
  23419. warn('Search depth limit reached for "' + this._type + '" tree.');
  23420. return null;
  23421. }
  23422. var kids = kidsOrEntries.get('Kids');
  23423. if (!isArray(kids)) {
  23424. return null;
  23425. }
  23426. l = 0;
  23427. r = kids.length - 1;
  23428. while (l <= r) {
  23429. m = (l + r) >> 1;
  23430. var kid = xref.fetchIfRef(kids[m]);
  23431. var limits = kid.get('Limits');
  23432. if (key < xref.fetchIfRef(limits[0])) {
  23433. r = m - 1;
  23434. } else if (key > xref.fetchIfRef(limits[1])) {
  23435. l = m + 1;
  23436. } else {
  23437. kidsOrEntries = xref.fetchIfRef(kids[m]);
  23438. break;
  23439. }
  23440. }
  23441. if (l > r) {
  23442. return null;
  23443. }
  23444. }
  23445. // If we get here, then we have found the right entry. Now go through the
  23446. // entries in the dictionary until we find the key we're looking for.
  23447. var entries = kidsOrEntries.get(this._type);
  23448. if (isArray(entries)) {
  23449. // Perform a binary search to reduce the lookup time.
  23450. l = 0;
  23451. r = entries.length - 2;
  23452. while (l <= r) {
  23453. // Check only even indices (0, 2, 4, ...) because the
  23454. // odd indices contain the actual data.
  23455. m = (l + r) & ~1;
  23456. var currentKey = xref.fetchIfRef(entries[m]);
  23457. if (key < currentKey) {
  23458. r = m - 2;
  23459. } else if (key > currentKey) {
  23460. l = m + 2;
  23461. } else {
  23462. return xref.fetchIfRef(entries[m + 1]);
  23463. }
  23464. }
  23465. }
  23466. return null;
  23467. }
  23468. };
  23469. return NameOrNumberTree;
  23470. })();
  23471. var NameTree = (function NameTreeClosure() {
  23472. function NameTree(root, xref) {
  23473. this.root = root;
  23474. this.xref = xref;
  23475. this._type = 'Names';
  23476. }
  23477. Util.inherit(NameTree, NameOrNumberTree, {});
  23478. return NameTree;
  23479. })();
  23480. var NumberTree = (function NumberTreeClosure() {
  23481. function NumberTree(root, xref) {
  23482. this.root = root;
  23483. this.xref = xref;
  23484. this._type = 'Nums';
  23485. }
  23486. Util.inherit(NumberTree, NameOrNumberTree, {});
  23487. return NumberTree;
  23488. })();
  23489. /**
  23490. * "A PDF file can refer to the contents of another file by using a File
  23491. * Specification (PDF 1.1)", see the spec (7.11) for more details.
  23492. * NOTE: Only embedded files are supported (as part of the attachments support)
  23493. * TODO: support the 'URL' file system (with caching if !/V), portable
  23494. * collections attributes and related files (/RF)
  23495. */
  23496. var FileSpec = (function FileSpecClosure() {
  23497. function FileSpec(root, xref) {
  23498. if (!root || !isDict(root)) {
  23499. return;
  23500. }
  23501. this.xref = xref;
  23502. this.root = root;
  23503. if (root.has('FS')) {
  23504. this.fs = root.get('FS');
  23505. }
  23506. this.description = root.has('Desc') ?
  23507. stringToPDFString(root.get('Desc')) :
  23508. '';
  23509. if (root.has('RF')) {
  23510. warn('Related file specifications are not supported');
  23511. }
  23512. this.contentAvailable = true;
  23513. if (!root.has('EF')) {
  23514. this.contentAvailable = false;
  23515. warn('Non-embedded file specifications are not supported');
  23516. }
  23517. }
  23518. function pickPlatformItem(dict) {
  23519. // Look for the filename in this order:
  23520. // UF, F, Unix, Mac, DOS
  23521. if (dict.has('UF')) {
  23522. return dict.get('UF');
  23523. } else if (dict.has('F')) {
  23524. return dict.get('F');
  23525. } else if (dict.has('Unix')) {
  23526. return dict.get('Unix');
  23527. } else if (dict.has('Mac')) {
  23528. return dict.get('Mac');
  23529. } else if (dict.has('DOS')) {
  23530. return dict.get('DOS');
  23531. } else {
  23532. return null;
  23533. }
  23534. }
  23535. FileSpec.prototype = {
  23536. get filename() {
  23537. if (!this._filename && this.root) {
  23538. var filename = pickPlatformItem(this.root) || 'unnamed';
  23539. this._filename = stringToPDFString(filename).
  23540. replace(/\\\\/g, '\\').
  23541. replace(/\\\//g, '/').
  23542. replace(/\\/g, '/');
  23543. }
  23544. return this._filename;
  23545. },
  23546. get content() {
  23547. if (!this.contentAvailable) {
  23548. return null;
  23549. }
  23550. if (!this.contentRef && this.root) {
  23551. this.contentRef = pickPlatformItem(this.root.get('EF'));
  23552. }
  23553. var content = null;
  23554. if (this.contentRef) {
  23555. var xref = this.xref;
  23556. var fileObj = xref.fetchIfRef(this.contentRef);
  23557. if (fileObj && isStream(fileObj)) {
  23558. content = fileObj.getBytes();
  23559. } else {
  23560. warn('Embedded file specification points to non-existing/invalid ' +
  23561. 'content');
  23562. }
  23563. } else {
  23564. warn('Embedded file specification does not have a content');
  23565. }
  23566. return content;
  23567. },
  23568. get serializable() {
  23569. return {
  23570. filename: this.filename,
  23571. content: this.content
  23572. };
  23573. }
  23574. };
  23575. return FileSpec;
  23576. })();
  23577. /**
  23578. * A helper for loading missing data in object graphs. It traverses the graph
  23579. * depth first and queues up any objects that have missing data. Once it has
  23580. * has traversed as many objects that are available it attempts to bundle the
  23581. * missing data requests and then resume from the nodes that weren't ready.
  23582. *
  23583. * NOTE: It provides protection from circular references by keeping track of
  23584. * of loaded references. However, you must be careful not to load any graphs
  23585. * that have references to the catalog or other pages since that will cause the
  23586. * entire PDF document object graph to be traversed.
  23587. */
  23588. var ObjectLoader = (function() {
  23589. function mayHaveChildren(value) {
  23590. return isRef(value) || isDict(value) || isArray(value) || isStream(value);
  23591. }
  23592. function addChildren(node, nodesToVisit) {
  23593. var value;
  23594. if (isDict(node) || isStream(node)) {
  23595. var map;
  23596. if (isDict(node)) {
  23597. map = node.map;
  23598. } else {
  23599. map = node.dict.map;
  23600. }
  23601. for (var key in map) {
  23602. value = map[key];
  23603. if (mayHaveChildren(value)) {
  23604. nodesToVisit.push(value);
  23605. }
  23606. }
  23607. } else if (isArray(node)) {
  23608. for (var i = 0, ii = node.length; i < ii; i++) {
  23609. value = node[i];
  23610. if (mayHaveChildren(value)) {
  23611. nodesToVisit.push(value);
  23612. }
  23613. }
  23614. }
  23615. }
  23616. function ObjectLoader(obj, keys, xref) {
  23617. this.obj = obj;
  23618. this.keys = keys;
  23619. this.xref = xref;
  23620. this.refSet = null;
  23621. this.capability = null;
  23622. }
  23623. ObjectLoader.prototype = {
  23624. load: function ObjectLoader_load() {
  23625. var keys = this.keys;
  23626. this.capability = createPromiseCapability();
  23627. // Don't walk the graph if all the data is already loaded.
  23628. if (!(this.xref.stream instanceof ChunkedStream) ||
  23629. this.xref.stream.getMissingChunks().length === 0) {
  23630. this.capability.resolve();
  23631. return this.capability.promise;
  23632. }
  23633. this.refSet = new RefSet();
  23634. // Setup the initial nodes to visit.
  23635. var nodesToVisit = [];
  23636. for (var i = 0; i < keys.length; i++) {
  23637. nodesToVisit.push(this.obj[keys[i]]);
  23638. }
  23639. this._walk(nodesToVisit);
  23640. return this.capability.promise;
  23641. },
  23642. _walk: function ObjectLoader_walk(nodesToVisit) {
  23643. var nodesToRevisit = [];
  23644. var pendingRequests = [];
  23645. // DFS walk of the object graph.
  23646. while (nodesToVisit.length) {
  23647. var currentNode = nodesToVisit.pop();
  23648. // Only references or chunked streams can cause missing data exceptions.
  23649. if (isRef(currentNode)) {
  23650. // Skip nodes that have already been visited.
  23651. if (this.refSet.has(currentNode)) {
  23652. continue;
  23653. }
  23654. try {
  23655. var ref = currentNode;
  23656. this.refSet.put(ref);
  23657. currentNode = this.xref.fetch(currentNode);
  23658. } catch (e) {
  23659. if (!(e instanceof MissingDataException)) {
  23660. throw e;
  23661. }
  23662. nodesToRevisit.push(currentNode);
  23663. pendingRequests.push({ begin: e.begin, end: e.end });
  23664. }
  23665. }
  23666. if (currentNode && currentNode.getBaseStreams) {
  23667. var baseStreams = currentNode.getBaseStreams();
  23668. var foundMissingData = false;
  23669. for (var i = 0; i < baseStreams.length; i++) {
  23670. var stream = baseStreams[i];
  23671. if (stream.getMissingChunks && stream.getMissingChunks().length) {
  23672. foundMissingData = true;
  23673. pendingRequests.push({
  23674. begin: stream.start,
  23675. end: stream.end
  23676. });
  23677. }
  23678. }
  23679. if (foundMissingData) {
  23680. nodesToRevisit.push(currentNode);
  23681. }
  23682. }
  23683. addChildren(currentNode, nodesToVisit);
  23684. }
  23685. if (pendingRequests.length) {
  23686. this.xref.stream.manager.requestRanges(pendingRequests).then(
  23687. function pendingRequestCallback() {
  23688. nodesToVisit = nodesToRevisit;
  23689. for (var i = 0; i < nodesToRevisit.length; i++) {
  23690. var node = nodesToRevisit[i];
  23691. // Remove any reference nodes from the currrent refset so they
  23692. // aren't skipped when we revist them.
  23693. if (isRef(node)) {
  23694. this.refSet.remove(node);
  23695. }
  23696. }
  23697. this._walk(nodesToVisit);
  23698. }.bind(this), this.capability.reject);
  23699. return;
  23700. }
  23701. // Everything is loaded.
  23702. this.refSet = null;
  23703. this.capability.resolve();
  23704. }
  23705. };
  23706. return ObjectLoader;
  23707. })();
  23708. exports.Catalog = Catalog;
  23709. exports.ObjectLoader = ObjectLoader;
  23710. exports.XRef = XRef;
  23711. }));
  23712. (function (root, factory) {
  23713. {
  23714. factory((root.pdfjsCorePsParser = {}), root.pdfjsSharedUtil,
  23715. root.pdfjsCoreParser);
  23716. }
  23717. }(this, function (exports, sharedUtil, coreParser) {
  23718. var error = sharedUtil.error;
  23719. var EOF = coreParser.EOF;
  23720. var Lexer = coreParser.Lexer;
  23721. var PostScriptParser = (function PostScriptParserClosure() {
  23722. function PostScriptParser(lexer) {
  23723. this.lexer = lexer;
  23724. this.operators = [];
  23725. this.token = null;
  23726. this.prev = null;
  23727. }
  23728. PostScriptParser.prototype = {
  23729. nextToken: function PostScriptParser_nextToken() {
  23730. this.prev = this.token;
  23731. this.token = this.lexer.getToken();
  23732. },
  23733. accept: function PostScriptParser_accept(type) {
  23734. if (this.token.type === type) {
  23735. this.nextToken();
  23736. return true;
  23737. }
  23738. return false;
  23739. },
  23740. expect: function PostScriptParser_expect(type) {
  23741. if (this.accept(type)) {
  23742. return true;
  23743. }
  23744. error('Unexpected symbol: found ' + this.token.type + ' expected ' +
  23745. type + '.');
  23746. },
  23747. parse: function PostScriptParser_parse() {
  23748. this.nextToken();
  23749. this.expect(PostScriptTokenTypes.LBRACE);
  23750. this.parseBlock();
  23751. this.expect(PostScriptTokenTypes.RBRACE);
  23752. return this.operators;
  23753. },
  23754. parseBlock: function PostScriptParser_parseBlock() {
  23755. while (true) {
  23756. if (this.accept(PostScriptTokenTypes.NUMBER)) {
  23757. this.operators.push(this.prev.value);
  23758. } else if (this.accept(PostScriptTokenTypes.OPERATOR)) {
  23759. this.operators.push(this.prev.value);
  23760. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  23761. this.parseCondition();
  23762. } else {
  23763. return;
  23764. }
  23765. }
  23766. },
  23767. parseCondition: function PostScriptParser_parseCondition() {
  23768. // Add two place holders that will be updated later
  23769. var conditionLocation = this.operators.length;
  23770. this.operators.push(null, null);
  23771. this.parseBlock();
  23772. this.expect(PostScriptTokenTypes.RBRACE);
  23773. if (this.accept(PostScriptTokenTypes.IF)) {
  23774. // The true block is right after the 'if' so it just falls through on
  23775. // true else it jumps and skips the true block.
  23776. this.operators[conditionLocation] = this.operators.length;
  23777. this.operators[conditionLocation + 1] = 'jz';
  23778. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  23779. var jumpLocation = this.operators.length;
  23780. this.operators.push(null, null);
  23781. var endOfTrue = this.operators.length;
  23782. this.parseBlock();
  23783. this.expect(PostScriptTokenTypes.RBRACE);
  23784. this.expect(PostScriptTokenTypes.IFELSE);
  23785. // The jump is added at the end of the true block to skip the false
  23786. // block.
  23787. this.operators[jumpLocation] = this.operators.length;
  23788. this.operators[jumpLocation + 1] = 'j';
  23789. this.operators[conditionLocation] = endOfTrue;
  23790. this.operators[conditionLocation + 1] = 'jz';
  23791. } else {
  23792. error('PS Function: error parsing conditional.');
  23793. }
  23794. }
  23795. };
  23796. return PostScriptParser;
  23797. })();
  23798. var PostScriptTokenTypes = {
  23799. LBRACE: 0,
  23800. RBRACE: 1,
  23801. NUMBER: 2,
  23802. OPERATOR: 3,
  23803. IF: 4,
  23804. IFELSE: 5
  23805. };
  23806. var PostScriptToken = (function PostScriptTokenClosure() {
  23807. function PostScriptToken(type, value) {
  23808. this.type = type;
  23809. this.value = value;
  23810. }
  23811. var opCache = {};
  23812. PostScriptToken.getOperator = function PostScriptToken_getOperator(op) {
  23813. var opValue = opCache[op];
  23814. if (opValue) {
  23815. return opValue;
  23816. }
  23817. return opCache[op] = new PostScriptToken(PostScriptTokenTypes.OPERATOR, op);
  23818. };
  23819. PostScriptToken.LBRACE = new PostScriptToken(PostScriptTokenTypes.LBRACE,
  23820. '{');
  23821. PostScriptToken.RBRACE = new PostScriptToken(PostScriptTokenTypes.RBRACE,
  23822. '}');
  23823. PostScriptToken.IF = new PostScriptToken(PostScriptTokenTypes.IF, 'IF');
  23824. PostScriptToken.IFELSE = new PostScriptToken(PostScriptTokenTypes.IFELSE,
  23825. 'IFELSE');
  23826. return PostScriptToken;
  23827. })();
  23828. var PostScriptLexer = (function PostScriptLexerClosure() {
  23829. function PostScriptLexer(stream) {
  23830. this.stream = stream;
  23831. this.nextChar();
  23832. this.strBuf = [];
  23833. }
  23834. PostScriptLexer.prototype = {
  23835. nextChar: function PostScriptLexer_nextChar() {
  23836. return (this.currentChar = this.stream.getByte());
  23837. },
  23838. getToken: function PostScriptLexer_getToken() {
  23839. var comment = false;
  23840. var ch = this.currentChar;
  23841. // skip comments
  23842. while (true) {
  23843. if (ch < 0) {
  23844. return EOF;
  23845. }
  23846. if (comment) {
  23847. if (ch === 0x0A || ch === 0x0D) {
  23848. comment = false;
  23849. }
  23850. } else if (ch === 0x25) { // '%'
  23851. comment = true;
  23852. } else if (!Lexer.isSpace(ch)) {
  23853. break;
  23854. }
  23855. ch = this.nextChar();
  23856. }
  23857. switch (ch | 0) {
  23858. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  23859. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  23860. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  23861. return new PostScriptToken(PostScriptTokenTypes.NUMBER,
  23862. this.getNumber());
  23863. case 0x7B: // '{'
  23864. this.nextChar();
  23865. return PostScriptToken.LBRACE;
  23866. case 0x7D: // '}'
  23867. this.nextChar();
  23868. return PostScriptToken.RBRACE;
  23869. }
  23870. // operator
  23871. var strBuf = this.strBuf;
  23872. strBuf.length = 0;
  23873. strBuf[0] = String.fromCharCode(ch);
  23874. while ((ch = this.nextChar()) >= 0 && // and 'A'-'Z', 'a'-'z'
  23875. ((ch >= 0x41 && ch <= 0x5A) || (ch >= 0x61 && ch <= 0x7A))) {
  23876. strBuf.push(String.fromCharCode(ch));
  23877. }
  23878. var str = strBuf.join('');
  23879. switch (str.toLowerCase()) {
  23880. case 'if':
  23881. return PostScriptToken.IF;
  23882. case 'ifelse':
  23883. return PostScriptToken.IFELSE;
  23884. default:
  23885. return PostScriptToken.getOperator(str);
  23886. }
  23887. },
  23888. getNumber: function PostScriptLexer_getNumber() {
  23889. var ch = this.currentChar;
  23890. var strBuf = this.strBuf;
  23891. strBuf.length = 0;
  23892. strBuf[0] = String.fromCharCode(ch);
  23893. while ((ch = this.nextChar()) >= 0) {
  23894. if ((ch >= 0x30 && ch <= 0x39) || // '0'-'9'
  23895. ch === 0x2D || ch === 0x2E) { // '-', '.'
  23896. strBuf.push(String.fromCharCode(ch));
  23897. } else {
  23898. break;
  23899. }
  23900. }
  23901. var value = parseFloat(strBuf.join(''));
  23902. if (isNaN(value)) {
  23903. error('Invalid floating point number: ' + value);
  23904. }
  23905. return value;
  23906. }
  23907. };
  23908. return PostScriptLexer;
  23909. })();
  23910. exports.PostScriptLexer = PostScriptLexer;
  23911. exports.PostScriptParser = PostScriptParser;
  23912. }));
  23913. (function (root, factory) {
  23914. {
  23915. factory((root.pdfjsCoreFonts = {}), root.pdfjsSharedUtil,
  23916. root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreParser,
  23917. root.pdfjsCoreCMap, root.pdfjsCoreGlyphList, root.pdfjsCoreCharsets,
  23918. root.pdfjsCoreFontRenderer);
  23919. }
  23920. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreParser,
  23921. coreCMap, coreGlyphList, coreCharsets, coreFontRenderer) {
  23922. var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
  23923. var FontType = sharedUtil.FontType;
  23924. var Util = sharedUtil.Util;
  23925. var assert = sharedUtil.assert;
  23926. var bytesToString = sharedUtil.bytesToString;
  23927. var error = sharedUtil.error;
  23928. var info = sharedUtil.info;
  23929. var isArray = sharedUtil.isArray;
  23930. var isInt = sharedUtil.isInt;
  23931. var isNum = sharedUtil.isNum;
  23932. var readUint32 = sharedUtil.readUint32;
  23933. var shadow = sharedUtil.shadow;
  23934. var stringToBytes = sharedUtil.stringToBytes;
  23935. var string32 = sharedUtil.string32;
  23936. var warn = sharedUtil.warn;
  23937. var Name = corePrimitives.Name;
  23938. var Stream = coreStream.Stream;
  23939. var Lexer = coreParser.Lexer;
  23940. var CMapFactory = coreCMap.CMapFactory;
  23941. var IdentityCMap = coreCMap.IdentityCMap;
  23942. var GlyphsUnicode = coreGlyphList.GlyphsUnicode;
  23943. var DingbatsGlyphsUnicode = coreGlyphList.DingbatsGlyphsUnicode;
  23944. var ISOAdobeCharset = coreCharsets.ISOAdobeCharset;
  23945. var ExpertCharset = coreCharsets.ExpertCharset;
  23946. var ExpertSubsetCharset = coreCharsets.ExpertSubsetCharset;
  23947. var FontRendererFactory = coreFontRenderer.FontRendererFactory;
  23948. // Unicode Private Use Area
  23949. var PRIVATE_USE_OFFSET_START = 0xE000;
  23950. var PRIVATE_USE_OFFSET_END = 0xF8FF;
  23951. var SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = false;
  23952. // PDF Glyph Space Units are one Thousandth of a TextSpace Unit
  23953. // except for Type 3 fonts
  23954. var PDF_GLYPH_SPACE_UNITS = 1000;
  23955. // Hinting is currently disabled due to unknown problems on windows
  23956. // in tracemonkey and various other pdfs with type1 fonts.
  23957. var HINTING_ENABLED = false;
  23958. // Accented charactars are not displayed properly on windows, using this flag
  23959. // to control analysis of seac charstrings.
  23960. var SEAC_ANALYSIS_ENABLED = false;
  23961. // Maximum subroutine call depth of type 2 chartrings. Matches OTS.
  23962. var MAX_SUBR_NESTING = 10;
  23963. var FontFlags = {
  23964. FixedPitch: 1,
  23965. Serif: 2,
  23966. Symbolic: 4,
  23967. Script: 8,
  23968. Nonsymbolic: 32,
  23969. Italic: 64,
  23970. AllCap: 65536,
  23971. SmallCap: 131072,
  23972. ForceBold: 262144
  23973. };
  23974. var Encodings = {
  23975. ExpertEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  23976. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  23977. 'space', 'exclamsmall', 'Hungarumlautsmall', '', 'dollaroldstyle',
  23978. 'dollarsuperior', 'ampersandsmall', 'Acutesmall', 'parenleftsuperior',
  23979. 'parenrightsuperior', 'twodotenleader', 'onedotenleader', 'comma',
  23980. 'hyphen', 'period', 'fraction', 'zerooldstyle', 'oneoldstyle',
  23981. 'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle',
  23982. 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'colon',
  23983. 'semicolon', 'commasuperior', 'threequartersemdash', 'periodsuperior',
  23984. 'questionsmall', '', 'asuperior', 'bsuperior', 'centsuperior', 'dsuperior',
  23985. 'esuperior', '', '', 'isuperior', '', '', 'lsuperior', 'msuperior',
  23986. 'nsuperior', 'osuperior', '', '', 'rsuperior', 'ssuperior', 'tsuperior',
  23987. '', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior', '',
  23988. 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall',
  23989. 'Asmall', 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall',
  23990. 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall',
  23991. 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall',
  23992. 'Vsmall', 'Wsmall', 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary',
  23993. 'onefitted', 'rupiah', 'Tildesmall', '', '', '', '', '', '', '', '', '',
  23994. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  23995. '', '', '', '', '', '', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall',
  23996. '', '', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall',
  23997. 'Caronsmall', '', 'Dotaccentsmall', '', '', 'Macronsmall', '', '',
  23998. 'figuredash', 'hypheninferior', '', '', 'Ogoneksmall', 'Ringsmall',
  23999. 'Cedillasmall', '', '', '', 'onequarter', 'onehalf', 'threequarters',
  24000. 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths',
  24001. 'seveneighths', 'onethird', 'twothirds', '', '', 'zerosuperior',
  24002. 'onesuperior', 'twosuperior', 'threesuperior', 'foursuperior',
  24003. 'fivesuperior', 'sixsuperior', 'sevensuperior', 'eightsuperior',
  24004. 'ninesuperior', 'zeroinferior', 'oneinferior', 'twoinferior',
  24005. 'threeinferior', 'fourinferior', 'fiveinferior', 'sixinferior',
  24006. 'seveninferior', 'eightinferior', 'nineinferior', 'centinferior',
  24007. 'dollarinferior', 'periodinferior', 'commainferior', 'Agravesmall',
  24008. 'Aacutesmall', 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall',
  24009. 'Aringsmall', 'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall',
  24010. 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall',
  24011. 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall',
  24012. 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall',
  24013. 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall',
  24014. 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall',
  24015. 'Ydieresissmall'],
  24016. MacExpertEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  24017. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  24018. 'space', 'exclamsmall', 'Hungarumlautsmall', 'centoldstyle',
  24019. 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall', 'Acutesmall',
  24020. 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  24021. 'onedotenleader', 'comma', 'hyphen', 'period', 'fraction', 'zerooldstyle',
  24022. 'oneoldstyle', 'twooldstyle', 'threeoldstyle', 'fouroldstyle',
  24023. 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle',
  24024. 'nineoldstyle', 'colon', 'semicolon', '', 'threequartersemdash', '',
  24025. 'questionsmall', '', '', '', '', 'Ethsmall', '', '', 'onequarter',
  24026. 'onehalf', 'threequarters', 'oneeighth', 'threeeighths', 'fiveeighths',
  24027. 'seveneighths', 'onethird', 'twothirds', '', '', '', '', '', '', 'ff',
  24028. 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior', '', 'parenrightinferior',
  24029. 'Circumflexsmall', 'hypheninferior', 'Gravesmall', 'Asmall', 'Bsmall',
  24030. 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall',
  24031. 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall',
  24032. 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
  24033. 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah',
  24034. 'Tildesmall', '', '', 'asuperior', 'centsuperior', '', '', '', '',
  24035. 'Aacutesmall', 'Agravesmall', 'Acircumflexsmall', 'Adieresissmall',
  24036. 'Atildesmall', 'Aringsmall', 'Ccedillasmall', 'Eacutesmall', 'Egravesmall',
  24037. 'Ecircumflexsmall', 'Edieresissmall', 'Iacutesmall', 'Igravesmall',
  24038. 'Icircumflexsmall', 'Idieresissmall', 'Ntildesmall', 'Oacutesmall',
  24039. 'Ogravesmall', 'Ocircumflexsmall', 'Odieresissmall', 'Otildesmall',
  24040. 'Uacutesmall', 'Ugravesmall', 'Ucircumflexsmall', 'Udieresissmall', '',
  24041. 'eightsuperior', 'fourinferior', 'threeinferior', 'sixinferior',
  24042. 'eightinferior', 'seveninferior', 'Scaronsmall', '', 'centinferior',
  24043. 'twoinferior', '', 'Dieresissmall', '', 'Caronsmall', 'osuperior',
  24044. 'fiveinferior', '', 'commainferior', 'periodinferior', 'Yacutesmall', '',
  24045. 'dollarinferior', '', 'Thornsmall', '', 'nineinferior', 'zeroinferior',
  24046. 'Zcaronsmall', 'AEsmall', 'Oslashsmall', 'questiondownsmall',
  24047. 'oneinferior', 'Lslashsmall', '', '', '', '', '', '', 'Cedillasmall', '',
  24048. '', '', '', '', 'OEsmall', 'figuredash', 'hyphensuperior', '', '', '', '',
  24049. 'exclamdownsmall', '', 'Ydieresissmall', '', 'onesuperior', 'twosuperior',
  24050. 'threesuperior', 'foursuperior', 'fivesuperior', 'sixsuperior',
  24051. 'sevensuperior', 'ninesuperior', 'zerosuperior', '', 'esuperior',
  24052. 'rsuperior', 'tsuperior', '', '', 'isuperior', 'ssuperior', 'dsuperior',
  24053. '', '', '', '', '', 'lsuperior', 'Ogoneksmall', 'Brevesmall',
  24054. 'Macronsmall', 'bsuperior', 'nsuperior', 'msuperior', 'commasuperior',
  24055. 'periodsuperior', 'Dotaccentsmall', 'Ringsmall'],
  24056. MacRomanEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  24057. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  24058. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  24059. 'ampersand', 'quotesingle', 'parenleft', 'parenright', 'asterisk', 'plus',
  24060. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  24061. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  24062. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  24063. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  24064. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  24065. 'asciicircum', 'underscore', 'grave', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
  24066. 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
  24067. 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', '',
  24068. 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde', 'Odieresis',
  24069. 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis', 'atilde',
  24070. 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  24071. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute',
  24072. 'ograve', 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave',
  24073. 'ucircumflex', 'udieresis', 'dagger', 'degree', 'cent', 'sterling',
  24074. 'section', 'bullet', 'paragraph', 'germandbls', 'registered', 'copyright',
  24075. 'trademark', 'acute', 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity',
  24076. 'plusminus', 'lessequal', 'greaterequal', 'yen', 'mu', 'partialdiff',
  24077. 'summation', 'product', 'pi', 'integral', 'ordfeminine', 'ordmasculine',
  24078. 'Omega', 'ae', 'oslash', 'questiondown', 'exclamdown', 'logicalnot',
  24079. 'radical', 'florin', 'approxequal', 'Delta', 'guillemotleft',
  24080. 'guillemotright', 'ellipsis', 'space', 'Agrave', 'Atilde', 'Otilde', 'OE',
  24081. 'oe', 'endash', 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft',
  24082. 'quoteright', 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction',
  24083. 'currency', 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl',
  24084. 'periodcentered', 'quotesinglbase', 'quotedblbase', 'perthousand',
  24085. 'Acircumflex', 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute',
  24086. 'Icircumflex', 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple',
  24087. 'Ograve', 'Uacute', 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex',
  24088. 'tilde', 'macron', 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut',
  24089. 'ogonek', 'caron'],
  24090. StandardEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  24091. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  24092. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  24093. 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus',
  24094. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  24095. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  24096. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  24097. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  24098. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  24099. 'asciicircum', 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f',
  24100. 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u',
  24101. 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde',
  24102. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  24103. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', 'exclamdown',
  24104. 'cent', 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  24105. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  24106. 'guilsinglright', 'fi', 'fl', '', 'endash', 'dagger', 'daggerdbl',
  24107. 'periodcentered', '', 'paragraph', 'bullet', 'quotesinglbase',
  24108. 'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis',
  24109. 'perthousand', '', 'questiondown', '', 'grave', 'acute', 'circumflex',
  24110. 'tilde', 'macron', 'breve', 'dotaccent', 'dieresis', '', 'ring', 'cedilla',
  24111. '', 'hungarumlaut', 'ogonek', 'caron', 'emdash', '', '', '', '', '', '',
  24112. '', '', '', '', '', '', '', '', '', '', 'AE', '', 'ordfeminine', '', '',
  24113. '', '', 'Lslash', 'Oslash', 'OE', 'ordmasculine', '', '', '', '', '', 'ae',
  24114. '', '', '', 'dotlessi', '', '', 'lslash', 'oslash', 'oe', 'germandbls'],
  24115. WinAnsiEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  24116. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  24117. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  24118. 'ampersand', 'quotesingle', 'parenleft', 'parenright', 'asterisk', 'plus',
  24119. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  24120. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  24121. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  24122. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  24123. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  24124. 'asciicircum', 'underscore', 'grave', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
  24125. 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
  24126. 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde',
  24127. 'bullet', 'Euro', 'bullet', 'quotesinglbase', 'florin', 'quotedblbase',
  24128. 'ellipsis', 'dagger', 'daggerdbl', 'circumflex', 'perthousand', 'Scaron',
  24129. 'guilsinglleft', 'OE', 'bullet', 'Zcaron', 'bullet', 'bullet', 'quoteleft',
  24130. 'quoteright', 'quotedblleft', 'quotedblright', 'bullet', 'endash',
  24131. 'emdash', 'tilde', 'trademark', 'scaron', 'guilsinglright', 'oe', 'bullet',
  24132. 'zcaron', 'Ydieresis', 'space', 'exclamdown', 'cent', 'sterling',
  24133. 'currency', 'yen', 'brokenbar', 'section', 'dieresis', 'copyright',
  24134. 'ordfeminine', 'guillemotleft', 'logicalnot', 'hyphen', 'registered',
  24135. 'macron', 'degree', 'plusminus', 'twosuperior', 'threesuperior', 'acute',
  24136. 'mu', 'paragraph', 'periodcentered', 'cedilla', 'onesuperior',
  24137. 'ordmasculine', 'guillemotright', 'onequarter', 'onehalf', 'threequarters',
  24138. 'questiondown', 'Agrave', 'Aacute', 'Acircumflex', 'Atilde', 'Adieresis',
  24139. 'Aring', 'AE', 'Ccedilla', 'Egrave', 'Eacute', 'Ecircumflex', 'Edieresis',
  24140. 'Igrave', 'Iacute', 'Icircumflex', 'Idieresis', 'Eth', 'Ntilde', 'Ograve',
  24141. 'Oacute', 'Ocircumflex', 'Otilde', 'Odieresis', 'multiply', 'Oslash',
  24142. 'Ugrave', 'Uacute', 'Ucircumflex', 'Udieresis', 'Yacute', 'Thorn',
  24143. 'germandbls', 'agrave', 'aacute', 'acircumflex', 'atilde', 'adieresis',
  24144. 'aring', 'ae', 'ccedilla', 'egrave', 'eacute', 'ecircumflex', 'edieresis',
  24145. 'igrave', 'iacute', 'icircumflex', 'idieresis', 'eth', 'ntilde', 'ograve',
  24146. 'oacute', 'ocircumflex', 'otilde', 'odieresis', 'divide', 'oslash',
  24147. 'ugrave', 'uacute', 'ucircumflex', 'udieresis', 'yacute', 'thorn',
  24148. 'ydieresis'],
  24149. SymbolSetEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  24150. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  24151. 'space', 'exclam', 'universal', 'numbersign', 'existential', 'percent',
  24152. 'ampersand', 'suchthat', 'parenleft', 'parenright', 'asteriskmath', 'plus',
  24153. 'comma', 'minus', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
  24154. 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',
  24155. 'equal', 'greater', 'question', 'congruent', 'Alpha', 'Beta', 'Chi',
  24156. 'Delta', 'Epsilon', 'Phi', 'Gamma', 'Eta', 'Iota', 'theta1', 'Kappa',
  24157. 'Lambda', 'Mu', 'Nu', 'Omicron', 'Pi', 'Theta', 'Rho', 'Sigma', 'Tau',
  24158. 'Upsilon', 'sigma1', 'Omega', 'Xi', 'Psi', 'Zeta', 'bracketleft',
  24159. 'therefore', 'bracketright', 'perpendicular', 'underscore', 'radicalex',
  24160. 'alpha', 'beta', 'chi', 'delta', 'epsilon', 'phi', 'gamma', 'eta', 'iota',
  24161. 'phi1', 'kappa', 'lambda', 'mu', 'nu', 'omicron', 'pi', 'theta', 'rho',
  24162. 'sigma', 'tau', 'upsilon', 'omega1', 'omega', 'xi', 'psi', 'zeta',
  24163. 'braceleft', 'bar', 'braceright', 'similar', '', '', '', '', '', '', '',
  24164. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  24165. '', '', '', '', '', '', '', 'Euro', 'Upsilon1', 'minute', 'lessequal',
  24166. 'fraction', 'infinity', 'florin', 'club', 'diamond', 'heart', 'spade',
  24167. 'arrowboth', 'arrowleft', 'arrowup', 'arrowright', 'arrowdown', 'degree',
  24168. 'plusminus', 'second', 'greaterequal', 'multiply', 'proportional',
  24169. 'partialdiff', 'bullet', 'divide', 'notequal', 'equivalence',
  24170. 'approxequal', 'ellipsis', 'arrowvertex', 'arrowhorizex', 'carriagereturn',
  24171. 'aleph', 'Ifraktur', 'Rfraktur', 'weierstrass', 'circlemultiply',
  24172. 'circleplus', 'emptyset', 'intersection', 'union', 'propersuperset',
  24173. 'reflexsuperset', 'notsubset', 'propersubset', 'reflexsubset', 'element',
  24174. 'notelement', 'angle', 'gradient', 'registerserif', 'copyrightserif',
  24175. 'trademarkserif', 'product', 'radical', 'dotmath', 'logicalnot',
  24176. 'logicaland', 'logicalor', 'arrowdblboth', 'arrowdblleft', 'arrowdblup',
  24177. 'arrowdblright', 'arrowdbldown', 'lozenge', 'angleleft', 'registersans',
  24178. 'copyrightsans', 'trademarksans', 'summation', 'parenlefttp',
  24179. 'parenleftex', 'parenleftbt', 'bracketlefttp', 'bracketleftex',
  24180. 'bracketleftbt', 'bracelefttp', 'braceleftmid', 'braceleftbt', 'braceex',
  24181. '', 'angleright', 'integral', 'integraltp', 'integralex', 'integralbt',
  24182. 'parenrighttp', 'parenrightex', 'parenrightbt', 'bracketrighttp',
  24183. 'bracketrightex', 'bracketrightbt', 'bracerighttp', 'bracerightmid',
  24184. 'bracerightbt'],
  24185. ZapfDingbatsEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  24186. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  24187. 'space', 'a1', 'a2', 'a202', 'a3', 'a4', 'a5', 'a119', 'a118', 'a117',
  24188. 'a11', 'a12', 'a13', 'a14', 'a15', 'a16', 'a105', 'a17', 'a18', 'a19',
  24189. 'a20', 'a21', 'a22', 'a23', 'a24', 'a25', 'a26', 'a27', 'a28', 'a6', 'a7',
  24190. 'a8', 'a9', 'a10', 'a29', 'a30', 'a31', 'a32', 'a33', 'a34', 'a35', 'a36',
  24191. 'a37', 'a38', 'a39', 'a40', 'a41', 'a42', 'a43', 'a44', 'a45', 'a46',
  24192. 'a47', 'a48', 'a49', 'a50', 'a51', 'a52', 'a53', 'a54', 'a55', 'a56',
  24193. 'a57', 'a58', 'a59', 'a60', 'a61', 'a62', 'a63', 'a64', 'a65', 'a66',
  24194. 'a67', 'a68', 'a69', 'a70', 'a71', 'a72', 'a73', 'a74', 'a203', 'a75',
  24195. 'a204', 'a76', 'a77', 'a78', 'a79', 'a81', 'a82', 'a83', 'a84', 'a97',
  24196. 'a98', 'a99', 'a100', '', 'a89', 'a90', 'a93', 'a94', 'a91', 'a92', 'a205',
  24197. 'a85', 'a206', 'a86', 'a87', 'a88', 'a95', 'a96', '', '', '', '', '', '',
  24198. '', '', '', '', '', '', '', '', '', '', '', '', '', 'a101', 'a102', 'a103',
  24199. 'a104', 'a106', 'a107', 'a108', 'a112', 'a111', 'a110', 'a109', 'a120',
  24200. 'a121', 'a122', 'a123', 'a124', 'a125', 'a126', 'a127', 'a128', 'a129',
  24201. 'a130', 'a131', 'a132', 'a133', 'a134', 'a135', 'a136', 'a137', 'a138',
  24202. 'a139', 'a140', 'a141', 'a142', 'a143', 'a144', 'a145', 'a146', 'a147',
  24203. 'a148', 'a149', 'a150', 'a151', 'a152', 'a153', 'a154', 'a155', 'a156',
  24204. 'a157', 'a158', 'a159', 'a160', 'a161', 'a163', 'a164', 'a196', 'a165',
  24205. 'a192', 'a166', 'a167', 'a168', 'a169', 'a170', 'a171', 'a172', 'a173',
  24206. 'a162', 'a174', 'a175', 'a176', 'a177', 'a178', 'a179', 'a193', 'a180',
  24207. 'a199', 'a181', 'a200', 'a182', '', 'a201', 'a183', 'a184', 'a197', 'a185',
  24208. 'a194', 'a198', 'a186', 'a195', 'a187', 'a188', 'a189', 'a190', 'a191']
  24209. };
  24210. /**
  24211. * Hold a map of decoded fonts and of the standard fourteen Type1
  24212. * fonts and their acronyms.
  24213. */
  24214. var stdFontMap = {
  24215. 'ArialNarrow': 'Helvetica',
  24216. 'ArialNarrow-Bold': 'Helvetica-Bold',
  24217. 'ArialNarrow-BoldItalic': 'Helvetica-BoldOblique',
  24218. 'ArialNarrow-Italic': 'Helvetica-Oblique',
  24219. 'ArialBlack': 'Helvetica',
  24220. 'ArialBlack-Bold': 'Helvetica-Bold',
  24221. 'ArialBlack-BoldItalic': 'Helvetica-BoldOblique',
  24222. 'ArialBlack-Italic': 'Helvetica-Oblique',
  24223. 'Arial': 'Helvetica',
  24224. 'Arial-Bold': 'Helvetica-Bold',
  24225. 'Arial-BoldItalic': 'Helvetica-BoldOblique',
  24226. 'Arial-Italic': 'Helvetica-Oblique',
  24227. 'Arial-BoldItalicMT': 'Helvetica-BoldOblique',
  24228. 'Arial-BoldMT': 'Helvetica-Bold',
  24229. 'Arial-ItalicMT': 'Helvetica-Oblique',
  24230. 'ArialMT': 'Helvetica',
  24231. 'Courier-Bold': 'Courier-Bold',
  24232. 'Courier-BoldItalic': 'Courier-BoldOblique',
  24233. 'Courier-Italic': 'Courier-Oblique',
  24234. 'CourierNew': 'Courier',
  24235. 'CourierNew-Bold': 'Courier-Bold',
  24236. 'CourierNew-BoldItalic': 'Courier-BoldOblique',
  24237. 'CourierNew-Italic': 'Courier-Oblique',
  24238. 'CourierNewPS-BoldItalicMT': 'Courier-BoldOblique',
  24239. 'CourierNewPS-BoldMT': 'Courier-Bold',
  24240. 'CourierNewPS-ItalicMT': 'Courier-Oblique',
  24241. 'CourierNewPSMT': 'Courier',
  24242. 'Helvetica': 'Helvetica',
  24243. 'Helvetica-Bold': 'Helvetica-Bold',
  24244. 'Helvetica-BoldItalic': 'Helvetica-BoldOblique',
  24245. 'Helvetica-BoldOblique': 'Helvetica-BoldOblique',
  24246. 'Helvetica-Italic': 'Helvetica-Oblique',
  24247. 'Helvetica-Oblique':'Helvetica-Oblique',
  24248. 'Symbol-Bold': 'Symbol',
  24249. 'Symbol-BoldItalic': 'Symbol',
  24250. 'Symbol-Italic': 'Symbol',
  24251. 'TimesNewRoman': 'Times-Roman',
  24252. 'TimesNewRoman-Bold': 'Times-Bold',
  24253. 'TimesNewRoman-BoldItalic': 'Times-BoldItalic',
  24254. 'TimesNewRoman-Italic': 'Times-Italic',
  24255. 'TimesNewRomanPS': 'Times-Roman',
  24256. 'TimesNewRomanPS-Bold': 'Times-Bold',
  24257. 'TimesNewRomanPS-BoldItalic': 'Times-BoldItalic',
  24258. 'TimesNewRomanPS-BoldItalicMT': 'Times-BoldItalic',
  24259. 'TimesNewRomanPS-BoldMT': 'Times-Bold',
  24260. 'TimesNewRomanPS-Italic': 'Times-Italic',
  24261. 'TimesNewRomanPS-ItalicMT': 'Times-Italic',
  24262. 'TimesNewRomanPSMT': 'Times-Roman',
  24263. 'TimesNewRomanPSMT-Bold': 'Times-Bold',
  24264. 'TimesNewRomanPSMT-BoldItalic': 'Times-BoldItalic',
  24265. 'TimesNewRomanPSMT-Italic': 'Times-Italic'
  24266. };
  24267. /**
  24268. * Holds the map of the non-standard fonts that might be included as a standard
  24269. * fonts without glyph data.
  24270. */
  24271. var nonStdFontMap = {
  24272. 'CenturyGothic': 'Helvetica',
  24273. 'CenturyGothic-Bold': 'Helvetica-Bold',
  24274. 'CenturyGothic-BoldItalic': 'Helvetica-BoldOblique',
  24275. 'CenturyGothic-Italic': 'Helvetica-Oblique',
  24276. 'ComicSansMS': 'Comic Sans MS',
  24277. 'ComicSansMS-Bold': 'Comic Sans MS-Bold',
  24278. 'ComicSansMS-BoldItalic': 'Comic Sans MS-BoldItalic',
  24279. 'ComicSansMS-Italic': 'Comic Sans MS-Italic',
  24280. 'LucidaConsole': 'Courier',
  24281. 'LucidaConsole-Bold': 'Courier-Bold',
  24282. 'LucidaConsole-BoldItalic': 'Courier-BoldOblique',
  24283. 'LucidaConsole-Italic': 'Courier-Oblique',
  24284. 'MS-Gothic': 'MS Gothic',
  24285. 'MS-Gothic-Bold': 'MS Gothic-Bold',
  24286. 'MS-Gothic-BoldItalic': 'MS Gothic-BoldItalic',
  24287. 'MS-Gothic-Italic': 'MS Gothic-Italic',
  24288. 'MS-Mincho': 'MS Mincho',
  24289. 'MS-Mincho-Bold': 'MS Mincho-Bold',
  24290. 'MS-Mincho-BoldItalic': 'MS Mincho-BoldItalic',
  24291. 'MS-Mincho-Italic': 'MS Mincho-Italic',
  24292. 'MS-PGothic': 'MS PGothic',
  24293. 'MS-PGothic-Bold': 'MS PGothic-Bold',
  24294. 'MS-PGothic-BoldItalic': 'MS PGothic-BoldItalic',
  24295. 'MS-PGothic-Italic': 'MS PGothic-Italic',
  24296. 'MS-PMincho': 'MS PMincho',
  24297. 'MS-PMincho-Bold': 'MS PMincho-Bold',
  24298. 'MS-PMincho-BoldItalic': 'MS PMincho-BoldItalic',
  24299. 'MS-PMincho-Italic': 'MS PMincho-Italic',
  24300. 'Wingdings': 'ZapfDingbats'
  24301. };
  24302. var serifFonts = {
  24303. 'Adobe Jenson': true, 'Adobe Text': true, 'Albertus': true,
  24304. 'Aldus': true, 'Alexandria': true, 'Algerian': true,
  24305. 'American Typewriter': true, 'Antiqua': true, 'Apex': true,
  24306. 'Arno': true, 'Aster': true, 'Aurora': true,
  24307. 'Baskerville': true, 'Bell': true, 'Bembo': true,
  24308. 'Bembo Schoolbook': true, 'Benguiat': true, 'Berkeley Old Style': true,
  24309. 'Bernhard Modern': true, 'Berthold City': true, 'Bodoni': true,
  24310. 'Bauer Bodoni': true, 'Book Antiqua': true, 'Bookman': true,
  24311. 'Bordeaux Roman': true, 'Californian FB': true, 'Calisto': true,
  24312. 'Calvert': true, 'Capitals': true, 'Cambria': true,
  24313. 'Cartier': true, 'Caslon': true, 'Catull': true,
  24314. 'Centaur': true, 'Century Old Style': true, 'Century Schoolbook': true,
  24315. 'Chaparral': true, 'Charis SIL': true, 'Cheltenham': true,
  24316. 'Cholla Slab': true, 'Clarendon': true, 'Clearface': true,
  24317. 'Cochin': true, 'Colonna': true, 'Computer Modern': true,
  24318. 'Concrete Roman': true, 'Constantia': true, 'Cooper Black': true,
  24319. 'Corona': true, 'Ecotype': true, 'Egyptienne': true,
  24320. 'Elephant': true, 'Excelsior': true, 'Fairfield': true,
  24321. 'FF Scala': true, 'Folkard': true, 'Footlight': true,
  24322. 'FreeSerif': true, 'Friz Quadrata': true, 'Garamond': true,
  24323. 'Gentium': true, 'Georgia': true, 'Gloucester': true,
  24324. 'Goudy Old Style': true, 'Goudy Schoolbook': true, 'Goudy Pro Font': true,
  24325. 'Granjon': true, 'Guardian Egyptian': true, 'Heather': true,
  24326. 'Hercules': true, 'High Tower Text': true, 'Hiroshige': true,
  24327. 'Hoefler Text': true, 'Humana Serif': true, 'Imprint': true,
  24328. 'Ionic No. 5': true, 'Janson': true, 'Joanna': true,
  24329. 'Korinna': true, 'Lexicon': true, 'Liberation Serif': true,
  24330. 'Linux Libertine': true, 'Literaturnaya': true, 'Lucida': true,
  24331. 'Lucida Bright': true, 'Melior': true, 'Memphis': true,
  24332. 'Miller': true, 'Minion': true, 'Modern': true,
  24333. 'Mona Lisa': true, 'Mrs Eaves': true, 'MS Serif': true,
  24334. 'Museo Slab': true, 'New York': true, 'Nimbus Roman': true,
  24335. 'NPS Rawlinson Roadway': true, 'Palatino': true, 'Perpetua': true,
  24336. 'Plantin': true, 'Plantin Schoolbook': true, 'Playbill': true,
  24337. 'Poor Richard': true, 'Rawlinson Roadway': true, 'Renault': true,
  24338. 'Requiem': true, 'Rockwell': true, 'Roman': true,
  24339. 'Rotis Serif': true, 'Sabon': true, 'Scala': true,
  24340. 'Seagull': true, 'Sistina': true, 'Souvenir': true,
  24341. 'STIX': true, 'Stone Informal': true, 'Stone Serif': true,
  24342. 'Sylfaen': true, 'Times': true, 'Trajan': true,
  24343. 'Trinité': true, 'Trump Mediaeval': true, 'Utopia': true,
  24344. 'Vale Type': true, 'Bitstream Vera': true, 'Vera Serif': true,
  24345. 'Versailles': true, 'Wanted': true, 'Weiss': true,
  24346. 'Wide Latin': true, 'Windsor': true, 'XITS': true
  24347. };
  24348. var symbolsFonts = {
  24349. 'Dingbats': true, 'Symbol': true, 'ZapfDingbats': true
  24350. };
  24351. // Glyph map for well-known standard fonts. Sometimes Ghostscript uses CID fonts
  24352. // but does not embed the CID to GID mapping. The mapping is incomplete for all
  24353. // glyphs, but common for some set of the standard fonts.
  24354. var GlyphMapForStandardFonts = {
  24355. '2': 10, '3': 32, '4': 33, '5': 34, '6': 35, '7': 36, '8': 37, '9': 38,
  24356. '10': 39, '11': 40, '12': 41, '13': 42, '14': 43, '15': 44, '16': 45,
  24357. '17': 46, '18': 47, '19': 48, '20': 49, '21': 50, '22': 51, '23': 52,
  24358. '24': 53, '25': 54, '26': 55, '27': 56, '28': 57, '29': 58, '30': 894,
  24359. '31': 60, '32': 61, '33': 62, '34': 63, '35': 64, '36': 65, '37': 66,
  24360. '38': 67, '39': 68, '40': 69, '41': 70, '42': 71, '43': 72, '44': 73,
  24361. '45': 74, '46': 75, '47': 76, '48': 77, '49': 78, '50': 79, '51': 80,
  24362. '52': 81, '53': 82, '54': 83, '55': 84, '56': 85, '57': 86, '58': 87,
  24363. '59': 88, '60': 89, '61': 90, '62': 91, '63': 92, '64': 93, '65': 94,
  24364. '66': 95, '67': 96, '68': 97, '69': 98, '70': 99, '71': 100, '72': 101,
  24365. '73': 102, '74': 103, '75': 104, '76': 105, '77': 106, '78': 107, '79': 108,
  24366. '80': 109, '81': 110, '82': 111, '83': 112, '84': 113, '85': 114, '86': 115,
  24367. '87': 116, '88': 117, '89': 118, '90': 119, '91': 120, '92': 121, '93': 122,
  24368. '94': 123, '95': 124, '96': 125, '97': 126, '98': 196, '99': 197, '100': 199,
  24369. '101': 201, '102': 209, '103': 214, '104': 220, '105': 225, '106': 224,
  24370. '107': 226, '108': 228, '109': 227, '110': 229, '111': 231, '112': 233,
  24371. '113': 232, '114': 234, '115': 235, '116': 237, '117': 236, '118': 238,
  24372. '119': 239, '120': 241, '121': 243, '122': 242, '123': 244, '124': 246,
  24373. '125': 245, '126': 250, '127': 249, '128': 251, '129': 252, '130': 8224,
  24374. '131': 176, '132': 162, '133': 163, '134': 167, '135': 8226, '136': 182,
  24375. '137': 223, '138': 174, '139': 169, '140': 8482, '141': 180, '142': 168,
  24376. '143': 8800, '144': 198, '145': 216, '146': 8734, '147': 177, '148': 8804,
  24377. '149': 8805, '150': 165, '151': 181, '152': 8706, '153': 8721, '154': 8719,
  24378. '156': 8747, '157': 170, '158': 186, '159': 8486, '160': 230, '161': 248,
  24379. '162': 191, '163': 161, '164': 172, '165': 8730, '166': 402, '167': 8776,
  24380. '168': 8710, '169': 171, '170': 187, '171': 8230, '210': 218, '223': 711,
  24381. '224': 321, '225': 322, '227': 353, '229': 382, '234': 253, '252': 263,
  24382. '253': 268, '254': 269, '258': 258, '260': 260, '261': 261, '265': 280,
  24383. '266': 281, '268': 283, '269': 313, '275': 323, '276': 324, '278': 328,
  24384. '284': 345, '285': 346, '286': 347, '292': 367, '295': 377, '296': 378,
  24385. '298': 380, '305': 963,
  24386. '306': 964, '307': 966, '308': 8215, '309': 8252, '310': 8319, '311': 8359,
  24387. '312': 8592, '313': 8593, '337': 9552, '493': 1039, '494': 1040, '705': 1524,
  24388. '706': 8362, '710': 64288, '711': 64298, '759': 1617, '761': 1776,
  24389. '763': 1778, '775': 1652, '777': 1764, '778': 1780, '779': 1781, '780': 1782,
  24390. '782': 771, '783': 64726, '786': 8363, '788': 8532, '790': 768, '791': 769,
  24391. '792': 768, '795': 803, '797': 64336, '798': 64337, '799': 64342,
  24392. '800': 64343, '801': 64344, '802': 64345, '803': 64362, '804': 64363,
  24393. '805': 64364, '2424': 7821, '2425': 7822, '2426': 7823, '2427': 7824,
  24394. '2428': 7825, '2429': 7826, '2430': 7827, '2433': 7682, '2678': 8045,
  24395. '2679': 8046, '2830': 1552, '2838': 686, '2840': 751, '2842': 753,
  24396. '2843': 754, '2844': 755, '2846': 757, '2856': 767, '2857': 848, '2858': 849,
  24397. '2862': 853, '2863': 854, '2864': 855, '2865': 861, '2866': 862, '2906': 7460,
  24398. '2908': 7462, '2909': 7463, '2910': 7464, '2912': 7466, '2913': 7467,
  24399. '2914': 7468, '2916': 7470, '2917': 7471, '2918': 7472, '2920': 7474,
  24400. '2921': 7475, '2922': 7476, '2924': 7478, '2925': 7479, '2926': 7480,
  24401. '2928': 7482, '2929': 7483, '2930': 7484, '2932': 7486, '2933': 7487,
  24402. '2934': 7488, '2936': 7490, '2937': 7491, '2938': 7492, '2940': 7494,
  24403. '2941': 7495, '2942': 7496, '2944': 7498, '2946': 7500, '2948': 7502,
  24404. '2950': 7504, '2951': 7505, '2952': 7506, '2954': 7508, '2955': 7509,
  24405. '2956': 7510, '2958': 7512, '2959': 7513, '2960': 7514, '2962': 7516,
  24406. '2963': 7517, '2964': 7518, '2966': 7520, '2967': 7521, '2968': 7522,
  24407. '2970': 7524, '2971': 7525, '2972': 7526, '2974': 7528, '2975': 7529,
  24408. '2976': 7530, '2978': 1537, '2979': 1538, '2980': 1539, '2982': 1549,
  24409. '2983': 1551, '2984': 1552, '2986': 1554, '2987': 1555, '2988': 1556,
  24410. '2990': 1623, '2991': 1624, '2995': 1775, '2999': 1791, '3002': 64290,
  24411. '3003': 64291, '3004': 64292, '3006': 64294, '3007': 64295, '3008': 64296,
  24412. '3011': 1900, '3014': 8223, '3015': 8244, '3017': 7532, '3018': 7533,
  24413. '3019': 7534, '3075': 7590, '3076': 7591, '3079': 7594, '3080': 7595,
  24414. '3083': 7598, '3084': 7599, '3087': 7602, '3088': 7603, '3091': 7606,
  24415. '3092': 7607, '3095': 7610, '3096': 7611, '3099': 7614, '3100': 7615,
  24416. '3103': 7618, '3104': 7619, '3107': 8337, '3108': 8338, '3116': 1884,
  24417. '3119': 1885, '3120': 1885, '3123': 1886, '3124': 1886, '3127': 1887,
  24418. '3128': 1887, '3131': 1888, '3132': 1888, '3135': 1889, '3136': 1889,
  24419. '3139': 1890, '3140': 1890, '3143': 1891, '3144': 1891, '3147': 1892,
  24420. '3148': 1892, '3153': 580, '3154': 581, '3157': 584, '3158': 585, '3161': 588,
  24421. '3162': 589, '3165': 891, '3166': 892, '3169': 1274, '3170': 1275,
  24422. '3173': 1278, '3174': 1279, '3181': 7622, '3182': 7623, '3282': 11799,
  24423. '3316': 578, '3379': 42785, '3393': 1159, '3416': 8377
  24424. };
  24425. // The glyph map for ArialBlack differs slightly from the glyph map used for
  24426. // other well-known standard fonts. Hence we use this (incomplete) CID to GID
  24427. // mapping to adjust the glyph map for non-embedded ArialBlack fonts.
  24428. var SupplementalGlyphMapForArialBlack = {
  24429. '227': 322, '264': 261, '291': 346,
  24430. };
  24431. // Some characters, e.g. copyrightserif, are mapped to the private use area and
  24432. // might not be displayed using standard fonts. Mapping/hacking well-known chars
  24433. // to the similar equivalents in the normal characters range.
  24434. var SpecialPUASymbols = {
  24435. '63721': 0x00A9, // copyrightsans (0xF8E9) => copyright
  24436. '63193': 0x00A9, // copyrightserif (0xF6D9) => copyright
  24437. '63720': 0x00AE, // registersans (0xF8E8) => registered
  24438. '63194': 0x00AE, // registerserif (0xF6DA) => registered
  24439. '63722': 0x2122, // trademarksans (0xF8EA) => trademark
  24440. '63195': 0x2122, // trademarkserif (0xF6DB) => trademark
  24441. '63729': 0x23A7, // bracelefttp (0xF8F1)
  24442. '63730': 0x23A8, // braceleftmid (0xF8F2)
  24443. '63731': 0x23A9, // braceleftbt (0xF8F3)
  24444. '63740': 0x23AB, // bracerighttp (0xF8FC)
  24445. '63741': 0x23AC, // bracerightmid (0xF8FD)
  24446. '63742': 0x23AD, // bracerightbt (0xF8FE)
  24447. '63726': 0x23A1, // bracketlefttp (0xF8EE)
  24448. '63727': 0x23A2, // bracketleftex (0xF8EF)
  24449. '63728': 0x23A3, // bracketleftbt (0xF8F0)
  24450. '63737': 0x23A4, // bracketrighttp (0xF8F9)
  24451. '63738': 0x23A5, // bracketrightex (0xF8FA)
  24452. '63739': 0x23A6, // bracketrightbt (0xF8FB)
  24453. '63723': 0x239B, // parenlefttp (0xF8EB)
  24454. '63724': 0x239C, // parenleftex (0xF8EC)
  24455. '63725': 0x239D, // parenleftbt (0xF8ED)
  24456. '63734': 0x239E, // parenrighttp (0xF8F6)
  24457. '63735': 0x239F, // parenrightex (0xF8F7)
  24458. '63736': 0x23A0, // parenrightbt (0xF8F8)
  24459. };
  24460. function mapSpecialUnicodeValues(code) {
  24461. if (code >= 0xFFF0 && code <= 0xFFFF) { // Specials unicode block.
  24462. return 0;
  24463. } else if (code >= 0xF600 && code <= 0xF8FF) {
  24464. return (SpecialPUASymbols[code] || code);
  24465. }
  24466. return code;
  24467. }
  24468. var UnicodeRanges = [
  24469. { 'begin': 0x0000, 'end': 0x007F }, // Basic Latin
  24470. { 'begin': 0x0080, 'end': 0x00FF }, // Latin-1 Supplement
  24471. { 'begin': 0x0100, 'end': 0x017F }, // Latin Extended-A
  24472. { 'begin': 0x0180, 'end': 0x024F }, // Latin Extended-B
  24473. { 'begin': 0x0250, 'end': 0x02AF }, // IPA Extensions
  24474. { 'begin': 0x02B0, 'end': 0x02FF }, // Spacing Modifier Letters
  24475. { 'begin': 0x0300, 'end': 0x036F }, // Combining Diacritical Marks
  24476. { 'begin': 0x0370, 'end': 0x03FF }, // Greek and Coptic
  24477. { 'begin': 0x2C80, 'end': 0x2CFF }, // Coptic
  24478. { 'begin': 0x0400, 'end': 0x04FF }, // Cyrillic
  24479. { 'begin': 0x0530, 'end': 0x058F }, // Armenian
  24480. { 'begin': 0x0590, 'end': 0x05FF }, // Hebrew
  24481. { 'begin': 0xA500, 'end': 0xA63F }, // Vai
  24482. { 'begin': 0x0600, 'end': 0x06FF }, // Arabic
  24483. { 'begin': 0x07C0, 'end': 0x07FF }, // NKo
  24484. { 'begin': 0x0900, 'end': 0x097F }, // Devanagari
  24485. { 'begin': 0x0980, 'end': 0x09FF }, // Bengali
  24486. { 'begin': 0x0A00, 'end': 0x0A7F }, // Gurmukhi
  24487. { 'begin': 0x0A80, 'end': 0x0AFF }, // Gujarati
  24488. { 'begin': 0x0B00, 'end': 0x0B7F }, // Oriya
  24489. { 'begin': 0x0B80, 'end': 0x0BFF }, // Tamil
  24490. { 'begin': 0x0C00, 'end': 0x0C7F }, // Telugu
  24491. { 'begin': 0x0C80, 'end': 0x0CFF }, // Kannada
  24492. { 'begin': 0x0D00, 'end': 0x0D7F }, // Malayalam
  24493. { 'begin': 0x0E00, 'end': 0x0E7F }, // Thai
  24494. { 'begin': 0x0E80, 'end': 0x0EFF }, // Lao
  24495. { 'begin': 0x10A0, 'end': 0x10FF }, // Georgian
  24496. { 'begin': 0x1B00, 'end': 0x1B7F }, // Balinese
  24497. { 'begin': 0x1100, 'end': 0x11FF }, // Hangul Jamo
  24498. { 'begin': 0x1E00, 'end': 0x1EFF }, // Latin Extended Additional
  24499. { 'begin': 0x1F00, 'end': 0x1FFF }, // Greek Extended
  24500. { 'begin': 0x2000, 'end': 0x206F }, // General Punctuation
  24501. { 'begin': 0x2070, 'end': 0x209F }, // Superscripts And Subscripts
  24502. { 'begin': 0x20A0, 'end': 0x20CF }, // Currency Symbol
  24503. { 'begin': 0x20D0, 'end': 0x20FF }, // Combining Diacritical Marks For Symbols
  24504. { 'begin': 0x2100, 'end': 0x214F }, // Letterlike Symbols
  24505. { 'begin': 0x2150, 'end': 0x218F }, // Number Forms
  24506. { 'begin': 0x2190, 'end': 0x21FF }, // Arrows
  24507. { 'begin': 0x2200, 'end': 0x22FF }, // Mathematical Operators
  24508. { 'begin': 0x2300, 'end': 0x23FF }, // Miscellaneous Technical
  24509. { 'begin': 0x2400, 'end': 0x243F }, // Control Pictures
  24510. { 'begin': 0x2440, 'end': 0x245F }, // Optical Character Recognition
  24511. { 'begin': 0x2460, 'end': 0x24FF }, // Enclosed Alphanumerics
  24512. { 'begin': 0x2500, 'end': 0x257F }, // Box Drawing
  24513. { 'begin': 0x2580, 'end': 0x259F }, // Block Elements
  24514. { 'begin': 0x25A0, 'end': 0x25FF }, // Geometric Shapes
  24515. { 'begin': 0x2600, 'end': 0x26FF }, // Miscellaneous Symbols
  24516. { 'begin': 0x2700, 'end': 0x27BF }, // Dingbats
  24517. { 'begin': 0x3000, 'end': 0x303F }, // CJK Symbols And Punctuation
  24518. { 'begin': 0x3040, 'end': 0x309F }, // Hiragana
  24519. { 'begin': 0x30A0, 'end': 0x30FF }, // Katakana
  24520. { 'begin': 0x3100, 'end': 0x312F }, // Bopomofo
  24521. { 'begin': 0x3130, 'end': 0x318F }, // Hangul Compatibility Jamo
  24522. { 'begin': 0xA840, 'end': 0xA87F }, // Phags-pa
  24523. { 'begin': 0x3200, 'end': 0x32FF }, // Enclosed CJK Letters And Months
  24524. { 'begin': 0x3300, 'end': 0x33FF }, // CJK Compatibility
  24525. { 'begin': 0xAC00, 'end': 0xD7AF }, // Hangul Syllables
  24526. { 'begin': 0xD800, 'end': 0xDFFF }, // Non-Plane 0 *
  24527. { 'begin': 0x10900, 'end': 0x1091F }, // Phoenicia
  24528. { 'begin': 0x4E00, 'end': 0x9FFF }, // CJK Unified Ideographs
  24529. { 'begin': 0xE000, 'end': 0xF8FF }, // Private Use Area (plane 0)
  24530. { 'begin': 0x31C0, 'end': 0x31EF }, // CJK Strokes
  24531. { 'begin': 0xFB00, 'end': 0xFB4F }, // Alphabetic Presentation Forms
  24532. { 'begin': 0xFB50, 'end': 0xFDFF }, // Arabic Presentation Forms-A
  24533. { 'begin': 0xFE20, 'end': 0xFE2F }, // Combining Half Marks
  24534. { 'begin': 0xFE10, 'end': 0xFE1F }, // Vertical Forms
  24535. { 'begin': 0xFE50, 'end': 0xFE6F }, // Small Form Variants
  24536. { 'begin': 0xFE70, 'end': 0xFEFF }, // Arabic Presentation Forms-B
  24537. { 'begin': 0xFF00, 'end': 0xFFEF }, // Halfwidth And Fullwidth Forms
  24538. { 'begin': 0xFFF0, 'end': 0xFFFF }, // Specials
  24539. { 'begin': 0x0F00, 'end': 0x0FFF }, // Tibetan
  24540. { 'begin': 0x0700, 'end': 0x074F }, // Syriac
  24541. { 'begin': 0x0780, 'end': 0x07BF }, // Thaana
  24542. { 'begin': 0x0D80, 'end': 0x0DFF }, // Sinhala
  24543. { 'begin': 0x1000, 'end': 0x109F }, // Myanmar
  24544. { 'begin': 0x1200, 'end': 0x137F }, // Ethiopic
  24545. { 'begin': 0x13A0, 'end': 0x13FF }, // Cherokee
  24546. { 'begin': 0x1400, 'end': 0x167F }, // Unified Canadian Aboriginal Syllabics
  24547. { 'begin': 0x1680, 'end': 0x169F }, // Ogham
  24548. { 'begin': 0x16A0, 'end': 0x16FF }, // Runic
  24549. { 'begin': 0x1780, 'end': 0x17FF }, // Khmer
  24550. { 'begin': 0x1800, 'end': 0x18AF }, // Mongolian
  24551. { 'begin': 0x2800, 'end': 0x28FF }, // Braille Patterns
  24552. { 'begin': 0xA000, 'end': 0xA48F }, // Yi Syllables
  24553. { 'begin': 0x1700, 'end': 0x171F }, // Tagalog
  24554. { 'begin': 0x10300, 'end': 0x1032F }, // Old Italic
  24555. { 'begin': 0x10330, 'end': 0x1034F }, // Gothic
  24556. { 'begin': 0x10400, 'end': 0x1044F }, // Deseret
  24557. { 'begin': 0x1D000, 'end': 0x1D0FF }, // Byzantine Musical Symbols
  24558. { 'begin': 0x1D400, 'end': 0x1D7FF }, // Mathematical Alphanumeric Symbols
  24559. { 'begin': 0xFF000, 'end': 0xFFFFD }, // Private Use (plane 15)
  24560. { 'begin': 0xFE00, 'end': 0xFE0F }, // Variation Selectors
  24561. { 'begin': 0xE0000, 'end': 0xE007F }, // Tags
  24562. { 'begin': 0x1900, 'end': 0x194F }, // Limbu
  24563. { 'begin': 0x1950, 'end': 0x197F }, // Tai Le
  24564. { 'begin': 0x1980, 'end': 0x19DF }, // New Tai Lue
  24565. { 'begin': 0x1A00, 'end': 0x1A1F }, // Buginese
  24566. { 'begin': 0x2C00, 'end': 0x2C5F }, // Glagolitic
  24567. { 'begin': 0x2D30, 'end': 0x2D7F }, // Tifinagh
  24568. { 'begin': 0x4DC0, 'end': 0x4DFF }, // Yijing Hexagram Symbols
  24569. { 'begin': 0xA800, 'end': 0xA82F }, // Syloti Nagri
  24570. { 'begin': 0x10000, 'end': 0x1007F }, // Linear B Syllabary
  24571. { 'begin': 0x10140, 'end': 0x1018F }, // Ancient Greek Numbers
  24572. { 'begin': 0x10380, 'end': 0x1039F }, // Ugaritic
  24573. { 'begin': 0x103A0, 'end': 0x103DF }, // Old Persian
  24574. { 'begin': 0x10450, 'end': 0x1047F }, // Shavian
  24575. { 'begin': 0x10480, 'end': 0x104AF }, // Osmanya
  24576. { 'begin': 0x10800, 'end': 0x1083F }, // Cypriot Syllabary
  24577. { 'begin': 0x10A00, 'end': 0x10A5F }, // Kharoshthi
  24578. { 'begin': 0x1D300, 'end': 0x1D35F }, // Tai Xuan Jing Symbols
  24579. { 'begin': 0x12000, 'end': 0x123FF }, // Cuneiform
  24580. { 'begin': 0x1D360, 'end': 0x1D37F }, // Counting Rod Numerals
  24581. { 'begin': 0x1B80, 'end': 0x1BBF }, // Sundanese
  24582. { 'begin': 0x1C00, 'end': 0x1C4F }, // Lepcha
  24583. { 'begin': 0x1C50, 'end': 0x1C7F }, // Ol Chiki
  24584. { 'begin': 0xA880, 'end': 0xA8DF }, // Saurashtra
  24585. { 'begin': 0xA900, 'end': 0xA92F }, // Kayah Li
  24586. { 'begin': 0xA930, 'end': 0xA95F }, // Rejang
  24587. { 'begin': 0xAA00, 'end': 0xAA5F }, // Cham
  24588. { 'begin': 0x10190, 'end': 0x101CF }, // Ancient Symbols
  24589. { 'begin': 0x101D0, 'end': 0x101FF }, // Phaistos Disc
  24590. { 'begin': 0x102A0, 'end': 0x102DF }, // Carian
  24591. { 'begin': 0x1F030, 'end': 0x1F09F } // Domino Tiles
  24592. ];
  24593. var MacStandardGlyphOrdering = [
  24594. '.notdef', '.null', 'nonmarkingreturn', 'space', 'exclam', 'quotedbl',
  24595. 'numbersign', 'dollar', 'percent', 'ampersand', 'quotesingle', 'parenleft',
  24596. 'parenright', 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash',
  24597. 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  24598. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question', 'at',
  24599. 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
  24600. 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'bracketleft',
  24601. 'backslash', 'bracketright', 'asciicircum', 'underscore', 'grave', 'a', 'b',
  24602. 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q',
  24603. 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright',
  24604. 'asciitilde', 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde',
  24605. 'Odieresis', 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis',
  24606. 'atilde', 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  24607. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute', 'ograve',
  24608. 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave', 'ucircumflex',
  24609. 'udieresis', 'dagger', 'degree', 'cent', 'sterling', 'section', 'bullet',
  24610. 'paragraph', 'germandbls', 'registered', 'copyright', 'trademark', 'acute',
  24611. 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity', 'plusminus', 'lessequal',
  24612. 'greaterequal', 'yen', 'mu', 'partialdiff', 'summation', 'product', 'pi',
  24613. 'integral', 'ordfeminine', 'ordmasculine', 'Omega', 'ae', 'oslash',
  24614. 'questiondown', 'exclamdown', 'logicalnot', 'radical', 'florin',
  24615. 'approxequal', 'Delta', 'guillemotleft', 'guillemotright', 'ellipsis',
  24616. 'nonbreakingspace', 'Agrave', 'Atilde', 'Otilde', 'OE', 'oe', 'endash',
  24617. 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft', 'quoteright',
  24618. 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction', 'currency',
  24619. 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl', 'periodcentered',
  24620. 'quotesinglbase', 'quotedblbase', 'perthousand', 'Acircumflex',
  24621. 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute', 'Icircumflex',
  24622. 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple', 'Ograve', 'Uacute',
  24623. 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex', 'tilde', 'macron',
  24624. 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron',
  24625. 'Lslash', 'lslash', 'Scaron', 'scaron', 'Zcaron', 'zcaron', 'brokenbar',
  24626. 'Eth', 'eth', 'Yacute', 'yacute', 'Thorn', 'thorn', 'minus', 'multiply',
  24627. 'onesuperior', 'twosuperior', 'threesuperior', 'onehalf', 'onequarter',
  24628. 'threequarters', 'franc', 'Gbreve', 'gbreve', 'Idotaccent', 'Scedilla',
  24629. 'scedilla', 'Cacute', 'cacute', 'Ccaron', 'ccaron', 'dcroat'];
  24630. function getUnicodeRangeFor(value) {
  24631. for (var i = 0, ii = UnicodeRanges.length; i < ii; i++) {
  24632. var range = UnicodeRanges[i];
  24633. if (value >= range.begin && value < range.end) {
  24634. return i;
  24635. }
  24636. }
  24637. return -1;
  24638. }
  24639. function isRTLRangeFor(value) {
  24640. var range = UnicodeRanges[13];
  24641. if (value >= range.begin && value < range.end) {
  24642. return true;
  24643. }
  24644. range = UnicodeRanges[11];
  24645. if (value >= range.begin && value < range.end) {
  24646. return true;
  24647. }
  24648. return false;
  24649. }
  24650. // The normalization table is obtained by filtering the Unicode characters
  24651. // database with <compat> entries.
  24652. var NormalizedUnicodes = {
  24653. '\u00A8': '\u0020\u0308',
  24654. '\u00AF': '\u0020\u0304',
  24655. '\u00B4': '\u0020\u0301',
  24656. '\u00B5': '\u03BC',
  24657. '\u00B8': '\u0020\u0327',
  24658. '\u0132': '\u0049\u004A',
  24659. '\u0133': '\u0069\u006A',
  24660. '\u013F': '\u004C\u00B7',
  24661. '\u0140': '\u006C\u00B7',
  24662. '\u0149': '\u02BC\u006E',
  24663. '\u017F': '\u0073',
  24664. '\u01C4': '\u0044\u017D',
  24665. '\u01C5': '\u0044\u017E',
  24666. '\u01C6': '\u0064\u017E',
  24667. '\u01C7': '\u004C\u004A',
  24668. '\u01C8': '\u004C\u006A',
  24669. '\u01C9': '\u006C\u006A',
  24670. '\u01CA': '\u004E\u004A',
  24671. '\u01CB': '\u004E\u006A',
  24672. '\u01CC': '\u006E\u006A',
  24673. '\u01F1': '\u0044\u005A',
  24674. '\u01F2': '\u0044\u007A',
  24675. '\u01F3': '\u0064\u007A',
  24676. '\u02D8': '\u0020\u0306',
  24677. '\u02D9': '\u0020\u0307',
  24678. '\u02DA': '\u0020\u030A',
  24679. '\u02DB': '\u0020\u0328',
  24680. '\u02DC': '\u0020\u0303',
  24681. '\u02DD': '\u0020\u030B',
  24682. '\u037A': '\u0020\u0345',
  24683. '\u0384': '\u0020\u0301',
  24684. '\u03D0': '\u03B2',
  24685. '\u03D1': '\u03B8',
  24686. '\u03D2': '\u03A5',
  24687. '\u03D5': '\u03C6',
  24688. '\u03D6': '\u03C0',
  24689. '\u03F0': '\u03BA',
  24690. '\u03F1': '\u03C1',
  24691. '\u03F2': '\u03C2',
  24692. '\u03F4': '\u0398',
  24693. '\u03F5': '\u03B5',
  24694. '\u03F9': '\u03A3',
  24695. '\u0587': '\u0565\u0582',
  24696. '\u0675': '\u0627\u0674',
  24697. '\u0676': '\u0648\u0674',
  24698. '\u0677': '\u06C7\u0674',
  24699. '\u0678': '\u064A\u0674',
  24700. '\u0E33': '\u0E4D\u0E32',
  24701. '\u0EB3': '\u0ECD\u0EB2',
  24702. '\u0EDC': '\u0EAB\u0E99',
  24703. '\u0EDD': '\u0EAB\u0EA1',
  24704. '\u0F77': '\u0FB2\u0F81',
  24705. '\u0F79': '\u0FB3\u0F81',
  24706. '\u1E9A': '\u0061\u02BE',
  24707. '\u1FBD': '\u0020\u0313',
  24708. '\u1FBF': '\u0020\u0313',
  24709. '\u1FC0': '\u0020\u0342',
  24710. '\u1FFE': '\u0020\u0314',
  24711. '\u2002': '\u0020',
  24712. '\u2003': '\u0020',
  24713. '\u2004': '\u0020',
  24714. '\u2005': '\u0020',
  24715. '\u2006': '\u0020',
  24716. '\u2008': '\u0020',
  24717. '\u2009': '\u0020',
  24718. '\u200A': '\u0020',
  24719. '\u2017': '\u0020\u0333',
  24720. '\u2024': '\u002E',
  24721. '\u2025': '\u002E\u002E',
  24722. '\u2026': '\u002E\u002E\u002E',
  24723. '\u2033': '\u2032\u2032',
  24724. '\u2034': '\u2032\u2032\u2032',
  24725. '\u2036': '\u2035\u2035',
  24726. '\u2037': '\u2035\u2035\u2035',
  24727. '\u203C': '\u0021\u0021',
  24728. '\u203E': '\u0020\u0305',
  24729. '\u2047': '\u003F\u003F',
  24730. '\u2048': '\u003F\u0021',
  24731. '\u2049': '\u0021\u003F',
  24732. '\u2057': '\u2032\u2032\u2032\u2032',
  24733. '\u205F': '\u0020',
  24734. '\u20A8': '\u0052\u0073',
  24735. '\u2100': '\u0061\u002F\u0063',
  24736. '\u2101': '\u0061\u002F\u0073',
  24737. '\u2103': '\u00B0\u0043',
  24738. '\u2105': '\u0063\u002F\u006F',
  24739. '\u2106': '\u0063\u002F\u0075',
  24740. '\u2107': '\u0190',
  24741. '\u2109': '\u00B0\u0046',
  24742. '\u2116': '\u004E\u006F',
  24743. '\u2121': '\u0054\u0045\u004C',
  24744. '\u2135': '\u05D0',
  24745. '\u2136': '\u05D1',
  24746. '\u2137': '\u05D2',
  24747. '\u2138': '\u05D3',
  24748. '\u213B': '\u0046\u0041\u0058',
  24749. '\u2160': '\u0049',
  24750. '\u2161': '\u0049\u0049',
  24751. '\u2162': '\u0049\u0049\u0049',
  24752. '\u2163': '\u0049\u0056',
  24753. '\u2164': '\u0056',
  24754. '\u2165': '\u0056\u0049',
  24755. '\u2166': '\u0056\u0049\u0049',
  24756. '\u2167': '\u0056\u0049\u0049\u0049',
  24757. '\u2168': '\u0049\u0058',
  24758. '\u2169': '\u0058',
  24759. '\u216A': '\u0058\u0049',
  24760. '\u216B': '\u0058\u0049\u0049',
  24761. '\u216C': '\u004C',
  24762. '\u216D': '\u0043',
  24763. '\u216E': '\u0044',
  24764. '\u216F': '\u004D',
  24765. '\u2170': '\u0069',
  24766. '\u2171': '\u0069\u0069',
  24767. '\u2172': '\u0069\u0069\u0069',
  24768. '\u2173': '\u0069\u0076',
  24769. '\u2174': '\u0076',
  24770. '\u2175': '\u0076\u0069',
  24771. '\u2176': '\u0076\u0069\u0069',
  24772. '\u2177': '\u0076\u0069\u0069\u0069',
  24773. '\u2178': '\u0069\u0078',
  24774. '\u2179': '\u0078',
  24775. '\u217A': '\u0078\u0069',
  24776. '\u217B': '\u0078\u0069\u0069',
  24777. '\u217C': '\u006C',
  24778. '\u217D': '\u0063',
  24779. '\u217E': '\u0064',
  24780. '\u217F': '\u006D',
  24781. '\u222C': '\u222B\u222B',
  24782. '\u222D': '\u222B\u222B\u222B',
  24783. '\u222F': '\u222E\u222E',
  24784. '\u2230': '\u222E\u222E\u222E',
  24785. '\u2474': '\u0028\u0031\u0029',
  24786. '\u2475': '\u0028\u0032\u0029',
  24787. '\u2476': '\u0028\u0033\u0029',
  24788. '\u2477': '\u0028\u0034\u0029',
  24789. '\u2478': '\u0028\u0035\u0029',
  24790. '\u2479': '\u0028\u0036\u0029',
  24791. '\u247A': '\u0028\u0037\u0029',
  24792. '\u247B': '\u0028\u0038\u0029',
  24793. '\u247C': '\u0028\u0039\u0029',
  24794. '\u247D': '\u0028\u0031\u0030\u0029',
  24795. '\u247E': '\u0028\u0031\u0031\u0029',
  24796. '\u247F': '\u0028\u0031\u0032\u0029',
  24797. '\u2480': '\u0028\u0031\u0033\u0029',
  24798. '\u2481': '\u0028\u0031\u0034\u0029',
  24799. '\u2482': '\u0028\u0031\u0035\u0029',
  24800. '\u2483': '\u0028\u0031\u0036\u0029',
  24801. '\u2484': '\u0028\u0031\u0037\u0029',
  24802. '\u2485': '\u0028\u0031\u0038\u0029',
  24803. '\u2486': '\u0028\u0031\u0039\u0029',
  24804. '\u2487': '\u0028\u0032\u0030\u0029',
  24805. '\u2488': '\u0031\u002E',
  24806. '\u2489': '\u0032\u002E',
  24807. '\u248A': '\u0033\u002E',
  24808. '\u248B': '\u0034\u002E',
  24809. '\u248C': '\u0035\u002E',
  24810. '\u248D': '\u0036\u002E',
  24811. '\u248E': '\u0037\u002E',
  24812. '\u248F': '\u0038\u002E',
  24813. '\u2490': '\u0039\u002E',
  24814. '\u2491': '\u0031\u0030\u002E',
  24815. '\u2492': '\u0031\u0031\u002E',
  24816. '\u2493': '\u0031\u0032\u002E',
  24817. '\u2494': '\u0031\u0033\u002E',
  24818. '\u2495': '\u0031\u0034\u002E',
  24819. '\u2496': '\u0031\u0035\u002E',
  24820. '\u2497': '\u0031\u0036\u002E',
  24821. '\u2498': '\u0031\u0037\u002E',
  24822. '\u2499': '\u0031\u0038\u002E',
  24823. '\u249A': '\u0031\u0039\u002E',
  24824. '\u249B': '\u0032\u0030\u002E',
  24825. '\u249C': '\u0028\u0061\u0029',
  24826. '\u249D': '\u0028\u0062\u0029',
  24827. '\u249E': '\u0028\u0063\u0029',
  24828. '\u249F': '\u0028\u0064\u0029',
  24829. '\u24A0': '\u0028\u0065\u0029',
  24830. '\u24A1': '\u0028\u0066\u0029',
  24831. '\u24A2': '\u0028\u0067\u0029',
  24832. '\u24A3': '\u0028\u0068\u0029',
  24833. '\u24A4': '\u0028\u0069\u0029',
  24834. '\u24A5': '\u0028\u006A\u0029',
  24835. '\u24A6': '\u0028\u006B\u0029',
  24836. '\u24A7': '\u0028\u006C\u0029',
  24837. '\u24A8': '\u0028\u006D\u0029',
  24838. '\u24A9': '\u0028\u006E\u0029',
  24839. '\u24AA': '\u0028\u006F\u0029',
  24840. '\u24AB': '\u0028\u0070\u0029',
  24841. '\u24AC': '\u0028\u0071\u0029',
  24842. '\u24AD': '\u0028\u0072\u0029',
  24843. '\u24AE': '\u0028\u0073\u0029',
  24844. '\u24AF': '\u0028\u0074\u0029',
  24845. '\u24B0': '\u0028\u0075\u0029',
  24846. '\u24B1': '\u0028\u0076\u0029',
  24847. '\u24B2': '\u0028\u0077\u0029',
  24848. '\u24B3': '\u0028\u0078\u0029',
  24849. '\u24B4': '\u0028\u0079\u0029',
  24850. '\u24B5': '\u0028\u007A\u0029',
  24851. '\u2A0C': '\u222B\u222B\u222B\u222B',
  24852. '\u2A74': '\u003A\u003A\u003D',
  24853. '\u2A75': '\u003D\u003D',
  24854. '\u2A76': '\u003D\u003D\u003D',
  24855. '\u2E9F': '\u6BCD',
  24856. '\u2EF3': '\u9F9F',
  24857. '\u2F00': '\u4E00',
  24858. '\u2F01': '\u4E28',
  24859. '\u2F02': '\u4E36',
  24860. '\u2F03': '\u4E3F',
  24861. '\u2F04': '\u4E59',
  24862. '\u2F05': '\u4E85',
  24863. '\u2F06': '\u4E8C',
  24864. '\u2F07': '\u4EA0',
  24865. '\u2F08': '\u4EBA',
  24866. '\u2F09': '\u513F',
  24867. '\u2F0A': '\u5165',
  24868. '\u2F0B': '\u516B',
  24869. '\u2F0C': '\u5182',
  24870. '\u2F0D': '\u5196',
  24871. '\u2F0E': '\u51AB',
  24872. '\u2F0F': '\u51E0',
  24873. '\u2F10': '\u51F5',
  24874. '\u2F11': '\u5200',
  24875. '\u2F12': '\u529B',
  24876. '\u2F13': '\u52F9',
  24877. '\u2F14': '\u5315',
  24878. '\u2F15': '\u531A',
  24879. '\u2F16': '\u5338',
  24880. '\u2F17': '\u5341',
  24881. '\u2F18': '\u535C',
  24882. '\u2F19': '\u5369',
  24883. '\u2F1A': '\u5382',
  24884. '\u2F1B': '\u53B6',
  24885. '\u2F1C': '\u53C8',
  24886. '\u2F1D': '\u53E3',
  24887. '\u2F1E': '\u56D7',
  24888. '\u2F1F': '\u571F',
  24889. '\u2F20': '\u58EB',
  24890. '\u2F21': '\u5902',
  24891. '\u2F22': '\u590A',
  24892. '\u2F23': '\u5915',
  24893. '\u2F24': '\u5927',
  24894. '\u2F25': '\u5973',
  24895. '\u2F26': '\u5B50',
  24896. '\u2F27': '\u5B80',
  24897. '\u2F28': '\u5BF8',
  24898. '\u2F29': '\u5C0F',
  24899. '\u2F2A': '\u5C22',
  24900. '\u2F2B': '\u5C38',
  24901. '\u2F2C': '\u5C6E',
  24902. '\u2F2D': '\u5C71',
  24903. '\u2F2E': '\u5DDB',
  24904. '\u2F2F': '\u5DE5',
  24905. '\u2F30': '\u5DF1',
  24906. '\u2F31': '\u5DFE',
  24907. '\u2F32': '\u5E72',
  24908. '\u2F33': '\u5E7A',
  24909. '\u2F34': '\u5E7F',
  24910. '\u2F35': '\u5EF4',
  24911. '\u2F36': '\u5EFE',
  24912. '\u2F37': '\u5F0B',
  24913. '\u2F38': '\u5F13',
  24914. '\u2F39': '\u5F50',
  24915. '\u2F3A': '\u5F61',
  24916. '\u2F3B': '\u5F73',
  24917. '\u2F3C': '\u5FC3',
  24918. '\u2F3D': '\u6208',
  24919. '\u2F3E': '\u6236',
  24920. '\u2F3F': '\u624B',
  24921. '\u2F40': '\u652F',
  24922. '\u2F41': '\u6534',
  24923. '\u2F42': '\u6587',
  24924. '\u2F43': '\u6597',
  24925. '\u2F44': '\u65A4',
  24926. '\u2F45': '\u65B9',
  24927. '\u2F46': '\u65E0',
  24928. '\u2F47': '\u65E5',
  24929. '\u2F48': '\u66F0',
  24930. '\u2F49': '\u6708',
  24931. '\u2F4A': '\u6728',
  24932. '\u2F4B': '\u6B20',
  24933. '\u2F4C': '\u6B62',
  24934. '\u2F4D': '\u6B79',
  24935. '\u2F4E': '\u6BB3',
  24936. '\u2F4F': '\u6BCB',
  24937. '\u2F50': '\u6BD4',
  24938. '\u2F51': '\u6BDB',
  24939. '\u2F52': '\u6C0F',
  24940. '\u2F53': '\u6C14',
  24941. '\u2F54': '\u6C34',
  24942. '\u2F55': '\u706B',
  24943. '\u2F56': '\u722A',
  24944. '\u2F57': '\u7236',
  24945. '\u2F58': '\u723B',
  24946. '\u2F59': '\u723F',
  24947. '\u2F5A': '\u7247',
  24948. '\u2F5B': '\u7259',
  24949. '\u2F5C': '\u725B',
  24950. '\u2F5D': '\u72AC',
  24951. '\u2F5E': '\u7384',
  24952. '\u2F5F': '\u7389',
  24953. '\u2F60': '\u74DC',
  24954. '\u2F61': '\u74E6',
  24955. '\u2F62': '\u7518',
  24956. '\u2F63': '\u751F',
  24957. '\u2F64': '\u7528',
  24958. '\u2F65': '\u7530',
  24959. '\u2F66': '\u758B',
  24960. '\u2F67': '\u7592',
  24961. '\u2F68': '\u7676',
  24962. '\u2F69': '\u767D',
  24963. '\u2F6A': '\u76AE',
  24964. '\u2F6B': '\u76BF',
  24965. '\u2F6C': '\u76EE',
  24966. '\u2F6D': '\u77DB',
  24967. '\u2F6E': '\u77E2',
  24968. '\u2F6F': '\u77F3',
  24969. '\u2F70': '\u793A',
  24970. '\u2F71': '\u79B8',
  24971. '\u2F72': '\u79BE',
  24972. '\u2F73': '\u7A74',
  24973. '\u2F74': '\u7ACB',
  24974. '\u2F75': '\u7AF9',
  24975. '\u2F76': '\u7C73',
  24976. '\u2F77': '\u7CF8',
  24977. '\u2F78': '\u7F36',
  24978. '\u2F79': '\u7F51',
  24979. '\u2F7A': '\u7F8A',
  24980. '\u2F7B': '\u7FBD',
  24981. '\u2F7C': '\u8001',
  24982. '\u2F7D': '\u800C',
  24983. '\u2F7E': '\u8012',
  24984. '\u2F7F': '\u8033',
  24985. '\u2F80': '\u807F',
  24986. '\u2F81': '\u8089',
  24987. '\u2F82': '\u81E3',
  24988. '\u2F83': '\u81EA',
  24989. '\u2F84': '\u81F3',
  24990. '\u2F85': '\u81FC',
  24991. '\u2F86': '\u820C',
  24992. '\u2F87': '\u821B',
  24993. '\u2F88': '\u821F',
  24994. '\u2F89': '\u826E',
  24995. '\u2F8A': '\u8272',
  24996. '\u2F8B': '\u8278',
  24997. '\u2F8C': '\u864D',
  24998. '\u2F8D': '\u866B',
  24999. '\u2F8E': '\u8840',
  25000. '\u2F8F': '\u884C',
  25001. '\u2F90': '\u8863',
  25002. '\u2F91': '\u897E',
  25003. '\u2F92': '\u898B',
  25004. '\u2F93': '\u89D2',
  25005. '\u2F94': '\u8A00',
  25006. '\u2F95': '\u8C37',
  25007. '\u2F96': '\u8C46',
  25008. '\u2F97': '\u8C55',
  25009. '\u2F98': '\u8C78',
  25010. '\u2F99': '\u8C9D',
  25011. '\u2F9A': '\u8D64',
  25012. '\u2F9B': '\u8D70',
  25013. '\u2F9C': '\u8DB3',
  25014. '\u2F9D': '\u8EAB',
  25015. '\u2F9E': '\u8ECA',
  25016. '\u2F9F': '\u8F9B',
  25017. '\u2FA0': '\u8FB0',
  25018. '\u2FA1': '\u8FB5',
  25019. '\u2FA2': '\u9091',
  25020. '\u2FA3': '\u9149',
  25021. '\u2FA4': '\u91C6',
  25022. '\u2FA5': '\u91CC',
  25023. '\u2FA6': '\u91D1',
  25024. '\u2FA7': '\u9577',
  25025. '\u2FA8': '\u9580',
  25026. '\u2FA9': '\u961C',
  25027. '\u2FAA': '\u96B6',
  25028. '\u2FAB': '\u96B9',
  25029. '\u2FAC': '\u96E8',
  25030. '\u2FAD': '\u9751',
  25031. '\u2FAE': '\u975E',
  25032. '\u2FAF': '\u9762',
  25033. '\u2FB0': '\u9769',
  25034. '\u2FB1': '\u97CB',
  25035. '\u2FB2': '\u97ED',
  25036. '\u2FB3': '\u97F3',
  25037. '\u2FB4': '\u9801',
  25038. '\u2FB5': '\u98A8',
  25039. '\u2FB6': '\u98DB',
  25040. '\u2FB7': '\u98DF',
  25041. '\u2FB8': '\u9996',
  25042. '\u2FB9': '\u9999',
  25043. '\u2FBA': '\u99AC',
  25044. '\u2FBB': '\u9AA8',
  25045. '\u2FBC': '\u9AD8',
  25046. '\u2FBD': '\u9ADF',
  25047. '\u2FBE': '\u9B25',
  25048. '\u2FBF': '\u9B2F',
  25049. '\u2FC0': '\u9B32',
  25050. '\u2FC1': '\u9B3C',
  25051. '\u2FC2': '\u9B5A',
  25052. '\u2FC3': '\u9CE5',
  25053. '\u2FC4': '\u9E75',
  25054. '\u2FC5': '\u9E7F',
  25055. '\u2FC6': '\u9EA5',
  25056. '\u2FC7': '\u9EBB',
  25057. '\u2FC8': '\u9EC3',
  25058. '\u2FC9': '\u9ECD',
  25059. '\u2FCA': '\u9ED1',
  25060. '\u2FCB': '\u9EF9',
  25061. '\u2FCC': '\u9EFD',
  25062. '\u2FCD': '\u9F0E',
  25063. '\u2FCE': '\u9F13',
  25064. '\u2FCF': '\u9F20',
  25065. '\u2FD0': '\u9F3B',
  25066. '\u2FD1': '\u9F4A',
  25067. '\u2FD2': '\u9F52',
  25068. '\u2FD3': '\u9F8D',
  25069. '\u2FD4': '\u9F9C',
  25070. '\u2FD5': '\u9FA0',
  25071. '\u3036': '\u3012',
  25072. '\u3038': '\u5341',
  25073. '\u3039': '\u5344',
  25074. '\u303A': '\u5345',
  25075. '\u309B': '\u0020\u3099',
  25076. '\u309C': '\u0020\u309A',
  25077. '\u3131': '\u1100',
  25078. '\u3132': '\u1101',
  25079. '\u3133': '\u11AA',
  25080. '\u3134': '\u1102',
  25081. '\u3135': '\u11AC',
  25082. '\u3136': '\u11AD',
  25083. '\u3137': '\u1103',
  25084. '\u3138': '\u1104',
  25085. '\u3139': '\u1105',
  25086. '\u313A': '\u11B0',
  25087. '\u313B': '\u11B1',
  25088. '\u313C': '\u11B2',
  25089. '\u313D': '\u11B3',
  25090. '\u313E': '\u11B4',
  25091. '\u313F': '\u11B5',
  25092. '\u3140': '\u111A',
  25093. '\u3141': '\u1106',
  25094. '\u3142': '\u1107',
  25095. '\u3143': '\u1108',
  25096. '\u3144': '\u1121',
  25097. '\u3145': '\u1109',
  25098. '\u3146': '\u110A',
  25099. '\u3147': '\u110B',
  25100. '\u3148': '\u110C',
  25101. '\u3149': '\u110D',
  25102. '\u314A': '\u110E',
  25103. '\u314B': '\u110F',
  25104. '\u314C': '\u1110',
  25105. '\u314D': '\u1111',
  25106. '\u314E': '\u1112',
  25107. '\u314F': '\u1161',
  25108. '\u3150': '\u1162',
  25109. '\u3151': '\u1163',
  25110. '\u3152': '\u1164',
  25111. '\u3153': '\u1165',
  25112. '\u3154': '\u1166',
  25113. '\u3155': '\u1167',
  25114. '\u3156': '\u1168',
  25115. '\u3157': '\u1169',
  25116. '\u3158': '\u116A',
  25117. '\u3159': '\u116B',
  25118. '\u315A': '\u116C',
  25119. '\u315B': '\u116D',
  25120. '\u315C': '\u116E',
  25121. '\u315D': '\u116F',
  25122. '\u315E': '\u1170',
  25123. '\u315F': '\u1171',
  25124. '\u3160': '\u1172',
  25125. '\u3161': '\u1173',
  25126. '\u3162': '\u1174',
  25127. '\u3163': '\u1175',
  25128. '\u3164': '\u1160',
  25129. '\u3165': '\u1114',
  25130. '\u3166': '\u1115',
  25131. '\u3167': '\u11C7',
  25132. '\u3168': '\u11C8',
  25133. '\u3169': '\u11CC',
  25134. '\u316A': '\u11CE',
  25135. '\u316B': '\u11D3',
  25136. '\u316C': '\u11D7',
  25137. '\u316D': '\u11D9',
  25138. '\u316E': '\u111C',
  25139. '\u316F': '\u11DD',
  25140. '\u3170': '\u11DF',
  25141. '\u3171': '\u111D',
  25142. '\u3172': '\u111E',
  25143. '\u3173': '\u1120',
  25144. '\u3174': '\u1122',
  25145. '\u3175': '\u1123',
  25146. '\u3176': '\u1127',
  25147. '\u3177': '\u1129',
  25148. '\u3178': '\u112B',
  25149. '\u3179': '\u112C',
  25150. '\u317A': '\u112D',
  25151. '\u317B': '\u112E',
  25152. '\u317C': '\u112F',
  25153. '\u317D': '\u1132',
  25154. '\u317E': '\u1136',
  25155. '\u317F': '\u1140',
  25156. '\u3180': '\u1147',
  25157. '\u3181': '\u114C',
  25158. '\u3182': '\u11F1',
  25159. '\u3183': '\u11F2',
  25160. '\u3184': '\u1157',
  25161. '\u3185': '\u1158',
  25162. '\u3186': '\u1159',
  25163. '\u3187': '\u1184',
  25164. '\u3188': '\u1185',
  25165. '\u3189': '\u1188',
  25166. '\u318A': '\u1191',
  25167. '\u318B': '\u1192',
  25168. '\u318C': '\u1194',
  25169. '\u318D': '\u119E',
  25170. '\u318E': '\u11A1',
  25171. '\u3200': '\u0028\u1100\u0029',
  25172. '\u3201': '\u0028\u1102\u0029',
  25173. '\u3202': '\u0028\u1103\u0029',
  25174. '\u3203': '\u0028\u1105\u0029',
  25175. '\u3204': '\u0028\u1106\u0029',
  25176. '\u3205': '\u0028\u1107\u0029',
  25177. '\u3206': '\u0028\u1109\u0029',
  25178. '\u3207': '\u0028\u110B\u0029',
  25179. '\u3208': '\u0028\u110C\u0029',
  25180. '\u3209': '\u0028\u110E\u0029',
  25181. '\u320A': '\u0028\u110F\u0029',
  25182. '\u320B': '\u0028\u1110\u0029',
  25183. '\u320C': '\u0028\u1111\u0029',
  25184. '\u320D': '\u0028\u1112\u0029',
  25185. '\u320E': '\u0028\u1100\u1161\u0029',
  25186. '\u320F': '\u0028\u1102\u1161\u0029',
  25187. '\u3210': '\u0028\u1103\u1161\u0029',
  25188. '\u3211': '\u0028\u1105\u1161\u0029',
  25189. '\u3212': '\u0028\u1106\u1161\u0029',
  25190. '\u3213': '\u0028\u1107\u1161\u0029',
  25191. '\u3214': '\u0028\u1109\u1161\u0029',
  25192. '\u3215': '\u0028\u110B\u1161\u0029',
  25193. '\u3216': '\u0028\u110C\u1161\u0029',
  25194. '\u3217': '\u0028\u110E\u1161\u0029',
  25195. '\u3218': '\u0028\u110F\u1161\u0029',
  25196. '\u3219': '\u0028\u1110\u1161\u0029',
  25197. '\u321A': '\u0028\u1111\u1161\u0029',
  25198. '\u321B': '\u0028\u1112\u1161\u0029',
  25199. '\u321C': '\u0028\u110C\u116E\u0029',
  25200. '\u321D': '\u0028\u110B\u1169\u110C\u1165\u11AB\u0029',
  25201. '\u321E': '\u0028\u110B\u1169\u1112\u116E\u0029',
  25202. '\u3220': '\u0028\u4E00\u0029',
  25203. '\u3221': '\u0028\u4E8C\u0029',
  25204. '\u3222': '\u0028\u4E09\u0029',
  25205. '\u3223': '\u0028\u56DB\u0029',
  25206. '\u3224': '\u0028\u4E94\u0029',
  25207. '\u3225': '\u0028\u516D\u0029',
  25208. '\u3226': '\u0028\u4E03\u0029',
  25209. '\u3227': '\u0028\u516B\u0029',
  25210. '\u3228': '\u0028\u4E5D\u0029',
  25211. '\u3229': '\u0028\u5341\u0029',
  25212. '\u322A': '\u0028\u6708\u0029',
  25213. '\u322B': '\u0028\u706B\u0029',
  25214. '\u322C': '\u0028\u6C34\u0029',
  25215. '\u322D': '\u0028\u6728\u0029',
  25216. '\u322E': '\u0028\u91D1\u0029',
  25217. '\u322F': '\u0028\u571F\u0029',
  25218. '\u3230': '\u0028\u65E5\u0029',
  25219. '\u3231': '\u0028\u682A\u0029',
  25220. '\u3232': '\u0028\u6709\u0029',
  25221. '\u3233': '\u0028\u793E\u0029',
  25222. '\u3234': '\u0028\u540D\u0029',
  25223. '\u3235': '\u0028\u7279\u0029',
  25224. '\u3236': '\u0028\u8CA1\u0029',
  25225. '\u3237': '\u0028\u795D\u0029',
  25226. '\u3238': '\u0028\u52B4\u0029',
  25227. '\u3239': '\u0028\u4EE3\u0029',
  25228. '\u323A': '\u0028\u547C\u0029',
  25229. '\u323B': '\u0028\u5B66\u0029',
  25230. '\u323C': '\u0028\u76E3\u0029',
  25231. '\u323D': '\u0028\u4F01\u0029',
  25232. '\u323E': '\u0028\u8CC7\u0029',
  25233. '\u323F': '\u0028\u5354\u0029',
  25234. '\u3240': '\u0028\u796D\u0029',
  25235. '\u3241': '\u0028\u4F11\u0029',
  25236. '\u3242': '\u0028\u81EA\u0029',
  25237. '\u3243': '\u0028\u81F3\u0029',
  25238. '\u32C0': '\u0031\u6708',
  25239. '\u32C1': '\u0032\u6708',
  25240. '\u32C2': '\u0033\u6708',
  25241. '\u32C3': '\u0034\u6708',
  25242. '\u32C4': '\u0035\u6708',
  25243. '\u32C5': '\u0036\u6708',
  25244. '\u32C6': '\u0037\u6708',
  25245. '\u32C7': '\u0038\u6708',
  25246. '\u32C8': '\u0039\u6708',
  25247. '\u32C9': '\u0031\u0030\u6708',
  25248. '\u32CA': '\u0031\u0031\u6708',
  25249. '\u32CB': '\u0031\u0032\u6708',
  25250. '\u3358': '\u0030\u70B9',
  25251. '\u3359': '\u0031\u70B9',
  25252. '\u335A': '\u0032\u70B9',
  25253. '\u335B': '\u0033\u70B9',
  25254. '\u335C': '\u0034\u70B9',
  25255. '\u335D': '\u0035\u70B9',
  25256. '\u335E': '\u0036\u70B9',
  25257. '\u335F': '\u0037\u70B9',
  25258. '\u3360': '\u0038\u70B9',
  25259. '\u3361': '\u0039\u70B9',
  25260. '\u3362': '\u0031\u0030\u70B9',
  25261. '\u3363': '\u0031\u0031\u70B9',
  25262. '\u3364': '\u0031\u0032\u70B9',
  25263. '\u3365': '\u0031\u0033\u70B9',
  25264. '\u3366': '\u0031\u0034\u70B9',
  25265. '\u3367': '\u0031\u0035\u70B9',
  25266. '\u3368': '\u0031\u0036\u70B9',
  25267. '\u3369': '\u0031\u0037\u70B9',
  25268. '\u336A': '\u0031\u0038\u70B9',
  25269. '\u336B': '\u0031\u0039\u70B9',
  25270. '\u336C': '\u0032\u0030\u70B9',
  25271. '\u336D': '\u0032\u0031\u70B9',
  25272. '\u336E': '\u0032\u0032\u70B9',
  25273. '\u336F': '\u0032\u0033\u70B9',
  25274. '\u3370': '\u0032\u0034\u70B9',
  25275. '\u33E0': '\u0031\u65E5',
  25276. '\u33E1': '\u0032\u65E5',
  25277. '\u33E2': '\u0033\u65E5',
  25278. '\u33E3': '\u0034\u65E5',
  25279. '\u33E4': '\u0035\u65E5',
  25280. '\u33E5': '\u0036\u65E5',
  25281. '\u33E6': '\u0037\u65E5',
  25282. '\u33E7': '\u0038\u65E5',
  25283. '\u33E8': '\u0039\u65E5',
  25284. '\u33E9': '\u0031\u0030\u65E5',
  25285. '\u33EA': '\u0031\u0031\u65E5',
  25286. '\u33EB': '\u0031\u0032\u65E5',
  25287. '\u33EC': '\u0031\u0033\u65E5',
  25288. '\u33ED': '\u0031\u0034\u65E5',
  25289. '\u33EE': '\u0031\u0035\u65E5',
  25290. '\u33EF': '\u0031\u0036\u65E5',
  25291. '\u33F0': '\u0031\u0037\u65E5',
  25292. '\u33F1': '\u0031\u0038\u65E5',
  25293. '\u33F2': '\u0031\u0039\u65E5',
  25294. '\u33F3': '\u0032\u0030\u65E5',
  25295. '\u33F4': '\u0032\u0031\u65E5',
  25296. '\u33F5': '\u0032\u0032\u65E5',
  25297. '\u33F6': '\u0032\u0033\u65E5',
  25298. '\u33F7': '\u0032\u0034\u65E5',
  25299. '\u33F8': '\u0032\u0035\u65E5',
  25300. '\u33F9': '\u0032\u0036\u65E5',
  25301. '\u33FA': '\u0032\u0037\u65E5',
  25302. '\u33FB': '\u0032\u0038\u65E5',
  25303. '\u33FC': '\u0032\u0039\u65E5',
  25304. '\u33FD': '\u0033\u0030\u65E5',
  25305. '\u33FE': '\u0033\u0031\u65E5',
  25306. '\uFB00': '\u0066\u0066',
  25307. '\uFB01': '\u0066\u0069',
  25308. '\uFB02': '\u0066\u006C',
  25309. '\uFB03': '\u0066\u0066\u0069',
  25310. '\uFB04': '\u0066\u0066\u006C',
  25311. '\uFB05': '\u017F\u0074',
  25312. '\uFB06': '\u0073\u0074',
  25313. '\uFB13': '\u0574\u0576',
  25314. '\uFB14': '\u0574\u0565',
  25315. '\uFB15': '\u0574\u056B',
  25316. '\uFB16': '\u057E\u0576',
  25317. '\uFB17': '\u0574\u056D',
  25318. '\uFB4F': '\u05D0\u05DC',
  25319. '\uFB50': '\u0671',
  25320. '\uFB51': '\u0671',
  25321. '\uFB52': '\u067B',
  25322. '\uFB53': '\u067B',
  25323. '\uFB54': '\u067B',
  25324. '\uFB55': '\u067B',
  25325. '\uFB56': '\u067E',
  25326. '\uFB57': '\u067E',
  25327. '\uFB58': '\u067E',
  25328. '\uFB59': '\u067E',
  25329. '\uFB5A': '\u0680',
  25330. '\uFB5B': '\u0680',
  25331. '\uFB5C': '\u0680',
  25332. '\uFB5D': '\u0680',
  25333. '\uFB5E': '\u067A',
  25334. '\uFB5F': '\u067A',
  25335. '\uFB60': '\u067A',
  25336. '\uFB61': '\u067A',
  25337. '\uFB62': '\u067F',
  25338. '\uFB63': '\u067F',
  25339. '\uFB64': '\u067F',
  25340. '\uFB65': '\u067F',
  25341. '\uFB66': '\u0679',
  25342. '\uFB67': '\u0679',
  25343. '\uFB68': '\u0679',
  25344. '\uFB69': '\u0679',
  25345. '\uFB6A': '\u06A4',
  25346. '\uFB6B': '\u06A4',
  25347. '\uFB6C': '\u06A4',
  25348. '\uFB6D': '\u06A4',
  25349. '\uFB6E': '\u06A6',
  25350. '\uFB6F': '\u06A6',
  25351. '\uFB70': '\u06A6',
  25352. '\uFB71': '\u06A6',
  25353. '\uFB72': '\u0684',
  25354. '\uFB73': '\u0684',
  25355. '\uFB74': '\u0684',
  25356. '\uFB75': '\u0684',
  25357. '\uFB76': '\u0683',
  25358. '\uFB77': '\u0683',
  25359. '\uFB78': '\u0683',
  25360. '\uFB79': '\u0683',
  25361. '\uFB7A': '\u0686',
  25362. '\uFB7B': '\u0686',
  25363. '\uFB7C': '\u0686',
  25364. '\uFB7D': '\u0686',
  25365. '\uFB7E': '\u0687',
  25366. '\uFB7F': '\u0687',
  25367. '\uFB80': '\u0687',
  25368. '\uFB81': '\u0687',
  25369. '\uFB82': '\u068D',
  25370. '\uFB83': '\u068D',
  25371. '\uFB84': '\u068C',
  25372. '\uFB85': '\u068C',
  25373. '\uFB86': '\u068E',
  25374. '\uFB87': '\u068E',
  25375. '\uFB88': '\u0688',
  25376. '\uFB89': '\u0688',
  25377. '\uFB8A': '\u0698',
  25378. '\uFB8B': '\u0698',
  25379. '\uFB8C': '\u0691',
  25380. '\uFB8D': '\u0691',
  25381. '\uFB8E': '\u06A9',
  25382. '\uFB8F': '\u06A9',
  25383. '\uFB90': '\u06A9',
  25384. '\uFB91': '\u06A9',
  25385. '\uFB92': '\u06AF',
  25386. '\uFB93': '\u06AF',
  25387. '\uFB94': '\u06AF',
  25388. '\uFB95': '\u06AF',
  25389. '\uFB96': '\u06B3',
  25390. '\uFB97': '\u06B3',
  25391. '\uFB98': '\u06B3',
  25392. '\uFB99': '\u06B3',
  25393. '\uFB9A': '\u06B1',
  25394. '\uFB9B': '\u06B1',
  25395. '\uFB9C': '\u06B1',
  25396. '\uFB9D': '\u06B1',
  25397. '\uFB9E': '\u06BA',
  25398. '\uFB9F': '\u06BA',
  25399. '\uFBA0': '\u06BB',
  25400. '\uFBA1': '\u06BB',
  25401. '\uFBA2': '\u06BB',
  25402. '\uFBA3': '\u06BB',
  25403. '\uFBA4': '\u06C0',
  25404. '\uFBA5': '\u06C0',
  25405. '\uFBA6': '\u06C1',
  25406. '\uFBA7': '\u06C1',
  25407. '\uFBA8': '\u06C1',
  25408. '\uFBA9': '\u06C1',
  25409. '\uFBAA': '\u06BE',
  25410. '\uFBAB': '\u06BE',
  25411. '\uFBAC': '\u06BE',
  25412. '\uFBAD': '\u06BE',
  25413. '\uFBAE': '\u06D2',
  25414. '\uFBAF': '\u06D2',
  25415. '\uFBB0': '\u06D3',
  25416. '\uFBB1': '\u06D3',
  25417. '\uFBD3': '\u06AD',
  25418. '\uFBD4': '\u06AD',
  25419. '\uFBD5': '\u06AD',
  25420. '\uFBD6': '\u06AD',
  25421. '\uFBD7': '\u06C7',
  25422. '\uFBD8': '\u06C7',
  25423. '\uFBD9': '\u06C6',
  25424. '\uFBDA': '\u06C6',
  25425. '\uFBDB': '\u06C8',
  25426. '\uFBDC': '\u06C8',
  25427. '\uFBDD': '\u0677',
  25428. '\uFBDE': '\u06CB',
  25429. '\uFBDF': '\u06CB',
  25430. '\uFBE0': '\u06C5',
  25431. '\uFBE1': '\u06C5',
  25432. '\uFBE2': '\u06C9',
  25433. '\uFBE3': '\u06C9',
  25434. '\uFBE4': '\u06D0',
  25435. '\uFBE5': '\u06D0',
  25436. '\uFBE6': '\u06D0',
  25437. '\uFBE7': '\u06D0',
  25438. '\uFBE8': '\u0649',
  25439. '\uFBE9': '\u0649',
  25440. '\uFBEA': '\u0626\u0627',
  25441. '\uFBEB': '\u0626\u0627',
  25442. '\uFBEC': '\u0626\u06D5',
  25443. '\uFBED': '\u0626\u06D5',
  25444. '\uFBEE': '\u0626\u0648',
  25445. '\uFBEF': '\u0626\u0648',
  25446. '\uFBF0': '\u0626\u06C7',
  25447. '\uFBF1': '\u0626\u06C7',
  25448. '\uFBF2': '\u0626\u06C6',
  25449. '\uFBF3': '\u0626\u06C6',
  25450. '\uFBF4': '\u0626\u06C8',
  25451. '\uFBF5': '\u0626\u06C8',
  25452. '\uFBF6': '\u0626\u06D0',
  25453. '\uFBF7': '\u0626\u06D0',
  25454. '\uFBF8': '\u0626\u06D0',
  25455. '\uFBF9': '\u0626\u0649',
  25456. '\uFBFA': '\u0626\u0649',
  25457. '\uFBFB': '\u0626\u0649',
  25458. '\uFBFC': '\u06CC',
  25459. '\uFBFD': '\u06CC',
  25460. '\uFBFE': '\u06CC',
  25461. '\uFBFF': '\u06CC',
  25462. '\uFC00': '\u0626\u062C',
  25463. '\uFC01': '\u0626\u062D',
  25464. '\uFC02': '\u0626\u0645',
  25465. '\uFC03': '\u0626\u0649',
  25466. '\uFC04': '\u0626\u064A',
  25467. '\uFC05': '\u0628\u062C',
  25468. '\uFC06': '\u0628\u062D',
  25469. '\uFC07': '\u0628\u062E',
  25470. '\uFC08': '\u0628\u0645',
  25471. '\uFC09': '\u0628\u0649',
  25472. '\uFC0A': '\u0628\u064A',
  25473. '\uFC0B': '\u062A\u062C',
  25474. '\uFC0C': '\u062A\u062D',
  25475. '\uFC0D': '\u062A\u062E',
  25476. '\uFC0E': '\u062A\u0645',
  25477. '\uFC0F': '\u062A\u0649',
  25478. '\uFC10': '\u062A\u064A',
  25479. '\uFC11': '\u062B\u062C',
  25480. '\uFC12': '\u062B\u0645',
  25481. '\uFC13': '\u062B\u0649',
  25482. '\uFC14': '\u062B\u064A',
  25483. '\uFC15': '\u062C\u062D',
  25484. '\uFC16': '\u062C\u0645',
  25485. '\uFC17': '\u062D\u062C',
  25486. '\uFC18': '\u062D\u0645',
  25487. '\uFC19': '\u062E\u062C',
  25488. '\uFC1A': '\u062E\u062D',
  25489. '\uFC1B': '\u062E\u0645',
  25490. '\uFC1C': '\u0633\u062C',
  25491. '\uFC1D': '\u0633\u062D',
  25492. '\uFC1E': '\u0633\u062E',
  25493. '\uFC1F': '\u0633\u0645',
  25494. '\uFC20': '\u0635\u062D',
  25495. '\uFC21': '\u0635\u0645',
  25496. '\uFC22': '\u0636\u062C',
  25497. '\uFC23': '\u0636\u062D',
  25498. '\uFC24': '\u0636\u062E',
  25499. '\uFC25': '\u0636\u0645',
  25500. '\uFC26': '\u0637\u062D',
  25501. '\uFC27': '\u0637\u0645',
  25502. '\uFC28': '\u0638\u0645',
  25503. '\uFC29': '\u0639\u062C',
  25504. '\uFC2A': '\u0639\u0645',
  25505. '\uFC2B': '\u063A\u062C',
  25506. '\uFC2C': '\u063A\u0645',
  25507. '\uFC2D': '\u0641\u062C',
  25508. '\uFC2E': '\u0641\u062D',
  25509. '\uFC2F': '\u0641\u062E',
  25510. '\uFC30': '\u0641\u0645',
  25511. '\uFC31': '\u0641\u0649',
  25512. '\uFC32': '\u0641\u064A',
  25513. '\uFC33': '\u0642\u062D',
  25514. '\uFC34': '\u0642\u0645',
  25515. '\uFC35': '\u0642\u0649',
  25516. '\uFC36': '\u0642\u064A',
  25517. '\uFC37': '\u0643\u0627',
  25518. '\uFC38': '\u0643\u062C',
  25519. '\uFC39': '\u0643\u062D',
  25520. '\uFC3A': '\u0643\u062E',
  25521. '\uFC3B': '\u0643\u0644',
  25522. '\uFC3C': '\u0643\u0645',
  25523. '\uFC3D': '\u0643\u0649',
  25524. '\uFC3E': '\u0643\u064A',
  25525. '\uFC3F': '\u0644\u062C',
  25526. '\uFC40': '\u0644\u062D',
  25527. '\uFC41': '\u0644\u062E',
  25528. '\uFC42': '\u0644\u0645',
  25529. '\uFC43': '\u0644\u0649',
  25530. '\uFC44': '\u0644\u064A',
  25531. '\uFC45': '\u0645\u062C',
  25532. '\uFC46': '\u0645\u062D',
  25533. '\uFC47': '\u0645\u062E',
  25534. '\uFC48': '\u0645\u0645',
  25535. '\uFC49': '\u0645\u0649',
  25536. '\uFC4A': '\u0645\u064A',
  25537. '\uFC4B': '\u0646\u062C',
  25538. '\uFC4C': '\u0646\u062D',
  25539. '\uFC4D': '\u0646\u062E',
  25540. '\uFC4E': '\u0646\u0645',
  25541. '\uFC4F': '\u0646\u0649',
  25542. '\uFC50': '\u0646\u064A',
  25543. '\uFC51': '\u0647\u062C',
  25544. '\uFC52': '\u0647\u0645',
  25545. '\uFC53': '\u0647\u0649',
  25546. '\uFC54': '\u0647\u064A',
  25547. '\uFC55': '\u064A\u062C',
  25548. '\uFC56': '\u064A\u062D',
  25549. '\uFC57': '\u064A\u062E',
  25550. '\uFC58': '\u064A\u0645',
  25551. '\uFC59': '\u064A\u0649',
  25552. '\uFC5A': '\u064A\u064A',
  25553. '\uFC5B': '\u0630\u0670',
  25554. '\uFC5C': '\u0631\u0670',
  25555. '\uFC5D': '\u0649\u0670',
  25556. '\uFC5E': '\u0020\u064C\u0651',
  25557. '\uFC5F': '\u0020\u064D\u0651',
  25558. '\uFC60': '\u0020\u064E\u0651',
  25559. '\uFC61': '\u0020\u064F\u0651',
  25560. '\uFC62': '\u0020\u0650\u0651',
  25561. '\uFC63': '\u0020\u0651\u0670',
  25562. '\uFC64': '\u0626\u0631',
  25563. '\uFC65': '\u0626\u0632',
  25564. '\uFC66': '\u0626\u0645',
  25565. '\uFC67': '\u0626\u0646',
  25566. '\uFC68': '\u0626\u0649',
  25567. '\uFC69': '\u0626\u064A',
  25568. '\uFC6A': '\u0628\u0631',
  25569. '\uFC6B': '\u0628\u0632',
  25570. '\uFC6C': '\u0628\u0645',
  25571. '\uFC6D': '\u0628\u0646',
  25572. '\uFC6E': '\u0628\u0649',
  25573. '\uFC6F': '\u0628\u064A',
  25574. '\uFC70': '\u062A\u0631',
  25575. '\uFC71': '\u062A\u0632',
  25576. '\uFC72': '\u062A\u0645',
  25577. '\uFC73': '\u062A\u0646',
  25578. '\uFC74': '\u062A\u0649',
  25579. '\uFC75': '\u062A\u064A',
  25580. '\uFC76': '\u062B\u0631',
  25581. '\uFC77': '\u062B\u0632',
  25582. '\uFC78': '\u062B\u0645',
  25583. '\uFC79': '\u062B\u0646',
  25584. '\uFC7A': '\u062B\u0649',
  25585. '\uFC7B': '\u062B\u064A',
  25586. '\uFC7C': '\u0641\u0649',
  25587. '\uFC7D': '\u0641\u064A',
  25588. '\uFC7E': '\u0642\u0649',
  25589. '\uFC7F': '\u0642\u064A',
  25590. '\uFC80': '\u0643\u0627',
  25591. '\uFC81': '\u0643\u0644',
  25592. '\uFC82': '\u0643\u0645',
  25593. '\uFC83': '\u0643\u0649',
  25594. '\uFC84': '\u0643\u064A',
  25595. '\uFC85': '\u0644\u0645',
  25596. '\uFC86': '\u0644\u0649',
  25597. '\uFC87': '\u0644\u064A',
  25598. '\uFC88': '\u0645\u0627',
  25599. '\uFC89': '\u0645\u0645',
  25600. '\uFC8A': '\u0646\u0631',
  25601. '\uFC8B': '\u0646\u0632',
  25602. '\uFC8C': '\u0646\u0645',
  25603. '\uFC8D': '\u0646\u0646',
  25604. '\uFC8E': '\u0646\u0649',
  25605. '\uFC8F': '\u0646\u064A',
  25606. '\uFC90': '\u0649\u0670',
  25607. '\uFC91': '\u064A\u0631',
  25608. '\uFC92': '\u064A\u0632',
  25609. '\uFC93': '\u064A\u0645',
  25610. '\uFC94': '\u064A\u0646',
  25611. '\uFC95': '\u064A\u0649',
  25612. '\uFC96': '\u064A\u064A',
  25613. '\uFC97': '\u0626\u062C',
  25614. '\uFC98': '\u0626\u062D',
  25615. '\uFC99': '\u0626\u062E',
  25616. '\uFC9A': '\u0626\u0645',
  25617. '\uFC9B': '\u0626\u0647',
  25618. '\uFC9C': '\u0628\u062C',
  25619. '\uFC9D': '\u0628\u062D',
  25620. '\uFC9E': '\u0628\u062E',
  25621. '\uFC9F': '\u0628\u0645',
  25622. '\uFCA0': '\u0628\u0647',
  25623. '\uFCA1': '\u062A\u062C',
  25624. '\uFCA2': '\u062A\u062D',
  25625. '\uFCA3': '\u062A\u062E',
  25626. '\uFCA4': '\u062A\u0645',
  25627. '\uFCA5': '\u062A\u0647',
  25628. '\uFCA6': '\u062B\u0645',
  25629. '\uFCA7': '\u062C\u062D',
  25630. '\uFCA8': '\u062C\u0645',
  25631. '\uFCA9': '\u062D\u062C',
  25632. '\uFCAA': '\u062D\u0645',
  25633. '\uFCAB': '\u062E\u062C',
  25634. '\uFCAC': '\u062E\u0645',
  25635. '\uFCAD': '\u0633\u062C',
  25636. '\uFCAE': '\u0633\u062D',
  25637. '\uFCAF': '\u0633\u062E',
  25638. '\uFCB0': '\u0633\u0645',
  25639. '\uFCB1': '\u0635\u062D',
  25640. '\uFCB2': '\u0635\u062E',
  25641. '\uFCB3': '\u0635\u0645',
  25642. '\uFCB4': '\u0636\u062C',
  25643. '\uFCB5': '\u0636\u062D',
  25644. '\uFCB6': '\u0636\u062E',
  25645. '\uFCB7': '\u0636\u0645',
  25646. '\uFCB8': '\u0637\u062D',
  25647. '\uFCB9': '\u0638\u0645',
  25648. '\uFCBA': '\u0639\u062C',
  25649. '\uFCBB': '\u0639\u0645',
  25650. '\uFCBC': '\u063A\u062C',
  25651. '\uFCBD': '\u063A\u0645',
  25652. '\uFCBE': '\u0641\u062C',
  25653. '\uFCBF': '\u0641\u062D',
  25654. '\uFCC0': '\u0641\u062E',
  25655. '\uFCC1': '\u0641\u0645',
  25656. '\uFCC2': '\u0642\u062D',
  25657. '\uFCC3': '\u0642\u0645',
  25658. '\uFCC4': '\u0643\u062C',
  25659. '\uFCC5': '\u0643\u062D',
  25660. '\uFCC6': '\u0643\u062E',
  25661. '\uFCC7': '\u0643\u0644',
  25662. '\uFCC8': '\u0643\u0645',
  25663. '\uFCC9': '\u0644\u062C',
  25664. '\uFCCA': '\u0644\u062D',
  25665. '\uFCCB': '\u0644\u062E',
  25666. '\uFCCC': '\u0644\u0645',
  25667. '\uFCCD': '\u0644\u0647',
  25668. '\uFCCE': '\u0645\u062C',
  25669. '\uFCCF': '\u0645\u062D',
  25670. '\uFCD0': '\u0645\u062E',
  25671. '\uFCD1': '\u0645\u0645',
  25672. '\uFCD2': '\u0646\u062C',
  25673. '\uFCD3': '\u0646\u062D',
  25674. '\uFCD4': '\u0646\u062E',
  25675. '\uFCD5': '\u0646\u0645',
  25676. '\uFCD6': '\u0646\u0647',
  25677. '\uFCD7': '\u0647\u062C',
  25678. '\uFCD8': '\u0647\u0645',
  25679. '\uFCD9': '\u0647\u0670',
  25680. '\uFCDA': '\u064A\u062C',
  25681. '\uFCDB': '\u064A\u062D',
  25682. '\uFCDC': '\u064A\u062E',
  25683. '\uFCDD': '\u064A\u0645',
  25684. '\uFCDE': '\u064A\u0647',
  25685. '\uFCDF': '\u0626\u0645',
  25686. '\uFCE0': '\u0626\u0647',
  25687. '\uFCE1': '\u0628\u0645',
  25688. '\uFCE2': '\u0628\u0647',
  25689. '\uFCE3': '\u062A\u0645',
  25690. '\uFCE4': '\u062A\u0647',
  25691. '\uFCE5': '\u062B\u0645',
  25692. '\uFCE6': '\u062B\u0647',
  25693. '\uFCE7': '\u0633\u0645',
  25694. '\uFCE8': '\u0633\u0647',
  25695. '\uFCE9': '\u0634\u0645',
  25696. '\uFCEA': '\u0634\u0647',
  25697. '\uFCEB': '\u0643\u0644',
  25698. '\uFCEC': '\u0643\u0645',
  25699. '\uFCED': '\u0644\u0645',
  25700. '\uFCEE': '\u0646\u0645',
  25701. '\uFCEF': '\u0646\u0647',
  25702. '\uFCF0': '\u064A\u0645',
  25703. '\uFCF1': '\u064A\u0647',
  25704. '\uFCF2': '\u0640\u064E\u0651',
  25705. '\uFCF3': '\u0640\u064F\u0651',
  25706. '\uFCF4': '\u0640\u0650\u0651',
  25707. '\uFCF5': '\u0637\u0649',
  25708. '\uFCF6': '\u0637\u064A',
  25709. '\uFCF7': '\u0639\u0649',
  25710. '\uFCF8': '\u0639\u064A',
  25711. '\uFCF9': '\u063A\u0649',
  25712. '\uFCFA': '\u063A\u064A',
  25713. '\uFCFB': '\u0633\u0649',
  25714. '\uFCFC': '\u0633\u064A',
  25715. '\uFCFD': '\u0634\u0649',
  25716. '\uFCFE': '\u0634\u064A',
  25717. '\uFCFF': '\u062D\u0649',
  25718. '\uFD00': '\u062D\u064A',
  25719. '\uFD01': '\u062C\u0649',
  25720. '\uFD02': '\u062C\u064A',
  25721. '\uFD03': '\u062E\u0649',
  25722. '\uFD04': '\u062E\u064A',
  25723. '\uFD05': '\u0635\u0649',
  25724. '\uFD06': '\u0635\u064A',
  25725. '\uFD07': '\u0636\u0649',
  25726. '\uFD08': '\u0636\u064A',
  25727. '\uFD09': '\u0634\u062C',
  25728. '\uFD0A': '\u0634\u062D',
  25729. '\uFD0B': '\u0634\u062E',
  25730. '\uFD0C': '\u0634\u0645',
  25731. '\uFD0D': '\u0634\u0631',
  25732. '\uFD0E': '\u0633\u0631',
  25733. '\uFD0F': '\u0635\u0631',
  25734. '\uFD10': '\u0636\u0631',
  25735. '\uFD11': '\u0637\u0649',
  25736. '\uFD12': '\u0637\u064A',
  25737. '\uFD13': '\u0639\u0649',
  25738. '\uFD14': '\u0639\u064A',
  25739. '\uFD15': '\u063A\u0649',
  25740. '\uFD16': '\u063A\u064A',
  25741. '\uFD17': '\u0633\u0649',
  25742. '\uFD18': '\u0633\u064A',
  25743. '\uFD19': '\u0634\u0649',
  25744. '\uFD1A': '\u0634\u064A',
  25745. '\uFD1B': '\u062D\u0649',
  25746. '\uFD1C': '\u062D\u064A',
  25747. '\uFD1D': '\u062C\u0649',
  25748. '\uFD1E': '\u062C\u064A',
  25749. '\uFD1F': '\u062E\u0649',
  25750. '\uFD20': '\u062E\u064A',
  25751. '\uFD21': '\u0635\u0649',
  25752. '\uFD22': '\u0635\u064A',
  25753. '\uFD23': '\u0636\u0649',
  25754. '\uFD24': '\u0636\u064A',
  25755. '\uFD25': '\u0634\u062C',
  25756. '\uFD26': '\u0634\u062D',
  25757. '\uFD27': '\u0634\u062E',
  25758. '\uFD28': '\u0634\u0645',
  25759. '\uFD29': '\u0634\u0631',
  25760. '\uFD2A': '\u0633\u0631',
  25761. '\uFD2B': '\u0635\u0631',
  25762. '\uFD2C': '\u0636\u0631',
  25763. '\uFD2D': '\u0634\u062C',
  25764. '\uFD2E': '\u0634\u062D',
  25765. '\uFD2F': '\u0634\u062E',
  25766. '\uFD30': '\u0634\u0645',
  25767. '\uFD31': '\u0633\u0647',
  25768. '\uFD32': '\u0634\u0647',
  25769. '\uFD33': '\u0637\u0645',
  25770. '\uFD34': '\u0633\u062C',
  25771. '\uFD35': '\u0633\u062D',
  25772. '\uFD36': '\u0633\u062E',
  25773. '\uFD37': '\u0634\u062C',
  25774. '\uFD38': '\u0634\u062D',
  25775. '\uFD39': '\u0634\u062E',
  25776. '\uFD3A': '\u0637\u0645',
  25777. '\uFD3B': '\u0638\u0645',
  25778. '\uFD3C': '\u0627\u064B',
  25779. '\uFD3D': '\u0627\u064B',
  25780. '\uFD50': '\u062A\u062C\u0645',
  25781. '\uFD51': '\u062A\u062D\u062C',
  25782. '\uFD52': '\u062A\u062D\u062C',
  25783. '\uFD53': '\u062A\u062D\u0645',
  25784. '\uFD54': '\u062A\u062E\u0645',
  25785. '\uFD55': '\u062A\u0645\u062C',
  25786. '\uFD56': '\u062A\u0645\u062D',
  25787. '\uFD57': '\u062A\u0645\u062E',
  25788. '\uFD58': '\u062C\u0645\u062D',
  25789. '\uFD59': '\u062C\u0645\u062D',
  25790. '\uFD5A': '\u062D\u0645\u064A',
  25791. '\uFD5B': '\u062D\u0645\u0649',
  25792. '\uFD5C': '\u0633\u062D\u062C',
  25793. '\uFD5D': '\u0633\u062C\u062D',
  25794. '\uFD5E': '\u0633\u062C\u0649',
  25795. '\uFD5F': '\u0633\u0645\u062D',
  25796. '\uFD60': '\u0633\u0645\u062D',
  25797. '\uFD61': '\u0633\u0645\u062C',
  25798. '\uFD62': '\u0633\u0645\u0645',
  25799. '\uFD63': '\u0633\u0645\u0645',
  25800. '\uFD64': '\u0635\u062D\u062D',
  25801. '\uFD65': '\u0635\u062D\u062D',
  25802. '\uFD66': '\u0635\u0645\u0645',
  25803. '\uFD67': '\u0634\u062D\u0645',
  25804. '\uFD68': '\u0634\u062D\u0645',
  25805. '\uFD69': '\u0634\u062C\u064A',
  25806. '\uFD6A': '\u0634\u0645\u062E',
  25807. '\uFD6B': '\u0634\u0645\u062E',
  25808. '\uFD6C': '\u0634\u0645\u0645',
  25809. '\uFD6D': '\u0634\u0645\u0645',
  25810. '\uFD6E': '\u0636\u062D\u0649',
  25811. '\uFD6F': '\u0636\u062E\u0645',
  25812. '\uFD70': '\u0636\u062E\u0645',
  25813. '\uFD71': '\u0637\u0645\u062D',
  25814. '\uFD72': '\u0637\u0645\u062D',
  25815. '\uFD73': '\u0637\u0645\u0645',
  25816. '\uFD74': '\u0637\u0645\u064A',
  25817. '\uFD75': '\u0639\u062C\u0645',
  25818. '\uFD76': '\u0639\u0645\u0645',
  25819. '\uFD77': '\u0639\u0645\u0645',
  25820. '\uFD78': '\u0639\u0645\u0649',
  25821. '\uFD79': '\u063A\u0645\u0645',
  25822. '\uFD7A': '\u063A\u0645\u064A',
  25823. '\uFD7B': '\u063A\u0645\u0649',
  25824. '\uFD7C': '\u0641\u062E\u0645',
  25825. '\uFD7D': '\u0641\u062E\u0645',
  25826. '\uFD7E': '\u0642\u0645\u062D',
  25827. '\uFD7F': '\u0642\u0645\u0645',
  25828. '\uFD80': '\u0644\u062D\u0645',
  25829. '\uFD81': '\u0644\u062D\u064A',
  25830. '\uFD82': '\u0644\u062D\u0649',
  25831. '\uFD83': '\u0644\u062C\u062C',
  25832. '\uFD84': '\u0644\u062C\u062C',
  25833. '\uFD85': '\u0644\u062E\u0645',
  25834. '\uFD86': '\u0644\u062E\u0645',
  25835. '\uFD87': '\u0644\u0645\u062D',
  25836. '\uFD88': '\u0644\u0645\u062D',
  25837. '\uFD89': '\u0645\u062D\u062C',
  25838. '\uFD8A': '\u0645\u062D\u0645',
  25839. '\uFD8B': '\u0645\u062D\u064A',
  25840. '\uFD8C': '\u0645\u062C\u062D',
  25841. '\uFD8D': '\u0645\u062C\u0645',
  25842. '\uFD8E': '\u0645\u062E\u062C',
  25843. '\uFD8F': '\u0645\u062E\u0645',
  25844. '\uFD92': '\u0645\u062C\u062E',
  25845. '\uFD93': '\u0647\u0645\u062C',
  25846. '\uFD94': '\u0647\u0645\u0645',
  25847. '\uFD95': '\u0646\u062D\u0645',
  25848. '\uFD96': '\u0646\u062D\u0649',
  25849. '\uFD97': '\u0646\u062C\u0645',
  25850. '\uFD98': '\u0646\u062C\u0645',
  25851. '\uFD99': '\u0646\u062C\u0649',
  25852. '\uFD9A': '\u0646\u0645\u064A',
  25853. '\uFD9B': '\u0646\u0645\u0649',
  25854. '\uFD9C': '\u064A\u0645\u0645',
  25855. '\uFD9D': '\u064A\u0645\u0645',
  25856. '\uFD9E': '\u0628\u062E\u064A',
  25857. '\uFD9F': '\u062A\u062C\u064A',
  25858. '\uFDA0': '\u062A\u062C\u0649',
  25859. '\uFDA1': '\u062A\u062E\u064A',
  25860. '\uFDA2': '\u062A\u062E\u0649',
  25861. '\uFDA3': '\u062A\u0645\u064A',
  25862. '\uFDA4': '\u062A\u0645\u0649',
  25863. '\uFDA5': '\u062C\u0645\u064A',
  25864. '\uFDA6': '\u062C\u062D\u0649',
  25865. '\uFDA7': '\u062C\u0645\u0649',
  25866. '\uFDA8': '\u0633\u062E\u0649',
  25867. '\uFDA9': '\u0635\u062D\u064A',
  25868. '\uFDAA': '\u0634\u062D\u064A',
  25869. '\uFDAB': '\u0636\u062D\u064A',
  25870. '\uFDAC': '\u0644\u062C\u064A',
  25871. '\uFDAD': '\u0644\u0645\u064A',
  25872. '\uFDAE': '\u064A\u062D\u064A',
  25873. '\uFDAF': '\u064A\u062C\u064A',
  25874. '\uFDB0': '\u064A\u0645\u064A',
  25875. '\uFDB1': '\u0645\u0645\u064A',
  25876. '\uFDB2': '\u0642\u0645\u064A',
  25877. '\uFDB3': '\u0646\u062D\u064A',
  25878. '\uFDB4': '\u0642\u0645\u062D',
  25879. '\uFDB5': '\u0644\u062D\u0645',
  25880. '\uFDB6': '\u0639\u0645\u064A',
  25881. '\uFDB7': '\u0643\u0645\u064A',
  25882. '\uFDB8': '\u0646\u062C\u062D',
  25883. '\uFDB9': '\u0645\u062E\u064A',
  25884. '\uFDBA': '\u0644\u062C\u0645',
  25885. '\uFDBB': '\u0643\u0645\u0645',
  25886. '\uFDBC': '\u0644\u062C\u0645',
  25887. '\uFDBD': '\u0646\u062C\u062D',
  25888. '\uFDBE': '\u062C\u062D\u064A',
  25889. '\uFDBF': '\u062D\u062C\u064A',
  25890. '\uFDC0': '\u0645\u062C\u064A',
  25891. '\uFDC1': '\u0641\u0645\u064A',
  25892. '\uFDC2': '\u0628\u062D\u064A',
  25893. '\uFDC3': '\u0643\u0645\u0645',
  25894. '\uFDC4': '\u0639\u062C\u0645',
  25895. '\uFDC5': '\u0635\u0645\u0645',
  25896. '\uFDC6': '\u0633\u062E\u064A',
  25897. '\uFDC7': '\u0646\u062C\u064A',
  25898. '\uFE49': '\u203E',
  25899. '\uFE4A': '\u203E',
  25900. '\uFE4B': '\u203E',
  25901. '\uFE4C': '\u203E',
  25902. '\uFE4D': '\u005F',
  25903. '\uFE4E': '\u005F',
  25904. '\uFE4F': '\u005F',
  25905. '\uFE80': '\u0621',
  25906. '\uFE81': '\u0622',
  25907. '\uFE82': '\u0622',
  25908. '\uFE83': '\u0623',
  25909. '\uFE84': '\u0623',
  25910. '\uFE85': '\u0624',
  25911. '\uFE86': '\u0624',
  25912. '\uFE87': '\u0625',
  25913. '\uFE88': '\u0625',
  25914. '\uFE89': '\u0626',
  25915. '\uFE8A': '\u0626',
  25916. '\uFE8B': '\u0626',
  25917. '\uFE8C': '\u0626',
  25918. '\uFE8D': '\u0627',
  25919. '\uFE8E': '\u0627',
  25920. '\uFE8F': '\u0628',
  25921. '\uFE90': '\u0628',
  25922. '\uFE91': '\u0628',
  25923. '\uFE92': '\u0628',
  25924. '\uFE93': '\u0629',
  25925. '\uFE94': '\u0629',
  25926. '\uFE95': '\u062A',
  25927. '\uFE96': '\u062A',
  25928. '\uFE97': '\u062A',
  25929. '\uFE98': '\u062A',
  25930. '\uFE99': '\u062B',
  25931. '\uFE9A': '\u062B',
  25932. '\uFE9B': '\u062B',
  25933. '\uFE9C': '\u062B',
  25934. '\uFE9D': '\u062C',
  25935. '\uFE9E': '\u062C',
  25936. '\uFE9F': '\u062C',
  25937. '\uFEA0': '\u062C',
  25938. '\uFEA1': '\u062D',
  25939. '\uFEA2': '\u062D',
  25940. '\uFEA3': '\u062D',
  25941. '\uFEA4': '\u062D',
  25942. '\uFEA5': '\u062E',
  25943. '\uFEA6': '\u062E',
  25944. '\uFEA7': '\u062E',
  25945. '\uFEA8': '\u062E',
  25946. '\uFEA9': '\u062F',
  25947. '\uFEAA': '\u062F',
  25948. '\uFEAB': '\u0630',
  25949. '\uFEAC': '\u0630',
  25950. '\uFEAD': '\u0631',
  25951. '\uFEAE': '\u0631',
  25952. '\uFEAF': '\u0632',
  25953. '\uFEB0': '\u0632',
  25954. '\uFEB1': '\u0633',
  25955. '\uFEB2': '\u0633',
  25956. '\uFEB3': '\u0633',
  25957. '\uFEB4': '\u0633',
  25958. '\uFEB5': '\u0634',
  25959. '\uFEB6': '\u0634',
  25960. '\uFEB7': '\u0634',
  25961. '\uFEB8': '\u0634',
  25962. '\uFEB9': '\u0635',
  25963. '\uFEBA': '\u0635',
  25964. '\uFEBB': '\u0635',
  25965. '\uFEBC': '\u0635',
  25966. '\uFEBD': '\u0636',
  25967. '\uFEBE': '\u0636',
  25968. '\uFEBF': '\u0636',
  25969. '\uFEC0': '\u0636',
  25970. '\uFEC1': '\u0637',
  25971. '\uFEC2': '\u0637',
  25972. '\uFEC3': '\u0637',
  25973. '\uFEC4': '\u0637',
  25974. '\uFEC5': '\u0638',
  25975. '\uFEC6': '\u0638',
  25976. '\uFEC7': '\u0638',
  25977. '\uFEC8': '\u0638',
  25978. '\uFEC9': '\u0639',
  25979. '\uFECA': '\u0639',
  25980. '\uFECB': '\u0639',
  25981. '\uFECC': '\u0639',
  25982. '\uFECD': '\u063A',
  25983. '\uFECE': '\u063A',
  25984. '\uFECF': '\u063A',
  25985. '\uFED0': '\u063A',
  25986. '\uFED1': '\u0641',
  25987. '\uFED2': '\u0641',
  25988. '\uFED3': '\u0641',
  25989. '\uFED4': '\u0641',
  25990. '\uFED5': '\u0642',
  25991. '\uFED6': '\u0642',
  25992. '\uFED7': '\u0642',
  25993. '\uFED8': '\u0642',
  25994. '\uFED9': '\u0643',
  25995. '\uFEDA': '\u0643',
  25996. '\uFEDB': '\u0643',
  25997. '\uFEDC': '\u0643',
  25998. '\uFEDD': '\u0644',
  25999. '\uFEDE': '\u0644',
  26000. '\uFEDF': '\u0644',
  26001. '\uFEE0': '\u0644',
  26002. '\uFEE1': '\u0645',
  26003. '\uFEE2': '\u0645',
  26004. '\uFEE3': '\u0645',
  26005. '\uFEE4': '\u0645',
  26006. '\uFEE5': '\u0646',
  26007. '\uFEE6': '\u0646',
  26008. '\uFEE7': '\u0646',
  26009. '\uFEE8': '\u0646',
  26010. '\uFEE9': '\u0647',
  26011. '\uFEEA': '\u0647',
  26012. '\uFEEB': '\u0647',
  26013. '\uFEEC': '\u0647',
  26014. '\uFEED': '\u0648',
  26015. '\uFEEE': '\u0648',
  26016. '\uFEEF': '\u0649',
  26017. '\uFEF0': '\u0649',
  26018. '\uFEF1': '\u064A',
  26019. '\uFEF2': '\u064A',
  26020. '\uFEF3': '\u064A',
  26021. '\uFEF4': '\u064A',
  26022. '\uFEF5': '\u0644\u0622',
  26023. '\uFEF6': '\u0644\u0622',
  26024. '\uFEF7': '\u0644\u0623',
  26025. '\uFEF8': '\u0644\u0623',
  26026. '\uFEF9': '\u0644\u0625',
  26027. '\uFEFA': '\u0644\u0625',
  26028. '\uFEFB': '\u0644\u0627',
  26029. '\uFEFC': '\u0644\u0627'
  26030. };
  26031. function reverseIfRtl(chars) {
  26032. var charsLength = chars.length;
  26033. //reverse an arabic ligature
  26034. if (charsLength <= 1 || !isRTLRangeFor(chars.charCodeAt(0))) {
  26035. return chars;
  26036. }
  26037. var s = '';
  26038. for (var ii = charsLength - 1; ii >= 0; ii--) {
  26039. s += chars[ii];
  26040. }
  26041. return s;
  26042. }
  26043. function adjustWidths(properties) {
  26044. if (!properties.fontMatrix) {
  26045. return;
  26046. }
  26047. if (properties.fontMatrix[0] === FONT_IDENTITY_MATRIX[0]) {
  26048. return;
  26049. }
  26050. // adjusting width to fontMatrix scale
  26051. var scale = 0.001 / properties.fontMatrix[0];
  26052. var glyphsWidths = properties.widths;
  26053. for (var glyph in glyphsWidths) {
  26054. glyphsWidths[glyph] *= scale;
  26055. }
  26056. properties.defaultWidth *= scale;
  26057. }
  26058. function getFontType(type, subtype) {
  26059. switch (type) {
  26060. case 'Type1':
  26061. return subtype === 'Type1C' ? FontType.TYPE1C : FontType.TYPE1;
  26062. case 'CIDFontType0':
  26063. return subtype === 'CIDFontType0C' ? FontType.CIDFONTTYPE0C :
  26064. FontType.CIDFONTTYPE0;
  26065. case 'OpenType':
  26066. return FontType.OPENTYPE;
  26067. case 'TrueType':
  26068. return FontType.TRUETYPE;
  26069. case 'CIDFontType2':
  26070. return FontType.CIDFONTTYPE2;
  26071. case 'MMType1':
  26072. return FontType.MMTYPE1;
  26073. case 'Type0':
  26074. return FontType.TYPE0;
  26075. default:
  26076. return FontType.UNKNOWN;
  26077. }
  26078. }
  26079. var Glyph = (function GlyphClosure() {
  26080. function Glyph(fontChar, unicode, accent, width, vmetric, operatorListId,
  26081. isSpace) {
  26082. this.fontChar = fontChar;
  26083. this.unicode = unicode;
  26084. this.accent = accent;
  26085. this.width = width;
  26086. this.vmetric = vmetric;
  26087. this.operatorListId = operatorListId;
  26088. this.isSpace = isSpace;
  26089. }
  26090. Glyph.prototype.matchesForCache = function(fontChar, unicode, accent, width,
  26091. vmetric, operatorListId, isSpace) {
  26092. return this.fontChar === fontChar &&
  26093. this.unicode === unicode &&
  26094. this.accent === accent &&
  26095. this.width === width &&
  26096. this.vmetric === vmetric &&
  26097. this.operatorListId === operatorListId &&
  26098. this.isSpace === isSpace;
  26099. };
  26100. return Glyph;
  26101. })();
  26102. var ToUnicodeMap = (function ToUnicodeMapClosure() {
  26103. function ToUnicodeMap(cmap) {
  26104. // The elements of this._map can be integers or strings, depending on how
  26105. // |cmap| was created.
  26106. this._map = cmap;
  26107. }
  26108. ToUnicodeMap.prototype = {
  26109. get length() {
  26110. return this._map.length;
  26111. },
  26112. forEach: function(callback) {
  26113. for (var charCode in this._map) {
  26114. callback(charCode, this._map[charCode].charCodeAt(0));
  26115. }
  26116. },
  26117. has: function(i) {
  26118. return this._map[i] !== undefined;
  26119. },
  26120. get: function(i) {
  26121. return this._map[i];
  26122. },
  26123. charCodeOf: function(v) {
  26124. return this._map.indexOf(v);
  26125. }
  26126. };
  26127. return ToUnicodeMap;
  26128. })();
  26129. var IdentityToUnicodeMap = (function IdentityToUnicodeMapClosure() {
  26130. function IdentityToUnicodeMap(firstChar, lastChar) {
  26131. this.firstChar = firstChar;
  26132. this.lastChar = lastChar;
  26133. }
  26134. IdentityToUnicodeMap.prototype = {
  26135. get length() {
  26136. return (this.lastChar + 1) - this.firstChar;
  26137. },
  26138. forEach: function (callback) {
  26139. for (var i = this.firstChar, ii = this.lastChar; i <= ii; i++) {
  26140. callback(i, i);
  26141. }
  26142. },
  26143. has: function (i) {
  26144. return this.firstChar <= i && i <= this.lastChar;
  26145. },
  26146. get: function (i) {
  26147. if (this.firstChar <= i && i <= this.lastChar) {
  26148. return String.fromCharCode(i);
  26149. }
  26150. return undefined;
  26151. },
  26152. charCodeOf: function (v) {
  26153. return (isInt(v) && v >= this.firstChar && v <= this.lastChar) ? v : -1;
  26154. }
  26155. };
  26156. return IdentityToUnicodeMap;
  26157. })();
  26158. var OpenTypeFileBuilder = (function OpenTypeFileBuilderClosure() {
  26159. function writeInt16(dest, offset, num) {
  26160. dest[offset] = (num >> 8) & 0xFF;
  26161. dest[offset + 1] = num & 0xFF;
  26162. }
  26163. function writeInt32(dest, offset, num) {
  26164. dest[offset] = (num >> 24) & 0xFF;
  26165. dest[offset + 1] = (num >> 16) & 0xFF;
  26166. dest[offset + 2] = (num >> 8) & 0xFF;
  26167. dest[offset + 3] = num & 0xFF;
  26168. }
  26169. function writeData(dest, offset, data) {
  26170. var i, ii;
  26171. if (data instanceof Uint8Array) {
  26172. dest.set(data, offset);
  26173. } else if (typeof data === 'string') {
  26174. for (i = 0, ii = data.length; i < ii; i++) {
  26175. dest[offset++] = data.charCodeAt(i) & 0xFF;
  26176. }
  26177. } else {
  26178. // treating everything else as array
  26179. for (i = 0, ii = data.length; i < ii; i++) {
  26180. dest[offset++] = data[i] & 0xFF;
  26181. }
  26182. }
  26183. }
  26184. function OpenTypeFileBuilder(sfnt) {
  26185. this.sfnt = sfnt;
  26186. this.tables = Object.create(null);
  26187. }
  26188. OpenTypeFileBuilder.getSearchParams =
  26189. function OpenTypeFileBuilder_getSearchParams(entriesCount, entrySize) {
  26190. var maxPower2 = 1, log2 = 0;
  26191. while ((maxPower2 ^ entriesCount) > maxPower2) {
  26192. maxPower2 <<= 1;
  26193. log2++;
  26194. }
  26195. var searchRange = maxPower2 * entrySize;
  26196. return {
  26197. range: searchRange,
  26198. entry: log2,
  26199. rangeShift: entrySize * entriesCount - searchRange
  26200. };
  26201. };
  26202. var OTF_HEADER_SIZE = 12;
  26203. var OTF_TABLE_ENTRY_SIZE = 16;
  26204. OpenTypeFileBuilder.prototype = {
  26205. toArray: function OpenTypeFileBuilder_toArray() {
  26206. var sfnt = this.sfnt;
  26207. // Tables needs to be written by ascendant alphabetic order
  26208. var tables = this.tables;
  26209. var tablesNames = Object.keys(tables);
  26210. tablesNames.sort();
  26211. var numTables = tablesNames.length;
  26212. var i, j, jj, table, tableName;
  26213. // layout the tables data
  26214. var offset = OTF_HEADER_SIZE + numTables * OTF_TABLE_ENTRY_SIZE;
  26215. var tableOffsets = [offset];
  26216. for (i = 0; i < numTables; i++) {
  26217. table = tables[tablesNames[i]];
  26218. var paddedLength = ((table.length + 3) & ~3) >>> 0;
  26219. offset += paddedLength;
  26220. tableOffsets.push(offset);
  26221. }
  26222. var file = new Uint8Array(offset);
  26223. // write the table data first (mostly for checksum)
  26224. for (i = 0; i < numTables; i++) {
  26225. table = tables[tablesNames[i]];
  26226. writeData(file, tableOffsets[i], table);
  26227. }
  26228. // sfnt version (4 bytes)
  26229. if (sfnt === 'true') {
  26230. // Windows hates the Mac TrueType sfnt version number
  26231. sfnt = string32(0x00010000);
  26232. }
  26233. file[0] = sfnt.charCodeAt(0) & 0xFF;
  26234. file[1] = sfnt.charCodeAt(1) & 0xFF;
  26235. file[2] = sfnt.charCodeAt(2) & 0xFF;
  26236. file[3] = sfnt.charCodeAt(3) & 0xFF;
  26237. // numTables (2 bytes)
  26238. writeInt16(file, 4, numTables);
  26239. var searchParams = OpenTypeFileBuilder.getSearchParams(numTables, 16);
  26240. // searchRange (2 bytes)
  26241. writeInt16(file, 6, searchParams.range);
  26242. // entrySelector (2 bytes)
  26243. writeInt16(file, 8, searchParams.entry);
  26244. // rangeShift (2 bytes)
  26245. writeInt16(file, 10, searchParams.rangeShift);
  26246. offset = OTF_HEADER_SIZE;
  26247. // writing table entries
  26248. for (i = 0; i < numTables; i++) {
  26249. tableName = tablesNames[i];
  26250. file[offset] = tableName.charCodeAt(0) & 0xFF;
  26251. file[offset + 1] = tableName.charCodeAt(1) & 0xFF;
  26252. file[offset + 2] = tableName.charCodeAt(2) & 0xFF;
  26253. file[offset + 3] = tableName.charCodeAt(3) & 0xFF;
  26254. // checksum
  26255. var checksum = 0;
  26256. for (j = tableOffsets[i], jj = tableOffsets[i + 1]; j < jj; j += 4) {
  26257. var quad = (file[j] << 24) + (file[j + 1] << 16) +
  26258. (file[j + 2] << 8) + file[j + 3];
  26259. checksum = (checksum + quad) | 0;
  26260. }
  26261. writeInt32(file, offset + 4, checksum);
  26262. // offset
  26263. writeInt32(file, offset + 8, tableOffsets[i]);
  26264. // length
  26265. writeInt32(file, offset + 12, tables[tableName].length);
  26266. offset += OTF_TABLE_ENTRY_SIZE;
  26267. }
  26268. return file;
  26269. },
  26270. addTable: function OpenTypeFileBuilder_addTable(tag, data) {
  26271. if (tag in this.tables) {
  26272. throw new Error('Table ' + tag + ' already exists');
  26273. }
  26274. this.tables[tag] = data;
  26275. }
  26276. };
  26277. return OpenTypeFileBuilder;
  26278. })();
  26279. // Problematic Unicode characters in the fonts that needs to be moved to avoid
  26280. // issues when they are painted on the canvas, e.g. complex-script shaping or
  26281. // control/whitespace characters. The ranges are listed in pairs: the first item
  26282. // is a code of the first problematic code, the second one is the next
  26283. // non-problematic code. The ranges must be in sorted order.
  26284. var ProblematicCharRanges = new Int32Array([
  26285. // Control characters.
  26286. 0x0000, 0x0020,
  26287. 0x007F, 0x00A1,
  26288. 0x00AD, 0x00AE,
  26289. // Chars that is used in complex-script shaping.
  26290. 0x0600, 0x0780,
  26291. 0x08A0, 0x10A0,
  26292. 0x1780, 0x1800,
  26293. // General punctuation chars.
  26294. 0x2000, 0x2010,
  26295. 0x2011, 0x2012,
  26296. 0x2028, 0x2030,
  26297. 0x205F, 0x2070,
  26298. 0x25CC, 0x25CD,
  26299. // Chars that is used in complex-script shaping.
  26300. 0xAA60, 0xAA80,
  26301. // Specials Unicode block.
  26302. 0xFFF0, 0x10000
  26303. ]);
  26304. /**
  26305. * 'Font' is the class the outside world should use, it encapsulate all the font
  26306. * decoding logics whatever type it is (assuming the font type is supported).
  26307. *
  26308. * For example to read a Type1 font and to attach it to the document:
  26309. * var type1Font = new Font("MyFontName", binaryFile, propertiesObject);
  26310. * type1Font.bind();
  26311. */
  26312. var Font = (function FontClosure() {
  26313. function Font(name, file, properties) {
  26314. var charCode, glyphName, fontChar;
  26315. this.name = name;
  26316. this.loadedName = properties.loadedName;
  26317. this.isType3Font = properties.isType3Font;
  26318. this.sizes = [];
  26319. this.glyphCache = {};
  26320. var names = name.split('+');
  26321. names = names.length > 1 ? names[1] : names[0];
  26322. names = names.split(/[-,_]/g)[0];
  26323. this.isSerifFont = !!(properties.flags & FontFlags.Serif);
  26324. this.isSymbolicFont = !!(properties.flags & FontFlags.Symbolic);
  26325. this.isMonospace = !!(properties.flags & FontFlags.FixedPitch);
  26326. var type = properties.type;
  26327. var subtype = properties.subtype;
  26328. this.type = type;
  26329. this.fallbackName = (this.isMonospace ? 'monospace' :
  26330. (this.isSerifFont ? 'serif' : 'sans-serif'));
  26331. this.differences = properties.differences;
  26332. this.widths = properties.widths;
  26333. this.defaultWidth = properties.defaultWidth;
  26334. this.composite = properties.composite;
  26335. this.wideChars = properties.wideChars;
  26336. this.cMap = properties.cMap;
  26337. this.ascent = properties.ascent / PDF_GLYPH_SPACE_UNITS;
  26338. this.descent = properties.descent / PDF_GLYPH_SPACE_UNITS;
  26339. this.fontMatrix = properties.fontMatrix;
  26340. this.bbox = properties.bbox;
  26341. this.toUnicode = properties.toUnicode = this.buildToUnicode(properties);
  26342. this.toFontChar = [];
  26343. if (properties.type === 'Type3') {
  26344. for (charCode = 0; charCode < 256; charCode++) {
  26345. this.toFontChar[charCode] = (this.differences[charCode] ||
  26346. properties.defaultEncoding[charCode]);
  26347. }
  26348. this.fontType = FontType.TYPE3;
  26349. return;
  26350. }
  26351. this.cidEncoding = properties.cidEncoding;
  26352. this.vertical = properties.vertical;
  26353. if (this.vertical) {
  26354. this.vmetrics = properties.vmetrics;
  26355. this.defaultVMetrics = properties.defaultVMetrics;
  26356. }
  26357. if (!file || file.isEmpty) {
  26358. if (file) {
  26359. // Some bad PDF generators will include empty font files,
  26360. // attempting to recover by assuming that no file exists.
  26361. warn('Font file is empty in "' + name + '" (' + this.loadedName + ')');
  26362. }
  26363. this.missingFile = true;
  26364. // The file data is not specified. Trying to fix the font name
  26365. // to be used with the canvas.font.
  26366. var fontName = name.replace(/[,_]/g, '-');
  26367. var isStandardFont = !!stdFontMap[fontName] ||
  26368. !!(nonStdFontMap[fontName] && stdFontMap[nonStdFontMap[fontName]]);
  26369. fontName = stdFontMap[fontName] || nonStdFontMap[fontName] || fontName;
  26370. this.bold = (fontName.search(/bold/gi) !== -1);
  26371. this.italic = ((fontName.search(/oblique/gi) !== -1) ||
  26372. (fontName.search(/italic/gi) !== -1));
  26373. // Use 'name' instead of 'fontName' here because the original
  26374. // name ArialBlack for example will be replaced by Helvetica.
  26375. this.black = (name.search(/Black/g) !== -1);
  26376. // if at least one width is present, remeasure all chars when exists
  26377. this.remeasure = Object.keys(this.widths).length > 0;
  26378. if (isStandardFont && type === 'CIDFontType2' &&
  26379. properties.cidEncoding.indexOf('Identity-') === 0) {
  26380. // Standard fonts might be embedded as CID font without glyph mapping.
  26381. // Building one based on GlyphMapForStandardFonts.
  26382. var map = [];
  26383. for (charCode in GlyphMapForStandardFonts) {
  26384. map[+charCode] = GlyphMapForStandardFonts[charCode];
  26385. }
  26386. if (/ArialBlack/i.test(name)) {
  26387. for (charCode in SupplementalGlyphMapForArialBlack) {
  26388. map[+charCode] = SupplementalGlyphMapForArialBlack[charCode];
  26389. }
  26390. }
  26391. var isIdentityUnicode = this.toUnicode instanceof IdentityToUnicodeMap;
  26392. if (!isIdentityUnicode) {
  26393. this.toUnicode.forEach(function(charCode, unicodeCharCode) {
  26394. map[+charCode] = unicodeCharCode;
  26395. });
  26396. }
  26397. this.toFontChar = map;
  26398. this.toUnicode = new ToUnicodeMap(map);
  26399. } else if (/Symbol/i.test(fontName)) {
  26400. var symbols = Encodings.SymbolSetEncoding;
  26401. for (charCode in symbols) {
  26402. fontChar = GlyphsUnicode[symbols[charCode]];
  26403. if (!fontChar) {
  26404. continue;
  26405. }
  26406. this.toFontChar[charCode] = fontChar;
  26407. }
  26408. for (charCode in properties.differences) {
  26409. fontChar = GlyphsUnicode[properties.differences[charCode]];
  26410. if (!fontChar) {
  26411. continue;
  26412. }
  26413. this.toFontChar[charCode] = fontChar;
  26414. }
  26415. } else if (/Dingbats/i.test(fontName)) {
  26416. if (/Wingdings/i.test(name)) {
  26417. warn('Wingdings font without embedded font file, ' +
  26418. 'falling back to the ZapfDingbats encoding.');
  26419. }
  26420. var dingbats = Encodings.ZapfDingbatsEncoding;
  26421. for (charCode in dingbats) {
  26422. fontChar = DingbatsGlyphsUnicode[dingbats[charCode]];
  26423. if (!fontChar) {
  26424. continue;
  26425. }
  26426. this.toFontChar[charCode] = fontChar;
  26427. }
  26428. for (charCode in properties.differences) {
  26429. fontChar = DingbatsGlyphsUnicode[properties.differences[charCode]];
  26430. if (!fontChar) {
  26431. continue;
  26432. }
  26433. this.toFontChar[charCode] = fontChar;
  26434. }
  26435. } else if (isStandardFont) {
  26436. this.toFontChar = [];
  26437. for (charCode in properties.defaultEncoding) {
  26438. glyphName = (properties.differences[charCode] ||
  26439. properties.defaultEncoding[charCode]);
  26440. this.toFontChar[charCode] = GlyphsUnicode[glyphName];
  26441. }
  26442. } else {
  26443. var unicodeCharCode, notCidFont = (type.indexOf('CIDFontType') === -1);
  26444. this.toUnicode.forEach(function(charCode, unicodeCharCode) {
  26445. if (notCidFont) {
  26446. glyphName = (properties.differences[charCode] ||
  26447. properties.defaultEncoding[charCode]);
  26448. unicodeCharCode = (GlyphsUnicode[glyphName] || unicodeCharCode);
  26449. }
  26450. this.toFontChar[charCode] = unicodeCharCode;
  26451. }.bind(this));
  26452. }
  26453. this.loadedName = fontName.split('-')[0];
  26454. this.loading = false;
  26455. this.fontType = getFontType(type, subtype);
  26456. return;
  26457. }
  26458. // Some fonts might use wrong font types for Type1C or CIDFontType0C
  26459. if (subtype === 'Type1C' && (type !== 'Type1' && type !== 'MMType1')) {
  26460. // Some TrueType fonts by mistake claim Type1C
  26461. if (isTrueTypeFile(file)) {
  26462. subtype = 'TrueType';
  26463. } else {
  26464. type = 'Type1';
  26465. }
  26466. }
  26467. if (subtype === 'CIDFontType0C' && type !== 'CIDFontType0') {
  26468. type = 'CIDFontType0';
  26469. }
  26470. if (subtype === 'OpenType') {
  26471. type = 'OpenType';
  26472. }
  26473. // Some CIDFontType0C fonts by mistake claim CIDFontType0.
  26474. if (type === 'CIDFontType0') {
  26475. if (isType1File(file)) {
  26476. subtype = 'CIDFontType0';
  26477. } else if (isOpenTypeFile(file)) {
  26478. // Sometimes the type/subtype can be a complete lie (see issue6782.pdf).
  26479. type = subtype = 'OpenType';
  26480. } else {
  26481. subtype = 'CIDFontType0C';
  26482. }
  26483. }
  26484. var data;
  26485. switch (type) {
  26486. case 'MMType1':
  26487. info('MMType1 font (' + name + '), falling back to Type1.');
  26488. /* falls through */
  26489. case 'Type1':
  26490. case 'CIDFontType0':
  26491. this.mimetype = 'font/opentype';
  26492. var cff = (subtype === 'Type1C' || subtype === 'CIDFontType0C') ?
  26493. new CFFFont(file, properties) : new Type1Font(name, file, properties);
  26494. adjustWidths(properties);
  26495. // Wrap the CFF data inside an OTF font file
  26496. data = this.convert(name, cff, properties);
  26497. break;
  26498. case 'OpenType':
  26499. case 'TrueType':
  26500. case 'CIDFontType2':
  26501. this.mimetype = 'font/opentype';
  26502. // Repair the TrueType file. It is can be damaged in the point of
  26503. // view of the sanitizer
  26504. data = this.checkAndRepair(name, file, properties);
  26505. if (this.isOpenType) {
  26506. adjustWidths(properties);
  26507. type = 'OpenType';
  26508. }
  26509. break;
  26510. default:
  26511. error('Font ' + type + ' is not supported');
  26512. break;
  26513. }
  26514. this.data = data;
  26515. this.fontType = getFontType(type, subtype);
  26516. // Transfer some properties again that could change during font conversion
  26517. this.fontMatrix = properties.fontMatrix;
  26518. this.widths = properties.widths;
  26519. this.defaultWidth = properties.defaultWidth;
  26520. this.encoding = properties.baseEncoding;
  26521. this.seacMap = properties.seacMap;
  26522. this.loading = true;
  26523. }
  26524. Font.getFontID = (function () {
  26525. var ID = 1;
  26526. return function Font_getFontID() {
  26527. return String(ID++);
  26528. };
  26529. })();
  26530. function int16(b0, b1) {
  26531. return (b0 << 8) + b1;
  26532. }
  26533. function int32(b0, b1, b2, b3) {
  26534. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  26535. }
  26536. function string16(value) {
  26537. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  26538. }
  26539. function safeString16(value) {
  26540. // clamp value to the 16-bit int range
  26541. value = (value > 0x7FFF ? 0x7FFF : (value < -0x8000 ? -0x8000 : value));
  26542. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  26543. }
  26544. function isTrueTypeFile(file) {
  26545. var header = file.peekBytes(4);
  26546. return readUint32(header, 0) === 0x00010000;
  26547. }
  26548. function isOpenTypeFile(file) {
  26549. var header = file.peekBytes(4);
  26550. return bytesToString(header) === 'OTTO';
  26551. }
  26552. function isType1File(file) {
  26553. var header = file.peekBytes(2);
  26554. // All Type1 font programs must begin with the comment '%!' (0x25 + 0x21).
  26555. if (header[0] === 0x25 && header[1] === 0x21) {
  26556. return true;
  26557. }
  26558. // ... obviously some fonts violate that part of the specification,
  26559. // please refer to the comment in |Type1Font| below.
  26560. if (header[0] === 0x80 && header[1] === 0x01) { // pfb file header.
  26561. return true;
  26562. }
  26563. return false;
  26564. }
  26565. /**
  26566. * Helper function for |adjustMapping|.
  26567. * @return {boolean}
  26568. */
  26569. function isProblematicUnicodeLocation(code) {
  26570. // Using binary search to find a range start.
  26571. var i = 0, j = ProblematicCharRanges.length - 1;
  26572. while (i < j) {
  26573. var c = (i + j + 1) >> 1;
  26574. if (code < ProblematicCharRanges[c]) {
  26575. j = c - 1;
  26576. } else {
  26577. i = c;
  26578. }
  26579. }
  26580. // Even index means code in problematic range.
  26581. return !(i & 1);
  26582. }
  26583. /**
  26584. * Rebuilds the char code to glyph ID map by trying to replace the char codes
  26585. * with their unicode value. It also moves char codes that are in known
  26586. * problematic locations.
  26587. * @return {Object} Two properties:
  26588. * 'toFontChar' - maps original char codes(the value that will be read
  26589. * from commands such as show text) to the char codes that will be used in the
  26590. * font that we build
  26591. * 'charCodeToGlyphId' - maps the new font char codes to glyph ids
  26592. */
  26593. function adjustMapping(charCodeToGlyphId, properties) {
  26594. var toUnicode = properties.toUnicode;
  26595. var isSymbolic = !!(properties.flags & FontFlags.Symbolic);
  26596. var isIdentityUnicode =
  26597. properties.toUnicode instanceof IdentityToUnicodeMap;
  26598. var newMap = Object.create(null);
  26599. var toFontChar = [];
  26600. var usedFontCharCodes = [];
  26601. var nextAvailableFontCharCode = PRIVATE_USE_OFFSET_START;
  26602. for (var originalCharCode in charCodeToGlyphId) {
  26603. originalCharCode |= 0;
  26604. var glyphId = charCodeToGlyphId[originalCharCode];
  26605. var fontCharCode = originalCharCode;
  26606. // First try to map the value to a unicode position if a non identity map
  26607. // was created.
  26608. if (!isIdentityUnicode && toUnicode.has(originalCharCode)) {
  26609. var unicode = toUnicode.get(fontCharCode);
  26610. // TODO: Try to map ligatures to the correct spot.
  26611. if (unicode.length === 1) {
  26612. fontCharCode = unicode.charCodeAt(0);
  26613. }
  26614. }
  26615. // Try to move control characters, special characters and already mapped
  26616. // characters to the private use area since they will not be drawn by
  26617. // canvas if left in their current position. Also, move characters if the
  26618. // font was symbolic and there is only an identity unicode map since the
  26619. // characters probably aren't in the correct position (fixes an issue
  26620. // with firefox and thuluthfont).
  26621. if ((usedFontCharCodes[fontCharCode] !== undefined ||
  26622. isProblematicUnicodeLocation(fontCharCode) ||
  26623. (isSymbolic && isIdentityUnicode)) &&
  26624. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END) { // Room left.
  26625. // Loop to try and find a free spot in the private use area.
  26626. do {
  26627. fontCharCode = nextAvailableFontCharCode++;
  26628. if (SKIP_PRIVATE_USE_RANGE_F000_TO_F01F && fontCharCode === 0xF000) {
  26629. fontCharCode = 0xF020;
  26630. nextAvailableFontCharCode = fontCharCode + 1;
  26631. }
  26632. } while (usedFontCharCodes[fontCharCode] !== undefined &&
  26633. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END);
  26634. }
  26635. newMap[fontCharCode] = glyphId;
  26636. toFontChar[originalCharCode] = fontCharCode;
  26637. usedFontCharCodes[fontCharCode] = true;
  26638. }
  26639. return {
  26640. toFontChar: toFontChar,
  26641. charCodeToGlyphId: newMap,
  26642. nextAvailableFontCharCode: nextAvailableFontCharCode
  26643. };
  26644. }
  26645. function getRanges(glyphs, numGlyphs) {
  26646. // Array.sort() sorts by characters, not numerically, so convert to an
  26647. // array of characters.
  26648. var codes = [];
  26649. for (var charCode in glyphs) {
  26650. // Remove an invalid glyph ID mappings to make OTS happy.
  26651. if (glyphs[charCode] >= numGlyphs) {
  26652. continue;
  26653. }
  26654. codes.push({ fontCharCode: charCode | 0, glyphId: glyphs[charCode] });
  26655. }
  26656. codes.sort(function fontGetRangesSort(a, b) {
  26657. return a.fontCharCode - b.fontCharCode;
  26658. });
  26659. // Split the sorted codes into ranges.
  26660. var ranges = [];
  26661. var length = codes.length;
  26662. for (var n = 0; n < length; ) {
  26663. var start = codes[n].fontCharCode;
  26664. var codeIndices = [codes[n].glyphId];
  26665. ++n;
  26666. var end = start;
  26667. while (n < length && end + 1 === codes[n].fontCharCode) {
  26668. codeIndices.push(codes[n].glyphId);
  26669. ++end;
  26670. ++n;
  26671. if (end === 0xFFFF) {
  26672. break;
  26673. }
  26674. }
  26675. ranges.push([start, end, codeIndices]);
  26676. }
  26677. return ranges;
  26678. }
  26679. function createCmapTable(glyphs, numGlyphs) {
  26680. var ranges = getRanges(glyphs, numGlyphs);
  26681. var numTables = ranges[ranges.length - 1][1] > 0xFFFF ? 2 : 1;
  26682. var cmap = '\x00\x00' + // version
  26683. string16(numTables) + // numTables
  26684. '\x00\x03' + // platformID
  26685. '\x00\x01' + // encodingID
  26686. string32(4 + numTables * 8); // start of the table record
  26687. var i, ii, j, jj;
  26688. for (i = ranges.length - 1; i >= 0; --i) {
  26689. if (ranges[i][0] <= 0xFFFF) { break; }
  26690. }
  26691. var bmpLength = i + 1;
  26692. if (ranges[i][0] < 0xFFFF && ranges[i][1] === 0xFFFF) {
  26693. ranges[i][1] = 0xFFFE;
  26694. }
  26695. var trailingRangesCount = ranges[i][1] < 0xFFFF ? 1 : 0;
  26696. var segCount = bmpLength + trailingRangesCount;
  26697. var searchParams = OpenTypeFileBuilder.getSearchParams(segCount, 2);
  26698. // Fill up the 4 parallel arrays describing the segments.
  26699. var startCount = '';
  26700. var endCount = '';
  26701. var idDeltas = '';
  26702. var idRangeOffsets = '';
  26703. var glyphsIds = '';
  26704. var bias = 0;
  26705. var range, start, end, codes;
  26706. for (i = 0, ii = bmpLength; i < ii; i++) {
  26707. range = ranges[i];
  26708. start = range[0];
  26709. end = range[1];
  26710. startCount += string16(start);
  26711. endCount += string16(end);
  26712. codes = range[2];
  26713. var contiguous = true;
  26714. for (j = 1, jj = codes.length; j < jj; ++j) {
  26715. if (codes[j] !== codes[j - 1] + 1) {
  26716. contiguous = false;
  26717. break;
  26718. }
  26719. }
  26720. if (!contiguous) {
  26721. var offset = (segCount - i) * 2 + bias * 2;
  26722. bias += (end - start + 1);
  26723. idDeltas += string16(0);
  26724. idRangeOffsets += string16(offset);
  26725. for (j = 0, jj = codes.length; j < jj; ++j) {
  26726. glyphsIds += string16(codes[j]);
  26727. }
  26728. } else {
  26729. var startCode = codes[0];
  26730. idDeltas += string16((startCode - start) & 0xFFFF);
  26731. idRangeOffsets += string16(0);
  26732. }
  26733. }
  26734. if (trailingRangesCount > 0) {
  26735. endCount += '\xFF\xFF';
  26736. startCount += '\xFF\xFF';
  26737. idDeltas += '\x00\x01';
  26738. idRangeOffsets += '\x00\x00';
  26739. }
  26740. var format314 = '\x00\x00' + // language
  26741. string16(2 * segCount) +
  26742. string16(searchParams.range) +
  26743. string16(searchParams.entry) +
  26744. string16(searchParams.rangeShift) +
  26745. endCount + '\x00\x00' + startCount +
  26746. idDeltas + idRangeOffsets + glyphsIds;
  26747. var format31012 = '';
  26748. var header31012 = '';
  26749. if (numTables > 1) {
  26750. cmap += '\x00\x03' + // platformID
  26751. '\x00\x0A' + // encodingID
  26752. string32(4 + numTables * 8 +
  26753. 4 + format314.length); // start of the table record
  26754. format31012 = '';
  26755. for (i = 0, ii = ranges.length; i < ii; i++) {
  26756. range = ranges[i];
  26757. start = range[0];
  26758. codes = range[2];
  26759. var code = codes[0];
  26760. for (j = 1, jj = codes.length; j < jj; ++j) {
  26761. if (codes[j] !== codes[j - 1] + 1) {
  26762. end = range[0] + j - 1;
  26763. format31012 += string32(start) + // startCharCode
  26764. string32(end) + // endCharCode
  26765. string32(code); // startGlyphID
  26766. start = end + 1;
  26767. code = codes[j];
  26768. }
  26769. }
  26770. format31012 += string32(start) + // startCharCode
  26771. string32(range[1]) + // endCharCode
  26772. string32(code); // startGlyphID
  26773. }
  26774. header31012 = '\x00\x0C' + // format
  26775. '\x00\x00' + // reserved
  26776. string32(format31012.length + 16) + // length
  26777. '\x00\x00\x00\x00' + // language
  26778. string32(format31012.length / 12); // nGroups
  26779. }
  26780. return cmap + '\x00\x04' + // format
  26781. string16(format314.length + 4) + // length
  26782. format314 + header31012 + format31012;
  26783. }
  26784. function validateOS2Table(os2) {
  26785. var stream = new Stream(os2.data);
  26786. var version = stream.getUint16();
  26787. // TODO verify all OS/2 tables fields, but currently we validate only those
  26788. // that give us issues
  26789. stream.getBytes(60); // skipping type, misc sizes, panose, unicode ranges
  26790. var selection = stream.getUint16();
  26791. if (version < 4 && (selection & 0x0300)) {
  26792. return false;
  26793. }
  26794. var firstChar = stream.getUint16();
  26795. var lastChar = stream.getUint16();
  26796. if (firstChar > lastChar) {
  26797. return false;
  26798. }
  26799. stream.getBytes(6); // skipping sTypoAscender/Descender/LineGap
  26800. var usWinAscent = stream.getUint16();
  26801. if (usWinAscent === 0) { // makes font unreadable by windows
  26802. return false;
  26803. }
  26804. // OS/2 appears to be valid, resetting some fields
  26805. os2.data[8] = os2.data[9] = 0; // IE rejects fonts if fsType != 0
  26806. return true;
  26807. }
  26808. function createOS2Table(properties, charstrings, override) {
  26809. override = override || {
  26810. unitsPerEm: 0,
  26811. yMax: 0,
  26812. yMin: 0,
  26813. ascent: 0,
  26814. descent: 0
  26815. };
  26816. var ulUnicodeRange1 = 0;
  26817. var ulUnicodeRange2 = 0;
  26818. var ulUnicodeRange3 = 0;
  26819. var ulUnicodeRange4 = 0;
  26820. var firstCharIndex = null;
  26821. var lastCharIndex = 0;
  26822. if (charstrings) {
  26823. for (var code in charstrings) {
  26824. code |= 0;
  26825. if (firstCharIndex > code || !firstCharIndex) {
  26826. firstCharIndex = code;
  26827. }
  26828. if (lastCharIndex < code) {
  26829. lastCharIndex = code;
  26830. }
  26831. var position = getUnicodeRangeFor(code);
  26832. if (position < 32) {
  26833. ulUnicodeRange1 |= 1 << position;
  26834. } else if (position < 64) {
  26835. ulUnicodeRange2 |= 1 << position - 32;
  26836. } else if (position < 96) {
  26837. ulUnicodeRange3 |= 1 << position - 64;
  26838. } else if (position < 123) {
  26839. ulUnicodeRange4 |= 1 << position - 96;
  26840. } else {
  26841. error('Unicode ranges Bits > 123 are reserved for internal usage');
  26842. }
  26843. }
  26844. } else {
  26845. // TODO
  26846. firstCharIndex = 0;
  26847. lastCharIndex = 255;
  26848. }
  26849. var bbox = properties.bbox || [0, 0, 0, 0];
  26850. var unitsPerEm = (override.unitsPerEm ||
  26851. 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0]);
  26852. // if the font units differ to the PDF glyph space units
  26853. // then scale up the values
  26854. var scale = (properties.ascentScaled ? 1.0 :
  26855. unitsPerEm / PDF_GLYPH_SPACE_UNITS);
  26856. var typoAscent = (override.ascent ||
  26857. Math.round(scale * (properties.ascent || bbox[3])));
  26858. var typoDescent = (override.descent ||
  26859. Math.round(scale * (properties.descent || bbox[1])));
  26860. if (typoDescent > 0 && properties.descent > 0 && bbox[1] < 0) {
  26861. typoDescent = -typoDescent; // fixing incorrect descent
  26862. }
  26863. var winAscent = override.yMax || typoAscent;
  26864. var winDescent = -override.yMin || -typoDescent;
  26865. return '\x00\x03' + // version
  26866. '\x02\x24' + // xAvgCharWidth
  26867. '\x01\xF4' + // usWeightClass
  26868. '\x00\x05' + // usWidthClass
  26869. '\x00\x00' + // fstype (0 to let the font loads via font-face on IE)
  26870. '\x02\x8A' + // ySubscriptXSize
  26871. '\x02\xBB' + // ySubscriptYSize
  26872. '\x00\x00' + // ySubscriptXOffset
  26873. '\x00\x8C' + // ySubscriptYOffset
  26874. '\x02\x8A' + // ySuperScriptXSize
  26875. '\x02\xBB' + // ySuperScriptYSize
  26876. '\x00\x00' + // ySuperScriptXOffset
  26877. '\x01\xDF' + // ySuperScriptYOffset
  26878. '\x00\x31' + // yStrikeOutSize
  26879. '\x01\x02' + // yStrikeOutPosition
  26880. '\x00\x00' + // sFamilyClass
  26881. '\x00\x00\x06' +
  26882. String.fromCharCode(properties.fixedPitch ? 0x09 : 0x00) +
  26883. '\x00\x00\x00\x00\x00\x00' + // Panose
  26884. string32(ulUnicodeRange1) + // ulUnicodeRange1 (Bits 0-31)
  26885. string32(ulUnicodeRange2) + // ulUnicodeRange2 (Bits 32-63)
  26886. string32(ulUnicodeRange3) + // ulUnicodeRange3 (Bits 64-95)
  26887. string32(ulUnicodeRange4) + // ulUnicodeRange4 (Bits 96-127)
  26888. '\x2A\x32\x31\x2A' + // achVendID
  26889. string16(properties.italicAngle ? 1 : 0) + // fsSelection
  26890. string16(firstCharIndex ||
  26891. properties.firstChar) + // usFirstCharIndex
  26892. string16(lastCharIndex || properties.lastChar) + // usLastCharIndex
  26893. string16(typoAscent) + // sTypoAscender
  26894. string16(typoDescent) + // sTypoDescender
  26895. '\x00\x64' + // sTypoLineGap (7%-10% of the unitsPerEM value)
  26896. string16(winAscent) + // usWinAscent
  26897. string16(winDescent) + // usWinDescent
  26898. '\x00\x00\x00\x00' + // ulCodePageRange1 (Bits 0-31)
  26899. '\x00\x00\x00\x00' + // ulCodePageRange2 (Bits 32-63)
  26900. string16(properties.xHeight) + // sxHeight
  26901. string16(properties.capHeight) + // sCapHeight
  26902. string16(0) + // usDefaultChar
  26903. string16(firstCharIndex || properties.firstChar) + // usBreakChar
  26904. '\x00\x03'; // usMaxContext
  26905. }
  26906. function createPostTable(properties) {
  26907. var angle = Math.floor(properties.italicAngle * (Math.pow(2, 16)));
  26908. return ('\x00\x03\x00\x00' + // Version number
  26909. string32(angle) + // italicAngle
  26910. '\x00\x00' + // underlinePosition
  26911. '\x00\x00' + // underlineThickness
  26912. string32(properties.fixedPitch) + // isFixedPitch
  26913. '\x00\x00\x00\x00' + // minMemType42
  26914. '\x00\x00\x00\x00' + // maxMemType42
  26915. '\x00\x00\x00\x00' + // minMemType1
  26916. '\x00\x00\x00\x00'); // maxMemType1
  26917. }
  26918. function createNameTable(name, proto) {
  26919. if (!proto) {
  26920. proto = [[], []]; // no strings and unicode strings
  26921. }
  26922. var strings = [
  26923. proto[0][0] || 'Original licence', // 0.Copyright
  26924. proto[0][1] || name, // 1.Font family
  26925. proto[0][2] || 'Unknown', // 2.Font subfamily (font weight)
  26926. proto[0][3] || 'uniqueID', // 3.Unique ID
  26927. proto[0][4] || name, // 4.Full font name
  26928. proto[0][5] || 'Version 0.11', // 5.Version
  26929. proto[0][6] || '', // 6.Postscript name
  26930. proto[0][7] || 'Unknown', // 7.Trademark
  26931. proto[0][8] || 'Unknown', // 8.Manufacturer
  26932. proto[0][9] || 'Unknown' // 9.Designer
  26933. ];
  26934. // Mac want 1-byte per character strings while Windows want
  26935. // 2-bytes per character, so duplicate the names table
  26936. var stringsUnicode = [];
  26937. var i, ii, j, jj, str;
  26938. for (i = 0, ii = strings.length; i < ii; i++) {
  26939. str = proto[1][i] || strings[i];
  26940. var strBufUnicode = [];
  26941. for (j = 0, jj = str.length; j < jj; j++) {
  26942. strBufUnicode.push(string16(str.charCodeAt(j)));
  26943. }
  26944. stringsUnicode.push(strBufUnicode.join(''));
  26945. }
  26946. var names = [strings, stringsUnicode];
  26947. var platforms = ['\x00\x01', '\x00\x03'];
  26948. var encodings = ['\x00\x00', '\x00\x01'];
  26949. var languages = ['\x00\x00', '\x04\x09'];
  26950. var namesRecordCount = strings.length * platforms.length;
  26951. var nameTable =
  26952. '\x00\x00' + // format
  26953. string16(namesRecordCount) + // Number of names Record
  26954. string16(namesRecordCount * 12 + 6); // Storage
  26955. // Build the name records field
  26956. var strOffset = 0;
  26957. for (i = 0, ii = platforms.length; i < ii; i++) {
  26958. var strs = names[i];
  26959. for (j = 0, jj = strs.length; j < jj; j++) {
  26960. str = strs[j];
  26961. var nameRecord =
  26962. platforms[i] + // platform ID
  26963. encodings[i] + // encoding ID
  26964. languages[i] + // language ID
  26965. string16(j) + // name ID
  26966. string16(str.length) +
  26967. string16(strOffset);
  26968. nameTable += nameRecord;
  26969. strOffset += str.length;
  26970. }
  26971. }
  26972. nameTable += strings.join('') + stringsUnicode.join('');
  26973. return nameTable;
  26974. }
  26975. Font.prototype = {
  26976. name: null,
  26977. font: null,
  26978. mimetype: null,
  26979. encoding: null,
  26980. get renderer() {
  26981. var renderer = FontRendererFactory.create(this);
  26982. return shadow(this, 'renderer', renderer);
  26983. },
  26984. exportData: function Font_exportData() {
  26985. var data = {};
  26986. for (var i in this) {
  26987. if (this.hasOwnProperty(i)) {
  26988. data[i] = this[i];
  26989. }
  26990. }
  26991. return data;
  26992. },
  26993. checkAndRepair: function Font_checkAndRepair(name, font, properties) {
  26994. function readTableEntry(file) {
  26995. var tag = bytesToString(file.getBytes(4));
  26996. var checksum = file.getInt32();
  26997. var offset = file.getInt32() >>> 0;
  26998. var length = file.getInt32() >>> 0;
  26999. // Read the table associated data
  27000. var previousPosition = file.pos;
  27001. file.pos = file.start ? file.start : 0;
  27002. file.skip(offset);
  27003. var data = file.getBytes(length);
  27004. file.pos = previousPosition;
  27005. if (tag === 'head') {
  27006. // clearing checksum adjustment
  27007. data[8] = data[9] = data[10] = data[11] = 0;
  27008. data[17] |= 0x20; //Set font optimized for cleartype flag
  27009. }
  27010. return {
  27011. tag: tag,
  27012. checksum: checksum,
  27013. length: length,
  27014. offset: offset,
  27015. data: data
  27016. };
  27017. }
  27018. function readOpenTypeHeader(ttf) {
  27019. return {
  27020. version: bytesToString(ttf.getBytes(4)),
  27021. numTables: ttf.getUint16(),
  27022. searchRange: ttf.getUint16(),
  27023. entrySelector: ttf.getUint16(),
  27024. rangeShift: ttf.getUint16()
  27025. };
  27026. }
  27027. /**
  27028. * Read the appropriate subtable from the cmap according to 9.6.6.4 from
  27029. * PDF spec
  27030. */
  27031. function readCmapTable(cmap, font, isSymbolicFont, hasEncoding) {
  27032. if (!cmap) {
  27033. warn('No cmap table available.');
  27034. return {
  27035. platformId: -1,
  27036. encodingId: -1,
  27037. mappings: [],
  27038. hasShortCmap: false
  27039. };
  27040. }
  27041. var segment;
  27042. var start = (font.start ? font.start : 0) + cmap.offset;
  27043. font.pos = start;
  27044. var version = font.getUint16();
  27045. var numTables = font.getUint16();
  27046. var potentialTable;
  27047. var canBreak = false;
  27048. // There's an order of preference in terms of which cmap subtable to
  27049. // use:
  27050. // - non-symbolic fonts the preference is a 3,1 table then a 1,0 table
  27051. // - symbolic fonts the preference is a 3,0 table then a 1,0 table
  27052. // The following takes advantage of the fact that the tables are sorted
  27053. // to work.
  27054. for (var i = 0; i < numTables; i++) {
  27055. var platformId = font.getUint16();
  27056. var encodingId = font.getUint16();
  27057. var offset = font.getInt32() >>> 0;
  27058. var useTable = false;
  27059. if (platformId === 0 && encodingId === 0) {
  27060. useTable = true;
  27061. // Continue the loop since there still may be a higher priority
  27062. // table.
  27063. } else if (platformId === 1 && encodingId === 0) {
  27064. useTable = true;
  27065. // Continue the loop since there still may be a higher priority
  27066. // table.
  27067. } else if (platformId === 3 && encodingId === 1 &&
  27068. ((!isSymbolicFont && hasEncoding) || !potentialTable)) {
  27069. useTable = true;
  27070. if (!isSymbolicFont) {
  27071. canBreak = true;
  27072. }
  27073. } else if (isSymbolicFont && platformId === 3 && encodingId === 0) {
  27074. useTable = true;
  27075. canBreak = true;
  27076. }
  27077. if (useTable) {
  27078. potentialTable = {
  27079. platformId: platformId,
  27080. encodingId: encodingId,
  27081. offset: offset
  27082. };
  27083. }
  27084. if (canBreak) {
  27085. break;
  27086. }
  27087. }
  27088. if (potentialTable) {
  27089. font.pos = start + potentialTable.offset;
  27090. }
  27091. if (!potentialTable || font.peekByte() === -1) {
  27092. warn('Could not find a preferred cmap table.');
  27093. return {
  27094. platformId: -1,
  27095. encodingId: -1,
  27096. mappings: [],
  27097. hasShortCmap: false
  27098. };
  27099. }
  27100. var format = font.getUint16();
  27101. var length = font.getUint16();
  27102. var language = font.getUint16();
  27103. var hasShortCmap = false;
  27104. var mappings = [];
  27105. var j, glyphId;
  27106. // TODO(mack): refactor this cmap subtable reading logic out
  27107. if (format === 0) {
  27108. for (j = 0; j < 256; j++) {
  27109. var index = font.getByte();
  27110. if (!index) {
  27111. continue;
  27112. }
  27113. mappings.push({
  27114. charCode: j,
  27115. glyphId: index
  27116. });
  27117. }
  27118. hasShortCmap = true;
  27119. } else if (format === 4) {
  27120. // re-creating the table in format 4 since the encoding
  27121. // might be changed
  27122. var segCount = (font.getUint16() >> 1);
  27123. font.getBytes(6); // skipping range fields
  27124. var segIndex, segments = [];
  27125. for (segIndex = 0; segIndex < segCount; segIndex++) {
  27126. segments.push({ end: font.getUint16() });
  27127. }
  27128. font.getUint16();
  27129. for (segIndex = 0; segIndex < segCount; segIndex++) {
  27130. segments[segIndex].start = font.getUint16();
  27131. }
  27132. for (segIndex = 0; segIndex < segCount; segIndex++) {
  27133. segments[segIndex].delta = font.getUint16();
  27134. }
  27135. var offsetsCount = 0;
  27136. for (segIndex = 0; segIndex < segCount; segIndex++) {
  27137. segment = segments[segIndex];
  27138. var rangeOffset = font.getUint16();
  27139. if (!rangeOffset) {
  27140. segment.offsetIndex = -1;
  27141. continue;
  27142. }
  27143. var offsetIndex = (rangeOffset >> 1) - (segCount - segIndex);
  27144. segment.offsetIndex = offsetIndex;
  27145. offsetsCount = Math.max(offsetsCount, offsetIndex +
  27146. segment.end - segment.start + 1);
  27147. }
  27148. var offsets = [];
  27149. for (j = 0; j < offsetsCount; j++) {
  27150. offsets.push(font.getUint16());
  27151. }
  27152. for (segIndex = 0; segIndex < segCount; segIndex++) {
  27153. segment = segments[segIndex];
  27154. start = segment.start;
  27155. var end = segment.end;
  27156. var delta = segment.delta;
  27157. offsetIndex = segment.offsetIndex;
  27158. for (j = start; j <= end; j++) {
  27159. if (j === 0xFFFF) {
  27160. continue;
  27161. }
  27162. glyphId = (offsetIndex < 0 ?
  27163. j : offsets[offsetIndex + j - start]);
  27164. glyphId = (glyphId + delta) & 0xFFFF;
  27165. if (glyphId === 0) {
  27166. continue;
  27167. }
  27168. mappings.push({
  27169. charCode: j,
  27170. glyphId: glyphId
  27171. });
  27172. }
  27173. }
  27174. } else if (format === 6) {
  27175. // Format 6 is a 2-bytes dense mapping, which means the font data
  27176. // lives glue together even if they are pretty far in the unicode
  27177. // table. (This looks weird, so I can have missed something), this
  27178. // works on Linux but seems to fails on Mac so let's rewrite the
  27179. // cmap table to a 3-1-4 style
  27180. var firstCode = font.getUint16();
  27181. var entryCount = font.getUint16();
  27182. for (j = 0; j < entryCount; j++) {
  27183. glyphId = font.getUint16();
  27184. var charCode = firstCode + j;
  27185. mappings.push({
  27186. charCode: charCode,
  27187. glyphId: glyphId
  27188. });
  27189. }
  27190. } else {
  27191. warn('cmap table has unsupported format: ' + format);
  27192. return {
  27193. platformId: -1,
  27194. encodingId: -1,
  27195. mappings: [],
  27196. hasShortCmap: false
  27197. };
  27198. }
  27199. // removing duplicate entries
  27200. mappings.sort(function (a, b) {
  27201. return a.charCode - b.charCode;
  27202. });
  27203. for (i = 1; i < mappings.length; i++) {
  27204. if (mappings[i - 1].charCode === mappings[i].charCode) {
  27205. mappings.splice(i, 1);
  27206. i--;
  27207. }
  27208. }
  27209. return {
  27210. platformId: potentialTable.platformId,
  27211. encodingId: potentialTable.encodingId,
  27212. mappings: mappings,
  27213. hasShortCmap: hasShortCmap
  27214. };
  27215. }
  27216. function sanitizeMetrics(font, header, metrics, numGlyphs) {
  27217. if (!header) {
  27218. if (metrics) {
  27219. metrics.data = null;
  27220. }
  27221. return;
  27222. }
  27223. font.pos = (font.start ? font.start : 0) + header.offset;
  27224. font.pos += header.length - 2;
  27225. var numOfMetrics = font.getUint16();
  27226. if (numOfMetrics > numGlyphs) {
  27227. info('The numOfMetrics (' + numOfMetrics + ') should not be ' +
  27228. 'greater than the numGlyphs (' + numGlyphs + ')');
  27229. // Reduce numOfMetrics if it is greater than numGlyphs
  27230. numOfMetrics = numGlyphs;
  27231. header.data[34] = (numOfMetrics & 0xff00) >> 8;
  27232. header.data[35] = numOfMetrics & 0x00ff;
  27233. }
  27234. var numOfSidebearings = numGlyphs - numOfMetrics;
  27235. var numMissing = numOfSidebearings -
  27236. ((metrics.length - numOfMetrics * 4) >> 1);
  27237. if (numMissing > 0) {
  27238. // For each missing glyph, we set both the width and lsb to 0 (zero).
  27239. // Since we need to add two properties for each glyph, this explains
  27240. // the use of |numMissing * 2| when initializing the typed array.
  27241. var entries = new Uint8Array(metrics.length + numMissing * 2);
  27242. entries.set(metrics.data);
  27243. metrics.data = entries;
  27244. }
  27245. }
  27246. function sanitizeGlyph(source, sourceStart, sourceEnd, dest, destStart,
  27247. hintsValid) {
  27248. if (sourceEnd - sourceStart <= 12) {
  27249. // glyph with data less than 12 is invalid one
  27250. return 0;
  27251. }
  27252. var glyf = source.subarray(sourceStart, sourceEnd);
  27253. var contoursCount = (glyf[0] << 8) | glyf[1];
  27254. if (contoursCount & 0x8000) {
  27255. // complex glyph, writing as is
  27256. dest.set(glyf, destStart);
  27257. return glyf.length;
  27258. }
  27259. var i, j = 10, flagsCount = 0;
  27260. for (i = 0; i < contoursCount; i++) {
  27261. var endPoint = (glyf[j] << 8) | glyf[j + 1];
  27262. flagsCount = endPoint + 1;
  27263. j += 2;
  27264. }
  27265. // skipping instructions
  27266. var instructionsStart = j;
  27267. var instructionsLength = (glyf[j] << 8) | glyf[j + 1];
  27268. j += 2 + instructionsLength;
  27269. var instructionsEnd = j;
  27270. // validating flags
  27271. var coordinatesLength = 0;
  27272. for (i = 0; i < flagsCount; i++) {
  27273. var flag = glyf[j++];
  27274. if (flag & 0xC0) {
  27275. // reserved flags must be zero, cleaning up
  27276. glyf[j - 1] = flag & 0x3F;
  27277. }
  27278. var xyLength = ((flag & 2) ? 1 : (flag & 16) ? 0 : 2) +
  27279. ((flag & 4) ? 1 : (flag & 32) ? 0 : 2);
  27280. coordinatesLength += xyLength;
  27281. if (flag & 8) {
  27282. var repeat = glyf[j++];
  27283. i += repeat;
  27284. coordinatesLength += repeat * xyLength;
  27285. }
  27286. }
  27287. // glyph without coordinates will be rejected
  27288. if (coordinatesLength === 0) {
  27289. return 0;
  27290. }
  27291. var glyphDataLength = j + coordinatesLength;
  27292. if (glyphDataLength > glyf.length) {
  27293. // not enough data for coordinates
  27294. return 0;
  27295. }
  27296. if (!hintsValid && instructionsLength > 0) {
  27297. dest.set(glyf.subarray(0, instructionsStart), destStart);
  27298. dest.set([0, 0], destStart + instructionsStart);
  27299. dest.set(glyf.subarray(instructionsEnd, glyphDataLength),
  27300. destStart + instructionsStart + 2);
  27301. glyphDataLength -= instructionsLength;
  27302. if (glyf.length - glyphDataLength > 3) {
  27303. glyphDataLength = (glyphDataLength + 3) & ~3;
  27304. }
  27305. return glyphDataLength;
  27306. }
  27307. if (glyf.length - glyphDataLength > 3) {
  27308. // truncating and aligning to 4 bytes the long glyph data
  27309. glyphDataLength = (glyphDataLength + 3) & ~3;
  27310. dest.set(glyf.subarray(0, glyphDataLength), destStart);
  27311. return glyphDataLength;
  27312. }
  27313. // glyph data is fine
  27314. dest.set(glyf, destStart);
  27315. return glyf.length;
  27316. }
  27317. function sanitizeHead(head, numGlyphs, locaLength) {
  27318. var data = head.data;
  27319. // Validate version:
  27320. // Should always be 0x00010000
  27321. var version = int32(data[0], data[1], data[2], data[3]);
  27322. if (version >> 16 !== 1) {
  27323. info('Attempting to fix invalid version in head table: ' + version);
  27324. data[0] = 0;
  27325. data[1] = 1;
  27326. data[2] = 0;
  27327. data[3] = 0;
  27328. }
  27329. var indexToLocFormat = int16(data[50], data[51]);
  27330. if (indexToLocFormat < 0 || indexToLocFormat > 1) {
  27331. info('Attempting to fix invalid indexToLocFormat in head table: ' +
  27332. indexToLocFormat);
  27333. // The value of indexToLocFormat should be 0 if the loca table
  27334. // consists of short offsets, and should be 1 if the loca table
  27335. // consists of long offsets.
  27336. //
  27337. // The number of entries in the loca table should be numGlyphs + 1.
  27338. //
  27339. // Using this information, we can work backwards to deduce if the
  27340. // size of each offset in the loca table, and thus figure out the
  27341. // appropriate value for indexToLocFormat.
  27342. var numGlyphsPlusOne = numGlyphs + 1;
  27343. if (locaLength === numGlyphsPlusOne << 1) {
  27344. // 0x0000 indicates the loca table consists of short offsets
  27345. data[50] = 0;
  27346. data[51] = 0;
  27347. } else if (locaLength === numGlyphsPlusOne << 2) {
  27348. // 0x0001 indicates the loca table consists of long offsets
  27349. data[50] = 0;
  27350. data[51] = 1;
  27351. } else {
  27352. warn('Could not fix indexToLocFormat: ' + indexToLocFormat);
  27353. }
  27354. }
  27355. }
  27356. function sanitizeGlyphLocations(loca, glyf, numGlyphs,
  27357. isGlyphLocationsLong, hintsValid,
  27358. dupFirstEntry) {
  27359. var itemSize, itemDecode, itemEncode;
  27360. if (isGlyphLocationsLong) {
  27361. itemSize = 4;
  27362. itemDecode = function fontItemDecodeLong(data, offset) {
  27363. return (data[offset] << 24) | (data[offset + 1] << 16) |
  27364. (data[offset + 2] << 8) | data[offset + 3];
  27365. };
  27366. itemEncode = function fontItemEncodeLong(data, offset, value) {
  27367. data[offset] = (value >>> 24) & 0xFF;
  27368. data[offset + 1] = (value >> 16) & 0xFF;
  27369. data[offset + 2] = (value >> 8) & 0xFF;
  27370. data[offset + 3] = value & 0xFF;
  27371. };
  27372. } else {
  27373. itemSize = 2;
  27374. itemDecode = function fontItemDecode(data, offset) {
  27375. return (data[offset] << 9) | (data[offset + 1] << 1);
  27376. };
  27377. itemEncode = function fontItemEncode(data, offset, value) {
  27378. data[offset] = (value >> 9) & 0xFF;
  27379. data[offset + 1] = (value >> 1) & 0xFF;
  27380. };
  27381. }
  27382. var locaData = loca.data;
  27383. var locaDataSize = itemSize * (1 + numGlyphs);
  27384. // is loca.data too short or long?
  27385. if (locaData.length !== locaDataSize) {
  27386. locaData = new Uint8Array(locaDataSize);
  27387. locaData.set(loca.data.subarray(0, locaDataSize));
  27388. loca.data = locaData;
  27389. }
  27390. // removing the invalid glyphs
  27391. var oldGlyfData = glyf.data;
  27392. var oldGlyfDataLength = oldGlyfData.length;
  27393. var newGlyfData = new Uint8Array(oldGlyfDataLength);
  27394. var startOffset = itemDecode(locaData, 0);
  27395. var writeOffset = 0;
  27396. var missingGlyphData = {};
  27397. itemEncode(locaData, 0, writeOffset);
  27398. var i, j;
  27399. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  27400. var endOffset = itemDecode(locaData, j);
  27401. if (endOffset > oldGlyfDataLength &&
  27402. ((oldGlyfDataLength + 3) & ~3) === endOffset) {
  27403. // Aspose breaks fonts by aligning the glyphs to the qword, but not
  27404. // the glyf table size, which makes last glyph out of range.
  27405. endOffset = oldGlyfDataLength;
  27406. }
  27407. if (endOffset > oldGlyfDataLength) {
  27408. // glyph end offset points outside glyf data, rejecting the glyph
  27409. itemEncode(locaData, j, writeOffset);
  27410. startOffset = endOffset;
  27411. continue;
  27412. }
  27413. if (startOffset === endOffset) {
  27414. missingGlyphData[i] = true;
  27415. }
  27416. var newLength = sanitizeGlyph(oldGlyfData, startOffset, endOffset,
  27417. newGlyfData, writeOffset, hintsValid);
  27418. writeOffset += newLength;
  27419. itemEncode(locaData, j, writeOffset);
  27420. startOffset = endOffset;
  27421. }
  27422. if (writeOffset === 0) {
  27423. // glyf table cannot be empty -- redoing the glyf and loca tables
  27424. // to have single glyph with one point
  27425. var simpleGlyph = new Uint8Array(
  27426. [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 49, 0]);
  27427. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  27428. itemEncode(locaData, j, simpleGlyph.length);
  27429. }
  27430. glyf.data = simpleGlyph;
  27431. return missingGlyphData;
  27432. }
  27433. if (dupFirstEntry) {
  27434. var firstEntryLength = itemDecode(locaData, itemSize);
  27435. if (newGlyfData.length > firstEntryLength + writeOffset) {
  27436. glyf.data = newGlyfData.subarray(0, firstEntryLength + writeOffset);
  27437. } else {
  27438. glyf.data = new Uint8Array(firstEntryLength + writeOffset);
  27439. glyf.data.set(newGlyfData.subarray(0, writeOffset));
  27440. }
  27441. glyf.data.set(newGlyfData.subarray(0, firstEntryLength), writeOffset);
  27442. itemEncode(loca.data, locaData.length - itemSize,
  27443. writeOffset + firstEntryLength);
  27444. } else {
  27445. glyf.data = newGlyfData.subarray(0, writeOffset);
  27446. }
  27447. return missingGlyphData;
  27448. }
  27449. function readPostScriptTable(post, properties, maxpNumGlyphs) {
  27450. var start = (font.start ? font.start : 0) + post.offset;
  27451. font.pos = start;
  27452. var length = post.length, end = start + length;
  27453. var version = font.getInt32();
  27454. // skip rest to the tables
  27455. font.getBytes(28);
  27456. var glyphNames;
  27457. var valid = true;
  27458. var i;
  27459. switch (version) {
  27460. case 0x00010000:
  27461. glyphNames = MacStandardGlyphOrdering;
  27462. break;
  27463. case 0x00020000:
  27464. var numGlyphs = font.getUint16();
  27465. if (numGlyphs !== maxpNumGlyphs) {
  27466. valid = false;
  27467. break;
  27468. }
  27469. var glyphNameIndexes = [];
  27470. for (i = 0; i < numGlyphs; ++i) {
  27471. var index = font.getUint16();
  27472. if (index >= 32768) {
  27473. valid = false;
  27474. break;
  27475. }
  27476. glyphNameIndexes.push(index);
  27477. }
  27478. if (!valid) {
  27479. break;
  27480. }
  27481. var customNames = [];
  27482. var strBuf = [];
  27483. while (font.pos < end) {
  27484. var stringLength = font.getByte();
  27485. strBuf.length = stringLength;
  27486. for (i = 0; i < stringLength; ++i) {
  27487. strBuf[i] = String.fromCharCode(font.getByte());
  27488. }
  27489. customNames.push(strBuf.join(''));
  27490. }
  27491. glyphNames = [];
  27492. for (i = 0; i < numGlyphs; ++i) {
  27493. var j = glyphNameIndexes[i];
  27494. if (j < 258) {
  27495. glyphNames.push(MacStandardGlyphOrdering[j]);
  27496. continue;
  27497. }
  27498. glyphNames.push(customNames[j - 258]);
  27499. }
  27500. break;
  27501. case 0x00030000:
  27502. break;
  27503. default:
  27504. warn('Unknown/unsupported post table version ' + version);
  27505. valid = false;
  27506. if (properties.defaultEncoding) {
  27507. glyphNames = properties.defaultEncoding;
  27508. }
  27509. break;
  27510. }
  27511. properties.glyphNames = glyphNames;
  27512. return valid;
  27513. }
  27514. function readNameTable(nameTable) {
  27515. var start = (font.start ? font.start : 0) + nameTable.offset;
  27516. font.pos = start;
  27517. var names = [[], []];
  27518. var length = nameTable.length, end = start + length;
  27519. var format = font.getUint16();
  27520. var FORMAT_0_HEADER_LENGTH = 6;
  27521. if (format !== 0 || length < FORMAT_0_HEADER_LENGTH) {
  27522. // unsupported name table format or table "too" small
  27523. return names;
  27524. }
  27525. var numRecords = font.getUint16();
  27526. var stringsStart = font.getUint16();
  27527. var records = [];
  27528. var NAME_RECORD_LENGTH = 12;
  27529. var i, ii;
  27530. for (i = 0; i < numRecords &&
  27531. font.pos + NAME_RECORD_LENGTH <= end; i++) {
  27532. var r = {
  27533. platform: font.getUint16(),
  27534. encoding: font.getUint16(),
  27535. language: font.getUint16(),
  27536. name: font.getUint16(),
  27537. length: font.getUint16(),
  27538. offset: font.getUint16()
  27539. };
  27540. // using only Macintosh and Windows platform/encoding names
  27541. if ((r.platform === 1 && r.encoding === 0 && r.language === 0) ||
  27542. (r.platform === 3 && r.encoding === 1 && r.language === 0x409)) {
  27543. records.push(r);
  27544. }
  27545. }
  27546. for (i = 0, ii = records.length; i < ii; i++) {
  27547. var record = records[i];
  27548. var pos = start + stringsStart + record.offset;
  27549. if (pos + record.length > end) {
  27550. continue; // outside of name table, ignoring
  27551. }
  27552. font.pos = pos;
  27553. var nameIndex = record.name;
  27554. if (record.encoding) {
  27555. // unicode
  27556. var str = '';
  27557. for (var j = 0, jj = record.length; j < jj; j += 2) {
  27558. str += String.fromCharCode(font.getUint16());
  27559. }
  27560. names[1][nameIndex] = str;
  27561. } else {
  27562. names[0][nameIndex] = bytesToString(font.getBytes(record.length));
  27563. }
  27564. }
  27565. return names;
  27566. }
  27567. var TTOpsStackDeltas = [
  27568. 0, 0, 0, 0, 0, 0, 0, 0, -2, -2, -2, -2, 0, 0, -2, -5,
  27569. -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, -1, -1,
  27570. 1, -1, -999, 0, 1, 0, -1, -2, 0, -1, -2, -1, -1, 0, -1, -1,
  27571. 0, 0, -999, -999, -1, -1, -1, -1, -2, -999, -2, -2, -999, 0, -2, -2,
  27572. 0, 0, -2, 0, -2, 0, 0, 0, -2, -1, -1, 1, 1, 0, 0, -1,
  27573. -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, 0, -999, -1, -1,
  27574. -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  27575. -2, -999, -999, -999, -999, -999, -1, -1, -2, -2, 0, 0, 0, 0, -1, -1,
  27576. -999, -2, -2, 0, 0, -1, -2, -2, 0, 0, 0, -1, -1, -1, -2];
  27577. // 0xC0-DF == -1 and 0xE0-FF == -2
  27578. function sanitizeTTProgram(table, ttContext) {
  27579. var data = table.data;
  27580. var i = 0, j, n, b, funcId, pc, lastEndf = 0, lastDeff = 0;
  27581. var stack = [];
  27582. var callstack = [];
  27583. var functionsCalled = [];
  27584. var tooComplexToFollowFunctions =
  27585. ttContext.tooComplexToFollowFunctions;
  27586. var inFDEF = false, ifLevel = 0, inELSE = 0;
  27587. for (var ii = data.length; i < ii;) {
  27588. var op = data[i++];
  27589. // The TrueType instruction set docs can be found at
  27590. // https://developer.apple.com/fonts/TTRefMan/RM05/Chap5.html
  27591. if (op === 0x40) { // NPUSHB - pushes n bytes
  27592. n = data[i++];
  27593. if (inFDEF || inELSE) {
  27594. i += n;
  27595. } else {
  27596. for (j = 0; j < n; j++) {
  27597. stack.push(data[i++]);
  27598. }
  27599. }
  27600. } else if (op === 0x41) { // NPUSHW - pushes n words
  27601. n = data[i++];
  27602. if (inFDEF || inELSE) {
  27603. i += n * 2;
  27604. } else {
  27605. for (j = 0; j < n; j++) {
  27606. b = data[i++];
  27607. stack.push((b << 8) | data[i++]);
  27608. }
  27609. }
  27610. } else if ((op & 0xF8) === 0xB0) { // PUSHB - pushes bytes
  27611. n = op - 0xB0 + 1;
  27612. if (inFDEF || inELSE) {
  27613. i += n;
  27614. } else {
  27615. for (j = 0; j < n; j++) {
  27616. stack.push(data[i++]);
  27617. }
  27618. }
  27619. } else if ((op & 0xF8) === 0xB8) { // PUSHW - pushes words
  27620. n = op - 0xB8 + 1;
  27621. if (inFDEF || inELSE) {
  27622. i += n * 2;
  27623. } else {
  27624. for (j = 0; j < n; j++) {
  27625. b = data[i++];
  27626. stack.push((b << 8) | data[i++]);
  27627. }
  27628. }
  27629. } else if (op === 0x2B && !tooComplexToFollowFunctions) { // CALL
  27630. if (!inFDEF && !inELSE) {
  27631. // collecting inforamtion about which functions are used
  27632. funcId = stack[stack.length - 1];
  27633. ttContext.functionsUsed[funcId] = true;
  27634. if (funcId in ttContext.functionsStackDeltas) {
  27635. stack.length += ttContext.functionsStackDeltas[funcId];
  27636. } else if (funcId in ttContext.functionsDefined &&
  27637. functionsCalled.indexOf(funcId) < 0) {
  27638. callstack.push({data: data, i: i, stackTop: stack.length - 1});
  27639. functionsCalled.push(funcId);
  27640. pc = ttContext.functionsDefined[funcId];
  27641. if (!pc) {
  27642. warn('TT: CALL non-existent function');
  27643. ttContext.hintsValid = false;
  27644. return;
  27645. }
  27646. data = pc.data;
  27647. i = pc.i;
  27648. }
  27649. }
  27650. } else if (op === 0x2C && !tooComplexToFollowFunctions) { // FDEF
  27651. if (inFDEF || inELSE) {
  27652. warn('TT: nested FDEFs not allowed');
  27653. tooComplexToFollowFunctions = true;
  27654. }
  27655. inFDEF = true;
  27656. // collecting inforamtion about which functions are defined
  27657. lastDeff = i;
  27658. funcId = stack.pop();
  27659. ttContext.functionsDefined[funcId] = {data: data, i: i};
  27660. } else if (op === 0x2D) { // ENDF - end of function
  27661. if (inFDEF) {
  27662. inFDEF = false;
  27663. lastEndf = i;
  27664. } else {
  27665. pc = callstack.pop();
  27666. if (!pc) {
  27667. warn('TT: ENDF bad stack');
  27668. ttContext.hintsValid = false;
  27669. return;
  27670. }
  27671. funcId = functionsCalled.pop();
  27672. data = pc.data;
  27673. i = pc.i;
  27674. ttContext.functionsStackDeltas[funcId] =
  27675. stack.length - pc.stackTop;
  27676. }
  27677. } else if (op === 0x89) { // IDEF - instruction definition
  27678. if (inFDEF || inELSE) {
  27679. warn('TT: nested IDEFs not allowed');
  27680. tooComplexToFollowFunctions = true;
  27681. }
  27682. inFDEF = true;
  27683. // recording it as a function to track ENDF
  27684. lastDeff = i;
  27685. } else if (op === 0x58) { // IF
  27686. ++ifLevel;
  27687. } else if (op === 0x1B) { // ELSE
  27688. inELSE = ifLevel;
  27689. } else if (op === 0x59) { // EIF
  27690. if (inELSE === ifLevel) {
  27691. inELSE = 0;
  27692. }
  27693. --ifLevel;
  27694. } else if (op === 0x1C) { // JMPR
  27695. if (!inFDEF && !inELSE) {
  27696. var offset = stack[stack.length - 1];
  27697. // only jumping forward to prevent infinite loop
  27698. if (offset > 0) {
  27699. i += offset - 1;
  27700. }
  27701. }
  27702. }
  27703. // Adjusting stack not extactly, but just enough to get function id
  27704. if (!inFDEF && !inELSE) {
  27705. var stackDelta = op <= 0x8E ? TTOpsStackDeltas[op] :
  27706. op >= 0xC0 && op <= 0xDF ? -1 : op >= 0xE0 ? -2 : 0;
  27707. if (op >= 0x71 && op <= 0x75) {
  27708. n = stack.pop();
  27709. if (n === n) {
  27710. stackDelta = -n * 2;
  27711. }
  27712. }
  27713. while (stackDelta < 0 && stack.length > 0) {
  27714. stack.pop();
  27715. stackDelta++;
  27716. }
  27717. while (stackDelta > 0) {
  27718. stack.push(NaN); // pushing any number into stack
  27719. stackDelta--;
  27720. }
  27721. }
  27722. }
  27723. ttContext.tooComplexToFollowFunctions = tooComplexToFollowFunctions;
  27724. var content = [data];
  27725. if (i > data.length) {
  27726. content.push(new Uint8Array(i - data.length));
  27727. }
  27728. if (lastDeff > lastEndf) {
  27729. warn('TT: complementing a missing function tail');
  27730. // new function definition started, but not finished
  27731. // complete function by [CLEAR, ENDF]
  27732. content.push(new Uint8Array([0x22, 0x2D]));
  27733. }
  27734. foldTTTable(table, content);
  27735. }
  27736. function checkInvalidFunctions(ttContext, maxFunctionDefs) {
  27737. if (ttContext.tooComplexToFollowFunctions) {
  27738. return;
  27739. }
  27740. if (ttContext.functionsDefined.length > maxFunctionDefs) {
  27741. warn('TT: more functions defined than expected');
  27742. ttContext.hintsValid = false;
  27743. return;
  27744. }
  27745. for (var j = 0, jj = ttContext.functionsUsed.length; j < jj; j++) {
  27746. if (j > maxFunctionDefs) {
  27747. warn('TT: invalid function id: ' + j);
  27748. ttContext.hintsValid = false;
  27749. return;
  27750. }
  27751. if (ttContext.functionsUsed[j] && !ttContext.functionsDefined[j]) {
  27752. warn('TT: undefined function: ' + j);
  27753. ttContext.hintsValid = false;
  27754. return;
  27755. }
  27756. }
  27757. }
  27758. function foldTTTable(table, content) {
  27759. if (content.length > 1) {
  27760. // concatenating the content items
  27761. var newLength = 0;
  27762. var j, jj;
  27763. for (j = 0, jj = content.length; j < jj; j++) {
  27764. newLength += content[j].length;
  27765. }
  27766. newLength = (newLength + 3) & ~3;
  27767. var result = new Uint8Array(newLength);
  27768. var pos = 0;
  27769. for (j = 0, jj = content.length; j < jj; j++) {
  27770. result.set(content[j], pos);
  27771. pos += content[j].length;
  27772. }
  27773. table.data = result;
  27774. table.length = newLength;
  27775. }
  27776. }
  27777. function sanitizeTTPrograms(fpgm, prep, cvt) {
  27778. var ttContext = {
  27779. functionsDefined: [],
  27780. functionsUsed: [],
  27781. functionsStackDeltas: [],
  27782. tooComplexToFollowFunctions: false,
  27783. hintsValid: true
  27784. };
  27785. if (fpgm) {
  27786. sanitizeTTProgram(fpgm, ttContext);
  27787. }
  27788. if (prep) {
  27789. sanitizeTTProgram(prep, ttContext);
  27790. }
  27791. if (fpgm) {
  27792. checkInvalidFunctions(ttContext, maxFunctionDefs);
  27793. }
  27794. if (cvt && (cvt.length & 1)) {
  27795. var cvtData = new Uint8Array(cvt.length + 1);
  27796. cvtData.set(cvt.data);
  27797. cvt.data = cvtData;
  27798. }
  27799. return ttContext.hintsValid;
  27800. }
  27801. // The following steps modify the original font data, making copy
  27802. font = new Stream(new Uint8Array(font.getBytes()));
  27803. var VALID_TABLES = ['OS/2', 'cmap', 'head', 'hhea', 'hmtx', 'maxp',
  27804. 'name', 'post', 'loca', 'glyf', 'fpgm', 'prep', 'cvt ', 'CFF '];
  27805. var header = readOpenTypeHeader(font);
  27806. var numTables = header.numTables;
  27807. var cff, cffFile;
  27808. var tables = { 'OS/2': null, cmap: null, head: null, hhea: null,
  27809. hmtx: null, maxp: null, name: null, post: null };
  27810. var table;
  27811. for (var i = 0; i < numTables; i++) {
  27812. table = readTableEntry(font);
  27813. if (VALID_TABLES.indexOf(table.tag) < 0) {
  27814. continue; // skipping table if it's not a required or optional table
  27815. }
  27816. if (table.length === 0) {
  27817. continue; // skipping empty tables
  27818. }
  27819. tables[table.tag] = table;
  27820. }
  27821. var isTrueType = !tables['CFF '];
  27822. if (!isTrueType) {
  27823. // OpenType font
  27824. if ((header.version === 'OTTO' && properties.type !== 'CIDFontType2') ||
  27825. !tables.head || !tables.hhea || !tables.maxp || !tables.post) {
  27826. // no major tables: throwing everything at CFFFont
  27827. cffFile = new Stream(tables['CFF '].data);
  27828. cff = new CFFFont(cffFile, properties);
  27829. adjustWidths(properties);
  27830. return this.convert(name, cff, properties);
  27831. }
  27832. delete tables.glyf;
  27833. delete tables.loca;
  27834. delete tables.fpgm;
  27835. delete tables.prep;
  27836. delete tables['cvt '];
  27837. this.isOpenType = true;
  27838. } else {
  27839. if (!tables.loca) {
  27840. error('Required "loca" table is not found');
  27841. }
  27842. if (!tables.glyf) {
  27843. warn('Required "glyf" table is not found -- trying to recover.');
  27844. // Note: We use `sanitizeGlyphLocations` to add dummy glyf data below.
  27845. tables.glyf = {
  27846. tag: 'glyf',
  27847. data: new Uint8Array(0),
  27848. };
  27849. }
  27850. this.isOpenType = false;
  27851. }
  27852. if (!tables.maxp) {
  27853. error('Required "maxp" table is not found');
  27854. }
  27855. font.pos = (font.start || 0) + tables.maxp.offset;
  27856. var version = font.getInt32();
  27857. var numGlyphs = font.getUint16();
  27858. var maxFunctionDefs = 0;
  27859. if (version >= 0x00010000 && tables.maxp.length >= 22) {
  27860. // maxZones can be invalid
  27861. font.pos += 8;
  27862. var maxZones = font.getUint16();
  27863. if (maxZones > 2) { // reset to 2 if font has invalid maxZones
  27864. tables.maxp.data[14] = 0;
  27865. tables.maxp.data[15] = 2;
  27866. }
  27867. font.pos += 4;
  27868. maxFunctionDefs = font.getUint16();
  27869. }
  27870. var dupFirstEntry = false;
  27871. if (properties.type === 'CIDFontType2' && properties.toUnicode &&
  27872. properties.toUnicode.get(0) > '\u0000') {
  27873. // oracle's defect (see 3427), duplicating first entry
  27874. dupFirstEntry = true;
  27875. numGlyphs++;
  27876. tables.maxp.data[4] = numGlyphs >> 8;
  27877. tables.maxp.data[5] = numGlyphs & 255;
  27878. }
  27879. var hintsValid = sanitizeTTPrograms(tables.fpgm, tables.prep,
  27880. tables['cvt '], maxFunctionDefs);
  27881. if (!hintsValid) {
  27882. delete tables.fpgm;
  27883. delete tables.prep;
  27884. delete tables['cvt '];
  27885. }
  27886. // Ensure the hmtx table contains the advance width and
  27887. // sidebearings information for numGlyphs in the maxp table
  27888. sanitizeMetrics(font, tables.hhea, tables.hmtx, numGlyphs);
  27889. if (!tables.head) {
  27890. error('Required "head" table is not found');
  27891. }
  27892. sanitizeHead(tables.head, numGlyphs, isTrueType ? tables.loca.length : 0);
  27893. var missingGlyphs = {};
  27894. if (isTrueType) {
  27895. var isGlyphLocationsLong = int16(tables.head.data[50],
  27896. tables.head.data[51]);
  27897. missingGlyphs = sanitizeGlyphLocations(tables.loca, tables.glyf,
  27898. numGlyphs, isGlyphLocationsLong,
  27899. hintsValid, dupFirstEntry);
  27900. }
  27901. if (!tables.hhea) {
  27902. error('Required "hhea" table is not found');
  27903. }
  27904. // Sanitizer reduces the glyph advanceWidth to the maxAdvanceWidth
  27905. // Sometimes it's 0. That needs to be fixed
  27906. if (tables.hhea.data[10] === 0 && tables.hhea.data[11] === 0) {
  27907. tables.hhea.data[10] = 0xFF;
  27908. tables.hhea.data[11] = 0xFF;
  27909. }
  27910. // Extract some more font properties from the OpenType head and
  27911. // hhea tables; yMin and descent value are always negative.
  27912. var metricsOverride = {
  27913. unitsPerEm: int16(tables.head.data[18], tables.head.data[19]),
  27914. yMax: int16(tables.head.data[42], tables.head.data[43]),
  27915. yMin: int16(tables.head.data[38], tables.head.data[39]) - 0x10000,
  27916. ascent: int16(tables.hhea.data[4], tables.hhea.data[5]),
  27917. descent: int16(tables.hhea.data[6], tables.hhea.data[7]) - 0x10000
  27918. };
  27919. // PDF FontDescriptor metrics lie -- using data from actual font.
  27920. this.ascent = metricsOverride.ascent / metricsOverride.unitsPerEm;
  27921. this.descent = metricsOverride.descent / metricsOverride.unitsPerEm;
  27922. // The 'post' table has glyphs names.
  27923. if (tables.post) {
  27924. var valid = readPostScriptTable(tables.post, properties, numGlyphs);
  27925. if (!valid) {
  27926. tables.post = null;
  27927. }
  27928. }
  27929. var charCodeToGlyphId = [], charCode;
  27930. var toUnicode = properties.toUnicode, widths = properties.widths;
  27931. var skipToUnicode = (toUnicode instanceof IdentityToUnicodeMap ||
  27932. toUnicode.length === 0x10000);
  27933. // Helper function to try to skip mapping of empty glyphs.
  27934. // Note: In some cases, just relying on the glyph data doesn't work,
  27935. // hence we also use a few heuristics to fix various PDF files.
  27936. function hasGlyph(glyphId, charCode, widthCode) {
  27937. if (!missingGlyphs[glyphId]) {
  27938. return true;
  27939. }
  27940. if (!skipToUnicode && charCode >= 0 && toUnicode.has(charCode)) {
  27941. return true;
  27942. }
  27943. if (widths && widthCode >= 0 && isNum(widths[widthCode])) {
  27944. return true;
  27945. }
  27946. return false;
  27947. }
  27948. if (properties.type === 'CIDFontType2') {
  27949. var cidToGidMap = properties.cidToGidMap || [];
  27950. var isCidToGidMapEmpty = cidToGidMap.length === 0;
  27951. properties.cMap.forEach(function(charCode, cid) {
  27952. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  27953. var glyphId = -1;
  27954. if (isCidToGidMapEmpty) {
  27955. glyphId = charCode;
  27956. } else if (cidToGidMap[cid] !== undefined) {
  27957. glyphId = cidToGidMap[cid];
  27958. }
  27959. if (glyphId >= 0 && glyphId < numGlyphs &&
  27960. hasGlyph(glyphId, charCode, cid)) {
  27961. charCodeToGlyphId[charCode] = glyphId;
  27962. }
  27963. });
  27964. if (dupFirstEntry) {
  27965. charCodeToGlyphId[0] = numGlyphs - 1;
  27966. }
  27967. } else {
  27968. // Most of the following logic in this code branch is based on the
  27969. // 9.6.6.4 of the PDF spec.
  27970. var hasEncoding =
  27971. properties.differences.length > 0 || !!properties.baseEncodingName;
  27972. var cmapTable =
  27973. readCmapTable(tables.cmap, font, this.isSymbolicFont, hasEncoding);
  27974. var cmapPlatformId = cmapTable.platformId;
  27975. var cmapEncodingId = cmapTable.encodingId;
  27976. var cmapMappings = cmapTable.mappings;
  27977. var cmapMappingsLength = cmapMappings.length;
  27978. // The spec seems to imply that if the font is symbolic the encoding
  27979. // should be ignored, this doesn't appear to work for 'preistabelle.pdf'
  27980. // where the the font is symbolic and it has an encoding.
  27981. if (hasEncoding &&
  27982. (cmapPlatformId === 3 && cmapEncodingId === 1 ||
  27983. cmapPlatformId === 1 && cmapEncodingId === 0) ||
  27984. (cmapPlatformId === -1 && cmapEncodingId === -1 && // Temporary hack
  27985. !!Encodings[properties.baseEncodingName])) { // Temporary hack
  27986. // When no preferred cmap table was found and |baseEncodingName| is
  27987. // one of the predefined encodings, we seem to obtain a better
  27988. // |charCodeToGlyphId| map from the code below (fixes bug 1057544).
  27989. // TODO: Note that this is a hack which should be removed as soon as
  27990. // we have proper support for more exotic cmap tables.
  27991. var baseEncoding = [];
  27992. if (properties.baseEncodingName === 'MacRomanEncoding' ||
  27993. properties.baseEncodingName === 'WinAnsiEncoding') {
  27994. baseEncoding = Encodings[properties.baseEncodingName];
  27995. }
  27996. for (charCode = 0; charCode < 256; charCode++) {
  27997. var glyphName;
  27998. if (this.differences && charCode in this.differences) {
  27999. glyphName = this.differences[charCode];
  28000. } else if (charCode in baseEncoding &&
  28001. baseEncoding[charCode] !== '') {
  28002. glyphName = baseEncoding[charCode];
  28003. } else {
  28004. glyphName = Encodings.StandardEncoding[charCode];
  28005. }
  28006. if (!glyphName) {
  28007. continue;
  28008. }
  28009. var unicodeOrCharCode, isUnicode = false;
  28010. if (cmapPlatformId === 3 && cmapEncodingId === 1) {
  28011. unicodeOrCharCode = GlyphsUnicode[glyphName];
  28012. isUnicode = true;
  28013. } else if (cmapPlatformId === 1 && cmapEncodingId === 0) {
  28014. // TODO: the encoding needs to be updated with mac os table.
  28015. unicodeOrCharCode = Encodings.MacRomanEncoding.indexOf(glyphName);
  28016. }
  28017. var found = false;
  28018. for (i = 0; i < cmapMappingsLength; ++i) {
  28019. if (cmapMappings[i].charCode !== unicodeOrCharCode) {
  28020. continue;
  28021. }
  28022. var code = isUnicode ? charCode : unicodeOrCharCode;
  28023. if (hasGlyph(cmapMappings[i].glyphId, code, -1)) {
  28024. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  28025. found = true;
  28026. break;
  28027. }
  28028. }
  28029. if (!found && properties.glyphNames) {
  28030. // Try to map using the post table.
  28031. var glyphId = properties.glyphNames.indexOf(glyphName);
  28032. if (glyphId > 0 && hasGlyph(glyphId, -1, -1)) {
  28033. charCodeToGlyphId[charCode] = glyphId;
  28034. found = true;
  28035. }
  28036. }
  28037. if (!found) {
  28038. charCodeToGlyphId[charCode] = 0; // notdef
  28039. }
  28040. }
  28041. } else if (cmapPlatformId === 0 && cmapEncodingId === 0) {
  28042. // Default Unicode semantics, use the charcodes as is.
  28043. for (i = 0; i < cmapMappingsLength; ++i) {
  28044. charCodeToGlyphId[cmapMappings[i].charCode] =
  28045. cmapMappings[i].glyphId;
  28046. }
  28047. } else {
  28048. // For (3, 0) cmap tables:
  28049. // The charcode key being stored in charCodeToGlyphId is the lower
  28050. // byte of the two-byte charcodes of the cmap table since according to
  28051. // the spec: 'each byte from the string shall be prepended with the
  28052. // high byte of the range [of charcodes in the cmap table], to form
  28053. // a two-byte character, which shall be used to select the
  28054. // associated glyph description from the subtable'.
  28055. //
  28056. // For (1, 0) cmap tables:
  28057. // 'single bytes from the string shall be used to look up the
  28058. // associated glyph descriptions from the subtable'. This means
  28059. // charcodes in the cmap will be single bytes, so no-op since
  28060. // glyph.charCode & 0xFF === glyph.charCode
  28061. for (i = 0; i < cmapMappingsLength; ++i) {
  28062. charCode = cmapMappings[i].charCode & 0xFF;
  28063. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  28064. }
  28065. }
  28066. }
  28067. if (charCodeToGlyphId.length === 0) {
  28068. // defines at least one glyph
  28069. charCodeToGlyphId[0] = 0;
  28070. }
  28071. // Converting glyphs and ids into font's cmap table
  28072. var newMapping = adjustMapping(charCodeToGlyphId, properties);
  28073. this.toFontChar = newMapping.toFontChar;
  28074. tables.cmap = {
  28075. tag: 'cmap',
  28076. data: createCmapTable(newMapping.charCodeToGlyphId, numGlyphs)
  28077. };
  28078. if (!tables['OS/2'] || !validateOS2Table(tables['OS/2'])) {
  28079. tables['OS/2'] = {
  28080. tag: 'OS/2',
  28081. data: createOS2Table(properties, newMapping.charCodeToGlyphId,
  28082. metricsOverride)
  28083. };
  28084. }
  28085. // Rewrite the 'post' table if needed
  28086. if (!tables.post) {
  28087. tables.post = {
  28088. tag: 'post',
  28089. data: createPostTable(properties)
  28090. };
  28091. }
  28092. if (!isTrueType) {
  28093. try {
  28094. // Trying to repair CFF file
  28095. cffFile = new Stream(tables['CFF '].data);
  28096. var parser = new CFFParser(cffFile, properties);
  28097. cff = parser.parse();
  28098. var compiler = new CFFCompiler(cff);
  28099. tables['CFF '].data = compiler.compile();
  28100. } catch (e) {
  28101. warn('Failed to compile font ' + properties.loadedName);
  28102. }
  28103. }
  28104. // Re-creating 'name' table
  28105. if (!tables.name) {
  28106. tables.name = {
  28107. tag: 'name',
  28108. data: createNameTable(this.name)
  28109. };
  28110. } else {
  28111. // ... using existing 'name' table as prototype
  28112. var namePrototype = readNameTable(tables.name);
  28113. tables.name.data = createNameTable(name, namePrototype);
  28114. }
  28115. var builder = new OpenTypeFileBuilder(header.version);
  28116. for (var tableTag in tables) {
  28117. builder.addTable(tableTag, tables[tableTag].data);
  28118. }
  28119. return builder.toArray();
  28120. },
  28121. convert: function Font_convert(fontName, font, properties) {
  28122. // TODO: Check the charstring widths to determine this.
  28123. properties.fixedPitch = false;
  28124. var mapping = font.getGlyphMapping(properties);
  28125. var newMapping = adjustMapping(mapping, properties);
  28126. this.toFontChar = newMapping.toFontChar;
  28127. var numGlyphs = font.numGlyphs;
  28128. function getCharCodes(charCodeToGlyphId, glyphId) {
  28129. var charCodes = null;
  28130. for (var charCode in charCodeToGlyphId) {
  28131. if (glyphId === charCodeToGlyphId[charCode]) {
  28132. if (!charCodes) {
  28133. charCodes = [];
  28134. }
  28135. charCodes.push(charCode | 0);
  28136. }
  28137. }
  28138. return charCodes;
  28139. }
  28140. function createCharCode(charCodeToGlyphId, glyphId) {
  28141. for (var charCode in charCodeToGlyphId) {
  28142. if (glyphId === charCodeToGlyphId[charCode]) {
  28143. return charCode | 0;
  28144. }
  28145. }
  28146. newMapping.charCodeToGlyphId[newMapping.nextAvailableFontCharCode] =
  28147. glyphId;
  28148. return newMapping.nextAvailableFontCharCode++;
  28149. }
  28150. var seacs = font.seacs;
  28151. if (SEAC_ANALYSIS_ENABLED && seacs && seacs.length) {
  28152. var matrix = properties.fontMatrix || FONT_IDENTITY_MATRIX;
  28153. var charset = font.getCharset();
  28154. var seacMap = Object.create(null);
  28155. for (var glyphId in seacs) {
  28156. glyphId |= 0;
  28157. var seac = seacs[glyphId];
  28158. var baseGlyphName = Encodings.StandardEncoding[seac[2]];
  28159. var accentGlyphName = Encodings.StandardEncoding[seac[3]];
  28160. var baseGlyphId = charset.indexOf(baseGlyphName);
  28161. var accentGlyphId = charset.indexOf(accentGlyphName);
  28162. if (baseGlyphId < 0 || accentGlyphId < 0) {
  28163. continue;
  28164. }
  28165. var accentOffset = {
  28166. x: seac[0] * matrix[0] + seac[1] * matrix[2] + matrix[4],
  28167. y: seac[0] * matrix[1] + seac[1] * matrix[3] + matrix[5]
  28168. };
  28169. var charCodes = getCharCodes(mapping, glyphId);
  28170. if (!charCodes) {
  28171. // There's no point in mapping it if the char code was never mapped
  28172. // to begin with.
  28173. continue;
  28174. }
  28175. for (var i = 0, ii = charCodes.length; i < ii; i++) {
  28176. var charCode = charCodes[i];
  28177. // Find a fontCharCode that maps to the base and accent glyphs.
  28178. // If one doesn't exists, create it.
  28179. var charCodeToGlyphId = newMapping.charCodeToGlyphId;
  28180. var baseFontCharCode = createCharCode(charCodeToGlyphId,
  28181. baseGlyphId);
  28182. var accentFontCharCode = createCharCode(charCodeToGlyphId,
  28183. accentGlyphId);
  28184. seacMap[charCode] = {
  28185. baseFontCharCode: baseFontCharCode,
  28186. accentFontCharCode: accentFontCharCode,
  28187. accentOffset: accentOffset
  28188. };
  28189. }
  28190. }
  28191. properties.seacMap = seacMap;
  28192. }
  28193. var unitsPerEm = 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0];
  28194. var builder = new OpenTypeFileBuilder('\x4F\x54\x54\x4F');
  28195. // PostScript Font Program
  28196. builder.addTable('CFF ', font.data);
  28197. // OS/2 and Windows Specific metrics
  28198. builder.addTable('OS/2', createOS2Table(properties,
  28199. newMapping.charCodeToGlyphId));
  28200. // Character to glyphs mapping
  28201. builder.addTable('cmap', createCmapTable(newMapping.charCodeToGlyphId,
  28202. numGlyphs));
  28203. // Font header
  28204. builder.addTable('head',
  28205. '\x00\x01\x00\x00' + // Version number
  28206. '\x00\x00\x10\x00' + // fontRevision
  28207. '\x00\x00\x00\x00' + // checksumAdjustement
  28208. '\x5F\x0F\x3C\xF5' + // magicNumber
  28209. '\x00\x00' + // Flags
  28210. safeString16(unitsPerEm) + // unitsPerEM
  28211. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // creation date
  28212. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // modifification date
  28213. '\x00\x00' + // xMin
  28214. safeString16(properties.descent) + // yMin
  28215. '\x0F\xFF' + // xMax
  28216. safeString16(properties.ascent) + // yMax
  28217. string16(properties.italicAngle ? 2 : 0) + // macStyle
  28218. '\x00\x11' + // lowestRecPPEM
  28219. '\x00\x00' + // fontDirectionHint
  28220. '\x00\x00' + // indexToLocFormat
  28221. '\x00\x00'); // glyphDataFormat
  28222. // Horizontal header
  28223. builder.addTable('hhea',
  28224. '\x00\x01\x00\x00' + // Version number
  28225. safeString16(properties.ascent) + // Typographic Ascent
  28226. safeString16(properties.descent) + // Typographic Descent
  28227. '\x00\x00' + // Line Gap
  28228. '\xFF\xFF' + // advanceWidthMax
  28229. '\x00\x00' + // minLeftSidebearing
  28230. '\x00\x00' + // minRightSidebearing
  28231. '\x00\x00' + // xMaxExtent
  28232. safeString16(properties.capHeight) + // caretSlopeRise
  28233. safeString16(Math.tan(properties.italicAngle) *
  28234. properties.xHeight) + // caretSlopeRun
  28235. '\x00\x00' + // caretOffset
  28236. '\x00\x00' + // -reserved-
  28237. '\x00\x00' + // -reserved-
  28238. '\x00\x00' + // -reserved-
  28239. '\x00\x00' + // -reserved-
  28240. '\x00\x00' + // metricDataFormat
  28241. string16(numGlyphs)); // Number of HMetrics
  28242. // Horizontal metrics
  28243. builder.addTable('hmtx', (function fontFieldsHmtx() {
  28244. var charstrings = font.charstrings;
  28245. var cffWidths = font.cff ? font.cff.widths : null;
  28246. var hmtx = '\x00\x00\x00\x00'; // Fake .notdef
  28247. for (var i = 1, ii = numGlyphs; i < ii; i++) {
  28248. var width = 0;
  28249. if (charstrings) {
  28250. var charstring = charstrings[i - 1];
  28251. width = 'width' in charstring ? charstring.width : 0;
  28252. } else if (cffWidths) {
  28253. width = Math.ceil(cffWidths[i] || 0);
  28254. }
  28255. hmtx += string16(width) + string16(0);
  28256. }
  28257. return hmtx;
  28258. })());
  28259. // Maximum profile
  28260. builder.addTable('maxp',
  28261. '\x00\x00\x50\x00' + // Version number
  28262. string16(numGlyphs)); // Num of glyphs
  28263. // Naming tables
  28264. builder.addTable('name', createNameTable(fontName));
  28265. // PostScript informations
  28266. builder.addTable('post', createPostTable(properties));
  28267. return builder.toArray();
  28268. },
  28269. /**
  28270. * Builds a char code to unicode map based on section 9.10 of the spec.
  28271. * @param {Object} properties Font properties object.
  28272. * @return {Object} A ToUnicodeMap object.
  28273. */
  28274. buildToUnicode: function Font_buildToUnicode(properties) {
  28275. // Section 9.10.2 Mapping Character Codes to Unicode Values
  28276. if (properties.toUnicode && properties.toUnicode.length !== 0) {
  28277. return properties.toUnicode;
  28278. }
  28279. // According to the spec if the font is a simple font we should only map
  28280. // to unicode if the base encoding is MacRoman, MacExpert, or WinAnsi or
  28281. // the differences array only contains adobe standard or symbol set names,
  28282. // in pratice it seems better to always try to create a toUnicode
  28283. // map based of the default encoding.
  28284. var toUnicode, charcode;
  28285. if (!properties.composite /* is simple font */) {
  28286. toUnicode = [];
  28287. var encoding = properties.defaultEncoding.slice();
  28288. var baseEncodingName = properties.baseEncodingName;
  28289. // Merge in the differences array.
  28290. var differences = properties.differences;
  28291. for (charcode in differences) {
  28292. encoding[charcode] = differences[charcode];
  28293. }
  28294. for (charcode in encoding) {
  28295. // a) Map the character code to a character name.
  28296. var glyphName = encoding[charcode];
  28297. // b) Look up the character name in the Adobe Glyph List (see the
  28298. // Bibliography) to obtain the corresponding Unicode value.
  28299. if (glyphName === '') {
  28300. continue;
  28301. } else if (GlyphsUnicode[glyphName] === undefined) {
  28302. // (undocumented) c) Few heuristics to recognize unknown glyphs
  28303. // NOTE: Adobe Reader does not do this step, but OSX Preview does
  28304. var code = 0;
  28305. switch (glyphName[0]) {
  28306. case 'G': // Gxx glyph
  28307. if (glyphName.length === 3) {
  28308. code = parseInt(glyphName.substr(1), 16);
  28309. }
  28310. break;
  28311. case 'g': // g00xx glyph
  28312. if (glyphName.length === 5) {
  28313. code = parseInt(glyphName.substr(1), 16);
  28314. }
  28315. break;
  28316. case 'C': // Cddd glyph
  28317. case 'c': // cddd glyph
  28318. if (glyphName.length >= 3) {
  28319. code = +glyphName.substr(1);
  28320. }
  28321. break;
  28322. }
  28323. if (code) {
  28324. // If |baseEncodingName| is one the predefined encodings,
  28325. // and |code| equals |charcode|, using the glyph defined in the
  28326. // baseEncoding seems to yield a better |toUnicode| mapping
  28327. // (fixes issue 5070).
  28328. if (baseEncodingName && code === +charcode) {
  28329. var baseEncoding = Encodings[baseEncodingName];
  28330. if (baseEncoding && (glyphName = baseEncoding[charcode])) {
  28331. toUnicode[charcode] =
  28332. String.fromCharCode(GlyphsUnicode[glyphName]);
  28333. continue;
  28334. }
  28335. }
  28336. toUnicode[charcode] = String.fromCharCode(code);
  28337. }
  28338. continue;
  28339. }
  28340. toUnicode[charcode] = String.fromCharCode(GlyphsUnicode[glyphName]);
  28341. }
  28342. return new ToUnicodeMap(toUnicode);
  28343. }
  28344. // If the font is a composite font that uses one of the predefined CMaps
  28345. // listed in Table 118 (except Identity–H and Identity–V) or whose
  28346. // descendant CIDFont uses the Adobe-GB1, Adobe-CNS1, Adobe-Japan1, or
  28347. // Adobe-Korea1 character collection:
  28348. if (properties.composite && (
  28349. (properties.cMap.builtInCMap &&
  28350. !(properties.cMap instanceof IdentityCMap)) ||
  28351. (properties.cidSystemInfo.registry === 'Adobe' &&
  28352. (properties.cidSystemInfo.ordering === 'GB1' ||
  28353. properties.cidSystemInfo.ordering === 'CNS1' ||
  28354. properties.cidSystemInfo.ordering === 'Japan1' ||
  28355. properties.cidSystemInfo.ordering === 'Korea1')))) {
  28356. // Then:
  28357. // a) Map the character code to a character identifier (CID) according
  28358. // to the font’s CMap.
  28359. // b) Obtain the registry and ordering of the character collection used
  28360. // by the font’s CMap (for example, Adobe and Japan1) from its
  28361. // CIDSystemInfo dictionary.
  28362. var registry = properties.cidSystemInfo.registry;
  28363. var ordering = properties.cidSystemInfo.ordering;
  28364. // c) Construct a second CMap name by concatenating the registry and
  28365. // ordering obtained in step (b) in the format registry–ordering–UCS2
  28366. // (for example, Adobe–Japan1–UCS2).
  28367. var ucs2CMapName = new Name(registry + '-' + ordering + '-UCS2');
  28368. // d) Obtain the CMap with the name constructed in step (c) (available
  28369. // from the ASN Web site; see the Bibliography).
  28370. var ucs2CMap = CMapFactory.create(ucs2CMapName,
  28371. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  28372. var cMap = properties.cMap;
  28373. toUnicode = [];
  28374. cMap.forEach(function(charcode, cid) {
  28375. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  28376. // e) Map the CID obtained in step (a) according to the CMap obtained
  28377. // in step (d), producing a Unicode value.
  28378. var ucs2 = ucs2CMap.lookup(cid);
  28379. if (ucs2) {
  28380. toUnicode[charcode] =
  28381. String.fromCharCode((ucs2.charCodeAt(0) << 8) +
  28382. ucs2.charCodeAt(1));
  28383. }
  28384. });
  28385. return new ToUnicodeMap(toUnicode);
  28386. }
  28387. // The viewer's choice, just use an identity map.
  28388. return new IdentityToUnicodeMap(properties.firstChar,
  28389. properties.lastChar);
  28390. },
  28391. get spaceWidth() {
  28392. if ('_shadowWidth' in this) {
  28393. return this._shadowWidth;
  28394. }
  28395. // trying to estimate space character width
  28396. var possibleSpaceReplacements = ['space', 'minus', 'one', 'i'];
  28397. var width;
  28398. for (var i = 0, ii = possibleSpaceReplacements.length; i < ii; i++) {
  28399. var glyphName = possibleSpaceReplacements[i];
  28400. // if possible, getting width by glyph name
  28401. if (glyphName in this.widths) {
  28402. width = this.widths[glyphName];
  28403. break;
  28404. }
  28405. var glyphUnicode = GlyphsUnicode[glyphName];
  28406. // finding the charcode via unicodeToCID map
  28407. var charcode = 0;
  28408. if (this.composite) {
  28409. if (this.cMap.contains(glyphUnicode)) {
  28410. charcode = this.cMap.lookup(glyphUnicode);
  28411. }
  28412. }
  28413. // ... via toUnicode map
  28414. if (!charcode && this.toUnicode) {
  28415. charcode = this.toUnicode.charCodeOf(glyphUnicode);
  28416. }
  28417. // setting it to unicode if negative or undefined
  28418. if (charcode <= 0) {
  28419. charcode = glyphUnicode;
  28420. }
  28421. // trying to get width via charcode
  28422. width = this.widths[charcode];
  28423. if (width) {
  28424. break; // the non-zero width found
  28425. }
  28426. }
  28427. width = width || this.defaultWidth;
  28428. // Do not shadow the property here. See discussion:
  28429. // https://github.com/mozilla/pdf.js/pull/2127#discussion_r1662280
  28430. this._shadowWidth = width;
  28431. return width;
  28432. },
  28433. charToGlyph: function Font_charToGlyph(charcode, isSpace) {
  28434. var fontCharCode, width, operatorListId;
  28435. var widthCode = charcode;
  28436. if (this.cMap && this.cMap.contains(charcode)) {
  28437. widthCode = this.cMap.lookup(charcode);
  28438. }
  28439. width = this.widths[widthCode];
  28440. width = isNum(width) ? width : this.defaultWidth;
  28441. var vmetric = this.vmetrics && this.vmetrics[widthCode];
  28442. var unicode = this.toUnicode.get(charcode) || charcode;
  28443. if (typeof unicode === 'number') {
  28444. unicode = String.fromCharCode(unicode);
  28445. }
  28446. // First try the toFontChar map, if it's not there then try falling
  28447. // back to the char code.
  28448. fontCharCode = this.toFontChar[charcode] || charcode;
  28449. if (this.missingFile) {
  28450. fontCharCode = mapSpecialUnicodeValues(fontCharCode);
  28451. }
  28452. if (this.isType3Font) {
  28453. // Font char code in this case is actually a glyph name.
  28454. operatorListId = fontCharCode;
  28455. }
  28456. var accent = null;
  28457. if (this.seacMap && this.seacMap[charcode]) {
  28458. var seac = this.seacMap[charcode];
  28459. fontCharCode = seac.baseFontCharCode;
  28460. accent = {
  28461. fontChar: String.fromCharCode(seac.accentFontCharCode),
  28462. offset: seac.accentOffset
  28463. };
  28464. }
  28465. var fontChar = String.fromCharCode(fontCharCode);
  28466. var glyph = this.glyphCache[charcode];
  28467. if (!glyph ||
  28468. !glyph.matchesForCache(fontChar, unicode, accent, width, vmetric,
  28469. operatorListId, isSpace)) {
  28470. glyph = new Glyph(fontChar, unicode, accent, width, vmetric,
  28471. operatorListId, isSpace);
  28472. this.glyphCache[charcode] = glyph;
  28473. }
  28474. return glyph;
  28475. },
  28476. charsToGlyphs: function Font_charsToGlyphs(chars) {
  28477. var charsCache = this.charsCache;
  28478. var glyphs, glyph, charcode;
  28479. // if we translated this string before, just grab it from the cache
  28480. if (charsCache) {
  28481. glyphs = charsCache[chars];
  28482. if (glyphs) {
  28483. return glyphs;
  28484. }
  28485. }
  28486. // lazily create the translation cache
  28487. if (!charsCache) {
  28488. charsCache = this.charsCache = Object.create(null);
  28489. }
  28490. glyphs = [];
  28491. var charsCacheKey = chars;
  28492. var i = 0, ii;
  28493. if (this.cMap) {
  28494. // composite fonts have multi-byte strings convert the string from
  28495. // single-byte to multi-byte
  28496. var c = {};
  28497. while (i < chars.length) {
  28498. this.cMap.readCharCode(chars, i, c);
  28499. charcode = c.charcode;
  28500. var length = c.length;
  28501. i += length;
  28502. // Space is char with code 0x20 and length 1 in multiple-byte codes.
  28503. var isSpace = length === 1 && chars.charCodeAt(i - 1) === 0x20;
  28504. glyph = this.charToGlyph(charcode, isSpace);
  28505. glyphs.push(glyph);
  28506. }
  28507. } else {
  28508. for (i = 0, ii = chars.length; i < ii; ++i) {
  28509. charcode = chars.charCodeAt(i);
  28510. glyph = this.charToGlyph(charcode, charcode === 0x20);
  28511. glyphs.push(glyph);
  28512. }
  28513. }
  28514. // Enter the translated string into the cache
  28515. return (charsCache[charsCacheKey] = glyphs);
  28516. }
  28517. };
  28518. return Font;
  28519. })();
  28520. var ErrorFont = (function ErrorFontClosure() {
  28521. function ErrorFont(error) {
  28522. this.error = error;
  28523. this.loadedName = 'g_font_error';
  28524. this.loading = false;
  28525. }
  28526. ErrorFont.prototype = {
  28527. charsToGlyphs: function ErrorFont_charsToGlyphs() {
  28528. return [];
  28529. },
  28530. exportData: function ErrorFont_exportData() {
  28531. return {error: this.error};
  28532. }
  28533. };
  28534. return ErrorFont;
  28535. })();
  28536. /**
  28537. * Shared logic for building a char code to glyph id mapping for Type1 and
  28538. * simple CFF fonts. See section 9.6.6.2 of the spec.
  28539. * @param {Object} properties Font properties object.
  28540. * @param {Object} builtInEncoding The encoding contained within the actual font
  28541. * data.
  28542. * @param {Array} Array of glyph names where the index is the glyph ID.
  28543. * @returns {Object} A char code to glyph ID map.
  28544. */
  28545. function type1FontGlyphMapping(properties, builtInEncoding, glyphNames) {
  28546. var charCodeToGlyphId = Object.create(null);
  28547. var glyphId, charCode, baseEncoding;
  28548. if (properties.baseEncodingName) {
  28549. // If a valid base encoding name was used, the mapping is initialized with
  28550. // that.
  28551. baseEncoding = Encodings[properties.baseEncodingName];
  28552. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  28553. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  28554. if (glyphId >= 0) {
  28555. charCodeToGlyphId[charCode] = glyphId;
  28556. } else {
  28557. charCodeToGlyphId[charCode] = 0; // notdef
  28558. }
  28559. }
  28560. } else if (!!(properties.flags & FontFlags.Symbolic)) {
  28561. // For a symbolic font the encoding should be the fonts built-in
  28562. // encoding.
  28563. for (charCode in builtInEncoding) {
  28564. charCodeToGlyphId[charCode] = builtInEncoding[charCode];
  28565. }
  28566. } else {
  28567. // For non-symbolic fonts that don't have a base encoding the standard
  28568. // encoding should be used.
  28569. baseEncoding = Encodings.StandardEncoding;
  28570. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  28571. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  28572. if (glyphId >= 0) {
  28573. charCodeToGlyphId[charCode] = glyphId;
  28574. } else {
  28575. charCodeToGlyphId[charCode] = 0; // notdef
  28576. }
  28577. }
  28578. }
  28579. // Lastly, merge in the differences.
  28580. var differences = properties.differences;
  28581. if (differences) {
  28582. for (charCode in differences) {
  28583. var glyphName = differences[charCode];
  28584. glyphId = glyphNames.indexOf(glyphName);
  28585. if (glyphId >= 0) {
  28586. charCodeToGlyphId[charCode] = glyphId;
  28587. } else {
  28588. charCodeToGlyphId[charCode] = 0; // notdef
  28589. }
  28590. }
  28591. }
  28592. return charCodeToGlyphId;
  28593. }
  28594. /*
  28595. * CharStrings are encoded following the the CharString Encoding sequence
  28596. * describe in Chapter 6 of the "Adobe Type1 Font Format" specification.
  28597. * The value in a byte indicates a command, a number, or subsequent bytes
  28598. * that are to be interpreted in a special way.
  28599. *
  28600. * CharString Number Encoding:
  28601. * A CharString byte containing the values from 32 through 255 inclusive
  28602. * indicate an integer. These values are decoded in four ranges.
  28603. *
  28604. * 1. A CharString byte containing a value, v, between 32 and 246 inclusive,
  28605. * indicate the integer v - 139. Thus, the integer values from -107 through
  28606. * 107 inclusive may be encoded in single byte.
  28607. *
  28608. * 2. A CharString byte containing a value, v, between 247 and 250 inclusive,
  28609. * indicates an integer involving the next byte, w, according to the formula:
  28610. * [(v - 247) x 256] + w + 108
  28611. *
  28612. * 3. A CharString byte containing a value, v, between 251 and 254 inclusive,
  28613. * indicates an integer involving the next byte, w, according to the formula:
  28614. * -[(v - 251) * 256] - w - 108
  28615. *
  28616. * 4. A CharString containing the value 255 indicates that the next 4 bytes
  28617. * are a two complement signed integer. The first of these bytes contains the
  28618. * highest order bits, the second byte contains the next higher order bits
  28619. * and the fourth byte contain the lowest order bits.
  28620. *
  28621. *
  28622. * CharString Command Encoding:
  28623. * CharStrings commands are encoded in 1 or 2 bytes.
  28624. *
  28625. * Single byte commands are encoded in 1 byte that contains a value between
  28626. * 0 and 31 inclusive.
  28627. * If a command byte contains the value 12, then the value in the next byte
  28628. * indicates a command. This "escape" mechanism allows many extra commands
  28629. * to be encoded and this encoding technique helps to minimize the length of
  28630. * the charStrings.
  28631. */
  28632. var Type1CharString = (function Type1CharStringClosure() {
  28633. var COMMAND_MAP = {
  28634. 'hstem': [1],
  28635. 'vstem': [3],
  28636. 'vmoveto': [4],
  28637. 'rlineto': [5],
  28638. 'hlineto': [6],
  28639. 'vlineto': [7],
  28640. 'rrcurveto': [8],
  28641. 'callsubr': [10],
  28642. 'flex': [12, 35],
  28643. 'drop' : [12, 18],
  28644. 'endchar': [14],
  28645. 'rmoveto': [21],
  28646. 'hmoveto': [22],
  28647. 'vhcurveto': [30],
  28648. 'hvcurveto': [31]
  28649. };
  28650. function Type1CharString() {
  28651. this.width = 0;
  28652. this.lsb = 0;
  28653. this.flexing = false;
  28654. this.output = [];
  28655. this.stack = [];
  28656. }
  28657. Type1CharString.prototype = {
  28658. convert: function Type1CharString_convert(encoded, subrs) {
  28659. var count = encoded.length;
  28660. var error = false;
  28661. var wx, sbx, subrNumber;
  28662. for (var i = 0; i < count; i++) {
  28663. var value = encoded[i];
  28664. if (value < 32) {
  28665. if (value === 12) {
  28666. value = (value << 8) + encoded[++i];
  28667. }
  28668. switch (value) {
  28669. case 1: // hstem
  28670. if (!HINTING_ENABLED) {
  28671. this.stack = [];
  28672. break;
  28673. }
  28674. error = this.executeCommand(2, COMMAND_MAP.hstem);
  28675. break;
  28676. case 3: // vstem
  28677. if (!HINTING_ENABLED) {
  28678. this.stack = [];
  28679. break;
  28680. }
  28681. error = this.executeCommand(2, COMMAND_MAP.vstem);
  28682. break;
  28683. case 4: // vmoveto
  28684. if (this.flexing) {
  28685. if (this.stack.length < 1) {
  28686. error = true;
  28687. break;
  28688. }
  28689. // Add the dx for flex and but also swap the values so they are
  28690. // the right order.
  28691. var dy = this.stack.pop();
  28692. this.stack.push(0, dy);
  28693. break;
  28694. }
  28695. error = this.executeCommand(1, COMMAND_MAP.vmoveto);
  28696. break;
  28697. case 5: // rlineto
  28698. error = this.executeCommand(2, COMMAND_MAP.rlineto);
  28699. break;
  28700. case 6: // hlineto
  28701. error = this.executeCommand(1, COMMAND_MAP.hlineto);
  28702. break;
  28703. case 7: // vlineto
  28704. error = this.executeCommand(1, COMMAND_MAP.vlineto);
  28705. break;
  28706. case 8: // rrcurveto
  28707. error = this.executeCommand(6, COMMAND_MAP.rrcurveto);
  28708. break;
  28709. case 9: // closepath
  28710. // closepath is a Type1 command that does not take argument and is
  28711. // useless in Type2 and it can simply be ignored.
  28712. this.stack = [];
  28713. break;
  28714. case 10: // callsubr
  28715. if (this.stack.length < 1) {
  28716. error = true;
  28717. break;
  28718. }
  28719. subrNumber = this.stack.pop();
  28720. error = this.convert(subrs[subrNumber], subrs);
  28721. break;
  28722. case 11: // return
  28723. return error;
  28724. case 13: // hsbw
  28725. if (this.stack.length < 2) {
  28726. error = true;
  28727. break;
  28728. }
  28729. // To convert to type2 we have to move the width value to the
  28730. // first part of the charstring and then use hmoveto with lsb.
  28731. wx = this.stack.pop();
  28732. sbx = this.stack.pop();
  28733. this.lsb = sbx;
  28734. this.width = wx;
  28735. this.stack.push(wx, sbx);
  28736. error = this.executeCommand(2, COMMAND_MAP.hmoveto);
  28737. break;
  28738. case 14: // endchar
  28739. this.output.push(COMMAND_MAP.endchar[0]);
  28740. break;
  28741. case 21: // rmoveto
  28742. if (this.flexing) {
  28743. break;
  28744. }
  28745. error = this.executeCommand(2, COMMAND_MAP.rmoveto);
  28746. break;
  28747. case 22: // hmoveto
  28748. if (this.flexing) {
  28749. // Add the dy for flex.
  28750. this.stack.push(0);
  28751. break;
  28752. }
  28753. error = this.executeCommand(1, COMMAND_MAP.hmoveto);
  28754. break;
  28755. case 30: // vhcurveto
  28756. error = this.executeCommand(4, COMMAND_MAP.vhcurveto);
  28757. break;
  28758. case 31: // hvcurveto
  28759. error = this.executeCommand(4, COMMAND_MAP.hvcurveto);
  28760. break;
  28761. case (12 << 8) + 0: // dotsection
  28762. // dotsection is a Type1 command to specify some hinting feature
  28763. // for dots that do not take a parameter and it can safely be
  28764. // ignored for Type2.
  28765. this.stack = [];
  28766. break;
  28767. case (12 << 8) + 1: // vstem3
  28768. if (!HINTING_ENABLED) {
  28769. this.stack = [];
  28770. break;
  28771. }
  28772. // [vh]stem3 are Type1 only and Type2 supports [vh]stem with
  28773. // multiple parameters, so instead of returning [vh]stem3 take a
  28774. // shortcut and return [vhstem] instead.
  28775. error = this.executeCommand(2, COMMAND_MAP.vstem);
  28776. break;
  28777. case (12 << 8) + 2: // hstem3
  28778. if (!HINTING_ENABLED) {
  28779. this.stack = [];
  28780. break;
  28781. }
  28782. // See vstem3.
  28783. error = this.executeCommand(2, COMMAND_MAP.hstem);
  28784. break;
  28785. case (12 << 8) + 6: // seac
  28786. // seac is like type 2's special endchar but it doesn't use the
  28787. // first argument asb, so remove it.
  28788. if (SEAC_ANALYSIS_ENABLED) {
  28789. this.seac = this.stack.splice(-4, 4);
  28790. error = this.executeCommand(0, COMMAND_MAP.endchar);
  28791. } else {
  28792. error = this.executeCommand(4, COMMAND_MAP.endchar);
  28793. }
  28794. break;
  28795. case (12 << 8) + 7: // sbw
  28796. if (this.stack.length < 4) {
  28797. error = true;
  28798. break;
  28799. }
  28800. // To convert to type2 we have to move the width value to the
  28801. // first part of the charstring and then use rmoveto with
  28802. // (dx, dy). The height argument will not be used for vmtx and
  28803. // vhea tables reconstruction -- ignoring it.
  28804. var wy = this.stack.pop();
  28805. wx = this.stack.pop();
  28806. var sby = this.stack.pop();
  28807. sbx = this.stack.pop();
  28808. this.lsb = sbx;
  28809. this.width = wx;
  28810. this.stack.push(wx, sbx, sby);
  28811. error = this.executeCommand(3, COMMAND_MAP.rmoveto);
  28812. break;
  28813. case (12 << 8) + 12: // div
  28814. if (this.stack.length < 2) {
  28815. error = true;
  28816. break;
  28817. }
  28818. var num2 = this.stack.pop();
  28819. var num1 = this.stack.pop();
  28820. this.stack.push(num1 / num2);
  28821. break;
  28822. case (12 << 8) + 16: // callothersubr
  28823. if (this.stack.length < 2) {
  28824. error = true;
  28825. break;
  28826. }
  28827. subrNumber = this.stack.pop();
  28828. var numArgs = this.stack.pop();
  28829. if (subrNumber === 0 && numArgs === 3) {
  28830. var flexArgs = this.stack.splice(this.stack.length - 17, 17);
  28831. this.stack.push(
  28832. flexArgs[2] + flexArgs[0], // bcp1x + rpx
  28833. flexArgs[3] + flexArgs[1], // bcp1y + rpy
  28834. flexArgs[4], // bcp2x
  28835. flexArgs[5], // bcp2y
  28836. flexArgs[6], // p2x
  28837. flexArgs[7], // p2y
  28838. flexArgs[8], // bcp3x
  28839. flexArgs[9], // bcp3y
  28840. flexArgs[10], // bcp4x
  28841. flexArgs[11], // bcp4y
  28842. flexArgs[12], // p3x
  28843. flexArgs[13], // p3y
  28844. flexArgs[14] // flexDepth
  28845. // 15 = finalx unused by flex
  28846. // 16 = finaly unused by flex
  28847. );
  28848. error = this.executeCommand(13, COMMAND_MAP.flex, true);
  28849. this.flexing = false;
  28850. this.stack.push(flexArgs[15], flexArgs[16]);
  28851. } else if (subrNumber === 1 && numArgs === 0) {
  28852. this.flexing = true;
  28853. }
  28854. break;
  28855. case (12 << 8) + 17: // pop
  28856. // Ignore this since it is only used with othersubr.
  28857. break;
  28858. case (12 << 8) + 33: // setcurrentpoint
  28859. // Ignore for now.
  28860. this.stack = [];
  28861. break;
  28862. default:
  28863. warn('Unknown type 1 charstring command of "' + value + '"');
  28864. break;
  28865. }
  28866. if (error) {
  28867. break;
  28868. }
  28869. continue;
  28870. } else if (value <= 246) {
  28871. value = value - 139;
  28872. } else if (value <= 250) {
  28873. value = ((value - 247) * 256) + encoded[++i] + 108;
  28874. } else if (value <= 254) {
  28875. value = -((value - 251) * 256) - encoded[++i] - 108;
  28876. } else {
  28877. value = (encoded[++i] & 0xff) << 24 | (encoded[++i] & 0xff) << 16 |
  28878. (encoded[++i] & 0xff) << 8 | (encoded[++i] & 0xff) << 0;
  28879. }
  28880. this.stack.push(value);
  28881. }
  28882. return error;
  28883. },
  28884. executeCommand: function(howManyArgs, command, keepStack) {
  28885. var stackLength = this.stack.length;
  28886. if (howManyArgs > stackLength) {
  28887. return true;
  28888. }
  28889. var start = stackLength - howManyArgs;
  28890. for (var i = start; i < stackLength; i++) {
  28891. var value = this.stack[i];
  28892. if (value === (value | 0)) { // int
  28893. this.output.push(28, (value >> 8) & 0xff, value & 0xff);
  28894. } else { // fixed point
  28895. value = (65536 * value) | 0;
  28896. this.output.push(255,
  28897. (value >> 24) & 0xFF,
  28898. (value >> 16) & 0xFF,
  28899. (value >> 8) & 0xFF,
  28900. value & 0xFF);
  28901. }
  28902. }
  28903. this.output.push.apply(this.output, command);
  28904. if (keepStack) {
  28905. this.stack.splice(start, howManyArgs);
  28906. } else {
  28907. this.stack.length = 0;
  28908. }
  28909. return false;
  28910. }
  28911. };
  28912. return Type1CharString;
  28913. })();
  28914. /*
  28915. * Type1Parser encapsulate the needed code for parsing a Type1 font
  28916. * program. Some of its logic depends on the Type2 charstrings
  28917. * structure.
  28918. * Note: this doesn't really parse the font since that would require evaluation
  28919. * of PostScript, but it is possible in most cases to extract what we need
  28920. * without a full parse.
  28921. */
  28922. var Type1Parser = (function Type1ParserClosure() {
  28923. /*
  28924. * Decrypt a Sequence of Ciphertext Bytes to Produce the Original Sequence
  28925. * of Plaintext Bytes. The function took a key as a parameter which can be
  28926. * for decrypting the eexec block of for decoding charStrings.
  28927. */
  28928. var EEXEC_ENCRYPT_KEY = 55665;
  28929. var CHAR_STRS_ENCRYPT_KEY = 4330;
  28930. function isHexDigit(code) {
  28931. return code >= 48 && code <= 57 || // '0'-'9'
  28932. code >= 65 && code <= 70 || // 'A'-'F'
  28933. code >= 97 && code <= 102; // 'a'-'f'
  28934. }
  28935. function decrypt(data, key, discardNumber) {
  28936. var r = key | 0, c1 = 52845, c2 = 22719;
  28937. var count = data.length;
  28938. var decrypted = new Uint8Array(count);
  28939. for (var i = 0; i < count; i++) {
  28940. var value = data[i];
  28941. decrypted[i] = value ^ (r >> 8);
  28942. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  28943. }
  28944. return Array.prototype.slice.call(decrypted, discardNumber);
  28945. }
  28946. function decryptAscii(data, key, discardNumber) {
  28947. var r = key | 0, c1 = 52845, c2 = 22719;
  28948. var count = data.length, maybeLength = count >>> 1;
  28949. var decrypted = new Uint8Array(maybeLength);
  28950. var i, j;
  28951. for (i = 0, j = 0; i < count; i++) {
  28952. var digit1 = data[i];
  28953. if (!isHexDigit(digit1)) {
  28954. continue;
  28955. }
  28956. i++;
  28957. var digit2;
  28958. while (i < count && !isHexDigit(digit2 = data[i])) {
  28959. i++;
  28960. }
  28961. if (i < count) {
  28962. var value = parseInt(String.fromCharCode(digit1, digit2), 16);
  28963. decrypted[j++] = value ^ (r >> 8);
  28964. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  28965. }
  28966. }
  28967. return Array.prototype.slice.call(decrypted, discardNumber, j);
  28968. }
  28969. function isSpecial(c) {
  28970. return c === 0x2F || // '/'
  28971. c === 0x5B || c === 0x5D || // '[', ']'
  28972. c === 0x7B || c === 0x7D || // '{', '}'
  28973. c === 0x28 || c === 0x29; // '(', ')'
  28974. }
  28975. function Type1Parser(stream, encrypted) {
  28976. if (encrypted) {
  28977. var data = stream.getBytes();
  28978. var isBinary = !(isHexDigit(data[0]) && isHexDigit(data[1]) &&
  28979. isHexDigit(data[2]) && isHexDigit(data[3]));
  28980. stream = new Stream(isBinary ? decrypt(data, EEXEC_ENCRYPT_KEY, 4) :
  28981. decryptAscii(data, EEXEC_ENCRYPT_KEY, 4));
  28982. }
  28983. this.stream = stream;
  28984. this.nextChar();
  28985. }
  28986. Type1Parser.prototype = {
  28987. readNumberArray: function Type1Parser_readNumberArray() {
  28988. this.getToken(); // read '[' or '{' (arrays can start with either)
  28989. var array = [];
  28990. while (true) {
  28991. var token = this.getToken();
  28992. if (token === null || token === ']' || token === '}') {
  28993. break;
  28994. }
  28995. array.push(parseFloat(token || 0));
  28996. }
  28997. return array;
  28998. },
  28999. readNumber: function Type1Parser_readNumber() {
  29000. var token = this.getToken();
  29001. return parseFloat(token || 0);
  29002. },
  29003. readInt: function Type1Parser_readInt() {
  29004. // Use '| 0' to prevent setting a double into length such as the double
  29005. // does not flow into the loop variable.
  29006. var token = this.getToken();
  29007. return parseInt(token || 0, 10) | 0;
  29008. },
  29009. readBoolean: function Type1Parser_readBoolean() {
  29010. var token = this.getToken();
  29011. // Use 1 and 0 since that's what type2 charstrings use.
  29012. return token === 'true' ? 1 : 0;
  29013. },
  29014. nextChar : function Type1_nextChar() {
  29015. return (this.currentChar = this.stream.getByte());
  29016. },
  29017. getToken: function Type1Parser_getToken() {
  29018. // Eat whitespace and comments.
  29019. var comment = false;
  29020. var ch = this.currentChar;
  29021. while (true) {
  29022. if (ch === -1) {
  29023. return null;
  29024. }
  29025. if (comment) {
  29026. if (ch === 0x0A || ch === 0x0D) {
  29027. comment = false;
  29028. }
  29029. } else if (ch === 0x25) { // '%'
  29030. comment = true;
  29031. } else if (!Lexer.isSpace(ch)) {
  29032. break;
  29033. }
  29034. ch = this.nextChar();
  29035. }
  29036. if (isSpecial(ch)) {
  29037. this.nextChar();
  29038. return String.fromCharCode(ch);
  29039. }
  29040. var token = '';
  29041. do {
  29042. token += String.fromCharCode(ch);
  29043. ch = this.nextChar();
  29044. } while (ch >= 0 && !Lexer.isSpace(ch) && !isSpecial(ch));
  29045. return token;
  29046. },
  29047. /*
  29048. * Returns an object containing a Subrs array and a CharStrings
  29049. * array extracted from and eexec encrypted block of data
  29050. */
  29051. extractFontProgram: function Type1Parser_extractFontProgram() {
  29052. var stream = this.stream;
  29053. var subrs = [], charstrings = [];
  29054. var program = {
  29055. subrs: [],
  29056. charstrings: [],
  29057. properties: {
  29058. 'privateData': {
  29059. 'lenIV': 4
  29060. }
  29061. }
  29062. };
  29063. var token, length, data, lenIV, encoded;
  29064. while ((token = this.getToken()) !== null) {
  29065. if (token !== '/') {
  29066. continue;
  29067. }
  29068. token = this.getToken();
  29069. switch (token) {
  29070. case 'CharStrings':
  29071. // The number immediately following CharStrings must be greater or
  29072. // equal to the number of CharStrings.
  29073. this.getToken();
  29074. this.getToken(); // read in 'dict'
  29075. this.getToken(); // read in 'dup'
  29076. this.getToken(); // read in 'begin'
  29077. while(true) {
  29078. token = this.getToken();
  29079. if (token === null || token === 'end') {
  29080. break;
  29081. }
  29082. if (token !== '/') {
  29083. continue;
  29084. }
  29085. var glyph = this.getToken();
  29086. length = this.readInt();
  29087. this.getToken(); // read in 'RD' or '-|'
  29088. data = stream.makeSubStream(stream.pos, length);
  29089. lenIV = program.properties.privateData['lenIV'];
  29090. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  29091. // Skip past the required space and binary data.
  29092. stream.skip(length);
  29093. this.nextChar();
  29094. token = this.getToken(); // read in 'ND' or '|-'
  29095. if (token === 'noaccess') {
  29096. this.getToken(); // read in 'def'
  29097. }
  29098. charstrings.push({
  29099. glyph: glyph,
  29100. encoded: encoded
  29101. });
  29102. }
  29103. break;
  29104. case 'Subrs':
  29105. var num = this.readInt();
  29106. this.getToken(); // read in 'array'
  29107. while ((token = this.getToken()) === 'dup') {
  29108. var index = this.readInt();
  29109. length = this.readInt();
  29110. this.getToken(); // read in 'RD' or '-|'
  29111. data = stream.makeSubStream(stream.pos, length);
  29112. lenIV = program.properties.privateData['lenIV'];
  29113. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  29114. // Skip past the required space and binary data.
  29115. stream.skip(length);
  29116. this.nextChar();
  29117. token = this.getToken(); // read in 'NP' or '|'
  29118. if (token === 'noaccess') {
  29119. this.getToken(); // read in 'put'
  29120. }
  29121. subrs[index] = encoded;
  29122. }
  29123. break;
  29124. case 'BlueValues':
  29125. case 'OtherBlues':
  29126. case 'FamilyBlues':
  29127. case 'FamilyOtherBlues':
  29128. var blueArray = this.readNumberArray();
  29129. // *Blue* values may contain invalid data: disables reading of
  29130. // those values when hinting is disabled.
  29131. if (blueArray.length > 0 && (blueArray.length % 2) === 0 &&
  29132. HINTING_ENABLED) {
  29133. program.properties.privateData[token] = blueArray;
  29134. }
  29135. break;
  29136. case 'StemSnapH':
  29137. case 'StemSnapV':
  29138. program.properties.privateData[token] = this.readNumberArray();
  29139. break;
  29140. case 'StdHW':
  29141. case 'StdVW':
  29142. program.properties.privateData[token] =
  29143. this.readNumberArray()[0];
  29144. break;
  29145. case 'BlueShift':
  29146. case 'lenIV':
  29147. case 'BlueFuzz':
  29148. case 'BlueScale':
  29149. case 'LanguageGroup':
  29150. case 'ExpansionFactor':
  29151. program.properties.privateData[token] = this.readNumber();
  29152. break;
  29153. case 'ForceBold':
  29154. program.properties.privateData[token] = this.readBoolean();
  29155. break;
  29156. }
  29157. }
  29158. for (var i = 0; i < charstrings.length; i++) {
  29159. glyph = charstrings[i].glyph;
  29160. encoded = charstrings[i].encoded;
  29161. var charString = new Type1CharString();
  29162. var error = charString.convert(encoded, subrs);
  29163. var output = charString.output;
  29164. if (error) {
  29165. // It seems when FreeType encounters an error while evaluating a glyph
  29166. // that it completely ignores the glyph so we'll mimic that behaviour
  29167. // here and put an endchar to make the validator happy.
  29168. output = [14];
  29169. }
  29170. program.charstrings.push({
  29171. glyphName: glyph,
  29172. charstring: output,
  29173. width: charString.width,
  29174. lsb: charString.lsb,
  29175. seac: charString.seac
  29176. });
  29177. }
  29178. return program;
  29179. },
  29180. extractFontHeader: function Type1Parser_extractFontHeader(properties) {
  29181. var token;
  29182. while ((token = this.getToken()) !== null) {
  29183. if (token !== '/') {
  29184. continue;
  29185. }
  29186. token = this.getToken();
  29187. switch (token) {
  29188. case 'FontMatrix':
  29189. var matrix = this.readNumberArray();
  29190. properties.fontMatrix = matrix;
  29191. break;
  29192. case 'Encoding':
  29193. var encodingArg = this.getToken();
  29194. var encoding;
  29195. if (!/^\d+$/.test(encodingArg)) {
  29196. // encoding name is specified
  29197. encoding = Encodings[encodingArg];
  29198. } else {
  29199. encoding = [];
  29200. var size = parseInt(encodingArg, 10) | 0;
  29201. this.getToken(); // read in 'array'
  29202. for (var j = 0; j < size; j++) {
  29203. token = this.getToken();
  29204. // skipping till first dup or def (e.g. ignoring for statement)
  29205. while (token !== 'dup' && token !== 'def') {
  29206. token = this.getToken();
  29207. if (token === null) {
  29208. return; // invalid header
  29209. }
  29210. }
  29211. if (token === 'def') {
  29212. break; // read all array data
  29213. }
  29214. var index = this.readInt();
  29215. this.getToken(); // read in '/'
  29216. var glyph = this.getToken();
  29217. encoding[index] = glyph;
  29218. this.getToken(); // read the in 'put'
  29219. }
  29220. }
  29221. properties.builtInEncoding = encoding;
  29222. break;
  29223. case 'FontBBox':
  29224. var fontBBox = this.readNumberArray();
  29225. // adjusting ascent/descent
  29226. properties.ascent = fontBBox[3];
  29227. properties.descent = fontBBox[1];
  29228. properties.ascentScaled = true;
  29229. break;
  29230. }
  29231. }
  29232. }
  29233. };
  29234. return Type1Parser;
  29235. })();
  29236. /**
  29237. * The CFF class takes a Type1 file and wrap it into a
  29238. * 'Compact Font Format' which itself embed Type2 charstrings.
  29239. */
  29240. var CFFStandardStrings = [
  29241. '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  29242. 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus',
  29243. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
  29244. 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',
  29245. 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
  29246. 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
  29247. 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright', 'asciicircum',
  29248. 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
  29249. 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
  29250. 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
  29251. 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  29252. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  29253. 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
  29254. 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase', 'quotedblbase',
  29255. 'quotedblright', 'guillemotright', 'ellipsis', 'perthousand', 'questiondown',
  29256. 'grave', 'acute', 'circumflex', 'tilde', 'macron', 'breve', 'dotaccent',
  29257. 'dieresis', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron', 'emdash',
  29258. 'AE', 'ordfeminine', 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae',
  29259. 'dotlessi', 'lslash', 'oslash', 'oe', 'germandbls', 'onesuperior',
  29260. 'logicalnot', 'mu', 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn',
  29261. 'onequarter', 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters',
  29262. 'twosuperior', 'registered', 'minus', 'eth', 'multiply', 'threesuperior',
  29263. 'copyright', 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring',
  29264. 'Atilde', 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave',
  29265. 'Iacute', 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute',
  29266. 'Ocircumflex', 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute',
  29267. 'Ucircumflex', 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron',
  29268. 'aacute', 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde',
  29269. 'ccedilla', 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute',
  29270. 'icircumflex', 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex',
  29271. 'odieresis', 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex',
  29272. 'udieresis', 'ugrave', 'yacute', 'ydieresis', 'zcaron', 'exclamsmall',
  29273. 'Hungarumlautsmall', 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall',
  29274. 'Acutesmall', 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  29275. 'onedotenleader', 'zerooldstyle', 'oneoldstyle', 'twooldstyle',
  29276. 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle',
  29277. 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'commasuperior',
  29278. 'threequartersemdash', 'periodsuperior', 'questionsmall', 'asuperior',
  29279. 'bsuperior', 'centsuperior', 'dsuperior', 'esuperior', 'isuperior',
  29280. 'lsuperior', 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  29281. 'tsuperior', 'ff', 'ffi', 'ffl', 'parenleftinferior', 'parenrightinferior',
  29282. 'Circumflexsmall', 'hyphensuperior', 'Gravesmall', 'Asmall', 'Bsmall',
  29283. 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall',
  29284. 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall',
  29285. 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
  29286. 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah',
  29287. 'Tildesmall', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall',
  29288. 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall', 'Caronsmall',
  29289. 'Dotaccentsmall', 'Macronsmall', 'figuredash', 'hypheninferior',
  29290. 'Ogoneksmall', 'Ringsmall', 'Cedillasmall', 'questiondownsmall', 'oneeighth',
  29291. 'threeeighths', 'fiveeighths', 'seveneighths', 'onethird', 'twothirds',
  29292. 'zerosuperior', 'foursuperior', 'fivesuperior', 'sixsuperior',
  29293. 'sevensuperior', 'eightsuperior', 'ninesuperior', 'zeroinferior',
  29294. 'oneinferior', 'twoinferior', 'threeinferior', 'fourinferior',
  29295. 'fiveinferior', 'sixinferior', 'seveninferior', 'eightinferior',
  29296. 'nineinferior', 'centinferior', 'dollarinferior', 'periodinferior',
  29297. 'commainferior', 'Agravesmall', 'Aacutesmall', 'Acircumflexsmall',
  29298. 'Atildesmall', 'Adieresissmall', 'Aringsmall', 'AEsmall', 'Ccedillasmall',
  29299. 'Egravesmall', 'Eacutesmall', 'Ecircumflexsmall', 'Edieresissmall',
  29300. 'Igravesmall', 'Iacutesmall', 'Icircumflexsmall', 'Idieresissmall',
  29301. 'Ethsmall', 'Ntildesmall', 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall',
  29302. 'Otildesmall', 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall',
  29303. 'Uacutesmall', 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall',
  29304. 'Thornsmall', 'Ydieresissmall', '001.000', '001.001', '001.002', '001.003',
  29305. 'Black', 'Bold', 'Book', 'Light', 'Medium', 'Regular', 'Roman', 'Semibold'
  29306. ];
  29307. // Type1Font is also a CIDFontType0.
  29308. var Type1Font = function Type1Font(name, file, properties) {
  29309. // Some bad generators embed pfb file as is, we have to strip 6-byte headers.
  29310. // Also, length1 and length2 might be off by 6 bytes as well.
  29311. // http://www.math.ubc.ca/~cass/piscript/type1.pdf
  29312. var PFB_HEADER_SIZE = 6;
  29313. var headerBlockLength = properties.length1;
  29314. var eexecBlockLength = properties.length2;
  29315. var pfbHeader = file.peekBytes(PFB_HEADER_SIZE);
  29316. var pfbHeaderPresent = pfbHeader[0] === 0x80 && pfbHeader[1] === 0x01;
  29317. if (pfbHeaderPresent) {
  29318. file.skip(PFB_HEADER_SIZE);
  29319. headerBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  29320. (pfbHeader[3] << 8) | pfbHeader[2];
  29321. }
  29322. // Get the data block containing glyphs and subrs informations
  29323. var headerBlock = new Stream(file.getBytes(headerBlockLength));
  29324. var headerBlockParser = new Type1Parser(headerBlock);
  29325. headerBlockParser.extractFontHeader(properties);
  29326. if (pfbHeaderPresent) {
  29327. pfbHeader = file.getBytes(PFB_HEADER_SIZE);
  29328. eexecBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  29329. (pfbHeader[3] << 8) | pfbHeader[2];
  29330. }
  29331. // Decrypt the data blocks and retrieve it's content
  29332. var eexecBlock = new Stream(file.getBytes(eexecBlockLength));
  29333. var eexecBlockParser = new Type1Parser(eexecBlock, true);
  29334. var data = eexecBlockParser.extractFontProgram();
  29335. for (var info in data.properties) {
  29336. properties[info] = data.properties[info];
  29337. }
  29338. var charstrings = data.charstrings;
  29339. var type2Charstrings = this.getType2Charstrings(charstrings);
  29340. var subrs = this.getType2Subrs(data.subrs);
  29341. this.charstrings = charstrings;
  29342. this.data = this.wrap(name, type2Charstrings, this.charstrings,
  29343. subrs, properties);
  29344. this.seacs = this.getSeacs(data.charstrings);
  29345. };
  29346. Type1Font.prototype = {
  29347. get numGlyphs() {
  29348. return this.charstrings.length + 1;
  29349. },
  29350. getCharset: function Type1Font_getCharset() {
  29351. var charset = ['.notdef'];
  29352. var charstrings = this.charstrings;
  29353. for (var glyphId = 0; glyphId < charstrings.length; glyphId++) {
  29354. charset.push(charstrings[glyphId].glyphName);
  29355. }
  29356. return charset;
  29357. },
  29358. getGlyphMapping: function Type1Font_getGlyphMapping(properties) {
  29359. var charstrings = this.charstrings;
  29360. var glyphNames = ['.notdef'], glyphId;
  29361. for (glyphId = 0; glyphId < charstrings.length; glyphId++) {
  29362. glyphNames.push(charstrings[glyphId].glyphName);
  29363. }
  29364. var encoding = properties.builtInEncoding;
  29365. if (encoding) {
  29366. var builtInEncoding = {};
  29367. for (var charCode in encoding) {
  29368. glyphId = glyphNames.indexOf(encoding[charCode]);
  29369. if (glyphId >= 0) {
  29370. builtInEncoding[charCode] = glyphId;
  29371. }
  29372. }
  29373. }
  29374. return type1FontGlyphMapping(properties, builtInEncoding, glyphNames);
  29375. },
  29376. getSeacs: function Type1Font_getSeacs(charstrings) {
  29377. var i, ii;
  29378. var seacMap = [];
  29379. for (i = 0, ii = charstrings.length; i < ii; i++) {
  29380. var charstring = charstrings[i];
  29381. if (charstring.seac) {
  29382. // Offset by 1 for .notdef
  29383. seacMap[i + 1] = charstring.seac;
  29384. }
  29385. }
  29386. return seacMap;
  29387. },
  29388. getType2Charstrings: function Type1Font_getType2Charstrings(
  29389. type1Charstrings) {
  29390. var type2Charstrings = [];
  29391. for (var i = 0, ii = type1Charstrings.length; i < ii; i++) {
  29392. type2Charstrings.push(type1Charstrings[i].charstring);
  29393. }
  29394. return type2Charstrings;
  29395. },
  29396. getType2Subrs: function Type1Font_getType2Subrs(type1Subrs) {
  29397. var bias = 0;
  29398. var count = type1Subrs.length;
  29399. if (count < 1133) {
  29400. bias = 107;
  29401. } else if (count < 33769) {
  29402. bias = 1131;
  29403. } else {
  29404. bias = 32768;
  29405. }
  29406. // Add a bunch of empty subrs to deal with the Type2 bias
  29407. var type2Subrs = [];
  29408. var i;
  29409. for (i = 0; i < bias; i++) {
  29410. type2Subrs.push([0x0B]);
  29411. }
  29412. for (i = 0; i < count; i++) {
  29413. type2Subrs.push(type1Subrs[i]);
  29414. }
  29415. return type2Subrs;
  29416. },
  29417. wrap: function Type1Font_wrap(name, glyphs, charstrings, subrs, properties) {
  29418. var cff = new CFF();
  29419. cff.header = new CFFHeader(1, 0, 4, 4);
  29420. cff.names = [name];
  29421. var topDict = new CFFTopDict();
  29422. // CFF strings IDs 0...390 are predefined names, so refering
  29423. // to entries in our own String INDEX starts at SID 391.
  29424. topDict.setByName('version', 391);
  29425. topDict.setByName('Notice', 392);
  29426. topDict.setByName('FullName', 393);
  29427. topDict.setByName('FamilyName', 394);
  29428. topDict.setByName('Weight', 395);
  29429. topDict.setByName('Encoding', null); // placeholder
  29430. topDict.setByName('FontMatrix', properties.fontMatrix);
  29431. topDict.setByName('FontBBox', properties.bbox);
  29432. topDict.setByName('charset', null); // placeholder
  29433. topDict.setByName('CharStrings', null); // placeholder
  29434. topDict.setByName('Private', null); // placeholder
  29435. cff.topDict = topDict;
  29436. var strings = new CFFStrings();
  29437. strings.add('Version 0.11'); // Version
  29438. strings.add('See original notice'); // Notice
  29439. strings.add(name); // FullName
  29440. strings.add(name); // FamilyName
  29441. strings.add('Medium'); // Weight
  29442. cff.strings = strings;
  29443. cff.globalSubrIndex = new CFFIndex();
  29444. var count = glyphs.length;
  29445. var charsetArray = [0];
  29446. var i, ii;
  29447. for (i = 0; i < count; i++) {
  29448. var index = CFFStandardStrings.indexOf(charstrings[i].glyphName);
  29449. // TODO: Insert the string and correctly map it. Previously it was
  29450. // thought mapping names that aren't in the standard strings to .notdef
  29451. // was fine, however in issue818 when mapping them all to .notdef the
  29452. // adieresis glyph no longer worked.
  29453. if (index === -1) {
  29454. index = 0;
  29455. }
  29456. charsetArray.push((index >> 8) & 0xff, index & 0xff);
  29457. }
  29458. cff.charset = new CFFCharset(false, 0, [], charsetArray);
  29459. var charStringsIndex = new CFFIndex();
  29460. charStringsIndex.add([0x8B, 0x0E]); // .notdef
  29461. for (i = 0; i < count; i++) {
  29462. charStringsIndex.add(glyphs[i]);
  29463. }
  29464. cff.charStrings = charStringsIndex;
  29465. var privateDict = new CFFPrivateDict();
  29466. privateDict.setByName('Subrs', null); // placeholder
  29467. var fields = [
  29468. 'BlueValues',
  29469. 'OtherBlues',
  29470. 'FamilyBlues',
  29471. 'FamilyOtherBlues',
  29472. 'StemSnapH',
  29473. 'StemSnapV',
  29474. 'BlueShift',
  29475. 'BlueFuzz',
  29476. 'BlueScale',
  29477. 'LanguageGroup',
  29478. 'ExpansionFactor',
  29479. 'ForceBold',
  29480. 'StdHW',
  29481. 'StdVW'
  29482. ];
  29483. for (i = 0, ii = fields.length; i < ii; i++) {
  29484. var field = fields[i];
  29485. if (!properties.privateData.hasOwnProperty(field)) {
  29486. continue;
  29487. }
  29488. var value = properties.privateData[field];
  29489. if (isArray(value)) {
  29490. // All of the private dictionary array data in CFF must be stored as
  29491. // "delta-encoded" numbers.
  29492. for (var j = value.length - 1; j > 0; j--) {
  29493. value[j] -= value[j - 1]; // ... difference from previous value
  29494. }
  29495. }
  29496. privateDict.setByName(field, value);
  29497. }
  29498. cff.topDict.privateDict = privateDict;
  29499. var subrIndex = new CFFIndex();
  29500. for (i = 0, ii = subrs.length; i < ii; i++) {
  29501. subrIndex.add(subrs[i]);
  29502. }
  29503. privateDict.subrsIndex = subrIndex;
  29504. var compiler = new CFFCompiler(cff);
  29505. return compiler.compile();
  29506. }
  29507. };
  29508. var CFFFont = (function CFFFontClosure() {
  29509. function CFFFont(file, properties) {
  29510. this.properties = properties;
  29511. var parser = new CFFParser(file, properties);
  29512. this.cff = parser.parse();
  29513. var compiler = new CFFCompiler(this.cff);
  29514. this.seacs = this.cff.seacs;
  29515. try {
  29516. this.data = compiler.compile();
  29517. } catch (e) {
  29518. warn('Failed to compile font ' + properties.loadedName);
  29519. // There may have just been an issue with the compiler, set the data
  29520. // anyway and hope the font loaded.
  29521. this.data = file;
  29522. }
  29523. }
  29524. CFFFont.prototype = {
  29525. get numGlyphs() {
  29526. return this.cff.charStrings.count;
  29527. },
  29528. getCharset: function CFFFont_getCharset() {
  29529. return this.cff.charset.charset;
  29530. },
  29531. getGlyphMapping: function CFFFont_getGlyphMapping() {
  29532. var cff = this.cff;
  29533. var properties = this.properties;
  29534. var charsets = cff.charset.charset;
  29535. var charCodeToGlyphId;
  29536. var glyphId;
  29537. if (properties.composite) {
  29538. charCodeToGlyphId = Object.create(null);
  29539. if (cff.isCIDFont) {
  29540. // If the font is actually a CID font then we should use the charset
  29541. // to map CIDs to GIDs.
  29542. for (glyphId = 0; glyphId < charsets.length; glyphId++) {
  29543. var cid = charsets[glyphId];
  29544. var charCode = properties.cMap.charCodeOf(cid);
  29545. charCodeToGlyphId[charCode] = glyphId;
  29546. }
  29547. } else {
  29548. // If it is NOT actually a CID font then CIDs should be mapped
  29549. // directly to GIDs.
  29550. for (glyphId = 0; glyphId < cff.charStrings.count; glyphId++) {
  29551. charCodeToGlyphId[glyphId] = glyphId;
  29552. }
  29553. }
  29554. return charCodeToGlyphId;
  29555. }
  29556. var encoding = cff.encoding ? cff.encoding.encoding : null;
  29557. charCodeToGlyphId = type1FontGlyphMapping(properties, encoding, charsets);
  29558. return charCodeToGlyphId;
  29559. }
  29560. };
  29561. return CFFFont;
  29562. })();
  29563. var CFFParser = (function CFFParserClosure() {
  29564. var CharstringValidationData = [
  29565. null,
  29566. { id: 'hstem', min: 2, stackClearing: true, stem: true },
  29567. null,
  29568. { id: 'vstem', min: 2, stackClearing: true, stem: true },
  29569. { id: 'vmoveto', min: 1, stackClearing: true },
  29570. { id: 'rlineto', min: 2, resetStack: true },
  29571. { id: 'hlineto', min: 1, resetStack: true },
  29572. { id: 'vlineto', min: 1, resetStack: true },
  29573. { id: 'rrcurveto', min: 6, resetStack: true },
  29574. null,
  29575. { id: 'callsubr', min: 1, undefStack: true },
  29576. { id: 'return', min: 0, undefStack: true },
  29577. null, // 12
  29578. null,
  29579. { id: 'endchar', min: 0, stackClearing: true },
  29580. null,
  29581. null,
  29582. null,
  29583. { id: 'hstemhm', min: 2, stackClearing: true, stem: true },
  29584. { id: 'hintmask', min: 0, stackClearing: true },
  29585. { id: 'cntrmask', min: 0, stackClearing: true },
  29586. { id: 'rmoveto', min: 2, stackClearing: true },
  29587. { id: 'hmoveto', min: 1, stackClearing: true },
  29588. { id: 'vstemhm', min: 2, stackClearing: true, stem: true },
  29589. { id: 'rcurveline', min: 8, resetStack: true },
  29590. { id: 'rlinecurve', min: 8, resetStack: true },
  29591. { id: 'vvcurveto', min: 4, resetStack: true },
  29592. { id: 'hhcurveto', min: 4, resetStack: true },
  29593. null, // shortint
  29594. { id: 'callgsubr', min: 1, undefStack: true },
  29595. { id: 'vhcurveto', min: 4, resetStack: true },
  29596. { id: 'hvcurveto', min: 4, resetStack: true }
  29597. ];
  29598. var CharstringValidationData12 = [
  29599. null,
  29600. null,
  29601. null,
  29602. { id: 'and', min: 2, stackDelta: -1 },
  29603. { id: 'or', min: 2, stackDelta: -1 },
  29604. { id: 'not', min: 1, stackDelta: 0 },
  29605. null,
  29606. null,
  29607. null,
  29608. { id: 'abs', min: 1, stackDelta: 0 },
  29609. { id: 'add', min: 2, stackDelta: -1,
  29610. stackFn: function stack_div(stack, index) {
  29611. stack[index - 2] = stack[index - 2] + stack[index - 1];
  29612. }
  29613. },
  29614. { id: 'sub', min: 2, stackDelta: -1,
  29615. stackFn: function stack_div(stack, index) {
  29616. stack[index - 2] = stack[index - 2] - stack[index - 1];
  29617. }
  29618. },
  29619. { id: 'div', min: 2, stackDelta: -1,
  29620. stackFn: function stack_div(stack, index) {
  29621. stack[index - 2] = stack[index - 2] / stack[index - 1];
  29622. }
  29623. },
  29624. null,
  29625. { id: 'neg', min: 1, stackDelta: 0,
  29626. stackFn: function stack_div(stack, index) {
  29627. stack[index - 1] = -stack[index - 1];
  29628. }
  29629. },
  29630. { id: 'eq', min: 2, stackDelta: -1 },
  29631. null,
  29632. null,
  29633. { id: 'drop', min: 1, stackDelta: -1 },
  29634. null,
  29635. { id: 'put', min: 2, stackDelta: -2 },
  29636. { id: 'get', min: 1, stackDelta: 0 },
  29637. { id: 'ifelse', min: 4, stackDelta: -3 },
  29638. { id: 'random', min: 0, stackDelta: 1 },
  29639. { id: 'mul', min: 2, stackDelta: -1,
  29640. stackFn: function stack_div(stack, index) {
  29641. stack[index - 2] = stack[index - 2] * stack[index - 1];
  29642. }
  29643. },
  29644. null,
  29645. { id: 'sqrt', min: 1, stackDelta: 0 },
  29646. { id: 'dup', min: 1, stackDelta: 1 },
  29647. { id: 'exch', min: 2, stackDelta: 0 },
  29648. { id: 'index', min: 2, stackDelta: 0 },
  29649. { id: 'roll', min: 3, stackDelta: -2 },
  29650. null,
  29651. null,
  29652. null,
  29653. { id: 'hflex', min: 7, resetStack: true },
  29654. { id: 'flex', min: 13, resetStack: true },
  29655. { id: 'hflex1', min: 9, resetStack: true },
  29656. { id: 'flex1', min: 11, resetStack: true }
  29657. ];
  29658. function CFFParser(file, properties) {
  29659. this.bytes = file.getBytes();
  29660. this.properties = properties;
  29661. }
  29662. CFFParser.prototype = {
  29663. parse: function CFFParser_parse() {
  29664. var properties = this.properties;
  29665. var cff = new CFF();
  29666. this.cff = cff;
  29667. // The first five sections must be in order, all the others are reached
  29668. // via offsets contained in one of the below.
  29669. var header = this.parseHeader();
  29670. var nameIndex = this.parseIndex(header.endPos);
  29671. var topDictIndex = this.parseIndex(nameIndex.endPos);
  29672. var stringIndex = this.parseIndex(topDictIndex.endPos);
  29673. var globalSubrIndex = this.parseIndex(stringIndex.endPos);
  29674. var topDictParsed = this.parseDict(topDictIndex.obj.get(0));
  29675. var topDict = this.createDict(CFFTopDict, topDictParsed, cff.strings);
  29676. cff.header = header.obj;
  29677. cff.names = this.parseNameIndex(nameIndex.obj);
  29678. cff.strings = this.parseStringIndex(stringIndex.obj);
  29679. cff.topDict = topDict;
  29680. cff.globalSubrIndex = globalSubrIndex.obj;
  29681. this.parsePrivateDict(cff.topDict);
  29682. cff.isCIDFont = topDict.hasName('ROS');
  29683. var charStringOffset = topDict.getByName('CharStrings');
  29684. var charStringIndex = this.parseIndex(charStringOffset).obj;
  29685. var fontMatrix = topDict.getByName('FontMatrix');
  29686. if (fontMatrix) {
  29687. properties.fontMatrix = fontMatrix;
  29688. }
  29689. var fontBBox = topDict.getByName('FontBBox');
  29690. if (fontBBox) {
  29691. // adjusting ascent/descent
  29692. properties.ascent = fontBBox[3];
  29693. properties.descent = fontBBox[1];
  29694. properties.ascentScaled = true;
  29695. }
  29696. var charset, encoding;
  29697. if (cff.isCIDFont) {
  29698. var fdArrayIndex = this.parseIndex(topDict.getByName('FDArray')).obj;
  29699. for (var i = 0, ii = fdArrayIndex.count; i < ii; ++i) {
  29700. var dictRaw = fdArrayIndex.get(i);
  29701. var fontDict = this.createDict(CFFTopDict, this.parseDict(dictRaw),
  29702. cff.strings);
  29703. this.parsePrivateDict(fontDict);
  29704. cff.fdArray.push(fontDict);
  29705. }
  29706. // cid fonts don't have an encoding
  29707. encoding = null;
  29708. charset = this.parseCharsets(topDict.getByName('charset'),
  29709. charStringIndex.count, cff.strings, true);
  29710. cff.fdSelect = this.parseFDSelect(topDict.getByName('FDSelect'),
  29711. charStringIndex.count);
  29712. } else {
  29713. charset = this.parseCharsets(topDict.getByName('charset'),
  29714. charStringIndex.count, cff.strings, false);
  29715. encoding = this.parseEncoding(topDict.getByName('Encoding'),
  29716. properties,
  29717. cff.strings, charset.charset);
  29718. }
  29719. cff.charset = charset;
  29720. cff.encoding = encoding;
  29721. var charStringsAndSeacs = this.parseCharStrings(
  29722. charStringIndex,
  29723. topDict.privateDict.subrsIndex,
  29724. globalSubrIndex.obj,
  29725. cff.fdSelect,
  29726. cff.fdArray);
  29727. cff.charStrings = charStringsAndSeacs.charStrings;
  29728. cff.seacs = charStringsAndSeacs.seacs;
  29729. cff.widths = charStringsAndSeacs.widths;
  29730. return cff;
  29731. },
  29732. parseHeader: function CFFParser_parseHeader() {
  29733. var bytes = this.bytes;
  29734. var bytesLength = bytes.length;
  29735. var offset = 0;
  29736. // Prevent an infinite loop, by checking that the offset is within the
  29737. // bounds of the bytes array. Necessary in empty, or invalid, font files.
  29738. while (offset < bytesLength && bytes[offset] !== 1) {
  29739. ++offset;
  29740. }
  29741. if (offset >= bytesLength) {
  29742. error('Invalid CFF header');
  29743. } else if (offset !== 0) {
  29744. info('cff data is shifted');
  29745. bytes = bytes.subarray(offset);
  29746. this.bytes = bytes;
  29747. }
  29748. var major = bytes[0];
  29749. var minor = bytes[1];
  29750. var hdrSize = bytes[2];
  29751. var offSize = bytes[3];
  29752. var header = new CFFHeader(major, minor, hdrSize, offSize);
  29753. return { obj: header, endPos: hdrSize };
  29754. },
  29755. parseDict: function CFFParser_parseDict(dict) {
  29756. var pos = 0;
  29757. function parseOperand() {
  29758. var value = dict[pos++];
  29759. if (value === 30) {
  29760. return parseFloatOperand(pos);
  29761. } else if (value === 28) {
  29762. value = dict[pos++];
  29763. value = ((value << 24) | (dict[pos++] << 16)) >> 16;
  29764. return value;
  29765. } else if (value === 29) {
  29766. value = dict[pos++];
  29767. value = (value << 8) | dict[pos++];
  29768. value = (value << 8) | dict[pos++];
  29769. value = (value << 8) | dict[pos++];
  29770. return value;
  29771. } else if (value >= 32 && value <= 246) {
  29772. return value - 139;
  29773. } else if (value >= 247 && value <= 250) {
  29774. return ((value - 247) * 256) + dict[pos++] + 108;
  29775. } else if (value >= 251 && value <= 254) {
  29776. return -((value - 251) * 256) - dict[pos++] - 108;
  29777. } else {
  29778. error('255 is not a valid DICT command');
  29779. }
  29780. return -1;
  29781. }
  29782. function parseFloatOperand() {
  29783. var str = '';
  29784. var eof = 15;
  29785. var lookup = ['0', '1', '2', '3', '4', '5', '6', '7', '8',
  29786. '9', '.', 'E', 'E-', null, '-'];
  29787. var length = dict.length;
  29788. while (pos < length) {
  29789. var b = dict[pos++];
  29790. var b1 = b >> 4;
  29791. var b2 = b & 15;
  29792. if (b1 === eof) {
  29793. break;
  29794. }
  29795. str += lookup[b1];
  29796. if (b2 === eof) {
  29797. break;
  29798. }
  29799. str += lookup[b2];
  29800. }
  29801. return parseFloat(str);
  29802. }
  29803. var operands = [];
  29804. var entries = [];
  29805. pos = 0;
  29806. var end = dict.length;
  29807. while (pos < end) {
  29808. var b = dict[pos];
  29809. if (b <= 21) {
  29810. if (b === 12) {
  29811. b = (b << 8) | dict[++pos];
  29812. }
  29813. entries.push([b, operands]);
  29814. operands = [];
  29815. ++pos;
  29816. } else {
  29817. operands.push(parseOperand());
  29818. }
  29819. }
  29820. return entries;
  29821. },
  29822. parseIndex: function CFFParser_parseIndex(pos) {
  29823. var cffIndex = new CFFIndex();
  29824. var bytes = this.bytes;
  29825. var count = (bytes[pos++] << 8) | bytes[pos++];
  29826. var offsets = [];
  29827. var end = pos;
  29828. var i, ii;
  29829. if (count !== 0) {
  29830. var offsetSize = bytes[pos++];
  29831. // add 1 for offset to determine size of last object
  29832. var startPos = pos + ((count + 1) * offsetSize) - 1;
  29833. for (i = 0, ii = count + 1; i < ii; ++i) {
  29834. var offset = 0;
  29835. for (var j = 0; j < offsetSize; ++j) {
  29836. offset <<= 8;
  29837. offset += bytes[pos++];
  29838. }
  29839. offsets.push(startPos + offset);
  29840. }
  29841. end = offsets[count];
  29842. }
  29843. for (i = 0, ii = offsets.length - 1; i < ii; ++i) {
  29844. var offsetStart = offsets[i];
  29845. var offsetEnd = offsets[i + 1];
  29846. cffIndex.add(bytes.subarray(offsetStart, offsetEnd));
  29847. }
  29848. return {obj: cffIndex, endPos: end};
  29849. },
  29850. parseNameIndex: function CFFParser_parseNameIndex(index) {
  29851. var names = [];
  29852. for (var i = 0, ii = index.count; i < ii; ++i) {
  29853. var name = index.get(i);
  29854. // OTS doesn't allow names to be over 127 characters.
  29855. var length = Math.min(name.length, 127);
  29856. var data = [];
  29857. // OTS also only permits certain characters in the name.
  29858. for (var j = 0; j < length; ++j) {
  29859. var c = name[j];
  29860. if (j === 0 && c === 0) {
  29861. data[j] = c;
  29862. continue;
  29863. }
  29864. if ((c < 33 || c > 126) || c === 91 /* [ */ || c === 93 /* ] */ ||
  29865. c === 40 /* ( */ || c === 41 /* ) */ || c === 123 /* { */ ||
  29866. c === 125 /* } */ || c === 60 /* < */ || c === 62 /* > */ ||
  29867. c === 47 /* / */ || c === 37 /* % */ || c === 35 /* # */) {
  29868. data[j] = 95;
  29869. continue;
  29870. }
  29871. data[j] = c;
  29872. }
  29873. names.push(bytesToString(data));
  29874. }
  29875. return names;
  29876. },
  29877. parseStringIndex: function CFFParser_parseStringIndex(index) {
  29878. var strings = new CFFStrings();
  29879. for (var i = 0, ii = index.count; i < ii; ++i) {
  29880. var data = index.get(i);
  29881. strings.add(bytesToString(data));
  29882. }
  29883. return strings;
  29884. },
  29885. createDict: function CFFParser_createDict(Type, dict, strings) {
  29886. var cffDict = new Type(strings);
  29887. for (var i = 0, ii = dict.length; i < ii; ++i) {
  29888. var pair = dict[i];
  29889. var key = pair[0];
  29890. var value = pair[1];
  29891. cffDict.setByKey(key, value);
  29892. }
  29893. return cffDict;
  29894. },
  29895. parseCharString: function CFFParser_parseCharString(state, data,
  29896. localSubrIndex,
  29897. globalSubrIndex) {
  29898. if (state.callDepth > MAX_SUBR_NESTING) {
  29899. return false;
  29900. }
  29901. var stackSize = state.stackSize;
  29902. var stack = state.stack;
  29903. var length = data.length;
  29904. for (var j = 0; j < length;) {
  29905. var value = data[j++];
  29906. var validationCommand = null;
  29907. if (value === 12) {
  29908. var q = data[j++];
  29909. if (q === 0) {
  29910. // The CFF specification state that the 'dotsection' command
  29911. // (12, 0) is deprecated and treated as a no-op, but all Type2
  29912. // charstrings processors should support them. Unfortunately
  29913. // the font sanitizer don't. As a workaround the sequence (12, 0)
  29914. // is replaced by a useless (0, hmoveto).
  29915. data[j - 2] = 139;
  29916. data[j - 1] = 22;
  29917. stackSize = 0;
  29918. } else {
  29919. validationCommand = CharstringValidationData12[q];
  29920. }
  29921. } else if (value === 28) { // number (16 bit)
  29922. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16)) >> 16;
  29923. j += 2;
  29924. stackSize++;
  29925. } else if (value === 14) {
  29926. if (stackSize >= 4) {
  29927. stackSize -= 4;
  29928. if (SEAC_ANALYSIS_ENABLED) {
  29929. state.seac = stack.slice(stackSize, stackSize + 4);
  29930. return false;
  29931. }
  29932. }
  29933. validationCommand = CharstringValidationData[value];
  29934. } else if (value >= 32 && value <= 246) { // number
  29935. stack[stackSize] = value - 139;
  29936. stackSize++;
  29937. } else if (value >= 247 && value <= 254) { // number (+1 bytes)
  29938. stack[stackSize] = (value < 251 ?
  29939. ((value - 247) << 8) + data[j] + 108 :
  29940. -((value - 251) << 8) - data[j] - 108);
  29941. j++;
  29942. stackSize++;
  29943. } else if (value === 255) { // number (32 bit)
  29944. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16) |
  29945. (data[j + 2] << 8) | data[j + 3]) / 65536;
  29946. j += 4;
  29947. stackSize++;
  29948. } else if (value === 19 || value === 20) {
  29949. state.hints += stackSize >> 1;
  29950. // skipping right amount of hints flag data
  29951. j += (state.hints + 7) >> 3;
  29952. stackSize %= 2;
  29953. validationCommand = CharstringValidationData[value];
  29954. } else if (value === 10 || value === 29) {
  29955. var subrsIndex;
  29956. if (value === 10) {
  29957. subrsIndex = localSubrIndex;
  29958. } else {
  29959. subrsIndex = globalSubrIndex;
  29960. }
  29961. if (!subrsIndex) {
  29962. validationCommand = CharstringValidationData[value];
  29963. warn('Missing subrsIndex for ' + validationCommand.id);
  29964. return false;
  29965. }
  29966. var bias = 32768;
  29967. if (subrsIndex.count < 1240) {
  29968. bias = 107;
  29969. } else if (subrsIndex.count < 33900) {
  29970. bias = 1131;
  29971. }
  29972. var subrNumber = stack[--stackSize] + bias;
  29973. if (subrNumber < 0 || subrNumber >= subrsIndex.count) {
  29974. validationCommand = CharstringValidationData[value];
  29975. warn('Out of bounds subrIndex for ' + validationCommand.id);
  29976. return false;
  29977. }
  29978. state.stackSize = stackSize;
  29979. state.callDepth++;
  29980. var valid = this.parseCharString(state, subrsIndex.get(subrNumber),
  29981. localSubrIndex, globalSubrIndex);
  29982. if (!valid) {
  29983. return false;
  29984. }
  29985. state.callDepth--;
  29986. stackSize = state.stackSize;
  29987. continue;
  29988. } else if (value === 11) {
  29989. state.stackSize = stackSize;
  29990. return true;
  29991. } else {
  29992. validationCommand = CharstringValidationData[value];
  29993. }
  29994. if (validationCommand) {
  29995. if (validationCommand.stem) {
  29996. state.hints += stackSize >> 1;
  29997. }
  29998. if ('min' in validationCommand) {
  29999. if (!state.undefStack && stackSize < validationCommand.min) {
  30000. warn('Not enough parameters for ' + validationCommand.id +
  30001. '; actual: ' + stackSize +
  30002. ', expected: ' + validationCommand.min);
  30003. return false;
  30004. }
  30005. }
  30006. if (state.firstStackClearing && validationCommand.stackClearing) {
  30007. state.firstStackClearing = false;
  30008. // the optional character width can be found before the first
  30009. // stack-clearing command arguments
  30010. stackSize -= validationCommand.min;
  30011. if (stackSize >= 2 && validationCommand.stem) {
  30012. // there are even amount of arguments for stem commands
  30013. stackSize %= 2;
  30014. } else if (stackSize > 1) {
  30015. warn('Found too many parameters for stack-clearing command');
  30016. }
  30017. if (stackSize > 0 && stack[stackSize - 1] >= 0) {
  30018. state.width = stack[stackSize - 1];
  30019. }
  30020. }
  30021. if ('stackDelta' in validationCommand) {
  30022. if ('stackFn' in validationCommand) {
  30023. validationCommand.stackFn(stack, stackSize);
  30024. }
  30025. stackSize += validationCommand.stackDelta;
  30026. } else if (validationCommand.stackClearing) {
  30027. stackSize = 0;
  30028. } else if (validationCommand.resetStack) {
  30029. stackSize = 0;
  30030. state.undefStack = false;
  30031. } else if (validationCommand.undefStack) {
  30032. stackSize = 0;
  30033. state.undefStack = true;
  30034. state.firstStackClearing = false;
  30035. }
  30036. }
  30037. }
  30038. state.stackSize = stackSize;
  30039. return true;
  30040. },
  30041. parseCharStrings: function CFFParser_parseCharStrings(charStrings,
  30042. localSubrIndex,
  30043. globalSubrIndex,
  30044. fdSelect,
  30045. fdArray) {
  30046. var seacs = [];
  30047. var widths = [];
  30048. var count = charStrings.count;
  30049. for (var i = 0; i < count; i++) {
  30050. var charstring = charStrings.get(i);
  30051. var state = {
  30052. callDepth: 0,
  30053. stackSize: 0,
  30054. stack: [],
  30055. undefStack: true,
  30056. hints: 0,
  30057. firstStackClearing: true,
  30058. seac: null,
  30059. width: null
  30060. };
  30061. var valid = true;
  30062. var localSubrToUse = null;
  30063. if (fdSelect && fdArray.length) {
  30064. var fdIndex = fdSelect.getFDIndex(i);
  30065. if (fdIndex === -1) {
  30066. warn('Glyph index is not in fd select.');
  30067. valid = false;
  30068. }
  30069. if (fdIndex >= fdArray.length) {
  30070. warn('Invalid fd index for glyph index.');
  30071. valid = false;
  30072. }
  30073. if (valid) {
  30074. localSubrToUse = fdArray[fdIndex].privateDict.subrsIndex;
  30075. }
  30076. } else if (localSubrIndex) {
  30077. localSubrToUse = localSubrIndex;
  30078. }
  30079. if (valid) {
  30080. valid = this.parseCharString(state, charstring, localSubrToUse,
  30081. globalSubrIndex);
  30082. }
  30083. if (state.width !== null) {
  30084. widths[i] = state.width;
  30085. }
  30086. if (state.seac !== null) {
  30087. seacs[i] = state.seac;
  30088. }
  30089. if (!valid) {
  30090. // resetting invalid charstring to single 'endchar'
  30091. charStrings.set(i, new Uint8Array([14]));
  30092. }
  30093. }
  30094. return { charStrings: charStrings, seacs: seacs, widths: widths };
  30095. },
  30096. emptyPrivateDictionary:
  30097. function CFFParser_emptyPrivateDictionary(parentDict) {
  30098. var privateDict = this.createDict(CFFPrivateDict, [],
  30099. parentDict.strings);
  30100. parentDict.setByKey(18, [0, 0]);
  30101. parentDict.privateDict = privateDict;
  30102. },
  30103. parsePrivateDict: function CFFParser_parsePrivateDict(parentDict) {
  30104. // no private dict, do nothing
  30105. if (!parentDict.hasName('Private')) {
  30106. this.emptyPrivateDictionary(parentDict);
  30107. return;
  30108. }
  30109. var privateOffset = parentDict.getByName('Private');
  30110. // make sure the params are formatted correctly
  30111. if (!isArray(privateOffset) || privateOffset.length !== 2) {
  30112. parentDict.removeByName('Private');
  30113. return;
  30114. }
  30115. var size = privateOffset[0];
  30116. var offset = privateOffset[1];
  30117. // remove empty dicts or ones that refer to invalid location
  30118. if (size === 0 || offset >= this.bytes.length) {
  30119. this.emptyPrivateDictionary(parentDict);
  30120. return;
  30121. }
  30122. var privateDictEnd = offset + size;
  30123. var dictData = this.bytes.subarray(offset, privateDictEnd);
  30124. var dict = this.parseDict(dictData);
  30125. var privateDict = this.createDict(CFFPrivateDict, dict,
  30126. parentDict.strings);
  30127. parentDict.privateDict = privateDict;
  30128. // Parse the Subrs index also since it's relative to the private dict.
  30129. if (!privateDict.getByName('Subrs')) {
  30130. return;
  30131. }
  30132. var subrsOffset = privateDict.getByName('Subrs');
  30133. var relativeOffset = offset + subrsOffset;
  30134. // Validate the offset.
  30135. if (subrsOffset === 0 || relativeOffset >= this.bytes.length) {
  30136. this.emptyPrivateDictionary(parentDict);
  30137. return;
  30138. }
  30139. var subrsIndex = this.parseIndex(relativeOffset);
  30140. privateDict.subrsIndex = subrsIndex.obj;
  30141. },
  30142. parseCharsets: function CFFParser_parseCharsets(pos, length, strings, cid) {
  30143. if (pos === 0) {
  30144. return new CFFCharset(true, CFFCharsetPredefinedTypes.ISO_ADOBE,
  30145. ISOAdobeCharset);
  30146. } else if (pos === 1) {
  30147. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT,
  30148. ExpertCharset);
  30149. } else if (pos === 2) {
  30150. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT_SUBSET,
  30151. ExpertSubsetCharset);
  30152. }
  30153. var bytes = this.bytes;
  30154. var start = pos;
  30155. var format = bytes[pos++];
  30156. var charset = ['.notdef'];
  30157. var id, count, i;
  30158. // subtract 1 for the .notdef glyph
  30159. length -= 1;
  30160. switch (format) {
  30161. case 0:
  30162. for (i = 0; i < length; i++) {
  30163. id = (bytes[pos++] << 8) | bytes[pos++];
  30164. charset.push(cid ? id : strings.get(id));
  30165. }
  30166. break;
  30167. case 1:
  30168. while (charset.length <= length) {
  30169. id = (bytes[pos++] << 8) | bytes[pos++];
  30170. count = bytes[pos++];
  30171. for (i = 0; i <= count; i++) {
  30172. charset.push(cid ? id++ : strings.get(id++));
  30173. }
  30174. }
  30175. break;
  30176. case 2:
  30177. while (charset.length <= length) {
  30178. id = (bytes[pos++] << 8) | bytes[pos++];
  30179. count = (bytes[pos++] << 8) | bytes[pos++];
  30180. for (i = 0; i <= count; i++) {
  30181. charset.push(cid ? id++ : strings.get(id++));
  30182. }
  30183. }
  30184. break;
  30185. default:
  30186. error('Unknown charset format');
  30187. }
  30188. // Raw won't be needed if we actually compile the charset.
  30189. var end = pos;
  30190. var raw = bytes.subarray(start, end);
  30191. return new CFFCharset(false, format, charset, raw);
  30192. },
  30193. parseEncoding: function CFFParser_parseEncoding(pos,
  30194. properties,
  30195. strings,
  30196. charset) {
  30197. var encoding = {};
  30198. var bytes = this.bytes;
  30199. var predefined = false;
  30200. var hasSupplement = false;
  30201. var format, i, ii;
  30202. var raw = null;
  30203. function readSupplement() {
  30204. var supplementsCount = bytes[pos++];
  30205. for (i = 0; i < supplementsCount; i++) {
  30206. var code = bytes[pos++];
  30207. var sid = (bytes[pos++] << 8) + (bytes[pos++] & 0xff);
  30208. encoding[code] = charset.indexOf(strings.get(sid));
  30209. }
  30210. }
  30211. if (pos === 0 || pos === 1) {
  30212. predefined = true;
  30213. format = pos;
  30214. var baseEncoding = pos ? Encodings.ExpertEncoding :
  30215. Encodings.StandardEncoding;
  30216. for (i = 0, ii = charset.length; i < ii; i++) {
  30217. var index = baseEncoding.indexOf(charset[i]);
  30218. if (index !== -1) {
  30219. encoding[index] = i;
  30220. }
  30221. }
  30222. } else {
  30223. var dataStart = pos;
  30224. format = bytes[pos++];
  30225. switch (format & 0x7f) {
  30226. case 0:
  30227. var glyphsCount = bytes[pos++];
  30228. for (i = 1; i <= glyphsCount; i++) {
  30229. encoding[bytes[pos++]] = i;
  30230. }
  30231. break;
  30232. case 1:
  30233. var rangesCount = bytes[pos++];
  30234. var gid = 1;
  30235. for (i = 0; i < rangesCount; i++) {
  30236. var start = bytes[pos++];
  30237. var left = bytes[pos++];
  30238. for (var j = start; j <= start + left; j++) {
  30239. encoding[j] = gid++;
  30240. }
  30241. }
  30242. break;
  30243. default:
  30244. error('Unknow encoding format: ' + format + ' in CFF');
  30245. break;
  30246. }
  30247. var dataEnd = pos;
  30248. if (format & 0x80) {
  30249. // The font sanitizer does not support CFF encoding with a
  30250. // supplement, since the encoding is not really used to map
  30251. // between gid to glyph, let's overwrite what is declared in
  30252. // the top dictionary to let the sanitizer think the font use
  30253. // StandardEncoding, that's a lie but that's ok.
  30254. bytes[dataStart] &= 0x7f;
  30255. readSupplement();
  30256. hasSupplement = true;
  30257. }
  30258. raw = bytes.subarray(dataStart, dataEnd);
  30259. }
  30260. format = format & 0x7f;
  30261. return new CFFEncoding(predefined, format, encoding, raw);
  30262. },
  30263. parseFDSelect: function CFFParser_parseFDSelect(pos, length) {
  30264. var start = pos;
  30265. var bytes = this.bytes;
  30266. var format = bytes[pos++];
  30267. var fdSelect = [];
  30268. var i;
  30269. switch (format) {
  30270. case 0:
  30271. for (i = 0; i < length; ++i) {
  30272. var id = bytes[pos++];
  30273. fdSelect.push(id);
  30274. }
  30275. break;
  30276. case 3:
  30277. var rangesCount = (bytes[pos++] << 8) | bytes[pos++];
  30278. for (i = 0; i < rangesCount; ++i) {
  30279. var first = (bytes[pos++] << 8) | bytes[pos++];
  30280. var fdIndex = bytes[pos++];
  30281. var next = (bytes[pos] << 8) | bytes[pos + 1];
  30282. for (var j = first; j < next; ++j) {
  30283. fdSelect.push(fdIndex);
  30284. }
  30285. }
  30286. // Advance past the sentinel(next).
  30287. pos += 2;
  30288. break;
  30289. default:
  30290. error('Unknown fdselect format ' + format);
  30291. break;
  30292. }
  30293. var end = pos;
  30294. return new CFFFDSelect(fdSelect, bytes.subarray(start, end));
  30295. }
  30296. };
  30297. return CFFParser;
  30298. })();
  30299. // Compact Font Format
  30300. var CFF = (function CFFClosure() {
  30301. function CFF() {
  30302. this.header = null;
  30303. this.names = [];
  30304. this.topDict = null;
  30305. this.strings = new CFFStrings();
  30306. this.globalSubrIndex = null;
  30307. // The following could really be per font, but since we only have one font
  30308. // store them here.
  30309. this.encoding = null;
  30310. this.charset = null;
  30311. this.charStrings = null;
  30312. this.fdArray = [];
  30313. this.fdSelect = null;
  30314. this.isCIDFont = false;
  30315. }
  30316. return CFF;
  30317. })();
  30318. var CFFHeader = (function CFFHeaderClosure() {
  30319. function CFFHeader(major, minor, hdrSize, offSize) {
  30320. this.major = major;
  30321. this.minor = minor;
  30322. this.hdrSize = hdrSize;
  30323. this.offSize = offSize;
  30324. }
  30325. return CFFHeader;
  30326. })();
  30327. var CFFStrings = (function CFFStringsClosure() {
  30328. function CFFStrings() {
  30329. this.strings = [];
  30330. }
  30331. CFFStrings.prototype = {
  30332. get: function CFFStrings_get(index) {
  30333. if (index >= 0 && index <= 390) {
  30334. return CFFStandardStrings[index];
  30335. }
  30336. if (index - 391 <= this.strings.length) {
  30337. return this.strings[index - 391];
  30338. }
  30339. return CFFStandardStrings[0];
  30340. },
  30341. add: function CFFStrings_add(value) {
  30342. this.strings.push(value);
  30343. },
  30344. get count() {
  30345. return this.strings.length;
  30346. }
  30347. };
  30348. return CFFStrings;
  30349. })();
  30350. var CFFIndex = (function CFFIndexClosure() {
  30351. function CFFIndex() {
  30352. this.objects = [];
  30353. this.length = 0;
  30354. }
  30355. CFFIndex.prototype = {
  30356. add: function CFFIndex_add(data) {
  30357. this.length += data.length;
  30358. this.objects.push(data);
  30359. },
  30360. set: function CFFIndex_set(index, data) {
  30361. this.length += data.length - this.objects[index].length;
  30362. this.objects[index] = data;
  30363. },
  30364. get: function CFFIndex_get(index) {
  30365. return this.objects[index];
  30366. },
  30367. get count() {
  30368. return this.objects.length;
  30369. }
  30370. };
  30371. return CFFIndex;
  30372. })();
  30373. var CFFDict = (function CFFDictClosure() {
  30374. function CFFDict(tables, strings) {
  30375. this.keyToNameMap = tables.keyToNameMap;
  30376. this.nameToKeyMap = tables.nameToKeyMap;
  30377. this.defaults = tables.defaults;
  30378. this.types = tables.types;
  30379. this.opcodes = tables.opcodes;
  30380. this.order = tables.order;
  30381. this.strings = strings;
  30382. this.values = {};
  30383. }
  30384. CFFDict.prototype = {
  30385. // value should always be an array
  30386. setByKey: function CFFDict_setByKey(key, value) {
  30387. if (!(key in this.keyToNameMap)) {
  30388. return false;
  30389. }
  30390. // ignore empty values
  30391. if (value.length === 0) {
  30392. return true;
  30393. }
  30394. var type = this.types[key];
  30395. // remove the array wrapping these types of values
  30396. if (type === 'num' || type === 'sid' || type === 'offset') {
  30397. value = value[0];
  30398. }
  30399. this.values[key] = value;
  30400. return true;
  30401. },
  30402. setByName: function CFFDict_setByName(name, value) {
  30403. if (!(name in this.nameToKeyMap)) {
  30404. error('Invalid dictionary name "' + name + '"');
  30405. }
  30406. this.values[this.nameToKeyMap[name]] = value;
  30407. },
  30408. hasName: function CFFDict_hasName(name) {
  30409. return this.nameToKeyMap[name] in this.values;
  30410. },
  30411. getByName: function CFFDict_getByName(name) {
  30412. if (!(name in this.nameToKeyMap)) {
  30413. error('Invalid dictionary name "' + name + '"');
  30414. }
  30415. var key = this.nameToKeyMap[name];
  30416. if (!(key in this.values)) {
  30417. return this.defaults[key];
  30418. }
  30419. return this.values[key];
  30420. },
  30421. removeByName: function CFFDict_removeByName(name) {
  30422. delete this.values[this.nameToKeyMap[name]];
  30423. }
  30424. };
  30425. CFFDict.createTables = function CFFDict_createTables(layout) {
  30426. var tables = {
  30427. keyToNameMap: {},
  30428. nameToKeyMap: {},
  30429. defaults: {},
  30430. types: {},
  30431. opcodes: {},
  30432. order: []
  30433. };
  30434. for (var i = 0, ii = layout.length; i < ii; ++i) {
  30435. var entry = layout[i];
  30436. var key = isArray(entry[0]) ? (entry[0][0] << 8) + entry[0][1] : entry[0];
  30437. tables.keyToNameMap[key] = entry[1];
  30438. tables.nameToKeyMap[entry[1]] = key;
  30439. tables.types[key] = entry[2];
  30440. tables.defaults[key] = entry[3];
  30441. tables.opcodes[key] = isArray(entry[0]) ? entry[0] : [entry[0]];
  30442. tables.order.push(key);
  30443. }
  30444. return tables;
  30445. };
  30446. return CFFDict;
  30447. })();
  30448. var CFFTopDict = (function CFFTopDictClosure() {
  30449. var layout = [
  30450. [[12, 30], 'ROS', ['sid', 'sid', 'num'], null],
  30451. [[12, 20], 'SyntheticBase', 'num', null],
  30452. [0, 'version', 'sid', null],
  30453. [1, 'Notice', 'sid', null],
  30454. [[12, 0], 'Copyright', 'sid', null],
  30455. [2, 'FullName', 'sid', null],
  30456. [3, 'FamilyName', 'sid', null],
  30457. [4, 'Weight', 'sid', null],
  30458. [[12, 1], 'isFixedPitch', 'num', 0],
  30459. [[12, 2], 'ItalicAngle', 'num', 0],
  30460. [[12, 3], 'UnderlinePosition', 'num', -100],
  30461. [[12, 4], 'UnderlineThickness', 'num', 50],
  30462. [[12, 5], 'PaintType', 'num', 0],
  30463. [[12, 6], 'CharstringType', 'num', 2],
  30464. [[12, 7], 'FontMatrix', ['num', 'num', 'num', 'num', 'num', 'num'],
  30465. [0.001, 0, 0, 0.001, 0, 0]],
  30466. [13, 'UniqueID', 'num', null],
  30467. [5, 'FontBBox', ['num', 'num', 'num', 'num'], [0, 0, 0, 0]],
  30468. [[12, 8], 'StrokeWidth', 'num', 0],
  30469. [14, 'XUID', 'array', null],
  30470. [15, 'charset', 'offset', 0],
  30471. [16, 'Encoding', 'offset', 0],
  30472. [17, 'CharStrings', 'offset', 0],
  30473. [18, 'Private', ['offset', 'offset'], null],
  30474. [[12, 21], 'PostScript', 'sid', null],
  30475. [[12, 22], 'BaseFontName', 'sid', null],
  30476. [[12, 23], 'BaseFontBlend', 'delta', null],
  30477. [[12, 31], 'CIDFontVersion', 'num', 0],
  30478. [[12, 32], 'CIDFontRevision', 'num', 0],
  30479. [[12, 33], 'CIDFontType', 'num', 0],
  30480. [[12, 34], 'CIDCount', 'num', 8720],
  30481. [[12, 35], 'UIDBase', 'num', null],
  30482. // XXX: CID Fonts on DirectWrite 6.1 only seem to work if FDSelect comes
  30483. // before FDArray.
  30484. [[12, 37], 'FDSelect', 'offset', null],
  30485. [[12, 36], 'FDArray', 'offset', null],
  30486. [[12, 38], 'FontName', 'sid', null]
  30487. ];
  30488. var tables = null;
  30489. function CFFTopDict(strings) {
  30490. if (tables === null) {
  30491. tables = CFFDict.createTables(layout);
  30492. }
  30493. CFFDict.call(this, tables, strings);
  30494. this.privateDict = null;
  30495. }
  30496. CFFTopDict.prototype = Object.create(CFFDict.prototype);
  30497. return CFFTopDict;
  30498. })();
  30499. var CFFPrivateDict = (function CFFPrivateDictClosure() {
  30500. var layout = [
  30501. [6, 'BlueValues', 'delta', null],
  30502. [7, 'OtherBlues', 'delta', null],
  30503. [8, 'FamilyBlues', 'delta', null],
  30504. [9, 'FamilyOtherBlues', 'delta', null],
  30505. [[12, 9], 'BlueScale', 'num', 0.039625],
  30506. [[12, 10], 'BlueShift', 'num', 7],
  30507. [[12, 11], 'BlueFuzz', 'num', 1],
  30508. [10, 'StdHW', 'num', null],
  30509. [11, 'StdVW', 'num', null],
  30510. [[12, 12], 'StemSnapH', 'delta', null],
  30511. [[12, 13], 'StemSnapV', 'delta', null],
  30512. [[12, 14], 'ForceBold', 'num', 0],
  30513. [[12, 17], 'LanguageGroup', 'num', 0],
  30514. [[12, 18], 'ExpansionFactor', 'num', 0.06],
  30515. [[12, 19], 'initialRandomSeed', 'num', 0],
  30516. [20, 'defaultWidthX', 'num', 0],
  30517. [21, 'nominalWidthX', 'num', 0],
  30518. [19, 'Subrs', 'offset', null]
  30519. ];
  30520. var tables = null;
  30521. function CFFPrivateDict(strings) {
  30522. if (tables === null) {
  30523. tables = CFFDict.createTables(layout);
  30524. }
  30525. CFFDict.call(this, tables, strings);
  30526. this.subrsIndex = null;
  30527. }
  30528. CFFPrivateDict.prototype = Object.create(CFFDict.prototype);
  30529. return CFFPrivateDict;
  30530. })();
  30531. var CFFCharsetPredefinedTypes = {
  30532. ISO_ADOBE: 0,
  30533. EXPERT: 1,
  30534. EXPERT_SUBSET: 2
  30535. };
  30536. var CFFCharset = (function CFFCharsetClosure() {
  30537. function CFFCharset(predefined, format, charset, raw) {
  30538. this.predefined = predefined;
  30539. this.format = format;
  30540. this.charset = charset;
  30541. this.raw = raw;
  30542. }
  30543. return CFFCharset;
  30544. })();
  30545. var CFFEncoding = (function CFFEncodingClosure() {
  30546. function CFFEncoding(predefined, format, encoding, raw) {
  30547. this.predefined = predefined;
  30548. this.format = format;
  30549. this.encoding = encoding;
  30550. this.raw = raw;
  30551. }
  30552. return CFFEncoding;
  30553. })();
  30554. var CFFFDSelect = (function CFFFDSelectClosure() {
  30555. function CFFFDSelect(fdSelect, raw) {
  30556. this.fdSelect = fdSelect;
  30557. this.raw = raw;
  30558. }
  30559. CFFFDSelect.prototype = {
  30560. getFDIndex: function CFFFDSelect_get(glyphIndex) {
  30561. if (glyphIndex < 0 || glyphIndex >= this.fdSelect.length) {
  30562. return -1;
  30563. }
  30564. return this.fdSelect[glyphIndex];
  30565. }
  30566. };
  30567. return CFFFDSelect;
  30568. })();
  30569. // Helper class to keep track of where an offset is within the data and helps
  30570. // filling in that offset once it's known.
  30571. var CFFOffsetTracker = (function CFFOffsetTrackerClosure() {
  30572. function CFFOffsetTracker() {
  30573. this.offsets = {};
  30574. }
  30575. CFFOffsetTracker.prototype = {
  30576. isTracking: function CFFOffsetTracker_isTracking(key) {
  30577. return key in this.offsets;
  30578. },
  30579. track: function CFFOffsetTracker_track(key, location) {
  30580. if (key in this.offsets) {
  30581. error('Already tracking location of ' + key);
  30582. }
  30583. this.offsets[key] = location;
  30584. },
  30585. offset: function CFFOffsetTracker_offset(value) {
  30586. for (var key in this.offsets) {
  30587. this.offsets[key] += value;
  30588. }
  30589. },
  30590. setEntryLocation: function CFFOffsetTracker_setEntryLocation(key,
  30591. values,
  30592. output) {
  30593. if (!(key in this.offsets)) {
  30594. error('Not tracking location of ' + key);
  30595. }
  30596. var data = output.data;
  30597. var dataOffset = this.offsets[key];
  30598. var size = 5;
  30599. for (var i = 0, ii = values.length; i < ii; ++i) {
  30600. var offset0 = i * size + dataOffset;
  30601. var offset1 = offset0 + 1;
  30602. var offset2 = offset0 + 2;
  30603. var offset3 = offset0 + 3;
  30604. var offset4 = offset0 + 4;
  30605. // It's easy to screw up offsets so perform this sanity check.
  30606. if (data[offset0] !== 0x1d || data[offset1] !== 0 ||
  30607. data[offset2] !== 0 || data[offset3] !== 0 || data[offset4] !== 0) {
  30608. error('writing to an offset that is not empty');
  30609. }
  30610. var value = values[i];
  30611. data[offset0] = 0x1d;
  30612. data[offset1] = (value >> 24) & 0xFF;
  30613. data[offset2] = (value >> 16) & 0xFF;
  30614. data[offset3] = (value >> 8) & 0xFF;
  30615. data[offset4] = value & 0xFF;
  30616. }
  30617. }
  30618. };
  30619. return CFFOffsetTracker;
  30620. })();
  30621. // Takes a CFF and converts it to the binary representation.
  30622. var CFFCompiler = (function CFFCompilerClosure() {
  30623. function CFFCompiler(cff) {
  30624. this.cff = cff;
  30625. }
  30626. CFFCompiler.prototype = {
  30627. compile: function CFFCompiler_compile() {
  30628. var cff = this.cff;
  30629. var output = {
  30630. data: [],
  30631. length: 0,
  30632. add: function CFFCompiler_add(data) {
  30633. this.data = this.data.concat(data);
  30634. this.length = this.data.length;
  30635. }
  30636. };
  30637. // Compile the five entries that must be in order.
  30638. var header = this.compileHeader(cff.header);
  30639. output.add(header);
  30640. var nameIndex = this.compileNameIndex(cff.names);
  30641. output.add(nameIndex);
  30642. if (cff.isCIDFont) {
  30643. // The spec is unclear on how font matrices should relate to each other
  30644. // when there is one in the main top dict and the sub top dicts.
  30645. // Windows handles this differently than linux and osx so we have to
  30646. // normalize to work on all.
  30647. // Rules based off of some mailing list discussions:
  30648. // - If main font has a matrix and subfont doesn't, use the main matrix.
  30649. // - If no main font matrix and there is a subfont matrix, use the
  30650. // subfont matrix.
  30651. // - If both have matrices, concat together.
  30652. // - If neither have matrices, use default.
  30653. // To make this work on all platforms we move the top matrix into each
  30654. // sub top dict and concat if necessary.
  30655. if (cff.topDict.hasName('FontMatrix')) {
  30656. var base = cff.topDict.getByName('FontMatrix');
  30657. cff.topDict.removeByName('FontMatrix');
  30658. for (var i = 0, ii = cff.fdArray.length; i < ii; i++) {
  30659. var subDict = cff.fdArray[i];
  30660. var matrix = base.slice(0);
  30661. if (subDict.hasName('FontMatrix')) {
  30662. matrix = Util.transform(matrix, subDict.getByName('FontMatrix'));
  30663. }
  30664. subDict.setByName('FontMatrix', matrix);
  30665. }
  30666. }
  30667. }
  30668. var compiled = this.compileTopDicts([cff.topDict],
  30669. output.length,
  30670. cff.isCIDFont);
  30671. output.add(compiled.output);
  30672. var topDictTracker = compiled.trackers[0];
  30673. var stringIndex = this.compileStringIndex(cff.strings.strings);
  30674. output.add(stringIndex);
  30675. var globalSubrIndex = this.compileIndex(cff.globalSubrIndex);
  30676. output.add(globalSubrIndex);
  30677. // Now start on the other entries that have no specfic order.
  30678. if (cff.encoding && cff.topDict.hasName('Encoding')) {
  30679. if (cff.encoding.predefined) {
  30680. topDictTracker.setEntryLocation('Encoding', [cff.encoding.format],
  30681. output);
  30682. } else {
  30683. var encoding = this.compileEncoding(cff.encoding);
  30684. topDictTracker.setEntryLocation('Encoding', [output.length], output);
  30685. output.add(encoding);
  30686. }
  30687. }
  30688. if (cff.charset && cff.topDict.hasName('charset')) {
  30689. if (cff.charset.predefined) {
  30690. topDictTracker.setEntryLocation('charset', [cff.charset.format],
  30691. output);
  30692. } else {
  30693. var charset = this.compileCharset(cff.charset);
  30694. topDictTracker.setEntryLocation('charset', [output.length], output);
  30695. output.add(charset);
  30696. }
  30697. }
  30698. var charStrings = this.compileCharStrings(cff.charStrings);
  30699. topDictTracker.setEntryLocation('CharStrings', [output.length], output);
  30700. output.add(charStrings);
  30701. if (cff.isCIDFont) {
  30702. // For some reason FDSelect must be in front of FDArray on windows. OSX
  30703. // and linux don't seem to care.
  30704. topDictTracker.setEntryLocation('FDSelect', [output.length], output);
  30705. var fdSelect = this.compileFDSelect(cff.fdSelect.raw);
  30706. output.add(fdSelect);
  30707. // It is unclear if the sub font dictionary can have CID related
  30708. // dictionary keys, but the sanitizer doesn't like them so remove them.
  30709. compiled = this.compileTopDicts(cff.fdArray, output.length, true);
  30710. topDictTracker.setEntryLocation('FDArray', [output.length], output);
  30711. output.add(compiled.output);
  30712. var fontDictTrackers = compiled.trackers;
  30713. this.compilePrivateDicts(cff.fdArray, fontDictTrackers, output);
  30714. }
  30715. this.compilePrivateDicts([cff.topDict], [topDictTracker], output);
  30716. // If the font data ends with INDEX whose object data is zero-length,
  30717. // the sanitizer will bail out. Add a dummy byte to avoid that.
  30718. output.add([0]);
  30719. return output.data;
  30720. },
  30721. encodeNumber: function CFFCompiler_encodeNumber(value) {
  30722. if (parseFloat(value) === parseInt(value, 10) && !isNaN(value)) { // isInt
  30723. return this.encodeInteger(value);
  30724. } else {
  30725. return this.encodeFloat(value);
  30726. }
  30727. },
  30728. encodeFloat: function CFFCompiler_encodeFloat(num) {
  30729. var value = num.toString();
  30730. // rounding inaccurate doubles
  30731. var m = /\.(\d*?)(?:9{5,20}|0{5,20})\d{0,2}(?:e(.+)|$)/.exec(value);
  30732. if (m) {
  30733. var epsilon = parseFloat('1e' + ((m[2] ? +m[2] : 0) + m[1].length));
  30734. value = (Math.round(num * epsilon) / epsilon).toString();
  30735. }
  30736. var nibbles = '';
  30737. var i, ii;
  30738. for (i = 0, ii = value.length; i < ii; ++i) {
  30739. var a = value[i];
  30740. if (a === 'e') {
  30741. nibbles += value[++i] === '-' ? 'c' : 'b';
  30742. } else if (a === '.') {
  30743. nibbles += 'a';
  30744. } else if (a === '-') {
  30745. nibbles += 'e';
  30746. } else {
  30747. nibbles += a;
  30748. }
  30749. }
  30750. nibbles += (nibbles.length & 1) ? 'f' : 'ff';
  30751. var out = [30];
  30752. for (i = 0, ii = nibbles.length; i < ii; i += 2) {
  30753. out.push(parseInt(nibbles.substr(i, 2), 16));
  30754. }
  30755. return out;
  30756. },
  30757. encodeInteger: function CFFCompiler_encodeInteger(value) {
  30758. var code;
  30759. if (value >= -107 && value <= 107) {
  30760. code = [value + 139];
  30761. } else if (value >= 108 && value <= 1131) {
  30762. value = [value - 108];
  30763. code = [(value >> 8) + 247, value & 0xFF];
  30764. } else if (value >= -1131 && value <= -108) {
  30765. value = -value - 108;
  30766. code = [(value >> 8) + 251, value & 0xFF];
  30767. } else if (value >= -32768 && value <= 32767) {
  30768. code = [0x1c, (value >> 8) & 0xFF, value & 0xFF];
  30769. } else {
  30770. code = [0x1d,
  30771. (value >> 24) & 0xFF,
  30772. (value >> 16) & 0xFF,
  30773. (value >> 8) & 0xFF,
  30774. value & 0xFF];
  30775. }
  30776. return code;
  30777. },
  30778. compileHeader: function CFFCompiler_compileHeader(header) {
  30779. return [
  30780. header.major,
  30781. header.minor,
  30782. header.hdrSize,
  30783. header.offSize
  30784. ];
  30785. },
  30786. compileNameIndex: function CFFCompiler_compileNameIndex(names) {
  30787. var nameIndex = new CFFIndex();
  30788. for (var i = 0, ii = names.length; i < ii; ++i) {
  30789. nameIndex.add(stringToBytes(names[i]));
  30790. }
  30791. return this.compileIndex(nameIndex);
  30792. },
  30793. compileTopDicts: function CFFCompiler_compileTopDicts(dicts,
  30794. length,
  30795. removeCidKeys) {
  30796. var fontDictTrackers = [];
  30797. var fdArrayIndex = new CFFIndex();
  30798. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  30799. var fontDict = dicts[i];
  30800. if (removeCidKeys) {
  30801. fontDict.removeByName('CIDFontVersion');
  30802. fontDict.removeByName('CIDFontRevision');
  30803. fontDict.removeByName('CIDFontType');
  30804. fontDict.removeByName('CIDCount');
  30805. fontDict.removeByName('UIDBase');
  30806. }
  30807. var fontDictTracker = new CFFOffsetTracker();
  30808. var fontDictData = this.compileDict(fontDict, fontDictTracker);
  30809. fontDictTrackers.push(fontDictTracker);
  30810. fdArrayIndex.add(fontDictData);
  30811. fontDictTracker.offset(length);
  30812. }
  30813. fdArrayIndex = this.compileIndex(fdArrayIndex, fontDictTrackers);
  30814. return {
  30815. trackers: fontDictTrackers,
  30816. output: fdArrayIndex
  30817. };
  30818. },
  30819. compilePrivateDicts: function CFFCompiler_compilePrivateDicts(dicts,
  30820. trackers,
  30821. output) {
  30822. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  30823. var fontDict = dicts[i];
  30824. assert(fontDict.privateDict && fontDict.hasName('Private'),
  30825. 'There must be an private dictionary.');
  30826. var privateDict = fontDict.privateDict;
  30827. var privateDictTracker = new CFFOffsetTracker();
  30828. var privateDictData = this.compileDict(privateDict, privateDictTracker);
  30829. var outputLength = output.length;
  30830. privateDictTracker.offset(outputLength);
  30831. if (!privateDictData.length) {
  30832. // The private dictionary was empty, set the output length to zero to
  30833. // ensure the offset length isn't out of bounds in the eyes of the
  30834. // sanitizer.
  30835. outputLength = 0;
  30836. }
  30837. trackers[i].setEntryLocation('Private',
  30838. [privateDictData.length, outputLength],
  30839. output);
  30840. output.add(privateDictData);
  30841. if (privateDict.subrsIndex && privateDict.hasName('Subrs')) {
  30842. var subrs = this.compileIndex(privateDict.subrsIndex);
  30843. privateDictTracker.setEntryLocation('Subrs', [privateDictData.length],
  30844. output);
  30845. output.add(subrs);
  30846. }
  30847. }
  30848. },
  30849. compileDict: function CFFCompiler_compileDict(dict, offsetTracker) {
  30850. var out = [];
  30851. // The dictionary keys must be in a certain order.
  30852. var order = dict.order;
  30853. for (var i = 0; i < order.length; ++i) {
  30854. var key = order[i];
  30855. if (!(key in dict.values)) {
  30856. continue;
  30857. }
  30858. var values = dict.values[key];
  30859. var types = dict.types[key];
  30860. if (!isArray(types)) {
  30861. types = [types];
  30862. }
  30863. if (!isArray(values)) {
  30864. values = [values];
  30865. }
  30866. // Remove any empty dict values.
  30867. if (values.length === 0) {
  30868. continue;
  30869. }
  30870. for (var j = 0, jj = types.length; j < jj; ++j) {
  30871. var type = types[j];
  30872. var value = values[j];
  30873. switch (type) {
  30874. case 'num':
  30875. case 'sid':
  30876. out = out.concat(this.encodeNumber(value));
  30877. break;
  30878. case 'offset':
  30879. // For offsets we just insert a 32bit integer so we don't have to
  30880. // deal with figuring out the length of the offset when it gets
  30881. // replaced later on by the compiler.
  30882. var name = dict.keyToNameMap[key];
  30883. // Some offsets have the offset and the length, so just record the
  30884. // position of the first one.
  30885. if (!offsetTracker.isTracking(name)) {
  30886. offsetTracker.track(name, out.length);
  30887. }
  30888. out = out.concat([0x1d, 0, 0, 0, 0]);
  30889. break;
  30890. case 'array':
  30891. case 'delta':
  30892. out = out.concat(this.encodeNumber(value));
  30893. for (var k = 1, kk = values.length; k < kk; ++k) {
  30894. out = out.concat(this.encodeNumber(values[k]));
  30895. }
  30896. break;
  30897. default:
  30898. error('Unknown data type of ' + type);
  30899. break;
  30900. }
  30901. }
  30902. out = out.concat(dict.opcodes[key]);
  30903. }
  30904. return out;
  30905. },
  30906. compileStringIndex: function CFFCompiler_compileStringIndex(strings) {
  30907. var stringIndex = new CFFIndex();
  30908. for (var i = 0, ii = strings.length; i < ii; ++i) {
  30909. stringIndex.add(stringToBytes(strings[i]));
  30910. }
  30911. return this.compileIndex(stringIndex);
  30912. },
  30913. compileGlobalSubrIndex: function CFFCompiler_compileGlobalSubrIndex() {
  30914. var globalSubrIndex = this.cff.globalSubrIndex;
  30915. this.out.writeByteArray(this.compileIndex(globalSubrIndex));
  30916. },
  30917. compileCharStrings: function CFFCompiler_compileCharStrings(charStrings) {
  30918. return this.compileIndex(charStrings);
  30919. },
  30920. compileCharset: function CFFCompiler_compileCharset(charset) {
  30921. return this.compileTypedArray(charset.raw);
  30922. },
  30923. compileEncoding: function CFFCompiler_compileEncoding(encoding) {
  30924. return this.compileTypedArray(encoding.raw);
  30925. },
  30926. compileFDSelect: function CFFCompiler_compileFDSelect(fdSelect) {
  30927. return this.compileTypedArray(fdSelect);
  30928. },
  30929. compileTypedArray: function CFFCompiler_compileTypedArray(data) {
  30930. var out = [];
  30931. for (var i = 0, ii = data.length; i < ii; ++i) {
  30932. out[i] = data[i];
  30933. }
  30934. return out;
  30935. },
  30936. compileIndex: function CFFCompiler_compileIndex(index, trackers) {
  30937. trackers = trackers || [];
  30938. var objects = index.objects;
  30939. // First 2 bytes contains the number of objects contained into this index
  30940. var count = objects.length;
  30941. // If there is no object, just create an index. This technically
  30942. // should just be [0, 0] but OTS has an issue with that.
  30943. if (count === 0) {
  30944. return [0, 0, 0];
  30945. }
  30946. var data = [(count >> 8) & 0xFF, count & 0xff];
  30947. var lastOffset = 1, i;
  30948. for (i = 0; i < count; ++i) {
  30949. lastOffset += objects[i].length;
  30950. }
  30951. var offsetSize;
  30952. if (lastOffset < 0x100) {
  30953. offsetSize = 1;
  30954. } else if (lastOffset < 0x10000) {
  30955. offsetSize = 2;
  30956. } else if (lastOffset < 0x1000000) {
  30957. offsetSize = 3;
  30958. } else {
  30959. offsetSize = 4;
  30960. }
  30961. // Next byte contains the offset size use to reference object in the file
  30962. data.push(offsetSize);
  30963. // Add another offset after this one because we need a new offset
  30964. var relativeOffset = 1;
  30965. for (i = 0; i < count + 1; i++) {
  30966. if (offsetSize === 1) {
  30967. data.push(relativeOffset & 0xFF);
  30968. } else if (offsetSize === 2) {
  30969. data.push((relativeOffset >> 8) & 0xFF,
  30970. relativeOffset & 0xFF);
  30971. } else if (offsetSize === 3) {
  30972. data.push((relativeOffset >> 16) & 0xFF,
  30973. (relativeOffset >> 8) & 0xFF,
  30974. relativeOffset & 0xFF);
  30975. } else {
  30976. data.push((relativeOffset >>> 24) & 0xFF,
  30977. (relativeOffset >> 16) & 0xFF,
  30978. (relativeOffset >> 8) & 0xFF,
  30979. relativeOffset & 0xFF);
  30980. }
  30981. if (objects[i]) {
  30982. relativeOffset += objects[i].length;
  30983. }
  30984. }
  30985. for (i = 0; i < count; i++) {
  30986. // Notify the tracker where the object will be offset in the data.
  30987. if (trackers[i]) {
  30988. trackers[i].offset(data.length);
  30989. }
  30990. for (var j = 0, jj = objects[i].length; j < jj; j++) {
  30991. data.push(objects[i][j]);
  30992. }
  30993. }
  30994. return data;
  30995. }
  30996. };
  30997. return CFFCompiler;
  30998. })();
  30999. function _enableSeacAnalysis(enabled) {
  31000. exports.SEAC_ANALYSIS_ENABLED = SEAC_ANALYSIS_ENABLED = enabled;
  31001. }
  31002. // Workaround for seac on Windows.
  31003. (function checkSeacSupport() {
  31004. if (typeof navigator !== 'undefined' && /Windows/.test(navigator.userAgent)) {
  31005. SEAC_ANALYSIS_ENABLED = true;
  31006. }
  31007. })();
  31008. // Workaround for Private Use Area characters in Chrome on Windows
  31009. // http://code.google.com/p/chromium/issues/detail?id=122465
  31010. // https://github.com/mozilla/pdf.js/issues/1689
  31011. (function checkChromeWindows() {
  31012. if (typeof navigator !== 'undefined' &&
  31013. /Windows.*Chrome/.test(navigator.userAgent)) {
  31014. SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = true;
  31015. }
  31016. })();
  31017. exports.SEAC_ANALYSIS_ENABLED = SEAC_ANALYSIS_ENABLED;
  31018. exports.CFFCompiler = CFFCompiler;
  31019. exports.CFFIndex = CFFIndex;
  31020. exports.CFFParser = CFFParser;
  31021. exports.CFFStrings = CFFStrings;
  31022. exports.Encodings = Encodings;
  31023. exports.ErrorFont = ErrorFont;
  31024. exports.FontFlags = FontFlags;
  31025. exports.Font = Font;
  31026. exports.IdentityToUnicodeMap = IdentityToUnicodeMap;
  31027. exports.NormalizedUnicodes = NormalizedUnicodes;
  31028. exports.ToUnicodeMap = ToUnicodeMap;
  31029. exports.Type1Parser = Type1Parser;
  31030. exports.getFontType = getFontType;
  31031. exports.reverseIfRtl = reverseIfRtl;
  31032. exports.serifFonts = serifFonts;
  31033. exports.symbolsFonts = symbolsFonts;
  31034. exports.stdFontMap = stdFontMap;
  31035. exports._enableSeacAnalysis = _enableSeacAnalysis;
  31036. // TODO refactor to remove cyclic dependency on font_renderer.js
  31037. coreFontRenderer._setCoreFonts(exports);
  31038. }));
  31039. (function (root, factory) {
  31040. {
  31041. factory((root.pdfjsCoreFunction = {}), root.pdfjsSharedUtil,
  31042. root.pdfjsCorePrimitives, root.pdfjsCorePsParser);
  31043. }
  31044. }(this, function (exports, sharedUtil, corePrimitives, corePsParser) {
  31045. var error = sharedUtil.error;
  31046. var info = sharedUtil.info;
  31047. var isArray = sharedUtil.isArray;
  31048. var isBool = sharedUtil.isBool;
  31049. var isDict = corePrimitives.isDict;
  31050. var isStream = corePrimitives.isStream;
  31051. var PostScriptLexer = corePsParser.PostScriptLexer;
  31052. var PostScriptParser = corePsParser.PostScriptParser;
  31053. var PDFFunction = (function PDFFunctionClosure() {
  31054. var CONSTRUCT_SAMPLED = 0;
  31055. var CONSTRUCT_INTERPOLATED = 2;
  31056. var CONSTRUCT_STICHED = 3;
  31057. var CONSTRUCT_POSTSCRIPT = 4;
  31058. return {
  31059. getSampleArray: function PDFFunction_getSampleArray(size, outputSize, bps,
  31060. str) {
  31061. var i, ii;
  31062. var length = 1;
  31063. for (i = 0, ii = size.length; i < ii; i++) {
  31064. length *= size[i];
  31065. }
  31066. length *= outputSize;
  31067. var array = new Array(length);
  31068. var codeSize = 0;
  31069. var codeBuf = 0;
  31070. // 32 is a valid bps so shifting won't work
  31071. var sampleMul = 1.0 / (Math.pow(2.0, bps) - 1);
  31072. var strBytes = str.getBytes((length * bps + 7) / 8);
  31073. var strIdx = 0;
  31074. for (i = 0; i < length; i++) {
  31075. while (codeSize < bps) {
  31076. codeBuf <<= 8;
  31077. codeBuf |= strBytes[strIdx++];
  31078. codeSize += 8;
  31079. }
  31080. codeSize -= bps;
  31081. array[i] = (codeBuf >> codeSize) * sampleMul;
  31082. codeBuf &= (1 << codeSize) - 1;
  31083. }
  31084. return array;
  31085. },
  31086. getIR: function PDFFunction_getIR(xref, fn) {
  31087. var dict = fn.dict;
  31088. if (!dict) {
  31089. dict = fn;
  31090. }
  31091. var types = [this.constructSampled,
  31092. null,
  31093. this.constructInterpolated,
  31094. this.constructStiched,
  31095. this.constructPostScript];
  31096. var typeNum = dict.get('FunctionType');
  31097. var typeFn = types[typeNum];
  31098. if (!typeFn) {
  31099. error('Unknown type of function');
  31100. }
  31101. return typeFn.call(this, fn, dict, xref);
  31102. },
  31103. fromIR: function PDFFunction_fromIR(IR) {
  31104. var type = IR[0];
  31105. switch (type) {
  31106. case CONSTRUCT_SAMPLED:
  31107. return this.constructSampledFromIR(IR);
  31108. case CONSTRUCT_INTERPOLATED:
  31109. return this.constructInterpolatedFromIR(IR);
  31110. case CONSTRUCT_STICHED:
  31111. return this.constructStichedFromIR(IR);
  31112. //case CONSTRUCT_POSTSCRIPT:
  31113. default:
  31114. return this.constructPostScriptFromIR(IR);
  31115. }
  31116. },
  31117. parse: function PDFFunction_parse(xref, fn) {
  31118. var IR = this.getIR(xref, fn);
  31119. return this.fromIR(IR);
  31120. },
  31121. parseArray: function PDFFunction_parseArray(xref, fnObj) {
  31122. if (!isArray(fnObj)) {
  31123. // not an array -- parsing as regular function
  31124. return this.parse(xref, fnObj);
  31125. }
  31126. var fnArray = [];
  31127. for (var j = 0, jj = fnObj.length; j < jj; j++) {
  31128. var obj = xref.fetchIfRef(fnObj[j]);
  31129. fnArray.push(PDFFunction.parse(xref, obj));
  31130. }
  31131. return function (src, srcOffset, dest, destOffset) {
  31132. for (var i = 0, ii = fnArray.length; i < ii; i++) {
  31133. fnArray[i](src, srcOffset, dest, destOffset + i);
  31134. }
  31135. };
  31136. },
  31137. constructSampled: function PDFFunction_constructSampled(str, dict) {
  31138. function toMultiArray(arr) {
  31139. var inputLength = arr.length;
  31140. var out = [];
  31141. var index = 0;
  31142. for (var i = 0; i < inputLength; i += 2) {
  31143. out[index] = [arr[i], arr[i + 1]];
  31144. ++index;
  31145. }
  31146. return out;
  31147. }
  31148. var domain = dict.get('Domain');
  31149. var range = dict.get('Range');
  31150. if (!domain || !range) {
  31151. error('No domain or range');
  31152. }
  31153. var inputSize = domain.length / 2;
  31154. var outputSize = range.length / 2;
  31155. domain = toMultiArray(domain);
  31156. range = toMultiArray(range);
  31157. var size = dict.get('Size');
  31158. var bps = dict.get('BitsPerSample');
  31159. var order = dict.get('Order') || 1;
  31160. if (order !== 1) {
  31161. // No description how cubic spline interpolation works in PDF32000:2008
  31162. // As in poppler, ignoring order, linear interpolation may work as good
  31163. info('No support for cubic spline interpolation: ' + order);
  31164. }
  31165. var encode = dict.get('Encode');
  31166. if (!encode) {
  31167. encode = [];
  31168. for (var i = 0; i < inputSize; ++i) {
  31169. encode.push(0);
  31170. encode.push(size[i] - 1);
  31171. }
  31172. }
  31173. encode = toMultiArray(encode);
  31174. var decode = dict.get('Decode');
  31175. if (!decode) {
  31176. decode = range;
  31177. } else {
  31178. decode = toMultiArray(decode);
  31179. }
  31180. var samples = this.getSampleArray(size, outputSize, bps, str);
  31181. return [
  31182. CONSTRUCT_SAMPLED, inputSize, domain, encode, decode, samples, size,
  31183. outputSize, Math.pow(2, bps) - 1, range
  31184. ];
  31185. },
  31186. constructSampledFromIR: function PDFFunction_constructSampledFromIR(IR) {
  31187. // See chapter 3, page 109 of the PDF reference
  31188. function interpolate(x, xmin, xmax, ymin, ymax) {
  31189. return ymin + ((x - xmin) * ((ymax - ymin) / (xmax - xmin)));
  31190. }
  31191. return function constructSampledFromIRResult(src, srcOffset,
  31192. dest, destOffset) {
  31193. // See chapter 3, page 110 of the PDF reference.
  31194. var m = IR[1];
  31195. var domain = IR[2];
  31196. var encode = IR[3];
  31197. var decode = IR[4];
  31198. var samples = IR[5];
  31199. var size = IR[6];
  31200. var n = IR[7];
  31201. //var mask = IR[8];
  31202. var range = IR[9];
  31203. // Building the cube vertices: its part and sample index
  31204. // http://rjwagner49.com/Mathematics/Interpolation.pdf
  31205. var cubeVertices = 1 << m;
  31206. var cubeN = new Float64Array(cubeVertices);
  31207. var cubeVertex = new Uint32Array(cubeVertices);
  31208. var i, j;
  31209. for (j = 0; j < cubeVertices; j++) {
  31210. cubeN[j] = 1;
  31211. }
  31212. var k = n, pos = 1;
  31213. // Map x_i to y_j for 0 <= i < m using the sampled function.
  31214. for (i = 0; i < m; ++i) {
  31215. // x_i' = min(max(x_i, Domain_2i), Domain_2i+1)
  31216. var domain_2i = domain[i][0];
  31217. var domain_2i_1 = domain[i][1];
  31218. var xi = Math.min(Math.max(src[srcOffset +i], domain_2i),
  31219. domain_2i_1);
  31220. // e_i = Interpolate(x_i', Domain_2i, Domain_2i+1,
  31221. // Encode_2i, Encode_2i+1)
  31222. var e = interpolate(xi, domain_2i, domain_2i_1,
  31223. encode[i][0], encode[i][1]);
  31224. // e_i' = min(max(e_i, 0), Size_i - 1)
  31225. var size_i = size[i];
  31226. e = Math.min(Math.max(e, 0), size_i - 1);
  31227. // Adjusting the cube: N and vertex sample index
  31228. var e0 = e < size_i - 1 ? Math.floor(e) : e - 1; // e1 = e0 + 1;
  31229. var n0 = e0 + 1 - e; // (e1 - e) / (e1 - e0);
  31230. var n1 = e - e0; // (e - e0) / (e1 - e0);
  31231. var offset0 = e0 * k;
  31232. var offset1 = offset0 + k; // e1 * k
  31233. for (j = 0; j < cubeVertices; j++) {
  31234. if (j & pos) {
  31235. cubeN[j] *= n1;
  31236. cubeVertex[j] += offset1;
  31237. } else {
  31238. cubeN[j] *= n0;
  31239. cubeVertex[j] += offset0;
  31240. }
  31241. }
  31242. k *= size_i;
  31243. pos <<= 1;
  31244. }
  31245. for (j = 0; j < n; ++j) {
  31246. // Sum all cube vertices' samples portions
  31247. var rj = 0;
  31248. for (i = 0; i < cubeVertices; i++) {
  31249. rj += samples[cubeVertex[i] + j] * cubeN[i];
  31250. }
  31251. // r_j' = Interpolate(r_j, 0, 2^BitsPerSample - 1,
  31252. // Decode_2j, Decode_2j+1)
  31253. rj = interpolate(rj, 0, 1, decode[j][0], decode[j][1]);
  31254. // y_j = min(max(r_j, range_2j), range_2j+1)
  31255. dest[destOffset + j] = Math.min(Math.max(rj, range[j][0]),
  31256. range[j][1]);
  31257. }
  31258. };
  31259. },
  31260. constructInterpolated: function PDFFunction_constructInterpolated(str,
  31261. dict) {
  31262. var c0 = dict.get('C0') || [0];
  31263. var c1 = dict.get('C1') || [1];
  31264. var n = dict.get('N');
  31265. if (!isArray(c0) || !isArray(c1)) {
  31266. error('Illegal dictionary for interpolated function');
  31267. }
  31268. var length = c0.length;
  31269. var diff = [];
  31270. for (var i = 0; i < length; ++i) {
  31271. diff.push(c1[i] - c0[i]);
  31272. }
  31273. return [CONSTRUCT_INTERPOLATED, c0, diff, n];
  31274. },
  31275. constructInterpolatedFromIR:
  31276. function PDFFunction_constructInterpolatedFromIR(IR) {
  31277. var c0 = IR[1];
  31278. var diff = IR[2];
  31279. var n = IR[3];
  31280. var length = diff.length;
  31281. return function constructInterpolatedFromIRResult(src, srcOffset,
  31282. dest, destOffset) {
  31283. var x = n === 1 ? src[srcOffset] : Math.pow(src[srcOffset], n);
  31284. for (var j = 0; j < length; ++j) {
  31285. dest[destOffset + j] = c0[j] + (x * diff[j]);
  31286. }
  31287. };
  31288. },
  31289. constructStiched: function PDFFunction_constructStiched(fn, dict, xref) {
  31290. var domain = dict.get('Domain');
  31291. if (!domain) {
  31292. error('No domain');
  31293. }
  31294. var inputSize = domain.length / 2;
  31295. if (inputSize !== 1) {
  31296. error('Bad domain for stiched function');
  31297. }
  31298. var fnRefs = dict.get('Functions');
  31299. var fns = [];
  31300. for (var i = 0, ii = fnRefs.length; i < ii; ++i) {
  31301. fns.push(PDFFunction.getIR(xref, xref.fetchIfRef(fnRefs[i])));
  31302. }
  31303. var bounds = dict.get('Bounds');
  31304. var encode = dict.get('Encode');
  31305. return [CONSTRUCT_STICHED, domain, bounds, encode, fns];
  31306. },
  31307. constructStichedFromIR: function PDFFunction_constructStichedFromIR(IR) {
  31308. var domain = IR[1];
  31309. var bounds = IR[2];
  31310. var encode = IR[3];
  31311. var fnsIR = IR[4];
  31312. var fns = [];
  31313. var tmpBuf = new Float32Array(1);
  31314. for (var i = 0, ii = fnsIR.length; i < ii; i++) {
  31315. fns.push(PDFFunction.fromIR(fnsIR[i]));
  31316. }
  31317. return function constructStichedFromIRResult(src, srcOffset,
  31318. dest, destOffset) {
  31319. var clip = function constructStichedFromIRClip(v, min, max) {
  31320. if (v > max) {
  31321. v = max;
  31322. } else if (v < min) {
  31323. v = min;
  31324. }
  31325. return v;
  31326. };
  31327. // clip to domain
  31328. var v = clip(src[srcOffset], domain[0], domain[1]);
  31329. // calulate which bound the value is in
  31330. for (var i = 0, ii = bounds.length; i < ii; ++i) {
  31331. if (v < bounds[i]) {
  31332. break;
  31333. }
  31334. }
  31335. // encode value into domain of function
  31336. var dmin = domain[0];
  31337. if (i > 0) {
  31338. dmin = bounds[i - 1];
  31339. }
  31340. var dmax = domain[1];
  31341. if (i < bounds.length) {
  31342. dmax = bounds[i];
  31343. }
  31344. var rmin = encode[2 * i];
  31345. var rmax = encode[2 * i + 1];
  31346. // Prevent the value from becoming NaN as a result
  31347. // of division by zero (fixes issue6113.pdf).
  31348. tmpBuf[0] = dmin === dmax ? rmin :
  31349. rmin + (v - dmin) * (rmax - rmin) / (dmax - dmin);
  31350. // call the appropriate function
  31351. fns[i](tmpBuf, 0, dest, destOffset);
  31352. };
  31353. },
  31354. constructPostScript: function PDFFunction_constructPostScript(fn, dict,
  31355. xref) {
  31356. var domain = dict.get('Domain');
  31357. var range = dict.get('Range');
  31358. if (!domain) {
  31359. error('No domain.');
  31360. }
  31361. if (!range) {
  31362. error('No range.');
  31363. }
  31364. var lexer = new PostScriptLexer(fn);
  31365. var parser = new PostScriptParser(lexer);
  31366. var code = parser.parse();
  31367. return [CONSTRUCT_POSTSCRIPT, domain, range, code];
  31368. },
  31369. constructPostScriptFromIR: function PDFFunction_constructPostScriptFromIR(
  31370. IR) {
  31371. var domain = IR[1];
  31372. var range = IR[2];
  31373. var code = IR[3];
  31374. var compiled = (new PostScriptCompiler()).compile(code, domain, range);
  31375. if (compiled) {
  31376. // Compiled function consists of simple expressions such as addition,
  31377. // subtraction, Math.max, and also contains 'var' and 'return'
  31378. // statements. See the generation in the PostScriptCompiler below.
  31379. /*jshint -W054 */
  31380. return new Function('src', 'srcOffset', 'dest', 'destOffset', compiled);
  31381. }
  31382. info('Unable to compile PS function');
  31383. var numOutputs = range.length >> 1;
  31384. var numInputs = domain.length >> 1;
  31385. var evaluator = new PostScriptEvaluator(code);
  31386. // Cache the values for a big speed up, the cache size is limited though
  31387. // since the number of possible values can be huge from a PS function.
  31388. var cache = {};
  31389. // The MAX_CACHE_SIZE is set to ~4x the maximum number of distinct values
  31390. // seen in our tests.
  31391. var MAX_CACHE_SIZE = 2048 * 4;
  31392. var cache_available = MAX_CACHE_SIZE;
  31393. var tmpBuf = new Float32Array(numInputs);
  31394. return function constructPostScriptFromIRResult(src, srcOffset,
  31395. dest, destOffset) {
  31396. var i, value;
  31397. var key = '';
  31398. var input = tmpBuf;
  31399. for (i = 0; i < numInputs; i++) {
  31400. value = src[srcOffset + i];
  31401. input[i] = value;
  31402. key += value + '_';
  31403. }
  31404. var cachedValue = cache[key];
  31405. if (cachedValue !== undefined) {
  31406. dest.set(cachedValue, destOffset);
  31407. return;
  31408. }
  31409. var output = new Float32Array(numOutputs);
  31410. var stack = evaluator.execute(input);
  31411. var stackIndex = stack.length - numOutputs;
  31412. for (i = 0; i < numOutputs; i++) {
  31413. value = stack[stackIndex + i];
  31414. var bound = range[i * 2];
  31415. if (value < bound) {
  31416. value = bound;
  31417. } else {
  31418. bound = range[i * 2 +1];
  31419. if (value > bound) {
  31420. value = bound;
  31421. }
  31422. }
  31423. output[i] = value;
  31424. }
  31425. if (cache_available > 0) {
  31426. cache_available--;
  31427. cache[key] = output;
  31428. }
  31429. dest.set(output, destOffset);
  31430. };
  31431. }
  31432. };
  31433. })();
  31434. function isPDFFunction(v) {
  31435. var fnDict;
  31436. if (typeof v !== 'object') {
  31437. return false;
  31438. } else if (isDict(v)) {
  31439. fnDict = v;
  31440. } else if (isStream(v)) {
  31441. fnDict = v.dict;
  31442. } else {
  31443. return false;
  31444. }
  31445. return fnDict.has('FunctionType');
  31446. }
  31447. var PostScriptStack = (function PostScriptStackClosure() {
  31448. var MAX_STACK_SIZE = 100;
  31449. function PostScriptStack(initialStack) {
  31450. this.stack = !initialStack ? [] :
  31451. Array.prototype.slice.call(initialStack, 0);
  31452. }
  31453. PostScriptStack.prototype = {
  31454. push: function PostScriptStack_push(value) {
  31455. if (this.stack.length >= MAX_STACK_SIZE) {
  31456. error('PostScript function stack overflow.');
  31457. }
  31458. this.stack.push(value);
  31459. },
  31460. pop: function PostScriptStack_pop() {
  31461. if (this.stack.length <= 0) {
  31462. error('PostScript function stack underflow.');
  31463. }
  31464. return this.stack.pop();
  31465. },
  31466. copy: function PostScriptStack_copy(n) {
  31467. if (this.stack.length + n >= MAX_STACK_SIZE) {
  31468. error('PostScript function stack overflow.');
  31469. }
  31470. var stack = this.stack;
  31471. for (var i = stack.length - n, j = n - 1; j >= 0; j--, i++) {
  31472. stack.push(stack[i]);
  31473. }
  31474. },
  31475. index: function PostScriptStack_index(n) {
  31476. this.push(this.stack[this.stack.length - n - 1]);
  31477. },
  31478. // rotate the last n stack elements p times
  31479. roll: function PostScriptStack_roll(n, p) {
  31480. var stack = this.stack;
  31481. var l = stack.length - n;
  31482. var r = stack.length - 1, c = l + (p - Math.floor(p / n) * n), i, j, t;
  31483. for (i = l, j = r; i < j; i++, j--) {
  31484. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  31485. }
  31486. for (i = l, j = c - 1; i < j; i++, j--) {
  31487. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  31488. }
  31489. for (i = c, j = r; i < j; i++, j--) {
  31490. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  31491. }
  31492. }
  31493. };
  31494. return PostScriptStack;
  31495. })();
  31496. var PostScriptEvaluator = (function PostScriptEvaluatorClosure() {
  31497. function PostScriptEvaluator(operators) {
  31498. this.operators = operators;
  31499. }
  31500. PostScriptEvaluator.prototype = {
  31501. execute: function PostScriptEvaluator_execute(initialStack) {
  31502. var stack = new PostScriptStack(initialStack);
  31503. var counter = 0;
  31504. var operators = this.operators;
  31505. var length = operators.length;
  31506. var operator, a, b;
  31507. while (counter < length) {
  31508. operator = operators[counter++];
  31509. if (typeof operator === 'number') {
  31510. // Operator is really an operand and should be pushed to the stack.
  31511. stack.push(operator);
  31512. continue;
  31513. }
  31514. switch (operator) {
  31515. // non standard ps operators
  31516. case 'jz': // jump if false
  31517. b = stack.pop();
  31518. a = stack.pop();
  31519. if (!a) {
  31520. counter = b;
  31521. }
  31522. break;
  31523. case 'j': // jump
  31524. a = stack.pop();
  31525. counter = a;
  31526. break;
  31527. // all ps operators in alphabetical order (excluding if/ifelse)
  31528. case 'abs':
  31529. a = stack.pop();
  31530. stack.push(Math.abs(a));
  31531. break;
  31532. case 'add':
  31533. b = stack.pop();
  31534. a = stack.pop();
  31535. stack.push(a + b);
  31536. break;
  31537. case 'and':
  31538. b = stack.pop();
  31539. a = stack.pop();
  31540. if (isBool(a) && isBool(b)) {
  31541. stack.push(a && b);
  31542. } else {
  31543. stack.push(a & b);
  31544. }
  31545. break;
  31546. case 'atan':
  31547. a = stack.pop();
  31548. stack.push(Math.atan(a));
  31549. break;
  31550. case 'bitshift':
  31551. b = stack.pop();
  31552. a = stack.pop();
  31553. if (a > 0) {
  31554. stack.push(a << b);
  31555. } else {
  31556. stack.push(a >> b);
  31557. }
  31558. break;
  31559. case 'ceiling':
  31560. a = stack.pop();
  31561. stack.push(Math.ceil(a));
  31562. break;
  31563. case 'copy':
  31564. a = stack.pop();
  31565. stack.copy(a);
  31566. break;
  31567. case 'cos':
  31568. a = stack.pop();
  31569. stack.push(Math.cos(a));
  31570. break;
  31571. case 'cvi':
  31572. a = stack.pop() | 0;
  31573. stack.push(a);
  31574. break;
  31575. case 'cvr':
  31576. // noop
  31577. break;
  31578. case 'div':
  31579. b = stack.pop();
  31580. a = stack.pop();
  31581. stack.push(a / b);
  31582. break;
  31583. case 'dup':
  31584. stack.copy(1);
  31585. break;
  31586. case 'eq':
  31587. b = stack.pop();
  31588. a = stack.pop();
  31589. stack.push(a === b);
  31590. break;
  31591. case 'exch':
  31592. stack.roll(2, 1);
  31593. break;
  31594. case 'exp':
  31595. b = stack.pop();
  31596. a = stack.pop();
  31597. stack.push(Math.pow(a, b));
  31598. break;
  31599. case 'false':
  31600. stack.push(false);
  31601. break;
  31602. case 'floor':
  31603. a = stack.pop();
  31604. stack.push(Math.floor(a));
  31605. break;
  31606. case 'ge':
  31607. b = stack.pop();
  31608. a = stack.pop();
  31609. stack.push(a >= b);
  31610. break;
  31611. case 'gt':
  31612. b = stack.pop();
  31613. a = stack.pop();
  31614. stack.push(a > b);
  31615. break;
  31616. case 'idiv':
  31617. b = stack.pop();
  31618. a = stack.pop();
  31619. stack.push((a / b) | 0);
  31620. break;
  31621. case 'index':
  31622. a = stack.pop();
  31623. stack.index(a);
  31624. break;
  31625. case 'le':
  31626. b = stack.pop();
  31627. a = stack.pop();
  31628. stack.push(a <= b);
  31629. break;
  31630. case 'ln':
  31631. a = stack.pop();
  31632. stack.push(Math.log(a));
  31633. break;
  31634. case 'log':
  31635. a = stack.pop();
  31636. stack.push(Math.log(a) / Math.LN10);
  31637. break;
  31638. case 'lt':
  31639. b = stack.pop();
  31640. a = stack.pop();
  31641. stack.push(a < b);
  31642. break;
  31643. case 'mod':
  31644. b = stack.pop();
  31645. a = stack.pop();
  31646. stack.push(a % b);
  31647. break;
  31648. case 'mul':
  31649. b = stack.pop();
  31650. a = stack.pop();
  31651. stack.push(a * b);
  31652. break;
  31653. case 'ne':
  31654. b = stack.pop();
  31655. a = stack.pop();
  31656. stack.push(a !== b);
  31657. break;
  31658. case 'neg':
  31659. a = stack.pop();
  31660. stack.push(-a);
  31661. break;
  31662. case 'not':
  31663. a = stack.pop();
  31664. if (isBool(a)) {
  31665. stack.push(!a);
  31666. } else {
  31667. stack.push(~a);
  31668. }
  31669. break;
  31670. case 'or':
  31671. b = stack.pop();
  31672. a = stack.pop();
  31673. if (isBool(a) && isBool(b)) {
  31674. stack.push(a || b);
  31675. } else {
  31676. stack.push(a | b);
  31677. }
  31678. break;
  31679. case 'pop':
  31680. stack.pop();
  31681. break;
  31682. case 'roll':
  31683. b = stack.pop();
  31684. a = stack.pop();
  31685. stack.roll(a, b);
  31686. break;
  31687. case 'round':
  31688. a = stack.pop();
  31689. stack.push(Math.round(a));
  31690. break;
  31691. case 'sin':
  31692. a = stack.pop();
  31693. stack.push(Math.sin(a));
  31694. break;
  31695. case 'sqrt':
  31696. a = stack.pop();
  31697. stack.push(Math.sqrt(a));
  31698. break;
  31699. case 'sub':
  31700. b = stack.pop();
  31701. a = stack.pop();
  31702. stack.push(a - b);
  31703. break;
  31704. case 'true':
  31705. stack.push(true);
  31706. break;
  31707. case 'truncate':
  31708. a = stack.pop();
  31709. a = a < 0 ? Math.ceil(a) : Math.floor(a);
  31710. stack.push(a);
  31711. break;
  31712. case 'xor':
  31713. b = stack.pop();
  31714. a = stack.pop();
  31715. if (isBool(a) && isBool(b)) {
  31716. stack.push(a !== b);
  31717. } else {
  31718. stack.push(a ^ b);
  31719. }
  31720. break;
  31721. default:
  31722. error('Unknown operator ' + operator);
  31723. break;
  31724. }
  31725. }
  31726. return stack.stack;
  31727. }
  31728. };
  31729. return PostScriptEvaluator;
  31730. })();
  31731. // Most of the PDFs functions consist of simple operations such as:
  31732. // roll, exch, sub, cvr, pop, index, dup, mul, if, gt, add.
  31733. //
  31734. // We can compile most of such programs, and at the same moment, we can
  31735. // optimize some expressions using basic math properties. Keeping track of
  31736. // min/max values will allow us to avoid extra Math.min/Math.max calls.
  31737. var PostScriptCompiler = (function PostScriptCompilerClosure() {
  31738. function AstNode(type) {
  31739. this.type = type;
  31740. }
  31741. AstNode.prototype.visit = function (visitor) {
  31742. throw new Error('abstract method');
  31743. };
  31744. function AstArgument(index, min, max) {
  31745. AstNode.call(this, 'args');
  31746. this.index = index;
  31747. this.min = min;
  31748. this.max = max;
  31749. }
  31750. AstArgument.prototype = Object.create(AstNode.prototype);
  31751. AstArgument.prototype.visit = function (visitor) {
  31752. visitor.visitArgument(this);
  31753. };
  31754. function AstLiteral(number) {
  31755. AstNode.call(this, 'literal');
  31756. this.number = number;
  31757. this.min = number;
  31758. this.max = number;
  31759. }
  31760. AstLiteral.prototype = Object.create(AstNode.prototype);
  31761. AstLiteral.prototype.visit = function (visitor) {
  31762. visitor.visitLiteral(this);
  31763. };
  31764. function AstBinaryOperation(op, arg1, arg2, min, max) {
  31765. AstNode.call(this, 'binary');
  31766. this.op = op;
  31767. this.arg1 = arg1;
  31768. this.arg2 = arg2;
  31769. this.min = min;
  31770. this.max = max;
  31771. }
  31772. AstBinaryOperation.prototype = Object.create(AstNode.prototype);
  31773. AstBinaryOperation.prototype.visit = function (visitor) {
  31774. visitor.visitBinaryOperation(this);
  31775. };
  31776. function AstMin(arg, max) {
  31777. AstNode.call(this, 'max');
  31778. this.arg = arg;
  31779. this.min = arg.min;
  31780. this.max = max;
  31781. }
  31782. AstMin.prototype = Object.create(AstNode.prototype);
  31783. AstMin.prototype.visit = function (visitor) {
  31784. visitor.visitMin(this);
  31785. };
  31786. function AstVariable(index, min, max) {
  31787. AstNode.call(this, 'var');
  31788. this.index = index;
  31789. this.min = min;
  31790. this.max = max;
  31791. }
  31792. AstVariable.prototype = Object.create(AstNode.prototype);
  31793. AstVariable.prototype.visit = function (visitor) {
  31794. visitor.visitVariable(this);
  31795. };
  31796. function AstVariableDefinition(variable, arg) {
  31797. AstNode.call(this, 'definition');
  31798. this.variable = variable;
  31799. this.arg = arg;
  31800. }
  31801. AstVariableDefinition.prototype = Object.create(AstNode.prototype);
  31802. AstVariableDefinition.prototype.visit = function (visitor) {
  31803. visitor.visitVariableDefinition(this);
  31804. };
  31805. function ExpressionBuilderVisitor() {
  31806. this.parts = [];
  31807. }
  31808. ExpressionBuilderVisitor.prototype = {
  31809. visitArgument: function (arg) {
  31810. this.parts.push('Math.max(', arg.min, ', Math.min(',
  31811. arg.max, ', src[srcOffset + ', arg.index, ']))');
  31812. },
  31813. visitVariable: function (variable) {
  31814. this.parts.push('v', variable.index);
  31815. },
  31816. visitLiteral: function (literal) {
  31817. this.parts.push(literal.number);
  31818. },
  31819. visitBinaryOperation: function (operation) {
  31820. this.parts.push('(');
  31821. operation.arg1.visit(this);
  31822. this.parts.push(' ', operation.op, ' ');
  31823. operation.arg2.visit(this);
  31824. this.parts.push(')');
  31825. },
  31826. visitVariableDefinition: function (definition) {
  31827. this.parts.push('var ');
  31828. definition.variable.visit(this);
  31829. this.parts.push(' = ');
  31830. definition.arg.visit(this);
  31831. this.parts.push(';');
  31832. },
  31833. visitMin: function (max) {
  31834. this.parts.push('Math.min(');
  31835. max.arg.visit(this);
  31836. this.parts.push(', ', max.max, ')');
  31837. },
  31838. toString: function () {
  31839. return this.parts.join('');
  31840. }
  31841. };
  31842. function buildAddOperation(num1, num2) {
  31843. if (num2.type === 'literal' && num2.number === 0) {
  31844. // optimization: second operand is 0
  31845. return num1;
  31846. }
  31847. if (num1.type === 'literal' && num1.number === 0) {
  31848. // optimization: first operand is 0
  31849. return num2;
  31850. }
  31851. if (num2.type === 'literal' && num1.type === 'literal') {
  31852. // optimization: operands operand are literals
  31853. return new AstLiteral(num1.number + num2.number);
  31854. }
  31855. return new AstBinaryOperation('+', num1, num2,
  31856. num1.min + num2.min, num1.max + num2.max);
  31857. }
  31858. function buildMulOperation(num1, num2) {
  31859. if (num2.type === 'literal') {
  31860. // optimization: second operands is a literal...
  31861. if (num2.number === 0) {
  31862. return new AstLiteral(0); // and it's 0
  31863. } else if (num2.number === 1) {
  31864. return num1; // and it's 1
  31865. } else if (num1.type === 'literal') {
  31866. // ... and first operands is a literal too
  31867. return new AstLiteral(num1.number * num2.number);
  31868. }
  31869. }
  31870. if (num1.type === 'literal') {
  31871. // optimization: first operands is a literal...
  31872. if (num1.number === 0) {
  31873. return new AstLiteral(0); // and it's 0
  31874. } else if (num1.number === 1) {
  31875. return num2; // and it's 1
  31876. }
  31877. }
  31878. var min = Math.min(num1.min * num2.min, num1.min * num2.max,
  31879. num1.max * num2.min, num1.max * num2.max);
  31880. var max = Math.max(num1.min * num2.min, num1.min * num2.max,
  31881. num1.max * num2.min, num1.max * num2.max);
  31882. return new AstBinaryOperation('*', num1, num2, min, max);
  31883. }
  31884. function buildSubOperation(num1, num2) {
  31885. if (num2.type === 'literal') {
  31886. // optimization: second operands is a literal...
  31887. if (num2.number === 0) {
  31888. return num1; // ... and it's 0
  31889. } else if (num1.type === 'literal') {
  31890. // ... and first operands is a literal too
  31891. return new AstLiteral(num1.number - num2.number);
  31892. }
  31893. }
  31894. if (num2.type === 'binary' && num2.op === '-' &&
  31895. num1.type === 'literal' && num1.number === 1 &&
  31896. num2.arg1.type === 'literal' && num2.arg1.number === 1) {
  31897. // optimization for case: 1 - (1 - x)
  31898. return num2.arg2;
  31899. }
  31900. return new AstBinaryOperation('-', num1, num2,
  31901. num1.min - num2.max, num1.max - num2.min);
  31902. }
  31903. function buildMinOperation(num1, max) {
  31904. if (num1.min >= max) {
  31905. // optimization: num1 min value is not less than required max
  31906. return new AstLiteral(max); // just returning max
  31907. } else if (num1.max <= max) {
  31908. // optimization: num1 max value is not greater than required max
  31909. return num1; // just returning an argument
  31910. }
  31911. return new AstMin(num1, max);
  31912. }
  31913. function PostScriptCompiler() {}
  31914. PostScriptCompiler.prototype = {
  31915. compile: function PostScriptCompiler_compile(code, domain, range) {
  31916. var stack = [];
  31917. var i, ii;
  31918. var instructions = [];
  31919. var inputSize = domain.length >> 1, outputSize = range.length >> 1;
  31920. var lastRegister = 0;
  31921. var n, j;
  31922. var num1, num2, ast1, ast2, tmpVar, item;
  31923. for (i = 0; i < inputSize; i++) {
  31924. stack.push(new AstArgument(i, domain[i * 2], domain[i * 2 + 1]));
  31925. }
  31926. for (i = 0, ii = code.length; i < ii; i++) {
  31927. item = code[i];
  31928. if (typeof item === 'number') {
  31929. stack.push(new AstLiteral(item));
  31930. continue;
  31931. }
  31932. switch (item) {
  31933. case 'add':
  31934. if (stack.length < 2) {
  31935. return null;
  31936. }
  31937. num2 = stack.pop();
  31938. num1 = stack.pop();
  31939. stack.push(buildAddOperation(num1, num2));
  31940. break;
  31941. case 'cvr':
  31942. if (stack.length < 1) {
  31943. return null;
  31944. }
  31945. break;
  31946. case 'mul':
  31947. if (stack.length < 2) {
  31948. return null;
  31949. }
  31950. num2 = stack.pop();
  31951. num1 = stack.pop();
  31952. stack.push(buildMulOperation(num1, num2));
  31953. break;
  31954. case 'sub':
  31955. if (stack.length < 2) {
  31956. return null;
  31957. }
  31958. num2 = stack.pop();
  31959. num1 = stack.pop();
  31960. stack.push(buildSubOperation(num1, num2));
  31961. break;
  31962. case 'exch':
  31963. if (stack.length < 2) {
  31964. return null;
  31965. }
  31966. ast1 = stack.pop(); ast2 = stack.pop();
  31967. stack.push(ast1, ast2);
  31968. break;
  31969. case 'pop':
  31970. if (stack.length < 1) {
  31971. return null;
  31972. }
  31973. stack.pop();
  31974. break;
  31975. case 'index':
  31976. if (stack.length < 1) {
  31977. return null;
  31978. }
  31979. num1 = stack.pop();
  31980. if (num1.type !== 'literal') {
  31981. return null;
  31982. }
  31983. n = num1.number;
  31984. if (n < 0 || (n|0) !== n || stack.length < n) {
  31985. return null;
  31986. }
  31987. ast1 = stack[stack.length - n - 1];
  31988. if (ast1.type === 'literal' || ast1.type === 'var') {
  31989. stack.push(ast1);
  31990. break;
  31991. }
  31992. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  31993. stack[stack.length - n - 1] = tmpVar;
  31994. stack.push(tmpVar);
  31995. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  31996. break;
  31997. case 'dup':
  31998. if (stack.length < 1) {
  31999. return null;
  32000. }
  32001. if (typeof code[i + 1] === 'number' && code[i + 2] === 'gt' &&
  32002. code[i + 3] === i + 7 && code[i + 4] === 'jz' &&
  32003. code[i + 5] === 'pop' && code[i + 6] === code[i + 1]) {
  32004. // special case of the commands sequence for the min operation
  32005. num1 = stack.pop();
  32006. stack.push(buildMinOperation(num1, code[i + 1]));
  32007. i += 6;
  32008. break;
  32009. }
  32010. ast1 = stack[stack.length - 1];
  32011. if (ast1.type === 'literal' || ast1.type === 'var') {
  32012. // we don't have to save into intermediate variable a literal or
  32013. // variable.
  32014. stack.push(ast1);
  32015. break;
  32016. }
  32017. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  32018. stack[stack.length - 1] = tmpVar;
  32019. stack.push(tmpVar);
  32020. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  32021. break;
  32022. case 'roll':
  32023. if (stack.length < 2) {
  32024. return null;
  32025. }
  32026. num2 = stack.pop();
  32027. num1 = stack.pop();
  32028. if (num2.type !== 'literal' || num1.type !== 'literal') {
  32029. // both roll operands must be numbers
  32030. return null;
  32031. }
  32032. j = num2.number;
  32033. n = num1.number;
  32034. if (n <= 0 || (n|0) !== n || (j|0) !== j || stack.length < n) {
  32035. // ... and integers
  32036. return null;
  32037. }
  32038. j = ((j % n) + n) % n;
  32039. if (j === 0) {
  32040. break; // just skipping -- there are nothing to rotate
  32041. }
  32042. Array.prototype.push.apply(stack,
  32043. stack.splice(stack.length - n, n - j));
  32044. break;
  32045. default:
  32046. return null; // unsupported operator
  32047. }
  32048. }
  32049. if (stack.length !== outputSize) {
  32050. return null;
  32051. }
  32052. var result = [];
  32053. instructions.forEach(function (instruction) {
  32054. var statementBuilder = new ExpressionBuilderVisitor();
  32055. instruction.visit(statementBuilder);
  32056. result.push(statementBuilder.toString());
  32057. });
  32058. stack.forEach(function (expr, i) {
  32059. var statementBuilder = new ExpressionBuilderVisitor();
  32060. expr.visit(statementBuilder);
  32061. var min = range[i * 2], max = range[i * 2 + 1];
  32062. var out = [statementBuilder.toString()];
  32063. if (min > expr.min) {
  32064. out.unshift('Math.max(', min, ', ');
  32065. out.push(')');
  32066. }
  32067. if (max < expr.max) {
  32068. out.unshift('Math.min(', max, ', ');
  32069. out.push(')');
  32070. }
  32071. out.unshift('dest[destOffset + ', i, '] = ');
  32072. out.push(';');
  32073. result.push(out.join(''));
  32074. });
  32075. return result.join('\n');
  32076. }
  32077. };
  32078. return PostScriptCompiler;
  32079. })();
  32080. exports.isPDFFunction = isPDFFunction;
  32081. exports.PDFFunction = PDFFunction;
  32082. exports.PostScriptEvaluator = PostScriptEvaluator;
  32083. exports.PostScriptCompiler = PostScriptCompiler;
  32084. }));
  32085. (function (root, factory) {
  32086. {
  32087. factory((root.pdfjsCoreColorSpace = {}), root.pdfjsSharedUtil,
  32088. root.pdfjsCorePrimitives, root.pdfjsCoreFunction, root.pdfjsCoreStream);
  32089. }
  32090. }(this, function (exports, sharedUtil, corePrimitives, coreFunction,
  32091. coreStream) {
  32092. var error = sharedUtil.error;
  32093. var info = sharedUtil.info;
  32094. var isArray = sharedUtil.isArray;
  32095. var isString = sharedUtil.isString;
  32096. var shadow = sharedUtil.shadow;
  32097. var warn = sharedUtil.warn;
  32098. var isDict = corePrimitives.isDict;
  32099. var isName = corePrimitives.isName;
  32100. var isStream = corePrimitives.isStream;
  32101. var PDFFunction = coreFunction.PDFFunction;
  32102. var coreImage; // see _setCoreImage below
  32103. var PDFImage; // = coreImage.PDFImage;
  32104. var ColorSpace = (function ColorSpaceClosure() {
  32105. // Constructor should define this.numComps, this.defaultColor, this.name
  32106. function ColorSpace() {
  32107. error('should not call ColorSpace constructor');
  32108. }
  32109. ColorSpace.prototype = {
  32110. /**
  32111. * Converts the color value to the RGB color. The color components are
  32112. * located in the src array starting from the srcOffset. Returns the array
  32113. * of the rgb components, each value ranging from [0,255].
  32114. */
  32115. getRgb: function ColorSpace_getRgb(src, srcOffset) {
  32116. var rgb = new Uint8Array(3);
  32117. this.getRgbItem(src, srcOffset, rgb, 0);
  32118. return rgb;
  32119. },
  32120. /**
  32121. * Converts the color value to the RGB color, similar to the getRgb method.
  32122. * The result placed into the dest array starting from the destOffset.
  32123. */
  32124. getRgbItem: function ColorSpace_getRgbItem(src, srcOffset,
  32125. dest, destOffset) {
  32126. error('Should not call ColorSpace.getRgbItem');
  32127. },
  32128. /**
  32129. * Converts the specified number of the color values to the RGB colors.
  32130. * The colors are located in the src array starting from the srcOffset.
  32131. * The result is placed into the dest array starting from the destOffset.
  32132. * The src array items shall be in [0,2^bits) range, the dest array items
  32133. * will be in [0,255] range. alpha01 indicates how many alpha components
  32134. * there are in the dest array; it will be either 0 (RGB array) or 1 (RGBA
  32135. * array).
  32136. */
  32137. getRgbBuffer: function ColorSpace_getRgbBuffer(src, srcOffset, count,
  32138. dest, destOffset, bits,
  32139. alpha01) {
  32140. error('Should not call ColorSpace.getRgbBuffer');
  32141. },
  32142. /**
  32143. * Determines the number of bytes required to store the result of the
  32144. * conversion done by the getRgbBuffer method. As in getRgbBuffer,
  32145. * |alpha01| is either 0 (RGB output) or 1 (RGBA output).
  32146. */
  32147. getOutputLength: function ColorSpace_getOutputLength(inputLength,
  32148. alpha01) {
  32149. error('Should not call ColorSpace.getOutputLength');
  32150. },
  32151. /**
  32152. * Returns true if source data will be equal the result/output data.
  32153. */
  32154. isPassthrough: function ColorSpace_isPassthrough(bits) {
  32155. return false;
  32156. },
  32157. /**
  32158. * Fills in the RGB colors in the destination buffer. alpha01 indicates
  32159. * how many alpha components there are in the dest array; it will be either
  32160. * 0 (RGB array) or 1 (RGBA array).
  32161. */
  32162. fillRgb: function ColorSpace_fillRgb(dest, originalWidth,
  32163. originalHeight, width, height,
  32164. actualHeight, bpc, comps, alpha01) {
  32165. var count = originalWidth * originalHeight;
  32166. var rgbBuf = null;
  32167. var numComponentColors = 1 << bpc;
  32168. var needsResizing = originalHeight !== height || originalWidth !== width;
  32169. var i, ii;
  32170. if (this.isPassthrough(bpc)) {
  32171. rgbBuf = comps;
  32172. } else if (this.numComps === 1 && count > numComponentColors &&
  32173. this.name !== 'DeviceGray' && this.name !== 'DeviceRGB') {
  32174. // Optimization: create a color map when there is just one component and
  32175. // we are converting more colors than the size of the color map. We
  32176. // don't build the map if the colorspace is gray or rgb since those
  32177. // methods are faster than building a map. This mainly offers big speed
  32178. // ups for indexed and alternate colorspaces.
  32179. //
  32180. // TODO it may be worth while to cache the color map. While running
  32181. // testing I never hit a cache so I will leave that out for now (perhaps
  32182. // we are reparsing colorspaces too much?).
  32183. var allColors = bpc <= 8 ? new Uint8Array(numComponentColors) :
  32184. new Uint16Array(numComponentColors);
  32185. var key;
  32186. for (i = 0; i < numComponentColors; i++) {
  32187. allColors[i] = i;
  32188. }
  32189. var colorMap = new Uint8Array(numComponentColors * 3);
  32190. this.getRgbBuffer(allColors, 0, numComponentColors, colorMap, 0, bpc,
  32191. /* alpha01 = */ 0);
  32192. var destPos, rgbPos;
  32193. if (!needsResizing) {
  32194. // Fill in the RGB values directly into |dest|.
  32195. destPos = 0;
  32196. for (i = 0; i < count; ++i) {
  32197. key = comps[i] * 3;
  32198. dest[destPos++] = colorMap[key];
  32199. dest[destPos++] = colorMap[key + 1];
  32200. dest[destPos++] = colorMap[key + 2];
  32201. destPos += alpha01;
  32202. }
  32203. } else {
  32204. rgbBuf = new Uint8Array(count * 3);
  32205. rgbPos = 0;
  32206. for (i = 0; i < count; ++i) {
  32207. key = comps[i] * 3;
  32208. rgbBuf[rgbPos++] = colorMap[key];
  32209. rgbBuf[rgbPos++] = colorMap[key + 1];
  32210. rgbBuf[rgbPos++] = colorMap[key + 2];
  32211. }
  32212. }
  32213. } else {
  32214. if (!needsResizing) {
  32215. // Fill in the RGB values directly into |dest|.
  32216. this.getRgbBuffer(comps, 0, width * actualHeight, dest, 0, bpc,
  32217. alpha01);
  32218. } else {
  32219. rgbBuf = new Uint8Array(count * 3);
  32220. this.getRgbBuffer(comps, 0, count, rgbBuf, 0, bpc,
  32221. /* alpha01 = */ 0);
  32222. }
  32223. }
  32224. if (rgbBuf) {
  32225. if (needsResizing) {
  32226. PDFImage.resize(rgbBuf, bpc, 3, originalWidth, originalHeight, width,
  32227. height, dest, alpha01);
  32228. } else {
  32229. rgbPos = 0;
  32230. destPos = 0;
  32231. for (i = 0, ii = width * actualHeight; i < ii; i++) {
  32232. dest[destPos++] = rgbBuf[rgbPos++];
  32233. dest[destPos++] = rgbBuf[rgbPos++];
  32234. dest[destPos++] = rgbBuf[rgbPos++];
  32235. destPos += alpha01;
  32236. }
  32237. }
  32238. }
  32239. },
  32240. /**
  32241. * True if the colorspace has components in the default range of [0, 1].
  32242. * This should be true for all colorspaces except for lab color spaces
  32243. * which are [0,100], [-128, 127], [-128, 127].
  32244. */
  32245. usesZeroToOneRange: true
  32246. };
  32247. ColorSpace.parse = function ColorSpace_parse(cs, xref, res) {
  32248. var IR = ColorSpace.parseToIR(cs, xref, res);
  32249. if (IR instanceof AlternateCS) {
  32250. return IR;
  32251. }
  32252. return ColorSpace.fromIR(IR);
  32253. };
  32254. ColorSpace.fromIR = function ColorSpace_fromIR(IR) {
  32255. var name = isArray(IR) ? IR[0] : IR;
  32256. var whitePoint, blackPoint, gamma;
  32257. switch (name) {
  32258. case 'DeviceGrayCS':
  32259. return this.singletons.gray;
  32260. case 'DeviceRgbCS':
  32261. return this.singletons.rgb;
  32262. case 'DeviceCmykCS':
  32263. return this.singletons.cmyk;
  32264. case 'CalGrayCS':
  32265. whitePoint = IR[1].WhitePoint;
  32266. blackPoint = IR[1].BlackPoint;
  32267. gamma = IR[1].Gamma;
  32268. return new CalGrayCS(whitePoint, blackPoint, gamma);
  32269. case 'CalRGBCS':
  32270. whitePoint = IR[1].WhitePoint;
  32271. blackPoint = IR[1].BlackPoint;
  32272. gamma = IR[1].Gamma;
  32273. var matrix = IR[1].Matrix;
  32274. return new CalRGBCS(whitePoint, blackPoint, gamma, matrix);
  32275. case 'PatternCS':
  32276. var basePatternCS = IR[1];
  32277. if (basePatternCS) {
  32278. basePatternCS = ColorSpace.fromIR(basePatternCS);
  32279. }
  32280. return new PatternCS(basePatternCS);
  32281. case 'IndexedCS':
  32282. var baseIndexedCS = IR[1];
  32283. var hiVal = IR[2];
  32284. var lookup = IR[3];
  32285. return new IndexedCS(ColorSpace.fromIR(baseIndexedCS), hiVal, lookup);
  32286. case 'AlternateCS':
  32287. var numComps = IR[1];
  32288. var alt = IR[2];
  32289. var tintFnIR = IR[3];
  32290. return new AlternateCS(numComps, ColorSpace.fromIR(alt),
  32291. PDFFunction.fromIR(tintFnIR));
  32292. case 'LabCS':
  32293. whitePoint = IR[1].WhitePoint;
  32294. blackPoint = IR[1].BlackPoint;
  32295. var range = IR[1].Range;
  32296. return new LabCS(whitePoint, blackPoint, range);
  32297. default:
  32298. error('Unknown name ' + name);
  32299. }
  32300. return null;
  32301. };
  32302. ColorSpace.parseToIR = function ColorSpace_parseToIR(cs, xref, res) {
  32303. if (isName(cs)) {
  32304. var colorSpaces = res.get('ColorSpace');
  32305. if (isDict(colorSpaces)) {
  32306. var refcs = colorSpaces.get(cs.name);
  32307. if (refcs) {
  32308. cs = refcs;
  32309. }
  32310. }
  32311. }
  32312. cs = xref.fetchIfRef(cs);
  32313. var mode;
  32314. if (isName(cs)) {
  32315. mode = cs.name;
  32316. this.mode = mode;
  32317. switch (mode) {
  32318. case 'DeviceGray':
  32319. case 'G':
  32320. return 'DeviceGrayCS';
  32321. case 'DeviceRGB':
  32322. case 'RGB':
  32323. return 'DeviceRgbCS';
  32324. case 'DeviceCMYK':
  32325. case 'CMYK':
  32326. return 'DeviceCmykCS';
  32327. case 'Pattern':
  32328. return ['PatternCS', null];
  32329. default:
  32330. error('unrecognized colorspace ' + mode);
  32331. }
  32332. } else if (isArray(cs)) {
  32333. mode = xref.fetchIfRef(cs[0]).name;
  32334. this.mode = mode;
  32335. var numComps, params, alt;
  32336. switch (mode) {
  32337. case 'DeviceGray':
  32338. case 'G':
  32339. return 'DeviceGrayCS';
  32340. case 'DeviceRGB':
  32341. case 'RGB':
  32342. return 'DeviceRgbCS';
  32343. case 'DeviceCMYK':
  32344. case 'CMYK':
  32345. return 'DeviceCmykCS';
  32346. case 'CalGray':
  32347. params = xref.fetchIfRef(cs[1]).getAll();
  32348. return ['CalGrayCS', params];
  32349. case 'CalRGB':
  32350. params = xref.fetchIfRef(cs[1]).getAll();
  32351. return ['CalRGBCS', params];
  32352. case 'ICCBased':
  32353. var stream = xref.fetchIfRef(cs[1]);
  32354. var dict = stream.dict;
  32355. numComps = dict.get('N');
  32356. alt = dict.get('Alternate');
  32357. if (alt) {
  32358. var altIR = ColorSpace.parseToIR(alt, xref, res);
  32359. // Parse the /Alternate CS to ensure that the number of components
  32360. // are correct, and also (indirectly) that it is not a PatternCS.
  32361. var altCS = ColorSpace.fromIR(altIR);
  32362. if (altCS.numComps === numComps) {
  32363. return altIR;
  32364. }
  32365. warn('ICCBased color space: Ignoring incorrect /Alternate entry.');
  32366. }
  32367. if (numComps === 1) {
  32368. return 'DeviceGrayCS';
  32369. } else if (numComps === 3) {
  32370. return 'DeviceRgbCS';
  32371. } else if (numComps === 4) {
  32372. return 'DeviceCmykCS';
  32373. }
  32374. break;
  32375. case 'Pattern':
  32376. var basePatternCS = cs[1] || null;
  32377. if (basePatternCS) {
  32378. basePatternCS = ColorSpace.parseToIR(basePatternCS, xref, res);
  32379. }
  32380. return ['PatternCS', basePatternCS];
  32381. case 'Indexed':
  32382. case 'I':
  32383. var baseIndexedCS = ColorSpace.parseToIR(cs[1], xref, res);
  32384. var hiVal = xref.fetchIfRef(cs[2]) + 1;
  32385. var lookup = xref.fetchIfRef(cs[3]);
  32386. if (isStream(lookup)) {
  32387. lookup = lookup.getBytes();
  32388. }
  32389. return ['IndexedCS', baseIndexedCS, hiVal, lookup];
  32390. case 'Separation':
  32391. case 'DeviceN':
  32392. var name = xref.fetchIfRef(cs[1]);
  32393. numComps = 1;
  32394. if (isName(name)) {
  32395. numComps = 1;
  32396. } else if (isArray(name)) {
  32397. numComps = name.length;
  32398. }
  32399. alt = ColorSpace.parseToIR(cs[2], xref, res);
  32400. var tintFnIR = PDFFunction.getIR(xref, xref.fetchIfRef(cs[3]));
  32401. return ['AlternateCS', numComps, alt, tintFnIR];
  32402. case 'Lab':
  32403. params = xref.fetchIfRef(cs[1]).getAll();
  32404. return ['LabCS', params];
  32405. default:
  32406. error('unimplemented color space object "' + mode + '"');
  32407. }
  32408. } else {
  32409. error('unrecognized color space object: "' + cs + '"');
  32410. }
  32411. return null;
  32412. };
  32413. /**
  32414. * Checks if a decode map matches the default decode map for a color space.
  32415. * This handles the general decode maps where there are two values per
  32416. * component. e.g. [0, 1, 0, 1, 0, 1] for a RGB color.
  32417. * This does not handle Lab, Indexed, or Pattern decode maps since they are
  32418. * slightly different.
  32419. * @param {Array} decode Decode map (usually from an image).
  32420. * @param {Number} n Number of components the color space has.
  32421. */
  32422. ColorSpace.isDefaultDecode = function ColorSpace_isDefaultDecode(decode, n) {
  32423. if (!isArray(decode)) {
  32424. return true;
  32425. }
  32426. if (n * 2 !== decode.length) {
  32427. warn('The decode map is not the correct length');
  32428. return true;
  32429. }
  32430. for (var i = 0, ii = decode.length; i < ii; i += 2) {
  32431. if (decode[i] !== 0 || decode[i + 1] !== 1) {
  32432. return false;
  32433. }
  32434. }
  32435. return true;
  32436. };
  32437. ColorSpace.singletons = {
  32438. get gray() {
  32439. return shadow(this, 'gray', new DeviceGrayCS());
  32440. },
  32441. get rgb() {
  32442. return shadow(this, 'rgb', new DeviceRgbCS());
  32443. },
  32444. get cmyk() {
  32445. return shadow(this, 'cmyk', new DeviceCmykCS());
  32446. }
  32447. };
  32448. return ColorSpace;
  32449. })();
  32450. /**
  32451. * Alternate color space handles both Separation and DeviceN color spaces. A
  32452. * Separation color space is actually just a DeviceN with one color component.
  32453. * Both color spaces use a tinting function to convert colors to a base color
  32454. * space.
  32455. */
  32456. var AlternateCS = (function AlternateCSClosure() {
  32457. function AlternateCS(numComps, base, tintFn) {
  32458. this.name = 'Alternate';
  32459. this.numComps = numComps;
  32460. this.defaultColor = new Float32Array(numComps);
  32461. for (var i = 0; i < numComps; ++i) {
  32462. this.defaultColor[i] = 1;
  32463. }
  32464. this.base = base;
  32465. this.tintFn = tintFn;
  32466. this.tmpBuf = new Float32Array(base.numComps);
  32467. }
  32468. AlternateCS.prototype = {
  32469. getRgb: ColorSpace.prototype.getRgb,
  32470. getRgbItem: function AlternateCS_getRgbItem(src, srcOffset,
  32471. dest, destOffset) {
  32472. var tmpBuf = this.tmpBuf;
  32473. this.tintFn(src, srcOffset, tmpBuf, 0);
  32474. this.base.getRgbItem(tmpBuf, 0, dest, destOffset);
  32475. },
  32476. getRgbBuffer: function AlternateCS_getRgbBuffer(src, srcOffset, count,
  32477. dest, destOffset, bits,
  32478. alpha01) {
  32479. var tintFn = this.tintFn;
  32480. var base = this.base;
  32481. var scale = 1 / ((1 << bits) - 1);
  32482. var baseNumComps = base.numComps;
  32483. var usesZeroToOneRange = base.usesZeroToOneRange;
  32484. var isPassthrough = (base.isPassthrough(8) || !usesZeroToOneRange) &&
  32485. alpha01 === 0;
  32486. var pos = isPassthrough ? destOffset : 0;
  32487. var baseBuf = isPassthrough ? dest : new Uint8Array(baseNumComps * count);
  32488. var numComps = this.numComps;
  32489. var scaled = new Float32Array(numComps);
  32490. var tinted = new Float32Array(baseNumComps);
  32491. var i, j;
  32492. if (usesZeroToOneRange) {
  32493. for (i = 0; i < count; i++) {
  32494. for (j = 0; j < numComps; j++) {
  32495. scaled[j] = src[srcOffset++] * scale;
  32496. }
  32497. tintFn(scaled, 0, tinted, 0);
  32498. for (j = 0; j < baseNumComps; j++) {
  32499. baseBuf[pos++] = tinted[j] * 255;
  32500. }
  32501. }
  32502. } else {
  32503. for (i = 0; i < count; i++) {
  32504. for (j = 0; j < numComps; j++) {
  32505. scaled[j] = src[srcOffset++] * scale;
  32506. }
  32507. tintFn(scaled, 0, tinted, 0);
  32508. base.getRgbItem(tinted, 0, baseBuf, pos);
  32509. pos += baseNumComps;
  32510. }
  32511. }
  32512. if (!isPassthrough) {
  32513. base.getRgbBuffer(baseBuf, 0, count, dest, destOffset, 8, alpha01);
  32514. }
  32515. },
  32516. getOutputLength: function AlternateCS_getOutputLength(inputLength,
  32517. alpha01) {
  32518. return this.base.getOutputLength(inputLength *
  32519. this.base.numComps / this.numComps,
  32520. alpha01);
  32521. },
  32522. isPassthrough: ColorSpace.prototype.isPassthrough,
  32523. fillRgb: ColorSpace.prototype.fillRgb,
  32524. isDefaultDecode: function AlternateCS_isDefaultDecode(decodeMap) {
  32525. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  32526. },
  32527. usesZeroToOneRange: true
  32528. };
  32529. return AlternateCS;
  32530. })();
  32531. var PatternCS = (function PatternCSClosure() {
  32532. function PatternCS(baseCS) {
  32533. this.name = 'Pattern';
  32534. this.base = baseCS;
  32535. }
  32536. PatternCS.prototype = {};
  32537. return PatternCS;
  32538. })();
  32539. var IndexedCS = (function IndexedCSClosure() {
  32540. function IndexedCS(base, highVal, lookup) {
  32541. this.name = 'Indexed';
  32542. this.numComps = 1;
  32543. this.defaultColor = new Uint8Array([0]);
  32544. this.base = base;
  32545. this.highVal = highVal;
  32546. var baseNumComps = base.numComps;
  32547. var length = baseNumComps * highVal;
  32548. var lookupArray;
  32549. if (isStream(lookup)) {
  32550. lookupArray = new Uint8Array(length);
  32551. var bytes = lookup.getBytes(length);
  32552. lookupArray.set(bytes);
  32553. } else if (isString(lookup)) {
  32554. lookupArray = new Uint8Array(length);
  32555. for (var i = 0; i < length; ++i) {
  32556. lookupArray[i] = lookup.charCodeAt(i);
  32557. }
  32558. } else if (lookup instanceof Uint8Array || lookup instanceof Array) {
  32559. lookupArray = lookup;
  32560. } else {
  32561. error('Unrecognized lookup table: ' + lookup);
  32562. }
  32563. this.lookup = lookupArray;
  32564. }
  32565. IndexedCS.prototype = {
  32566. getRgb: ColorSpace.prototype.getRgb,
  32567. getRgbItem: function IndexedCS_getRgbItem(src, srcOffset,
  32568. dest, destOffset) {
  32569. var numComps = this.base.numComps;
  32570. var start = src[srcOffset] * numComps;
  32571. this.base.getRgbItem(this.lookup, start, dest, destOffset);
  32572. },
  32573. getRgbBuffer: function IndexedCS_getRgbBuffer(src, srcOffset, count,
  32574. dest, destOffset, bits,
  32575. alpha01) {
  32576. var base = this.base;
  32577. var numComps = base.numComps;
  32578. var outputDelta = base.getOutputLength(numComps, alpha01);
  32579. var lookup = this.lookup;
  32580. for (var i = 0; i < count; ++i) {
  32581. var lookupPos = src[srcOffset++] * numComps;
  32582. base.getRgbBuffer(lookup, lookupPos, 1, dest, destOffset, 8, alpha01);
  32583. destOffset += outputDelta;
  32584. }
  32585. },
  32586. getOutputLength: function IndexedCS_getOutputLength(inputLength, alpha01) {
  32587. return this.base.getOutputLength(inputLength * this.base.numComps,
  32588. alpha01);
  32589. },
  32590. isPassthrough: ColorSpace.prototype.isPassthrough,
  32591. fillRgb: ColorSpace.prototype.fillRgb,
  32592. isDefaultDecode: function IndexedCS_isDefaultDecode(decodeMap) {
  32593. // indexed color maps shouldn't be changed
  32594. return true;
  32595. },
  32596. usesZeroToOneRange: true
  32597. };
  32598. return IndexedCS;
  32599. })();
  32600. var DeviceGrayCS = (function DeviceGrayCSClosure() {
  32601. function DeviceGrayCS() {
  32602. this.name = 'DeviceGray';
  32603. this.numComps = 1;
  32604. this.defaultColor = new Float32Array([0]);
  32605. }
  32606. DeviceGrayCS.prototype = {
  32607. getRgb: ColorSpace.prototype.getRgb,
  32608. getRgbItem: function DeviceGrayCS_getRgbItem(src, srcOffset,
  32609. dest, destOffset) {
  32610. var c = (src[srcOffset] * 255) | 0;
  32611. c = c < 0 ? 0 : c > 255 ? 255 : c;
  32612. dest[destOffset] = dest[destOffset + 1] = dest[destOffset + 2] = c;
  32613. },
  32614. getRgbBuffer: function DeviceGrayCS_getRgbBuffer(src, srcOffset, count,
  32615. dest, destOffset, bits,
  32616. alpha01) {
  32617. var scale = 255 / ((1 << bits) - 1);
  32618. var j = srcOffset, q = destOffset;
  32619. for (var i = 0; i < count; ++i) {
  32620. var c = (scale * src[j++]) | 0;
  32621. dest[q++] = c;
  32622. dest[q++] = c;
  32623. dest[q++] = c;
  32624. q += alpha01;
  32625. }
  32626. },
  32627. getOutputLength: function DeviceGrayCS_getOutputLength(inputLength,
  32628. alpha01) {
  32629. return inputLength * (3 + alpha01);
  32630. },
  32631. isPassthrough: ColorSpace.prototype.isPassthrough,
  32632. fillRgb: ColorSpace.prototype.fillRgb,
  32633. isDefaultDecode: function DeviceGrayCS_isDefaultDecode(decodeMap) {
  32634. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  32635. },
  32636. usesZeroToOneRange: true
  32637. };
  32638. return DeviceGrayCS;
  32639. })();
  32640. var DeviceRgbCS = (function DeviceRgbCSClosure() {
  32641. function DeviceRgbCS() {
  32642. this.name = 'DeviceRGB';
  32643. this.numComps = 3;
  32644. this.defaultColor = new Float32Array([0, 0, 0]);
  32645. }
  32646. DeviceRgbCS.prototype = {
  32647. getRgb: ColorSpace.prototype.getRgb,
  32648. getRgbItem: function DeviceRgbCS_getRgbItem(src, srcOffset,
  32649. dest, destOffset) {
  32650. var r = (src[srcOffset] * 255) | 0;
  32651. var g = (src[srcOffset + 1] * 255) | 0;
  32652. var b = (src[srcOffset + 2] * 255) | 0;
  32653. dest[destOffset] = r < 0 ? 0 : r > 255 ? 255 : r;
  32654. dest[destOffset + 1] = g < 0 ? 0 : g > 255 ? 255 : g;
  32655. dest[destOffset + 2] = b < 0 ? 0 : b > 255 ? 255 : b;
  32656. },
  32657. getRgbBuffer: function DeviceRgbCS_getRgbBuffer(src, srcOffset, count,
  32658. dest, destOffset, bits,
  32659. alpha01) {
  32660. if (bits === 8 && alpha01 === 0) {
  32661. dest.set(src.subarray(srcOffset, srcOffset + count * 3), destOffset);
  32662. return;
  32663. }
  32664. var scale = 255 / ((1 << bits) - 1);
  32665. var j = srcOffset, q = destOffset;
  32666. for (var i = 0; i < count; ++i) {
  32667. dest[q++] = (scale * src[j++]) | 0;
  32668. dest[q++] = (scale * src[j++]) | 0;
  32669. dest[q++] = (scale * src[j++]) | 0;
  32670. q += alpha01;
  32671. }
  32672. },
  32673. getOutputLength: function DeviceRgbCS_getOutputLength(inputLength,
  32674. alpha01) {
  32675. return (inputLength * (3 + alpha01) / 3) | 0;
  32676. },
  32677. isPassthrough: function DeviceRgbCS_isPassthrough(bits) {
  32678. return bits === 8;
  32679. },
  32680. fillRgb: ColorSpace.prototype.fillRgb,
  32681. isDefaultDecode: function DeviceRgbCS_isDefaultDecode(decodeMap) {
  32682. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  32683. },
  32684. usesZeroToOneRange: true
  32685. };
  32686. return DeviceRgbCS;
  32687. })();
  32688. var DeviceCmykCS = (function DeviceCmykCSClosure() {
  32689. // The coefficients below was found using numerical analysis: the method of
  32690. // steepest descent for the sum((f_i - color_value_i)^2) for r/g/b colors,
  32691. // where color_value is the tabular value from the table of sampled RGB colors
  32692. // from CMYK US Web Coated (SWOP) colorspace, and f_i is the corresponding
  32693. // CMYK color conversion using the estimation below:
  32694. // f(A, B,.. N) = Acc+Bcm+Ccy+Dck+c+Fmm+Gmy+Hmk+Im+Jyy+Kyk+Ly+Mkk+Nk+255
  32695. function convertToRgb(src, srcOffset, srcScale, dest, destOffset) {
  32696. var c = src[srcOffset + 0] * srcScale;
  32697. var m = src[srcOffset + 1] * srcScale;
  32698. var y = src[srcOffset + 2] * srcScale;
  32699. var k = src[srcOffset + 3] * srcScale;
  32700. var r =
  32701. (c * (-4.387332384609988 * c + 54.48615194189176 * m +
  32702. 18.82290502165302 * y + 212.25662451639585 * k +
  32703. -285.2331026137004) +
  32704. m * (1.7149763477362134 * m - 5.6096736904047315 * y +
  32705. -17.873870861415444 * k - 5.497006427196366) +
  32706. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  32707. 17.5119270841813) +
  32708. k * (-21.86122147463605 * k - 189.48180835922747) + 255) | 0;
  32709. var g =
  32710. (c * (8.841041422036149 * c + 60.118027045597366 * m +
  32711. 6.871425592049007 * y + 31.159100130055922 * k +
  32712. -79.2970844816548) +
  32713. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  32714. 131.35250912493976 * k - 190.9453302588951) +
  32715. y * (4.444339102852739 * y + 9.8632861493405 * k - 24.86741582555878) +
  32716. k * (-20.737325471181034 * k - 187.80453709719578) + 255) | 0;
  32717. var b =
  32718. (c * (0.8842522430003296 * c + 8.078677503112928 * m +
  32719. 30.89978309703729 * y - 0.23883238689178934 * k +
  32720. -14.183576799673286) +
  32721. m * (10.49593273432072 * m + 63.02378494754052 * y +
  32722. 50.606957656360734 * k - 112.23884253719248) +
  32723. y * (0.03296041114873217 * y + 115.60384449646641 * k +
  32724. -193.58209356861505) +
  32725. k * (-22.33816807309886 * k - 180.12613974708367) + 255) | 0;
  32726. dest[destOffset] = r > 255 ? 255 : r < 0 ? 0 : r;
  32727. dest[destOffset + 1] = g > 255 ? 255 : g < 0 ? 0 : g;
  32728. dest[destOffset + 2] = b > 255 ? 255 : b < 0 ? 0 : b;
  32729. }
  32730. function DeviceCmykCS() {
  32731. this.name = 'DeviceCMYK';
  32732. this.numComps = 4;
  32733. this.defaultColor = new Float32Array([0, 0, 0, 1]);
  32734. }
  32735. DeviceCmykCS.prototype = {
  32736. getRgb: ColorSpace.prototype.getRgb,
  32737. getRgbItem: function DeviceCmykCS_getRgbItem(src, srcOffset,
  32738. dest, destOffset) {
  32739. convertToRgb(src, srcOffset, 1, dest, destOffset);
  32740. },
  32741. getRgbBuffer: function DeviceCmykCS_getRgbBuffer(src, srcOffset, count,
  32742. dest, destOffset, bits,
  32743. alpha01) {
  32744. var scale = 1 / ((1 << bits) - 1);
  32745. for (var i = 0; i < count; i++) {
  32746. convertToRgb(src, srcOffset, scale, dest, destOffset);
  32747. srcOffset += 4;
  32748. destOffset += 3 + alpha01;
  32749. }
  32750. },
  32751. getOutputLength: function DeviceCmykCS_getOutputLength(inputLength,
  32752. alpha01) {
  32753. return (inputLength / 4 * (3 + alpha01)) | 0;
  32754. },
  32755. isPassthrough: ColorSpace.prototype.isPassthrough,
  32756. fillRgb: ColorSpace.prototype.fillRgb,
  32757. isDefaultDecode: function DeviceCmykCS_isDefaultDecode(decodeMap) {
  32758. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  32759. },
  32760. usesZeroToOneRange: true
  32761. };
  32762. return DeviceCmykCS;
  32763. })();
  32764. //
  32765. // CalGrayCS: Based on "PDF Reference, Sixth Ed", p.245
  32766. //
  32767. var CalGrayCS = (function CalGrayCSClosure() {
  32768. function CalGrayCS(whitePoint, blackPoint, gamma) {
  32769. this.name = 'CalGray';
  32770. this.numComps = 1;
  32771. this.defaultColor = new Float32Array([0]);
  32772. if (!whitePoint) {
  32773. error('WhitePoint missing - required for color space CalGray');
  32774. }
  32775. blackPoint = blackPoint || [0, 0, 0];
  32776. gamma = gamma || 1;
  32777. // Translate arguments to spec variables.
  32778. this.XW = whitePoint[0];
  32779. this.YW = whitePoint[1];
  32780. this.ZW = whitePoint[2];
  32781. this.XB = blackPoint[0];
  32782. this.YB = blackPoint[1];
  32783. this.ZB = blackPoint[2];
  32784. this.G = gamma;
  32785. // Validate variables as per spec.
  32786. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  32787. error('Invalid WhitePoint components for ' + this.name +
  32788. ', no fallback available');
  32789. }
  32790. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  32791. info('Invalid BlackPoint for ' + this.name + ', falling back to default');
  32792. this.XB = this.YB = this.ZB = 0;
  32793. }
  32794. if (this.XB !== 0 || this.YB !== 0 || this.ZB !== 0) {
  32795. warn(this.name + ', BlackPoint: XB: ' + this.XB + ', YB: ' + this.YB +
  32796. ', ZB: ' + this.ZB + ', only default values are supported.');
  32797. }
  32798. if (this.G < 1) {
  32799. info('Invalid Gamma: ' + this.G + ' for ' + this.name +
  32800. ', falling back to default');
  32801. this.G = 1;
  32802. }
  32803. }
  32804. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  32805. // A represents a gray component of a calibrated gray space.
  32806. // A <---> AG in the spec
  32807. var A = src[srcOffset] * scale;
  32808. var AG = Math.pow(A, cs.G);
  32809. // Computes L as per spec. ( = cs.YW * AG )
  32810. // Except if other than default BlackPoint values are used.
  32811. var L = cs.YW * AG;
  32812. // http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html, Ch 4.
  32813. // Convert values to rgb range [0, 255].
  32814. var val = Math.max(295.8 * Math.pow(L, 0.333333333333333333) - 40.8, 0) | 0;
  32815. dest[destOffset] = val;
  32816. dest[destOffset + 1] = val;
  32817. dest[destOffset + 2] = val;
  32818. }
  32819. CalGrayCS.prototype = {
  32820. getRgb: ColorSpace.prototype.getRgb,
  32821. getRgbItem: function CalGrayCS_getRgbItem(src, srcOffset,
  32822. dest, destOffset) {
  32823. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  32824. },
  32825. getRgbBuffer: function CalGrayCS_getRgbBuffer(src, srcOffset, count,
  32826. dest, destOffset, bits,
  32827. alpha01) {
  32828. var scale = 1 / ((1 << bits) - 1);
  32829. for (var i = 0; i < count; ++i) {
  32830. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  32831. srcOffset += 1;
  32832. destOffset += 3 + alpha01;
  32833. }
  32834. },
  32835. getOutputLength: function CalGrayCS_getOutputLength(inputLength, alpha01) {
  32836. return inputLength * (3 + alpha01);
  32837. },
  32838. isPassthrough: ColorSpace.prototype.isPassthrough,
  32839. fillRgb: ColorSpace.prototype.fillRgb,
  32840. isDefaultDecode: function CalGrayCS_isDefaultDecode(decodeMap) {
  32841. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  32842. },
  32843. usesZeroToOneRange: true
  32844. };
  32845. return CalGrayCS;
  32846. })();
  32847. //
  32848. // CalRGBCS: Based on "PDF Reference, Sixth Ed", p.247
  32849. //
  32850. var CalRGBCS = (function CalRGBCSClosure() {
  32851. // See http://www.brucelindbloom.com/index.html?Eqn_ChromAdapt.html for these
  32852. // matrices.
  32853. var BRADFORD_SCALE_MATRIX = new Float32Array([
  32854. 0.8951, 0.2664, -0.1614,
  32855. -0.7502, 1.7135, 0.0367,
  32856. 0.0389, -0.0685, 1.0296]);
  32857. var BRADFORD_SCALE_INVERSE_MATRIX = new Float32Array([
  32858. 0.9869929, -0.1470543, 0.1599627,
  32859. 0.4323053, 0.5183603, 0.0492912,
  32860. -0.0085287, 0.0400428, 0.9684867]);
  32861. // See http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html.
  32862. var SRGB_D65_XYZ_TO_RGB_MATRIX = new Float32Array([
  32863. 3.2404542, -1.5371385, -0.4985314,
  32864. -0.9692660, 1.8760108, 0.0415560,
  32865. 0.0556434, -0.2040259, 1.0572252]);
  32866. var FLAT_WHITEPOINT_MATRIX = new Float32Array([1, 1, 1]);
  32867. var tempNormalizeMatrix = new Float32Array(3);
  32868. var tempConvertMatrix1 = new Float32Array(3);
  32869. var tempConvertMatrix2 = new Float32Array(3);
  32870. var DECODE_L_CONSTANT = Math.pow(((8 + 16) / 116), 3) / 8.0;
  32871. function CalRGBCS(whitePoint, blackPoint, gamma, matrix) {
  32872. this.name = 'CalRGB';
  32873. this.numComps = 3;
  32874. this.defaultColor = new Float32Array(3);
  32875. if (!whitePoint) {
  32876. error('WhitePoint missing - required for color space CalRGB');
  32877. }
  32878. blackPoint = blackPoint || new Float32Array(3);
  32879. gamma = gamma || new Float32Array([1, 1, 1]);
  32880. matrix = matrix || new Float32Array([1, 0, 0, 0, 1, 0, 0, 0, 1]);
  32881. // Translate arguments to spec variables.
  32882. var XW = whitePoint[0];
  32883. var YW = whitePoint[1];
  32884. var ZW = whitePoint[2];
  32885. this.whitePoint = whitePoint;
  32886. var XB = blackPoint[0];
  32887. var YB = blackPoint[1];
  32888. var ZB = blackPoint[2];
  32889. this.blackPoint = blackPoint;
  32890. this.GR = gamma[0];
  32891. this.GG = gamma[1];
  32892. this.GB = gamma[2];
  32893. this.MXA = matrix[0];
  32894. this.MYA = matrix[1];
  32895. this.MZA = matrix[2];
  32896. this.MXB = matrix[3];
  32897. this.MYB = matrix[4];
  32898. this.MZB = matrix[5];
  32899. this.MXC = matrix[6];
  32900. this.MYC = matrix[7];
  32901. this.MZC = matrix[8];
  32902. // Validate variables as per spec.
  32903. if (XW < 0 || ZW < 0 || YW !== 1) {
  32904. error('Invalid WhitePoint components for ' + this.name +
  32905. ', no fallback available');
  32906. }
  32907. if (XB < 0 || YB < 0 || ZB < 0) {
  32908. info('Invalid BlackPoint for ' + this.name + ' [' + XB + ', ' + YB +
  32909. ', ' + ZB + '], falling back to default');
  32910. this.blackPoint = new Float32Array(3);
  32911. }
  32912. if (this.GR < 0 || this.GG < 0 || this.GB < 0) {
  32913. info('Invalid Gamma [' + this.GR + ', ' + this.GG + ', ' + this.GB +
  32914. '] for ' + this.name + ', falling back to default');
  32915. this.GR = this.GG = this.GB = 1;
  32916. }
  32917. if (this.MXA < 0 || this.MYA < 0 || this.MZA < 0 ||
  32918. this.MXB < 0 || this.MYB < 0 || this.MZB < 0 ||
  32919. this.MXC < 0 || this.MYC < 0 || this.MZC < 0) {
  32920. info('Invalid Matrix for ' + this.name + ' [' +
  32921. this.MXA + ', ' + this.MYA + ', ' + this.MZA +
  32922. this.MXB + ', ' + this.MYB + ', ' + this.MZB +
  32923. this.MXC + ', ' + this.MYC + ', ' + this.MZC +
  32924. '], falling back to default');
  32925. this.MXA = this.MYB = this.MZC = 1;
  32926. this.MXB = this.MYA = this.MZA = this.MXC = this.MYC = this.MZB = 0;
  32927. }
  32928. }
  32929. function matrixProduct(a, b, result) {
  32930. result[0] = a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
  32931. result[1] = a[3] * b[0] + a[4] * b[1] + a[5] * b[2];
  32932. result[2] = a[6] * b[0] + a[7] * b[1] + a[8] * b[2];
  32933. }
  32934. function convertToFlat(sourceWhitePoint, LMS, result) {
  32935. result[0] = LMS[0] * 1 / sourceWhitePoint[0];
  32936. result[1] = LMS[1] * 1 / sourceWhitePoint[1];
  32937. result[2] = LMS[2] * 1 / sourceWhitePoint[2];
  32938. }
  32939. function convertToD65(sourceWhitePoint, LMS, result) {
  32940. var D65X = 0.95047;
  32941. var D65Y = 1;
  32942. var D65Z = 1.08883;
  32943. result[0] = LMS[0] * D65X / sourceWhitePoint[0];
  32944. result[1] = LMS[1] * D65Y / sourceWhitePoint[1];
  32945. result[2] = LMS[2] * D65Z / sourceWhitePoint[2];
  32946. }
  32947. function sRGBTransferFunction(color) {
  32948. // See http://en.wikipedia.org/wiki/SRGB.
  32949. if (color <= 0.0031308){
  32950. return adjustToRange(0, 1, 12.92 * color);
  32951. }
  32952. return adjustToRange(0, 1, (1 + 0.055) * Math.pow(color, 1 / 2.4) - 0.055);
  32953. }
  32954. function adjustToRange(min, max, value) {
  32955. return Math.max(min, Math.min(max, value));
  32956. }
  32957. function decodeL(L) {
  32958. if (L < 0) {
  32959. return -decodeL(-L);
  32960. }
  32961. if (L > 8.0) {
  32962. return Math.pow(((L + 16) / 116), 3);
  32963. }
  32964. return L * DECODE_L_CONSTANT;
  32965. }
  32966. function compensateBlackPoint(sourceBlackPoint, XYZ_Flat, result) {
  32967. // In case the blackPoint is already the default blackPoint then there is
  32968. // no need to do compensation.
  32969. if (sourceBlackPoint[0] === 0 &&
  32970. sourceBlackPoint[1] === 0 &&
  32971. sourceBlackPoint[2] === 0) {
  32972. result[0] = XYZ_Flat[0];
  32973. result[1] = XYZ_Flat[1];
  32974. result[2] = XYZ_Flat[2];
  32975. return;
  32976. }
  32977. // For the blackPoint calculation details, please see
  32978. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  32979. // AdobeBPC.pdf.
  32980. // The destination blackPoint is the default blackPoint [0, 0, 0].
  32981. var zeroDecodeL = decodeL(0);
  32982. var X_DST = zeroDecodeL;
  32983. var X_SRC = decodeL(sourceBlackPoint[0]);
  32984. var Y_DST = zeroDecodeL;
  32985. var Y_SRC = decodeL(sourceBlackPoint[1]);
  32986. var Z_DST = zeroDecodeL;
  32987. var Z_SRC = decodeL(sourceBlackPoint[2]);
  32988. var X_Scale = (1 - X_DST) / (1 - X_SRC);
  32989. var X_Offset = 1 - X_Scale;
  32990. var Y_Scale = (1 - Y_DST) / (1 - Y_SRC);
  32991. var Y_Offset = 1 - Y_Scale;
  32992. var Z_Scale = (1 - Z_DST) / (1 - Z_SRC);
  32993. var Z_Offset = 1 - Z_Scale;
  32994. result[0] = XYZ_Flat[0] * X_Scale + X_Offset;
  32995. result[1] = XYZ_Flat[1] * Y_Scale + Y_Offset;
  32996. result[2] = XYZ_Flat[2] * Z_Scale + Z_Offset;
  32997. }
  32998. function normalizeWhitePointToFlat(sourceWhitePoint, XYZ_In, result) {
  32999. // In case the whitePoint is already flat then there is no need to do
  33000. // normalization.
  33001. if (sourceWhitePoint[0] === 1 && sourceWhitePoint[2] === 1) {
  33002. result[0] = XYZ_In[0];
  33003. result[1] = XYZ_In[1];
  33004. result[2] = XYZ_In[2];
  33005. return;
  33006. }
  33007. var LMS = result;
  33008. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  33009. var LMS_Flat = tempNormalizeMatrix;
  33010. convertToFlat(sourceWhitePoint, LMS, LMS_Flat);
  33011. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_Flat, result);
  33012. }
  33013. function normalizeWhitePointToD65(sourceWhitePoint, XYZ_In, result) {
  33014. var LMS = result;
  33015. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  33016. var LMS_D65 = tempNormalizeMatrix;
  33017. convertToD65(sourceWhitePoint, LMS, LMS_D65);
  33018. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_D65, result);
  33019. }
  33020. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  33021. // A, B and C represent a red, green and blue components of a calibrated
  33022. // rgb space.
  33023. var A = adjustToRange(0, 1, src[srcOffset] * scale);
  33024. var B = adjustToRange(0, 1, src[srcOffset + 1] * scale);
  33025. var C = adjustToRange(0, 1, src[srcOffset + 2] * scale);
  33026. // A <---> AGR in the spec
  33027. // B <---> BGG in the spec
  33028. // C <---> CGB in the spec
  33029. var AGR = Math.pow(A, cs.GR);
  33030. var BGG = Math.pow(B, cs.GG);
  33031. var CGB = Math.pow(C, cs.GB);
  33032. // Computes intermediate variables L, M, N as per spec.
  33033. // To decode X, Y, Z values map L, M, N directly to them.
  33034. var X = cs.MXA * AGR + cs.MXB * BGG + cs.MXC * CGB;
  33035. var Y = cs.MYA * AGR + cs.MYB * BGG + cs.MYC * CGB;
  33036. var Z = cs.MZA * AGR + cs.MZB * BGG + cs.MZC * CGB;
  33037. // The following calculations are based on this document:
  33038. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  33039. // AdobeBPC.pdf.
  33040. var XYZ = tempConvertMatrix1;
  33041. XYZ[0] = X;
  33042. XYZ[1] = Y;
  33043. XYZ[2] = Z;
  33044. var XYZ_Flat = tempConvertMatrix2;
  33045. normalizeWhitePointToFlat(cs.whitePoint, XYZ, XYZ_Flat);
  33046. var XYZ_Black = tempConvertMatrix1;
  33047. compensateBlackPoint(cs.blackPoint, XYZ_Flat, XYZ_Black);
  33048. var XYZ_D65 = tempConvertMatrix2;
  33049. normalizeWhitePointToD65(FLAT_WHITEPOINT_MATRIX, XYZ_Black, XYZ_D65);
  33050. var SRGB = tempConvertMatrix1;
  33051. matrixProduct(SRGB_D65_XYZ_TO_RGB_MATRIX, XYZ_D65, SRGB);
  33052. var sR = sRGBTransferFunction(SRGB[0]);
  33053. var sG = sRGBTransferFunction(SRGB[1]);
  33054. var sB = sRGBTransferFunction(SRGB[2]);
  33055. // Convert the values to rgb range [0, 255].
  33056. dest[destOffset] = Math.round(sR * 255);
  33057. dest[destOffset + 1] = Math.round(sG * 255);
  33058. dest[destOffset + 2] = Math.round(sB * 255);
  33059. }
  33060. CalRGBCS.prototype = {
  33061. getRgb: function CalRGBCS_getRgb(src, srcOffset) {
  33062. var rgb = new Uint8Array(3);
  33063. this.getRgbItem(src, srcOffset, rgb, 0);
  33064. return rgb;
  33065. },
  33066. getRgbItem: function CalRGBCS_getRgbItem(src, srcOffset,
  33067. dest, destOffset) {
  33068. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  33069. },
  33070. getRgbBuffer: function CalRGBCS_getRgbBuffer(src, srcOffset, count,
  33071. dest, destOffset, bits,
  33072. alpha01) {
  33073. var scale = 1 / ((1 << bits) - 1);
  33074. for (var i = 0; i < count; ++i) {
  33075. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  33076. srcOffset += 3;
  33077. destOffset += 3 + alpha01;
  33078. }
  33079. },
  33080. getOutputLength: function CalRGBCS_getOutputLength(inputLength, alpha01) {
  33081. return (inputLength * (3 + alpha01) / 3) | 0;
  33082. },
  33083. isPassthrough: ColorSpace.prototype.isPassthrough,
  33084. fillRgb: ColorSpace.prototype.fillRgb,
  33085. isDefaultDecode: function CalRGBCS_isDefaultDecode(decodeMap) {
  33086. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  33087. },
  33088. usesZeroToOneRange: true
  33089. };
  33090. return CalRGBCS;
  33091. })();
  33092. //
  33093. // LabCS: Based on "PDF Reference, Sixth Ed", p.250
  33094. //
  33095. var LabCS = (function LabCSClosure() {
  33096. function LabCS(whitePoint, blackPoint, range) {
  33097. this.name = 'Lab';
  33098. this.numComps = 3;
  33099. this.defaultColor = new Float32Array([0, 0, 0]);
  33100. if (!whitePoint) {
  33101. error('WhitePoint missing - required for color space Lab');
  33102. }
  33103. blackPoint = blackPoint || [0, 0, 0];
  33104. range = range || [-100, 100, -100, 100];
  33105. // Translate args to spec variables
  33106. this.XW = whitePoint[0];
  33107. this.YW = whitePoint[1];
  33108. this.ZW = whitePoint[2];
  33109. this.amin = range[0];
  33110. this.amax = range[1];
  33111. this.bmin = range[2];
  33112. this.bmax = range[3];
  33113. // These are here just for completeness - the spec doesn't offer any
  33114. // formulas that use BlackPoint in Lab
  33115. this.XB = blackPoint[0];
  33116. this.YB = blackPoint[1];
  33117. this.ZB = blackPoint[2];
  33118. // Validate vars as per spec
  33119. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  33120. error('Invalid WhitePoint components, no fallback available');
  33121. }
  33122. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  33123. info('Invalid BlackPoint, falling back to default');
  33124. this.XB = this.YB = this.ZB = 0;
  33125. }
  33126. if (this.amin > this.amax || this.bmin > this.bmax) {
  33127. info('Invalid Range, falling back to defaults');
  33128. this.amin = -100;
  33129. this.amax = 100;
  33130. this.bmin = -100;
  33131. this.bmax = 100;
  33132. }
  33133. }
  33134. // Function g(x) from spec
  33135. function fn_g(x) {
  33136. if (x >= 6 / 29) {
  33137. return x * x * x;
  33138. } else {
  33139. return (108 / 841) * (x - 4 / 29);
  33140. }
  33141. }
  33142. function decode(value, high1, low2, high2) {
  33143. return low2 + (value) * (high2 - low2) / (high1);
  33144. }
  33145. // If decoding is needed maxVal should be 2^bits per component - 1.
  33146. function convertToRgb(cs, src, srcOffset, maxVal, dest, destOffset) {
  33147. // XXX: Lab input is in the range of [0, 100], [amin, amax], [bmin, bmax]
  33148. // not the usual [0, 1]. If a command like setFillColor is used the src
  33149. // values will already be within the correct range. However, if we are
  33150. // converting an image we have to map the values to the correct range given
  33151. // above.
  33152. // Ls,as,bs <---> L*,a*,b* in the spec
  33153. var Ls = src[srcOffset];
  33154. var as = src[srcOffset + 1];
  33155. var bs = src[srcOffset + 2];
  33156. if (maxVal !== false) {
  33157. Ls = decode(Ls, maxVal, 0, 100);
  33158. as = decode(as, maxVal, cs.amin, cs.amax);
  33159. bs = decode(bs, maxVal, cs.bmin, cs.bmax);
  33160. }
  33161. // Adjust limits of 'as' and 'bs'
  33162. as = as > cs.amax ? cs.amax : as < cs.amin ? cs.amin : as;
  33163. bs = bs > cs.bmax ? cs.bmax : bs < cs.bmin ? cs.bmin : bs;
  33164. // Computes intermediate variables X,Y,Z as per spec
  33165. var M = (Ls + 16) / 116;
  33166. var L = M + (as / 500);
  33167. var N = M - (bs / 200);
  33168. var X = cs.XW * fn_g(L);
  33169. var Y = cs.YW * fn_g(M);
  33170. var Z = cs.ZW * fn_g(N);
  33171. var r, g, b;
  33172. // Using different conversions for D50 and D65 white points,
  33173. // per http://www.color.org/srgb.pdf
  33174. if (cs.ZW < 1) {
  33175. // Assuming D50 (X=0.9642, Y=1.00, Z=0.8249)
  33176. r = X * 3.1339 + Y * -1.6170 + Z * -0.4906;
  33177. g = X * -0.9785 + Y * 1.9160 + Z * 0.0333;
  33178. b = X * 0.0720 + Y * -0.2290 + Z * 1.4057;
  33179. } else {
  33180. // Assuming D65 (X=0.9505, Y=1.00, Z=1.0888)
  33181. r = X * 3.2406 + Y * -1.5372 + Z * -0.4986;
  33182. g = X * -0.9689 + Y * 1.8758 + Z * 0.0415;
  33183. b = X * 0.0557 + Y * -0.2040 + Z * 1.0570;
  33184. }
  33185. // clamp color values to [0,1] range then convert to [0,255] range.
  33186. dest[destOffset] = r <= 0 ? 0 : r >= 1 ? 255 : Math.sqrt(r) * 255 | 0;
  33187. dest[destOffset + 1] = g <= 0 ? 0 : g >= 1 ? 255 : Math.sqrt(g) * 255 | 0;
  33188. dest[destOffset + 2] = b <= 0 ? 0 : b >= 1 ? 255 : Math.sqrt(b) * 255 | 0;
  33189. }
  33190. LabCS.prototype = {
  33191. getRgb: ColorSpace.prototype.getRgb,
  33192. getRgbItem: function LabCS_getRgbItem(src, srcOffset, dest, destOffset) {
  33193. convertToRgb(this, src, srcOffset, false, dest, destOffset);
  33194. },
  33195. getRgbBuffer: function LabCS_getRgbBuffer(src, srcOffset, count,
  33196. dest, destOffset, bits,
  33197. alpha01) {
  33198. var maxVal = (1 << bits) - 1;
  33199. for (var i = 0; i < count; i++) {
  33200. convertToRgb(this, src, srcOffset, maxVal, dest, destOffset);
  33201. srcOffset += 3;
  33202. destOffset += 3 + alpha01;
  33203. }
  33204. },
  33205. getOutputLength: function LabCS_getOutputLength(inputLength, alpha01) {
  33206. return (inputLength * (3 + alpha01) / 3) | 0;
  33207. },
  33208. isPassthrough: ColorSpace.prototype.isPassthrough,
  33209. fillRgb: ColorSpace.prototype.fillRgb,
  33210. isDefaultDecode: function LabCS_isDefaultDecode(decodeMap) {
  33211. // XXX: Decoding is handled with the lab conversion because of the strange
  33212. // ranges that are used.
  33213. return true;
  33214. },
  33215. usesZeroToOneRange: false
  33216. };
  33217. return LabCS;
  33218. })();
  33219. // TODO refactor to remove dependency on image.js
  33220. function _setCoreImage(coreImage_) {
  33221. coreImage = coreImage_;
  33222. PDFImage = coreImage_.PDFImage;
  33223. }
  33224. exports._setCoreImage = _setCoreImage;
  33225. exports.ColorSpace = ColorSpace;
  33226. // TODO refactor to remove dependency on colorspace.js
  33227. coreStream._setCoreColorSpace(exports);
  33228. }));
  33229. (function (root, factory) {
  33230. {
  33231. factory((root.pdfjsCoreImage = {}), root.pdfjsSharedUtil,
  33232. root.pdfjsCorePrimitives, root.pdfjsCoreColorSpace, root.pdfjsCoreStream,
  33233. root.pdfjsCoreJpx);
  33234. }
  33235. }(this, function (exports, sharedUtil, corePrimitives, coreColorSpace,
  33236. coreStream, coreJpx) {
  33237. var ImageKind = sharedUtil.ImageKind;
  33238. var assert = sharedUtil.assert;
  33239. var error = sharedUtil.error;
  33240. var info = sharedUtil.info;
  33241. var isArray = sharedUtil.isArray;
  33242. var warn = sharedUtil.warn;
  33243. var Name = corePrimitives.Name;
  33244. var isStream = corePrimitives.isStream;
  33245. var ColorSpace = coreColorSpace.ColorSpace;
  33246. var DecodeStream = coreStream.DecodeStream;
  33247. var Stream = coreStream.Stream;
  33248. var JpegStream = coreStream.JpegStream;
  33249. var JpxImage = coreJpx.JpxImage;
  33250. var PDFImage = (function PDFImageClosure() {
  33251. /**
  33252. * Decode the image in the main thread if it supported. Resovles the promise
  33253. * when the image data is ready.
  33254. */
  33255. function handleImageData(handler, xref, res, image) {
  33256. if (image instanceof JpegStream && image.isNativelyDecodable(xref, res)) {
  33257. // For natively supported jpegs send them to the main thread for decoding.
  33258. var dict = image.dict;
  33259. var colorSpace = dict.get('ColorSpace', 'CS');
  33260. colorSpace = ColorSpace.parse(colorSpace, xref, res);
  33261. var numComps = colorSpace.numComps;
  33262. var decodePromise = handler.sendWithPromise('JpegDecode',
  33263. [image.getIR(), numComps]);
  33264. return decodePromise.then(function (message) {
  33265. var data = message.data;
  33266. return new Stream(data, 0, data.length, image.dict);
  33267. });
  33268. } else {
  33269. return Promise.resolve(image);
  33270. }
  33271. }
  33272. /**
  33273. * Decode and clamp a value. The formula is different from the spec because we
  33274. * don't decode to float range [0,1], we decode it in the [0,max] range.
  33275. */
  33276. function decodeAndClamp(value, addend, coefficient, max) {
  33277. value = addend + value * coefficient;
  33278. // Clamp the value to the range
  33279. return (value < 0 ? 0 : (value > max ? max : value));
  33280. }
  33281. function PDFImage(xref, res, image, inline, smask, mask, isMask) {
  33282. this.image = image;
  33283. var dict = image.dict;
  33284. if (dict.has('Filter')) {
  33285. var filter = dict.get('Filter').name;
  33286. if (filter === 'JPXDecode') {
  33287. var jpxImage = new JpxImage();
  33288. jpxImage.parseImageProperties(image.stream);
  33289. image.stream.reset();
  33290. image.bitsPerComponent = jpxImage.bitsPerComponent;
  33291. image.numComps = jpxImage.componentsCount;
  33292. } else if (filter === 'JBIG2Decode') {
  33293. image.bitsPerComponent = 1;
  33294. image.numComps = 1;
  33295. }
  33296. }
  33297. // TODO cache rendered images?
  33298. this.width = dict.get('Width', 'W');
  33299. this.height = dict.get('Height', 'H');
  33300. if (this.width < 1 || this.height < 1) {
  33301. error('Invalid image width: ' + this.width + ' or height: ' +
  33302. this.height);
  33303. }
  33304. this.interpolate = dict.get('Interpolate', 'I') || false;
  33305. this.imageMask = dict.get('ImageMask', 'IM') || false;
  33306. this.matte = dict.get('Matte') || false;
  33307. var bitsPerComponent = image.bitsPerComponent;
  33308. if (!bitsPerComponent) {
  33309. bitsPerComponent = dict.get('BitsPerComponent', 'BPC');
  33310. if (!bitsPerComponent) {
  33311. if (this.imageMask) {
  33312. bitsPerComponent = 1;
  33313. } else {
  33314. error('Bits per component missing in image: ' + this.imageMask);
  33315. }
  33316. }
  33317. }
  33318. this.bpc = bitsPerComponent;
  33319. if (!this.imageMask) {
  33320. var colorSpace = dict.get('ColorSpace', 'CS');
  33321. if (!colorSpace) {
  33322. info('JPX images (which do not require color spaces)');
  33323. switch (image.numComps) {
  33324. case 1:
  33325. colorSpace = Name.get('DeviceGray');
  33326. break;
  33327. case 3:
  33328. colorSpace = Name.get('DeviceRGB');
  33329. break;
  33330. case 4:
  33331. colorSpace = Name.get('DeviceCMYK');
  33332. break;
  33333. default:
  33334. error('JPX images with ' + this.numComps +
  33335. ' color components not supported.');
  33336. }
  33337. }
  33338. this.colorSpace = ColorSpace.parse(colorSpace, xref, res);
  33339. this.numComps = this.colorSpace.numComps;
  33340. }
  33341. this.decode = dict.get('Decode', 'D');
  33342. this.needsDecode = false;
  33343. if (this.decode &&
  33344. ((this.colorSpace && !this.colorSpace.isDefaultDecode(this.decode)) ||
  33345. (isMask && !ColorSpace.isDefaultDecode(this.decode, 1)))) {
  33346. this.needsDecode = true;
  33347. // Do some preprocessing to avoid more math.
  33348. var max = (1 << bitsPerComponent) - 1;
  33349. this.decodeCoefficients = [];
  33350. this.decodeAddends = [];
  33351. for (var i = 0, j = 0; i < this.decode.length; i += 2, ++j) {
  33352. var dmin = this.decode[i];
  33353. var dmax = this.decode[i + 1];
  33354. this.decodeCoefficients[j] = dmax - dmin;
  33355. this.decodeAddends[j] = max * dmin;
  33356. }
  33357. }
  33358. if (smask) {
  33359. this.smask = new PDFImage(xref, res, smask, false);
  33360. } else if (mask) {
  33361. if (isStream(mask)) {
  33362. var maskDict = mask.dict, imageMask = maskDict.get('ImageMask', 'IM');
  33363. if (!imageMask) {
  33364. warn('Ignoring /Mask in image without /ImageMask.');
  33365. } else {
  33366. this.mask = new PDFImage(xref, res, mask, false, null, null, true);
  33367. }
  33368. } else {
  33369. // Color key mask (just an array).
  33370. this.mask = mask;
  33371. }
  33372. }
  33373. }
  33374. /**
  33375. * Handles processing of image data and returns the Promise that is resolved
  33376. * with a PDFImage when the image is ready to be used.
  33377. */
  33378. PDFImage.buildImage = function PDFImage_buildImage(handler, xref,
  33379. res, image, inline) {
  33380. var imagePromise = handleImageData(handler, xref, res, image);
  33381. var smaskPromise;
  33382. var maskPromise;
  33383. var smask = image.dict.get('SMask');
  33384. var mask = image.dict.get('Mask');
  33385. if (smask) {
  33386. smaskPromise = handleImageData(handler, xref, res, smask);
  33387. maskPromise = Promise.resolve(null);
  33388. } else {
  33389. smaskPromise = Promise.resolve(null);
  33390. if (mask) {
  33391. if (isStream(mask)) {
  33392. maskPromise = handleImageData(handler, xref, res, mask);
  33393. } else if (isArray(mask)) {
  33394. maskPromise = Promise.resolve(mask);
  33395. } else {
  33396. warn('Unsupported mask format.');
  33397. maskPromise = Promise.resolve(null);
  33398. }
  33399. } else {
  33400. maskPromise = Promise.resolve(null);
  33401. }
  33402. }
  33403. return Promise.all([imagePromise, smaskPromise, maskPromise]).then(
  33404. function(results) {
  33405. var imageData = results[0];
  33406. var smaskData = results[1];
  33407. var maskData = results[2];
  33408. return new PDFImage(xref, res, imageData, inline, smaskData, maskData);
  33409. });
  33410. };
  33411. /**
  33412. * Resize an image using the nearest neighbor algorithm. Currently only
  33413. * supports one and three component images.
  33414. * @param {TypedArray} pixels The original image with one component.
  33415. * @param {Number} bpc Number of bits per component.
  33416. * @param {Number} components Number of color components, 1 or 3 is supported.
  33417. * @param {Number} w1 Original width.
  33418. * @param {Number} h1 Original height.
  33419. * @param {Number} w2 New width.
  33420. * @param {Number} h2 New height.
  33421. * @param {TypedArray} dest (Optional) The destination buffer.
  33422. * @param {Number} alpha01 (Optional) Size reserved for the alpha channel.
  33423. * @return {TypedArray} Resized image data.
  33424. */
  33425. PDFImage.resize = function PDFImage_resize(pixels, bpc, components,
  33426. w1, h1, w2, h2, dest, alpha01) {
  33427. if (components !== 1 && components !== 3) {
  33428. error('Unsupported component count for resizing.');
  33429. }
  33430. var length = w2 * h2 * components;
  33431. var temp = dest ? dest : (bpc <= 8 ? new Uint8Array(length) :
  33432. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  33433. var xRatio = w1 / w2;
  33434. var yRatio = h1 / h2;
  33435. var i, j, py, newIndex = 0, oldIndex;
  33436. var xScaled = new Uint16Array(w2);
  33437. var w1Scanline = w1 * components;
  33438. if (alpha01 !== 1) {
  33439. alpha01 = 0;
  33440. }
  33441. for (j = 0; j < w2; j++) {
  33442. xScaled[j] = Math.floor(j * xRatio) * components;
  33443. }
  33444. if (components === 1) {
  33445. for (i = 0; i < h2; i++) {
  33446. py = Math.floor(i * yRatio) * w1Scanline;
  33447. for (j = 0; j < w2; j++) {
  33448. oldIndex = py + xScaled[j];
  33449. temp[newIndex++] = pixels[oldIndex];
  33450. }
  33451. }
  33452. } else if (components === 3) {
  33453. for (i = 0; i < h2; i++) {
  33454. py = Math.floor(i * yRatio) * w1Scanline;
  33455. for (j = 0; j < w2; j++) {
  33456. oldIndex = py + xScaled[j];
  33457. temp[newIndex++] = pixels[oldIndex++];
  33458. temp[newIndex++] = pixels[oldIndex++];
  33459. temp[newIndex++] = pixels[oldIndex++];
  33460. newIndex += alpha01;
  33461. }
  33462. }
  33463. }
  33464. return temp;
  33465. };
  33466. PDFImage.createMask =
  33467. function PDFImage_createMask(imgArray, width, height,
  33468. imageIsFromDecodeStream, inverseDecode) {
  33469. // |imgArray| might not contain full data for every pixel of the mask, so
  33470. // we need to distinguish between |computedLength| and |actualLength|.
  33471. // In particular, if inverseDecode is true, then the array we return must
  33472. // have a length of |computedLength|.
  33473. var computedLength = ((width + 7) >> 3) * height;
  33474. var actualLength = imgArray.byteLength;
  33475. var haveFullData = computedLength === actualLength;
  33476. var data, i;
  33477. if (imageIsFromDecodeStream && (!inverseDecode || haveFullData)) {
  33478. // imgArray came from a DecodeStream and its data is in an appropriate
  33479. // form, so we can just transfer it.
  33480. data = imgArray;
  33481. } else if (!inverseDecode) {
  33482. data = new Uint8Array(actualLength);
  33483. data.set(imgArray);
  33484. } else {
  33485. data = new Uint8Array(computedLength);
  33486. data.set(imgArray);
  33487. for (i = actualLength; i < computedLength; i++) {
  33488. data[i] = 0xff;
  33489. }
  33490. }
  33491. // If necessary, invert the original mask data (but not any extra we might
  33492. // have added above). It's safe to modify the array -- whether it's the
  33493. // original or a copy, we're about to transfer it anyway, so nothing else
  33494. // in this thread can be relying on its contents.
  33495. if (inverseDecode) {
  33496. for (i = 0; i < actualLength; i++) {
  33497. data[i] = ~data[i];
  33498. }
  33499. }
  33500. return {data: data, width: width, height: height};
  33501. };
  33502. PDFImage.prototype = {
  33503. get drawWidth() {
  33504. return Math.max(this.width,
  33505. this.smask && this.smask.width || 0,
  33506. this.mask && this.mask.width || 0);
  33507. },
  33508. get drawHeight() {
  33509. return Math.max(this.height,
  33510. this.smask && this.smask.height || 0,
  33511. this.mask && this.mask.height || 0);
  33512. },
  33513. decodeBuffer: function PDFImage_decodeBuffer(buffer) {
  33514. var bpc = this.bpc;
  33515. var numComps = this.numComps;
  33516. var decodeAddends = this.decodeAddends;
  33517. var decodeCoefficients = this.decodeCoefficients;
  33518. var max = (1 << bpc) - 1;
  33519. var i, ii;
  33520. if (bpc === 1) {
  33521. // If the buffer needed decode that means it just needs to be inverted.
  33522. for (i = 0, ii = buffer.length; i < ii; i++) {
  33523. buffer[i] = +!(buffer[i]);
  33524. }
  33525. return;
  33526. }
  33527. var index = 0;
  33528. for (i = 0, ii = this.width * this.height; i < ii; i++) {
  33529. for (var j = 0; j < numComps; j++) {
  33530. buffer[index] = decodeAndClamp(buffer[index], decodeAddends[j],
  33531. decodeCoefficients[j], max);
  33532. index++;
  33533. }
  33534. }
  33535. },
  33536. getComponents: function PDFImage_getComponents(buffer) {
  33537. var bpc = this.bpc;
  33538. // This image doesn't require any extra work.
  33539. if (bpc === 8) {
  33540. return buffer;
  33541. }
  33542. var width = this.width;
  33543. var height = this.height;
  33544. var numComps = this.numComps;
  33545. var length = width * height * numComps;
  33546. var bufferPos = 0;
  33547. var output = (bpc <= 8 ? new Uint8Array(length) :
  33548. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  33549. var rowComps = width * numComps;
  33550. var max = (1 << bpc) - 1;
  33551. var i = 0, ii, buf;
  33552. if (bpc === 1) {
  33553. // Optimization for reading 1 bpc images.
  33554. var mask, loop1End, loop2End;
  33555. for (var j = 0; j < height; j++) {
  33556. loop1End = i + (rowComps & ~7);
  33557. loop2End = i + rowComps;
  33558. // unroll loop for all full bytes
  33559. while (i < loop1End) {
  33560. buf = buffer[bufferPos++];
  33561. output[i] = (buf >> 7) & 1;
  33562. output[i + 1] = (buf >> 6) & 1;
  33563. output[i + 2] = (buf >> 5) & 1;
  33564. output[i + 3] = (buf >> 4) & 1;
  33565. output[i + 4] = (buf >> 3) & 1;
  33566. output[i + 5] = (buf >> 2) & 1;
  33567. output[i + 6] = (buf >> 1) & 1;
  33568. output[i + 7] = buf & 1;
  33569. i += 8;
  33570. }
  33571. // handle remaing bits
  33572. if (i < loop2End) {
  33573. buf = buffer[bufferPos++];
  33574. mask = 128;
  33575. while (i < loop2End) {
  33576. output[i++] = +!!(buf & mask);
  33577. mask >>= 1;
  33578. }
  33579. }
  33580. }
  33581. } else {
  33582. // The general case that handles all other bpc values.
  33583. var bits = 0;
  33584. buf = 0;
  33585. for (i = 0, ii = length; i < ii; ++i) {
  33586. if (i % rowComps === 0) {
  33587. buf = 0;
  33588. bits = 0;
  33589. }
  33590. while (bits < bpc) {
  33591. buf = (buf << 8) | buffer[bufferPos++];
  33592. bits += 8;
  33593. }
  33594. var remainingBits = bits - bpc;
  33595. var value = buf >> remainingBits;
  33596. output[i] = (value < 0 ? 0 : (value > max ? max : value));
  33597. buf = buf & ((1 << remainingBits) - 1);
  33598. bits = remainingBits;
  33599. }
  33600. }
  33601. return output;
  33602. },
  33603. fillOpacity: function PDFImage_fillOpacity(rgbaBuf, width, height,
  33604. actualHeight, image) {
  33605. var smask = this.smask;
  33606. var mask = this.mask;
  33607. var alphaBuf, sw, sh, i, ii, j;
  33608. if (smask) {
  33609. sw = smask.width;
  33610. sh = smask.height;
  33611. alphaBuf = new Uint8Array(sw * sh);
  33612. smask.fillGrayBuffer(alphaBuf);
  33613. if (sw !== width || sh !== height) {
  33614. alphaBuf = PDFImage.resize(alphaBuf, smask.bpc, 1, sw, sh, width,
  33615. height);
  33616. }
  33617. } else if (mask) {
  33618. if (mask instanceof PDFImage) {
  33619. sw = mask.width;
  33620. sh = mask.height;
  33621. alphaBuf = new Uint8Array(sw * sh);
  33622. mask.numComps = 1;
  33623. mask.fillGrayBuffer(alphaBuf);
  33624. // Need to invert values in rgbaBuf
  33625. for (i = 0, ii = sw * sh; i < ii; ++i) {
  33626. alphaBuf[i] = 255 - alphaBuf[i];
  33627. }
  33628. if (sw !== width || sh !== height) {
  33629. alphaBuf = PDFImage.resize(alphaBuf, mask.bpc, 1, sw, sh, width,
  33630. height);
  33631. }
  33632. } else if (isArray(mask)) {
  33633. // Color key mask: if any of the compontents are outside the range
  33634. // then they should be painted.
  33635. alphaBuf = new Uint8Array(width * height);
  33636. var numComps = this.numComps;
  33637. for (i = 0, ii = width * height; i < ii; ++i) {
  33638. var opacity = 0;
  33639. var imageOffset = i * numComps;
  33640. for (j = 0; j < numComps; ++j) {
  33641. var color = image[imageOffset + j];
  33642. var maskOffset = j * 2;
  33643. if (color < mask[maskOffset] || color > mask[maskOffset + 1]) {
  33644. opacity = 255;
  33645. break;
  33646. }
  33647. }
  33648. alphaBuf[i] = opacity;
  33649. }
  33650. } else {
  33651. error('Unknown mask format.');
  33652. }
  33653. }
  33654. if (alphaBuf) {
  33655. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  33656. rgbaBuf[j] = alphaBuf[i];
  33657. }
  33658. } else {
  33659. // No mask.
  33660. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  33661. rgbaBuf[j] = 255;
  33662. }
  33663. }
  33664. },
  33665. undoPreblend: function PDFImage_undoPreblend(buffer, width, height) {
  33666. var matte = this.smask && this.smask.matte;
  33667. if (!matte) {
  33668. return;
  33669. }
  33670. var matteRgb = this.colorSpace.getRgb(matte, 0);
  33671. var matteR = matteRgb[0];
  33672. var matteG = matteRgb[1];
  33673. var matteB = matteRgb[2];
  33674. var length = width * height * 4;
  33675. var r, g, b;
  33676. for (var i = 0; i < length; i += 4) {
  33677. var alpha = buffer[i + 3];
  33678. if (alpha === 0) {
  33679. // according formula we have to get Infinity in all components
  33680. // making it white (typical paper color) should be okay
  33681. buffer[i] = 255;
  33682. buffer[i + 1] = 255;
  33683. buffer[i + 2] = 255;
  33684. continue;
  33685. }
  33686. var k = 255 / alpha;
  33687. r = (buffer[i] - matteR) * k + matteR;
  33688. g = (buffer[i + 1] - matteG) * k + matteG;
  33689. b = (buffer[i + 2] - matteB) * k + matteB;
  33690. buffer[i] = r <= 0 ? 0 : r >= 255 ? 255 : r | 0;
  33691. buffer[i + 1] = g <= 0 ? 0 : g >= 255 ? 255 : g | 0;
  33692. buffer[i + 2] = b <= 0 ? 0 : b >= 255 ? 255 : b | 0;
  33693. }
  33694. },
  33695. createImageData: function PDFImage_createImageData(forceRGBA) {
  33696. var drawWidth = this.drawWidth;
  33697. var drawHeight = this.drawHeight;
  33698. var imgData = { // other fields are filled in below
  33699. width: drawWidth,
  33700. height: drawHeight
  33701. };
  33702. var numComps = this.numComps;
  33703. var originalWidth = this.width;
  33704. var originalHeight = this.height;
  33705. var bpc = this.bpc;
  33706. // Rows start at byte boundary.
  33707. var rowBytes = (originalWidth * numComps * bpc + 7) >> 3;
  33708. var imgArray;
  33709. if (!forceRGBA) {
  33710. // If it is a 1-bit-per-pixel grayscale (i.e. black-and-white) image
  33711. // without any complications, we pass a same-sized copy to the main
  33712. // thread rather than expanding by 32x to RGBA form. This saves *lots*
  33713. // of memory for many scanned documents. It's also much faster.
  33714. //
  33715. // Similarly, if it is a 24-bit-per pixel RGB image without any
  33716. // complications, we avoid expanding by 1.333x to RGBA form.
  33717. var kind;
  33718. if (this.colorSpace.name === 'DeviceGray' && bpc === 1) {
  33719. kind = ImageKind.GRAYSCALE_1BPP;
  33720. } else if (this.colorSpace.name === 'DeviceRGB' && bpc === 8 &&
  33721. !this.needsDecode) {
  33722. kind = ImageKind.RGB_24BPP;
  33723. }
  33724. if (kind && !this.smask && !this.mask &&
  33725. drawWidth === originalWidth && drawHeight === originalHeight) {
  33726. imgData.kind = kind;
  33727. imgArray = this.getImageBytes(originalHeight * rowBytes);
  33728. // If imgArray came from a DecodeStream, we're safe to transfer it
  33729. // (and thus neuter it) because it will constitute the entire
  33730. // DecodeStream's data. But if it came from a Stream, we need to
  33731. // copy it because it'll only be a portion of the Stream's data, and
  33732. // the rest will be read later on.
  33733. if (this.image instanceof DecodeStream) {
  33734. imgData.data = imgArray;
  33735. } else {
  33736. var newArray = new Uint8Array(imgArray.length);
  33737. newArray.set(imgArray);
  33738. imgData.data = newArray;
  33739. }
  33740. if (this.needsDecode) {
  33741. // Invert the buffer (which must be grayscale if we reached here).
  33742. assert(kind === ImageKind.GRAYSCALE_1BPP);
  33743. var buffer = imgData.data;
  33744. for (var i = 0, ii = buffer.length; i < ii; i++) {
  33745. buffer[i] ^= 0xff;
  33746. }
  33747. }
  33748. return imgData;
  33749. }
  33750. if (this.image instanceof JpegStream && !this.smask && !this.mask &&
  33751. (this.colorSpace.name === 'DeviceGray' ||
  33752. this.colorSpace.name === 'DeviceRGB' ||
  33753. this.colorSpace.name === 'DeviceCMYK')) {
  33754. imgData.kind = ImageKind.RGB_24BPP;
  33755. imgData.data = this.getImageBytes(originalHeight * rowBytes,
  33756. drawWidth, drawHeight, true);
  33757. return imgData;
  33758. }
  33759. }
  33760. imgArray = this.getImageBytes(originalHeight * rowBytes);
  33761. // imgArray can be incomplete (e.g. after CCITT fax encoding).
  33762. var actualHeight = 0 | (imgArray.length / rowBytes *
  33763. drawHeight / originalHeight);
  33764. var comps = this.getComponents(imgArray);
  33765. // If opacity data is present, use RGBA_32BPP form. Otherwise, use the
  33766. // more compact RGB_24BPP form if allowable.
  33767. var alpha01, maybeUndoPreblend;
  33768. if (!forceRGBA && !this.smask && !this.mask) {
  33769. imgData.kind = ImageKind.RGB_24BPP;
  33770. imgData.data = new Uint8Array(drawWidth * drawHeight * 3);
  33771. alpha01 = 0;
  33772. maybeUndoPreblend = false;
  33773. } else {
  33774. imgData.kind = ImageKind.RGBA_32BPP;
  33775. imgData.data = new Uint8Array(drawWidth * drawHeight * 4);
  33776. alpha01 = 1;
  33777. maybeUndoPreblend = true;
  33778. // Color key masking (opacity) must be performed before decoding.
  33779. this.fillOpacity(imgData.data, drawWidth, drawHeight, actualHeight,
  33780. comps);
  33781. }
  33782. if (this.needsDecode) {
  33783. this.decodeBuffer(comps);
  33784. }
  33785. this.colorSpace.fillRgb(imgData.data, originalWidth, originalHeight,
  33786. drawWidth, drawHeight, actualHeight, bpc, comps,
  33787. alpha01);
  33788. if (maybeUndoPreblend) {
  33789. this.undoPreblend(imgData.data, drawWidth, actualHeight);
  33790. }
  33791. return imgData;
  33792. },
  33793. fillGrayBuffer: function PDFImage_fillGrayBuffer(buffer) {
  33794. var numComps = this.numComps;
  33795. if (numComps !== 1) {
  33796. error('Reading gray scale from a color image: ' + numComps);
  33797. }
  33798. var width = this.width;
  33799. var height = this.height;
  33800. var bpc = this.bpc;
  33801. // rows start at byte boundary
  33802. var rowBytes = (width * numComps * bpc + 7) >> 3;
  33803. var imgArray = this.getImageBytes(height * rowBytes);
  33804. var comps = this.getComponents(imgArray);
  33805. var i, length;
  33806. if (bpc === 1) {
  33807. // inline decoding (= inversion) for 1 bpc images
  33808. length = width * height;
  33809. if (this.needsDecode) {
  33810. // invert and scale to {0, 255}
  33811. for (i = 0; i < length; ++i) {
  33812. buffer[i] = (comps[i] - 1) & 255;
  33813. }
  33814. } else {
  33815. // scale to {0, 255}
  33816. for (i = 0; i < length; ++i) {
  33817. buffer[i] = (-comps[i]) & 255;
  33818. }
  33819. }
  33820. return;
  33821. }
  33822. if (this.needsDecode) {
  33823. this.decodeBuffer(comps);
  33824. }
  33825. length = width * height;
  33826. // we aren't using a colorspace so we need to scale the value
  33827. var scale = 255 / ((1 << bpc) - 1);
  33828. for (i = 0; i < length; ++i) {
  33829. buffer[i] = (scale * comps[i]) | 0;
  33830. }
  33831. },
  33832. getImageBytes: function PDFImage_getImageBytes(length,
  33833. drawWidth, drawHeight,
  33834. forceRGB) {
  33835. this.image.reset();
  33836. this.image.drawWidth = drawWidth || this.width;
  33837. this.image.drawHeight = drawHeight || this.height;
  33838. this.image.forceRGB = !!forceRGB;
  33839. return this.image.getBytes(length);
  33840. }
  33841. };
  33842. return PDFImage;
  33843. })();
  33844. exports.PDFImage = PDFImage;
  33845. // TODO refactor to remove dependency on colorspace.js
  33846. coreColorSpace._setCoreImage(exports);
  33847. }));
  33848. (function (root, factory) {
  33849. {
  33850. factory((root.pdfjsCorePattern = {}), root.pdfjsSharedUtil,
  33851. root.pdfjsCorePrimitives, root.pdfjsCoreFunction,
  33852. root.pdfjsCoreColorSpace);
  33853. }
  33854. }(this, function (exports, sharedUtil, corePrimitives, coreFunction,
  33855. coreColorSpace) {
  33856. var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  33857. var MissingDataException = sharedUtil.MissingDataException;
  33858. var Util = sharedUtil.Util;
  33859. var assert = sharedUtil.assert;
  33860. var error = sharedUtil.error;
  33861. var info = sharedUtil.info;
  33862. var warn = sharedUtil.warn;
  33863. var isStream = corePrimitives.isStream;
  33864. var PDFFunction = coreFunction.PDFFunction;
  33865. var ColorSpace = coreColorSpace.ColorSpace;
  33866. var ShadingType = {
  33867. FUNCTION_BASED: 1,
  33868. AXIAL: 2,
  33869. RADIAL: 3,
  33870. FREE_FORM_MESH: 4,
  33871. LATTICE_FORM_MESH: 5,
  33872. COONS_PATCH_MESH: 6,
  33873. TENSOR_PATCH_MESH: 7
  33874. };
  33875. var Pattern = (function PatternClosure() {
  33876. // Constructor should define this.getPattern
  33877. function Pattern() {
  33878. error('should not call Pattern constructor');
  33879. }
  33880. Pattern.prototype = {
  33881. // Input: current Canvas context
  33882. // Output: the appropriate fillStyle or strokeStyle
  33883. getPattern: function Pattern_getPattern(ctx) {
  33884. error('Should not call Pattern.getStyle: ' + ctx);
  33885. }
  33886. };
  33887. Pattern.parseShading = function Pattern_parseShading(shading, matrix, xref,
  33888. res, handler) {
  33889. var dict = isStream(shading) ? shading.dict : shading;
  33890. var type = dict.get('ShadingType');
  33891. try {
  33892. switch (type) {
  33893. case ShadingType.AXIAL:
  33894. case ShadingType.RADIAL:
  33895. // Both radial and axial shadings are handled by RadialAxial shading.
  33896. return new Shadings.RadialAxial(dict, matrix, xref, res);
  33897. case ShadingType.FREE_FORM_MESH:
  33898. case ShadingType.LATTICE_FORM_MESH:
  33899. case ShadingType.COONS_PATCH_MESH:
  33900. case ShadingType.TENSOR_PATCH_MESH:
  33901. return new Shadings.Mesh(shading, matrix, xref, res);
  33902. default:
  33903. throw new Error('Unsupported ShadingType: ' + type);
  33904. }
  33905. } catch (ex) {
  33906. if (ex instanceof MissingDataException) {
  33907. throw ex;
  33908. }
  33909. handler.send('UnsupportedFeature',
  33910. {featureId: UNSUPPORTED_FEATURES.shadingPattern});
  33911. warn(ex);
  33912. return new Shadings.Dummy();
  33913. }
  33914. };
  33915. return Pattern;
  33916. })();
  33917. var Shadings = {};
  33918. // A small number to offset the first/last color stops so we can insert ones to
  33919. // support extend. Number.MIN_VALUE is too small and breaks the extend.
  33920. Shadings.SMALL_NUMBER = 1e-6;
  33921. // Radial and axial shading have very similar implementations
  33922. // If needed, the implementations can be broken into two classes
  33923. Shadings.RadialAxial = (function RadialAxialClosure() {
  33924. function RadialAxial(dict, matrix, xref, res) {
  33925. this.matrix = matrix;
  33926. this.coordsArr = dict.get('Coords');
  33927. this.shadingType = dict.get('ShadingType');
  33928. this.type = 'Pattern';
  33929. var cs = dict.get('ColorSpace', 'CS');
  33930. cs = ColorSpace.parse(cs, xref, res);
  33931. this.cs = cs;
  33932. var t0 = 0.0, t1 = 1.0;
  33933. if (dict.has('Domain')) {
  33934. var domainArr = dict.get('Domain');
  33935. t0 = domainArr[0];
  33936. t1 = domainArr[1];
  33937. }
  33938. var extendStart = false, extendEnd = false;
  33939. if (dict.has('Extend')) {
  33940. var extendArr = dict.get('Extend');
  33941. extendStart = extendArr[0];
  33942. extendEnd = extendArr[1];
  33943. }
  33944. if (this.shadingType === ShadingType.RADIAL &&
  33945. (!extendStart || !extendEnd)) {
  33946. // Radial gradient only currently works if either circle is fully within
  33947. // the other circle.
  33948. var x1 = this.coordsArr[0];
  33949. var y1 = this.coordsArr[1];
  33950. var r1 = this.coordsArr[2];
  33951. var x2 = this.coordsArr[3];
  33952. var y2 = this.coordsArr[4];
  33953. var r2 = this.coordsArr[5];
  33954. var distance = Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
  33955. if (r1 <= r2 + distance &&
  33956. r2 <= r1 + distance) {
  33957. warn('Unsupported radial gradient.');
  33958. }
  33959. }
  33960. this.extendStart = extendStart;
  33961. this.extendEnd = extendEnd;
  33962. var fnObj = dict.get('Function');
  33963. var fn = PDFFunction.parseArray(xref, fnObj);
  33964. // 10 samples seems good enough for now, but probably won't work
  33965. // if there are sharp color changes. Ideally, we would implement
  33966. // the spec faithfully and add lossless optimizations.
  33967. var diff = t1 - t0;
  33968. var step = diff / 10;
  33969. var colorStops = this.colorStops = [];
  33970. // Protect against bad domains so we don't end up in an infinte loop below.
  33971. if (t0 >= t1 || step <= 0) {
  33972. // Acrobat doesn't seem to handle these cases so we'll ignore for
  33973. // now.
  33974. info('Bad shading domain.');
  33975. return;
  33976. }
  33977. var color = new Float32Array(cs.numComps), ratio = new Float32Array(1);
  33978. var rgbColor;
  33979. for (var i = t0; i <= t1; i += step) {
  33980. ratio[0] = i;
  33981. fn(ratio, 0, color, 0);
  33982. rgbColor = cs.getRgb(color, 0);
  33983. var cssColor = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  33984. colorStops.push([(i - t0) / diff, cssColor]);
  33985. }
  33986. var background = 'transparent';
  33987. if (dict.has('Background')) {
  33988. rgbColor = cs.getRgb(dict.get('Background'), 0);
  33989. background = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  33990. }
  33991. if (!extendStart) {
  33992. // Insert a color stop at the front and offset the first real color stop
  33993. // so it doesn't conflict with the one we insert.
  33994. colorStops.unshift([0, background]);
  33995. colorStops[1][0] += Shadings.SMALL_NUMBER;
  33996. }
  33997. if (!extendEnd) {
  33998. // Same idea as above in extendStart but for the end.
  33999. colorStops[colorStops.length - 1][0] -= Shadings.SMALL_NUMBER;
  34000. colorStops.push([1, background]);
  34001. }
  34002. this.colorStops = colorStops;
  34003. }
  34004. RadialAxial.prototype = {
  34005. getIR: function RadialAxial_getIR() {
  34006. var coordsArr = this.coordsArr;
  34007. var shadingType = this.shadingType;
  34008. var type, p0, p1, r0, r1;
  34009. if (shadingType === ShadingType.AXIAL) {
  34010. p0 = [coordsArr[0], coordsArr[1]];
  34011. p1 = [coordsArr[2], coordsArr[3]];
  34012. r0 = null;
  34013. r1 = null;
  34014. type = 'axial';
  34015. } else if (shadingType === ShadingType.RADIAL) {
  34016. p0 = [coordsArr[0], coordsArr[1]];
  34017. p1 = [coordsArr[3], coordsArr[4]];
  34018. r0 = coordsArr[2];
  34019. r1 = coordsArr[5];
  34020. type = 'radial';
  34021. } else {
  34022. error('getPattern type unknown: ' + shadingType);
  34023. }
  34024. var matrix = this.matrix;
  34025. if (matrix) {
  34026. p0 = Util.applyTransform(p0, matrix);
  34027. p1 = Util.applyTransform(p1, matrix);
  34028. if (shadingType === ShadingType.RADIAL) {
  34029. var scale = Util.singularValueDecompose2dScale(matrix);
  34030. r0 *= scale[0];
  34031. r1 *= scale[1];
  34032. }
  34033. }
  34034. return ['RadialAxial', type, this.colorStops, p0, p1, r0, r1];
  34035. }
  34036. };
  34037. return RadialAxial;
  34038. })();
  34039. // All mesh shading. For now, they will be presented as set of the triangles
  34040. // to be drawn on the canvas and rgb color for each vertex.
  34041. Shadings.Mesh = (function MeshClosure() {
  34042. function MeshStreamReader(stream, context) {
  34043. this.stream = stream;
  34044. this.context = context;
  34045. this.buffer = 0;
  34046. this.bufferLength = 0;
  34047. var numComps = context.numComps;
  34048. this.tmpCompsBuf = new Float32Array(numComps);
  34049. var csNumComps = context.colorSpace.numComps;
  34050. this.tmpCsCompsBuf = context.colorFn ? new Float32Array(csNumComps) :
  34051. this.tmpCompsBuf;
  34052. }
  34053. MeshStreamReader.prototype = {
  34054. get hasData() {
  34055. if (this.stream.end) {
  34056. return this.stream.pos < this.stream.end;
  34057. }
  34058. if (this.bufferLength > 0) {
  34059. return true;
  34060. }
  34061. var nextByte = this.stream.getByte();
  34062. if (nextByte < 0) {
  34063. return false;
  34064. }
  34065. this.buffer = nextByte;
  34066. this.bufferLength = 8;
  34067. return true;
  34068. },
  34069. readBits: function MeshStreamReader_readBits(n) {
  34070. var buffer = this.buffer;
  34071. var bufferLength = this.bufferLength;
  34072. if (n === 32) {
  34073. if (bufferLength === 0) {
  34074. return ((this.stream.getByte() << 24) |
  34075. (this.stream.getByte() << 16) | (this.stream.getByte() << 8) |
  34076. this.stream.getByte()) >>> 0;
  34077. }
  34078. buffer = (buffer << 24) | (this.stream.getByte() << 16) |
  34079. (this.stream.getByte() << 8) | this.stream.getByte();
  34080. var nextByte = this.stream.getByte();
  34081. this.buffer = nextByte & ((1 << bufferLength) - 1);
  34082. return ((buffer << (8 - bufferLength)) |
  34083. ((nextByte & 0xFF) >> bufferLength)) >>> 0;
  34084. }
  34085. if (n === 8 && bufferLength === 0) {
  34086. return this.stream.getByte();
  34087. }
  34088. while (bufferLength < n) {
  34089. buffer = (buffer << 8) | this.stream.getByte();
  34090. bufferLength += 8;
  34091. }
  34092. bufferLength -= n;
  34093. this.bufferLength = bufferLength;
  34094. this.buffer = buffer & ((1 << bufferLength) - 1);
  34095. return buffer >> bufferLength;
  34096. },
  34097. align: function MeshStreamReader_align() {
  34098. this.buffer = 0;
  34099. this.bufferLength = 0;
  34100. },
  34101. readFlag: function MeshStreamReader_readFlag() {
  34102. return this.readBits(this.context.bitsPerFlag);
  34103. },
  34104. readCoordinate: function MeshStreamReader_readCoordinate() {
  34105. var bitsPerCoordinate = this.context.bitsPerCoordinate;
  34106. var xi = this.readBits(bitsPerCoordinate);
  34107. var yi = this.readBits(bitsPerCoordinate);
  34108. var decode = this.context.decode;
  34109. var scale = bitsPerCoordinate < 32 ? 1 / ((1 << bitsPerCoordinate) - 1) :
  34110. 2.3283064365386963e-10; // 2 ^ -32
  34111. return [
  34112. xi * scale * (decode[1] - decode[0]) + decode[0],
  34113. yi * scale * (decode[3] - decode[2]) + decode[2]
  34114. ];
  34115. },
  34116. readComponents: function MeshStreamReader_readComponents() {
  34117. var numComps = this.context.numComps;
  34118. var bitsPerComponent = this.context.bitsPerComponent;
  34119. var scale = bitsPerComponent < 32 ? 1 / ((1 << bitsPerComponent) - 1) :
  34120. 2.3283064365386963e-10; // 2 ^ -32
  34121. var decode = this.context.decode;
  34122. var components = this.tmpCompsBuf;
  34123. for (var i = 0, j = 4; i < numComps; i++, j += 2) {
  34124. var ci = this.readBits(bitsPerComponent);
  34125. components[i] = ci * scale * (decode[j + 1] - decode[j]) + decode[j];
  34126. }
  34127. var color = this.tmpCsCompsBuf;
  34128. if (this.context.colorFn) {
  34129. this.context.colorFn(components, 0, color, 0);
  34130. }
  34131. return this.context.colorSpace.getRgb(color, 0);
  34132. }
  34133. };
  34134. function decodeType4Shading(mesh, reader) {
  34135. var coords = mesh.coords;
  34136. var colors = mesh.colors;
  34137. var operators = [];
  34138. var ps = []; // not maintaining cs since that will match ps
  34139. var verticesLeft = 0; // assuming we have all data to start a new triangle
  34140. while (reader.hasData) {
  34141. var f = reader.readFlag();
  34142. var coord = reader.readCoordinate();
  34143. var color = reader.readComponents();
  34144. if (verticesLeft === 0) { // ignoring flags if we started a triangle
  34145. assert(0 <= f && f <= 2, 'Unknown type4 flag');
  34146. switch (f) {
  34147. case 0:
  34148. verticesLeft = 3;
  34149. break;
  34150. case 1:
  34151. ps.push(ps[ps.length - 2], ps[ps.length - 1]);
  34152. verticesLeft = 1;
  34153. break;
  34154. case 2:
  34155. ps.push(ps[ps.length - 3], ps[ps.length - 1]);
  34156. verticesLeft = 1;
  34157. break;
  34158. }
  34159. operators.push(f);
  34160. }
  34161. ps.push(coords.length);
  34162. coords.push(coord);
  34163. colors.push(color);
  34164. verticesLeft--;
  34165. reader.align();
  34166. }
  34167. mesh.figures.push({
  34168. type: 'triangles',
  34169. coords: new Int32Array(ps),
  34170. colors: new Int32Array(ps),
  34171. });
  34172. }
  34173. function decodeType5Shading(mesh, reader, verticesPerRow) {
  34174. var coords = mesh.coords;
  34175. var colors = mesh.colors;
  34176. var ps = []; // not maintaining cs since that will match ps
  34177. while (reader.hasData) {
  34178. var coord = reader.readCoordinate();
  34179. var color = reader.readComponents();
  34180. ps.push(coords.length);
  34181. coords.push(coord);
  34182. colors.push(color);
  34183. }
  34184. mesh.figures.push({
  34185. type: 'lattice',
  34186. coords: new Int32Array(ps),
  34187. colors: new Int32Array(ps),
  34188. verticesPerRow: verticesPerRow
  34189. });
  34190. }
  34191. var MIN_SPLIT_PATCH_CHUNKS_AMOUNT = 3;
  34192. var MAX_SPLIT_PATCH_CHUNKS_AMOUNT = 20;
  34193. var TRIANGLE_DENSITY = 20; // count of triangles per entire mesh bounds
  34194. var getB = (function getBClosure() {
  34195. function buildB(count) {
  34196. var lut = [];
  34197. for (var i = 0; i <= count; i++) {
  34198. var t = i / count, t_ = 1 - t;
  34199. lut.push(new Float32Array([t_ * t_ * t_, 3 * t * t_ * t_,
  34200. 3 * t * t * t_, t * t * t]));
  34201. }
  34202. return lut;
  34203. }
  34204. var cache = [];
  34205. return function getB(count) {
  34206. if (!cache[count]) {
  34207. cache[count] = buildB(count);
  34208. }
  34209. return cache[count];
  34210. };
  34211. })();
  34212. function buildFigureFromPatch(mesh, index) {
  34213. var figure = mesh.figures[index];
  34214. assert(figure.type === 'patch', 'Unexpected patch mesh figure');
  34215. var coords = mesh.coords, colors = mesh.colors;
  34216. var pi = figure.coords;
  34217. var ci = figure.colors;
  34218. var figureMinX = Math.min(coords[pi[0]][0], coords[pi[3]][0],
  34219. coords[pi[12]][0], coords[pi[15]][0]);
  34220. var figureMinY = Math.min(coords[pi[0]][1], coords[pi[3]][1],
  34221. coords[pi[12]][1], coords[pi[15]][1]);
  34222. var figureMaxX = Math.max(coords[pi[0]][0], coords[pi[3]][0],
  34223. coords[pi[12]][0], coords[pi[15]][0]);
  34224. var figureMaxY = Math.max(coords[pi[0]][1], coords[pi[3]][1],
  34225. coords[pi[12]][1], coords[pi[15]][1]);
  34226. var splitXBy = Math.ceil((figureMaxX - figureMinX) * TRIANGLE_DENSITY /
  34227. (mesh.bounds[2] - mesh.bounds[0]));
  34228. splitXBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  34229. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitXBy));
  34230. var splitYBy = Math.ceil((figureMaxY - figureMinY) * TRIANGLE_DENSITY /
  34231. (mesh.bounds[3] - mesh.bounds[1]));
  34232. splitYBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  34233. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitYBy));
  34234. var verticesPerRow = splitXBy + 1;
  34235. var figureCoords = new Int32Array((splitYBy + 1) * verticesPerRow);
  34236. var figureColors = new Int32Array((splitYBy + 1) * verticesPerRow);
  34237. var k = 0;
  34238. var cl = new Uint8Array(3), cr = new Uint8Array(3);
  34239. var c0 = colors[ci[0]], c1 = colors[ci[1]],
  34240. c2 = colors[ci[2]], c3 = colors[ci[3]];
  34241. var bRow = getB(splitYBy), bCol = getB(splitXBy);
  34242. for (var row = 0; row <= splitYBy; row++) {
  34243. cl[0] = ((c0[0] * (splitYBy - row) + c2[0] * row) / splitYBy) | 0;
  34244. cl[1] = ((c0[1] * (splitYBy - row) + c2[1] * row) / splitYBy) | 0;
  34245. cl[2] = ((c0[2] * (splitYBy - row) + c2[2] * row) / splitYBy) | 0;
  34246. cr[0] = ((c1[0] * (splitYBy - row) + c3[0] * row) / splitYBy) | 0;
  34247. cr[1] = ((c1[1] * (splitYBy - row) + c3[1] * row) / splitYBy) | 0;
  34248. cr[2] = ((c1[2] * (splitYBy - row) + c3[2] * row) / splitYBy) | 0;
  34249. for (var col = 0; col <= splitXBy; col++, k++) {
  34250. if ((row === 0 || row === splitYBy) &&
  34251. (col === 0 || col === splitXBy)) {
  34252. continue;
  34253. }
  34254. var x = 0, y = 0;
  34255. var q = 0;
  34256. for (var i = 0; i <= 3; i++) {
  34257. for (var j = 0; j <= 3; j++, q++) {
  34258. var m = bRow[row][i] * bCol[col][j];
  34259. x += coords[pi[q]][0] * m;
  34260. y += coords[pi[q]][1] * m;
  34261. }
  34262. }
  34263. figureCoords[k] = coords.length;
  34264. coords.push([x, y]);
  34265. figureColors[k] = colors.length;
  34266. var newColor = new Uint8Array(3);
  34267. newColor[0] = ((cl[0] * (splitXBy - col) + cr[0] * col) / splitXBy) | 0;
  34268. newColor[1] = ((cl[1] * (splitXBy - col) + cr[1] * col) / splitXBy) | 0;
  34269. newColor[2] = ((cl[2] * (splitXBy - col) + cr[2] * col) / splitXBy) | 0;
  34270. colors.push(newColor);
  34271. }
  34272. }
  34273. figureCoords[0] = pi[0];
  34274. figureColors[0] = ci[0];
  34275. figureCoords[splitXBy] = pi[3];
  34276. figureColors[splitXBy] = ci[1];
  34277. figureCoords[verticesPerRow * splitYBy] = pi[12];
  34278. figureColors[verticesPerRow * splitYBy] = ci[2];
  34279. figureCoords[verticesPerRow * splitYBy + splitXBy] = pi[15];
  34280. figureColors[verticesPerRow * splitYBy + splitXBy] = ci[3];
  34281. mesh.figures[index] = {
  34282. type: 'lattice',
  34283. coords: figureCoords,
  34284. colors: figureColors,
  34285. verticesPerRow: verticesPerRow
  34286. };
  34287. }
  34288. function decodeType6Shading(mesh, reader) {
  34289. // A special case of Type 7. The p11, p12, p21, p22 automatically filled
  34290. var coords = mesh.coords;
  34291. var colors = mesh.colors;
  34292. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  34293. var cs = new Int32Array(4); // c00, c30, c03, c33
  34294. while (reader.hasData) {
  34295. var f = reader.readFlag();
  34296. assert(0 <= f && f <= 3, 'Unknown type6 flag');
  34297. var i, ii;
  34298. var pi = coords.length;
  34299. for (i = 0, ii = (f !== 0 ? 8 : 12); i < ii; i++) {
  34300. coords.push(reader.readCoordinate());
  34301. }
  34302. var ci = colors.length;
  34303. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  34304. colors.push(reader.readComponents());
  34305. }
  34306. var tmp1, tmp2, tmp3, tmp4;
  34307. switch (f) {
  34308. case 0:
  34309. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  34310. ps[ 8] = pi + 2; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 7;
  34311. ps[ 4] = pi + 1; /* calculated below */ ps[ 7] = pi + 8;
  34312. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  34313. cs[2] = ci + 1; cs[3] = ci + 2;
  34314. cs[0] = ci; cs[1] = ci + 3;
  34315. break;
  34316. case 1:
  34317. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  34318. ps[12] = tmp4; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  34319. ps[ 8] = tmp3; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 3;
  34320. ps[ 4] = tmp2; /* calculated below */ ps[ 7] = pi + 4;
  34321. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  34322. tmp1 = cs[2]; tmp2 = cs[3];
  34323. cs[2] = tmp2; cs[3] = ci;
  34324. cs[0] = tmp1; cs[1] = ci + 1;
  34325. break;
  34326. case 2:
  34327. tmp1 = ps[15];
  34328. tmp2 = ps[11];
  34329. ps[12] = ps[3]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  34330. ps[ 8] = ps[7]; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 3;
  34331. ps[ 4] = tmp2; /* calculated below */ ps[ 7] = pi + 4;
  34332. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  34333. tmp1 = cs[3];
  34334. cs[2] = cs[1]; cs[3] = ci;
  34335. cs[0] = tmp1; cs[1] = ci + 1;
  34336. break;
  34337. case 3:
  34338. ps[12] = ps[0]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  34339. ps[ 8] = ps[1]; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 3;
  34340. ps[ 4] = ps[2]; /* calculated below */ ps[ 7] = pi + 4;
  34341. ps[ 0] = ps[3]; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  34342. cs[2] = cs[0]; cs[3] = ci;
  34343. cs[0] = cs[1]; cs[1] = ci + 1;
  34344. break;
  34345. }
  34346. // set p11, p12, p21, p22
  34347. ps[5] = coords.length;
  34348. coords.push([
  34349. (-4 * coords[ps[0]][0] - coords[ps[15]][0] +
  34350. 6 * (coords[ps[4]][0] + coords[ps[1]][0]) -
  34351. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  34352. 3 * (coords[ps[13]][0] + coords[ps[7]][0])) / 9,
  34353. (-4 * coords[ps[0]][1] - coords[ps[15]][1] +
  34354. 6 * (coords[ps[4]][1] + coords[ps[1]][1]) -
  34355. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  34356. 3 * (coords[ps[13]][1] + coords[ps[7]][1])) / 9
  34357. ]);
  34358. ps[6] = coords.length;
  34359. coords.push([
  34360. (-4 * coords[ps[3]][0] - coords[ps[12]][0] +
  34361. 6 * (coords[ps[2]][0] + coords[ps[7]][0]) -
  34362. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  34363. 3 * (coords[ps[4]][0] + coords[ps[14]][0])) / 9,
  34364. (-4 * coords[ps[3]][1] - coords[ps[12]][1] +
  34365. 6 * (coords[ps[2]][1] + coords[ps[7]][1]) -
  34366. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  34367. 3 * (coords[ps[4]][1] + coords[ps[14]][1])) / 9
  34368. ]);
  34369. ps[9] = coords.length;
  34370. coords.push([
  34371. (-4 * coords[ps[12]][0] - coords[ps[3]][0] +
  34372. 6 * (coords[ps[8]][0] + coords[ps[13]][0]) -
  34373. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  34374. 3 * (coords[ps[11]][0] + coords[ps[1]][0])) / 9,
  34375. (-4 * coords[ps[12]][1] - coords[ps[3]][1] +
  34376. 6 * (coords[ps[8]][1] + coords[ps[13]][1]) -
  34377. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  34378. 3 * (coords[ps[11]][1] + coords[ps[1]][1])) / 9
  34379. ]);
  34380. ps[10] = coords.length;
  34381. coords.push([
  34382. (-4 * coords[ps[15]][0] - coords[ps[0]][0] +
  34383. 6 * (coords[ps[11]][0] + coords[ps[14]][0]) -
  34384. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  34385. 3 * (coords[ps[2]][0] + coords[ps[8]][0])) / 9,
  34386. (-4 * coords[ps[15]][1] - coords[ps[0]][1] +
  34387. 6 * (coords[ps[11]][1] + coords[ps[14]][1]) -
  34388. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  34389. 3 * (coords[ps[2]][1] + coords[ps[8]][1])) / 9
  34390. ]);
  34391. mesh.figures.push({
  34392. type: 'patch',
  34393. coords: new Int32Array(ps), // making copies of ps and cs
  34394. colors: new Int32Array(cs)
  34395. });
  34396. }
  34397. }
  34398. function decodeType7Shading(mesh, reader) {
  34399. var coords = mesh.coords;
  34400. var colors = mesh.colors;
  34401. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  34402. var cs = new Int32Array(4); // c00, c30, c03, c33
  34403. while (reader.hasData) {
  34404. var f = reader.readFlag();
  34405. assert(0 <= f && f <= 3, 'Unknown type7 flag');
  34406. var i, ii;
  34407. var pi = coords.length;
  34408. for (i = 0, ii = (f !== 0 ? 12 : 16); i < ii; i++) {
  34409. coords.push(reader.readCoordinate());
  34410. }
  34411. var ci = colors.length;
  34412. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  34413. colors.push(reader.readComponents());
  34414. }
  34415. var tmp1, tmp2, tmp3, tmp4;
  34416. switch (f) {
  34417. case 0:
  34418. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  34419. ps[ 8] = pi + 2; ps[ 9] = pi + 13; ps[10] = pi + 14; ps[11] = pi + 7;
  34420. ps[ 4] = pi + 1; ps[ 5] = pi + 12; ps[ 6] = pi + 15; ps[ 7] = pi + 8;
  34421. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  34422. cs[2] = ci + 1; cs[3] = ci + 2;
  34423. cs[0] = ci; cs[1] = ci + 3;
  34424. break;
  34425. case 1:
  34426. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  34427. ps[12] = tmp4; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  34428. ps[ 8] = tmp3; ps[ 9] = pi + 9; ps[10] = pi + 10; ps[11] = pi + 3;
  34429. ps[ 4] = tmp2; ps[ 5] = pi + 8; ps[ 6] = pi + 11; ps[ 7] = pi + 4;
  34430. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  34431. tmp1 = cs[2]; tmp2 = cs[3];
  34432. cs[2] = tmp2; cs[3] = ci;
  34433. cs[0] = tmp1; cs[1] = ci + 1;
  34434. break;
  34435. case 2:
  34436. tmp1 = ps[15];
  34437. tmp2 = ps[11];
  34438. ps[12] = ps[3]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  34439. ps[ 8] = ps[7]; ps[ 9] = pi + 9; ps[10] = pi + 10; ps[11] = pi + 3;
  34440. ps[ 4] = tmp2; ps[ 5] = pi + 8; ps[ 6] = pi + 11; ps[ 7] = pi + 4;
  34441. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  34442. tmp1 = cs[3];
  34443. cs[2] = cs[1]; cs[3] = ci;
  34444. cs[0] = tmp1; cs[1] = ci + 1;
  34445. break;
  34446. case 3:
  34447. ps[12] = ps[0]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  34448. ps[ 8] = ps[1]; ps[ 9] = pi + 9; ps[10] = pi + 10; ps[11] = pi + 3;
  34449. ps[ 4] = ps[2]; ps[ 5] = pi + 8; ps[ 6] = pi + 11; ps[ 7] = pi + 4;
  34450. ps[ 0] = ps[3]; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  34451. cs[2] = cs[0]; cs[3] = ci;
  34452. cs[0] = cs[1]; cs[1] = ci + 1;
  34453. break;
  34454. }
  34455. mesh.figures.push({
  34456. type: 'patch',
  34457. coords: new Int32Array(ps), // making copies of ps and cs
  34458. colors: new Int32Array(cs)
  34459. });
  34460. }
  34461. }
  34462. function updateBounds(mesh) {
  34463. var minX = mesh.coords[0][0], minY = mesh.coords[0][1],
  34464. maxX = minX, maxY = minY;
  34465. for (var i = 1, ii = mesh.coords.length; i < ii; i++) {
  34466. var x = mesh.coords[i][0], y = mesh.coords[i][1];
  34467. minX = minX > x ? x : minX;
  34468. minY = minY > y ? y : minY;
  34469. maxX = maxX < x ? x : maxX;
  34470. maxY = maxY < y ? y : maxY;
  34471. }
  34472. mesh.bounds = [minX, minY, maxX, maxY];
  34473. }
  34474. function packData(mesh) {
  34475. var i, ii, j, jj;
  34476. var coords = mesh.coords;
  34477. var coordsPacked = new Float32Array(coords.length * 2);
  34478. for (i = 0, j = 0, ii = coords.length; i < ii; i++) {
  34479. var xy = coords[i];
  34480. coordsPacked[j++] = xy[0];
  34481. coordsPacked[j++] = xy[1];
  34482. }
  34483. mesh.coords = coordsPacked;
  34484. var colors = mesh.colors;
  34485. var colorsPacked = new Uint8Array(colors.length * 3);
  34486. for (i = 0, j = 0, ii = colors.length; i < ii; i++) {
  34487. var c = colors[i];
  34488. colorsPacked[j++] = c[0];
  34489. colorsPacked[j++] = c[1];
  34490. colorsPacked[j++] = c[2];
  34491. }
  34492. mesh.colors = colorsPacked;
  34493. var figures = mesh.figures;
  34494. for (i = 0, ii = figures.length; i < ii; i++) {
  34495. var figure = figures[i], ps = figure.coords, cs = figure.colors;
  34496. for (j = 0, jj = ps.length; j < jj; j++) {
  34497. ps[j] *= 2;
  34498. cs[j] *= 3;
  34499. }
  34500. }
  34501. }
  34502. function Mesh(stream, matrix, xref, res) {
  34503. assert(isStream(stream), 'Mesh data is not a stream');
  34504. var dict = stream.dict;
  34505. this.matrix = matrix;
  34506. this.shadingType = dict.get('ShadingType');
  34507. this.type = 'Pattern';
  34508. this.bbox = dict.get('BBox');
  34509. var cs = dict.get('ColorSpace', 'CS');
  34510. cs = ColorSpace.parse(cs, xref, res);
  34511. this.cs = cs;
  34512. this.background = dict.has('Background') ?
  34513. cs.getRgb(dict.get('Background'), 0) : null;
  34514. var fnObj = dict.get('Function');
  34515. var fn = fnObj ? PDFFunction.parseArray(xref, fnObj) : null;
  34516. this.coords = [];
  34517. this.colors = [];
  34518. this.figures = [];
  34519. var decodeContext = {
  34520. bitsPerCoordinate: dict.get('BitsPerCoordinate'),
  34521. bitsPerComponent: dict.get('BitsPerComponent'),
  34522. bitsPerFlag: dict.get('BitsPerFlag'),
  34523. decode: dict.get('Decode'),
  34524. colorFn: fn,
  34525. colorSpace: cs,
  34526. numComps: fn ? 1 : cs.numComps
  34527. };
  34528. var reader = new MeshStreamReader(stream, decodeContext);
  34529. var patchMesh = false;
  34530. switch (this.shadingType) {
  34531. case ShadingType.FREE_FORM_MESH:
  34532. decodeType4Shading(this, reader);
  34533. break;
  34534. case ShadingType.LATTICE_FORM_MESH:
  34535. var verticesPerRow = dict.get('VerticesPerRow') | 0;
  34536. assert(verticesPerRow >= 2, 'Invalid VerticesPerRow');
  34537. decodeType5Shading(this, reader, verticesPerRow);
  34538. break;
  34539. case ShadingType.COONS_PATCH_MESH:
  34540. decodeType6Shading(this, reader);
  34541. patchMesh = true;
  34542. break;
  34543. case ShadingType.TENSOR_PATCH_MESH:
  34544. decodeType7Shading(this, reader);
  34545. patchMesh = true;
  34546. break;
  34547. default:
  34548. error('Unsupported mesh type.');
  34549. break;
  34550. }
  34551. if (patchMesh) {
  34552. // dirty bounds calculation for determining, how dense shall be triangles
  34553. updateBounds(this);
  34554. for (var i = 0, ii = this.figures.length; i < ii; i++) {
  34555. buildFigureFromPatch(this, i);
  34556. }
  34557. }
  34558. // calculate bounds
  34559. updateBounds(this);
  34560. packData(this);
  34561. }
  34562. Mesh.prototype = {
  34563. getIR: function Mesh_getIR() {
  34564. return ['Mesh', this.shadingType, this.coords, this.colors, this.figures,
  34565. this.bounds, this.matrix, this.bbox, this.background];
  34566. }
  34567. };
  34568. return Mesh;
  34569. })();
  34570. Shadings.Dummy = (function DummyClosure() {
  34571. function Dummy() {
  34572. this.type = 'Pattern';
  34573. }
  34574. Dummy.prototype = {
  34575. getIR: function Dummy_getIR() {
  34576. return ['Dummy'];
  34577. }
  34578. };
  34579. return Dummy;
  34580. })();
  34581. function getTilingPatternIR(operatorList, dict, args) {
  34582. var matrix = dict.get('Matrix');
  34583. var bbox = dict.get('BBox');
  34584. var xstep = dict.get('XStep');
  34585. var ystep = dict.get('YStep');
  34586. var paintType = dict.get('PaintType');
  34587. var tilingType = dict.get('TilingType');
  34588. return [
  34589. 'TilingPattern', args, operatorList, matrix, bbox, xstep, ystep,
  34590. paintType, tilingType
  34591. ];
  34592. }
  34593. exports.Pattern = Pattern;
  34594. exports.getTilingPatternIR = getTilingPatternIR;
  34595. }));
  34596. (function (root, factory) {
  34597. {
  34598. factory((root.pdfjsCoreEvaluator = {}), root.pdfjsSharedUtil,
  34599. root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreParser,
  34600. root.pdfjsCoreImage, root.pdfjsCoreColorSpace, root.pdfjsCoreMurmurHash3,
  34601. root.pdfjsCoreFonts, root.pdfjsCoreFunction, root.pdfjsCorePattern,
  34602. root.pdfjsCoreCMap, root.pdfjsCoreMetrics, root.pdfjsCoreBidi);
  34603. }
  34604. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreParser,
  34605. coreImage, coreColorSpace, coreMurmurHash3, coreFonts,
  34606. coreFunction, corePattern, coreCMap, coreMetrics, coreBidi) {
  34607. var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
  34608. var IDENTITY_MATRIX = sharedUtil.IDENTITY_MATRIX;
  34609. var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  34610. var ImageKind = sharedUtil.ImageKind;
  34611. var OPS = sharedUtil.OPS;
  34612. var TextRenderingMode = sharedUtil.TextRenderingMode;
  34613. var Util = sharedUtil.Util;
  34614. var assert = sharedUtil.assert;
  34615. var createPromiseCapability = sharedUtil.createPromiseCapability;
  34616. var error = sharedUtil.error;
  34617. var info = sharedUtil.info;
  34618. var isArray = sharedUtil.isArray;
  34619. var isNum = sharedUtil.isNum;
  34620. var isString = sharedUtil.isString;
  34621. var warn = sharedUtil.warn;
  34622. var Dict = corePrimitives.Dict;
  34623. var Name = corePrimitives.Name;
  34624. var isCmd = corePrimitives.isCmd;
  34625. var isDict = corePrimitives.isDict;
  34626. var isName = corePrimitives.isName;
  34627. var isRef = corePrimitives.isRef;
  34628. var isStream = corePrimitives.isStream;
  34629. var DecodeStream = coreStream.DecodeStream;
  34630. var JpegStream = coreStream.JpegStream;
  34631. var Lexer = coreParser.Lexer;
  34632. var Parser = coreParser.Parser;
  34633. var isEOF = coreParser.isEOF;
  34634. var PDFImage = coreImage.PDFImage;
  34635. var ColorSpace = coreColorSpace.ColorSpace;
  34636. var MurmurHash3_64 = coreMurmurHash3.MurmurHash3_64;
  34637. var Encodings = coreFonts.Encodings;
  34638. var ErrorFont = coreFonts.ErrorFont;
  34639. var FontFlags = coreFonts.FontFlags;
  34640. var Font = coreFonts.Font;
  34641. var IdentityToUnicodeMap = coreFonts.IdentityToUnicodeMap;
  34642. var NormalizedUnicodes = coreFonts.NormalizedUnicodes;
  34643. var ToUnicodeMap = coreFonts.ToUnicodeMap;
  34644. var getFontType = coreFonts.getFontType;
  34645. var reverseIfRtl = coreFonts.reverseIfRtl;
  34646. var serifFonts = coreFonts.serifFonts;
  34647. var symbolsFonts = coreFonts.symbolsFonts;
  34648. var stdFontMap = coreFonts.stdFontMap;
  34649. var isPDFFunction = coreFunction.isPDFFunction;
  34650. var PDFFunction = coreFunction.PDFFunction;
  34651. var Pattern = corePattern.Pattern;
  34652. var getTilingPatternIR = corePattern.getTilingPatternIR;
  34653. var CMapFactory = coreCMap.CMapFactory;
  34654. var IdentityCMap = coreCMap.IdentityCMap;
  34655. var Metrics = coreMetrics.Metrics;
  34656. var bidi = coreBidi.bidi;
  34657. var PartialEvaluator = (function PartialEvaluatorClosure() {
  34658. function PartialEvaluator(pdfManager, xref, handler, pageIndex,
  34659. uniquePrefix, idCounters, fontCache) {
  34660. this.pdfManager = pdfManager;
  34661. this.xref = xref;
  34662. this.handler = handler;
  34663. this.pageIndex = pageIndex;
  34664. this.uniquePrefix = uniquePrefix;
  34665. this.idCounters = idCounters;
  34666. this.fontCache = fontCache;
  34667. }
  34668. // Trying to minimize Date.now() usage and check every 100 time
  34669. var TIME_SLOT_DURATION_MS = 20;
  34670. var CHECK_TIME_EVERY = 100;
  34671. function TimeSlotManager() {
  34672. this.reset();
  34673. }
  34674. TimeSlotManager.prototype = {
  34675. check: function TimeSlotManager_check() {
  34676. if (++this.checked < CHECK_TIME_EVERY) {
  34677. return false;
  34678. }
  34679. this.checked = 0;
  34680. return this.endTime <= Date.now();
  34681. },
  34682. reset: function TimeSlotManager_reset() {
  34683. this.endTime = Date.now() + TIME_SLOT_DURATION_MS;
  34684. this.checked = 0;
  34685. }
  34686. };
  34687. var deferred = Promise.resolve();
  34688. var TILING_PATTERN = 1, SHADING_PATTERN = 2;
  34689. PartialEvaluator.prototype = {
  34690. hasBlendModes: function PartialEvaluator_hasBlendModes(resources) {
  34691. if (!isDict(resources)) {
  34692. return false;
  34693. }
  34694. var processed = Object.create(null);
  34695. if (resources.objId) {
  34696. processed[resources.objId] = true;
  34697. }
  34698. var nodes = [resources];
  34699. while (nodes.length) {
  34700. var key;
  34701. var node = nodes.shift();
  34702. // First check the current resources for blend modes.
  34703. var graphicStates = node.get('ExtGState');
  34704. if (isDict(graphicStates)) {
  34705. graphicStates = graphicStates.getAll();
  34706. for (key in graphicStates) {
  34707. var graphicState = graphicStates[key];
  34708. var bm = graphicState['BM'];
  34709. if (isName(bm) && bm.name !== 'Normal') {
  34710. return true;
  34711. }
  34712. }
  34713. }
  34714. // Descend into the XObjects to look for more resources and blend modes.
  34715. var xObjects = node.get('XObject');
  34716. if (!isDict(xObjects)) {
  34717. continue;
  34718. }
  34719. xObjects = xObjects.getAll();
  34720. for (key in xObjects) {
  34721. var xObject = xObjects[key];
  34722. if (!isStream(xObject)) {
  34723. continue;
  34724. }
  34725. if (xObject.dict.objId) {
  34726. if (processed[xObject.dict.objId]) {
  34727. // stream has objId and is processed already
  34728. continue;
  34729. }
  34730. processed[xObject.dict.objId] = true;
  34731. }
  34732. var xResources = xObject.dict.get('Resources');
  34733. // Checking objId to detect an infinite loop.
  34734. if (isDict(xResources) &&
  34735. (!xResources.objId || !processed[xResources.objId])) {
  34736. nodes.push(xResources);
  34737. if (xResources.objId) {
  34738. processed[xResources.objId] = true;
  34739. }
  34740. }
  34741. }
  34742. }
  34743. return false;
  34744. },
  34745. buildFormXObject: function PartialEvaluator_buildFormXObject(resources,
  34746. xobj, smask,
  34747. operatorList,
  34748. task,
  34749. initialState) {
  34750. var matrix = xobj.dict.getArray('Matrix');
  34751. var bbox = xobj.dict.getArray('BBox');
  34752. var group = xobj.dict.get('Group');
  34753. if (group) {
  34754. var groupOptions = {
  34755. matrix: matrix,
  34756. bbox: bbox,
  34757. smask: smask,
  34758. isolated: false,
  34759. knockout: false
  34760. };
  34761. var groupSubtype = group.get('S');
  34762. var colorSpace;
  34763. if (isName(groupSubtype) && groupSubtype.name === 'Transparency') {
  34764. groupOptions.isolated = (group.get('I') || false);
  34765. groupOptions.knockout = (group.get('K') || false);
  34766. colorSpace = (group.has('CS') ?
  34767. ColorSpace.parse(group.get('CS'), this.xref, resources) : null);
  34768. }
  34769. if (smask && smask.backdrop) {
  34770. colorSpace = colorSpace || ColorSpace.singletons.rgb;
  34771. smask.backdrop = colorSpace.getRgb(smask.backdrop, 0);
  34772. }
  34773. operatorList.addOp(OPS.beginGroup, [groupOptions]);
  34774. }
  34775. operatorList.addOp(OPS.paintFormXObjectBegin, [matrix, bbox]);
  34776. return this.getOperatorList(xobj, task,
  34777. (xobj.dict.get('Resources') || resources), operatorList, initialState).
  34778. then(function () {
  34779. operatorList.addOp(OPS.paintFormXObjectEnd, []);
  34780. if (group) {
  34781. operatorList.addOp(OPS.endGroup, [groupOptions]);
  34782. }
  34783. });
  34784. },
  34785. buildPaintImageXObject:
  34786. function PartialEvaluator_buildPaintImageXObject(resources, image,
  34787. inline, operatorList,
  34788. cacheKey, imageCache) {
  34789. var self = this;
  34790. var dict = image.dict;
  34791. var w = dict.get('Width', 'W');
  34792. var h = dict.get('Height', 'H');
  34793. if (!(w && isNum(w)) || !(h && isNum(h))) {
  34794. warn('Image dimensions are missing, or not numbers.');
  34795. return;
  34796. }
  34797. if (PDFJS.maxImageSize !== -1 && w * h > PDFJS.maxImageSize) {
  34798. warn('Image exceeded maximum allowed size and was removed.');
  34799. return;
  34800. }
  34801. var imageMask = (dict.get('ImageMask', 'IM') || false);
  34802. var imgData, args;
  34803. if (imageMask) {
  34804. // This depends on a tmpCanvas being filled with the
  34805. // current fillStyle, such that processing the pixel
  34806. // data can't be done here. Instead of creating a
  34807. // complete PDFImage, only read the information needed
  34808. // for later.
  34809. var width = dict.get('Width', 'W');
  34810. var height = dict.get('Height', 'H');
  34811. var bitStrideLength = (width + 7) >> 3;
  34812. var imgArray = image.getBytes(bitStrideLength * height);
  34813. var decode = dict.get('Decode', 'D');
  34814. var inverseDecode = (!!decode && decode[0] > 0);
  34815. imgData = PDFImage.createMask(imgArray, width, height,
  34816. image instanceof DecodeStream,
  34817. inverseDecode);
  34818. imgData.cached = true;
  34819. args = [imgData];
  34820. operatorList.addOp(OPS.paintImageMaskXObject, args);
  34821. if (cacheKey) {
  34822. imageCache[cacheKey] = {
  34823. fn: OPS.paintImageMaskXObject,
  34824. args: args
  34825. };
  34826. }
  34827. return;
  34828. }
  34829. var softMask = (dict.get('SMask', 'SM') || false);
  34830. var mask = (dict.get('Mask') || false);
  34831. var SMALL_IMAGE_DIMENSIONS = 200;
  34832. // Inlining small images into the queue as RGB data
  34833. if (inline && !softMask && !mask && !(image instanceof JpegStream) &&
  34834. (w + h) < SMALL_IMAGE_DIMENSIONS) {
  34835. var imageObj = new PDFImage(this.xref, resources, image,
  34836. inline, null, null);
  34837. // We force the use of RGBA_32BPP images here, because we can't handle
  34838. // any other kind.
  34839. imgData = imageObj.createImageData(/* forceRGBA = */ true);
  34840. operatorList.addOp(OPS.paintInlineImageXObject, [imgData]);
  34841. return;
  34842. }
  34843. // If there is no imageMask, create the PDFImage and a lot
  34844. // of image processing can be done here.
  34845. var uniquePrefix = (this.uniquePrefix || '');
  34846. var objId = 'img_' + uniquePrefix + (++this.idCounters.obj);
  34847. operatorList.addDependency(objId);
  34848. args = [objId, w, h];
  34849. if (!softMask && !mask && image instanceof JpegStream &&
  34850. image.isNativelySupported(this.xref, resources)) {
  34851. // These JPEGs don't need any more processing so we can just send it.
  34852. operatorList.addOp(OPS.paintJpegXObject, args);
  34853. this.handler.send('obj',
  34854. [objId, this.pageIndex, 'JpegStream', image.getIR()]);
  34855. return;
  34856. }
  34857. PDFImage.buildImage(self.handler, self.xref, resources, image, inline).
  34858. then(function(imageObj) {
  34859. var imgData = imageObj.createImageData(/* forceRGBA = */ false);
  34860. self.handler.send('obj', [objId, self.pageIndex, 'Image', imgData],
  34861. [imgData.data.buffer]);
  34862. }).then(undefined, function (reason) {
  34863. warn('Unable to decode image: ' + reason);
  34864. self.handler.send('obj', [objId, self.pageIndex, 'Image', null]);
  34865. });
  34866. operatorList.addOp(OPS.paintImageXObject, args);
  34867. if (cacheKey) {
  34868. imageCache[cacheKey] = {
  34869. fn: OPS.paintImageXObject,
  34870. args: args
  34871. };
  34872. }
  34873. },
  34874. handleSMask: function PartialEvaluator_handleSmask(smask, resources,
  34875. operatorList, task,
  34876. stateManager) {
  34877. var smaskContent = smask.get('G');
  34878. var smaskOptions = {
  34879. subtype: smask.get('S').name,
  34880. backdrop: smask.get('BC')
  34881. };
  34882. // The SMask might have a alpha/luminosity value transfer function --
  34883. // we will build a map of integer values in range 0..255 to be fast.
  34884. var transferObj = smask.get('TR');
  34885. if (isPDFFunction(transferObj)) {
  34886. var transferFn = PDFFunction.parse(this.xref, transferObj);
  34887. var transferMap = new Uint8Array(256);
  34888. var tmp = new Float32Array(1);
  34889. for (var i = 0; i < 255; i++) {
  34890. tmp[0] = i / 255;
  34891. transferFn(tmp, 0, tmp, 0);
  34892. transferMap[i] = (tmp[0] * 255) | 0;
  34893. }
  34894. smaskOptions.transferMap = transferMap;
  34895. }
  34896. return this.buildFormXObject(resources, smaskContent, smaskOptions,
  34897. operatorList, task, stateManager.state.clone());
  34898. },
  34899. handleTilingType:
  34900. function PartialEvaluator_handleTilingType(fn, args, resources,
  34901. pattern, patternDict,
  34902. operatorList, task) {
  34903. // Create an IR of the pattern code.
  34904. var tilingOpList = new OperatorList();
  34905. // Merge the available resources, to prevent issues when the patternDict
  34906. // is missing some /Resources entries (fixes issue6541.pdf).
  34907. var resourcesArray = [patternDict.get('Resources'), resources];
  34908. var patternResources = Dict.merge(this.xref, resourcesArray);
  34909. return this.getOperatorList(pattern, task, patternResources,
  34910. tilingOpList).then(function () {
  34911. // Add the dependencies to the parent operator list so they are
  34912. // resolved before sub operator list is executed synchronously.
  34913. operatorList.addDependencies(tilingOpList.dependencies);
  34914. operatorList.addOp(fn, getTilingPatternIR({
  34915. fnArray: tilingOpList.fnArray,
  34916. argsArray: tilingOpList.argsArray
  34917. }, patternDict, args));
  34918. });
  34919. },
  34920. handleSetFont:
  34921. function PartialEvaluator_handleSetFont(resources, fontArgs, fontRef,
  34922. operatorList, task, state) {
  34923. // TODO(mack): Not needed?
  34924. var fontName;
  34925. if (fontArgs) {
  34926. fontArgs = fontArgs.slice();
  34927. fontName = fontArgs[0].name;
  34928. }
  34929. var self = this;
  34930. return this.loadFont(fontName, fontRef, this.xref, resources).then(
  34931. function (translated) {
  34932. if (!translated.font.isType3Font) {
  34933. return translated;
  34934. }
  34935. return translated.loadType3Data(self, resources, operatorList, task).
  34936. then(function () {
  34937. return translated;
  34938. }, function (reason) {
  34939. // Error in the font data -- sending unsupported feature notification.
  34940. self.handler.send('UnsupportedFeature',
  34941. {featureId: UNSUPPORTED_FEATURES.font});
  34942. return new TranslatedFont('g_font_error',
  34943. new ErrorFont('Type3 font load error: ' + reason), translated.font);
  34944. });
  34945. }).then(function (translated) {
  34946. state.font = translated.font;
  34947. translated.send(self.handler);
  34948. return translated.loadedName;
  34949. });
  34950. },
  34951. handleText: function PartialEvaluator_handleText(chars, state) {
  34952. var font = state.font;
  34953. var glyphs = font.charsToGlyphs(chars);
  34954. var isAddToPathSet = !!(state.textRenderingMode &
  34955. TextRenderingMode.ADD_TO_PATH_FLAG);
  34956. if (font.data && (isAddToPathSet || PDFJS.disableFontFace)) {
  34957. var buildPath = function (fontChar) {
  34958. if (!font.renderer.hasBuiltPath(fontChar)) {
  34959. var path = font.renderer.getPathJs(fontChar);
  34960. this.handler.send('commonobj', [
  34961. font.loadedName + '_path_' + fontChar,
  34962. 'FontPath',
  34963. path
  34964. ]);
  34965. }
  34966. }.bind(this);
  34967. for (var i = 0, ii = glyphs.length; i < ii; i++) {
  34968. var glyph = glyphs[i];
  34969. buildPath(glyph.fontChar);
  34970. // If the glyph has an accent we need to build a path for its
  34971. // fontChar too, otherwise CanvasGraphics_paintChar will fail.
  34972. var accent = glyph.accent;
  34973. if (accent && accent.fontChar) {
  34974. buildPath(accent.fontChar);
  34975. }
  34976. }
  34977. }
  34978. return glyphs;
  34979. },
  34980. setGState: function PartialEvaluator_setGState(resources, gState,
  34981. operatorList, task,
  34982. xref, stateManager) {
  34983. // This array holds the converted/processed state data.
  34984. var gStateObj = [];
  34985. var gStateMap = gState.map;
  34986. var self = this;
  34987. var promise = Promise.resolve();
  34988. for (var key in gStateMap) {
  34989. var value = gStateMap[key];
  34990. switch (key) {
  34991. case 'Type':
  34992. break;
  34993. case 'LW':
  34994. case 'LC':
  34995. case 'LJ':
  34996. case 'ML':
  34997. case 'D':
  34998. case 'RI':
  34999. case 'FL':
  35000. case 'CA':
  35001. case 'ca':
  35002. gStateObj.push([key, value]);
  35003. break;
  35004. case 'Font':
  35005. promise = promise.then(function () {
  35006. return self.handleSetFont(resources, null, value[0], operatorList,
  35007. task, stateManager.state).
  35008. then(function (loadedName) {
  35009. operatorList.addDependency(loadedName);
  35010. gStateObj.push([key, [loadedName, value[1]]]);
  35011. });
  35012. });
  35013. break;
  35014. case 'BM':
  35015. gStateObj.push([key, value]);
  35016. break;
  35017. case 'SMask':
  35018. if (isName(value) && value.name === 'None') {
  35019. gStateObj.push([key, false]);
  35020. break;
  35021. }
  35022. var dict = xref.fetchIfRef(value);
  35023. if (isDict(dict)) {
  35024. promise = promise.then(function () {
  35025. return self.handleSMask(dict, resources, operatorList,
  35026. task, stateManager);
  35027. });
  35028. gStateObj.push([key, true]);
  35029. } else {
  35030. warn('Unsupported SMask type');
  35031. }
  35032. break;
  35033. // Only generate info log messages for the following since
  35034. // they are unlikely to have a big impact on the rendering.
  35035. case 'OP':
  35036. case 'op':
  35037. case 'OPM':
  35038. case 'BG':
  35039. case 'BG2':
  35040. case 'UCR':
  35041. case 'UCR2':
  35042. case 'TR':
  35043. case 'TR2':
  35044. case 'HT':
  35045. case 'SM':
  35046. case 'SA':
  35047. case 'AIS':
  35048. case 'TK':
  35049. // TODO implement these operators.
  35050. info('graphic state operator ' + key);
  35051. break;
  35052. default:
  35053. info('Unknown graphic state operator ' + key);
  35054. break;
  35055. }
  35056. }
  35057. return promise.then(function () {
  35058. if (gStateObj.length >= 0) {
  35059. operatorList.addOp(OPS.setGState, [gStateObj]);
  35060. }
  35061. });
  35062. },
  35063. loadFont: function PartialEvaluator_loadFont(fontName, font, xref,
  35064. resources) {
  35065. function errorFont() {
  35066. return Promise.resolve(new TranslatedFont('g_font_error',
  35067. new ErrorFont('Font ' + fontName + ' is not available'), font));
  35068. }
  35069. var fontRef;
  35070. if (font) { // Loading by ref.
  35071. assert(isRef(font));
  35072. fontRef = font;
  35073. } else { // Loading by name.
  35074. var fontRes = resources.get('Font');
  35075. if (fontRes) {
  35076. fontRef = fontRes.getRaw(fontName);
  35077. } else {
  35078. warn('fontRes not available');
  35079. return errorFont();
  35080. }
  35081. }
  35082. if (!fontRef) {
  35083. warn('fontRef not available');
  35084. return errorFont();
  35085. }
  35086. if (this.fontCache.has(fontRef)) {
  35087. return this.fontCache.get(fontRef);
  35088. }
  35089. font = xref.fetchIfRef(fontRef);
  35090. if (!isDict(font)) {
  35091. return errorFont();
  35092. }
  35093. // We are holding font.translated references just for fontRef that are not
  35094. // dictionaries (Dict). See explanation below.
  35095. if (font.translated) {
  35096. return font.translated;
  35097. }
  35098. var fontCapability = createPromiseCapability();
  35099. var preEvaluatedFont = this.preEvaluateFont(font, xref);
  35100. var descriptor = preEvaluatedFont.descriptor;
  35101. var fontID = fontRef.num + '_' + fontRef.gen;
  35102. if (isDict(descriptor)) {
  35103. if (!descriptor.fontAliases) {
  35104. descriptor.fontAliases = Object.create(null);
  35105. }
  35106. var fontAliases = descriptor.fontAliases;
  35107. var hash = preEvaluatedFont.hash;
  35108. if (fontAliases[hash]) {
  35109. var aliasFontRef = fontAliases[hash].aliasRef;
  35110. if (aliasFontRef && this.fontCache.has(aliasFontRef)) {
  35111. this.fontCache.putAlias(fontRef, aliasFontRef);
  35112. return this.fontCache.get(fontRef);
  35113. }
  35114. }
  35115. if (!fontAliases[hash]) {
  35116. fontAliases[hash] = {
  35117. fontID: Font.getFontID()
  35118. };
  35119. }
  35120. fontAliases[hash].aliasRef = fontRef;
  35121. fontID = fontAliases[hash].fontID;
  35122. }
  35123. // Workaround for bad PDF generators that don't reference fonts
  35124. // properly, i.e. by not using an object identifier.
  35125. // Check if the fontRef is a Dict (as opposed to a standard object),
  35126. // in which case we don't cache the font and instead reference it by
  35127. // fontName in font.loadedName below.
  35128. var fontRefIsDict = isDict(fontRef);
  35129. if (!fontRefIsDict) {
  35130. this.fontCache.put(fontRef, fontCapability.promise);
  35131. }
  35132. // Keep track of each font we translated so the caller can
  35133. // load them asynchronously before calling display on a page.
  35134. font.loadedName = 'g_' + this.pdfManager.docId + '_f' + (fontRefIsDict ?
  35135. fontName.replace(/\W/g, '') : fontID);
  35136. font.translated = fontCapability.promise;
  35137. // TODO move promises into translate font
  35138. var translatedPromise;
  35139. try {
  35140. translatedPromise = Promise.resolve(
  35141. this.translateFont(preEvaluatedFont, xref));
  35142. } catch (e) {
  35143. translatedPromise = Promise.reject(e);
  35144. }
  35145. var self = this;
  35146. translatedPromise.then(function (translatedFont) {
  35147. if (translatedFont.fontType !== undefined) {
  35148. var xrefFontStats = xref.stats.fontTypes;
  35149. xrefFontStats[translatedFont.fontType] = true;
  35150. }
  35151. fontCapability.resolve(new TranslatedFont(font.loadedName,
  35152. translatedFont, font));
  35153. }, function (reason) {
  35154. // TODO fontCapability.reject?
  35155. // Error in the font data -- sending unsupported feature notification.
  35156. self.handler.send('UnsupportedFeature',
  35157. {featureId: UNSUPPORTED_FEATURES.font});
  35158. try {
  35159. // error, but it's still nice to have font type reported
  35160. var descriptor = preEvaluatedFont.descriptor;
  35161. var fontFile3 = descriptor && descriptor.get('FontFile3');
  35162. var subtype = fontFile3 && fontFile3.get('Subtype');
  35163. var fontType = getFontType(preEvaluatedFont.type,
  35164. subtype && subtype.name);
  35165. var xrefFontStats = xref.stats.fontTypes;
  35166. xrefFontStats[fontType] = true;
  35167. } catch (ex) { }
  35168. fontCapability.resolve(new TranslatedFont(font.loadedName,
  35169. new ErrorFont(reason instanceof Error ? reason.message : reason),
  35170. font));
  35171. });
  35172. return fontCapability.promise;
  35173. },
  35174. buildPath: function PartialEvaluator_buildPath(operatorList, fn, args) {
  35175. var lastIndex = operatorList.length - 1;
  35176. if (!args) {
  35177. args = [];
  35178. }
  35179. if (lastIndex < 0 ||
  35180. operatorList.fnArray[lastIndex] !== OPS.constructPath) {
  35181. operatorList.addOp(OPS.constructPath, [[fn], args]);
  35182. } else {
  35183. var opArgs = operatorList.argsArray[lastIndex];
  35184. opArgs[0].push(fn);
  35185. Array.prototype.push.apply(opArgs[1], args);
  35186. }
  35187. },
  35188. handleColorN: function PartialEvaluator_handleColorN(operatorList, fn, args,
  35189. cs, patterns, resources, task, xref) {
  35190. // compile tiling patterns
  35191. var patternName = args[args.length - 1];
  35192. // SCN/scn applies patterns along with normal colors
  35193. var pattern;
  35194. if (isName(patternName) &&
  35195. (pattern = patterns.get(patternName.name))) {
  35196. var dict = (isStream(pattern) ? pattern.dict : pattern);
  35197. var typeNum = dict.get('PatternType');
  35198. if (typeNum === TILING_PATTERN) {
  35199. var color = cs.base ? cs.base.getRgb(args, 0) : null;
  35200. return this.handleTilingType(fn, color, resources, pattern,
  35201. dict, operatorList, task);
  35202. } else if (typeNum === SHADING_PATTERN) {
  35203. var shading = dict.get('Shading');
  35204. var matrix = dict.get('Matrix');
  35205. pattern = Pattern.parseShading(shading, matrix, xref, resources,
  35206. this.handler);
  35207. operatorList.addOp(fn, pattern.getIR());
  35208. return Promise.resolve();
  35209. } else {
  35210. return Promise.reject('Unknown PatternType: ' + typeNum);
  35211. }
  35212. }
  35213. // TODO shall we fail here?
  35214. operatorList.addOp(fn, args);
  35215. return Promise.resolve();
  35216. },
  35217. getOperatorList: function PartialEvaluator_getOperatorList(stream,
  35218. task,
  35219. resources,
  35220. operatorList,
  35221. initialState) {
  35222. var self = this;
  35223. var xref = this.xref;
  35224. var imageCache = {};
  35225. assert(operatorList);
  35226. resources = (resources || Dict.empty);
  35227. var xobjs = (resources.get('XObject') || Dict.empty);
  35228. var patterns = (resources.get('Pattern') || Dict.empty);
  35229. var stateManager = new StateManager(initialState || new EvalState());
  35230. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  35231. var timeSlotManager = new TimeSlotManager();
  35232. return new Promise(function next(resolve, reject) {
  35233. task.ensureNotTerminated();
  35234. timeSlotManager.reset();
  35235. var stop, operation = {}, i, ii, cs;
  35236. while (!(stop = timeSlotManager.check())) {
  35237. // The arguments parsed by read() are used beyond this loop, so we
  35238. // cannot reuse the same array on each iteration. Therefore we pass
  35239. // in |null| as the initial value (see the comment on
  35240. // EvaluatorPreprocessor_read() for why).
  35241. operation.args = null;
  35242. if (!(preprocessor.read(operation))) {
  35243. break;
  35244. }
  35245. var args = operation.args;
  35246. var fn = operation.fn;
  35247. switch (fn | 0) {
  35248. case OPS.paintXObject:
  35249. if (args[0].code) {
  35250. break;
  35251. }
  35252. // eagerly compile XForm objects
  35253. var name = args[0].name;
  35254. if (!name) {
  35255. warn('XObject must be referred to by name.');
  35256. continue;
  35257. }
  35258. if (imageCache[name] !== undefined) {
  35259. operatorList.addOp(imageCache[name].fn, imageCache[name].args);
  35260. args = null;
  35261. continue;
  35262. }
  35263. var xobj = xobjs.get(name);
  35264. if (xobj) {
  35265. assert(isStream(xobj), 'XObject should be a stream');
  35266. var type = xobj.dict.get('Subtype');
  35267. assert(isName(type),
  35268. 'XObject should have a Name subtype');
  35269. if (type.name === 'Form') {
  35270. stateManager.save();
  35271. return self.buildFormXObject(resources, xobj, null,
  35272. operatorList, task,
  35273. stateManager.state.clone()).
  35274. then(function () {
  35275. stateManager.restore();
  35276. next(resolve, reject);
  35277. }, reject);
  35278. } else if (type.name === 'Image') {
  35279. self.buildPaintImageXObject(resources, xobj, false,
  35280. operatorList, name, imageCache);
  35281. args = null;
  35282. continue;
  35283. } else if (type.name === 'PS') {
  35284. // PostScript XObjects are unused when viewing documents.
  35285. // See section 4.7.1 of Adobe's PDF reference.
  35286. info('Ignored XObject subtype PS');
  35287. continue;
  35288. } else {
  35289. error('Unhandled XObject subtype ' + type.name);
  35290. }
  35291. }
  35292. break;
  35293. case OPS.setFont:
  35294. var fontSize = args[1];
  35295. // eagerly collect all fonts
  35296. return self.handleSetFont(resources, args, null, operatorList,
  35297. task, stateManager.state).
  35298. then(function (loadedName) {
  35299. operatorList.addDependency(loadedName);
  35300. operatorList.addOp(OPS.setFont, [loadedName, fontSize]);
  35301. next(resolve, reject);
  35302. }, reject);
  35303. case OPS.endInlineImage:
  35304. var cacheKey = args[0].cacheKey;
  35305. if (cacheKey) {
  35306. var cacheEntry = imageCache[cacheKey];
  35307. if (cacheEntry !== undefined) {
  35308. operatorList.addOp(cacheEntry.fn, cacheEntry.args);
  35309. args = null;
  35310. continue;
  35311. }
  35312. }
  35313. self.buildPaintImageXObject(resources, args[0], true,
  35314. operatorList, cacheKey, imageCache);
  35315. args = null;
  35316. continue;
  35317. case OPS.showText:
  35318. args[0] = self.handleText(args[0], stateManager.state);
  35319. break;
  35320. case OPS.showSpacedText:
  35321. var arr = args[0];
  35322. var combinedGlyphs = [];
  35323. var arrLength = arr.length;
  35324. var state = stateManager.state;
  35325. for (i = 0; i < arrLength; ++i) {
  35326. var arrItem = arr[i];
  35327. if (isString(arrItem)) {
  35328. Array.prototype.push.apply(combinedGlyphs,
  35329. self.handleText(arrItem, state));
  35330. } else if (isNum(arrItem)) {
  35331. combinedGlyphs.push(arrItem);
  35332. }
  35333. }
  35334. args[0] = combinedGlyphs;
  35335. fn = OPS.showText;
  35336. break;
  35337. case OPS.nextLineShowText:
  35338. operatorList.addOp(OPS.nextLine);
  35339. args[0] = self.handleText(args[0], stateManager.state);
  35340. fn = OPS.showText;
  35341. break;
  35342. case OPS.nextLineSetSpacingShowText:
  35343. operatorList.addOp(OPS.nextLine);
  35344. operatorList.addOp(OPS.setWordSpacing, [args.shift()]);
  35345. operatorList.addOp(OPS.setCharSpacing, [args.shift()]);
  35346. args[0] = self.handleText(args[0], stateManager.state);
  35347. fn = OPS.showText;
  35348. break;
  35349. case OPS.setTextRenderingMode:
  35350. stateManager.state.textRenderingMode = args[0];
  35351. break;
  35352. case OPS.setFillColorSpace:
  35353. stateManager.state.fillColorSpace =
  35354. ColorSpace.parse(args[0], xref, resources);
  35355. continue;
  35356. case OPS.setStrokeColorSpace:
  35357. stateManager.state.strokeColorSpace =
  35358. ColorSpace.parse(args[0], xref, resources);
  35359. continue;
  35360. case OPS.setFillColor:
  35361. cs = stateManager.state.fillColorSpace;
  35362. args = cs.getRgb(args, 0);
  35363. fn = OPS.setFillRGBColor;
  35364. break;
  35365. case OPS.setStrokeColor:
  35366. cs = stateManager.state.strokeColorSpace;
  35367. args = cs.getRgb(args, 0);
  35368. fn = OPS.setStrokeRGBColor;
  35369. break;
  35370. case OPS.setFillGray:
  35371. stateManager.state.fillColorSpace = ColorSpace.singletons.gray;
  35372. args = ColorSpace.singletons.gray.getRgb(args, 0);
  35373. fn = OPS.setFillRGBColor;
  35374. break;
  35375. case OPS.setStrokeGray:
  35376. stateManager.state.strokeColorSpace = ColorSpace.singletons.gray;
  35377. args = ColorSpace.singletons.gray.getRgb(args, 0);
  35378. fn = OPS.setStrokeRGBColor;
  35379. break;
  35380. case OPS.setFillCMYKColor:
  35381. stateManager.state.fillColorSpace = ColorSpace.singletons.cmyk;
  35382. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  35383. fn = OPS.setFillRGBColor;
  35384. break;
  35385. case OPS.setStrokeCMYKColor:
  35386. stateManager.state.strokeColorSpace = ColorSpace.singletons.cmyk;
  35387. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  35388. fn = OPS.setStrokeRGBColor;
  35389. break;
  35390. case OPS.setFillRGBColor:
  35391. stateManager.state.fillColorSpace = ColorSpace.singletons.rgb;
  35392. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  35393. break;
  35394. case OPS.setStrokeRGBColor:
  35395. stateManager.state.strokeColorSpace = ColorSpace.singletons.rgb;
  35396. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  35397. break;
  35398. case OPS.setFillColorN:
  35399. cs = stateManager.state.fillColorSpace;
  35400. if (cs.name === 'Pattern') {
  35401. return self.handleColorN(operatorList, OPS.setFillColorN,
  35402. args, cs, patterns, resources, task, xref).then(function() {
  35403. next(resolve, reject);
  35404. }, reject);
  35405. }
  35406. args = cs.getRgb(args, 0);
  35407. fn = OPS.setFillRGBColor;
  35408. break;
  35409. case OPS.setStrokeColorN:
  35410. cs = stateManager.state.strokeColorSpace;
  35411. if (cs.name === 'Pattern') {
  35412. return self.handleColorN(operatorList, OPS.setStrokeColorN,
  35413. args, cs, patterns, resources, task, xref).then(function() {
  35414. next(resolve, reject);
  35415. }, reject);
  35416. }
  35417. args = cs.getRgb(args, 0);
  35418. fn = OPS.setStrokeRGBColor;
  35419. break;
  35420. case OPS.shadingFill:
  35421. var shadingRes = resources.get('Shading');
  35422. if (!shadingRes) {
  35423. error('No shading resource found');
  35424. }
  35425. var shading = shadingRes.get(args[0].name);
  35426. if (!shading) {
  35427. error('No shading object found');
  35428. }
  35429. var shadingFill = Pattern.parseShading(shading, null, xref,
  35430. resources, self.handler);
  35431. var patternIR = shadingFill.getIR();
  35432. args = [patternIR];
  35433. fn = OPS.shadingFill;
  35434. break;
  35435. case OPS.setGState:
  35436. var dictName = args[0];
  35437. var extGState = resources.get('ExtGState');
  35438. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  35439. break;
  35440. }
  35441. var gState = extGState.get(dictName.name);
  35442. return self.setGState(resources, gState, operatorList, task,
  35443. xref, stateManager).then(function() {
  35444. next(resolve, reject);
  35445. }, reject);
  35446. case OPS.moveTo:
  35447. case OPS.lineTo:
  35448. case OPS.curveTo:
  35449. case OPS.curveTo2:
  35450. case OPS.curveTo3:
  35451. case OPS.closePath:
  35452. self.buildPath(operatorList, fn, args);
  35453. continue;
  35454. case OPS.rectangle:
  35455. self.buildPath(operatorList, fn, args);
  35456. continue;
  35457. case OPS.markPoint:
  35458. case OPS.markPointProps:
  35459. case OPS.beginMarkedContent:
  35460. case OPS.beginMarkedContentProps:
  35461. case OPS.endMarkedContent:
  35462. case OPS.beginCompat:
  35463. case OPS.endCompat:
  35464. // Ignore operators where the corresponding handlers are known to
  35465. // be no-op in CanvasGraphics (display/canvas.js). This prevents
  35466. // serialization errors and is also a bit more efficient.
  35467. // We could also try to serialize all objects in a general way,
  35468. // e.g. as done in https://github.com/mozilla/pdf.js/pull/6266,
  35469. // but doing so is meaningless without knowing the semantics.
  35470. continue;
  35471. default:
  35472. // Note: Let's hope that the ignored operator does not have any
  35473. // non-serializable arguments, otherwise postMessage will throw
  35474. // "An object could not be cloned.".
  35475. }
  35476. operatorList.addOp(fn, args);
  35477. }
  35478. if (stop) {
  35479. deferred.then(function () {
  35480. next(resolve, reject);
  35481. }, reject);
  35482. return;
  35483. }
  35484. // Some PDFs don't close all restores inside object/form.
  35485. // Closing those for them.
  35486. for (i = 0, ii = preprocessor.savedStatesDepth; i < ii; i++) {
  35487. operatorList.addOp(OPS.restore, []);
  35488. }
  35489. resolve();
  35490. });
  35491. },
  35492. getTextContent:
  35493. function PartialEvaluator_getTextContent(stream, task, resources,
  35494. stateManager,
  35495. normalizeWhitespace) {
  35496. stateManager = (stateManager || new StateManager(new TextState()));
  35497. var WhitespaceRegexp = /\s/g;
  35498. var textContent = {
  35499. items: [],
  35500. styles: Object.create(null)
  35501. };
  35502. var textContentItem = {
  35503. initialized: false,
  35504. str: [],
  35505. width: 0,
  35506. height: 0,
  35507. vertical: false,
  35508. lastAdvanceWidth: 0,
  35509. lastAdvanceHeight: 0,
  35510. textAdvanceScale: 0,
  35511. spaceWidth: 0,
  35512. fakeSpaceMin: Infinity,
  35513. fakeMultiSpaceMin: Infinity,
  35514. fakeMultiSpaceMax: -0,
  35515. textRunBreakAllowed: false,
  35516. transform: null,
  35517. fontName: null
  35518. };
  35519. var SPACE_FACTOR = 0.3;
  35520. var MULTI_SPACE_FACTOR = 1.5;
  35521. var MULTI_SPACE_FACTOR_MAX = 4;
  35522. var self = this;
  35523. var xref = this.xref;
  35524. resources = (xref.fetchIfRef(resources) || Dict.empty);
  35525. // The xobj is parsed iff it's needed, e.g. if there is a `DO` cmd.
  35526. var xobjs = null;
  35527. var xobjsCache = {};
  35528. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  35529. var textState;
  35530. function ensureTextContentItem() {
  35531. if (textContentItem.initialized) {
  35532. return textContentItem;
  35533. }
  35534. var font = textState.font;
  35535. if (!(font.loadedName in textContent.styles)) {
  35536. textContent.styles[font.loadedName] = {
  35537. fontFamily: font.fallbackName,
  35538. ascent: font.ascent,
  35539. descent: font.descent,
  35540. vertical: font.vertical
  35541. };
  35542. }
  35543. textContentItem.fontName = font.loadedName;
  35544. // 9.4.4 Text Space Details
  35545. var tsm = [textState.fontSize * textState.textHScale, 0,
  35546. 0, textState.fontSize,
  35547. 0, textState.textRise];
  35548. if (font.isType3Font &&
  35549. textState.fontMatrix !== FONT_IDENTITY_MATRIX &&
  35550. textState.fontSize === 1) {
  35551. var glyphHeight = font.bbox[3] - font.bbox[1];
  35552. if (glyphHeight > 0) {
  35553. glyphHeight = glyphHeight * textState.fontMatrix[3];
  35554. tsm[3] *= glyphHeight;
  35555. }
  35556. }
  35557. var trm = Util.transform(textState.ctm,
  35558. Util.transform(textState.textMatrix, tsm));
  35559. textContentItem.transform = trm;
  35560. if (!font.vertical) {
  35561. textContentItem.width = 0;
  35562. textContentItem.height = Math.sqrt(trm[2] * trm[2] + trm[3] * trm[3]);
  35563. textContentItem.vertical = false;
  35564. } else {
  35565. textContentItem.width = Math.sqrt(trm[0] * trm[0] + trm[1] * trm[1]);
  35566. textContentItem.height = 0;
  35567. textContentItem.vertical = true;
  35568. }
  35569. var a = textState.textLineMatrix[0];
  35570. var b = textState.textLineMatrix[1];
  35571. var scaleLineX = Math.sqrt(a * a + b * b);
  35572. a = textState.ctm[0];
  35573. b = textState.ctm[1];
  35574. var scaleCtmX = Math.sqrt(a * a + b * b);
  35575. textContentItem.textAdvanceScale = scaleCtmX * scaleLineX;
  35576. textContentItem.lastAdvanceWidth = 0;
  35577. textContentItem.lastAdvanceHeight = 0;
  35578. var spaceWidth = font.spaceWidth / 1000 * textState.fontSize;
  35579. if (spaceWidth) {
  35580. textContentItem.spaceWidth = spaceWidth;
  35581. textContentItem.fakeSpaceMin = spaceWidth * SPACE_FACTOR;
  35582. textContentItem.fakeMultiSpaceMin = spaceWidth * MULTI_SPACE_FACTOR;
  35583. textContentItem.fakeMultiSpaceMax =
  35584. spaceWidth * MULTI_SPACE_FACTOR_MAX;
  35585. // It's okay for monospace fonts to fake as much space as needed.
  35586. textContentItem.textRunBreakAllowed = !font.isMonospace;
  35587. } else {
  35588. textContentItem.spaceWidth = 0;
  35589. textContentItem.fakeSpaceMin = Infinity;
  35590. textContentItem.fakeMultiSpaceMin = Infinity;
  35591. textContentItem.fakeMultiSpaceMax = 0;
  35592. textContentItem.textRunBreakAllowed = false;
  35593. }
  35594. textContentItem.initialized = true;
  35595. return textContentItem;
  35596. }
  35597. function replaceWhitespace(str) {
  35598. // Replaces all whitespaces with standard spaces (0x20), to avoid
  35599. // alignment issues between the textLayer and the canvas if the text
  35600. // contains e.g. tabs (fixes issue6612.pdf).
  35601. var i = 0, ii = str.length, code;
  35602. while (i < ii && (code = str.charCodeAt(i)) >= 0x20 && code <= 0x7F) {
  35603. i++;
  35604. }
  35605. return (i < ii ? str.replace(WhitespaceRegexp, ' ') : str);
  35606. }
  35607. function runBidiTransform(textChunk) {
  35608. var str = textChunk.str.join('');
  35609. var bidiResult = PDFJS.bidi(str, -1, textChunk.vertical);
  35610. return {
  35611. str: (normalizeWhitespace ? replaceWhitespace(bidiResult.str) :
  35612. bidiResult.str),
  35613. dir: bidiResult.dir,
  35614. width: textChunk.width,
  35615. height: textChunk.height,
  35616. transform: textChunk.transform,
  35617. fontName: textChunk.fontName
  35618. };
  35619. }
  35620. function handleSetFont(fontName, fontRef) {
  35621. return self.loadFont(fontName, fontRef, xref, resources).
  35622. then(function (translated) {
  35623. textState.font = translated.font;
  35624. textState.fontMatrix = translated.font.fontMatrix ||
  35625. FONT_IDENTITY_MATRIX;
  35626. });
  35627. }
  35628. function buildTextContentItem(chars) {
  35629. var font = textState.font;
  35630. var textChunk = ensureTextContentItem();
  35631. var width = 0;
  35632. var height = 0;
  35633. var glyphs = font.charsToGlyphs(chars);
  35634. var defaultVMetrics = font.defaultVMetrics;
  35635. for (var i = 0; i < glyphs.length; i++) {
  35636. var glyph = glyphs[i];
  35637. var vMetricX = null;
  35638. var vMetricY = null;
  35639. var glyphWidth = null;
  35640. if (font.vertical) {
  35641. if (glyph.vmetric) {
  35642. glyphWidth = glyph.vmetric[0];
  35643. vMetricX = glyph.vmetric[1];
  35644. vMetricY = glyph.vmetric[2];
  35645. } else {
  35646. glyphWidth = glyph.width;
  35647. vMetricX = glyph.width * 0.5;
  35648. vMetricY = defaultVMetrics[2];
  35649. }
  35650. } else {
  35651. glyphWidth = glyph.width;
  35652. }
  35653. var glyphUnicode = glyph.unicode;
  35654. if (NormalizedUnicodes[glyphUnicode] !== undefined) {
  35655. glyphUnicode = NormalizedUnicodes[glyphUnicode];
  35656. }
  35657. glyphUnicode = reverseIfRtl(glyphUnicode);
  35658. // The following will calculate the x and y of the individual glyphs.
  35659. // if (font.vertical) {
  35660. // tsm[4] -= vMetricX * Math.abs(textState.fontSize) *
  35661. // textState.fontMatrix[0];
  35662. // tsm[5] -= vMetricY * textState.fontSize *
  35663. // textState.fontMatrix[0];
  35664. // }
  35665. // var trm = Util.transform(textState.textMatrix, tsm);
  35666. // var pt = Util.applyTransform([trm[4], trm[5]], textState.ctm);
  35667. // var x = pt[0];
  35668. // var y = pt[1];
  35669. var charSpacing = textState.charSpacing;
  35670. if (glyph.isSpace) {
  35671. var wordSpacing = textState.wordSpacing;
  35672. charSpacing += wordSpacing;
  35673. if (wordSpacing > 0) {
  35674. addFakeSpaces(wordSpacing, textChunk.str);
  35675. }
  35676. }
  35677. var tx = 0;
  35678. var ty = 0;
  35679. if (!font.vertical) {
  35680. var w0 = glyphWidth * textState.fontMatrix[0];
  35681. tx = (w0 * textState.fontSize + charSpacing) *
  35682. textState.textHScale;
  35683. width += tx;
  35684. } else {
  35685. var w1 = glyphWidth * textState.fontMatrix[0];
  35686. ty = w1 * textState.fontSize + charSpacing;
  35687. height += ty;
  35688. }
  35689. textState.translateTextMatrix(tx, ty);
  35690. textChunk.str.push(glyphUnicode);
  35691. }
  35692. if (!font.vertical) {
  35693. textChunk.lastAdvanceWidth = width;
  35694. textChunk.width += width * textChunk.textAdvanceScale;
  35695. } else {
  35696. textChunk.lastAdvanceHeight = height;
  35697. textChunk.height += Math.abs(height * textChunk.textAdvanceScale);
  35698. }
  35699. return textChunk;
  35700. }
  35701. function addFakeSpaces(width, strBuf) {
  35702. if (width < textContentItem.fakeSpaceMin) {
  35703. return;
  35704. }
  35705. if (width < textContentItem.fakeMultiSpaceMin) {
  35706. strBuf.push(' ');
  35707. return;
  35708. }
  35709. var fakeSpaces = Math.round(width / textContentItem.spaceWidth);
  35710. while (fakeSpaces-- > 0) {
  35711. strBuf.push(' ');
  35712. }
  35713. }
  35714. function flushTextContentItem() {
  35715. if (!textContentItem.initialized) {
  35716. return;
  35717. }
  35718. textContent.items.push(runBidiTransform(textContentItem));
  35719. textContentItem.initialized = false;
  35720. textContentItem.str.length = 0;
  35721. }
  35722. var timeSlotManager = new TimeSlotManager();
  35723. return new Promise(function next(resolve, reject) {
  35724. task.ensureNotTerminated();
  35725. timeSlotManager.reset();
  35726. var stop, operation = {}, args = [];
  35727. while (!(stop = timeSlotManager.check())) {
  35728. // The arguments parsed by read() are not used beyond this loop, so
  35729. // we can reuse the same array on every iteration, thus avoiding
  35730. // unnecessary allocations.
  35731. args.length = 0;
  35732. operation.args = args;
  35733. if (!(preprocessor.read(operation))) {
  35734. break;
  35735. }
  35736. textState = stateManager.state;
  35737. var fn = operation.fn;
  35738. args = operation.args;
  35739. var advance;
  35740. switch (fn | 0) {
  35741. case OPS.setFont:
  35742. flushTextContentItem();
  35743. textState.fontSize = args[1];
  35744. return handleSetFont(args[0].name).then(function() {
  35745. next(resolve, reject);
  35746. }, reject);
  35747. case OPS.setTextRise:
  35748. flushTextContentItem();
  35749. textState.textRise = args[0];
  35750. break;
  35751. case OPS.setHScale:
  35752. flushTextContentItem();
  35753. textState.textHScale = args[0] / 100;
  35754. break;
  35755. case OPS.setLeading:
  35756. flushTextContentItem();
  35757. textState.leading = args[0];
  35758. break;
  35759. case OPS.moveText:
  35760. // Optimization to treat same line movement as advance
  35761. var isSameTextLine = !textState.font ? false :
  35762. ((textState.font.vertical ? args[0] : args[1]) === 0);
  35763. advance = args[0] - args[1];
  35764. if (isSameTextLine && textContentItem.initialized &&
  35765. advance > 0 &&
  35766. advance <= textContentItem.fakeMultiSpaceMax) {
  35767. textState.translateTextLineMatrix(args[0], args[1]);
  35768. textContentItem.width +=
  35769. (args[0] - textContentItem.lastAdvanceWidth);
  35770. textContentItem.height +=
  35771. (args[1] - textContentItem.lastAdvanceHeight);
  35772. var diff = (args[0] - textContentItem.lastAdvanceWidth) -
  35773. (args[1] - textContentItem.lastAdvanceHeight);
  35774. addFakeSpaces(diff, textContentItem.str);
  35775. break;
  35776. }
  35777. flushTextContentItem();
  35778. textState.translateTextLineMatrix(args[0], args[1]);
  35779. textState.textMatrix = textState.textLineMatrix.slice();
  35780. break;
  35781. case OPS.setLeadingMoveText:
  35782. flushTextContentItem();
  35783. textState.leading = -args[1];
  35784. textState.translateTextLineMatrix(args[0], args[1]);
  35785. textState.textMatrix = textState.textLineMatrix.slice();
  35786. break;
  35787. case OPS.nextLine:
  35788. flushTextContentItem();
  35789. textState.carriageReturn();
  35790. break;
  35791. case OPS.setTextMatrix:
  35792. flushTextContentItem();
  35793. textState.setTextMatrix(args[0], args[1], args[2], args[3],
  35794. args[4], args[5]);
  35795. textState.setTextLineMatrix(args[0], args[1], args[2], args[3],
  35796. args[4], args[5]);
  35797. break;
  35798. case OPS.setCharSpacing:
  35799. textState.charSpacing = args[0];
  35800. break;
  35801. case OPS.setWordSpacing:
  35802. textState.wordSpacing = args[0];
  35803. break;
  35804. case OPS.beginText:
  35805. flushTextContentItem();
  35806. textState.textMatrix = IDENTITY_MATRIX.slice();
  35807. textState.textLineMatrix = IDENTITY_MATRIX.slice();
  35808. break;
  35809. case OPS.showSpacedText:
  35810. var items = args[0];
  35811. var offset;
  35812. for (var j = 0, jj = items.length; j < jj; j++) {
  35813. if (typeof items[j] === 'string') {
  35814. buildTextContentItem(items[j]);
  35815. } else {
  35816. ensureTextContentItem();
  35817. // PDF Specification 5.3.2 states:
  35818. // The number is expressed in thousandths of a unit of text
  35819. // space.
  35820. // This amount is subtracted from the current horizontal or
  35821. // vertical coordinate, depending on the writing mode.
  35822. // In the default coordinate system, a positive adjustment
  35823. // has the effect of moving the next glyph painted either to
  35824. // the left or down by the given amount.
  35825. advance = items[j] * textState.fontSize / 1000;
  35826. var breakTextRun = false;
  35827. if (textState.font.vertical) {
  35828. offset = advance *
  35829. (textState.textHScale * textState.textMatrix[2] +
  35830. textState.textMatrix[3]);
  35831. textState.translateTextMatrix(0, advance);
  35832. breakTextRun = textContentItem.textRunBreakAllowed &&
  35833. advance > textContentItem.fakeMultiSpaceMax;
  35834. if (!breakTextRun) {
  35835. // Value needs to be added to height to paint down.
  35836. textContentItem.height += offset;
  35837. }
  35838. } else {
  35839. advance = -advance;
  35840. offset = advance * (
  35841. textState.textHScale * textState.textMatrix[0] +
  35842. textState.textMatrix[1]);
  35843. textState.translateTextMatrix(advance, 0);
  35844. breakTextRun = textContentItem.textRunBreakAllowed &&
  35845. advance > textContentItem.fakeMultiSpaceMax;
  35846. if (!breakTextRun) {
  35847. // Value needs to be subtracted from width to paint left.
  35848. textContentItem.width += offset;
  35849. }
  35850. }
  35851. if (breakTextRun) {
  35852. flushTextContentItem();
  35853. } else if (advance > 0) {
  35854. addFakeSpaces(advance, textContentItem.str);
  35855. }
  35856. }
  35857. }
  35858. break;
  35859. case OPS.showText:
  35860. buildTextContentItem(args[0]);
  35861. break;
  35862. case OPS.nextLineShowText:
  35863. flushTextContentItem();
  35864. textState.carriageReturn();
  35865. buildTextContentItem(args[0]);
  35866. break;
  35867. case OPS.nextLineSetSpacingShowText:
  35868. flushTextContentItem();
  35869. textState.wordSpacing = args[0];
  35870. textState.charSpacing = args[1];
  35871. textState.carriageReturn();
  35872. buildTextContentItem(args[2]);
  35873. break;
  35874. case OPS.paintXObject:
  35875. flushTextContentItem();
  35876. if (args[0].code) {
  35877. break;
  35878. }
  35879. if (!xobjs) {
  35880. xobjs = (resources.get('XObject') || Dict.empty);
  35881. }
  35882. var name = args[0].name;
  35883. if (xobjsCache.key === name) {
  35884. if (xobjsCache.texts) {
  35885. Util.appendToArray(textContent.items, xobjsCache.texts.items);
  35886. Util.extendObj(textContent.styles, xobjsCache.texts.styles);
  35887. }
  35888. break;
  35889. }
  35890. var xobj = xobjs.get(name);
  35891. if (!xobj) {
  35892. break;
  35893. }
  35894. assert(isStream(xobj), 'XObject should be a stream');
  35895. var type = xobj.dict.get('Subtype');
  35896. assert(isName(type),
  35897. 'XObject should have a Name subtype');
  35898. if ('Form' !== type.name) {
  35899. xobjsCache.key = name;
  35900. xobjsCache.texts = null;
  35901. break;
  35902. }
  35903. stateManager.save();
  35904. var matrix = xobj.dict.get('Matrix');
  35905. if (isArray(matrix) && matrix.length === 6) {
  35906. stateManager.transform(matrix);
  35907. }
  35908. return self.getTextContent(xobj, task,
  35909. xobj.dict.get('Resources') || resources, stateManager,
  35910. normalizeWhitespace).then(function (formTextContent) {
  35911. Util.appendToArray(textContent.items, formTextContent.items);
  35912. Util.extendObj(textContent.styles, formTextContent.styles);
  35913. stateManager.restore();
  35914. xobjsCache.key = name;
  35915. xobjsCache.texts = formTextContent;
  35916. next(resolve, reject);
  35917. }, reject);
  35918. case OPS.setGState:
  35919. flushTextContentItem();
  35920. var dictName = args[0];
  35921. var extGState = resources.get('ExtGState');
  35922. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  35923. break;
  35924. }
  35925. var gsStateMap = extGState.get(dictName.name);
  35926. var gsStateFont = null;
  35927. for (var key in gsStateMap) {
  35928. if (key === 'Font') {
  35929. assert(!gsStateFont);
  35930. gsStateFont = gsStateMap[key];
  35931. }
  35932. }
  35933. if (gsStateFont) {
  35934. textState.fontSize = gsStateFont[1];
  35935. return handleSetFont(gsStateFont[0]).then(function() {
  35936. next(resolve, reject);
  35937. }, reject);
  35938. }
  35939. break;
  35940. } // switch
  35941. } // while
  35942. if (stop) {
  35943. deferred.then(function () {
  35944. next(resolve, reject);
  35945. }, reject);
  35946. return;
  35947. }
  35948. flushTextContentItem();
  35949. resolve(textContent);
  35950. });
  35951. },
  35952. extractDataStructures: function
  35953. partialEvaluatorExtractDataStructures(dict, baseDict,
  35954. xref, properties) {
  35955. // 9.10.2
  35956. var toUnicode = (dict.get('ToUnicode') || baseDict.get('ToUnicode'));
  35957. if (toUnicode) {
  35958. properties.toUnicode = this.readToUnicode(toUnicode);
  35959. }
  35960. if (properties.composite) {
  35961. // CIDSystemInfo helps to match CID to glyphs
  35962. var cidSystemInfo = dict.get('CIDSystemInfo');
  35963. if (isDict(cidSystemInfo)) {
  35964. properties.cidSystemInfo = {
  35965. registry: cidSystemInfo.get('Registry'),
  35966. ordering: cidSystemInfo.get('Ordering'),
  35967. supplement: cidSystemInfo.get('Supplement')
  35968. };
  35969. }
  35970. var cidToGidMap = dict.get('CIDToGIDMap');
  35971. if (isStream(cidToGidMap)) {
  35972. properties.cidToGidMap = this.readCidToGidMap(cidToGidMap);
  35973. }
  35974. }
  35975. // Based on 9.6.6 of the spec the encoding can come from multiple places
  35976. // and depends on the font type. The base encoding and differences are
  35977. // read here, but the encoding that is actually used is chosen during
  35978. // glyph mapping in the font.
  35979. // TODO: Loading the built in encoding in the font would allow the
  35980. // differences to be merged in here not require us to hold on to it.
  35981. var differences = [];
  35982. var baseEncodingName = null;
  35983. var encoding;
  35984. if (dict.has('Encoding')) {
  35985. encoding = dict.get('Encoding');
  35986. if (isDict(encoding)) {
  35987. baseEncodingName = encoding.get('BaseEncoding');
  35988. baseEncodingName = (isName(baseEncodingName) ?
  35989. baseEncodingName.name : null);
  35990. // Load the differences between the base and original
  35991. if (encoding.has('Differences')) {
  35992. var diffEncoding = encoding.get('Differences');
  35993. var index = 0;
  35994. for (var j = 0, jj = diffEncoding.length; j < jj; j++) {
  35995. var data = diffEncoding[j];
  35996. if (isNum(data)) {
  35997. index = data;
  35998. } else if (isName(data)) {
  35999. differences[index++] = data.name;
  36000. } else if (isRef(data)) {
  36001. diffEncoding[j--] = xref.fetch(data);
  36002. continue;
  36003. } else {
  36004. error('Invalid entry in \'Differences\' array: ' + data);
  36005. }
  36006. }
  36007. }
  36008. } else if (isName(encoding)) {
  36009. baseEncodingName = encoding.name;
  36010. } else {
  36011. error('Encoding is not a Name nor a Dict');
  36012. }
  36013. // According to table 114 if the encoding is a named encoding it must be
  36014. // one of these predefined encodings.
  36015. if ((baseEncodingName !== 'MacRomanEncoding' &&
  36016. baseEncodingName !== 'MacExpertEncoding' &&
  36017. baseEncodingName !== 'WinAnsiEncoding')) {
  36018. baseEncodingName = null;
  36019. }
  36020. }
  36021. if (baseEncodingName) {
  36022. properties.defaultEncoding = Encodings[baseEncodingName].slice();
  36023. } else {
  36024. encoding = (properties.type === 'TrueType' ?
  36025. Encodings.WinAnsiEncoding : Encodings.StandardEncoding);
  36026. // The Symbolic attribute can be misused for regular fonts
  36027. // Heuristic: we have to check if the font is a standard one also
  36028. if (!!(properties.flags & FontFlags.Symbolic)) {
  36029. encoding = Encodings.MacRomanEncoding;
  36030. if (!properties.file) {
  36031. if (/Symbol/i.test(properties.name)) {
  36032. encoding = Encodings.SymbolSetEncoding;
  36033. } else if (/Dingbats/i.test(properties.name)) {
  36034. encoding = Encodings.ZapfDingbatsEncoding;
  36035. }
  36036. }
  36037. }
  36038. properties.defaultEncoding = encoding;
  36039. }
  36040. properties.differences = differences;
  36041. properties.baseEncodingName = baseEncodingName;
  36042. properties.dict = dict;
  36043. },
  36044. readToUnicode: function PartialEvaluator_readToUnicode(toUnicode) {
  36045. var cmap, cmapObj = toUnicode;
  36046. if (isName(cmapObj)) {
  36047. cmap = CMapFactory.create(cmapObj,
  36048. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  36049. if (cmap instanceof IdentityCMap) {
  36050. return new IdentityToUnicodeMap(0, 0xFFFF);
  36051. }
  36052. return new ToUnicodeMap(cmap.getMap());
  36053. } else if (isStream(cmapObj)) {
  36054. cmap = CMapFactory.create(cmapObj,
  36055. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  36056. if (cmap instanceof IdentityCMap) {
  36057. return new IdentityToUnicodeMap(0, 0xFFFF);
  36058. }
  36059. var map = new Array(cmap.length);
  36060. // Convert UTF-16BE
  36061. // NOTE: cmap can be a sparse array, so use forEach instead of for(;;)
  36062. // to iterate over all keys.
  36063. cmap.forEach(function(charCode, token) {
  36064. var str = [];
  36065. for (var k = 0; k < token.length; k += 2) {
  36066. var w1 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  36067. if ((w1 & 0xF800) !== 0xD800) { // w1 < 0xD800 || w1 > 0xDFFF
  36068. str.push(w1);
  36069. continue;
  36070. }
  36071. k += 2;
  36072. var w2 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  36073. str.push(((w1 & 0x3ff) << 10) + (w2 & 0x3ff) + 0x10000);
  36074. }
  36075. map[charCode] = String.fromCharCode.apply(String, str);
  36076. });
  36077. return new ToUnicodeMap(map);
  36078. }
  36079. return null;
  36080. },
  36081. readCidToGidMap: function PartialEvaluator_readCidToGidMap(cidToGidStream) {
  36082. // Extract the encoding from the CIDToGIDMap
  36083. var glyphsData = cidToGidStream.getBytes();
  36084. // Set encoding 0 to later verify the font has an encoding
  36085. var result = [];
  36086. for (var j = 0, jj = glyphsData.length; j < jj; j++) {
  36087. var glyphID = (glyphsData[j++] << 8) | glyphsData[j];
  36088. if (glyphID === 0) {
  36089. continue;
  36090. }
  36091. var code = j >> 1;
  36092. result[code] = glyphID;
  36093. }
  36094. return result;
  36095. },
  36096. extractWidths: function PartialEvaluator_extractWidths(dict, xref,
  36097. descriptor,
  36098. properties) {
  36099. var glyphsWidths = [];
  36100. var defaultWidth = 0;
  36101. var glyphsVMetrics = [];
  36102. var defaultVMetrics;
  36103. var i, ii, j, jj, start, code, widths;
  36104. if (properties.composite) {
  36105. defaultWidth = dict.get('DW') || 1000;
  36106. widths = dict.get('W');
  36107. if (widths) {
  36108. for (i = 0, ii = widths.length; i < ii; i++) {
  36109. start = widths[i++];
  36110. code = xref.fetchIfRef(widths[i]);
  36111. if (isArray(code)) {
  36112. for (j = 0, jj = code.length; j < jj; j++) {
  36113. glyphsWidths[start++] = code[j];
  36114. }
  36115. } else {
  36116. var width = widths[++i];
  36117. for (j = start; j <= code; j++) {
  36118. glyphsWidths[j] = width;
  36119. }
  36120. }
  36121. }
  36122. }
  36123. if (properties.vertical) {
  36124. var vmetrics = (dict.get('DW2') || [880, -1000]);
  36125. defaultVMetrics = [vmetrics[1], defaultWidth * 0.5, vmetrics[0]];
  36126. vmetrics = dict.get('W2');
  36127. if (vmetrics) {
  36128. for (i = 0, ii = vmetrics.length; i < ii; i++) {
  36129. start = vmetrics[i++];
  36130. code = xref.fetchIfRef(vmetrics[i]);
  36131. if (isArray(code)) {
  36132. for (j = 0, jj = code.length; j < jj; j++) {
  36133. glyphsVMetrics[start++] = [code[j++], code[j++], code[j]];
  36134. }
  36135. } else {
  36136. var vmetric = [vmetrics[++i], vmetrics[++i], vmetrics[++i]];
  36137. for (j = start; j <= code; j++) {
  36138. glyphsVMetrics[j] = vmetric;
  36139. }
  36140. }
  36141. }
  36142. }
  36143. }
  36144. } else {
  36145. var firstChar = properties.firstChar;
  36146. widths = dict.get('Widths');
  36147. if (widths) {
  36148. j = firstChar;
  36149. for (i = 0, ii = widths.length; i < ii; i++) {
  36150. glyphsWidths[j++] = widths[i];
  36151. }
  36152. defaultWidth = (parseFloat(descriptor.get('MissingWidth')) || 0);
  36153. } else {
  36154. // Trying get the BaseFont metrics (see comment above).
  36155. var baseFontName = dict.get('BaseFont');
  36156. if (isName(baseFontName)) {
  36157. var metrics = this.getBaseFontMetrics(baseFontName.name);
  36158. glyphsWidths = this.buildCharCodeToWidth(metrics.widths,
  36159. properties);
  36160. defaultWidth = metrics.defaultWidth;
  36161. }
  36162. }
  36163. }
  36164. // Heuristic: detection of monospace font by checking all non-zero widths
  36165. var isMonospace = true;
  36166. var firstWidth = defaultWidth;
  36167. for (var glyph in glyphsWidths) {
  36168. var glyphWidth = glyphsWidths[glyph];
  36169. if (!glyphWidth) {
  36170. continue;
  36171. }
  36172. if (!firstWidth) {
  36173. firstWidth = glyphWidth;
  36174. continue;
  36175. }
  36176. if (firstWidth !== glyphWidth) {
  36177. isMonospace = false;
  36178. break;
  36179. }
  36180. }
  36181. if (isMonospace) {
  36182. properties.flags |= FontFlags.FixedPitch;
  36183. }
  36184. properties.defaultWidth = defaultWidth;
  36185. properties.widths = glyphsWidths;
  36186. properties.defaultVMetrics = defaultVMetrics;
  36187. properties.vmetrics = glyphsVMetrics;
  36188. },
  36189. isSerifFont: function PartialEvaluator_isSerifFont(baseFontName) {
  36190. // Simulating descriptor flags attribute
  36191. var fontNameWoStyle = baseFontName.split('-')[0];
  36192. return (fontNameWoStyle in serifFonts) ||
  36193. (fontNameWoStyle.search(/serif/gi) !== -1);
  36194. },
  36195. getBaseFontMetrics: function PartialEvaluator_getBaseFontMetrics(name) {
  36196. var defaultWidth = 0;
  36197. var widths = [];
  36198. var monospace = false;
  36199. var lookupName = (stdFontMap[name] || name);
  36200. if (!(lookupName in Metrics)) {
  36201. // Use default fonts for looking up font metrics if the passed
  36202. // font is not a base font
  36203. if (this.isSerifFont(name)) {
  36204. lookupName = 'Times-Roman';
  36205. } else {
  36206. lookupName = 'Helvetica';
  36207. }
  36208. }
  36209. var glyphWidths = Metrics[lookupName];
  36210. if (isNum(glyphWidths)) {
  36211. defaultWidth = glyphWidths;
  36212. monospace = true;
  36213. } else {
  36214. widths = glyphWidths;
  36215. }
  36216. return {
  36217. defaultWidth: defaultWidth,
  36218. monospace: monospace,
  36219. widths: widths
  36220. };
  36221. },
  36222. buildCharCodeToWidth:
  36223. function PartialEvaluator_bulildCharCodeToWidth(widthsByGlyphName,
  36224. properties) {
  36225. var widths = Object.create(null);
  36226. var differences = properties.differences;
  36227. var encoding = properties.defaultEncoding;
  36228. for (var charCode = 0; charCode < 256; charCode++) {
  36229. if (charCode in differences &&
  36230. widthsByGlyphName[differences[charCode]]) {
  36231. widths[charCode] = widthsByGlyphName[differences[charCode]];
  36232. continue;
  36233. }
  36234. if (charCode in encoding && widthsByGlyphName[encoding[charCode]]) {
  36235. widths[charCode] = widthsByGlyphName[encoding[charCode]];
  36236. continue;
  36237. }
  36238. }
  36239. return widths;
  36240. },
  36241. preEvaluateFont: function PartialEvaluator_preEvaluateFont(dict, xref) {
  36242. var baseDict = dict;
  36243. var type = dict.get('Subtype');
  36244. assert(isName(type), 'invalid font Subtype');
  36245. var composite = false;
  36246. var uint8array;
  36247. if (type.name === 'Type0') {
  36248. // If font is a composite
  36249. // - get the descendant font
  36250. // - set the type according to the descendant font
  36251. // - get the FontDescriptor from the descendant font
  36252. var df = dict.get('DescendantFonts');
  36253. if (!df) {
  36254. error('Descendant fonts are not specified');
  36255. }
  36256. dict = (isArray(df) ? xref.fetchIfRef(df[0]) : df);
  36257. type = dict.get('Subtype');
  36258. assert(isName(type), 'invalid font Subtype');
  36259. composite = true;
  36260. }
  36261. var descriptor = dict.get('FontDescriptor');
  36262. if (descriptor) {
  36263. var hash = new MurmurHash3_64();
  36264. var encoding = baseDict.getRaw('Encoding');
  36265. if (isName(encoding)) {
  36266. hash.update(encoding.name);
  36267. } else if (isRef(encoding)) {
  36268. hash.update(encoding.num + '_' + encoding.gen);
  36269. } else if (isDict(encoding)) {
  36270. var keys = encoding.getKeys();
  36271. for (var i = 0, ii = keys.length; i < ii; i++) {
  36272. var entry = encoding.getRaw(keys[i]);
  36273. if (isName(entry)) {
  36274. hash.update(entry.name);
  36275. } else if (isRef(entry)) {
  36276. hash.update(entry.num + '_' + entry.gen);
  36277. } else if (isArray(entry)) { // 'Differences' entry.
  36278. // Ideally we should check the contents of the array, but to avoid
  36279. // parsing it here and then again in |extractDataStructures|,
  36280. // we only use the array length for now (fixes bug1157493.pdf).
  36281. hash.update(entry.length.toString());
  36282. }
  36283. }
  36284. }
  36285. var toUnicode = dict.get('ToUnicode') || baseDict.get('ToUnicode');
  36286. if (isStream(toUnicode)) {
  36287. var stream = toUnicode.str || toUnicode;
  36288. uint8array = stream.buffer ?
  36289. new Uint8Array(stream.buffer.buffer, 0, stream.bufferLength) :
  36290. new Uint8Array(stream.bytes.buffer,
  36291. stream.start, stream.end - stream.start);
  36292. hash.update(uint8array);
  36293. } else if (isName(toUnicode)) {
  36294. hash.update(toUnicode.name);
  36295. }
  36296. var widths = dict.get('Widths') || baseDict.get('Widths');
  36297. if (widths) {
  36298. uint8array = new Uint8Array(new Uint32Array(widths).buffer);
  36299. hash.update(uint8array);
  36300. }
  36301. }
  36302. return {
  36303. descriptor: descriptor,
  36304. dict: dict,
  36305. baseDict: baseDict,
  36306. composite: composite,
  36307. type: type.name,
  36308. hash: hash ? hash.hexdigest() : ''
  36309. };
  36310. },
  36311. translateFont: function PartialEvaluator_translateFont(preEvaluatedFont,
  36312. xref) {
  36313. var baseDict = preEvaluatedFont.baseDict;
  36314. var dict = preEvaluatedFont.dict;
  36315. var composite = preEvaluatedFont.composite;
  36316. var descriptor = preEvaluatedFont.descriptor;
  36317. var type = preEvaluatedFont.type;
  36318. var maxCharIndex = (composite ? 0xFFFF : 0xFF);
  36319. var properties;
  36320. if (!descriptor) {
  36321. if (type === 'Type3') {
  36322. // FontDescriptor is only required for Type3 fonts when the document
  36323. // is a tagged pdf. Create a barbebones one to get by.
  36324. descriptor = new Dict(null);
  36325. descriptor.set('FontName', Name.get(type));
  36326. descriptor.set('FontBBox', dict.get('FontBBox'));
  36327. } else {
  36328. // Before PDF 1.5 if the font was one of the base 14 fonts, having a
  36329. // FontDescriptor was not required.
  36330. // This case is here for compatibility.
  36331. var baseFontName = dict.get('BaseFont');
  36332. if (!isName(baseFontName)) {
  36333. error('Base font is not specified');
  36334. }
  36335. // Using base font name as a font name.
  36336. baseFontName = baseFontName.name.replace(/[,_]/g, '-');
  36337. var metrics = this.getBaseFontMetrics(baseFontName);
  36338. // Simulating descriptor flags attribute
  36339. var fontNameWoStyle = baseFontName.split('-')[0];
  36340. var flags =
  36341. (this.isSerifFont(fontNameWoStyle) ? FontFlags.Serif : 0) |
  36342. (metrics.monospace ? FontFlags.FixedPitch : 0) |
  36343. (symbolsFonts[fontNameWoStyle] ? FontFlags.Symbolic :
  36344. FontFlags.Nonsymbolic);
  36345. properties = {
  36346. type: type,
  36347. name: baseFontName,
  36348. widths: metrics.widths,
  36349. defaultWidth: metrics.defaultWidth,
  36350. flags: flags,
  36351. firstChar: 0,
  36352. lastChar: maxCharIndex
  36353. };
  36354. this.extractDataStructures(dict, dict, xref, properties);
  36355. properties.widths = this.buildCharCodeToWidth(metrics.widths,
  36356. properties);
  36357. return new Font(baseFontName, null, properties);
  36358. }
  36359. }
  36360. // According to the spec if 'FontDescriptor' is declared, 'FirstChar',
  36361. // 'LastChar' and 'Widths' should exist too, but some PDF encoders seem
  36362. // to ignore this rule when a variant of a standart font is used.
  36363. // TODO Fill the width array depending on which of the base font this is
  36364. // a variant.
  36365. var firstChar = (dict.get('FirstChar') || 0);
  36366. var lastChar = (dict.get('LastChar') || maxCharIndex);
  36367. var fontName = descriptor.get('FontName');
  36368. var baseFont = dict.get('BaseFont');
  36369. // Some bad PDFs have a string as the font name.
  36370. if (isString(fontName)) {
  36371. fontName = Name.get(fontName);
  36372. }
  36373. if (isString(baseFont)) {
  36374. baseFont = Name.get(baseFont);
  36375. }
  36376. if (type !== 'Type3') {
  36377. var fontNameStr = fontName && fontName.name;
  36378. var baseFontStr = baseFont && baseFont.name;
  36379. if (fontNameStr !== baseFontStr) {
  36380. info('The FontDescriptor\'s FontName is "' + fontNameStr +
  36381. '" but should be the same as the Font\'s BaseFont "' +
  36382. baseFontStr + '"');
  36383. // Workaround for cases where e.g. fontNameStr = 'Arial' and
  36384. // baseFontStr = 'Arial,Bold' (needed when no font file is embedded).
  36385. if (fontNameStr && baseFontStr &&
  36386. baseFontStr.indexOf(fontNameStr) === 0) {
  36387. fontName = baseFont;
  36388. }
  36389. }
  36390. }
  36391. fontName = (fontName || baseFont);
  36392. assert(isName(fontName), 'invalid font name');
  36393. var fontFile = descriptor.get('FontFile', 'FontFile2', 'FontFile3');
  36394. if (fontFile) {
  36395. if (fontFile.dict) {
  36396. var subtype = fontFile.dict.get('Subtype');
  36397. if (subtype) {
  36398. subtype = subtype.name;
  36399. }
  36400. var length1 = fontFile.dict.get('Length1');
  36401. var length2 = fontFile.dict.get('Length2');
  36402. }
  36403. }
  36404. properties = {
  36405. type: type,
  36406. name: fontName.name,
  36407. subtype: subtype,
  36408. file: fontFile,
  36409. length1: length1,
  36410. length2: length2,
  36411. loadedName: baseDict.loadedName,
  36412. composite: composite,
  36413. wideChars: composite,
  36414. fixedPitch: false,
  36415. fontMatrix: (dict.get('FontMatrix') || FONT_IDENTITY_MATRIX),
  36416. firstChar: firstChar || 0,
  36417. lastChar: (lastChar || maxCharIndex),
  36418. bbox: descriptor.get('FontBBox'),
  36419. ascent: descriptor.get('Ascent'),
  36420. descent: descriptor.get('Descent'),
  36421. xHeight: descriptor.get('XHeight'),
  36422. capHeight: descriptor.get('CapHeight'),
  36423. flags: descriptor.get('Flags'),
  36424. italicAngle: descriptor.get('ItalicAngle'),
  36425. coded: false
  36426. };
  36427. if (composite) {
  36428. var cidEncoding = baseDict.get('Encoding');
  36429. if (isName(cidEncoding)) {
  36430. properties.cidEncoding = cidEncoding.name;
  36431. }
  36432. properties.cMap = CMapFactory.create(cidEncoding,
  36433. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  36434. properties.vertical = properties.cMap.vertical;
  36435. }
  36436. this.extractDataStructures(dict, baseDict, xref, properties);
  36437. this.extractWidths(dict, xref, descriptor, properties);
  36438. if (type === 'Type3') {
  36439. properties.isType3Font = true;
  36440. }
  36441. return new Font(fontName.name, fontFile, properties);
  36442. }
  36443. };
  36444. return PartialEvaluator;
  36445. })();
  36446. var TranslatedFont = (function TranslatedFontClosure() {
  36447. function TranslatedFont(loadedName, font, dict) {
  36448. this.loadedName = loadedName;
  36449. this.font = font;
  36450. this.dict = dict;
  36451. this.type3Loaded = null;
  36452. this.sent = false;
  36453. }
  36454. TranslatedFont.prototype = {
  36455. send: function (handler) {
  36456. if (this.sent) {
  36457. return;
  36458. }
  36459. var fontData = this.font.exportData();
  36460. handler.send('commonobj', [
  36461. this.loadedName,
  36462. 'Font',
  36463. fontData
  36464. ]);
  36465. this.sent = true;
  36466. },
  36467. loadType3Data: function (evaluator, resources, parentOperatorList, task) {
  36468. assert(this.font.isType3Font);
  36469. if (this.type3Loaded) {
  36470. return this.type3Loaded;
  36471. }
  36472. var translatedFont = this.font;
  36473. var loadCharProcsPromise = Promise.resolve();
  36474. var charProcs = this.dict.get('CharProcs').getAll();
  36475. var fontResources = this.dict.get('Resources') || resources;
  36476. var charProcKeys = Object.keys(charProcs);
  36477. var charProcOperatorList = {};
  36478. for (var i = 0, n = charProcKeys.length; i < n; ++i) {
  36479. loadCharProcsPromise = loadCharProcsPromise.then(function (key) {
  36480. var glyphStream = charProcs[key];
  36481. var operatorList = new OperatorList();
  36482. return evaluator.getOperatorList(glyphStream, task, fontResources,
  36483. operatorList).then(function () {
  36484. charProcOperatorList[key] = operatorList.getIR();
  36485. // Add the dependencies to the parent operator list so they are
  36486. // resolved before sub operator list is executed synchronously.
  36487. parentOperatorList.addDependencies(operatorList.dependencies);
  36488. }, function (reason) {
  36489. warn('Type3 font resource \"' + key + '\" is not available');
  36490. var operatorList = new OperatorList();
  36491. charProcOperatorList[key] = operatorList.getIR();
  36492. });
  36493. }.bind(this, charProcKeys[i]));
  36494. }
  36495. this.type3Loaded = loadCharProcsPromise.then(function () {
  36496. translatedFont.charProcOperatorList = charProcOperatorList;
  36497. });
  36498. return this.type3Loaded;
  36499. }
  36500. };
  36501. return TranslatedFont;
  36502. })();
  36503. var OperatorList = (function OperatorListClosure() {
  36504. var CHUNK_SIZE = 1000;
  36505. var CHUNK_SIZE_ABOUT = CHUNK_SIZE - 5; // close to chunk size
  36506. function getTransfers(queue) {
  36507. var transfers = [];
  36508. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  36509. for (var i = 0, ii = queue.length; i < ii; i++) {
  36510. switch (fnArray[i]) {
  36511. case OPS.paintInlineImageXObject:
  36512. case OPS.paintInlineImageXObjectGroup:
  36513. case OPS.paintImageMaskXObject:
  36514. var arg = argsArray[i][0]; // first param in imgData
  36515. if (!arg.cached) {
  36516. transfers.push(arg.data.buffer);
  36517. }
  36518. break;
  36519. }
  36520. }
  36521. return transfers;
  36522. }
  36523. function OperatorList(intent, messageHandler, pageIndex) {
  36524. this.messageHandler = messageHandler;
  36525. this.fnArray = [];
  36526. this.argsArray = [];
  36527. this.dependencies = {};
  36528. this._totalLength = 0;
  36529. this.pageIndex = pageIndex;
  36530. this.intent = intent;
  36531. }
  36532. OperatorList.prototype = {
  36533. get length() {
  36534. return this.argsArray.length;
  36535. },
  36536. /**
  36537. * @returns {number} The total length of the entire operator list,
  36538. * since `this.length === 0` after flushing.
  36539. */
  36540. get totalLength() {
  36541. return (this._totalLength + this.length);
  36542. },
  36543. addOp: function(fn, args) {
  36544. this.fnArray.push(fn);
  36545. this.argsArray.push(args);
  36546. if (this.messageHandler) {
  36547. if (this.fnArray.length >= CHUNK_SIZE) {
  36548. this.flush();
  36549. } else if (this.fnArray.length >= CHUNK_SIZE_ABOUT &&
  36550. (fn === OPS.restore || fn === OPS.endText)) {
  36551. // heuristic to flush on boundary of restore or endText
  36552. this.flush();
  36553. }
  36554. }
  36555. },
  36556. addDependency: function(dependency) {
  36557. if (dependency in this.dependencies) {
  36558. return;
  36559. }
  36560. this.dependencies[dependency] = true;
  36561. this.addOp(OPS.dependency, [dependency]);
  36562. },
  36563. addDependencies: function(dependencies) {
  36564. for (var key in dependencies) {
  36565. this.addDependency(key);
  36566. }
  36567. },
  36568. addOpList: function(opList) {
  36569. Util.extendObj(this.dependencies, opList.dependencies);
  36570. for (var i = 0, ii = opList.length; i < ii; i++) {
  36571. this.addOp(opList.fnArray[i], opList.argsArray[i]);
  36572. }
  36573. },
  36574. getIR: function() {
  36575. return {
  36576. fnArray: this.fnArray,
  36577. argsArray: this.argsArray,
  36578. length: this.length
  36579. };
  36580. },
  36581. flush: function(lastChunk) {
  36582. if (this.intent !== 'oplist') {
  36583. new QueueOptimizer().optimize(this);
  36584. }
  36585. var transfers = getTransfers(this);
  36586. var length = this.length;
  36587. this._totalLength += length;
  36588. this.messageHandler.send('RenderPageChunk', {
  36589. operatorList: {
  36590. fnArray: this.fnArray,
  36591. argsArray: this.argsArray,
  36592. lastChunk: lastChunk,
  36593. length: length
  36594. },
  36595. pageIndex: this.pageIndex,
  36596. intent: this.intent
  36597. }, transfers);
  36598. this.dependencies = {};
  36599. this.fnArray.length = 0;
  36600. this.argsArray.length = 0;
  36601. }
  36602. };
  36603. return OperatorList;
  36604. })();
  36605. var StateManager = (function StateManagerClosure() {
  36606. function StateManager(initialState) {
  36607. this.state = initialState;
  36608. this.stateStack = [];
  36609. }
  36610. StateManager.prototype = {
  36611. save: function () {
  36612. var old = this.state;
  36613. this.stateStack.push(this.state);
  36614. this.state = old.clone();
  36615. },
  36616. restore: function () {
  36617. var prev = this.stateStack.pop();
  36618. if (prev) {
  36619. this.state = prev;
  36620. }
  36621. },
  36622. transform: function (args) {
  36623. this.state.ctm = Util.transform(this.state.ctm, args);
  36624. }
  36625. };
  36626. return StateManager;
  36627. })();
  36628. var TextState = (function TextStateClosure() {
  36629. function TextState() {
  36630. this.ctm = new Float32Array(IDENTITY_MATRIX);
  36631. this.fontSize = 0;
  36632. this.font = null;
  36633. this.fontMatrix = FONT_IDENTITY_MATRIX;
  36634. this.textMatrix = IDENTITY_MATRIX.slice();
  36635. this.textLineMatrix = IDENTITY_MATRIX.slice();
  36636. this.charSpacing = 0;
  36637. this.wordSpacing = 0;
  36638. this.leading = 0;
  36639. this.textHScale = 1;
  36640. this.textRise = 0;
  36641. }
  36642. TextState.prototype = {
  36643. setTextMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  36644. var m = this.textMatrix;
  36645. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  36646. },
  36647. setTextLineMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  36648. var m = this.textLineMatrix;
  36649. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  36650. },
  36651. translateTextMatrix: function TextState_translateTextMatrix(x, y) {
  36652. var m = this.textMatrix;
  36653. m[4] = m[0] * x + m[2] * y + m[4];
  36654. m[5] = m[1] * x + m[3] * y + m[5];
  36655. },
  36656. translateTextLineMatrix: function TextState_translateTextMatrix(x, y) {
  36657. var m = this.textLineMatrix;
  36658. m[4] = m[0] * x + m[2] * y + m[4];
  36659. m[5] = m[1] * x + m[3] * y + m[5];
  36660. },
  36661. calcRenderMatrix: function TextState_calcRendeMatrix(ctm) {
  36662. // 9.4.4 Text Space Details
  36663. var tsm = [this.fontSize * this.textHScale, 0,
  36664. 0, this.fontSize,
  36665. 0, this.textRise];
  36666. return Util.transform(ctm, Util.transform(this.textMatrix, tsm));
  36667. },
  36668. carriageReturn: function TextState_carriageReturn() {
  36669. this.translateTextLineMatrix(0, -this.leading);
  36670. this.textMatrix = this.textLineMatrix.slice();
  36671. },
  36672. clone: function TextState_clone() {
  36673. var clone = Object.create(this);
  36674. clone.textMatrix = this.textMatrix.slice();
  36675. clone.textLineMatrix = this.textLineMatrix.slice();
  36676. clone.fontMatrix = this.fontMatrix.slice();
  36677. return clone;
  36678. }
  36679. };
  36680. return TextState;
  36681. })();
  36682. var EvalState = (function EvalStateClosure() {
  36683. function EvalState() {
  36684. this.ctm = new Float32Array(IDENTITY_MATRIX);
  36685. this.font = null;
  36686. this.textRenderingMode = TextRenderingMode.FILL;
  36687. this.fillColorSpace = ColorSpace.singletons.gray;
  36688. this.strokeColorSpace = ColorSpace.singletons.gray;
  36689. }
  36690. EvalState.prototype = {
  36691. clone: function CanvasExtraState_clone() {
  36692. return Object.create(this);
  36693. },
  36694. };
  36695. return EvalState;
  36696. })();
  36697. var EvaluatorPreprocessor = (function EvaluatorPreprocessorClosure() {
  36698. // Specifies properties for each command
  36699. //
  36700. // If variableArgs === true: [0, `numArgs`] expected
  36701. // If variableArgs === false: exactly `numArgs` expected
  36702. var OP_MAP = {
  36703. // Graphic state
  36704. w: { id: OPS.setLineWidth, numArgs: 1, variableArgs: false },
  36705. J: { id: OPS.setLineCap, numArgs: 1, variableArgs: false },
  36706. j: { id: OPS.setLineJoin, numArgs: 1, variableArgs: false },
  36707. M: { id: OPS.setMiterLimit, numArgs: 1, variableArgs: false },
  36708. d: { id: OPS.setDash, numArgs: 2, variableArgs: false },
  36709. ri: { id: OPS.setRenderingIntent, numArgs: 1, variableArgs: false },
  36710. i: { id: OPS.setFlatness, numArgs: 1, variableArgs: false },
  36711. gs: { id: OPS.setGState, numArgs: 1, variableArgs: false },
  36712. q: { id: OPS.save, numArgs: 0, variableArgs: false },
  36713. Q: { id: OPS.restore, numArgs: 0, variableArgs: false },
  36714. cm: { id: OPS.transform, numArgs: 6, variableArgs: false },
  36715. // Path
  36716. m: { id: OPS.moveTo, numArgs: 2, variableArgs: false },
  36717. l: { id: OPS.lineTo, numArgs: 2, variableArgs: false },
  36718. c: { id: OPS.curveTo, numArgs: 6, variableArgs: false },
  36719. v: { id: OPS.curveTo2, numArgs: 4, variableArgs: false },
  36720. y: { id: OPS.curveTo3, numArgs: 4, variableArgs: false },
  36721. h: { id: OPS.closePath, numArgs: 0, variableArgs: false },
  36722. re: { id: OPS.rectangle, numArgs: 4, variableArgs: false },
  36723. S: { id: OPS.stroke, numArgs: 0, variableArgs: false },
  36724. s: { id: OPS.closeStroke, numArgs: 0, variableArgs: false },
  36725. f: { id: OPS.fill, numArgs: 0, variableArgs: false },
  36726. F: { id: OPS.fill, numArgs: 0, variableArgs: false },
  36727. 'f*': { id: OPS.eoFill, numArgs: 0, variableArgs: false },
  36728. B: { id: OPS.fillStroke, numArgs: 0, variableArgs: false },
  36729. 'B*': { id: OPS.eoFillStroke, numArgs: 0, variableArgs: false },
  36730. b: { id: OPS.closeFillStroke, numArgs: 0, variableArgs: false },
  36731. 'b*': { id: OPS.closeEOFillStroke, numArgs: 0, variableArgs: false },
  36732. n: { id: OPS.endPath, numArgs: 0, variableArgs: false },
  36733. // Clipping
  36734. W: { id: OPS.clip, numArgs: 0, variableArgs: false },
  36735. 'W*': { id: OPS.eoClip, numArgs: 0, variableArgs: false },
  36736. // Text
  36737. BT: { id: OPS.beginText, numArgs: 0, variableArgs: false },
  36738. ET: { id: OPS.endText, numArgs: 0, variableArgs: false },
  36739. Tc: { id: OPS.setCharSpacing, numArgs: 1, variableArgs: false },
  36740. Tw: { id: OPS.setWordSpacing, numArgs: 1, variableArgs: false },
  36741. Tz: { id: OPS.setHScale, numArgs: 1, variableArgs: false },
  36742. TL: { id: OPS.setLeading, numArgs: 1, variableArgs: false },
  36743. Tf: { id: OPS.setFont, numArgs: 2, variableArgs: false },
  36744. Tr: { id: OPS.setTextRenderingMode, numArgs: 1, variableArgs: false },
  36745. Ts: { id: OPS.setTextRise, numArgs: 1, variableArgs: false },
  36746. Td: { id: OPS.moveText, numArgs: 2, variableArgs: false },
  36747. TD: { id: OPS.setLeadingMoveText, numArgs: 2, variableArgs: false },
  36748. Tm: { id: OPS.setTextMatrix, numArgs: 6, variableArgs: false },
  36749. 'T*': { id: OPS.nextLine, numArgs: 0, variableArgs: false },
  36750. Tj: { id: OPS.showText, numArgs: 1, variableArgs: false },
  36751. TJ: { id: OPS.showSpacedText, numArgs: 1, variableArgs: false },
  36752. '\'': { id: OPS.nextLineShowText, numArgs: 1, variableArgs: false },
  36753. '"': { id: OPS.nextLineSetSpacingShowText, numArgs: 3,
  36754. variableArgs: false },
  36755. // Type3 fonts
  36756. d0: { id: OPS.setCharWidth, numArgs: 2, variableArgs: false },
  36757. d1: { id: OPS.setCharWidthAndBounds, numArgs: 6, variableArgs: false },
  36758. // Color
  36759. CS: { id: OPS.setStrokeColorSpace, numArgs: 1, variableArgs: false },
  36760. cs: { id: OPS.setFillColorSpace, numArgs: 1, variableArgs: false },
  36761. SC: { id: OPS.setStrokeColor, numArgs: 4, variableArgs: true },
  36762. SCN: { id: OPS.setStrokeColorN, numArgs: 33, variableArgs: true },
  36763. sc: { id: OPS.setFillColor, numArgs: 4, variableArgs: true },
  36764. scn: { id: OPS.setFillColorN, numArgs: 33, variableArgs: true },
  36765. G: { id: OPS.setStrokeGray, numArgs: 1, variableArgs: false },
  36766. g: { id: OPS.setFillGray, numArgs: 1, variableArgs: false },
  36767. RG: { id: OPS.setStrokeRGBColor, numArgs: 3, variableArgs: false },
  36768. rg: { id: OPS.setFillRGBColor, numArgs: 3, variableArgs: false },
  36769. K: { id: OPS.setStrokeCMYKColor, numArgs: 4, variableArgs: false },
  36770. k: { id: OPS.setFillCMYKColor, numArgs: 4, variableArgs: false },
  36771. // Shading
  36772. sh: { id: OPS.shadingFill, numArgs: 1, variableArgs: false },
  36773. // Images
  36774. BI: { id: OPS.beginInlineImage, numArgs: 0, variableArgs: false },
  36775. ID: { id: OPS.beginImageData, numArgs: 0, variableArgs: false },
  36776. EI: { id: OPS.endInlineImage, numArgs: 1, variableArgs: false },
  36777. // XObjects
  36778. Do: { id: OPS.paintXObject, numArgs: 1, variableArgs: false },
  36779. MP: { id: OPS.markPoint, numArgs: 1, variableArgs: false },
  36780. DP: { id: OPS.markPointProps, numArgs: 2, variableArgs: false },
  36781. BMC: { id: OPS.beginMarkedContent, numArgs: 1, variableArgs: false },
  36782. BDC: { id: OPS.beginMarkedContentProps, numArgs: 2,
  36783. variableArgs: false },
  36784. EMC: { id: OPS.endMarkedContent, numArgs: 0, variableArgs: false },
  36785. // Compatibility
  36786. BX: { id: OPS.beginCompat, numArgs: 0, variableArgs: false },
  36787. EX: { id: OPS.endCompat, numArgs: 0, variableArgs: false },
  36788. // (reserved partial commands for the lexer)
  36789. BM: null,
  36790. BD: null,
  36791. 'true': null,
  36792. fa: null,
  36793. fal: null,
  36794. fals: null,
  36795. 'false': null,
  36796. nu: null,
  36797. nul: null,
  36798. 'null': null
  36799. };
  36800. function EvaluatorPreprocessor(stream, xref, stateManager) {
  36801. // TODO(mduan): pass array of knownCommands rather than OP_MAP
  36802. // dictionary
  36803. this.parser = new Parser(new Lexer(stream, OP_MAP), false, xref);
  36804. this.stateManager = stateManager;
  36805. this.nonProcessedArgs = [];
  36806. }
  36807. EvaluatorPreprocessor.prototype = {
  36808. get savedStatesDepth() {
  36809. return this.stateManager.stateStack.length;
  36810. },
  36811. // |operation| is an object with two fields:
  36812. //
  36813. // - |fn| is an out param.
  36814. //
  36815. // - |args| is an inout param. On entry, it should have one of two values.
  36816. //
  36817. // - An empty array. This indicates that the caller is providing the
  36818. // array in which the args will be stored in. The caller should use
  36819. // this value if it can reuse a single array for each call to read().
  36820. //
  36821. // - |null|. This indicates that the caller needs this function to create
  36822. // the array in which any args are stored in. If there are zero args,
  36823. // this function will leave |operation.args| as |null| (thus avoiding
  36824. // allocations that would occur if we used an empty array to represent
  36825. // zero arguments). Otherwise, it will replace |null| with a new array
  36826. // containing the arguments. The caller should use this value if it
  36827. // cannot reuse an array for each call to read().
  36828. //
  36829. // These two modes are present because this function is very hot and so
  36830. // avoiding allocations where possible is worthwhile.
  36831. //
  36832. read: function EvaluatorPreprocessor_read(operation) {
  36833. var args = operation.args;
  36834. while (true) {
  36835. var obj = this.parser.getObj();
  36836. if (isCmd(obj)) {
  36837. var cmd = obj.cmd;
  36838. // Check that the command is valid
  36839. var opSpec = OP_MAP[cmd];
  36840. if (!opSpec) {
  36841. warn('Unknown command "' + cmd + '"');
  36842. continue;
  36843. }
  36844. var fn = opSpec.id;
  36845. var numArgs = opSpec.numArgs;
  36846. var argsLength = args !== null ? args.length : 0;
  36847. if (!opSpec.variableArgs) {
  36848. // Postscript commands can be nested, e.g. /F2 /GS2 gs 5.711 Tf
  36849. if (argsLength !== numArgs) {
  36850. var nonProcessedArgs = this.nonProcessedArgs;
  36851. while (argsLength > numArgs) {
  36852. nonProcessedArgs.push(args.shift());
  36853. argsLength--;
  36854. }
  36855. while (argsLength < numArgs && nonProcessedArgs.length !== 0) {
  36856. if (!args) {
  36857. args = [];
  36858. }
  36859. args.unshift(nonProcessedArgs.pop());
  36860. argsLength++;
  36861. }
  36862. }
  36863. if (argsLength < numArgs) {
  36864. // If we receive too few args, it's not possible to possible
  36865. // to execute the command, so skip the command
  36866. info('Command ' + fn + ': because expected ' +
  36867. numArgs + ' args, but received ' + argsLength +
  36868. ' args; skipping');
  36869. args = null;
  36870. continue;
  36871. }
  36872. } else if (argsLength > numArgs) {
  36873. info('Command ' + fn + ': expected [0,' + numArgs +
  36874. '] args, but received ' + argsLength + ' args');
  36875. }
  36876. // TODO figure out how to type-check vararg functions
  36877. this.preprocessCommand(fn, args);
  36878. operation.fn = fn;
  36879. operation.args = args;
  36880. return true;
  36881. } else {
  36882. if (isEOF(obj)) {
  36883. return false; // no more commands
  36884. }
  36885. // argument
  36886. if (obj !== null) {
  36887. if (!args) {
  36888. args = [];
  36889. }
  36890. args.push((obj instanceof Dict ? obj.getAll() : obj));
  36891. assert(args.length <= 33, 'Too many arguments');
  36892. }
  36893. }
  36894. }
  36895. },
  36896. preprocessCommand:
  36897. function EvaluatorPreprocessor_preprocessCommand(fn, args) {
  36898. switch (fn | 0) {
  36899. case OPS.save:
  36900. this.stateManager.save();
  36901. break;
  36902. case OPS.restore:
  36903. this.stateManager.restore();
  36904. break;
  36905. case OPS.transform:
  36906. this.stateManager.transform(args);
  36907. break;
  36908. }
  36909. }
  36910. };
  36911. return EvaluatorPreprocessor;
  36912. })();
  36913. var QueueOptimizer = (function QueueOptimizerClosure() {
  36914. function addState(parentState, pattern, fn) {
  36915. var state = parentState;
  36916. for (var i = 0, ii = pattern.length - 1; i < ii; i++) {
  36917. var item = pattern[i];
  36918. state = (state[item] || (state[item] = []));
  36919. }
  36920. state[pattern[pattern.length - 1]] = fn;
  36921. }
  36922. function handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  36923. argsArray) {
  36924. // Handles special case of mainly LaTeX documents which use image masks to
  36925. // draw lines with the current fill style.
  36926. // 'count' groups of (save, transform, paintImageMaskXObject, restore)+
  36927. // have been found at iFirstSave.
  36928. var iFirstPIMXO = iFirstSave + 2;
  36929. for (var i = 0; i < count; i++) {
  36930. var arg = argsArray[iFirstPIMXO + 4 * i];
  36931. var imageMask = arg.length === 1 && arg[0];
  36932. if (imageMask && imageMask.width === 1 && imageMask.height === 1 &&
  36933. (!imageMask.data.length ||
  36934. (imageMask.data.length === 1 && imageMask.data[0] === 0))) {
  36935. fnArray[iFirstPIMXO + 4 * i] = OPS.paintSolidColorImageMask;
  36936. continue;
  36937. }
  36938. break;
  36939. }
  36940. return count - i;
  36941. }
  36942. var InitialState = [];
  36943. // This replaces (save, transform, paintInlineImageXObject, restore)+
  36944. // sequences with one |paintInlineImageXObjectGroup| operation.
  36945. addState(InitialState,
  36946. [OPS.save, OPS.transform, OPS.paintInlineImageXObject, OPS.restore],
  36947. function foundInlineImageGroup(context) {
  36948. var MIN_IMAGES_IN_INLINE_IMAGES_BLOCK = 10;
  36949. var MAX_IMAGES_IN_INLINE_IMAGES_BLOCK = 200;
  36950. var MAX_WIDTH = 1000;
  36951. var IMAGE_PADDING = 1;
  36952. var fnArray = context.fnArray, argsArray = context.argsArray;
  36953. var curr = context.iCurr;
  36954. var iFirstSave = curr - 3;
  36955. var iFirstTransform = curr - 2;
  36956. var iFirstPIIXO = curr - 1;
  36957. // Look for the quartets.
  36958. var i = iFirstSave + 4;
  36959. var ii = fnArray.length;
  36960. while (i + 3 < ii) {
  36961. if (fnArray[i] !== OPS.save ||
  36962. fnArray[i + 1] !== OPS.transform ||
  36963. fnArray[i + 2] !== OPS.paintInlineImageXObject ||
  36964. fnArray[i + 3] !== OPS.restore) {
  36965. break; // ops don't match
  36966. }
  36967. i += 4;
  36968. }
  36969. // At this point, i is the index of the first op past the last valid
  36970. // quartet.
  36971. var count = Math.min((i - iFirstSave) / 4,
  36972. MAX_IMAGES_IN_INLINE_IMAGES_BLOCK);
  36973. if (count < MIN_IMAGES_IN_INLINE_IMAGES_BLOCK) {
  36974. return i;
  36975. }
  36976. // assuming that heights of those image is too small (~1 pixel)
  36977. // packing as much as possible by lines
  36978. var maxX = 0;
  36979. var map = [], maxLineHeight = 0;
  36980. var currentX = IMAGE_PADDING, currentY = IMAGE_PADDING;
  36981. var q;
  36982. for (q = 0; q < count; q++) {
  36983. var transform = argsArray[iFirstTransform + (q << 2)];
  36984. var img = argsArray[iFirstPIIXO + (q << 2)][0];
  36985. if (currentX + img.width > MAX_WIDTH) {
  36986. // starting new line
  36987. maxX = Math.max(maxX, currentX);
  36988. currentY += maxLineHeight + 2 * IMAGE_PADDING;
  36989. currentX = 0;
  36990. maxLineHeight = 0;
  36991. }
  36992. map.push({
  36993. transform: transform,
  36994. x: currentX, y: currentY,
  36995. w: img.width, h: img.height
  36996. });
  36997. currentX += img.width + 2 * IMAGE_PADDING;
  36998. maxLineHeight = Math.max(maxLineHeight, img.height);
  36999. }
  37000. var imgWidth = Math.max(maxX, currentX) + IMAGE_PADDING;
  37001. var imgHeight = currentY + maxLineHeight + IMAGE_PADDING;
  37002. var imgData = new Uint8Array(imgWidth * imgHeight * 4);
  37003. var imgRowSize = imgWidth << 2;
  37004. for (q = 0; q < count; q++) {
  37005. var data = argsArray[iFirstPIIXO + (q << 2)][0].data;
  37006. // Copy image by lines and extends pixels into padding.
  37007. var rowSize = map[q].w << 2;
  37008. var dataOffset = 0;
  37009. var offset = (map[q].x + map[q].y * imgWidth) << 2;
  37010. imgData.set(data.subarray(0, rowSize), offset - imgRowSize);
  37011. for (var k = 0, kk = map[q].h; k < kk; k++) {
  37012. imgData.set(data.subarray(dataOffset, dataOffset + rowSize), offset);
  37013. dataOffset += rowSize;
  37014. offset += imgRowSize;
  37015. }
  37016. imgData.set(data.subarray(dataOffset - rowSize, dataOffset), offset);
  37017. while (offset >= 0) {
  37018. data[offset - 4] = data[offset];
  37019. data[offset - 3] = data[offset + 1];
  37020. data[offset - 2] = data[offset + 2];
  37021. data[offset - 1] = data[offset + 3];
  37022. data[offset + rowSize] = data[offset + rowSize - 4];
  37023. data[offset + rowSize + 1] = data[offset + rowSize - 3];
  37024. data[offset + rowSize + 2] = data[offset + rowSize - 2];
  37025. data[offset + rowSize + 3] = data[offset + rowSize - 1];
  37026. offset -= imgRowSize;
  37027. }
  37028. }
  37029. // Replace queue items.
  37030. fnArray.splice(iFirstSave, count * 4, OPS.paintInlineImageXObjectGroup);
  37031. argsArray.splice(iFirstSave, count * 4,
  37032. [{ width: imgWidth, height: imgHeight, kind: ImageKind.RGBA_32BPP,
  37033. data: imgData }, map]);
  37034. return iFirstSave + 1;
  37035. });
  37036. // This replaces (save, transform, paintImageMaskXObject, restore)+
  37037. // sequences with one |paintImageMaskXObjectGroup| or one
  37038. // |paintImageMaskXObjectRepeat| operation.
  37039. addState(InitialState,
  37040. [OPS.save, OPS.transform, OPS.paintImageMaskXObject, OPS.restore],
  37041. function foundImageMaskGroup(context) {
  37042. var MIN_IMAGES_IN_MASKS_BLOCK = 10;
  37043. var MAX_IMAGES_IN_MASKS_BLOCK = 100;
  37044. var MAX_SAME_IMAGES_IN_MASKS_BLOCK = 1000;
  37045. var fnArray = context.fnArray, argsArray = context.argsArray;
  37046. var curr = context.iCurr;
  37047. var iFirstSave = curr - 3;
  37048. var iFirstTransform = curr - 2;
  37049. var iFirstPIMXO = curr - 1;
  37050. // Look for the quartets.
  37051. var i = iFirstSave + 4;
  37052. var ii = fnArray.length;
  37053. while (i + 3 < ii) {
  37054. if (fnArray[i] !== OPS.save ||
  37055. fnArray[i + 1] !== OPS.transform ||
  37056. fnArray[i + 2] !== OPS.paintImageMaskXObject ||
  37057. fnArray[i + 3] !== OPS.restore) {
  37058. break; // ops don't match
  37059. }
  37060. i += 4;
  37061. }
  37062. // At this point, i is the index of the first op past the last valid
  37063. // quartet.
  37064. var count = (i - iFirstSave) / 4;
  37065. count = handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  37066. argsArray);
  37067. if (count < MIN_IMAGES_IN_MASKS_BLOCK) {
  37068. return i;
  37069. }
  37070. var q;
  37071. var isSameImage = false;
  37072. var iTransform, transformArgs;
  37073. var firstPIMXOArg0 = argsArray[iFirstPIMXO][0];
  37074. if (argsArray[iFirstTransform][1] === 0 &&
  37075. argsArray[iFirstTransform][2] === 0) {
  37076. isSameImage = true;
  37077. var firstTransformArg0 = argsArray[iFirstTransform][0];
  37078. var firstTransformArg3 = argsArray[iFirstTransform][3];
  37079. iTransform = iFirstTransform + 4;
  37080. var iPIMXO = iFirstPIMXO + 4;
  37081. for (q = 1; q < count; q++, iTransform += 4, iPIMXO += 4) {
  37082. transformArgs = argsArray[iTransform];
  37083. if (argsArray[iPIMXO][0] !== firstPIMXOArg0 ||
  37084. transformArgs[0] !== firstTransformArg0 ||
  37085. transformArgs[1] !== 0 ||
  37086. transformArgs[2] !== 0 ||
  37087. transformArgs[3] !== firstTransformArg3) {
  37088. if (q < MIN_IMAGES_IN_MASKS_BLOCK) {
  37089. isSameImage = false;
  37090. } else {
  37091. count = q;
  37092. }
  37093. break; // different image or transform
  37094. }
  37095. }
  37096. }
  37097. if (isSameImage) {
  37098. count = Math.min(count, MAX_SAME_IMAGES_IN_MASKS_BLOCK);
  37099. var positions = new Float32Array(count * 2);
  37100. iTransform = iFirstTransform;
  37101. for (q = 0; q < count; q++, iTransform += 4) {
  37102. transformArgs = argsArray[iTransform];
  37103. positions[(q << 1)] = transformArgs[4];
  37104. positions[(q << 1) + 1] = transformArgs[5];
  37105. }
  37106. // Replace queue items.
  37107. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectRepeat);
  37108. argsArray.splice(iFirstSave, count * 4,
  37109. [firstPIMXOArg0, firstTransformArg0, firstTransformArg3, positions]);
  37110. } else {
  37111. count = Math.min(count, MAX_IMAGES_IN_MASKS_BLOCK);
  37112. var images = [];
  37113. for (q = 0; q < count; q++) {
  37114. transformArgs = argsArray[iFirstTransform + (q << 2)];
  37115. var maskParams = argsArray[iFirstPIMXO + (q << 2)][0];
  37116. images.push({ data: maskParams.data, width: maskParams.width,
  37117. height: maskParams.height,
  37118. transform: transformArgs });
  37119. }
  37120. // Replace queue items.
  37121. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectGroup);
  37122. argsArray.splice(iFirstSave, count * 4, [images]);
  37123. }
  37124. return iFirstSave + 1;
  37125. });
  37126. // This replaces (save, transform, paintImageXObject, restore)+ sequences
  37127. // with one paintImageXObjectRepeat operation, if the |transform| and
  37128. // |paintImageXObjectRepeat| ops are appropriate.
  37129. addState(InitialState,
  37130. [OPS.save, OPS.transform, OPS.paintImageXObject, OPS.restore],
  37131. function (context) {
  37132. var MIN_IMAGES_IN_BLOCK = 3;
  37133. var MAX_IMAGES_IN_BLOCK = 1000;
  37134. var fnArray = context.fnArray, argsArray = context.argsArray;
  37135. var curr = context.iCurr;
  37136. var iFirstSave = curr - 3;
  37137. var iFirstTransform = curr - 2;
  37138. var iFirstPIXO = curr - 1;
  37139. var iFirstRestore = curr;
  37140. if (argsArray[iFirstTransform][1] !== 0 ||
  37141. argsArray[iFirstTransform][2] !== 0) {
  37142. return iFirstRestore + 1; // transform has the wrong form
  37143. }
  37144. // Look for the quartets.
  37145. var firstPIXOArg0 = argsArray[iFirstPIXO][0];
  37146. var firstTransformArg0 = argsArray[iFirstTransform][0];
  37147. var firstTransformArg3 = argsArray[iFirstTransform][3];
  37148. var i = iFirstSave + 4;
  37149. var ii = fnArray.length;
  37150. while (i + 3 < ii) {
  37151. if (fnArray[i] !== OPS.save ||
  37152. fnArray[i + 1] !== OPS.transform ||
  37153. fnArray[i + 2] !== OPS.paintImageXObject ||
  37154. fnArray[i + 3] !== OPS.restore) {
  37155. break; // ops don't match
  37156. }
  37157. if (argsArray[i + 1][0] !== firstTransformArg0 ||
  37158. argsArray[i + 1][1] !== 0 ||
  37159. argsArray[i + 1][2] !== 0 ||
  37160. argsArray[i + 1][3] !== firstTransformArg3) {
  37161. break; // transforms don't match
  37162. }
  37163. if (argsArray[i + 2][0] !== firstPIXOArg0) {
  37164. break; // images don't match
  37165. }
  37166. i += 4;
  37167. }
  37168. // At this point, i is the index of the first op past the last valid
  37169. // quartet.
  37170. var count = Math.min((i - iFirstSave) / 4, MAX_IMAGES_IN_BLOCK);
  37171. if (count < MIN_IMAGES_IN_BLOCK) {
  37172. return i;
  37173. }
  37174. // Extract the (x,y) positions from all of the matching transforms.
  37175. var positions = new Float32Array(count * 2);
  37176. var iTransform = iFirstTransform;
  37177. for (var q = 0; q < count; q++, iTransform += 4) {
  37178. var transformArgs = argsArray[iTransform];
  37179. positions[(q << 1)] = transformArgs[4];
  37180. positions[(q << 1) + 1] = transformArgs[5];
  37181. }
  37182. // Replace queue items.
  37183. var args = [firstPIXOArg0, firstTransformArg0, firstTransformArg3,
  37184. positions];
  37185. fnArray.splice(iFirstSave, count * 4, OPS.paintImageXObjectRepeat);
  37186. argsArray.splice(iFirstSave, count * 4, args);
  37187. return iFirstSave + 1;
  37188. });
  37189. // This replaces (beginText, setFont, setTextMatrix, showText, endText)+
  37190. // sequences with (beginText, setFont, (setTextMatrix, showText)+, endText)+
  37191. // sequences, if the font for each one is the same.
  37192. addState(InitialState,
  37193. [OPS.beginText, OPS.setFont, OPS.setTextMatrix, OPS.showText, OPS.endText],
  37194. function (context) {
  37195. var MIN_CHARS_IN_BLOCK = 3;
  37196. var MAX_CHARS_IN_BLOCK = 1000;
  37197. var fnArray = context.fnArray, argsArray = context.argsArray;
  37198. var curr = context.iCurr;
  37199. var iFirstBeginText = curr - 4;
  37200. var iFirstSetFont = curr - 3;
  37201. var iFirstSetTextMatrix = curr - 2;
  37202. var iFirstShowText = curr - 1;
  37203. var iFirstEndText = curr;
  37204. // Look for the quintets.
  37205. var firstSetFontArg0 = argsArray[iFirstSetFont][0];
  37206. var firstSetFontArg1 = argsArray[iFirstSetFont][1];
  37207. var i = iFirstBeginText + 5;
  37208. var ii = fnArray.length;
  37209. while (i + 4 < ii) {
  37210. if (fnArray[i] !== OPS.beginText ||
  37211. fnArray[i + 1] !== OPS.setFont ||
  37212. fnArray[i + 2] !== OPS.setTextMatrix ||
  37213. fnArray[i + 3] !== OPS.showText ||
  37214. fnArray[i + 4] !== OPS.endText) {
  37215. break; // ops don't match
  37216. }
  37217. if (argsArray[i + 1][0] !== firstSetFontArg0 ||
  37218. argsArray[i + 1][1] !== firstSetFontArg1) {
  37219. break; // fonts don't match
  37220. }
  37221. i += 5;
  37222. }
  37223. // At this point, i is the index of the first op past the last valid
  37224. // quintet.
  37225. var count = Math.min(((i - iFirstBeginText) / 5), MAX_CHARS_IN_BLOCK);
  37226. if (count < MIN_CHARS_IN_BLOCK) {
  37227. return i;
  37228. }
  37229. // If the preceding quintet is (<something>, setFont, setTextMatrix,
  37230. // showText, endText), include that as well. (E.g. <something> might be
  37231. // |dependency|.)
  37232. var iFirst = iFirstBeginText;
  37233. if (iFirstBeginText >= 4 &&
  37234. fnArray[iFirstBeginText - 4] === fnArray[iFirstSetFont] &&
  37235. fnArray[iFirstBeginText - 3] === fnArray[iFirstSetTextMatrix] &&
  37236. fnArray[iFirstBeginText - 2] === fnArray[iFirstShowText] &&
  37237. fnArray[iFirstBeginText - 1] === fnArray[iFirstEndText] &&
  37238. argsArray[iFirstBeginText - 4][0] === firstSetFontArg0 &&
  37239. argsArray[iFirstBeginText - 4][1] === firstSetFontArg1) {
  37240. count++;
  37241. iFirst -= 5;
  37242. }
  37243. // Remove (endText, beginText, setFont) trios.
  37244. var iEndText = iFirst + 4;
  37245. for (var q = 1; q < count; q++) {
  37246. fnArray.splice(iEndText, 3);
  37247. argsArray.splice(iEndText, 3);
  37248. iEndText += 2;
  37249. }
  37250. return iEndText + 1;
  37251. });
  37252. function QueueOptimizer() {}
  37253. QueueOptimizer.prototype = {
  37254. optimize: function QueueOptimizer_optimize(queue) {
  37255. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  37256. var context = {
  37257. iCurr: 0,
  37258. fnArray: fnArray,
  37259. argsArray: argsArray
  37260. };
  37261. var state;
  37262. var i = 0, ii = fnArray.length;
  37263. while (i < ii) {
  37264. state = (state || InitialState)[fnArray[i]];
  37265. if (typeof state === 'function') { // we found some handler
  37266. context.iCurr = i;
  37267. // state() returns the index of the first non-matching op (if we
  37268. // didn't match) or the first op past the modified ops (if we did
  37269. // match and replace).
  37270. i = state(context);
  37271. state = undefined; // reset the state machine
  37272. ii = context.fnArray.length;
  37273. } else {
  37274. i++;
  37275. }
  37276. }
  37277. }
  37278. };
  37279. return QueueOptimizer;
  37280. })();
  37281. exports.OperatorList = OperatorList;
  37282. exports.PartialEvaluator = PartialEvaluator;
  37283. }));
  37284. (function (root, factory) {
  37285. {
  37286. factory((root.pdfjsCoreAnnotation = {}), root.pdfjsSharedUtil,
  37287. root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreColorSpace,
  37288. root.pdfjsCoreObj, root.pdfjsCoreEvaluator);
  37289. }
  37290. }(this, function (exports, sharedUtil, corePrimitives, coreStream,
  37291. coreColorSpace, coreObj, coreEvaluator) {
  37292. var AnnotationBorderStyleType = sharedUtil.AnnotationBorderStyleType;
  37293. var AnnotationFlag = sharedUtil.AnnotationFlag;
  37294. var AnnotationType = sharedUtil.AnnotationType;
  37295. var OPS = sharedUtil.OPS;
  37296. var Util = sharedUtil.Util;
  37297. var isArray = sharedUtil.isArray;
  37298. var isInt = sharedUtil.isInt;
  37299. var isValidUrl = sharedUtil.isValidUrl;
  37300. var stringToBytes = sharedUtil.stringToBytes;
  37301. var stringToPDFString = sharedUtil.stringToPDFString;
  37302. var stringToUTF8String = sharedUtil.stringToUTF8String;
  37303. var warn = sharedUtil.warn;
  37304. var Dict = corePrimitives.Dict;
  37305. var isDict = corePrimitives.isDict;
  37306. var isName = corePrimitives.isName;
  37307. var Stream = coreStream.Stream;
  37308. var ColorSpace = coreColorSpace.ColorSpace;
  37309. var ObjectLoader = coreObj.ObjectLoader;
  37310. var OperatorList = coreEvaluator.OperatorList;
  37311. /**
  37312. * @class
  37313. * @alias AnnotationFactory
  37314. */
  37315. function AnnotationFactory() {}
  37316. AnnotationFactory.prototype = /** @lends AnnotationFactory.prototype */ {
  37317. /**
  37318. * @param {XRef} xref
  37319. * @param {Object} ref
  37320. * @returns {Annotation}
  37321. */
  37322. create: function AnnotationFactory_create(xref, ref) {
  37323. var dict = xref.fetchIfRef(ref);
  37324. if (!isDict(dict)) {
  37325. return;
  37326. }
  37327. // Determine the annotation's subtype.
  37328. var subtype = dict.get('Subtype');
  37329. subtype = isName(subtype) ? subtype.name : '';
  37330. // Return the right annotation object based on the subtype and field type.
  37331. var parameters = {
  37332. dict: dict,
  37333. ref: ref
  37334. };
  37335. switch (subtype) {
  37336. case 'Link':
  37337. return new LinkAnnotation(parameters);
  37338. case 'Text':
  37339. return new TextAnnotation(parameters);
  37340. case 'Widget':
  37341. var fieldType = Util.getInheritableProperty(dict, 'FT');
  37342. if (isName(fieldType) && fieldType.name === 'Tx') {
  37343. return new TextWidgetAnnotation(parameters);
  37344. }
  37345. return new WidgetAnnotation(parameters);
  37346. case 'Popup':
  37347. return new PopupAnnotation(parameters);
  37348. case 'Highlight':
  37349. return new HighlightAnnotation(parameters);
  37350. case 'Underline':
  37351. return new UnderlineAnnotation(parameters);
  37352. case 'Squiggly':
  37353. return new SquigglyAnnotation(parameters);
  37354. case 'StrikeOut':
  37355. return new StrikeOutAnnotation(parameters);
  37356. default:
  37357. warn('Unimplemented annotation type "' + subtype + '", ' +
  37358. 'falling back to base annotation');
  37359. return new Annotation(parameters);
  37360. }
  37361. }
  37362. };
  37363. var Annotation = (function AnnotationClosure() {
  37364. // 12.5.5: Algorithm: Appearance streams
  37365. function getTransformMatrix(rect, bbox, matrix) {
  37366. var bounds = Util.getAxialAlignedBoundingBox(bbox, matrix);
  37367. var minX = bounds[0];
  37368. var minY = bounds[1];
  37369. var maxX = bounds[2];
  37370. var maxY = bounds[3];
  37371. if (minX === maxX || minY === maxY) {
  37372. // From real-life file, bbox was [0, 0, 0, 0]. In this case,
  37373. // just apply the transform for rect
  37374. return [1, 0, 0, 1, rect[0], rect[1]];
  37375. }
  37376. var xRatio = (rect[2] - rect[0]) / (maxX - minX);
  37377. var yRatio = (rect[3] - rect[1]) / (maxY - minY);
  37378. return [
  37379. xRatio,
  37380. 0,
  37381. 0,
  37382. yRatio,
  37383. rect[0] - minX * xRatio,
  37384. rect[1] - minY * yRatio
  37385. ];
  37386. }
  37387. function getDefaultAppearance(dict) {
  37388. var appearanceState = dict.get('AP');
  37389. if (!isDict(appearanceState)) {
  37390. return;
  37391. }
  37392. var appearance;
  37393. var appearances = appearanceState.get('N');
  37394. if (isDict(appearances)) {
  37395. var as = dict.get('AS');
  37396. if (as && appearances.has(as.name)) {
  37397. appearance = appearances.get(as.name);
  37398. }
  37399. } else {
  37400. appearance = appearances;
  37401. }
  37402. return appearance;
  37403. }
  37404. function Annotation(params) {
  37405. var dict = params.dict;
  37406. this.setFlags(dict.get('F'));
  37407. this.setRectangle(dict.get('Rect'));
  37408. this.setColor(dict.get('C'));
  37409. this.setBorderStyle(dict);
  37410. this.appearance = getDefaultAppearance(dict);
  37411. // Expose public properties using a data object.
  37412. this.data = {};
  37413. this.data.id = params.ref.toString();
  37414. this.data.subtype = dict.get('Subtype').name;
  37415. this.data.annotationFlags = this.flags;
  37416. this.data.rect = this.rectangle;
  37417. this.data.color = this.color;
  37418. this.data.borderStyle = this.borderStyle;
  37419. this.data.hasAppearance = !!this.appearance;
  37420. }
  37421. Annotation.prototype = {
  37422. /**
  37423. * @return {boolean}
  37424. */
  37425. get viewable() {
  37426. if (this.flags) {
  37427. return !this.hasFlag(AnnotationFlag.INVISIBLE) &&
  37428. !this.hasFlag(AnnotationFlag.HIDDEN) &&
  37429. !this.hasFlag(AnnotationFlag.NOVIEW);
  37430. }
  37431. return true;
  37432. },
  37433. /**
  37434. * @return {boolean}
  37435. */
  37436. get printable() {
  37437. if (this.flags) {
  37438. return this.hasFlag(AnnotationFlag.PRINT) &&
  37439. !this.hasFlag(AnnotationFlag.INVISIBLE) &&
  37440. !this.hasFlag(AnnotationFlag.HIDDEN);
  37441. }
  37442. return false;
  37443. },
  37444. /**
  37445. * Set the flags.
  37446. *
  37447. * @public
  37448. * @memberof Annotation
  37449. * @param {number} flags - Unsigned 32-bit integer specifying annotation
  37450. * characteristics
  37451. * @see {@link shared/util.js}
  37452. */
  37453. setFlags: function Annotation_setFlags(flags) {
  37454. if (isInt(flags)) {
  37455. this.flags = flags;
  37456. } else {
  37457. this.flags = 0;
  37458. }
  37459. },
  37460. /**
  37461. * Check if a provided flag is set.
  37462. *
  37463. * @public
  37464. * @memberof Annotation
  37465. * @param {number} flag - Hexadecimal representation for an annotation
  37466. * characteristic
  37467. * @return {boolean}
  37468. * @see {@link shared/util.js}
  37469. */
  37470. hasFlag: function Annotation_hasFlag(flag) {
  37471. if (this.flags) {
  37472. return (this.flags & flag) > 0;
  37473. }
  37474. return false;
  37475. },
  37476. /**
  37477. * Set the rectangle.
  37478. *
  37479. * @public
  37480. * @memberof Annotation
  37481. * @param {Array} rectangle - The rectangle array with exactly four entries
  37482. */
  37483. setRectangle: function Annotation_setRectangle(rectangle) {
  37484. if (isArray(rectangle) && rectangle.length === 4) {
  37485. this.rectangle = Util.normalizeRect(rectangle);
  37486. } else {
  37487. this.rectangle = [0, 0, 0, 0];
  37488. }
  37489. },
  37490. /**
  37491. * Set the color and take care of color space conversion.
  37492. *
  37493. * @public
  37494. * @memberof Annotation
  37495. * @param {Array} color - The color array containing either 0
  37496. * (transparent), 1 (grayscale), 3 (RGB) or
  37497. * 4 (CMYK) elements
  37498. */
  37499. setColor: function Annotation_setColor(color) {
  37500. var rgbColor = new Uint8Array(3); // Black in RGB color space (default)
  37501. if (!isArray(color)) {
  37502. this.color = rgbColor;
  37503. return;
  37504. }
  37505. switch (color.length) {
  37506. case 0: // Transparent, which we indicate with a null value
  37507. this.color = null;
  37508. break;
  37509. case 1: // Convert grayscale to RGB
  37510. ColorSpace.singletons.gray.getRgbItem(color, 0, rgbColor, 0);
  37511. this.color = rgbColor;
  37512. break;
  37513. case 3: // Convert RGB percentages to RGB
  37514. ColorSpace.singletons.rgb.getRgbItem(color, 0, rgbColor, 0);
  37515. this.color = rgbColor;
  37516. break;
  37517. case 4: // Convert CMYK to RGB
  37518. ColorSpace.singletons.cmyk.getRgbItem(color, 0, rgbColor, 0);
  37519. this.color = rgbColor;
  37520. break;
  37521. default:
  37522. this.color = rgbColor;
  37523. break;
  37524. }
  37525. },
  37526. /**
  37527. * Set the border style (as AnnotationBorderStyle object).
  37528. *
  37529. * @public
  37530. * @memberof Annotation
  37531. * @param {Dict} borderStyle - The border style dictionary
  37532. */
  37533. setBorderStyle: function Annotation_setBorderStyle(borderStyle) {
  37534. this.borderStyle = new AnnotationBorderStyle();
  37535. if (!isDict(borderStyle)) {
  37536. return;
  37537. }
  37538. if (borderStyle.has('BS')) {
  37539. var dict = borderStyle.get('BS');
  37540. var dictType;
  37541. if (!dict.has('Type') || (isName(dictType = dict.get('Type')) &&
  37542. dictType.name === 'Border')) {
  37543. this.borderStyle.setWidth(dict.get('W'));
  37544. this.borderStyle.setStyle(dict.get('S'));
  37545. this.borderStyle.setDashArray(dict.get('D'));
  37546. }
  37547. } else if (borderStyle.has('Border')) {
  37548. var array = borderStyle.get('Border');
  37549. if (isArray(array) && array.length >= 3) {
  37550. this.borderStyle.setHorizontalCornerRadius(array[0]);
  37551. this.borderStyle.setVerticalCornerRadius(array[1]);
  37552. this.borderStyle.setWidth(array[2]);
  37553. if (array.length === 4) { // Dash array available
  37554. this.borderStyle.setDashArray(array[3]);
  37555. }
  37556. }
  37557. } else {
  37558. // There are no border entries in the dictionary. According to the
  37559. // specification, we should draw a solid border of width 1 in that
  37560. // case, but Adobe Reader did not implement that part of the
  37561. // specification and instead draws no border at all, so we do the same.
  37562. // See also https://github.com/mozilla/pdf.js/issues/6179.
  37563. this.borderStyle.setWidth(0);
  37564. }
  37565. },
  37566. loadResources: function Annotation_loadResources(keys) {
  37567. return new Promise(function (resolve, reject) {
  37568. this.appearance.dict.getAsync('Resources').then(function (resources) {
  37569. if (!resources) {
  37570. resolve();
  37571. return;
  37572. }
  37573. var objectLoader = new ObjectLoader(resources.map,
  37574. keys,
  37575. resources.xref);
  37576. objectLoader.load().then(function() {
  37577. resolve(resources);
  37578. }, reject);
  37579. }, reject);
  37580. }.bind(this));
  37581. },
  37582. getOperatorList: function Annotation_getOperatorList(evaluator, task) {
  37583. if (!this.appearance) {
  37584. return Promise.resolve(new OperatorList());
  37585. }
  37586. var data = this.data;
  37587. var appearanceDict = this.appearance.dict;
  37588. var resourcesPromise = this.loadResources([
  37589. 'ExtGState',
  37590. 'ColorSpace',
  37591. 'Pattern',
  37592. 'Shading',
  37593. 'XObject',
  37594. 'Font'
  37595. // ProcSet
  37596. // Properties
  37597. ]);
  37598. var bbox = appearanceDict.get('BBox') || [0, 0, 1, 1];
  37599. var matrix = appearanceDict.get('Matrix') || [1, 0, 0, 1, 0 ,0];
  37600. var transform = getTransformMatrix(data.rect, bbox, matrix);
  37601. var self = this;
  37602. return resourcesPromise.then(function(resources) {
  37603. var opList = new OperatorList();
  37604. opList.addOp(OPS.beginAnnotation, [data.rect, transform, matrix]);
  37605. return evaluator.getOperatorList(self.appearance, task,
  37606. resources, opList).
  37607. then(function () {
  37608. opList.addOp(OPS.endAnnotation, []);
  37609. self.appearance.reset();
  37610. return opList;
  37611. });
  37612. });
  37613. }
  37614. };
  37615. Annotation.appendToOperatorList = function Annotation_appendToOperatorList(
  37616. annotations, opList, partialEvaluator, task, intent) {
  37617. var annotationPromises = [];
  37618. for (var i = 0, n = annotations.length; i < n; ++i) {
  37619. if ((intent === 'display' && annotations[i].viewable) ||
  37620. (intent === 'print' && annotations[i].printable)) {
  37621. annotationPromises.push(
  37622. annotations[i].getOperatorList(partialEvaluator, task));
  37623. }
  37624. }
  37625. return Promise.all(annotationPromises).then(function(operatorLists) {
  37626. opList.addOp(OPS.beginAnnotations, []);
  37627. for (var i = 0, n = operatorLists.length; i < n; ++i) {
  37628. opList.addOpList(operatorLists[i]);
  37629. }
  37630. opList.addOp(OPS.endAnnotations, []);
  37631. });
  37632. };
  37633. return Annotation;
  37634. })();
  37635. /**
  37636. * Contains all data regarding an annotation's border style.
  37637. *
  37638. * @class
  37639. */
  37640. var AnnotationBorderStyle = (function AnnotationBorderStyleClosure() {
  37641. /**
  37642. * @constructor
  37643. * @private
  37644. */
  37645. function AnnotationBorderStyle() {
  37646. this.width = 1;
  37647. this.style = AnnotationBorderStyleType.SOLID;
  37648. this.dashArray = [3];
  37649. this.horizontalCornerRadius = 0;
  37650. this.verticalCornerRadius = 0;
  37651. }
  37652. AnnotationBorderStyle.prototype = {
  37653. /**
  37654. * Set the width.
  37655. *
  37656. * @public
  37657. * @memberof AnnotationBorderStyle
  37658. * @param {integer} width - The width
  37659. */
  37660. setWidth: function AnnotationBorderStyle_setWidth(width) {
  37661. if (width === (width | 0)) {
  37662. this.width = width;
  37663. }
  37664. },
  37665. /**
  37666. * Set the style.
  37667. *
  37668. * @public
  37669. * @memberof AnnotationBorderStyle
  37670. * @param {Object} style - The style object
  37671. * @see {@link shared/util.js}
  37672. */
  37673. setStyle: function AnnotationBorderStyle_setStyle(style) {
  37674. if (!style) {
  37675. return;
  37676. }
  37677. switch (style.name) {
  37678. case 'S':
  37679. this.style = AnnotationBorderStyleType.SOLID;
  37680. break;
  37681. case 'D':
  37682. this.style = AnnotationBorderStyleType.DASHED;
  37683. break;
  37684. case 'B':
  37685. this.style = AnnotationBorderStyleType.BEVELED;
  37686. break;
  37687. case 'I':
  37688. this.style = AnnotationBorderStyleType.INSET;
  37689. break;
  37690. case 'U':
  37691. this.style = AnnotationBorderStyleType.UNDERLINE;
  37692. break;
  37693. default:
  37694. break;
  37695. }
  37696. },
  37697. /**
  37698. * Set the dash array.
  37699. *
  37700. * @public
  37701. * @memberof AnnotationBorderStyle
  37702. * @param {Array} dashArray - The dash array with at least one element
  37703. */
  37704. setDashArray: function AnnotationBorderStyle_setDashArray(dashArray) {
  37705. // We validate the dash array, but we do not use it because CSS does not
  37706. // allow us to change spacing of dashes. For more information, visit
  37707. // http://www.w3.org/TR/css3-background/#the-border-style.
  37708. if (isArray(dashArray) && dashArray.length > 0) {
  37709. // According to the PDF specification: the elements in a dashArray
  37710. // shall be numbers that are nonnegative and not all equal to zero.
  37711. var isValid = true;
  37712. var allZeros = true;
  37713. for (var i = 0, len = dashArray.length; i < len; i++) {
  37714. var element = dashArray[i];
  37715. var validNumber = (+element >= 0);
  37716. if (!validNumber) {
  37717. isValid = false;
  37718. break;
  37719. } else if (element > 0) {
  37720. allZeros = false;
  37721. }
  37722. }
  37723. if (isValid && !allZeros) {
  37724. this.dashArray = dashArray;
  37725. } else {
  37726. this.width = 0; // Adobe behavior when the array is invalid.
  37727. }
  37728. } else if (dashArray) {
  37729. this.width = 0; // Adobe behavior when the array is invalid.
  37730. }
  37731. },
  37732. /**
  37733. * Set the horizontal corner radius (from a Border dictionary).
  37734. *
  37735. * @public
  37736. * @memberof AnnotationBorderStyle
  37737. * @param {integer} radius - The horizontal corner radius
  37738. */
  37739. setHorizontalCornerRadius:
  37740. function AnnotationBorderStyle_setHorizontalCornerRadius(radius) {
  37741. if (radius === (radius | 0)) {
  37742. this.horizontalCornerRadius = radius;
  37743. }
  37744. },
  37745. /**
  37746. * Set the vertical corner radius (from a Border dictionary).
  37747. *
  37748. * @public
  37749. * @memberof AnnotationBorderStyle
  37750. * @param {integer} radius - The vertical corner radius
  37751. */
  37752. setVerticalCornerRadius:
  37753. function AnnotationBorderStyle_setVerticalCornerRadius(radius) {
  37754. if (radius === (radius | 0)) {
  37755. this.verticalCornerRadius = radius;
  37756. }
  37757. }
  37758. };
  37759. return AnnotationBorderStyle;
  37760. })();
  37761. var WidgetAnnotation = (function WidgetAnnotationClosure() {
  37762. function WidgetAnnotation(params) {
  37763. Annotation.call(this, params);
  37764. var dict = params.dict;
  37765. var data = this.data;
  37766. data.annotationType = AnnotationType.WIDGET;
  37767. data.fieldValue = stringToPDFString(
  37768. Util.getInheritableProperty(dict, 'V') || '');
  37769. data.alternativeText = stringToPDFString(dict.get('TU') || '');
  37770. data.defaultAppearance = Util.getInheritableProperty(dict, 'DA') || '';
  37771. var fieldType = Util.getInheritableProperty(dict, 'FT');
  37772. data.fieldType = isName(fieldType) ? fieldType.name : '';
  37773. data.fieldFlags = Util.getInheritableProperty(dict, 'Ff') || 0;
  37774. this.fieldResources = Util.getInheritableProperty(dict, 'DR') || Dict.empty;
  37775. // Hide unsupported Widget signatures.
  37776. if (data.fieldType === 'Sig') {
  37777. warn('unimplemented annotation type: Widget signature');
  37778. this.setFlags(AnnotationFlag.HIDDEN);
  37779. }
  37780. // Building the full field name by collecting the field and
  37781. // its ancestors 'T' data and joining them using '.'.
  37782. var fieldName = [];
  37783. var namedItem = dict;
  37784. var ref = params.ref;
  37785. while (namedItem) {
  37786. var parent = namedItem.get('Parent');
  37787. var parentRef = namedItem.getRaw('Parent');
  37788. var name = namedItem.get('T');
  37789. if (name) {
  37790. fieldName.unshift(stringToPDFString(name));
  37791. } else if (parent && ref) {
  37792. // The field name is absent, that means more than one field
  37793. // with the same name may exist. Replacing the empty name
  37794. // with the '`' plus index in the parent's 'Kids' array.
  37795. // This is not in the PDF spec but necessary to id the
  37796. // the input controls.
  37797. var kids = parent.get('Kids');
  37798. var j, jj;
  37799. for (j = 0, jj = kids.length; j < jj; j++) {
  37800. var kidRef = kids[j];
  37801. if (kidRef.num === ref.num && kidRef.gen === ref.gen) {
  37802. break;
  37803. }
  37804. }
  37805. fieldName.unshift('`' + j);
  37806. }
  37807. namedItem = parent;
  37808. ref = parentRef;
  37809. }
  37810. data.fullName = fieldName.join('.');
  37811. }
  37812. Util.inherit(WidgetAnnotation, Annotation, {});
  37813. return WidgetAnnotation;
  37814. })();
  37815. var TextWidgetAnnotation = (function TextWidgetAnnotationClosure() {
  37816. function TextWidgetAnnotation(params) {
  37817. WidgetAnnotation.call(this, params);
  37818. this.data.textAlignment = Util.getInheritableProperty(params.dict, 'Q');
  37819. this.data.hasHtml = !this.data.hasAppearance && !!this.data.fieldValue;
  37820. }
  37821. Util.inherit(TextWidgetAnnotation, WidgetAnnotation, {
  37822. getOperatorList: function TextWidgetAnnotation_getOperatorList(evaluator,
  37823. task) {
  37824. if (this.appearance) {
  37825. return Annotation.prototype.getOperatorList.call(this, evaluator, task);
  37826. }
  37827. var opList = new OperatorList();
  37828. var data = this.data;
  37829. // Even if there is an appearance stream, ignore it. This is the
  37830. // behaviour used by Adobe Reader.
  37831. if (!data.defaultAppearance) {
  37832. return Promise.resolve(opList);
  37833. }
  37834. var stream = new Stream(stringToBytes(data.defaultAppearance));
  37835. return evaluator.getOperatorList(stream, task,
  37836. this.fieldResources, opList).
  37837. then(function () {
  37838. return opList;
  37839. });
  37840. }
  37841. });
  37842. return TextWidgetAnnotation;
  37843. })();
  37844. var TextAnnotation = (function TextAnnotationClosure() {
  37845. var DEFAULT_ICON_SIZE = 22; // px
  37846. function TextAnnotation(parameters) {
  37847. Annotation.call(this, parameters);
  37848. this.data.annotationType = AnnotationType.TEXT;
  37849. this.data.hasHtml = true;
  37850. var dict = parameters.dict;
  37851. if (this.data.hasAppearance) {
  37852. this.data.name = 'NoIcon';
  37853. } else {
  37854. this.data.rect[1] = this.data.rect[3] - DEFAULT_ICON_SIZE;
  37855. this.data.rect[2] = this.data.rect[0] + DEFAULT_ICON_SIZE;
  37856. this.data.name = dict.has('Name') ? dict.get('Name').name : 'Note';
  37857. }
  37858. if (!dict.has('C')) {
  37859. // Fall back to the default background color.
  37860. this.data.color = null;
  37861. }
  37862. this.data.hasPopup = dict.has('Popup');
  37863. if (!this.data.hasPopup) {
  37864. // There is no associated Popup annotation, so the Text annotation
  37865. // must create its own popup.
  37866. this.data.title = stringToPDFString(dict.get('T') || '');
  37867. this.data.contents = stringToPDFString(dict.get('Contents') || '');
  37868. this.data.hasHtml = (this.data.title || this.data.contents);
  37869. }
  37870. }
  37871. Util.inherit(TextAnnotation, Annotation, {});
  37872. return TextAnnotation;
  37873. })();
  37874. var LinkAnnotation = (function LinkAnnotationClosure() {
  37875. function LinkAnnotation(params) {
  37876. Annotation.call(this, params);
  37877. var dict = params.dict;
  37878. var data = this.data;
  37879. data.annotationType = AnnotationType.LINK;
  37880. data.hasHtml = true;
  37881. var action = dict.get('A');
  37882. if (action && isDict(action)) {
  37883. var linkType = action.get('S').name;
  37884. if (linkType === 'URI') {
  37885. var url = action.get('URI');
  37886. if (isName(url)) {
  37887. // Some bad PDFs do not put parentheses around relative URLs.
  37888. url = '/' + url.name;
  37889. } else if (url) {
  37890. url = addDefaultProtocolToUrl(url);
  37891. }
  37892. // TODO: pdf spec mentions urls can be relative to a Base
  37893. // entry in the dictionary.
  37894. if (!isValidUrl(url, false)) {
  37895. url = '';
  37896. }
  37897. // According to ISO 32000-1:2008, section 12.6.4.7,
  37898. // URI should to be encoded in 7-bit ASCII.
  37899. // Some bad PDFs may have URIs in UTF-8 encoding, see Bugzilla 1122280.
  37900. try {
  37901. data.url = stringToUTF8String(url);
  37902. } catch (e) {
  37903. // Fall back to a simple copy.
  37904. data.url = url;
  37905. }
  37906. } else if (linkType === 'GoTo') {
  37907. data.dest = action.get('D');
  37908. } else if (linkType === 'GoToR') {
  37909. var urlDict = action.get('F');
  37910. if (isDict(urlDict)) {
  37911. // We assume that the 'url' is a Filspec dictionary
  37912. // and fetch the url without checking any further
  37913. url = urlDict.get('F') || '';
  37914. }
  37915. // TODO: pdf reference says that GoToR
  37916. // can also have 'NewWindow' attribute
  37917. if (!isValidUrl(url, false)) {
  37918. url = '';
  37919. }
  37920. data.url = url;
  37921. data.dest = action.get('D');
  37922. } else if (linkType === 'Named') {
  37923. data.action = action.get('N').name;
  37924. } else {
  37925. warn('unrecognized link type: ' + linkType);
  37926. }
  37927. } else if (dict.has('Dest')) {
  37928. // simple destination link
  37929. var dest = dict.get('Dest');
  37930. data.dest = isName(dest) ? dest.name : dest;
  37931. }
  37932. }
  37933. // Lets URLs beginning with 'www.' default to using the 'http://' protocol.
  37934. function addDefaultProtocolToUrl(url) {
  37935. if (url && url.indexOf('www.') === 0) {
  37936. return ('http://' + url);
  37937. }
  37938. return url;
  37939. }
  37940. Util.inherit(LinkAnnotation, Annotation, {});
  37941. return LinkAnnotation;
  37942. })();
  37943. var PopupAnnotation = (function PopupAnnotationClosure() {
  37944. function PopupAnnotation(parameters) {
  37945. Annotation.call(this, parameters);
  37946. this.data.annotationType = AnnotationType.POPUP;
  37947. var dict = parameters.dict;
  37948. var parentItem = dict.get('Parent');
  37949. if (!parentItem) {
  37950. warn('Popup annotation has a missing or invalid parent annotation.');
  37951. return;
  37952. }
  37953. this.data.parentId = dict.getRaw('Parent').toString();
  37954. this.data.title = stringToPDFString(parentItem.get('T') || '');
  37955. this.data.contents = stringToPDFString(parentItem.get('Contents') || '');
  37956. if (!parentItem.has('C')) {
  37957. // Fall back to the default background color.
  37958. this.data.color = null;
  37959. } else {
  37960. this.setColor(parentItem.get('C'));
  37961. this.data.color = this.color;
  37962. }
  37963. this.data.hasHtml = (this.data.title || this.data.contents);
  37964. }
  37965. Util.inherit(PopupAnnotation, Annotation, {});
  37966. return PopupAnnotation;
  37967. })();
  37968. var HighlightAnnotation = (function HighlightAnnotationClosure() {
  37969. function HighlightAnnotation(parameters) {
  37970. Annotation.call(this, parameters);
  37971. this.data.annotationType = AnnotationType.HIGHLIGHT;
  37972. this.data.hasHtml = true;
  37973. // PDF viewers completely ignore any border styles.
  37974. this.data.borderStyle.setWidth(0);
  37975. }
  37976. Util.inherit(HighlightAnnotation, Annotation, {});
  37977. return HighlightAnnotation;
  37978. })();
  37979. var UnderlineAnnotation = (function UnderlineAnnotationClosure() {
  37980. function UnderlineAnnotation(parameters) {
  37981. Annotation.call(this, parameters);
  37982. this.data.annotationType = AnnotationType.UNDERLINE;
  37983. this.data.hasHtml = true;
  37984. // PDF viewers completely ignore any border styles.
  37985. this.data.borderStyle.setWidth(0);
  37986. }
  37987. Util.inherit(UnderlineAnnotation, Annotation, {});
  37988. return UnderlineAnnotation;
  37989. })();
  37990. var SquigglyAnnotation = (function SquigglyAnnotationClosure() {
  37991. function SquigglyAnnotation(parameters) {
  37992. Annotation.call(this, parameters);
  37993. this.data.annotationType = AnnotationType.SQUIGGLY;
  37994. this.data.hasHtml = true;
  37995. // PDF viewers completely ignore any border styles.
  37996. this.data.borderStyle.setWidth(0);
  37997. }
  37998. Util.inherit(SquigglyAnnotation, Annotation, {});
  37999. return SquigglyAnnotation;
  38000. })();
  38001. var StrikeOutAnnotation = (function StrikeOutAnnotationClosure() {
  38002. function StrikeOutAnnotation(parameters) {
  38003. Annotation.call(this, parameters);
  38004. this.data.annotationType = AnnotationType.STRIKEOUT;
  38005. this.data.hasHtml = true;
  38006. // PDF viewers completely ignore any border styles.
  38007. this.data.borderStyle.setWidth(0);
  38008. }
  38009. Util.inherit(StrikeOutAnnotation, Annotation, {});
  38010. return StrikeOutAnnotation;
  38011. })();
  38012. exports.Annotation = Annotation;
  38013. exports.AnnotationBorderStyle = AnnotationBorderStyle;
  38014. exports.AnnotationFactory = AnnotationFactory;
  38015. }));
  38016. (function (root, factory) {
  38017. {
  38018. factory((root.pdfjsCoreDocument = {}), root.pdfjsSharedUtil,
  38019. root.pdfjsCorePrimitives, root.pdfjsCoreStream,
  38020. root.pdfjsCoreObj, root.pdfjsCoreParser, root.pdfjsCoreCrypto,
  38021. root.pdfjsCoreEvaluator, root.pdfjsCoreAnnotation);
  38022. }
  38023. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreObj,
  38024. coreParser, coreCrypto, coreEvaluator, coreAnnotation) {
  38025. var MissingDataException = sharedUtil.MissingDataException;
  38026. var Util = sharedUtil.Util;
  38027. var assert = sharedUtil.assert;
  38028. var error = sharedUtil.error;
  38029. var info = sharedUtil.info;
  38030. var isArray = sharedUtil.isArray;
  38031. var isArrayBuffer = sharedUtil.isArrayBuffer;
  38032. var isString = sharedUtil.isString;
  38033. var shadow = sharedUtil.shadow;
  38034. var stringToBytes = sharedUtil.stringToBytes;
  38035. var stringToPDFString = sharedUtil.stringToPDFString;
  38036. var warn = sharedUtil.warn;
  38037. var Dict = corePrimitives.Dict;
  38038. var isDict = corePrimitives.isDict;
  38039. var isName = corePrimitives.isName;
  38040. var isStream = corePrimitives.isStream;
  38041. var NullStream = coreStream.NullStream;
  38042. var Stream = coreStream.Stream;
  38043. var StreamsSequenceStream = coreStream.StreamsSequenceStream;
  38044. var Catalog = coreObj.Catalog;
  38045. var ObjectLoader = coreObj.ObjectLoader;
  38046. var XRef = coreObj.XRef;
  38047. var Lexer = coreParser.Lexer;
  38048. var Linearization = coreParser.Linearization;
  38049. var calculateMD5 = coreCrypto.calculateMD5;
  38050. var OperatorList = coreEvaluator.OperatorList;
  38051. var PartialEvaluator = coreEvaluator.PartialEvaluator;
  38052. var Annotation = coreAnnotation.Annotation;
  38053. var AnnotationFactory = coreAnnotation.AnnotationFactory;
  38054. var Page = (function PageClosure() {
  38055. var LETTER_SIZE_MEDIABOX = [0, 0, 612, 792];
  38056. function Page(pdfManager, xref, pageIndex, pageDict, ref, fontCache) {
  38057. this.pdfManager = pdfManager;
  38058. this.pageIndex = pageIndex;
  38059. this.pageDict = pageDict;
  38060. this.xref = xref;
  38061. this.ref = ref;
  38062. this.fontCache = fontCache;
  38063. this.idCounters = {
  38064. obj: 0
  38065. };
  38066. this.resourcesPromise = null;
  38067. }
  38068. Page.prototype = {
  38069. getPageProp: function Page_getPageProp(key) {
  38070. return this.pageDict.get(key);
  38071. },
  38072. getInheritedPageProp: function Page_getInheritedPageProp(key) {
  38073. var dict = this.pageDict, valueArray = null, loopCount = 0;
  38074. var MAX_LOOP_COUNT = 100;
  38075. // Always walk up the entire parent chain, to be able to find
  38076. // e.g. \Resources placed on multiple levels of the tree.
  38077. while (dict) {
  38078. var value = dict.get(key);
  38079. if (value) {
  38080. if (!valueArray) {
  38081. valueArray = [];
  38082. }
  38083. valueArray.push(value);
  38084. }
  38085. if (++loopCount > MAX_LOOP_COUNT) {
  38086. warn('Page_getInheritedPageProp: maximum loop count exceeded.');
  38087. break;
  38088. }
  38089. dict = dict.get('Parent');
  38090. }
  38091. if (!valueArray) {
  38092. return Dict.empty;
  38093. }
  38094. if (valueArray.length === 1 || !isDict(valueArray[0]) ||
  38095. loopCount > MAX_LOOP_COUNT) {
  38096. return valueArray[0];
  38097. }
  38098. return Dict.merge(this.xref, valueArray);
  38099. },
  38100. get content() {
  38101. return this.getPageProp('Contents');
  38102. },
  38103. get resources() {
  38104. // For robustness: The spec states that a \Resources entry has to be
  38105. // present, but can be empty. Some document omit it still, in this case
  38106. // we return an empty dictionary.
  38107. return shadow(this, 'resources', this.getInheritedPageProp('Resources'));
  38108. },
  38109. get mediaBox() {
  38110. var obj = this.getInheritedPageProp('MediaBox');
  38111. // Reset invalid media box to letter size.
  38112. if (!isArray(obj) || obj.length !== 4) {
  38113. obj = LETTER_SIZE_MEDIABOX;
  38114. }
  38115. return shadow(this, 'mediaBox', obj);
  38116. },
  38117. get view() {
  38118. var mediaBox = this.mediaBox;
  38119. var cropBox = this.getInheritedPageProp('CropBox');
  38120. if (!isArray(cropBox) || cropBox.length !== 4) {
  38121. return shadow(this, 'view', mediaBox);
  38122. }
  38123. // From the spec, 6th ed., p.963:
  38124. // "The crop, bleed, trim, and art boxes should not ordinarily
  38125. // extend beyond the boundaries of the media box. If they do, they are
  38126. // effectively reduced to their intersection with the media box."
  38127. cropBox = Util.intersect(cropBox, mediaBox);
  38128. if (!cropBox) {
  38129. return shadow(this, 'view', mediaBox);
  38130. }
  38131. return shadow(this, 'view', cropBox);
  38132. },
  38133. get rotate() {
  38134. var rotate = this.getInheritedPageProp('Rotate') || 0;
  38135. // Normalize rotation so it's a multiple of 90 and between 0 and 270
  38136. if (rotate % 90 !== 0) {
  38137. rotate = 0;
  38138. } else if (rotate >= 360) {
  38139. rotate = rotate % 360;
  38140. } else if (rotate < 0) {
  38141. // The spec doesn't cover negatives, assume its counterclockwise
  38142. // rotation. The following is the other implementation of modulo.
  38143. rotate = ((rotate % 360) + 360) % 360;
  38144. }
  38145. return shadow(this, 'rotate', rotate);
  38146. },
  38147. getContentStream: function Page_getContentStream() {
  38148. var content = this.content;
  38149. var stream;
  38150. if (isArray(content)) {
  38151. // fetching items
  38152. var xref = this.xref;
  38153. var i, n = content.length;
  38154. var streams = [];
  38155. for (i = 0; i < n; ++i) {
  38156. streams.push(xref.fetchIfRef(content[i]));
  38157. }
  38158. stream = new StreamsSequenceStream(streams);
  38159. } else if (isStream(content)) {
  38160. stream = content;
  38161. } else {
  38162. // replacing non-existent page content with empty one
  38163. stream = new NullStream();
  38164. }
  38165. return stream;
  38166. },
  38167. loadResources: function Page_loadResources(keys) {
  38168. if (!this.resourcesPromise) {
  38169. // TODO: add async getInheritedPageProp and remove this.
  38170. this.resourcesPromise = this.pdfManager.ensure(this, 'resources');
  38171. }
  38172. return this.resourcesPromise.then(function resourceSuccess() {
  38173. var objectLoader = new ObjectLoader(this.resources.map,
  38174. keys,
  38175. this.xref);
  38176. return objectLoader.load();
  38177. }.bind(this));
  38178. },
  38179. getOperatorList: function Page_getOperatorList(handler, task, intent) {
  38180. var self = this;
  38181. var pdfManager = this.pdfManager;
  38182. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  38183. []);
  38184. var resourcesPromise = this.loadResources([
  38185. 'ExtGState',
  38186. 'ColorSpace',
  38187. 'Pattern',
  38188. 'Shading',
  38189. 'XObject',
  38190. 'Font'
  38191. // ProcSet
  38192. // Properties
  38193. ]);
  38194. var partialEvaluator = new PartialEvaluator(pdfManager, this.xref,
  38195. handler, this.pageIndex,
  38196. 'p' + this.pageIndex + '_',
  38197. this.idCounters,
  38198. this.fontCache);
  38199. var dataPromises = Promise.all([contentStreamPromise, resourcesPromise]);
  38200. var pageListPromise = dataPromises.then(function(data) {
  38201. var contentStream = data[0];
  38202. var opList = new OperatorList(intent, handler, self.pageIndex);
  38203. handler.send('StartRenderPage', {
  38204. transparency: partialEvaluator.hasBlendModes(self.resources),
  38205. pageIndex: self.pageIndex,
  38206. intent: intent
  38207. });
  38208. return partialEvaluator.getOperatorList(contentStream, task,
  38209. self.resources, opList).then(function () {
  38210. return opList;
  38211. });
  38212. });
  38213. var annotationsPromise = pdfManager.ensure(this, 'annotations');
  38214. return Promise.all([pageListPromise, annotationsPromise]).then(
  38215. function(datas) {
  38216. var pageOpList = datas[0];
  38217. var annotations = datas[1];
  38218. if (annotations.length === 0) {
  38219. pageOpList.flush(true);
  38220. return pageOpList;
  38221. }
  38222. var annotationsReadyPromise = Annotation.appendToOperatorList(
  38223. annotations, pageOpList, partialEvaluator, task, intent);
  38224. return annotationsReadyPromise.then(function () {
  38225. pageOpList.flush(true);
  38226. return pageOpList;
  38227. });
  38228. });
  38229. },
  38230. extractTextContent: function Page_extractTextContent(task,
  38231. normalizeWhitespace) {
  38232. var handler = {
  38233. on: function nullHandlerOn() {},
  38234. send: function nullHandlerSend() {}
  38235. };
  38236. var self = this;
  38237. var pdfManager = this.pdfManager;
  38238. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  38239. []);
  38240. var resourcesPromise = this.loadResources([
  38241. 'ExtGState',
  38242. 'XObject',
  38243. 'Font'
  38244. ]);
  38245. var dataPromises = Promise.all([contentStreamPromise,
  38246. resourcesPromise]);
  38247. return dataPromises.then(function(data) {
  38248. var contentStream = data[0];
  38249. var partialEvaluator = new PartialEvaluator(pdfManager, self.xref,
  38250. handler, self.pageIndex,
  38251. 'p' + self.pageIndex + '_',
  38252. self.idCounters,
  38253. self.fontCache);
  38254. return partialEvaluator.getTextContent(contentStream,
  38255. task,
  38256. self.resources,
  38257. /* stateManager = */ null,
  38258. normalizeWhitespace);
  38259. });
  38260. },
  38261. getAnnotationsData: function Page_getAnnotationsData(intent) {
  38262. var annotations = this.annotations;
  38263. var annotationsData = [];
  38264. for (var i = 0, n = annotations.length; i < n; ++i) {
  38265. if (intent) {
  38266. if (!(intent === 'display' && annotations[i].viewable) &&
  38267. !(intent === 'print' && annotations[i].printable)) {
  38268. continue;
  38269. }
  38270. }
  38271. annotationsData.push(annotations[i].data);
  38272. }
  38273. return annotationsData;
  38274. },
  38275. get annotations() {
  38276. var annotations = [];
  38277. var annotationRefs = this.getInheritedPageProp('Annots') || [];
  38278. var annotationFactory = new AnnotationFactory();
  38279. for (var i = 0, n = annotationRefs.length; i < n; ++i) {
  38280. var annotationRef = annotationRefs[i];
  38281. var annotation = annotationFactory.create(this.xref, annotationRef);
  38282. if (annotation) {
  38283. annotations.push(annotation);
  38284. }
  38285. }
  38286. return shadow(this, 'annotations', annotations);
  38287. }
  38288. };
  38289. return Page;
  38290. })();
  38291. /**
  38292. * The `PDFDocument` holds all the data of the PDF file. Compared to the
  38293. * `PDFDoc`, this one doesn't have any job management code.
  38294. * Right now there exists one PDFDocument on the main thread + one object
  38295. * for each worker. If there is no worker support enabled, there are two
  38296. * `PDFDocument` objects on the main thread created.
  38297. */
  38298. var PDFDocument = (function PDFDocumentClosure() {
  38299. var FINGERPRINT_FIRST_BYTES = 1024;
  38300. var EMPTY_FINGERPRINT = '\x00\x00\x00\x00\x00\x00\x00' +
  38301. '\x00\x00\x00\x00\x00\x00\x00\x00\x00';
  38302. function PDFDocument(pdfManager, arg, password) {
  38303. if (isStream(arg)) {
  38304. init.call(this, pdfManager, arg, password);
  38305. } else if (isArrayBuffer(arg)) {
  38306. init.call(this, pdfManager, new Stream(arg), password);
  38307. } else {
  38308. error('PDFDocument: Unknown argument type');
  38309. }
  38310. }
  38311. function init(pdfManager, stream, password) {
  38312. assert(stream.length > 0, 'stream must have data');
  38313. this.pdfManager = pdfManager;
  38314. this.stream = stream;
  38315. var xref = new XRef(this.stream, password, pdfManager);
  38316. this.xref = xref;
  38317. }
  38318. function find(stream, needle, limit, backwards) {
  38319. var pos = stream.pos;
  38320. var end = stream.end;
  38321. var strBuf = [];
  38322. if (pos + limit > end) {
  38323. limit = end - pos;
  38324. }
  38325. for (var n = 0; n < limit; ++n) {
  38326. strBuf.push(String.fromCharCode(stream.getByte()));
  38327. }
  38328. var str = strBuf.join('');
  38329. stream.pos = pos;
  38330. var index = backwards ? str.lastIndexOf(needle) : str.indexOf(needle);
  38331. if (index === -1) {
  38332. return false; /* not found */
  38333. }
  38334. stream.pos += index;
  38335. return true; /* found */
  38336. }
  38337. var DocumentInfoValidators = {
  38338. get entries() {
  38339. // Lazily build this since all the validation functions below are not
  38340. // defined until after this file loads.
  38341. return shadow(this, 'entries', {
  38342. Title: isString,
  38343. Author: isString,
  38344. Subject: isString,
  38345. Keywords: isString,
  38346. Creator: isString,
  38347. Producer: isString,
  38348. CreationDate: isString,
  38349. ModDate: isString,
  38350. Trapped: isName
  38351. });
  38352. }
  38353. };
  38354. PDFDocument.prototype = {
  38355. parse: function PDFDocument_parse(recoveryMode) {
  38356. this.setup(recoveryMode);
  38357. var version = this.catalog.catDict.get('Version');
  38358. if (isName(version)) {
  38359. this.pdfFormatVersion = version.name;
  38360. }
  38361. try {
  38362. // checking if AcroForm is present
  38363. this.acroForm = this.catalog.catDict.get('AcroForm');
  38364. if (this.acroForm) {
  38365. this.xfa = this.acroForm.get('XFA');
  38366. var fields = this.acroForm.get('Fields');
  38367. if ((!fields || !isArray(fields) || fields.length === 0) &&
  38368. !this.xfa) {
  38369. // no fields and no XFA -- not a form (?)
  38370. this.acroForm = null;
  38371. }
  38372. }
  38373. } catch (ex) {
  38374. info('Something wrong with AcroForm entry');
  38375. this.acroForm = null;
  38376. }
  38377. },
  38378. get linearization() {
  38379. var linearization = null;
  38380. if (this.stream.length) {
  38381. try {
  38382. linearization = Linearization.create(this.stream);
  38383. } catch (err) {
  38384. if (err instanceof MissingDataException) {
  38385. throw err;
  38386. }
  38387. info(err);
  38388. }
  38389. }
  38390. // shadow the prototype getter with a data property
  38391. return shadow(this, 'linearization', linearization);
  38392. },
  38393. get startXRef() {
  38394. var stream = this.stream;
  38395. var startXRef = 0;
  38396. var linearization = this.linearization;
  38397. if (linearization) {
  38398. // Find end of first obj.
  38399. stream.reset();
  38400. if (find(stream, 'endobj', 1024)) {
  38401. startXRef = stream.pos + 6;
  38402. }
  38403. } else {
  38404. // Find startxref by jumping backward from the end of the file.
  38405. var step = 1024;
  38406. var found = false, pos = stream.end;
  38407. while (!found && pos > 0) {
  38408. pos -= step - 'startxref'.length;
  38409. if (pos < 0) {
  38410. pos = 0;
  38411. }
  38412. stream.pos = pos;
  38413. found = find(stream, 'startxref', step, true);
  38414. }
  38415. if (found) {
  38416. stream.skip(9);
  38417. var ch;
  38418. do {
  38419. ch = stream.getByte();
  38420. } while (Lexer.isSpace(ch));
  38421. var str = '';
  38422. while (ch >= 0x20 && ch <= 0x39) { // < '9'
  38423. str += String.fromCharCode(ch);
  38424. ch = stream.getByte();
  38425. }
  38426. startXRef = parseInt(str, 10);
  38427. if (isNaN(startXRef)) {
  38428. startXRef = 0;
  38429. }
  38430. }
  38431. }
  38432. // shadow the prototype getter with a data property
  38433. return shadow(this, 'startXRef', startXRef);
  38434. },
  38435. get mainXRefEntriesOffset() {
  38436. var mainXRefEntriesOffset = 0;
  38437. var linearization = this.linearization;
  38438. if (linearization) {
  38439. mainXRefEntriesOffset = linearization.mainXRefEntriesOffset;
  38440. }
  38441. // shadow the prototype getter with a data property
  38442. return shadow(this, 'mainXRefEntriesOffset', mainXRefEntriesOffset);
  38443. },
  38444. // Find the header, remove leading garbage and setup the stream
  38445. // starting from the header.
  38446. checkHeader: function PDFDocument_checkHeader() {
  38447. var stream = this.stream;
  38448. stream.reset();
  38449. if (find(stream, '%PDF-', 1024)) {
  38450. // Found the header, trim off any garbage before it.
  38451. stream.moveStart();
  38452. // Reading file format version
  38453. var MAX_VERSION_LENGTH = 12;
  38454. var version = '', ch;
  38455. while ((ch = stream.getByte()) > 0x20) { // SPACE
  38456. if (version.length >= MAX_VERSION_LENGTH) {
  38457. break;
  38458. }
  38459. version += String.fromCharCode(ch);
  38460. }
  38461. if (!this.pdfFormatVersion) {
  38462. // removing "%PDF-"-prefix
  38463. this.pdfFormatVersion = version.substring(5);
  38464. }
  38465. return;
  38466. }
  38467. // May not be a PDF file, continue anyway.
  38468. },
  38469. parseStartXRef: function PDFDocument_parseStartXRef() {
  38470. var startXRef = this.startXRef;
  38471. this.xref.setStartXRef(startXRef);
  38472. },
  38473. setup: function PDFDocument_setup(recoveryMode) {
  38474. this.xref.parse(recoveryMode);
  38475. var self = this;
  38476. var pageFactory = {
  38477. createPage: function (pageIndex, dict, ref, fontCache) {
  38478. return new Page(self.pdfManager, self.xref, pageIndex, dict, ref,
  38479. fontCache);
  38480. }
  38481. };
  38482. this.catalog = new Catalog(this.pdfManager, this.xref, pageFactory);
  38483. },
  38484. get numPages() {
  38485. var linearization = this.linearization;
  38486. var num = linearization ? linearization.numPages : this.catalog.numPages;
  38487. // shadow the prototype getter
  38488. return shadow(this, 'numPages', num);
  38489. },
  38490. get documentInfo() {
  38491. var docInfo = {
  38492. PDFFormatVersion: this.pdfFormatVersion,
  38493. IsAcroFormPresent: !!this.acroForm,
  38494. IsXFAPresent: !!this.xfa
  38495. };
  38496. var infoDict;
  38497. try {
  38498. infoDict = this.xref.trailer.get('Info');
  38499. } catch (err) {
  38500. info('The document information dictionary is invalid.');
  38501. }
  38502. if (infoDict) {
  38503. var validEntries = DocumentInfoValidators.entries;
  38504. // Only fill the document info with valid entries from the spec.
  38505. for (var key in validEntries) {
  38506. if (infoDict.has(key)) {
  38507. var value = infoDict.get(key);
  38508. // Make sure the value conforms to the spec.
  38509. if (validEntries[key](value)) {
  38510. docInfo[key] = (typeof value !== 'string' ?
  38511. value : stringToPDFString(value));
  38512. } else {
  38513. info('Bad value in document info for "' + key + '"');
  38514. }
  38515. }
  38516. }
  38517. }
  38518. return shadow(this, 'documentInfo', docInfo);
  38519. },
  38520. get fingerprint() {
  38521. var xref = this.xref, hash, fileID = '';
  38522. var idArray = xref.trailer.get('ID');
  38523. if (idArray && isArray(idArray) && idArray[0] && isString(idArray[0]) &&
  38524. idArray[0] !== EMPTY_FINGERPRINT) {
  38525. hash = stringToBytes(idArray[0]);
  38526. } else {
  38527. if (this.stream.ensureRange) {
  38528. this.stream.ensureRange(0,
  38529. Math.min(FINGERPRINT_FIRST_BYTES, this.stream.end));
  38530. }
  38531. hash = calculateMD5(this.stream.bytes.subarray(0,
  38532. FINGERPRINT_FIRST_BYTES), 0, FINGERPRINT_FIRST_BYTES);
  38533. }
  38534. for (var i = 0, n = hash.length; i < n; i++) {
  38535. var hex = hash[i].toString(16);
  38536. fileID += hex.length === 1 ? '0' + hex : hex;
  38537. }
  38538. return shadow(this, 'fingerprint', fileID);
  38539. },
  38540. getPage: function PDFDocument_getPage(pageIndex) {
  38541. return this.catalog.getPage(pageIndex);
  38542. },
  38543. cleanup: function PDFDocument_cleanup() {
  38544. return this.catalog.cleanup();
  38545. }
  38546. };
  38547. return PDFDocument;
  38548. })();
  38549. exports.Page = Page;
  38550. exports.PDFDocument = PDFDocument;
  38551. }));
  38552. (function (root, factory) {
  38553. {
  38554. factory((root.pdfjsCorePdfManager = {}), root.pdfjsSharedUtil,
  38555. root.pdfjsCoreStream, root.pdfjsCoreChunkedStream,
  38556. root.pdfjsCoreDocument);
  38557. }
  38558. }(this, function (exports, sharedUtil, coreStream, coreChunkedStream,
  38559. coreDocument) {
  38560. var NotImplementedException = sharedUtil.NotImplementedException;
  38561. var MissingDataException = sharedUtil.MissingDataException;
  38562. var createPromiseCapability = sharedUtil.createPromiseCapability;
  38563. var Util = sharedUtil.Util;
  38564. var Stream = coreStream.Stream;
  38565. var ChunkedStreamManager = coreChunkedStream.ChunkedStreamManager;
  38566. var PDFDocument = coreDocument.PDFDocument;
  38567. var BasePdfManager = (function BasePdfManagerClosure() {
  38568. function BasePdfManager() {
  38569. throw new Error('Cannot initialize BaseManagerManager');
  38570. }
  38571. BasePdfManager.prototype = {
  38572. get docId() {
  38573. return this._docId;
  38574. },
  38575. onLoadedStream: function BasePdfManager_onLoadedStream() {
  38576. throw new NotImplementedException();
  38577. },
  38578. ensureDoc: function BasePdfManager_ensureDoc(prop, args) {
  38579. return this.ensure(this.pdfDocument, prop, args);
  38580. },
  38581. ensureXRef: function BasePdfManager_ensureXRef(prop, args) {
  38582. return this.ensure(this.pdfDocument.xref, prop, args);
  38583. },
  38584. ensureCatalog: function BasePdfManager_ensureCatalog(prop, args) {
  38585. return this.ensure(this.pdfDocument.catalog, prop, args);
  38586. },
  38587. getPage: function BasePdfManager_getPage(pageIndex) {
  38588. return this.pdfDocument.getPage(pageIndex);
  38589. },
  38590. cleanup: function BasePdfManager_cleanup() {
  38591. return this.pdfDocument.cleanup();
  38592. },
  38593. ensure: function BasePdfManager_ensure(obj, prop, args) {
  38594. return new NotImplementedException();
  38595. },
  38596. requestRange: function BasePdfManager_requestRange(begin, end) {
  38597. return new NotImplementedException();
  38598. },
  38599. requestLoadedStream: function BasePdfManager_requestLoadedStream() {
  38600. return new NotImplementedException();
  38601. },
  38602. sendProgressiveData: function BasePdfManager_sendProgressiveData(chunk) {
  38603. return new NotImplementedException();
  38604. },
  38605. updatePassword: function BasePdfManager_updatePassword(password) {
  38606. this.pdfDocument.xref.password = this.password = password;
  38607. if (this._passwordChangedCapability) {
  38608. this._passwordChangedCapability.resolve();
  38609. }
  38610. },
  38611. passwordChanged: function BasePdfManager_passwordChanged() {
  38612. this._passwordChangedCapability = createPromiseCapability();
  38613. return this._passwordChangedCapability.promise;
  38614. },
  38615. terminate: function BasePdfManager_terminate() {
  38616. return new NotImplementedException();
  38617. }
  38618. };
  38619. return BasePdfManager;
  38620. })();
  38621. var LocalPdfManager = (function LocalPdfManagerClosure() {
  38622. function LocalPdfManager(docId, data, password) {
  38623. this._docId = docId;
  38624. var stream = new Stream(data);
  38625. this.pdfDocument = new PDFDocument(this, stream, password);
  38626. this._loadedStreamCapability = createPromiseCapability();
  38627. this._loadedStreamCapability.resolve(stream);
  38628. }
  38629. Util.inherit(LocalPdfManager, BasePdfManager, {
  38630. ensure: function LocalPdfManager_ensure(obj, prop, args) {
  38631. return new Promise(function (resolve, reject) {
  38632. try {
  38633. var value = obj[prop];
  38634. var result;
  38635. if (typeof value === 'function') {
  38636. result = value.apply(obj, args);
  38637. } else {
  38638. result = value;
  38639. }
  38640. resolve(result);
  38641. } catch (e) {
  38642. reject(e);
  38643. }
  38644. });
  38645. },
  38646. requestRange: function LocalPdfManager_requestRange(begin, end) {
  38647. return Promise.resolve();
  38648. },
  38649. requestLoadedStream: function LocalPdfManager_requestLoadedStream() {
  38650. return;
  38651. },
  38652. onLoadedStream: function LocalPdfManager_onLoadedStream() {
  38653. return this._loadedStreamCapability.promise;
  38654. },
  38655. terminate: function LocalPdfManager_terminate() {
  38656. return;
  38657. }
  38658. });
  38659. return LocalPdfManager;
  38660. })();
  38661. var NetworkPdfManager = (function NetworkPdfManagerClosure() {
  38662. function NetworkPdfManager(docId, args, msgHandler) {
  38663. this._docId = docId;
  38664. this.msgHandler = msgHandler;
  38665. var params = {
  38666. msgHandler: msgHandler,
  38667. httpHeaders: args.httpHeaders,
  38668. withCredentials: args.withCredentials,
  38669. chunkedViewerLoading: args.chunkedViewerLoading,
  38670. disableAutoFetch: args.disableAutoFetch,
  38671. initialData: args.initialData
  38672. };
  38673. this.streamManager = new ChunkedStreamManager(args.length,
  38674. args.rangeChunkSize,
  38675. args.url, params);
  38676. this.pdfDocument = new PDFDocument(this, this.streamManager.getStream(),
  38677. args.password);
  38678. }
  38679. Util.inherit(NetworkPdfManager, BasePdfManager, {
  38680. ensure: function NetworkPdfManager_ensure(obj, prop, args) {
  38681. var pdfManager = this;
  38682. return new Promise(function (resolve, reject) {
  38683. function ensureHelper() {
  38684. try {
  38685. var result;
  38686. var value = obj[prop];
  38687. if (typeof value === 'function') {
  38688. result = value.apply(obj, args);
  38689. } else {
  38690. result = value;
  38691. }
  38692. resolve(result);
  38693. } catch(e) {
  38694. if (!(e instanceof MissingDataException)) {
  38695. reject(e);
  38696. return;
  38697. }
  38698. pdfManager.streamManager.requestRange(e.begin, e.end).
  38699. then(ensureHelper, reject);
  38700. }
  38701. }
  38702. ensureHelper();
  38703. });
  38704. },
  38705. requestRange: function NetworkPdfManager_requestRange(begin, end) {
  38706. return this.streamManager.requestRange(begin, end);
  38707. },
  38708. requestLoadedStream: function NetworkPdfManager_requestLoadedStream() {
  38709. this.streamManager.requestAllChunks();
  38710. },
  38711. sendProgressiveData:
  38712. function NetworkPdfManager_sendProgressiveData(chunk) {
  38713. this.streamManager.onReceiveData({ chunk: chunk });
  38714. },
  38715. onLoadedStream: function NetworkPdfManager_onLoadedStream() {
  38716. return this.streamManager.onLoadedStream();
  38717. },
  38718. terminate: function NetworkPdfManager_terminate() {
  38719. this.streamManager.abort();
  38720. }
  38721. });
  38722. return NetworkPdfManager;
  38723. })();
  38724. exports.LocalPdfManager = LocalPdfManager;
  38725. exports.NetworkPdfManager = NetworkPdfManager;
  38726. }));
  38727. (function (root, factory) {
  38728. {
  38729. factory((root.pdfjsCoreWorker = {}), root.pdfjsSharedUtil,
  38730. root.pdfjsCorePrimitives, root.pdfjsCorePdfManager,
  38731. root.pdfjsSharedGlobal);
  38732. }
  38733. }(this, function (exports, sharedUtil, corePrimitives, corePdfManager,
  38734. sharedGlobal) {
  38735. var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  38736. var InvalidPDFException = sharedUtil.InvalidPDFException;
  38737. var MessageHandler = sharedUtil.MessageHandler;
  38738. var MissingPDFException = sharedUtil.MissingPDFException;
  38739. var UnexpectedResponseException = sharedUtil.UnexpectedResponseException;
  38740. var PasswordException = sharedUtil.PasswordException;
  38741. var PasswordResponses = sharedUtil.PasswordResponses;
  38742. var UnknownErrorException = sharedUtil.UnknownErrorException;
  38743. var XRefParseException = sharedUtil.XRefParseException;
  38744. var createPromiseCapability = sharedUtil.createPromiseCapability;
  38745. var error = sharedUtil.error;
  38746. var info = sharedUtil.info;
  38747. var isInt = sharedUtil.isInt;
  38748. var warn = sharedUtil.warn;
  38749. var Ref = corePrimitives.Ref;
  38750. var LocalPdfManager = corePdfManager.LocalPdfManager;
  38751. var NetworkPdfManager = corePdfManager.NetworkPdfManager;
  38752. var globalScope = sharedGlobal.globalScope;
  38753. var PDFJS = sharedGlobal.PDFJS;
  38754. var WorkerTask = (function WorkerTaskClosure() {
  38755. function WorkerTask(name) {
  38756. this.name = name;
  38757. this.terminated = false;
  38758. this._capability = createPromiseCapability();
  38759. }
  38760. WorkerTask.prototype = {
  38761. get finished() {
  38762. return this._capability.promise;
  38763. },
  38764. finish: function () {
  38765. this._capability.resolve();
  38766. },
  38767. terminate: function () {
  38768. this.terminated = true;
  38769. },
  38770. ensureNotTerminated: function () {
  38771. if (this.terminated) {
  38772. throw new Error('Worker task was terminated');
  38773. }
  38774. }
  38775. };
  38776. return WorkerTask;
  38777. })();
  38778. var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
  38779. setup: function wphSetup(handler, port) {
  38780. var testMessageProcessed = false;
  38781. handler.on('test', function wphSetupTest(data) {
  38782. if (testMessageProcessed) {
  38783. return; // we already processed 'test' message once
  38784. }
  38785. testMessageProcessed = true;
  38786. // check if Uint8Array can be sent to worker
  38787. if (!(data instanceof Uint8Array)) {
  38788. handler.send('test', 'main', false);
  38789. return;
  38790. }
  38791. // making sure postMessage transfers are working
  38792. var supportTransfers = data[0] === 255;
  38793. handler.postMessageTransfers = supportTransfers;
  38794. // check if the response property is supported by xhr
  38795. var xhr = new XMLHttpRequest();
  38796. var responseExists = 'response' in xhr;
  38797. // check if the property is actually implemented
  38798. try {
  38799. var dummy = xhr.responseType;
  38800. } catch (e) {
  38801. responseExists = false;
  38802. }
  38803. if (!responseExists) {
  38804. handler.send('test', false);
  38805. return;
  38806. }
  38807. handler.send('test', {
  38808. supportTypedArray: true,
  38809. supportTransfers: supportTransfers
  38810. });
  38811. });
  38812. handler.on('GetDocRequest', function wphSetupDoc(data) {
  38813. return WorkerMessageHandler.createDocumentHandler(data, port);
  38814. });
  38815. },
  38816. createDocumentHandler: function wphCreateDocumentHandler(docParams, port) {
  38817. // This context is actually holds references on pdfManager and handler,
  38818. // until the latter is destroyed.
  38819. var pdfManager;
  38820. var terminated = false;
  38821. var cancelXHRs = null;
  38822. var WorkerTasks = [];
  38823. var docId = docParams.docId;
  38824. var workerHandlerName = docParams.docId + '_worker';
  38825. var handler = new MessageHandler(workerHandlerName, docId, port);
  38826. function ensureNotTerminated() {
  38827. if (terminated) {
  38828. throw new Error('Worker was terminated');
  38829. }
  38830. }
  38831. function startWorkerTask(task) {
  38832. WorkerTasks.push(task);
  38833. }
  38834. function finishWorkerTask(task) {
  38835. task.finish();
  38836. var i = WorkerTasks.indexOf(task);
  38837. WorkerTasks.splice(i, 1);
  38838. }
  38839. function loadDocument(recoveryMode) {
  38840. var loadDocumentCapability = createPromiseCapability();
  38841. var parseSuccess = function parseSuccess() {
  38842. var numPagesPromise = pdfManager.ensureDoc('numPages');
  38843. var fingerprintPromise = pdfManager.ensureDoc('fingerprint');
  38844. var encryptedPromise = pdfManager.ensureXRef('encrypt');
  38845. Promise.all([numPagesPromise, fingerprintPromise,
  38846. encryptedPromise]).then(function onDocReady(results) {
  38847. var doc = {
  38848. numPages: results[0],
  38849. fingerprint: results[1],
  38850. encrypted: !!results[2],
  38851. };
  38852. loadDocumentCapability.resolve(doc);
  38853. },
  38854. parseFailure);
  38855. };
  38856. var parseFailure = function parseFailure(e) {
  38857. loadDocumentCapability.reject(e);
  38858. };
  38859. pdfManager.ensureDoc('checkHeader', []).then(function() {
  38860. pdfManager.ensureDoc('parseStartXRef', []).then(function() {
  38861. pdfManager.ensureDoc('parse', [recoveryMode]).then(
  38862. parseSuccess, parseFailure);
  38863. }, parseFailure);
  38864. }, parseFailure);
  38865. return loadDocumentCapability.promise;
  38866. }
  38867. function getPdfManager(data) {
  38868. var pdfManagerCapability = createPromiseCapability();
  38869. var pdfManager;
  38870. var source = data.source;
  38871. var disableRange = data.disableRange;
  38872. if (source.data) {
  38873. try {
  38874. pdfManager = new LocalPdfManager(docId, source.data, source.password);
  38875. pdfManagerCapability.resolve(pdfManager);
  38876. } catch (ex) {
  38877. pdfManagerCapability.reject(ex);
  38878. }
  38879. return pdfManagerCapability.promise;
  38880. } else if (source.chunkedViewerLoading) {
  38881. try {
  38882. pdfManager = new NetworkPdfManager(docId, source, handler);
  38883. pdfManagerCapability.resolve(pdfManager);
  38884. } catch (ex) {
  38885. pdfManagerCapability.reject(ex);
  38886. }
  38887. return pdfManagerCapability.promise;
  38888. }
  38889. var networkManager = new NetworkManager(source.url, {
  38890. httpHeaders: source.httpHeaders,
  38891. withCredentials: source.withCredentials
  38892. });
  38893. var cachedChunks = [];
  38894. var fullRequestXhrId = networkManager.requestFull({
  38895. onHeadersReceived: function onHeadersReceived() {
  38896. if (disableRange) {
  38897. return;
  38898. }
  38899. var fullRequestXhr = networkManager.getRequestXhr(fullRequestXhrId);
  38900. if (fullRequestXhr.getResponseHeader('Accept-Ranges') !== 'bytes') {
  38901. return;
  38902. }
  38903. var contentEncoding =
  38904. fullRequestXhr.getResponseHeader('Content-Encoding') || 'identity';
  38905. if (contentEncoding !== 'identity') {
  38906. return;
  38907. }
  38908. var length = fullRequestXhr.getResponseHeader('Content-Length');
  38909. length = parseInt(length, 10);
  38910. if (!isInt(length)) {
  38911. return;
  38912. }
  38913. source.length = length;
  38914. if (length <= 2 * source.rangeChunkSize) {
  38915. // The file size is smaller than the size of two chunks, so it does
  38916. // not make any sense to abort the request and retry with a range
  38917. // request.
  38918. return;
  38919. }
  38920. if (networkManager.isStreamingRequest(fullRequestXhrId)) {
  38921. // We can continue fetching when progressive loading is enabled,
  38922. // and we don't need the autoFetch feature.
  38923. source.disableAutoFetch = true;
  38924. } else {
  38925. // NOTE: by cancelling the full request, and then issuing range
  38926. // requests, there will be an issue for sites where you can only
  38927. // request the pdf once. However, if this is the case, then the
  38928. // server should not be returning that it can support range
  38929. // requests.
  38930. networkManager.abortRequest(fullRequestXhrId);
  38931. }
  38932. try {
  38933. pdfManager = new NetworkPdfManager(docId, source, handler);
  38934. pdfManagerCapability.resolve(pdfManager);
  38935. } catch (ex) {
  38936. pdfManagerCapability.reject(ex);
  38937. }
  38938. cancelXHRs = null;
  38939. },
  38940. onProgressiveData: source.disableStream ? null :
  38941. function onProgressiveData(chunk) {
  38942. if (!pdfManager) {
  38943. cachedChunks.push(chunk);
  38944. return;
  38945. }
  38946. pdfManager.sendProgressiveData(chunk);
  38947. },
  38948. onDone: function onDone(args) {
  38949. if (pdfManager) {
  38950. return; // already processed
  38951. }
  38952. var pdfFile;
  38953. if (args === null) {
  38954. // TODO add some streaming manager, e.g. for unknown length files.
  38955. // The data was returned in the onProgressiveData, combining...
  38956. var pdfFileLength = 0, pos = 0;
  38957. cachedChunks.forEach(function (chunk) {
  38958. pdfFileLength += chunk.byteLength;
  38959. });
  38960. if (source.length && pdfFileLength !== source.length) {
  38961. warn('reported HTTP length is different from actual');
  38962. }
  38963. var pdfFileArray = new Uint8Array(pdfFileLength);
  38964. cachedChunks.forEach(function (chunk) {
  38965. pdfFileArray.set(new Uint8Array(chunk), pos);
  38966. pos += chunk.byteLength;
  38967. });
  38968. pdfFile = pdfFileArray.buffer;
  38969. } else {
  38970. pdfFile = args.chunk;
  38971. }
  38972. // the data is array, instantiating directly from it
  38973. try {
  38974. pdfManager = new LocalPdfManager(docId, pdfFile, source.password);
  38975. pdfManagerCapability.resolve(pdfManager);
  38976. } catch (ex) {
  38977. pdfManagerCapability.reject(ex);
  38978. }
  38979. cancelXHRs = null;
  38980. },
  38981. onError: function onError(status) {
  38982. var exception;
  38983. if (status === 404 || status === 0 && /^file:/.test(source.url)) {
  38984. exception = new MissingPDFException('Missing PDF "' +
  38985. source.url + '".');
  38986. handler.send('MissingPDF', exception);
  38987. } else {
  38988. exception = new UnexpectedResponseException(
  38989. 'Unexpected server response (' + status +
  38990. ') while retrieving PDF "' + source.url + '".', status);
  38991. handler.send('UnexpectedResponse', exception);
  38992. }
  38993. cancelXHRs = null;
  38994. },
  38995. onProgress: function onProgress(evt) {
  38996. handler.send('DocProgress', {
  38997. loaded: evt.loaded,
  38998. total: evt.lengthComputable ? evt.total : source.length
  38999. });
  39000. }
  39001. });
  39002. cancelXHRs = function () {
  39003. networkManager.abortRequest(fullRequestXhrId);
  39004. };
  39005. return pdfManagerCapability.promise;
  39006. }
  39007. var setupDoc = function(data) {
  39008. var onSuccess = function(doc) {
  39009. ensureNotTerminated();
  39010. handler.send('GetDoc', { pdfInfo: doc });
  39011. };
  39012. var onFailure = function(e) {
  39013. if (e instanceof PasswordException) {
  39014. if (e.code === PasswordResponses.NEED_PASSWORD) {
  39015. handler.send('NeedPassword', e);
  39016. } else if (e.code === PasswordResponses.INCORRECT_PASSWORD) {
  39017. handler.send('IncorrectPassword', e);
  39018. }
  39019. } else if (e instanceof InvalidPDFException) {
  39020. handler.send('InvalidPDF', e);
  39021. } else if (e instanceof MissingPDFException) {
  39022. handler.send('MissingPDF', e);
  39023. } else if (e instanceof UnexpectedResponseException) {
  39024. handler.send('UnexpectedResponse', e);
  39025. } else {
  39026. handler.send('UnknownError',
  39027. new UnknownErrorException(e.message, e.toString()));
  39028. }
  39029. };
  39030. ensureNotTerminated();
  39031. PDFJS.maxImageSize = data.maxImageSize === undefined ?
  39032. -1 : data.maxImageSize;
  39033. PDFJS.disableFontFace = data.disableFontFace;
  39034. PDFJS.disableCreateObjectURL = data.disableCreateObjectURL;
  39035. PDFJS.verbosity = data.verbosity;
  39036. PDFJS.cMapUrl = data.cMapUrl === undefined ?
  39037. null : data.cMapUrl;
  39038. PDFJS.cMapPacked = data.cMapPacked === true;
  39039. getPdfManager(data).then(function (newPdfManager) {
  39040. if (terminated) {
  39041. // We were in a process of setting up the manager, but it got
  39042. // terminated in the middle.
  39043. newPdfManager.terminate();
  39044. throw new Error('Worker was terminated');
  39045. }
  39046. pdfManager = newPdfManager;
  39047. handler.send('PDFManagerReady', null);
  39048. pdfManager.onLoadedStream().then(function(stream) {
  39049. handler.send('DataLoaded', { length: stream.bytes.byteLength });
  39050. });
  39051. }).then(function pdfManagerReady() {
  39052. ensureNotTerminated();
  39053. loadDocument(false).then(onSuccess, function loadFailure(ex) {
  39054. ensureNotTerminated();
  39055. // Try again with recoveryMode == true
  39056. if (!(ex instanceof XRefParseException)) {
  39057. if (ex instanceof PasswordException) {
  39058. // after password exception prepare to receive a new password
  39059. // to repeat loading
  39060. pdfManager.passwordChanged().then(pdfManagerReady);
  39061. }
  39062. onFailure(ex);
  39063. return;
  39064. }
  39065. pdfManager.requestLoadedStream();
  39066. pdfManager.onLoadedStream().then(function() {
  39067. ensureNotTerminated();
  39068. loadDocument(true).then(onSuccess, onFailure);
  39069. });
  39070. }, onFailure);
  39071. }, onFailure);
  39072. };
  39073. handler.on('GetPage', function wphSetupGetPage(data) {
  39074. return pdfManager.getPage(data.pageIndex).then(function(page) {
  39075. var rotatePromise = pdfManager.ensure(page, 'rotate');
  39076. var refPromise = pdfManager.ensure(page, 'ref');
  39077. var viewPromise = pdfManager.ensure(page, 'view');
  39078. return Promise.all([rotatePromise, refPromise, viewPromise]).then(
  39079. function(results) {
  39080. return {
  39081. rotate: results[0],
  39082. ref: results[1],
  39083. view: results[2]
  39084. };
  39085. });
  39086. });
  39087. });
  39088. handler.on('GetPageIndex', function wphSetupGetPageIndex(data) {
  39089. var ref = new Ref(data.ref.num, data.ref.gen);
  39090. var catalog = pdfManager.pdfDocument.catalog;
  39091. return catalog.getPageIndex(ref);
  39092. });
  39093. handler.on('GetDestinations',
  39094. function wphSetupGetDestinations(data) {
  39095. return pdfManager.ensureCatalog('destinations');
  39096. }
  39097. );
  39098. handler.on('GetDestination',
  39099. function wphSetupGetDestination(data) {
  39100. return pdfManager.ensureCatalog('getDestination', [data.id]);
  39101. }
  39102. );
  39103. handler.on('GetPageLabels',
  39104. function wphSetupGetPageLabels(data) {
  39105. return pdfManager.ensureCatalog('pageLabels');
  39106. }
  39107. );
  39108. handler.on('GetAttachments',
  39109. function wphSetupGetAttachments(data) {
  39110. return pdfManager.ensureCatalog('attachments');
  39111. }
  39112. );
  39113. handler.on('GetJavaScript',
  39114. function wphSetupGetJavaScript(data) {
  39115. return pdfManager.ensureCatalog('javaScript');
  39116. }
  39117. );
  39118. handler.on('GetOutline',
  39119. function wphSetupGetOutline(data) {
  39120. return pdfManager.ensureCatalog('documentOutline');
  39121. }
  39122. );
  39123. handler.on('GetMetadata',
  39124. function wphSetupGetMetadata(data) {
  39125. return Promise.all([pdfManager.ensureDoc('documentInfo'),
  39126. pdfManager.ensureCatalog('metadata')]);
  39127. }
  39128. );
  39129. handler.on('GetData', function wphSetupGetData(data) {
  39130. pdfManager.requestLoadedStream();
  39131. return pdfManager.onLoadedStream().then(function(stream) {
  39132. return stream.bytes;
  39133. });
  39134. });
  39135. handler.on('GetStats',
  39136. function wphSetupGetStats(data) {
  39137. return pdfManager.pdfDocument.xref.stats;
  39138. }
  39139. );
  39140. handler.on('UpdatePassword', function wphSetupUpdatePassword(data) {
  39141. pdfManager.updatePassword(data);
  39142. });
  39143. handler.on('GetAnnotations', function wphSetupGetAnnotations(data) {
  39144. return pdfManager.getPage(data.pageIndex).then(function(page) {
  39145. return pdfManager.ensure(page, 'getAnnotationsData', [data.intent]);
  39146. });
  39147. });
  39148. handler.on('RenderPageRequest', function wphSetupRenderPage(data) {
  39149. var pageIndex = data.pageIndex;
  39150. pdfManager.getPage(pageIndex).then(function(page) {
  39151. var task = new WorkerTask('RenderPageRequest: page ' + pageIndex);
  39152. startWorkerTask(task);
  39153. var pageNum = pageIndex + 1;
  39154. var start = Date.now();
  39155. // Pre compile the pdf page and fetch the fonts/images.
  39156. page.getOperatorList(handler, task, data.intent).then(
  39157. function(operatorList) {
  39158. finishWorkerTask(task);
  39159. info('page=' + pageNum + ' - getOperatorList: time=' +
  39160. (Date.now() - start) + 'ms, len=' + operatorList.totalLength);
  39161. }, function(e) {
  39162. finishWorkerTask(task);
  39163. if (task.terminated) {
  39164. return; // ignoring errors from the terminated thread
  39165. }
  39166. // For compatibility with older behavior, generating unknown
  39167. // unsupported feature notification on errors.
  39168. handler.send('UnsupportedFeature',
  39169. {featureId: UNSUPPORTED_FEATURES.unknown});
  39170. var minimumStackMessage =
  39171. 'worker.js: while trying to getPage() and getOperatorList()';
  39172. var wrappedException;
  39173. // Turn the error into an obj that can be serialized
  39174. if (typeof e === 'string') {
  39175. wrappedException = {
  39176. message: e,
  39177. stack: minimumStackMessage
  39178. };
  39179. } else if (typeof e === 'object') {
  39180. wrappedException = {
  39181. message: e.message || e.toString(),
  39182. stack: e.stack || minimumStackMessage
  39183. };
  39184. } else {
  39185. wrappedException = {
  39186. message: 'Unknown exception type: ' + (typeof e),
  39187. stack: minimumStackMessage
  39188. };
  39189. }
  39190. handler.send('PageError', {
  39191. pageNum: pageNum,
  39192. error: wrappedException,
  39193. intent: data.intent
  39194. });
  39195. });
  39196. });
  39197. }, this);
  39198. handler.on('GetTextContent', function wphExtractText(data) {
  39199. var pageIndex = data.pageIndex;
  39200. var normalizeWhitespace = data.normalizeWhitespace;
  39201. return pdfManager.getPage(pageIndex).then(function(page) {
  39202. var task = new WorkerTask('GetTextContent: page ' + pageIndex);
  39203. startWorkerTask(task);
  39204. var pageNum = pageIndex + 1;
  39205. var start = Date.now();
  39206. return page.extractTextContent(task, normalizeWhitespace).then(
  39207. function(textContent) {
  39208. finishWorkerTask(task);
  39209. info('text indexing: page=' + pageNum + ' - time=' +
  39210. (Date.now() - start) + 'ms');
  39211. return textContent;
  39212. }, function (reason) {
  39213. finishWorkerTask(task);
  39214. if (task.terminated) {
  39215. return; // ignoring errors from the terminated thread
  39216. }
  39217. throw reason;
  39218. });
  39219. });
  39220. });
  39221. handler.on('Cleanup', function wphCleanup(data) {
  39222. return pdfManager.cleanup();
  39223. });
  39224. handler.on('Terminate', function wphTerminate(data) {
  39225. terminated = true;
  39226. if (pdfManager) {
  39227. pdfManager.terminate();
  39228. pdfManager = null;
  39229. }
  39230. if (cancelXHRs) {
  39231. cancelXHRs();
  39232. }
  39233. var waitOn = [];
  39234. WorkerTasks.forEach(function (task) {
  39235. waitOn.push(task.finished);
  39236. task.terminate();
  39237. });
  39238. return Promise.all(waitOn).then(function () {
  39239. // Notice that even if we destroying handler, resolved response promise
  39240. // must be sent back.
  39241. handler.destroy();
  39242. handler = null;
  39243. });
  39244. });
  39245. handler.on('Ready', function wphReady(data) {
  39246. setupDoc(docParams);
  39247. docParams = null; // we don't need docParams anymore -- saving memory.
  39248. });
  39249. return workerHandlerName;
  39250. }
  39251. };
  39252. function initializeWorker() {
  39253. if (!('console' in globalScope)) {
  39254. var consoleTimer = {};
  39255. var workerConsole = {
  39256. log: function log() {
  39257. var args = Array.prototype.slice.call(arguments);
  39258. globalScope.postMessage({
  39259. targetName: 'main',
  39260. action: 'console_log',
  39261. data: args
  39262. });
  39263. },
  39264. error: function error() {
  39265. var args = Array.prototype.slice.call(arguments);
  39266. globalScope.postMessage({
  39267. targetName: 'main',
  39268. action: 'console_error',
  39269. data: args
  39270. });
  39271. throw 'pdf.js execution error';
  39272. },
  39273. time: function time(name) {
  39274. consoleTimer[name] = Date.now();
  39275. },
  39276. timeEnd: function timeEnd(name) {
  39277. var time = consoleTimer[name];
  39278. if (!time) {
  39279. error('Unknown timer name ' + name);
  39280. }
  39281. this.log('Timer:', name, Date.now() - time);
  39282. }
  39283. };
  39284. globalScope.console = workerConsole;
  39285. }
  39286. var handler = new MessageHandler('worker', 'main', self);
  39287. WorkerMessageHandler.setup(handler, self);
  39288. handler.send('ready', null);
  39289. }
  39290. // Worker thread (and not node.js)?
  39291. if (typeof window === 'undefined' &&
  39292. !(typeof module !== 'undefined' && module.require)) {
  39293. initializeWorker();
  39294. }
  39295. exports.WorkerTask = WorkerTask;
  39296. exports.WorkerMessageHandler = WorkerMessageHandler;
  39297. }));
  39298. }).call(pdfjsLibs);
  39299. exports.PDFJS = pdfjsLibs.pdfjsSharedGlobal.PDFJS;
  39300. }));