pdf.worker.js 1.3 MB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385213862138721388213892139021391213922139321394213952139621397213982139921400214012140221403214042140521406214072140821409214102141121412214132141421415214162141721418214192142021421214222142321424214252142621427214282142921430214312143221433214342143521436214372143821439214402144121442214432144421445214462144721448214492145021451214522145321454214552145621457214582145921460214612146221463214642146521466214672146821469214702147121472214732147421475214762147721478214792148021481214822148321484214852148621487214882148921490214912149221493214942149521496214972149821499215002150121502215032150421505215062150721508215092151021511215122151321514215152151621517215182151921520215212152221523215242152521526215272152821529215302153121532215332153421535215362153721538215392154021541215422154321544215452154621547215482154921550215512155221553215542155521556215572155821559215602156121562215632156421565215662156721568215692157021571215722157321574215752157621577215782157921580215812158221583215842158521586215872158821589215902159121592215932159421595215962159721598215992160021601216022160321604216052160621607216082160921610216112161221613216142161521616216172161821619216202162121622216232162421625216262162721628216292163021631216322163321634216352163621637216382163921640216412164221643216442164521646216472164821649216502165121652216532165421655216562165721658216592166021661216622166321664216652166621667216682166921670216712167221673216742167521676216772167821679216802168121682216832168421685216862168721688216892169021691216922169321694216952169621697216982169921700217012170221703217042170521706217072170821709217102171121712217132171421715217162171721718217192172021721217222172321724217252172621727217282172921730217312173221733217342173521736217372173821739217402174121742217432174421745217462174721748217492175021751217522175321754217552175621757217582175921760217612176221763217642176521766217672176821769217702177121772217732177421775217762177721778217792178021781217822178321784217852178621787217882178921790217912179221793217942179521796217972179821799218002180121802218032180421805218062180721808218092181021811218122181321814218152181621817218182181921820218212182221823218242182521826218272182821829218302183121832218332183421835218362183721838218392184021841218422184321844218452184621847218482184921850218512185221853218542185521856218572185821859218602186121862218632186421865218662186721868218692187021871218722187321874218752187621877218782187921880218812188221883218842188521886218872188821889218902189121892218932189421895218962189721898218992190021901219022190321904219052190621907219082190921910219112191221913219142191521916219172191821919219202192121922219232192421925219262192721928219292193021931219322193321934219352193621937219382193921940219412194221943219442194521946219472194821949219502195121952219532195421955219562195721958219592196021961219622196321964219652196621967219682196921970219712197221973219742197521976219772197821979219802198121982219832198421985219862198721988219892199021991219922199321994219952199621997219982199922000220012200222003220042200522006220072200822009220102201122012220132201422015220162201722018220192202022021220222202322024220252202622027220282202922030220312203222033220342203522036220372203822039220402204122042220432204422045220462204722048220492205022051220522205322054220552205622057220582205922060220612206222063220642206522066220672206822069220702207122072220732207422075220762207722078220792208022081220822208322084220852208622087220882208922090220912209222093220942209522096220972209822099221002210122102221032210422105221062210722108221092211022111221122211322114221152211622117221182211922120221212212222123221242212522126221272212822129221302213122132221332213422135221362213722138221392214022141221422214322144221452214622147221482214922150221512215222153221542215522156221572215822159221602216122162221632216422165221662216722168221692217022171221722217322174221752217622177221782217922180221812218222183221842218522186221872218822189221902219122192221932219422195221962219722198221992220022201222022220322204222052220622207222082220922210222112221222213222142221522216222172221822219222202222122222222232222422225222262222722228222292223022231222322223322234222352223622237222382223922240222412224222243222442224522246222472224822249222502225122252222532225422255222562225722258222592226022261222622226322264222652226622267222682226922270222712227222273222742227522276222772227822279222802228122282222832228422285222862228722288222892229022291222922229322294222952229622297222982229922300223012230222303223042230522306223072230822309223102231122312223132231422315223162231722318223192232022321223222232322324223252232622327223282232922330223312233222333223342233522336223372233822339223402234122342223432234422345223462234722348223492235022351223522235322354223552235622357223582235922360223612236222363223642236522366223672236822369223702237122372223732237422375223762237722378223792238022381223822238322384223852238622387223882238922390223912239222393223942239522396223972239822399224002240122402224032240422405224062240722408224092241022411224122241322414224152241622417224182241922420224212242222423224242242522426224272242822429224302243122432224332243422435224362243722438224392244022441224422244322444224452244622447224482244922450224512245222453224542245522456224572245822459224602246122462224632246422465224662246722468224692247022471224722247322474224752247622477224782247922480224812248222483224842248522486224872248822489224902249122492224932249422495224962249722498224992250022501225022250322504225052250622507225082250922510225112251222513225142251522516225172251822519225202252122522225232252422525225262252722528225292253022531225322253322534225352253622537225382253922540225412254222543225442254522546225472254822549225502255122552225532255422555225562255722558225592256022561225622256322564225652256622567225682256922570225712257222573225742257522576225772257822579225802258122582225832258422585225862258722588225892259022591225922259322594225952259622597225982259922600226012260222603226042260522606226072260822609226102261122612226132261422615226162261722618226192262022621226222262322624226252262622627226282262922630226312263222633226342263522636226372263822639226402264122642226432264422645226462264722648226492265022651226522265322654226552265622657226582265922660226612266222663226642266522666226672266822669226702267122672226732267422675226762267722678226792268022681226822268322684226852268622687226882268922690226912269222693226942269522696226972269822699227002270122702227032270422705227062270722708227092271022711227122271322714227152271622717227182271922720227212272222723227242272522726227272272822729227302273122732227332273422735227362273722738227392274022741227422274322744227452274622747227482274922750227512275222753227542275522756227572275822759227602276122762227632276422765227662276722768227692277022771227722277322774227752277622777227782277922780227812278222783227842278522786227872278822789227902279122792227932279422795227962279722798227992280022801228022280322804228052280622807228082280922810228112281222813228142281522816228172281822819228202282122822228232282422825228262282722828228292283022831228322283322834228352283622837228382283922840228412284222843228442284522846228472284822849228502285122852228532285422855228562285722858228592286022861228622286322864228652286622867228682286922870228712287222873228742287522876228772287822879228802288122882228832288422885228862288722888228892289022891228922289322894228952289622897228982289922900229012290222903229042290522906229072290822909229102291122912229132291422915229162291722918229192292022921229222292322924229252292622927229282292922930229312293222933229342293522936229372293822939229402294122942229432294422945229462294722948229492295022951229522295322954229552295622957229582295922960229612296222963229642296522966229672296822969229702297122972229732297422975229762297722978229792298022981229822298322984229852298622987229882298922990229912299222993229942299522996229972299822999230002300123002230032300423005230062300723008230092301023011230122301323014230152301623017230182301923020230212302223023230242302523026230272302823029230302303123032230332303423035230362303723038230392304023041230422304323044230452304623047230482304923050230512305223053230542305523056230572305823059230602306123062230632306423065230662306723068230692307023071230722307323074230752307623077230782307923080230812308223083230842308523086230872308823089230902309123092230932309423095230962309723098230992310023101231022310323104231052310623107231082310923110231112311223113231142311523116231172311823119231202312123122231232312423125231262312723128231292313023131231322313323134231352313623137231382313923140231412314223143231442314523146231472314823149231502315123152231532315423155231562315723158231592316023161231622316323164231652316623167231682316923170231712317223173231742317523176231772317823179231802318123182231832318423185231862318723188231892319023191231922319323194231952319623197231982319923200232012320223203232042320523206232072320823209232102321123212232132321423215232162321723218232192322023221232222322323224232252322623227232282322923230232312323223233232342323523236232372323823239232402324123242232432324423245232462324723248232492325023251232522325323254232552325623257232582325923260232612326223263232642326523266232672326823269232702327123272232732327423275232762327723278232792328023281232822328323284232852328623287232882328923290232912329223293232942329523296232972329823299233002330123302233032330423305233062330723308233092331023311233122331323314233152331623317233182331923320233212332223323233242332523326233272332823329233302333123332233332333423335233362333723338233392334023341233422334323344233452334623347233482334923350233512335223353233542335523356233572335823359233602336123362233632336423365233662336723368233692337023371233722337323374233752337623377233782337923380233812338223383233842338523386233872338823389233902339123392233932339423395233962339723398233992340023401234022340323404234052340623407234082340923410234112341223413234142341523416234172341823419234202342123422234232342423425234262342723428234292343023431234322343323434234352343623437234382343923440234412344223443234442344523446234472344823449234502345123452234532345423455234562345723458234592346023461234622346323464234652346623467234682346923470234712347223473234742347523476234772347823479234802348123482234832348423485234862348723488234892349023491234922349323494234952349623497234982349923500235012350223503235042350523506235072350823509235102351123512235132351423515235162351723518235192352023521235222352323524235252352623527235282352923530235312353223533235342353523536235372353823539235402354123542235432354423545235462354723548235492355023551235522355323554235552355623557235582355923560235612356223563235642356523566235672356823569235702357123572235732357423575235762357723578235792358023581235822358323584235852358623587235882358923590235912359223593235942359523596235972359823599236002360123602236032360423605236062360723608236092361023611236122361323614236152361623617236182361923620236212362223623236242362523626236272362823629236302363123632236332363423635236362363723638236392364023641236422364323644236452364623647236482364923650236512365223653236542365523656236572365823659236602366123662236632366423665236662366723668236692367023671236722367323674236752367623677236782367923680236812368223683236842368523686236872368823689236902369123692236932369423695236962369723698236992370023701237022370323704237052370623707237082370923710237112371223713237142371523716237172371823719237202372123722237232372423725237262372723728237292373023731237322373323734237352373623737237382373923740237412374223743237442374523746237472374823749237502375123752237532375423755237562375723758237592376023761237622376323764237652376623767237682376923770237712377223773237742377523776237772377823779237802378123782237832378423785237862378723788237892379023791237922379323794237952379623797237982379923800238012380223803238042380523806238072380823809238102381123812238132381423815238162381723818238192382023821238222382323824238252382623827238282382923830238312383223833238342383523836238372383823839238402384123842238432384423845238462384723848238492385023851238522385323854238552385623857238582385923860238612386223863238642386523866238672386823869238702387123872238732387423875238762387723878238792388023881238822388323884238852388623887238882388923890238912389223893238942389523896238972389823899239002390123902239032390423905239062390723908239092391023911239122391323914239152391623917239182391923920239212392223923239242392523926239272392823929239302393123932239332393423935239362393723938239392394023941239422394323944239452394623947239482394923950239512395223953239542395523956239572395823959239602396123962239632396423965239662396723968239692397023971239722397323974239752397623977239782397923980239812398223983239842398523986239872398823989239902399123992239932399423995239962399723998239992400024001240022400324004240052400624007240082400924010240112401224013240142401524016240172401824019240202402124022240232402424025240262402724028240292403024031240322403324034240352403624037240382403924040240412404224043240442404524046240472404824049240502405124052240532405424055240562405724058240592406024061240622406324064240652406624067240682406924070240712407224073240742407524076240772407824079240802408124082240832408424085240862408724088240892409024091240922409324094240952409624097240982409924100241012410224103241042410524106241072410824109241102411124112241132411424115241162411724118241192412024121241222412324124241252412624127241282412924130241312413224133241342413524136241372413824139241402414124142241432414424145241462414724148241492415024151241522415324154241552415624157241582415924160241612416224163241642416524166241672416824169241702417124172241732417424175241762417724178241792418024181241822418324184241852418624187241882418924190241912419224193241942419524196241972419824199242002420124202242032420424205242062420724208242092421024211242122421324214242152421624217242182421924220242212422224223242242422524226242272422824229242302423124232242332423424235242362423724238242392424024241242422424324244242452424624247242482424924250242512425224253242542425524256242572425824259242602426124262242632426424265242662426724268242692427024271242722427324274242752427624277242782427924280242812428224283242842428524286242872428824289242902429124292242932429424295242962429724298242992430024301243022430324304243052430624307243082430924310243112431224313243142431524316243172431824319243202432124322243232432424325243262432724328243292433024331243322433324334243352433624337243382433924340243412434224343243442434524346243472434824349243502435124352243532435424355243562435724358243592436024361243622436324364243652436624367243682436924370243712437224373243742437524376243772437824379243802438124382243832438424385243862438724388243892439024391243922439324394243952439624397243982439924400244012440224403244042440524406244072440824409244102441124412244132441424415244162441724418244192442024421244222442324424244252442624427244282442924430244312443224433244342443524436244372443824439244402444124442244432444424445244462444724448244492445024451244522445324454244552445624457244582445924460244612446224463244642446524466244672446824469244702447124472244732447424475244762447724478244792448024481244822448324484244852448624487244882448924490244912449224493244942449524496244972449824499245002450124502245032450424505245062450724508245092451024511245122451324514245152451624517245182451924520245212452224523245242452524526245272452824529245302453124532245332453424535245362453724538245392454024541245422454324544245452454624547245482454924550245512455224553245542455524556245572455824559245602456124562245632456424565245662456724568245692457024571245722457324574245752457624577245782457924580245812458224583245842458524586245872458824589245902459124592245932459424595245962459724598245992460024601246022460324604246052460624607246082460924610246112461224613246142461524616246172461824619246202462124622246232462424625246262462724628246292463024631246322463324634246352463624637246382463924640246412464224643246442464524646246472464824649246502465124652246532465424655246562465724658246592466024661246622466324664246652466624667246682466924670246712467224673246742467524676246772467824679246802468124682246832468424685246862468724688246892469024691246922469324694246952469624697246982469924700247012470224703247042470524706247072470824709247102471124712247132471424715247162471724718247192472024721247222472324724247252472624727247282472924730247312473224733247342473524736247372473824739247402474124742247432474424745247462474724748247492475024751247522475324754247552475624757247582475924760247612476224763247642476524766247672476824769247702477124772247732477424775247762477724778247792478024781247822478324784247852478624787247882478924790247912479224793247942479524796247972479824799248002480124802248032480424805248062480724808248092481024811248122481324814248152481624817248182481924820248212482224823248242482524826248272482824829248302483124832248332483424835248362483724838248392484024841248422484324844248452484624847248482484924850248512485224853248542485524856248572485824859248602486124862248632486424865248662486724868248692487024871248722487324874248752487624877248782487924880248812488224883248842488524886248872488824889248902489124892248932489424895248962489724898248992490024901249022490324904249052490624907249082490924910249112491224913249142491524916249172491824919249202492124922249232492424925249262492724928249292493024931249322493324934249352493624937249382493924940249412494224943249442494524946249472494824949249502495124952249532495424955249562495724958249592496024961249622496324964249652496624967249682496924970249712497224973249742497524976249772497824979249802498124982249832498424985249862498724988249892499024991249922499324994249952499624997249982499925000250012500225003250042500525006250072500825009250102501125012250132501425015250162501725018250192502025021250222502325024250252502625027250282502925030250312503225033250342503525036250372503825039250402504125042250432504425045250462504725048250492505025051250522505325054250552505625057250582505925060250612506225063250642506525066250672506825069250702507125072250732507425075250762507725078250792508025081250822508325084250852508625087250882508925090250912509225093250942509525096250972509825099251002510125102251032510425105251062510725108251092511025111251122511325114251152511625117251182511925120251212512225123251242512525126251272512825129251302513125132251332513425135251362513725138251392514025141251422514325144251452514625147251482514925150251512515225153251542515525156251572515825159251602516125162251632516425165251662516725168251692517025171251722517325174251752517625177251782517925180251812518225183251842518525186251872518825189251902519125192251932519425195251962519725198251992520025201252022520325204252052520625207252082520925210252112521225213252142521525216252172521825219252202522125222252232522425225252262522725228252292523025231252322523325234252352523625237252382523925240252412524225243252442524525246252472524825249252502525125252252532525425255252562525725258252592526025261252622526325264252652526625267252682526925270252712527225273252742527525276252772527825279252802528125282252832528425285252862528725288252892529025291252922529325294252952529625297252982529925300253012530225303253042530525306253072530825309253102531125312253132531425315253162531725318253192532025321253222532325324253252532625327253282532925330253312533225333253342533525336253372533825339253402534125342253432534425345253462534725348253492535025351253522535325354253552535625357253582535925360253612536225363253642536525366253672536825369253702537125372253732537425375253762537725378253792538025381253822538325384253852538625387253882538925390253912539225393253942539525396253972539825399254002540125402254032540425405254062540725408254092541025411254122541325414254152541625417254182541925420254212542225423254242542525426254272542825429254302543125432254332543425435254362543725438254392544025441254422544325444254452544625447254482544925450254512545225453254542545525456254572545825459254602546125462254632546425465254662546725468254692547025471254722547325474254752547625477254782547925480254812548225483254842548525486254872548825489254902549125492254932549425495254962549725498254992550025501255022550325504255052550625507255082550925510255112551225513255142551525516255172551825519255202552125522255232552425525255262552725528255292553025531255322553325534255352553625537255382553925540255412554225543255442554525546255472554825549255502555125552255532555425555255562555725558255592556025561255622556325564255652556625567255682556925570255712557225573255742557525576255772557825579255802558125582255832558425585255862558725588255892559025591255922559325594255952559625597255982559925600256012560225603256042560525606256072560825609256102561125612256132561425615256162561725618256192562025621256222562325624256252562625627256282562925630256312563225633256342563525636256372563825639256402564125642256432564425645256462564725648256492565025651256522565325654256552565625657256582565925660256612566225663256642566525666256672566825669256702567125672256732567425675256762567725678256792568025681256822568325684256852568625687256882568925690256912569225693256942569525696256972569825699257002570125702257032570425705257062570725708257092571025711257122571325714257152571625717257182571925720257212572225723257242572525726257272572825729257302573125732257332573425735257362573725738257392574025741257422574325744257452574625747257482574925750257512575225753257542575525756257572575825759257602576125762257632576425765257662576725768257692577025771257722577325774257752577625777257782577925780257812578225783257842578525786257872578825789257902579125792257932579425795257962579725798257992580025801258022580325804258052580625807258082580925810258112581225813258142581525816258172581825819258202582125822258232582425825258262582725828258292583025831258322583325834258352583625837258382583925840258412584225843258442584525846258472584825849258502585125852258532585425855258562585725858258592586025861258622586325864258652586625867258682586925870258712587225873258742587525876258772587825879258802588125882258832588425885258862588725888258892589025891258922589325894258952589625897258982589925900259012590225903259042590525906259072590825909259102591125912259132591425915259162591725918259192592025921259222592325924259252592625927259282592925930259312593225933259342593525936259372593825939259402594125942259432594425945259462594725948259492595025951259522595325954259552595625957259582595925960259612596225963259642596525966259672596825969259702597125972259732597425975259762597725978259792598025981259822598325984259852598625987259882598925990259912599225993259942599525996259972599825999260002600126002260032600426005260062600726008260092601026011260122601326014260152601626017260182601926020260212602226023260242602526026260272602826029260302603126032260332603426035260362603726038260392604026041260422604326044260452604626047260482604926050260512605226053260542605526056260572605826059260602606126062260632606426065260662606726068260692607026071260722607326074260752607626077260782607926080260812608226083260842608526086260872608826089260902609126092260932609426095260962609726098260992610026101261022610326104261052610626107261082610926110261112611226113261142611526116261172611826119261202612126122261232612426125261262612726128261292613026131261322613326134261352613626137261382613926140261412614226143261442614526146261472614826149261502615126152261532615426155261562615726158261592616026161261622616326164261652616626167261682616926170261712617226173261742617526176261772617826179261802618126182261832618426185261862618726188261892619026191261922619326194261952619626197261982619926200262012620226203262042620526206262072620826209262102621126212262132621426215262162621726218262192622026221262222622326224262252622626227262282622926230262312623226233262342623526236262372623826239262402624126242262432624426245262462624726248262492625026251262522625326254262552625626257262582625926260262612626226263262642626526266262672626826269262702627126272262732627426275262762627726278262792628026281262822628326284262852628626287262882628926290262912629226293262942629526296262972629826299263002630126302263032630426305263062630726308263092631026311263122631326314263152631626317263182631926320263212632226323263242632526326263272632826329263302633126332263332633426335263362633726338263392634026341263422634326344263452634626347263482634926350263512635226353263542635526356263572635826359263602636126362263632636426365263662636726368263692637026371263722637326374263752637626377263782637926380263812638226383263842638526386263872638826389263902639126392263932639426395263962639726398263992640026401264022640326404264052640626407264082640926410264112641226413264142641526416264172641826419264202642126422264232642426425264262642726428264292643026431264322643326434264352643626437264382643926440264412644226443264442644526446264472644826449264502645126452264532645426455264562645726458264592646026461264622646326464264652646626467264682646926470264712647226473264742647526476264772647826479264802648126482264832648426485264862648726488264892649026491264922649326494264952649626497264982649926500265012650226503265042650526506265072650826509265102651126512265132651426515265162651726518265192652026521265222652326524265252652626527265282652926530265312653226533265342653526536265372653826539265402654126542265432654426545265462654726548265492655026551265522655326554265552655626557265582655926560265612656226563265642656526566265672656826569265702657126572265732657426575265762657726578265792658026581265822658326584265852658626587265882658926590265912659226593265942659526596265972659826599266002660126602266032660426605266062660726608266092661026611266122661326614266152661626617266182661926620266212662226623266242662526626266272662826629266302663126632266332663426635266362663726638266392664026641266422664326644266452664626647266482664926650266512665226653266542665526656266572665826659266602666126662266632666426665266662666726668266692667026671266722667326674266752667626677266782667926680266812668226683266842668526686266872668826689266902669126692266932669426695266962669726698266992670026701267022670326704267052670626707267082670926710267112671226713267142671526716267172671826719267202672126722267232672426725267262672726728267292673026731267322673326734267352673626737267382673926740267412674226743267442674526746267472674826749267502675126752267532675426755267562675726758267592676026761267622676326764267652676626767267682676926770267712677226773267742677526776267772677826779267802678126782267832678426785267862678726788267892679026791267922679326794267952679626797267982679926800268012680226803268042680526806268072680826809268102681126812268132681426815268162681726818268192682026821268222682326824268252682626827268282682926830268312683226833268342683526836268372683826839268402684126842268432684426845268462684726848268492685026851268522685326854268552685626857268582685926860268612686226863268642686526866268672686826869268702687126872268732687426875268762687726878268792688026881268822688326884268852688626887268882688926890268912689226893268942689526896268972689826899269002690126902269032690426905269062690726908269092691026911269122691326914269152691626917269182691926920269212692226923269242692526926269272692826929269302693126932269332693426935269362693726938269392694026941269422694326944269452694626947269482694926950269512695226953269542695526956269572695826959269602696126962269632696426965269662696726968269692697026971269722697326974269752697626977269782697926980269812698226983269842698526986269872698826989269902699126992269932699426995269962699726998269992700027001270022700327004270052700627007270082700927010270112701227013270142701527016270172701827019270202702127022270232702427025270262702727028270292703027031270322703327034270352703627037270382703927040270412704227043270442704527046270472704827049270502705127052270532705427055270562705727058270592706027061270622706327064270652706627067270682706927070270712707227073270742707527076270772707827079270802708127082270832708427085270862708727088270892709027091270922709327094270952709627097270982709927100271012710227103271042710527106271072710827109271102711127112271132711427115271162711727118271192712027121271222712327124271252712627127271282712927130271312713227133271342713527136271372713827139271402714127142271432714427145271462714727148271492715027151271522715327154271552715627157271582715927160271612716227163271642716527166271672716827169271702717127172271732717427175271762717727178271792718027181271822718327184271852718627187271882718927190271912719227193271942719527196271972719827199272002720127202272032720427205272062720727208272092721027211272122721327214272152721627217272182721927220272212722227223272242722527226272272722827229272302723127232272332723427235272362723727238272392724027241272422724327244272452724627247272482724927250272512725227253272542725527256272572725827259272602726127262272632726427265272662726727268272692727027271272722727327274272752727627277272782727927280272812728227283272842728527286272872728827289272902729127292272932729427295272962729727298272992730027301273022730327304273052730627307273082730927310273112731227313273142731527316273172731827319273202732127322273232732427325273262732727328273292733027331273322733327334273352733627337273382733927340273412734227343273442734527346273472734827349273502735127352273532735427355273562735727358273592736027361273622736327364273652736627367273682736927370273712737227373273742737527376273772737827379273802738127382273832738427385273862738727388273892739027391273922739327394273952739627397273982739927400274012740227403274042740527406274072740827409274102741127412274132741427415274162741727418274192742027421274222742327424274252742627427274282742927430274312743227433274342743527436274372743827439274402744127442274432744427445274462744727448274492745027451274522745327454274552745627457274582745927460274612746227463274642746527466274672746827469274702747127472274732747427475274762747727478274792748027481274822748327484274852748627487274882748927490274912749227493274942749527496274972749827499275002750127502275032750427505275062750727508275092751027511275122751327514275152751627517275182751927520275212752227523275242752527526275272752827529275302753127532275332753427535275362753727538275392754027541275422754327544275452754627547275482754927550275512755227553275542755527556275572755827559275602756127562275632756427565275662756727568275692757027571275722757327574275752757627577275782757927580275812758227583275842758527586275872758827589275902759127592275932759427595275962759727598275992760027601276022760327604276052760627607276082760927610276112761227613276142761527616276172761827619276202762127622276232762427625276262762727628276292763027631276322763327634276352763627637276382763927640276412764227643276442764527646276472764827649276502765127652276532765427655276562765727658276592766027661276622766327664276652766627667276682766927670276712767227673276742767527676276772767827679276802768127682276832768427685276862768727688276892769027691276922769327694276952769627697276982769927700277012770227703277042770527706277072770827709277102771127712277132771427715277162771727718277192772027721277222772327724277252772627727277282772927730277312773227733277342773527736277372773827739277402774127742277432774427745277462774727748277492775027751277522775327754277552775627757277582775927760277612776227763277642776527766277672776827769277702777127772277732777427775277762777727778277792778027781277822778327784277852778627787277882778927790277912779227793277942779527796277972779827799278002780127802278032780427805278062780727808278092781027811278122781327814278152781627817278182781927820278212782227823278242782527826278272782827829278302783127832278332783427835278362783727838278392784027841278422784327844278452784627847278482784927850278512785227853278542785527856278572785827859278602786127862278632786427865278662786727868278692787027871278722787327874278752787627877278782787927880278812788227883278842788527886278872788827889278902789127892278932789427895278962789727898278992790027901279022790327904279052790627907279082790927910279112791227913279142791527916279172791827919279202792127922279232792427925279262792727928279292793027931279322793327934279352793627937279382793927940279412794227943279442794527946279472794827949279502795127952279532795427955279562795727958279592796027961279622796327964279652796627967279682796927970279712797227973279742797527976279772797827979279802798127982279832798427985279862798727988279892799027991279922799327994279952799627997279982799928000280012800228003280042800528006280072800828009280102801128012280132801428015280162801728018280192802028021280222802328024280252802628027280282802928030280312803228033280342803528036280372803828039280402804128042280432804428045280462804728048280492805028051280522805328054280552805628057280582805928060280612806228063280642806528066280672806828069280702807128072280732807428075280762807728078280792808028081280822808328084280852808628087280882808928090280912809228093280942809528096280972809828099281002810128102281032810428105281062810728108281092811028111281122811328114281152811628117281182811928120281212812228123281242812528126281272812828129281302813128132281332813428135281362813728138281392814028141281422814328144281452814628147281482814928150281512815228153281542815528156281572815828159281602816128162281632816428165281662816728168281692817028171281722817328174281752817628177281782817928180281812818228183281842818528186281872818828189281902819128192281932819428195281962819728198281992820028201282022820328204282052820628207282082820928210282112821228213282142821528216282172821828219282202822128222282232822428225282262822728228282292823028231282322823328234282352823628237282382823928240282412824228243282442824528246282472824828249282502825128252282532825428255282562825728258282592826028261282622826328264282652826628267282682826928270282712827228273282742827528276282772827828279282802828128282282832828428285282862828728288282892829028291282922829328294282952829628297282982829928300283012830228303283042830528306283072830828309283102831128312283132831428315283162831728318283192832028321283222832328324283252832628327283282832928330283312833228333283342833528336283372833828339283402834128342283432834428345283462834728348283492835028351283522835328354283552835628357283582835928360283612836228363283642836528366283672836828369283702837128372283732837428375283762837728378283792838028381283822838328384283852838628387283882838928390283912839228393283942839528396283972839828399284002840128402284032840428405284062840728408284092841028411284122841328414284152841628417284182841928420284212842228423284242842528426284272842828429284302843128432284332843428435284362843728438284392844028441284422844328444284452844628447284482844928450284512845228453284542845528456284572845828459284602846128462284632846428465284662846728468284692847028471284722847328474284752847628477284782847928480284812848228483284842848528486284872848828489284902849128492284932849428495284962849728498284992850028501285022850328504285052850628507285082850928510285112851228513285142851528516285172851828519285202852128522285232852428525285262852728528285292853028531285322853328534285352853628537285382853928540285412854228543285442854528546285472854828549285502855128552285532855428555285562855728558285592856028561285622856328564285652856628567285682856928570285712857228573285742857528576285772857828579285802858128582285832858428585285862858728588285892859028591285922859328594285952859628597285982859928600286012860228603286042860528606286072860828609286102861128612286132861428615286162861728618286192862028621286222862328624286252862628627286282862928630286312863228633286342863528636286372863828639286402864128642286432864428645286462864728648286492865028651286522865328654286552865628657286582865928660286612866228663286642866528666286672866828669286702867128672286732867428675286762867728678286792868028681286822868328684286852868628687286882868928690286912869228693286942869528696286972869828699287002870128702287032870428705287062870728708287092871028711287122871328714287152871628717287182871928720287212872228723287242872528726287272872828729287302873128732287332873428735287362873728738287392874028741287422874328744287452874628747287482874928750287512875228753287542875528756287572875828759287602876128762287632876428765287662876728768287692877028771287722877328774287752877628777287782877928780287812878228783287842878528786287872878828789287902879128792287932879428795287962879728798287992880028801288022880328804288052880628807288082880928810288112881228813288142881528816288172881828819288202882128822288232882428825288262882728828288292883028831288322883328834288352883628837288382883928840288412884228843288442884528846288472884828849288502885128852288532885428855288562885728858288592886028861288622886328864288652886628867288682886928870288712887228873288742887528876288772887828879288802888128882288832888428885288862888728888288892889028891288922889328894288952889628897288982889928900289012890228903289042890528906289072890828909289102891128912289132891428915289162891728918289192892028921289222892328924289252892628927289282892928930289312893228933289342893528936289372893828939289402894128942289432894428945289462894728948289492895028951289522895328954289552895628957289582895928960289612896228963289642896528966289672896828969289702897128972289732897428975289762897728978289792898028981289822898328984289852898628987289882898928990289912899228993289942899528996289972899828999290002900129002290032900429005290062900729008290092901029011290122901329014290152901629017290182901929020290212902229023290242902529026290272902829029290302903129032290332903429035290362903729038290392904029041290422904329044290452904629047290482904929050290512905229053290542905529056290572905829059290602906129062290632906429065290662906729068290692907029071290722907329074290752907629077290782907929080290812908229083290842908529086290872908829089290902909129092290932909429095290962909729098290992910029101291022910329104291052910629107291082910929110291112911229113291142911529116291172911829119291202912129122291232912429125291262912729128291292913029131291322913329134291352913629137291382913929140291412914229143291442914529146291472914829149291502915129152291532915429155291562915729158291592916029161291622916329164291652916629167291682916929170291712917229173291742917529176291772917829179291802918129182291832918429185291862918729188291892919029191291922919329194291952919629197291982919929200292012920229203292042920529206292072920829209292102921129212292132921429215292162921729218292192922029221292222922329224292252922629227292282922929230292312923229233292342923529236292372923829239292402924129242292432924429245292462924729248292492925029251292522925329254292552925629257292582925929260292612926229263292642926529266292672926829269292702927129272292732927429275292762927729278292792928029281292822928329284292852928629287292882928929290292912929229293292942929529296292972929829299293002930129302293032930429305293062930729308293092931029311293122931329314293152931629317293182931929320293212932229323293242932529326293272932829329293302933129332293332933429335293362933729338293392934029341293422934329344293452934629347293482934929350293512935229353293542935529356293572935829359293602936129362293632936429365293662936729368293692937029371293722937329374293752937629377293782937929380293812938229383293842938529386293872938829389293902939129392293932939429395293962939729398293992940029401294022940329404294052940629407294082940929410294112941229413294142941529416294172941829419294202942129422294232942429425294262942729428294292943029431294322943329434294352943629437294382943929440294412944229443294442944529446294472944829449294502945129452294532945429455294562945729458294592946029461294622946329464294652946629467294682946929470294712947229473294742947529476294772947829479294802948129482294832948429485294862948729488294892949029491294922949329494294952949629497294982949929500295012950229503295042950529506295072950829509295102951129512295132951429515295162951729518295192952029521295222952329524295252952629527295282952929530295312953229533295342953529536295372953829539295402954129542295432954429545295462954729548295492955029551295522955329554295552955629557295582955929560295612956229563295642956529566295672956829569295702957129572295732957429575295762957729578295792958029581295822958329584295852958629587295882958929590295912959229593295942959529596295972959829599296002960129602296032960429605296062960729608296092961029611296122961329614296152961629617296182961929620296212962229623296242962529626296272962829629296302963129632296332963429635296362963729638296392964029641296422964329644296452964629647296482964929650296512965229653296542965529656296572965829659296602966129662296632966429665296662966729668296692967029671296722967329674296752967629677296782967929680296812968229683296842968529686296872968829689296902969129692296932969429695296962969729698296992970029701297022970329704297052970629707297082970929710297112971229713297142971529716297172971829719297202972129722297232972429725297262972729728297292973029731297322973329734297352973629737297382973929740297412974229743297442974529746297472974829749297502975129752297532975429755297562975729758297592976029761297622976329764297652976629767297682976929770297712977229773297742977529776297772977829779297802978129782297832978429785297862978729788297892979029791297922979329794297952979629797297982979929800298012980229803298042980529806298072980829809298102981129812298132981429815298162981729818298192982029821298222982329824298252982629827298282982929830298312983229833298342983529836298372983829839298402984129842298432984429845298462984729848298492985029851298522985329854298552985629857298582985929860298612986229863298642986529866298672986829869298702987129872298732987429875298762987729878298792988029881298822988329884298852988629887298882988929890298912989229893298942989529896298972989829899299002990129902299032990429905299062990729908299092991029911299122991329914299152991629917299182991929920299212992229923299242992529926299272992829929299302993129932299332993429935299362993729938299392994029941299422994329944299452994629947299482994929950299512995229953299542995529956299572995829959299602996129962299632996429965299662996729968299692997029971299722997329974299752997629977299782997929980299812998229983299842998529986299872998829989299902999129992299932999429995299962999729998299993000030001300023000330004300053000630007300083000930010300113001230013300143001530016300173001830019300203002130022300233002430025300263002730028300293003030031300323003330034300353003630037300383003930040300413004230043300443004530046300473004830049300503005130052300533005430055300563005730058300593006030061300623006330064300653006630067300683006930070300713007230073300743007530076300773007830079300803008130082300833008430085300863008730088300893009030091300923009330094300953009630097300983009930100301013010230103301043010530106301073010830109301103011130112301133011430115301163011730118301193012030121301223012330124301253012630127301283012930130301313013230133301343013530136301373013830139301403014130142301433014430145301463014730148301493015030151301523015330154301553015630157301583015930160301613016230163301643016530166301673016830169301703017130172301733017430175301763017730178301793018030181301823018330184301853018630187301883018930190301913019230193301943019530196301973019830199302003020130202302033020430205302063020730208302093021030211302123021330214302153021630217302183021930220302213022230223302243022530226302273022830229302303023130232302333023430235302363023730238302393024030241302423024330244302453024630247302483024930250302513025230253302543025530256302573025830259302603026130262302633026430265302663026730268302693027030271302723027330274302753027630277302783027930280302813028230283302843028530286302873028830289302903029130292302933029430295302963029730298302993030030301303023030330304303053030630307303083030930310303113031230313303143031530316303173031830319303203032130322303233032430325303263032730328303293033030331303323033330334303353033630337303383033930340303413034230343303443034530346303473034830349303503035130352303533035430355303563035730358303593036030361303623036330364303653036630367303683036930370303713037230373303743037530376303773037830379303803038130382303833038430385303863038730388303893039030391303923039330394303953039630397303983039930400304013040230403304043040530406304073040830409304103041130412304133041430415304163041730418304193042030421304223042330424304253042630427304283042930430304313043230433304343043530436304373043830439304403044130442304433044430445304463044730448304493045030451304523045330454304553045630457304583045930460304613046230463304643046530466304673046830469304703047130472304733047430475304763047730478304793048030481304823048330484304853048630487304883048930490304913049230493304943049530496304973049830499305003050130502305033050430505305063050730508305093051030511305123051330514305153051630517305183051930520305213052230523305243052530526305273052830529305303053130532305333053430535305363053730538305393054030541305423054330544305453054630547305483054930550305513055230553305543055530556305573055830559305603056130562305633056430565305663056730568305693057030571305723057330574305753057630577305783057930580305813058230583305843058530586305873058830589305903059130592305933059430595305963059730598305993060030601306023060330604306053060630607306083060930610306113061230613306143061530616306173061830619306203062130622306233062430625306263062730628306293063030631306323063330634306353063630637306383063930640306413064230643306443064530646306473064830649306503065130652306533065430655306563065730658306593066030661306623066330664306653066630667306683066930670306713067230673306743067530676306773067830679306803068130682306833068430685306863068730688306893069030691306923069330694306953069630697306983069930700307013070230703307043070530706307073070830709307103071130712307133071430715307163071730718307193072030721307223072330724307253072630727307283072930730307313073230733307343073530736307373073830739307403074130742307433074430745307463074730748307493075030751307523075330754307553075630757307583075930760307613076230763307643076530766307673076830769307703077130772307733077430775307763077730778307793078030781307823078330784307853078630787307883078930790307913079230793307943079530796307973079830799308003080130802308033080430805308063080730808308093081030811308123081330814308153081630817308183081930820308213082230823308243082530826308273082830829308303083130832308333083430835308363083730838308393084030841308423084330844308453084630847308483084930850308513085230853308543085530856308573085830859308603086130862308633086430865308663086730868308693087030871308723087330874308753087630877308783087930880308813088230883308843088530886308873088830889308903089130892308933089430895308963089730898308993090030901309023090330904309053090630907309083090930910309113091230913309143091530916309173091830919309203092130922309233092430925309263092730928309293093030931309323093330934309353093630937309383093930940309413094230943309443094530946309473094830949309503095130952309533095430955309563095730958309593096030961309623096330964309653096630967309683096930970309713097230973309743097530976309773097830979309803098130982309833098430985309863098730988309893099030991309923099330994309953099630997309983099931000310013100231003310043100531006310073100831009310103101131012310133101431015310163101731018310193102031021310223102331024310253102631027310283102931030310313103231033310343103531036310373103831039310403104131042310433104431045310463104731048310493105031051310523105331054310553105631057310583105931060310613106231063310643106531066310673106831069310703107131072310733107431075310763107731078310793108031081310823108331084310853108631087310883108931090310913109231093310943109531096310973109831099311003110131102311033110431105311063110731108311093111031111311123111331114311153111631117311183111931120311213112231123311243112531126311273112831129311303113131132311333113431135311363113731138311393114031141311423114331144311453114631147311483114931150311513115231153311543115531156311573115831159311603116131162311633116431165311663116731168311693117031171311723117331174311753117631177311783117931180311813118231183311843118531186311873118831189311903119131192311933119431195311963119731198311993120031201312023120331204312053120631207312083120931210312113121231213312143121531216312173121831219312203122131222312233122431225312263122731228312293123031231312323123331234312353123631237312383123931240312413124231243312443124531246312473124831249312503125131252312533125431255312563125731258312593126031261312623126331264312653126631267312683126931270312713127231273312743127531276312773127831279312803128131282312833128431285312863128731288312893129031291312923129331294312953129631297312983129931300313013130231303313043130531306313073130831309313103131131312313133131431315313163131731318313193132031321313223132331324313253132631327313283132931330313313133231333313343133531336313373133831339313403134131342313433134431345313463134731348313493135031351313523135331354313553135631357313583135931360313613136231363313643136531366313673136831369313703137131372313733137431375313763137731378313793138031381313823138331384313853138631387313883138931390313913139231393313943139531396313973139831399314003140131402314033140431405314063140731408314093141031411314123141331414314153141631417314183141931420314213142231423314243142531426314273142831429314303143131432314333143431435314363143731438314393144031441314423144331444314453144631447314483144931450314513145231453314543145531456314573145831459314603146131462314633146431465314663146731468314693147031471314723147331474314753147631477314783147931480314813148231483314843148531486314873148831489314903149131492314933149431495314963149731498314993150031501315023150331504315053150631507315083150931510315113151231513315143151531516315173151831519315203152131522315233152431525315263152731528315293153031531315323153331534315353153631537315383153931540315413154231543315443154531546315473154831549315503155131552315533155431555315563155731558315593156031561315623156331564315653156631567315683156931570315713157231573315743157531576315773157831579315803158131582315833158431585315863158731588315893159031591315923159331594315953159631597315983159931600316013160231603316043160531606316073160831609316103161131612316133161431615316163161731618316193162031621316223162331624316253162631627316283162931630316313163231633316343163531636316373163831639316403164131642316433164431645316463164731648316493165031651316523165331654316553165631657316583165931660316613166231663316643166531666316673166831669316703167131672316733167431675316763167731678316793168031681316823168331684316853168631687316883168931690316913169231693316943169531696316973169831699317003170131702317033170431705317063170731708317093171031711317123171331714317153171631717317183171931720317213172231723317243172531726317273172831729317303173131732317333173431735317363173731738317393174031741317423174331744317453174631747317483174931750317513175231753317543175531756317573175831759317603176131762317633176431765317663176731768317693177031771317723177331774317753177631777317783177931780317813178231783317843178531786317873178831789317903179131792317933179431795317963179731798317993180031801318023180331804318053180631807318083180931810318113181231813318143181531816318173181831819318203182131822318233182431825318263182731828318293183031831318323183331834318353183631837318383183931840318413184231843318443184531846318473184831849318503185131852318533185431855318563185731858318593186031861318623186331864318653186631867318683186931870318713187231873318743187531876318773187831879318803188131882318833188431885318863188731888318893189031891318923189331894318953189631897318983189931900319013190231903319043190531906319073190831909319103191131912319133191431915319163191731918319193192031921319223192331924319253192631927319283192931930319313193231933319343193531936319373193831939319403194131942319433194431945319463194731948319493195031951319523195331954319553195631957319583195931960319613196231963319643196531966319673196831969319703197131972319733197431975319763197731978319793198031981319823198331984319853198631987319883198931990319913199231993319943199531996319973199831999320003200132002320033200432005320063200732008320093201032011320123201332014320153201632017320183201932020320213202232023320243202532026320273202832029320303203132032320333203432035320363203732038320393204032041320423204332044320453204632047320483204932050320513205232053320543205532056320573205832059320603206132062320633206432065320663206732068320693207032071320723207332074320753207632077320783207932080320813208232083320843208532086320873208832089320903209132092320933209432095320963209732098320993210032101321023210332104321053210632107321083210932110321113211232113321143211532116321173211832119321203212132122321233212432125321263212732128321293213032131321323213332134321353213632137321383213932140321413214232143321443214532146321473214832149321503215132152321533215432155321563215732158321593216032161321623216332164321653216632167321683216932170321713217232173321743217532176321773217832179321803218132182321833218432185321863218732188321893219032191321923219332194321953219632197321983219932200322013220232203322043220532206322073220832209322103221132212322133221432215322163221732218322193222032221322223222332224322253222632227322283222932230322313223232233322343223532236322373223832239322403224132242322433224432245322463224732248322493225032251322523225332254322553225632257322583225932260322613226232263322643226532266322673226832269322703227132272322733227432275322763227732278322793228032281322823228332284322853228632287322883228932290322913229232293322943229532296322973229832299323003230132302323033230432305323063230732308323093231032311323123231332314323153231632317323183231932320323213232232323323243232532326323273232832329323303233132332323333233432335323363233732338323393234032341323423234332344323453234632347323483234932350323513235232353323543235532356323573235832359323603236132362323633236432365323663236732368323693237032371323723237332374323753237632377323783237932380323813238232383323843238532386323873238832389323903239132392323933239432395323963239732398323993240032401324023240332404324053240632407324083240932410324113241232413324143241532416324173241832419324203242132422324233242432425324263242732428324293243032431324323243332434324353243632437324383243932440324413244232443324443244532446324473244832449324503245132452324533245432455324563245732458324593246032461324623246332464324653246632467324683246932470324713247232473324743247532476324773247832479324803248132482324833248432485324863248732488324893249032491324923249332494324953249632497324983249932500325013250232503325043250532506325073250832509325103251132512325133251432515325163251732518325193252032521325223252332524325253252632527325283252932530325313253232533325343253532536325373253832539325403254132542325433254432545325463254732548325493255032551325523255332554325553255632557325583255932560325613256232563325643256532566325673256832569325703257132572325733257432575325763257732578325793258032581325823258332584325853258632587325883258932590325913259232593325943259532596325973259832599326003260132602326033260432605326063260732608326093261032611326123261332614326153261632617326183261932620326213262232623326243262532626326273262832629326303263132632326333263432635326363263732638326393264032641326423264332644326453264632647326483264932650326513265232653326543265532656326573265832659326603266132662326633266432665326663266732668326693267032671326723267332674326753267632677326783267932680326813268232683326843268532686326873268832689326903269132692326933269432695326963269732698326993270032701327023270332704327053270632707327083270932710327113271232713327143271532716327173271832719327203272132722327233272432725327263272732728327293273032731327323273332734327353273632737327383273932740327413274232743327443274532746327473274832749327503275132752327533275432755327563275732758327593276032761327623276332764327653276632767327683276932770327713277232773327743277532776327773277832779327803278132782327833278432785327863278732788327893279032791327923279332794327953279632797327983279932800328013280232803328043280532806328073280832809328103281132812328133281432815328163281732818328193282032821328223282332824328253282632827328283282932830328313283232833328343283532836328373283832839328403284132842328433284432845328463284732848328493285032851328523285332854328553285632857328583285932860328613286232863328643286532866328673286832869328703287132872328733287432875328763287732878328793288032881328823288332884328853288632887328883288932890328913289232893328943289532896328973289832899329003290132902329033290432905329063290732908329093291032911329123291332914329153291632917329183291932920329213292232923329243292532926329273292832929329303293132932329333293432935329363293732938329393294032941329423294332944329453294632947329483294932950329513295232953329543295532956329573295832959329603296132962329633296432965329663296732968329693297032971329723297332974329753297632977329783297932980329813298232983329843298532986329873298832989329903299132992329933299432995329963299732998329993300033001330023300333004330053300633007330083300933010330113301233013330143301533016330173301833019330203302133022330233302433025330263302733028330293303033031330323303333034330353303633037330383303933040330413304233043330443304533046330473304833049330503305133052330533305433055330563305733058330593306033061330623306333064330653306633067330683306933070330713307233073330743307533076330773307833079330803308133082330833308433085330863308733088330893309033091330923309333094330953309633097330983309933100331013310233103331043310533106331073310833109331103311133112331133311433115331163311733118331193312033121331223312333124331253312633127331283312933130331313313233133331343313533136331373313833139331403314133142331433314433145331463314733148331493315033151331523315333154331553315633157331583315933160331613316233163331643316533166331673316833169331703317133172331733317433175331763317733178331793318033181331823318333184331853318633187331883318933190331913319233193331943319533196331973319833199332003320133202332033320433205332063320733208332093321033211332123321333214332153321633217332183321933220332213322233223332243322533226332273322833229332303323133232332333323433235332363323733238332393324033241332423324333244332453324633247332483324933250332513325233253332543325533256332573325833259332603326133262332633326433265332663326733268332693327033271332723327333274332753327633277332783327933280332813328233283332843328533286332873328833289332903329133292332933329433295332963329733298332993330033301333023330333304333053330633307333083330933310333113331233313333143331533316333173331833319333203332133322333233332433325333263332733328333293333033331333323333333334333353333633337333383333933340333413334233343333443334533346333473334833349333503335133352333533335433355333563335733358333593336033361333623336333364333653336633367333683336933370333713337233373333743337533376333773337833379333803338133382333833338433385333863338733388333893339033391333923339333394333953339633397333983339933400334013340233403334043340533406334073340833409334103341133412334133341433415334163341733418334193342033421334223342333424334253342633427334283342933430334313343233433334343343533436334373343833439334403344133442334433344433445334463344733448334493345033451334523345333454334553345633457334583345933460334613346233463334643346533466334673346833469334703347133472334733347433475334763347733478334793348033481334823348333484334853348633487334883348933490334913349233493334943349533496334973349833499335003350133502335033350433505335063350733508335093351033511335123351333514335153351633517335183351933520335213352233523335243352533526335273352833529335303353133532335333353433535335363353733538335393354033541335423354333544335453354633547335483354933550335513355233553335543355533556335573355833559335603356133562335633356433565335663356733568335693357033571335723357333574335753357633577335783357933580335813358233583335843358533586335873358833589335903359133592335933359433595335963359733598335993360033601336023360333604336053360633607336083360933610336113361233613336143361533616336173361833619336203362133622336233362433625336263362733628336293363033631336323363333634336353363633637336383363933640336413364233643336443364533646336473364833649336503365133652336533365433655336563365733658336593366033661336623366333664336653366633667336683366933670336713367233673336743367533676336773367833679336803368133682336833368433685336863368733688336893369033691336923369333694336953369633697336983369933700337013370233703337043370533706337073370833709337103371133712337133371433715337163371733718337193372033721337223372333724337253372633727337283372933730337313373233733337343373533736337373373833739337403374133742337433374433745337463374733748337493375033751337523375333754337553375633757337583375933760337613376233763337643376533766337673376833769337703377133772337733377433775337763377733778337793378033781337823378333784337853378633787337883378933790337913379233793337943379533796337973379833799338003380133802338033380433805338063380733808338093381033811338123381333814338153381633817338183381933820338213382233823338243382533826338273382833829338303383133832338333383433835338363383733838338393384033841338423384333844338453384633847338483384933850338513385233853338543385533856338573385833859338603386133862338633386433865338663386733868338693387033871338723387333874338753387633877338783387933880338813388233883338843388533886338873388833889338903389133892338933389433895338963389733898338993390033901339023390333904339053390633907339083390933910339113391233913339143391533916339173391833919339203392133922339233392433925339263392733928339293393033931339323393333934339353393633937339383393933940339413394233943339443394533946339473394833949339503395133952339533395433955339563395733958339593396033961339623396333964339653396633967339683396933970339713397233973339743397533976339773397833979339803398133982339833398433985339863398733988339893399033991339923399333994339953399633997339983399934000340013400234003340043400534006340073400834009340103401134012340133401434015340163401734018340193402034021340223402334024340253402634027340283402934030340313403234033340343403534036340373403834039340403404134042340433404434045340463404734048340493405034051340523405334054340553405634057340583405934060340613406234063340643406534066340673406834069340703407134072340733407434075340763407734078340793408034081340823408334084340853408634087340883408934090340913409234093340943409534096340973409834099341003410134102341033410434105341063410734108341093411034111341123411334114341153411634117341183411934120341213412234123341243412534126341273412834129341303413134132341333413434135341363413734138341393414034141341423414334144341453414634147341483414934150341513415234153341543415534156341573415834159341603416134162341633416434165341663416734168341693417034171341723417334174341753417634177341783417934180341813418234183341843418534186341873418834189341903419134192341933419434195341963419734198341993420034201342023420334204342053420634207342083420934210342113421234213342143421534216342173421834219342203422134222342233422434225342263422734228342293423034231342323423334234342353423634237342383423934240342413424234243342443424534246342473424834249342503425134252342533425434255342563425734258342593426034261342623426334264342653426634267342683426934270342713427234273342743427534276342773427834279342803428134282342833428434285342863428734288342893429034291342923429334294342953429634297342983429934300343013430234303343043430534306343073430834309343103431134312343133431434315343163431734318343193432034321343223432334324343253432634327343283432934330343313433234333343343433534336343373433834339343403434134342343433434434345343463434734348343493435034351343523435334354343553435634357343583435934360343613436234363343643436534366343673436834369343703437134372343733437434375343763437734378343793438034381343823438334384343853438634387343883438934390343913439234393343943439534396343973439834399344003440134402344033440434405344063440734408344093441034411344123441334414344153441634417344183441934420344213442234423344243442534426344273442834429344303443134432344333443434435344363443734438344393444034441344423444334444344453444634447344483444934450344513445234453344543445534456344573445834459344603446134462344633446434465344663446734468344693447034471344723447334474344753447634477344783447934480344813448234483344843448534486344873448834489344903449134492344933449434495344963449734498344993450034501345023450334504345053450634507345083450934510345113451234513345143451534516345173451834519345203452134522345233452434525345263452734528345293453034531345323453334534345353453634537345383453934540345413454234543345443454534546345473454834549345503455134552345533455434555345563455734558345593456034561345623456334564345653456634567345683456934570345713457234573345743457534576345773457834579345803458134582345833458434585345863458734588345893459034591345923459334594345953459634597345983459934600346013460234603346043460534606346073460834609346103461134612346133461434615346163461734618346193462034621346223462334624346253462634627346283462934630346313463234633346343463534636346373463834639346403464134642346433464434645346463464734648346493465034651346523465334654346553465634657346583465934660346613466234663346643466534666346673466834669346703467134672346733467434675346763467734678346793468034681346823468334684346853468634687346883468934690346913469234693346943469534696346973469834699347003470134702347033470434705347063470734708347093471034711347123471334714347153471634717347183471934720347213472234723347243472534726347273472834729347303473134732347333473434735347363473734738347393474034741347423474334744347453474634747347483474934750347513475234753347543475534756347573475834759347603476134762347633476434765347663476734768347693477034771347723477334774347753477634777347783477934780347813478234783347843478534786347873478834789347903479134792347933479434795347963479734798347993480034801348023480334804348053480634807348083480934810348113481234813348143481534816348173481834819348203482134822348233482434825348263482734828348293483034831348323483334834348353483634837348383483934840348413484234843348443484534846348473484834849348503485134852348533485434855348563485734858348593486034861348623486334864348653486634867348683486934870348713487234873348743487534876348773487834879348803488134882348833488434885348863488734888348893489034891348923489334894348953489634897348983489934900349013490234903349043490534906349073490834909349103491134912349133491434915349163491734918349193492034921349223492334924349253492634927349283492934930349313493234933349343493534936349373493834939349403494134942349433494434945349463494734948349493495034951349523495334954349553495634957349583495934960349613496234963349643496534966349673496834969349703497134972349733497434975349763497734978349793498034981349823498334984349853498634987349883498934990349913499234993349943499534996349973499834999350003500135002350033500435005350063500735008350093501035011350123501335014350153501635017350183501935020350213502235023350243502535026350273502835029350303503135032350333503435035350363503735038350393504035041350423504335044350453504635047350483504935050350513505235053350543505535056350573505835059350603506135062350633506435065350663506735068350693507035071350723507335074350753507635077350783507935080350813508235083350843508535086350873508835089350903509135092350933509435095350963509735098350993510035101351023510335104351053510635107351083510935110351113511235113351143511535116351173511835119351203512135122351233512435125351263512735128351293513035131351323513335134351353513635137351383513935140351413514235143351443514535146351473514835149351503515135152351533515435155351563515735158351593516035161351623516335164351653516635167351683516935170351713517235173351743517535176351773517835179351803518135182351833518435185351863518735188351893519035191351923519335194351953519635197351983519935200352013520235203352043520535206352073520835209352103521135212352133521435215352163521735218352193522035221352223522335224352253522635227352283522935230352313523235233352343523535236352373523835239352403524135242352433524435245352463524735248352493525035251352523525335254352553525635257352583525935260352613526235263352643526535266352673526835269352703527135272352733527435275352763527735278352793528035281352823528335284352853528635287352883528935290352913529235293352943529535296352973529835299353003530135302353033530435305353063530735308353093531035311353123531335314353153531635317353183531935320353213532235323353243532535326353273532835329353303533135332353333533435335353363533735338353393534035341353423534335344353453534635347353483534935350353513535235353353543535535356353573535835359353603536135362353633536435365353663536735368353693537035371353723537335374353753537635377353783537935380353813538235383353843538535386353873538835389353903539135392353933539435395353963539735398353993540035401354023540335404354053540635407354083540935410354113541235413354143541535416354173541835419354203542135422354233542435425354263542735428354293543035431354323543335434354353543635437354383543935440354413544235443354443544535446354473544835449354503545135452354533545435455354563545735458354593546035461354623546335464354653546635467354683546935470354713547235473354743547535476354773547835479354803548135482354833548435485354863548735488354893549035491354923549335494354953549635497354983549935500355013550235503355043550535506355073550835509355103551135512355133551435515355163551735518355193552035521355223552335524355253552635527355283552935530355313553235533355343553535536355373553835539355403554135542355433554435545355463554735548355493555035551355523555335554355553555635557355583555935560355613556235563355643556535566355673556835569355703557135572355733557435575355763557735578355793558035581355823558335584355853558635587355883558935590355913559235593355943559535596355973559835599356003560135602356033560435605356063560735608356093561035611356123561335614356153561635617356183561935620356213562235623356243562535626356273562835629356303563135632356333563435635356363563735638356393564035641356423564335644356453564635647356483564935650356513565235653356543565535656356573565835659356603566135662356633566435665356663566735668356693567035671356723567335674356753567635677356783567935680356813568235683356843568535686356873568835689356903569135692356933569435695356963569735698356993570035701357023570335704357053570635707357083570935710357113571235713357143571535716357173571835719357203572135722357233572435725357263572735728357293573035731357323573335734357353573635737357383573935740357413574235743357443574535746357473574835749357503575135752357533575435755357563575735758357593576035761357623576335764357653576635767357683576935770357713577235773357743577535776357773577835779357803578135782357833578435785357863578735788357893579035791357923579335794357953579635797357983579935800358013580235803358043580535806358073580835809358103581135812358133581435815358163581735818358193582035821358223582335824358253582635827358283582935830358313583235833358343583535836358373583835839358403584135842358433584435845358463584735848358493585035851358523585335854358553585635857358583585935860358613586235863358643586535866358673586835869358703587135872358733587435875358763587735878358793588035881358823588335884358853588635887358883588935890358913589235893358943589535896358973589835899359003590135902359033590435905359063590735908359093591035911359123591335914359153591635917359183591935920359213592235923359243592535926359273592835929359303593135932359333593435935359363593735938359393594035941359423594335944359453594635947359483594935950359513595235953359543595535956359573595835959359603596135962359633596435965359663596735968359693597035971359723597335974359753597635977359783597935980359813598235983359843598535986359873598835989359903599135992359933599435995359963599735998359993600036001360023600336004360053600636007360083600936010360113601236013360143601536016360173601836019360203602136022360233602436025360263602736028360293603036031360323603336034360353603636037360383603936040360413604236043360443604536046360473604836049360503605136052360533605436055360563605736058360593606036061360623606336064360653606636067360683606936070360713607236073360743607536076360773607836079360803608136082360833608436085360863608736088360893609036091360923609336094360953609636097360983609936100361013610236103361043610536106361073610836109361103611136112361133611436115361163611736118361193612036121361223612336124361253612636127361283612936130361313613236133361343613536136361373613836139361403614136142361433614436145361463614736148361493615036151361523615336154361553615636157361583615936160361613616236163361643616536166361673616836169361703617136172361733617436175361763617736178361793618036181361823618336184361853618636187361883618936190361913619236193361943619536196361973619836199362003620136202362033620436205362063620736208362093621036211362123621336214362153621636217362183621936220362213622236223362243622536226362273622836229362303623136232362333623436235362363623736238362393624036241362423624336244362453624636247362483624936250362513625236253362543625536256362573625836259362603626136262362633626436265362663626736268362693627036271362723627336274362753627636277362783627936280362813628236283362843628536286362873628836289362903629136292362933629436295362963629736298362993630036301363023630336304363053630636307363083630936310363113631236313363143631536316363173631836319363203632136322363233632436325363263632736328363293633036331363323633336334363353633636337363383633936340363413634236343363443634536346363473634836349363503635136352363533635436355363563635736358363593636036361363623636336364363653636636367363683636936370363713637236373363743637536376363773637836379363803638136382363833638436385363863638736388363893639036391363923639336394363953639636397363983639936400364013640236403364043640536406364073640836409364103641136412364133641436415364163641736418364193642036421364223642336424364253642636427364283642936430364313643236433364343643536436364373643836439364403644136442364433644436445364463644736448364493645036451364523645336454364553645636457364583645936460364613646236463364643646536466364673646836469364703647136472364733647436475364763647736478364793648036481364823648336484364853648636487364883648936490364913649236493364943649536496364973649836499365003650136502365033650436505365063650736508365093651036511365123651336514365153651636517365183651936520365213652236523365243652536526365273652836529365303653136532365333653436535365363653736538365393654036541365423654336544365453654636547365483654936550365513655236553365543655536556365573655836559365603656136562365633656436565365663656736568365693657036571365723657336574365753657636577365783657936580365813658236583365843658536586365873658836589365903659136592365933659436595365963659736598365993660036601366023660336604366053660636607366083660936610366113661236613366143661536616366173661836619366203662136622366233662436625366263662736628366293663036631366323663336634366353663636637366383663936640366413664236643366443664536646366473664836649366503665136652366533665436655366563665736658366593666036661366623666336664366653666636667366683666936670366713667236673366743667536676366773667836679366803668136682366833668436685366863668736688366893669036691366923669336694366953669636697366983669936700367013670236703367043670536706367073670836709367103671136712367133671436715367163671736718367193672036721367223672336724367253672636727367283672936730367313673236733367343673536736367373673836739367403674136742367433674436745367463674736748367493675036751367523675336754367553675636757367583675936760367613676236763367643676536766367673676836769367703677136772367733677436775367763677736778367793678036781367823678336784367853678636787367883678936790367913679236793367943679536796367973679836799368003680136802368033680436805368063680736808368093681036811368123681336814368153681636817368183681936820368213682236823368243682536826368273682836829368303683136832368333683436835368363683736838368393684036841368423684336844368453684636847368483684936850368513685236853368543685536856368573685836859368603686136862368633686436865368663686736868368693687036871368723687336874368753687636877368783687936880368813688236883368843688536886368873688836889368903689136892368933689436895368963689736898368993690036901369023690336904369053690636907369083690936910369113691236913369143691536916369173691836919369203692136922369233692436925369263692736928369293693036931369323693336934369353693636937369383693936940369413694236943369443694536946369473694836949369503695136952369533695436955369563695736958369593696036961369623696336964369653696636967369683696936970369713697236973369743697536976369773697836979369803698136982369833698436985369863698736988369893699036991369923699336994369953699636997369983699937000370013700237003370043700537006370073700837009370103701137012370133701437015370163701737018370193702037021370223702337024370253702637027370283702937030370313703237033370343703537036370373703837039370403704137042370433704437045370463704737048370493705037051370523705337054370553705637057370583705937060370613706237063370643706537066370673706837069370703707137072370733707437075370763707737078370793708037081370823708337084370853708637087370883708937090370913709237093370943709537096370973709837099371003710137102371033710437105371063710737108371093711037111371123711337114371153711637117371183711937120371213712237123371243712537126371273712837129371303713137132371333713437135371363713737138371393714037141371423714337144371453714637147371483714937150371513715237153371543715537156371573715837159371603716137162371633716437165371663716737168371693717037171371723717337174371753717637177371783717937180371813718237183371843718537186371873718837189371903719137192371933719437195371963719737198371993720037201372023720337204372053720637207372083720937210372113721237213372143721537216372173721837219372203722137222372233722437225372263722737228372293723037231372323723337234372353723637237372383723937240372413724237243372443724537246372473724837249372503725137252372533725437255372563725737258372593726037261372623726337264372653726637267372683726937270372713727237273372743727537276372773727837279372803728137282372833728437285372863728737288372893729037291372923729337294372953729637297372983729937300373013730237303373043730537306373073730837309373103731137312373133731437315373163731737318373193732037321373223732337324373253732637327373283732937330373313733237333373343733537336373373733837339373403734137342373433734437345373463734737348373493735037351373523735337354373553735637357373583735937360373613736237363373643736537366373673736837369373703737137372373733737437375373763737737378373793738037381373823738337384373853738637387373883738937390373913739237393373943739537396373973739837399374003740137402374033740437405374063740737408374093741037411374123741337414374153741637417374183741937420374213742237423374243742537426374273742837429374303743137432374333743437435374363743737438374393744037441374423744337444374453744637447374483744937450374513745237453374543745537456374573745837459374603746137462374633746437465374663746737468374693747037471374723747337474374753747637477374783747937480374813748237483374843748537486374873748837489374903749137492374933749437495374963749737498374993750037501375023750337504375053750637507375083750937510375113751237513375143751537516375173751837519375203752137522375233752437525375263752737528375293753037531375323753337534375353753637537375383753937540375413754237543375443754537546375473754837549375503755137552375533755437555375563755737558375593756037561375623756337564375653756637567375683756937570375713757237573375743757537576375773757837579375803758137582375833758437585375863758737588375893759037591375923759337594375953759637597375983759937600376013760237603376043760537606376073760837609376103761137612376133761437615376163761737618376193762037621376223762337624376253762637627376283762937630376313763237633376343763537636376373763837639376403764137642376433764437645376463764737648376493765037651376523765337654376553765637657376583765937660376613766237663376643766537666376673766837669376703767137672376733767437675376763767737678376793768037681376823768337684376853768637687376883768937690376913769237693376943769537696376973769837699377003770137702377033770437705377063770737708377093771037711377123771337714377153771637717377183771937720377213772237723377243772537726377273772837729377303773137732377333773437735377363773737738377393774037741377423774337744377453774637747377483774937750377513775237753377543775537756377573775837759377603776137762377633776437765377663776737768377693777037771377723777337774377753777637777377783777937780377813778237783377843778537786377873778837789377903779137792377933779437795377963779737798377993780037801378023780337804378053780637807378083780937810378113781237813378143781537816378173781837819378203782137822378233782437825378263782737828378293783037831378323783337834378353783637837378383783937840378413784237843378443784537846378473784837849378503785137852378533785437855378563785737858378593786037861378623786337864378653786637867378683786937870378713787237873378743787537876378773787837879378803788137882378833788437885378863788737888378893789037891378923789337894378953789637897378983789937900379013790237903379043790537906379073790837909379103791137912379133791437915379163791737918379193792037921379223792337924379253792637927379283792937930379313793237933379343793537936379373793837939379403794137942379433794437945379463794737948379493795037951379523795337954379553795637957379583795937960379613796237963379643796537966379673796837969379703797137972379733797437975379763797737978379793798037981379823798337984379853798637987379883798937990379913799237993379943799537996379973799837999380003800138002380033800438005380063800738008380093801038011380123801338014380153801638017380183801938020380213802238023380243802538026380273802838029380303803138032380333803438035380363803738038380393804038041380423804338044380453804638047380483804938050380513805238053380543805538056380573805838059380603806138062380633806438065380663806738068380693807038071380723807338074380753807638077380783807938080380813808238083380843808538086380873808838089380903809138092380933809438095380963809738098380993810038101381023810338104381053810638107381083810938110381113811238113381143811538116381173811838119381203812138122381233812438125381263812738128381293813038131381323813338134381353813638137381383813938140381413814238143381443814538146381473814838149381503815138152381533815438155381563815738158381593816038161381623816338164381653816638167381683816938170381713817238173381743817538176381773817838179381803818138182381833818438185381863818738188381893819038191381923819338194381953819638197381983819938200382013820238203382043820538206382073820838209382103821138212382133821438215382163821738218382193822038221382223822338224382253822638227382283822938230382313823238233382343823538236382373823838239382403824138242382433824438245382463824738248382493825038251382523825338254382553825638257382583825938260382613826238263382643826538266382673826838269382703827138272382733827438275382763827738278382793828038281382823828338284382853828638287382883828938290382913829238293382943829538296382973829838299383003830138302383033830438305383063830738308383093831038311383123831338314383153831638317383183831938320383213832238323383243832538326383273832838329383303833138332383333833438335383363833738338383393834038341383423834338344383453834638347383483834938350383513835238353383543835538356383573835838359383603836138362383633836438365383663836738368383693837038371383723837338374383753837638377383783837938380383813838238383383843838538386383873838838389383903839138392383933839438395383963839738398383993840038401384023840338404384053840638407384083840938410384113841238413384143841538416384173841838419384203842138422384233842438425384263842738428384293843038431384323843338434384353843638437384383843938440384413844238443384443844538446384473844838449384503845138452384533845438455384563845738458384593846038461384623846338464384653846638467384683846938470384713847238473384743847538476384773847838479384803848138482384833848438485384863848738488384893849038491384923849338494384953849638497384983849938500385013850238503385043850538506385073850838509385103851138512385133851438515385163851738518385193852038521385223852338524385253852638527385283852938530385313853238533385343853538536385373853838539385403854138542385433854438545385463854738548385493855038551385523855338554385553855638557385583855938560385613856238563385643856538566385673856838569385703857138572385733857438575385763857738578385793858038581385823858338584385853858638587385883858938590385913859238593385943859538596385973859838599386003860138602386033860438605386063860738608386093861038611386123861338614386153861638617386183861938620386213862238623386243862538626386273862838629386303863138632386333863438635386363863738638386393864038641386423864338644386453864638647386483864938650386513865238653386543865538656386573865838659386603866138662386633866438665386663866738668386693867038671386723867338674386753867638677386783867938680386813868238683386843868538686386873868838689386903869138692386933869438695386963869738698386993870038701387023870338704387053870638707387083870938710387113871238713387143871538716387173871838719387203872138722387233872438725387263872738728387293873038731387323873338734387353873638737387383873938740387413874238743387443874538746387473874838749387503875138752387533875438755387563875738758387593876038761387623876338764387653876638767387683876938770387713877238773387743877538776387773877838779387803878138782387833878438785387863878738788387893879038791387923879338794387953879638797387983879938800388013880238803388043880538806388073880838809388103881138812388133881438815388163881738818388193882038821388223882338824388253882638827388283882938830388313883238833388343883538836388373883838839388403884138842388433884438845388463884738848388493885038851388523885338854388553885638857388583885938860388613886238863388643886538866388673886838869388703887138872388733887438875388763887738878388793888038881388823888338884388853888638887388883888938890388913889238893388943889538896388973889838899389003890138902389033890438905389063890738908389093891038911389123891338914389153891638917389183891938920389213892238923389243892538926389273892838929389303893138932389333893438935389363893738938389393894038941389423894338944389453894638947389483894938950389513895238953389543895538956389573895838959389603896138962389633896438965389663896738968389693897038971389723897338974389753897638977389783897938980389813898238983389843898538986389873898838989389903899138992389933899438995389963899738998389993900039001390023900339004390053900639007390083900939010390113901239013390143901539016390173901839019390203902139022390233902439025390263902739028390293903039031390323903339034390353903639037390383903939040390413904239043390443904539046390473904839049390503905139052390533905439055390563905739058390593906039061390623906339064390653906639067390683906939070390713907239073390743907539076390773907839079390803908139082390833908439085390863908739088390893909039091390923909339094390953909639097390983909939100391013910239103391043910539106391073910839109391103911139112391133911439115391163911739118391193912039121391223912339124391253912639127391283912939130391313913239133391343913539136391373913839139391403914139142391433914439145391463914739148391493915039151391523915339154391553915639157391583915939160391613916239163391643916539166391673916839169391703917139172391733917439175391763917739178391793918039181391823918339184391853918639187391883918939190391913919239193391943919539196391973919839199392003920139202392033920439205392063920739208392093921039211392123921339214392153921639217392183921939220392213922239223392243922539226392273922839229392303923139232392333923439235392363923739238392393924039241392423924339244392453924639247392483924939250392513925239253392543925539256392573925839259392603926139262392633926439265392663926739268392693927039271392723927339274392753927639277392783927939280392813928239283392843928539286392873928839289392903929139292392933929439295392963929739298392993930039301393023930339304393053930639307393083930939310393113931239313393143931539316393173931839319393203932139322393233932439325393263932739328393293933039331393323933339334393353933639337393383933939340393413934239343393443934539346393473934839349393503935139352393533935439355393563935739358393593936039361393623936339364393653936639367393683936939370393713937239373393743937539376393773937839379393803938139382393833938439385393863938739388393893939039391393923939339394393953939639397393983939939400394013940239403394043940539406394073940839409394103941139412394133941439415394163941739418394193942039421394223942339424394253942639427394283942939430394313943239433394343943539436394373943839439394403944139442394433944439445394463944739448394493945039451394523945339454394553945639457394583945939460394613946239463394643946539466394673946839469394703947139472394733947439475394763947739478394793948039481394823948339484394853948639487394883948939490394913949239493394943949539496394973949839499395003950139502395033950439505395063950739508395093951039511395123951339514395153951639517395183951939520395213952239523395243952539526395273952839529395303953139532395333953439535395363953739538395393954039541395423954339544395453954639547395483954939550395513955239553395543955539556395573955839559395603956139562395633956439565395663956739568395693957039571395723957339574395753957639577395783957939580395813958239583395843958539586395873958839589395903959139592395933959439595395963959739598395993960039601396023960339604396053960639607396083960939610396113961239613396143961539616396173961839619396203962139622396233962439625396263962739628396293963039631396323963339634396353963639637396383963939640396413964239643396443964539646396473964839649396503965139652396533965439655396563965739658396593966039661396623966339664396653966639667396683966939670396713967239673396743967539676396773967839679396803968139682396833968439685396863968739688396893969039691396923969339694396953969639697396983969939700397013970239703397043970539706397073970839709397103971139712397133971439715397163971739718397193972039721397223972339724397253972639727397283972939730397313973239733397343973539736397373973839739397403974139742397433974439745397463974739748397493975039751397523975339754397553975639757397583975939760397613976239763397643976539766397673976839769397703977139772397733977439775397763977739778397793978039781397823978339784397853978639787397883978939790397913979239793397943979539796397973979839799398003980139802398033980439805398063980739808398093981039811398123981339814398153981639817398183981939820398213982239823398243982539826398273982839829398303983139832398333983439835398363983739838398393984039841398423984339844398453984639847398483984939850398513985239853398543985539856398573985839859398603986139862398633986439865398663986739868398693987039871398723987339874398753987639877398783987939880398813988239883398843988539886398873988839889398903989139892398933989439895398963989739898398993990039901399023990339904399053990639907399083990939910399113991239913399143991539916399173991839919399203992139922399233992439925399263992739928399293993039931399323993339934399353993639937399383993939940399413994239943399443994539946399473994839949399503995139952399533995439955399563995739958399593996039961399623996339964399653996639967399683996939970399713997239973399743997539976399773997839979399803998139982399833998439985399863998739988399893999039991399923999339994399953999639997399983999940000400014000240003400044000540006400074000840009400104001140012400134001440015400164001740018400194002040021400224002340024400254002640027400284002940030400314003240033400344003540036400374003840039400404004140042400434004440045400464004740048400494005040051400524005340054400554005640057400584005940060400614006240063400644006540066400674006840069400704007140072400734007440075400764007740078400794008040081400824008340084400854008640087400884008940090400914009240093400944009540096400974009840099401004010140102401034010440105401064010740108401094011040111401124011340114401154011640117401184011940120401214012240123401244012540126401274012840129401304013140132401334013440135401364013740138401394014040141401424014340144401454014640147401484014940150401514015240153401544015540156401574015840159401604016140162401634016440165401664016740168401694017040171401724017340174401754017640177401784017940180401814018240183401844018540186401874018840189401904019140192401934019440195401964019740198401994020040201402024020340204402054020640207402084020940210402114021240213402144021540216402174021840219402204022140222402234022440225402264022740228402294023040231402324023340234402354023640237402384023940240402414024240243402444024540246402474024840249402504025140252402534025440255402564025740258402594026040261402624026340264402654026640267402684026940270402714027240273402744027540276402774027840279402804028140282402834028440285402864028740288402894029040291402924029340294402954029640297402984029940300403014030240303403044030540306403074030840309403104031140312403134031440315403164031740318403194032040321403224032340324403254032640327403284032940330403314033240333403344033540336403374033840339403404034140342403434034440345403464034740348403494035040351403524035340354403554035640357403584035940360403614036240363403644036540366403674036840369403704037140372403734037440375403764037740378403794038040381403824038340384403854038640387403884038940390403914039240393403944039540396403974039840399404004040140402404034040440405404064040740408404094041040411404124041340414404154041640417404184041940420404214042240423404244042540426404274042840429404304043140432404334043440435404364043740438404394044040441404424044340444404454044640447404484044940450404514045240453404544045540456404574045840459404604046140462404634046440465404664046740468404694047040471404724047340474404754047640477404784047940480404814048240483404844048540486404874048840489404904049140492404934049440495404964049740498404994050040501405024050340504405054050640507405084050940510405114051240513405144051540516405174051840519405204052140522405234052440525405264052740528405294053040531405324053340534405354053640537405384053940540405414054240543405444054540546405474054840549405504055140552405534055440555405564055740558405594056040561405624056340564405654056640567405684056940570405714057240573405744057540576405774057840579405804058140582405834058440585405864058740588405894059040591405924059340594405954059640597405984059940600406014060240603406044060540606406074060840609406104061140612406134061440615406164061740618406194062040621406224062340624406254062640627406284062940630406314063240633406344063540636406374063840639406404064140642406434064440645406464064740648406494065040651406524065340654406554065640657406584065940660406614066240663406644066540666406674066840669406704067140672406734067440675406764067740678406794068040681406824068340684406854068640687406884068940690406914069240693406944069540696406974069840699407004070140702407034070440705407064070740708407094071040711407124071340714407154071640717407184071940720407214072240723407244072540726407274072840729407304073140732407334073440735407364073740738407394074040741407424074340744407454074640747407484074940750407514075240753407544075540756407574075840759407604076140762407634076440765407664076740768407694077040771407724077340774407754077640777407784077940780407814078240783407844078540786407874078840789407904079140792407934079440795407964079740798407994080040801408024080340804408054080640807408084080940810408114081240813408144081540816408174081840819408204082140822408234082440825408264082740828408294083040831408324083340834408354083640837408384083940840408414084240843408444084540846408474084840849408504085140852408534085440855408564085740858408594086040861408624086340864408654086640867408684086940870408714087240873408744087540876408774087840879408804088140882408834088440885408864088740888408894089040891408924089340894408954089640897408984089940900409014090240903409044090540906409074090840909409104091140912409134091440915409164091740918409194092040921409224092340924409254092640927409284092940930409314093240933409344093540936409374093840939409404094140942409434094440945409464094740948409494095040951409524095340954409554095640957409584095940960409614096240963409644096540966409674096840969409704097140972409734097440975409764097740978409794098040981409824098340984409854098640987409884098940990409914099240993409944099540996409974099840999410004100141002410034100441005410064100741008410094101041011410124101341014410154101641017410184101941020410214102241023410244102541026410274102841029410304103141032410334103441035410364103741038410394104041041410424104341044410454104641047410484104941050410514105241053410544105541056410574105841059410604106141062410634106441065410664106741068410694107041071410724107341074410754107641077410784107941080410814108241083410844108541086410874108841089410904109141092410934109441095410964109741098410994110041101411024110341104411054110641107411084110941110411114111241113411144111541116411174111841119411204112141122411234112441125411264112741128411294113041131411324113341134411354113641137411384113941140411414114241143411444114541146411474114841149
  1. /* Copyright 2012 Mozilla Foundation
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. *
  9. * Unless required by applicable law or agreed to in writing, software
  10. * distributed under the License is distributed on an "AS IS" BASIS,
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License.
  14. */
  15. /*jshint globalstrict: false */
  16. /* globals PDFJS */
  17. // Initializing PDFJS global object (if still undefined)
  18. if (typeof PDFJS === 'undefined') {
  19. (typeof window !== 'undefined' ? window : this).PDFJS = {};
  20. }
  21. PDFJS.version = '1.3.96';
  22. PDFJS.build = '0a21c8c';
  23. (function pdfjsWrapper() {
  24. // Use strict in our context only - users might not want it
  25. 'use strict';
  26. (function (root, factory) {
  27. if (typeof define === 'function' && define.amd) {
  28. define('pdfjs/shared/global', ['exports'], factory);
  29. } else if (typeof exports !== 'undefined') {
  30. factory(exports);
  31. } else {
  32. factory((root.pdfjsSharedGlobal = {}));
  33. }
  34. }(this, function (exports) {
  35. var globalScope = (typeof window !== 'undefined') ? window :
  36. (typeof global !== 'undefined') ? global :
  37. (typeof self !== 'undefined') ? self : this;
  38. var isWorker = (typeof window === 'undefined');
  39. // The global PDFJS object exposes the API
  40. // In production, it will be declared outside a global wrapper
  41. // In development, it will be declared here
  42. if (!globalScope.PDFJS) {
  43. globalScope.PDFJS = {};
  44. }
  45. globalScope.PDFJS.pdfBug = false;
  46. exports.globalScope = globalScope;
  47. exports.isWorker = isWorker;
  48. exports.PDFJS = globalScope.PDFJS;
  49. }));
  50. (function (root, factory) {
  51. if (typeof define === 'function' && define.amd) {
  52. define('pdfjs/shared/util', ['exports', 'pdfjs/shared/global'], factory);
  53. } else if (typeof exports !== 'undefined') {
  54. factory(exports, require('./global.js'));
  55. } else {
  56. factory((root.pdfjsSharedUtil = {}), root.pdfjsSharedGlobal);
  57. }
  58. }(this, function (exports, sharedGlobal) {
  59. var PDFJS = sharedGlobal.PDFJS;
  60. var globalScope = sharedGlobal.globalScope;
  61. var FONT_IDENTITY_MATRIX = [0.001, 0, 0, 0.001, 0, 0];
  62. var TextRenderingMode = {
  63. FILL: 0,
  64. STROKE: 1,
  65. FILL_STROKE: 2,
  66. INVISIBLE: 3,
  67. FILL_ADD_TO_PATH: 4,
  68. STROKE_ADD_TO_PATH: 5,
  69. FILL_STROKE_ADD_TO_PATH: 6,
  70. ADD_TO_PATH: 7,
  71. FILL_STROKE_MASK: 3,
  72. ADD_TO_PATH_FLAG: 4
  73. };
  74. var ImageKind = {
  75. GRAYSCALE_1BPP: 1,
  76. RGB_24BPP: 2,
  77. RGBA_32BPP: 3
  78. };
  79. var AnnotationType = {
  80. TEXT: 1,
  81. LINK: 2,
  82. FREETEXT: 3,
  83. LINE: 4,
  84. SQUARE: 5,
  85. CIRCLE: 6,
  86. POLYGON: 7,
  87. POLYLINE: 8,
  88. HIGHLIGHT: 9,
  89. UNDERLINE: 10,
  90. SQUIGGLY: 11,
  91. STRIKEOUT: 12,
  92. STAMP: 13,
  93. CARET: 14,
  94. INK: 15,
  95. POPUP: 16,
  96. FILEATTACHMENT: 17,
  97. SOUND: 18,
  98. MOVIE: 19,
  99. WIDGET: 20,
  100. SCREEN: 21,
  101. PRINTERMARK: 22,
  102. TRAPNET: 23,
  103. WATERMARK: 24,
  104. THREED: 25,
  105. REDACT: 26
  106. };
  107. var AnnotationFlag = {
  108. INVISIBLE: 0x01,
  109. HIDDEN: 0x02,
  110. PRINT: 0x04,
  111. NOZOOM: 0x08,
  112. NOROTATE: 0x10,
  113. NOVIEW: 0x20,
  114. READONLY: 0x40,
  115. LOCKED: 0x80,
  116. TOGGLENOVIEW: 0x100,
  117. LOCKEDCONTENTS: 0x200
  118. };
  119. var AnnotationBorderStyleType = {
  120. SOLID: 1,
  121. DASHED: 2,
  122. BEVELED: 3,
  123. INSET: 4,
  124. UNDERLINE: 5
  125. };
  126. var StreamType = {
  127. UNKNOWN: 0,
  128. FLATE: 1,
  129. LZW: 2,
  130. DCT: 3,
  131. JPX: 4,
  132. JBIG: 5,
  133. A85: 6,
  134. AHX: 7,
  135. CCF: 8,
  136. RL: 9
  137. };
  138. var FontType = {
  139. UNKNOWN: 0,
  140. TYPE1: 1,
  141. TYPE1C: 2,
  142. CIDFONTTYPE0: 3,
  143. CIDFONTTYPE0C: 4,
  144. TRUETYPE: 5,
  145. CIDFONTTYPE2: 6,
  146. TYPE3: 7,
  147. OPENTYPE: 8,
  148. TYPE0: 9,
  149. MMTYPE1: 10
  150. };
  151. PDFJS.VERBOSITY_LEVELS = {
  152. errors: 0,
  153. warnings: 1,
  154. infos: 5
  155. };
  156. // All the possible operations for an operator list.
  157. var OPS = PDFJS.OPS = {
  158. // Intentionally start from 1 so it is easy to spot bad operators that will be
  159. // 0's.
  160. dependency: 1,
  161. setLineWidth: 2,
  162. setLineCap: 3,
  163. setLineJoin: 4,
  164. setMiterLimit: 5,
  165. setDash: 6,
  166. setRenderingIntent: 7,
  167. setFlatness: 8,
  168. setGState: 9,
  169. save: 10,
  170. restore: 11,
  171. transform: 12,
  172. moveTo: 13,
  173. lineTo: 14,
  174. curveTo: 15,
  175. curveTo2: 16,
  176. curveTo3: 17,
  177. closePath: 18,
  178. rectangle: 19,
  179. stroke: 20,
  180. closeStroke: 21,
  181. fill: 22,
  182. eoFill: 23,
  183. fillStroke: 24,
  184. eoFillStroke: 25,
  185. closeFillStroke: 26,
  186. closeEOFillStroke: 27,
  187. endPath: 28,
  188. clip: 29,
  189. eoClip: 30,
  190. beginText: 31,
  191. endText: 32,
  192. setCharSpacing: 33,
  193. setWordSpacing: 34,
  194. setHScale: 35,
  195. setLeading: 36,
  196. setFont: 37,
  197. setTextRenderingMode: 38,
  198. setTextRise: 39,
  199. moveText: 40,
  200. setLeadingMoveText: 41,
  201. setTextMatrix: 42,
  202. nextLine: 43,
  203. showText: 44,
  204. showSpacedText: 45,
  205. nextLineShowText: 46,
  206. nextLineSetSpacingShowText: 47,
  207. setCharWidth: 48,
  208. setCharWidthAndBounds: 49,
  209. setStrokeColorSpace: 50,
  210. setFillColorSpace: 51,
  211. setStrokeColor: 52,
  212. setStrokeColorN: 53,
  213. setFillColor: 54,
  214. setFillColorN: 55,
  215. setStrokeGray: 56,
  216. setFillGray: 57,
  217. setStrokeRGBColor: 58,
  218. setFillRGBColor: 59,
  219. setStrokeCMYKColor: 60,
  220. setFillCMYKColor: 61,
  221. shadingFill: 62,
  222. beginInlineImage: 63,
  223. beginImageData: 64,
  224. endInlineImage: 65,
  225. paintXObject: 66,
  226. markPoint: 67,
  227. markPointProps: 68,
  228. beginMarkedContent: 69,
  229. beginMarkedContentProps: 70,
  230. endMarkedContent: 71,
  231. beginCompat: 72,
  232. endCompat: 73,
  233. paintFormXObjectBegin: 74,
  234. paintFormXObjectEnd: 75,
  235. beginGroup: 76,
  236. endGroup: 77,
  237. beginAnnotations: 78,
  238. endAnnotations: 79,
  239. beginAnnotation: 80,
  240. endAnnotation: 81,
  241. paintJpegXObject: 82,
  242. paintImageMaskXObject: 83,
  243. paintImageMaskXObjectGroup: 84,
  244. paintImageXObject: 85,
  245. paintInlineImageXObject: 86,
  246. paintInlineImageXObjectGroup: 87,
  247. paintImageXObjectRepeat: 88,
  248. paintImageMaskXObjectRepeat: 89,
  249. paintSolidColorImageMask: 90,
  250. constructPath: 91
  251. };
  252. // A notice for devs. These are good for things that are helpful to devs, such
  253. // as warning that Workers were disabled, which is important to devs but not
  254. // end users.
  255. function info(msg) {
  256. if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.infos) {
  257. console.log('Info: ' + msg);
  258. }
  259. }
  260. // Non-fatal warnings.
  261. function warn(msg) {
  262. if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.warnings) {
  263. console.log('Warning: ' + msg);
  264. }
  265. }
  266. // Deprecated API function -- treated as warnings.
  267. function deprecated(details) {
  268. warn('Deprecated API usage: ' + details);
  269. }
  270. // Fatal errors that should trigger the fallback UI and halt execution by
  271. // throwing an exception.
  272. function error(msg) {
  273. if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.errors) {
  274. console.log('Error: ' + msg);
  275. console.log(backtrace());
  276. }
  277. throw new Error(msg);
  278. }
  279. function backtrace() {
  280. try {
  281. throw new Error();
  282. } catch (e) {
  283. return e.stack ? e.stack.split('\n').slice(2).join('\n') : '';
  284. }
  285. }
  286. function assert(cond, msg) {
  287. if (!cond) {
  288. error(msg);
  289. }
  290. }
  291. var UNSUPPORTED_FEATURES = PDFJS.UNSUPPORTED_FEATURES = {
  292. unknown: 'unknown',
  293. forms: 'forms',
  294. javaScript: 'javaScript',
  295. smask: 'smask',
  296. shadingPattern: 'shadingPattern',
  297. font: 'font'
  298. };
  299. // Combines two URLs. The baseUrl shall be absolute URL. If the url is an
  300. // absolute URL, it will be returned as is.
  301. function combineUrl(baseUrl, url) {
  302. if (!url) {
  303. return baseUrl;
  304. }
  305. if (/^[a-z][a-z0-9+\-.]*:/i.test(url)) {
  306. return url;
  307. }
  308. var i;
  309. if (url.charAt(0) === '/') {
  310. // absolute path
  311. i = baseUrl.indexOf('://');
  312. if (url.charAt(1) === '/') {
  313. ++i;
  314. } else {
  315. i = baseUrl.indexOf('/', i + 3);
  316. }
  317. return baseUrl.substring(0, i) + url;
  318. } else {
  319. // relative path
  320. var pathLength = baseUrl.length;
  321. i = baseUrl.lastIndexOf('#');
  322. pathLength = i >= 0 ? i : pathLength;
  323. i = baseUrl.lastIndexOf('?', pathLength);
  324. pathLength = i >= 0 ? i : pathLength;
  325. var prefixLength = baseUrl.lastIndexOf('/', pathLength);
  326. return baseUrl.substring(0, prefixLength + 1) + url;
  327. }
  328. }
  329. // Validates if URL is safe and allowed, e.g. to avoid XSS.
  330. function isValidUrl(url, allowRelative) {
  331. if (!url) {
  332. return false;
  333. }
  334. // RFC 3986 (http://tools.ietf.org/html/rfc3986#section-3.1)
  335. // scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
  336. var protocol = /^[a-z][a-z0-9+\-.]*(?=:)/i.exec(url);
  337. if (!protocol) {
  338. return allowRelative;
  339. }
  340. protocol = protocol[0].toLowerCase();
  341. switch (protocol) {
  342. case 'http':
  343. case 'https':
  344. case 'ftp':
  345. case 'mailto':
  346. case 'tel':
  347. return true;
  348. default:
  349. return false;
  350. }
  351. }
  352. PDFJS.isValidUrl = isValidUrl;
  353. function shadow(obj, prop, value) {
  354. Object.defineProperty(obj, prop, { value: value,
  355. enumerable: true,
  356. configurable: true,
  357. writable: false });
  358. return value;
  359. }
  360. PDFJS.shadow = shadow;
  361. var LinkTarget = PDFJS.LinkTarget = {
  362. NONE: 0, // Default value.
  363. SELF: 1,
  364. BLANK: 2,
  365. PARENT: 3,
  366. TOP: 4,
  367. };
  368. var LinkTargetStringMap = [
  369. '',
  370. '_self',
  371. '_blank',
  372. '_parent',
  373. '_top'
  374. ];
  375. function isExternalLinkTargetSet() {
  376. if (PDFJS.openExternalLinksInNewWindow) {
  377. deprecated('PDFJS.openExternalLinksInNewWindow, please use ' +
  378. '"PDFJS.externalLinkTarget = PDFJS.LinkTarget.BLANK" instead.');
  379. if (PDFJS.externalLinkTarget === LinkTarget.NONE) {
  380. PDFJS.externalLinkTarget = LinkTarget.BLANK;
  381. }
  382. // Reset the deprecated parameter, to suppress further warnings.
  383. PDFJS.openExternalLinksInNewWindow = false;
  384. }
  385. switch (PDFJS.externalLinkTarget) {
  386. case LinkTarget.NONE:
  387. return false;
  388. case LinkTarget.SELF:
  389. case LinkTarget.BLANK:
  390. case LinkTarget.PARENT:
  391. case LinkTarget.TOP:
  392. return true;
  393. }
  394. warn('PDFJS.externalLinkTarget is invalid: ' + PDFJS.externalLinkTarget);
  395. // Reset the external link target, to suppress further warnings.
  396. PDFJS.externalLinkTarget = LinkTarget.NONE;
  397. return false;
  398. }
  399. PDFJS.isExternalLinkTargetSet = isExternalLinkTargetSet;
  400. var PasswordResponses = PDFJS.PasswordResponses = {
  401. NEED_PASSWORD: 1,
  402. INCORRECT_PASSWORD: 2
  403. };
  404. var PasswordException = (function PasswordExceptionClosure() {
  405. function PasswordException(msg, code) {
  406. this.name = 'PasswordException';
  407. this.message = msg;
  408. this.code = code;
  409. }
  410. PasswordException.prototype = new Error();
  411. PasswordException.constructor = PasswordException;
  412. return PasswordException;
  413. })();
  414. PDFJS.PasswordException = PasswordException;
  415. var UnknownErrorException = (function UnknownErrorExceptionClosure() {
  416. function UnknownErrorException(msg, details) {
  417. this.name = 'UnknownErrorException';
  418. this.message = msg;
  419. this.details = details;
  420. }
  421. UnknownErrorException.prototype = new Error();
  422. UnknownErrorException.constructor = UnknownErrorException;
  423. return UnknownErrorException;
  424. })();
  425. PDFJS.UnknownErrorException = UnknownErrorException;
  426. var InvalidPDFException = (function InvalidPDFExceptionClosure() {
  427. function InvalidPDFException(msg) {
  428. this.name = 'InvalidPDFException';
  429. this.message = msg;
  430. }
  431. InvalidPDFException.prototype = new Error();
  432. InvalidPDFException.constructor = InvalidPDFException;
  433. return InvalidPDFException;
  434. })();
  435. PDFJS.InvalidPDFException = InvalidPDFException;
  436. var MissingPDFException = (function MissingPDFExceptionClosure() {
  437. function MissingPDFException(msg) {
  438. this.name = 'MissingPDFException';
  439. this.message = msg;
  440. }
  441. MissingPDFException.prototype = new Error();
  442. MissingPDFException.constructor = MissingPDFException;
  443. return MissingPDFException;
  444. })();
  445. PDFJS.MissingPDFException = MissingPDFException;
  446. var UnexpectedResponseException =
  447. (function UnexpectedResponseExceptionClosure() {
  448. function UnexpectedResponseException(msg, status) {
  449. this.name = 'UnexpectedResponseException';
  450. this.message = msg;
  451. this.status = status;
  452. }
  453. UnexpectedResponseException.prototype = new Error();
  454. UnexpectedResponseException.constructor = UnexpectedResponseException;
  455. return UnexpectedResponseException;
  456. })();
  457. PDFJS.UnexpectedResponseException = UnexpectedResponseException;
  458. var NotImplementedException = (function NotImplementedExceptionClosure() {
  459. function NotImplementedException(msg) {
  460. this.message = msg;
  461. }
  462. NotImplementedException.prototype = new Error();
  463. NotImplementedException.prototype.name = 'NotImplementedException';
  464. NotImplementedException.constructor = NotImplementedException;
  465. return NotImplementedException;
  466. })();
  467. var MissingDataException = (function MissingDataExceptionClosure() {
  468. function MissingDataException(begin, end) {
  469. this.begin = begin;
  470. this.end = end;
  471. this.message = 'Missing data [' + begin + ', ' + end + ')';
  472. }
  473. MissingDataException.prototype = new Error();
  474. MissingDataException.prototype.name = 'MissingDataException';
  475. MissingDataException.constructor = MissingDataException;
  476. return MissingDataException;
  477. })();
  478. var XRefParseException = (function XRefParseExceptionClosure() {
  479. function XRefParseException(msg) {
  480. this.message = msg;
  481. }
  482. XRefParseException.prototype = new Error();
  483. XRefParseException.prototype.name = 'XRefParseException';
  484. XRefParseException.constructor = XRefParseException;
  485. return XRefParseException;
  486. })();
  487. function bytesToString(bytes) {
  488. assert(bytes !== null && typeof bytes === 'object' &&
  489. bytes.length !== undefined, 'Invalid argument for bytesToString');
  490. var length = bytes.length;
  491. var MAX_ARGUMENT_COUNT = 8192;
  492. if (length < MAX_ARGUMENT_COUNT) {
  493. return String.fromCharCode.apply(null, bytes);
  494. }
  495. var strBuf = [];
  496. for (var i = 0; i < length; i += MAX_ARGUMENT_COUNT) {
  497. var chunkEnd = Math.min(i + MAX_ARGUMENT_COUNT, length);
  498. var chunk = bytes.subarray(i, chunkEnd);
  499. strBuf.push(String.fromCharCode.apply(null, chunk));
  500. }
  501. return strBuf.join('');
  502. }
  503. function stringToBytes(str) {
  504. assert(typeof str === 'string', 'Invalid argument for stringToBytes');
  505. var length = str.length;
  506. var bytes = new Uint8Array(length);
  507. for (var i = 0; i < length; ++i) {
  508. bytes[i] = str.charCodeAt(i) & 0xFF;
  509. }
  510. return bytes;
  511. }
  512. function string32(value) {
  513. return String.fromCharCode((value >> 24) & 0xff, (value >> 16) & 0xff,
  514. (value >> 8) & 0xff, value & 0xff);
  515. }
  516. function log2(x) {
  517. var n = 1, i = 0;
  518. while (x > n) {
  519. n <<= 1;
  520. i++;
  521. }
  522. return i;
  523. }
  524. function readInt8(data, start) {
  525. return (data[start] << 24) >> 24;
  526. }
  527. function readUint16(data, offset) {
  528. return (data[offset] << 8) | data[offset + 1];
  529. }
  530. function readUint32(data, offset) {
  531. return ((data[offset] << 24) | (data[offset + 1] << 16) |
  532. (data[offset + 2] << 8) | data[offset + 3]) >>> 0;
  533. }
  534. // Lazy test the endianness of the platform
  535. // NOTE: This will be 'true' for simulated TypedArrays
  536. function isLittleEndian() {
  537. var buffer8 = new Uint8Array(2);
  538. buffer8[0] = 1;
  539. var buffer16 = new Uint16Array(buffer8.buffer);
  540. return (buffer16[0] === 1);
  541. }
  542. Object.defineProperty(PDFJS, 'isLittleEndian', {
  543. configurable: true,
  544. get: function PDFJS_isLittleEndian() {
  545. return shadow(PDFJS, 'isLittleEndian', isLittleEndian());
  546. }
  547. });
  548. // Lazy test if the userAgent support CanvasTypedArrays
  549. function hasCanvasTypedArrays() {
  550. var canvas = document.createElement('canvas');
  551. canvas.width = canvas.height = 1;
  552. var ctx = canvas.getContext('2d');
  553. var imageData = ctx.createImageData(1, 1);
  554. return (typeof imageData.data.buffer !== 'undefined');
  555. }
  556. Object.defineProperty(PDFJS, 'hasCanvasTypedArrays', {
  557. configurable: true,
  558. get: function PDFJS_hasCanvasTypedArrays() {
  559. return shadow(PDFJS, 'hasCanvasTypedArrays', hasCanvasTypedArrays());
  560. }
  561. });
  562. var Uint32ArrayView = (function Uint32ArrayViewClosure() {
  563. function Uint32ArrayView(buffer, length) {
  564. this.buffer = buffer;
  565. this.byteLength = buffer.length;
  566. this.length = length === undefined ? (this.byteLength >> 2) : length;
  567. ensureUint32ArrayViewProps(this.length);
  568. }
  569. Uint32ArrayView.prototype = Object.create(null);
  570. var uint32ArrayViewSetters = 0;
  571. function createUint32ArrayProp(index) {
  572. return {
  573. get: function () {
  574. var buffer = this.buffer, offset = index << 2;
  575. return (buffer[offset] | (buffer[offset + 1] << 8) |
  576. (buffer[offset + 2] << 16) | (buffer[offset + 3] << 24)) >>> 0;
  577. },
  578. set: function (value) {
  579. var buffer = this.buffer, offset = index << 2;
  580. buffer[offset] = value & 255;
  581. buffer[offset + 1] = (value >> 8) & 255;
  582. buffer[offset + 2] = (value >> 16) & 255;
  583. buffer[offset + 3] = (value >>> 24) & 255;
  584. }
  585. };
  586. }
  587. function ensureUint32ArrayViewProps(length) {
  588. while (uint32ArrayViewSetters < length) {
  589. Object.defineProperty(Uint32ArrayView.prototype,
  590. uint32ArrayViewSetters,
  591. createUint32ArrayProp(uint32ArrayViewSetters));
  592. uint32ArrayViewSetters++;
  593. }
  594. }
  595. return Uint32ArrayView;
  596. })();
  597. exports.Uint32ArrayView = Uint32ArrayView;
  598. var IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0];
  599. var Util = PDFJS.Util = (function UtilClosure() {
  600. function Util() {}
  601. var rgbBuf = ['rgb(', 0, ',', 0, ',', 0, ')'];
  602. // makeCssRgb() can be called thousands of times. Using |rgbBuf| avoids
  603. // creating many intermediate strings.
  604. Util.makeCssRgb = function Util_makeCssRgb(r, g, b) {
  605. rgbBuf[1] = r;
  606. rgbBuf[3] = g;
  607. rgbBuf[5] = b;
  608. return rgbBuf.join('');
  609. };
  610. // Concatenates two transformation matrices together and returns the result.
  611. Util.transform = function Util_transform(m1, m2) {
  612. return [
  613. m1[0] * m2[0] + m1[2] * m2[1],
  614. m1[1] * m2[0] + m1[3] * m2[1],
  615. m1[0] * m2[2] + m1[2] * m2[3],
  616. m1[1] * m2[2] + m1[3] * m2[3],
  617. m1[0] * m2[4] + m1[2] * m2[5] + m1[4],
  618. m1[1] * m2[4] + m1[3] * m2[5] + m1[5]
  619. ];
  620. };
  621. // For 2d affine transforms
  622. Util.applyTransform = function Util_applyTransform(p, m) {
  623. var xt = p[0] * m[0] + p[1] * m[2] + m[4];
  624. var yt = p[0] * m[1] + p[1] * m[3] + m[5];
  625. return [xt, yt];
  626. };
  627. Util.applyInverseTransform = function Util_applyInverseTransform(p, m) {
  628. var d = m[0] * m[3] - m[1] * m[2];
  629. var xt = (p[0] * m[3] - p[1] * m[2] + m[2] * m[5] - m[4] * m[3]) / d;
  630. var yt = (-p[0] * m[1] + p[1] * m[0] + m[4] * m[1] - m[5] * m[0]) / d;
  631. return [xt, yt];
  632. };
  633. // Applies the transform to the rectangle and finds the minimum axially
  634. // aligned bounding box.
  635. Util.getAxialAlignedBoundingBox =
  636. function Util_getAxialAlignedBoundingBox(r, m) {
  637. var p1 = Util.applyTransform(r, m);
  638. var p2 = Util.applyTransform(r.slice(2, 4), m);
  639. var p3 = Util.applyTransform([r[0], r[3]], m);
  640. var p4 = Util.applyTransform([r[2], r[1]], m);
  641. return [
  642. Math.min(p1[0], p2[0], p3[0], p4[0]),
  643. Math.min(p1[1], p2[1], p3[1], p4[1]),
  644. Math.max(p1[0], p2[0], p3[0], p4[0]),
  645. Math.max(p1[1], p2[1], p3[1], p4[1])
  646. ];
  647. };
  648. Util.inverseTransform = function Util_inverseTransform(m) {
  649. var d = m[0] * m[3] - m[1] * m[2];
  650. return [m[3] / d, -m[1] / d, -m[2] / d, m[0] / d,
  651. (m[2] * m[5] - m[4] * m[3]) / d, (m[4] * m[1] - m[5] * m[0]) / d];
  652. };
  653. // Apply a generic 3d matrix M on a 3-vector v:
  654. // | a b c | | X |
  655. // | d e f | x | Y |
  656. // | g h i | | Z |
  657. // M is assumed to be serialized as [a,b,c,d,e,f,g,h,i],
  658. // with v as [X,Y,Z]
  659. Util.apply3dTransform = function Util_apply3dTransform(m, v) {
  660. return [
  661. m[0] * v[0] + m[1] * v[1] + m[2] * v[2],
  662. m[3] * v[0] + m[4] * v[1] + m[5] * v[2],
  663. m[6] * v[0] + m[7] * v[1] + m[8] * v[2]
  664. ];
  665. };
  666. // This calculation uses Singular Value Decomposition.
  667. // The SVD can be represented with formula A = USV. We are interested in the
  668. // matrix S here because it represents the scale values.
  669. Util.singularValueDecompose2dScale =
  670. function Util_singularValueDecompose2dScale(m) {
  671. var transpose = [m[0], m[2], m[1], m[3]];
  672. // Multiply matrix m with its transpose.
  673. var a = m[0] * transpose[0] + m[1] * transpose[2];
  674. var b = m[0] * transpose[1] + m[1] * transpose[3];
  675. var c = m[2] * transpose[0] + m[3] * transpose[2];
  676. var d = m[2] * transpose[1] + m[3] * transpose[3];
  677. // Solve the second degree polynomial to get roots.
  678. var first = (a + d) / 2;
  679. var second = Math.sqrt((a + d) * (a + d) - 4 * (a * d - c * b)) / 2;
  680. var sx = first + second || 1;
  681. var sy = first - second || 1;
  682. // Scale values are the square roots of the eigenvalues.
  683. return [Math.sqrt(sx), Math.sqrt(sy)];
  684. };
  685. // Normalize rectangle rect=[x1, y1, x2, y2] so that (x1,y1) < (x2,y2)
  686. // For coordinate systems whose origin lies in the bottom-left, this
  687. // means normalization to (BL,TR) ordering. For systems with origin in the
  688. // top-left, this means (TL,BR) ordering.
  689. Util.normalizeRect = function Util_normalizeRect(rect) {
  690. var r = rect.slice(0); // clone rect
  691. if (rect[0] > rect[2]) {
  692. r[0] = rect[2];
  693. r[2] = rect[0];
  694. }
  695. if (rect[1] > rect[3]) {
  696. r[1] = rect[3];
  697. r[3] = rect[1];
  698. }
  699. return r;
  700. };
  701. // Returns a rectangle [x1, y1, x2, y2] corresponding to the
  702. // intersection of rect1 and rect2. If no intersection, returns 'false'
  703. // The rectangle coordinates of rect1, rect2 should be [x1, y1, x2, y2]
  704. Util.intersect = function Util_intersect(rect1, rect2) {
  705. function compare(a, b) {
  706. return a - b;
  707. }
  708. // Order points along the axes
  709. var orderedX = [rect1[0], rect1[2], rect2[0], rect2[2]].sort(compare),
  710. orderedY = [rect1[1], rect1[3], rect2[1], rect2[3]].sort(compare),
  711. result = [];
  712. rect1 = Util.normalizeRect(rect1);
  713. rect2 = Util.normalizeRect(rect2);
  714. // X: first and second points belong to different rectangles?
  715. if ((orderedX[0] === rect1[0] && orderedX[1] === rect2[0]) ||
  716. (orderedX[0] === rect2[0] && orderedX[1] === rect1[0])) {
  717. // Intersection must be between second and third points
  718. result[0] = orderedX[1];
  719. result[2] = orderedX[2];
  720. } else {
  721. return false;
  722. }
  723. // Y: first and second points belong to different rectangles?
  724. if ((orderedY[0] === rect1[1] && orderedY[1] === rect2[1]) ||
  725. (orderedY[0] === rect2[1] && orderedY[1] === rect1[1])) {
  726. // Intersection must be between second and third points
  727. result[1] = orderedY[1];
  728. result[3] = orderedY[2];
  729. } else {
  730. return false;
  731. }
  732. return result;
  733. };
  734. Util.sign = function Util_sign(num) {
  735. return num < 0 ? -1 : 1;
  736. };
  737. Util.appendToArray = function Util_appendToArray(arr1, arr2) {
  738. Array.prototype.push.apply(arr1, arr2);
  739. };
  740. Util.prependToArray = function Util_prependToArray(arr1, arr2) {
  741. Array.prototype.unshift.apply(arr1, arr2);
  742. };
  743. Util.extendObj = function extendObj(obj1, obj2) {
  744. for (var key in obj2) {
  745. obj1[key] = obj2[key];
  746. }
  747. };
  748. Util.getInheritableProperty = function Util_getInheritableProperty(dict,
  749. name) {
  750. while (dict && !dict.has(name)) {
  751. dict = dict.get('Parent');
  752. }
  753. if (!dict) {
  754. return null;
  755. }
  756. return dict.get(name);
  757. };
  758. Util.inherit = function Util_inherit(sub, base, prototype) {
  759. sub.prototype = Object.create(base.prototype);
  760. sub.prototype.constructor = sub;
  761. for (var prop in prototype) {
  762. sub.prototype[prop] = prototype[prop];
  763. }
  764. };
  765. Util.loadScript = function Util_loadScript(src, callback) {
  766. var script = document.createElement('script');
  767. var loaded = false;
  768. script.setAttribute('src', src);
  769. if (callback) {
  770. script.onload = function() {
  771. if (!loaded) {
  772. callback();
  773. }
  774. loaded = true;
  775. };
  776. }
  777. document.getElementsByTagName('head')[0].appendChild(script);
  778. };
  779. return Util;
  780. })();
  781. /**
  782. * PDF page viewport created based on scale, rotation and offset.
  783. * @class
  784. * @alias PDFJS.PageViewport
  785. */
  786. var PageViewport = PDFJS.PageViewport = (function PageViewportClosure() {
  787. /**
  788. * @constructor
  789. * @private
  790. * @param viewBox {Array} xMin, yMin, xMax and yMax coordinates.
  791. * @param scale {number} scale of the viewport.
  792. * @param rotation {number} rotations of the viewport in degrees.
  793. * @param offsetX {number} offset X
  794. * @param offsetY {number} offset Y
  795. * @param dontFlip {boolean} if true, axis Y will not be flipped.
  796. */
  797. function PageViewport(viewBox, scale, rotation, offsetX, offsetY, dontFlip) {
  798. this.viewBox = viewBox;
  799. this.scale = scale;
  800. this.rotation = rotation;
  801. this.offsetX = offsetX;
  802. this.offsetY = offsetY;
  803. // creating transform to convert pdf coordinate system to the normal
  804. // canvas like coordinates taking in account scale and rotation
  805. var centerX = (viewBox[2] + viewBox[0]) / 2;
  806. var centerY = (viewBox[3] + viewBox[1]) / 2;
  807. var rotateA, rotateB, rotateC, rotateD;
  808. rotation = rotation % 360;
  809. rotation = rotation < 0 ? rotation + 360 : rotation;
  810. switch (rotation) {
  811. case 180:
  812. rotateA = -1; rotateB = 0; rotateC = 0; rotateD = 1;
  813. break;
  814. case 90:
  815. rotateA = 0; rotateB = 1; rotateC = 1; rotateD = 0;
  816. break;
  817. case 270:
  818. rotateA = 0; rotateB = -1; rotateC = -1; rotateD = 0;
  819. break;
  820. //case 0:
  821. default:
  822. rotateA = 1; rotateB = 0; rotateC = 0; rotateD = -1;
  823. break;
  824. }
  825. if (dontFlip) {
  826. rotateC = -rotateC; rotateD = -rotateD;
  827. }
  828. var offsetCanvasX, offsetCanvasY;
  829. var width, height;
  830. if (rotateA === 0) {
  831. offsetCanvasX = Math.abs(centerY - viewBox[1]) * scale + offsetX;
  832. offsetCanvasY = Math.abs(centerX - viewBox[0]) * scale + offsetY;
  833. width = Math.abs(viewBox[3] - viewBox[1]) * scale;
  834. height = Math.abs(viewBox[2] - viewBox[0]) * scale;
  835. } else {
  836. offsetCanvasX = Math.abs(centerX - viewBox[0]) * scale + offsetX;
  837. offsetCanvasY = Math.abs(centerY - viewBox[1]) * scale + offsetY;
  838. width = Math.abs(viewBox[2] - viewBox[0]) * scale;
  839. height = Math.abs(viewBox[3] - viewBox[1]) * scale;
  840. }
  841. // creating transform for the following operations:
  842. // translate(-centerX, -centerY), rotate and flip vertically,
  843. // scale, and translate(offsetCanvasX, offsetCanvasY)
  844. this.transform = [
  845. rotateA * scale,
  846. rotateB * scale,
  847. rotateC * scale,
  848. rotateD * scale,
  849. offsetCanvasX - rotateA * scale * centerX - rotateC * scale * centerY,
  850. offsetCanvasY - rotateB * scale * centerX - rotateD * scale * centerY
  851. ];
  852. this.width = width;
  853. this.height = height;
  854. this.fontScale = scale;
  855. }
  856. PageViewport.prototype = /** @lends PDFJS.PageViewport.prototype */ {
  857. /**
  858. * Clones viewport with additional properties.
  859. * @param args {Object} (optional) If specified, may contain the 'scale' or
  860. * 'rotation' properties to override the corresponding properties in
  861. * the cloned viewport.
  862. * @returns {PDFJS.PageViewport} Cloned viewport.
  863. */
  864. clone: function PageViewPort_clone(args) {
  865. args = args || {};
  866. var scale = 'scale' in args ? args.scale : this.scale;
  867. var rotation = 'rotation' in args ? args.rotation : this.rotation;
  868. return new PageViewport(this.viewBox.slice(), scale, rotation,
  869. this.offsetX, this.offsetY, args.dontFlip);
  870. },
  871. /**
  872. * Converts PDF point to the viewport coordinates. For examples, useful for
  873. * converting PDF location into canvas pixel coordinates.
  874. * @param x {number} X coordinate.
  875. * @param y {number} Y coordinate.
  876. * @returns {Object} Object that contains 'x' and 'y' properties of the
  877. * point in the viewport coordinate space.
  878. * @see {@link convertToPdfPoint}
  879. * @see {@link convertToViewportRectangle}
  880. */
  881. convertToViewportPoint: function PageViewport_convertToViewportPoint(x, y) {
  882. return Util.applyTransform([x, y], this.transform);
  883. },
  884. /**
  885. * Converts PDF rectangle to the viewport coordinates.
  886. * @param rect {Array} xMin, yMin, xMax and yMax coordinates.
  887. * @returns {Array} Contains corresponding coordinates of the rectangle
  888. * in the viewport coordinate space.
  889. * @see {@link convertToViewportPoint}
  890. */
  891. convertToViewportRectangle:
  892. function PageViewport_convertToViewportRectangle(rect) {
  893. var tl = Util.applyTransform([rect[0], rect[1]], this.transform);
  894. var br = Util.applyTransform([rect[2], rect[3]], this.transform);
  895. return [tl[0], tl[1], br[0], br[1]];
  896. },
  897. /**
  898. * Converts viewport coordinates to the PDF location. For examples, useful
  899. * for converting canvas pixel location into PDF one.
  900. * @param x {number} X coordinate.
  901. * @param y {number} Y coordinate.
  902. * @returns {Object} Object that contains 'x' and 'y' properties of the
  903. * point in the PDF coordinate space.
  904. * @see {@link convertToViewportPoint}
  905. */
  906. convertToPdfPoint: function PageViewport_convertToPdfPoint(x, y) {
  907. return Util.applyInverseTransform([x, y], this.transform);
  908. }
  909. };
  910. return PageViewport;
  911. })();
  912. var PDFStringTranslateTable = [
  913. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  914. 0x2D8, 0x2C7, 0x2C6, 0x2D9, 0x2DD, 0x2DB, 0x2DA, 0x2DC, 0, 0, 0, 0, 0, 0, 0,
  915. 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,
  916. 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,
  917. 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,
  918. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x2022, 0x2020, 0x2021, 0x2026, 0x2014,
  919. 0x2013, 0x192, 0x2044, 0x2039, 0x203A, 0x2212, 0x2030, 0x201E, 0x201C,
  920. 0x201D, 0x2018, 0x2019, 0x201A, 0x2122, 0xFB01, 0xFB02, 0x141, 0x152, 0x160,
  921. 0x178, 0x17D, 0x131, 0x142, 0x153, 0x161, 0x17E, 0, 0x20AC
  922. ];
  923. function stringToPDFString(str) {
  924. var i, n = str.length, strBuf = [];
  925. if (str[0] === '\xFE' && str[1] === '\xFF') {
  926. // UTF16BE BOM
  927. for (i = 2; i < n; i += 2) {
  928. strBuf.push(String.fromCharCode(
  929. (str.charCodeAt(i) << 8) | str.charCodeAt(i + 1)));
  930. }
  931. } else {
  932. for (i = 0; i < n; ++i) {
  933. var code = PDFStringTranslateTable[str.charCodeAt(i)];
  934. strBuf.push(code ? String.fromCharCode(code) : str.charAt(i));
  935. }
  936. }
  937. return strBuf.join('');
  938. }
  939. function stringToUTF8String(str) {
  940. return decodeURIComponent(escape(str));
  941. }
  942. function utf8StringToString(str) {
  943. return unescape(encodeURIComponent(str));
  944. }
  945. function isEmptyObj(obj) {
  946. for (var key in obj) {
  947. return false;
  948. }
  949. return true;
  950. }
  951. function isBool(v) {
  952. return typeof v === 'boolean';
  953. }
  954. function isInt(v) {
  955. return typeof v === 'number' && ((v | 0) === v);
  956. }
  957. function isNum(v) {
  958. return typeof v === 'number';
  959. }
  960. function isString(v) {
  961. return typeof v === 'string';
  962. }
  963. function isArray(v) {
  964. return v instanceof Array;
  965. }
  966. function isArrayBuffer(v) {
  967. return typeof v === 'object' && v !== null && v.byteLength !== undefined;
  968. }
  969. /**
  970. * Promise Capability object.
  971. *
  972. * @typedef {Object} PromiseCapability
  973. * @property {Promise} promise - A promise object.
  974. * @property {function} resolve - Fullfills the promise.
  975. * @property {function} reject - Rejects the promise.
  976. */
  977. /**
  978. * Creates a promise capability object.
  979. * @alias PDFJS.createPromiseCapability
  980. *
  981. * @return {PromiseCapability} A capability object contains:
  982. * - a Promise, resolve and reject methods.
  983. */
  984. function createPromiseCapability() {
  985. var capability = {};
  986. capability.promise = new Promise(function (resolve, reject) {
  987. capability.resolve = resolve;
  988. capability.reject = reject;
  989. });
  990. return capability;
  991. }
  992. PDFJS.createPromiseCapability = createPromiseCapability;
  993. /**
  994. * Polyfill for Promises:
  995. * The following promise implementation tries to generally implement the
  996. * Promise/A+ spec. Some notable differences from other promise libaries are:
  997. * - There currently isn't a seperate deferred and promise object.
  998. * - Unhandled rejections eventually show an error if they aren't handled.
  999. *
  1000. * Based off of the work in:
  1001. * https://bugzilla.mozilla.org/show_bug.cgi?id=810490
  1002. */
  1003. (function PromiseClosure() {
  1004. if (globalScope.Promise) {
  1005. // Promises existing in the DOM/Worker, checking presence of all/resolve
  1006. if (typeof globalScope.Promise.all !== 'function') {
  1007. globalScope.Promise.all = function (iterable) {
  1008. var count = 0, results = [], resolve, reject;
  1009. var promise = new globalScope.Promise(function (resolve_, reject_) {
  1010. resolve = resolve_;
  1011. reject = reject_;
  1012. });
  1013. iterable.forEach(function (p, i) {
  1014. count++;
  1015. p.then(function (result) {
  1016. results[i] = result;
  1017. count--;
  1018. if (count === 0) {
  1019. resolve(results);
  1020. }
  1021. }, reject);
  1022. });
  1023. if (count === 0) {
  1024. resolve(results);
  1025. }
  1026. return promise;
  1027. };
  1028. }
  1029. if (typeof globalScope.Promise.resolve !== 'function') {
  1030. globalScope.Promise.resolve = function (value) {
  1031. return new globalScope.Promise(function (resolve) { resolve(value); });
  1032. };
  1033. }
  1034. if (typeof globalScope.Promise.reject !== 'function') {
  1035. globalScope.Promise.reject = function (reason) {
  1036. return new globalScope.Promise(function (resolve, reject) {
  1037. reject(reason);
  1038. });
  1039. };
  1040. }
  1041. if (typeof globalScope.Promise.prototype.catch !== 'function') {
  1042. globalScope.Promise.prototype.catch = function (onReject) {
  1043. return globalScope.Promise.prototype.then(undefined, onReject);
  1044. };
  1045. }
  1046. return;
  1047. }
  1048. var STATUS_PENDING = 0;
  1049. var STATUS_RESOLVED = 1;
  1050. var STATUS_REJECTED = 2;
  1051. // In an attempt to avoid silent exceptions, unhandled rejections are
  1052. // tracked and if they aren't handled in a certain amount of time an
  1053. // error is logged.
  1054. var REJECTION_TIMEOUT = 500;
  1055. var HandlerManager = {
  1056. handlers: [],
  1057. running: false,
  1058. unhandledRejections: [],
  1059. pendingRejectionCheck: false,
  1060. scheduleHandlers: function scheduleHandlers(promise) {
  1061. if (promise._status === STATUS_PENDING) {
  1062. return;
  1063. }
  1064. this.handlers = this.handlers.concat(promise._handlers);
  1065. promise._handlers = [];
  1066. if (this.running) {
  1067. return;
  1068. }
  1069. this.running = true;
  1070. setTimeout(this.runHandlers.bind(this), 0);
  1071. },
  1072. runHandlers: function runHandlers() {
  1073. var RUN_TIMEOUT = 1; // ms
  1074. var timeoutAt = Date.now() + RUN_TIMEOUT;
  1075. while (this.handlers.length > 0) {
  1076. var handler = this.handlers.shift();
  1077. var nextStatus = handler.thisPromise._status;
  1078. var nextValue = handler.thisPromise._value;
  1079. try {
  1080. if (nextStatus === STATUS_RESOLVED) {
  1081. if (typeof handler.onResolve === 'function') {
  1082. nextValue = handler.onResolve(nextValue);
  1083. }
  1084. } else if (typeof handler.onReject === 'function') {
  1085. nextValue = handler.onReject(nextValue);
  1086. nextStatus = STATUS_RESOLVED;
  1087. if (handler.thisPromise._unhandledRejection) {
  1088. this.removeUnhandeledRejection(handler.thisPromise);
  1089. }
  1090. }
  1091. } catch (ex) {
  1092. nextStatus = STATUS_REJECTED;
  1093. nextValue = ex;
  1094. }
  1095. handler.nextPromise._updateStatus(nextStatus, nextValue);
  1096. if (Date.now() >= timeoutAt) {
  1097. break;
  1098. }
  1099. }
  1100. if (this.handlers.length > 0) {
  1101. setTimeout(this.runHandlers.bind(this), 0);
  1102. return;
  1103. }
  1104. this.running = false;
  1105. },
  1106. addUnhandledRejection: function addUnhandledRejection(promise) {
  1107. this.unhandledRejections.push({
  1108. promise: promise,
  1109. time: Date.now()
  1110. });
  1111. this.scheduleRejectionCheck();
  1112. },
  1113. removeUnhandeledRejection: function removeUnhandeledRejection(promise) {
  1114. promise._unhandledRejection = false;
  1115. for (var i = 0; i < this.unhandledRejections.length; i++) {
  1116. if (this.unhandledRejections[i].promise === promise) {
  1117. this.unhandledRejections.splice(i);
  1118. i--;
  1119. }
  1120. }
  1121. },
  1122. scheduleRejectionCheck: function scheduleRejectionCheck() {
  1123. if (this.pendingRejectionCheck) {
  1124. return;
  1125. }
  1126. this.pendingRejectionCheck = true;
  1127. setTimeout(function rejectionCheck() {
  1128. this.pendingRejectionCheck = false;
  1129. var now = Date.now();
  1130. for (var i = 0; i < this.unhandledRejections.length; i++) {
  1131. if (now - this.unhandledRejections[i].time > REJECTION_TIMEOUT) {
  1132. var unhandled = this.unhandledRejections[i].promise._value;
  1133. var msg = 'Unhandled rejection: ' + unhandled;
  1134. if (unhandled.stack) {
  1135. msg += '\n' + unhandled.stack;
  1136. }
  1137. warn(msg);
  1138. this.unhandledRejections.splice(i);
  1139. i--;
  1140. }
  1141. }
  1142. if (this.unhandledRejections.length) {
  1143. this.scheduleRejectionCheck();
  1144. }
  1145. }.bind(this), REJECTION_TIMEOUT);
  1146. }
  1147. };
  1148. function Promise(resolver) {
  1149. this._status = STATUS_PENDING;
  1150. this._handlers = [];
  1151. try {
  1152. resolver.call(this, this._resolve.bind(this), this._reject.bind(this));
  1153. } catch (e) {
  1154. this._reject(e);
  1155. }
  1156. }
  1157. /**
  1158. * Builds a promise that is resolved when all the passed in promises are
  1159. * resolved.
  1160. * @param {array} array of data and/or promises to wait for.
  1161. * @return {Promise} New dependant promise.
  1162. */
  1163. Promise.all = function Promise_all(promises) {
  1164. var resolveAll, rejectAll;
  1165. var deferred = new Promise(function (resolve, reject) {
  1166. resolveAll = resolve;
  1167. rejectAll = reject;
  1168. });
  1169. var unresolved = promises.length;
  1170. var results = [];
  1171. if (unresolved === 0) {
  1172. resolveAll(results);
  1173. return deferred;
  1174. }
  1175. function reject(reason) {
  1176. if (deferred._status === STATUS_REJECTED) {
  1177. return;
  1178. }
  1179. results = [];
  1180. rejectAll(reason);
  1181. }
  1182. for (var i = 0, ii = promises.length; i < ii; ++i) {
  1183. var promise = promises[i];
  1184. var resolve = (function(i) {
  1185. return function(value) {
  1186. if (deferred._status === STATUS_REJECTED) {
  1187. return;
  1188. }
  1189. results[i] = value;
  1190. unresolved--;
  1191. if (unresolved === 0) {
  1192. resolveAll(results);
  1193. }
  1194. };
  1195. })(i);
  1196. if (Promise.isPromise(promise)) {
  1197. promise.then(resolve, reject);
  1198. } else {
  1199. resolve(promise);
  1200. }
  1201. }
  1202. return deferred;
  1203. };
  1204. /**
  1205. * Checks if the value is likely a promise (has a 'then' function).
  1206. * @return {boolean} true if value is thenable
  1207. */
  1208. Promise.isPromise = function Promise_isPromise(value) {
  1209. return value && typeof value.then === 'function';
  1210. };
  1211. /**
  1212. * Creates resolved promise
  1213. * @param value resolve value
  1214. * @returns {Promise}
  1215. */
  1216. Promise.resolve = function Promise_resolve(value) {
  1217. return new Promise(function (resolve) { resolve(value); });
  1218. };
  1219. /**
  1220. * Creates rejected promise
  1221. * @param reason rejection value
  1222. * @returns {Promise}
  1223. */
  1224. Promise.reject = function Promise_reject(reason) {
  1225. return new Promise(function (resolve, reject) { reject(reason); });
  1226. };
  1227. Promise.prototype = {
  1228. _status: null,
  1229. _value: null,
  1230. _handlers: null,
  1231. _unhandledRejection: null,
  1232. _updateStatus: function Promise__updateStatus(status, value) {
  1233. if (this._status === STATUS_RESOLVED ||
  1234. this._status === STATUS_REJECTED) {
  1235. return;
  1236. }
  1237. if (status === STATUS_RESOLVED &&
  1238. Promise.isPromise(value)) {
  1239. value.then(this._updateStatus.bind(this, STATUS_RESOLVED),
  1240. this._updateStatus.bind(this, STATUS_REJECTED));
  1241. return;
  1242. }
  1243. this._status = status;
  1244. this._value = value;
  1245. if (status === STATUS_REJECTED && this._handlers.length === 0) {
  1246. this._unhandledRejection = true;
  1247. HandlerManager.addUnhandledRejection(this);
  1248. }
  1249. HandlerManager.scheduleHandlers(this);
  1250. },
  1251. _resolve: function Promise_resolve(value) {
  1252. this._updateStatus(STATUS_RESOLVED, value);
  1253. },
  1254. _reject: function Promise_reject(reason) {
  1255. this._updateStatus(STATUS_REJECTED, reason);
  1256. },
  1257. then: function Promise_then(onResolve, onReject) {
  1258. var nextPromise = new Promise(function (resolve, reject) {
  1259. this.resolve = resolve;
  1260. this.reject = reject;
  1261. });
  1262. this._handlers.push({
  1263. thisPromise: this,
  1264. onResolve: onResolve,
  1265. onReject: onReject,
  1266. nextPromise: nextPromise
  1267. });
  1268. HandlerManager.scheduleHandlers(this);
  1269. return nextPromise;
  1270. },
  1271. catch: function Promise_catch(onReject) {
  1272. return this.then(undefined, onReject);
  1273. }
  1274. };
  1275. globalScope.Promise = Promise;
  1276. })();
  1277. var StatTimer = (function StatTimerClosure() {
  1278. function rpad(str, pad, length) {
  1279. while (str.length < length) {
  1280. str += pad;
  1281. }
  1282. return str;
  1283. }
  1284. function StatTimer() {
  1285. this.started = {};
  1286. this.times = [];
  1287. this.enabled = true;
  1288. }
  1289. StatTimer.prototype = {
  1290. time: function StatTimer_time(name) {
  1291. if (!this.enabled) {
  1292. return;
  1293. }
  1294. if (name in this.started) {
  1295. warn('Timer is already running for ' + name);
  1296. }
  1297. this.started[name] = Date.now();
  1298. },
  1299. timeEnd: function StatTimer_timeEnd(name) {
  1300. if (!this.enabled) {
  1301. return;
  1302. }
  1303. if (!(name in this.started)) {
  1304. warn('Timer has not been started for ' + name);
  1305. }
  1306. this.times.push({
  1307. 'name': name,
  1308. 'start': this.started[name],
  1309. 'end': Date.now()
  1310. });
  1311. // Remove timer from started so it can be called again.
  1312. delete this.started[name];
  1313. },
  1314. toString: function StatTimer_toString() {
  1315. var i, ii;
  1316. var times = this.times;
  1317. var out = '';
  1318. // Find the longest name for padding purposes.
  1319. var longest = 0;
  1320. for (i = 0, ii = times.length; i < ii; ++i) {
  1321. var name = times[i]['name'];
  1322. if (name.length > longest) {
  1323. longest = name.length;
  1324. }
  1325. }
  1326. for (i = 0, ii = times.length; i < ii; ++i) {
  1327. var span = times[i];
  1328. var duration = span.end - span.start;
  1329. out += rpad(span['name'], ' ', longest) + ' ' + duration + 'ms\n';
  1330. }
  1331. return out;
  1332. }
  1333. };
  1334. return StatTimer;
  1335. })();
  1336. PDFJS.createBlob = function createBlob(data, contentType) {
  1337. if (typeof Blob !== 'undefined') {
  1338. return new Blob([data], { type: contentType });
  1339. }
  1340. // Blob builder is deprecated in FF14 and removed in FF18.
  1341. var bb = new MozBlobBuilder();
  1342. bb.append(data);
  1343. return bb.getBlob(contentType);
  1344. };
  1345. PDFJS.createObjectURL = (function createObjectURLClosure() {
  1346. // Blob/createObjectURL is not available, falling back to data schema.
  1347. var digits =
  1348. 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
  1349. return function createObjectURL(data, contentType) {
  1350. if (!PDFJS.disableCreateObjectURL &&
  1351. typeof URL !== 'undefined' && URL.createObjectURL) {
  1352. var blob = PDFJS.createBlob(data, contentType);
  1353. return URL.createObjectURL(blob);
  1354. }
  1355. var buffer = 'data:' + contentType + ';base64,';
  1356. for (var i = 0, ii = data.length; i < ii; i += 3) {
  1357. var b1 = data[i] & 0xFF;
  1358. var b2 = data[i + 1] & 0xFF;
  1359. var b3 = data[i + 2] & 0xFF;
  1360. var d1 = b1 >> 2, d2 = ((b1 & 3) << 4) | (b2 >> 4);
  1361. var d3 = i + 1 < ii ? ((b2 & 0xF) << 2) | (b3 >> 6) : 64;
  1362. var d4 = i + 2 < ii ? (b3 & 0x3F) : 64;
  1363. buffer += digits[d1] + digits[d2] + digits[d3] + digits[d4];
  1364. }
  1365. return buffer;
  1366. };
  1367. })();
  1368. function MessageHandler(sourceName, targetName, comObj) {
  1369. this.sourceName = sourceName;
  1370. this.targetName = targetName;
  1371. this.comObj = comObj;
  1372. this.callbackIndex = 1;
  1373. this.postMessageTransfers = true;
  1374. var callbacksCapabilities = this.callbacksCapabilities = {};
  1375. var ah = this.actionHandler = {};
  1376. this._onComObjOnMessage = function messageHandlerComObjOnMessage(event) {
  1377. var data = event.data;
  1378. if (data.targetName !== this.sourceName) {
  1379. return;
  1380. }
  1381. if (data.isReply) {
  1382. var callbackId = data.callbackId;
  1383. if (data.callbackId in callbacksCapabilities) {
  1384. var callback = callbacksCapabilities[callbackId];
  1385. delete callbacksCapabilities[callbackId];
  1386. if ('error' in data) {
  1387. callback.reject(data.error);
  1388. } else {
  1389. callback.resolve(data.data);
  1390. }
  1391. } else {
  1392. error('Cannot resolve callback ' + callbackId);
  1393. }
  1394. } else if (data.action in ah) {
  1395. var action = ah[data.action];
  1396. if (data.callbackId) {
  1397. var sourceName = this.sourceName;
  1398. var targetName = data.sourceName;
  1399. Promise.resolve().then(function () {
  1400. return action[0].call(action[1], data.data);
  1401. }).then(function (result) {
  1402. comObj.postMessage({
  1403. sourceName: sourceName,
  1404. targetName: targetName,
  1405. isReply: true,
  1406. callbackId: data.callbackId,
  1407. data: result
  1408. });
  1409. }, function (reason) {
  1410. if (reason instanceof Error) {
  1411. // Serialize error to avoid "DataCloneError"
  1412. reason = reason + '';
  1413. }
  1414. comObj.postMessage({
  1415. sourceName: sourceName,
  1416. targetName: targetName,
  1417. isReply: true,
  1418. callbackId: data.callbackId,
  1419. error: reason
  1420. });
  1421. });
  1422. } else {
  1423. action[0].call(action[1], data.data);
  1424. }
  1425. } else {
  1426. error('Unknown action from worker: ' + data.action);
  1427. }
  1428. }.bind(this);
  1429. comObj.addEventListener('message', this._onComObjOnMessage);
  1430. }
  1431. MessageHandler.prototype = {
  1432. on: function messageHandlerOn(actionName, handler, scope) {
  1433. var ah = this.actionHandler;
  1434. if (ah[actionName]) {
  1435. error('There is already an actionName called "' + actionName + '"');
  1436. }
  1437. ah[actionName] = [handler, scope];
  1438. },
  1439. /**
  1440. * Sends a message to the comObj to invoke the action with the supplied data.
  1441. * @param {String} actionName Action to call.
  1442. * @param {JSON} data JSON data to send.
  1443. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers
  1444. */
  1445. send: function messageHandlerSend(actionName, data, transfers) {
  1446. var message = {
  1447. sourceName: this.sourceName,
  1448. targetName: this.targetName,
  1449. action: actionName,
  1450. data: data
  1451. };
  1452. this.postMessage(message, transfers);
  1453. },
  1454. /**
  1455. * Sends a message to the comObj to invoke the action with the supplied data.
  1456. * Expects that other side will callback with the response.
  1457. * @param {String} actionName Action to call.
  1458. * @param {JSON} data JSON data to send.
  1459. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers.
  1460. * @returns {Promise} Promise to be resolved with response data.
  1461. */
  1462. sendWithPromise:
  1463. function messageHandlerSendWithPromise(actionName, data, transfers) {
  1464. var callbackId = this.callbackIndex++;
  1465. var message = {
  1466. sourceName: this.sourceName,
  1467. targetName: this.targetName,
  1468. action: actionName,
  1469. data: data,
  1470. callbackId: callbackId
  1471. };
  1472. var capability = createPromiseCapability();
  1473. this.callbacksCapabilities[callbackId] = capability;
  1474. try {
  1475. this.postMessage(message, transfers);
  1476. } catch (e) {
  1477. capability.reject(e);
  1478. }
  1479. return capability.promise;
  1480. },
  1481. /**
  1482. * Sends raw message to the comObj.
  1483. * @private
  1484. * @param message {Object} Raw message.
  1485. * @param transfers List of transfers/ArrayBuffers, or undefined.
  1486. */
  1487. postMessage: function (message, transfers) {
  1488. if (transfers && this.postMessageTransfers) {
  1489. this.comObj.postMessage(message, transfers);
  1490. } else {
  1491. this.comObj.postMessage(message);
  1492. }
  1493. },
  1494. destroy: function () {
  1495. this.comObj.removeEventListener('message', this._onComObjOnMessage);
  1496. }
  1497. };
  1498. function loadJpegStream(id, imageUrl, objs) {
  1499. var img = new Image();
  1500. img.onload = (function loadJpegStream_onloadClosure() {
  1501. objs.resolve(id, img);
  1502. });
  1503. img.onerror = (function loadJpegStream_onerrorClosure() {
  1504. objs.resolve(id, null);
  1505. warn('Error during JPEG image loading');
  1506. });
  1507. img.src = imageUrl;
  1508. }
  1509. exports.FONT_IDENTITY_MATRIX = FONT_IDENTITY_MATRIX;
  1510. exports.IDENTITY_MATRIX = IDENTITY_MATRIX;
  1511. exports.OPS = OPS;
  1512. exports.UNSUPPORTED_FEATURES = UNSUPPORTED_FEATURES;
  1513. exports.AnnotationBorderStyleType = AnnotationBorderStyleType;
  1514. exports.AnnotationFlag = AnnotationFlag;
  1515. exports.AnnotationType = AnnotationType;
  1516. exports.FontType = FontType;
  1517. exports.ImageKind = ImageKind;
  1518. exports.InvalidPDFException = InvalidPDFException;
  1519. exports.LinkTarget = LinkTarget;
  1520. exports.LinkTargetStringMap = LinkTargetStringMap;
  1521. exports.MessageHandler = MessageHandler;
  1522. exports.MissingDataException = MissingDataException;
  1523. exports.MissingPDFException = MissingPDFException;
  1524. exports.NotImplementedException = NotImplementedException;
  1525. exports.PasswordException = PasswordException;
  1526. exports.PasswordResponses = PasswordResponses;
  1527. exports.StatTimer = StatTimer;
  1528. exports.StreamType = StreamType;
  1529. exports.TextRenderingMode = TextRenderingMode;
  1530. exports.UnexpectedResponseException = UnexpectedResponseException;
  1531. exports.UnknownErrorException = UnknownErrorException;
  1532. exports.Util = Util;
  1533. exports.XRefParseException = XRefParseException;
  1534. exports.assert = assert;
  1535. exports.bytesToString = bytesToString;
  1536. exports.combineUrl = combineUrl;
  1537. exports.createPromiseCapability = createPromiseCapability;
  1538. exports.deprecated = deprecated;
  1539. exports.error = error;
  1540. exports.info = info;
  1541. exports.isArray = isArray;
  1542. exports.isArrayBuffer = isArrayBuffer;
  1543. exports.isBool = isBool;
  1544. exports.isEmptyObj = isEmptyObj;
  1545. exports.isExternalLinkTargetSet = isExternalLinkTargetSet;
  1546. exports.isInt = isInt;
  1547. exports.isNum = isNum;
  1548. exports.isString = isString;
  1549. exports.isValidUrl = isValidUrl;
  1550. exports.loadJpegStream = loadJpegStream;
  1551. exports.log2 = log2;
  1552. exports.readInt8 = readInt8;
  1553. exports.readUint16 = readUint16;
  1554. exports.readUint32 = readUint32;
  1555. exports.shadow = shadow;
  1556. exports.string32 = string32;
  1557. exports.stringToBytes = stringToBytes;
  1558. exports.stringToPDFString = stringToPDFString;
  1559. exports.stringToUTF8String = stringToUTF8String;
  1560. exports.utf8StringToString = utf8StringToString;
  1561. exports.warn = warn;
  1562. }));
  1563. var NetworkManager = (function NetworkManagerClosure() {
  1564. var OK_RESPONSE = 200;
  1565. var PARTIAL_CONTENT_RESPONSE = 206;
  1566. function NetworkManager(url, args) {
  1567. this.url = url;
  1568. args = args || {};
  1569. this.isHttp = /^https?:/i.test(url);
  1570. this.httpHeaders = (this.isHttp && args.httpHeaders) || {};
  1571. this.withCredentials = args.withCredentials || false;
  1572. this.getXhr = args.getXhr ||
  1573. function NetworkManager_getXhr() {
  1574. return new XMLHttpRequest();
  1575. };
  1576. this.currXhrId = 0;
  1577. this.pendingRequests = {};
  1578. this.loadedRequests = {};
  1579. }
  1580. function getArrayBuffer(xhr) {
  1581. var data = xhr.response;
  1582. if (typeof data !== 'string') {
  1583. return data;
  1584. }
  1585. var length = data.length;
  1586. var array = new Uint8Array(length);
  1587. for (var i = 0; i < length; i++) {
  1588. array[i] = data.charCodeAt(i) & 0xFF;
  1589. }
  1590. return array.buffer;
  1591. }
  1592. var supportsMozChunked = (function supportsMozChunkedClosure() {
  1593. try {
  1594. var x = new XMLHttpRequest();
  1595. // Firefox 37- required .open() to be called before setting responseType.
  1596. // https://bugzilla.mozilla.org/show_bug.cgi?id=707484
  1597. // Even though the URL is not visited, .open() could fail if the URL is
  1598. // blocked, e.g. via the connect-src CSP directive or the NoScript addon.
  1599. // When this error occurs, this feature detection method will mistakenly
  1600. // report that moz-chunked-arraybuffer is not supported in Firefox 37-.
  1601. x.open('GET', 'https://example.com');
  1602. x.responseType = 'moz-chunked-arraybuffer';
  1603. return x.responseType === 'moz-chunked-arraybuffer';
  1604. } catch (e) {
  1605. return false;
  1606. }
  1607. })();
  1608. NetworkManager.prototype = {
  1609. requestRange: function NetworkManager_requestRange(begin, end, listeners) {
  1610. var args = {
  1611. begin: begin,
  1612. end: end
  1613. };
  1614. for (var prop in listeners) {
  1615. args[prop] = listeners[prop];
  1616. }
  1617. return this.request(args);
  1618. },
  1619. requestFull: function NetworkManager_requestFull(listeners) {
  1620. return this.request(listeners);
  1621. },
  1622. request: function NetworkManager_request(args) {
  1623. var xhr = this.getXhr();
  1624. var xhrId = this.currXhrId++;
  1625. var pendingRequest = this.pendingRequests[xhrId] = {
  1626. xhr: xhr
  1627. };
  1628. xhr.open('GET', this.url);
  1629. xhr.withCredentials = this.withCredentials;
  1630. for (var property in this.httpHeaders) {
  1631. var value = this.httpHeaders[property];
  1632. if (typeof value === 'undefined') {
  1633. continue;
  1634. }
  1635. xhr.setRequestHeader(property, value);
  1636. }
  1637. if (this.isHttp && 'begin' in args && 'end' in args) {
  1638. var rangeStr = args.begin + '-' + (args.end - 1);
  1639. xhr.setRequestHeader('Range', 'bytes=' + rangeStr);
  1640. pendingRequest.expectedStatus = 206;
  1641. } else {
  1642. pendingRequest.expectedStatus = 200;
  1643. }
  1644. var useMozChunkedLoading = supportsMozChunked && !!args.onProgressiveData;
  1645. if (useMozChunkedLoading) {
  1646. xhr.responseType = 'moz-chunked-arraybuffer';
  1647. pendingRequest.onProgressiveData = args.onProgressiveData;
  1648. pendingRequest.mozChunked = true;
  1649. } else {
  1650. xhr.responseType = 'arraybuffer';
  1651. }
  1652. if (args.onError) {
  1653. xhr.onerror = function(evt) {
  1654. args.onError(xhr.status);
  1655. };
  1656. }
  1657. xhr.onreadystatechange = this.onStateChange.bind(this, xhrId);
  1658. xhr.onprogress = this.onProgress.bind(this, xhrId);
  1659. pendingRequest.onHeadersReceived = args.onHeadersReceived;
  1660. pendingRequest.onDone = args.onDone;
  1661. pendingRequest.onError = args.onError;
  1662. pendingRequest.onProgress = args.onProgress;
  1663. xhr.send(null);
  1664. return xhrId;
  1665. },
  1666. onProgress: function NetworkManager_onProgress(xhrId, evt) {
  1667. var pendingRequest = this.pendingRequests[xhrId];
  1668. if (!pendingRequest) {
  1669. // Maybe abortRequest was called...
  1670. return;
  1671. }
  1672. if (pendingRequest.mozChunked) {
  1673. var chunk = getArrayBuffer(pendingRequest.xhr);
  1674. pendingRequest.onProgressiveData(chunk);
  1675. }
  1676. var onProgress = pendingRequest.onProgress;
  1677. if (onProgress) {
  1678. onProgress(evt);
  1679. }
  1680. },
  1681. onStateChange: function NetworkManager_onStateChange(xhrId, evt) {
  1682. var pendingRequest = this.pendingRequests[xhrId];
  1683. if (!pendingRequest) {
  1684. // Maybe abortRequest was called...
  1685. return;
  1686. }
  1687. var xhr = pendingRequest.xhr;
  1688. if (xhr.readyState >= 2 && pendingRequest.onHeadersReceived) {
  1689. pendingRequest.onHeadersReceived();
  1690. delete pendingRequest.onHeadersReceived;
  1691. }
  1692. if (xhr.readyState !== 4) {
  1693. return;
  1694. }
  1695. if (!(xhrId in this.pendingRequests)) {
  1696. // The XHR request might have been aborted in onHeadersReceived()
  1697. // callback, in which case we should abort request
  1698. return;
  1699. }
  1700. delete this.pendingRequests[xhrId];
  1701. // success status == 0 can be on ftp, file and other protocols
  1702. if (xhr.status === 0 && this.isHttp) {
  1703. if (pendingRequest.onError) {
  1704. pendingRequest.onError(xhr.status);
  1705. }
  1706. return;
  1707. }
  1708. var xhrStatus = xhr.status || OK_RESPONSE;
  1709. // From http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35.2:
  1710. // "A server MAY ignore the Range header". This means it's possible to
  1711. // get a 200 rather than a 206 response from a range request.
  1712. var ok_response_on_range_request =
  1713. xhrStatus === OK_RESPONSE &&
  1714. pendingRequest.expectedStatus === PARTIAL_CONTENT_RESPONSE;
  1715. if (!ok_response_on_range_request &&
  1716. xhrStatus !== pendingRequest.expectedStatus) {
  1717. if (pendingRequest.onError) {
  1718. pendingRequest.onError(xhr.status);
  1719. }
  1720. return;
  1721. }
  1722. this.loadedRequests[xhrId] = true;
  1723. var chunk = getArrayBuffer(xhr);
  1724. if (xhrStatus === PARTIAL_CONTENT_RESPONSE) {
  1725. var rangeHeader = xhr.getResponseHeader('Content-Range');
  1726. var matches = /bytes (\d+)-(\d+)\/(\d+)/.exec(rangeHeader);
  1727. var begin = parseInt(matches[1], 10);
  1728. pendingRequest.onDone({
  1729. begin: begin,
  1730. chunk: chunk
  1731. });
  1732. } else if (pendingRequest.onProgressiveData) {
  1733. pendingRequest.onDone(null);
  1734. } else if (chunk) {
  1735. pendingRequest.onDone({
  1736. begin: 0,
  1737. chunk: chunk
  1738. });
  1739. } else if (pendingRequest.onError) {
  1740. pendingRequest.onError(xhr.status);
  1741. }
  1742. },
  1743. hasPendingRequests: function NetworkManager_hasPendingRequests() {
  1744. for (var xhrId in this.pendingRequests) {
  1745. return true;
  1746. }
  1747. return false;
  1748. },
  1749. getRequestXhr: function NetworkManager_getXhr(xhrId) {
  1750. return this.pendingRequests[xhrId].xhr;
  1751. },
  1752. isStreamingRequest: function NetworkManager_isStreamingRequest(xhrId) {
  1753. return !!(this.pendingRequests[xhrId].onProgressiveData);
  1754. },
  1755. isPendingRequest: function NetworkManager_isPendingRequest(xhrId) {
  1756. return xhrId in this.pendingRequests;
  1757. },
  1758. isLoadedRequest: function NetworkManager_isLoadedRequest(xhrId) {
  1759. return xhrId in this.loadedRequests;
  1760. },
  1761. abortAllRequests: function NetworkManager_abortAllRequests() {
  1762. for (var xhrId in this.pendingRequests) {
  1763. this.abortRequest(xhrId | 0);
  1764. }
  1765. },
  1766. abortRequest: function NetworkManager_abortRequest(xhrId) {
  1767. var xhr = this.pendingRequests[xhrId].xhr;
  1768. delete this.pendingRequests[xhrId];
  1769. xhr.abort();
  1770. }
  1771. };
  1772. return NetworkManager;
  1773. })();
  1774. (function (root, factory) {
  1775. if (typeof define === 'function' && define.amd) {
  1776. define('pdfjs/core/arithmetic_decoder', ['exports'], factory);
  1777. } else if (typeof exports !== 'undefined') {
  1778. factory(exports);
  1779. } else {
  1780. factory((root.pdfjsCoreArithmeticDecoder = {}));
  1781. }
  1782. }(this, function (exports) {
  1783. /* This class implements the QM Coder decoding as defined in
  1784. * JPEG 2000 Part I Final Committee Draft Version 1.0
  1785. * Annex C.3 Arithmetic decoding procedure
  1786. * available at http://www.jpeg.org/public/fcd15444-1.pdf
  1787. *
  1788. * The arithmetic decoder is used in conjunction with context models to decode
  1789. * JPEG2000 and JBIG2 streams.
  1790. */
  1791. var ArithmeticDecoder = (function ArithmeticDecoderClosure() {
  1792. // Table C-2
  1793. var QeTable = [
  1794. {qe: 0x5601, nmps: 1, nlps: 1, switchFlag: 1},
  1795. {qe: 0x3401, nmps: 2, nlps: 6, switchFlag: 0},
  1796. {qe: 0x1801, nmps: 3, nlps: 9, switchFlag: 0},
  1797. {qe: 0x0AC1, nmps: 4, nlps: 12, switchFlag: 0},
  1798. {qe: 0x0521, nmps: 5, nlps: 29, switchFlag: 0},
  1799. {qe: 0x0221, nmps: 38, nlps: 33, switchFlag: 0},
  1800. {qe: 0x5601, nmps: 7, nlps: 6, switchFlag: 1},
  1801. {qe: 0x5401, nmps: 8, nlps: 14, switchFlag: 0},
  1802. {qe: 0x4801, nmps: 9, nlps: 14, switchFlag: 0},
  1803. {qe: 0x3801, nmps: 10, nlps: 14, switchFlag: 0},
  1804. {qe: 0x3001, nmps: 11, nlps: 17, switchFlag: 0},
  1805. {qe: 0x2401, nmps: 12, nlps: 18, switchFlag: 0},
  1806. {qe: 0x1C01, nmps: 13, nlps: 20, switchFlag: 0},
  1807. {qe: 0x1601, nmps: 29, nlps: 21, switchFlag: 0},
  1808. {qe: 0x5601, nmps: 15, nlps: 14, switchFlag: 1},
  1809. {qe: 0x5401, nmps: 16, nlps: 14, switchFlag: 0},
  1810. {qe: 0x5101, nmps: 17, nlps: 15, switchFlag: 0},
  1811. {qe: 0x4801, nmps: 18, nlps: 16, switchFlag: 0},
  1812. {qe: 0x3801, nmps: 19, nlps: 17, switchFlag: 0},
  1813. {qe: 0x3401, nmps: 20, nlps: 18, switchFlag: 0},
  1814. {qe: 0x3001, nmps: 21, nlps: 19, switchFlag: 0},
  1815. {qe: 0x2801, nmps: 22, nlps: 19, switchFlag: 0},
  1816. {qe: 0x2401, nmps: 23, nlps: 20, switchFlag: 0},
  1817. {qe: 0x2201, nmps: 24, nlps: 21, switchFlag: 0},
  1818. {qe: 0x1C01, nmps: 25, nlps: 22, switchFlag: 0},
  1819. {qe: 0x1801, nmps: 26, nlps: 23, switchFlag: 0},
  1820. {qe: 0x1601, nmps: 27, nlps: 24, switchFlag: 0},
  1821. {qe: 0x1401, nmps: 28, nlps: 25, switchFlag: 0},
  1822. {qe: 0x1201, nmps: 29, nlps: 26, switchFlag: 0},
  1823. {qe: 0x1101, nmps: 30, nlps: 27, switchFlag: 0},
  1824. {qe: 0x0AC1, nmps: 31, nlps: 28, switchFlag: 0},
  1825. {qe: 0x09C1, nmps: 32, nlps: 29, switchFlag: 0},
  1826. {qe: 0x08A1, nmps: 33, nlps: 30, switchFlag: 0},
  1827. {qe: 0x0521, nmps: 34, nlps: 31, switchFlag: 0},
  1828. {qe: 0x0441, nmps: 35, nlps: 32, switchFlag: 0},
  1829. {qe: 0x02A1, nmps: 36, nlps: 33, switchFlag: 0},
  1830. {qe: 0x0221, nmps: 37, nlps: 34, switchFlag: 0},
  1831. {qe: 0x0141, nmps: 38, nlps: 35, switchFlag: 0},
  1832. {qe: 0x0111, nmps: 39, nlps: 36, switchFlag: 0},
  1833. {qe: 0x0085, nmps: 40, nlps: 37, switchFlag: 0},
  1834. {qe: 0x0049, nmps: 41, nlps: 38, switchFlag: 0},
  1835. {qe: 0x0025, nmps: 42, nlps: 39, switchFlag: 0},
  1836. {qe: 0x0015, nmps: 43, nlps: 40, switchFlag: 0},
  1837. {qe: 0x0009, nmps: 44, nlps: 41, switchFlag: 0},
  1838. {qe: 0x0005, nmps: 45, nlps: 42, switchFlag: 0},
  1839. {qe: 0x0001, nmps: 45, nlps: 43, switchFlag: 0},
  1840. {qe: 0x5601, nmps: 46, nlps: 46, switchFlag: 0}
  1841. ];
  1842. // C.3.5 Initialisation of the decoder (INITDEC)
  1843. function ArithmeticDecoder(data, start, end) {
  1844. this.data = data;
  1845. this.bp = start;
  1846. this.dataEnd = end;
  1847. this.chigh = data[start];
  1848. this.clow = 0;
  1849. this.byteIn();
  1850. this.chigh = ((this.chigh << 7) & 0xFFFF) | ((this.clow >> 9) & 0x7F);
  1851. this.clow = (this.clow << 7) & 0xFFFF;
  1852. this.ct -= 7;
  1853. this.a = 0x8000;
  1854. }
  1855. ArithmeticDecoder.prototype = {
  1856. // C.3.4 Compressed data input (BYTEIN)
  1857. byteIn: function ArithmeticDecoder_byteIn() {
  1858. var data = this.data;
  1859. var bp = this.bp;
  1860. if (data[bp] === 0xFF) {
  1861. var b1 = data[bp + 1];
  1862. if (b1 > 0x8F) {
  1863. this.clow += 0xFF00;
  1864. this.ct = 8;
  1865. } else {
  1866. bp++;
  1867. this.clow += (data[bp] << 9);
  1868. this.ct = 7;
  1869. this.bp = bp;
  1870. }
  1871. } else {
  1872. bp++;
  1873. this.clow += bp < this.dataEnd ? (data[bp] << 8) : 0xFF00;
  1874. this.ct = 8;
  1875. this.bp = bp;
  1876. }
  1877. if (this.clow > 0xFFFF) {
  1878. this.chigh += (this.clow >> 16);
  1879. this.clow &= 0xFFFF;
  1880. }
  1881. },
  1882. // C.3.2 Decoding a decision (DECODE)
  1883. readBit: function ArithmeticDecoder_readBit(contexts, pos) {
  1884. // contexts are packed into 1 byte:
  1885. // highest 7 bits carry cx.index, lowest bit carries cx.mps
  1886. var cx_index = contexts[pos] >> 1, cx_mps = contexts[pos] & 1;
  1887. var qeTableIcx = QeTable[cx_index];
  1888. var qeIcx = qeTableIcx.qe;
  1889. var d;
  1890. var a = this.a - qeIcx;
  1891. if (this.chigh < qeIcx) {
  1892. // exchangeLps
  1893. if (a < qeIcx) {
  1894. a = qeIcx;
  1895. d = cx_mps;
  1896. cx_index = qeTableIcx.nmps;
  1897. } else {
  1898. a = qeIcx;
  1899. d = 1 ^ cx_mps;
  1900. if (qeTableIcx.switchFlag === 1) {
  1901. cx_mps = d;
  1902. }
  1903. cx_index = qeTableIcx.nlps;
  1904. }
  1905. } else {
  1906. this.chigh -= qeIcx;
  1907. if ((a & 0x8000) !== 0) {
  1908. this.a = a;
  1909. return cx_mps;
  1910. }
  1911. // exchangeMps
  1912. if (a < qeIcx) {
  1913. d = 1 ^ cx_mps;
  1914. if (qeTableIcx.switchFlag === 1) {
  1915. cx_mps = d;
  1916. }
  1917. cx_index = qeTableIcx.nlps;
  1918. } else {
  1919. d = cx_mps;
  1920. cx_index = qeTableIcx.nmps;
  1921. }
  1922. }
  1923. // C.3.3 renormD;
  1924. do {
  1925. if (this.ct === 0) {
  1926. this.byteIn();
  1927. }
  1928. a <<= 1;
  1929. this.chigh = ((this.chigh << 1) & 0xFFFF) | ((this.clow >> 15) & 1);
  1930. this.clow = (this.clow << 1) & 0xFFFF;
  1931. this.ct--;
  1932. } while ((a & 0x8000) === 0);
  1933. this.a = a;
  1934. contexts[pos] = cx_index << 1 | cx_mps;
  1935. return d;
  1936. }
  1937. };
  1938. return ArithmeticDecoder;
  1939. })();
  1940. exports.ArithmeticDecoder = ArithmeticDecoder;
  1941. }));
  1942. (function (root, factory) {
  1943. if (typeof define === 'function' && define.amd) {
  1944. define('pdfjs/core/charsets', ['exports'], factory);
  1945. } else if (typeof exports !== 'undefined') {
  1946. factory(exports);
  1947. } else {
  1948. factory((root.pdfjsCoreCharsets = {}));
  1949. }
  1950. }(this, function (exports) {
  1951. var ISOAdobeCharset = [
  1952. '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar',
  1953. 'percent', 'ampersand', 'quoteright', 'parenleft', 'parenright',
  1954. 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash', 'zero',
  1955. 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  1956. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question',
  1957. 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
  1958. 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
  1959. 'bracketleft', 'backslash', 'bracketright', 'asciicircum', 'underscore',
  1960. 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
  1961. 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
  1962. 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
  1963. 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  1964. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  1965. 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
  1966. 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase',
  1967. 'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis',
  1968. 'perthousand', 'questiondown', 'grave', 'acute', 'circumflex', 'tilde',
  1969. 'macron', 'breve', 'dotaccent', 'dieresis', 'ring', 'cedilla',
  1970. 'hungarumlaut', 'ogonek', 'caron', 'emdash', 'AE', 'ordfeminine',
  1971. 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae', 'dotlessi', 'lslash',
  1972. 'oslash', 'oe', 'germandbls', 'onesuperior', 'logicalnot', 'mu',
  1973. 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn', 'onequarter',
  1974. 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters', 'twosuperior',
  1975. 'registered', 'minus', 'eth', 'multiply', 'threesuperior', 'copyright',
  1976. 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring', 'Atilde',
  1977. 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave', 'Iacute',
  1978. 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute', 'Ocircumflex',
  1979. 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute', 'Ucircumflex',
  1980. 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron', 'aacute',
  1981. 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde', 'ccedilla',
  1982. 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute', 'icircumflex',
  1983. 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex', 'odieresis',
  1984. 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex', 'udieresis',
  1985. 'ugrave', 'yacute', 'ydieresis', 'zcaron'
  1986. ];
  1987. var ExpertCharset = [
  1988. '.notdef', 'space', 'exclamsmall', 'Hungarumlautsmall', 'dollaroldstyle',
  1989. 'dollarsuperior', 'ampersandsmall', 'Acutesmall', 'parenleftsuperior',
  1990. 'parenrightsuperior', 'twodotenleader', 'onedotenleader', 'comma',
  1991. 'hyphen', 'period', 'fraction', 'zerooldstyle', 'oneoldstyle',
  1992. 'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle',
  1993. 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle',
  1994. 'colon', 'semicolon', 'commasuperior', 'threequartersemdash',
  1995. 'periodsuperior', 'questionsmall', 'asuperior', 'bsuperior',
  1996. 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',
  1997. 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  1998. 'tsuperior', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior',
  1999. 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall',
  2000. 'Asmall', 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall',
  2001. 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall',
  2002. 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall',
  2003. 'Vsmall', 'Wsmall', 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary',
  2004. 'onefitted', 'rupiah', 'Tildesmall', 'exclamdownsmall', 'centoldstyle',
  2005. 'Lslashsmall', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall',
  2006. 'Brevesmall', 'Caronsmall', 'Dotaccentsmall', 'Macronsmall',
  2007. 'figuredash', 'hypheninferior', 'Ogoneksmall', 'Ringsmall',
  2008. 'Cedillasmall', 'onequarter', 'onehalf', 'threequarters',
  2009. 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths',
  2010. 'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'onesuperior',
  2011. 'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',
  2012. 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',
  2013. 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior',
  2014. 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior',
  2015. 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior',
  2016. 'periodinferior', 'commainferior', 'Agravesmall', 'Aacutesmall',
  2017. 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall', 'Aringsmall',
  2018. 'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall',
  2019. 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall',
  2020. 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall',
  2021. 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall',
  2022. 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall',
  2023. 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall',
  2024. 'Ydieresissmall'
  2025. ];
  2026. var ExpertSubsetCharset = [
  2027. '.notdef', 'space', 'dollaroldstyle', 'dollarsuperior',
  2028. 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  2029. 'onedotenleader', 'comma', 'hyphen', 'period', 'fraction',
  2030. 'zerooldstyle', 'oneoldstyle', 'twooldstyle', 'threeoldstyle',
  2031. 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle',
  2032. 'eightoldstyle', 'nineoldstyle', 'colon', 'semicolon', 'commasuperior',
  2033. 'threequartersemdash', 'periodsuperior', 'asuperior', 'bsuperior',
  2034. 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',
  2035. 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  2036. 'tsuperior', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior',
  2037. 'parenrightinferior', 'hyphensuperior', 'colonmonetary', 'onefitted',
  2038. 'rupiah', 'centoldstyle', 'figuredash', 'hypheninferior', 'onequarter',
  2039. 'onehalf', 'threequarters', 'oneeighth', 'threeeighths', 'fiveeighths',
  2040. 'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'onesuperior',
  2041. 'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',
  2042. 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',
  2043. 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior',
  2044. 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior',
  2045. 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior',
  2046. 'periodinferior', 'commainferior'
  2047. ];
  2048. exports.ISOAdobeCharset = ISOAdobeCharset;
  2049. exports.ExpertCharset = ExpertCharset;
  2050. exports.ExpertSubsetCharset = ExpertSubsetCharset;
  2051. }));
  2052. (function (root, factory) {
  2053. if (typeof define === 'function' && define.amd) {
  2054. define('pdfjs/core/glyphlist', ['exports'], factory);
  2055. } else if (typeof exports !== 'undefined') {
  2056. factory(exports);
  2057. } else {
  2058. factory((root.pdfjsCoreGlyphList = {}));
  2059. }
  2060. }(this, function (exports) {
  2061. var GlyphsUnicode = {
  2062. A: 0x0041,
  2063. AE: 0x00C6,
  2064. AEacute: 0x01FC,
  2065. AEmacron: 0x01E2,
  2066. AEsmall: 0xF7E6,
  2067. Aacute: 0x00C1,
  2068. Aacutesmall: 0xF7E1,
  2069. Abreve: 0x0102,
  2070. Abreveacute: 0x1EAE,
  2071. Abrevecyrillic: 0x04D0,
  2072. Abrevedotbelow: 0x1EB6,
  2073. Abrevegrave: 0x1EB0,
  2074. Abrevehookabove: 0x1EB2,
  2075. Abrevetilde: 0x1EB4,
  2076. Acaron: 0x01CD,
  2077. Acircle: 0x24B6,
  2078. Acircumflex: 0x00C2,
  2079. Acircumflexacute: 0x1EA4,
  2080. Acircumflexdotbelow: 0x1EAC,
  2081. Acircumflexgrave: 0x1EA6,
  2082. Acircumflexhookabove: 0x1EA8,
  2083. Acircumflexsmall: 0xF7E2,
  2084. Acircumflextilde: 0x1EAA,
  2085. Acute: 0xF6C9,
  2086. Acutesmall: 0xF7B4,
  2087. Acyrillic: 0x0410,
  2088. Adblgrave: 0x0200,
  2089. Adieresis: 0x00C4,
  2090. Adieresiscyrillic: 0x04D2,
  2091. Adieresismacron: 0x01DE,
  2092. Adieresissmall: 0xF7E4,
  2093. Adotbelow: 0x1EA0,
  2094. Adotmacron: 0x01E0,
  2095. Agrave: 0x00C0,
  2096. Agravesmall: 0xF7E0,
  2097. Ahookabove: 0x1EA2,
  2098. Aiecyrillic: 0x04D4,
  2099. Ainvertedbreve: 0x0202,
  2100. Alpha: 0x0391,
  2101. Alphatonos: 0x0386,
  2102. Amacron: 0x0100,
  2103. Amonospace: 0xFF21,
  2104. Aogonek: 0x0104,
  2105. Aring: 0x00C5,
  2106. Aringacute: 0x01FA,
  2107. Aringbelow: 0x1E00,
  2108. Aringsmall: 0xF7E5,
  2109. Asmall: 0xF761,
  2110. Atilde: 0x00C3,
  2111. Atildesmall: 0xF7E3,
  2112. Aybarmenian: 0x0531,
  2113. B: 0x0042,
  2114. Bcircle: 0x24B7,
  2115. Bdotaccent: 0x1E02,
  2116. Bdotbelow: 0x1E04,
  2117. Becyrillic: 0x0411,
  2118. Benarmenian: 0x0532,
  2119. Beta: 0x0392,
  2120. Bhook: 0x0181,
  2121. Blinebelow: 0x1E06,
  2122. Bmonospace: 0xFF22,
  2123. Brevesmall: 0xF6F4,
  2124. Bsmall: 0xF762,
  2125. Btopbar: 0x0182,
  2126. C: 0x0043,
  2127. Caarmenian: 0x053E,
  2128. Cacute: 0x0106,
  2129. Caron: 0xF6CA,
  2130. Caronsmall: 0xF6F5,
  2131. Ccaron: 0x010C,
  2132. Ccedilla: 0x00C7,
  2133. Ccedillaacute: 0x1E08,
  2134. Ccedillasmall: 0xF7E7,
  2135. Ccircle: 0x24B8,
  2136. Ccircumflex: 0x0108,
  2137. Cdot: 0x010A,
  2138. Cdotaccent: 0x010A,
  2139. Cedillasmall: 0xF7B8,
  2140. Chaarmenian: 0x0549,
  2141. Cheabkhasiancyrillic: 0x04BC,
  2142. Checyrillic: 0x0427,
  2143. Chedescenderabkhasiancyrillic: 0x04BE,
  2144. Chedescendercyrillic: 0x04B6,
  2145. Chedieresiscyrillic: 0x04F4,
  2146. Cheharmenian: 0x0543,
  2147. Chekhakassiancyrillic: 0x04CB,
  2148. Cheverticalstrokecyrillic: 0x04B8,
  2149. Chi: 0x03A7,
  2150. Chook: 0x0187,
  2151. Circumflexsmall: 0xF6F6,
  2152. Cmonospace: 0xFF23,
  2153. Coarmenian: 0x0551,
  2154. Csmall: 0xF763,
  2155. D: 0x0044,
  2156. DZ: 0x01F1,
  2157. DZcaron: 0x01C4,
  2158. Daarmenian: 0x0534,
  2159. Dafrican: 0x0189,
  2160. Dcaron: 0x010E,
  2161. Dcedilla: 0x1E10,
  2162. Dcircle: 0x24B9,
  2163. Dcircumflexbelow: 0x1E12,
  2164. Dcroat: 0x0110,
  2165. Ddotaccent: 0x1E0A,
  2166. Ddotbelow: 0x1E0C,
  2167. Decyrillic: 0x0414,
  2168. Deicoptic: 0x03EE,
  2169. Delta: 0x2206,
  2170. Deltagreek: 0x0394,
  2171. Dhook: 0x018A,
  2172. Dieresis: 0xF6CB,
  2173. DieresisAcute: 0xF6CC,
  2174. DieresisGrave: 0xF6CD,
  2175. Dieresissmall: 0xF7A8,
  2176. Digammagreek: 0x03DC,
  2177. Djecyrillic: 0x0402,
  2178. Dlinebelow: 0x1E0E,
  2179. Dmonospace: 0xFF24,
  2180. Dotaccentsmall: 0xF6F7,
  2181. Dslash: 0x0110,
  2182. Dsmall: 0xF764,
  2183. Dtopbar: 0x018B,
  2184. Dz: 0x01F2,
  2185. Dzcaron: 0x01C5,
  2186. Dzeabkhasiancyrillic: 0x04E0,
  2187. Dzecyrillic: 0x0405,
  2188. Dzhecyrillic: 0x040F,
  2189. E: 0x0045,
  2190. Eacute: 0x00C9,
  2191. Eacutesmall: 0xF7E9,
  2192. Ebreve: 0x0114,
  2193. Ecaron: 0x011A,
  2194. Ecedillabreve: 0x1E1C,
  2195. Echarmenian: 0x0535,
  2196. Ecircle: 0x24BA,
  2197. Ecircumflex: 0x00CA,
  2198. Ecircumflexacute: 0x1EBE,
  2199. Ecircumflexbelow: 0x1E18,
  2200. Ecircumflexdotbelow: 0x1EC6,
  2201. Ecircumflexgrave: 0x1EC0,
  2202. Ecircumflexhookabove: 0x1EC2,
  2203. Ecircumflexsmall: 0xF7EA,
  2204. Ecircumflextilde: 0x1EC4,
  2205. Ecyrillic: 0x0404,
  2206. Edblgrave: 0x0204,
  2207. Edieresis: 0x00CB,
  2208. Edieresissmall: 0xF7EB,
  2209. Edot: 0x0116,
  2210. Edotaccent: 0x0116,
  2211. Edotbelow: 0x1EB8,
  2212. Efcyrillic: 0x0424,
  2213. Egrave: 0x00C8,
  2214. Egravesmall: 0xF7E8,
  2215. Eharmenian: 0x0537,
  2216. Ehookabove: 0x1EBA,
  2217. Eightroman: 0x2167,
  2218. Einvertedbreve: 0x0206,
  2219. Eiotifiedcyrillic: 0x0464,
  2220. Elcyrillic: 0x041B,
  2221. Elevenroman: 0x216A,
  2222. Emacron: 0x0112,
  2223. Emacronacute: 0x1E16,
  2224. Emacrongrave: 0x1E14,
  2225. Emcyrillic: 0x041C,
  2226. Emonospace: 0xFF25,
  2227. Encyrillic: 0x041D,
  2228. Endescendercyrillic: 0x04A2,
  2229. Eng: 0x014A,
  2230. Enghecyrillic: 0x04A4,
  2231. Enhookcyrillic: 0x04C7,
  2232. Eogonek: 0x0118,
  2233. Eopen: 0x0190,
  2234. Epsilon: 0x0395,
  2235. Epsilontonos: 0x0388,
  2236. Ercyrillic: 0x0420,
  2237. Ereversed: 0x018E,
  2238. Ereversedcyrillic: 0x042D,
  2239. Escyrillic: 0x0421,
  2240. Esdescendercyrillic: 0x04AA,
  2241. Esh: 0x01A9,
  2242. Esmall: 0xF765,
  2243. Eta: 0x0397,
  2244. Etarmenian: 0x0538,
  2245. Etatonos: 0x0389,
  2246. Eth: 0x00D0,
  2247. Ethsmall: 0xF7F0,
  2248. Etilde: 0x1EBC,
  2249. Etildebelow: 0x1E1A,
  2250. Euro: 0x20AC,
  2251. Ezh: 0x01B7,
  2252. Ezhcaron: 0x01EE,
  2253. Ezhreversed: 0x01B8,
  2254. F: 0x0046,
  2255. Fcircle: 0x24BB,
  2256. Fdotaccent: 0x1E1E,
  2257. Feharmenian: 0x0556,
  2258. Feicoptic: 0x03E4,
  2259. Fhook: 0x0191,
  2260. Fitacyrillic: 0x0472,
  2261. Fiveroman: 0x2164,
  2262. Fmonospace: 0xFF26,
  2263. Fourroman: 0x2163,
  2264. Fsmall: 0xF766,
  2265. G: 0x0047,
  2266. GBsquare: 0x3387,
  2267. Gacute: 0x01F4,
  2268. Gamma: 0x0393,
  2269. Gammaafrican: 0x0194,
  2270. Gangiacoptic: 0x03EA,
  2271. Gbreve: 0x011E,
  2272. Gcaron: 0x01E6,
  2273. Gcedilla: 0x0122,
  2274. Gcircle: 0x24BC,
  2275. Gcircumflex: 0x011C,
  2276. Gcommaaccent: 0x0122,
  2277. Gdot: 0x0120,
  2278. Gdotaccent: 0x0120,
  2279. Gecyrillic: 0x0413,
  2280. Ghadarmenian: 0x0542,
  2281. Ghemiddlehookcyrillic: 0x0494,
  2282. Ghestrokecyrillic: 0x0492,
  2283. Gheupturncyrillic: 0x0490,
  2284. Ghook: 0x0193,
  2285. Gimarmenian: 0x0533,
  2286. Gjecyrillic: 0x0403,
  2287. Gmacron: 0x1E20,
  2288. Gmonospace: 0xFF27,
  2289. Grave: 0xF6CE,
  2290. Gravesmall: 0xF760,
  2291. Gsmall: 0xF767,
  2292. Gsmallhook: 0x029B,
  2293. Gstroke: 0x01E4,
  2294. H: 0x0048,
  2295. H18533: 0x25CF,
  2296. H18543: 0x25AA,
  2297. H18551: 0x25AB,
  2298. H22073: 0x25A1,
  2299. HPsquare: 0x33CB,
  2300. Haabkhasiancyrillic: 0x04A8,
  2301. Hadescendercyrillic: 0x04B2,
  2302. Hardsigncyrillic: 0x042A,
  2303. Hbar: 0x0126,
  2304. Hbrevebelow: 0x1E2A,
  2305. Hcedilla: 0x1E28,
  2306. Hcircle: 0x24BD,
  2307. Hcircumflex: 0x0124,
  2308. Hdieresis: 0x1E26,
  2309. Hdotaccent: 0x1E22,
  2310. Hdotbelow: 0x1E24,
  2311. Hmonospace: 0xFF28,
  2312. Hoarmenian: 0x0540,
  2313. Horicoptic: 0x03E8,
  2314. Hsmall: 0xF768,
  2315. Hungarumlaut: 0xF6CF,
  2316. Hungarumlautsmall: 0xF6F8,
  2317. Hzsquare: 0x3390,
  2318. I: 0x0049,
  2319. IAcyrillic: 0x042F,
  2320. IJ: 0x0132,
  2321. IUcyrillic: 0x042E,
  2322. Iacute: 0x00CD,
  2323. Iacutesmall: 0xF7ED,
  2324. Ibreve: 0x012C,
  2325. Icaron: 0x01CF,
  2326. Icircle: 0x24BE,
  2327. Icircumflex: 0x00CE,
  2328. Icircumflexsmall: 0xF7EE,
  2329. Icyrillic: 0x0406,
  2330. Idblgrave: 0x0208,
  2331. Idieresis: 0x00CF,
  2332. Idieresisacute: 0x1E2E,
  2333. Idieresiscyrillic: 0x04E4,
  2334. Idieresissmall: 0xF7EF,
  2335. Idot: 0x0130,
  2336. Idotaccent: 0x0130,
  2337. Idotbelow: 0x1ECA,
  2338. Iebrevecyrillic: 0x04D6,
  2339. Iecyrillic: 0x0415,
  2340. Ifraktur: 0x2111,
  2341. Igrave: 0x00CC,
  2342. Igravesmall: 0xF7EC,
  2343. Ihookabove: 0x1EC8,
  2344. Iicyrillic: 0x0418,
  2345. Iinvertedbreve: 0x020A,
  2346. Iishortcyrillic: 0x0419,
  2347. Imacron: 0x012A,
  2348. Imacroncyrillic: 0x04E2,
  2349. Imonospace: 0xFF29,
  2350. Iniarmenian: 0x053B,
  2351. Iocyrillic: 0x0401,
  2352. Iogonek: 0x012E,
  2353. Iota: 0x0399,
  2354. Iotaafrican: 0x0196,
  2355. Iotadieresis: 0x03AA,
  2356. Iotatonos: 0x038A,
  2357. Ismall: 0xF769,
  2358. Istroke: 0x0197,
  2359. Itilde: 0x0128,
  2360. Itildebelow: 0x1E2C,
  2361. Izhitsacyrillic: 0x0474,
  2362. Izhitsadblgravecyrillic: 0x0476,
  2363. J: 0x004A,
  2364. Jaarmenian: 0x0541,
  2365. Jcircle: 0x24BF,
  2366. Jcircumflex: 0x0134,
  2367. Jecyrillic: 0x0408,
  2368. Jheharmenian: 0x054B,
  2369. Jmonospace: 0xFF2A,
  2370. Jsmall: 0xF76A,
  2371. K: 0x004B,
  2372. KBsquare: 0x3385,
  2373. KKsquare: 0x33CD,
  2374. Kabashkircyrillic: 0x04A0,
  2375. Kacute: 0x1E30,
  2376. Kacyrillic: 0x041A,
  2377. Kadescendercyrillic: 0x049A,
  2378. Kahookcyrillic: 0x04C3,
  2379. Kappa: 0x039A,
  2380. Kastrokecyrillic: 0x049E,
  2381. Kaverticalstrokecyrillic: 0x049C,
  2382. Kcaron: 0x01E8,
  2383. Kcedilla: 0x0136,
  2384. Kcircle: 0x24C0,
  2385. Kcommaaccent: 0x0136,
  2386. Kdotbelow: 0x1E32,
  2387. Keharmenian: 0x0554,
  2388. Kenarmenian: 0x053F,
  2389. Khacyrillic: 0x0425,
  2390. Kheicoptic: 0x03E6,
  2391. Khook: 0x0198,
  2392. Kjecyrillic: 0x040C,
  2393. Klinebelow: 0x1E34,
  2394. Kmonospace: 0xFF2B,
  2395. Koppacyrillic: 0x0480,
  2396. Koppagreek: 0x03DE,
  2397. Ksicyrillic: 0x046E,
  2398. Ksmall: 0xF76B,
  2399. L: 0x004C,
  2400. LJ: 0x01C7,
  2401. LL: 0xF6BF,
  2402. Lacute: 0x0139,
  2403. Lambda: 0x039B,
  2404. Lcaron: 0x013D,
  2405. Lcedilla: 0x013B,
  2406. Lcircle: 0x24C1,
  2407. Lcircumflexbelow: 0x1E3C,
  2408. Lcommaaccent: 0x013B,
  2409. Ldot: 0x013F,
  2410. Ldotaccent: 0x013F,
  2411. Ldotbelow: 0x1E36,
  2412. Ldotbelowmacron: 0x1E38,
  2413. Liwnarmenian: 0x053C,
  2414. Lj: 0x01C8,
  2415. Ljecyrillic: 0x0409,
  2416. Llinebelow: 0x1E3A,
  2417. Lmonospace: 0xFF2C,
  2418. Lslash: 0x0141,
  2419. Lslashsmall: 0xF6F9,
  2420. Lsmall: 0xF76C,
  2421. M: 0x004D,
  2422. MBsquare: 0x3386,
  2423. Macron: 0xF6D0,
  2424. Macronsmall: 0xF7AF,
  2425. Macute: 0x1E3E,
  2426. Mcircle: 0x24C2,
  2427. Mdotaccent: 0x1E40,
  2428. Mdotbelow: 0x1E42,
  2429. Menarmenian: 0x0544,
  2430. Mmonospace: 0xFF2D,
  2431. Msmall: 0xF76D,
  2432. Mturned: 0x019C,
  2433. Mu: 0x039C,
  2434. N: 0x004E,
  2435. NJ: 0x01CA,
  2436. Nacute: 0x0143,
  2437. Ncaron: 0x0147,
  2438. Ncedilla: 0x0145,
  2439. Ncircle: 0x24C3,
  2440. Ncircumflexbelow: 0x1E4A,
  2441. Ncommaaccent: 0x0145,
  2442. Ndotaccent: 0x1E44,
  2443. Ndotbelow: 0x1E46,
  2444. Nhookleft: 0x019D,
  2445. Nineroman: 0x2168,
  2446. Nj: 0x01CB,
  2447. Njecyrillic: 0x040A,
  2448. Nlinebelow: 0x1E48,
  2449. Nmonospace: 0xFF2E,
  2450. Nowarmenian: 0x0546,
  2451. Nsmall: 0xF76E,
  2452. Ntilde: 0x00D1,
  2453. Ntildesmall: 0xF7F1,
  2454. Nu: 0x039D,
  2455. O: 0x004F,
  2456. OE: 0x0152,
  2457. OEsmall: 0xF6FA,
  2458. Oacute: 0x00D3,
  2459. Oacutesmall: 0xF7F3,
  2460. Obarredcyrillic: 0x04E8,
  2461. Obarreddieresiscyrillic: 0x04EA,
  2462. Obreve: 0x014E,
  2463. Ocaron: 0x01D1,
  2464. Ocenteredtilde: 0x019F,
  2465. Ocircle: 0x24C4,
  2466. Ocircumflex: 0x00D4,
  2467. Ocircumflexacute: 0x1ED0,
  2468. Ocircumflexdotbelow: 0x1ED8,
  2469. Ocircumflexgrave: 0x1ED2,
  2470. Ocircumflexhookabove: 0x1ED4,
  2471. Ocircumflexsmall: 0xF7F4,
  2472. Ocircumflextilde: 0x1ED6,
  2473. Ocyrillic: 0x041E,
  2474. Odblacute: 0x0150,
  2475. Odblgrave: 0x020C,
  2476. Odieresis: 0x00D6,
  2477. Odieresiscyrillic: 0x04E6,
  2478. Odieresissmall: 0xF7F6,
  2479. Odotbelow: 0x1ECC,
  2480. Ogoneksmall: 0xF6FB,
  2481. Ograve: 0x00D2,
  2482. Ogravesmall: 0xF7F2,
  2483. Oharmenian: 0x0555,
  2484. Ohm: 0x2126,
  2485. Ohookabove: 0x1ECE,
  2486. Ohorn: 0x01A0,
  2487. Ohornacute: 0x1EDA,
  2488. Ohorndotbelow: 0x1EE2,
  2489. Ohorngrave: 0x1EDC,
  2490. Ohornhookabove: 0x1EDE,
  2491. Ohorntilde: 0x1EE0,
  2492. Ohungarumlaut: 0x0150,
  2493. Oi: 0x01A2,
  2494. Oinvertedbreve: 0x020E,
  2495. Omacron: 0x014C,
  2496. Omacronacute: 0x1E52,
  2497. Omacrongrave: 0x1E50,
  2498. Omega: 0x2126,
  2499. Omegacyrillic: 0x0460,
  2500. Omegagreek: 0x03A9,
  2501. Omegaroundcyrillic: 0x047A,
  2502. Omegatitlocyrillic: 0x047C,
  2503. Omegatonos: 0x038F,
  2504. Omicron: 0x039F,
  2505. Omicrontonos: 0x038C,
  2506. Omonospace: 0xFF2F,
  2507. Oneroman: 0x2160,
  2508. Oogonek: 0x01EA,
  2509. Oogonekmacron: 0x01EC,
  2510. Oopen: 0x0186,
  2511. Oslash: 0x00D8,
  2512. Oslashacute: 0x01FE,
  2513. Oslashsmall: 0xF7F8,
  2514. Osmall: 0xF76F,
  2515. Ostrokeacute: 0x01FE,
  2516. Otcyrillic: 0x047E,
  2517. Otilde: 0x00D5,
  2518. Otildeacute: 0x1E4C,
  2519. Otildedieresis: 0x1E4E,
  2520. Otildesmall: 0xF7F5,
  2521. P: 0x0050,
  2522. Pacute: 0x1E54,
  2523. Pcircle: 0x24C5,
  2524. Pdotaccent: 0x1E56,
  2525. Pecyrillic: 0x041F,
  2526. Peharmenian: 0x054A,
  2527. Pemiddlehookcyrillic: 0x04A6,
  2528. Phi: 0x03A6,
  2529. Phook: 0x01A4,
  2530. Pi: 0x03A0,
  2531. Piwrarmenian: 0x0553,
  2532. Pmonospace: 0xFF30,
  2533. Psi: 0x03A8,
  2534. Psicyrillic: 0x0470,
  2535. Psmall: 0xF770,
  2536. Q: 0x0051,
  2537. Qcircle: 0x24C6,
  2538. Qmonospace: 0xFF31,
  2539. Qsmall: 0xF771,
  2540. R: 0x0052,
  2541. Raarmenian: 0x054C,
  2542. Racute: 0x0154,
  2543. Rcaron: 0x0158,
  2544. Rcedilla: 0x0156,
  2545. Rcircle: 0x24C7,
  2546. Rcommaaccent: 0x0156,
  2547. Rdblgrave: 0x0210,
  2548. Rdotaccent: 0x1E58,
  2549. Rdotbelow: 0x1E5A,
  2550. Rdotbelowmacron: 0x1E5C,
  2551. Reharmenian: 0x0550,
  2552. Rfraktur: 0x211C,
  2553. Rho: 0x03A1,
  2554. Ringsmall: 0xF6FC,
  2555. Rinvertedbreve: 0x0212,
  2556. Rlinebelow: 0x1E5E,
  2557. Rmonospace: 0xFF32,
  2558. Rsmall: 0xF772,
  2559. Rsmallinverted: 0x0281,
  2560. Rsmallinvertedsuperior: 0x02B6,
  2561. S: 0x0053,
  2562. SF010000: 0x250C,
  2563. SF020000: 0x2514,
  2564. SF030000: 0x2510,
  2565. SF040000: 0x2518,
  2566. SF050000: 0x253C,
  2567. SF060000: 0x252C,
  2568. SF070000: 0x2534,
  2569. SF080000: 0x251C,
  2570. SF090000: 0x2524,
  2571. SF100000: 0x2500,
  2572. SF110000: 0x2502,
  2573. SF190000: 0x2561,
  2574. SF200000: 0x2562,
  2575. SF210000: 0x2556,
  2576. SF220000: 0x2555,
  2577. SF230000: 0x2563,
  2578. SF240000: 0x2551,
  2579. SF250000: 0x2557,
  2580. SF260000: 0x255D,
  2581. SF270000: 0x255C,
  2582. SF280000: 0x255B,
  2583. SF360000: 0x255E,
  2584. SF370000: 0x255F,
  2585. SF380000: 0x255A,
  2586. SF390000: 0x2554,
  2587. SF400000: 0x2569,
  2588. SF410000: 0x2566,
  2589. SF420000: 0x2560,
  2590. SF430000: 0x2550,
  2591. SF440000: 0x256C,
  2592. SF450000: 0x2567,
  2593. SF460000: 0x2568,
  2594. SF470000: 0x2564,
  2595. SF480000: 0x2565,
  2596. SF490000: 0x2559,
  2597. SF500000: 0x2558,
  2598. SF510000: 0x2552,
  2599. SF520000: 0x2553,
  2600. SF530000: 0x256B,
  2601. SF540000: 0x256A,
  2602. Sacute: 0x015A,
  2603. Sacutedotaccent: 0x1E64,
  2604. Sampigreek: 0x03E0,
  2605. Scaron: 0x0160,
  2606. Scarondotaccent: 0x1E66,
  2607. Scaronsmall: 0xF6FD,
  2608. Scedilla: 0x015E,
  2609. Schwa: 0x018F,
  2610. Schwacyrillic: 0x04D8,
  2611. Schwadieresiscyrillic: 0x04DA,
  2612. Scircle: 0x24C8,
  2613. Scircumflex: 0x015C,
  2614. Scommaaccent: 0x0218,
  2615. Sdotaccent: 0x1E60,
  2616. Sdotbelow: 0x1E62,
  2617. Sdotbelowdotaccent: 0x1E68,
  2618. Seharmenian: 0x054D,
  2619. Sevenroman: 0x2166,
  2620. Shaarmenian: 0x0547,
  2621. Shacyrillic: 0x0428,
  2622. Shchacyrillic: 0x0429,
  2623. Sheicoptic: 0x03E2,
  2624. Shhacyrillic: 0x04BA,
  2625. Shimacoptic: 0x03EC,
  2626. Sigma: 0x03A3,
  2627. Sixroman: 0x2165,
  2628. Smonospace: 0xFF33,
  2629. Softsigncyrillic: 0x042C,
  2630. Ssmall: 0xF773,
  2631. Stigmagreek: 0x03DA,
  2632. T: 0x0054,
  2633. Tau: 0x03A4,
  2634. Tbar: 0x0166,
  2635. Tcaron: 0x0164,
  2636. Tcedilla: 0x0162,
  2637. Tcircle: 0x24C9,
  2638. Tcircumflexbelow: 0x1E70,
  2639. Tcommaaccent: 0x0162,
  2640. Tdotaccent: 0x1E6A,
  2641. Tdotbelow: 0x1E6C,
  2642. Tecyrillic: 0x0422,
  2643. Tedescendercyrillic: 0x04AC,
  2644. Tenroman: 0x2169,
  2645. Tetsecyrillic: 0x04B4,
  2646. Theta: 0x0398,
  2647. Thook: 0x01AC,
  2648. Thorn: 0x00DE,
  2649. Thornsmall: 0xF7FE,
  2650. Threeroman: 0x2162,
  2651. Tildesmall: 0xF6FE,
  2652. Tiwnarmenian: 0x054F,
  2653. Tlinebelow: 0x1E6E,
  2654. Tmonospace: 0xFF34,
  2655. Toarmenian: 0x0539,
  2656. Tonefive: 0x01BC,
  2657. Tonesix: 0x0184,
  2658. Tonetwo: 0x01A7,
  2659. Tretroflexhook: 0x01AE,
  2660. Tsecyrillic: 0x0426,
  2661. Tshecyrillic: 0x040B,
  2662. Tsmall: 0xF774,
  2663. Twelveroman: 0x216B,
  2664. Tworoman: 0x2161,
  2665. U: 0x0055,
  2666. Uacute: 0x00DA,
  2667. Uacutesmall: 0xF7FA,
  2668. Ubreve: 0x016C,
  2669. Ucaron: 0x01D3,
  2670. Ucircle: 0x24CA,
  2671. Ucircumflex: 0x00DB,
  2672. Ucircumflexbelow: 0x1E76,
  2673. Ucircumflexsmall: 0xF7FB,
  2674. Ucyrillic: 0x0423,
  2675. Udblacute: 0x0170,
  2676. Udblgrave: 0x0214,
  2677. Udieresis: 0x00DC,
  2678. Udieresisacute: 0x01D7,
  2679. Udieresisbelow: 0x1E72,
  2680. Udieresiscaron: 0x01D9,
  2681. Udieresiscyrillic: 0x04F0,
  2682. Udieresisgrave: 0x01DB,
  2683. Udieresismacron: 0x01D5,
  2684. Udieresissmall: 0xF7FC,
  2685. Udotbelow: 0x1EE4,
  2686. Ugrave: 0x00D9,
  2687. Ugravesmall: 0xF7F9,
  2688. Uhookabove: 0x1EE6,
  2689. Uhorn: 0x01AF,
  2690. Uhornacute: 0x1EE8,
  2691. Uhorndotbelow: 0x1EF0,
  2692. Uhorngrave: 0x1EEA,
  2693. Uhornhookabove: 0x1EEC,
  2694. Uhorntilde: 0x1EEE,
  2695. Uhungarumlaut: 0x0170,
  2696. Uhungarumlautcyrillic: 0x04F2,
  2697. Uinvertedbreve: 0x0216,
  2698. Ukcyrillic: 0x0478,
  2699. Umacron: 0x016A,
  2700. Umacroncyrillic: 0x04EE,
  2701. Umacrondieresis: 0x1E7A,
  2702. Umonospace: 0xFF35,
  2703. Uogonek: 0x0172,
  2704. Upsilon: 0x03A5,
  2705. Upsilon1: 0x03D2,
  2706. Upsilonacutehooksymbolgreek: 0x03D3,
  2707. Upsilonafrican: 0x01B1,
  2708. Upsilondieresis: 0x03AB,
  2709. Upsilondieresishooksymbolgreek: 0x03D4,
  2710. Upsilonhooksymbol: 0x03D2,
  2711. Upsilontonos: 0x038E,
  2712. Uring: 0x016E,
  2713. Ushortcyrillic: 0x040E,
  2714. Usmall: 0xF775,
  2715. Ustraightcyrillic: 0x04AE,
  2716. Ustraightstrokecyrillic: 0x04B0,
  2717. Utilde: 0x0168,
  2718. Utildeacute: 0x1E78,
  2719. Utildebelow: 0x1E74,
  2720. V: 0x0056,
  2721. Vcircle: 0x24CB,
  2722. Vdotbelow: 0x1E7E,
  2723. Vecyrillic: 0x0412,
  2724. Vewarmenian: 0x054E,
  2725. Vhook: 0x01B2,
  2726. Vmonospace: 0xFF36,
  2727. Voarmenian: 0x0548,
  2728. Vsmall: 0xF776,
  2729. Vtilde: 0x1E7C,
  2730. W: 0x0057,
  2731. Wacute: 0x1E82,
  2732. Wcircle: 0x24CC,
  2733. Wcircumflex: 0x0174,
  2734. Wdieresis: 0x1E84,
  2735. Wdotaccent: 0x1E86,
  2736. Wdotbelow: 0x1E88,
  2737. Wgrave: 0x1E80,
  2738. Wmonospace: 0xFF37,
  2739. Wsmall: 0xF777,
  2740. X: 0x0058,
  2741. Xcircle: 0x24CD,
  2742. Xdieresis: 0x1E8C,
  2743. Xdotaccent: 0x1E8A,
  2744. Xeharmenian: 0x053D,
  2745. Xi: 0x039E,
  2746. Xmonospace: 0xFF38,
  2747. Xsmall: 0xF778,
  2748. Y: 0x0059,
  2749. Yacute: 0x00DD,
  2750. Yacutesmall: 0xF7FD,
  2751. Yatcyrillic: 0x0462,
  2752. Ycircle: 0x24CE,
  2753. Ycircumflex: 0x0176,
  2754. Ydieresis: 0x0178,
  2755. Ydieresissmall: 0xF7FF,
  2756. Ydotaccent: 0x1E8E,
  2757. Ydotbelow: 0x1EF4,
  2758. Yericyrillic: 0x042B,
  2759. Yerudieresiscyrillic: 0x04F8,
  2760. Ygrave: 0x1EF2,
  2761. Yhook: 0x01B3,
  2762. Yhookabove: 0x1EF6,
  2763. Yiarmenian: 0x0545,
  2764. Yicyrillic: 0x0407,
  2765. Yiwnarmenian: 0x0552,
  2766. Ymonospace: 0xFF39,
  2767. Ysmall: 0xF779,
  2768. Ytilde: 0x1EF8,
  2769. Yusbigcyrillic: 0x046A,
  2770. Yusbigiotifiedcyrillic: 0x046C,
  2771. Yuslittlecyrillic: 0x0466,
  2772. Yuslittleiotifiedcyrillic: 0x0468,
  2773. Z: 0x005A,
  2774. Zaarmenian: 0x0536,
  2775. Zacute: 0x0179,
  2776. Zcaron: 0x017D,
  2777. Zcaronsmall: 0xF6FF,
  2778. Zcircle: 0x24CF,
  2779. Zcircumflex: 0x1E90,
  2780. Zdot: 0x017B,
  2781. Zdotaccent: 0x017B,
  2782. Zdotbelow: 0x1E92,
  2783. Zecyrillic: 0x0417,
  2784. Zedescendercyrillic: 0x0498,
  2785. Zedieresiscyrillic: 0x04DE,
  2786. Zeta: 0x0396,
  2787. Zhearmenian: 0x053A,
  2788. Zhebrevecyrillic: 0x04C1,
  2789. Zhecyrillic: 0x0416,
  2790. Zhedescendercyrillic: 0x0496,
  2791. Zhedieresiscyrillic: 0x04DC,
  2792. Zlinebelow: 0x1E94,
  2793. Zmonospace: 0xFF3A,
  2794. Zsmall: 0xF77A,
  2795. Zstroke: 0x01B5,
  2796. a: 0x0061,
  2797. aabengali: 0x0986,
  2798. aacute: 0x00E1,
  2799. aadeva: 0x0906,
  2800. aagujarati: 0x0A86,
  2801. aagurmukhi: 0x0A06,
  2802. aamatragurmukhi: 0x0A3E,
  2803. aarusquare: 0x3303,
  2804. aavowelsignbengali: 0x09BE,
  2805. aavowelsigndeva: 0x093E,
  2806. aavowelsigngujarati: 0x0ABE,
  2807. abbreviationmarkarmenian: 0x055F,
  2808. abbreviationsigndeva: 0x0970,
  2809. abengali: 0x0985,
  2810. abopomofo: 0x311A,
  2811. abreve: 0x0103,
  2812. abreveacute: 0x1EAF,
  2813. abrevecyrillic: 0x04D1,
  2814. abrevedotbelow: 0x1EB7,
  2815. abrevegrave: 0x1EB1,
  2816. abrevehookabove: 0x1EB3,
  2817. abrevetilde: 0x1EB5,
  2818. acaron: 0x01CE,
  2819. acircle: 0x24D0,
  2820. acircumflex: 0x00E2,
  2821. acircumflexacute: 0x1EA5,
  2822. acircumflexdotbelow: 0x1EAD,
  2823. acircumflexgrave: 0x1EA7,
  2824. acircumflexhookabove: 0x1EA9,
  2825. acircumflextilde: 0x1EAB,
  2826. acute: 0x00B4,
  2827. acutebelowcmb: 0x0317,
  2828. acutecmb: 0x0301,
  2829. acutecomb: 0x0301,
  2830. acutedeva: 0x0954,
  2831. acutelowmod: 0x02CF,
  2832. acutetonecmb: 0x0341,
  2833. acyrillic: 0x0430,
  2834. adblgrave: 0x0201,
  2835. addakgurmukhi: 0x0A71,
  2836. adeva: 0x0905,
  2837. adieresis: 0x00E4,
  2838. adieresiscyrillic: 0x04D3,
  2839. adieresismacron: 0x01DF,
  2840. adotbelow: 0x1EA1,
  2841. adotmacron: 0x01E1,
  2842. ae: 0x00E6,
  2843. aeacute: 0x01FD,
  2844. aekorean: 0x3150,
  2845. aemacron: 0x01E3,
  2846. afii00208: 0x2015,
  2847. afii08941: 0x20A4,
  2848. afii10017: 0x0410,
  2849. afii10018: 0x0411,
  2850. afii10019: 0x0412,
  2851. afii10020: 0x0413,
  2852. afii10021: 0x0414,
  2853. afii10022: 0x0415,
  2854. afii10023: 0x0401,
  2855. afii10024: 0x0416,
  2856. afii10025: 0x0417,
  2857. afii10026: 0x0418,
  2858. afii10027: 0x0419,
  2859. afii10028: 0x041A,
  2860. afii10029: 0x041B,
  2861. afii10030: 0x041C,
  2862. afii10031: 0x041D,
  2863. afii10032: 0x041E,
  2864. afii10033: 0x041F,
  2865. afii10034: 0x0420,
  2866. afii10035: 0x0421,
  2867. afii10036: 0x0422,
  2868. afii10037: 0x0423,
  2869. afii10038: 0x0424,
  2870. afii10039: 0x0425,
  2871. afii10040: 0x0426,
  2872. afii10041: 0x0427,
  2873. afii10042: 0x0428,
  2874. afii10043: 0x0429,
  2875. afii10044: 0x042A,
  2876. afii10045: 0x042B,
  2877. afii10046: 0x042C,
  2878. afii10047: 0x042D,
  2879. afii10048: 0x042E,
  2880. afii10049: 0x042F,
  2881. afii10050: 0x0490,
  2882. afii10051: 0x0402,
  2883. afii10052: 0x0403,
  2884. afii10053: 0x0404,
  2885. afii10054: 0x0405,
  2886. afii10055: 0x0406,
  2887. afii10056: 0x0407,
  2888. afii10057: 0x0408,
  2889. afii10058: 0x0409,
  2890. afii10059: 0x040A,
  2891. afii10060: 0x040B,
  2892. afii10061: 0x040C,
  2893. afii10062: 0x040E,
  2894. afii10063: 0xF6C4,
  2895. afii10064: 0xF6C5,
  2896. afii10065: 0x0430,
  2897. afii10066: 0x0431,
  2898. afii10067: 0x0432,
  2899. afii10068: 0x0433,
  2900. afii10069: 0x0434,
  2901. afii10070: 0x0435,
  2902. afii10071: 0x0451,
  2903. afii10072: 0x0436,
  2904. afii10073: 0x0437,
  2905. afii10074: 0x0438,
  2906. afii10075: 0x0439,
  2907. afii10076: 0x043A,
  2908. afii10077: 0x043B,
  2909. afii10078: 0x043C,
  2910. afii10079: 0x043D,
  2911. afii10080: 0x043E,
  2912. afii10081: 0x043F,
  2913. afii10082: 0x0440,
  2914. afii10083: 0x0441,
  2915. afii10084: 0x0442,
  2916. afii10085: 0x0443,
  2917. afii10086: 0x0444,
  2918. afii10087: 0x0445,
  2919. afii10088: 0x0446,
  2920. afii10089: 0x0447,
  2921. afii10090: 0x0448,
  2922. afii10091: 0x0449,
  2923. afii10092: 0x044A,
  2924. afii10093: 0x044B,
  2925. afii10094: 0x044C,
  2926. afii10095: 0x044D,
  2927. afii10096: 0x044E,
  2928. afii10097: 0x044F,
  2929. afii10098: 0x0491,
  2930. afii10099: 0x0452,
  2931. afii10100: 0x0453,
  2932. afii10101: 0x0454,
  2933. afii10102: 0x0455,
  2934. afii10103: 0x0456,
  2935. afii10104: 0x0457,
  2936. afii10105: 0x0458,
  2937. afii10106: 0x0459,
  2938. afii10107: 0x045A,
  2939. afii10108: 0x045B,
  2940. afii10109: 0x045C,
  2941. afii10110: 0x045E,
  2942. afii10145: 0x040F,
  2943. afii10146: 0x0462,
  2944. afii10147: 0x0472,
  2945. afii10148: 0x0474,
  2946. afii10192: 0xF6C6,
  2947. afii10193: 0x045F,
  2948. afii10194: 0x0463,
  2949. afii10195: 0x0473,
  2950. afii10196: 0x0475,
  2951. afii10831: 0xF6C7,
  2952. afii10832: 0xF6C8,
  2953. afii10846: 0x04D9,
  2954. afii299: 0x200E,
  2955. afii300: 0x200F,
  2956. afii301: 0x200D,
  2957. afii57381: 0x066A,
  2958. afii57388: 0x060C,
  2959. afii57392: 0x0660,
  2960. afii57393: 0x0661,
  2961. afii57394: 0x0662,
  2962. afii57395: 0x0663,
  2963. afii57396: 0x0664,
  2964. afii57397: 0x0665,
  2965. afii57398: 0x0666,
  2966. afii57399: 0x0667,
  2967. afii57400: 0x0668,
  2968. afii57401: 0x0669,
  2969. afii57403: 0x061B,
  2970. afii57407: 0x061F,
  2971. afii57409: 0x0621,
  2972. afii57410: 0x0622,
  2973. afii57411: 0x0623,
  2974. afii57412: 0x0624,
  2975. afii57413: 0x0625,
  2976. afii57414: 0x0626,
  2977. afii57415: 0x0627,
  2978. afii57416: 0x0628,
  2979. afii57417: 0x0629,
  2980. afii57418: 0x062A,
  2981. afii57419: 0x062B,
  2982. afii57420: 0x062C,
  2983. afii57421: 0x062D,
  2984. afii57422: 0x062E,
  2985. afii57423: 0x062F,
  2986. afii57424: 0x0630,
  2987. afii57425: 0x0631,
  2988. afii57426: 0x0632,
  2989. afii57427: 0x0633,
  2990. afii57428: 0x0634,
  2991. afii57429: 0x0635,
  2992. afii57430: 0x0636,
  2993. afii57431: 0x0637,
  2994. afii57432: 0x0638,
  2995. afii57433: 0x0639,
  2996. afii57434: 0x063A,
  2997. afii57440: 0x0640,
  2998. afii57441: 0x0641,
  2999. afii57442: 0x0642,
  3000. afii57443: 0x0643,
  3001. afii57444: 0x0644,
  3002. afii57445: 0x0645,
  3003. afii57446: 0x0646,
  3004. afii57448: 0x0648,
  3005. afii57449: 0x0649,
  3006. afii57450: 0x064A,
  3007. afii57451: 0x064B,
  3008. afii57452: 0x064C,
  3009. afii57453: 0x064D,
  3010. afii57454: 0x064E,
  3011. afii57455: 0x064F,
  3012. afii57456: 0x0650,
  3013. afii57457: 0x0651,
  3014. afii57458: 0x0652,
  3015. afii57470: 0x0647,
  3016. afii57505: 0x06A4,
  3017. afii57506: 0x067E,
  3018. afii57507: 0x0686,
  3019. afii57508: 0x0698,
  3020. afii57509: 0x06AF,
  3021. afii57511: 0x0679,
  3022. afii57512: 0x0688,
  3023. afii57513: 0x0691,
  3024. afii57514: 0x06BA,
  3025. afii57519: 0x06D2,
  3026. afii57534: 0x06D5,
  3027. afii57636: 0x20AA,
  3028. afii57645: 0x05BE,
  3029. afii57658: 0x05C3,
  3030. afii57664: 0x05D0,
  3031. afii57665: 0x05D1,
  3032. afii57666: 0x05D2,
  3033. afii57667: 0x05D3,
  3034. afii57668: 0x05D4,
  3035. afii57669: 0x05D5,
  3036. afii57670: 0x05D6,
  3037. afii57671: 0x05D7,
  3038. afii57672: 0x05D8,
  3039. afii57673: 0x05D9,
  3040. afii57674: 0x05DA,
  3041. afii57675: 0x05DB,
  3042. afii57676: 0x05DC,
  3043. afii57677: 0x05DD,
  3044. afii57678: 0x05DE,
  3045. afii57679: 0x05DF,
  3046. afii57680: 0x05E0,
  3047. afii57681: 0x05E1,
  3048. afii57682: 0x05E2,
  3049. afii57683: 0x05E3,
  3050. afii57684: 0x05E4,
  3051. afii57685: 0x05E5,
  3052. afii57686: 0x05E6,
  3053. afii57687: 0x05E7,
  3054. afii57688: 0x05E8,
  3055. afii57689: 0x05E9,
  3056. afii57690: 0x05EA,
  3057. afii57694: 0xFB2A,
  3058. afii57695: 0xFB2B,
  3059. afii57700: 0xFB4B,
  3060. afii57705: 0xFB1F,
  3061. afii57716: 0x05F0,
  3062. afii57717: 0x05F1,
  3063. afii57718: 0x05F2,
  3064. afii57723: 0xFB35,
  3065. afii57793: 0x05B4,
  3066. afii57794: 0x05B5,
  3067. afii57795: 0x05B6,
  3068. afii57796: 0x05BB,
  3069. afii57797: 0x05B8,
  3070. afii57798: 0x05B7,
  3071. afii57799: 0x05B0,
  3072. afii57800: 0x05B2,
  3073. afii57801: 0x05B1,
  3074. afii57802: 0x05B3,
  3075. afii57803: 0x05C2,
  3076. afii57804: 0x05C1,
  3077. afii57806: 0x05B9,
  3078. afii57807: 0x05BC,
  3079. afii57839: 0x05BD,
  3080. afii57841: 0x05BF,
  3081. afii57842: 0x05C0,
  3082. afii57929: 0x02BC,
  3083. afii61248: 0x2105,
  3084. afii61289: 0x2113,
  3085. afii61352: 0x2116,
  3086. afii61573: 0x202C,
  3087. afii61574: 0x202D,
  3088. afii61575: 0x202E,
  3089. afii61664: 0x200C,
  3090. afii63167: 0x066D,
  3091. afii64937: 0x02BD,
  3092. agrave: 0x00E0,
  3093. agujarati: 0x0A85,
  3094. agurmukhi: 0x0A05,
  3095. ahiragana: 0x3042,
  3096. ahookabove: 0x1EA3,
  3097. aibengali: 0x0990,
  3098. aibopomofo: 0x311E,
  3099. aideva: 0x0910,
  3100. aiecyrillic: 0x04D5,
  3101. aigujarati: 0x0A90,
  3102. aigurmukhi: 0x0A10,
  3103. aimatragurmukhi: 0x0A48,
  3104. ainarabic: 0x0639,
  3105. ainfinalarabic: 0xFECA,
  3106. aininitialarabic: 0xFECB,
  3107. ainmedialarabic: 0xFECC,
  3108. ainvertedbreve: 0x0203,
  3109. aivowelsignbengali: 0x09C8,
  3110. aivowelsigndeva: 0x0948,
  3111. aivowelsigngujarati: 0x0AC8,
  3112. akatakana: 0x30A2,
  3113. akatakanahalfwidth: 0xFF71,
  3114. akorean: 0x314F,
  3115. alef: 0x05D0,
  3116. alefarabic: 0x0627,
  3117. alefdageshhebrew: 0xFB30,
  3118. aleffinalarabic: 0xFE8E,
  3119. alefhamzaabovearabic: 0x0623,
  3120. alefhamzaabovefinalarabic: 0xFE84,
  3121. alefhamzabelowarabic: 0x0625,
  3122. alefhamzabelowfinalarabic: 0xFE88,
  3123. alefhebrew: 0x05D0,
  3124. aleflamedhebrew: 0xFB4F,
  3125. alefmaddaabovearabic: 0x0622,
  3126. alefmaddaabovefinalarabic: 0xFE82,
  3127. alefmaksuraarabic: 0x0649,
  3128. alefmaksurafinalarabic: 0xFEF0,
  3129. alefmaksurainitialarabic: 0xFEF3,
  3130. alefmaksuramedialarabic: 0xFEF4,
  3131. alefpatahhebrew: 0xFB2E,
  3132. alefqamatshebrew: 0xFB2F,
  3133. aleph: 0x2135,
  3134. allequal: 0x224C,
  3135. alpha: 0x03B1,
  3136. alphatonos: 0x03AC,
  3137. amacron: 0x0101,
  3138. amonospace: 0xFF41,
  3139. ampersand: 0x0026,
  3140. ampersandmonospace: 0xFF06,
  3141. ampersandsmall: 0xF726,
  3142. amsquare: 0x33C2,
  3143. anbopomofo: 0x3122,
  3144. angbopomofo: 0x3124,
  3145. angbracketleft: 0x3008, // This glyph is missing from Adobe's original list.
  3146. angbracketright: 0x3009, // This glyph is missing from Adobe's original list.
  3147. angkhankhuthai: 0x0E5A,
  3148. angle: 0x2220,
  3149. anglebracketleft: 0x3008,
  3150. anglebracketleftvertical: 0xFE3F,
  3151. anglebracketright: 0x3009,
  3152. anglebracketrightvertical: 0xFE40,
  3153. angleleft: 0x2329,
  3154. angleright: 0x232A,
  3155. angstrom: 0x212B,
  3156. anoteleia: 0x0387,
  3157. anudattadeva: 0x0952,
  3158. anusvarabengali: 0x0982,
  3159. anusvaradeva: 0x0902,
  3160. anusvaragujarati: 0x0A82,
  3161. aogonek: 0x0105,
  3162. apaatosquare: 0x3300,
  3163. aparen: 0x249C,
  3164. apostrophearmenian: 0x055A,
  3165. apostrophemod: 0x02BC,
  3166. apple: 0xF8FF,
  3167. approaches: 0x2250,
  3168. approxequal: 0x2248,
  3169. approxequalorimage: 0x2252,
  3170. approximatelyequal: 0x2245,
  3171. araeaekorean: 0x318E,
  3172. araeakorean: 0x318D,
  3173. arc: 0x2312,
  3174. arighthalfring: 0x1E9A,
  3175. aring: 0x00E5,
  3176. aringacute: 0x01FB,
  3177. aringbelow: 0x1E01,
  3178. arrowboth: 0x2194,
  3179. arrowdashdown: 0x21E3,
  3180. arrowdashleft: 0x21E0,
  3181. arrowdashright: 0x21E2,
  3182. arrowdashup: 0x21E1,
  3183. arrowdblboth: 0x21D4,
  3184. arrowdbldown: 0x21D3,
  3185. arrowdblleft: 0x21D0,
  3186. arrowdblright: 0x21D2,
  3187. arrowdblup: 0x21D1,
  3188. arrowdown: 0x2193,
  3189. arrowdownleft: 0x2199,
  3190. arrowdownright: 0x2198,
  3191. arrowdownwhite: 0x21E9,
  3192. arrowheaddownmod: 0x02C5,
  3193. arrowheadleftmod: 0x02C2,
  3194. arrowheadrightmod: 0x02C3,
  3195. arrowheadupmod: 0x02C4,
  3196. arrowhorizex: 0xF8E7,
  3197. arrowleft: 0x2190,
  3198. arrowleftdbl: 0x21D0,
  3199. arrowleftdblstroke: 0x21CD,
  3200. arrowleftoverright: 0x21C6,
  3201. arrowleftwhite: 0x21E6,
  3202. arrowright: 0x2192,
  3203. arrowrightdblstroke: 0x21CF,
  3204. arrowrightheavy: 0x279E,
  3205. arrowrightoverleft: 0x21C4,
  3206. arrowrightwhite: 0x21E8,
  3207. arrowtableft: 0x21E4,
  3208. arrowtabright: 0x21E5,
  3209. arrowup: 0x2191,
  3210. arrowupdn: 0x2195,
  3211. arrowupdnbse: 0x21A8,
  3212. arrowupdownbase: 0x21A8,
  3213. arrowupleft: 0x2196,
  3214. arrowupleftofdown: 0x21C5,
  3215. arrowupright: 0x2197,
  3216. arrowupwhite: 0x21E7,
  3217. arrowvertex: 0xF8E6,
  3218. asciicircum: 0x005E,
  3219. asciicircummonospace: 0xFF3E,
  3220. asciitilde: 0x007E,
  3221. asciitildemonospace: 0xFF5E,
  3222. ascript: 0x0251,
  3223. ascriptturned: 0x0252,
  3224. asmallhiragana: 0x3041,
  3225. asmallkatakana: 0x30A1,
  3226. asmallkatakanahalfwidth: 0xFF67,
  3227. asterisk: 0x002A,
  3228. asteriskaltonearabic: 0x066D,
  3229. asteriskarabic: 0x066D,
  3230. asteriskmath: 0x2217,
  3231. asteriskmonospace: 0xFF0A,
  3232. asterisksmall: 0xFE61,
  3233. asterism: 0x2042,
  3234. asuperior: 0xF6E9,
  3235. asymptoticallyequal: 0x2243,
  3236. at: 0x0040,
  3237. atilde: 0x00E3,
  3238. atmonospace: 0xFF20,
  3239. atsmall: 0xFE6B,
  3240. aturned: 0x0250,
  3241. aubengali: 0x0994,
  3242. aubopomofo: 0x3120,
  3243. audeva: 0x0914,
  3244. augujarati: 0x0A94,
  3245. augurmukhi: 0x0A14,
  3246. aulengthmarkbengali: 0x09D7,
  3247. aumatragurmukhi: 0x0A4C,
  3248. auvowelsignbengali: 0x09CC,
  3249. auvowelsigndeva: 0x094C,
  3250. auvowelsigngujarati: 0x0ACC,
  3251. avagrahadeva: 0x093D,
  3252. aybarmenian: 0x0561,
  3253. ayin: 0x05E2,
  3254. ayinaltonehebrew: 0xFB20,
  3255. ayinhebrew: 0x05E2,
  3256. b: 0x0062,
  3257. babengali: 0x09AC,
  3258. backslash: 0x005C,
  3259. backslashmonospace: 0xFF3C,
  3260. badeva: 0x092C,
  3261. bagujarati: 0x0AAC,
  3262. bagurmukhi: 0x0A2C,
  3263. bahiragana: 0x3070,
  3264. bahtthai: 0x0E3F,
  3265. bakatakana: 0x30D0,
  3266. bar: 0x007C,
  3267. barmonospace: 0xFF5C,
  3268. bbopomofo: 0x3105,
  3269. bcircle: 0x24D1,
  3270. bdotaccent: 0x1E03,
  3271. bdotbelow: 0x1E05,
  3272. beamedsixteenthnotes: 0x266C,
  3273. because: 0x2235,
  3274. becyrillic: 0x0431,
  3275. beharabic: 0x0628,
  3276. behfinalarabic: 0xFE90,
  3277. behinitialarabic: 0xFE91,
  3278. behiragana: 0x3079,
  3279. behmedialarabic: 0xFE92,
  3280. behmeeminitialarabic: 0xFC9F,
  3281. behmeemisolatedarabic: 0xFC08,
  3282. behnoonfinalarabic: 0xFC6D,
  3283. bekatakana: 0x30D9,
  3284. benarmenian: 0x0562,
  3285. bet: 0x05D1,
  3286. beta: 0x03B2,
  3287. betasymbolgreek: 0x03D0,
  3288. betdagesh: 0xFB31,
  3289. betdageshhebrew: 0xFB31,
  3290. bethebrew: 0x05D1,
  3291. betrafehebrew: 0xFB4C,
  3292. bhabengali: 0x09AD,
  3293. bhadeva: 0x092D,
  3294. bhagujarati: 0x0AAD,
  3295. bhagurmukhi: 0x0A2D,
  3296. bhook: 0x0253,
  3297. bihiragana: 0x3073,
  3298. bikatakana: 0x30D3,
  3299. bilabialclick: 0x0298,
  3300. bindigurmukhi: 0x0A02,
  3301. birusquare: 0x3331,
  3302. blackcircle: 0x25CF,
  3303. blackdiamond: 0x25C6,
  3304. blackdownpointingtriangle: 0x25BC,
  3305. blackleftpointingpointer: 0x25C4,
  3306. blackleftpointingtriangle: 0x25C0,
  3307. blacklenticularbracketleft: 0x3010,
  3308. blacklenticularbracketleftvertical: 0xFE3B,
  3309. blacklenticularbracketright: 0x3011,
  3310. blacklenticularbracketrightvertical: 0xFE3C,
  3311. blacklowerlefttriangle: 0x25E3,
  3312. blacklowerrighttriangle: 0x25E2,
  3313. blackrectangle: 0x25AC,
  3314. blackrightpointingpointer: 0x25BA,
  3315. blackrightpointingtriangle: 0x25B6,
  3316. blacksmallsquare: 0x25AA,
  3317. blacksmilingface: 0x263B,
  3318. blacksquare: 0x25A0,
  3319. blackstar: 0x2605,
  3320. blackupperlefttriangle: 0x25E4,
  3321. blackupperrighttriangle: 0x25E5,
  3322. blackuppointingsmalltriangle: 0x25B4,
  3323. blackuppointingtriangle: 0x25B2,
  3324. blank: 0x2423,
  3325. blinebelow: 0x1E07,
  3326. block: 0x2588,
  3327. bmonospace: 0xFF42,
  3328. bobaimaithai: 0x0E1A,
  3329. bohiragana: 0x307C,
  3330. bokatakana: 0x30DC,
  3331. bparen: 0x249D,
  3332. bqsquare: 0x33C3,
  3333. braceex: 0xF8F4,
  3334. braceleft: 0x007B,
  3335. braceleftbt: 0xF8F3,
  3336. braceleftmid: 0xF8F2,
  3337. braceleftmonospace: 0xFF5B,
  3338. braceleftsmall: 0xFE5B,
  3339. bracelefttp: 0xF8F1,
  3340. braceleftvertical: 0xFE37,
  3341. braceright: 0x007D,
  3342. bracerightbt: 0xF8FE,
  3343. bracerightmid: 0xF8FD,
  3344. bracerightmonospace: 0xFF5D,
  3345. bracerightsmall: 0xFE5C,
  3346. bracerighttp: 0xF8FC,
  3347. bracerightvertical: 0xFE38,
  3348. bracketleft: 0x005B,
  3349. bracketleftbt: 0xF8F0,
  3350. bracketleftex: 0xF8EF,
  3351. bracketleftmonospace: 0xFF3B,
  3352. bracketlefttp: 0xF8EE,
  3353. bracketright: 0x005D,
  3354. bracketrightbt: 0xF8FB,
  3355. bracketrightex: 0xF8FA,
  3356. bracketrightmonospace: 0xFF3D,
  3357. bracketrighttp: 0xF8F9,
  3358. breve: 0x02D8,
  3359. brevebelowcmb: 0x032E,
  3360. brevecmb: 0x0306,
  3361. breveinvertedbelowcmb: 0x032F,
  3362. breveinvertedcmb: 0x0311,
  3363. breveinverteddoublecmb: 0x0361,
  3364. bridgebelowcmb: 0x032A,
  3365. bridgeinvertedbelowcmb: 0x033A,
  3366. brokenbar: 0x00A6,
  3367. bstroke: 0x0180,
  3368. bsuperior: 0xF6EA,
  3369. btopbar: 0x0183,
  3370. buhiragana: 0x3076,
  3371. bukatakana: 0x30D6,
  3372. bullet: 0x2022,
  3373. bulletinverse: 0x25D8,
  3374. bulletoperator: 0x2219,
  3375. bullseye: 0x25CE,
  3376. c: 0x0063,
  3377. caarmenian: 0x056E,
  3378. cabengali: 0x099A,
  3379. cacute: 0x0107,
  3380. cadeva: 0x091A,
  3381. cagujarati: 0x0A9A,
  3382. cagurmukhi: 0x0A1A,
  3383. calsquare: 0x3388,
  3384. candrabindubengali: 0x0981,
  3385. candrabinducmb: 0x0310,
  3386. candrabindudeva: 0x0901,
  3387. candrabindugujarati: 0x0A81,
  3388. capslock: 0x21EA,
  3389. careof: 0x2105,
  3390. caron: 0x02C7,
  3391. caronbelowcmb: 0x032C,
  3392. caroncmb: 0x030C,
  3393. carriagereturn: 0x21B5,
  3394. cbopomofo: 0x3118,
  3395. ccaron: 0x010D,
  3396. ccedilla: 0x00E7,
  3397. ccedillaacute: 0x1E09,
  3398. ccircle: 0x24D2,
  3399. ccircumflex: 0x0109,
  3400. ccurl: 0x0255,
  3401. cdot: 0x010B,
  3402. cdotaccent: 0x010B,
  3403. cdsquare: 0x33C5,
  3404. cedilla: 0x00B8,
  3405. cedillacmb: 0x0327,
  3406. cent: 0x00A2,
  3407. centigrade: 0x2103,
  3408. centinferior: 0xF6DF,
  3409. centmonospace: 0xFFE0,
  3410. centoldstyle: 0xF7A2,
  3411. centsuperior: 0xF6E0,
  3412. chaarmenian: 0x0579,
  3413. chabengali: 0x099B,
  3414. chadeva: 0x091B,
  3415. chagujarati: 0x0A9B,
  3416. chagurmukhi: 0x0A1B,
  3417. chbopomofo: 0x3114,
  3418. cheabkhasiancyrillic: 0x04BD,
  3419. checkmark: 0x2713,
  3420. checyrillic: 0x0447,
  3421. chedescenderabkhasiancyrillic: 0x04BF,
  3422. chedescendercyrillic: 0x04B7,
  3423. chedieresiscyrillic: 0x04F5,
  3424. cheharmenian: 0x0573,
  3425. chekhakassiancyrillic: 0x04CC,
  3426. cheverticalstrokecyrillic: 0x04B9,
  3427. chi: 0x03C7,
  3428. chieuchacirclekorean: 0x3277,
  3429. chieuchaparenkorean: 0x3217,
  3430. chieuchcirclekorean: 0x3269,
  3431. chieuchkorean: 0x314A,
  3432. chieuchparenkorean: 0x3209,
  3433. chochangthai: 0x0E0A,
  3434. chochanthai: 0x0E08,
  3435. chochingthai: 0x0E09,
  3436. chochoethai: 0x0E0C,
  3437. chook: 0x0188,
  3438. cieucacirclekorean: 0x3276,
  3439. cieucaparenkorean: 0x3216,
  3440. cieuccirclekorean: 0x3268,
  3441. cieuckorean: 0x3148,
  3442. cieucparenkorean: 0x3208,
  3443. cieucuparenkorean: 0x321C,
  3444. circle: 0x25CB,
  3445. circlecopyrt: 0x00A9, // This glyph is missing from Adobe's original list.
  3446. circlemultiply: 0x2297,
  3447. circleot: 0x2299,
  3448. circleplus: 0x2295,
  3449. circlepostalmark: 0x3036,
  3450. circlewithlefthalfblack: 0x25D0,
  3451. circlewithrighthalfblack: 0x25D1,
  3452. circumflex: 0x02C6,
  3453. circumflexbelowcmb: 0x032D,
  3454. circumflexcmb: 0x0302,
  3455. clear: 0x2327,
  3456. clickalveolar: 0x01C2,
  3457. clickdental: 0x01C0,
  3458. clicklateral: 0x01C1,
  3459. clickretroflex: 0x01C3,
  3460. club: 0x2663,
  3461. clubsuitblack: 0x2663,
  3462. clubsuitwhite: 0x2667,
  3463. cmcubedsquare: 0x33A4,
  3464. cmonospace: 0xFF43,
  3465. cmsquaredsquare: 0x33A0,
  3466. coarmenian: 0x0581,
  3467. colon: 0x003A,
  3468. colonmonetary: 0x20A1,
  3469. colonmonospace: 0xFF1A,
  3470. colonsign: 0x20A1,
  3471. colonsmall: 0xFE55,
  3472. colontriangularhalfmod: 0x02D1,
  3473. colontriangularmod: 0x02D0,
  3474. comma: 0x002C,
  3475. commaabovecmb: 0x0313,
  3476. commaaboverightcmb: 0x0315,
  3477. commaaccent: 0xF6C3,
  3478. commaarabic: 0x060C,
  3479. commaarmenian: 0x055D,
  3480. commainferior: 0xF6E1,
  3481. commamonospace: 0xFF0C,
  3482. commareversedabovecmb: 0x0314,
  3483. commareversedmod: 0x02BD,
  3484. commasmall: 0xFE50,
  3485. commasuperior: 0xF6E2,
  3486. commaturnedabovecmb: 0x0312,
  3487. commaturnedmod: 0x02BB,
  3488. compass: 0x263C,
  3489. congruent: 0x2245,
  3490. contourintegral: 0x222E,
  3491. control: 0x2303,
  3492. controlACK: 0x0006,
  3493. controlBEL: 0x0007,
  3494. controlBS: 0x0008,
  3495. controlCAN: 0x0018,
  3496. controlCR: 0x000D,
  3497. controlDC1: 0x0011,
  3498. controlDC2: 0x0012,
  3499. controlDC3: 0x0013,
  3500. controlDC4: 0x0014,
  3501. controlDEL: 0x007F,
  3502. controlDLE: 0x0010,
  3503. controlEM: 0x0019,
  3504. controlENQ: 0x0005,
  3505. controlEOT: 0x0004,
  3506. controlESC: 0x001B,
  3507. controlETB: 0x0017,
  3508. controlETX: 0x0003,
  3509. controlFF: 0x000C,
  3510. controlFS: 0x001C,
  3511. controlGS: 0x001D,
  3512. controlHT: 0x0009,
  3513. controlLF: 0x000A,
  3514. controlNAK: 0x0015,
  3515. controlRS: 0x001E,
  3516. controlSI: 0x000F,
  3517. controlSO: 0x000E,
  3518. controlSOT: 0x0002,
  3519. controlSTX: 0x0001,
  3520. controlSUB: 0x001A,
  3521. controlSYN: 0x0016,
  3522. controlUS: 0x001F,
  3523. controlVT: 0x000B,
  3524. copyright: 0x00A9,
  3525. copyrightsans: 0xF8E9,
  3526. copyrightserif: 0xF6D9,
  3527. cornerbracketleft: 0x300C,
  3528. cornerbracketlefthalfwidth: 0xFF62,
  3529. cornerbracketleftvertical: 0xFE41,
  3530. cornerbracketright: 0x300D,
  3531. cornerbracketrighthalfwidth: 0xFF63,
  3532. cornerbracketrightvertical: 0xFE42,
  3533. corporationsquare: 0x337F,
  3534. cosquare: 0x33C7,
  3535. coverkgsquare: 0x33C6,
  3536. cparen: 0x249E,
  3537. cruzeiro: 0x20A2,
  3538. cstretched: 0x0297,
  3539. curlyand: 0x22CF,
  3540. curlyor: 0x22CE,
  3541. currency: 0x00A4,
  3542. cyrBreve: 0xF6D1,
  3543. cyrFlex: 0xF6D2,
  3544. cyrbreve: 0xF6D4,
  3545. cyrflex: 0xF6D5,
  3546. d: 0x0064,
  3547. daarmenian: 0x0564,
  3548. dabengali: 0x09A6,
  3549. dadarabic: 0x0636,
  3550. dadeva: 0x0926,
  3551. dadfinalarabic: 0xFEBE,
  3552. dadinitialarabic: 0xFEBF,
  3553. dadmedialarabic: 0xFEC0,
  3554. dagesh: 0x05BC,
  3555. dageshhebrew: 0x05BC,
  3556. dagger: 0x2020,
  3557. daggerdbl: 0x2021,
  3558. dagujarati: 0x0AA6,
  3559. dagurmukhi: 0x0A26,
  3560. dahiragana: 0x3060,
  3561. dakatakana: 0x30C0,
  3562. dalarabic: 0x062F,
  3563. dalet: 0x05D3,
  3564. daletdagesh: 0xFB33,
  3565. daletdageshhebrew: 0xFB33,
  3566. dalethebrew: 0x05D3,
  3567. dalfinalarabic: 0xFEAA,
  3568. dammaarabic: 0x064F,
  3569. dammalowarabic: 0x064F,
  3570. dammatanaltonearabic: 0x064C,
  3571. dammatanarabic: 0x064C,
  3572. danda: 0x0964,
  3573. dargahebrew: 0x05A7,
  3574. dargalefthebrew: 0x05A7,
  3575. dasiapneumatacyrilliccmb: 0x0485,
  3576. dblGrave: 0xF6D3,
  3577. dblanglebracketleft: 0x300A,
  3578. dblanglebracketleftvertical: 0xFE3D,
  3579. dblanglebracketright: 0x300B,
  3580. dblanglebracketrightvertical: 0xFE3E,
  3581. dblarchinvertedbelowcmb: 0x032B,
  3582. dblarrowleft: 0x21D4,
  3583. dblarrowright: 0x21D2,
  3584. dbldanda: 0x0965,
  3585. dblgrave: 0xF6D6,
  3586. dblgravecmb: 0x030F,
  3587. dblintegral: 0x222C,
  3588. dbllowline: 0x2017,
  3589. dbllowlinecmb: 0x0333,
  3590. dbloverlinecmb: 0x033F,
  3591. dblprimemod: 0x02BA,
  3592. dblverticalbar: 0x2016,
  3593. dblverticallineabovecmb: 0x030E,
  3594. dbopomofo: 0x3109,
  3595. dbsquare: 0x33C8,
  3596. dcaron: 0x010F,
  3597. dcedilla: 0x1E11,
  3598. dcircle: 0x24D3,
  3599. dcircumflexbelow: 0x1E13,
  3600. dcroat: 0x0111,
  3601. ddabengali: 0x09A1,
  3602. ddadeva: 0x0921,
  3603. ddagujarati: 0x0AA1,
  3604. ddagurmukhi: 0x0A21,
  3605. ddalarabic: 0x0688,
  3606. ddalfinalarabic: 0xFB89,
  3607. dddhadeva: 0x095C,
  3608. ddhabengali: 0x09A2,
  3609. ddhadeva: 0x0922,
  3610. ddhagujarati: 0x0AA2,
  3611. ddhagurmukhi: 0x0A22,
  3612. ddotaccent: 0x1E0B,
  3613. ddotbelow: 0x1E0D,
  3614. decimalseparatorarabic: 0x066B,
  3615. decimalseparatorpersian: 0x066B,
  3616. decyrillic: 0x0434,
  3617. degree: 0x00B0,
  3618. dehihebrew: 0x05AD,
  3619. dehiragana: 0x3067,
  3620. deicoptic: 0x03EF,
  3621. dekatakana: 0x30C7,
  3622. deleteleft: 0x232B,
  3623. deleteright: 0x2326,
  3624. delta: 0x03B4,
  3625. deltaturned: 0x018D,
  3626. denominatorminusonenumeratorbengali: 0x09F8,
  3627. dezh: 0x02A4,
  3628. dhabengali: 0x09A7,
  3629. dhadeva: 0x0927,
  3630. dhagujarati: 0x0AA7,
  3631. dhagurmukhi: 0x0A27,
  3632. dhook: 0x0257,
  3633. dialytikatonos: 0x0385,
  3634. dialytikatonoscmb: 0x0344,
  3635. diamond: 0x2666,
  3636. diamondsuitwhite: 0x2662,
  3637. dieresis: 0x00A8,
  3638. dieresisacute: 0xF6D7,
  3639. dieresisbelowcmb: 0x0324,
  3640. dieresiscmb: 0x0308,
  3641. dieresisgrave: 0xF6D8,
  3642. dieresistonos: 0x0385,
  3643. dihiragana: 0x3062,
  3644. dikatakana: 0x30C2,
  3645. dittomark: 0x3003,
  3646. divide: 0x00F7,
  3647. divides: 0x2223,
  3648. divisionslash: 0x2215,
  3649. djecyrillic: 0x0452,
  3650. dkshade: 0x2593,
  3651. dlinebelow: 0x1E0F,
  3652. dlsquare: 0x3397,
  3653. dmacron: 0x0111,
  3654. dmonospace: 0xFF44,
  3655. dnblock: 0x2584,
  3656. dochadathai: 0x0E0E,
  3657. dodekthai: 0x0E14,
  3658. dohiragana: 0x3069,
  3659. dokatakana: 0x30C9,
  3660. dollar: 0x0024,
  3661. dollarinferior: 0xF6E3,
  3662. dollarmonospace: 0xFF04,
  3663. dollaroldstyle: 0xF724,
  3664. dollarsmall: 0xFE69,
  3665. dollarsuperior: 0xF6E4,
  3666. dong: 0x20AB,
  3667. dorusquare: 0x3326,
  3668. dotaccent: 0x02D9,
  3669. dotaccentcmb: 0x0307,
  3670. dotbelowcmb: 0x0323,
  3671. dotbelowcomb: 0x0323,
  3672. dotkatakana: 0x30FB,
  3673. dotlessi: 0x0131,
  3674. dotlessj: 0xF6BE,
  3675. dotlessjstrokehook: 0x0284,
  3676. dotmath: 0x22C5,
  3677. dottedcircle: 0x25CC,
  3678. doubleyodpatah: 0xFB1F,
  3679. doubleyodpatahhebrew: 0xFB1F,
  3680. downtackbelowcmb: 0x031E,
  3681. downtackmod: 0x02D5,
  3682. dparen: 0x249F,
  3683. dsuperior: 0xF6EB,
  3684. dtail: 0x0256,
  3685. dtopbar: 0x018C,
  3686. duhiragana: 0x3065,
  3687. dukatakana: 0x30C5,
  3688. dz: 0x01F3,
  3689. dzaltone: 0x02A3,
  3690. dzcaron: 0x01C6,
  3691. dzcurl: 0x02A5,
  3692. dzeabkhasiancyrillic: 0x04E1,
  3693. dzecyrillic: 0x0455,
  3694. dzhecyrillic: 0x045F,
  3695. e: 0x0065,
  3696. eacute: 0x00E9,
  3697. earth: 0x2641,
  3698. ebengali: 0x098F,
  3699. ebopomofo: 0x311C,
  3700. ebreve: 0x0115,
  3701. ecandradeva: 0x090D,
  3702. ecandragujarati: 0x0A8D,
  3703. ecandravowelsigndeva: 0x0945,
  3704. ecandravowelsigngujarati: 0x0AC5,
  3705. ecaron: 0x011B,
  3706. ecedillabreve: 0x1E1D,
  3707. echarmenian: 0x0565,
  3708. echyiwnarmenian: 0x0587,
  3709. ecircle: 0x24D4,
  3710. ecircumflex: 0x00EA,
  3711. ecircumflexacute: 0x1EBF,
  3712. ecircumflexbelow: 0x1E19,
  3713. ecircumflexdotbelow: 0x1EC7,
  3714. ecircumflexgrave: 0x1EC1,
  3715. ecircumflexhookabove: 0x1EC3,
  3716. ecircumflextilde: 0x1EC5,
  3717. ecyrillic: 0x0454,
  3718. edblgrave: 0x0205,
  3719. edeva: 0x090F,
  3720. edieresis: 0x00EB,
  3721. edot: 0x0117,
  3722. edotaccent: 0x0117,
  3723. edotbelow: 0x1EB9,
  3724. eegurmukhi: 0x0A0F,
  3725. eematragurmukhi: 0x0A47,
  3726. efcyrillic: 0x0444,
  3727. egrave: 0x00E8,
  3728. egujarati: 0x0A8F,
  3729. eharmenian: 0x0567,
  3730. ehbopomofo: 0x311D,
  3731. ehiragana: 0x3048,
  3732. ehookabove: 0x1EBB,
  3733. eibopomofo: 0x311F,
  3734. eight: 0x0038,
  3735. eightarabic: 0x0668,
  3736. eightbengali: 0x09EE,
  3737. eightcircle: 0x2467,
  3738. eightcircleinversesansserif: 0x2791,
  3739. eightdeva: 0x096E,
  3740. eighteencircle: 0x2471,
  3741. eighteenparen: 0x2485,
  3742. eighteenperiod: 0x2499,
  3743. eightgujarati: 0x0AEE,
  3744. eightgurmukhi: 0x0A6E,
  3745. eighthackarabic: 0x0668,
  3746. eighthangzhou: 0x3028,
  3747. eighthnotebeamed: 0x266B,
  3748. eightideographicparen: 0x3227,
  3749. eightinferior: 0x2088,
  3750. eightmonospace: 0xFF18,
  3751. eightoldstyle: 0xF738,
  3752. eightparen: 0x247B,
  3753. eightperiod: 0x248F,
  3754. eightpersian: 0x06F8,
  3755. eightroman: 0x2177,
  3756. eightsuperior: 0x2078,
  3757. eightthai: 0x0E58,
  3758. einvertedbreve: 0x0207,
  3759. eiotifiedcyrillic: 0x0465,
  3760. ekatakana: 0x30A8,
  3761. ekatakanahalfwidth: 0xFF74,
  3762. ekonkargurmukhi: 0x0A74,
  3763. ekorean: 0x3154,
  3764. elcyrillic: 0x043B,
  3765. element: 0x2208,
  3766. elevencircle: 0x246A,
  3767. elevenparen: 0x247E,
  3768. elevenperiod: 0x2492,
  3769. elevenroman: 0x217A,
  3770. ellipsis: 0x2026,
  3771. ellipsisvertical: 0x22EE,
  3772. emacron: 0x0113,
  3773. emacronacute: 0x1E17,
  3774. emacrongrave: 0x1E15,
  3775. emcyrillic: 0x043C,
  3776. emdash: 0x2014,
  3777. emdashvertical: 0xFE31,
  3778. emonospace: 0xFF45,
  3779. emphasismarkarmenian: 0x055B,
  3780. emptyset: 0x2205,
  3781. enbopomofo: 0x3123,
  3782. encyrillic: 0x043D,
  3783. endash: 0x2013,
  3784. endashvertical: 0xFE32,
  3785. endescendercyrillic: 0x04A3,
  3786. eng: 0x014B,
  3787. engbopomofo: 0x3125,
  3788. enghecyrillic: 0x04A5,
  3789. enhookcyrillic: 0x04C8,
  3790. enspace: 0x2002,
  3791. eogonek: 0x0119,
  3792. eokorean: 0x3153,
  3793. eopen: 0x025B,
  3794. eopenclosed: 0x029A,
  3795. eopenreversed: 0x025C,
  3796. eopenreversedclosed: 0x025E,
  3797. eopenreversedhook: 0x025D,
  3798. eparen: 0x24A0,
  3799. epsilon: 0x03B5,
  3800. epsilontonos: 0x03AD,
  3801. equal: 0x003D,
  3802. equalmonospace: 0xFF1D,
  3803. equalsmall: 0xFE66,
  3804. equalsuperior: 0x207C,
  3805. equivalence: 0x2261,
  3806. erbopomofo: 0x3126,
  3807. ercyrillic: 0x0440,
  3808. ereversed: 0x0258,
  3809. ereversedcyrillic: 0x044D,
  3810. escyrillic: 0x0441,
  3811. esdescendercyrillic: 0x04AB,
  3812. esh: 0x0283,
  3813. eshcurl: 0x0286,
  3814. eshortdeva: 0x090E,
  3815. eshortvowelsigndeva: 0x0946,
  3816. eshreversedloop: 0x01AA,
  3817. eshsquatreversed: 0x0285,
  3818. esmallhiragana: 0x3047,
  3819. esmallkatakana: 0x30A7,
  3820. esmallkatakanahalfwidth: 0xFF6A,
  3821. estimated: 0x212E,
  3822. esuperior: 0xF6EC,
  3823. eta: 0x03B7,
  3824. etarmenian: 0x0568,
  3825. etatonos: 0x03AE,
  3826. eth: 0x00F0,
  3827. etilde: 0x1EBD,
  3828. etildebelow: 0x1E1B,
  3829. etnahtafoukhhebrew: 0x0591,
  3830. etnahtafoukhlefthebrew: 0x0591,
  3831. etnahtahebrew: 0x0591,
  3832. etnahtalefthebrew: 0x0591,
  3833. eturned: 0x01DD,
  3834. eukorean: 0x3161,
  3835. euro: 0x20AC,
  3836. evowelsignbengali: 0x09C7,
  3837. evowelsigndeva: 0x0947,
  3838. evowelsigngujarati: 0x0AC7,
  3839. exclam: 0x0021,
  3840. exclamarmenian: 0x055C,
  3841. exclamdbl: 0x203C,
  3842. exclamdown: 0x00A1,
  3843. exclamdownsmall: 0xF7A1,
  3844. exclammonospace: 0xFF01,
  3845. exclamsmall: 0xF721,
  3846. existential: 0x2203,
  3847. ezh: 0x0292,
  3848. ezhcaron: 0x01EF,
  3849. ezhcurl: 0x0293,
  3850. ezhreversed: 0x01B9,
  3851. ezhtail: 0x01BA,
  3852. f: 0x0066,
  3853. fadeva: 0x095E,
  3854. fagurmukhi: 0x0A5E,
  3855. fahrenheit: 0x2109,
  3856. fathaarabic: 0x064E,
  3857. fathalowarabic: 0x064E,
  3858. fathatanarabic: 0x064B,
  3859. fbopomofo: 0x3108,
  3860. fcircle: 0x24D5,
  3861. fdotaccent: 0x1E1F,
  3862. feharabic: 0x0641,
  3863. feharmenian: 0x0586,
  3864. fehfinalarabic: 0xFED2,
  3865. fehinitialarabic: 0xFED3,
  3866. fehmedialarabic: 0xFED4,
  3867. feicoptic: 0x03E5,
  3868. female: 0x2640,
  3869. ff: 0xFB00,
  3870. ffi: 0xFB03,
  3871. ffl: 0xFB04,
  3872. fi: 0xFB01,
  3873. fifteencircle: 0x246E,
  3874. fifteenparen: 0x2482,
  3875. fifteenperiod: 0x2496,
  3876. figuredash: 0x2012,
  3877. filledbox: 0x25A0,
  3878. filledrect: 0x25AC,
  3879. finalkaf: 0x05DA,
  3880. finalkafdagesh: 0xFB3A,
  3881. finalkafdageshhebrew: 0xFB3A,
  3882. finalkafhebrew: 0x05DA,
  3883. finalmem: 0x05DD,
  3884. finalmemhebrew: 0x05DD,
  3885. finalnun: 0x05DF,
  3886. finalnunhebrew: 0x05DF,
  3887. finalpe: 0x05E3,
  3888. finalpehebrew: 0x05E3,
  3889. finaltsadi: 0x05E5,
  3890. finaltsadihebrew: 0x05E5,
  3891. firsttonechinese: 0x02C9,
  3892. fisheye: 0x25C9,
  3893. fitacyrillic: 0x0473,
  3894. five: 0x0035,
  3895. fivearabic: 0x0665,
  3896. fivebengali: 0x09EB,
  3897. fivecircle: 0x2464,
  3898. fivecircleinversesansserif: 0x278E,
  3899. fivedeva: 0x096B,
  3900. fiveeighths: 0x215D,
  3901. fivegujarati: 0x0AEB,
  3902. fivegurmukhi: 0x0A6B,
  3903. fivehackarabic: 0x0665,
  3904. fivehangzhou: 0x3025,
  3905. fiveideographicparen: 0x3224,
  3906. fiveinferior: 0x2085,
  3907. fivemonospace: 0xFF15,
  3908. fiveoldstyle: 0xF735,
  3909. fiveparen: 0x2478,
  3910. fiveperiod: 0x248C,
  3911. fivepersian: 0x06F5,
  3912. fiveroman: 0x2174,
  3913. fivesuperior: 0x2075,
  3914. fivethai: 0x0E55,
  3915. fl: 0xFB02,
  3916. florin: 0x0192,
  3917. fmonospace: 0xFF46,
  3918. fmsquare: 0x3399,
  3919. fofanthai: 0x0E1F,
  3920. fofathai: 0x0E1D,
  3921. fongmanthai: 0x0E4F,
  3922. forall: 0x2200,
  3923. four: 0x0034,
  3924. fourarabic: 0x0664,
  3925. fourbengali: 0x09EA,
  3926. fourcircle: 0x2463,
  3927. fourcircleinversesansserif: 0x278D,
  3928. fourdeva: 0x096A,
  3929. fourgujarati: 0x0AEA,
  3930. fourgurmukhi: 0x0A6A,
  3931. fourhackarabic: 0x0664,
  3932. fourhangzhou: 0x3024,
  3933. fourideographicparen: 0x3223,
  3934. fourinferior: 0x2084,
  3935. fourmonospace: 0xFF14,
  3936. fournumeratorbengali: 0x09F7,
  3937. fouroldstyle: 0xF734,
  3938. fourparen: 0x2477,
  3939. fourperiod: 0x248B,
  3940. fourpersian: 0x06F4,
  3941. fourroman: 0x2173,
  3942. foursuperior: 0x2074,
  3943. fourteencircle: 0x246D,
  3944. fourteenparen: 0x2481,
  3945. fourteenperiod: 0x2495,
  3946. fourthai: 0x0E54,
  3947. fourthtonechinese: 0x02CB,
  3948. fparen: 0x24A1,
  3949. fraction: 0x2044,
  3950. franc: 0x20A3,
  3951. g: 0x0067,
  3952. gabengali: 0x0997,
  3953. gacute: 0x01F5,
  3954. gadeva: 0x0917,
  3955. gafarabic: 0x06AF,
  3956. gaffinalarabic: 0xFB93,
  3957. gafinitialarabic: 0xFB94,
  3958. gafmedialarabic: 0xFB95,
  3959. gagujarati: 0x0A97,
  3960. gagurmukhi: 0x0A17,
  3961. gahiragana: 0x304C,
  3962. gakatakana: 0x30AC,
  3963. gamma: 0x03B3,
  3964. gammalatinsmall: 0x0263,
  3965. gammasuperior: 0x02E0,
  3966. gangiacoptic: 0x03EB,
  3967. gbopomofo: 0x310D,
  3968. gbreve: 0x011F,
  3969. gcaron: 0x01E7,
  3970. gcedilla: 0x0123,
  3971. gcircle: 0x24D6,
  3972. gcircumflex: 0x011D,
  3973. gcommaaccent: 0x0123,
  3974. gdot: 0x0121,
  3975. gdotaccent: 0x0121,
  3976. gecyrillic: 0x0433,
  3977. gehiragana: 0x3052,
  3978. gekatakana: 0x30B2,
  3979. geometricallyequal: 0x2251,
  3980. gereshaccenthebrew: 0x059C,
  3981. gereshhebrew: 0x05F3,
  3982. gereshmuqdamhebrew: 0x059D,
  3983. germandbls: 0x00DF,
  3984. gershayimaccenthebrew: 0x059E,
  3985. gershayimhebrew: 0x05F4,
  3986. getamark: 0x3013,
  3987. ghabengali: 0x0998,
  3988. ghadarmenian: 0x0572,
  3989. ghadeva: 0x0918,
  3990. ghagujarati: 0x0A98,
  3991. ghagurmukhi: 0x0A18,
  3992. ghainarabic: 0x063A,
  3993. ghainfinalarabic: 0xFECE,
  3994. ghaininitialarabic: 0xFECF,
  3995. ghainmedialarabic: 0xFED0,
  3996. ghemiddlehookcyrillic: 0x0495,
  3997. ghestrokecyrillic: 0x0493,
  3998. gheupturncyrillic: 0x0491,
  3999. ghhadeva: 0x095A,
  4000. ghhagurmukhi: 0x0A5A,
  4001. ghook: 0x0260,
  4002. ghzsquare: 0x3393,
  4003. gihiragana: 0x304E,
  4004. gikatakana: 0x30AE,
  4005. gimarmenian: 0x0563,
  4006. gimel: 0x05D2,
  4007. gimeldagesh: 0xFB32,
  4008. gimeldageshhebrew: 0xFB32,
  4009. gimelhebrew: 0x05D2,
  4010. gjecyrillic: 0x0453,
  4011. glottalinvertedstroke: 0x01BE,
  4012. glottalstop: 0x0294,
  4013. glottalstopinverted: 0x0296,
  4014. glottalstopmod: 0x02C0,
  4015. glottalstopreversed: 0x0295,
  4016. glottalstopreversedmod: 0x02C1,
  4017. glottalstopreversedsuperior: 0x02E4,
  4018. glottalstopstroke: 0x02A1,
  4019. glottalstopstrokereversed: 0x02A2,
  4020. gmacron: 0x1E21,
  4021. gmonospace: 0xFF47,
  4022. gohiragana: 0x3054,
  4023. gokatakana: 0x30B4,
  4024. gparen: 0x24A2,
  4025. gpasquare: 0x33AC,
  4026. gradient: 0x2207,
  4027. grave: 0x0060,
  4028. gravebelowcmb: 0x0316,
  4029. gravecmb: 0x0300,
  4030. gravecomb: 0x0300,
  4031. gravedeva: 0x0953,
  4032. gravelowmod: 0x02CE,
  4033. gravemonospace: 0xFF40,
  4034. gravetonecmb: 0x0340,
  4035. greater: 0x003E,
  4036. greaterequal: 0x2265,
  4037. greaterequalorless: 0x22DB,
  4038. greatermonospace: 0xFF1E,
  4039. greaterorequivalent: 0x2273,
  4040. greaterorless: 0x2277,
  4041. greateroverequal: 0x2267,
  4042. greatersmall: 0xFE65,
  4043. gscript: 0x0261,
  4044. gstroke: 0x01E5,
  4045. guhiragana: 0x3050,
  4046. guillemotleft: 0x00AB,
  4047. guillemotright: 0x00BB,
  4048. guilsinglleft: 0x2039,
  4049. guilsinglright: 0x203A,
  4050. gukatakana: 0x30B0,
  4051. guramusquare: 0x3318,
  4052. gysquare: 0x33C9,
  4053. h: 0x0068,
  4054. haabkhasiancyrillic: 0x04A9,
  4055. haaltonearabic: 0x06C1,
  4056. habengali: 0x09B9,
  4057. hadescendercyrillic: 0x04B3,
  4058. hadeva: 0x0939,
  4059. hagujarati: 0x0AB9,
  4060. hagurmukhi: 0x0A39,
  4061. haharabic: 0x062D,
  4062. hahfinalarabic: 0xFEA2,
  4063. hahinitialarabic: 0xFEA3,
  4064. hahiragana: 0x306F,
  4065. hahmedialarabic: 0xFEA4,
  4066. haitusquare: 0x332A,
  4067. hakatakana: 0x30CF,
  4068. hakatakanahalfwidth: 0xFF8A,
  4069. halantgurmukhi: 0x0A4D,
  4070. hamzaarabic: 0x0621,
  4071. hamzalowarabic: 0x0621,
  4072. hangulfiller: 0x3164,
  4073. hardsigncyrillic: 0x044A,
  4074. harpoonleftbarbup: 0x21BC,
  4075. harpoonrightbarbup: 0x21C0,
  4076. hasquare: 0x33CA,
  4077. hatafpatah: 0x05B2,
  4078. hatafpatah16: 0x05B2,
  4079. hatafpatah23: 0x05B2,
  4080. hatafpatah2f: 0x05B2,
  4081. hatafpatahhebrew: 0x05B2,
  4082. hatafpatahnarrowhebrew: 0x05B2,
  4083. hatafpatahquarterhebrew: 0x05B2,
  4084. hatafpatahwidehebrew: 0x05B2,
  4085. hatafqamats: 0x05B3,
  4086. hatafqamats1b: 0x05B3,
  4087. hatafqamats28: 0x05B3,
  4088. hatafqamats34: 0x05B3,
  4089. hatafqamatshebrew: 0x05B3,
  4090. hatafqamatsnarrowhebrew: 0x05B3,
  4091. hatafqamatsquarterhebrew: 0x05B3,
  4092. hatafqamatswidehebrew: 0x05B3,
  4093. hatafsegol: 0x05B1,
  4094. hatafsegol17: 0x05B1,
  4095. hatafsegol24: 0x05B1,
  4096. hatafsegol30: 0x05B1,
  4097. hatafsegolhebrew: 0x05B1,
  4098. hatafsegolnarrowhebrew: 0x05B1,
  4099. hatafsegolquarterhebrew: 0x05B1,
  4100. hatafsegolwidehebrew: 0x05B1,
  4101. hbar: 0x0127,
  4102. hbopomofo: 0x310F,
  4103. hbrevebelow: 0x1E2B,
  4104. hcedilla: 0x1E29,
  4105. hcircle: 0x24D7,
  4106. hcircumflex: 0x0125,
  4107. hdieresis: 0x1E27,
  4108. hdotaccent: 0x1E23,
  4109. hdotbelow: 0x1E25,
  4110. he: 0x05D4,
  4111. heart: 0x2665,
  4112. heartsuitblack: 0x2665,
  4113. heartsuitwhite: 0x2661,
  4114. hedagesh: 0xFB34,
  4115. hedageshhebrew: 0xFB34,
  4116. hehaltonearabic: 0x06C1,
  4117. heharabic: 0x0647,
  4118. hehebrew: 0x05D4,
  4119. hehfinalaltonearabic: 0xFBA7,
  4120. hehfinalalttwoarabic: 0xFEEA,
  4121. hehfinalarabic: 0xFEEA,
  4122. hehhamzaabovefinalarabic: 0xFBA5,
  4123. hehhamzaaboveisolatedarabic: 0xFBA4,
  4124. hehinitialaltonearabic: 0xFBA8,
  4125. hehinitialarabic: 0xFEEB,
  4126. hehiragana: 0x3078,
  4127. hehmedialaltonearabic: 0xFBA9,
  4128. hehmedialarabic: 0xFEEC,
  4129. heiseierasquare: 0x337B,
  4130. hekatakana: 0x30D8,
  4131. hekatakanahalfwidth: 0xFF8D,
  4132. hekutaarusquare: 0x3336,
  4133. henghook: 0x0267,
  4134. herutusquare: 0x3339,
  4135. het: 0x05D7,
  4136. hethebrew: 0x05D7,
  4137. hhook: 0x0266,
  4138. hhooksuperior: 0x02B1,
  4139. hieuhacirclekorean: 0x327B,
  4140. hieuhaparenkorean: 0x321B,
  4141. hieuhcirclekorean: 0x326D,
  4142. hieuhkorean: 0x314E,
  4143. hieuhparenkorean: 0x320D,
  4144. hihiragana: 0x3072,
  4145. hikatakana: 0x30D2,
  4146. hikatakanahalfwidth: 0xFF8B,
  4147. hiriq: 0x05B4,
  4148. hiriq14: 0x05B4,
  4149. hiriq21: 0x05B4,
  4150. hiriq2d: 0x05B4,
  4151. hiriqhebrew: 0x05B4,
  4152. hiriqnarrowhebrew: 0x05B4,
  4153. hiriqquarterhebrew: 0x05B4,
  4154. hiriqwidehebrew: 0x05B4,
  4155. hlinebelow: 0x1E96,
  4156. hmonospace: 0xFF48,
  4157. hoarmenian: 0x0570,
  4158. hohipthai: 0x0E2B,
  4159. hohiragana: 0x307B,
  4160. hokatakana: 0x30DB,
  4161. hokatakanahalfwidth: 0xFF8E,
  4162. holam: 0x05B9,
  4163. holam19: 0x05B9,
  4164. holam26: 0x05B9,
  4165. holam32: 0x05B9,
  4166. holamhebrew: 0x05B9,
  4167. holamnarrowhebrew: 0x05B9,
  4168. holamquarterhebrew: 0x05B9,
  4169. holamwidehebrew: 0x05B9,
  4170. honokhukthai: 0x0E2E,
  4171. hookabovecomb: 0x0309,
  4172. hookcmb: 0x0309,
  4173. hookpalatalizedbelowcmb: 0x0321,
  4174. hookretroflexbelowcmb: 0x0322,
  4175. hoonsquare: 0x3342,
  4176. horicoptic: 0x03E9,
  4177. horizontalbar: 0x2015,
  4178. horncmb: 0x031B,
  4179. hotsprings: 0x2668,
  4180. house: 0x2302,
  4181. hparen: 0x24A3,
  4182. hsuperior: 0x02B0,
  4183. hturned: 0x0265,
  4184. huhiragana: 0x3075,
  4185. huiitosquare: 0x3333,
  4186. hukatakana: 0x30D5,
  4187. hukatakanahalfwidth: 0xFF8C,
  4188. hungarumlaut: 0x02DD,
  4189. hungarumlautcmb: 0x030B,
  4190. hv: 0x0195,
  4191. hyphen: 0x002D,
  4192. hypheninferior: 0xF6E5,
  4193. hyphenmonospace: 0xFF0D,
  4194. hyphensmall: 0xFE63,
  4195. hyphensuperior: 0xF6E6,
  4196. hyphentwo: 0x2010,
  4197. i: 0x0069,
  4198. iacute: 0x00ED,
  4199. iacyrillic: 0x044F,
  4200. ibengali: 0x0987,
  4201. ibopomofo: 0x3127,
  4202. ibreve: 0x012D,
  4203. icaron: 0x01D0,
  4204. icircle: 0x24D8,
  4205. icircumflex: 0x00EE,
  4206. icyrillic: 0x0456,
  4207. idblgrave: 0x0209,
  4208. ideographearthcircle: 0x328F,
  4209. ideographfirecircle: 0x328B,
  4210. ideographicallianceparen: 0x323F,
  4211. ideographiccallparen: 0x323A,
  4212. ideographiccentrecircle: 0x32A5,
  4213. ideographicclose: 0x3006,
  4214. ideographiccomma: 0x3001,
  4215. ideographiccommaleft: 0xFF64,
  4216. ideographiccongratulationparen: 0x3237,
  4217. ideographiccorrectcircle: 0x32A3,
  4218. ideographicearthparen: 0x322F,
  4219. ideographicenterpriseparen: 0x323D,
  4220. ideographicexcellentcircle: 0x329D,
  4221. ideographicfestivalparen: 0x3240,
  4222. ideographicfinancialcircle: 0x3296,
  4223. ideographicfinancialparen: 0x3236,
  4224. ideographicfireparen: 0x322B,
  4225. ideographichaveparen: 0x3232,
  4226. ideographichighcircle: 0x32A4,
  4227. ideographiciterationmark: 0x3005,
  4228. ideographiclaborcircle: 0x3298,
  4229. ideographiclaborparen: 0x3238,
  4230. ideographicleftcircle: 0x32A7,
  4231. ideographiclowcircle: 0x32A6,
  4232. ideographicmedicinecircle: 0x32A9,
  4233. ideographicmetalparen: 0x322E,
  4234. ideographicmoonparen: 0x322A,
  4235. ideographicnameparen: 0x3234,
  4236. ideographicperiod: 0x3002,
  4237. ideographicprintcircle: 0x329E,
  4238. ideographicreachparen: 0x3243,
  4239. ideographicrepresentparen: 0x3239,
  4240. ideographicresourceparen: 0x323E,
  4241. ideographicrightcircle: 0x32A8,
  4242. ideographicsecretcircle: 0x3299,
  4243. ideographicselfparen: 0x3242,
  4244. ideographicsocietyparen: 0x3233,
  4245. ideographicspace: 0x3000,
  4246. ideographicspecialparen: 0x3235,
  4247. ideographicstockparen: 0x3231,
  4248. ideographicstudyparen: 0x323B,
  4249. ideographicsunparen: 0x3230,
  4250. ideographicsuperviseparen: 0x323C,
  4251. ideographicwaterparen: 0x322C,
  4252. ideographicwoodparen: 0x322D,
  4253. ideographiczero: 0x3007,
  4254. ideographmetalcircle: 0x328E,
  4255. ideographmooncircle: 0x328A,
  4256. ideographnamecircle: 0x3294,
  4257. ideographsuncircle: 0x3290,
  4258. ideographwatercircle: 0x328C,
  4259. ideographwoodcircle: 0x328D,
  4260. ideva: 0x0907,
  4261. idieresis: 0x00EF,
  4262. idieresisacute: 0x1E2F,
  4263. idieresiscyrillic: 0x04E5,
  4264. idotbelow: 0x1ECB,
  4265. iebrevecyrillic: 0x04D7,
  4266. iecyrillic: 0x0435,
  4267. ieungacirclekorean: 0x3275,
  4268. ieungaparenkorean: 0x3215,
  4269. ieungcirclekorean: 0x3267,
  4270. ieungkorean: 0x3147,
  4271. ieungparenkorean: 0x3207,
  4272. igrave: 0x00EC,
  4273. igujarati: 0x0A87,
  4274. igurmukhi: 0x0A07,
  4275. ihiragana: 0x3044,
  4276. ihookabove: 0x1EC9,
  4277. iibengali: 0x0988,
  4278. iicyrillic: 0x0438,
  4279. iideva: 0x0908,
  4280. iigujarati: 0x0A88,
  4281. iigurmukhi: 0x0A08,
  4282. iimatragurmukhi: 0x0A40,
  4283. iinvertedbreve: 0x020B,
  4284. iishortcyrillic: 0x0439,
  4285. iivowelsignbengali: 0x09C0,
  4286. iivowelsigndeva: 0x0940,
  4287. iivowelsigngujarati: 0x0AC0,
  4288. ij: 0x0133,
  4289. ikatakana: 0x30A4,
  4290. ikatakanahalfwidth: 0xFF72,
  4291. ikorean: 0x3163,
  4292. ilde: 0x02DC,
  4293. iluyhebrew: 0x05AC,
  4294. imacron: 0x012B,
  4295. imacroncyrillic: 0x04E3,
  4296. imageorapproximatelyequal: 0x2253,
  4297. imatragurmukhi: 0x0A3F,
  4298. imonospace: 0xFF49,
  4299. increment: 0x2206,
  4300. infinity: 0x221E,
  4301. iniarmenian: 0x056B,
  4302. integral: 0x222B,
  4303. integralbottom: 0x2321,
  4304. integralbt: 0x2321,
  4305. integralex: 0xF8F5,
  4306. integraltop: 0x2320,
  4307. integraltp: 0x2320,
  4308. intersection: 0x2229,
  4309. intisquare: 0x3305,
  4310. invbullet: 0x25D8,
  4311. invcircle: 0x25D9,
  4312. invsmileface: 0x263B,
  4313. iocyrillic: 0x0451,
  4314. iogonek: 0x012F,
  4315. iota: 0x03B9,
  4316. iotadieresis: 0x03CA,
  4317. iotadieresistonos: 0x0390,
  4318. iotalatin: 0x0269,
  4319. iotatonos: 0x03AF,
  4320. iparen: 0x24A4,
  4321. irigurmukhi: 0x0A72,
  4322. ismallhiragana: 0x3043,
  4323. ismallkatakana: 0x30A3,
  4324. ismallkatakanahalfwidth: 0xFF68,
  4325. issharbengali: 0x09FA,
  4326. istroke: 0x0268,
  4327. isuperior: 0xF6ED,
  4328. iterationhiragana: 0x309D,
  4329. iterationkatakana: 0x30FD,
  4330. itilde: 0x0129,
  4331. itildebelow: 0x1E2D,
  4332. iubopomofo: 0x3129,
  4333. iucyrillic: 0x044E,
  4334. ivowelsignbengali: 0x09BF,
  4335. ivowelsigndeva: 0x093F,
  4336. ivowelsigngujarati: 0x0ABF,
  4337. izhitsacyrillic: 0x0475,
  4338. izhitsadblgravecyrillic: 0x0477,
  4339. j: 0x006A,
  4340. jaarmenian: 0x0571,
  4341. jabengali: 0x099C,
  4342. jadeva: 0x091C,
  4343. jagujarati: 0x0A9C,
  4344. jagurmukhi: 0x0A1C,
  4345. jbopomofo: 0x3110,
  4346. jcaron: 0x01F0,
  4347. jcircle: 0x24D9,
  4348. jcircumflex: 0x0135,
  4349. jcrossedtail: 0x029D,
  4350. jdotlessstroke: 0x025F,
  4351. jecyrillic: 0x0458,
  4352. jeemarabic: 0x062C,
  4353. jeemfinalarabic: 0xFE9E,
  4354. jeeminitialarabic: 0xFE9F,
  4355. jeemmedialarabic: 0xFEA0,
  4356. jeharabic: 0x0698,
  4357. jehfinalarabic: 0xFB8B,
  4358. jhabengali: 0x099D,
  4359. jhadeva: 0x091D,
  4360. jhagujarati: 0x0A9D,
  4361. jhagurmukhi: 0x0A1D,
  4362. jheharmenian: 0x057B,
  4363. jis: 0x3004,
  4364. jmonospace: 0xFF4A,
  4365. jparen: 0x24A5,
  4366. jsuperior: 0x02B2,
  4367. k: 0x006B,
  4368. kabashkircyrillic: 0x04A1,
  4369. kabengali: 0x0995,
  4370. kacute: 0x1E31,
  4371. kacyrillic: 0x043A,
  4372. kadescendercyrillic: 0x049B,
  4373. kadeva: 0x0915,
  4374. kaf: 0x05DB,
  4375. kafarabic: 0x0643,
  4376. kafdagesh: 0xFB3B,
  4377. kafdageshhebrew: 0xFB3B,
  4378. kaffinalarabic: 0xFEDA,
  4379. kafhebrew: 0x05DB,
  4380. kafinitialarabic: 0xFEDB,
  4381. kafmedialarabic: 0xFEDC,
  4382. kafrafehebrew: 0xFB4D,
  4383. kagujarati: 0x0A95,
  4384. kagurmukhi: 0x0A15,
  4385. kahiragana: 0x304B,
  4386. kahookcyrillic: 0x04C4,
  4387. kakatakana: 0x30AB,
  4388. kakatakanahalfwidth: 0xFF76,
  4389. kappa: 0x03BA,
  4390. kappasymbolgreek: 0x03F0,
  4391. kapyeounmieumkorean: 0x3171,
  4392. kapyeounphieuphkorean: 0x3184,
  4393. kapyeounpieupkorean: 0x3178,
  4394. kapyeounssangpieupkorean: 0x3179,
  4395. karoriisquare: 0x330D,
  4396. kashidaautoarabic: 0x0640,
  4397. kashidaautonosidebearingarabic: 0x0640,
  4398. kasmallkatakana: 0x30F5,
  4399. kasquare: 0x3384,
  4400. kasraarabic: 0x0650,
  4401. kasratanarabic: 0x064D,
  4402. kastrokecyrillic: 0x049F,
  4403. katahiraprolongmarkhalfwidth: 0xFF70,
  4404. kaverticalstrokecyrillic: 0x049D,
  4405. kbopomofo: 0x310E,
  4406. kcalsquare: 0x3389,
  4407. kcaron: 0x01E9,
  4408. kcedilla: 0x0137,
  4409. kcircle: 0x24DA,
  4410. kcommaaccent: 0x0137,
  4411. kdotbelow: 0x1E33,
  4412. keharmenian: 0x0584,
  4413. kehiragana: 0x3051,
  4414. kekatakana: 0x30B1,
  4415. kekatakanahalfwidth: 0xFF79,
  4416. kenarmenian: 0x056F,
  4417. kesmallkatakana: 0x30F6,
  4418. kgreenlandic: 0x0138,
  4419. khabengali: 0x0996,
  4420. khacyrillic: 0x0445,
  4421. khadeva: 0x0916,
  4422. khagujarati: 0x0A96,
  4423. khagurmukhi: 0x0A16,
  4424. khaharabic: 0x062E,
  4425. khahfinalarabic: 0xFEA6,
  4426. khahinitialarabic: 0xFEA7,
  4427. khahmedialarabic: 0xFEA8,
  4428. kheicoptic: 0x03E7,
  4429. khhadeva: 0x0959,
  4430. khhagurmukhi: 0x0A59,
  4431. khieukhacirclekorean: 0x3278,
  4432. khieukhaparenkorean: 0x3218,
  4433. khieukhcirclekorean: 0x326A,
  4434. khieukhkorean: 0x314B,
  4435. khieukhparenkorean: 0x320A,
  4436. khokhaithai: 0x0E02,
  4437. khokhonthai: 0x0E05,
  4438. khokhuatthai: 0x0E03,
  4439. khokhwaithai: 0x0E04,
  4440. khomutthai: 0x0E5B,
  4441. khook: 0x0199,
  4442. khorakhangthai: 0x0E06,
  4443. khzsquare: 0x3391,
  4444. kihiragana: 0x304D,
  4445. kikatakana: 0x30AD,
  4446. kikatakanahalfwidth: 0xFF77,
  4447. kiroguramusquare: 0x3315,
  4448. kiromeetorusquare: 0x3316,
  4449. kirosquare: 0x3314,
  4450. kiyeokacirclekorean: 0x326E,
  4451. kiyeokaparenkorean: 0x320E,
  4452. kiyeokcirclekorean: 0x3260,
  4453. kiyeokkorean: 0x3131,
  4454. kiyeokparenkorean: 0x3200,
  4455. kiyeoksioskorean: 0x3133,
  4456. kjecyrillic: 0x045C,
  4457. klinebelow: 0x1E35,
  4458. klsquare: 0x3398,
  4459. kmcubedsquare: 0x33A6,
  4460. kmonospace: 0xFF4B,
  4461. kmsquaredsquare: 0x33A2,
  4462. kohiragana: 0x3053,
  4463. kohmsquare: 0x33C0,
  4464. kokaithai: 0x0E01,
  4465. kokatakana: 0x30B3,
  4466. kokatakanahalfwidth: 0xFF7A,
  4467. kooposquare: 0x331E,
  4468. koppacyrillic: 0x0481,
  4469. koreanstandardsymbol: 0x327F,
  4470. koroniscmb: 0x0343,
  4471. kparen: 0x24A6,
  4472. kpasquare: 0x33AA,
  4473. ksicyrillic: 0x046F,
  4474. ktsquare: 0x33CF,
  4475. kturned: 0x029E,
  4476. kuhiragana: 0x304F,
  4477. kukatakana: 0x30AF,
  4478. kukatakanahalfwidth: 0xFF78,
  4479. kvsquare: 0x33B8,
  4480. kwsquare: 0x33BE,
  4481. l: 0x006C,
  4482. labengali: 0x09B2,
  4483. lacute: 0x013A,
  4484. ladeva: 0x0932,
  4485. lagujarati: 0x0AB2,
  4486. lagurmukhi: 0x0A32,
  4487. lakkhangyaothai: 0x0E45,
  4488. lamaleffinalarabic: 0xFEFC,
  4489. lamalefhamzaabovefinalarabic: 0xFEF8,
  4490. lamalefhamzaaboveisolatedarabic: 0xFEF7,
  4491. lamalefhamzabelowfinalarabic: 0xFEFA,
  4492. lamalefhamzabelowisolatedarabic: 0xFEF9,
  4493. lamalefisolatedarabic: 0xFEFB,
  4494. lamalefmaddaabovefinalarabic: 0xFEF6,
  4495. lamalefmaddaaboveisolatedarabic: 0xFEF5,
  4496. lamarabic: 0x0644,
  4497. lambda: 0x03BB,
  4498. lambdastroke: 0x019B,
  4499. lamed: 0x05DC,
  4500. lameddagesh: 0xFB3C,
  4501. lameddageshhebrew: 0xFB3C,
  4502. lamedhebrew: 0x05DC,
  4503. lamfinalarabic: 0xFEDE,
  4504. lamhahinitialarabic: 0xFCCA,
  4505. laminitialarabic: 0xFEDF,
  4506. lamjeeminitialarabic: 0xFCC9,
  4507. lamkhahinitialarabic: 0xFCCB,
  4508. lamlamhehisolatedarabic: 0xFDF2,
  4509. lammedialarabic: 0xFEE0,
  4510. lammeemhahinitialarabic: 0xFD88,
  4511. lammeeminitialarabic: 0xFCCC,
  4512. largecircle: 0x25EF,
  4513. lbar: 0x019A,
  4514. lbelt: 0x026C,
  4515. lbopomofo: 0x310C,
  4516. lcaron: 0x013E,
  4517. lcedilla: 0x013C,
  4518. lcircle: 0x24DB,
  4519. lcircumflexbelow: 0x1E3D,
  4520. lcommaaccent: 0x013C,
  4521. ldot: 0x0140,
  4522. ldotaccent: 0x0140,
  4523. ldotbelow: 0x1E37,
  4524. ldotbelowmacron: 0x1E39,
  4525. leftangleabovecmb: 0x031A,
  4526. lefttackbelowcmb: 0x0318,
  4527. less: 0x003C,
  4528. lessequal: 0x2264,
  4529. lessequalorgreater: 0x22DA,
  4530. lessmonospace: 0xFF1C,
  4531. lessorequivalent: 0x2272,
  4532. lessorgreater: 0x2276,
  4533. lessoverequal: 0x2266,
  4534. lesssmall: 0xFE64,
  4535. lezh: 0x026E,
  4536. lfblock: 0x258C,
  4537. lhookretroflex: 0x026D,
  4538. lira: 0x20A4,
  4539. liwnarmenian: 0x056C,
  4540. lj: 0x01C9,
  4541. ljecyrillic: 0x0459,
  4542. ll: 0xF6C0,
  4543. lladeva: 0x0933,
  4544. llagujarati: 0x0AB3,
  4545. llinebelow: 0x1E3B,
  4546. llladeva: 0x0934,
  4547. llvocalicbengali: 0x09E1,
  4548. llvocalicdeva: 0x0961,
  4549. llvocalicvowelsignbengali: 0x09E3,
  4550. llvocalicvowelsigndeva: 0x0963,
  4551. lmiddletilde: 0x026B,
  4552. lmonospace: 0xFF4C,
  4553. lmsquare: 0x33D0,
  4554. lochulathai: 0x0E2C,
  4555. logicaland: 0x2227,
  4556. logicalnot: 0x00AC,
  4557. logicalnotreversed: 0x2310,
  4558. logicalor: 0x2228,
  4559. lolingthai: 0x0E25,
  4560. longs: 0x017F,
  4561. lowlinecenterline: 0xFE4E,
  4562. lowlinecmb: 0x0332,
  4563. lowlinedashed: 0xFE4D,
  4564. lozenge: 0x25CA,
  4565. lparen: 0x24A7,
  4566. lslash: 0x0142,
  4567. lsquare: 0x2113,
  4568. lsuperior: 0xF6EE,
  4569. ltshade: 0x2591,
  4570. luthai: 0x0E26,
  4571. lvocalicbengali: 0x098C,
  4572. lvocalicdeva: 0x090C,
  4573. lvocalicvowelsignbengali: 0x09E2,
  4574. lvocalicvowelsigndeva: 0x0962,
  4575. lxsquare: 0x33D3,
  4576. m: 0x006D,
  4577. mabengali: 0x09AE,
  4578. macron: 0x00AF,
  4579. macronbelowcmb: 0x0331,
  4580. macroncmb: 0x0304,
  4581. macronlowmod: 0x02CD,
  4582. macronmonospace: 0xFFE3,
  4583. macute: 0x1E3F,
  4584. madeva: 0x092E,
  4585. magujarati: 0x0AAE,
  4586. magurmukhi: 0x0A2E,
  4587. mahapakhhebrew: 0x05A4,
  4588. mahapakhlefthebrew: 0x05A4,
  4589. mahiragana: 0x307E,
  4590. maichattawalowleftthai: 0xF895,
  4591. maichattawalowrightthai: 0xF894,
  4592. maichattawathai: 0x0E4B,
  4593. maichattawaupperleftthai: 0xF893,
  4594. maieklowleftthai: 0xF88C,
  4595. maieklowrightthai: 0xF88B,
  4596. maiekthai: 0x0E48,
  4597. maiekupperleftthai: 0xF88A,
  4598. maihanakatleftthai: 0xF884,
  4599. maihanakatthai: 0x0E31,
  4600. maitaikhuleftthai: 0xF889,
  4601. maitaikhuthai: 0x0E47,
  4602. maitholowleftthai: 0xF88F,
  4603. maitholowrightthai: 0xF88E,
  4604. maithothai: 0x0E49,
  4605. maithoupperleftthai: 0xF88D,
  4606. maitrilowleftthai: 0xF892,
  4607. maitrilowrightthai: 0xF891,
  4608. maitrithai: 0x0E4A,
  4609. maitriupperleftthai: 0xF890,
  4610. maiyamokthai: 0x0E46,
  4611. makatakana: 0x30DE,
  4612. makatakanahalfwidth: 0xFF8F,
  4613. male: 0x2642,
  4614. mansyonsquare: 0x3347,
  4615. maqafhebrew: 0x05BE,
  4616. mars: 0x2642,
  4617. masoracirclehebrew: 0x05AF,
  4618. masquare: 0x3383,
  4619. mbopomofo: 0x3107,
  4620. mbsquare: 0x33D4,
  4621. mcircle: 0x24DC,
  4622. mcubedsquare: 0x33A5,
  4623. mdotaccent: 0x1E41,
  4624. mdotbelow: 0x1E43,
  4625. meemarabic: 0x0645,
  4626. meemfinalarabic: 0xFEE2,
  4627. meeminitialarabic: 0xFEE3,
  4628. meemmedialarabic: 0xFEE4,
  4629. meemmeeminitialarabic: 0xFCD1,
  4630. meemmeemisolatedarabic: 0xFC48,
  4631. meetorusquare: 0x334D,
  4632. mehiragana: 0x3081,
  4633. meizierasquare: 0x337E,
  4634. mekatakana: 0x30E1,
  4635. mekatakanahalfwidth: 0xFF92,
  4636. mem: 0x05DE,
  4637. memdagesh: 0xFB3E,
  4638. memdageshhebrew: 0xFB3E,
  4639. memhebrew: 0x05DE,
  4640. menarmenian: 0x0574,
  4641. merkhahebrew: 0x05A5,
  4642. merkhakefulahebrew: 0x05A6,
  4643. merkhakefulalefthebrew: 0x05A6,
  4644. merkhalefthebrew: 0x05A5,
  4645. mhook: 0x0271,
  4646. mhzsquare: 0x3392,
  4647. middledotkatakanahalfwidth: 0xFF65,
  4648. middot: 0x00B7,
  4649. mieumacirclekorean: 0x3272,
  4650. mieumaparenkorean: 0x3212,
  4651. mieumcirclekorean: 0x3264,
  4652. mieumkorean: 0x3141,
  4653. mieumpansioskorean: 0x3170,
  4654. mieumparenkorean: 0x3204,
  4655. mieumpieupkorean: 0x316E,
  4656. mieumsioskorean: 0x316F,
  4657. mihiragana: 0x307F,
  4658. mikatakana: 0x30DF,
  4659. mikatakanahalfwidth: 0xFF90,
  4660. minus: 0x2212,
  4661. minusbelowcmb: 0x0320,
  4662. minuscircle: 0x2296,
  4663. minusmod: 0x02D7,
  4664. minusplus: 0x2213,
  4665. minute: 0x2032,
  4666. miribaarusquare: 0x334A,
  4667. mirisquare: 0x3349,
  4668. mlonglegturned: 0x0270,
  4669. mlsquare: 0x3396,
  4670. mmcubedsquare: 0x33A3,
  4671. mmonospace: 0xFF4D,
  4672. mmsquaredsquare: 0x339F,
  4673. mohiragana: 0x3082,
  4674. mohmsquare: 0x33C1,
  4675. mokatakana: 0x30E2,
  4676. mokatakanahalfwidth: 0xFF93,
  4677. molsquare: 0x33D6,
  4678. momathai: 0x0E21,
  4679. moverssquare: 0x33A7,
  4680. moverssquaredsquare: 0x33A8,
  4681. mparen: 0x24A8,
  4682. mpasquare: 0x33AB,
  4683. mssquare: 0x33B3,
  4684. msuperior: 0xF6EF,
  4685. mturned: 0x026F,
  4686. mu: 0x00B5,
  4687. mu1: 0x00B5,
  4688. muasquare: 0x3382,
  4689. muchgreater: 0x226B,
  4690. muchless: 0x226A,
  4691. mufsquare: 0x338C,
  4692. mugreek: 0x03BC,
  4693. mugsquare: 0x338D,
  4694. muhiragana: 0x3080,
  4695. mukatakana: 0x30E0,
  4696. mukatakanahalfwidth: 0xFF91,
  4697. mulsquare: 0x3395,
  4698. multiply: 0x00D7,
  4699. mumsquare: 0x339B,
  4700. munahhebrew: 0x05A3,
  4701. munahlefthebrew: 0x05A3,
  4702. musicalnote: 0x266A,
  4703. musicalnotedbl: 0x266B,
  4704. musicflatsign: 0x266D,
  4705. musicsharpsign: 0x266F,
  4706. mussquare: 0x33B2,
  4707. muvsquare: 0x33B6,
  4708. muwsquare: 0x33BC,
  4709. mvmegasquare: 0x33B9,
  4710. mvsquare: 0x33B7,
  4711. mwmegasquare: 0x33BF,
  4712. mwsquare: 0x33BD,
  4713. n: 0x006E,
  4714. nabengali: 0x09A8,
  4715. nabla: 0x2207,
  4716. nacute: 0x0144,
  4717. nadeva: 0x0928,
  4718. nagujarati: 0x0AA8,
  4719. nagurmukhi: 0x0A28,
  4720. nahiragana: 0x306A,
  4721. nakatakana: 0x30CA,
  4722. nakatakanahalfwidth: 0xFF85,
  4723. napostrophe: 0x0149,
  4724. nasquare: 0x3381,
  4725. nbopomofo: 0x310B,
  4726. nbspace: 0x00A0,
  4727. ncaron: 0x0148,
  4728. ncedilla: 0x0146,
  4729. ncircle: 0x24DD,
  4730. ncircumflexbelow: 0x1E4B,
  4731. ncommaaccent: 0x0146,
  4732. ndotaccent: 0x1E45,
  4733. ndotbelow: 0x1E47,
  4734. nehiragana: 0x306D,
  4735. nekatakana: 0x30CD,
  4736. nekatakanahalfwidth: 0xFF88,
  4737. newsheqelsign: 0x20AA,
  4738. nfsquare: 0x338B,
  4739. ngabengali: 0x0999,
  4740. ngadeva: 0x0919,
  4741. ngagujarati: 0x0A99,
  4742. ngagurmukhi: 0x0A19,
  4743. ngonguthai: 0x0E07,
  4744. nhiragana: 0x3093,
  4745. nhookleft: 0x0272,
  4746. nhookretroflex: 0x0273,
  4747. nieunacirclekorean: 0x326F,
  4748. nieunaparenkorean: 0x320F,
  4749. nieuncieuckorean: 0x3135,
  4750. nieuncirclekorean: 0x3261,
  4751. nieunhieuhkorean: 0x3136,
  4752. nieunkorean: 0x3134,
  4753. nieunpansioskorean: 0x3168,
  4754. nieunparenkorean: 0x3201,
  4755. nieunsioskorean: 0x3167,
  4756. nieuntikeutkorean: 0x3166,
  4757. nihiragana: 0x306B,
  4758. nikatakana: 0x30CB,
  4759. nikatakanahalfwidth: 0xFF86,
  4760. nikhahitleftthai: 0xF899,
  4761. nikhahitthai: 0x0E4D,
  4762. nine: 0x0039,
  4763. ninearabic: 0x0669,
  4764. ninebengali: 0x09EF,
  4765. ninecircle: 0x2468,
  4766. ninecircleinversesansserif: 0x2792,
  4767. ninedeva: 0x096F,
  4768. ninegujarati: 0x0AEF,
  4769. ninegurmukhi: 0x0A6F,
  4770. ninehackarabic: 0x0669,
  4771. ninehangzhou: 0x3029,
  4772. nineideographicparen: 0x3228,
  4773. nineinferior: 0x2089,
  4774. ninemonospace: 0xFF19,
  4775. nineoldstyle: 0xF739,
  4776. nineparen: 0x247C,
  4777. nineperiod: 0x2490,
  4778. ninepersian: 0x06F9,
  4779. nineroman: 0x2178,
  4780. ninesuperior: 0x2079,
  4781. nineteencircle: 0x2472,
  4782. nineteenparen: 0x2486,
  4783. nineteenperiod: 0x249A,
  4784. ninethai: 0x0E59,
  4785. nj: 0x01CC,
  4786. njecyrillic: 0x045A,
  4787. nkatakana: 0x30F3,
  4788. nkatakanahalfwidth: 0xFF9D,
  4789. nlegrightlong: 0x019E,
  4790. nlinebelow: 0x1E49,
  4791. nmonospace: 0xFF4E,
  4792. nmsquare: 0x339A,
  4793. nnabengali: 0x09A3,
  4794. nnadeva: 0x0923,
  4795. nnagujarati: 0x0AA3,
  4796. nnagurmukhi: 0x0A23,
  4797. nnnadeva: 0x0929,
  4798. nohiragana: 0x306E,
  4799. nokatakana: 0x30CE,
  4800. nokatakanahalfwidth: 0xFF89,
  4801. nonbreakingspace: 0x00A0,
  4802. nonenthai: 0x0E13,
  4803. nonuthai: 0x0E19,
  4804. noonarabic: 0x0646,
  4805. noonfinalarabic: 0xFEE6,
  4806. noonghunnaarabic: 0x06BA,
  4807. noonghunnafinalarabic: 0xFB9F,
  4808. nooninitialarabic: 0xFEE7,
  4809. noonjeeminitialarabic: 0xFCD2,
  4810. noonjeemisolatedarabic: 0xFC4B,
  4811. noonmedialarabic: 0xFEE8,
  4812. noonmeeminitialarabic: 0xFCD5,
  4813. noonmeemisolatedarabic: 0xFC4E,
  4814. noonnoonfinalarabic: 0xFC8D,
  4815. notcontains: 0x220C,
  4816. notelement: 0x2209,
  4817. notelementof: 0x2209,
  4818. notequal: 0x2260,
  4819. notgreater: 0x226F,
  4820. notgreaternorequal: 0x2271,
  4821. notgreaternorless: 0x2279,
  4822. notidentical: 0x2262,
  4823. notless: 0x226E,
  4824. notlessnorequal: 0x2270,
  4825. notparallel: 0x2226,
  4826. notprecedes: 0x2280,
  4827. notsubset: 0x2284,
  4828. notsucceeds: 0x2281,
  4829. notsuperset: 0x2285,
  4830. nowarmenian: 0x0576,
  4831. nparen: 0x24A9,
  4832. nssquare: 0x33B1,
  4833. nsuperior: 0x207F,
  4834. ntilde: 0x00F1,
  4835. nu: 0x03BD,
  4836. nuhiragana: 0x306C,
  4837. nukatakana: 0x30CC,
  4838. nukatakanahalfwidth: 0xFF87,
  4839. nuktabengali: 0x09BC,
  4840. nuktadeva: 0x093C,
  4841. nuktagujarati: 0x0ABC,
  4842. nuktagurmukhi: 0x0A3C,
  4843. numbersign: 0x0023,
  4844. numbersignmonospace: 0xFF03,
  4845. numbersignsmall: 0xFE5F,
  4846. numeralsigngreek: 0x0374,
  4847. numeralsignlowergreek: 0x0375,
  4848. numero: 0x2116,
  4849. nun: 0x05E0,
  4850. nundagesh: 0xFB40,
  4851. nundageshhebrew: 0xFB40,
  4852. nunhebrew: 0x05E0,
  4853. nvsquare: 0x33B5,
  4854. nwsquare: 0x33BB,
  4855. nyabengali: 0x099E,
  4856. nyadeva: 0x091E,
  4857. nyagujarati: 0x0A9E,
  4858. nyagurmukhi: 0x0A1E,
  4859. o: 0x006F,
  4860. oacute: 0x00F3,
  4861. oangthai: 0x0E2D,
  4862. obarred: 0x0275,
  4863. obarredcyrillic: 0x04E9,
  4864. obarreddieresiscyrillic: 0x04EB,
  4865. obengali: 0x0993,
  4866. obopomofo: 0x311B,
  4867. obreve: 0x014F,
  4868. ocandradeva: 0x0911,
  4869. ocandragujarati: 0x0A91,
  4870. ocandravowelsigndeva: 0x0949,
  4871. ocandravowelsigngujarati: 0x0AC9,
  4872. ocaron: 0x01D2,
  4873. ocircle: 0x24DE,
  4874. ocircumflex: 0x00F4,
  4875. ocircumflexacute: 0x1ED1,
  4876. ocircumflexdotbelow: 0x1ED9,
  4877. ocircumflexgrave: 0x1ED3,
  4878. ocircumflexhookabove: 0x1ED5,
  4879. ocircumflextilde: 0x1ED7,
  4880. ocyrillic: 0x043E,
  4881. odblacute: 0x0151,
  4882. odblgrave: 0x020D,
  4883. odeva: 0x0913,
  4884. odieresis: 0x00F6,
  4885. odieresiscyrillic: 0x04E7,
  4886. odotbelow: 0x1ECD,
  4887. oe: 0x0153,
  4888. oekorean: 0x315A,
  4889. ogonek: 0x02DB,
  4890. ogonekcmb: 0x0328,
  4891. ograve: 0x00F2,
  4892. ogujarati: 0x0A93,
  4893. oharmenian: 0x0585,
  4894. ohiragana: 0x304A,
  4895. ohookabove: 0x1ECF,
  4896. ohorn: 0x01A1,
  4897. ohornacute: 0x1EDB,
  4898. ohorndotbelow: 0x1EE3,
  4899. ohorngrave: 0x1EDD,
  4900. ohornhookabove: 0x1EDF,
  4901. ohorntilde: 0x1EE1,
  4902. ohungarumlaut: 0x0151,
  4903. oi: 0x01A3,
  4904. oinvertedbreve: 0x020F,
  4905. okatakana: 0x30AA,
  4906. okatakanahalfwidth: 0xFF75,
  4907. okorean: 0x3157,
  4908. olehebrew: 0x05AB,
  4909. omacron: 0x014D,
  4910. omacronacute: 0x1E53,
  4911. omacrongrave: 0x1E51,
  4912. omdeva: 0x0950,
  4913. omega: 0x03C9,
  4914. omega1: 0x03D6,
  4915. omegacyrillic: 0x0461,
  4916. omegalatinclosed: 0x0277,
  4917. omegaroundcyrillic: 0x047B,
  4918. omegatitlocyrillic: 0x047D,
  4919. omegatonos: 0x03CE,
  4920. omgujarati: 0x0AD0,
  4921. omicron: 0x03BF,
  4922. omicrontonos: 0x03CC,
  4923. omonospace: 0xFF4F,
  4924. one: 0x0031,
  4925. onearabic: 0x0661,
  4926. onebengali: 0x09E7,
  4927. onecircle: 0x2460,
  4928. onecircleinversesansserif: 0x278A,
  4929. onedeva: 0x0967,
  4930. onedotenleader: 0x2024,
  4931. oneeighth: 0x215B,
  4932. onefitted: 0xF6DC,
  4933. onegujarati: 0x0AE7,
  4934. onegurmukhi: 0x0A67,
  4935. onehackarabic: 0x0661,
  4936. onehalf: 0x00BD,
  4937. onehangzhou: 0x3021,
  4938. oneideographicparen: 0x3220,
  4939. oneinferior: 0x2081,
  4940. onemonospace: 0xFF11,
  4941. onenumeratorbengali: 0x09F4,
  4942. oneoldstyle: 0xF731,
  4943. oneparen: 0x2474,
  4944. oneperiod: 0x2488,
  4945. onepersian: 0x06F1,
  4946. onequarter: 0x00BC,
  4947. oneroman: 0x2170,
  4948. onesuperior: 0x00B9,
  4949. onethai: 0x0E51,
  4950. onethird: 0x2153,
  4951. oogonek: 0x01EB,
  4952. oogonekmacron: 0x01ED,
  4953. oogurmukhi: 0x0A13,
  4954. oomatragurmukhi: 0x0A4B,
  4955. oopen: 0x0254,
  4956. oparen: 0x24AA,
  4957. openbullet: 0x25E6,
  4958. option: 0x2325,
  4959. ordfeminine: 0x00AA,
  4960. ordmasculine: 0x00BA,
  4961. orthogonal: 0x221F,
  4962. oshortdeva: 0x0912,
  4963. oshortvowelsigndeva: 0x094A,
  4964. oslash: 0x00F8,
  4965. oslashacute: 0x01FF,
  4966. osmallhiragana: 0x3049,
  4967. osmallkatakana: 0x30A9,
  4968. osmallkatakanahalfwidth: 0xFF6B,
  4969. ostrokeacute: 0x01FF,
  4970. osuperior: 0xF6F0,
  4971. otcyrillic: 0x047F,
  4972. otilde: 0x00F5,
  4973. otildeacute: 0x1E4D,
  4974. otildedieresis: 0x1E4F,
  4975. oubopomofo: 0x3121,
  4976. overline: 0x203E,
  4977. overlinecenterline: 0xFE4A,
  4978. overlinecmb: 0x0305,
  4979. overlinedashed: 0xFE49,
  4980. overlinedblwavy: 0xFE4C,
  4981. overlinewavy: 0xFE4B,
  4982. overscore: 0x00AF,
  4983. ovowelsignbengali: 0x09CB,
  4984. ovowelsigndeva: 0x094B,
  4985. ovowelsigngujarati: 0x0ACB,
  4986. p: 0x0070,
  4987. paampssquare: 0x3380,
  4988. paasentosquare: 0x332B,
  4989. pabengali: 0x09AA,
  4990. pacute: 0x1E55,
  4991. padeva: 0x092A,
  4992. pagedown: 0x21DF,
  4993. pageup: 0x21DE,
  4994. pagujarati: 0x0AAA,
  4995. pagurmukhi: 0x0A2A,
  4996. pahiragana: 0x3071,
  4997. paiyannoithai: 0x0E2F,
  4998. pakatakana: 0x30D1,
  4999. palatalizationcyrilliccmb: 0x0484,
  5000. palochkacyrillic: 0x04C0,
  5001. pansioskorean: 0x317F,
  5002. paragraph: 0x00B6,
  5003. parallel: 0x2225,
  5004. parenleft: 0x0028,
  5005. parenleftaltonearabic: 0xFD3E,
  5006. parenleftbt: 0xF8ED,
  5007. parenleftex: 0xF8EC,
  5008. parenleftinferior: 0x208D,
  5009. parenleftmonospace: 0xFF08,
  5010. parenleftsmall: 0xFE59,
  5011. parenleftsuperior: 0x207D,
  5012. parenlefttp: 0xF8EB,
  5013. parenleftvertical: 0xFE35,
  5014. parenright: 0x0029,
  5015. parenrightaltonearabic: 0xFD3F,
  5016. parenrightbt: 0xF8F8,
  5017. parenrightex: 0xF8F7,
  5018. parenrightinferior: 0x208E,
  5019. parenrightmonospace: 0xFF09,
  5020. parenrightsmall: 0xFE5A,
  5021. parenrightsuperior: 0x207E,
  5022. parenrighttp: 0xF8F6,
  5023. parenrightvertical: 0xFE36,
  5024. partialdiff: 0x2202,
  5025. paseqhebrew: 0x05C0,
  5026. pashtahebrew: 0x0599,
  5027. pasquare: 0x33A9,
  5028. patah: 0x05B7,
  5029. patah11: 0x05B7,
  5030. patah1d: 0x05B7,
  5031. patah2a: 0x05B7,
  5032. patahhebrew: 0x05B7,
  5033. patahnarrowhebrew: 0x05B7,
  5034. patahquarterhebrew: 0x05B7,
  5035. patahwidehebrew: 0x05B7,
  5036. pazerhebrew: 0x05A1,
  5037. pbopomofo: 0x3106,
  5038. pcircle: 0x24DF,
  5039. pdotaccent: 0x1E57,
  5040. pe: 0x05E4,
  5041. pecyrillic: 0x043F,
  5042. pedagesh: 0xFB44,
  5043. pedageshhebrew: 0xFB44,
  5044. peezisquare: 0x333B,
  5045. pefinaldageshhebrew: 0xFB43,
  5046. peharabic: 0x067E,
  5047. peharmenian: 0x057A,
  5048. pehebrew: 0x05E4,
  5049. pehfinalarabic: 0xFB57,
  5050. pehinitialarabic: 0xFB58,
  5051. pehiragana: 0x307A,
  5052. pehmedialarabic: 0xFB59,
  5053. pekatakana: 0x30DA,
  5054. pemiddlehookcyrillic: 0x04A7,
  5055. perafehebrew: 0xFB4E,
  5056. percent: 0x0025,
  5057. percentarabic: 0x066A,
  5058. percentmonospace: 0xFF05,
  5059. percentsmall: 0xFE6A,
  5060. period: 0x002E,
  5061. periodarmenian: 0x0589,
  5062. periodcentered: 0x00B7,
  5063. periodhalfwidth: 0xFF61,
  5064. periodinferior: 0xF6E7,
  5065. periodmonospace: 0xFF0E,
  5066. periodsmall: 0xFE52,
  5067. periodsuperior: 0xF6E8,
  5068. perispomenigreekcmb: 0x0342,
  5069. perpendicular: 0x22A5,
  5070. perthousand: 0x2030,
  5071. peseta: 0x20A7,
  5072. pfsquare: 0x338A,
  5073. phabengali: 0x09AB,
  5074. phadeva: 0x092B,
  5075. phagujarati: 0x0AAB,
  5076. phagurmukhi: 0x0A2B,
  5077. phi: 0x03C6,
  5078. phi1: 0x03D5,
  5079. phieuphacirclekorean: 0x327A,
  5080. phieuphaparenkorean: 0x321A,
  5081. phieuphcirclekorean: 0x326C,
  5082. phieuphkorean: 0x314D,
  5083. phieuphparenkorean: 0x320C,
  5084. philatin: 0x0278,
  5085. phinthuthai: 0x0E3A,
  5086. phisymbolgreek: 0x03D5,
  5087. phook: 0x01A5,
  5088. phophanthai: 0x0E1E,
  5089. phophungthai: 0x0E1C,
  5090. phosamphaothai: 0x0E20,
  5091. pi: 0x03C0,
  5092. pieupacirclekorean: 0x3273,
  5093. pieupaparenkorean: 0x3213,
  5094. pieupcieuckorean: 0x3176,
  5095. pieupcirclekorean: 0x3265,
  5096. pieupkiyeokkorean: 0x3172,
  5097. pieupkorean: 0x3142,
  5098. pieupparenkorean: 0x3205,
  5099. pieupsioskiyeokkorean: 0x3174,
  5100. pieupsioskorean: 0x3144,
  5101. pieupsiostikeutkorean: 0x3175,
  5102. pieupthieuthkorean: 0x3177,
  5103. pieuptikeutkorean: 0x3173,
  5104. pihiragana: 0x3074,
  5105. pikatakana: 0x30D4,
  5106. pisymbolgreek: 0x03D6,
  5107. piwrarmenian: 0x0583,
  5108. plus: 0x002B,
  5109. plusbelowcmb: 0x031F,
  5110. pluscircle: 0x2295,
  5111. plusminus: 0x00B1,
  5112. plusmod: 0x02D6,
  5113. plusmonospace: 0xFF0B,
  5114. plussmall: 0xFE62,
  5115. plussuperior: 0x207A,
  5116. pmonospace: 0xFF50,
  5117. pmsquare: 0x33D8,
  5118. pohiragana: 0x307D,
  5119. pointingindexdownwhite: 0x261F,
  5120. pointingindexleftwhite: 0x261C,
  5121. pointingindexrightwhite: 0x261E,
  5122. pointingindexupwhite: 0x261D,
  5123. pokatakana: 0x30DD,
  5124. poplathai: 0x0E1B,
  5125. postalmark: 0x3012,
  5126. postalmarkface: 0x3020,
  5127. pparen: 0x24AB,
  5128. precedes: 0x227A,
  5129. prescription: 0x211E,
  5130. primemod: 0x02B9,
  5131. primereversed: 0x2035,
  5132. product: 0x220F,
  5133. projective: 0x2305,
  5134. prolongedkana: 0x30FC,
  5135. propellor: 0x2318,
  5136. propersubset: 0x2282,
  5137. propersuperset: 0x2283,
  5138. proportion: 0x2237,
  5139. proportional: 0x221D,
  5140. psi: 0x03C8,
  5141. psicyrillic: 0x0471,
  5142. psilipneumatacyrilliccmb: 0x0486,
  5143. pssquare: 0x33B0,
  5144. puhiragana: 0x3077,
  5145. pukatakana: 0x30D7,
  5146. pvsquare: 0x33B4,
  5147. pwsquare: 0x33BA,
  5148. q: 0x0071,
  5149. qadeva: 0x0958,
  5150. qadmahebrew: 0x05A8,
  5151. qafarabic: 0x0642,
  5152. qaffinalarabic: 0xFED6,
  5153. qafinitialarabic: 0xFED7,
  5154. qafmedialarabic: 0xFED8,
  5155. qamats: 0x05B8,
  5156. qamats10: 0x05B8,
  5157. qamats1a: 0x05B8,
  5158. qamats1c: 0x05B8,
  5159. qamats27: 0x05B8,
  5160. qamats29: 0x05B8,
  5161. qamats33: 0x05B8,
  5162. qamatsde: 0x05B8,
  5163. qamatshebrew: 0x05B8,
  5164. qamatsnarrowhebrew: 0x05B8,
  5165. qamatsqatanhebrew: 0x05B8,
  5166. qamatsqatannarrowhebrew: 0x05B8,
  5167. qamatsqatanquarterhebrew: 0x05B8,
  5168. qamatsqatanwidehebrew: 0x05B8,
  5169. qamatsquarterhebrew: 0x05B8,
  5170. qamatswidehebrew: 0x05B8,
  5171. qarneyparahebrew: 0x059F,
  5172. qbopomofo: 0x3111,
  5173. qcircle: 0x24E0,
  5174. qhook: 0x02A0,
  5175. qmonospace: 0xFF51,
  5176. qof: 0x05E7,
  5177. qofdagesh: 0xFB47,
  5178. qofdageshhebrew: 0xFB47,
  5179. qofhebrew: 0x05E7,
  5180. qparen: 0x24AC,
  5181. quarternote: 0x2669,
  5182. qubuts: 0x05BB,
  5183. qubuts18: 0x05BB,
  5184. qubuts25: 0x05BB,
  5185. qubuts31: 0x05BB,
  5186. qubutshebrew: 0x05BB,
  5187. qubutsnarrowhebrew: 0x05BB,
  5188. qubutsquarterhebrew: 0x05BB,
  5189. qubutswidehebrew: 0x05BB,
  5190. question: 0x003F,
  5191. questionarabic: 0x061F,
  5192. questionarmenian: 0x055E,
  5193. questiondown: 0x00BF,
  5194. questiondownsmall: 0xF7BF,
  5195. questiongreek: 0x037E,
  5196. questionmonospace: 0xFF1F,
  5197. questionsmall: 0xF73F,
  5198. quotedbl: 0x0022,
  5199. quotedblbase: 0x201E,
  5200. quotedblleft: 0x201C,
  5201. quotedblmonospace: 0xFF02,
  5202. quotedblprime: 0x301E,
  5203. quotedblprimereversed: 0x301D,
  5204. quotedblright: 0x201D,
  5205. quoteleft: 0x2018,
  5206. quoteleftreversed: 0x201B,
  5207. quotereversed: 0x201B,
  5208. quoteright: 0x2019,
  5209. quoterightn: 0x0149,
  5210. quotesinglbase: 0x201A,
  5211. quotesingle: 0x0027,
  5212. quotesinglemonospace: 0xFF07,
  5213. r: 0x0072,
  5214. raarmenian: 0x057C,
  5215. rabengali: 0x09B0,
  5216. racute: 0x0155,
  5217. radeva: 0x0930,
  5218. radical: 0x221A,
  5219. radicalex: 0xF8E5,
  5220. radoverssquare: 0x33AE,
  5221. radoverssquaredsquare: 0x33AF,
  5222. radsquare: 0x33AD,
  5223. rafe: 0x05BF,
  5224. rafehebrew: 0x05BF,
  5225. ragujarati: 0x0AB0,
  5226. ragurmukhi: 0x0A30,
  5227. rahiragana: 0x3089,
  5228. rakatakana: 0x30E9,
  5229. rakatakanahalfwidth: 0xFF97,
  5230. ralowerdiagonalbengali: 0x09F1,
  5231. ramiddlediagonalbengali: 0x09F0,
  5232. ramshorn: 0x0264,
  5233. ratio: 0x2236,
  5234. rbopomofo: 0x3116,
  5235. rcaron: 0x0159,
  5236. rcedilla: 0x0157,
  5237. rcircle: 0x24E1,
  5238. rcommaaccent: 0x0157,
  5239. rdblgrave: 0x0211,
  5240. rdotaccent: 0x1E59,
  5241. rdotbelow: 0x1E5B,
  5242. rdotbelowmacron: 0x1E5D,
  5243. referencemark: 0x203B,
  5244. reflexsubset: 0x2286,
  5245. reflexsuperset: 0x2287,
  5246. registered: 0x00AE,
  5247. registersans: 0xF8E8,
  5248. registerserif: 0xF6DA,
  5249. reharabic: 0x0631,
  5250. reharmenian: 0x0580,
  5251. rehfinalarabic: 0xFEAE,
  5252. rehiragana: 0x308C,
  5253. rekatakana: 0x30EC,
  5254. rekatakanahalfwidth: 0xFF9A,
  5255. resh: 0x05E8,
  5256. reshdageshhebrew: 0xFB48,
  5257. reshhebrew: 0x05E8,
  5258. reversedtilde: 0x223D,
  5259. reviahebrew: 0x0597,
  5260. reviamugrashhebrew: 0x0597,
  5261. revlogicalnot: 0x2310,
  5262. rfishhook: 0x027E,
  5263. rfishhookreversed: 0x027F,
  5264. rhabengali: 0x09DD,
  5265. rhadeva: 0x095D,
  5266. rho: 0x03C1,
  5267. rhook: 0x027D,
  5268. rhookturned: 0x027B,
  5269. rhookturnedsuperior: 0x02B5,
  5270. rhosymbolgreek: 0x03F1,
  5271. rhotichookmod: 0x02DE,
  5272. rieulacirclekorean: 0x3271,
  5273. rieulaparenkorean: 0x3211,
  5274. rieulcirclekorean: 0x3263,
  5275. rieulhieuhkorean: 0x3140,
  5276. rieulkiyeokkorean: 0x313A,
  5277. rieulkiyeoksioskorean: 0x3169,
  5278. rieulkorean: 0x3139,
  5279. rieulmieumkorean: 0x313B,
  5280. rieulpansioskorean: 0x316C,
  5281. rieulparenkorean: 0x3203,
  5282. rieulphieuphkorean: 0x313F,
  5283. rieulpieupkorean: 0x313C,
  5284. rieulpieupsioskorean: 0x316B,
  5285. rieulsioskorean: 0x313D,
  5286. rieulthieuthkorean: 0x313E,
  5287. rieultikeutkorean: 0x316A,
  5288. rieulyeorinhieuhkorean: 0x316D,
  5289. rightangle: 0x221F,
  5290. righttackbelowcmb: 0x0319,
  5291. righttriangle: 0x22BF,
  5292. rihiragana: 0x308A,
  5293. rikatakana: 0x30EA,
  5294. rikatakanahalfwidth: 0xFF98,
  5295. ring: 0x02DA,
  5296. ringbelowcmb: 0x0325,
  5297. ringcmb: 0x030A,
  5298. ringhalfleft: 0x02BF,
  5299. ringhalfleftarmenian: 0x0559,
  5300. ringhalfleftbelowcmb: 0x031C,
  5301. ringhalfleftcentered: 0x02D3,
  5302. ringhalfright: 0x02BE,
  5303. ringhalfrightbelowcmb: 0x0339,
  5304. ringhalfrightcentered: 0x02D2,
  5305. rinvertedbreve: 0x0213,
  5306. rittorusquare: 0x3351,
  5307. rlinebelow: 0x1E5F,
  5308. rlongleg: 0x027C,
  5309. rlonglegturned: 0x027A,
  5310. rmonospace: 0xFF52,
  5311. rohiragana: 0x308D,
  5312. rokatakana: 0x30ED,
  5313. rokatakanahalfwidth: 0xFF9B,
  5314. roruathai: 0x0E23,
  5315. rparen: 0x24AD,
  5316. rrabengali: 0x09DC,
  5317. rradeva: 0x0931,
  5318. rragurmukhi: 0x0A5C,
  5319. rreharabic: 0x0691,
  5320. rrehfinalarabic: 0xFB8D,
  5321. rrvocalicbengali: 0x09E0,
  5322. rrvocalicdeva: 0x0960,
  5323. rrvocalicgujarati: 0x0AE0,
  5324. rrvocalicvowelsignbengali: 0x09C4,
  5325. rrvocalicvowelsigndeva: 0x0944,
  5326. rrvocalicvowelsigngujarati: 0x0AC4,
  5327. rsuperior: 0xF6F1,
  5328. rtblock: 0x2590,
  5329. rturned: 0x0279,
  5330. rturnedsuperior: 0x02B4,
  5331. ruhiragana: 0x308B,
  5332. rukatakana: 0x30EB,
  5333. rukatakanahalfwidth: 0xFF99,
  5334. rupeemarkbengali: 0x09F2,
  5335. rupeesignbengali: 0x09F3,
  5336. rupiah: 0xF6DD,
  5337. ruthai: 0x0E24,
  5338. rvocalicbengali: 0x098B,
  5339. rvocalicdeva: 0x090B,
  5340. rvocalicgujarati: 0x0A8B,
  5341. rvocalicvowelsignbengali: 0x09C3,
  5342. rvocalicvowelsigndeva: 0x0943,
  5343. rvocalicvowelsigngujarati: 0x0AC3,
  5344. s: 0x0073,
  5345. sabengali: 0x09B8,
  5346. sacute: 0x015B,
  5347. sacutedotaccent: 0x1E65,
  5348. sadarabic: 0x0635,
  5349. sadeva: 0x0938,
  5350. sadfinalarabic: 0xFEBA,
  5351. sadinitialarabic: 0xFEBB,
  5352. sadmedialarabic: 0xFEBC,
  5353. sagujarati: 0x0AB8,
  5354. sagurmukhi: 0x0A38,
  5355. sahiragana: 0x3055,
  5356. sakatakana: 0x30B5,
  5357. sakatakanahalfwidth: 0xFF7B,
  5358. sallallahoualayhewasallamarabic: 0xFDFA,
  5359. samekh: 0x05E1,
  5360. samekhdagesh: 0xFB41,
  5361. samekhdageshhebrew: 0xFB41,
  5362. samekhhebrew: 0x05E1,
  5363. saraaathai: 0x0E32,
  5364. saraaethai: 0x0E41,
  5365. saraaimaimalaithai: 0x0E44,
  5366. saraaimaimuanthai: 0x0E43,
  5367. saraamthai: 0x0E33,
  5368. saraathai: 0x0E30,
  5369. saraethai: 0x0E40,
  5370. saraiileftthai: 0xF886,
  5371. saraiithai: 0x0E35,
  5372. saraileftthai: 0xF885,
  5373. saraithai: 0x0E34,
  5374. saraothai: 0x0E42,
  5375. saraueeleftthai: 0xF888,
  5376. saraueethai: 0x0E37,
  5377. saraueleftthai: 0xF887,
  5378. sarauethai: 0x0E36,
  5379. sarauthai: 0x0E38,
  5380. sarauuthai: 0x0E39,
  5381. sbopomofo: 0x3119,
  5382. scaron: 0x0161,
  5383. scarondotaccent: 0x1E67,
  5384. scedilla: 0x015F,
  5385. schwa: 0x0259,
  5386. schwacyrillic: 0x04D9,
  5387. schwadieresiscyrillic: 0x04DB,
  5388. schwahook: 0x025A,
  5389. scircle: 0x24E2,
  5390. scircumflex: 0x015D,
  5391. scommaaccent: 0x0219,
  5392. sdotaccent: 0x1E61,
  5393. sdotbelow: 0x1E63,
  5394. sdotbelowdotaccent: 0x1E69,
  5395. seagullbelowcmb: 0x033C,
  5396. second: 0x2033,
  5397. secondtonechinese: 0x02CA,
  5398. section: 0x00A7,
  5399. seenarabic: 0x0633,
  5400. seenfinalarabic: 0xFEB2,
  5401. seeninitialarabic: 0xFEB3,
  5402. seenmedialarabic: 0xFEB4,
  5403. segol: 0x05B6,
  5404. segol13: 0x05B6,
  5405. segol1f: 0x05B6,
  5406. segol2c: 0x05B6,
  5407. segolhebrew: 0x05B6,
  5408. segolnarrowhebrew: 0x05B6,
  5409. segolquarterhebrew: 0x05B6,
  5410. segoltahebrew: 0x0592,
  5411. segolwidehebrew: 0x05B6,
  5412. seharmenian: 0x057D,
  5413. sehiragana: 0x305B,
  5414. sekatakana: 0x30BB,
  5415. sekatakanahalfwidth: 0xFF7E,
  5416. semicolon: 0x003B,
  5417. semicolonarabic: 0x061B,
  5418. semicolonmonospace: 0xFF1B,
  5419. semicolonsmall: 0xFE54,
  5420. semivoicedmarkkana: 0x309C,
  5421. semivoicedmarkkanahalfwidth: 0xFF9F,
  5422. sentisquare: 0x3322,
  5423. sentosquare: 0x3323,
  5424. seven: 0x0037,
  5425. sevenarabic: 0x0667,
  5426. sevenbengali: 0x09ED,
  5427. sevencircle: 0x2466,
  5428. sevencircleinversesansserif: 0x2790,
  5429. sevendeva: 0x096D,
  5430. seveneighths: 0x215E,
  5431. sevengujarati: 0x0AED,
  5432. sevengurmukhi: 0x0A6D,
  5433. sevenhackarabic: 0x0667,
  5434. sevenhangzhou: 0x3027,
  5435. sevenideographicparen: 0x3226,
  5436. seveninferior: 0x2087,
  5437. sevenmonospace: 0xFF17,
  5438. sevenoldstyle: 0xF737,
  5439. sevenparen: 0x247A,
  5440. sevenperiod: 0x248E,
  5441. sevenpersian: 0x06F7,
  5442. sevenroman: 0x2176,
  5443. sevensuperior: 0x2077,
  5444. seventeencircle: 0x2470,
  5445. seventeenparen: 0x2484,
  5446. seventeenperiod: 0x2498,
  5447. seventhai: 0x0E57,
  5448. sfthyphen: 0x00AD,
  5449. shaarmenian: 0x0577,
  5450. shabengali: 0x09B6,
  5451. shacyrillic: 0x0448,
  5452. shaddaarabic: 0x0651,
  5453. shaddadammaarabic: 0xFC61,
  5454. shaddadammatanarabic: 0xFC5E,
  5455. shaddafathaarabic: 0xFC60,
  5456. shaddakasraarabic: 0xFC62,
  5457. shaddakasratanarabic: 0xFC5F,
  5458. shade: 0x2592,
  5459. shadedark: 0x2593,
  5460. shadelight: 0x2591,
  5461. shademedium: 0x2592,
  5462. shadeva: 0x0936,
  5463. shagujarati: 0x0AB6,
  5464. shagurmukhi: 0x0A36,
  5465. shalshelethebrew: 0x0593,
  5466. shbopomofo: 0x3115,
  5467. shchacyrillic: 0x0449,
  5468. sheenarabic: 0x0634,
  5469. sheenfinalarabic: 0xFEB6,
  5470. sheeninitialarabic: 0xFEB7,
  5471. sheenmedialarabic: 0xFEB8,
  5472. sheicoptic: 0x03E3,
  5473. sheqel: 0x20AA,
  5474. sheqelhebrew: 0x20AA,
  5475. sheva: 0x05B0,
  5476. sheva115: 0x05B0,
  5477. sheva15: 0x05B0,
  5478. sheva22: 0x05B0,
  5479. sheva2e: 0x05B0,
  5480. shevahebrew: 0x05B0,
  5481. shevanarrowhebrew: 0x05B0,
  5482. shevaquarterhebrew: 0x05B0,
  5483. shevawidehebrew: 0x05B0,
  5484. shhacyrillic: 0x04BB,
  5485. shimacoptic: 0x03ED,
  5486. shin: 0x05E9,
  5487. shindagesh: 0xFB49,
  5488. shindageshhebrew: 0xFB49,
  5489. shindageshshindot: 0xFB2C,
  5490. shindageshshindothebrew: 0xFB2C,
  5491. shindageshsindot: 0xFB2D,
  5492. shindageshsindothebrew: 0xFB2D,
  5493. shindothebrew: 0x05C1,
  5494. shinhebrew: 0x05E9,
  5495. shinshindot: 0xFB2A,
  5496. shinshindothebrew: 0xFB2A,
  5497. shinsindot: 0xFB2B,
  5498. shinsindothebrew: 0xFB2B,
  5499. shook: 0x0282,
  5500. sigma: 0x03C3,
  5501. sigma1: 0x03C2,
  5502. sigmafinal: 0x03C2,
  5503. sigmalunatesymbolgreek: 0x03F2,
  5504. sihiragana: 0x3057,
  5505. sikatakana: 0x30B7,
  5506. sikatakanahalfwidth: 0xFF7C,
  5507. siluqhebrew: 0x05BD,
  5508. siluqlefthebrew: 0x05BD,
  5509. similar: 0x223C,
  5510. sindothebrew: 0x05C2,
  5511. siosacirclekorean: 0x3274,
  5512. siosaparenkorean: 0x3214,
  5513. sioscieuckorean: 0x317E,
  5514. sioscirclekorean: 0x3266,
  5515. sioskiyeokkorean: 0x317A,
  5516. sioskorean: 0x3145,
  5517. siosnieunkorean: 0x317B,
  5518. siosparenkorean: 0x3206,
  5519. siospieupkorean: 0x317D,
  5520. siostikeutkorean: 0x317C,
  5521. six: 0x0036,
  5522. sixarabic: 0x0666,
  5523. sixbengali: 0x09EC,
  5524. sixcircle: 0x2465,
  5525. sixcircleinversesansserif: 0x278F,
  5526. sixdeva: 0x096C,
  5527. sixgujarati: 0x0AEC,
  5528. sixgurmukhi: 0x0A6C,
  5529. sixhackarabic: 0x0666,
  5530. sixhangzhou: 0x3026,
  5531. sixideographicparen: 0x3225,
  5532. sixinferior: 0x2086,
  5533. sixmonospace: 0xFF16,
  5534. sixoldstyle: 0xF736,
  5535. sixparen: 0x2479,
  5536. sixperiod: 0x248D,
  5537. sixpersian: 0x06F6,
  5538. sixroman: 0x2175,
  5539. sixsuperior: 0x2076,
  5540. sixteencircle: 0x246F,
  5541. sixteencurrencydenominatorbengali: 0x09F9,
  5542. sixteenparen: 0x2483,
  5543. sixteenperiod: 0x2497,
  5544. sixthai: 0x0E56,
  5545. slash: 0x002F,
  5546. slashmonospace: 0xFF0F,
  5547. slong: 0x017F,
  5548. slongdotaccent: 0x1E9B,
  5549. smileface: 0x263A,
  5550. smonospace: 0xFF53,
  5551. sofpasuqhebrew: 0x05C3,
  5552. softhyphen: 0x00AD,
  5553. softsigncyrillic: 0x044C,
  5554. sohiragana: 0x305D,
  5555. sokatakana: 0x30BD,
  5556. sokatakanahalfwidth: 0xFF7F,
  5557. soliduslongoverlaycmb: 0x0338,
  5558. solidusshortoverlaycmb: 0x0337,
  5559. sorusithai: 0x0E29,
  5560. sosalathai: 0x0E28,
  5561. sosothai: 0x0E0B,
  5562. sosuathai: 0x0E2A,
  5563. space: 0x0020,
  5564. spacehackarabic: 0x0020,
  5565. spade: 0x2660,
  5566. spadesuitblack: 0x2660,
  5567. spadesuitwhite: 0x2664,
  5568. sparen: 0x24AE,
  5569. squarebelowcmb: 0x033B,
  5570. squarecc: 0x33C4,
  5571. squarecm: 0x339D,
  5572. squarediagonalcrosshatchfill: 0x25A9,
  5573. squarehorizontalfill: 0x25A4,
  5574. squarekg: 0x338F,
  5575. squarekm: 0x339E,
  5576. squarekmcapital: 0x33CE,
  5577. squareln: 0x33D1,
  5578. squarelog: 0x33D2,
  5579. squaremg: 0x338E,
  5580. squaremil: 0x33D5,
  5581. squaremm: 0x339C,
  5582. squaremsquared: 0x33A1,
  5583. squareorthogonalcrosshatchfill: 0x25A6,
  5584. squareupperlefttolowerrightfill: 0x25A7,
  5585. squareupperrighttolowerleftfill: 0x25A8,
  5586. squareverticalfill: 0x25A5,
  5587. squarewhitewithsmallblack: 0x25A3,
  5588. srsquare: 0x33DB,
  5589. ssabengali: 0x09B7,
  5590. ssadeva: 0x0937,
  5591. ssagujarati: 0x0AB7,
  5592. ssangcieuckorean: 0x3149,
  5593. ssanghieuhkorean: 0x3185,
  5594. ssangieungkorean: 0x3180,
  5595. ssangkiyeokkorean: 0x3132,
  5596. ssangnieunkorean: 0x3165,
  5597. ssangpieupkorean: 0x3143,
  5598. ssangsioskorean: 0x3146,
  5599. ssangtikeutkorean: 0x3138,
  5600. ssuperior: 0xF6F2,
  5601. sterling: 0x00A3,
  5602. sterlingmonospace: 0xFFE1,
  5603. strokelongoverlaycmb: 0x0336,
  5604. strokeshortoverlaycmb: 0x0335,
  5605. subset: 0x2282,
  5606. subsetnotequal: 0x228A,
  5607. subsetorequal: 0x2286,
  5608. succeeds: 0x227B,
  5609. suchthat: 0x220B,
  5610. suhiragana: 0x3059,
  5611. sukatakana: 0x30B9,
  5612. sukatakanahalfwidth: 0xFF7D,
  5613. sukunarabic: 0x0652,
  5614. summation: 0x2211,
  5615. sun: 0x263C,
  5616. superset: 0x2283,
  5617. supersetnotequal: 0x228B,
  5618. supersetorequal: 0x2287,
  5619. svsquare: 0x33DC,
  5620. syouwaerasquare: 0x337C,
  5621. t: 0x0074,
  5622. tabengali: 0x09A4,
  5623. tackdown: 0x22A4,
  5624. tackleft: 0x22A3,
  5625. tadeva: 0x0924,
  5626. tagujarati: 0x0AA4,
  5627. tagurmukhi: 0x0A24,
  5628. taharabic: 0x0637,
  5629. tahfinalarabic: 0xFEC2,
  5630. tahinitialarabic: 0xFEC3,
  5631. tahiragana: 0x305F,
  5632. tahmedialarabic: 0xFEC4,
  5633. taisyouerasquare: 0x337D,
  5634. takatakana: 0x30BF,
  5635. takatakanahalfwidth: 0xFF80,
  5636. tatweelarabic: 0x0640,
  5637. tau: 0x03C4,
  5638. tav: 0x05EA,
  5639. tavdages: 0xFB4A,
  5640. tavdagesh: 0xFB4A,
  5641. tavdageshhebrew: 0xFB4A,
  5642. tavhebrew: 0x05EA,
  5643. tbar: 0x0167,
  5644. tbopomofo: 0x310A,
  5645. tcaron: 0x0165,
  5646. tccurl: 0x02A8,
  5647. tcedilla: 0x0163,
  5648. tcheharabic: 0x0686,
  5649. tchehfinalarabic: 0xFB7B,
  5650. tchehinitialarabic: 0xFB7C,
  5651. tchehmedialarabic: 0xFB7D,
  5652. tcircle: 0x24E3,
  5653. tcircumflexbelow: 0x1E71,
  5654. tcommaaccent: 0x0163,
  5655. tdieresis: 0x1E97,
  5656. tdotaccent: 0x1E6B,
  5657. tdotbelow: 0x1E6D,
  5658. tecyrillic: 0x0442,
  5659. tedescendercyrillic: 0x04AD,
  5660. teharabic: 0x062A,
  5661. tehfinalarabic: 0xFE96,
  5662. tehhahinitialarabic: 0xFCA2,
  5663. tehhahisolatedarabic: 0xFC0C,
  5664. tehinitialarabic: 0xFE97,
  5665. tehiragana: 0x3066,
  5666. tehjeeminitialarabic: 0xFCA1,
  5667. tehjeemisolatedarabic: 0xFC0B,
  5668. tehmarbutaarabic: 0x0629,
  5669. tehmarbutafinalarabic: 0xFE94,
  5670. tehmedialarabic: 0xFE98,
  5671. tehmeeminitialarabic: 0xFCA4,
  5672. tehmeemisolatedarabic: 0xFC0E,
  5673. tehnoonfinalarabic: 0xFC73,
  5674. tekatakana: 0x30C6,
  5675. tekatakanahalfwidth: 0xFF83,
  5676. telephone: 0x2121,
  5677. telephoneblack: 0x260E,
  5678. telishagedolahebrew: 0x05A0,
  5679. telishaqetanahebrew: 0x05A9,
  5680. tencircle: 0x2469,
  5681. tenideographicparen: 0x3229,
  5682. tenparen: 0x247D,
  5683. tenperiod: 0x2491,
  5684. tenroman: 0x2179,
  5685. tesh: 0x02A7,
  5686. tet: 0x05D8,
  5687. tetdagesh: 0xFB38,
  5688. tetdageshhebrew: 0xFB38,
  5689. tethebrew: 0x05D8,
  5690. tetsecyrillic: 0x04B5,
  5691. tevirhebrew: 0x059B,
  5692. tevirlefthebrew: 0x059B,
  5693. thabengali: 0x09A5,
  5694. thadeva: 0x0925,
  5695. thagujarati: 0x0AA5,
  5696. thagurmukhi: 0x0A25,
  5697. thalarabic: 0x0630,
  5698. thalfinalarabic: 0xFEAC,
  5699. thanthakhatlowleftthai: 0xF898,
  5700. thanthakhatlowrightthai: 0xF897,
  5701. thanthakhatthai: 0x0E4C,
  5702. thanthakhatupperleftthai: 0xF896,
  5703. theharabic: 0x062B,
  5704. thehfinalarabic: 0xFE9A,
  5705. thehinitialarabic: 0xFE9B,
  5706. thehmedialarabic: 0xFE9C,
  5707. thereexists: 0x2203,
  5708. therefore: 0x2234,
  5709. theta: 0x03B8,
  5710. theta1: 0x03D1,
  5711. thetasymbolgreek: 0x03D1,
  5712. thieuthacirclekorean: 0x3279,
  5713. thieuthaparenkorean: 0x3219,
  5714. thieuthcirclekorean: 0x326B,
  5715. thieuthkorean: 0x314C,
  5716. thieuthparenkorean: 0x320B,
  5717. thirteencircle: 0x246C,
  5718. thirteenparen: 0x2480,
  5719. thirteenperiod: 0x2494,
  5720. thonangmonthothai: 0x0E11,
  5721. thook: 0x01AD,
  5722. thophuthaothai: 0x0E12,
  5723. thorn: 0x00FE,
  5724. thothahanthai: 0x0E17,
  5725. thothanthai: 0x0E10,
  5726. thothongthai: 0x0E18,
  5727. thothungthai: 0x0E16,
  5728. thousandcyrillic: 0x0482,
  5729. thousandsseparatorarabic: 0x066C,
  5730. thousandsseparatorpersian: 0x066C,
  5731. three: 0x0033,
  5732. threearabic: 0x0663,
  5733. threebengali: 0x09E9,
  5734. threecircle: 0x2462,
  5735. threecircleinversesansserif: 0x278C,
  5736. threedeva: 0x0969,
  5737. threeeighths: 0x215C,
  5738. threegujarati: 0x0AE9,
  5739. threegurmukhi: 0x0A69,
  5740. threehackarabic: 0x0663,
  5741. threehangzhou: 0x3023,
  5742. threeideographicparen: 0x3222,
  5743. threeinferior: 0x2083,
  5744. threemonospace: 0xFF13,
  5745. threenumeratorbengali: 0x09F6,
  5746. threeoldstyle: 0xF733,
  5747. threeparen: 0x2476,
  5748. threeperiod: 0x248A,
  5749. threepersian: 0x06F3,
  5750. threequarters: 0x00BE,
  5751. threequartersemdash: 0xF6DE,
  5752. threeroman: 0x2172,
  5753. threesuperior: 0x00B3,
  5754. threethai: 0x0E53,
  5755. thzsquare: 0x3394,
  5756. tihiragana: 0x3061,
  5757. tikatakana: 0x30C1,
  5758. tikatakanahalfwidth: 0xFF81,
  5759. tikeutacirclekorean: 0x3270,
  5760. tikeutaparenkorean: 0x3210,
  5761. tikeutcirclekorean: 0x3262,
  5762. tikeutkorean: 0x3137,
  5763. tikeutparenkorean: 0x3202,
  5764. tilde: 0x02DC,
  5765. tildebelowcmb: 0x0330,
  5766. tildecmb: 0x0303,
  5767. tildecomb: 0x0303,
  5768. tildedoublecmb: 0x0360,
  5769. tildeoperator: 0x223C,
  5770. tildeoverlaycmb: 0x0334,
  5771. tildeverticalcmb: 0x033E,
  5772. timescircle: 0x2297,
  5773. tipehahebrew: 0x0596,
  5774. tipehalefthebrew: 0x0596,
  5775. tippigurmukhi: 0x0A70,
  5776. titlocyrilliccmb: 0x0483,
  5777. tiwnarmenian: 0x057F,
  5778. tlinebelow: 0x1E6F,
  5779. tmonospace: 0xFF54,
  5780. toarmenian: 0x0569,
  5781. tohiragana: 0x3068,
  5782. tokatakana: 0x30C8,
  5783. tokatakanahalfwidth: 0xFF84,
  5784. tonebarextrahighmod: 0x02E5,
  5785. tonebarextralowmod: 0x02E9,
  5786. tonebarhighmod: 0x02E6,
  5787. tonebarlowmod: 0x02E8,
  5788. tonebarmidmod: 0x02E7,
  5789. tonefive: 0x01BD,
  5790. tonesix: 0x0185,
  5791. tonetwo: 0x01A8,
  5792. tonos: 0x0384,
  5793. tonsquare: 0x3327,
  5794. topatakthai: 0x0E0F,
  5795. tortoiseshellbracketleft: 0x3014,
  5796. tortoiseshellbracketleftsmall: 0xFE5D,
  5797. tortoiseshellbracketleftvertical: 0xFE39,
  5798. tortoiseshellbracketright: 0x3015,
  5799. tortoiseshellbracketrightsmall: 0xFE5E,
  5800. tortoiseshellbracketrightvertical: 0xFE3A,
  5801. totaothai: 0x0E15,
  5802. tpalatalhook: 0x01AB,
  5803. tparen: 0x24AF,
  5804. trademark: 0x2122,
  5805. trademarksans: 0xF8EA,
  5806. trademarkserif: 0xF6DB,
  5807. tretroflexhook: 0x0288,
  5808. triagdn: 0x25BC,
  5809. triaglf: 0x25C4,
  5810. triagrt: 0x25BA,
  5811. triagup: 0x25B2,
  5812. ts: 0x02A6,
  5813. tsadi: 0x05E6,
  5814. tsadidagesh: 0xFB46,
  5815. tsadidageshhebrew: 0xFB46,
  5816. tsadihebrew: 0x05E6,
  5817. tsecyrillic: 0x0446,
  5818. tsere: 0x05B5,
  5819. tsere12: 0x05B5,
  5820. tsere1e: 0x05B5,
  5821. tsere2b: 0x05B5,
  5822. tserehebrew: 0x05B5,
  5823. tserenarrowhebrew: 0x05B5,
  5824. tserequarterhebrew: 0x05B5,
  5825. tserewidehebrew: 0x05B5,
  5826. tshecyrillic: 0x045B,
  5827. tsuperior: 0xF6F3,
  5828. ttabengali: 0x099F,
  5829. ttadeva: 0x091F,
  5830. ttagujarati: 0x0A9F,
  5831. ttagurmukhi: 0x0A1F,
  5832. tteharabic: 0x0679,
  5833. ttehfinalarabic: 0xFB67,
  5834. ttehinitialarabic: 0xFB68,
  5835. ttehmedialarabic: 0xFB69,
  5836. tthabengali: 0x09A0,
  5837. tthadeva: 0x0920,
  5838. tthagujarati: 0x0AA0,
  5839. tthagurmukhi: 0x0A20,
  5840. tturned: 0x0287,
  5841. tuhiragana: 0x3064,
  5842. tukatakana: 0x30C4,
  5843. tukatakanahalfwidth: 0xFF82,
  5844. tusmallhiragana: 0x3063,
  5845. tusmallkatakana: 0x30C3,
  5846. tusmallkatakanahalfwidth: 0xFF6F,
  5847. twelvecircle: 0x246B,
  5848. twelveparen: 0x247F,
  5849. twelveperiod: 0x2493,
  5850. twelveroman: 0x217B,
  5851. twentycircle: 0x2473,
  5852. twentyhangzhou: 0x5344,
  5853. twentyparen: 0x2487,
  5854. twentyperiod: 0x249B,
  5855. two: 0x0032,
  5856. twoarabic: 0x0662,
  5857. twobengali: 0x09E8,
  5858. twocircle: 0x2461,
  5859. twocircleinversesansserif: 0x278B,
  5860. twodeva: 0x0968,
  5861. twodotenleader: 0x2025,
  5862. twodotleader: 0x2025,
  5863. twodotleadervertical: 0xFE30,
  5864. twogujarati: 0x0AE8,
  5865. twogurmukhi: 0x0A68,
  5866. twohackarabic: 0x0662,
  5867. twohangzhou: 0x3022,
  5868. twoideographicparen: 0x3221,
  5869. twoinferior: 0x2082,
  5870. twomonospace: 0xFF12,
  5871. twonumeratorbengali: 0x09F5,
  5872. twooldstyle: 0xF732,
  5873. twoparen: 0x2475,
  5874. twoperiod: 0x2489,
  5875. twopersian: 0x06F2,
  5876. tworoman: 0x2171,
  5877. twostroke: 0x01BB,
  5878. twosuperior: 0x00B2,
  5879. twothai: 0x0E52,
  5880. twothirds: 0x2154,
  5881. u: 0x0075,
  5882. uacute: 0x00FA,
  5883. ubar: 0x0289,
  5884. ubengali: 0x0989,
  5885. ubopomofo: 0x3128,
  5886. ubreve: 0x016D,
  5887. ucaron: 0x01D4,
  5888. ucircle: 0x24E4,
  5889. ucircumflex: 0x00FB,
  5890. ucircumflexbelow: 0x1E77,
  5891. ucyrillic: 0x0443,
  5892. udattadeva: 0x0951,
  5893. udblacute: 0x0171,
  5894. udblgrave: 0x0215,
  5895. udeva: 0x0909,
  5896. udieresis: 0x00FC,
  5897. udieresisacute: 0x01D8,
  5898. udieresisbelow: 0x1E73,
  5899. udieresiscaron: 0x01DA,
  5900. udieresiscyrillic: 0x04F1,
  5901. udieresisgrave: 0x01DC,
  5902. udieresismacron: 0x01D6,
  5903. udotbelow: 0x1EE5,
  5904. ugrave: 0x00F9,
  5905. ugujarati: 0x0A89,
  5906. ugurmukhi: 0x0A09,
  5907. uhiragana: 0x3046,
  5908. uhookabove: 0x1EE7,
  5909. uhorn: 0x01B0,
  5910. uhornacute: 0x1EE9,
  5911. uhorndotbelow: 0x1EF1,
  5912. uhorngrave: 0x1EEB,
  5913. uhornhookabove: 0x1EED,
  5914. uhorntilde: 0x1EEF,
  5915. uhungarumlaut: 0x0171,
  5916. uhungarumlautcyrillic: 0x04F3,
  5917. uinvertedbreve: 0x0217,
  5918. ukatakana: 0x30A6,
  5919. ukatakanahalfwidth: 0xFF73,
  5920. ukcyrillic: 0x0479,
  5921. ukorean: 0x315C,
  5922. umacron: 0x016B,
  5923. umacroncyrillic: 0x04EF,
  5924. umacrondieresis: 0x1E7B,
  5925. umatragurmukhi: 0x0A41,
  5926. umonospace: 0xFF55,
  5927. underscore: 0x005F,
  5928. underscoredbl: 0x2017,
  5929. underscoremonospace: 0xFF3F,
  5930. underscorevertical: 0xFE33,
  5931. underscorewavy: 0xFE4F,
  5932. union: 0x222A,
  5933. universal: 0x2200,
  5934. uogonek: 0x0173,
  5935. uparen: 0x24B0,
  5936. upblock: 0x2580,
  5937. upperdothebrew: 0x05C4,
  5938. upsilon: 0x03C5,
  5939. upsilondieresis: 0x03CB,
  5940. upsilondieresistonos: 0x03B0,
  5941. upsilonlatin: 0x028A,
  5942. upsilontonos: 0x03CD,
  5943. uptackbelowcmb: 0x031D,
  5944. uptackmod: 0x02D4,
  5945. uragurmukhi: 0x0A73,
  5946. uring: 0x016F,
  5947. ushortcyrillic: 0x045E,
  5948. usmallhiragana: 0x3045,
  5949. usmallkatakana: 0x30A5,
  5950. usmallkatakanahalfwidth: 0xFF69,
  5951. ustraightcyrillic: 0x04AF,
  5952. ustraightstrokecyrillic: 0x04B1,
  5953. utilde: 0x0169,
  5954. utildeacute: 0x1E79,
  5955. utildebelow: 0x1E75,
  5956. uubengali: 0x098A,
  5957. uudeva: 0x090A,
  5958. uugujarati: 0x0A8A,
  5959. uugurmukhi: 0x0A0A,
  5960. uumatragurmukhi: 0x0A42,
  5961. uuvowelsignbengali: 0x09C2,
  5962. uuvowelsigndeva: 0x0942,
  5963. uuvowelsigngujarati: 0x0AC2,
  5964. uvowelsignbengali: 0x09C1,
  5965. uvowelsigndeva: 0x0941,
  5966. uvowelsigngujarati: 0x0AC1,
  5967. v: 0x0076,
  5968. vadeva: 0x0935,
  5969. vagujarati: 0x0AB5,
  5970. vagurmukhi: 0x0A35,
  5971. vakatakana: 0x30F7,
  5972. vav: 0x05D5,
  5973. vavdagesh: 0xFB35,
  5974. vavdagesh65: 0xFB35,
  5975. vavdageshhebrew: 0xFB35,
  5976. vavhebrew: 0x05D5,
  5977. vavholam: 0xFB4B,
  5978. vavholamhebrew: 0xFB4B,
  5979. vavvavhebrew: 0x05F0,
  5980. vavyodhebrew: 0x05F1,
  5981. vcircle: 0x24E5,
  5982. vdotbelow: 0x1E7F,
  5983. vecyrillic: 0x0432,
  5984. veharabic: 0x06A4,
  5985. vehfinalarabic: 0xFB6B,
  5986. vehinitialarabic: 0xFB6C,
  5987. vehmedialarabic: 0xFB6D,
  5988. vekatakana: 0x30F9,
  5989. venus: 0x2640,
  5990. verticalbar: 0x007C,
  5991. verticallineabovecmb: 0x030D,
  5992. verticallinebelowcmb: 0x0329,
  5993. verticallinelowmod: 0x02CC,
  5994. verticallinemod: 0x02C8,
  5995. vewarmenian: 0x057E,
  5996. vhook: 0x028B,
  5997. vikatakana: 0x30F8,
  5998. viramabengali: 0x09CD,
  5999. viramadeva: 0x094D,
  6000. viramagujarati: 0x0ACD,
  6001. visargabengali: 0x0983,
  6002. visargadeva: 0x0903,
  6003. visargagujarati: 0x0A83,
  6004. vmonospace: 0xFF56,
  6005. voarmenian: 0x0578,
  6006. voicediterationhiragana: 0x309E,
  6007. voicediterationkatakana: 0x30FE,
  6008. voicedmarkkana: 0x309B,
  6009. voicedmarkkanahalfwidth: 0xFF9E,
  6010. vokatakana: 0x30FA,
  6011. vparen: 0x24B1,
  6012. vtilde: 0x1E7D,
  6013. vturned: 0x028C,
  6014. vuhiragana: 0x3094,
  6015. vukatakana: 0x30F4,
  6016. w: 0x0077,
  6017. wacute: 0x1E83,
  6018. waekorean: 0x3159,
  6019. wahiragana: 0x308F,
  6020. wakatakana: 0x30EF,
  6021. wakatakanahalfwidth: 0xFF9C,
  6022. wakorean: 0x3158,
  6023. wasmallhiragana: 0x308E,
  6024. wasmallkatakana: 0x30EE,
  6025. wattosquare: 0x3357,
  6026. wavedash: 0x301C,
  6027. wavyunderscorevertical: 0xFE34,
  6028. wawarabic: 0x0648,
  6029. wawfinalarabic: 0xFEEE,
  6030. wawhamzaabovearabic: 0x0624,
  6031. wawhamzaabovefinalarabic: 0xFE86,
  6032. wbsquare: 0x33DD,
  6033. wcircle: 0x24E6,
  6034. wcircumflex: 0x0175,
  6035. wdieresis: 0x1E85,
  6036. wdotaccent: 0x1E87,
  6037. wdotbelow: 0x1E89,
  6038. wehiragana: 0x3091,
  6039. weierstrass: 0x2118,
  6040. wekatakana: 0x30F1,
  6041. wekorean: 0x315E,
  6042. weokorean: 0x315D,
  6043. wgrave: 0x1E81,
  6044. whitebullet: 0x25E6,
  6045. whitecircle: 0x25CB,
  6046. whitecircleinverse: 0x25D9,
  6047. whitecornerbracketleft: 0x300E,
  6048. whitecornerbracketleftvertical: 0xFE43,
  6049. whitecornerbracketright: 0x300F,
  6050. whitecornerbracketrightvertical: 0xFE44,
  6051. whitediamond: 0x25C7,
  6052. whitediamondcontainingblacksmalldiamond: 0x25C8,
  6053. whitedownpointingsmalltriangle: 0x25BF,
  6054. whitedownpointingtriangle: 0x25BD,
  6055. whiteleftpointingsmalltriangle: 0x25C3,
  6056. whiteleftpointingtriangle: 0x25C1,
  6057. whitelenticularbracketleft: 0x3016,
  6058. whitelenticularbracketright: 0x3017,
  6059. whiterightpointingsmalltriangle: 0x25B9,
  6060. whiterightpointingtriangle: 0x25B7,
  6061. whitesmallsquare: 0x25AB,
  6062. whitesmilingface: 0x263A,
  6063. whitesquare: 0x25A1,
  6064. whitestar: 0x2606,
  6065. whitetelephone: 0x260F,
  6066. whitetortoiseshellbracketleft: 0x3018,
  6067. whitetortoiseshellbracketright: 0x3019,
  6068. whiteuppointingsmalltriangle: 0x25B5,
  6069. whiteuppointingtriangle: 0x25B3,
  6070. wihiragana: 0x3090,
  6071. wikatakana: 0x30F0,
  6072. wikorean: 0x315F,
  6073. wmonospace: 0xFF57,
  6074. wohiragana: 0x3092,
  6075. wokatakana: 0x30F2,
  6076. wokatakanahalfwidth: 0xFF66,
  6077. won: 0x20A9,
  6078. wonmonospace: 0xFFE6,
  6079. wowaenthai: 0x0E27,
  6080. wparen: 0x24B2,
  6081. wring: 0x1E98,
  6082. wsuperior: 0x02B7,
  6083. wturned: 0x028D,
  6084. wynn: 0x01BF,
  6085. x: 0x0078,
  6086. xabovecmb: 0x033D,
  6087. xbopomofo: 0x3112,
  6088. xcircle: 0x24E7,
  6089. xdieresis: 0x1E8D,
  6090. xdotaccent: 0x1E8B,
  6091. xeharmenian: 0x056D,
  6092. xi: 0x03BE,
  6093. xmonospace: 0xFF58,
  6094. xparen: 0x24B3,
  6095. xsuperior: 0x02E3,
  6096. y: 0x0079,
  6097. yaadosquare: 0x334E,
  6098. yabengali: 0x09AF,
  6099. yacute: 0x00FD,
  6100. yadeva: 0x092F,
  6101. yaekorean: 0x3152,
  6102. yagujarati: 0x0AAF,
  6103. yagurmukhi: 0x0A2F,
  6104. yahiragana: 0x3084,
  6105. yakatakana: 0x30E4,
  6106. yakatakanahalfwidth: 0xFF94,
  6107. yakorean: 0x3151,
  6108. yamakkanthai: 0x0E4E,
  6109. yasmallhiragana: 0x3083,
  6110. yasmallkatakana: 0x30E3,
  6111. yasmallkatakanahalfwidth: 0xFF6C,
  6112. yatcyrillic: 0x0463,
  6113. ycircle: 0x24E8,
  6114. ycircumflex: 0x0177,
  6115. ydieresis: 0x00FF,
  6116. ydotaccent: 0x1E8F,
  6117. ydotbelow: 0x1EF5,
  6118. yeharabic: 0x064A,
  6119. yehbarreearabic: 0x06D2,
  6120. yehbarreefinalarabic: 0xFBAF,
  6121. yehfinalarabic: 0xFEF2,
  6122. yehhamzaabovearabic: 0x0626,
  6123. yehhamzaabovefinalarabic: 0xFE8A,
  6124. yehhamzaaboveinitialarabic: 0xFE8B,
  6125. yehhamzaabovemedialarabic: 0xFE8C,
  6126. yehinitialarabic: 0xFEF3,
  6127. yehmedialarabic: 0xFEF4,
  6128. yehmeeminitialarabic: 0xFCDD,
  6129. yehmeemisolatedarabic: 0xFC58,
  6130. yehnoonfinalarabic: 0xFC94,
  6131. yehthreedotsbelowarabic: 0x06D1,
  6132. yekorean: 0x3156,
  6133. yen: 0x00A5,
  6134. yenmonospace: 0xFFE5,
  6135. yeokorean: 0x3155,
  6136. yeorinhieuhkorean: 0x3186,
  6137. yerahbenyomohebrew: 0x05AA,
  6138. yerahbenyomolefthebrew: 0x05AA,
  6139. yericyrillic: 0x044B,
  6140. yerudieresiscyrillic: 0x04F9,
  6141. yesieungkorean: 0x3181,
  6142. yesieungpansioskorean: 0x3183,
  6143. yesieungsioskorean: 0x3182,
  6144. yetivhebrew: 0x059A,
  6145. ygrave: 0x1EF3,
  6146. yhook: 0x01B4,
  6147. yhookabove: 0x1EF7,
  6148. yiarmenian: 0x0575,
  6149. yicyrillic: 0x0457,
  6150. yikorean: 0x3162,
  6151. yinyang: 0x262F,
  6152. yiwnarmenian: 0x0582,
  6153. ymonospace: 0xFF59,
  6154. yod: 0x05D9,
  6155. yoddagesh: 0xFB39,
  6156. yoddageshhebrew: 0xFB39,
  6157. yodhebrew: 0x05D9,
  6158. yodyodhebrew: 0x05F2,
  6159. yodyodpatahhebrew: 0xFB1F,
  6160. yohiragana: 0x3088,
  6161. yoikorean: 0x3189,
  6162. yokatakana: 0x30E8,
  6163. yokatakanahalfwidth: 0xFF96,
  6164. yokorean: 0x315B,
  6165. yosmallhiragana: 0x3087,
  6166. yosmallkatakana: 0x30E7,
  6167. yosmallkatakanahalfwidth: 0xFF6E,
  6168. yotgreek: 0x03F3,
  6169. yoyaekorean: 0x3188,
  6170. yoyakorean: 0x3187,
  6171. yoyakthai: 0x0E22,
  6172. yoyingthai: 0x0E0D,
  6173. yparen: 0x24B4,
  6174. ypogegrammeni: 0x037A,
  6175. ypogegrammenigreekcmb: 0x0345,
  6176. yr: 0x01A6,
  6177. yring: 0x1E99,
  6178. ysuperior: 0x02B8,
  6179. ytilde: 0x1EF9,
  6180. yturned: 0x028E,
  6181. yuhiragana: 0x3086,
  6182. yuikorean: 0x318C,
  6183. yukatakana: 0x30E6,
  6184. yukatakanahalfwidth: 0xFF95,
  6185. yukorean: 0x3160,
  6186. yusbigcyrillic: 0x046B,
  6187. yusbigiotifiedcyrillic: 0x046D,
  6188. yuslittlecyrillic: 0x0467,
  6189. yuslittleiotifiedcyrillic: 0x0469,
  6190. yusmallhiragana: 0x3085,
  6191. yusmallkatakana: 0x30E5,
  6192. yusmallkatakanahalfwidth: 0xFF6D,
  6193. yuyekorean: 0x318B,
  6194. yuyeokorean: 0x318A,
  6195. yyabengali: 0x09DF,
  6196. yyadeva: 0x095F,
  6197. z: 0x007A,
  6198. zaarmenian: 0x0566,
  6199. zacute: 0x017A,
  6200. zadeva: 0x095B,
  6201. zagurmukhi: 0x0A5B,
  6202. zaharabic: 0x0638,
  6203. zahfinalarabic: 0xFEC6,
  6204. zahinitialarabic: 0xFEC7,
  6205. zahiragana: 0x3056,
  6206. zahmedialarabic: 0xFEC8,
  6207. zainarabic: 0x0632,
  6208. zainfinalarabic: 0xFEB0,
  6209. zakatakana: 0x30B6,
  6210. zaqefgadolhebrew: 0x0595,
  6211. zaqefqatanhebrew: 0x0594,
  6212. zarqahebrew: 0x0598,
  6213. zayin: 0x05D6,
  6214. zayindagesh: 0xFB36,
  6215. zayindageshhebrew: 0xFB36,
  6216. zayinhebrew: 0x05D6,
  6217. zbopomofo: 0x3117,
  6218. zcaron: 0x017E,
  6219. zcircle: 0x24E9,
  6220. zcircumflex: 0x1E91,
  6221. zcurl: 0x0291,
  6222. zdot: 0x017C,
  6223. zdotaccent: 0x017C,
  6224. zdotbelow: 0x1E93,
  6225. zecyrillic: 0x0437,
  6226. zedescendercyrillic: 0x0499,
  6227. zedieresiscyrillic: 0x04DF,
  6228. zehiragana: 0x305C,
  6229. zekatakana: 0x30BC,
  6230. zero: 0x0030,
  6231. zeroarabic: 0x0660,
  6232. zerobengali: 0x09E6,
  6233. zerodeva: 0x0966,
  6234. zerogujarati: 0x0AE6,
  6235. zerogurmukhi: 0x0A66,
  6236. zerohackarabic: 0x0660,
  6237. zeroinferior: 0x2080,
  6238. zeromonospace: 0xFF10,
  6239. zerooldstyle: 0xF730,
  6240. zeropersian: 0x06F0,
  6241. zerosuperior: 0x2070,
  6242. zerothai: 0x0E50,
  6243. zerowidthjoiner: 0xFEFF,
  6244. zerowidthnonjoiner: 0x200C,
  6245. zerowidthspace: 0x200B,
  6246. zeta: 0x03B6,
  6247. zhbopomofo: 0x3113,
  6248. zhearmenian: 0x056A,
  6249. zhebrevecyrillic: 0x04C2,
  6250. zhecyrillic: 0x0436,
  6251. zhedescendercyrillic: 0x0497,
  6252. zhedieresiscyrillic: 0x04DD,
  6253. zihiragana: 0x3058,
  6254. zikatakana: 0x30B8,
  6255. zinorhebrew: 0x05AE,
  6256. zlinebelow: 0x1E95,
  6257. zmonospace: 0xFF5A,
  6258. zohiragana: 0x305E,
  6259. zokatakana: 0x30BE,
  6260. zparen: 0x24B5,
  6261. zretroflexhook: 0x0290,
  6262. zstroke: 0x01B6,
  6263. zuhiragana: 0x305A,
  6264. zukatakana: 0x30BA,
  6265. '.notdef': 0x0000
  6266. };
  6267. var DingbatsGlyphsUnicode = {
  6268. space: 0x0020,
  6269. a1: 0x2701,
  6270. a2: 0x2702,
  6271. a202: 0x2703,
  6272. a3: 0x2704,
  6273. a4: 0x260E,
  6274. a5: 0x2706,
  6275. a119: 0x2707,
  6276. a118: 0x2708,
  6277. a117: 0x2709,
  6278. a11: 0x261B,
  6279. a12: 0x261E,
  6280. a13: 0x270C,
  6281. a14: 0x270D,
  6282. a15: 0x270E,
  6283. a16: 0x270F,
  6284. a105: 0x2710,
  6285. a17: 0x2711,
  6286. a18: 0x2712,
  6287. a19: 0x2713,
  6288. a20: 0x2714,
  6289. a21: 0x2715,
  6290. a22: 0x2716,
  6291. a23: 0x2717,
  6292. a24: 0x2718,
  6293. a25: 0x2719,
  6294. a26: 0x271A,
  6295. a27: 0x271B,
  6296. a28: 0x271C,
  6297. a6: 0x271D,
  6298. a7: 0x271E,
  6299. a8: 0x271F,
  6300. a9: 0x2720,
  6301. a10: 0x2721,
  6302. a29: 0x2722,
  6303. a30: 0x2723,
  6304. a31: 0x2724,
  6305. a32: 0x2725,
  6306. a33: 0x2726,
  6307. a34: 0x2727,
  6308. a35: 0x2605,
  6309. a36: 0x2729,
  6310. a37: 0x272A,
  6311. a38: 0x272B,
  6312. a39: 0x272C,
  6313. a40: 0x272D,
  6314. a41: 0x272E,
  6315. a42: 0x272F,
  6316. a43: 0x2730,
  6317. a44: 0x2731,
  6318. a45: 0x2732,
  6319. a46: 0x2733,
  6320. a47: 0x2734,
  6321. a48: 0x2735,
  6322. a49: 0x2736,
  6323. a50: 0x2737,
  6324. a51: 0x2738,
  6325. a52: 0x2739,
  6326. a53: 0x273A,
  6327. a54: 0x273B,
  6328. a55: 0x273C,
  6329. a56: 0x273D,
  6330. a57: 0x273E,
  6331. a58: 0x273F,
  6332. a59: 0x2740,
  6333. a60: 0x2741,
  6334. a61: 0x2742,
  6335. a62: 0x2743,
  6336. a63: 0x2744,
  6337. a64: 0x2745,
  6338. a65: 0x2746,
  6339. a66: 0x2747,
  6340. a67: 0x2748,
  6341. a68: 0x2749,
  6342. a69: 0x274A,
  6343. a70: 0x274B,
  6344. a71: 0x25CF,
  6345. a72: 0x274D,
  6346. a73: 0x25A0,
  6347. a74: 0x274F,
  6348. a203: 0x2750,
  6349. a75: 0x2751,
  6350. a204: 0x2752,
  6351. a76: 0x25B2,
  6352. a77: 0x25BC,
  6353. a78: 0x25C6,
  6354. a79: 0x2756,
  6355. a81: 0x25D7,
  6356. a82: 0x2758,
  6357. a83: 0x2759,
  6358. a84: 0x275A,
  6359. a97: 0x275B,
  6360. a98: 0x275C,
  6361. a99: 0x275D,
  6362. a100: 0x275E,
  6363. a101: 0x2761,
  6364. a102: 0x2762,
  6365. a103: 0x2763,
  6366. a104: 0x2764,
  6367. a106: 0x2765,
  6368. a107: 0x2766,
  6369. a108: 0x2767,
  6370. a112: 0x2663,
  6371. a111: 0x2666,
  6372. a110: 0x2665,
  6373. a109: 0x2660,
  6374. a120: 0x2460,
  6375. a121: 0x2461,
  6376. a122: 0x2462,
  6377. a123: 0x2463,
  6378. a124: 0x2464,
  6379. a125: 0x2465,
  6380. a126: 0x2466,
  6381. a127: 0x2467,
  6382. a128: 0x2468,
  6383. a129: 0x2469,
  6384. a130: 0x2776,
  6385. a131: 0x2777,
  6386. a132: 0x2778,
  6387. a133: 0x2779,
  6388. a134: 0x277A,
  6389. a135: 0x277B,
  6390. a136: 0x277C,
  6391. a137: 0x277D,
  6392. a138: 0x277E,
  6393. a139: 0x277F,
  6394. a140: 0x2780,
  6395. a141: 0x2781,
  6396. a142: 0x2782,
  6397. a143: 0x2783,
  6398. a144: 0x2784,
  6399. a145: 0x2785,
  6400. a146: 0x2786,
  6401. a147: 0x2787,
  6402. a148: 0x2788,
  6403. a149: 0x2789,
  6404. a150: 0x278A,
  6405. a151: 0x278B,
  6406. a152: 0x278C,
  6407. a153: 0x278D,
  6408. a154: 0x278E,
  6409. a155: 0x278F,
  6410. a156: 0x2790,
  6411. a157: 0x2791,
  6412. a158: 0x2792,
  6413. a159: 0x2793,
  6414. a160: 0x2794,
  6415. a161: 0x2192,
  6416. a163: 0x2194,
  6417. a164: 0x2195,
  6418. a196: 0x2798,
  6419. a165: 0x2799,
  6420. a192: 0x279A,
  6421. a166: 0x279B,
  6422. a167: 0x279C,
  6423. a168: 0x279D,
  6424. a169: 0x279E,
  6425. a170: 0x279F,
  6426. a171: 0x27A0,
  6427. a172: 0x27A1,
  6428. a173: 0x27A2,
  6429. a162: 0x27A3,
  6430. a174: 0x27A4,
  6431. a175: 0x27A5,
  6432. a176: 0x27A6,
  6433. a177: 0x27A7,
  6434. a178: 0x27A8,
  6435. a179: 0x27A9,
  6436. a193: 0x27AA,
  6437. a180: 0x27AB,
  6438. a199: 0x27AC,
  6439. a181: 0x27AD,
  6440. a200: 0x27AE,
  6441. a182: 0x27AF,
  6442. a201: 0x27B1,
  6443. a183: 0x27B2,
  6444. a184: 0x27B3,
  6445. a197: 0x27B4,
  6446. a185: 0x27B5,
  6447. a194: 0x27B6,
  6448. a198: 0x27B7,
  6449. a186: 0x27B8,
  6450. a195: 0x27B9,
  6451. a187: 0x27BA,
  6452. a188: 0x27BB,
  6453. a189: 0x27BC,
  6454. a190: 0x27BD,
  6455. a191: 0x27BE,
  6456. a89: 0x2768, // 0xF8D7
  6457. a90: 0x2769, // 0xF8D8
  6458. a93: 0x276A, // 0xF8D9
  6459. a94: 0x276B, // 0xF8DA
  6460. a91: 0x276C, // 0xF8DB
  6461. a92: 0x276D, // 0xF8DC
  6462. a205: 0x276E, // 0xF8DD
  6463. a85: 0x276F, // 0xF8DE
  6464. a206: 0x2770, // 0xF8DF
  6465. a86: 0x2771, // 0xF8E0
  6466. a87: 0x2772, // 0xF8E1
  6467. a88: 0x2773, // 0xF8E2
  6468. a95: 0x2774, // 0xF8E3
  6469. a96: 0x2775, // 0xF8E4
  6470. '.notdef': 0x0000
  6471. };
  6472. exports.GlyphsUnicode = GlyphsUnicode;
  6473. exports.DingbatsGlyphsUnicode = DingbatsGlyphsUnicode;
  6474. }));
  6475. (function (root, factory) {
  6476. if (typeof define === 'function' && define.amd) {
  6477. define('pdfjs/core/jpg', ['exports'], factory);
  6478. } else if (typeof exports !== 'undefined') {
  6479. factory(exports);
  6480. } else {
  6481. factory((root.pdfjsCoreJpg = {}));
  6482. }
  6483. }(this, function (exports) {
  6484. /*
  6485. This code was forked from https://github.com/notmasteryet/jpgjs. The original
  6486. version was created by github user notmasteryet
  6487. - The JPEG specification can be found in the ITU CCITT Recommendation T.81
  6488. (www.w3.org/Graphics/JPEG/itu-t81.pdf)
  6489. - The JFIF specification can be found in the JPEG File Interchange Format
  6490. (www.w3.org/Graphics/JPEG/jfif3.pdf)
  6491. - The Adobe Application-Specific JPEG markers in the Supporting the DCT Filters
  6492. in PostScript Level 2, Technical Note #5116
  6493. (partners.adobe.com/public/developer/en/ps/sdk/5116.DCT_Filter.pdf)
  6494. */
  6495. var JpegImage = (function jpegImage() {
  6496. var dctZigZag = new Uint8Array([
  6497. 0,
  6498. 1, 8,
  6499. 16, 9, 2,
  6500. 3, 10, 17, 24,
  6501. 32, 25, 18, 11, 4,
  6502. 5, 12, 19, 26, 33, 40,
  6503. 48, 41, 34, 27, 20, 13, 6,
  6504. 7, 14, 21, 28, 35, 42, 49, 56,
  6505. 57, 50, 43, 36, 29, 22, 15,
  6506. 23, 30, 37, 44, 51, 58,
  6507. 59, 52, 45, 38, 31,
  6508. 39, 46, 53, 60,
  6509. 61, 54, 47,
  6510. 55, 62,
  6511. 63
  6512. ]);
  6513. var dctCos1 = 4017; // cos(pi/16)
  6514. var dctSin1 = 799; // sin(pi/16)
  6515. var dctCos3 = 3406; // cos(3*pi/16)
  6516. var dctSin3 = 2276; // sin(3*pi/16)
  6517. var dctCos6 = 1567; // cos(6*pi/16)
  6518. var dctSin6 = 3784; // sin(6*pi/16)
  6519. var dctSqrt2 = 5793; // sqrt(2)
  6520. var dctSqrt1d2 = 2896; // sqrt(2) / 2
  6521. function constructor() {
  6522. }
  6523. function buildHuffmanTable(codeLengths, values) {
  6524. var k = 0, code = [], i, j, length = 16;
  6525. while (length > 0 && !codeLengths[length - 1]) {
  6526. length--;
  6527. }
  6528. code.push({children: [], index: 0});
  6529. var p = code[0], q;
  6530. for (i = 0; i < length; i++) {
  6531. for (j = 0; j < codeLengths[i]; j++) {
  6532. p = code.pop();
  6533. p.children[p.index] = values[k];
  6534. while (p.index > 0) {
  6535. p = code.pop();
  6536. }
  6537. p.index++;
  6538. code.push(p);
  6539. while (code.length <= i) {
  6540. code.push(q = {children: [], index: 0});
  6541. p.children[p.index] = q.children;
  6542. p = q;
  6543. }
  6544. k++;
  6545. }
  6546. if (i + 1 < length) {
  6547. // p here points to last code
  6548. code.push(q = {children: [], index: 0});
  6549. p.children[p.index] = q.children;
  6550. p = q;
  6551. }
  6552. }
  6553. return code[0].children;
  6554. }
  6555. function getBlockBufferOffset(component, row, col) {
  6556. return 64 * ((component.blocksPerLine + 1) * row + col);
  6557. }
  6558. function decodeScan(data, offset, frame, components, resetInterval,
  6559. spectralStart, spectralEnd, successivePrev, successive) {
  6560. var precision = frame.precision;
  6561. var samplesPerLine = frame.samplesPerLine;
  6562. var scanLines = frame.scanLines;
  6563. var mcusPerLine = frame.mcusPerLine;
  6564. var progressive = frame.progressive;
  6565. var maxH = frame.maxH, maxV = frame.maxV;
  6566. var startOffset = offset, bitsData = 0, bitsCount = 0;
  6567. function readBit() {
  6568. if (bitsCount > 0) {
  6569. bitsCount--;
  6570. return (bitsData >> bitsCount) & 1;
  6571. }
  6572. bitsData = data[offset++];
  6573. if (bitsData === 0xFF) {
  6574. var nextByte = data[offset++];
  6575. if (nextByte) {
  6576. throw 'unexpected marker: ' +
  6577. ((bitsData << 8) | nextByte).toString(16);
  6578. }
  6579. // unstuff 0
  6580. }
  6581. bitsCount = 7;
  6582. return bitsData >>> 7;
  6583. }
  6584. function decodeHuffman(tree) {
  6585. var node = tree;
  6586. while (true) {
  6587. node = node[readBit()];
  6588. if (typeof node === 'number') {
  6589. return node;
  6590. }
  6591. if (typeof node !== 'object') {
  6592. throw 'invalid huffman sequence';
  6593. }
  6594. }
  6595. }
  6596. function receive(length) {
  6597. var n = 0;
  6598. while (length > 0) {
  6599. n = (n << 1) | readBit();
  6600. length--;
  6601. }
  6602. return n;
  6603. }
  6604. function receiveAndExtend(length) {
  6605. if (length === 1) {
  6606. return readBit() === 1 ? 1 : -1;
  6607. }
  6608. var n = receive(length);
  6609. if (n >= 1 << (length - 1)) {
  6610. return n;
  6611. }
  6612. return n + (-1 << length) + 1;
  6613. }
  6614. function decodeBaseline(component, offset) {
  6615. var t = decodeHuffman(component.huffmanTableDC);
  6616. var diff = t === 0 ? 0 : receiveAndExtend(t);
  6617. component.blockData[offset] = (component.pred += diff);
  6618. var k = 1;
  6619. while (k < 64) {
  6620. var rs = decodeHuffman(component.huffmanTableAC);
  6621. var s = rs & 15, r = rs >> 4;
  6622. if (s === 0) {
  6623. if (r < 15) {
  6624. break;
  6625. }
  6626. k += 16;
  6627. continue;
  6628. }
  6629. k += r;
  6630. var z = dctZigZag[k];
  6631. component.blockData[offset + z] = receiveAndExtend(s);
  6632. k++;
  6633. }
  6634. }
  6635. function decodeDCFirst(component, offset) {
  6636. var t = decodeHuffman(component.huffmanTableDC);
  6637. var diff = t === 0 ? 0 : (receiveAndExtend(t) << successive);
  6638. component.blockData[offset] = (component.pred += diff);
  6639. }
  6640. function decodeDCSuccessive(component, offset) {
  6641. component.blockData[offset] |= readBit() << successive;
  6642. }
  6643. var eobrun = 0;
  6644. function decodeACFirst(component, offset) {
  6645. if (eobrun > 0) {
  6646. eobrun--;
  6647. return;
  6648. }
  6649. var k = spectralStart, e = spectralEnd;
  6650. while (k <= e) {
  6651. var rs = decodeHuffman(component.huffmanTableAC);
  6652. var s = rs & 15, r = rs >> 4;
  6653. if (s === 0) {
  6654. if (r < 15) {
  6655. eobrun = receive(r) + (1 << r) - 1;
  6656. break;
  6657. }
  6658. k += 16;
  6659. continue;
  6660. }
  6661. k += r;
  6662. var z = dctZigZag[k];
  6663. component.blockData[offset + z] =
  6664. receiveAndExtend(s) * (1 << successive);
  6665. k++;
  6666. }
  6667. }
  6668. var successiveACState = 0, successiveACNextValue;
  6669. function decodeACSuccessive(component, offset) {
  6670. var k = spectralStart;
  6671. var e = spectralEnd;
  6672. var r = 0;
  6673. var s;
  6674. var rs;
  6675. while (k <= e) {
  6676. var z = dctZigZag[k];
  6677. switch (successiveACState) {
  6678. case 0: // initial state
  6679. rs = decodeHuffman(component.huffmanTableAC);
  6680. s = rs & 15;
  6681. r = rs >> 4;
  6682. if (s === 0) {
  6683. if (r < 15) {
  6684. eobrun = receive(r) + (1 << r);
  6685. successiveACState = 4;
  6686. } else {
  6687. r = 16;
  6688. successiveACState = 1;
  6689. }
  6690. } else {
  6691. if (s !== 1) {
  6692. throw 'invalid ACn encoding';
  6693. }
  6694. successiveACNextValue = receiveAndExtend(s);
  6695. successiveACState = r ? 2 : 3;
  6696. }
  6697. continue;
  6698. case 1: // skipping r zero items
  6699. case 2:
  6700. if (component.blockData[offset + z]) {
  6701. component.blockData[offset + z] += (readBit() << successive);
  6702. } else {
  6703. r--;
  6704. if (r === 0) {
  6705. successiveACState = successiveACState === 2 ? 3 : 0;
  6706. }
  6707. }
  6708. break;
  6709. case 3: // set value for a zero item
  6710. if (component.blockData[offset + z]) {
  6711. component.blockData[offset + z] += (readBit() << successive);
  6712. } else {
  6713. component.blockData[offset + z] =
  6714. successiveACNextValue << successive;
  6715. successiveACState = 0;
  6716. }
  6717. break;
  6718. case 4: // eob
  6719. if (component.blockData[offset + z]) {
  6720. component.blockData[offset + z] += (readBit() << successive);
  6721. }
  6722. break;
  6723. }
  6724. k++;
  6725. }
  6726. if (successiveACState === 4) {
  6727. eobrun--;
  6728. if (eobrun === 0) {
  6729. successiveACState = 0;
  6730. }
  6731. }
  6732. }
  6733. function decodeMcu(component, decode, mcu, row, col) {
  6734. var mcuRow = (mcu / mcusPerLine) | 0;
  6735. var mcuCol = mcu % mcusPerLine;
  6736. var blockRow = mcuRow * component.v + row;
  6737. var blockCol = mcuCol * component.h + col;
  6738. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  6739. decode(component, offset);
  6740. }
  6741. function decodeBlock(component, decode, mcu) {
  6742. var blockRow = (mcu / component.blocksPerLine) | 0;
  6743. var blockCol = mcu % component.blocksPerLine;
  6744. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  6745. decode(component, offset);
  6746. }
  6747. var componentsLength = components.length;
  6748. var component, i, j, k, n;
  6749. var decodeFn;
  6750. if (progressive) {
  6751. if (spectralStart === 0) {
  6752. decodeFn = successivePrev === 0 ? decodeDCFirst : decodeDCSuccessive;
  6753. } else {
  6754. decodeFn = successivePrev === 0 ? decodeACFirst : decodeACSuccessive;
  6755. }
  6756. } else {
  6757. decodeFn = decodeBaseline;
  6758. }
  6759. var mcu = 0, marker;
  6760. var mcuExpected;
  6761. if (componentsLength === 1) {
  6762. mcuExpected = components[0].blocksPerLine * components[0].blocksPerColumn;
  6763. } else {
  6764. mcuExpected = mcusPerLine * frame.mcusPerColumn;
  6765. }
  6766. if (!resetInterval) {
  6767. resetInterval = mcuExpected;
  6768. }
  6769. var h, v;
  6770. while (mcu < mcuExpected) {
  6771. // reset interval stuff
  6772. for (i = 0; i < componentsLength; i++) {
  6773. components[i].pred = 0;
  6774. }
  6775. eobrun = 0;
  6776. if (componentsLength === 1) {
  6777. component = components[0];
  6778. for (n = 0; n < resetInterval; n++) {
  6779. decodeBlock(component, decodeFn, mcu);
  6780. mcu++;
  6781. }
  6782. } else {
  6783. for (n = 0; n < resetInterval; n++) {
  6784. for (i = 0; i < componentsLength; i++) {
  6785. component = components[i];
  6786. h = component.h;
  6787. v = component.v;
  6788. for (j = 0; j < v; j++) {
  6789. for (k = 0; k < h; k++) {
  6790. decodeMcu(component, decodeFn, mcu, j, k);
  6791. }
  6792. }
  6793. }
  6794. mcu++;
  6795. }
  6796. }
  6797. // find marker
  6798. bitsCount = 0;
  6799. marker = (data[offset] << 8) | data[offset + 1];
  6800. if (marker <= 0xFF00) {
  6801. throw 'marker was not found';
  6802. }
  6803. if (marker >= 0xFFD0 && marker <= 0xFFD7) { // RSTx
  6804. offset += 2;
  6805. } else {
  6806. break;
  6807. }
  6808. }
  6809. return offset - startOffset;
  6810. }
  6811. // A port of poppler's IDCT method which in turn is taken from:
  6812. // Christoph Loeffler, Adriaan Ligtenberg, George S. Moschytz,
  6813. // 'Practical Fast 1-D DCT Algorithms with 11 Multiplications',
  6814. // IEEE Intl. Conf. on Acoustics, Speech & Signal Processing, 1989,
  6815. // 988-991.
  6816. function quantizeAndInverse(component, blockBufferOffset, p) {
  6817. var qt = component.quantizationTable, blockData = component.blockData;
  6818. var v0, v1, v2, v3, v4, v5, v6, v7;
  6819. var p0, p1, p2, p3, p4, p5, p6, p7;
  6820. var t;
  6821. // inverse DCT on rows
  6822. for (var row = 0; row < 64; row += 8) {
  6823. // gather block data
  6824. p0 = blockData[blockBufferOffset + row];
  6825. p1 = blockData[blockBufferOffset + row + 1];
  6826. p2 = blockData[blockBufferOffset + row + 2];
  6827. p3 = blockData[blockBufferOffset + row + 3];
  6828. p4 = blockData[blockBufferOffset + row + 4];
  6829. p5 = blockData[blockBufferOffset + row + 5];
  6830. p6 = blockData[blockBufferOffset + row + 6];
  6831. p7 = blockData[blockBufferOffset + row + 7];
  6832. // dequant p0
  6833. p0 *= qt[row];
  6834. // check for all-zero AC coefficients
  6835. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  6836. t = (dctSqrt2 * p0 + 512) >> 10;
  6837. p[row] = t;
  6838. p[row + 1] = t;
  6839. p[row + 2] = t;
  6840. p[row + 3] = t;
  6841. p[row + 4] = t;
  6842. p[row + 5] = t;
  6843. p[row + 6] = t;
  6844. p[row + 7] = t;
  6845. continue;
  6846. }
  6847. // dequant p1 ... p7
  6848. p1 *= qt[row + 1];
  6849. p2 *= qt[row + 2];
  6850. p3 *= qt[row + 3];
  6851. p4 *= qt[row + 4];
  6852. p5 *= qt[row + 5];
  6853. p6 *= qt[row + 6];
  6854. p7 *= qt[row + 7];
  6855. // stage 4
  6856. v0 = (dctSqrt2 * p0 + 128) >> 8;
  6857. v1 = (dctSqrt2 * p4 + 128) >> 8;
  6858. v2 = p2;
  6859. v3 = p6;
  6860. v4 = (dctSqrt1d2 * (p1 - p7) + 128) >> 8;
  6861. v7 = (dctSqrt1d2 * (p1 + p7) + 128) >> 8;
  6862. v5 = p3 << 4;
  6863. v6 = p5 << 4;
  6864. // stage 3
  6865. v0 = (v0 + v1 + 1) >> 1;
  6866. v1 = v0 - v1;
  6867. t = (v2 * dctSin6 + v3 * dctCos6 + 128) >> 8;
  6868. v2 = (v2 * dctCos6 - v3 * dctSin6 + 128) >> 8;
  6869. v3 = t;
  6870. v4 = (v4 + v6 + 1) >> 1;
  6871. v6 = v4 - v6;
  6872. v7 = (v7 + v5 + 1) >> 1;
  6873. v5 = v7 - v5;
  6874. // stage 2
  6875. v0 = (v0 + v3 + 1) >> 1;
  6876. v3 = v0 - v3;
  6877. v1 = (v1 + v2 + 1) >> 1;
  6878. v2 = v1 - v2;
  6879. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  6880. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  6881. v7 = t;
  6882. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  6883. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  6884. v6 = t;
  6885. // stage 1
  6886. p[row] = v0 + v7;
  6887. p[row + 7] = v0 - v7;
  6888. p[row + 1] = v1 + v6;
  6889. p[row + 6] = v1 - v6;
  6890. p[row + 2] = v2 + v5;
  6891. p[row + 5] = v2 - v5;
  6892. p[row + 3] = v3 + v4;
  6893. p[row + 4] = v3 - v4;
  6894. }
  6895. // inverse DCT on columns
  6896. for (var col = 0; col < 8; ++col) {
  6897. p0 = p[col];
  6898. p1 = p[col + 8];
  6899. p2 = p[col + 16];
  6900. p3 = p[col + 24];
  6901. p4 = p[col + 32];
  6902. p5 = p[col + 40];
  6903. p6 = p[col + 48];
  6904. p7 = p[col + 56];
  6905. // check for all-zero AC coefficients
  6906. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  6907. t = (dctSqrt2 * p0 + 8192) >> 14;
  6908. // convert to 8 bit
  6909. t = (t < -2040) ? 0 : (t >= 2024) ? 255 : (t + 2056) >> 4;
  6910. blockData[blockBufferOffset + col] = t;
  6911. blockData[blockBufferOffset + col + 8] = t;
  6912. blockData[blockBufferOffset + col + 16] = t;
  6913. blockData[blockBufferOffset + col + 24] = t;
  6914. blockData[blockBufferOffset + col + 32] = t;
  6915. blockData[blockBufferOffset + col + 40] = t;
  6916. blockData[blockBufferOffset + col + 48] = t;
  6917. blockData[blockBufferOffset + col + 56] = t;
  6918. continue;
  6919. }
  6920. // stage 4
  6921. v0 = (dctSqrt2 * p0 + 2048) >> 12;
  6922. v1 = (dctSqrt2 * p4 + 2048) >> 12;
  6923. v2 = p2;
  6924. v3 = p6;
  6925. v4 = (dctSqrt1d2 * (p1 - p7) + 2048) >> 12;
  6926. v7 = (dctSqrt1d2 * (p1 + p7) + 2048) >> 12;
  6927. v5 = p3;
  6928. v6 = p5;
  6929. // stage 3
  6930. // Shift v0 by 128.5 << 5 here, so we don't need to shift p0...p7 when
  6931. // converting to UInt8 range later.
  6932. v0 = ((v0 + v1 + 1) >> 1) + 4112;
  6933. v1 = v0 - v1;
  6934. t = (v2 * dctSin6 + v3 * dctCos6 + 2048) >> 12;
  6935. v2 = (v2 * dctCos6 - v3 * dctSin6 + 2048) >> 12;
  6936. v3 = t;
  6937. v4 = (v4 + v6 + 1) >> 1;
  6938. v6 = v4 - v6;
  6939. v7 = (v7 + v5 + 1) >> 1;
  6940. v5 = v7 - v5;
  6941. // stage 2
  6942. v0 = (v0 + v3 + 1) >> 1;
  6943. v3 = v0 - v3;
  6944. v1 = (v1 + v2 + 1) >> 1;
  6945. v2 = v1 - v2;
  6946. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  6947. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  6948. v7 = t;
  6949. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  6950. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  6951. v6 = t;
  6952. // stage 1
  6953. p0 = v0 + v7;
  6954. p7 = v0 - v7;
  6955. p1 = v1 + v6;
  6956. p6 = v1 - v6;
  6957. p2 = v2 + v5;
  6958. p5 = v2 - v5;
  6959. p3 = v3 + v4;
  6960. p4 = v3 - v4;
  6961. // convert to 8-bit integers
  6962. p0 = (p0 < 16) ? 0 : (p0 >= 4080) ? 255 : p0 >> 4;
  6963. p1 = (p1 < 16) ? 0 : (p1 >= 4080) ? 255 : p1 >> 4;
  6964. p2 = (p2 < 16) ? 0 : (p2 >= 4080) ? 255 : p2 >> 4;
  6965. p3 = (p3 < 16) ? 0 : (p3 >= 4080) ? 255 : p3 >> 4;
  6966. p4 = (p4 < 16) ? 0 : (p4 >= 4080) ? 255 : p4 >> 4;
  6967. p5 = (p5 < 16) ? 0 : (p5 >= 4080) ? 255 : p5 >> 4;
  6968. p6 = (p6 < 16) ? 0 : (p6 >= 4080) ? 255 : p6 >> 4;
  6969. p7 = (p7 < 16) ? 0 : (p7 >= 4080) ? 255 : p7 >> 4;
  6970. // store block data
  6971. blockData[blockBufferOffset + col] = p0;
  6972. blockData[blockBufferOffset + col + 8] = p1;
  6973. blockData[blockBufferOffset + col + 16] = p2;
  6974. blockData[blockBufferOffset + col + 24] = p3;
  6975. blockData[blockBufferOffset + col + 32] = p4;
  6976. blockData[blockBufferOffset + col + 40] = p5;
  6977. blockData[blockBufferOffset + col + 48] = p6;
  6978. blockData[blockBufferOffset + col + 56] = p7;
  6979. }
  6980. }
  6981. function buildComponentData(frame, component) {
  6982. var blocksPerLine = component.blocksPerLine;
  6983. var blocksPerColumn = component.blocksPerColumn;
  6984. var computationBuffer = new Int16Array(64);
  6985. for (var blockRow = 0; blockRow < blocksPerColumn; blockRow++) {
  6986. for (var blockCol = 0; blockCol < blocksPerLine; blockCol++) {
  6987. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  6988. quantizeAndInverse(component, offset, computationBuffer);
  6989. }
  6990. }
  6991. return component.blockData;
  6992. }
  6993. function clamp0to255(a) {
  6994. return a <= 0 ? 0 : a >= 255 ? 255 : a;
  6995. }
  6996. constructor.prototype = {
  6997. parse: function parse(data) {
  6998. function readUint16() {
  6999. var value = (data[offset] << 8) | data[offset + 1];
  7000. offset += 2;
  7001. return value;
  7002. }
  7003. function readDataBlock() {
  7004. var length = readUint16();
  7005. var array = data.subarray(offset, offset + length - 2);
  7006. offset += array.length;
  7007. return array;
  7008. }
  7009. function prepareComponents(frame) {
  7010. var mcusPerLine = Math.ceil(frame.samplesPerLine / 8 / frame.maxH);
  7011. var mcusPerColumn = Math.ceil(frame.scanLines / 8 / frame.maxV);
  7012. for (var i = 0; i < frame.components.length; i++) {
  7013. component = frame.components[i];
  7014. var blocksPerLine = Math.ceil(Math.ceil(frame.samplesPerLine / 8) *
  7015. component.h / frame.maxH);
  7016. var blocksPerColumn = Math.ceil(Math.ceil(frame.scanLines / 8) *
  7017. component.v / frame.maxV);
  7018. var blocksPerLineForMcu = mcusPerLine * component.h;
  7019. var blocksPerColumnForMcu = mcusPerColumn * component.v;
  7020. var blocksBufferSize = 64 * blocksPerColumnForMcu *
  7021. (blocksPerLineForMcu + 1);
  7022. component.blockData = new Int16Array(blocksBufferSize);
  7023. component.blocksPerLine = blocksPerLine;
  7024. component.blocksPerColumn = blocksPerColumn;
  7025. }
  7026. frame.mcusPerLine = mcusPerLine;
  7027. frame.mcusPerColumn = mcusPerColumn;
  7028. }
  7029. var offset = 0, length = data.length;
  7030. var jfif = null;
  7031. var adobe = null;
  7032. var pixels = null;
  7033. var frame, resetInterval;
  7034. var quantizationTables = [];
  7035. var huffmanTablesAC = [], huffmanTablesDC = [];
  7036. var fileMarker = readUint16();
  7037. if (fileMarker !== 0xFFD8) { // SOI (Start of Image)
  7038. throw 'SOI not found';
  7039. }
  7040. fileMarker = readUint16();
  7041. while (fileMarker !== 0xFFD9) { // EOI (End of image)
  7042. var i, j, l;
  7043. switch(fileMarker) {
  7044. case 0xFFE0: // APP0 (Application Specific)
  7045. case 0xFFE1: // APP1
  7046. case 0xFFE2: // APP2
  7047. case 0xFFE3: // APP3
  7048. case 0xFFE4: // APP4
  7049. case 0xFFE5: // APP5
  7050. case 0xFFE6: // APP6
  7051. case 0xFFE7: // APP7
  7052. case 0xFFE8: // APP8
  7053. case 0xFFE9: // APP9
  7054. case 0xFFEA: // APP10
  7055. case 0xFFEB: // APP11
  7056. case 0xFFEC: // APP12
  7057. case 0xFFED: // APP13
  7058. case 0xFFEE: // APP14
  7059. case 0xFFEF: // APP15
  7060. case 0xFFFE: // COM (Comment)
  7061. var appData = readDataBlock();
  7062. if (fileMarker === 0xFFE0) {
  7063. if (appData[0] === 0x4A && appData[1] === 0x46 &&
  7064. appData[2] === 0x49 && appData[3] === 0x46 &&
  7065. appData[4] === 0) { // 'JFIF\x00'
  7066. jfif = {
  7067. version: { major: appData[5], minor: appData[6] },
  7068. densityUnits: appData[7],
  7069. xDensity: (appData[8] << 8) | appData[9],
  7070. yDensity: (appData[10] << 8) | appData[11],
  7071. thumbWidth: appData[12],
  7072. thumbHeight: appData[13],
  7073. thumbData: appData.subarray(14, 14 +
  7074. 3 * appData[12] * appData[13])
  7075. };
  7076. }
  7077. }
  7078. // TODO APP1 - Exif
  7079. if (fileMarker === 0xFFEE) {
  7080. if (appData[0] === 0x41 && appData[1] === 0x64 &&
  7081. appData[2] === 0x6F && appData[3] === 0x62 &&
  7082. appData[4] === 0x65) { // 'Adobe'
  7083. adobe = {
  7084. version: (appData[5] << 8) | appData[6],
  7085. flags0: (appData[7] << 8) | appData[8],
  7086. flags1: (appData[9] << 8) | appData[10],
  7087. transformCode: appData[11]
  7088. };
  7089. }
  7090. }
  7091. break;
  7092. case 0xFFDB: // DQT (Define Quantization Tables)
  7093. var quantizationTablesLength = readUint16();
  7094. var quantizationTablesEnd = quantizationTablesLength + offset - 2;
  7095. var z;
  7096. while (offset < quantizationTablesEnd) {
  7097. var quantizationTableSpec = data[offset++];
  7098. var tableData = new Uint16Array(64);
  7099. if ((quantizationTableSpec >> 4) === 0) { // 8 bit values
  7100. for (j = 0; j < 64; j++) {
  7101. z = dctZigZag[j];
  7102. tableData[z] = data[offset++];
  7103. }
  7104. } else if ((quantizationTableSpec >> 4) === 1) { //16 bit
  7105. for (j = 0; j < 64; j++) {
  7106. z = dctZigZag[j];
  7107. tableData[z] = readUint16();
  7108. }
  7109. } else {
  7110. throw 'DQT: invalid table spec';
  7111. }
  7112. quantizationTables[quantizationTableSpec & 15] = tableData;
  7113. }
  7114. break;
  7115. case 0xFFC0: // SOF0 (Start of Frame, Baseline DCT)
  7116. case 0xFFC1: // SOF1 (Start of Frame, Extended DCT)
  7117. case 0xFFC2: // SOF2 (Start of Frame, Progressive DCT)
  7118. if (frame) {
  7119. throw 'Only single frame JPEGs supported';
  7120. }
  7121. readUint16(); // skip data length
  7122. frame = {};
  7123. frame.extended = (fileMarker === 0xFFC1);
  7124. frame.progressive = (fileMarker === 0xFFC2);
  7125. frame.precision = data[offset++];
  7126. frame.scanLines = readUint16();
  7127. frame.samplesPerLine = readUint16();
  7128. frame.components = [];
  7129. frame.componentIds = {};
  7130. var componentsCount = data[offset++], componentId;
  7131. var maxH = 0, maxV = 0;
  7132. for (i = 0; i < componentsCount; i++) {
  7133. componentId = data[offset];
  7134. var h = data[offset + 1] >> 4;
  7135. var v = data[offset + 1] & 15;
  7136. if (maxH < h) {
  7137. maxH = h;
  7138. }
  7139. if (maxV < v) {
  7140. maxV = v;
  7141. }
  7142. var qId = data[offset + 2];
  7143. l = frame.components.push({
  7144. h: h,
  7145. v: v,
  7146. quantizationTable: quantizationTables[qId]
  7147. });
  7148. frame.componentIds[componentId] = l - 1;
  7149. offset += 3;
  7150. }
  7151. frame.maxH = maxH;
  7152. frame.maxV = maxV;
  7153. prepareComponents(frame);
  7154. break;
  7155. case 0xFFC4: // DHT (Define Huffman Tables)
  7156. var huffmanLength = readUint16();
  7157. for (i = 2; i < huffmanLength;) {
  7158. var huffmanTableSpec = data[offset++];
  7159. var codeLengths = new Uint8Array(16);
  7160. var codeLengthSum = 0;
  7161. for (j = 0; j < 16; j++, offset++) {
  7162. codeLengthSum += (codeLengths[j] = data[offset]);
  7163. }
  7164. var huffmanValues = new Uint8Array(codeLengthSum);
  7165. for (j = 0; j < codeLengthSum; j++, offset++) {
  7166. huffmanValues[j] = data[offset];
  7167. }
  7168. i += 17 + codeLengthSum;
  7169. ((huffmanTableSpec >> 4) === 0 ?
  7170. huffmanTablesDC : huffmanTablesAC)[huffmanTableSpec & 15] =
  7171. buildHuffmanTable(codeLengths, huffmanValues);
  7172. }
  7173. break;
  7174. case 0xFFDD: // DRI (Define Restart Interval)
  7175. readUint16(); // skip data length
  7176. resetInterval = readUint16();
  7177. break;
  7178. case 0xFFDA: // SOS (Start of Scan)
  7179. var scanLength = readUint16();
  7180. var selectorsCount = data[offset++];
  7181. var components = [], component;
  7182. for (i = 0; i < selectorsCount; i++) {
  7183. var componentIndex = frame.componentIds[data[offset++]];
  7184. component = frame.components[componentIndex];
  7185. var tableSpec = data[offset++];
  7186. component.huffmanTableDC = huffmanTablesDC[tableSpec >> 4];
  7187. component.huffmanTableAC = huffmanTablesAC[tableSpec & 15];
  7188. components.push(component);
  7189. }
  7190. var spectralStart = data[offset++];
  7191. var spectralEnd = data[offset++];
  7192. var successiveApproximation = data[offset++];
  7193. var processed = decodeScan(data, offset,
  7194. frame, components, resetInterval,
  7195. spectralStart, spectralEnd,
  7196. successiveApproximation >> 4, successiveApproximation & 15);
  7197. offset += processed;
  7198. break;
  7199. case 0xFFFF: // Fill bytes
  7200. if (data[offset] !== 0xFF) { // Avoid skipping a valid marker.
  7201. offset--;
  7202. }
  7203. break;
  7204. default:
  7205. if (data[offset - 3] === 0xFF &&
  7206. data[offset - 2] >= 0xC0 && data[offset - 2] <= 0xFE) {
  7207. // could be incorrect encoding -- last 0xFF byte of the previous
  7208. // block was eaten by the encoder
  7209. offset -= 3;
  7210. break;
  7211. }
  7212. throw 'unknown JPEG marker ' + fileMarker.toString(16);
  7213. }
  7214. fileMarker = readUint16();
  7215. }
  7216. this.width = frame.samplesPerLine;
  7217. this.height = frame.scanLines;
  7218. this.jfif = jfif;
  7219. this.adobe = adobe;
  7220. this.components = [];
  7221. for (i = 0; i < frame.components.length; i++) {
  7222. component = frame.components[i];
  7223. this.components.push({
  7224. output: buildComponentData(frame, component),
  7225. scaleX: component.h / frame.maxH,
  7226. scaleY: component.v / frame.maxV,
  7227. blocksPerLine: component.blocksPerLine,
  7228. blocksPerColumn: component.blocksPerColumn
  7229. });
  7230. }
  7231. this.numComponents = this.components.length;
  7232. },
  7233. _getLinearizedBlockData: function getLinearizedBlockData(width, height) {
  7234. var scaleX = this.width / width, scaleY = this.height / height;
  7235. var component, componentScaleX, componentScaleY, blocksPerScanline;
  7236. var x, y, i, j, k;
  7237. var index;
  7238. var offset = 0;
  7239. var output;
  7240. var numComponents = this.components.length;
  7241. var dataLength = width * height * numComponents;
  7242. var data = new Uint8Array(dataLength);
  7243. var xScaleBlockOffset = new Uint32Array(width);
  7244. var mask3LSB = 0xfffffff8; // used to clear the 3 LSBs
  7245. for (i = 0; i < numComponents; i++) {
  7246. component = this.components[i];
  7247. componentScaleX = component.scaleX * scaleX;
  7248. componentScaleY = component.scaleY * scaleY;
  7249. offset = i;
  7250. output = component.output;
  7251. blocksPerScanline = (component.blocksPerLine + 1) << 3;
  7252. // precalculate the xScaleBlockOffset
  7253. for (x = 0; x < width; x++) {
  7254. j = 0 | (x * componentScaleX);
  7255. xScaleBlockOffset[x] = ((j & mask3LSB) << 3) | (j & 7);
  7256. }
  7257. // linearize the blocks of the component
  7258. for (y = 0; y < height; y++) {
  7259. j = 0 | (y * componentScaleY);
  7260. index = blocksPerScanline * (j & mask3LSB) | ((j & 7) << 3);
  7261. for (x = 0; x < width; x++) {
  7262. data[offset] = output[index + xScaleBlockOffset[x]];
  7263. offset += numComponents;
  7264. }
  7265. }
  7266. }
  7267. // decodeTransform contains pairs of multiplier (-256..256) and additive
  7268. var transform = this.decodeTransform;
  7269. if (transform) {
  7270. for (i = 0; i < dataLength;) {
  7271. for (j = 0, k = 0; j < numComponents; j++, i++, k += 2) {
  7272. data[i] = ((data[i] * transform[k]) >> 8) + transform[k + 1];
  7273. }
  7274. }
  7275. }
  7276. return data;
  7277. },
  7278. _isColorConversionNeeded: function isColorConversionNeeded() {
  7279. if (this.adobe && this.adobe.transformCode) {
  7280. // The adobe transform marker overrides any previous setting
  7281. return true;
  7282. } else if (this.numComponents === 3) {
  7283. return true;
  7284. } else {
  7285. return false;
  7286. }
  7287. },
  7288. _convertYccToRgb: function convertYccToRgb(data) {
  7289. var Y, Cb, Cr;
  7290. for (var i = 0, length = data.length; i < length; i += 3) {
  7291. Y = data[i ];
  7292. Cb = data[i + 1];
  7293. Cr = data[i + 2];
  7294. data[i ] = clamp0to255(Y - 179.456 + 1.402 * Cr);
  7295. data[i + 1] = clamp0to255(Y + 135.459 - 0.344 * Cb - 0.714 * Cr);
  7296. data[i + 2] = clamp0to255(Y - 226.816 + 1.772 * Cb);
  7297. }
  7298. return data;
  7299. },
  7300. _convertYcckToRgb: function convertYcckToRgb(data) {
  7301. var Y, Cb, Cr, k;
  7302. var offset = 0;
  7303. for (var i = 0, length = data.length; i < length; i += 4) {
  7304. Y = data[i];
  7305. Cb = data[i + 1];
  7306. Cr = data[i + 2];
  7307. k = data[i + 3];
  7308. var r = -122.67195406894 +
  7309. Cb * (-6.60635669420364e-5 * Cb + 0.000437130475926232 * Cr -
  7310. 5.4080610064599e-5 * Y + 0.00048449797120281 * k -
  7311. 0.154362151871126) +
  7312. Cr * (-0.000957964378445773 * Cr + 0.000817076911346625 * Y -
  7313. 0.00477271405408747 * k + 1.53380253221734) +
  7314. Y * (0.000961250184130688 * Y - 0.00266257332283933 * k +
  7315. 0.48357088451265) +
  7316. k * (-0.000336197177618394 * k + 0.484791561490776);
  7317. var g = 107.268039397724 +
  7318. Cb * (2.19927104525741e-5 * Cb - 0.000640992018297945 * Cr +
  7319. 0.000659397001245577 * Y + 0.000426105652938837 * k -
  7320. 0.176491792462875) +
  7321. Cr * (-0.000778269941513683 * Cr + 0.00130872261408275 * Y +
  7322. 0.000770482631801132 * k - 0.151051492775562) +
  7323. Y * (0.00126935368114843 * Y - 0.00265090189010898 * k +
  7324. 0.25802910206845) +
  7325. k * (-0.000318913117588328 * k - 0.213742400323665);
  7326. var b = -20.810012546947 +
  7327. Cb * (-0.000570115196973677 * Cb - 2.63409051004589e-5 * Cr +
  7328. 0.0020741088115012 * Y - 0.00288260236853442 * k +
  7329. 0.814272968359295) +
  7330. Cr * (-1.53496057440975e-5 * Cr - 0.000132689043961446 * Y +
  7331. 0.000560833691242812 * k - 0.195152027534049) +
  7332. Y * (0.00174418132927582 * Y - 0.00255243321439347 * k +
  7333. 0.116935020465145) +
  7334. k * (-0.000343531996510555 * k + 0.24165260232407);
  7335. data[offset++] = clamp0to255(r);
  7336. data[offset++] = clamp0to255(g);
  7337. data[offset++] = clamp0to255(b);
  7338. }
  7339. return data;
  7340. },
  7341. _convertYcckToCmyk: function convertYcckToCmyk(data) {
  7342. var Y, Cb, Cr;
  7343. for (var i = 0, length = data.length; i < length; i += 4) {
  7344. Y = data[i];
  7345. Cb = data[i + 1];
  7346. Cr = data[i + 2];
  7347. data[i ] = clamp0to255(434.456 - Y - 1.402 * Cr);
  7348. data[i + 1] = clamp0to255(119.541 - Y + 0.344 * Cb + 0.714 * Cr);
  7349. data[i + 2] = clamp0to255(481.816 - Y - 1.772 * Cb);
  7350. // K in data[i + 3] is unchanged
  7351. }
  7352. return data;
  7353. },
  7354. _convertCmykToRgb: function convertCmykToRgb(data) {
  7355. var c, m, y, k;
  7356. var offset = 0;
  7357. var min = -255 * 255 * 255;
  7358. var scale = 1 / 255 / 255;
  7359. for (var i = 0, length = data.length; i < length; i += 4) {
  7360. c = data[i];
  7361. m = data[i + 1];
  7362. y = data[i + 2];
  7363. k = data[i + 3];
  7364. var r =
  7365. c * (-4.387332384609988 * c + 54.48615194189176 * m +
  7366. 18.82290502165302 * y + 212.25662451639585 * k -
  7367. 72734.4411664936) +
  7368. m * (1.7149763477362134 * m - 5.6096736904047315 * y -
  7369. 17.873870861415444 * k - 1401.7366389350734) +
  7370. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  7371. 4465.541406466231) -
  7372. k * (21.86122147463605 * k + 48317.86113160301);
  7373. var g =
  7374. c * (8.841041422036149 * c + 60.118027045597366 * m +
  7375. 6.871425592049007 * y + 31.159100130055922 * k -
  7376. 20220.756542821975) +
  7377. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  7378. 131.35250912493976 * k - 48691.05921601825) +
  7379. y * (4.444339102852739 * y + 9.8632861493405 * k -
  7380. 6341.191035517494) -
  7381. k * (20.737325471181034 * k + 47890.15695978492);
  7382. var b =
  7383. c * (0.8842522430003296 * c + 8.078677503112928 * m +
  7384. 30.89978309703729 * y - 0.23883238689178934 * k -
  7385. 3616.812083916688) +
  7386. m * (10.49593273432072 * m + 63.02378494754052 * y +
  7387. 50.606957656360734 * k - 28620.90484698408) +
  7388. y * (0.03296041114873217 * y + 115.60384449646641 * k -
  7389. 49363.43385999684) -
  7390. k * (22.33816807309886 * k + 45932.16563550634);
  7391. data[offset++] = r >= 0 ? 255 : r <= min ? 0 : 255 + r * scale | 0;
  7392. data[offset++] = g >= 0 ? 255 : g <= min ? 0 : 255 + g * scale | 0;
  7393. data[offset++] = b >= 0 ? 255 : b <= min ? 0 : 255 + b * scale | 0;
  7394. }
  7395. return data;
  7396. },
  7397. getData: function getData(width, height, forceRGBoutput) {
  7398. if (this.numComponents > 4) {
  7399. throw 'Unsupported color mode';
  7400. }
  7401. // type of data: Uint8Array(width * height * numComponents)
  7402. var data = this._getLinearizedBlockData(width, height);
  7403. if (this.numComponents === 3) {
  7404. return this._convertYccToRgb(data);
  7405. } else if (this.numComponents === 4) {
  7406. if (this._isColorConversionNeeded()) {
  7407. if (forceRGBoutput) {
  7408. return this._convertYcckToRgb(data);
  7409. } else {
  7410. return this._convertYcckToCmyk(data);
  7411. }
  7412. } else if (forceRGBoutput) {
  7413. return this._convertCmykToRgb(data);
  7414. }
  7415. }
  7416. return data;
  7417. }
  7418. };
  7419. return constructor;
  7420. })();
  7421. exports.JpegImage = JpegImage;
  7422. }));
  7423. (function (root, factory) {
  7424. if (typeof define === 'function' && define.amd) {
  7425. define('pdfjs/core/metrics', ['exports'], factory);
  7426. } else if (typeof exports !== 'undefined') {
  7427. factory(exports);
  7428. } else {
  7429. factory((root.pdfjsCoreMetrics = {}));
  7430. }
  7431. }(this, function (exports) {
  7432. // The Metrics object contains glyph widths (in glyph space units).
  7433. // As per PDF spec, for most fonts (Type 3 being an exception) a glyph
  7434. // space unit corresponds to 1/1000th of text space unit.
  7435. var Metrics = {
  7436. 'Courier': 600,
  7437. 'Courier-Bold': 600,
  7438. 'Courier-BoldOblique': 600,
  7439. 'Courier-Oblique': 600,
  7440. 'Helvetica' : {
  7441. 'space': 278,
  7442. 'exclam': 278,
  7443. 'quotedbl': 355,
  7444. 'numbersign': 556,
  7445. 'dollar': 556,
  7446. 'percent': 889,
  7447. 'ampersand': 667,
  7448. 'quoteright': 222,
  7449. 'parenleft': 333,
  7450. 'parenright': 333,
  7451. 'asterisk': 389,
  7452. 'plus': 584,
  7453. 'comma': 278,
  7454. 'hyphen': 333,
  7455. 'period': 278,
  7456. 'slash': 278,
  7457. 'zero': 556,
  7458. 'one': 556,
  7459. 'two': 556,
  7460. 'three': 556,
  7461. 'four': 556,
  7462. 'five': 556,
  7463. 'six': 556,
  7464. 'seven': 556,
  7465. 'eight': 556,
  7466. 'nine': 556,
  7467. 'colon': 278,
  7468. 'semicolon': 278,
  7469. 'less': 584,
  7470. 'equal': 584,
  7471. 'greater': 584,
  7472. 'question': 556,
  7473. 'at': 1015,
  7474. 'A': 667,
  7475. 'B': 667,
  7476. 'C': 722,
  7477. 'D': 722,
  7478. 'E': 667,
  7479. 'F': 611,
  7480. 'G': 778,
  7481. 'H': 722,
  7482. 'I': 278,
  7483. 'J': 500,
  7484. 'K': 667,
  7485. 'L': 556,
  7486. 'M': 833,
  7487. 'N': 722,
  7488. 'O': 778,
  7489. 'P': 667,
  7490. 'Q': 778,
  7491. 'R': 722,
  7492. 'S': 667,
  7493. 'T': 611,
  7494. 'U': 722,
  7495. 'V': 667,
  7496. 'W': 944,
  7497. 'X': 667,
  7498. 'Y': 667,
  7499. 'Z': 611,
  7500. 'bracketleft': 278,
  7501. 'backslash': 278,
  7502. 'bracketright': 278,
  7503. 'asciicircum': 469,
  7504. 'underscore': 556,
  7505. 'quoteleft': 222,
  7506. 'a': 556,
  7507. 'b': 556,
  7508. 'c': 500,
  7509. 'd': 556,
  7510. 'e': 556,
  7511. 'f': 278,
  7512. 'g': 556,
  7513. 'h': 556,
  7514. 'i': 222,
  7515. 'j': 222,
  7516. 'k': 500,
  7517. 'l': 222,
  7518. 'm': 833,
  7519. 'n': 556,
  7520. 'o': 556,
  7521. 'p': 556,
  7522. 'q': 556,
  7523. 'r': 333,
  7524. 's': 500,
  7525. 't': 278,
  7526. 'u': 556,
  7527. 'v': 500,
  7528. 'w': 722,
  7529. 'x': 500,
  7530. 'y': 500,
  7531. 'z': 500,
  7532. 'braceleft': 334,
  7533. 'bar': 260,
  7534. 'braceright': 334,
  7535. 'asciitilde': 584,
  7536. 'exclamdown': 333,
  7537. 'cent': 556,
  7538. 'sterling': 556,
  7539. 'fraction': 167,
  7540. 'yen': 556,
  7541. 'florin': 556,
  7542. 'section': 556,
  7543. 'currency': 556,
  7544. 'quotesingle': 191,
  7545. 'quotedblleft': 333,
  7546. 'guillemotleft': 556,
  7547. 'guilsinglleft': 333,
  7548. 'guilsinglright': 333,
  7549. 'fi': 500,
  7550. 'fl': 500,
  7551. 'endash': 556,
  7552. 'dagger': 556,
  7553. 'daggerdbl': 556,
  7554. 'periodcentered': 278,
  7555. 'paragraph': 537,
  7556. 'bullet': 350,
  7557. 'quotesinglbase': 222,
  7558. 'quotedblbase': 333,
  7559. 'quotedblright': 333,
  7560. 'guillemotright': 556,
  7561. 'ellipsis': 1000,
  7562. 'perthousand': 1000,
  7563. 'questiondown': 611,
  7564. 'grave': 333,
  7565. 'acute': 333,
  7566. 'circumflex': 333,
  7567. 'tilde': 333,
  7568. 'macron': 333,
  7569. 'breve': 333,
  7570. 'dotaccent': 333,
  7571. 'dieresis': 333,
  7572. 'ring': 333,
  7573. 'cedilla': 333,
  7574. 'hungarumlaut': 333,
  7575. 'ogonek': 333,
  7576. 'caron': 333,
  7577. 'emdash': 1000,
  7578. 'AE': 1000,
  7579. 'ordfeminine': 370,
  7580. 'Lslash': 556,
  7581. 'Oslash': 778,
  7582. 'OE': 1000,
  7583. 'ordmasculine': 365,
  7584. 'ae': 889,
  7585. 'dotlessi': 278,
  7586. 'lslash': 222,
  7587. 'oslash': 611,
  7588. 'oe': 944,
  7589. 'germandbls': 611,
  7590. 'Idieresis': 278,
  7591. 'eacute': 556,
  7592. 'abreve': 556,
  7593. 'uhungarumlaut': 556,
  7594. 'ecaron': 556,
  7595. 'Ydieresis': 667,
  7596. 'divide': 584,
  7597. 'Yacute': 667,
  7598. 'Acircumflex': 667,
  7599. 'aacute': 556,
  7600. 'Ucircumflex': 722,
  7601. 'yacute': 500,
  7602. 'scommaaccent': 500,
  7603. 'ecircumflex': 556,
  7604. 'Uring': 722,
  7605. 'Udieresis': 722,
  7606. 'aogonek': 556,
  7607. 'Uacute': 722,
  7608. 'uogonek': 556,
  7609. 'Edieresis': 667,
  7610. 'Dcroat': 722,
  7611. 'commaaccent': 250,
  7612. 'copyright': 737,
  7613. 'Emacron': 667,
  7614. 'ccaron': 500,
  7615. 'aring': 556,
  7616. 'Ncommaaccent': 722,
  7617. 'lacute': 222,
  7618. 'agrave': 556,
  7619. 'Tcommaaccent': 611,
  7620. 'Cacute': 722,
  7621. 'atilde': 556,
  7622. 'Edotaccent': 667,
  7623. 'scaron': 500,
  7624. 'scedilla': 500,
  7625. 'iacute': 278,
  7626. 'lozenge': 471,
  7627. 'Rcaron': 722,
  7628. 'Gcommaaccent': 778,
  7629. 'ucircumflex': 556,
  7630. 'acircumflex': 556,
  7631. 'Amacron': 667,
  7632. 'rcaron': 333,
  7633. 'ccedilla': 500,
  7634. 'Zdotaccent': 611,
  7635. 'Thorn': 667,
  7636. 'Omacron': 778,
  7637. 'Racute': 722,
  7638. 'Sacute': 667,
  7639. 'dcaron': 643,
  7640. 'Umacron': 722,
  7641. 'uring': 556,
  7642. 'threesuperior': 333,
  7643. 'Ograve': 778,
  7644. 'Agrave': 667,
  7645. 'Abreve': 667,
  7646. 'multiply': 584,
  7647. 'uacute': 556,
  7648. 'Tcaron': 611,
  7649. 'partialdiff': 476,
  7650. 'ydieresis': 500,
  7651. 'Nacute': 722,
  7652. 'icircumflex': 278,
  7653. 'Ecircumflex': 667,
  7654. 'adieresis': 556,
  7655. 'edieresis': 556,
  7656. 'cacute': 500,
  7657. 'nacute': 556,
  7658. 'umacron': 556,
  7659. 'Ncaron': 722,
  7660. 'Iacute': 278,
  7661. 'plusminus': 584,
  7662. 'brokenbar': 260,
  7663. 'registered': 737,
  7664. 'Gbreve': 778,
  7665. 'Idotaccent': 278,
  7666. 'summation': 600,
  7667. 'Egrave': 667,
  7668. 'racute': 333,
  7669. 'omacron': 556,
  7670. 'Zacute': 611,
  7671. 'Zcaron': 611,
  7672. 'greaterequal': 549,
  7673. 'Eth': 722,
  7674. 'Ccedilla': 722,
  7675. 'lcommaaccent': 222,
  7676. 'tcaron': 317,
  7677. 'eogonek': 556,
  7678. 'Uogonek': 722,
  7679. 'Aacute': 667,
  7680. 'Adieresis': 667,
  7681. 'egrave': 556,
  7682. 'zacute': 500,
  7683. 'iogonek': 222,
  7684. 'Oacute': 778,
  7685. 'oacute': 556,
  7686. 'amacron': 556,
  7687. 'sacute': 500,
  7688. 'idieresis': 278,
  7689. 'Ocircumflex': 778,
  7690. 'Ugrave': 722,
  7691. 'Delta': 612,
  7692. 'thorn': 556,
  7693. 'twosuperior': 333,
  7694. 'Odieresis': 778,
  7695. 'mu': 556,
  7696. 'igrave': 278,
  7697. 'ohungarumlaut': 556,
  7698. 'Eogonek': 667,
  7699. 'dcroat': 556,
  7700. 'threequarters': 834,
  7701. 'Scedilla': 667,
  7702. 'lcaron': 299,
  7703. 'Kcommaaccent': 667,
  7704. 'Lacute': 556,
  7705. 'trademark': 1000,
  7706. 'edotaccent': 556,
  7707. 'Igrave': 278,
  7708. 'Imacron': 278,
  7709. 'Lcaron': 556,
  7710. 'onehalf': 834,
  7711. 'lessequal': 549,
  7712. 'ocircumflex': 556,
  7713. 'ntilde': 556,
  7714. 'Uhungarumlaut': 722,
  7715. 'Eacute': 667,
  7716. 'emacron': 556,
  7717. 'gbreve': 556,
  7718. 'onequarter': 834,
  7719. 'Scaron': 667,
  7720. 'Scommaaccent': 667,
  7721. 'Ohungarumlaut': 778,
  7722. 'degree': 400,
  7723. 'ograve': 556,
  7724. 'Ccaron': 722,
  7725. 'ugrave': 556,
  7726. 'radical': 453,
  7727. 'Dcaron': 722,
  7728. 'rcommaaccent': 333,
  7729. 'Ntilde': 722,
  7730. 'otilde': 556,
  7731. 'Rcommaaccent': 722,
  7732. 'Lcommaaccent': 556,
  7733. 'Atilde': 667,
  7734. 'Aogonek': 667,
  7735. 'Aring': 667,
  7736. 'Otilde': 778,
  7737. 'zdotaccent': 500,
  7738. 'Ecaron': 667,
  7739. 'Iogonek': 278,
  7740. 'kcommaaccent': 500,
  7741. 'minus': 584,
  7742. 'Icircumflex': 278,
  7743. 'ncaron': 556,
  7744. 'tcommaaccent': 278,
  7745. 'logicalnot': 584,
  7746. 'odieresis': 556,
  7747. 'udieresis': 556,
  7748. 'notequal': 549,
  7749. 'gcommaaccent': 556,
  7750. 'eth': 556,
  7751. 'zcaron': 500,
  7752. 'ncommaaccent': 556,
  7753. 'onesuperior': 333,
  7754. 'imacron': 278,
  7755. 'Euro': 556
  7756. },
  7757. 'Helvetica-Bold': {
  7758. 'space': 278,
  7759. 'exclam': 333,
  7760. 'quotedbl': 474,
  7761. 'numbersign': 556,
  7762. 'dollar': 556,
  7763. 'percent': 889,
  7764. 'ampersand': 722,
  7765. 'quoteright': 278,
  7766. 'parenleft': 333,
  7767. 'parenright': 333,
  7768. 'asterisk': 389,
  7769. 'plus': 584,
  7770. 'comma': 278,
  7771. 'hyphen': 333,
  7772. 'period': 278,
  7773. 'slash': 278,
  7774. 'zero': 556,
  7775. 'one': 556,
  7776. 'two': 556,
  7777. 'three': 556,
  7778. 'four': 556,
  7779. 'five': 556,
  7780. 'six': 556,
  7781. 'seven': 556,
  7782. 'eight': 556,
  7783. 'nine': 556,
  7784. 'colon': 333,
  7785. 'semicolon': 333,
  7786. 'less': 584,
  7787. 'equal': 584,
  7788. 'greater': 584,
  7789. 'question': 611,
  7790. 'at': 975,
  7791. 'A': 722,
  7792. 'B': 722,
  7793. 'C': 722,
  7794. 'D': 722,
  7795. 'E': 667,
  7796. 'F': 611,
  7797. 'G': 778,
  7798. 'H': 722,
  7799. 'I': 278,
  7800. 'J': 556,
  7801. 'K': 722,
  7802. 'L': 611,
  7803. 'M': 833,
  7804. 'N': 722,
  7805. 'O': 778,
  7806. 'P': 667,
  7807. 'Q': 778,
  7808. 'R': 722,
  7809. 'S': 667,
  7810. 'T': 611,
  7811. 'U': 722,
  7812. 'V': 667,
  7813. 'W': 944,
  7814. 'X': 667,
  7815. 'Y': 667,
  7816. 'Z': 611,
  7817. 'bracketleft': 333,
  7818. 'backslash': 278,
  7819. 'bracketright': 333,
  7820. 'asciicircum': 584,
  7821. 'underscore': 556,
  7822. 'quoteleft': 278,
  7823. 'a': 556,
  7824. 'b': 611,
  7825. 'c': 556,
  7826. 'd': 611,
  7827. 'e': 556,
  7828. 'f': 333,
  7829. 'g': 611,
  7830. 'h': 611,
  7831. 'i': 278,
  7832. 'j': 278,
  7833. 'k': 556,
  7834. 'l': 278,
  7835. 'm': 889,
  7836. 'n': 611,
  7837. 'o': 611,
  7838. 'p': 611,
  7839. 'q': 611,
  7840. 'r': 389,
  7841. 's': 556,
  7842. 't': 333,
  7843. 'u': 611,
  7844. 'v': 556,
  7845. 'w': 778,
  7846. 'x': 556,
  7847. 'y': 556,
  7848. 'z': 500,
  7849. 'braceleft': 389,
  7850. 'bar': 280,
  7851. 'braceright': 389,
  7852. 'asciitilde': 584,
  7853. 'exclamdown': 333,
  7854. 'cent': 556,
  7855. 'sterling': 556,
  7856. 'fraction': 167,
  7857. 'yen': 556,
  7858. 'florin': 556,
  7859. 'section': 556,
  7860. 'currency': 556,
  7861. 'quotesingle': 238,
  7862. 'quotedblleft': 500,
  7863. 'guillemotleft': 556,
  7864. 'guilsinglleft': 333,
  7865. 'guilsinglright': 333,
  7866. 'fi': 611,
  7867. 'fl': 611,
  7868. 'endash': 556,
  7869. 'dagger': 556,
  7870. 'daggerdbl': 556,
  7871. 'periodcentered': 278,
  7872. 'paragraph': 556,
  7873. 'bullet': 350,
  7874. 'quotesinglbase': 278,
  7875. 'quotedblbase': 500,
  7876. 'quotedblright': 500,
  7877. 'guillemotright': 556,
  7878. 'ellipsis': 1000,
  7879. 'perthousand': 1000,
  7880. 'questiondown': 611,
  7881. 'grave': 333,
  7882. 'acute': 333,
  7883. 'circumflex': 333,
  7884. 'tilde': 333,
  7885. 'macron': 333,
  7886. 'breve': 333,
  7887. 'dotaccent': 333,
  7888. 'dieresis': 333,
  7889. 'ring': 333,
  7890. 'cedilla': 333,
  7891. 'hungarumlaut': 333,
  7892. 'ogonek': 333,
  7893. 'caron': 333,
  7894. 'emdash': 1000,
  7895. 'AE': 1000,
  7896. 'ordfeminine': 370,
  7897. 'Lslash': 611,
  7898. 'Oslash': 778,
  7899. 'OE': 1000,
  7900. 'ordmasculine': 365,
  7901. 'ae': 889,
  7902. 'dotlessi': 278,
  7903. 'lslash': 278,
  7904. 'oslash': 611,
  7905. 'oe': 944,
  7906. 'germandbls': 611,
  7907. 'Idieresis': 278,
  7908. 'eacute': 556,
  7909. 'abreve': 556,
  7910. 'uhungarumlaut': 611,
  7911. 'ecaron': 556,
  7912. 'Ydieresis': 667,
  7913. 'divide': 584,
  7914. 'Yacute': 667,
  7915. 'Acircumflex': 722,
  7916. 'aacute': 556,
  7917. 'Ucircumflex': 722,
  7918. 'yacute': 556,
  7919. 'scommaaccent': 556,
  7920. 'ecircumflex': 556,
  7921. 'Uring': 722,
  7922. 'Udieresis': 722,
  7923. 'aogonek': 556,
  7924. 'Uacute': 722,
  7925. 'uogonek': 611,
  7926. 'Edieresis': 667,
  7927. 'Dcroat': 722,
  7928. 'commaaccent': 250,
  7929. 'copyright': 737,
  7930. 'Emacron': 667,
  7931. 'ccaron': 556,
  7932. 'aring': 556,
  7933. 'Ncommaaccent': 722,
  7934. 'lacute': 278,
  7935. 'agrave': 556,
  7936. 'Tcommaaccent': 611,
  7937. 'Cacute': 722,
  7938. 'atilde': 556,
  7939. 'Edotaccent': 667,
  7940. 'scaron': 556,
  7941. 'scedilla': 556,
  7942. 'iacute': 278,
  7943. 'lozenge': 494,
  7944. 'Rcaron': 722,
  7945. 'Gcommaaccent': 778,
  7946. 'ucircumflex': 611,
  7947. 'acircumflex': 556,
  7948. 'Amacron': 722,
  7949. 'rcaron': 389,
  7950. 'ccedilla': 556,
  7951. 'Zdotaccent': 611,
  7952. 'Thorn': 667,
  7953. 'Omacron': 778,
  7954. 'Racute': 722,
  7955. 'Sacute': 667,
  7956. 'dcaron': 743,
  7957. 'Umacron': 722,
  7958. 'uring': 611,
  7959. 'threesuperior': 333,
  7960. 'Ograve': 778,
  7961. 'Agrave': 722,
  7962. 'Abreve': 722,
  7963. 'multiply': 584,
  7964. 'uacute': 611,
  7965. 'Tcaron': 611,
  7966. 'partialdiff': 494,
  7967. 'ydieresis': 556,
  7968. 'Nacute': 722,
  7969. 'icircumflex': 278,
  7970. 'Ecircumflex': 667,
  7971. 'adieresis': 556,
  7972. 'edieresis': 556,
  7973. 'cacute': 556,
  7974. 'nacute': 611,
  7975. 'umacron': 611,
  7976. 'Ncaron': 722,
  7977. 'Iacute': 278,
  7978. 'plusminus': 584,
  7979. 'brokenbar': 280,
  7980. 'registered': 737,
  7981. 'Gbreve': 778,
  7982. 'Idotaccent': 278,
  7983. 'summation': 600,
  7984. 'Egrave': 667,
  7985. 'racute': 389,
  7986. 'omacron': 611,
  7987. 'Zacute': 611,
  7988. 'Zcaron': 611,
  7989. 'greaterequal': 549,
  7990. 'Eth': 722,
  7991. 'Ccedilla': 722,
  7992. 'lcommaaccent': 278,
  7993. 'tcaron': 389,
  7994. 'eogonek': 556,
  7995. 'Uogonek': 722,
  7996. 'Aacute': 722,
  7997. 'Adieresis': 722,
  7998. 'egrave': 556,
  7999. 'zacute': 500,
  8000. 'iogonek': 278,
  8001. 'Oacute': 778,
  8002. 'oacute': 611,
  8003. 'amacron': 556,
  8004. 'sacute': 556,
  8005. 'idieresis': 278,
  8006. 'Ocircumflex': 778,
  8007. 'Ugrave': 722,
  8008. 'Delta': 612,
  8009. 'thorn': 611,
  8010. 'twosuperior': 333,
  8011. 'Odieresis': 778,
  8012. 'mu': 611,
  8013. 'igrave': 278,
  8014. 'ohungarumlaut': 611,
  8015. 'Eogonek': 667,
  8016. 'dcroat': 611,
  8017. 'threequarters': 834,
  8018. 'Scedilla': 667,
  8019. 'lcaron': 400,
  8020. 'Kcommaaccent': 722,
  8021. 'Lacute': 611,
  8022. 'trademark': 1000,
  8023. 'edotaccent': 556,
  8024. 'Igrave': 278,
  8025. 'Imacron': 278,
  8026. 'Lcaron': 611,
  8027. 'onehalf': 834,
  8028. 'lessequal': 549,
  8029. 'ocircumflex': 611,
  8030. 'ntilde': 611,
  8031. 'Uhungarumlaut': 722,
  8032. 'Eacute': 667,
  8033. 'emacron': 556,
  8034. 'gbreve': 611,
  8035. 'onequarter': 834,
  8036. 'Scaron': 667,
  8037. 'Scommaaccent': 667,
  8038. 'Ohungarumlaut': 778,
  8039. 'degree': 400,
  8040. 'ograve': 611,
  8041. 'Ccaron': 722,
  8042. 'ugrave': 611,
  8043. 'radical': 549,
  8044. 'Dcaron': 722,
  8045. 'rcommaaccent': 389,
  8046. 'Ntilde': 722,
  8047. 'otilde': 611,
  8048. 'Rcommaaccent': 722,
  8049. 'Lcommaaccent': 611,
  8050. 'Atilde': 722,
  8051. 'Aogonek': 722,
  8052. 'Aring': 722,
  8053. 'Otilde': 778,
  8054. 'zdotaccent': 500,
  8055. 'Ecaron': 667,
  8056. 'Iogonek': 278,
  8057. 'kcommaaccent': 556,
  8058. 'minus': 584,
  8059. 'Icircumflex': 278,
  8060. 'ncaron': 611,
  8061. 'tcommaaccent': 333,
  8062. 'logicalnot': 584,
  8063. 'odieresis': 611,
  8064. 'udieresis': 611,
  8065. 'notequal': 549,
  8066. 'gcommaaccent': 611,
  8067. 'eth': 611,
  8068. 'zcaron': 500,
  8069. 'ncommaaccent': 611,
  8070. 'onesuperior': 333,
  8071. 'imacron': 278,
  8072. 'Euro': 556
  8073. },
  8074. 'Helvetica-BoldOblique': {
  8075. 'space': 278,
  8076. 'exclam': 333,
  8077. 'quotedbl': 474,
  8078. 'numbersign': 556,
  8079. 'dollar': 556,
  8080. 'percent': 889,
  8081. 'ampersand': 722,
  8082. 'quoteright': 278,
  8083. 'parenleft': 333,
  8084. 'parenright': 333,
  8085. 'asterisk': 389,
  8086. 'plus': 584,
  8087. 'comma': 278,
  8088. 'hyphen': 333,
  8089. 'period': 278,
  8090. 'slash': 278,
  8091. 'zero': 556,
  8092. 'one': 556,
  8093. 'two': 556,
  8094. 'three': 556,
  8095. 'four': 556,
  8096. 'five': 556,
  8097. 'six': 556,
  8098. 'seven': 556,
  8099. 'eight': 556,
  8100. 'nine': 556,
  8101. 'colon': 333,
  8102. 'semicolon': 333,
  8103. 'less': 584,
  8104. 'equal': 584,
  8105. 'greater': 584,
  8106. 'question': 611,
  8107. 'at': 975,
  8108. 'A': 722,
  8109. 'B': 722,
  8110. 'C': 722,
  8111. 'D': 722,
  8112. 'E': 667,
  8113. 'F': 611,
  8114. 'G': 778,
  8115. 'H': 722,
  8116. 'I': 278,
  8117. 'J': 556,
  8118. 'K': 722,
  8119. 'L': 611,
  8120. 'M': 833,
  8121. 'N': 722,
  8122. 'O': 778,
  8123. 'P': 667,
  8124. 'Q': 778,
  8125. 'R': 722,
  8126. 'S': 667,
  8127. 'T': 611,
  8128. 'U': 722,
  8129. 'V': 667,
  8130. 'W': 944,
  8131. 'X': 667,
  8132. 'Y': 667,
  8133. 'Z': 611,
  8134. 'bracketleft': 333,
  8135. 'backslash': 278,
  8136. 'bracketright': 333,
  8137. 'asciicircum': 584,
  8138. 'underscore': 556,
  8139. 'quoteleft': 278,
  8140. 'a': 556,
  8141. 'b': 611,
  8142. 'c': 556,
  8143. 'd': 611,
  8144. 'e': 556,
  8145. 'f': 333,
  8146. 'g': 611,
  8147. 'h': 611,
  8148. 'i': 278,
  8149. 'j': 278,
  8150. 'k': 556,
  8151. 'l': 278,
  8152. 'm': 889,
  8153. 'n': 611,
  8154. 'o': 611,
  8155. 'p': 611,
  8156. 'q': 611,
  8157. 'r': 389,
  8158. 's': 556,
  8159. 't': 333,
  8160. 'u': 611,
  8161. 'v': 556,
  8162. 'w': 778,
  8163. 'x': 556,
  8164. 'y': 556,
  8165. 'z': 500,
  8166. 'braceleft': 389,
  8167. 'bar': 280,
  8168. 'braceright': 389,
  8169. 'asciitilde': 584,
  8170. 'exclamdown': 333,
  8171. 'cent': 556,
  8172. 'sterling': 556,
  8173. 'fraction': 167,
  8174. 'yen': 556,
  8175. 'florin': 556,
  8176. 'section': 556,
  8177. 'currency': 556,
  8178. 'quotesingle': 238,
  8179. 'quotedblleft': 500,
  8180. 'guillemotleft': 556,
  8181. 'guilsinglleft': 333,
  8182. 'guilsinglright': 333,
  8183. 'fi': 611,
  8184. 'fl': 611,
  8185. 'endash': 556,
  8186. 'dagger': 556,
  8187. 'daggerdbl': 556,
  8188. 'periodcentered': 278,
  8189. 'paragraph': 556,
  8190. 'bullet': 350,
  8191. 'quotesinglbase': 278,
  8192. 'quotedblbase': 500,
  8193. 'quotedblright': 500,
  8194. 'guillemotright': 556,
  8195. 'ellipsis': 1000,
  8196. 'perthousand': 1000,
  8197. 'questiondown': 611,
  8198. 'grave': 333,
  8199. 'acute': 333,
  8200. 'circumflex': 333,
  8201. 'tilde': 333,
  8202. 'macron': 333,
  8203. 'breve': 333,
  8204. 'dotaccent': 333,
  8205. 'dieresis': 333,
  8206. 'ring': 333,
  8207. 'cedilla': 333,
  8208. 'hungarumlaut': 333,
  8209. 'ogonek': 333,
  8210. 'caron': 333,
  8211. 'emdash': 1000,
  8212. 'AE': 1000,
  8213. 'ordfeminine': 370,
  8214. 'Lslash': 611,
  8215. 'Oslash': 778,
  8216. 'OE': 1000,
  8217. 'ordmasculine': 365,
  8218. 'ae': 889,
  8219. 'dotlessi': 278,
  8220. 'lslash': 278,
  8221. 'oslash': 611,
  8222. 'oe': 944,
  8223. 'germandbls': 611,
  8224. 'Idieresis': 278,
  8225. 'eacute': 556,
  8226. 'abreve': 556,
  8227. 'uhungarumlaut': 611,
  8228. 'ecaron': 556,
  8229. 'Ydieresis': 667,
  8230. 'divide': 584,
  8231. 'Yacute': 667,
  8232. 'Acircumflex': 722,
  8233. 'aacute': 556,
  8234. 'Ucircumflex': 722,
  8235. 'yacute': 556,
  8236. 'scommaaccent': 556,
  8237. 'ecircumflex': 556,
  8238. 'Uring': 722,
  8239. 'Udieresis': 722,
  8240. 'aogonek': 556,
  8241. 'Uacute': 722,
  8242. 'uogonek': 611,
  8243. 'Edieresis': 667,
  8244. 'Dcroat': 722,
  8245. 'commaaccent': 250,
  8246. 'copyright': 737,
  8247. 'Emacron': 667,
  8248. 'ccaron': 556,
  8249. 'aring': 556,
  8250. 'Ncommaaccent': 722,
  8251. 'lacute': 278,
  8252. 'agrave': 556,
  8253. 'Tcommaaccent': 611,
  8254. 'Cacute': 722,
  8255. 'atilde': 556,
  8256. 'Edotaccent': 667,
  8257. 'scaron': 556,
  8258. 'scedilla': 556,
  8259. 'iacute': 278,
  8260. 'lozenge': 494,
  8261. 'Rcaron': 722,
  8262. 'Gcommaaccent': 778,
  8263. 'ucircumflex': 611,
  8264. 'acircumflex': 556,
  8265. 'Amacron': 722,
  8266. 'rcaron': 389,
  8267. 'ccedilla': 556,
  8268. 'Zdotaccent': 611,
  8269. 'Thorn': 667,
  8270. 'Omacron': 778,
  8271. 'Racute': 722,
  8272. 'Sacute': 667,
  8273. 'dcaron': 743,
  8274. 'Umacron': 722,
  8275. 'uring': 611,
  8276. 'threesuperior': 333,
  8277. 'Ograve': 778,
  8278. 'Agrave': 722,
  8279. 'Abreve': 722,
  8280. 'multiply': 584,
  8281. 'uacute': 611,
  8282. 'Tcaron': 611,
  8283. 'partialdiff': 494,
  8284. 'ydieresis': 556,
  8285. 'Nacute': 722,
  8286. 'icircumflex': 278,
  8287. 'Ecircumflex': 667,
  8288. 'adieresis': 556,
  8289. 'edieresis': 556,
  8290. 'cacute': 556,
  8291. 'nacute': 611,
  8292. 'umacron': 611,
  8293. 'Ncaron': 722,
  8294. 'Iacute': 278,
  8295. 'plusminus': 584,
  8296. 'brokenbar': 280,
  8297. 'registered': 737,
  8298. 'Gbreve': 778,
  8299. 'Idotaccent': 278,
  8300. 'summation': 600,
  8301. 'Egrave': 667,
  8302. 'racute': 389,
  8303. 'omacron': 611,
  8304. 'Zacute': 611,
  8305. 'Zcaron': 611,
  8306. 'greaterequal': 549,
  8307. 'Eth': 722,
  8308. 'Ccedilla': 722,
  8309. 'lcommaaccent': 278,
  8310. 'tcaron': 389,
  8311. 'eogonek': 556,
  8312. 'Uogonek': 722,
  8313. 'Aacute': 722,
  8314. 'Adieresis': 722,
  8315. 'egrave': 556,
  8316. 'zacute': 500,
  8317. 'iogonek': 278,
  8318. 'Oacute': 778,
  8319. 'oacute': 611,
  8320. 'amacron': 556,
  8321. 'sacute': 556,
  8322. 'idieresis': 278,
  8323. 'Ocircumflex': 778,
  8324. 'Ugrave': 722,
  8325. 'Delta': 612,
  8326. 'thorn': 611,
  8327. 'twosuperior': 333,
  8328. 'Odieresis': 778,
  8329. 'mu': 611,
  8330. 'igrave': 278,
  8331. 'ohungarumlaut': 611,
  8332. 'Eogonek': 667,
  8333. 'dcroat': 611,
  8334. 'threequarters': 834,
  8335. 'Scedilla': 667,
  8336. 'lcaron': 400,
  8337. 'Kcommaaccent': 722,
  8338. 'Lacute': 611,
  8339. 'trademark': 1000,
  8340. 'edotaccent': 556,
  8341. 'Igrave': 278,
  8342. 'Imacron': 278,
  8343. 'Lcaron': 611,
  8344. 'onehalf': 834,
  8345. 'lessequal': 549,
  8346. 'ocircumflex': 611,
  8347. 'ntilde': 611,
  8348. 'Uhungarumlaut': 722,
  8349. 'Eacute': 667,
  8350. 'emacron': 556,
  8351. 'gbreve': 611,
  8352. 'onequarter': 834,
  8353. 'Scaron': 667,
  8354. 'Scommaaccent': 667,
  8355. 'Ohungarumlaut': 778,
  8356. 'degree': 400,
  8357. 'ograve': 611,
  8358. 'Ccaron': 722,
  8359. 'ugrave': 611,
  8360. 'radical': 549,
  8361. 'Dcaron': 722,
  8362. 'rcommaaccent': 389,
  8363. 'Ntilde': 722,
  8364. 'otilde': 611,
  8365. 'Rcommaaccent': 722,
  8366. 'Lcommaaccent': 611,
  8367. 'Atilde': 722,
  8368. 'Aogonek': 722,
  8369. 'Aring': 722,
  8370. 'Otilde': 778,
  8371. 'zdotaccent': 500,
  8372. 'Ecaron': 667,
  8373. 'Iogonek': 278,
  8374. 'kcommaaccent': 556,
  8375. 'minus': 584,
  8376. 'Icircumflex': 278,
  8377. 'ncaron': 611,
  8378. 'tcommaaccent': 333,
  8379. 'logicalnot': 584,
  8380. 'odieresis': 611,
  8381. 'udieresis': 611,
  8382. 'notequal': 549,
  8383. 'gcommaaccent': 611,
  8384. 'eth': 611,
  8385. 'zcaron': 500,
  8386. 'ncommaaccent': 611,
  8387. 'onesuperior': 333,
  8388. 'imacron': 278,
  8389. 'Euro': 556
  8390. },
  8391. 'Helvetica-Oblique' : {
  8392. 'space': 278,
  8393. 'exclam': 278,
  8394. 'quotedbl': 355,
  8395. 'numbersign': 556,
  8396. 'dollar': 556,
  8397. 'percent': 889,
  8398. 'ampersand': 667,
  8399. 'quoteright': 222,
  8400. 'parenleft': 333,
  8401. 'parenright': 333,
  8402. 'asterisk': 389,
  8403. 'plus': 584,
  8404. 'comma': 278,
  8405. 'hyphen': 333,
  8406. 'period': 278,
  8407. 'slash': 278,
  8408. 'zero': 556,
  8409. 'one': 556,
  8410. 'two': 556,
  8411. 'three': 556,
  8412. 'four': 556,
  8413. 'five': 556,
  8414. 'six': 556,
  8415. 'seven': 556,
  8416. 'eight': 556,
  8417. 'nine': 556,
  8418. 'colon': 278,
  8419. 'semicolon': 278,
  8420. 'less': 584,
  8421. 'equal': 584,
  8422. 'greater': 584,
  8423. 'question': 556,
  8424. 'at': 1015,
  8425. 'A': 667,
  8426. 'B': 667,
  8427. 'C': 722,
  8428. 'D': 722,
  8429. 'E': 667,
  8430. 'F': 611,
  8431. 'G': 778,
  8432. 'H': 722,
  8433. 'I': 278,
  8434. 'J': 500,
  8435. 'K': 667,
  8436. 'L': 556,
  8437. 'M': 833,
  8438. 'N': 722,
  8439. 'O': 778,
  8440. 'P': 667,
  8441. 'Q': 778,
  8442. 'R': 722,
  8443. 'S': 667,
  8444. 'T': 611,
  8445. 'U': 722,
  8446. 'V': 667,
  8447. 'W': 944,
  8448. 'X': 667,
  8449. 'Y': 667,
  8450. 'Z': 611,
  8451. 'bracketleft': 278,
  8452. 'backslash': 278,
  8453. 'bracketright': 278,
  8454. 'asciicircum': 469,
  8455. 'underscore': 556,
  8456. 'quoteleft': 222,
  8457. 'a': 556,
  8458. 'b': 556,
  8459. 'c': 500,
  8460. 'd': 556,
  8461. 'e': 556,
  8462. 'f': 278,
  8463. 'g': 556,
  8464. 'h': 556,
  8465. 'i': 222,
  8466. 'j': 222,
  8467. 'k': 500,
  8468. 'l': 222,
  8469. 'm': 833,
  8470. 'n': 556,
  8471. 'o': 556,
  8472. 'p': 556,
  8473. 'q': 556,
  8474. 'r': 333,
  8475. 's': 500,
  8476. 't': 278,
  8477. 'u': 556,
  8478. 'v': 500,
  8479. 'w': 722,
  8480. 'x': 500,
  8481. 'y': 500,
  8482. 'z': 500,
  8483. 'braceleft': 334,
  8484. 'bar': 260,
  8485. 'braceright': 334,
  8486. 'asciitilde': 584,
  8487. 'exclamdown': 333,
  8488. 'cent': 556,
  8489. 'sterling': 556,
  8490. 'fraction': 167,
  8491. 'yen': 556,
  8492. 'florin': 556,
  8493. 'section': 556,
  8494. 'currency': 556,
  8495. 'quotesingle': 191,
  8496. 'quotedblleft': 333,
  8497. 'guillemotleft': 556,
  8498. 'guilsinglleft': 333,
  8499. 'guilsinglright': 333,
  8500. 'fi': 500,
  8501. 'fl': 500,
  8502. 'endash': 556,
  8503. 'dagger': 556,
  8504. 'daggerdbl': 556,
  8505. 'periodcentered': 278,
  8506. 'paragraph': 537,
  8507. 'bullet': 350,
  8508. 'quotesinglbase': 222,
  8509. 'quotedblbase': 333,
  8510. 'quotedblright': 333,
  8511. 'guillemotright': 556,
  8512. 'ellipsis': 1000,
  8513. 'perthousand': 1000,
  8514. 'questiondown': 611,
  8515. 'grave': 333,
  8516. 'acute': 333,
  8517. 'circumflex': 333,
  8518. 'tilde': 333,
  8519. 'macron': 333,
  8520. 'breve': 333,
  8521. 'dotaccent': 333,
  8522. 'dieresis': 333,
  8523. 'ring': 333,
  8524. 'cedilla': 333,
  8525. 'hungarumlaut': 333,
  8526. 'ogonek': 333,
  8527. 'caron': 333,
  8528. 'emdash': 1000,
  8529. 'AE': 1000,
  8530. 'ordfeminine': 370,
  8531. 'Lslash': 556,
  8532. 'Oslash': 778,
  8533. 'OE': 1000,
  8534. 'ordmasculine': 365,
  8535. 'ae': 889,
  8536. 'dotlessi': 278,
  8537. 'lslash': 222,
  8538. 'oslash': 611,
  8539. 'oe': 944,
  8540. 'germandbls': 611,
  8541. 'Idieresis': 278,
  8542. 'eacute': 556,
  8543. 'abreve': 556,
  8544. 'uhungarumlaut': 556,
  8545. 'ecaron': 556,
  8546. 'Ydieresis': 667,
  8547. 'divide': 584,
  8548. 'Yacute': 667,
  8549. 'Acircumflex': 667,
  8550. 'aacute': 556,
  8551. 'Ucircumflex': 722,
  8552. 'yacute': 500,
  8553. 'scommaaccent': 500,
  8554. 'ecircumflex': 556,
  8555. 'Uring': 722,
  8556. 'Udieresis': 722,
  8557. 'aogonek': 556,
  8558. 'Uacute': 722,
  8559. 'uogonek': 556,
  8560. 'Edieresis': 667,
  8561. 'Dcroat': 722,
  8562. 'commaaccent': 250,
  8563. 'copyright': 737,
  8564. 'Emacron': 667,
  8565. 'ccaron': 500,
  8566. 'aring': 556,
  8567. 'Ncommaaccent': 722,
  8568. 'lacute': 222,
  8569. 'agrave': 556,
  8570. 'Tcommaaccent': 611,
  8571. 'Cacute': 722,
  8572. 'atilde': 556,
  8573. 'Edotaccent': 667,
  8574. 'scaron': 500,
  8575. 'scedilla': 500,
  8576. 'iacute': 278,
  8577. 'lozenge': 471,
  8578. 'Rcaron': 722,
  8579. 'Gcommaaccent': 778,
  8580. 'ucircumflex': 556,
  8581. 'acircumflex': 556,
  8582. 'Amacron': 667,
  8583. 'rcaron': 333,
  8584. 'ccedilla': 500,
  8585. 'Zdotaccent': 611,
  8586. 'Thorn': 667,
  8587. 'Omacron': 778,
  8588. 'Racute': 722,
  8589. 'Sacute': 667,
  8590. 'dcaron': 643,
  8591. 'Umacron': 722,
  8592. 'uring': 556,
  8593. 'threesuperior': 333,
  8594. 'Ograve': 778,
  8595. 'Agrave': 667,
  8596. 'Abreve': 667,
  8597. 'multiply': 584,
  8598. 'uacute': 556,
  8599. 'Tcaron': 611,
  8600. 'partialdiff': 476,
  8601. 'ydieresis': 500,
  8602. 'Nacute': 722,
  8603. 'icircumflex': 278,
  8604. 'Ecircumflex': 667,
  8605. 'adieresis': 556,
  8606. 'edieresis': 556,
  8607. 'cacute': 500,
  8608. 'nacute': 556,
  8609. 'umacron': 556,
  8610. 'Ncaron': 722,
  8611. 'Iacute': 278,
  8612. 'plusminus': 584,
  8613. 'brokenbar': 260,
  8614. 'registered': 737,
  8615. 'Gbreve': 778,
  8616. 'Idotaccent': 278,
  8617. 'summation': 600,
  8618. 'Egrave': 667,
  8619. 'racute': 333,
  8620. 'omacron': 556,
  8621. 'Zacute': 611,
  8622. 'Zcaron': 611,
  8623. 'greaterequal': 549,
  8624. 'Eth': 722,
  8625. 'Ccedilla': 722,
  8626. 'lcommaaccent': 222,
  8627. 'tcaron': 317,
  8628. 'eogonek': 556,
  8629. 'Uogonek': 722,
  8630. 'Aacute': 667,
  8631. 'Adieresis': 667,
  8632. 'egrave': 556,
  8633. 'zacute': 500,
  8634. 'iogonek': 222,
  8635. 'Oacute': 778,
  8636. 'oacute': 556,
  8637. 'amacron': 556,
  8638. 'sacute': 500,
  8639. 'idieresis': 278,
  8640. 'Ocircumflex': 778,
  8641. 'Ugrave': 722,
  8642. 'Delta': 612,
  8643. 'thorn': 556,
  8644. 'twosuperior': 333,
  8645. 'Odieresis': 778,
  8646. 'mu': 556,
  8647. 'igrave': 278,
  8648. 'ohungarumlaut': 556,
  8649. 'Eogonek': 667,
  8650. 'dcroat': 556,
  8651. 'threequarters': 834,
  8652. 'Scedilla': 667,
  8653. 'lcaron': 299,
  8654. 'Kcommaaccent': 667,
  8655. 'Lacute': 556,
  8656. 'trademark': 1000,
  8657. 'edotaccent': 556,
  8658. 'Igrave': 278,
  8659. 'Imacron': 278,
  8660. 'Lcaron': 556,
  8661. 'onehalf': 834,
  8662. 'lessequal': 549,
  8663. 'ocircumflex': 556,
  8664. 'ntilde': 556,
  8665. 'Uhungarumlaut': 722,
  8666. 'Eacute': 667,
  8667. 'emacron': 556,
  8668. 'gbreve': 556,
  8669. 'onequarter': 834,
  8670. 'Scaron': 667,
  8671. 'Scommaaccent': 667,
  8672. 'Ohungarumlaut': 778,
  8673. 'degree': 400,
  8674. 'ograve': 556,
  8675. 'Ccaron': 722,
  8676. 'ugrave': 556,
  8677. 'radical': 453,
  8678. 'Dcaron': 722,
  8679. 'rcommaaccent': 333,
  8680. 'Ntilde': 722,
  8681. 'otilde': 556,
  8682. 'Rcommaaccent': 722,
  8683. 'Lcommaaccent': 556,
  8684. 'Atilde': 667,
  8685. 'Aogonek': 667,
  8686. 'Aring': 667,
  8687. 'Otilde': 778,
  8688. 'zdotaccent': 500,
  8689. 'Ecaron': 667,
  8690. 'Iogonek': 278,
  8691. 'kcommaaccent': 500,
  8692. 'minus': 584,
  8693. 'Icircumflex': 278,
  8694. 'ncaron': 556,
  8695. 'tcommaaccent': 278,
  8696. 'logicalnot': 584,
  8697. 'odieresis': 556,
  8698. 'udieresis': 556,
  8699. 'notequal': 549,
  8700. 'gcommaaccent': 556,
  8701. 'eth': 556,
  8702. 'zcaron': 500,
  8703. 'ncommaaccent': 556,
  8704. 'onesuperior': 333,
  8705. 'imacron': 278,
  8706. 'Euro': 556
  8707. },
  8708. 'Symbol': {
  8709. 'space': 250,
  8710. 'exclam': 333,
  8711. 'universal': 713,
  8712. 'numbersign': 500,
  8713. 'existential': 549,
  8714. 'percent': 833,
  8715. 'ampersand': 778,
  8716. 'suchthat': 439,
  8717. 'parenleft': 333,
  8718. 'parenright': 333,
  8719. 'asteriskmath': 500,
  8720. 'plus': 549,
  8721. 'comma': 250,
  8722. 'minus': 549,
  8723. 'period': 250,
  8724. 'slash': 278,
  8725. 'zero': 500,
  8726. 'one': 500,
  8727. 'two': 500,
  8728. 'three': 500,
  8729. 'four': 500,
  8730. 'five': 500,
  8731. 'six': 500,
  8732. 'seven': 500,
  8733. 'eight': 500,
  8734. 'nine': 500,
  8735. 'colon': 278,
  8736. 'semicolon': 278,
  8737. 'less': 549,
  8738. 'equal': 549,
  8739. 'greater': 549,
  8740. 'question': 444,
  8741. 'congruent': 549,
  8742. 'Alpha': 722,
  8743. 'Beta': 667,
  8744. 'Chi': 722,
  8745. 'Delta': 612,
  8746. 'Epsilon': 611,
  8747. 'Phi': 763,
  8748. 'Gamma': 603,
  8749. 'Eta': 722,
  8750. 'Iota': 333,
  8751. 'theta1': 631,
  8752. 'Kappa': 722,
  8753. 'Lambda': 686,
  8754. 'Mu': 889,
  8755. 'Nu': 722,
  8756. 'Omicron': 722,
  8757. 'Pi': 768,
  8758. 'Theta': 741,
  8759. 'Rho': 556,
  8760. 'Sigma': 592,
  8761. 'Tau': 611,
  8762. 'Upsilon': 690,
  8763. 'sigma1': 439,
  8764. 'Omega': 768,
  8765. 'Xi': 645,
  8766. 'Psi': 795,
  8767. 'Zeta': 611,
  8768. 'bracketleft': 333,
  8769. 'therefore': 863,
  8770. 'bracketright': 333,
  8771. 'perpendicular': 658,
  8772. 'underscore': 500,
  8773. 'radicalex': 500,
  8774. 'alpha': 631,
  8775. 'beta': 549,
  8776. 'chi': 549,
  8777. 'delta': 494,
  8778. 'epsilon': 439,
  8779. 'phi': 521,
  8780. 'gamma': 411,
  8781. 'eta': 603,
  8782. 'iota': 329,
  8783. 'phi1': 603,
  8784. 'kappa': 549,
  8785. 'lambda': 549,
  8786. 'mu': 576,
  8787. 'nu': 521,
  8788. 'omicron': 549,
  8789. 'pi': 549,
  8790. 'theta': 521,
  8791. 'rho': 549,
  8792. 'sigma': 603,
  8793. 'tau': 439,
  8794. 'upsilon': 576,
  8795. 'omega1': 713,
  8796. 'omega': 686,
  8797. 'xi': 493,
  8798. 'psi': 686,
  8799. 'zeta': 494,
  8800. 'braceleft': 480,
  8801. 'bar': 200,
  8802. 'braceright': 480,
  8803. 'similar': 549,
  8804. 'Euro': 750,
  8805. 'Upsilon1': 620,
  8806. 'minute': 247,
  8807. 'lessequal': 549,
  8808. 'fraction': 167,
  8809. 'infinity': 713,
  8810. 'florin': 500,
  8811. 'club': 753,
  8812. 'diamond': 753,
  8813. 'heart': 753,
  8814. 'spade': 753,
  8815. 'arrowboth': 1042,
  8816. 'arrowleft': 987,
  8817. 'arrowup': 603,
  8818. 'arrowright': 987,
  8819. 'arrowdown': 603,
  8820. 'degree': 400,
  8821. 'plusminus': 549,
  8822. 'second': 411,
  8823. 'greaterequal': 549,
  8824. 'multiply': 549,
  8825. 'proportional': 713,
  8826. 'partialdiff': 494,
  8827. 'bullet': 460,
  8828. 'divide': 549,
  8829. 'notequal': 549,
  8830. 'equivalence': 549,
  8831. 'approxequal': 549,
  8832. 'ellipsis': 1000,
  8833. 'arrowvertex': 603,
  8834. 'arrowhorizex': 1000,
  8835. 'carriagereturn': 658,
  8836. 'aleph': 823,
  8837. 'Ifraktur': 686,
  8838. 'Rfraktur': 795,
  8839. 'weierstrass': 987,
  8840. 'circlemultiply': 768,
  8841. 'circleplus': 768,
  8842. 'emptyset': 823,
  8843. 'intersection': 768,
  8844. 'union': 768,
  8845. 'propersuperset': 713,
  8846. 'reflexsuperset': 713,
  8847. 'notsubset': 713,
  8848. 'propersubset': 713,
  8849. 'reflexsubset': 713,
  8850. 'element': 713,
  8851. 'notelement': 713,
  8852. 'angle': 768,
  8853. 'gradient': 713,
  8854. 'registerserif': 790,
  8855. 'copyrightserif': 790,
  8856. 'trademarkserif': 890,
  8857. 'product': 823,
  8858. 'radical': 549,
  8859. 'dotmath': 250,
  8860. 'logicalnot': 713,
  8861. 'logicaland': 603,
  8862. 'logicalor': 603,
  8863. 'arrowdblboth': 1042,
  8864. 'arrowdblleft': 987,
  8865. 'arrowdblup': 603,
  8866. 'arrowdblright': 987,
  8867. 'arrowdbldown': 603,
  8868. 'lozenge': 494,
  8869. 'angleleft': 329,
  8870. 'registersans': 790,
  8871. 'copyrightsans': 790,
  8872. 'trademarksans': 786,
  8873. 'summation': 713,
  8874. 'parenlefttp': 384,
  8875. 'parenleftex': 384,
  8876. 'parenleftbt': 384,
  8877. 'bracketlefttp': 384,
  8878. 'bracketleftex': 384,
  8879. 'bracketleftbt': 384,
  8880. 'bracelefttp': 494,
  8881. 'braceleftmid': 494,
  8882. 'braceleftbt': 494,
  8883. 'braceex': 494,
  8884. 'angleright': 329,
  8885. 'integral': 274,
  8886. 'integraltp': 686,
  8887. 'integralex': 686,
  8888. 'integralbt': 686,
  8889. 'parenrighttp': 384,
  8890. 'parenrightex': 384,
  8891. 'parenrightbt': 384,
  8892. 'bracketrighttp': 384,
  8893. 'bracketrightex': 384,
  8894. 'bracketrightbt': 384,
  8895. 'bracerighttp': 494,
  8896. 'bracerightmid': 494,
  8897. 'bracerightbt': 494,
  8898. 'apple': 790
  8899. },
  8900. 'Times-Roman': {
  8901. 'space': 250,
  8902. 'exclam': 333,
  8903. 'quotedbl': 408,
  8904. 'numbersign': 500,
  8905. 'dollar': 500,
  8906. 'percent': 833,
  8907. 'ampersand': 778,
  8908. 'quoteright': 333,
  8909. 'parenleft': 333,
  8910. 'parenright': 333,
  8911. 'asterisk': 500,
  8912. 'plus': 564,
  8913. 'comma': 250,
  8914. 'hyphen': 333,
  8915. 'period': 250,
  8916. 'slash': 278,
  8917. 'zero': 500,
  8918. 'one': 500,
  8919. 'two': 500,
  8920. 'three': 500,
  8921. 'four': 500,
  8922. 'five': 500,
  8923. 'six': 500,
  8924. 'seven': 500,
  8925. 'eight': 500,
  8926. 'nine': 500,
  8927. 'colon': 278,
  8928. 'semicolon': 278,
  8929. 'less': 564,
  8930. 'equal': 564,
  8931. 'greater': 564,
  8932. 'question': 444,
  8933. 'at': 921,
  8934. 'A': 722,
  8935. 'B': 667,
  8936. 'C': 667,
  8937. 'D': 722,
  8938. 'E': 611,
  8939. 'F': 556,
  8940. 'G': 722,
  8941. 'H': 722,
  8942. 'I': 333,
  8943. 'J': 389,
  8944. 'K': 722,
  8945. 'L': 611,
  8946. 'M': 889,
  8947. 'N': 722,
  8948. 'O': 722,
  8949. 'P': 556,
  8950. 'Q': 722,
  8951. 'R': 667,
  8952. 'S': 556,
  8953. 'T': 611,
  8954. 'U': 722,
  8955. 'V': 722,
  8956. 'W': 944,
  8957. 'X': 722,
  8958. 'Y': 722,
  8959. 'Z': 611,
  8960. 'bracketleft': 333,
  8961. 'backslash': 278,
  8962. 'bracketright': 333,
  8963. 'asciicircum': 469,
  8964. 'underscore': 500,
  8965. 'quoteleft': 333,
  8966. 'a': 444,
  8967. 'b': 500,
  8968. 'c': 444,
  8969. 'd': 500,
  8970. 'e': 444,
  8971. 'f': 333,
  8972. 'g': 500,
  8973. 'h': 500,
  8974. 'i': 278,
  8975. 'j': 278,
  8976. 'k': 500,
  8977. 'l': 278,
  8978. 'm': 778,
  8979. 'n': 500,
  8980. 'o': 500,
  8981. 'p': 500,
  8982. 'q': 500,
  8983. 'r': 333,
  8984. 's': 389,
  8985. 't': 278,
  8986. 'u': 500,
  8987. 'v': 500,
  8988. 'w': 722,
  8989. 'x': 500,
  8990. 'y': 500,
  8991. 'z': 444,
  8992. 'braceleft': 480,
  8993. 'bar': 200,
  8994. 'braceright': 480,
  8995. 'asciitilde': 541,
  8996. 'exclamdown': 333,
  8997. 'cent': 500,
  8998. 'sterling': 500,
  8999. 'fraction': 167,
  9000. 'yen': 500,
  9001. 'florin': 500,
  9002. 'section': 500,
  9003. 'currency': 500,
  9004. 'quotesingle': 180,
  9005. 'quotedblleft': 444,
  9006. 'guillemotleft': 500,
  9007. 'guilsinglleft': 333,
  9008. 'guilsinglright': 333,
  9009. 'fi': 556,
  9010. 'fl': 556,
  9011. 'endash': 500,
  9012. 'dagger': 500,
  9013. 'daggerdbl': 500,
  9014. 'periodcentered': 250,
  9015. 'paragraph': 453,
  9016. 'bullet': 350,
  9017. 'quotesinglbase': 333,
  9018. 'quotedblbase': 444,
  9019. 'quotedblright': 444,
  9020. 'guillemotright': 500,
  9021. 'ellipsis': 1000,
  9022. 'perthousand': 1000,
  9023. 'questiondown': 444,
  9024. 'grave': 333,
  9025. 'acute': 333,
  9026. 'circumflex': 333,
  9027. 'tilde': 333,
  9028. 'macron': 333,
  9029. 'breve': 333,
  9030. 'dotaccent': 333,
  9031. 'dieresis': 333,
  9032. 'ring': 333,
  9033. 'cedilla': 333,
  9034. 'hungarumlaut': 333,
  9035. 'ogonek': 333,
  9036. 'caron': 333,
  9037. 'emdash': 1000,
  9038. 'AE': 889,
  9039. 'ordfeminine': 276,
  9040. 'Lslash': 611,
  9041. 'Oslash': 722,
  9042. 'OE': 889,
  9043. 'ordmasculine': 310,
  9044. 'ae': 667,
  9045. 'dotlessi': 278,
  9046. 'lslash': 278,
  9047. 'oslash': 500,
  9048. 'oe': 722,
  9049. 'germandbls': 500,
  9050. 'Idieresis': 333,
  9051. 'eacute': 444,
  9052. 'abreve': 444,
  9053. 'uhungarumlaut': 500,
  9054. 'ecaron': 444,
  9055. 'Ydieresis': 722,
  9056. 'divide': 564,
  9057. 'Yacute': 722,
  9058. 'Acircumflex': 722,
  9059. 'aacute': 444,
  9060. 'Ucircumflex': 722,
  9061. 'yacute': 500,
  9062. 'scommaaccent': 389,
  9063. 'ecircumflex': 444,
  9064. 'Uring': 722,
  9065. 'Udieresis': 722,
  9066. 'aogonek': 444,
  9067. 'Uacute': 722,
  9068. 'uogonek': 500,
  9069. 'Edieresis': 611,
  9070. 'Dcroat': 722,
  9071. 'commaaccent': 250,
  9072. 'copyright': 760,
  9073. 'Emacron': 611,
  9074. 'ccaron': 444,
  9075. 'aring': 444,
  9076. 'Ncommaaccent': 722,
  9077. 'lacute': 278,
  9078. 'agrave': 444,
  9079. 'Tcommaaccent': 611,
  9080. 'Cacute': 667,
  9081. 'atilde': 444,
  9082. 'Edotaccent': 611,
  9083. 'scaron': 389,
  9084. 'scedilla': 389,
  9085. 'iacute': 278,
  9086. 'lozenge': 471,
  9087. 'Rcaron': 667,
  9088. 'Gcommaaccent': 722,
  9089. 'ucircumflex': 500,
  9090. 'acircumflex': 444,
  9091. 'Amacron': 722,
  9092. 'rcaron': 333,
  9093. 'ccedilla': 444,
  9094. 'Zdotaccent': 611,
  9095. 'Thorn': 556,
  9096. 'Omacron': 722,
  9097. 'Racute': 667,
  9098. 'Sacute': 556,
  9099. 'dcaron': 588,
  9100. 'Umacron': 722,
  9101. 'uring': 500,
  9102. 'threesuperior': 300,
  9103. 'Ograve': 722,
  9104. 'Agrave': 722,
  9105. 'Abreve': 722,
  9106. 'multiply': 564,
  9107. 'uacute': 500,
  9108. 'Tcaron': 611,
  9109. 'partialdiff': 476,
  9110. 'ydieresis': 500,
  9111. 'Nacute': 722,
  9112. 'icircumflex': 278,
  9113. 'Ecircumflex': 611,
  9114. 'adieresis': 444,
  9115. 'edieresis': 444,
  9116. 'cacute': 444,
  9117. 'nacute': 500,
  9118. 'umacron': 500,
  9119. 'Ncaron': 722,
  9120. 'Iacute': 333,
  9121. 'plusminus': 564,
  9122. 'brokenbar': 200,
  9123. 'registered': 760,
  9124. 'Gbreve': 722,
  9125. 'Idotaccent': 333,
  9126. 'summation': 600,
  9127. 'Egrave': 611,
  9128. 'racute': 333,
  9129. 'omacron': 500,
  9130. 'Zacute': 611,
  9131. 'Zcaron': 611,
  9132. 'greaterequal': 549,
  9133. 'Eth': 722,
  9134. 'Ccedilla': 667,
  9135. 'lcommaaccent': 278,
  9136. 'tcaron': 326,
  9137. 'eogonek': 444,
  9138. 'Uogonek': 722,
  9139. 'Aacute': 722,
  9140. 'Adieresis': 722,
  9141. 'egrave': 444,
  9142. 'zacute': 444,
  9143. 'iogonek': 278,
  9144. 'Oacute': 722,
  9145. 'oacute': 500,
  9146. 'amacron': 444,
  9147. 'sacute': 389,
  9148. 'idieresis': 278,
  9149. 'Ocircumflex': 722,
  9150. 'Ugrave': 722,
  9151. 'Delta': 612,
  9152. 'thorn': 500,
  9153. 'twosuperior': 300,
  9154. 'Odieresis': 722,
  9155. 'mu': 500,
  9156. 'igrave': 278,
  9157. 'ohungarumlaut': 500,
  9158. 'Eogonek': 611,
  9159. 'dcroat': 500,
  9160. 'threequarters': 750,
  9161. 'Scedilla': 556,
  9162. 'lcaron': 344,
  9163. 'Kcommaaccent': 722,
  9164. 'Lacute': 611,
  9165. 'trademark': 980,
  9166. 'edotaccent': 444,
  9167. 'Igrave': 333,
  9168. 'Imacron': 333,
  9169. 'Lcaron': 611,
  9170. 'onehalf': 750,
  9171. 'lessequal': 549,
  9172. 'ocircumflex': 500,
  9173. 'ntilde': 500,
  9174. 'Uhungarumlaut': 722,
  9175. 'Eacute': 611,
  9176. 'emacron': 444,
  9177. 'gbreve': 500,
  9178. 'onequarter': 750,
  9179. 'Scaron': 556,
  9180. 'Scommaaccent': 556,
  9181. 'Ohungarumlaut': 722,
  9182. 'degree': 400,
  9183. 'ograve': 500,
  9184. 'Ccaron': 667,
  9185. 'ugrave': 500,
  9186. 'radical': 453,
  9187. 'Dcaron': 722,
  9188. 'rcommaaccent': 333,
  9189. 'Ntilde': 722,
  9190. 'otilde': 500,
  9191. 'Rcommaaccent': 667,
  9192. 'Lcommaaccent': 611,
  9193. 'Atilde': 722,
  9194. 'Aogonek': 722,
  9195. 'Aring': 722,
  9196. 'Otilde': 722,
  9197. 'zdotaccent': 444,
  9198. 'Ecaron': 611,
  9199. 'Iogonek': 333,
  9200. 'kcommaaccent': 500,
  9201. 'minus': 564,
  9202. 'Icircumflex': 333,
  9203. 'ncaron': 500,
  9204. 'tcommaaccent': 278,
  9205. 'logicalnot': 564,
  9206. 'odieresis': 500,
  9207. 'udieresis': 500,
  9208. 'notequal': 549,
  9209. 'gcommaaccent': 500,
  9210. 'eth': 500,
  9211. 'zcaron': 444,
  9212. 'ncommaaccent': 500,
  9213. 'onesuperior': 300,
  9214. 'imacron': 278,
  9215. 'Euro': 500
  9216. },
  9217. 'Times-Bold': {
  9218. 'space': 250,
  9219. 'exclam': 333,
  9220. 'quotedbl': 555,
  9221. 'numbersign': 500,
  9222. 'dollar': 500,
  9223. 'percent': 1000,
  9224. 'ampersand': 833,
  9225. 'quoteright': 333,
  9226. 'parenleft': 333,
  9227. 'parenright': 333,
  9228. 'asterisk': 500,
  9229. 'plus': 570,
  9230. 'comma': 250,
  9231. 'hyphen': 333,
  9232. 'period': 250,
  9233. 'slash': 278,
  9234. 'zero': 500,
  9235. 'one': 500,
  9236. 'two': 500,
  9237. 'three': 500,
  9238. 'four': 500,
  9239. 'five': 500,
  9240. 'six': 500,
  9241. 'seven': 500,
  9242. 'eight': 500,
  9243. 'nine': 500,
  9244. 'colon': 333,
  9245. 'semicolon': 333,
  9246. 'less': 570,
  9247. 'equal': 570,
  9248. 'greater': 570,
  9249. 'question': 500,
  9250. 'at': 930,
  9251. 'A': 722,
  9252. 'B': 667,
  9253. 'C': 722,
  9254. 'D': 722,
  9255. 'E': 667,
  9256. 'F': 611,
  9257. 'G': 778,
  9258. 'H': 778,
  9259. 'I': 389,
  9260. 'J': 500,
  9261. 'K': 778,
  9262. 'L': 667,
  9263. 'M': 944,
  9264. 'N': 722,
  9265. 'O': 778,
  9266. 'P': 611,
  9267. 'Q': 778,
  9268. 'R': 722,
  9269. 'S': 556,
  9270. 'T': 667,
  9271. 'U': 722,
  9272. 'V': 722,
  9273. 'W': 1000,
  9274. 'X': 722,
  9275. 'Y': 722,
  9276. 'Z': 667,
  9277. 'bracketleft': 333,
  9278. 'backslash': 278,
  9279. 'bracketright': 333,
  9280. 'asciicircum': 581,
  9281. 'underscore': 500,
  9282. 'quoteleft': 333,
  9283. 'a': 500,
  9284. 'b': 556,
  9285. 'c': 444,
  9286. 'd': 556,
  9287. 'e': 444,
  9288. 'f': 333,
  9289. 'g': 500,
  9290. 'h': 556,
  9291. 'i': 278,
  9292. 'j': 333,
  9293. 'k': 556,
  9294. 'l': 278,
  9295. 'm': 833,
  9296. 'n': 556,
  9297. 'o': 500,
  9298. 'p': 556,
  9299. 'q': 556,
  9300. 'r': 444,
  9301. 's': 389,
  9302. 't': 333,
  9303. 'u': 556,
  9304. 'v': 500,
  9305. 'w': 722,
  9306. 'x': 500,
  9307. 'y': 500,
  9308. 'z': 444,
  9309. 'braceleft': 394,
  9310. 'bar': 220,
  9311. 'braceright': 394,
  9312. 'asciitilde': 520,
  9313. 'exclamdown': 333,
  9314. 'cent': 500,
  9315. 'sterling': 500,
  9316. 'fraction': 167,
  9317. 'yen': 500,
  9318. 'florin': 500,
  9319. 'section': 500,
  9320. 'currency': 500,
  9321. 'quotesingle': 278,
  9322. 'quotedblleft': 500,
  9323. 'guillemotleft': 500,
  9324. 'guilsinglleft': 333,
  9325. 'guilsinglright': 333,
  9326. 'fi': 556,
  9327. 'fl': 556,
  9328. 'endash': 500,
  9329. 'dagger': 500,
  9330. 'daggerdbl': 500,
  9331. 'periodcentered': 250,
  9332. 'paragraph': 540,
  9333. 'bullet': 350,
  9334. 'quotesinglbase': 333,
  9335. 'quotedblbase': 500,
  9336. 'quotedblright': 500,
  9337. 'guillemotright': 500,
  9338. 'ellipsis': 1000,
  9339. 'perthousand': 1000,
  9340. 'questiondown': 500,
  9341. 'grave': 333,
  9342. 'acute': 333,
  9343. 'circumflex': 333,
  9344. 'tilde': 333,
  9345. 'macron': 333,
  9346. 'breve': 333,
  9347. 'dotaccent': 333,
  9348. 'dieresis': 333,
  9349. 'ring': 333,
  9350. 'cedilla': 333,
  9351. 'hungarumlaut': 333,
  9352. 'ogonek': 333,
  9353. 'caron': 333,
  9354. 'emdash': 1000,
  9355. 'AE': 1000,
  9356. 'ordfeminine': 300,
  9357. 'Lslash': 667,
  9358. 'Oslash': 778,
  9359. 'OE': 1000,
  9360. 'ordmasculine': 330,
  9361. 'ae': 722,
  9362. 'dotlessi': 278,
  9363. 'lslash': 278,
  9364. 'oslash': 500,
  9365. 'oe': 722,
  9366. 'germandbls': 556,
  9367. 'Idieresis': 389,
  9368. 'eacute': 444,
  9369. 'abreve': 500,
  9370. 'uhungarumlaut': 556,
  9371. 'ecaron': 444,
  9372. 'Ydieresis': 722,
  9373. 'divide': 570,
  9374. 'Yacute': 722,
  9375. 'Acircumflex': 722,
  9376. 'aacute': 500,
  9377. 'Ucircumflex': 722,
  9378. 'yacute': 500,
  9379. 'scommaaccent': 389,
  9380. 'ecircumflex': 444,
  9381. 'Uring': 722,
  9382. 'Udieresis': 722,
  9383. 'aogonek': 500,
  9384. 'Uacute': 722,
  9385. 'uogonek': 556,
  9386. 'Edieresis': 667,
  9387. 'Dcroat': 722,
  9388. 'commaaccent': 250,
  9389. 'copyright': 747,
  9390. 'Emacron': 667,
  9391. 'ccaron': 444,
  9392. 'aring': 500,
  9393. 'Ncommaaccent': 722,
  9394. 'lacute': 278,
  9395. 'agrave': 500,
  9396. 'Tcommaaccent': 667,
  9397. 'Cacute': 722,
  9398. 'atilde': 500,
  9399. 'Edotaccent': 667,
  9400. 'scaron': 389,
  9401. 'scedilla': 389,
  9402. 'iacute': 278,
  9403. 'lozenge': 494,
  9404. 'Rcaron': 722,
  9405. 'Gcommaaccent': 778,
  9406. 'ucircumflex': 556,
  9407. 'acircumflex': 500,
  9408. 'Amacron': 722,
  9409. 'rcaron': 444,
  9410. 'ccedilla': 444,
  9411. 'Zdotaccent': 667,
  9412. 'Thorn': 611,
  9413. 'Omacron': 778,
  9414. 'Racute': 722,
  9415. 'Sacute': 556,
  9416. 'dcaron': 672,
  9417. 'Umacron': 722,
  9418. 'uring': 556,
  9419. 'threesuperior': 300,
  9420. 'Ograve': 778,
  9421. 'Agrave': 722,
  9422. 'Abreve': 722,
  9423. 'multiply': 570,
  9424. 'uacute': 556,
  9425. 'Tcaron': 667,
  9426. 'partialdiff': 494,
  9427. 'ydieresis': 500,
  9428. 'Nacute': 722,
  9429. 'icircumflex': 278,
  9430. 'Ecircumflex': 667,
  9431. 'adieresis': 500,
  9432. 'edieresis': 444,
  9433. 'cacute': 444,
  9434. 'nacute': 556,
  9435. 'umacron': 556,
  9436. 'Ncaron': 722,
  9437. 'Iacute': 389,
  9438. 'plusminus': 570,
  9439. 'brokenbar': 220,
  9440. 'registered': 747,
  9441. 'Gbreve': 778,
  9442. 'Idotaccent': 389,
  9443. 'summation': 600,
  9444. 'Egrave': 667,
  9445. 'racute': 444,
  9446. 'omacron': 500,
  9447. 'Zacute': 667,
  9448. 'Zcaron': 667,
  9449. 'greaterequal': 549,
  9450. 'Eth': 722,
  9451. 'Ccedilla': 722,
  9452. 'lcommaaccent': 278,
  9453. 'tcaron': 416,
  9454. 'eogonek': 444,
  9455. 'Uogonek': 722,
  9456. 'Aacute': 722,
  9457. 'Adieresis': 722,
  9458. 'egrave': 444,
  9459. 'zacute': 444,
  9460. 'iogonek': 278,
  9461. 'Oacute': 778,
  9462. 'oacute': 500,
  9463. 'amacron': 500,
  9464. 'sacute': 389,
  9465. 'idieresis': 278,
  9466. 'Ocircumflex': 778,
  9467. 'Ugrave': 722,
  9468. 'Delta': 612,
  9469. 'thorn': 556,
  9470. 'twosuperior': 300,
  9471. 'Odieresis': 778,
  9472. 'mu': 556,
  9473. 'igrave': 278,
  9474. 'ohungarumlaut': 500,
  9475. 'Eogonek': 667,
  9476. 'dcroat': 556,
  9477. 'threequarters': 750,
  9478. 'Scedilla': 556,
  9479. 'lcaron': 394,
  9480. 'Kcommaaccent': 778,
  9481. 'Lacute': 667,
  9482. 'trademark': 1000,
  9483. 'edotaccent': 444,
  9484. 'Igrave': 389,
  9485. 'Imacron': 389,
  9486. 'Lcaron': 667,
  9487. 'onehalf': 750,
  9488. 'lessequal': 549,
  9489. 'ocircumflex': 500,
  9490. 'ntilde': 556,
  9491. 'Uhungarumlaut': 722,
  9492. 'Eacute': 667,
  9493. 'emacron': 444,
  9494. 'gbreve': 500,
  9495. 'onequarter': 750,
  9496. 'Scaron': 556,
  9497. 'Scommaaccent': 556,
  9498. 'Ohungarumlaut': 778,
  9499. 'degree': 400,
  9500. 'ograve': 500,
  9501. 'Ccaron': 722,
  9502. 'ugrave': 556,
  9503. 'radical': 549,
  9504. 'Dcaron': 722,
  9505. 'rcommaaccent': 444,
  9506. 'Ntilde': 722,
  9507. 'otilde': 500,
  9508. 'Rcommaaccent': 722,
  9509. 'Lcommaaccent': 667,
  9510. 'Atilde': 722,
  9511. 'Aogonek': 722,
  9512. 'Aring': 722,
  9513. 'Otilde': 778,
  9514. 'zdotaccent': 444,
  9515. 'Ecaron': 667,
  9516. 'Iogonek': 389,
  9517. 'kcommaaccent': 556,
  9518. 'minus': 570,
  9519. 'Icircumflex': 389,
  9520. 'ncaron': 556,
  9521. 'tcommaaccent': 333,
  9522. 'logicalnot': 570,
  9523. 'odieresis': 500,
  9524. 'udieresis': 556,
  9525. 'notequal': 549,
  9526. 'gcommaaccent': 500,
  9527. 'eth': 500,
  9528. 'zcaron': 444,
  9529. 'ncommaaccent': 556,
  9530. 'onesuperior': 300,
  9531. 'imacron': 278,
  9532. 'Euro': 500
  9533. },
  9534. 'Times-BoldItalic': {
  9535. 'space': 250,
  9536. 'exclam': 389,
  9537. 'quotedbl': 555,
  9538. 'numbersign': 500,
  9539. 'dollar': 500,
  9540. 'percent': 833,
  9541. 'ampersand': 778,
  9542. 'quoteright': 333,
  9543. 'parenleft': 333,
  9544. 'parenright': 333,
  9545. 'asterisk': 500,
  9546. 'plus': 570,
  9547. 'comma': 250,
  9548. 'hyphen': 333,
  9549. 'period': 250,
  9550. 'slash': 278,
  9551. 'zero': 500,
  9552. 'one': 500,
  9553. 'two': 500,
  9554. 'three': 500,
  9555. 'four': 500,
  9556. 'five': 500,
  9557. 'six': 500,
  9558. 'seven': 500,
  9559. 'eight': 500,
  9560. 'nine': 500,
  9561. 'colon': 333,
  9562. 'semicolon': 333,
  9563. 'less': 570,
  9564. 'equal': 570,
  9565. 'greater': 570,
  9566. 'question': 500,
  9567. 'at': 832,
  9568. 'A': 667,
  9569. 'B': 667,
  9570. 'C': 667,
  9571. 'D': 722,
  9572. 'E': 667,
  9573. 'F': 667,
  9574. 'G': 722,
  9575. 'H': 778,
  9576. 'I': 389,
  9577. 'J': 500,
  9578. 'K': 667,
  9579. 'L': 611,
  9580. 'M': 889,
  9581. 'N': 722,
  9582. 'O': 722,
  9583. 'P': 611,
  9584. 'Q': 722,
  9585. 'R': 667,
  9586. 'S': 556,
  9587. 'T': 611,
  9588. 'U': 722,
  9589. 'V': 667,
  9590. 'W': 889,
  9591. 'X': 667,
  9592. 'Y': 611,
  9593. 'Z': 611,
  9594. 'bracketleft': 333,
  9595. 'backslash': 278,
  9596. 'bracketright': 333,
  9597. 'asciicircum': 570,
  9598. 'underscore': 500,
  9599. 'quoteleft': 333,
  9600. 'a': 500,
  9601. 'b': 500,
  9602. 'c': 444,
  9603. 'd': 500,
  9604. 'e': 444,
  9605. 'f': 333,
  9606. 'g': 500,
  9607. 'h': 556,
  9608. 'i': 278,
  9609. 'j': 278,
  9610. 'k': 500,
  9611. 'l': 278,
  9612. 'm': 778,
  9613. 'n': 556,
  9614. 'o': 500,
  9615. 'p': 500,
  9616. 'q': 500,
  9617. 'r': 389,
  9618. 's': 389,
  9619. 't': 278,
  9620. 'u': 556,
  9621. 'v': 444,
  9622. 'w': 667,
  9623. 'x': 500,
  9624. 'y': 444,
  9625. 'z': 389,
  9626. 'braceleft': 348,
  9627. 'bar': 220,
  9628. 'braceright': 348,
  9629. 'asciitilde': 570,
  9630. 'exclamdown': 389,
  9631. 'cent': 500,
  9632. 'sterling': 500,
  9633. 'fraction': 167,
  9634. 'yen': 500,
  9635. 'florin': 500,
  9636. 'section': 500,
  9637. 'currency': 500,
  9638. 'quotesingle': 278,
  9639. 'quotedblleft': 500,
  9640. 'guillemotleft': 500,
  9641. 'guilsinglleft': 333,
  9642. 'guilsinglright': 333,
  9643. 'fi': 556,
  9644. 'fl': 556,
  9645. 'endash': 500,
  9646. 'dagger': 500,
  9647. 'daggerdbl': 500,
  9648. 'periodcentered': 250,
  9649. 'paragraph': 500,
  9650. 'bullet': 350,
  9651. 'quotesinglbase': 333,
  9652. 'quotedblbase': 500,
  9653. 'quotedblright': 500,
  9654. 'guillemotright': 500,
  9655. 'ellipsis': 1000,
  9656. 'perthousand': 1000,
  9657. 'questiondown': 500,
  9658. 'grave': 333,
  9659. 'acute': 333,
  9660. 'circumflex': 333,
  9661. 'tilde': 333,
  9662. 'macron': 333,
  9663. 'breve': 333,
  9664. 'dotaccent': 333,
  9665. 'dieresis': 333,
  9666. 'ring': 333,
  9667. 'cedilla': 333,
  9668. 'hungarumlaut': 333,
  9669. 'ogonek': 333,
  9670. 'caron': 333,
  9671. 'emdash': 1000,
  9672. 'AE': 944,
  9673. 'ordfeminine': 266,
  9674. 'Lslash': 611,
  9675. 'Oslash': 722,
  9676. 'OE': 944,
  9677. 'ordmasculine': 300,
  9678. 'ae': 722,
  9679. 'dotlessi': 278,
  9680. 'lslash': 278,
  9681. 'oslash': 500,
  9682. 'oe': 722,
  9683. 'germandbls': 500,
  9684. 'Idieresis': 389,
  9685. 'eacute': 444,
  9686. 'abreve': 500,
  9687. 'uhungarumlaut': 556,
  9688. 'ecaron': 444,
  9689. 'Ydieresis': 611,
  9690. 'divide': 570,
  9691. 'Yacute': 611,
  9692. 'Acircumflex': 667,
  9693. 'aacute': 500,
  9694. 'Ucircumflex': 722,
  9695. 'yacute': 444,
  9696. 'scommaaccent': 389,
  9697. 'ecircumflex': 444,
  9698. 'Uring': 722,
  9699. 'Udieresis': 722,
  9700. 'aogonek': 500,
  9701. 'Uacute': 722,
  9702. 'uogonek': 556,
  9703. 'Edieresis': 667,
  9704. 'Dcroat': 722,
  9705. 'commaaccent': 250,
  9706. 'copyright': 747,
  9707. 'Emacron': 667,
  9708. 'ccaron': 444,
  9709. 'aring': 500,
  9710. 'Ncommaaccent': 722,
  9711. 'lacute': 278,
  9712. 'agrave': 500,
  9713. 'Tcommaaccent': 611,
  9714. 'Cacute': 667,
  9715. 'atilde': 500,
  9716. 'Edotaccent': 667,
  9717. 'scaron': 389,
  9718. 'scedilla': 389,
  9719. 'iacute': 278,
  9720. 'lozenge': 494,
  9721. 'Rcaron': 667,
  9722. 'Gcommaaccent': 722,
  9723. 'ucircumflex': 556,
  9724. 'acircumflex': 500,
  9725. 'Amacron': 667,
  9726. 'rcaron': 389,
  9727. 'ccedilla': 444,
  9728. 'Zdotaccent': 611,
  9729. 'Thorn': 611,
  9730. 'Omacron': 722,
  9731. 'Racute': 667,
  9732. 'Sacute': 556,
  9733. 'dcaron': 608,
  9734. 'Umacron': 722,
  9735. 'uring': 556,
  9736. 'threesuperior': 300,
  9737. 'Ograve': 722,
  9738. 'Agrave': 667,
  9739. 'Abreve': 667,
  9740. 'multiply': 570,
  9741. 'uacute': 556,
  9742. 'Tcaron': 611,
  9743. 'partialdiff': 494,
  9744. 'ydieresis': 444,
  9745. 'Nacute': 722,
  9746. 'icircumflex': 278,
  9747. 'Ecircumflex': 667,
  9748. 'adieresis': 500,
  9749. 'edieresis': 444,
  9750. 'cacute': 444,
  9751. 'nacute': 556,
  9752. 'umacron': 556,
  9753. 'Ncaron': 722,
  9754. 'Iacute': 389,
  9755. 'plusminus': 570,
  9756. 'brokenbar': 220,
  9757. 'registered': 747,
  9758. 'Gbreve': 722,
  9759. 'Idotaccent': 389,
  9760. 'summation': 600,
  9761. 'Egrave': 667,
  9762. 'racute': 389,
  9763. 'omacron': 500,
  9764. 'Zacute': 611,
  9765. 'Zcaron': 611,
  9766. 'greaterequal': 549,
  9767. 'Eth': 722,
  9768. 'Ccedilla': 667,
  9769. 'lcommaaccent': 278,
  9770. 'tcaron': 366,
  9771. 'eogonek': 444,
  9772. 'Uogonek': 722,
  9773. 'Aacute': 667,
  9774. 'Adieresis': 667,
  9775. 'egrave': 444,
  9776. 'zacute': 389,
  9777. 'iogonek': 278,
  9778. 'Oacute': 722,
  9779. 'oacute': 500,
  9780. 'amacron': 500,
  9781. 'sacute': 389,
  9782. 'idieresis': 278,
  9783. 'Ocircumflex': 722,
  9784. 'Ugrave': 722,
  9785. 'Delta': 612,
  9786. 'thorn': 500,
  9787. 'twosuperior': 300,
  9788. 'Odieresis': 722,
  9789. 'mu': 576,
  9790. 'igrave': 278,
  9791. 'ohungarumlaut': 500,
  9792. 'Eogonek': 667,
  9793. 'dcroat': 500,
  9794. 'threequarters': 750,
  9795. 'Scedilla': 556,
  9796. 'lcaron': 382,
  9797. 'Kcommaaccent': 667,
  9798. 'Lacute': 611,
  9799. 'trademark': 1000,
  9800. 'edotaccent': 444,
  9801. 'Igrave': 389,
  9802. 'Imacron': 389,
  9803. 'Lcaron': 611,
  9804. 'onehalf': 750,
  9805. 'lessequal': 549,
  9806. 'ocircumflex': 500,
  9807. 'ntilde': 556,
  9808. 'Uhungarumlaut': 722,
  9809. 'Eacute': 667,
  9810. 'emacron': 444,
  9811. 'gbreve': 500,
  9812. 'onequarter': 750,
  9813. 'Scaron': 556,
  9814. 'Scommaaccent': 556,
  9815. 'Ohungarumlaut': 722,
  9816. 'degree': 400,
  9817. 'ograve': 500,
  9818. 'Ccaron': 667,
  9819. 'ugrave': 556,
  9820. 'radical': 549,
  9821. 'Dcaron': 722,
  9822. 'rcommaaccent': 389,
  9823. 'Ntilde': 722,
  9824. 'otilde': 500,
  9825. 'Rcommaaccent': 667,
  9826. 'Lcommaaccent': 611,
  9827. 'Atilde': 667,
  9828. 'Aogonek': 667,
  9829. 'Aring': 667,
  9830. 'Otilde': 722,
  9831. 'zdotaccent': 389,
  9832. 'Ecaron': 667,
  9833. 'Iogonek': 389,
  9834. 'kcommaaccent': 500,
  9835. 'minus': 606,
  9836. 'Icircumflex': 389,
  9837. 'ncaron': 556,
  9838. 'tcommaaccent': 278,
  9839. 'logicalnot': 606,
  9840. 'odieresis': 500,
  9841. 'udieresis': 556,
  9842. 'notequal': 549,
  9843. 'gcommaaccent': 500,
  9844. 'eth': 500,
  9845. 'zcaron': 389,
  9846. 'ncommaaccent': 556,
  9847. 'onesuperior': 300,
  9848. 'imacron': 278,
  9849. 'Euro': 500
  9850. },
  9851. 'Times-Italic': {
  9852. 'space': 250,
  9853. 'exclam': 333,
  9854. 'quotedbl': 420,
  9855. 'numbersign': 500,
  9856. 'dollar': 500,
  9857. 'percent': 833,
  9858. 'ampersand': 778,
  9859. 'quoteright': 333,
  9860. 'parenleft': 333,
  9861. 'parenright': 333,
  9862. 'asterisk': 500,
  9863. 'plus': 675,
  9864. 'comma': 250,
  9865. 'hyphen': 333,
  9866. 'period': 250,
  9867. 'slash': 278,
  9868. 'zero': 500,
  9869. 'one': 500,
  9870. 'two': 500,
  9871. 'three': 500,
  9872. 'four': 500,
  9873. 'five': 500,
  9874. 'six': 500,
  9875. 'seven': 500,
  9876. 'eight': 500,
  9877. 'nine': 500,
  9878. 'colon': 333,
  9879. 'semicolon': 333,
  9880. 'less': 675,
  9881. 'equal': 675,
  9882. 'greater': 675,
  9883. 'question': 500,
  9884. 'at': 920,
  9885. 'A': 611,
  9886. 'B': 611,
  9887. 'C': 667,
  9888. 'D': 722,
  9889. 'E': 611,
  9890. 'F': 611,
  9891. 'G': 722,
  9892. 'H': 722,
  9893. 'I': 333,
  9894. 'J': 444,
  9895. 'K': 667,
  9896. 'L': 556,
  9897. 'M': 833,
  9898. 'N': 667,
  9899. 'O': 722,
  9900. 'P': 611,
  9901. 'Q': 722,
  9902. 'R': 611,
  9903. 'S': 500,
  9904. 'T': 556,
  9905. 'U': 722,
  9906. 'V': 611,
  9907. 'W': 833,
  9908. 'X': 611,
  9909. 'Y': 556,
  9910. 'Z': 556,
  9911. 'bracketleft': 389,
  9912. 'backslash': 278,
  9913. 'bracketright': 389,
  9914. 'asciicircum': 422,
  9915. 'underscore': 500,
  9916. 'quoteleft': 333,
  9917. 'a': 500,
  9918. 'b': 500,
  9919. 'c': 444,
  9920. 'd': 500,
  9921. 'e': 444,
  9922. 'f': 278,
  9923. 'g': 500,
  9924. 'h': 500,
  9925. 'i': 278,
  9926. 'j': 278,
  9927. 'k': 444,
  9928. 'l': 278,
  9929. 'm': 722,
  9930. 'n': 500,
  9931. 'o': 500,
  9932. 'p': 500,
  9933. 'q': 500,
  9934. 'r': 389,
  9935. 's': 389,
  9936. 't': 278,
  9937. 'u': 500,
  9938. 'v': 444,
  9939. 'w': 667,
  9940. 'x': 444,
  9941. 'y': 444,
  9942. 'z': 389,
  9943. 'braceleft': 400,
  9944. 'bar': 275,
  9945. 'braceright': 400,
  9946. 'asciitilde': 541,
  9947. 'exclamdown': 389,
  9948. 'cent': 500,
  9949. 'sterling': 500,
  9950. 'fraction': 167,
  9951. 'yen': 500,
  9952. 'florin': 500,
  9953. 'section': 500,
  9954. 'currency': 500,
  9955. 'quotesingle': 214,
  9956. 'quotedblleft': 556,
  9957. 'guillemotleft': 500,
  9958. 'guilsinglleft': 333,
  9959. 'guilsinglright': 333,
  9960. 'fi': 500,
  9961. 'fl': 500,
  9962. 'endash': 500,
  9963. 'dagger': 500,
  9964. 'daggerdbl': 500,
  9965. 'periodcentered': 250,
  9966. 'paragraph': 523,
  9967. 'bullet': 350,
  9968. 'quotesinglbase': 333,
  9969. 'quotedblbase': 556,
  9970. 'quotedblright': 556,
  9971. 'guillemotright': 500,
  9972. 'ellipsis': 889,
  9973. 'perthousand': 1000,
  9974. 'questiondown': 500,
  9975. 'grave': 333,
  9976. 'acute': 333,
  9977. 'circumflex': 333,
  9978. 'tilde': 333,
  9979. 'macron': 333,
  9980. 'breve': 333,
  9981. 'dotaccent': 333,
  9982. 'dieresis': 333,
  9983. 'ring': 333,
  9984. 'cedilla': 333,
  9985. 'hungarumlaut': 333,
  9986. 'ogonek': 333,
  9987. 'caron': 333,
  9988. 'emdash': 889,
  9989. 'AE': 889,
  9990. 'ordfeminine': 276,
  9991. 'Lslash': 556,
  9992. 'Oslash': 722,
  9993. 'OE': 944,
  9994. 'ordmasculine': 310,
  9995. 'ae': 667,
  9996. 'dotlessi': 278,
  9997. 'lslash': 278,
  9998. 'oslash': 500,
  9999. 'oe': 667,
  10000. 'germandbls': 500,
  10001. 'Idieresis': 333,
  10002. 'eacute': 444,
  10003. 'abreve': 500,
  10004. 'uhungarumlaut': 500,
  10005. 'ecaron': 444,
  10006. 'Ydieresis': 556,
  10007. 'divide': 675,
  10008. 'Yacute': 556,
  10009. 'Acircumflex': 611,
  10010. 'aacute': 500,
  10011. 'Ucircumflex': 722,
  10012. 'yacute': 444,
  10013. 'scommaaccent': 389,
  10014. 'ecircumflex': 444,
  10015. 'Uring': 722,
  10016. 'Udieresis': 722,
  10017. 'aogonek': 500,
  10018. 'Uacute': 722,
  10019. 'uogonek': 500,
  10020. 'Edieresis': 611,
  10021. 'Dcroat': 722,
  10022. 'commaaccent': 250,
  10023. 'copyright': 760,
  10024. 'Emacron': 611,
  10025. 'ccaron': 444,
  10026. 'aring': 500,
  10027. 'Ncommaaccent': 667,
  10028. 'lacute': 278,
  10029. 'agrave': 500,
  10030. 'Tcommaaccent': 556,
  10031. 'Cacute': 667,
  10032. 'atilde': 500,
  10033. 'Edotaccent': 611,
  10034. 'scaron': 389,
  10035. 'scedilla': 389,
  10036. 'iacute': 278,
  10037. 'lozenge': 471,
  10038. 'Rcaron': 611,
  10039. 'Gcommaaccent': 722,
  10040. 'ucircumflex': 500,
  10041. 'acircumflex': 500,
  10042. 'Amacron': 611,
  10043. 'rcaron': 389,
  10044. 'ccedilla': 444,
  10045. 'Zdotaccent': 556,
  10046. 'Thorn': 611,
  10047. 'Omacron': 722,
  10048. 'Racute': 611,
  10049. 'Sacute': 500,
  10050. 'dcaron': 544,
  10051. 'Umacron': 722,
  10052. 'uring': 500,
  10053. 'threesuperior': 300,
  10054. 'Ograve': 722,
  10055. 'Agrave': 611,
  10056. 'Abreve': 611,
  10057. 'multiply': 675,
  10058. 'uacute': 500,
  10059. 'Tcaron': 556,
  10060. 'partialdiff': 476,
  10061. 'ydieresis': 444,
  10062. 'Nacute': 667,
  10063. 'icircumflex': 278,
  10064. 'Ecircumflex': 611,
  10065. 'adieresis': 500,
  10066. 'edieresis': 444,
  10067. 'cacute': 444,
  10068. 'nacute': 500,
  10069. 'umacron': 500,
  10070. 'Ncaron': 667,
  10071. 'Iacute': 333,
  10072. 'plusminus': 675,
  10073. 'brokenbar': 275,
  10074. 'registered': 760,
  10075. 'Gbreve': 722,
  10076. 'Idotaccent': 333,
  10077. 'summation': 600,
  10078. 'Egrave': 611,
  10079. 'racute': 389,
  10080. 'omacron': 500,
  10081. 'Zacute': 556,
  10082. 'Zcaron': 556,
  10083. 'greaterequal': 549,
  10084. 'Eth': 722,
  10085. 'Ccedilla': 667,
  10086. 'lcommaaccent': 278,
  10087. 'tcaron': 300,
  10088. 'eogonek': 444,
  10089. 'Uogonek': 722,
  10090. 'Aacute': 611,
  10091. 'Adieresis': 611,
  10092. 'egrave': 444,
  10093. 'zacute': 389,
  10094. 'iogonek': 278,
  10095. 'Oacute': 722,
  10096. 'oacute': 500,
  10097. 'amacron': 500,
  10098. 'sacute': 389,
  10099. 'idieresis': 278,
  10100. 'Ocircumflex': 722,
  10101. 'Ugrave': 722,
  10102. 'Delta': 612,
  10103. 'thorn': 500,
  10104. 'twosuperior': 300,
  10105. 'Odieresis': 722,
  10106. 'mu': 500,
  10107. 'igrave': 278,
  10108. 'ohungarumlaut': 500,
  10109. 'Eogonek': 611,
  10110. 'dcroat': 500,
  10111. 'threequarters': 750,
  10112. 'Scedilla': 500,
  10113. 'lcaron': 300,
  10114. 'Kcommaaccent': 667,
  10115. 'Lacute': 556,
  10116. 'trademark': 980,
  10117. 'edotaccent': 444,
  10118. 'Igrave': 333,
  10119. 'Imacron': 333,
  10120. 'Lcaron': 611,
  10121. 'onehalf': 750,
  10122. 'lessequal': 549,
  10123. 'ocircumflex': 500,
  10124. 'ntilde': 500,
  10125. 'Uhungarumlaut': 722,
  10126. 'Eacute': 611,
  10127. 'emacron': 444,
  10128. 'gbreve': 500,
  10129. 'onequarter': 750,
  10130. 'Scaron': 500,
  10131. 'Scommaaccent': 500,
  10132. 'Ohungarumlaut': 722,
  10133. 'degree': 400,
  10134. 'ograve': 500,
  10135. 'Ccaron': 667,
  10136. 'ugrave': 500,
  10137. 'radical': 453,
  10138. 'Dcaron': 722,
  10139. 'rcommaaccent': 389,
  10140. 'Ntilde': 667,
  10141. 'otilde': 500,
  10142. 'Rcommaaccent': 611,
  10143. 'Lcommaaccent': 556,
  10144. 'Atilde': 611,
  10145. 'Aogonek': 611,
  10146. 'Aring': 611,
  10147. 'Otilde': 722,
  10148. 'zdotaccent': 389,
  10149. 'Ecaron': 611,
  10150. 'Iogonek': 333,
  10151. 'kcommaaccent': 444,
  10152. 'minus': 675,
  10153. 'Icircumflex': 333,
  10154. 'ncaron': 500,
  10155. 'tcommaaccent': 278,
  10156. 'logicalnot': 675,
  10157. 'odieresis': 500,
  10158. 'udieresis': 500,
  10159. 'notequal': 549,
  10160. 'gcommaaccent': 500,
  10161. 'eth': 500,
  10162. 'zcaron': 389,
  10163. 'ncommaaccent': 500,
  10164. 'onesuperior': 300,
  10165. 'imacron': 278,
  10166. 'Euro': 500
  10167. },
  10168. 'ZapfDingbats': {
  10169. 'space': 278,
  10170. 'a1': 974,
  10171. 'a2': 961,
  10172. 'a202': 974,
  10173. 'a3': 980,
  10174. 'a4': 719,
  10175. 'a5': 789,
  10176. 'a119': 790,
  10177. 'a118': 791,
  10178. 'a117': 690,
  10179. 'a11': 960,
  10180. 'a12': 939,
  10181. 'a13': 549,
  10182. 'a14': 855,
  10183. 'a15': 911,
  10184. 'a16': 933,
  10185. 'a105': 911,
  10186. 'a17': 945,
  10187. 'a18': 974,
  10188. 'a19': 755,
  10189. 'a20': 846,
  10190. 'a21': 762,
  10191. 'a22': 761,
  10192. 'a23': 571,
  10193. 'a24': 677,
  10194. 'a25': 763,
  10195. 'a26': 760,
  10196. 'a27': 759,
  10197. 'a28': 754,
  10198. 'a6': 494,
  10199. 'a7': 552,
  10200. 'a8': 537,
  10201. 'a9': 577,
  10202. 'a10': 692,
  10203. 'a29': 786,
  10204. 'a30': 788,
  10205. 'a31': 788,
  10206. 'a32': 790,
  10207. 'a33': 793,
  10208. 'a34': 794,
  10209. 'a35': 816,
  10210. 'a36': 823,
  10211. 'a37': 789,
  10212. 'a38': 841,
  10213. 'a39': 823,
  10214. 'a40': 833,
  10215. 'a41': 816,
  10216. 'a42': 831,
  10217. 'a43': 923,
  10218. 'a44': 744,
  10219. 'a45': 723,
  10220. 'a46': 749,
  10221. 'a47': 790,
  10222. 'a48': 792,
  10223. 'a49': 695,
  10224. 'a50': 776,
  10225. 'a51': 768,
  10226. 'a52': 792,
  10227. 'a53': 759,
  10228. 'a54': 707,
  10229. 'a55': 708,
  10230. 'a56': 682,
  10231. 'a57': 701,
  10232. 'a58': 826,
  10233. 'a59': 815,
  10234. 'a60': 789,
  10235. 'a61': 789,
  10236. 'a62': 707,
  10237. 'a63': 687,
  10238. 'a64': 696,
  10239. 'a65': 689,
  10240. 'a66': 786,
  10241. 'a67': 787,
  10242. 'a68': 713,
  10243. 'a69': 791,
  10244. 'a70': 785,
  10245. 'a71': 791,
  10246. 'a72': 873,
  10247. 'a73': 761,
  10248. 'a74': 762,
  10249. 'a203': 762,
  10250. 'a75': 759,
  10251. 'a204': 759,
  10252. 'a76': 892,
  10253. 'a77': 892,
  10254. 'a78': 788,
  10255. 'a79': 784,
  10256. 'a81': 438,
  10257. 'a82': 138,
  10258. 'a83': 277,
  10259. 'a84': 415,
  10260. 'a97': 392,
  10261. 'a98': 392,
  10262. 'a99': 668,
  10263. 'a100': 668,
  10264. 'a89': 390,
  10265. 'a90': 390,
  10266. 'a93': 317,
  10267. 'a94': 317,
  10268. 'a91': 276,
  10269. 'a92': 276,
  10270. 'a205': 509,
  10271. 'a85': 509,
  10272. 'a206': 410,
  10273. 'a86': 410,
  10274. 'a87': 234,
  10275. 'a88': 234,
  10276. 'a95': 334,
  10277. 'a96': 334,
  10278. 'a101': 732,
  10279. 'a102': 544,
  10280. 'a103': 544,
  10281. 'a104': 910,
  10282. 'a106': 667,
  10283. 'a107': 760,
  10284. 'a108': 760,
  10285. 'a112': 776,
  10286. 'a111': 595,
  10287. 'a110': 694,
  10288. 'a109': 626,
  10289. 'a120': 788,
  10290. 'a121': 788,
  10291. 'a122': 788,
  10292. 'a123': 788,
  10293. 'a124': 788,
  10294. 'a125': 788,
  10295. 'a126': 788,
  10296. 'a127': 788,
  10297. 'a128': 788,
  10298. 'a129': 788,
  10299. 'a130': 788,
  10300. 'a131': 788,
  10301. 'a132': 788,
  10302. 'a133': 788,
  10303. 'a134': 788,
  10304. 'a135': 788,
  10305. 'a136': 788,
  10306. 'a137': 788,
  10307. 'a138': 788,
  10308. 'a139': 788,
  10309. 'a140': 788,
  10310. 'a141': 788,
  10311. 'a142': 788,
  10312. 'a143': 788,
  10313. 'a144': 788,
  10314. 'a145': 788,
  10315. 'a146': 788,
  10316. 'a147': 788,
  10317. 'a148': 788,
  10318. 'a149': 788,
  10319. 'a150': 788,
  10320. 'a151': 788,
  10321. 'a152': 788,
  10322. 'a153': 788,
  10323. 'a154': 788,
  10324. 'a155': 788,
  10325. 'a156': 788,
  10326. 'a157': 788,
  10327. 'a158': 788,
  10328. 'a159': 788,
  10329. 'a160': 894,
  10330. 'a161': 838,
  10331. 'a163': 1016,
  10332. 'a164': 458,
  10333. 'a196': 748,
  10334. 'a165': 924,
  10335. 'a192': 748,
  10336. 'a166': 918,
  10337. 'a167': 927,
  10338. 'a168': 928,
  10339. 'a169': 928,
  10340. 'a170': 834,
  10341. 'a171': 873,
  10342. 'a172': 828,
  10343. 'a173': 924,
  10344. 'a162': 924,
  10345. 'a174': 917,
  10346. 'a175': 930,
  10347. 'a176': 931,
  10348. 'a177': 463,
  10349. 'a178': 883,
  10350. 'a179': 836,
  10351. 'a193': 836,
  10352. 'a180': 867,
  10353. 'a199': 867,
  10354. 'a181': 696,
  10355. 'a200': 696,
  10356. 'a182': 874,
  10357. 'a201': 874,
  10358. 'a183': 760,
  10359. 'a184': 946,
  10360. 'a197': 771,
  10361. 'a185': 865,
  10362. 'a194': 771,
  10363. 'a198': 888,
  10364. 'a186': 967,
  10365. 'a195': 888,
  10366. 'a187': 831,
  10367. 'a188': 873,
  10368. 'a189': 927,
  10369. 'a190': 970,
  10370. 'a191': 918
  10371. }
  10372. };
  10373. exports.Metrics = Metrics;
  10374. }));
  10375. (function (root, factory) {
  10376. if (typeof define === 'function' && define.amd) {
  10377. define('pdfjs/core/bidi', ['exports', 'pdfjs/shared/global'], factory);
  10378. } else if (typeof exports !== 'undefined') {
  10379. factory(exports, require('../shared/global.js'));
  10380. } else {
  10381. factory((root.pdfjsCoreBidi = {}), root.pdfjsSharedGlobal);
  10382. }
  10383. }(this, function (exports, sharedGlobal) {
  10384. var PDFJS = sharedGlobal.PDFJS;
  10385. var bidi = PDFJS.bidi = (function bidiClosure() {
  10386. // Character types for symbols from 0000 to 00FF.
  10387. var baseTypes = [
  10388. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'S', 'B', 'S', 'WS',
  10389. 'B', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  10390. 'BN', 'BN', 'B', 'B', 'B', 'S', 'WS', 'ON', 'ON', 'ET', 'ET', 'ET', 'ON',
  10391. 'ON', 'ON', 'ON', 'ON', 'ON', 'CS', 'ON', 'CS', 'ON', 'EN', 'EN', 'EN',
  10392. 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'ON', 'ON', 'ON', 'ON', 'ON',
  10393. 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  10394. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'ON', 'ON',
  10395. 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  10396. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  10397. 'L', 'ON', 'ON', 'ON', 'ON', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'B', 'BN',
  10398. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  10399. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  10400. 'BN', 'CS', 'ON', 'ET', 'ET', 'ET', 'ET', 'ON', 'ON', 'ON', 'ON', 'L', 'ON',
  10401. 'ON', 'ON', 'ON', 'ON', 'ET', 'ET', 'EN', 'EN', 'ON', 'L', 'ON', 'ON', 'ON',
  10402. 'EN', 'L', 'ON', 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  10403. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  10404. 'L', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  10405. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  10406. 'L', 'L', 'L', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L'
  10407. ];
  10408. // Character types for symbols from 0600 to 06FF
  10409. var arabicTypes = [
  10410. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  10411. 'CS', 'AL', 'ON', 'ON', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL',
  10412. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  10413. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  10414. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  10415. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  10416. 'AL', 'AL', 'AL', 'AL', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM',
  10417. 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'AL', 'AL',
  10418. 'AL', 'AL', 'AL', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN',
  10419. 'AN', 'ET', 'AN', 'AN', 'AL', 'AL', 'AL', 'NSM', 'AL', 'AL', 'AL', 'AL',
  10420. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  10421. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  10422. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  10423. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  10424. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  10425. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  10426. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  10427. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  10428. 'AL', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM',
  10429. 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'ON', 'NSM',
  10430. 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  10431. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL'
  10432. ];
  10433. function isOdd(i) {
  10434. return (i & 1) !== 0;
  10435. }
  10436. function isEven(i) {
  10437. return (i & 1) === 0;
  10438. }
  10439. function findUnequal(arr, start, value) {
  10440. for (var j = start, jj = arr.length; j < jj; ++j) {
  10441. if (arr[j] !== value) {
  10442. return j;
  10443. }
  10444. }
  10445. return j;
  10446. }
  10447. function setValues(arr, start, end, value) {
  10448. for (var j = start; j < end; ++j) {
  10449. arr[j] = value;
  10450. }
  10451. }
  10452. function reverseValues(arr, start, end) {
  10453. for (var i = start, j = end - 1; i < j; ++i, --j) {
  10454. var temp = arr[i];
  10455. arr[i] = arr[j];
  10456. arr[j] = temp;
  10457. }
  10458. }
  10459. function createBidiText(str, isLTR, vertical) {
  10460. return {
  10461. str: str,
  10462. dir: (vertical ? 'ttb' : (isLTR ? 'ltr' : 'rtl'))
  10463. };
  10464. }
  10465. // These are used in bidi(), which is called frequently. We re-use them on
  10466. // each call to avoid unnecessary allocations.
  10467. var chars = [];
  10468. var types = [];
  10469. function bidi(str, startLevel, vertical) {
  10470. var isLTR = true;
  10471. var strLength = str.length;
  10472. if (strLength === 0 || vertical) {
  10473. return createBidiText(str, isLTR, vertical);
  10474. }
  10475. // Get types and fill arrays
  10476. chars.length = strLength;
  10477. types.length = strLength;
  10478. var numBidi = 0;
  10479. var i, ii;
  10480. for (i = 0; i < strLength; ++i) {
  10481. chars[i] = str.charAt(i);
  10482. var charCode = str.charCodeAt(i);
  10483. var charType = 'L';
  10484. if (charCode <= 0x00ff) {
  10485. charType = baseTypes[charCode];
  10486. } else if (0x0590 <= charCode && charCode <= 0x05f4) {
  10487. charType = 'R';
  10488. } else if (0x0600 <= charCode && charCode <= 0x06ff) {
  10489. charType = arabicTypes[charCode & 0xff];
  10490. } else if (0x0700 <= charCode && charCode <= 0x08AC) {
  10491. charType = 'AL';
  10492. }
  10493. if (charType === 'R' || charType === 'AL' || charType === 'AN') {
  10494. numBidi++;
  10495. }
  10496. types[i] = charType;
  10497. }
  10498. // Detect the bidi method
  10499. // - If there are no rtl characters then no bidi needed
  10500. // - If less than 30% chars are rtl then string is primarily ltr
  10501. // - If more than 30% chars are rtl then string is primarily rtl
  10502. if (numBidi === 0) {
  10503. isLTR = true;
  10504. return createBidiText(str, isLTR);
  10505. }
  10506. if (startLevel === -1) {
  10507. if ((strLength / numBidi) < 0.3) {
  10508. isLTR = true;
  10509. startLevel = 0;
  10510. } else {
  10511. isLTR = false;
  10512. startLevel = 1;
  10513. }
  10514. }
  10515. var levels = [];
  10516. for (i = 0; i < strLength; ++i) {
  10517. levels[i] = startLevel;
  10518. }
  10519. /*
  10520. X1-X10: skip most of this, since we are NOT doing the embeddings.
  10521. */
  10522. var e = (isOdd(startLevel) ? 'R' : 'L');
  10523. var sor = e;
  10524. var eor = sor;
  10525. /*
  10526. W1. Examine each non-spacing mark (NSM) in the level run, and change the
  10527. type of the NSM to the type of the previous character. If the NSM is at the
  10528. start of the level run, it will get the type of sor.
  10529. */
  10530. var lastType = sor;
  10531. for (i = 0; i < strLength; ++i) {
  10532. if (types[i] === 'NSM') {
  10533. types[i] = lastType;
  10534. } else {
  10535. lastType = types[i];
  10536. }
  10537. }
  10538. /*
  10539. W2. Search backwards from each instance of a European number until the
  10540. first strong type (R, L, AL, or sor) is found. If an AL is found, change
  10541. the type of the European number to Arabic number.
  10542. */
  10543. lastType = sor;
  10544. var t;
  10545. for (i = 0; i < strLength; ++i) {
  10546. t = types[i];
  10547. if (t === 'EN') {
  10548. types[i] = (lastType === 'AL') ? 'AN' : 'EN';
  10549. } else if (t === 'R' || t === 'L' || t === 'AL') {
  10550. lastType = t;
  10551. }
  10552. }
  10553. /*
  10554. W3. Change all ALs to R.
  10555. */
  10556. for (i = 0; i < strLength; ++i) {
  10557. t = types[i];
  10558. if (t === 'AL') {
  10559. types[i] = 'R';
  10560. }
  10561. }
  10562. /*
  10563. W4. A single European separator between two European numbers changes to a
  10564. European number. A single common separator between two numbers of the same
  10565. type changes to that type:
  10566. */
  10567. for (i = 1; i < strLength - 1; ++i) {
  10568. if (types[i] === 'ES' && types[i - 1] === 'EN' && types[i + 1] === 'EN') {
  10569. types[i] = 'EN';
  10570. }
  10571. if (types[i] === 'CS' &&
  10572. (types[i - 1] === 'EN' || types[i - 1] === 'AN') &&
  10573. types[i + 1] === types[i - 1]) {
  10574. types[i] = types[i - 1];
  10575. }
  10576. }
  10577. /*
  10578. W5. A sequence of European terminators adjacent to European numbers changes
  10579. to all European numbers:
  10580. */
  10581. for (i = 0; i < strLength; ++i) {
  10582. if (types[i] === 'EN') {
  10583. // do before
  10584. var j;
  10585. for (j = i - 1; j >= 0; --j) {
  10586. if (types[j] !== 'ET') {
  10587. break;
  10588. }
  10589. types[j] = 'EN';
  10590. }
  10591. // do after
  10592. for (j = i + 1; j < strLength; --j) {
  10593. if (types[j] !== 'ET') {
  10594. break;
  10595. }
  10596. types[j] = 'EN';
  10597. }
  10598. }
  10599. }
  10600. /*
  10601. W6. Otherwise, separators and terminators change to Other Neutral:
  10602. */
  10603. for (i = 0; i < strLength; ++i) {
  10604. t = types[i];
  10605. if (t === 'WS' || t === 'ES' || t === 'ET' || t === 'CS') {
  10606. types[i] = 'ON';
  10607. }
  10608. }
  10609. /*
  10610. W7. Search backwards from each instance of a European number until the
  10611. first strong type (R, L, or sor) is found. If an L is found, then change
  10612. the type of the European number to L.
  10613. */
  10614. lastType = sor;
  10615. for (i = 0; i < strLength; ++i) {
  10616. t = types[i];
  10617. if (t === 'EN') {
  10618. types[i] = ((lastType === 'L') ? 'L' : 'EN');
  10619. } else if (t === 'R' || t === 'L') {
  10620. lastType = t;
  10621. }
  10622. }
  10623. /*
  10624. N1. A sequence of neutrals takes the direction of the surrounding strong
  10625. text if the text on both sides has the same direction. European and Arabic
  10626. numbers are treated as though they were R. Start-of-level-run (sor) and
  10627. end-of-level-run (eor) are used at level run boundaries.
  10628. */
  10629. for (i = 0; i < strLength; ++i) {
  10630. if (types[i] === 'ON') {
  10631. var end = findUnequal(types, i + 1, 'ON');
  10632. var before = sor;
  10633. if (i > 0) {
  10634. before = types[i - 1];
  10635. }
  10636. var after = eor;
  10637. if (end + 1 < strLength) {
  10638. after = types[end + 1];
  10639. }
  10640. if (before !== 'L') {
  10641. before = 'R';
  10642. }
  10643. if (after !== 'L') {
  10644. after = 'R';
  10645. }
  10646. if (before === after) {
  10647. setValues(types, i, end, before);
  10648. }
  10649. i = end - 1; // reset to end (-1 so next iteration is ok)
  10650. }
  10651. }
  10652. /*
  10653. N2. Any remaining neutrals take the embedding direction.
  10654. */
  10655. for (i = 0; i < strLength; ++i) {
  10656. if (types[i] === 'ON') {
  10657. types[i] = e;
  10658. }
  10659. }
  10660. /*
  10661. I1. For all characters with an even (left-to-right) embedding direction,
  10662. those of type R go up one level and those of type AN or EN go up two
  10663. levels.
  10664. I2. For all characters with an odd (right-to-left) embedding direction,
  10665. those of type L, EN or AN go up one level.
  10666. */
  10667. for (i = 0; i < strLength; ++i) {
  10668. t = types[i];
  10669. if (isEven(levels[i])) {
  10670. if (t === 'R') {
  10671. levels[i] += 1;
  10672. } else if (t === 'AN' || t === 'EN') {
  10673. levels[i] += 2;
  10674. }
  10675. } else { // isOdd
  10676. if (t === 'L' || t === 'AN' || t === 'EN') {
  10677. levels[i] += 1;
  10678. }
  10679. }
  10680. }
  10681. /*
  10682. L1. On each line, reset the embedding level of the following characters to
  10683. the paragraph embedding level:
  10684. segment separators,
  10685. paragraph separators,
  10686. any sequence of whitespace characters preceding a segment separator or
  10687. paragraph separator, and any sequence of white space characters at the end
  10688. of the line.
  10689. */
  10690. // don't bother as text is only single line
  10691. /*
  10692. L2. From the highest level found in the text to the lowest odd level on
  10693. each line, reverse any contiguous sequence of characters that are at that
  10694. level or higher.
  10695. */
  10696. // find highest level & lowest odd level
  10697. var highestLevel = -1;
  10698. var lowestOddLevel = 99;
  10699. var level;
  10700. for (i = 0, ii = levels.length; i < ii; ++i) {
  10701. level = levels[i];
  10702. if (highestLevel < level) {
  10703. highestLevel = level;
  10704. }
  10705. if (lowestOddLevel > level && isOdd(level)) {
  10706. lowestOddLevel = level;
  10707. }
  10708. }
  10709. // now reverse between those limits
  10710. for (level = highestLevel; level >= lowestOddLevel; --level) {
  10711. // find segments to reverse
  10712. var start = -1;
  10713. for (i = 0, ii = levels.length; i < ii; ++i) {
  10714. if (levels[i] < level) {
  10715. if (start >= 0) {
  10716. reverseValues(chars, start, i);
  10717. start = -1;
  10718. }
  10719. } else if (start < 0) {
  10720. start = i;
  10721. }
  10722. }
  10723. if (start >= 0) {
  10724. reverseValues(chars, start, levels.length);
  10725. }
  10726. }
  10727. /*
  10728. L3. Combining marks applied to a right-to-left base character will at this
  10729. point precede their base character. If the rendering engine expects them to
  10730. follow the base characters in the final display process, then the ordering
  10731. of the marks and the base character must be reversed.
  10732. */
  10733. // don't bother for now
  10734. /*
  10735. L4. A character that possesses the mirrored property as specified by
  10736. Section 4.7, Mirrored, must be depicted by a mirrored glyph if the resolved
  10737. directionality of that character is R.
  10738. */
  10739. // don't mirror as characters are already mirrored in the pdf
  10740. // Finally, return string
  10741. for (i = 0, ii = chars.length; i < ii; ++i) {
  10742. var ch = chars[i];
  10743. if (ch === '<' || ch === '>') {
  10744. chars[i] = '';
  10745. }
  10746. }
  10747. return createBidiText(chars.join(''), isLTR);
  10748. }
  10749. return bidi;
  10750. })();
  10751. exports.bidi = bidi;
  10752. }));
  10753. (function (root, factory) {
  10754. if (typeof define === 'function' && define.amd) {
  10755. define('pdfjs/core/chunked_stream', ['exports', 'pdfjs/shared/util'],
  10756. factory);
  10757. } else if (typeof exports !== 'undefined') {
  10758. factory(exports, require('../shared/util.js'));
  10759. } else {
  10760. factory((root.pdfjsCoreChunkedStream = {}), root.pdfjsSharedUtil);
  10761. }
  10762. }(this, function (exports, sharedUtil) {
  10763. var MissingDataException = sharedUtil.MissingDataException;
  10764. var assert = sharedUtil.assert;
  10765. var createPromiseCapability = sharedUtil.createPromiseCapability;
  10766. var isInt = sharedUtil.isInt;
  10767. var isEmptyObj = sharedUtil.isEmptyObj;
  10768. var ChunkedStream = (function ChunkedStreamClosure() {
  10769. function ChunkedStream(length, chunkSize, manager) {
  10770. this.bytes = new Uint8Array(length);
  10771. this.start = 0;
  10772. this.pos = 0;
  10773. this.end = length;
  10774. this.chunkSize = chunkSize;
  10775. this.loadedChunks = [];
  10776. this.numChunksLoaded = 0;
  10777. this.numChunks = Math.ceil(length / chunkSize);
  10778. this.manager = manager;
  10779. this.progressiveDataLength = 0;
  10780. this.lastSuccessfulEnsureByteChunk = -1; // a single-entry cache
  10781. }
  10782. // required methods for a stream. if a particular stream does not
  10783. // implement these, an error should be thrown
  10784. ChunkedStream.prototype = {
  10785. getMissingChunks: function ChunkedStream_getMissingChunks() {
  10786. var chunks = [];
  10787. for (var chunk = 0, n = this.numChunks; chunk < n; ++chunk) {
  10788. if (!this.loadedChunks[chunk]) {
  10789. chunks.push(chunk);
  10790. }
  10791. }
  10792. return chunks;
  10793. },
  10794. getBaseStreams: function ChunkedStream_getBaseStreams() {
  10795. return [this];
  10796. },
  10797. allChunksLoaded: function ChunkedStream_allChunksLoaded() {
  10798. return this.numChunksLoaded === this.numChunks;
  10799. },
  10800. onReceiveData: function ChunkedStream_onReceiveData(begin, chunk) {
  10801. var end = begin + chunk.byteLength;
  10802. assert(begin % this.chunkSize === 0, 'Bad begin offset: ' + begin);
  10803. // Using this.length is inaccurate here since this.start can be moved
  10804. // See ChunkedStream.moveStart()
  10805. var length = this.bytes.length;
  10806. assert(end % this.chunkSize === 0 || end === length,
  10807. 'Bad end offset: ' + end);
  10808. this.bytes.set(new Uint8Array(chunk), begin);
  10809. var chunkSize = this.chunkSize;
  10810. var beginChunk = Math.floor(begin / chunkSize);
  10811. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  10812. var curChunk;
  10813. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  10814. if (!this.loadedChunks[curChunk]) {
  10815. this.loadedChunks[curChunk] = true;
  10816. ++this.numChunksLoaded;
  10817. }
  10818. }
  10819. },
  10820. onReceiveProgressiveData:
  10821. function ChunkedStream_onReceiveProgressiveData(data) {
  10822. var position = this.progressiveDataLength;
  10823. var beginChunk = Math.floor(position / this.chunkSize);
  10824. this.bytes.set(new Uint8Array(data), position);
  10825. position += data.byteLength;
  10826. this.progressiveDataLength = position;
  10827. var endChunk = position >= this.end ? this.numChunks :
  10828. Math.floor(position / this.chunkSize);
  10829. var curChunk;
  10830. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  10831. if (!this.loadedChunks[curChunk]) {
  10832. this.loadedChunks[curChunk] = true;
  10833. ++this.numChunksLoaded;
  10834. }
  10835. }
  10836. },
  10837. ensureByte: function ChunkedStream_ensureByte(pos) {
  10838. var chunk = Math.floor(pos / this.chunkSize);
  10839. if (chunk === this.lastSuccessfulEnsureByteChunk) {
  10840. return;
  10841. }
  10842. if (!this.loadedChunks[chunk]) {
  10843. throw new MissingDataException(pos, pos + 1);
  10844. }
  10845. this.lastSuccessfulEnsureByteChunk = chunk;
  10846. },
  10847. ensureRange: function ChunkedStream_ensureRange(begin, end) {
  10848. if (begin >= end) {
  10849. return;
  10850. }
  10851. if (end <= this.progressiveDataLength) {
  10852. return;
  10853. }
  10854. var chunkSize = this.chunkSize;
  10855. var beginChunk = Math.floor(begin / chunkSize);
  10856. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  10857. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  10858. if (!this.loadedChunks[chunk]) {
  10859. throw new MissingDataException(begin, end);
  10860. }
  10861. }
  10862. },
  10863. nextEmptyChunk: function ChunkedStream_nextEmptyChunk(beginChunk) {
  10864. var chunk, numChunks = this.numChunks;
  10865. for (var i = 0; i < numChunks; ++i) {
  10866. chunk = (beginChunk + i) % numChunks; // Wrap around to beginning
  10867. if (!this.loadedChunks[chunk]) {
  10868. return chunk;
  10869. }
  10870. }
  10871. return null;
  10872. },
  10873. hasChunk: function ChunkedStream_hasChunk(chunk) {
  10874. return !!this.loadedChunks[chunk];
  10875. },
  10876. get length() {
  10877. return this.end - this.start;
  10878. },
  10879. get isEmpty() {
  10880. return this.length === 0;
  10881. },
  10882. getByte: function ChunkedStream_getByte() {
  10883. var pos = this.pos;
  10884. if (pos >= this.end) {
  10885. return -1;
  10886. }
  10887. this.ensureByte(pos);
  10888. return this.bytes[this.pos++];
  10889. },
  10890. getUint16: function ChunkedStream_getUint16() {
  10891. var b0 = this.getByte();
  10892. var b1 = this.getByte();
  10893. if (b0 === -1 || b1 === -1) {
  10894. return -1;
  10895. }
  10896. return (b0 << 8) + b1;
  10897. },
  10898. getInt32: function ChunkedStream_getInt32() {
  10899. var b0 = this.getByte();
  10900. var b1 = this.getByte();
  10901. var b2 = this.getByte();
  10902. var b3 = this.getByte();
  10903. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  10904. },
  10905. // returns subarray of original buffer
  10906. // should only be read
  10907. getBytes: function ChunkedStream_getBytes(length) {
  10908. var bytes = this.bytes;
  10909. var pos = this.pos;
  10910. var strEnd = this.end;
  10911. if (!length) {
  10912. this.ensureRange(pos, strEnd);
  10913. return bytes.subarray(pos, strEnd);
  10914. }
  10915. var end = pos + length;
  10916. if (end > strEnd) {
  10917. end = strEnd;
  10918. }
  10919. this.ensureRange(pos, end);
  10920. this.pos = end;
  10921. return bytes.subarray(pos, end);
  10922. },
  10923. peekByte: function ChunkedStream_peekByte() {
  10924. var peekedByte = this.getByte();
  10925. this.pos--;
  10926. return peekedByte;
  10927. },
  10928. peekBytes: function ChunkedStream_peekBytes(length) {
  10929. var bytes = this.getBytes(length);
  10930. this.pos -= bytes.length;
  10931. return bytes;
  10932. },
  10933. getByteRange: function ChunkedStream_getBytes(begin, end) {
  10934. this.ensureRange(begin, end);
  10935. return this.bytes.subarray(begin, end);
  10936. },
  10937. skip: function ChunkedStream_skip(n) {
  10938. if (!n) {
  10939. n = 1;
  10940. }
  10941. this.pos += n;
  10942. },
  10943. reset: function ChunkedStream_reset() {
  10944. this.pos = this.start;
  10945. },
  10946. moveStart: function ChunkedStream_moveStart() {
  10947. this.start = this.pos;
  10948. },
  10949. makeSubStream: function ChunkedStream_makeSubStream(start, length, dict) {
  10950. this.ensureRange(start, start + length);
  10951. function ChunkedStreamSubstream() {}
  10952. ChunkedStreamSubstream.prototype = Object.create(this);
  10953. ChunkedStreamSubstream.prototype.getMissingChunks = function() {
  10954. var chunkSize = this.chunkSize;
  10955. var beginChunk = Math.floor(this.start / chunkSize);
  10956. var endChunk = Math.floor((this.end - 1) / chunkSize) + 1;
  10957. var missingChunks = [];
  10958. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  10959. if (!this.loadedChunks[chunk]) {
  10960. missingChunks.push(chunk);
  10961. }
  10962. }
  10963. return missingChunks;
  10964. };
  10965. var subStream = new ChunkedStreamSubstream();
  10966. subStream.pos = subStream.start = start;
  10967. subStream.end = start + length || this.end;
  10968. subStream.dict = dict;
  10969. return subStream;
  10970. },
  10971. isStream: true
  10972. };
  10973. return ChunkedStream;
  10974. })();
  10975. var ChunkedStreamManager = (function ChunkedStreamManagerClosure() {
  10976. function ChunkedStreamManager(length, chunkSize, url, args) {
  10977. this.stream = new ChunkedStream(length, chunkSize, this);
  10978. this.length = length;
  10979. this.chunkSize = chunkSize;
  10980. this.url = url;
  10981. this.disableAutoFetch = args.disableAutoFetch;
  10982. var msgHandler = this.msgHandler = args.msgHandler;
  10983. if (args.chunkedViewerLoading) {
  10984. msgHandler.on('OnDataRange', this.onReceiveData.bind(this));
  10985. msgHandler.on('OnDataProgress', this.onProgress.bind(this));
  10986. this.sendRequest = function ChunkedStreamManager_sendRequest(begin, end) {
  10987. msgHandler.send('RequestDataRange', { begin: begin, end: end });
  10988. };
  10989. } else {
  10990. var getXhr = function getXhr() {
  10991. return new XMLHttpRequest();
  10992. };
  10993. this.networkManager = new NetworkManager(this.url, {
  10994. getXhr: getXhr,
  10995. httpHeaders: args.httpHeaders,
  10996. withCredentials: args.withCredentials
  10997. });
  10998. this.sendRequest = function ChunkedStreamManager_sendRequest(begin, end) {
  10999. this.networkManager.requestRange(begin, end, {
  11000. onDone: this.onReceiveData.bind(this),
  11001. onProgress: this.onProgress.bind(this)
  11002. });
  11003. };
  11004. }
  11005. this.currRequestId = 0;
  11006. this.chunksNeededByRequest = {};
  11007. this.requestsByChunk = {};
  11008. this.promisesByRequest = {};
  11009. this.progressiveDataLength = 0;
  11010. this._loadedStreamCapability = createPromiseCapability();
  11011. if (args.initialData) {
  11012. this.onReceiveData({chunk: args.initialData});
  11013. }
  11014. }
  11015. ChunkedStreamManager.prototype = {
  11016. onLoadedStream: function ChunkedStreamManager_getLoadedStream() {
  11017. return this._loadedStreamCapability.promise;
  11018. },
  11019. // Get all the chunks that are not yet loaded and groups them into
  11020. // contiguous ranges to load in as few requests as possible
  11021. requestAllChunks: function ChunkedStreamManager_requestAllChunks() {
  11022. var missingChunks = this.stream.getMissingChunks();
  11023. this._requestChunks(missingChunks);
  11024. return this._loadedStreamCapability.promise;
  11025. },
  11026. _requestChunks: function ChunkedStreamManager_requestChunks(chunks) {
  11027. var requestId = this.currRequestId++;
  11028. var chunksNeeded;
  11029. var i, ii;
  11030. this.chunksNeededByRequest[requestId] = chunksNeeded = {};
  11031. for (i = 0, ii = chunks.length; i < ii; i++) {
  11032. if (!this.stream.hasChunk(chunks[i])) {
  11033. chunksNeeded[chunks[i]] = true;
  11034. }
  11035. }
  11036. if (isEmptyObj(chunksNeeded)) {
  11037. return Promise.resolve();
  11038. }
  11039. var capability = createPromiseCapability();
  11040. this.promisesByRequest[requestId] = capability;
  11041. var chunksToRequest = [];
  11042. for (var chunk in chunksNeeded) {
  11043. chunk = chunk | 0;
  11044. if (!(chunk in this.requestsByChunk)) {
  11045. this.requestsByChunk[chunk] = [];
  11046. chunksToRequest.push(chunk);
  11047. }
  11048. this.requestsByChunk[chunk].push(requestId);
  11049. }
  11050. if (!chunksToRequest.length) {
  11051. return capability.promise;
  11052. }
  11053. var groupedChunksToRequest = this.groupChunks(chunksToRequest);
  11054. for (i = 0; i < groupedChunksToRequest.length; ++i) {
  11055. var groupedChunk = groupedChunksToRequest[i];
  11056. var begin = groupedChunk.beginChunk * this.chunkSize;
  11057. var end = Math.min(groupedChunk.endChunk * this.chunkSize, this.length);
  11058. this.sendRequest(begin, end);
  11059. }
  11060. return capability.promise;
  11061. },
  11062. getStream: function ChunkedStreamManager_getStream() {
  11063. return this.stream;
  11064. },
  11065. // Loads any chunks in the requested range that are not yet loaded
  11066. requestRange: function ChunkedStreamManager_requestRange(begin, end) {
  11067. end = Math.min(end, this.length);
  11068. var beginChunk = this.getBeginChunk(begin);
  11069. var endChunk = this.getEndChunk(end);
  11070. var chunks = [];
  11071. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  11072. chunks.push(chunk);
  11073. }
  11074. return this._requestChunks(chunks);
  11075. },
  11076. requestRanges: function ChunkedStreamManager_requestRanges(ranges) {
  11077. ranges = ranges || [];
  11078. var chunksToRequest = [];
  11079. for (var i = 0; i < ranges.length; i++) {
  11080. var beginChunk = this.getBeginChunk(ranges[i].begin);
  11081. var endChunk = this.getEndChunk(ranges[i].end);
  11082. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  11083. if (chunksToRequest.indexOf(chunk) < 0) {
  11084. chunksToRequest.push(chunk);
  11085. }
  11086. }
  11087. }
  11088. chunksToRequest.sort(function(a, b) { return a - b; });
  11089. return this._requestChunks(chunksToRequest);
  11090. },
  11091. // Groups a sorted array of chunks into as few contiguous larger
  11092. // chunks as possible
  11093. groupChunks: function ChunkedStreamManager_groupChunks(chunks) {
  11094. var groupedChunks = [];
  11095. var beginChunk = -1;
  11096. var prevChunk = -1;
  11097. for (var i = 0; i < chunks.length; ++i) {
  11098. var chunk = chunks[i];
  11099. if (beginChunk < 0) {
  11100. beginChunk = chunk;
  11101. }
  11102. if (prevChunk >= 0 && prevChunk + 1 !== chunk) {
  11103. groupedChunks.push({ beginChunk: beginChunk,
  11104. endChunk: prevChunk + 1 });
  11105. beginChunk = chunk;
  11106. }
  11107. if (i + 1 === chunks.length) {
  11108. groupedChunks.push({ beginChunk: beginChunk,
  11109. endChunk: chunk + 1 });
  11110. }
  11111. prevChunk = chunk;
  11112. }
  11113. return groupedChunks;
  11114. },
  11115. onProgress: function ChunkedStreamManager_onProgress(args) {
  11116. var bytesLoaded = (this.stream.numChunksLoaded * this.chunkSize +
  11117. args.loaded);
  11118. this.msgHandler.send('DocProgress', {
  11119. loaded: bytesLoaded,
  11120. total: this.length
  11121. });
  11122. },
  11123. onReceiveData: function ChunkedStreamManager_onReceiveData(args) {
  11124. var chunk = args.chunk;
  11125. var isProgressive = args.begin === undefined;
  11126. var begin = isProgressive ? this.progressiveDataLength : args.begin;
  11127. var end = begin + chunk.byteLength;
  11128. var beginChunk = Math.floor(begin / this.chunkSize);
  11129. var endChunk = end < this.length ? Math.floor(end / this.chunkSize) :
  11130. Math.ceil(end / this.chunkSize);
  11131. if (isProgressive) {
  11132. this.stream.onReceiveProgressiveData(chunk);
  11133. this.progressiveDataLength = end;
  11134. } else {
  11135. this.stream.onReceiveData(begin, chunk);
  11136. }
  11137. if (this.stream.allChunksLoaded()) {
  11138. this._loadedStreamCapability.resolve(this.stream);
  11139. }
  11140. var loadedRequests = [];
  11141. var i, requestId;
  11142. for (chunk = beginChunk; chunk < endChunk; ++chunk) {
  11143. // The server might return more chunks than requested
  11144. var requestIds = this.requestsByChunk[chunk] || [];
  11145. delete this.requestsByChunk[chunk];
  11146. for (i = 0; i < requestIds.length; ++i) {
  11147. requestId = requestIds[i];
  11148. var chunksNeeded = this.chunksNeededByRequest[requestId];
  11149. if (chunk in chunksNeeded) {
  11150. delete chunksNeeded[chunk];
  11151. }
  11152. if (!isEmptyObj(chunksNeeded)) {
  11153. continue;
  11154. }
  11155. loadedRequests.push(requestId);
  11156. }
  11157. }
  11158. // If there are no pending requests, automatically fetch the next
  11159. // unfetched chunk of the PDF
  11160. if (!this.disableAutoFetch && isEmptyObj(this.requestsByChunk)) {
  11161. var nextEmptyChunk;
  11162. if (this.stream.numChunksLoaded === 1) {
  11163. // This is a special optimization so that after fetching the first
  11164. // chunk, rather than fetching the second chunk, we fetch the last
  11165. // chunk.
  11166. var lastChunk = this.stream.numChunks - 1;
  11167. if (!this.stream.hasChunk(lastChunk)) {
  11168. nextEmptyChunk = lastChunk;
  11169. }
  11170. } else {
  11171. nextEmptyChunk = this.stream.nextEmptyChunk(endChunk);
  11172. }
  11173. if (isInt(nextEmptyChunk)) {
  11174. this._requestChunks([nextEmptyChunk]);
  11175. }
  11176. }
  11177. for (i = 0; i < loadedRequests.length; ++i) {
  11178. requestId = loadedRequests[i];
  11179. var capability = this.promisesByRequest[requestId];
  11180. delete this.promisesByRequest[requestId];
  11181. capability.resolve();
  11182. }
  11183. this.msgHandler.send('DocProgress', {
  11184. loaded: this.stream.numChunksLoaded * this.chunkSize,
  11185. total: this.length
  11186. });
  11187. },
  11188. onError: function ChunkedStreamManager_onError(err) {
  11189. this._loadedStreamCapability.reject(err);
  11190. },
  11191. getBeginChunk: function ChunkedStreamManager_getBeginChunk(begin) {
  11192. var chunk = Math.floor(begin / this.chunkSize);
  11193. return chunk;
  11194. },
  11195. getEndChunk: function ChunkedStreamManager_getEndChunk(end) {
  11196. var chunk = Math.floor((end - 1) / this.chunkSize) + 1;
  11197. return chunk;
  11198. },
  11199. abort: function ChunkedStreamManager_abort() {
  11200. if (this.networkManager) {
  11201. this.networkManager.abortAllRequests();
  11202. }
  11203. for(var requestId in this.promisesByRequest) {
  11204. var capability = this.promisesByRequest[requestId];
  11205. capability.reject(new Error('Request was aborted'));
  11206. }
  11207. }
  11208. };
  11209. return ChunkedStreamManager;
  11210. })();
  11211. exports.ChunkedStream = ChunkedStream;
  11212. exports.ChunkedStreamManager = ChunkedStreamManager;
  11213. }));
  11214. (function (root, factory) {
  11215. if (typeof define === 'function' && define.amd) {
  11216. define('pdfjs/core/jbig2', ['exports', 'pdfjs/shared/util',
  11217. 'pdfjs/core/arithmetic_decoder'], factory);
  11218. } else if (typeof exports !== 'undefined') {
  11219. factory(exports, require('../shared/util.js'),
  11220. require('./arithmetic_decoder.js'));
  11221. } else {
  11222. factory((root.pdfjsCoreJbig2 = {}), root.pdfjsSharedUtil,
  11223. root.pdfjsCoreArithmeticDecoder);
  11224. }
  11225. }(this, function (exports, sharedUtil, coreArithmeticDecoder) {
  11226. var error = sharedUtil.error;
  11227. var log2 = sharedUtil.log2;
  11228. var readInt8 = sharedUtil.readInt8;
  11229. var readUint16 = sharedUtil.readUint16;
  11230. var readUint32 = sharedUtil.readUint32;
  11231. var shadow = sharedUtil.shadow;
  11232. var ArithmeticDecoder = coreArithmeticDecoder.ArithmeticDecoder;
  11233. var Jbig2Image = (function Jbig2ImageClosure() {
  11234. // Utility data structures
  11235. function ContextCache() {}
  11236. ContextCache.prototype = {
  11237. getContexts: function(id) {
  11238. if (id in this) {
  11239. return this[id];
  11240. }
  11241. return (this[id] = new Int8Array(1 << 16));
  11242. }
  11243. };
  11244. function DecodingContext(data, start, end) {
  11245. this.data = data;
  11246. this.start = start;
  11247. this.end = end;
  11248. }
  11249. DecodingContext.prototype = {
  11250. get decoder() {
  11251. var decoder = new ArithmeticDecoder(this.data, this.start, this.end);
  11252. return shadow(this, 'decoder', decoder);
  11253. },
  11254. get contextCache() {
  11255. var cache = new ContextCache();
  11256. return shadow(this, 'contextCache', cache);
  11257. }
  11258. };
  11259. // Annex A. Arithmetic Integer Decoding Procedure
  11260. // A.2 Procedure for decoding values
  11261. function decodeInteger(contextCache, procedure, decoder) {
  11262. var contexts = contextCache.getContexts(procedure);
  11263. var prev = 1;
  11264. function readBits(length) {
  11265. var v = 0;
  11266. for (var i = 0; i < length; i++) {
  11267. var bit = decoder.readBit(contexts, prev);
  11268. prev = (prev < 256 ? (prev << 1) | bit :
  11269. (((prev << 1) | bit) & 511) | 256);
  11270. v = (v << 1) | bit;
  11271. }
  11272. return v >>> 0;
  11273. }
  11274. var sign = readBits(1);
  11275. var value = readBits(1) ?
  11276. (readBits(1) ?
  11277. (readBits(1) ?
  11278. (readBits(1) ?
  11279. (readBits(1) ?
  11280. (readBits(32) + 4436) :
  11281. readBits(12) + 340) :
  11282. readBits(8) + 84) :
  11283. readBits(6) + 20) :
  11284. readBits(4) + 4) :
  11285. readBits(2);
  11286. return (sign === 0 ? value : (value > 0 ? -value : null));
  11287. }
  11288. // A.3 The IAID decoding procedure
  11289. function decodeIAID(contextCache, decoder, codeLength) {
  11290. var contexts = contextCache.getContexts('IAID');
  11291. var prev = 1;
  11292. for (var i = 0; i < codeLength; i++) {
  11293. var bit = decoder.readBit(contexts, prev);
  11294. prev = (prev << 1) | bit;
  11295. }
  11296. if (codeLength < 31) {
  11297. return prev & ((1 << codeLength) - 1);
  11298. }
  11299. return prev & 0x7FFFFFFF;
  11300. }
  11301. // 7.3 Segment types
  11302. var SegmentTypes = [
  11303. 'SymbolDictionary', null, null, null, 'IntermediateTextRegion', null,
  11304. 'ImmediateTextRegion', 'ImmediateLosslessTextRegion', null, null, null,
  11305. null, null, null, null, null, 'patternDictionary', null, null, null,
  11306. 'IntermediateHalftoneRegion', null, 'ImmediateHalftoneRegion',
  11307. 'ImmediateLosslessHalftoneRegion', null, null, null, null, null, null, null,
  11308. null, null, null, null, null, 'IntermediateGenericRegion', null,
  11309. 'ImmediateGenericRegion', 'ImmediateLosslessGenericRegion',
  11310. 'IntermediateGenericRefinementRegion', null,
  11311. 'ImmediateGenericRefinementRegion',
  11312. 'ImmediateLosslessGenericRefinementRegion', null, null, null, null,
  11313. 'PageInformation', 'EndOfPage', 'EndOfStripe', 'EndOfFile', 'Profiles',
  11314. 'Tables', null, null, null, null, null, null, null, null,
  11315. 'Extension'
  11316. ];
  11317. var CodingTemplates = [
  11318. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  11319. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: 2, y: -1},
  11320. {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  11321. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: 2, y: -2},
  11322. {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1},
  11323. {x: 2, y: -1}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  11324. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  11325. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -2, y: 0},
  11326. {x: -1, y: 0}],
  11327. [{x: -3, y: -1}, {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1},
  11328. {x: 1, y: -1}, {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}]
  11329. ];
  11330. var RefinementTemplates = [
  11331. {
  11332. coding: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  11333. reference: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}, {x: 0, y: 0},
  11334. {x: 1, y: 0}, {x: -1, y: 1}, {x: 0, y: 1}, {x: 1, y: 1}]
  11335. },
  11336. {
  11337. coding: [{x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  11338. reference: [{x: 0, y: -1}, {x: -1, y: 0}, {x: 0, y: 0}, {x: 1, y: 0},
  11339. {x: 0, y: 1}, {x: 1, y: 1}]
  11340. }
  11341. ];
  11342. // See 6.2.5.7 Decoding the bitmap.
  11343. var ReusedContexts = [
  11344. 0x9B25, // 10011 0110010 0101
  11345. 0x0795, // 0011 110010 101
  11346. 0x00E5, // 001 11001 01
  11347. 0x0195 // 011001 0101
  11348. ];
  11349. var RefinementReusedContexts = [
  11350. 0x0020, // '000' + '0' (coding) + '00010000' + '0' (reference)
  11351. 0x0008 // '0000' + '001000'
  11352. ];
  11353. function decodeBitmapTemplate0(width, height, decodingContext) {
  11354. var decoder = decodingContext.decoder;
  11355. var contexts = decodingContext.contextCache.getContexts('GB');
  11356. var contextLabel, i, j, pixel, row, row1, row2, bitmap = [];
  11357. // ...ooooo....
  11358. // ..ooooooo... Context template for current pixel (X)
  11359. // .ooooX...... (concatenate values of 'o'-pixels to get contextLabel)
  11360. var OLD_PIXEL_MASK = 0x7BF7; // 01111 0111111 0111
  11361. for (i = 0; i < height; i++) {
  11362. row = bitmap[i] = new Uint8Array(width);
  11363. row1 = (i < 1) ? row : bitmap[i - 1];
  11364. row2 = (i < 2) ? row : bitmap[i - 2];
  11365. // At the beginning of each row:
  11366. // Fill contextLabel with pixels that are above/right of (X)
  11367. contextLabel = (row2[0] << 13) | (row2[1] << 12) | (row2[2] << 11) |
  11368. (row1[0] << 7) | (row1[1] << 6) | (row1[2] << 5) |
  11369. (row1[3] << 4);
  11370. for (j = 0; j < width; j++) {
  11371. row[j] = pixel = decoder.readBit(contexts, contextLabel);
  11372. // At each pixel: Clear contextLabel pixels that are shifted
  11373. // out of the context, then add new ones.
  11374. contextLabel = ((contextLabel & OLD_PIXEL_MASK) << 1) |
  11375. (j + 3 < width ? row2[j + 3] << 11 : 0) |
  11376. (j + 4 < width ? row1[j + 4] << 4 : 0) | pixel;
  11377. }
  11378. }
  11379. return bitmap;
  11380. }
  11381. // 6.2 Generic Region Decoding Procedure
  11382. function decodeBitmap(mmr, width, height, templateIndex, prediction, skip, at,
  11383. decodingContext) {
  11384. if (mmr) {
  11385. error('JBIG2 error: MMR encoding is not supported');
  11386. }
  11387. // Use optimized version for the most common case
  11388. if (templateIndex === 0 && !skip && !prediction && at.length === 4 &&
  11389. at[0].x === 3 && at[0].y === -1 && at[1].x === -3 && at[1].y === -1 &&
  11390. at[2].x === 2 && at[2].y === -2 && at[3].x === -2 && at[3].y === -2) {
  11391. return decodeBitmapTemplate0(width, height, decodingContext);
  11392. }
  11393. var useskip = !!skip;
  11394. var template = CodingTemplates[templateIndex].concat(at);
  11395. // Sorting is non-standard, and it is not required. But sorting increases
  11396. // the number of template bits that can be reused from the previous
  11397. // contextLabel in the main loop.
  11398. template.sort(function (a, b) {
  11399. return (a.y - b.y) || (a.x - b.x);
  11400. });
  11401. var templateLength = template.length;
  11402. var templateX = new Int8Array(templateLength);
  11403. var templateY = new Int8Array(templateLength);
  11404. var changingTemplateEntries = [];
  11405. var reuseMask = 0, minX = 0, maxX = 0, minY = 0;
  11406. var c, k;
  11407. for (k = 0; k < templateLength; k++) {
  11408. templateX[k] = template[k].x;
  11409. templateY[k] = template[k].y;
  11410. minX = Math.min(minX, template[k].x);
  11411. maxX = Math.max(maxX, template[k].x);
  11412. minY = Math.min(minY, template[k].y);
  11413. // Check if the template pixel appears in two consecutive context labels,
  11414. // so it can be reused. Otherwise, we add it to the list of changing
  11415. // template entries.
  11416. if (k < templateLength - 1 &&
  11417. template[k].y === template[k + 1].y &&
  11418. template[k].x === template[k + 1].x - 1) {
  11419. reuseMask |= 1 << (templateLength - 1 - k);
  11420. } else {
  11421. changingTemplateEntries.push(k);
  11422. }
  11423. }
  11424. var changingEntriesLength = changingTemplateEntries.length;
  11425. var changingTemplateX = new Int8Array(changingEntriesLength);
  11426. var changingTemplateY = new Int8Array(changingEntriesLength);
  11427. var changingTemplateBit = new Uint16Array(changingEntriesLength);
  11428. for (c = 0; c < changingEntriesLength; c++) {
  11429. k = changingTemplateEntries[c];
  11430. changingTemplateX[c] = template[k].x;
  11431. changingTemplateY[c] = template[k].y;
  11432. changingTemplateBit[c] = 1 << (templateLength - 1 - k);
  11433. }
  11434. // Get the safe bounding box edges from the width, height, minX, maxX, minY
  11435. var sbb_left = -minX;
  11436. var sbb_top = -minY;
  11437. var sbb_right = width - maxX;
  11438. var pseudoPixelContext = ReusedContexts[templateIndex];
  11439. var row = new Uint8Array(width);
  11440. var bitmap = [];
  11441. var decoder = decodingContext.decoder;
  11442. var contexts = decodingContext.contextCache.getContexts('GB');
  11443. var ltp = 0, j, i0, j0, contextLabel = 0, bit, shift;
  11444. for (var i = 0; i < height; i++) {
  11445. if (prediction) {
  11446. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  11447. ltp ^= sltp;
  11448. if (ltp) {
  11449. bitmap.push(row); // duplicate previous row
  11450. continue;
  11451. }
  11452. }
  11453. row = new Uint8Array(row);
  11454. bitmap.push(row);
  11455. for (j = 0; j < width; j++) {
  11456. if (useskip && skip[i][j]) {
  11457. row[j] = 0;
  11458. continue;
  11459. }
  11460. // Are we in the middle of a scanline, so we can reuse contextLabel
  11461. // bits?
  11462. if (j >= sbb_left && j < sbb_right && i >= sbb_top) {
  11463. // If yes, we can just shift the bits that are reusable and only
  11464. // fetch the remaining ones.
  11465. contextLabel = (contextLabel << 1) & reuseMask;
  11466. for (k = 0; k < changingEntriesLength; k++) {
  11467. i0 = i + changingTemplateY[k];
  11468. j0 = j + changingTemplateX[k];
  11469. bit = bitmap[i0][j0];
  11470. if (bit) {
  11471. bit = changingTemplateBit[k];
  11472. contextLabel |= bit;
  11473. }
  11474. }
  11475. } else {
  11476. // compute the contextLabel from scratch
  11477. contextLabel = 0;
  11478. shift = templateLength - 1;
  11479. for (k = 0; k < templateLength; k++, shift--) {
  11480. j0 = j + templateX[k];
  11481. if (j0 >= 0 && j0 < width) {
  11482. i0 = i + templateY[k];
  11483. if (i0 >= 0) {
  11484. bit = bitmap[i0][j0];
  11485. if (bit) {
  11486. contextLabel |= bit << shift;
  11487. }
  11488. }
  11489. }
  11490. }
  11491. }
  11492. var pixel = decoder.readBit(contexts, contextLabel);
  11493. row[j] = pixel;
  11494. }
  11495. }
  11496. return bitmap;
  11497. }
  11498. // 6.3.2 Generic Refinement Region Decoding Procedure
  11499. function decodeRefinement(width, height, templateIndex, referenceBitmap,
  11500. offsetX, offsetY, prediction, at,
  11501. decodingContext) {
  11502. var codingTemplate = RefinementTemplates[templateIndex].coding;
  11503. if (templateIndex === 0) {
  11504. codingTemplate = codingTemplate.concat([at[0]]);
  11505. }
  11506. var codingTemplateLength = codingTemplate.length;
  11507. var codingTemplateX = new Int32Array(codingTemplateLength);
  11508. var codingTemplateY = new Int32Array(codingTemplateLength);
  11509. var k;
  11510. for (k = 0; k < codingTemplateLength; k++) {
  11511. codingTemplateX[k] = codingTemplate[k].x;
  11512. codingTemplateY[k] = codingTemplate[k].y;
  11513. }
  11514. var referenceTemplate = RefinementTemplates[templateIndex].reference;
  11515. if (templateIndex === 0) {
  11516. referenceTemplate = referenceTemplate.concat([at[1]]);
  11517. }
  11518. var referenceTemplateLength = referenceTemplate.length;
  11519. var referenceTemplateX = new Int32Array(referenceTemplateLength);
  11520. var referenceTemplateY = new Int32Array(referenceTemplateLength);
  11521. for (k = 0; k < referenceTemplateLength; k++) {
  11522. referenceTemplateX[k] = referenceTemplate[k].x;
  11523. referenceTemplateY[k] = referenceTemplate[k].y;
  11524. }
  11525. var referenceWidth = referenceBitmap[0].length;
  11526. var referenceHeight = referenceBitmap.length;
  11527. var pseudoPixelContext = RefinementReusedContexts[templateIndex];
  11528. var bitmap = [];
  11529. var decoder = decodingContext.decoder;
  11530. var contexts = decodingContext.contextCache.getContexts('GR');
  11531. var ltp = 0;
  11532. for (var i = 0; i < height; i++) {
  11533. if (prediction) {
  11534. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  11535. ltp ^= sltp;
  11536. if (ltp) {
  11537. error('JBIG2 error: prediction is not supported');
  11538. }
  11539. }
  11540. var row = new Uint8Array(width);
  11541. bitmap.push(row);
  11542. for (var j = 0; j < width; j++) {
  11543. var i0, j0;
  11544. var contextLabel = 0;
  11545. for (k = 0; k < codingTemplateLength; k++) {
  11546. i0 = i + codingTemplateY[k];
  11547. j0 = j + codingTemplateX[k];
  11548. if (i0 < 0 || j0 < 0 || j0 >= width) {
  11549. contextLabel <<= 1; // out of bound pixel
  11550. } else {
  11551. contextLabel = (contextLabel << 1) | bitmap[i0][j0];
  11552. }
  11553. }
  11554. for (k = 0; k < referenceTemplateLength; k++) {
  11555. i0 = i + referenceTemplateY[k] + offsetY;
  11556. j0 = j + referenceTemplateX[k] + offsetX;
  11557. if (i0 < 0 || i0 >= referenceHeight || j0 < 0 ||
  11558. j0 >= referenceWidth) {
  11559. contextLabel <<= 1; // out of bound pixel
  11560. } else {
  11561. contextLabel = (contextLabel << 1) | referenceBitmap[i0][j0];
  11562. }
  11563. }
  11564. var pixel = decoder.readBit(contexts, contextLabel);
  11565. row[j] = pixel;
  11566. }
  11567. }
  11568. return bitmap;
  11569. }
  11570. // 6.5.5 Decoding the symbol dictionary
  11571. function decodeSymbolDictionary(huffman, refinement, symbols,
  11572. numberOfNewSymbols, numberOfExportedSymbols,
  11573. huffmanTables, templateIndex, at,
  11574. refinementTemplateIndex, refinementAt,
  11575. decodingContext) {
  11576. if (huffman) {
  11577. error('JBIG2 error: huffman is not supported');
  11578. }
  11579. var newSymbols = [];
  11580. var currentHeight = 0;
  11581. var symbolCodeLength = log2(symbols.length + numberOfNewSymbols);
  11582. var decoder = decodingContext.decoder;
  11583. var contextCache = decodingContext.contextCache;
  11584. while (newSymbols.length < numberOfNewSymbols) {
  11585. var deltaHeight = decodeInteger(contextCache, 'IADH', decoder); // 6.5.6
  11586. currentHeight += deltaHeight;
  11587. var currentWidth = 0;
  11588. var totalWidth = 0;
  11589. while (true) {
  11590. var deltaWidth = decodeInteger(contextCache, 'IADW', decoder); // 6.5.7
  11591. if (deltaWidth === null) {
  11592. break; // OOB
  11593. }
  11594. currentWidth += deltaWidth;
  11595. totalWidth += currentWidth;
  11596. var bitmap;
  11597. if (refinement) {
  11598. // 6.5.8.2 Refinement/aggregate-coded symbol bitmap
  11599. var numberOfInstances = decodeInteger(contextCache, 'IAAI', decoder);
  11600. if (numberOfInstances > 1) {
  11601. bitmap = decodeTextRegion(huffman, refinement,
  11602. currentWidth, currentHeight, 0,
  11603. numberOfInstances, 1, //strip size
  11604. symbols.concat(newSymbols),
  11605. symbolCodeLength,
  11606. 0, //transposed
  11607. 0, //ds offset
  11608. 1, //top left 7.4.3.1.1
  11609. 0, //OR operator
  11610. huffmanTables,
  11611. refinementTemplateIndex, refinementAt,
  11612. decodingContext);
  11613. } else {
  11614. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  11615. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  11616. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  11617. var symbol = (symbolId < symbols.length ? symbols[symbolId] :
  11618. newSymbols[symbolId - symbols.length]);
  11619. bitmap = decodeRefinement(currentWidth, currentHeight,
  11620. refinementTemplateIndex, symbol, rdx, rdy, false, refinementAt,
  11621. decodingContext);
  11622. }
  11623. } else {
  11624. // 6.5.8.1 Direct-coded symbol bitmap
  11625. bitmap = decodeBitmap(false, currentWidth, currentHeight,
  11626. templateIndex, false, null, at, decodingContext);
  11627. }
  11628. newSymbols.push(bitmap);
  11629. }
  11630. }
  11631. // 6.5.10 Exported symbols
  11632. var exportedSymbols = [];
  11633. var flags = [], currentFlag = false;
  11634. var totalSymbolsLength = symbols.length + numberOfNewSymbols;
  11635. while (flags.length < totalSymbolsLength) {
  11636. var runLength = decodeInteger(contextCache, 'IAEX', decoder);
  11637. while (runLength--) {
  11638. flags.push(currentFlag);
  11639. }
  11640. currentFlag = !currentFlag;
  11641. }
  11642. for (var i = 0, ii = symbols.length; i < ii; i++) {
  11643. if (flags[i]) {
  11644. exportedSymbols.push(symbols[i]);
  11645. }
  11646. }
  11647. for (var j = 0; j < numberOfNewSymbols; i++, j++) {
  11648. if (flags[i]) {
  11649. exportedSymbols.push(newSymbols[j]);
  11650. }
  11651. }
  11652. return exportedSymbols;
  11653. }
  11654. function decodeTextRegion(huffman, refinement, width, height,
  11655. defaultPixelValue, numberOfSymbolInstances,
  11656. stripSize, inputSymbols, symbolCodeLength,
  11657. transposed, dsOffset, referenceCorner,
  11658. combinationOperator, huffmanTables,
  11659. refinementTemplateIndex, refinementAt,
  11660. decodingContext) {
  11661. if (huffman) {
  11662. error('JBIG2 error: huffman is not supported');
  11663. }
  11664. // Prepare bitmap
  11665. var bitmap = [];
  11666. var i, row;
  11667. for (i = 0; i < height; i++) {
  11668. row = new Uint8Array(width);
  11669. if (defaultPixelValue) {
  11670. for (var j = 0; j < width; j++) {
  11671. row[j] = defaultPixelValue;
  11672. }
  11673. }
  11674. bitmap.push(row);
  11675. }
  11676. var decoder = decodingContext.decoder;
  11677. var contextCache = decodingContext.contextCache;
  11678. var stripT = -decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  11679. var firstS = 0;
  11680. i = 0;
  11681. while (i < numberOfSymbolInstances) {
  11682. var deltaT = decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  11683. stripT += deltaT;
  11684. var deltaFirstS = decodeInteger(contextCache, 'IAFS', decoder); // 6.4.7
  11685. firstS += deltaFirstS;
  11686. var currentS = firstS;
  11687. do {
  11688. var currentT = (stripSize === 1 ? 0 :
  11689. decodeInteger(contextCache, 'IAIT', decoder)); // 6.4.9
  11690. var t = stripSize * stripT + currentT;
  11691. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  11692. var applyRefinement = (refinement &&
  11693. decodeInteger(contextCache, 'IARI', decoder));
  11694. var symbolBitmap = inputSymbols[symbolId];
  11695. var symbolWidth = symbolBitmap[0].length;
  11696. var symbolHeight = symbolBitmap.length;
  11697. if (applyRefinement) {
  11698. var rdw = decodeInteger(contextCache, 'IARDW', decoder); // 6.4.11.1
  11699. var rdh = decodeInteger(contextCache, 'IARDH', decoder); // 6.4.11.2
  11700. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  11701. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  11702. symbolWidth += rdw;
  11703. symbolHeight += rdh;
  11704. symbolBitmap = decodeRefinement(symbolWidth, symbolHeight,
  11705. refinementTemplateIndex, symbolBitmap, (rdw >> 1) + rdx,
  11706. (rdh >> 1) + rdy, false, refinementAt,
  11707. decodingContext);
  11708. }
  11709. var offsetT = t - ((referenceCorner & 1) ? 0 : symbolHeight);
  11710. var offsetS = currentS - ((referenceCorner & 2) ? symbolWidth : 0);
  11711. var s2, t2, symbolRow;
  11712. if (transposed) {
  11713. // Place Symbol Bitmap from T1,S1
  11714. for (s2 = 0; s2 < symbolHeight; s2++) {
  11715. row = bitmap[offsetS + s2];
  11716. if (!row) {
  11717. continue;
  11718. }
  11719. symbolRow = symbolBitmap[s2];
  11720. // To ignore Parts of Symbol bitmap which goes
  11721. // outside bitmap region
  11722. var maxWidth = Math.min(width - offsetT, symbolWidth);
  11723. switch (combinationOperator) {
  11724. case 0: // OR
  11725. for (t2 = 0; t2 < maxWidth; t2++) {
  11726. row[offsetT + t2] |= symbolRow[t2];
  11727. }
  11728. break;
  11729. case 2: // XOR
  11730. for (t2 = 0; t2 < maxWidth; t2++) {
  11731. row[offsetT + t2] ^= symbolRow[t2];
  11732. }
  11733. break;
  11734. default:
  11735. error('JBIG2 error: operator ' + combinationOperator +
  11736. ' is not supported');
  11737. }
  11738. }
  11739. currentS += symbolHeight - 1;
  11740. } else {
  11741. for (t2 = 0; t2 < symbolHeight; t2++) {
  11742. row = bitmap[offsetT + t2];
  11743. if (!row) {
  11744. continue;
  11745. }
  11746. symbolRow = symbolBitmap[t2];
  11747. switch (combinationOperator) {
  11748. case 0: // OR
  11749. for (s2 = 0; s2 < symbolWidth; s2++) {
  11750. row[offsetS + s2] |= symbolRow[s2];
  11751. }
  11752. break;
  11753. case 2: // XOR
  11754. for (s2 = 0; s2 < symbolWidth; s2++) {
  11755. row[offsetS + s2] ^= symbolRow[s2];
  11756. }
  11757. break;
  11758. default:
  11759. error('JBIG2 error: operator ' + combinationOperator +
  11760. ' is not supported');
  11761. }
  11762. }
  11763. currentS += symbolWidth - 1;
  11764. }
  11765. i++;
  11766. var deltaS = decodeInteger(contextCache, 'IADS', decoder); // 6.4.8
  11767. if (deltaS === null) {
  11768. break; // OOB
  11769. }
  11770. currentS += deltaS + dsOffset;
  11771. } while (true);
  11772. }
  11773. return bitmap;
  11774. }
  11775. function readSegmentHeader(data, start) {
  11776. var segmentHeader = {};
  11777. segmentHeader.number = readUint32(data, start);
  11778. var flags = data[start + 4];
  11779. var segmentType = flags & 0x3F;
  11780. if (!SegmentTypes[segmentType]) {
  11781. error('JBIG2 error: invalid segment type: ' + segmentType);
  11782. }
  11783. segmentHeader.type = segmentType;
  11784. segmentHeader.typeName = SegmentTypes[segmentType];
  11785. segmentHeader.deferredNonRetain = !!(flags & 0x80);
  11786. var pageAssociationFieldSize = !!(flags & 0x40);
  11787. var referredFlags = data[start + 5];
  11788. var referredToCount = (referredFlags >> 5) & 7;
  11789. var retainBits = [referredFlags & 31];
  11790. var position = start + 6;
  11791. if (referredFlags === 7) {
  11792. referredToCount = readUint32(data, position - 1) & 0x1FFFFFFF;
  11793. position += 3;
  11794. var bytes = (referredToCount + 7) >> 3;
  11795. retainBits[0] = data[position++];
  11796. while (--bytes > 0) {
  11797. retainBits.push(data[position++]);
  11798. }
  11799. } else if (referredFlags === 5 || referredFlags === 6) {
  11800. error('JBIG2 error: invalid referred-to flags');
  11801. }
  11802. segmentHeader.retainBits = retainBits;
  11803. var referredToSegmentNumberSize = (segmentHeader.number <= 256 ? 1 :
  11804. (segmentHeader.number <= 65536 ? 2 : 4));
  11805. var referredTo = [];
  11806. var i, ii;
  11807. for (i = 0; i < referredToCount; i++) {
  11808. var number = (referredToSegmentNumberSize === 1 ? data[position] :
  11809. (referredToSegmentNumberSize === 2 ? readUint16(data, position) :
  11810. readUint32(data, position)));
  11811. referredTo.push(number);
  11812. position += referredToSegmentNumberSize;
  11813. }
  11814. segmentHeader.referredTo = referredTo;
  11815. if (!pageAssociationFieldSize) {
  11816. segmentHeader.pageAssociation = data[position++];
  11817. } else {
  11818. segmentHeader.pageAssociation = readUint32(data, position);
  11819. position += 4;
  11820. }
  11821. segmentHeader.length = readUint32(data, position);
  11822. position += 4;
  11823. if (segmentHeader.length === 0xFFFFFFFF) {
  11824. // 7.2.7 Segment data length, unknown segment length
  11825. if (segmentType === 38) { // ImmediateGenericRegion
  11826. var genericRegionInfo = readRegionSegmentInformation(data, position);
  11827. var genericRegionSegmentFlags = data[position +
  11828. RegionSegmentInformationFieldLength];
  11829. var genericRegionMmr = !!(genericRegionSegmentFlags & 1);
  11830. // searching for the segment end
  11831. var searchPatternLength = 6;
  11832. var searchPattern = new Uint8Array(searchPatternLength);
  11833. if (!genericRegionMmr) {
  11834. searchPattern[0] = 0xFF;
  11835. searchPattern[1] = 0xAC;
  11836. }
  11837. searchPattern[2] = (genericRegionInfo.height >>> 24) & 0xFF;
  11838. searchPattern[3] = (genericRegionInfo.height >> 16) & 0xFF;
  11839. searchPattern[4] = (genericRegionInfo.height >> 8) & 0xFF;
  11840. searchPattern[5] = genericRegionInfo.height & 0xFF;
  11841. for (i = position, ii = data.length; i < ii; i++) {
  11842. var j = 0;
  11843. while (j < searchPatternLength && searchPattern[j] === data[i + j]) {
  11844. j++;
  11845. }
  11846. if (j === searchPatternLength) {
  11847. segmentHeader.length = i + searchPatternLength;
  11848. break;
  11849. }
  11850. }
  11851. if (segmentHeader.length === 0xFFFFFFFF) {
  11852. error('JBIG2 error: segment end was not found');
  11853. }
  11854. } else {
  11855. error('JBIG2 error: invalid unknown segment length');
  11856. }
  11857. }
  11858. segmentHeader.headerEnd = position;
  11859. return segmentHeader;
  11860. }
  11861. function readSegments(header, data, start, end) {
  11862. var segments = [];
  11863. var position = start;
  11864. while (position < end) {
  11865. var segmentHeader = readSegmentHeader(data, position);
  11866. position = segmentHeader.headerEnd;
  11867. var segment = {
  11868. header: segmentHeader,
  11869. data: data
  11870. };
  11871. if (!header.randomAccess) {
  11872. segment.start = position;
  11873. position += segmentHeader.length;
  11874. segment.end = position;
  11875. }
  11876. segments.push(segment);
  11877. if (segmentHeader.type === 51) {
  11878. break; // end of file is found
  11879. }
  11880. }
  11881. if (header.randomAccess) {
  11882. for (var i = 0, ii = segments.length; i < ii; i++) {
  11883. segments[i].start = position;
  11884. position += segments[i].header.length;
  11885. segments[i].end = position;
  11886. }
  11887. }
  11888. return segments;
  11889. }
  11890. // 7.4.1 Region segment information field
  11891. function readRegionSegmentInformation(data, start) {
  11892. return {
  11893. width: readUint32(data, start),
  11894. height: readUint32(data, start + 4),
  11895. x: readUint32(data, start + 8),
  11896. y: readUint32(data, start + 12),
  11897. combinationOperator: data[start + 16] & 7
  11898. };
  11899. }
  11900. var RegionSegmentInformationFieldLength = 17;
  11901. function processSegment(segment, visitor) {
  11902. var header = segment.header;
  11903. var data = segment.data, position = segment.start, end = segment.end;
  11904. var args, at, i, atLength;
  11905. switch (header.type) {
  11906. case 0: // SymbolDictionary
  11907. // 7.4.2 Symbol dictionary segment syntax
  11908. var dictionary = {};
  11909. var dictionaryFlags = readUint16(data, position); // 7.4.2.1.1
  11910. dictionary.huffman = !!(dictionaryFlags & 1);
  11911. dictionary.refinement = !!(dictionaryFlags & 2);
  11912. dictionary.huffmanDHSelector = (dictionaryFlags >> 2) & 3;
  11913. dictionary.huffmanDWSelector = (dictionaryFlags >> 4) & 3;
  11914. dictionary.bitmapSizeSelector = (dictionaryFlags >> 6) & 1;
  11915. dictionary.aggregationInstancesSelector = (dictionaryFlags >> 7) & 1;
  11916. dictionary.bitmapCodingContextUsed = !!(dictionaryFlags & 256);
  11917. dictionary.bitmapCodingContextRetained = !!(dictionaryFlags & 512);
  11918. dictionary.template = (dictionaryFlags >> 10) & 3;
  11919. dictionary.refinementTemplate = (dictionaryFlags >> 12) & 1;
  11920. position += 2;
  11921. if (!dictionary.huffman) {
  11922. atLength = dictionary.template === 0 ? 4 : 1;
  11923. at = [];
  11924. for (i = 0; i < atLength; i++) {
  11925. at.push({
  11926. x: readInt8(data, position),
  11927. y: readInt8(data, position + 1)
  11928. });
  11929. position += 2;
  11930. }
  11931. dictionary.at = at;
  11932. }
  11933. if (dictionary.refinement && !dictionary.refinementTemplate) {
  11934. at = [];
  11935. for (i = 0; i < 2; i++) {
  11936. at.push({
  11937. x: readInt8(data, position),
  11938. y: readInt8(data, position + 1)
  11939. });
  11940. position += 2;
  11941. }
  11942. dictionary.refinementAt = at;
  11943. }
  11944. dictionary.numberOfExportedSymbols = readUint32(data, position);
  11945. position += 4;
  11946. dictionary.numberOfNewSymbols = readUint32(data, position);
  11947. position += 4;
  11948. args = [dictionary, header.number, header.referredTo,
  11949. data, position, end];
  11950. break;
  11951. case 6: // ImmediateTextRegion
  11952. case 7: // ImmediateLosslessTextRegion
  11953. var textRegion = {};
  11954. textRegion.info = readRegionSegmentInformation(data, position);
  11955. position += RegionSegmentInformationFieldLength;
  11956. var textRegionSegmentFlags = readUint16(data, position);
  11957. position += 2;
  11958. textRegion.huffman = !!(textRegionSegmentFlags & 1);
  11959. textRegion.refinement = !!(textRegionSegmentFlags & 2);
  11960. textRegion.stripSize = 1 << ((textRegionSegmentFlags >> 2) & 3);
  11961. textRegion.referenceCorner = (textRegionSegmentFlags >> 4) & 3;
  11962. textRegion.transposed = !!(textRegionSegmentFlags & 64);
  11963. textRegion.combinationOperator = (textRegionSegmentFlags >> 7) & 3;
  11964. textRegion.defaultPixelValue = (textRegionSegmentFlags >> 9) & 1;
  11965. textRegion.dsOffset = (textRegionSegmentFlags << 17) >> 27;
  11966. textRegion.refinementTemplate = (textRegionSegmentFlags >> 15) & 1;
  11967. if (textRegion.huffman) {
  11968. var textRegionHuffmanFlags = readUint16(data, position);
  11969. position += 2;
  11970. textRegion.huffmanFS = (textRegionHuffmanFlags) & 3;
  11971. textRegion.huffmanDS = (textRegionHuffmanFlags >> 2) & 3;
  11972. textRegion.huffmanDT = (textRegionHuffmanFlags >> 4) & 3;
  11973. textRegion.huffmanRefinementDW = (textRegionHuffmanFlags >> 6) & 3;
  11974. textRegion.huffmanRefinementDH = (textRegionHuffmanFlags >> 8) & 3;
  11975. textRegion.huffmanRefinementDX = (textRegionHuffmanFlags >> 10) & 3;
  11976. textRegion.huffmanRefinementDY = (textRegionHuffmanFlags >> 12) & 3;
  11977. textRegion.huffmanRefinementSizeSelector =
  11978. !!(textRegionHuffmanFlags & 14);
  11979. }
  11980. if (textRegion.refinement && !textRegion.refinementTemplate) {
  11981. at = [];
  11982. for (i = 0; i < 2; i++) {
  11983. at.push({
  11984. x: readInt8(data, position),
  11985. y: readInt8(data, position + 1)
  11986. });
  11987. position += 2;
  11988. }
  11989. textRegion.refinementAt = at;
  11990. }
  11991. textRegion.numberOfSymbolInstances = readUint32(data, position);
  11992. position += 4;
  11993. // TODO 7.4.3.1.7 Symbol ID Huffman table decoding
  11994. if (textRegion.huffman) {
  11995. error('JBIG2 error: huffman is not supported');
  11996. }
  11997. args = [textRegion, header.referredTo, data, position, end];
  11998. break;
  11999. case 38: // ImmediateGenericRegion
  12000. case 39: // ImmediateLosslessGenericRegion
  12001. var genericRegion = {};
  12002. genericRegion.info = readRegionSegmentInformation(data, position);
  12003. position += RegionSegmentInformationFieldLength;
  12004. var genericRegionSegmentFlags = data[position++];
  12005. genericRegion.mmr = !!(genericRegionSegmentFlags & 1);
  12006. genericRegion.template = (genericRegionSegmentFlags >> 1) & 3;
  12007. genericRegion.prediction = !!(genericRegionSegmentFlags & 8);
  12008. if (!genericRegion.mmr) {
  12009. atLength = genericRegion.template === 0 ? 4 : 1;
  12010. at = [];
  12011. for (i = 0; i < atLength; i++) {
  12012. at.push({
  12013. x: readInt8(data, position),
  12014. y: readInt8(data, position + 1)
  12015. });
  12016. position += 2;
  12017. }
  12018. genericRegion.at = at;
  12019. }
  12020. args = [genericRegion, data, position, end];
  12021. break;
  12022. case 48: // PageInformation
  12023. var pageInfo = {
  12024. width: readUint32(data, position),
  12025. height: readUint32(data, position + 4),
  12026. resolutionX: readUint32(data, position + 8),
  12027. resolutionY: readUint32(data, position + 12)
  12028. };
  12029. if (pageInfo.height === 0xFFFFFFFF) {
  12030. delete pageInfo.height;
  12031. }
  12032. var pageSegmentFlags = data[position + 16];
  12033. var pageStripingInformatiom = readUint16(data, position + 17);
  12034. pageInfo.lossless = !!(pageSegmentFlags & 1);
  12035. pageInfo.refinement = !!(pageSegmentFlags & 2);
  12036. pageInfo.defaultPixelValue = (pageSegmentFlags >> 2) & 1;
  12037. pageInfo.combinationOperator = (pageSegmentFlags >> 3) & 3;
  12038. pageInfo.requiresBuffer = !!(pageSegmentFlags & 32);
  12039. pageInfo.combinationOperatorOverride = !!(pageSegmentFlags & 64);
  12040. args = [pageInfo];
  12041. break;
  12042. case 49: // EndOfPage
  12043. break;
  12044. case 50: // EndOfStripe
  12045. break;
  12046. case 51: // EndOfFile
  12047. break;
  12048. case 62: // 7.4.15 defines 2 extension types which
  12049. // are comments and can be ignored.
  12050. break;
  12051. default:
  12052. error('JBIG2 error: segment type ' + header.typeName + '(' +
  12053. header.type + ') is not implemented');
  12054. }
  12055. var callbackName = 'on' + header.typeName;
  12056. if (callbackName in visitor) {
  12057. visitor[callbackName].apply(visitor, args);
  12058. }
  12059. }
  12060. function processSegments(segments, visitor) {
  12061. for (var i = 0, ii = segments.length; i < ii; i++) {
  12062. processSegment(segments[i], visitor);
  12063. }
  12064. }
  12065. function parseJbig2(data, start, end) {
  12066. var position = start;
  12067. if (data[position] !== 0x97 || data[position + 1] !== 0x4A ||
  12068. data[position + 2] !== 0x42 || data[position + 3] !== 0x32 ||
  12069. data[position + 4] !== 0x0D || data[position + 5] !== 0x0A ||
  12070. data[position + 6] !== 0x1A || data[position + 7] !== 0x0A) {
  12071. error('JBIG2 error: invalid header');
  12072. }
  12073. var header = {};
  12074. position += 8;
  12075. var flags = data[position++];
  12076. header.randomAccess = !(flags & 1);
  12077. if (!(flags & 2)) {
  12078. header.numberOfPages = readUint32(data, position);
  12079. position += 4;
  12080. }
  12081. var segments = readSegments(header, data, position, end);
  12082. error('Not implemented');
  12083. // processSegments(segments, new SimpleSegmentVisitor());
  12084. }
  12085. function parseJbig2Chunks(chunks) {
  12086. var visitor = new SimpleSegmentVisitor();
  12087. for (var i = 0, ii = chunks.length; i < ii; i++) {
  12088. var chunk = chunks[i];
  12089. var segments = readSegments({}, chunk.data, chunk.start, chunk.end);
  12090. processSegments(segments, visitor);
  12091. }
  12092. return visitor.buffer;
  12093. }
  12094. function SimpleSegmentVisitor() {}
  12095. SimpleSegmentVisitor.prototype = {
  12096. onPageInformation: function SimpleSegmentVisitor_onPageInformation(info) {
  12097. this.currentPageInfo = info;
  12098. var rowSize = (info.width + 7) >> 3;
  12099. var buffer = new Uint8Array(rowSize * info.height);
  12100. // The contents of ArrayBuffers are initialized to 0.
  12101. // Fill the buffer with 0xFF only if info.defaultPixelValue is set
  12102. if (info.defaultPixelValue) {
  12103. for (var i = 0, ii = buffer.length; i < ii; i++) {
  12104. buffer[i] = 0xFF;
  12105. }
  12106. }
  12107. this.buffer = buffer;
  12108. },
  12109. drawBitmap: function SimpleSegmentVisitor_drawBitmap(regionInfo, bitmap) {
  12110. var pageInfo = this.currentPageInfo;
  12111. var width = regionInfo.width, height = regionInfo.height;
  12112. var rowSize = (pageInfo.width + 7) >> 3;
  12113. var combinationOperator = pageInfo.combinationOperatorOverride ?
  12114. regionInfo.combinationOperator : pageInfo.combinationOperator;
  12115. var buffer = this.buffer;
  12116. var mask0 = 128 >> (regionInfo.x & 7);
  12117. var offset0 = regionInfo.y * rowSize + (regionInfo.x >> 3);
  12118. var i, j, mask, offset;
  12119. switch (combinationOperator) {
  12120. case 0: // OR
  12121. for (i = 0; i < height; i++) {
  12122. mask = mask0;
  12123. offset = offset0;
  12124. for (j = 0; j < width; j++) {
  12125. if (bitmap[i][j]) {
  12126. buffer[offset] |= mask;
  12127. }
  12128. mask >>= 1;
  12129. if (!mask) {
  12130. mask = 128;
  12131. offset++;
  12132. }
  12133. }
  12134. offset0 += rowSize;
  12135. }
  12136. break;
  12137. case 2: // XOR
  12138. for (i = 0; i < height; i++) {
  12139. mask = mask0;
  12140. offset = offset0;
  12141. for (j = 0; j < width; j++) {
  12142. if (bitmap[i][j]) {
  12143. buffer[offset] ^= mask;
  12144. }
  12145. mask >>= 1;
  12146. if (!mask) {
  12147. mask = 128;
  12148. offset++;
  12149. }
  12150. }
  12151. offset0 += rowSize;
  12152. }
  12153. break;
  12154. default:
  12155. error('JBIG2 error: operator ' + combinationOperator +
  12156. ' is not supported');
  12157. }
  12158. },
  12159. onImmediateGenericRegion:
  12160. function SimpleSegmentVisitor_onImmediateGenericRegion(region, data,
  12161. start, end) {
  12162. var regionInfo = region.info;
  12163. var decodingContext = new DecodingContext(data, start, end);
  12164. var bitmap = decodeBitmap(region.mmr, regionInfo.width, regionInfo.height,
  12165. region.template, region.prediction, null,
  12166. region.at, decodingContext);
  12167. this.drawBitmap(regionInfo, bitmap);
  12168. },
  12169. onImmediateLosslessGenericRegion:
  12170. function SimpleSegmentVisitor_onImmediateLosslessGenericRegion() {
  12171. this.onImmediateGenericRegion.apply(this, arguments);
  12172. },
  12173. onSymbolDictionary:
  12174. function SimpleSegmentVisitor_onSymbolDictionary(dictionary,
  12175. currentSegment,
  12176. referredSegments,
  12177. data, start, end) {
  12178. var huffmanTables;
  12179. if (dictionary.huffman) {
  12180. error('JBIG2 error: huffman is not supported');
  12181. }
  12182. // Combines exported symbols from all referred segments
  12183. var symbols = this.symbols;
  12184. if (!symbols) {
  12185. this.symbols = symbols = {};
  12186. }
  12187. var inputSymbols = [];
  12188. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  12189. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  12190. }
  12191. var decodingContext = new DecodingContext(data, start, end);
  12192. symbols[currentSegment] = decodeSymbolDictionary(dictionary.huffman,
  12193. dictionary.refinement, inputSymbols, dictionary.numberOfNewSymbols,
  12194. dictionary.numberOfExportedSymbols, huffmanTables,
  12195. dictionary.template, dictionary.at,
  12196. dictionary.refinementTemplate, dictionary.refinementAt,
  12197. decodingContext);
  12198. },
  12199. onImmediateTextRegion:
  12200. function SimpleSegmentVisitor_onImmediateTextRegion(region,
  12201. referredSegments,
  12202. data, start, end) {
  12203. var regionInfo = region.info;
  12204. var huffmanTables;
  12205. // Combines exported symbols from all referred segments
  12206. var symbols = this.symbols;
  12207. var inputSymbols = [];
  12208. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  12209. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  12210. }
  12211. var symbolCodeLength = log2(inputSymbols.length);
  12212. var decodingContext = new DecodingContext(data, start, end);
  12213. var bitmap = decodeTextRegion(region.huffman, region.refinement,
  12214. regionInfo.width, regionInfo.height, region.defaultPixelValue,
  12215. region.numberOfSymbolInstances, region.stripSize, inputSymbols,
  12216. symbolCodeLength, region.transposed, region.dsOffset,
  12217. region.referenceCorner, region.combinationOperator, huffmanTables,
  12218. region.refinementTemplate, region.refinementAt, decodingContext);
  12219. this.drawBitmap(regionInfo, bitmap);
  12220. },
  12221. onImmediateLosslessTextRegion:
  12222. function SimpleSegmentVisitor_onImmediateLosslessTextRegion() {
  12223. this.onImmediateTextRegion.apply(this, arguments);
  12224. }
  12225. };
  12226. function Jbig2Image() {}
  12227. Jbig2Image.prototype = {
  12228. parseChunks: function Jbig2Image_parseChunks(chunks) {
  12229. return parseJbig2Chunks(chunks);
  12230. }
  12231. };
  12232. return Jbig2Image;
  12233. })();
  12234. exports.Jbig2Image = Jbig2Image;
  12235. }));
  12236. (function (root, factory) {
  12237. if (typeof define === 'function' && define.amd) {
  12238. define('pdfjs/core/jpx', ['exports', 'pdfjs/shared/util',
  12239. 'pdfjs/core/arithmetic_decoder'], factory);
  12240. } else if (typeof exports !== 'undefined') {
  12241. factory(exports, require('../shared/util.js'),
  12242. require('./arithmetic_decoder.js'));
  12243. } else {
  12244. factory((root.pdfjsCoreJpx = {}), root.pdfjsSharedUtil,
  12245. root.pdfjsCoreArithmeticDecoder);
  12246. }
  12247. }(this, function (exports, sharedUtil, coreArithmeticDecoder) {
  12248. var info = sharedUtil.info;
  12249. var log2 = sharedUtil.log2;
  12250. var readUint16 = sharedUtil.readUint16;
  12251. var readUint32 = sharedUtil.readUint32;
  12252. var warn = sharedUtil.warn;
  12253. var ArithmeticDecoder = coreArithmeticDecoder.ArithmeticDecoder;
  12254. var JpxImage = (function JpxImageClosure() {
  12255. // Table E.1
  12256. var SubbandsGainLog2 = {
  12257. 'LL': 0,
  12258. 'LH': 1,
  12259. 'HL': 1,
  12260. 'HH': 2
  12261. };
  12262. function JpxImage() {
  12263. this.failOnCorruptedImage = false;
  12264. }
  12265. JpxImage.prototype = {
  12266. parse: function JpxImage_parse(data) {
  12267. var head = readUint16(data, 0);
  12268. // No box header, immediate start of codestream (SOC)
  12269. if (head === 0xFF4F) {
  12270. this.parseCodestream(data, 0, data.length);
  12271. return;
  12272. }
  12273. var position = 0, length = data.length;
  12274. while (position < length) {
  12275. var headerSize = 8;
  12276. var lbox = readUint32(data, position);
  12277. var tbox = readUint32(data, position + 4);
  12278. position += headerSize;
  12279. if (lbox === 1) {
  12280. // XLBox: read UInt64 according to spec.
  12281. // JavaScript's int precision of 53 bit should be sufficient here.
  12282. lbox = readUint32(data, position) * 4294967296 +
  12283. readUint32(data, position + 4);
  12284. position += 8;
  12285. headerSize += 8;
  12286. }
  12287. if (lbox === 0) {
  12288. lbox = length - position + headerSize;
  12289. }
  12290. if (lbox < headerSize) {
  12291. throw new Error('JPX Error: Invalid box field size');
  12292. }
  12293. var dataLength = lbox - headerSize;
  12294. var jumpDataLength = true;
  12295. switch (tbox) {
  12296. case 0x6A703268: // 'jp2h'
  12297. jumpDataLength = false; // parsing child boxes
  12298. break;
  12299. case 0x636F6C72: // 'colr'
  12300. // Colorspaces are not used, the CS from the PDF is used.
  12301. var method = data[position];
  12302. var precedence = data[position + 1];
  12303. var approximation = data[position + 2];
  12304. if (method === 1) {
  12305. // enumerated colorspace
  12306. var colorspace = readUint32(data, position + 3);
  12307. switch (colorspace) {
  12308. case 16: // this indicates a sRGB colorspace
  12309. case 17: // this indicates a grayscale colorspace
  12310. case 18: // this indicates a YUV colorspace
  12311. break;
  12312. default:
  12313. warn('Unknown colorspace ' + colorspace);
  12314. break;
  12315. }
  12316. } else if (method === 2) {
  12317. info('ICC profile not supported');
  12318. }
  12319. break;
  12320. case 0x6A703263: // 'jp2c'
  12321. this.parseCodestream(data, position, position + dataLength);
  12322. break;
  12323. case 0x6A502020: // 'jP\024\024'
  12324. if (0x0d0a870a !== readUint32(data, position)) {
  12325. warn('Invalid JP2 signature');
  12326. }
  12327. break;
  12328. // The following header types are valid but currently not used:
  12329. case 0x6A501A1A: // 'jP\032\032'
  12330. case 0x66747970: // 'ftyp'
  12331. case 0x72726571: // 'rreq'
  12332. case 0x72657320: // 'res '
  12333. case 0x69686472: // 'ihdr'
  12334. break;
  12335. default:
  12336. var headerType = String.fromCharCode((tbox >> 24) & 0xFF,
  12337. (tbox >> 16) & 0xFF,
  12338. (tbox >> 8) & 0xFF,
  12339. tbox & 0xFF);
  12340. warn('Unsupported header type ' + tbox + ' (' + headerType + ')');
  12341. break;
  12342. }
  12343. if (jumpDataLength) {
  12344. position += dataLength;
  12345. }
  12346. }
  12347. },
  12348. parseImageProperties: function JpxImage_parseImageProperties(stream) {
  12349. var newByte = stream.getByte();
  12350. while (newByte >= 0) {
  12351. var oldByte = newByte;
  12352. newByte = stream.getByte();
  12353. var code = (oldByte << 8) | newByte;
  12354. // Image and tile size (SIZ)
  12355. if (code === 0xFF51) {
  12356. stream.skip(4);
  12357. var Xsiz = stream.getInt32() >>> 0; // Byte 4
  12358. var Ysiz = stream.getInt32() >>> 0; // Byte 8
  12359. var XOsiz = stream.getInt32() >>> 0; // Byte 12
  12360. var YOsiz = stream.getInt32() >>> 0; // Byte 16
  12361. stream.skip(16);
  12362. var Csiz = stream.getUint16(); // Byte 36
  12363. this.width = Xsiz - XOsiz;
  12364. this.height = Ysiz - YOsiz;
  12365. this.componentsCount = Csiz;
  12366. // Results are always returned as Uint8Arrays
  12367. this.bitsPerComponent = 8;
  12368. return;
  12369. }
  12370. }
  12371. throw new Error('JPX Error: No size marker found in JPX stream');
  12372. },
  12373. parseCodestream: function JpxImage_parseCodestream(data, start, end) {
  12374. var context = {};
  12375. try {
  12376. var doNotRecover = false;
  12377. var position = start;
  12378. while (position + 1 < end) {
  12379. var code = readUint16(data, position);
  12380. position += 2;
  12381. var length = 0, j, sqcd, spqcds, spqcdSize, scalarExpounded, tile;
  12382. switch (code) {
  12383. case 0xFF4F: // Start of codestream (SOC)
  12384. context.mainHeader = true;
  12385. break;
  12386. case 0xFFD9: // End of codestream (EOC)
  12387. break;
  12388. case 0xFF51: // Image and tile size (SIZ)
  12389. length = readUint16(data, position);
  12390. var siz = {};
  12391. siz.Xsiz = readUint32(data, position + 4);
  12392. siz.Ysiz = readUint32(data, position + 8);
  12393. siz.XOsiz = readUint32(data, position + 12);
  12394. siz.YOsiz = readUint32(data, position + 16);
  12395. siz.XTsiz = readUint32(data, position + 20);
  12396. siz.YTsiz = readUint32(data, position + 24);
  12397. siz.XTOsiz = readUint32(data, position + 28);
  12398. siz.YTOsiz = readUint32(data, position + 32);
  12399. var componentsCount = readUint16(data, position + 36);
  12400. siz.Csiz = componentsCount;
  12401. var components = [];
  12402. j = position + 38;
  12403. for (var i = 0; i < componentsCount; i++) {
  12404. var component = {
  12405. precision: (data[j] & 0x7F) + 1,
  12406. isSigned: !!(data[j] & 0x80),
  12407. XRsiz: data[j + 1],
  12408. YRsiz: data[j + 1]
  12409. };
  12410. calculateComponentDimensions(component, siz);
  12411. components.push(component);
  12412. }
  12413. context.SIZ = siz;
  12414. context.components = components;
  12415. calculateTileGrids(context, components);
  12416. context.QCC = [];
  12417. context.COC = [];
  12418. break;
  12419. case 0xFF5C: // Quantization default (QCD)
  12420. length = readUint16(data, position);
  12421. var qcd = {};
  12422. j = position + 2;
  12423. sqcd = data[j++];
  12424. switch (sqcd & 0x1F) {
  12425. case 0:
  12426. spqcdSize = 8;
  12427. scalarExpounded = true;
  12428. break;
  12429. case 1:
  12430. spqcdSize = 16;
  12431. scalarExpounded = false;
  12432. break;
  12433. case 2:
  12434. spqcdSize = 16;
  12435. scalarExpounded = true;
  12436. break;
  12437. default:
  12438. throw new Error('JPX Error: Invalid SQcd value ' + sqcd);
  12439. }
  12440. qcd.noQuantization = (spqcdSize === 8);
  12441. qcd.scalarExpounded = scalarExpounded;
  12442. qcd.guardBits = sqcd >> 5;
  12443. spqcds = [];
  12444. while (j < length + position) {
  12445. var spqcd = {};
  12446. if (spqcdSize === 8) {
  12447. spqcd.epsilon = data[j++] >> 3;
  12448. spqcd.mu = 0;
  12449. } else {
  12450. spqcd.epsilon = data[j] >> 3;
  12451. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  12452. j += 2;
  12453. }
  12454. spqcds.push(spqcd);
  12455. }
  12456. qcd.SPqcds = spqcds;
  12457. if (context.mainHeader) {
  12458. context.QCD = qcd;
  12459. } else {
  12460. context.currentTile.QCD = qcd;
  12461. context.currentTile.QCC = [];
  12462. }
  12463. break;
  12464. case 0xFF5D: // Quantization component (QCC)
  12465. length = readUint16(data, position);
  12466. var qcc = {};
  12467. j = position + 2;
  12468. var cqcc;
  12469. if (context.SIZ.Csiz < 257) {
  12470. cqcc = data[j++];
  12471. } else {
  12472. cqcc = readUint16(data, j);
  12473. j += 2;
  12474. }
  12475. sqcd = data[j++];
  12476. switch (sqcd & 0x1F) {
  12477. case 0:
  12478. spqcdSize = 8;
  12479. scalarExpounded = true;
  12480. break;
  12481. case 1:
  12482. spqcdSize = 16;
  12483. scalarExpounded = false;
  12484. break;
  12485. case 2:
  12486. spqcdSize = 16;
  12487. scalarExpounded = true;
  12488. break;
  12489. default:
  12490. throw new Error('JPX Error: Invalid SQcd value ' + sqcd);
  12491. }
  12492. qcc.noQuantization = (spqcdSize === 8);
  12493. qcc.scalarExpounded = scalarExpounded;
  12494. qcc.guardBits = sqcd >> 5;
  12495. spqcds = [];
  12496. while (j < (length + position)) {
  12497. spqcd = {};
  12498. if (spqcdSize === 8) {
  12499. spqcd.epsilon = data[j++] >> 3;
  12500. spqcd.mu = 0;
  12501. } else {
  12502. spqcd.epsilon = data[j] >> 3;
  12503. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  12504. j += 2;
  12505. }
  12506. spqcds.push(spqcd);
  12507. }
  12508. qcc.SPqcds = spqcds;
  12509. if (context.mainHeader) {
  12510. context.QCC[cqcc] = qcc;
  12511. } else {
  12512. context.currentTile.QCC[cqcc] = qcc;
  12513. }
  12514. break;
  12515. case 0xFF52: // Coding style default (COD)
  12516. length = readUint16(data, position);
  12517. var cod = {};
  12518. j = position + 2;
  12519. var scod = data[j++];
  12520. cod.entropyCoderWithCustomPrecincts = !!(scod & 1);
  12521. cod.sopMarkerUsed = !!(scod & 2);
  12522. cod.ephMarkerUsed = !!(scod & 4);
  12523. cod.progressionOrder = data[j++];
  12524. cod.layersCount = readUint16(data, j);
  12525. j += 2;
  12526. cod.multipleComponentTransform = data[j++];
  12527. cod.decompositionLevelsCount = data[j++];
  12528. cod.xcb = (data[j++] & 0xF) + 2;
  12529. cod.ycb = (data[j++] & 0xF) + 2;
  12530. var blockStyle = data[j++];
  12531. cod.selectiveArithmeticCodingBypass = !!(blockStyle & 1);
  12532. cod.resetContextProbabilities = !!(blockStyle & 2);
  12533. cod.terminationOnEachCodingPass = !!(blockStyle & 4);
  12534. cod.verticalyStripe = !!(blockStyle & 8);
  12535. cod.predictableTermination = !!(blockStyle & 16);
  12536. cod.segmentationSymbolUsed = !!(blockStyle & 32);
  12537. cod.reversibleTransformation = data[j++];
  12538. if (cod.entropyCoderWithCustomPrecincts) {
  12539. var precinctsSizes = [];
  12540. while (j < length + position) {
  12541. var precinctsSize = data[j++];
  12542. precinctsSizes.push({
  12543. PPx: precinctsSize & 0xF,
  12544. PPy: precinctsSize >> 4
  12545. });
  12546. }
  12547. cod.precinctsSizes = precinctsSizes;
  12548. }
  12549. var unsupported = [];
  12550. if (cod.selectiveArithmeticCodingBypass) {
  12551. unsupported.push('selectiveArithmeticCodingBypass');
  12552. }
  12553. if (cod.resetContextProbabilities) {
  12554. unsupported.push('resetContextProbabilities');
  12555. }
  12556. if (cod.terminationOnEachCodingPass) {
  12557. unsupported.push('terminationOnEachCodingPass');
  12558. }
  12559. if (cod.verticalyStripe) {
  12560. unsupported.push('verticalyStripe');
  12561. }
  12562. if (cod.predictableTermination) {
  12563. unsupported.push('predictableTermination');
  12564. }
  12565. if (unsupported.length > 0) {
  12566. doNotRecover = true;
  12567. throw new Error('JPX Error: Unsupported COD options (' +
  12568. unsupported.join(', ') + ')');
  12569. }
  12570. if (context.mainHeader) {
  12571. context.COD = cod;
  12572. } else {
  12573. context.currentTile.COD = cod;
  12574. context.currentTile.COC = [];
  12575. }
  12576. break;
  12577. case 0xFF90: // Start of tile-part (SOT)
  12578. length = readUint16(data, position);
  12579. tile = {};
  12580. tile.index = readUint16(data, position + 2);
  12581. tile.length = readUint32(data, position + 4);
  12582. tile.dataEnd = tile.length + position - 2;
  12583. tile.partIndex = data[position + 8];
  12584. tile.partsCount = data[position + 9];
  12585. context.mainHeader = false;
  12586. if (tile.partIndex === 0) {
  12587. // reset component specific settings
  12588. tile.COD = context.COD;
  12589. tile.COC = context.COC.slice(0); // clone of the global COC
  12590. tile.QCD = context.QCD;
  12591. tile.QCC = context.QCC.slice(0); // clone of the global COC
  12592. }
  12593. context.currentTile = tile;
  12594. break;
  12595. case 0xFF93: // Start of data (SOD)
  12596. tile = context.currentTile;
  12597. if (tile.partIndex === 0) {
  12598. initializeTile(context, tile.index);
  12599. buildPackets(context);
  12600. }
  12601. // moving to the end of the data
  12602. length = tile.dataEnd - position;
  12603. parseTilePackets(context, data, position, length);
  12604. break;
  12605. case 0xFF55: // Tile-part lengths, main header (TLM)
  12606. case 0xFF57: // Packet length, main header (PLM)
  12607. case 0xFF58: // Packet length, tile-part header (PLT)
  12608. case 0xFF64: // Comment (COM)
  12609. length = readUint16(data, position);
  12610. // skipping content
  12611. break;
  12612. case 0xFF53: // Coding style component (COC)
  12613. throw new Error('JPX Error: Codestream code 0xFF53 (COC) is ' +
  12614. 'not implemented');
  12615. default:
  12616. throw new Error('JPX Error: Unknown codestream code: ' +
  12617. code.toString(16));
  12618. }
  12619. position += length;
  12620. }
  12621. } catch (e) {
  12622. if (doNotRecover || this.failOnCorruptedImage) {
  12623. throw e;
  12624. } else {
  12625. warn('Trying to recover from ' + e.message);
  12626. }
  12627. }
  12628. this.tiles = transformComponents(context);
  12629. this.width = context.SIZ.Xsiz - context.SIZ.XOsiz;
  12630. this.height = context.SIZ.Ysiz - context.SIZ.YOsiz;
  12631. this.componentsCount = context.SIZ.Csiz;
  12632. }
  12633. };
  12634. function calculateComponentDimensions(component, siz) {
  12635. // Section B.2 Component mapping
  12636. component.x0 = Math.ceil(siz.XOsiz / component.XRsiz);
  12637. component.x1 = Math.ceil(siz.Xsiz / component.XRsiz);
  12638. component.y0 = Math.ceil(siz.YOsiz / component.YRsiz);
  12639. component.y1 = Math.ceil(siz.Ysiz / component.YRsiz);
  12640. component.width = component.x1 - component.x0;
  12641. component.height = component.y1 - component.y0;
  12642. }
  12643. function calculateTileGrids(context, components) {
  12644. var siz = context.SIZ;
  12645. // Section B.3 Division into tile and tile-components
  12646. var tile, tiles = [];
  12647. var numXtiles = Math.ceil((siz.Xsiz - siz.XTOsiz) / siz.XTsiz);
  12648. var numYtiles = Math.ceil((siz.Ysiz - siz.YTOsiz) / siz.YTsiz);
  12649. for (var q = 0; q < numYtiles; q++) {
  12650. for (var p = 0; p < numXtiles; p++) {
  12651. tile = {};
  12652. tile.tx0 = Math.max(siz.XTOsiz + p * siz.XTsiz, siz.XOsiz);
  12653. tile.ty0 = Math.max(siz.YTOsiz + q * siz.YTsiz, siz.YOsiz);
  12654. tile.tx1 = Math.min(siz.XTOsiz + (p + 1) * siz.XTsiz, siz.Xsiz);
  12655. tile.ty1 = Math.min(siz.YTOsiz + (q + 1) * siz.YTsiz, siz.Ysiz);
  12656. tile.width = tile.tx1 - tile.tx0;
  12657. tile.height = tile.ty1 - tile.ty0;
  12658. tile.components = [];
  12659. tiles.push(tile);
  12660. }
  12661. }
  12662. context.tiles = tiles;
  12663. var componentsCount = siz.Csiz;
  12664. for (var i = 0, ii = componentsCount; i < ii; i++) {
  12665. var component = components[i];
  12666. for (var j = 0, jj = tiles.length; j < jj; j++) {
  12667. var tileComponent = {};
  12668. tile = tiles[j];
  12669. tileComponent.tcx0 = Math.ceil(tile.tx0 / component.XRsiz);
  12670. tileComponent.tcy0 = Math.ceil(tile.ty0 / component.YRsiz);
  12671. tileComponent.tcx1 = Math.ceil(tile.tx1 / component.XRsiz);
  12672. tileComponent.tcy1 = Math.ceil(tile.ty1 / component.YRsiz);
  12673. tileComponent.width = tileComponent.tcx1 - tileComponent.tcx0;
  12674. tileComponent.height = tileComponent.tcy1 - tileComponent.tcy0;
  12675. tile.components[i] = tileComponent;
  12676. }
  12677. }
  12678. }
  12679. function getBlocksDimensions(context, component, r) {
  12680. var codOrCoc = component.codingStyleParameters;
  12681. var result = {};
  12682. if (!codOrCoc.entropyCoderWithCustomPrecincts) {
  12683. result.PPx = 15;
  12684. result.PPy = 15;
  12685. } else {
  12686. result.PPx = codOrCoc.precinctsSizes[r].PPx;
  12687. result.PPy = codOrCoc.precinctsSizes[r].PPy;
  12688. }
  12689. // calculate codeblock size as described in section B.7
  12690. result.xcb_ = (r > 0 ? Math.min(codOrCoc.xcb, result.PPx - 1) :
  12691. Math.min(codOrCoc.xcb, result.PPx));
  12692. result.ycb_ = (r > 0 ? Math.min(codOrCoc.ycb, result.PPy - 1) :
  12693. Math.min(codOrCoc.ycb, result.PPy));
  12694. return result;
  12695. }
  12696. function buildPrecincts(context, resolution, dimensions) {
  12697. // Section B.6 Division resolution to precincts
  12698. var precinctWidth = 1 << dimensions.PPx;
  12699. var precinctHeight = 1 << dimensions.PPy;
  12700. // Jasper introduces codeblock groups for mapping each subband codeblocks
  12701. // to precincts. Precinct partition divides a resolution according to width
  12702. // and height parameters. The subband that belongs to the resolution level
  12703. // has a different size than the level, unless it is the zero resolution.
  12704. // From Jasper documentation: jpeg2000.pdf, section K: Tier-2 coding:
  12705. // The precinct partitioning for a particular subband is derived from a
  12706. // partitioning of its parent LL band (i.e., the LL band at the next higher
  12707. // resolution level)... The LL band associated with each resolution level is
  12708. // divided into precincts... Each of the resulting precinct regions is then
  12709. // mapped into its child subbands (if any) at the next lower resolution
  12710. // level. This is accomplished by using the coordinate transformation
  12711. // (u, v) = (ceil(x/2), ceil(y/2)) where (x, y) and (u, v) are the
  12712. // coordinates of a point in the LL band and child subband, respectively.
  12713. var isZeroRes = resolution.resLevel === 0;
  12714. var precinctWidthInSubband = 1 << (dimensions.PPx + (isZeroRes ? 0 : -1));
  12715. var precinctHeightInSubband = 1 << (dimensions.PPy + (isZeroRes ? 0 : -1));
  12716. var numprecinctswide = (resolution.trx1 > resolution.trx0 ?
  12717. Math.ceil(resolution.trx1 / precinctWidth) -
  12718. Math.floor(resolution.trx0 / precinctWidth) : 0);
  12719. var numprecinctshigh = (resolution.try1 > resolution.try0 ?
  12720. Math.ceil(resolution.try1 / precinctHeight) -
  12721. Math.floor(resolution.try0 / precinctHeight) : 0);
  12722. var numprecincts = numprecinctswide * numprecinctshigh;
  12723. resolution.precinctParameters = {
  12724. precinctWidth: precinctWidth,
  12725. precinctHeight: precinctHeight,
  12726. numprecinctswide: numprecinctswide,
  12727. numprecinctshigh: numprecinctshigh,
  12728. numprecincts: numprecincts,
  12729. precinctWidthInSubband: precinctWidthInSubband,
  12730. precinctHeightInSubband: precinctHeightInSubband
  12731. };
  12732. }
  12733. function buildCodeblocks(context, subband, dimensions) {
  12734. // Section B.7 Division sub-band into code-blocks
  12735. var xcb_ = dimensions.xcb_;
  12736. var ycb_ = dimensions.ycb_;
  12737. var codeblockWidth = 1 << xcb_;
  12738. var codeblockHeight = 1 << ycb_;
  12739. var cbx0 = subband.tbx0 >> xcb_;
  12740. var cby0 = subband.tby0 >> ycb_;
  12741. var cbx1 = (subband.tbx1 + codeblockWidth - 1) >> xcb_;
  12742. var cby1 = (subband.tby1 + codeblockHeight - 1) >> ycb_;
  12743. var precinctParameters = subband.resolution.precinctParameters;
  12744. var codeblocks = [];
  12745. var precincts = [];
  12746. var i, j, codeblock, precinctNumber;
  12747. for (j = cby0; j < cby1; j++) {
  12748. for (i = cbx0; i < cbx1; i++) {
  12749. codeblock = {
  12750. cbx: i,
  12751. cby: j,
  12752. tbx0: codeblockWidth * i,
  12753. tby0: codeblockHeight * j,
  12754. tbx1: codeblockWidth * (i + 1),
  12755. tby1: codeblockHeight * (j + 1)
  12756. };
  12757. codeblock.tbx0_ = Math.max(subband.tbx0, codeblock.tbx0);
  12758. codeblock.tby0_ = Math.max(subband.tby0, codeblock.tby0);
  12759. codeblock.tbx1_ = Math.min(subband.tbx1, codeblock.tbx1);
  12760. codeblock.tby1_ = Math.min(subband.tby1, codeblock.tby1);
  12761. // Calculate precinct number for this codeblock, codeblock position
  12762. // should be relative to its subband, use actual dimension and position
  12763. // See comment about codeblock group width and height
  12764. var pi = Math.floor((codeblock.tbx0_ - subband.tbx0) /
  12765. precinctParameters.precinctWidthInSubband);
  12766. var pj = Math.floor((codeblock.tby0_ - subband.tby0) /
  12767. precinctParameters.precinctHeightInSubband);
  12768. precinctNumber = pi + (pj * precinctParameters.numprecinctswide);
  12769. codeblock.precinctNumber = precinctNumber;
  12770. codeblock.subbandType = subband.type;
  12771. codeblock.Lblock = 3;
  12772. if (codeblock.tbx1_ <= codeblock.tbx0_ ||
  12773. codeblock.tby1_ <= codeblock.tby0_) {
  12774. continue;
  12775. }
  12776. codeblocks.push(codeblock);
  12777. // building precinct for the sub-band
  12778. var precinct = precincts[precinctNumber];
  12779. if (precinct !== undefined) {
  12780. if (i < precinct.cbxMin) {
  12781. precinct.cbxMin = i;
  12782. } else if (i > precinct.cbxMax) {
  12783. precinct.cbxMax = i;
  12784. }
  12785. if (j < precinct.cbyMin) {
  12786. precinct.cbxMin = j;
  12787. } else if (j > precinct.cbyMax) {
  12788. precinct.cbyMax = j;
  12789. }
  12790. } else {
  12791. precincts[precinctNumber] = precinct = {
  12792. cbxMin: i,
  12793. cbyMin: j,
  12794. cbxMax: i,
  12795. cbyMax: j
  12796. };
  12797. }
  12798. codeblock.precinct = precinct;
  12799. }
  12800. }
  12801. subband.codeblockParameters = {
  12802. codeblockWidth: xcb_,
  12803. codeblockHeight: ycb_,
  12804. numcodeblockwide: cbx1 - cbx0 + 1,
  12805. numcodeblockhigh: cby1 - cby0 + 1
  12806. };
  12807. subband.codeblocks = codeblocks;
  12808. subband.precincts = precincts;
  12809. }
  12810. function createPacket(resolution, precinctNumber, layerNumber) {
  12811. var precinctCodeblocks = [];
  12812. // Section B.10.8 Order of info in packet
  12813. var subbands = resolution.subbands;
  12814. // sub-bands already ordered in 'LL', 'HL', 'LH', and 'HH' sequence
  12815. for (var i = 0, ii = subbands.length; i < ii; i++) {
  12816. var subband = subbands[i];
  12817. var codeblocks = subband.codeblocks;
  12818. for (var j = 0, jj = codeblocks.length; j < jj; j++) {
  12819. var codeblock = codeblocks[j];
  12820. if (codeblock.precinctNumber !== precinctNumber) {
  12821. continue;
  12822. }
  12823. precinctCodeblocks.push(codeblock);
  12824. }
  12825. }
  12826. return {
  12827. layerNumber: layerNumber,
  12828. codeblocks: precinctCodeblocks
  12829. };
  12830. }
  12831. function LayerResolutionComponentPositionIterator(context) {
  12832. var siz = context.SIZ;
  12833. var tileIndex = context.currentTile.index;
  12834. var tile = context.tiles[tileIndex];
  12835. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  12836. var componentsCount = siz.Csiz;
  12837. var maxDecompositionLevelsCount = 0;
  12838. for (var q = 0; q < componentsCount; q++) {
  12839. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  12840. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  12841. }
  12842. var l = 0, r = 0, i = 0, k = 0;
  12843. this.nextPacket = function JpxImage_nextPacket() {
  12844. // Section B.12.1.1 Layer-resolution-component-position
  12845. for (; l < layersCount; l++) {
  12846. for (; r <= maxDecompositionLevelsCount; r++) {
  12847. for (; i < componentsCount; i++) {
  12848. var component = tile.components[i];
  12849. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  12850. continue;
  12851. }
  12852. var resolution = component.resolutions[r];
  12853. var numprecincts = resolution.precinctParameters.numprecincts;
  12854. for (; k < numprecincts;) {
  12855. var packet = createPacket(resolution, k, l);
  12856. k++;
  12857. return packet;
  12858. }
  12859. k = 0;
  12860. }
  12861. i = 0;
  12862. }
  12863. r = 0;
  12864. }
  12865. throw new Error('JPX Error: Out of packets');
  12866. };
  12867. }
  12868. function ResolutionLayerComponentPositionIterator(context) {
  12869. var siz = context.SIZ;
  12870. var tileIndex = context.currentTile.index;
  12871. var tile = context.tiles[tileIndex];
  12872. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  12873. var componentsCount = siz.Csiz;
  12874. var maxDecompositionLevelsCount = 0;
  12875. for (var q = 0; q < componentsCount; q++) {
  12876. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  12877. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  12878. }
  12879. var r = 0, l = 0, i = 0, k = 0;
  12880. this.nextPacket = function JpxImage_nextPacket() {
  12881. // Section B.12.1.2 Resolution-layer-component-position
  12882. for (; r <= maxDecompositionLevelsCount; r++) {
  12883. for (; l < layersCount; l++) {
  12884. for (; i < componentsCount; i++) {
  12885. var component = tile.components[i];
  12886. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  12887. continue;
  12888. }
  12889. var resolution = component.resolutions[r];
  12890. var numprecincts = resolution.precinctParameters.numprecincts;
  12891. for (; k < numprecincts;) {
  12892. var packet = createPacket(resolution, k, l);
  12893. k++;
  12894. return packet;
  12895. }
  12896. k = 0;
  12897. }
  12898. i = 0;
  12899. }
  12900. l = 0;
  12901. }
  12902. throw new Error('JPX Error: Out of packets');
  12903. };
  12904. }
  12905. function ResolutionPositionComponentLayerIterator(context) {
  12906. var siz = context.SIZ;
  12907. var tileIndex = context.currentTile.index;
  12908. var tile = context.tiles[tileIndex];
  12909. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  12910. var componentsCount = siz.Csiz;
  12911. var l, r, c, p;
  12912. var maxDecompositionLevelsCount = 0;
  12913. for (c = 0; c < componentsCount; c++) {
  12914. var component = tile.components[c];
  12915. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  12916. component.codingStyleParameters.decompositionLevelsCount);
  12917. }
  12918. var maxNumPrecinctsInLevel = new Int32Array(
  12919. maxDecompositionLevelsCount + 1);
  12920. for (r = 0; r <= maxDecompositionLevelsCount; ++r) {
  12921. var maxNumPrecincts = 0;
  12922. for (c = 0; c < componentsCount; ++c) {
  12923. var resolutions = tile.components[c].resolutions;
  12924. if (r < resolutions.length) {
  12925. maxNumPrecincts = Math.max(maxNumPrecincts,
  12926. resolutions[r].precinctParameters.numprecincts);
  12927. }
  12928. }
  12929. maxNumPrecinctsInLevel[r] = maxNumPrecincts;
  12930. }
  12931. l = 0;
  12932. r = 0;
  12933. c = 0;
  12934. p = 0;
  12935. this.nextPacket = function JpxImage_nextPacket() {
  12936. // Section B.12.1.3 Resolution-position-component-layer
  12937. for (; r <= maxDecompositionLevelsCount; r++) {
  12938. for (; p < maxNumPrecinctsInLevel[r]; p++) {
  12939. for (; c < componentsCount; c++) {
  12940. var component = tile.components[c];
  12941. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  12942. continue;
  12943. }
  12944. var resolution = component.resolutions[r];
  12945. var numprecincts = resolution.precinctParameters.numprecincts;
  12946. if (p >= numprecincts) {
  12947. continue;
  12948. }
  12949. for (; l < layersCount;) {
  12950. var packet = createPacket(resolution, p, l);
  12951. l++;
  12952. return packet;
  12953. }
  12954. l = 0;
  12955. }
  12956. c = 0;
  12957. }
  12958. p = 0;
  12959. }
  12960. throw new Error('JPX Error: Out of packets');
  12961. };
  12962. }
  12963. function PositionComponentResolutionLayerIterator(context) {
  12964. var siz = context.SIZ;
  12965. var tileIndex = context.currentTile.index;
  12966. var tile = context.tiles[tileIndex];
  12967. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  12968. var componentsCount = siz.Csiz;
  12969. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  12970. var precinctsIterationSizes = precinctsSizes;
  12971. var l = 0, r = 0, c = 0, px = 0, py = 0;
  12972. this.nextPacket = function JpxImage_nextPacket() {
  12973. // Section B.12.1.4 Position-component-resolution-layer
  12974. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  12975. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  12976. for (; c < componentsCount; c++) {
  12977. var component = tile.components[c];
  12978. var decompositionLevelsCount =
  12979. component.codingStyleParameters.decompositionLevelsCount;
  12980. for (; r <= decompositionLevelsCount; r++) {
  12981. var resolution = component.resolutions[r];
  12982. var sizeInImageScale =
  12983. precinctsSizes.components[c].resolutions[r];
  12984. var k = getPrecinctIndexIfExist(
  12985. px,
  12986. py,
  12987. sizeInImageScale,
  12988. precinctsIterationSizes,
  12989. resolution);
  12990. if (k === null) {
  12991. continue;
  12992. }
  12993. for (; l < layersCount;) {
  12994. var packet = createPacket(resolution, k, l);
  12995. l++;
  12996. return packet;
  12997. }
  12998. l = 0;
  12999. }
  13000. r = 0;
  13001. }
  13002. c = 0;
  13003. }
  13004. px = 0;
  13005. }
  13006. throw new Error('JPX Error: Out of packets');
  13007. };
  13008. }
  13009. function ComponentPositionResolutionLayerIterator(context) {
  13010. var siz = context.SIZ;
  13011. var tileIndex = context.currentTile.index;
  13012. var tile = context.tiles[tileIndex];
  13013. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  13014. var componentsCount = siz.Csiz;
  13015. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  13016. var l = 0, r = 0, c = 0, px = 0, py = 0;
  13017. this.nextPacket = function JpxImage_nextPacket() {
  13018. // Section B.12.1.5 Component-position-resolution-layer
  13019. for (; c < componentsCount; ++c) {
  13020. var component = tile.components[c];
  13021. var precinctsIterationSizes = precinctsSizes.components[c];
  13022. var decompositionLevelsCount =
  13023. component.codingStyleParameters.decompositionLevelsCount;
  13024. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  13025. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  13026. for (; r <= decompositionLevelsCount; r++) {
  13027. var resolution = component.resolutions[r];
  13028. var sizeInImageScale = precinctsIterationSizes.resolutions[r];
  13029. var k = getPrecinctIndexIfExist(
  13030. px,
  13031. py,
  13032. sizeInImageScale,
  13033. precinctsIterationSizes,
  13034. resolution);
  13035. if (k === null) {
  13036. continue;
  13037. }
  13038. for (; l < layersCount;) {
  13039. var packet = createPacket(resolution, k, l);
  13040. l++;
  13041. return packet;
  13042. }
  13043. l = 0;
  13044. }
  13045. r = 0;
  13046. }
  13047. px = 0;
  13048. }
  13049. py = 0;
  13050. }
  13051. throw new Error('JPX Error: Out of packets');
  13052. };
  13053. }
  13054. function getPrecinctIndexIfExist(
  13055. pxIndex, pyIndex, sizeInImageScale, precinctIterationSizes, resolution) {
  13056. var posX = pxIndex * precinctIterationSizes.minWidth;
  13057. var posY = pyIndex * precinctIterationSizes.minHeight;
  13058. if (posX % sizeInImageScale.width !== 0 ||
  13059. posY % sizeInImageScale.height !== 0) {
  13060. return null;
  13061. }
  13062. var startPrecinctRowIndex =
  13063. (posY / sizeInImageScale.width) *
  13064. resolution.precinctParameters.numprecinctswide;
  13065. return (posX / sizeInImageScale.height) + startPrecinctRowIndex;
  13066. }
  13067. function getPrecinctSizesInImageScale(tile) {
  13068. var componentsCount = tile.components.length;
  13069. var minWidth = Number.MAX_VALUE;
  13070. var minHeight = Number.MAX_VALUE;
  13071. var maxNumWide = 0;
  13072. var maxNumHigh = 0;
  13073. var sizePerComponent = new Array(componentsCount);
  13074. for (var c = 0; c < componentsCount; c++) {
  13075. var component = tile.components[c];
  13076. var decompositionLevelsCount =
  13077. component.codingStyleParameters.decompositionLevelsCount;
  13078. var sizePerResolution = new Array(decompositionLevelsCount + 1);
  13079. var minWidthCurrentComponent = Number.MAX_VALUE;
  13080. var minHeightCurrentComponent = Number.MAX_VALUE;
  13081. var maxNumWideCurrentComponent = 0;
  13082. var maxNumHighCurrentComponent = 0;
  13083. var scale = 1;
  13084. for (var r = decompositionLevelsCount; r >= 0; --r) {
  13085. var resolution = component.resolutions[r];
  13086. var widthCurrentResolution =
  13087. scale * resolution.precinctParameters.precinctWidth;
  13088. var heightCurrentResolution =
  13089. scale * resolution.precinctParameters.precinctHeight;
  13090. minWidthCurrentComponent = Math.min(
  13091. minWidthCurrentComponent,
  13092. widthCurrentResolution);
  13093. minHeightCurrentComponent = Math.min(
  13094. minHeightCurrentComponent,
  13095. heightCurrentResolution);
  13096. maxNumWideCurrentComponent = Math.max(maxNumWideCurrentComponent,
  13097. resolution.precinctParameters.numprecinctswide);
  13098. maxNumHighCurrentComponent = Math.max(maxNumHighCurrentComponent,
  13099. resolution.precinctParameters.numprecinctshigh);
  13100. sizePerResolution[r] = {
  13101. width: widthCurrentResolution,
  13102. height: heightCurrentResolution
  13103. };
  13104. scale <<= 1;
  13105. }
  13106. minWidth = Math.min(minWidth, minWidthCurrentComponent);
  13107. minHeight = Math.min(minHeight, minHeightCurrentComponent);
  13108. maxNumWide = Math.max(maxNumWide, maxNumWideCurrentComponent);
  13109. maxNumHigh = Math.max(maxNumHigh, maxNumHighCurrentComponent);
  13110. sizePerComponent[c] = {
  13111. resolutions: sizePerResolution,
  13112. minWidth: minWidthCurrentComponent,
  13113. minHeight: minHeightCurrentComponent,
  13114. maxNumWide: maxNumWideCurrentComponent,
  13115. maxNumHigh: maxNumHighCurrentComponent
  13116. };
  13117. }
  13118. return {
  13119. components: sizePerComponent,
  13120. minWidth: minWidth,
  13121. minHeight: minHeight,
  13122. maxNumWide: maxNumWide,
  13123. maxNumHigh: maxNumHigh
  13124. };
  13125. }
  13126. function buildPackets(context) {
  13127. var siz = context.SIZ;
  13128. var tileIndex = context.currentTile.index;
  13129. var tile = context.tiles[tileIndex];
  13130. var componentsCount = siz.Csiz;
  13131. // Creating resolutions and sub-bands for each component
  13132. for (var c = 0; c < componentsCount; c++) {
  13133. var component = tile.components[c];
  13134. var decompositionLevelsCount =
  13135. component.codingStyleParameters.decompositionLevelsCount;
  13136. // Section B.5 Resolution levels and sub-bands
  13137. var resolutions = [];
  13138. var subbands = [];
  13139. for (var r = 0; r <= decompositionLevelsCount; r++) {
  13140. var blocksDimensions = getBlocksDimensions(context, component, r);
  13141. var resolution = {};
  13142. var scale = 1 << (decompositionLevelsCount - r);
  13143. resolution.trx0 = Math.ceil(component.tcx0 / scale);
  13144. resolution.try0 = Math.ceil(component.tcy0 / scale);
  13145. resolution.trx1 = Math.ceil(component.tcx1 / scale);
  13146. resolution.try1 = Math.ceil(component.tcy1 / scale);
  13147. resolution.resLevel = r;
  13148. buildPrecincts(context, resolution, blocksDimensions);
  13149. resolutions.push(resolution);
  13150. var subband;
  13151. if (r === 0) {
  13152. // one sub-band (LL) with last decomposition
  13153. subband = {};
  13154. subband.type = 'LL';
  13155. subband.tbx0 = Math.ceil(component.tcx0 / scale);
  13156. subband.tby0 = Math.ceil(component.tcy0 / scale);
  13157. subband.tbx1 = Math.ceil(component.tcx1 / scale);
  13158. subband.tby1 = Math.ceil(component.tcy1 / scale);
  13159. subband.resolution = resolution;
  13160. buildCodeblocks(context, subband, blocksDimensions);
  13161. subbands.push(subband);
  13162. resolution.subbands = [subband];
  13163. } else {
  13164. var bscale = 1 << (decompositionLevelsCount - r + 1);
  13165. var resolutionSubbands = [];
  13166. // three sub-bands (HL, LH and HH) with rest of decompositions
  13167. subband = {};
  13168. subband.type = 'HL';
  13169. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  13170. subband.tby0 = Math.ceil(component.tcy0 / bscale);
  13171. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  13172. subband.tby1 = Math.ceil(component.tcy1 / bscale);
  13173. subband.resolution = resolution;
  13174. buildCodeblocks(context, subband, blocksDimensions);
  13175. subbands.push(subband);
  13176. resolutionSubbands.push(subband);
  13177. subband = {};
  13178. subband.type = 'LH';
  13179. subband.tbx0 = Math.ceil(component.tcx0 / bscale);
  13180. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  13181. subband.tbx1 = Math.ceil(component.tcx1 / bscale);
  13182. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  13183. subband.resolution = resolution;
  13184. buildCodeblocks(context, subband, blocksDimensions);
  13185. subbands.push(subband);
  13186. resolutionSubbands.push(subband);
  13187. subband = {};
  13188. subband.type = 'HH';
  13189. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  13190. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  13191. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  13192. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  13193. subband.resolution = resolution;
  13194. buildCodeblocks(context, subband, blocksDimensions);
  13195. subbands.push(subband);
  13196. resolutionSubbands.push(subband);
  13197. resolution.subbands = resolutionSubbands;
  13198. }
  13199. }
  13200. component.resolutions = resolutions;
  13201. component.subbands = subbands;
  13202. }
  13203. // Generate the packets sequence
  13204. var progressionOrder = tile.codingStyleDefaultParameters.progressionOrder;
  13205. switch (progressionOrder) {
  13206. case 0:
  13207. tile.packetsIterator =
  13208. new LayerResolutionComponentPositionIterator(context);
  13209. break;
  13210. case 1:
  13211. tile.packetsIterator =
  13212. new ResolutionLayerComponentPositionIterator(context);
  13213. break;
  13214. case 2:
  13215. tile.packetsIterator =
  13216. new ResolutionPositionComponentLayerIterator(context);
  13217. break;
  13218. case 3:
  13219. tile.packetsIterator =
  13220. new PositionComponentResolutionLayerIterator(context);
  13221. break;
  13222. case 4:
  13223. tile.packetsIterator =
  13224. new ComponentPositionResolutionLayerIterator(context);
  13225. break;
  13226. default:
  13227. throw new Error('JPX Error: Unsupported progression order ' +
  13228. progressionOrder);
  13229. }
  13230. }
  13231. function parseTilePackets(context, data, offset, dataLength) {
  13232. var position = 0;
  13233. var buffer, bufferSize = 0, skipNextBit = false;
  13234. function readBits(count) {
  13235. while (bufferSize < count) {
  13236. var b = data[offset + position];
  13237. position++;
  13238. if (skipNextBit) {
  13239. buffer = (buffer << 7) | b;
  13240. bufferSize += 7;
  13241. skipNextBit = false;
  13242. } else {
  13243. buffer = (buffer << 8) | b;
  13244. bufferSize += 8;
  13245. }
  13246. if (b === 0xFF) {
  13247. skipNextBit = true;
  13248. }
  13249. }
  13250. bufferSize -= count;
  13251. return (buffer >>> bufferSize) & ((1 << count) - 1);
  13252. }
  13253. function skipMarkerIfEqual(value) {
  13254. if (data[offset + position - 1] === 0xFF &&
  13255. data[offset + position] === value) {
  13256. skipBytes(1);
  13257. return true;
  13258. } else if (data[offset + position] === 0xFF &&
  13259. data[offset + position + 1] === value) {
  13260. skipBytes(2);
  13261. return true;
  13262. }
  13263. return false;
  13264. }
  13265. function skipBytes(count) {
  13266. position += count;
  13267. }
  13268. function alignToByte() {
  13269. bufferSize = 0;
  13270. if (skipNextBit) {
  13271. position++;
  13272. skipNextBit = false;
  13273. }
  13274. }
  13275. function readCodingpasses() {
  13276. if (readBits(1) === 0) {
  13277. return 1;
  13278. }
  13279. if (readBits(1) === 0) {
  13280. return 2;
  13281. }
  13282. var value = readBits(2);
  13283. if (value < 3) {
  13284. return value + 3;
  13285. }
  13286. value = readBits(5);
  13287. if (value < 31) {
  13288. return value + 6;
  13289. }
  13290. value = readBits(7);
  13291. return value + 37;
  13292. }
  13293. var tileIndex = context.currentTile.index;
  13294. var tile = context.tiles[tileIndex];
  13295. var sopMarkerUsed = context.COD.sopMarkerUsed;
  13296. var ephMarkerUsed = context.COD.ephMarkerUsed;
  13297. var packetsIterator = tile.packetsIterator;
  13298. while (position < dataLength) {
  13299. alignToByte();
  13300. if (sopMarkerUsed && skipMarkerIfEqual(0x91)) {
  13301. // Skip also marker segment length and packet sequence ID
  13302. skipBytes(4);
  13303. }
  13304. var packet = packetsIterator.nextPacket();
  13305. if (!readBits(1)) {
  13306. continue;
  13307. }
  13308. var layerNumber = packet.layerNumber;
  13309. var queue = [], codeblock;
  13310. for (var i = 0, ii = packet.codeblocks.length; i < ii; i++) {
  13311. codeblock = packet.codeblocks[i];
  13312. var precinct = codeblock.precinct;
  13313. var codeblockColumn = codeblock.cbx - precinct.cbxMin;
  13314. var codeblockRow = codeblock.cby - precinct.cbyMin;
  13315. var codeblockIncluded = false;
  13316. var firstTimeInclusion = false;
  13317. var valueReady;
  13318. if (codeblock['included'] !== undefined) {
  13319. codeblockIncluded = !!readBits(1);
  13320. } else {
  13321. // reading inclusion tree
  13322. precinct = codeblock.precinct;
  13323. var inclusionTree, zeroBitPlanesTree;
  13324. if (precinct['inclusionTree'] !== undefined) {
  13325. inclusionTree = precinct.inclusionTree;
  13326. } else {
  13327. // building inclusion and zero bit-planes trees
  13328. var width = precinct.cbxMax - precinct.cbxMin + 1;
  13329. var height = precinct.cbyMax - precinct.cbyMin + 1;
  13330. inclusionTree = new InclusionTree(width, height, layerNumber);
  13331. zeroBitPlanesTree = new TagTree(width, height);
  13332. precinct.inclusionTree = inclusionTree;
  13333. precinct.zeroBitPlanesTree = zeroBitPlanesTree;
  13334. }
  13335. if (inclusionTree.reset(codeblockColumn, codeblockRow, layerNumber)) {
  13336. while (true) {
  13337. if (readBits(1)) {
  13338. valueReady = !inclusionTree.nextLevel();
  13339. if (valueReady) {
  13340. codeblock.included = true;
  13341. codeblockIncluded = firstTimeInclusion = true;
  13342. break;
  13343. }
  13344. } else {
  13345. inclusionTree.incrementValue(layerNumber);
  13346. break;
  13347. }
  13348. }
  13349. }
  13350. }
  13351. if (!codeblockIncluded) {
  13352. continue;
  13353. }
  13354. if (firstTimeInclusion) {
  13355. zeroBitPlanesTree = precinct.zeroBitPlanesTree;
  13356. zeroBitPlanesTree.reset(codeblockColumn, codeblockRow);
  13357. while (true) {
  13358. if (readBits(1)) {
  13359. valueReady = !zeroBitPlanesTree.nextLevel();
  13360. if (valueReady) {
  13361. break;
  13362. }
  13363. } else {
  13364. zeroBitPlanesTree.incrementValue();
  13365. }
  13366. }
  13367. codeblock.zeroBitPlanes = zeroBitPlanesTree.value;
  13368. }
  13369. var codingpasses = readCodingpasses();
  13370. while (readBits(1)) {
  13371. codeblock.Lblock++;
  13372. }
  13373. var codingpassesLog2 = log2(codingpasses);
  13374. // rounding down log2
  13375. var bits = ((codingpasses < (1 << codingpassesLog2)) ?
  13376. codingpassesLog2 - 1 : codingpassesLog2) + codeblock.Lblock;
  13377. var codedDataLength = readBits(bits);
  13378. queue.push({
  13379. codeblock: codeblock,
  13380. codingpasses: codingpasses,
  13381. dataLength: codedDataLength
  13382. });
  13383. }
  13384. alignToByte();
  13385. if (ephMarkerUsed) {
  13386. skipMarkerIfEqual(0x92);
  13387. }
  13388. while (queue.length > 0) {
  13389. var packetItem = queue.shift();
  13390. codeblock = packetItem.codeblock;
  13391. if (codeblock['data'] === undefined) {
  13392. codeblock.data = [];
  13393. }
  13394. codeblock.data.push({
  13395. data: data,
  13396. start: offset + position,
  13397. end: offset + position + packetItem.dataLength,
  13398. codingpasses: packetItem.codingpasses
  13399. });
  13400. position += packetItem.dataLength;
  13401. }
  13402. }
  13403. return position;
  13404. }
  13405. function copyCoefficients(coefficients, levelWidth, levelHeight, subband,
  13406. delta, mb, reversible, segmentationSymbolUsed) {
  13407. var x0 = subband.tbx0;
  13408. var y0 = subband.tby0;
  13409. var width = subband.tbx1 - subband.tbx0;
  13410. var codeblocks = subband.codeblocks;
  13411. var right = subband.type.charAt(0) === 'H' ? 1 : 0;
  13412. var bottom = subband.type.charAt(1) === 'H' ? levelWidth : 0;
  13413. for (var i = 0, ii = codeblocks.length; i < ii; ++i) {
  13414. var codeblock = codeblocks[i];
  13415. var blockWidth = codeblock.tbx1_ - codeblock.tbx0_;
  13416. var blockHeight = codeblock.tby1_ - codeblock.tby0_;
  13417. if (blockWidth === 0 || blockHeight === 0) {
  13418. continue;
  13419. }
  13420. if (codeblock['data'] === undefined) {
  13421. continue;
  13422. }
  13423. var bitModel, currentCodingpassType;
  13424. bitModel = new BitModel(blockWidth, blockHeight, codeblock.subbandType,
  13425. codeblock.zeroBitPlanes, mb);
  13426. currentCodingpassType = 2; // first bit plane starts from cleanup
  13427. // collect data
  13428. var data = codeblock.data, totalLength = 0, codingpasses = 0;
  13429. var j, jj, dataItem;
  13430. for (j = 0, jj = data.length; j < jj; j++) {
  13431. dataItem = data[j];
  13432. totalLength += dataItem.end - dataItem.start;
  13433. codingpasses += dataItem.codingpasses;
  13434. }
  13435. var encodedData = new Uint8Array(totalLength);
  13436. var position = 0;
  13437. for (j = 0, jj = data.length; j < jj; j++) {
  13438. dataItem = data[j];
  13439. var chunk = dataItem.data.subarray(dataItem.start, dataItem.end);
  13440. encodedData.set(chunk, position);
  13441. position += chunk.length;
  13442. }
  13443. // decoding the item
  13444. var decoder = new ArithmeticDecoder(encodedData, 0, totalLength);
  13445. bitModel.setDecoder(decoder);
  13446. for (j = 0; j < codingpasses; j++) {
  13447. switch (currentCodingpassType) {
  13448. case 0:
  13449. bitModel.runSignificancePropogationPass();
  13450. break;
  13451. case 1:
  13452. bitModel.runMagnitudeRefinementPass();
  13453. break;
  13454. case 2:
  13455. bitModel.runCleanupPass();
  13456. if (segmentationSymbolUsed) {
  13457. bitModel.checkSegmentationSymbol();
  13458. }
  13459. break;
  13460. }
  13461. currentCodingpassType = (currentCodingpassType + 1) % 3;
  13462. }
  13463. var offset = (codeblock.tbx0_ - x0) + (codeblock.tby0_ - y0) * width;
  13464. var sign = bitModel.coefficentsSign;
  13465. var magnitude = bitModel.coefficentsMagnitude;
  13466. var bitsDecoded = bitModel.bitsDecoded;
  13467. var magnitudeCorrection = reversible ? 0 : 0.5;
  13468. var k, n, nb;
  13469. position = 0;
  13470. // Do the interleaving of Section F.3.3 here, so we do not need
  13471. // to copy later. LL level is not interleaved, just copied.
  13472. var interleave = (subband.type !== 'LL');
  13473. for (j = 0; j < blockHeight; j++) {
  13474. var row = (offset / width) | 0; // row in the non-interleaved subband
  13475. var levelOffset = 2 * row * (levelWidth - width) + right + bottom;
  13476. for (k = 0; k < blockWidth; k++) {
  13477. n = magnitude[position];
  13478. if (n !== 0) {
  13479. n = (n + magnitudeCorrection) * delta;
  13480. if (sign[position] !== 0) {
  13481. n = -n;
  13482. }
  13483. nb = bitsDecoded[position];
  13484. var pos = interleave ? (levelOffset + (offset << 1)) : offset;
  13485. if (reversible && (nb >= mb)) {
  13486. coefficients[pos] = n;
  13487. } else {
  13488. coefficients[pos] = n * (1 << (mb - nb));
  13489. }
  13490. }
  13491. offset++;
  13492. position++;
  13493. }
  13494. offset += width - blockWidth;
  13495. }
  13496. }
  13497. }
  13498. function transformTile(context, tile, c) {
  13499. var component = tile.components[c];
  13500. var codingStyleParameters = component.codingStyleParameters;
  13501. var quantizationParameters = component.quantizationParameters;
  13502. var decompositionLevelsCount =
  13503. codingStyleParameters.decompositionLevelsCount;
  13504. var spqcds = quantizationParameters.SPqcds;
  13505. var scalarExpounded = quantizationParameters.scalarExpounded;
  13506. var guardBits = quantizationParameters.guardBits;
  13507. var segmentationSymbolUsed = codingStyleParameters.segmentationSymbolUsed;
  13508. var precision = context.components[c].precision;
  13509. var reversible = codingStyleParameters.reversibleTransformation;
  13510. var transform = (reversible ? new ReversibleTransform() :
  13511. new IrreversibleTransform());
  13512. var subbandCoefficients = [];
  13513. var b = 0;
  13514. for (var i = 0; i <= decompositionLevelsCount; i++) {
  13515. var resolution = component.resolutions[i];
  13516. var width = resolution.trx1 - resolution.trx0;
  13517. var height = resolution.try1 - resolution.try0;
  13518. // Allocate space for the whole sublevel.
  13519. var coefficients = new Float32Array(width * height);
  13520. for (var j = 0, jj = resolution.subbands.length; j < jj; j++) {
  13521. var mu, epsilon;
  13522. if (!scalarExpounded) {
  13523. // formula E-5
  13524. mu = spqcds[0].mu;
  13525. epsilon = spqcds[0].epsilon + (i > 0 ? 1 - i : 0);
  13526. } else {
  13527. mu = spqcds[b].mu;
  13528. epsilon = spqcds[b].epsilon;
  13529. b++;
  13530. }
  13531. var subband = resolution.subbands[j];
  13532. var gainLog2 = SubbandsGainLog2[subband.type];
  13533. // calulate quantization coefficient (Section E.1.1.1)
  13534. var delta = (reversible ? 1 :
  13535. Math.pow(2, precision + gainLog2 - epsilon) * (1 + mu / 2048));
  13536. var mb = (guardBits + epsilon - 1);
  13537. // In the first resolution level, copyCoefficients will fill the
  13538. // whole array with coefficients. In the succeding passes,
  13539. // copyCoefficients will consecutively fill in the values that belong
  13540. // to the interleaved positions of the HL, LH, and HH coefficients.
  13541. // The LL coefficients will then be interleaved in Transform.iterate().
  13542. copyCoefficients(coefficients, width, height, subband, delta, mb,
  13543. reversible, segmentationSymbolUsed);
  13544. }
  13545. subbandCoefficients.push({
  13546. width: width,
  13547. height: height,
  13548. items: coefficients
  13549. });
  13550. }
  13551. var result = transform.calculate(subbandCoefficients,
  13552. component.tcx0, component.tcy0);
  13553. return {
  13554. left: component.tcx0,
  13555. top: component.tcy0,
  13556. width: result.width,
  13557. height: result.height,
  13558. items: result.items
  13559. };
  13560. }
  13561. function transformComponents(context) {
  13562. var siz = context.SIZ;
  13563. var components = context.components;
  13564. var componentsCount = siz.Csiz;
  13565. var resultImages = [];
  13566. for (var i = 0, ii = context.tiles.length; i < ii; i++) {
  13567. var tile = context.tiles[i];
  13568. var transformedTiles = [];
  13569. var c;
  13570. for (c = 0; c < componentsCount; c++) {
  13571. transformedTiles[c] = transformTile(context, tile, c);
  13572. }
  13573. var tile0 = transformedTiles[0];
  13574. var out = new Uint8Array(tile0.items.length * componentsCount);
  13575. var result = {
  13576. left: tile0.left,
  13577. top: tile0.top,
  13578. width: tile0.width,
  13579. height: tile0.height,
  13580. items: out
  13581. };
  13582. // Section G.2.2 Inverse multi component transform
  13583. var shift, offset, max, min, maxK;
  13584. var pos = 0, j, jj, y0, y1, y2, r, g, b, k, val;
  13585. if (tile.codingStyleDefaultParameters.multipleComponentTransform) {
  13586. var fourComponents = componentsCount === 4;
  13587. var y0items = transformedTiles[0].items;
  13588. var y1items = transformedTiles[1].items;
  13589. var y2items = transformedTiles[2].items;
  13590. var y3items = fourComponents ? transformedTiles[3].items : null;
  13591. // HACK: The multiple component transform formulas below assume that
  13592. // all components have the same precision. With this in mind, we
  13593. // compute shift and offset only once.
  13594. shift = components[0].precision - 8;
  13595. offset = (128 << shift) + 0.5;
  13596. max = 255 * (1 << shift);
  13597. maxK = max * 0.5;
  13598. min = -maxK;
  13599. var component0 = tile.components[0];
  13600. var alpha01 = componentsCount - 3;
  13601. jj = y0items.length;
  13602. if (!component0.codingStyleParameters.reversibleTransformation) {
  13603. // inverse irreversible multiple component transform
  13604. for (j = 0; j < jj; j++, pos += alpha01) {
  13605. y0 = y0items[j] + offset;
  13606. y1 = y1items[j];
  13607. y2 = y2items[j];
  13608. r = y0 + 1.402 * y2;
  13609. g = y0 - 0.34413 * y1 - 0.71414 * y2;
  13610. b = y0 + 1.772 * y1;
  13611. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  13612. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  13613. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  13614. }
  13615. } else {
  13616. // inverse reversible multiple component transform
  13617. for (j = 0; j < jj; j++, pos += alpha01) {
  13618. y0 = y0items[j] + offset;
  13619. y1 = y1items[j];
  13620. y2 = y2items[j];
  13621. g = y0 - ((y2 + y1) >> 2);
  13622. r = g + y2;
  13623. b = g + y1;
  13624. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  13625. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  13626. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  13627. }
  13628. }
  13629. if (fourComponents) {
  13630. for (j = 0, pos = 3; j < jj; j++, pos += 4) {
  13631. k = y3items[j];
  13632. out[pos] = k <= min ? 0 : k >= maxK ? 255 : (k + offset) >> shift;
  13633. }
  13634. }
  13635. } else { // no multi-component transform
  13636. for (c = 0; c < componentsCount; c++) {
  13637. var items = transformedTiles[c].items;
  13638. shift = components[c].precision - 8;
  13639. offset = (128 << shift) + 0.5;
  13640. max = (127.5 * (1 << shift));
  13641. min = -max;
  13642. for (pos = c, j = 0, jj = items.length; j < jj; j++) {
  13643. val = items[j];
  13644. out[pos] = val <= min ? 0 :
  13645. val >= max ? 255 : (val + offset) >> shift;
  13646. pos += componentsCount;
  13647. }
  13648. }
  13649. }
  13650. resultImages.push(result);
  13651. }
  13652. return resultImages;
  13653. }
  13654. function initializeTile(context, tileIndex) {
  13655. var siz = context.SIZ;
  13656. var componentsCount = siz.Csiz;
  13657. var tile = context.tiles[tileIndex];
  13658. for (var c = 0; c < componentsCount; c++) {
  13659. var component = tile.components[c];
  13660. var qcdOrQcc = (context.currentTile.QCC[c] !== undefined ?
  13661. context.currentTile.QCC[c] : context.currentTile.QCD);
  13662. component.quantizationParameters = qcdOrQcc;
  13663. var codOrCoc = (context.currentTile.COC[c] !== undefined ?
  13664. context.currentTile.COC[c] : context.currentTile.COD);
  13665. component.codingStyleParameters = codOrCoc;
  13666. }
  13667. tile.codingStyleDefaultParameters = context.currentTile.COD;
  13668. }
  13669. // Section B.10.2 Tag trees
  13670. var TagTree = (function TagTreeClosure() {
  13671. function TagTree(width, height) {
  13672. var levelsLength = log2(Math.max(width, height)) + 1;
  13673. this.levels = [];
  13674. for (var i = 0; i < levelsLength; i++) {
  13675. var level = {
  13676. width: width,
  13677. height: height,
  13678. items: []
  13679. };
  13680. this.levels.push(level);
  13681. width = Math.ceil(width / 2);
  13682. height = Math.ceil(height / 2);
  13683. }
  13684. }
  13685. TagTree.prototype = {
  13686. reset: function TagTree_reset(i, j) {
  13687. var currentLevel = 0, value = 0, level;
  13688. while (currentLevel < this.levels.length) {
  13689. level = this.levels[currentLevel];
  13690. var index = i + j * level.width;
  13691. if (level.items[index] !== undefined) {
  13692. value = level.items[index];
  13693. break;
  13694. }
  13695. level.index = index;
  13696. i >>= 1;
  13697. j >>= 1;
  13698. currentLevel++;
  13699. }
  13700. currentLevel--;
  13701. level = this.levels[currentLevel];
  13702. level.items[level.index] = value;
  13703. this.currentLevel = currentLevel;
  13704. delete this.value;
  13705. },
  13706. incrementValue: function TagTree_incrementValue() {
  13707. var level = this.levels[this.currentLevel];
  13708. level.items[level.index]++;
  13709. },
  13710. nextLevel: function TagTree_nextLevel() {
  13711. var currentLevel = this.currentLevel;
  13712. var level = this.levels[currentLevel];
  13713. var value = level.items[level.index];
  13714. currentLevel--;
  13715. if (currentLevel < 0) {
  13716. this.value = value;
  13717. return false;
  13718. }
  13719. this.currentLevel = currentLevel;
  13720. level = this.levels[currentLevel];
  13721. level.items[level.index] = value;
  13722. return true;
  13723. }
  13724. };
  13725. return TagTree;
  13726. })();
  13727. var InclusionTree = (function InclusionTreeClosure() {
  13728. function InclusionTree(width, height, defaultValue) {
  13729. var levelsLength = log2(Math.max(width, height)) + 1;
  13730. this.levels = [];
  13731. for (var i = 0; i < levelsLength; i++) {
  13732. var items = new Uint8Array(width * height);
  13733. for (var j = 0, jj = items.length; j < jj; j++) {
  13734. items[j] = defaultValue;
  13735. }
  13736. var level = {
  13737. width: width,
  13738. height: height,
  13739. items: items
  13740. };
  13741. this.levels.push(level);
  13742. width = Math.ceil(width / 2);
  13743. height = Math.ceil(height / 2);
  13744. }
  13745. }
  13746. InclusionTree.prototype = {
  13747. reset: function InclusionTree_reset(i, j, stopValue) {
  13748. var currentLevel = 0;
  13749. while (currentLevel < this.levels.length) {
  13750. var level = this.levels[currentLevel];
  13751. var index = i + j * level.width;
  13752. level.index = index;
  13753. var value = level.items[index];
  13754. if (value === 0xFF) {
  13755. break;
  13756. }
  13757. if (value > stopValue) {
  13758. this.currentLevel = currentLevel;
  13759. // already know about this one, propagating the value to top levels
  13760. this.propagateValues();
  13761. return false;
  13762. }
  13763. i >>= 1;
  13764. j >>= 1;
  13765. currentLevel++;
  13766. }
  13767. this.currentLevel = currentLevel - 1;
  13768. return true;
  13769. },
  13770. incrementValue: function InclusionTree_incrementValue(stopValue) {
  13771. var level = this.levels[this.currentLevel];
  13772. level.items[level.index] = stopValue + 1;
  13773. this.propagateValues();
  13774. },
  13775. propagateValues: function InclusionTree_propagateValues() {
  13776. var levelIndex = this.currentLevel;
  13777. var level = this.levels[levelIndex];
  13778. var currentValue = level.items[level.index];
  13779. while (--levelIndex >= 0) {
  13780. level = this.levels[levelIndex];
  13781. level.items[level.index] = currentValue;
  13782. }
  13783. },
  13784. nextLevel: function InclusionTree_nextLevel() {
  13785. var currentLevel = this.currentLevel;
  13786. var level = this.levels[currentLevel];
  13787. var value = level.items[level.index];
  13788. level.items[level.index] = 0xFF;
  13789. currentLevel--;
  13790. if (currentLevel < 0) {
  13791. return false;
  13792. }
  13793. this.currentLevel = currentLevel;
  13794. level = this.levels[currentLevel];
  13795. level.items[level.index] = value;
  13796. return true;
  13797. }
  13798. };
  13799. return InclusionTree;
  13800. })();
  13801. // Section D. Coefficient bit modeling
  13802. var BitModel = (function BitModelClosure() {
  13803. var UNIFORM_CONTEXT = 17;
  13804. var RUNLENGTH_CONTEXT = 18;
  13805. // Table D-1
  13806. // The index is binary presentation: 0dddvvhh, ddd - sum of Di (0..4),
  13807. // vv - sum of Vi (0..2), and hh - sum of Hi (0..2)
  13808. var LLAndLHContextsLabel = new Uint8Array([
  13809. 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,
  13810. 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,
  13811. 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
  13812. ]);
  13813. var HLContextLabel = new Uint8Array([
  13814. 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,
  13815. 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,
  13816. 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
  13817. ]);
  13818. var HHContextLabel = new Uint8Array([
  13819. 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,
  13820. 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,
  13821. 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
  13822. ]);
  13823. function BitModel(width, height, subband, zeroBitPlanes, mb) {
  13824. this.width = width;
  13825. this.height = height;
  13826. this.contextLabelTable = (subband === 'HH' ? HHContextLabel :
  13827. (subband === 'HL' ? HLContextLabel : LLAndLHContextsLabel));
  13828. var coefficientCount = width * height;
  13829. // coefficients outside the encoding region treated as insignificant
  13830. // add border state cells for significanceState
  13831. this.neighborsSignificance = new Uint8Array(coefficientCount);
  13832. this.coefficentsSign = new Uint8Array(coefficientCount);
  13833. this.coefficentsMagnitude = mb > 14 ? new Uint32Array(coefficientCount) :
  13834. mb > 6 ? new Uint16Array(coefficientCount) :
  13835. new Uint8Array(coefficientCount);
  13836. this.processingFlags = new Uint8Array(coefficientCount);
  13837. var bitsDecoded = new Uint8Array(coefficientCount);
  13838. if (zeroBitPlanes !== 0) {
  13839. for (var i = 0; i < coefficientCount; i++) {
  13840. bitsDecoded[i] = zeroBitPlanes;
  13841. }
  13842. }
  13843. this.bitsDecoded = bitsDecoded;
  13844. this.reset();
  13845. }
  13846. BitModel.prototype = {
  13847. setDecoder: function BitModel_setDecoder(decoder) {
  13848. this.decoder = decoder;
  13849. },
  13850. reset: function BitModel_reset() {
  13851. // We have 17 contexts that are accessed via context labels,
  13852. // plus the uniform and runlength context.
  13853. this.contexts = new Int8Array(19);
  13854. // Contexts are packed into 1 byte:
  13855. // highest 7 bits carry the index, lowest bit carries mps
  13856. this.contexts[0] = (4 << 1) | 0;
  13857. this.contexts[UNIFORM_CONTEXT] = (46 << 1) | 0;
  13858. this.contexts[RUNLENGTH_CONTEXT] = (3 << 1) | 0;
  13859. },
  13860. setNeighborsSignificance:
  13861. function BitModel_setNeighborsSignificance(row, column, index) {
  13862. var neighborsSignificance = this.neighborsSignificance;
  13863. var width = this.width, height = this.height;
  13864. var left = (column > 0);
  13865. var right = (column + 1 < width);
  13866. var i;
  13867. if (row > 0) {
  13868. i = index - width;
  13869. if (left) {
  13870. neighborsSignificance[i - 1] += 0x10;
  13871. }
  13872. if (right) {
  13873. neighborsSignificance[i + 1] += 0x10;
  13874. }
  13875. neighborsSignificance[i] += 0x04;
  13876. }
  13877. if (row + 1 < height) {
  13878. i = index + width;
  13879. if (left) {
  13880. neighborsSignificance[i - 1] += 0x10;
  13881. }
  13882. if (right) {
  13883. neighborsSignificance[i + 1] += 0x10;
  13884. }
  13885. neighborsSignificance[i] += 0x04;
  13886. }
  13887. if (left) {
  13888. neighborsSignificance[index - 1] += 0x01;
  13889. }
  13890. if (right) {
  13891. neighborsSignificance[index + 1] += 0x01;
  13892. }
  13893. neighborsSignificance[index] |= 0x80;
  13894. },
  13895. runSignificancePropogationPass:
  13896. function BitModel_runSignificancePropogationPass() {
  13897. var decoder = this.decoder;
  13898. var width = this.width, height = this.height;
  13899. var coefficentsMagnitude = this.coefficentsMagnitude;
  13900. var coefficentsSign = this.coefficentsSign;
  13901. var neighborsSignificance = this.neighborsSignificance;
  13902. var processingFlags = this.processingFlags;
  13903. var contexts = this.contexts;
  13904. var labels = this.contextLabelTable;
  13905. var bitsDecoded = this.bitsDecoded;
  13906. var processedInverseMask = ~1;
  13907. var processedMask = 1;
  13908. var firstMagnitudeBitMask = 2;
  13909. for (var i0 = 0; i0 < height; i0 += 4) {
  13910. for (var j = 0; j < width; j++) {
  13911. var index = i0 * width + j;
  13912. for (var i1 = 0; i1 < 4; i1++, index += width) {
  13913. var i = i0 + i1;
  13914. if (i >= height) {
  13915. break;
  13916. }
  13917. // clear processed flag first
  13918. processingFlags[index] &= processedInverseMask;
  13919. if (coefficentsMagnitude[index] ||
  13920. !neighborsSignificance[index]) {
  13921. continue;
  13922. }
  13923. var contextLabel = labels[neighborsSignificance[index]];
  13924. var decision = decoder.readBit(contexts, contextLabel);
  13925. if (decision) {
  13926. var sign = this.decodeSignBit(i, j, index);
  13927. coefficentsSign[index] = sign;
  13928. coefficentsMagnitude[index] = 1;
  13929. this.setNeighborsSignificance(i, j, index);
  13930. processingFlags[index] |= firstMagnitudeBitMask;
  13931. }
  13932. bitsDecoded[index]++;
  13933. processingFlags[index] |= processedMask;
  13934. }
  13935. }
  13936. }
  13937. },
  13938. decodeSignBit: function BitModel_decodeSignBit(row, column, index) {
  13939. var width = this.width, height = this.height;
  13940. var coefficentsMagnitude = this.coefficentsMagnitude;
  13941. var coefficentsSign = this.coefficentsSign;
  13942. var contribution, sign0, sign1, significance1;
  13943. var contextLabel, decoded;
  13944. // calculate horizontal contribution
  13945. significance1 = (column > 0 && coefficentsMagnitude[index - 1] !== 0);
  13946. if (column + 1 < width && coefficentsMagnitude[index + 1] !== 0) {
  13947. sign1 = coefficentsSign[index + 1];
  13948. if (significance1) {
  13949. sign0 = coefficentsSign[index - 1];
  13950. contribution = 1 - sign1 - sign0;
  13951. } else {
  13952. contribution = 1 - sign1 - sign1;
  13953. }
  13954. } else if (significance1) {
  13955. sign0 = coefficentsSign[index - 1];
  13956. contribution = 1 - sign0 - sign0;
  13957. } else {
  13958. contribution = 0;
  13959. }
  13960. var horizontalContribution = 3 * contribution;
  13961. // calculate vertical contribution and combine with the horizontal
  13962. significance1 = (row > 0 && coefficentsMagnitude[index - width] !== 0);
  13963. if (row + 1 < height && coefficentsMagnitude[index + width] !== 0) {
  13964. sign1 = coefficentsSign[index + width];
  13965. if (significance1) {
  13966. sign0 = coefficentsSign[index - width];
  13967. contribution = 1 - sign1 - sign0 + horizontalContribution;
  13968. } else {
  13969. contribution = 1 - sign1 - sign1 + horizontalContribution;
  13970. }
  13971. } else if (significance1) {
  13972. sign0 = coefficentsSign[index - width];
  13973. contribution = 1 - sign0 - sign0 + horizontalContribution;
  13974. } else {
  13975. contribution = horizontalContribution;
  13976. }
  13977. if (contribution >= 0) {
  13978. contextLabel = 9 + contribution;
  13979. decoded = this.decoder.readBit(this.contexts, contextLabel);
  13980. } else {
  13981. contextLabel = 9 - contribution;
  13982. decoded = this.decoder.readBit(this.contexts, contextLabel) ^ 1;
  13983. }
  13984. return decoded;
  13985. },
  13986. runMagnitudeRefinementPass:
  13987. function BitModel_runMagnitudeRefinementPass() {
  13988. var decoder = this.decoder;
  13989. var width = this.width, height = this.height;
  13990. var coefficentsMagnitude = this.coefficentsMagnitude;
  13991. var neighborsSignificance = this.neighborsSignificance;
  13992. var contexts = this.contexts;
  13993. var bitsDecoded = this.bitsDecoded;
  13994. var processingFlags = this.processingFlags;
  13995. var processedMask = 1;
  13996. var firstMagnitudeBitMask = 2;
  13997. var length = width * height;
  13998. var width4 = width * 4;
  13999. for (var index0 = 0, indexNext; index0 < length; index0 = indexNext) {
  14000. indexNext = Math.min(length, index0 + width4);
  14001. for (var j = 0; j < width; j++) {
  14002. for (var index = index0 + j; index < indexNext; index += width) {
  14003. // significant but not those that have just become
  14004. if (!coefficentsMagnitude[index] ||
  14005. (processingFlags[index] & processedMask) !== 0) {
  14006. continue;
  14007. }
  14008. var contextLabel = 16;
  14009. if ((processingFlags[index] & firstMagnitudeBitMask) !== 0) {
  14010. processingFlags[index] ^= firstMagnitudeBitMask;
  14011. // first refinement
  14012. var significance = neighborsSignificance[index] & 127;
  14013. contextLabel = significance === 0 ? 15 : 14;
  14014. }
  14015. var bit = decoder.readBit(contexts, contextLabel);
  14016. coefficentsMagnitude[index] =
  14017. (coefficentsMagnitude[index] << 1) | bit;
  14018. bitsDecoded[index]++;
  14019. processingFlags[index] |= processedMask;
  14020. }
  14021. }
  14022. }
  14023. },
  14024. runCleanupPass: function BitModel_runCleanupPass() {
  14025. var decoder = this.decoder;
  14026. var width = this.width, height = this.height;
  14027. var neighborsSignificance = this.neighborsSignificance;
  14028. var coefficentsMagnitude = this.coefficentsMagnitude;
  14029. var coefficentsSign = this.coefficentsSign;
  14030. var contexts = this.contexts;
  14031. var labels = this.contextLabelTable;
  14032. var bitsDecoded = this.bitsDecoded;
  14033. var processingFlags = this.processingFlags;
  14034. var processedMask = 1;
  14035. var firstMagnitudeBitMask = 2;
  14036. var oneRowDown = width;
  14037. var twoRowsDown = width * 2;
  14038. var threeRowsDown = width * 3;
  14039. var iNext;
  14040. for (var i0 = 0; i0 < height; i0 = iNext) {
  14041. iNext = Math.min(i0 + 4, height);
  14042. var indexBase = i0 * width;
  14043. var checkAllEmpty = i0 + 3 < height;
  14044. for (var j = 0; j < width; j++) {
  14045. var index0 = indexBase + j;
  14046. // using the property: labels[neighborsSignificance[index]] === 0
  14047. // when neighborsSignificance[index] === 0
  14048. var allEmpty = (checkAllEmpty &&
  14049. processingFlags[index0] === 0 &&
  14050. processingFlags[index0 + oneRowDown] === 0 &&
  14051. processingFlags[index0 + twoRowsDown] === 0 &&
  14052. processingFlags[index0 + threeRowsDown] === 0 &&
  14053. neighborsSignificance[index0] === 0 &&
  14054. neighborsSignificance[index0 + oneRowDown] === 0 &&
  14055. neighborsSignificance[index0 + twoRowsDown] === 0 &&
  14056. neighborsSignificance[index0 + threeRowsDown] === 0);
  14057. var i1 = 0, index = index0;
  14058. var i = i0, sign;
  14059. if (allEmpty) {
  14060. var hasSignificantCoefficent =
  14061. decoder.readBit(contexts, RUNLENGTH_CONTEXT);
  14062. if (!hasSignificantCoefficent) {
  14063. bitsDecoded[index0]++;
  14064. bitsDecoded[index0 + oneRowDown]++;
  14065. bitsDecoded[index0 + twoRowsDown]++;
  14066. bitsDecoded[index0 + threeRowsDown]++;
  14067. continue; // next column
  14068. }
  14069. i1 = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  14070. decoder.readBit(contexts, UNIFORM_CONTEXT);
  14071. if (i1 !== 0) {
  14072. i = i0 + i1;
  14073. index += i1 * width;
  14074. }
  14075. sign = this.decodeSignBit(i, j, index);
  14076. coefficentsSign[index] = sign;
  14077. coefficentsMagnitude[index] = 1;
  14078. this.setNeighborsSignificance(i, j, index);
  14079. processingFlags[index] |= firstMagnitudeBitMask;
  14080. index = index0;
  14081. for (var i2 = i0; i2 <= i; i2++, index += width) {
  14082. bitsDecoded[index]++;
  14083. }
  14084. i1++;
  14085. }
  14086. for (i = i0 + i1; i < iNext; i++, index += width) {
  14087. if (coefficentsMagnitude[index] ||
  14088. (processingFlags[index] & processedMask) !== 0) {
  14089. continue;
  14090. }
  14091. var contextLabel = labels[neighborsSignificance[index]];
  14092. var decision = decoder.readBit(contexts, contextLabel);
  14093. if (decision === 1) {
  14094. sign = this.decodeSignBit(i, j, index);
  14095. coefficentsSign[index] = sign;
  14096. coefficentsMagnitude[index] = 1;
  14097. this.setNeighborsSignificance(i, j, index);
  14098. processingFlags[index] |= firstMagnitudeBitMask;
  14099. }
  14100. bitsDecoded[index]++;
  14101. }
  14102. }
  14103. }
  14104. },
  14105. checkSegmentationSymbol: function BitModel_checkSegmentationSymbol() {
  14106. var decoder = this.decoder;
  14107. var contexts = this.contexts;
  14108. var symbol = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 3) |
  14109. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 2) |
  14110. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  14111. decoder.readBit(contexts, UNIFORM_CONTEXT);
  14112. if (symbol !== 0xA) {
  14113. throw new Error('JPX Error: Invalid segmentation symbol');
  14114. }
  14115. }
  14116. };
  14117. return BitModel;
  14118. })();
  14119. // Section F, Discrete wavelet transformation
  14120. var Transform = (function TransformClosure() {
  14121. function Transform() {}
  14122. Transform.prototype.calculate =
  14123. function transformCalculate(subbands, u0, v0) {
  14124. var ll = subbands[0];
  14125. for (var i = 1, ii = subbands.length; i < ii; i++) {
  14126. ll = this.iterate(ll, subbands[i], u0, v0);
  14127. }
  14128. return ll;
  14129. };
  14130. Transform.prototype.extend = function extend(buffer, offset, size) {
  14131. // Section F.3.7 extending... using max extension of 4
  14132. var i1 = offset - 1, j1 = offset + 1;
  14133. var i2 = offset + size - 2, j2 = offset + size;
  14134. buffer[i1--] = buffer[j1++];
  14135. buffer[j2++] = buffer[i2--];
  14136. buffer[i1--] = buffer[j1++];
  14137. buffer[j2++] = buffer[i2--];
  14138. buffer[i1--] = buffer[j1++];
  14139. buffer[j2++] = buffer[i2--];
  14140. buffer[i1] = buffer[j1];
  14141. buffer[j2] = buffer[i2];
  14142. };
  14143. Transform.prototype.iterate = function Transform_iterate(ll, hl_lh_hh,
  14144. u0, v0) {
  14145. var llWidth = ll.width, llHeight = ll.height, llItems = ll.items;
  14146. var width = hl_lh_hh.width;
  14147. var height = hl_lh_hh.height;
  14148. var items = hl_lh_hh.items;
  14149. var i, j, k, l, u, v;
  14150. // Interleave LL according to Section F.3.3
  14151. for (k = 0, i = 0; i < llHeight; i++) {
  14152. l = i * 2 * width;
  14153. for (j = 0; j < llWidth; j++, k++, l += 2) {
  14154. items[l] = llItems[k];
  14155. }
  14156. }
  14157. // The LL band is not needed anymore.
  14158. llItems = ll.items = null;
  14159. var bufferPadding = 4;
  14160. var rowBuffer = new Float32Array(width + 2 * bufferPadding);
  14161. // Section F.3.4 HOR_SR
  14162. if (width === 1) {
  14163. // if width = 1, when u0 even keep items as is, when odd divide by 2
  14164. if ((u0 & 1) !== 0) {
  14165. for (v = 0, k = 0; v < height; v++, k += width) {
  14166. items[k] *= 0.5;
  14167. }
  14168. }
  14169. } else {
  14170. for (v = 0, k = 0; v < height; v++, k += width) {
  14171. rowBuffer.set(items.subarray(k, k + width), bufferPadding);
  14172. this.extend(rowBuffer, bufferPadding, width);
  14173. this.filter(rowBuffer, bufferPadding, width);
  14174. items.set(
  14175. rowBuffer.subarray(bufferPadding, bufferPadding + width),
  14176. k);
  14177. }
  14178. }
  14179. // Accesses to the items array can take long, because it may not fit into
  14180. // CPU cache and has to be fetched from main memory. Since subsequent
  14181. // accesses to the items array are not local when reading columns, we
  14182. // have a cache miss every time. To reduce cache misses, get up to
  14183. // 'numBuffers' items at a time and store them into the individual
  14184. // buffers. The colBuffers should be small enough to fit into CPU cache.
  14185. var numBuffers = 16;
  14186. var colBuffers = [];
  14187. for (i = 0; i < numBuffers; i++) {
  14188. colBuffers.push(new Float32Array(height + 2 * bufferPadding));
  14189. }
  14190. var b, currentBuffer = 0;
  14191. ll = bufferPadding + height;
  14192. // Section F.3.5 VER_SR
  14193. if (height === 1) {
  14194. // if height = 1, when v0 even keep items as is, when odd divide by 2
  14195. if ((v0 & 1) !== 0) {
  14196. for (u = 0; u < width; u++) {
  14197. items[u] *= 0.5;
  14198. }
  14199. }
  14200. } else {
  14201. for (u = 0; u < width; u++) {
  14202. // if we ran out of buffers, copy several image columns at once
  14203. if (currentBuffer === 0) {
  14204. numBuffers = Math.min(width - u, numBuffers);
  14205. for (k = u, l = bufferPadding; l < ll; k += width, l++) {
  14206. for (b = 0; b < numBuffers; b++) {
  14207. colBuffers[b][l] = items[k + b];
  14208. }
  14209. }
  14210. currentBuffer = numBuffers;
  14211. }
  14212. currentBuffer--;
  14213. var buffer = colBuffers[currentBuffer];
  14214. this.extend(buffer, bufferPadding, height);
  14215. this.filter(buffer, bufferPadding, height);
  14216. // If this is last buffer in this group of buffers, flush all buffers.
  14217. if (currentBuffer === 0) {
  14218. k = u - numBuffers + 1;
  14219. for (l = bufferPadding; l < ll; k += width, l++) {
  14220. for (b = 0; b < numBuffers; b++) {
  14221. items[k + b] = colBuffers[b][l];
  14222. }
  14223. }
  14224. }
  14225. }
  14226. }
  14227. return {
  14228. width: width,
  14229. height: height,
  14230. items: items
  14231. };
  14232. };
  14233. return Transform;
  14234. })();
  14235. // Section 3.8.2 Irreversible 9-7 filter
  14236. var IrreversibleTransform = (function IrreversibleTransformClosure() {
  14237. function IrreversibleTransform() {
  14238. Transform.call(this);
  14239. }
  14240. IrreversibleTransform.prototype = Object.create(Transform.prototype);
  14241. IrreversibleTransform.prototype.filter =
  14242. function irreversibleTransformFilter(x, offset, length) {
  14243. var len = length >> 1;
  14244. offset = offset | 0;
  14245. var j, n, current, next;
  14246. var alpha = -1.586134342059924;
  14247. var beta = -0.052980118572961;
  14248. var gamma = 0.882911075530934;
  14249. var delta = 0.443506852043971;
  14250. var K = 1.230174104914001;
  14251. var K_ = 1 / K;
  14252. // step 1 is combined with step 3
  14253. // step 2
  14254. j = offset - 3;
  14255. for (n = len + 4; n--; j += 2) {
  14256. x[j] *= K_;
  14257. }
  14258. // step 1 & 3
  14259. j = offset - 2;
  14260. current = delta * x[j -1];
  14261. for (n = len + 3; n--; j += 2) {
  14262. next = delta * x[j + 1];
  14263. x[j] = K * x[j] - current - next;
  14264. if (n--) {
  14265. j += 2;
  14266. current = delta * x[j + 1];
  14267. x[j] = K * x[j] - current - next;
  14268. } else {
  14269. break;
  14270. }
  14271. }
  14272. // step 4
  14273. j = offset - 1;
  14274. current = gamma * x[j - 1];
  14275. for (n = len + 2; n--; j += 2) {
  14276. next = gamma * x[j + 1];
  14277. x[j] -= current + next;
  14278. if (n--) {
  14279. j += 2;
  14280. current = gamma * x[j + 1];
  14281. x[j] -= current + next;
  14282. } else {
  14283. break;
  14284. }
  14285. }
  14286. // step 5
  14287. j = offset;
  14288. current = beta * x[j - 1];
  14289. for (n = len + 1; n--; j += 2) {
  14290. next = beta * x[j + 1];
  14291. x[j] -= current + next;
  14292. if (n--) {
  14293. j += 2;
  14294. current = beta * x[j + 1];
  14295. x[j] -= current + next;
  14296. } else {
  14297. break;
  14298. }
  14299. }
  14300. // step 6
  14301. if (len !== 0) {
  14302. j = offset + 1;
  14303. current = alpha * x[j - 1];
  14304. for (n = len; n--; j += 2) {
  14305. next = alpha * x[j + 1];
  14306. x[j] -= current + next;
  14307. if (n--) {
  14308. j += 2;
  14309. current = alpha * x[j + 1];
  14310. x[j] -= current + next;
  14311. } else {
  14312. break;
  14313. }
  14314. }
  14315. }
  14316. };
  14317. return IrreversibleTransform;
  14318. })();
  14319. // Section 3.8.1 Reversible 5-3 filter
  14320. var ReversibleTransform = (function ReversibleTransformClosure() {
  14321. function ReversibleTransform() {
  14322. Transform.call(this);
  14323. }
  14324. ReversibleTransform.prototype = Object.create(Transform.prototype);
  14325. ReversibleTransform.prototype.filter =
  14326. function reversibleTransformFilter(x, offset, length) {
  14327. var len = length >> 1;
  14328. offset = offset | 0;
  14329. var j, n;
  14330. for (j = offset, n = len + 1; n--; j += 2) {
  14331. x[j] -= (x[j - 1] + x[j + 1] + 2) >> 2;
  14332. }
  14333. for (j = offset + 1, n = len; n--; j += 2) {
  14334. x[j] += (x[j - 1] + x[j + 1]) >> 1;
  14335. }
  14336. };
  14337. return ReversibleTransform;
  14338. })();
  14339. return JpxImage;
  14340. })();
  14341. exports.JpxImage = JpxImage;
  14342. }));
  14343. (function (root, factory) {
  14344. if (typeof define === 'function' && define.amd) {
  14345. define('pdfjs/core/murmurhash3', ['exports', 'pdfjs/shared/util'], factory);
  14346. } else if (typeof exports !== 'undefined') {
  14347. factory(exports, require('../shared/util.js'));
  14348. } else {
  14349. factory((root.pdfjsCoreMurmurHash3 = {}), root.pdfjsSharedUtil);
  14350. }
  14351. }(this, function (exports, sharedUtil) {
  14352. var Uint32ArrayView = sharedUtil.Uint32ArrayView;
  14353. var MurmurHash3_64 = (function MurmurHash3_64Closure (seed) {
  14354. // Workaround for missing math precison in JS.
  14355. var MASK_HIGH = 0xffff0000;
  14356. var MASK_LOW = 0xffff;
  14357. function MurmurHash3_64 (seed) {
  14358. var SEED = 0xc3d2e1f0;
  14359. this.h1 = seed ? seed & 0xffffffff : SEED;
  14360. this.h2 = seed ? seed & 0xffffffff : SEED;
  14361. }
  14362. var alwaysUseUint32ArrayView = false;
  14363. // old webkits have issues with non-aligned arrays
  14364. try {
  14365. new Uint32Array(new Uint8Array(5).buffer, 0, 1);
  14366. } catch (e) {
  14367. alwaysUseUint32ArrayView = true;
  14368. }
  14369. MurmurHash3_64.prototype = {
  14370. update: function MurmurHash3_64_update(input) {
  14371. var useUint32ArrayView = alwaysUseUint32ArrayView;
  14372. var i;
  14373. if (typeof input === 'string') {
  14374. var data = new Uint8Array(input.length * 2);
  14375. var length = 0;
  14376. for (i = 0; i < input.length; i++) {
  14377. var code = input.charCodeAt(i);
  14378. if (code <= 0xff) {
  14379. data[length++] = code;
  14380. }
  14381. else {
  14382. data[length++] = code >>> 8;
  14383. data[length++] = code & 0xff;
  14384. }
  14385. }
  14386. } else if (input instanceof Uint8Array) {
  14387. data = input;
  14388. length = data.length;
  14389. } else if (typeof input === 'object' && ('length' in input)) {
  14390. // processing regular arrays as well, e.g. for IE9
  14391. data = input;
  14392. length = data.length;
  14393. useUint32ArrayView = true;
  14394. } else {
  14395. throw new Error('Wrong data format in MurmurHash3_64_update. ' +
  14396. 'Input must be a string or array.');
  14397. }
  14398. var blockCounts = length >> 2;
  14399. var tailLength = length - blockCounts * 4;
  14400. // we don't care about endianness here
  14401. var dataUint32 = useUint32ArrayView ?
  14402. new Uint32ArrayView(data, blockCounts) :
  14403. new Uint32Array(data.buffer, 0, blockCounts);
  14404. var k1 = 0;
  14405. var k2 = 0;
  14406. var h1 = this.h1;
  14407. var h2 = this.h2;
  14408. var C1 = 0xcc9e2d51;
  14409. var C2 = 0x1b873593;
  14410. var C1_LOW = C1 & MASK_LOW;
  14411. var C2_LOW = C2 & MASK_LOW;
  14412. for (i = 0; i < blockCounts; i++) {
  14413. if (i & 1) {
  14414. k1 = dataUint32[i];
  14415. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  14416. k1 = k1 << 15 | k1 >>> 17;
  14417. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  14418. h1 ^= k1;
  14419. h1 = h1 << 13 | h1 >>> 19;
  14420. h1 = h1 * 5 + 0xe6546b64;
  14421. } else {
  14422. k2 = dataUint32[i];
  14423. k2 = (k2 * C1 & MASK_HIGH) | (k2 * C1_LOW & MASK_LOW);
  14424. k2 = k2 << 15 | k2 >>> 17;
  14425. k2 = (k2 * C2 & MASK_HIGH) | (k2 * C2_LOW & MASK_LOW);
  14426. h2 ^= k2;
  14427. h2 = h2 << 13 | h2 >>> 19;
  14428. h2 = h2 * 5 + 0xe6546b64;
  14429. }
  14430. }
  14431. k1 = 0;
  14432. switch (tailLength) {
  14433. case 3:
  14434. k1 ^= data[blockCounts * 4 + 2] << 16;
  14435. /* falls through */
  14436. case 2:
  14437. k1 ^= data[blockCounts * 4 + 1] << 8;
  14438. /* falls through */
  14439. case 1:
  14440. k1 ^= data[blockCounts * 4];
  14441. /* falls through */
  14442. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  14443. k1 = k1 << 15 | k1 >>> 17;
  14444. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  14445. if (blockCounts & 1) {
  14446. h1 ^= k1;
  14447. } else {
  14448. h2 ^= k1;
  14449. }
  14450. }
  14451. this.h1 = h1;
  14452. this.h2 = h2;
  14453. return this;
  14454. },
  14455. hexdigest: function MurmurHash3_64_hexdigest () {
  14456. var h1 = this.h1;
  14457. var h2 = this.h2;
  14458. h1 ^= h2 >>> 1;
  14459. h1 = (h1 * 0xed558ccd & MASK_HIGH) | (h1 * 0x8ccd & MASK_LOW);
  14460. h2 = (h2 * 0xff51afd7 & MASK_HIGH) |
  14461. (((h2 << 16 | h1 >>> 16) * 0xafd7ed55 & MASK_HIGH) >>> 16);
  14462. h1 ^= h2 >>> 1;
  14463. h1 = (h1 * 0x1a85ec53 & MASK_HIGH) | (h1 * 0xec53 & MASK_LOW);
  14464. h2 = (h2 * 0xc4ceb9fe & MASK_HIGH) |
  14465. (((h2 << 16 | h1 >>> 16) * 0xb9fe1a85 & MASK_HIGH) >>> 16);
  14466. h1 ^= h2 >>> 1;
  14467. for (var i = 0, arr = [h1, h2], str = ''; i < arr.length; i++) {
  14468. var hex = (arr[i] >>> 0).toString(16);
  14469. while (hex.length < 8) {
  14470. hex = '0' + hex;
  14471. }
  14472. str += hex;
  14473. }
  14474. return str;
  14475. }
  14476. };
  14477. return MurmurHash3_64;
  14478. })();
  14479. exports.MurmurHash3_64 = MurmurHash3_64;
  14480. }));
  14481. (function (root, factory) {
  14482. if (typeof define === 'function' && define.amd) {
  14483. define('pdfjs/core/primitives', ['exports', 'pdfjs/shared/util'], factory);
  14484. } else if (typeof exports !== 'undefined') {
  14485. factory(exports, require('../shared/util.js'));
  14486. } else {
  14487. factory((root.pdfjsCorePrimitives = {}), root.pdfjsSharedUtil);
  14488. }
  14489. }(this, function (exports, sharedUtil) {
  14490. var isArray = sharedUtil.isArray;
  14491. var Name = (function NameClosure() {
  14492. function Name(name) {
  14493. this.name = name;
  14494. }
  14495. Name.prototype = {};
  14496. var nameCache = {};
  14497. Name.get = function Name_get(name) {
  14498. var nameValue = nameCache[name];
  14499. return (nameValue ? nameValue : (nameCache[name] = new Name(name)));
  14500. };
  14501. return Name;
  14502. })();
  14503. var Cmd = (function CmdClosure() {
  14504. function Cmd(cmd) {
  14505. this.cmd = cmd;
  14506. }
  14507. Cmd.prototype = {};
  14508. var cmdCache = {};
  14509. Cmd.get = function Cmd_get(cmd) {
  14510. var cmdValue = cmdCache[cmd];
  14511. return (cmdValue ? cmdValue : (cmdCache[cmd] = new Cmd(cmd)));
  14512. };
  14513. return Cmd;
  14514. })();
  14515. var Dict = (function DictClosure() {
  14516. var nonSerializable = function nonSerializableClosure() {
  14517. return nonSerializable; // creating closure on some variable
  14518. };
  14519. var GETALL_DICTIONARY_TYPES_WHITELIST = {
  14520. 'Background': true,
  14521. 'ExtGState': true,
  14522. 'Halftone': true,
  14523. 'Layout': true,
  14524. 'Mask': true,
  14525. 'Pagination': true,
  14526. 'Printing': true
  14527. };
  14528. function isRecursionAllowedFor(dict) {
  14529. if (!isName(dict.Type)) {
  14530. return true;
  14531. }
  14532. var dictType = dict.Type.name;
  14533. return GETALL_DICTIONARY_TYPES_WHITELIST[dictType] === true;
  14534. }
  14535. // xref is optional
  14536. function Dict(xref) {
  14537. // Map should only be used internally, use functions below to access.
  14538. this.map = Object.create(null);
  14539. this.xref = xref;
  14540. this.objId = null;
  14541. this.__nonSerializable__ = nonSerializable; // disable cloning of the Dict
  14542. }
  14543. Dict.prototype = {
  14544. assignXref: function Dict_assignXref(newXref) {
  14545. this.xref = newXref;
  14546. },
  14547. // automatically dereferences Ref objects
  14548. get: function Dict_get(key1, key2, key3) {
  14549. var value;
  14550. var xref = this.xref;
  14551. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  14552. typeof key2 === 'undefined') {
  14553. return xref ? xref.fetchIfRef(value) : value;
  14554. }
  14555. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  14556. typeof key3 === 'undefined') {
  14557. return xref ? xref.fetchIfRef(value) : value;
  14558. }
  14559. value = this.map[key3] || null;
  14560. return xref ? xref.fetchIfRef(value) : value;
  14561. },
  14562. // Same as get(), but returns a promise and uses fetchIfRefAsync().
  14563. getAsync: function Dict_getAsync(key1, key2, key3) {
  14564. var value;
  14565. var xref = this.xref;
  14566. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  14567. typeof key2 === 'undefined') {
  14568. if (xref) {
  14569. return xref.fetchIfRefAsync(value);
  14570. }
  14571. return Promise.resolve(value);
  14572. }
  14573. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  14574. typeof key3 === 'undefined') {
  14575. if (xref) {
  14576. return xref.fetchIfRefAsync(value);
  14577. }
  14578. return Promise.resolve(value);
  14579. }
  14580. value = this.map[key3] || null;
  14581. if (xref) {
  14582. return xref.fetchIfRefAsync(value);
  14583. }
  14584. return Promise.resolve(value);
  14585. },
  14586. // Same as get(), but dereferences all elements if the result is an Array.
  14587. getArray: function Dict_getArray(key1, key2, key3) {
  14588. var value = this.get(key1, key2, key3);
  14589. var xref = this.xref;
  14590. if (!isArray(value) || !xref) {
  14591. return value;
  14592. }
  14593. value = value.slice(); // Ensure that we don't modify the Dict data.
  14594. for (var i = 0, ii = value.length; i < ii; i++) {
  14595. if (!isRef(value[i])) {
  14596. continue;
  14597. }
  14598. value[i] = xref.fetch(value[i]);
  14599. }
  14600. return value;
  14601. },
  14602. // no dereferencing
  14603. getRaw: function Dict_getRaw(key) {
  14604. return this.map[key];
  14605. },
  14606. // creates new map and dereferences all Refs
  14607. getAll: function Dict_getAll() {
  14608. var all = Object.create(null);
  14609. var queue = null;
  14610. var key, obj;
  14611. for (key in this.map) {
  14612. obj = this.get(key);
  14613. if (obj instanceof Dict) {
  14614. if (isRecursionAllowedFor(obj)) {
  14615. (queue || (queue = [])).push({target: all, key: key, obj: obj});
  14616. } else {
  14617. all[key] = this.getRaw(key);
  14618. }
  14619. } else {
  14620. all[key] = obj;
  14621. }
  14622. }
  14623. if (!queue) {
  14624. return all;
  14625. }
  14626. // trying to take cyclic references into the account
  14627. var processed = Object.create(null);
  14628. while (queue.length > 0) {
  14629. var item = queue.shift();
  14630. var itemObj = item.obj;
  14631. var objId = itemObj.objId;
  14632. if (objId && objId in processed) {
  14633. item.target[item.key] = processed[objId];
  14634. continue;
  14635. }
  14636. var dereferenced = Object.create(null);
  14637. for (key in itemObj.map) {
  14638. obj = itemObj.get(key);
  14639. if (obj instanceof Dict) {
  14640. if (isRecursionAllowedFor(obj)) {
  14641. queue.push({target: dereferenced, key: key, obj: obj});
  14642. } else {
  14643. dereferenced[key] = itemObj.getRaw(key);
  14644. }
  14645. } else {
  14646. dereferenced[key] = obj;
  14647. }
  14648. }
  14649. if (objId) {
  14650. processed[objId] = dereferenced;
  14651. }
  14652. item.target[item.key] = dereferenced;
  14653. }
  14654. return all;
  14655. },
  14656. getKeys: function Dict_getKeys() {
  14657. return Object.keys(this.map);
  14658. },
  14659. set: function Dict_set(key, value) {
  14660. this.map[key] = value;
  14661. },
  14662. has: function Dict_has(key) {
  14663. return key in this.map;
  14664. },
  14665. forEach: function Dict_forEach(callback) {
  14666. for (var key in this.map) {
  14667. callback(key, this.get(key));
  14668. }
  14669. }
  14670. };
  14671. Dict.empty = new Dict(null);
  14672. Dict.merge = function Dict_merge(xref, dictArray) {
  14673. var mergedDict = new Dict(xref);
  14674. for (var i = 0, ii = dictArray.length; i < ii; i++) {
  14675. var dict = dictArray[i];
  14676. if (!isDict(dict)) {
  14677. continue;
  14678. }
  14679. for (var keyName in dict.map) {
  14680. if (mergedDict.map[keyName]) {
  14681. continue;
  14682. }
  14683. mergedDict.map[keyName] = dict.map[keyName];
  14684. }
  14685. }
  14686. return mergedDict;
  14687. };
  14688. return Dict;
  14689. })();
  14690. var Ref = (function RefClosure() {
  14691. function Ref(num, gen) {
  14692. this.num = num;
  14693. this.gen = gen;
  14694. }
  14695. Ref.prototype = {
  14696. toString: function Ref_toString() {
  14697. // This function is hot, so we make the string as compact as possible.
  14698. // |this.gen| is almost always zero, so we treat that case specially.
  14699. var str = this.num + 'R';
  14700. if (this.gen !== 0) {
  14701. str += this.gen;
  14702. }
  14703. return str;
  14704. }
  14705. };
  14706. return Ref;
  14707. })();
  14708. // The reference is identified by number and generation.
  14709. // This structure stores only one instance of the reference.
  14710. var RefSet = (function RefSetClosure() {
  14711. function RefSet() {
  14712. this.dict = {};
  14713. }
  14714. RefSet.prototype = {
  14715. has: function RefSet_has(ref) {
  14716. return ref.toString() in this.dict;
  14717. },
  14718. put: function RefSet_put(ref) {
  14719. this.dict[ref.toString()] = true;
  14720. },
  14721. remove: function RefSet_remove(ref) {
  14722. delete this.dict[ref.toString()];
  14723. }
  14724. };
  14725. return RefSet;
  14726. })();
  14727. var RefSetCache = (function RefSetCacheClosure() {
  14728. function RefSetCache() {
  14729. this.dict = Object.create(null);
  14730. }
  14731. RefSetCache.prototype = {
  14732. get: function RefSetCache_get(ref) {
  14733. return this.dict[ref.toString()];
  14734. },
  14735. has: function RefSetCache_has(ref) {
  14736. return ref.toString() in this.dict;
  14737. },
  14738. put: function RefSetCache_put(ref, obj) {
  14739. this.dict[ref.toString()] = obj;
  14740. },
  14741. putAlias: function RefSetCache_putAlias(ref, aliasRef) {
  14742. this.dict[ref.toString()] = this.get(aliasRef);
  14743. },
  14744. forEach: function RefSetCache_forEach(fn, thisArg) {
  14745. for (var i in this.dict) {
  14746. fn.call(thisArg, this.dict[i]);
  14747. }
  14748. },
  14749. clear: function RefSetCache_clear() {
  14750. this.dict = Object.create(null);
  14751. }
  14752. };
  14753. return RefSetCache;
  14754. })();
  14755. function isName(v) {
  14756. return v instanceof Name;
  14757. }
  14758. function isCmd(v, cmd) {
  14759. return v instanceof Cmd && (cmd === undefined || v.cmd === cmd);
  14760. }
  14761. function isDict(v, type) {
  14762. if (!(v instanceof Dict)) {
  14763. return false;
  14764. }
  14765. if (!type) {
  14766. return true;
  14767. }
  14768. var dictType = v.get('Type');
  14769. return isName(dictType) && dictType.name === type;
  14770. }
  14771. function isRef(v) {
  14772. return v instanceof Ref;
  14773. }
  14774. function isStream(v) {
  14775. return typeof v === 'object' && v !== null && v.getBytes !== undefined;
  14776. }
  14777. exports.Cmd = Cmd;
  14778. exports.Dict = Dict;
  14779. exports.Name = Name;
  14780. exports.Ref = Ref;
  14781. exports.RefSet = RefSet;
  14782. exports.RefSetCache = RefSetCache;
  14783. exports.isCmd = isCmd;
  14784. exports.isDict = isDict;
  14785. exports.isName = isName;
  14786. exports.isRef = isRef;
  14787. exports.isStream = isStream;
  14788. }));
  14789. (function (root, factory) {
  14790. if (typeof define === 'function' && define.amd) {
  14791. define('pdfjs/core/stream', ['exports', 'pdfjs/shared/util',
  14792. 'pdfjs/core/primitives', 'pdfjs/core/jbig2', 'pdfjs/core/jpg',
  14793. 'pdfjs/core/jpx'], factory);
  14794. } else if (typeof exports !== 'undefined') {
  14795. factory(exports, require('../shared/util.js'), require('./primitives.js'),
  14796. require('./jbig2.js'), require('./jpg.js'), require('./jpx.js'));
  14797. } else {
  14798. factory((root.pdfjsCoreStream = {}), root.pdfjsSharedUtil,
  14799. root.pdfjsCorePrimitives, root.pdfjsCoreJbig2, root.pdfjsCoreJpg,
  14800. root.pdfjsCoreJpx);
  14801. }
  14802. }(this, function (exports, sharedUtil, corePrimitives, coreJbig2, coreJpg,
  14803. coreJpx) {
  14804. var Util = sharedUtil.Util;
  14805. var error = sharedUtil.error;
  14806. var info = sharedUtil.info;
  14807. var isArray = sharedUtil.isArray;
  14808. var shadow = sharedUtil.shadow;
  14809. var warn = sharedUtil.warn;
  14810. var Dict = corePrimitives.Dict;
  14811. var Jbig2Image = coreJbig2.Jbig2Image;
  14812. var JpegImage = coreJpg.JpegImage;
  14813. var JpxImage = coreJpx.JpxImage;
  14814. var coreParser; // see _setCoreParser below
  14815. var EOF; // = coreParser.EOF;
  14816. var Lexer; // = coreParser.Lexer;
  14817. var coreColorSpace; // see _setCoreColorSpace below
  14818. var ColorSpace; // = coreColorSpace.ColorSpace;
  14819. var Stream = (function StreamClosure() {
  14820. function Stream(arrayBuffer, start, length, dict) {
  14821. this.bytes = (arrayBuffer instanceof Uint8Array ?
  14822. arrayBuffer : new Uint8Array(arrayBuffer));
  14823. this.start = start || 0;
  14824. this.pos = this.start;
  14825. this.end = (start + length) || this.bytes.length;
  14826. this.dict = dict;
  14827. }
  14828. // required methods for a stream. if a particular stream does not
  14829. // implement these, an error should be thrown
  14830. Stream.prototype = {
  14831. get length() {
  14832. return this.end - this.start;
  14833. },
  14834. get isEmpty() {
  14835. return this.length === 0;
  14836. },
  14837. getByte: function Stream_getByte() {
  14838. if (this.pos >= this.end) {
  14839. return -1;
  14840. }
  14841. return this.bytes[this.pos++];
  14842. },
  14843. getUint16: function Stream_getUint16() {
  14844. var b0 = this.getByte();
  14845. var b1 = this.getByte();
  14846. if (b0 === -1 || b1 === -1) {
  14847. return -1;
  14848. }
  14849. return (b0 << 8) + b1;
  14850. },
  14851. getInt32: function Stream_getInt32() {
  14852. var b0 = this.getByte();
  14853. var b1 = this.getByte();
  14854. var b2 = this.getByte();
  14855. var b3 = this.getByte();
  14856. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  14857. },
  14858. // returns subarray of original buffer
  14859. // should only be read
  14860. getBytes: function Stream_getBytes(length) {
  14861. var bytes = this.bytes;
  14862. var pos = this.pos;
  14863. var strEnd = this.end;
  14864. if (!length) {
  14865. return bytes.subarray(pos, strEnd);
  14866. }
  14867. var end = pos + length;
  14868. if (end > strEnd) {
  14869. end = strEnd;
  14870. }
  14871. this.pos = end;
  14872. return bytes.subarray(pos, end);
  14873. },
  14874. peekByte: function Stream_peekByte() {
  14875. var peekedByte = this.getByte();
  14876. this.pos--;
  14877. return peekedByte;
  14878. },
  14879. peekBytes: function Stream_peekBytes(length) {
  14880. var bytes = this.getBytes(length);
  14881. this.pos -= bytes.length;
  14882. return bytes;
  14883. },
  14884. skip: function Stream_skip(n) {
  14885. if (!n) {
  14886. n = 1;
  14887. }
  14888. this.pos += n;
  14889. },
  14890. reset: function Stream_reset() {
  14891. this.pos = this.start;
  14892. },
  14893. moveStart: function Stream_moveStart() {
  14894. this.start = this.pos;
  14895. },
  14896. makeSubStream: function Stream_makeSubStream(start, length, dict) {
  14897. return new Stream(this.bytes.buffer, start, length, dict);
  14898. },
  14899. isStream: true
  14900. };
  14901. return Stream;
  14902. })();
  14903. var StringStream = (function StringStreamClosure() {
  14904. function StringStream(str) {
  14905. var length = str.length;
  14906. var bytes = new Uint8Array(length);
  14907. for (var n = 0; n < length; ++n) {
  14908. bytes[n] = str.charCodeAt(n);
  14909. }
  14910. Stream.call(this, bytes);
  14911. }
  14912. StringStream.prototype = Stream.prototype;
  14913. return StringStream;
  14914. })();
  14915. // super class for the decoding streams
  14916. var DecodeStream = (function DecodeStreamClosure() {
  14917. // Lots of DecodeStreams are created whose buffers are never used. For these
  14918. // we share a single empty buffer. This is (a) space-efficient and (b) avoids
  14919. // having special cases that would be required if we used |null| for an empty
  14920. // buffer.
  14921. var emptyBuffer = new Uint8Array(0);
  14922. function DecodeStream(maybeMinBufferLength) {
  14923. this.pos = 0;
  14924. this.bufferLength = 0;
  14925. this.eof = false;
  14926. this.buffer = emptyBuffer;
  14927. this.minBufferLength = 512;
  14928. if (maybeMinBufferLength) {
  14929. // Compute the first power of two that is as big as maybeMinBufferLength.
  14930. while (this.minBufferLength < maybeMinBufferLength) {
  14931. this.minBufferLength *= 2;
  14932. }
  14933. }
  14934. }
  14935. DecodeStream.prototype = {
  14936. get isEmpty() {
  14937. while (!this.eof && this.bufferLength === 0) {
  14938. this.readBlock();
  14939. }
  14940. return this.bufferLength === 0;
  14941. },
  14942. ensureBuffer: function DecodeStream_ensureBuffer(requested) {
  14943. var buffer = this.buffer;
  14944. if (requested <= buffer.byteLength) {
  14945. return buffer;
  14946. }
  14947. var size = this.minBufferLength;
  14948. while (size < requested) {
  14949. size *= 2;
  14950. }
  14951. var buffer2 = new Uint8Array(size);
  14952. buffer2.set(buffer);
  14953. return (this.buffer = buffer2);
  14954. },
  14955. getByte: function DecodeStream_getByte() {
  14956. var pos = this.pos;
  14957. while (this.bufferLength <= pos) {
  14958. if (this.eof) {
  14959. return -1;
  14960. }
  14961. this.readBlock();
  14962. }
  14963. return this.buffer[this.pos++];
  14964. },
  14965. getUint16: function DecodeStream_getUint16() {
  14966. var b0 = this.getByte();
  14967. var b1 = this.getByte();
  14968. if (b0 === -1 || b1 === -1) {
  14969. return -1;
  14970. }
  14971. return (b0 << 8) + b1;
  14972. },
  14973. getInt32: function DecodeStream_getInt32() {
  14974. var b0 = this.getByte();
  14975. var b1 = this.getByte();
  14976. var b2 = this.getByte();
  14977. var b3 = this.getByte();
  14978. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  14979. },
  14980. getBytes: function DecodeStream_getBytes(length) {
  14981. var end, pos = this.pos;
  14982. if (length) {
  14983. this.ensureBuffer(pos + length);
  14984. end = pos + length;
  14985. while (!this.eof && this.bufferLength < end) {
  14986. this.readBlock();
  14987. }
  14988. var bufEnd = this.bufferLength;
  14989. if (end > bufEnd) {
  14990. end = bufEnd;
  14991. }
  14992. } else {
  14993. while (!this.eof) {
  14994. this.readBlock();
  14995. }
  14996. end = this.bufferLength;
  14997. }
  14998. this.pos = end;
  14999. return this.buffer.subarray(pos, end);
  15000. },
  15001. peekByte: function DecodeStream_peekByte() {
  15002. var peekedByte = this.getByte();
  15003. this.pos--;
  15004. return peekedByte;
  15005. },
  15006. peekBytes: function DecodeStream_peekBytes(length) {
  15007. var bytes = this.getBytes(length);
  15008. this.pos -= bytes.length;
  15009. return bytes;
  15010. },
  15011. makeSubStream: function DecodeStream_makeSubStream(start, length, dict) {
  15012. var end = start + length;
  15013. while (this.bufferLength <= end && !this.eof) {
  15014. this.readBlock();
  15015. }
  15016. return new Stream(this.buffer, start, length, dict);
  15017. },
  15018. skip: function DecodeStream_skip(n) {
  15019. if (!n) {
  15020. n = 1;
  15021. }
  15022. this.pos += n;
  15023. },
  15024. reset: function DecodeStream_reset() {
  15025. this.pos = 0;
  15026. },
  15027. getBaseStreams: function DecodeStream_getBaseStreams() {
  15028. if (this.str && this.str.getBaseStreams) {
  15029. return this.str.getBaseStreams();
  15030. }
  15031. return [];
  15032. }
  15033. };
  15034. return DecodeStream;
  15035. })();
  15036. var StreamsSequenceStream = (function StreamsSequenceStreamClosure() {
  15037. function StreamsSequenceStream(streams) {
  15038. this.streams = streams;
  15039. DecodeStream.call(this, /* maybeLength = */ null);
  15040. }
  15041. StreamsSequenceStream.prototype = Object.create(DecodeStream.prototype);
  15042. StreamsSequenceStream.prototype.readBlock =
  15043. function streamSequenceStreamReadBlock() {
  15044. var streams = this.streams;
  15045. if (streams.length === 0) {
  15046. this.eof = true;
  15047. return;
  15048. }
  15049. var stream = streams.shift();
  15050. var chunk = stream.getBytes();
  15051. var bufferLength = this.bufferLength;
  15052. var newLength = bufferLength + chunk.length;
  15053. var buffer = this.ensureBuffer(newLength);
  15054. buffer.set(chunk, bufferLength);
  15055. this.bufferLength = newLength;
  15056. };
  15057. StreamsSequenceStream.prototype.getBaseStreams =
  15058. function StreamsSequenceStream_getBaseStreams() {
  15059. var baseStreams = [];
  15060. for (var i = 0, ii = this.streams.length; i < ii; i++) {
  15061. var stream = this.streams[i];
  15062. if (stream.getBaseStreams) {
  15063. Util.appendToArray(baseStreams, stream.getBaseStreams());
  15064. }
  15065. }
  15066. return baseStreams;
  15067. };
  15068. return StreamsSequenceStream;
  15069. })();
  15070. var FlateStream = (function FlateStreamClosure() {
  15071. var codeLenCodeMap = new Int32Array([
  15072. 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
  15073. ]);
  15074. var lengthDecode = new Int32Array([
  15075. 0x00003, 0x00004, 0x00005, 0x00006, 0x00007, 0x00008, 0x00009, 0x0000a,
  15076. 0x1000b, 0x1000d, 0x1000f, 0x10011, 0x20013, 0x20017, 0x2001b, 0x2001f,
  15077. 0x30023, 0x3002b, 0x30033, 0x3003b, 0x40043, 0x40053, 0x40063, 0x40073,
  15078. 0x50083, 0x500a3, 0x500c3, 0x500e3, 0x00102, 0x00102, 0x00102
  15079. ]);
  15080. var distDecode = new Int32Array([
  15081. 0x00001, 0x00002, 0x00003, 0x00004, 0x10005, 0x10007, 0x20009, 0x2000d,
  15082. 0x30011, 0x30019, 0x40021, 0x40031, 0x50041, 0x50061, 0x60081, 0x600c1,
  15083. 0x70101, 0x70181, 0x80201, 0x80301, 0x90401, 0x90601, 0xa0801, 0xa0c01,
  15084. 0xb1001, 0xb1801, 0xc2001, 0xc3001, 0xd4001, 0xd6001
  15085. ]);
  15086. var fixedLitCodeTab = [new Int32Array([
  15087. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c0,
  15088. 0x70108, 0x80060, 0x80020, 0x900a0, 0x80000, 0x80080, 0x80040, 0x900e0,
  15089. 0x70104, 0x80058, 0x80018, 0x90090, 0x70114, 0x80078, 0x80038, 0x900d0,
  15090. 0x7010c, 0x80068, 0x80028, 0x900b0, 0x80008, 0x80088, 0x80048, 0x900f0,
  15091. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c8,
  15092. 0x7010a, 0x80064, 0x80024, 0x900a8, 0x80004, 0x80084, 0x80044, 0x900e8,
  15093. 0x70106, 0x8005c, 0x8001c, 0x90098, 0x70116, 0x8007c, 0x8003c, 0x900d8,
  15094. 0x7010e, 0x8006c, 0x8002c, 0x900b8, 0x8000c, 0x8008c, 0x8004c, 0x900f8,
  15095. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c4,
  15096. 0x70109, 0x80062, 0x80022, 0x900a4, 0x80002, 0x80082, 0x80042, 0x900e4,
  15097. 0x70105, 0x8005a, 0x8001a, 0x90094, 0x70115, 0x8007a, 0x8003a, 0x900d4,
  15098. 0x7010d, 0x8006a, 0x8002a, 0x900b4, 0x8000a, 0x8008a, 0x8004a, 0x900f4,
  15099. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cc,
  15100. 0x7010b, 0x80066, 0x80026, 0x900ac, 0x80006, 0x80086, 0x80046, 0x900ec,
  15101. 0x70107, 0x8005e, 0x8001e, 0x9009c, 0x70117, 0x8007e, 0x8003e, 0x900dc,
  15102. 0x7010f, 0x8006e, 0x8002e, 0x900bc, 0x8000e, 0x8008e, 0x8004e, 0x900fc,
  15103. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c2,
  15104. 0x70108, 0x80061, 0x80021, 0x900a2, 0x80001, 0x80081, 0x80041, 0x900e2,
  15105. 0x70104, 0x80059, 0x80019, 0x90092, 0x70114, 0x80079, 0x80039, 0x900d2,
  15106. 0x7010c, 0x80069, 0x80029, 0x900b2, 0x80009, 0x80089, 0x80049, 0x900f2,
  15107. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900ca,
  15108. 0x7010a, 0x80065, 0x80025, 0x900aa, 0x80005, 0x80085, 0x80045, 0x900ea,
  15109. 0x70106, 0x8005d, 0x8001d, 0x9009a, 0x70116, 0x8007d, 0x8003d, 0x900da,
  15110. 0x7010e, 0x8006d, 0x8002d, 0x900ba, 0x8000d, 0x8008d, 0x8004d, 0x900fa,
  15111. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c6,
  15112. 0x70109, 0x80063, 0x80023, 0x900a6, 0x80003, 0x80083, 0x80043, 0x900e6,
  15113. 0x70105, 0x8005b, 0x8001b, 0x90096, 0x70115, 0x8007b, 0x8003b, 0x900d6,
  15114. 0x7010d, 0x8006b, 0x8002b, 0x900b6, 0x8000b, 0x8008b, 0x8004b, 0x900f6,
  15115. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900ce,
  15116. 0x7010b, 0x80067, 0x80027, 0x900ae, 0x80007, 0x80087, 0x80047, 0x900ee,
  15117. 0x70107, 0x8005f, 0x8001f, 0x9009e, 0x70117, 0x8007f, 0x8003f, 0x900de,
  15118. 0x7010f, 0x8006f, 0x8002f, 0x900be, 0x8000f, 0x8008f, 0x8004f, 0x900fe,
  15119. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c1,
  15120. 0x70108, 0x80060, 0x80020, 0x900a1, 0x80000, 0x80080, 0x80040, 0x900e1,
  15121. 0x70104, 0x80058, 0x80018, 0x90091, 0x70114, 0x80078, 0x80038, 0x900d1,
  15122. 0x7010c, 0x80068, 0x80028, 0x900b1, 0x80008, 0x80088, 0x80048, 0x900f1,
  15123. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c9,
  15124. 0x7010a, 0x80064, 0x80024, 0x900a9, 0x80004, 0x80084, 0x80044, 0x900e9,
  15125. 0x70106, 0x8005c, 0x8001c, 0x90099, 0x70116, 0x8007c, 0x8003c, 0x900d9,
  15126. 0x7010e, 0x8006c, 0x8002c, 0x900b9, 0x8000c, 0x8008c, 0x8004c, 0x900f9,
  15127. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c5,
  15128. 0x70109, 0x80062, 0x80022, 0x900a5, 0x80002, 0x80082, 0x80042, 0x900e5,
  15129. 0x70105, 0x8005a, 0x8001a, 0x90095, 0x70115, 0x8007a, 0x8003a, 0x900d5,
  15130. 0x7010d, 0x8006a, 0x8002a, 0x900b5, 0x8000a, 0x8008a, 0x8004a, 0x900f5,
  15131. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cd,
  15132. 0x7010b, 0x80066, 0x80026, 0x900ad, 0x80006, 0x80086, 0x80046, 0x900ed,
  15133. 0x70107, 0x8005e, 0x8001e, 0x9009d, 0x70117, 0x8007e, 0x8003e, 0x900dd,
  15134. 0x7010f, 0x8006e, 0x8002e, 0x900bd, 0x8000e, 0x8008e, 0x8004e, 0x900fd,
  15135. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c3,
  15136. 0x70108, 0x80061, 0x80021, 0x900a3, 0x80001, 0x80081, 0x80041, 0x900e3,
  15137. 0x70104, 0x80059, 0x80019, 0x90093, 0x70114, 0x80079, 0x80039, 0x900d3,
  15138. 0x7010c, 0x80069, 0x80029, 0x900b3, 0x80009, 0x80089, 0x80049, 0x900f3,
  15139. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900cb,
  15140. 0x7010a, 0x80065, 0x80025, 0x900ab, 0x80005, 0x80085, 0x80045, 0x900eb,
  15141. 0x70106, 0x8005d, 0x8001d, 0x9009b, 0x70116, 0x8007d, 0x8003d, 0x900db,
  15142. 0x7010e, 0x8006d, 0x8002d, 0x900bb, 0x8000d, 0x8008d, 0x8004d, 0x900fb,
  15143. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c7,
  15144. 0x70109, 0x80063, 0x80023, 0x900a7, 0x80003, 0x80083, 0x80043, 0x900e7,
  15145. 0x70105, 0x8005b, 0x8001b, 0x90097, 0x70115, 0x8007b, 0x8003b, 0x900d7,
  15146. 0x7010d, 0x8006b, 0x8002b, 0x900b7, 0x8000b, 0x8008b, 0x8004b, 0x900f7,
  15147. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900cf,
  15148. 0x7010b, 0x80067, 0x80027, 0x900af, 0x80007, 0x80087, 0x80047, 0x900ef,
  15149. 0x70107, 0x8005f, 0x8001f, 0x9009f, 0x70117, 0x8007f, 0x8003f, 0x900df,
  15150. 0x7010f, 0x8006f, 0x8002f, 0x900bf, 0x8000f, 0x8008f, 0x8004f, 0x900ff
  15151. ]), 9];
  15152. var fixedDistCodeTab = [new Int32Array([
  15153. 0x50000, 0x50010, 0x50008, 0x50018, 0x50004, 0x50014, 0x5000c, 0x5001c,
  15154. 0x50002, 0x50012, 0x5000a, 0x5001a, 0x50006, 0x50016, 0x5000e, 0x00000,
  15155. 0x50001, 0x50011, 0x50009, 0x50019, 0x50005, 0x50015, 0x5000d, 0x5001d,
  15156. 0x50003, 0x50013, 0x5000b, 0x5001b, 0x50007, 0x50017, 0x5000f, 0x00000
  15157. ]), 5];
  15158. function FlateStream(str, maybeLength) {
  15159. this.str = str;
  15160. this.dict = str.dict;
  15161. var cmf = str.getByte();
  15162. var flg = str.getByte();
  15163. if (cmf === -1 || flg === -1) {
  15164. error('Invalid header in flate stream: ' + cmf + ', ' + flg);
  15165. }
  15166. if ((cmf & 0x0f) !== 0x08) {
  15167. error('Unknown compression method in flate stream: ' + cmf + ', ' + flg);
  15168. }
  15169. if ((((cmf << 8) + flg) % 31) !== 0) {
  15170. error('Bad FCHECK in flate stream: ' + cmf + ', ' + flg);
  15171. }
  15172. if (flg & 0x20) {
  15173. error('FDICT bit set in flate stream: ' + cmf + ', ' + flg);
  15174. }
  15175. this.codeSize = 0;
  15176. this.codeBuf = 0;
  15177. DecodeStream.call(this, maybeLength);
  15178. }
  15179. FlateStream.prototype = Object.create(DecodeStream.prototype);
  15180. FlateStream.prototype.getBits = function FlateStream_getBits(bits) {
  15181. var str = this.str;
  15182. var codeSize = this.codeSize;
  15183. var codeBuf = this.codeBuf;
  15184. var b;
  15185. while (codeSize < bits) {
  15186. if ((b = str.getByte()) === -1) {
  15187. error('Bad encoding in flate stream');
  15188. }
  15189. codeBuf |= b << codeSize;
  15190. codeSize += 8;
  15191. }
  15192. b = codeBuf & ((1 << bits) - 1);
  15193. this.codeBuf = codeBuf >> bits;
  15194. this.codeSize = codeSize -= bits;
  15195. return b;
  15196. };
  15197. FlateStream.prototype.getCode = function FlateStream_getCode(table) {
  15198. var str = this.str;
  15199. var codes = table[0];
  15200. var maxLen = table[1];
  15201. var codeSize = this.codeSize;
  15202. var codeBuf = this.codeBuf;
  15203. var b;
  15204. while (codeSize < maxLen) {
  15205. if ((b = str.getByte()) === -1) {
  15206. // premature end of stream. code might however still be valid.
  15207. // codeSize < codeLen check below guards against incomplete codeVal.
  15208. break;
  15209. }
  15210. codeBuf |= (b << codeSize);
  15211. codeSize += 8;
  15212. }
  15213. var code = codes[codeBuf & ((1 << maxLen) - 1)];
  15214. var codeLen = code >> 16;
  15215. var codeVal = code & 0xffff;
  15216. if (codeLen < 1 || codeSize < codeLen) {
  15217. error('Bad encoding in flate stream');
  15218. }
  15219. this.codeBuf = (codeBuf >> codeLen);
  15220. this.codeSize = (codeSize - codeLen);
  15221. return codeVal;
  15222. };
  15223. FlateStream.prototype.generateHuffmanTable =
  15224. function flateStreamGenerateHuffmanTable(lengths) {
  15225. var n = lengths.length;
  15226. // find max code length
  15227. var maxLen = 0;
  15228. var i;
  15229. for (i = 0; i < n; ++i) {
  15230. if (lengths[i] > maxLen) {
  15231. maxLen = lengths[i];
  15232. }
  15233. }
  15234. // build the table
  15235. var size = 1 << maxLen;
  15236. var codes = new Int32Array(size);
  15237. for (var len = 1, code = 0, skip = 2;
  15238. len <= maxLen;
  15239. ++len, code <<= 1, skip <<= 1) {
  15240. for (var val = 0; val < n; ++val) {
  15241. if (lengths[val] === len) {
  15242. // bit-reverse the code
  15243. var code2 = 0;
  15244. var t = code;
  15245. for (i = 0; i < len; ++i) {
  15246. code2 = (code2 << 1) | (t & 1);
  15247. t >>= 1;
  15248. }
  15249. // fill the table entries
  15250. for (i = code2; i < size; i += skip) {
  15251. codes[i] = (len << 16) | val;
  15252. }
  15253. ++code;
  15254. }
  15255. }
  15256. }
  15257. return [codes, maxLen];
  15258. };
  15259. FlateStream.prototype.readBlock = function FlateStream_readBlock() {
  15260. var buffer, len;
  15261. var str = this.str;
  15262. // read block header
  15263. var hdr = this.getBits(3);
  15264. if (hdr & 1) {
  15265. this.eof = true;
  15266. }
  15267. hdr >>= 1;
  15268. if (hdr === 0) { // uncompressed block
  15269. var b;
  15270. if ((b = str.getByte()) === -1) {
  15271. error('Bad block header in flate stream');
  15272. }
  15273. var blockLen = b;
  15274. if ((b = str.getByte()) === -1) {
  15275. error('Bad block header in flate stream');
  15276. }
  15277. blockLen |= (b << 8);
  15278. if ((b = str.getByte()) === -1) {
  15279. error('Bad block header in flate stream');
  15280. }
  15281. var check = b;
  15282. if ((b = str.getByte()) === -1) {
  15283. error('Bad block header in flate stream');
  15284. }
  15285. check |= (b << 8);
  15286. if (check !== (~blockLen & 0xffff) &&
  15287. (blockLen !== 0 || check !== 0)) {
  15288. // Ignoring error for bad "empty" block (see issue 1277)
  15289. error('Bad uncompressed block length in flate stream');
  15290. }
  15291. this.codeBuf = 0;
  15292. this.codeSize = 0;
  15293. var bufferLength = this.bufferLength;
  15294. buffer = this.ensureBuffer(bufferLength + blockLen);
  15295. var end = bufferLength + blockLen;
  15296. this.bufferLength = end;
  15297. if (blockLen === 0) {
  15298. if (str.peekByte() === -1) {
  15299. this.eof = true;
  15300. }
  15301. } else {
  15302. for (var n = bufferLength; n < end; ++n) {
  15303. if ((b = str.getByte()) === -1) {
  15304. this.eof = true;
  15305. break;
  15306. }
  15307. buffer[n] = b;
  15308. }
  15309. }
  15310. return;
  15311. }
  15312. var litCodeTable;
  15313. var distCodeTable;
  15314. if (hdr === 1) { // compressed block, fixed codes
  15315. litCodeTable = fixedLitCodeTab;
  15316. distCodeTable = fixedDistCodeTab;
  15317. } else if (hdr === 2) { // compressed block, dynamic codes
  15318. var numLitCodes = this.getBits(5) + 257;
  15319. var numDistCodes = this.getBits(5) + 1;
  15320. var numCodeLenCodes = this.getBits(4) + 4;
  15321. // build the code lengths code table
  15322. var codeLenCodeLengths = new Uint8Array(codeLenCodeMap.length);
  15323. var i;
  15324. for (i = 0; i < numCodeLenCodes; ++i) {
  15325. codeLenCodeLengths[codeLenCodeMap[i]] = this.getBits(3);
  15326. }
  15327. var codeLenCodeTab = this.generateHuffmanTable(codeLenCodeLengths);
  15328. // build the literal and distance code tables
  15329. len = 0;
  15330. i = 0;
  15331. var codes = numLitCodes + numDistCodes;
  15332. var codeLengths = new Uint8Array(codes);
  15333. var bitsLength, bitsOffset, what;
  15334. while (i < codes) {
  15335. var code = this.getCode(codeLenCodeTab);
  15336. if (code === 16) {
  15337. bitsLength = 2; bitsOffset = 3; what = len;
  15338. } else if (code === 17) {
  15339. bitsLength = 3; bitsOffset = 3; what = (len = 0);
  15340. } else if (code === 18) {
  15341. bitsLength = 7; bitsOffset = 11; what = (len = 0);
  15342. } else {
  15343. codeLengths[i++] = len = code;
  15344. continue;
  15345. }
  15346. var repeatLength = this.getBits(bitsLength) + bitsOffset;
  15347. while (repeatLength-- > 0) {
  15348. codeLengths[i++] = what;
  15349. }
  15350. }
  15351. litCodeTable =
  15352. this.generateHuffmanTable(codeLengths.subarray(0, numLitCodes));
  15353. distCodeTable =
  15354. this.generateHuffmanTable(codeLengths.subarray(numLitCodes, codes));
  15355. } else {
  15356. error('Unknown block type in flate stream');
  15357. }
  15358. buffer = this.buffer;
  15359. var limit = buffer ? buffer.length : 0;
  15360. var pos = this.bufferLength;
  15361. while (true) {
  15362. var code1 = this.getCode(litCodeTable);
  15363. if (code1 < 256) {
  15364. if (pos + 1 >= limit) {
  15365. buffer = this.ensureBuffer(pos + 1);
  15366. limit = buffer.length;
  15367. }
  15368. buffer[pos++] = code1;
  15369. continue;
  15370. }
  15371. if (code1 === 256) {
  15372. this.bufferLength = pos;
  15373. return;
  15374. }
  15375. code1 -= 257;
  15376. code1 = lengthDecode[code1];
  15377. var code2 = code1 >> 16;
  15378. if (code2 > 0) {
  15379. code2 = this.getBits(code2);
  15380. }
  15381. len = (code1 & 0xffff) + code2;
  15382. code1 = this.getCode(distCodeTable);
  15383. code1 = distDecode[code1];
  15384. code2 = code1 >> 16;
  15385. if (code2 > 0) {
  15386. code2 = this.getBits(code2);
  15387. }
  15388. var dist = (code1 & 0xffff) + code2;
  15389. if (pos + len >= limit) {
  15390. buffer = this.ensureBuffer(pos + len);
  15391. limit = buffer.length;
  15392. }
  15393. for (var k = 0; k < len; ++k, ++pos) {
  15394. buffer[pos] = buffer[pos - dist];
  15395. }
  15396. }
  15397. };
  15398. return FlateStream;
  15399. })();
  15400. var PredictorStream = (function PredictorStreamClosure() {
  15401. function PredictorStream(str, maybeLength, params) {
  15402. var predictor = this.predictor = params.get('Predictor') || 1;
  15403. if (predictor <= 1) {
  15404. return str; // no prediction
  15405. }
  15406. if (predictor !== 2 && (predictor < 10 || predictor > 15)) {
  15407. error('Unsupported predictor: ' + predictor);
  15408. }
  15409. if (predictor === 2) {
  15410. this.readBlock = this.readBlockTiff;
  15411. } else {
  15412. this.readBlock = this.readBlockPng;
  15413. }
  15414. this.str = str;
  15415. this.dict = str.dict;
  15416. var colors = this.colors = params.get('Colors') || 1;
  15417. var bits = this.bits = params.get('BitsPerComponent') || 8;
  15418. var columns = this.columns = params.get('Columns') || 1;
  15419. this.pixBytes = (colors * bits + 7) >> 3;
  15420. this.rowBytes = (columns * colors * bits + 7) >> 3;
  15421. DecodeStream.call(this, maybeLength);
  15422. return this;
  15423. }
  15424. PredictorStream.prototype = Object.create(DecodeStream.prototype);
  15425. PredictorStream.prototype.readBlockTiff =
  15426. function predictorStreamReadBlockTiff() {
  15427. var rowBytes = this.rowBytes;
  15428. var bufferLength = this.bufferLength;
  15429. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  15430. var bits = this.bits;
  15431. var colors = this.colors;
  15432. var rawBytes = this.str.getBytes(rowBytes);
  15433. this.eof = !rawBytes.length;
  15434. if (this.eof) {
  15435. return;
  15436. }
  15437. var inbuf = 0, outbuf = 0;
  15438. var inbits = 0, outbits = 0;
  15439. var pos = bufferLength;
  15440. var i;
  15441. if (bits === 1) {
  15442. for (i = 0; i < rowBytes; ++i) {
  15443. var c = rawBytes[i];
  15444. inbuf = (inbuf << 8) | c;
  15445. // bitwise addition is exclusive or
  15446. // first shift inbuf and then add
  15447. buffer[pos++] = (c ^ (inbuf >> colors)) & 0xFF;
  15448. // truncate inbuf (assumes colors < 16)
  15449. inbuf &= 0xFFFF;
  15450. }
  15451. } else if (bits === 8) {
  15452. for (i = 0; i < colors; ++i) {
  15453. buffer[pos++] = rawBytes[i];
  15454. }
  15455. for (; i < rowBytes; ++i) {
  15456. buffer[pos] = buffer[pos - colors] + rawBytes[i];
  15457. pos++;
  15458. }
  15459. } else {
  15460. var compArray = new Uint8Array(colors + 1);
  15461. var bitMask = (1 << bits) - 1;
  15462. var j = 0, k = bufferLength;
  15463. var columns = this.columns;
  15464. for (i = 0; i < columns; ++i) {
  15465. for (var kk = 0; kk < colors; ++kk) {
  15466. if (inbits < bits) {
  15467. inbuf = (inbuf << 8) | (rawBytes[j++] & 0xFF);
  15468. inbits += 8;
  15469. }
  15470. compArray[kk] = (compArray[kk] +
  15471. (inbuf >> (inbits - bits))) & bitMask;
  15472. inbits -= bits;
  15473. outbuf = (outbuf << bits) | compArray[kk];
  15474. outbits += bits;
  15475. if (outbits >= 8) {
  15476. buffer[k++] = (outbuf >> (outbits - 8)) & 0xFF;
  15477. outbits -= 8;
  15478. }
  15479. }
  15480. }
  15481. if (outbits > 0) {
  15482. buffer[k++] = (outbuf << (8 - outbits)) +
  15483. (inbuf & ((1 << (8 - outbits)) - 1));
  15484. }
  15485. }
  15486. this.bufferLength += rowBytes;
  15487. };
  15488. PredictorStream.prototype.readBlockPng =
  15489. function predictorStreamReadBlockPng() {
  15490. var rowBytes = this.rowBytes;
  15491. var pixBytes = this.pixBytes;
  15492. var predictor = this.str.getByte();
  15493. var rawBytes = this.str.getBytes(rowBytes);
  15494. this.eof = !rawBytes.length;
  15495. if (this.eof) {
  15496. return;
  15497. }
  15498. var bufferLength = this.bufferLength;
  15499. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  15500. var prevRow = buffer.subarray(bufferLength - rowBytes, bufferLength);
  15501. if (prevRow.length === 0) {
  15502. prevRow = new Uint8Array(rowBytes);
  15503. }
  15504. var i, j = bufferLength, up, c;
  15505. switch (predictor) {
  15506. case 0:
  15507. for (i = 0; i < rowBytes; ++i) {
  15508. buffer[j++] = rawBytes[i];
  15509. }
  15510. break;
  15511. case 1:
  15512. for (i = 0; i < pixBytes; ++i) {
  15513. buffer[j++] = rawBytes[i];
  15514. }
  15515. for (; i < rowBytes; ++i) {
  15516. buffer[j] = (buffer[j - pixBytes] + rawBytes[i]) & 0xFF;
  15517. j++;
  15518. }
  15519. break;
  15520. case 2:
  15521. for (i = 0; i < rowBytes; ++i) {
  15522. buffer[j++] = (prevRow[i] + rawBytes[i]) & 0xFF;
  15523. }
  15524. break;
  15525. case 3:
  15526. for (i = 0; i < pixBytes; ++i) {
  15527. buffer[j++] = (prevRow[i] >> 1) + rawBytes[i];
  15528. }
  15529. for (; i < rowBytes; ++i) {
  15530. buffer[j] = (((prevRow[i] + buffer[j - pixBytes]) >> 1) +
  15531. rawBytes[i]) & 0xFF;
  15532. j++;
  15533. }
  15534. break;
  15535. case 4:
  15536. // we need to save the up left pixels values. the simplest way
  15537. // is to create a new buffer
  15538. for (i = 0; i < pixBytes; ++i) {
  15539. up = prevRow[i];
  15540. c = rawBytes[i];
  15541. buffer[j++] = up + c;
  15542. }
  15543. for (; i < rowBytes; ++i) {
  15544. up = prevRow[i];
  15545. var upLeft = prevRow[i - pixBytes];
  15546. var left = buffer[j - pixBytes];
  15547. var p = left + up - upLeft;
  15548. var pa = p - left;
  15549. if (pa < 0) {
  15550. pa = -pa;
  15551. }
  15552. var pb = p - up;
  15553. if (pb < 0) {
  15554. pb = -pb;
  15555. }
  15556. var pc = p - upLeft;
  15557. if (pc < 0) {
  15558. pc = -pc;
  15559. }
  15560. c = rawBytes[i];
  15561. if (pa <= pb && pa <= pc) {
  15562. buffer[j++] = left + c;
  15563. } else if (pb <= pc) {
  15564. buffer[j++] = up + c;
  15565. } else {
  15566. buffer[j++] = upLeft + c;
  15567. }
  15568. }
  15569. break;
  15570. default:
  15571. error('Unsupported predictor: ' + predictor);
  15572. }
  15573. this.bufferLength += rowBytes;
  15574. };
  15575. return PredictorStream;
  15576. })();
  15577. /**
  15578. * Depending on the type of JPEG a JpegStream is handled in different ways. For
  15579. * JPEG's that are supported natively such as DeviceGray and DeviceRGB the image
  15580. * data is stored and then loaded by the browser. For unsupported JPEG's we use
  15581. * a library to decode these images and the stream behaves like all the other
  15582. * DecodeStreams.
  15583. */
  15584. var JpegStream = (function JpegStreamClosure() {
  15585. function JpegStream(stream, maybeLength, dict, xref) {
  15586. // Some images may contain 'junk' before the SOI (start-of-image) marker.
  15587. // Note: this seems to mainly affect inline images.
  15588. var ch;
  15589. while ((ch = stream.getByte()) !== -1) {
  15590. if (ch === 0xFF) { // Find the first byte of the SOI marker (0xFFD8).
  15591. stream.skip(-1); // Reset the stream position to the SOI.
  15592. break;
  15593. }
  15594. }
  15595. this.stream = stream;
  15596. this.maybeLength = maybeLength;
  15597. this.dict = dict;
  15598. DecodeStream.call(this, maybeLength);
  15599. }
  15600. JpegStream.prototype = Object.create(DecodeStream.prototype);
  15601. Object.defineProperty(JpegStream.prototype, 'bytes', {
  15602. get: function JpegStream_bytes() {
  15603. // If this.maybeLength is null, we'll get the entire stream.
  15604. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  15605. },
  15606. configurable: true
  15607. });
  15608. JpegStream.prototype.ensureBuffer = function JpegStream_ensureBuffer(req) {
  15609. if (this.bufferLength) {
  15610. return;
  15611. }
  15612. try {
  15613. var jpegImage = new JpegImage();
  15614. // checking if values needs to be transformed before conversion
  15615. if (this.forceRGB && this.dict && isArray(this.dict.get('Decode'))) {
  15616. var decodeArr = this.dict.get('Decode');
  15617. var bitsPerComponent = this.dict.get('BitsPerComponent') || 8;
  15618. var decodeArrLength = decodeArr.length;
  15619. var transform = new Int32Array(decodeArrLength);
  15620. var transformNeeded = false;
  15621. var maxValue = (1 << bitsPerComponent) - 1;
  15622. for (var i = 0; i < decodeArrLength; i += 2) {
  15623. transform[i] = ((decodeArr[i + 1] - decodeArr[i]) * 256) | 0;
  15624. transform[i + 1] = (decodeArr[i] * maxValue) | 0;
  15625. if (transform[i] !== 256 || transform[i + 1] !== 0) {
  15626. transformNeeded = true;
  15627. }
  15628. }
  15629. if (transformNeeded) {
  15630. jpegImage.decodeTransform = transform;
  15631. }
  15632. }
  15633. jpegImage.parse(this.bytes);
  15634. var data = jpegImage.getData(this.drawWidth, this.drawHeight,
  15635. this.forceRGB);
  15636. this.buffer = data;
  15637. this.bufferLength = data.length;
  15638. this.eof = true;
  15639. } catch (e) {
  15640. error('JPEG error: ' + e);
  15641. }
  15642. };
  15643. JpegStream.prototype.getBytes = function JpegStream_getBytes(length) {
  15644. this.ensureBuffer();
  15645. return this.buffer;
  15646. };
  15647. JpegStream.prototype.getIR = function JpegStream_getIR() {
  15648. return PDFJS.createObjectURL(this.bytes, 'image/jpeg');
  15649. };
  15650. /**
  15651. * Checks if the image can be decoded and displayed by the browser without any
  15652. * further processing such as color space conversions.
  15653. */
  15654. JpegStream.prototype.isNativelySupported =
  15655. function JpegStream_isNativelySupported(xref, res) {
  15656. var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
  15657. return (cs.name === 'DeviceGray' || cs.name === 'DeviceRGB') &&
  15658. cs.isDefaultDecode(this.dict.get('Decode', 'D'));
  15659. };
  15660. /**
  15661. * Checks if the image can be decoded by the browser.
  15662. */
  15663. JpegStream.prototype.isNativelyDecodable =
  15664. function JpegStream_isNativelyDecodable(xref, res) {
  15665. var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
  15666. return (cs.numComps === 1 || cs.numComps === 3) &&
  15667. cs.isDefaultDecode(this.dict.get('Decode', 'D'));
  15668. };
  15669. return JpegStream;
  15670. })();
  15671. /**
  15672. * For JPEG 2000's we use a library to decode these images and
  15673. * the stream behaves like all the other DecodeStreams.
  15674. */
  15675. var JpxStream = (function JpxStreamClosure() {
  15676. function JpxStream(stream, maybeLength, dict) {
  15677. this.stream = stream;
  15678. this.maybeLength = maybeLength;
  15679. this.dict = dict;
  15680. DecodeStream.call(this, maybeLength);
  15681. }
  15682. JpxStream.prototype = Object.create(DecodeStream.prototype);
  15683. Object.defineProperty(JpxStream.prototype, 'bytes', {
  15684. get: function JpxStream_bytes() {
  15685. // If this.maybeLength is null, we'll get the entire stream.
  15686. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  15687. },
  15688. configurable: true
  15689. });
  15690. JpxStream.prototype.ensureBuffer = function JpxStream_ensureBuffer(req) {
  15691. if (this.bufferLength) {
  15692. return;
  15693. }
  15694. var jpxImage = new JpxImage();
  15695. jpxImage.parse(this.bytes);
  15696. var width = jpxImage.width;
  15697. var height = jpxImage.height;
  15698. var componentsCount = jpxImage.componentsCount;
  15699. var tileCount = jpxImage.tiles.length;
  15700. if (tileCount === 1) {
  15701. this.buffer = jpxImage.tiles[0].items;
  15702. } else {
  15703. var data = new Uint8Array(width * height * componentsCount);
  15704. for (var k = 0; k < tileCount; k++) {
  15705. var tileComponents = jpxImage.tiles[k];
  15706. var tileWidth = tileComponents.width;
  15707. var tileHeight = tileComponents.height;
  15708. var tileLeft = tileComponents.left;
  15709. var tileTop = tileComponents.top;
  15710. var src = tileComponents.items;
  15711. var srcPosition = 0;
  15712. var dataPosition = (width * tileTop + tileLeft) * componentsCount;
  15713. var imgRowSize = width * componentsCount;
  15714. var tileRowSize = tileWidth * componentsCount;
  15715. for (var j = 0; j < tileHeight; j++) {
  15716. var rowBytes = src.subarray(srcPosition, srcPosition + tileRowSize);
  15717. data.set(rowBytes, dataPosition);
  15718. srcPosition += tileRowSize;
  15719. dataPosition += imgRowSize;
  15720. }
  15721. }
  15722. this.buffer = data;
  15723. }
  15724. this.bufferLength = this.buffer.length;
  15725. this.eof = true;
  15726. };
  15727. return JpxStream;
  15728. })();
  15729. /**
  15730. * For JBIG2's we use a library to decode these images and
  15731. * the stream behaves like all the other DecodeStreams.
  15732. */
  15733. var Jbig2Stream = (function Jbig2StreamClosure() {
  15734. function Jbig2Stream(stream, maybeLength, dict) {
  15735. this.stream = stream;
  15736. this.maybeLength = maybeLength;
  15737. this.dict = dict;
  15738. DecodeStream.call(this, maybeLength);
  15739. }
  15740. Jbig2Stream.prototype = Object.create(DecodeStream.prototype);
  15741. Object.defineProperty(Jbig2Stream.prototype, 'bytes', {
  15742. get: function Jbig2Stream_bytes() {
  15743. // If this.maybeLength is null, we'll get the entire stream.
  15744. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  15745. },
  15746. configurable: true
  15747. });
  15748. Jbig2Stream.prototype.ensureBuffer = function Jbig2Stream_ensureBuffer(req) {
  15749. if (this.bufferLength) {
  15750. return;
  15751. }
  15752. var jbig2Image = new Jbig2Image();
  15753. var chunks = [], xref = this.dict.xref;
  15754. var decodeParams = xref.fetchIfRef(this.dict.get('DecodeParms'));
  15755. // According to the PDF specification, DecodeParms can be either
  15756. // a dictionary, or an array whose elements are dictionaries.
  15757. if (isArray(decodeParams)) {
  15758. if (decodeParams.length > 1) {
  15759. warn('JBIG2 - \'DecodeParms\' array with multiple elements ' +
  15760. 'not supported.');
  15761. }
  15762. decodeParams = xref.fetchIfRef(decodeParams[0]);
  15763. }
  15764. if (decodeParams && decodeParams.has('JBIG2Globals')) {
  15765. var globalsStream = decodeParams.get('JBIG2Globals');
  15766. var globals = globalsStream.getBytes();
  15767. chunks.push({data: globals, start: 0, end: globals.length});
  15768. }
  15769. chunks.push({data: this.bytes, start: 0, end: this.bytes.length});
  15770. var data = jbig2Image.parseChunks(chunks);
  15771. var dataLength = data.length;
  15772. // JBIG2 had black as 1 and white as 0, inverting the colors
  15773. for (var i = 0; i < dataLength; i++) {
  15774. data[i] ^= 0xFF;
  15775. }
  15776. this.buffer = data;
  15777. this.bufferLength = dataLength;
  15778. this.eof = true;
  15779. };
  15780. return Jbig2Stream;
  15781. })();
  15782. var DecryptStream = (function DecryptStreamClosure() {
  15783. function DecryptStream(str, maybeLength, decrypt) {
  15784. this.str = str;
  15785. this.dict = str.dict;
  15786. this.decrypt = decrypt;
  15787. this.nextChunk = null;
  15788. this.initialized = false;
  15789. DecodeStream.call(this, maybeLength);
  15790. }
  15791. var chunkSize = 512;
  15792. DecryptStream.prototype = Object.create(DecodeStream.prototype);
  15793. DecryptStream.prototype.readBlock = function DecryptStream_readBlock() {
  15794. var chunk;
  15795. if (this.initialized) {
  15796. chunk = this.nextChunk;
  15797. } else {
  15798. chunk = this.str.getBytes(chunkSize);
  15799. this.initialized = true;
  15800. }
  15801. if (!chunk || chunk.length === 0) {
  15802. this.eof = true;
  15803. return;
  15804. }
  15805. this.nextChunk = this.str.getBytes(chunkSize);
  15806. var hasMoreData = this.nextChunk && this.nextChunk.length > 0;
  15807. var decrypt = this.decrypt;
  15808. chunk = decrypt(chunk, !hasMoreData);
  15809. var bufferLength = this.bufferLength;
  15810. var i, n = chunk.length;
  15811. var buffer = this.ensureBuffer(bufferLength + n);
  15812. for (i = 0; i < n; i++) {
  15813. buffer[bufferLength++] = chunk[i];
  15814. }
  15815. this.bufferLength = bufferLength;
  15816. };
  15817. return DecryptStream;
  15818. })();
  15819. var Ascii85Stream = (function Ascii85StreamClosure() {
  15820. function Ascii85Stream(str, maybeLength) {
  15821. this.str = str;
  15822. this.dict = str.dict;
  15823. this.input = new Uint8Array(5);
  15824. // Most streams increase in size when decoded, but Ascii85 streams
  15825. // typically shrink by ~20%.
  15826. if (maybeLength) {
  15827. maybeLength = 0.8 * maybeLength;
  15828. }
  15829. DecodeStream.call(this, maybeLength);
  15830. }
  15831. Ascii85Stream.prototype = Object.create(DecodeStream.prototype);
  15832. Ascii85Stream.prototype.readBlock = function Ascii85Stream_readBlock() {
  15833. var TILDA_CHAR = 0x7E; // '~'
  15834. var Z_LOWER_CHAR = 0x7A; // 'z'
  15835. var EOF = -1;
  15836. var str = this.str;
  15837. var c = str.getByte();
  15838. while (Lexer.isSpace(c)) {
  15839. c = str.getByte();
  15840. }
  15841. if (c === EOF || c === TILDA_CHAR) {
  15842. this.eof = true;
  15843. return;
  15844. }
  15845. var bufferLength = this.bufferLength, buffer;
  15846. var i;
  15847. // special code for z
  15848. if (c === Z_LOWER_CHAR) {
  15849. buffer = this.ensureBuffer(bufferLength + 4);
  15850. for (i = 0; i < 4; ++i) {
  15851. buffer[bufferLength + i] = 0;
  15852. }
  15853. this.bufferLength += 4;
  15854. } else {
  15855. var input = this.input;
  15856. input[0] = c;
  15857. for (i = 1; i < 5; ++i) {
  15858. c = str.getByte();
  15859. while (Lexer.isSpace(c)) {
  15860. c = str.getByte();
  15861. }
  15862. input[i] = c;
  15863. if (c === EOF || c === TILDA_CHAR) {
  15864. break;
  15865. }
  15866. }
  15867. buffer = this.ensureBuffer(bufferLength + i - 1);
  15868. this.bufferLength += i - 1;
  15869. // partial ending;
  15870. if (i < 5) {
  15871. for (; i < 5; ++i) {
  15872. input[i] = 0x21 + 84;
  15873. }
  15874. this.eof = true;
  15875. }
  15876. var t = 0;
  15877. for (i = 0; i < 5; ++i) {
  15878. t = t * 85 + (input[i] - 0x21);
  15879. }
  15880. for (i = 3; i >= 0; --i) {
  15881. buffer[bufferLength + i] = t & 0xFF;
  15882. t >>= 8;
  15883. }
  15884. }
  15885. };
  15886. return Ascii85Stream;
  15887. })();
  15888. var AsciiHexStream = (function AsciiHexStreamClosure() {
  15889. function AsciiHexStream(str, maybeLength) {
  15890. this.str = str;
  15891. this.dict = str.dict;
  15892. this.firstDigit = -1;
  15893. // Most streams increase in size when decoded, but AsciiHex streams shrink
  15894. // by 50%.
  15895. if (maybeLength) {
  15896. maybeLength = 0.5 * maybeLength;
  15897. }
  15898. DecodeStream.call(this, maybeLength);
  15899. }
  15900. AsciiHexStream.prototype = Object.create(DecodeStream.prototype);
  15901. AsciiHexStream.prototype.readBlock = function AsciiHexStream_readBlock() {
  15902. var UPSTREAM_BLOCK_SIZE = 8000;
  15903. var bytes = this.str.getBytes(UPSTREAM_BLOCK_SIZE);
  15904. if (!bytes.length) {
  15905. this.eof = true;
  15906. return;
  15907. }
  15908. var maxDecodeLength = (bytes.length + 1) >> 1;
  15909. var buffer = this.ensureBuffer(this.bufferLength + maxDecodeLength);
  15910. var bufferLength = this.bufferLength;
  15911. var firstDigit = this.firstDigit;
  15912. for (var i = 0, ii = bytes.length; i < ii; i++) {
  15913. var ch = bytes[i], digit;
  15914. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  15915. digit = ch & 0x0F;
  15916. } else if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  15917. // 'A'-'Z', 'a'-'z'
  15918. digit = (ch & 0x0F) + 9;
  15919. } else if (ch === 0x3E) { // '>'
  15920. this.eof = true;
  15921. break;
  15922. } else { // probably whitespace
  15923. continue; // ignoring
  15924. }
  15925. if (firstDigit < 0) {
  15926. firstDigit = digit;
  15927. } else {
  15928. buffer[bufferLength++] = (firstDigit << 4) | digit;
  15929. firstDigit = -1;
  15930. }
  15931. }
  15932. if (firstDigit >= 0 && this.eof) {
  15933. // incomplete byte
  15934. buffer[bufferLength++] = (firstDigit << 4);
  15935. firstDigit = -1;
  15936. }
  15937. this.firstDigit = firstDigit;
  15938. this.bufferLength = bufferLength;
  15939. };
  15940. return AsciiHexStream;
  15941. })();
  15942. var RunLengthStream = (function RunLengthStreamClosure() {
  15943. function RunLengthStream(str, maybeLength) {
  15944. this.str = str;
  15945. this.dict = str.dict;
  15946. DecodeStream.call(this, maybeLength);
  15947. }
  15948. RunLengthStream.prototype = Object.create(DecodeStream.prototype);
  15949. RunLengthStream.prototype.readBlock = function RunLengthStream_readBlock() {
  15950. // The repeatHeader has following format. The first byte defines type of run
  15951. // and amount of bytes to repeat/copy: n = 0 through 127 - copy next n bytes
  15952. // (in addition to the second byte from the header), n = 129 through 255 -
  15953. // duplicate the second byte from the header (257 - n) times, n = 128 - end.
  15954. var repeatHeader = this.str.getBytes(2);
  15955. if (!repeatHeader || repeatHeader.length < 2 || repeatHeader[0] === 128) {
  15956. this.eof = true;
  15957. return;
  15958. }
  15959. var buffer;
  15960. var bufferLength = this.bufferLength;
  15961. var n = repeatHeader[0];
  15962. if (n < 128) {
  15963. // copy n bytes
  15964. buffer = this.ensureBuffer(bufferLength + n + 1);
  15965. buffer[bufferLength++] = repeatHeader[1];
  15966. if (n > 0) {
  15967. var source = this.str.getBytes(n);
  15968. buffer.set(source, bufferLength);
  15969. bufferLength += n;
  15970. }
  15971. } else {
  15972. n = 257 - n;
  15973. var b = repeatHeader[1];
  15974. buffer = this.ensureBuffer(bufferLength + n + 1);
  15975. for (var i = 0; i < n; i++) {
  15976. buffer[bufferLength++] = b;
  15977. }
  15978. }
  15979. this.bufferLength = bufferLength;
  15980. };
  15981. return RunLengthStream;
  15982. })();
  15983. var CCITTFaxStream = (function CCITTFaxStreamClosure() {
  15984. var ccittEOL = -2;
  15985. var twoDimPass = 0;
  15986. var twoDimHoriz = 1;
  15987. var twoDimVert0 = 2;
  15988. var twoDimVertR1 = 3;
  15989. var twoDimVertL1 = 4;
  15990. var twoDimVertR2 = 5;
  15991. var twoDimVertL2 = 6;
  15992. var twoDimVertR3 = 7;
  15993. var twoDimVertL3 = 8;
  15994. var twoDimTable = [
  15995. [-1, -1], [-1, -1], // 000000x
  15996. [7, twoDimVertL3], // 0000010
  15997. [7, twoDimVertR3], // 0000011
  15998. [6, twoDimVertL2], [6, twoDimVertL2], // 000010x
  15999. [6, twoDimVertR2], [6, twoDimVertR2], // 000011x
  16000. [4, twoDimPass], [4, twoDimPass], // 0001xxx
  16001. [4, twoDimPass], [4, twoDimPass],
  16002. [4, twoDimPass], [4, twoDimPass],
  16003. [4, twoDimPass], [4, twoDimPass],
  16004. [3, twoDimHoriz], [3, twoDimHoriz], // 001xxxx
  16005. [3, twoDimHoriz], [3, twoDimHoriz],
  16006. [3, twoDimHoriz], [3, twoDimHoriz],
  16007. [3, twoDimHoriz], [3, twoDimHoriz],
  16008. [3, twoDimHoriz], [3, twoDimHoriz],
  16009. [3, twoDimHoriz], [3, twoDimHoriz],
  16010. [3, twoDimHoriz], [3, twoDimHoriz],
  16011. [3, twoDimHoriz], [3, twoDimHoriz],
  16012. [3, twoDimVertL1], [3, twoDimVertL1], // 010xxxx
  16013. [3, twoDimVertL1], [3, twoDimVertL1],
  16014. [3, twoDimVertL1], [3, twoDimVertL1],
  16015. [3, twoDimVertL1], [3, twoDimVertL1],
  16016. [3, twoDimVertL1], [3, twoDimVertL1],
  16017. [3, twoDimVertL1], [3, twoDimVertL1],
  16018. [3, twoDimVertL1], [3, twoDimVertL1],
  16019. [3, twoDimVertL1], [3, twoDimVertL1],
  16020. [3, twoDimVertR1], [3, twoDimVertR1], // 011xxxx
  16021. [3, twoDimVertR1], [3, twoDimVertR1],
  16022. [3, twoDimVertR1], [3, twoDimVertR1],
  16023. [3, twoDimVertR1], [3, twoDimVertR1],
  16024. [3, twoDimVertR1], [3, twoDimVertR1],
  16025. [3, twoDimVertR1], [3, twoDimVertR1],
  16026. [3, twoDimVertR1], [3, twoDimVertR1],
  16027. [3, twoDimVertR1], [3, twoDimVertR1],
  16028. [1, twoDimVert0], [1, twoDimVert0], // 1xxxxxx
  16029. [1, twoDimVert0], [1, twoDimVert0],
  16030. [1, twoDimVert0], [1, twoDimVert0],
  16031. [1, twoDimVert0], [1, twoDimVert0],
  16032. [1, twoDimVert0], [1, twoDimVert0],
  16033. [1, twoDimVert0], [1, twoDimVert0],
  16034. [1, twoDimVert0], [1, twoDimVert0],
  16035. [1, twoDimVert0], [1, twoDimVert0],
  16036. [1, twoDimVert0], [1, twoDimVert0],
  16037. [1, twoDimVert0], [1, twoDimVert0],
  16038. [1, twoDimVert0], [1, twoDimVert0],
  16039. [1, twoDimVert0], [1, twoDimVert0],
  16040. [1, twoDimVert0], [1, twoDimVert0],
  16041. [1, twoDimVert0], [1, twoDimVert0],
  16042. [1, twoDimVert0], [1, twoDimVert0],
  16043. [1, twoDimVert0], [1, twoDimVert0],
  16044. [1, twoDimVert0], [1, twoDimVert0],
  16045. [1, twoDimVert0], [1, twoDimVert0],
  16046. [1, twoDimVert0], [1, twoDimVert0],
  16047. [1, twoDimVert0], [1, twoDimVert0],
  16048. [1, twoDimVert0], [1, twoDimVert0],
  16049. [1, twoDimVert0], [1, twoDimVert0],
  16050. [1, twoDimVert0], [1, twoDimVert0],
  16051. [1, twoDimVert0], [1, twoDimVert0],
  16052. [1, twoDimVert0], [1, twoDimVert0],
  16053. [1, twoDimVert0], [1, twoDimVert0],
  16054. [1, twoDimVert0], [1, twoDimVert0],
  16055. [1, twoDimVert0], [1, twoDimVert0],
  16056. [1, twoDimVert0], [1, twoDimVert0],
  16057. [1, twoDimVert0], [1, twoDimVert0],
  16058. [1, twoDimVert0], [1, twoDimVert0],
  16059. [1, twoDimVert0], [1, twoDimVert0]
  16060. ];
  16061. var whiteTable1 = [
  16062. [-1, -1], // 00000
  16063. [12, ccittEOL], // 00001
  16064. [-1, -1], [-1, -1], // 0001x
  16065. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 001xx
  16066. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 010xx
  16067. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 011xx
  16068. [11, 1792], [11, 1792], // 1000x
  16069. [12, 1984], // 10010
  16070. [12, 2048], // 10011
  16071. [12, 2112], // 10100
  16072. [12, 2176], // 10101
  16073. [12, 2240], // 10110
  16074. [12, 2304], // 10111
  16075. [11, 1856], [11, 1856], // 1100x
  16076. [11, 1920], [11, 1920], // 1101x
  16077. [12, 2368], // 11100
  16078. [12, 2432], // 11101
  16079. [12, 2496], // 11110
  16080. [12, 2560] // 11111
  16081. ];
  16082. var whiteTable2 = [
  16083. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000000xx
  16084. [8, 29], [8, 29], // 00000010x
  16085. [8, 30], [8, 30], // 00000011x
  16086. [8, 45], [8, 45], // 00000100x
  16087. [8, 46], [8, 46], // 00000101x
  16088. [7, 22], [7, 22], [7, 22], [7, 22], // 0000011xx
  16089. [7, 23], [7, 23], [7, 23], [7, 23], // 0000100xx
  16090. [8, 47], [8, 47], // 00001010x
  16091. [8, 48], [8, 48], // 00001011x
  16092. [6, 13], [6, 13], [6, 13], [6, 13], // 000011xxx
  16093. [6, 13], [6, 13], [6, 13], [6, 13],
  16094. [7, 20], [7, 20], [7, 20], [7, 20], // 0001000xx
  16095. [8, 33], [8, 33], // 00010010x
  16096. [8, 34], [8, 34], // 00010011x
  16097. [8, 35], [8, 35], // 00010100x
  16098. [8, 36], [8, 36], // 00010101x
  16099. [8, 37], [8, 37], // 00010110x
  16100. [8, 38], [8, 38], // 00010111x
  16101. [7, 19], [7, 19], [7, 19], [7, 19], // 0001100xx
  16102. [8, 31], [8, 31], // 00011010x
  16103. [8, 32], [8, 32], // 00011011x
  16104. [6, 1], [6, 1], [6, 1], [6, 1], // 000111xxx
  16105. [6, 1], [6, 1], [6, 1], [6, 1],
  16106. [6, 12], [6, 12], [6, 12], [6, 12], // 001000xxx
  16107. [6, 12], [6, 12], [6, 12], [6, 12],
  16108. [8, 53], [8, 53], // 00100100x
  16109. [8, 54], [8, 54], // 00100101x
  16110. [7, 26], [7, 26], [7, 26], [7, 26], // 0010011xx
  16111. [8, 39], [8, 39], // 00101000x
  16112. [8, 40], [8, 40], // 00101001x
  16113. [8, 41], [8, 41], // 00101010x
  16114. [8, 42], [8, 42], // 00101011x
  16115. [8, 43], [8, 43], // 00101100x
  16116. [8, 44], [8, 44], // 00101101x
  16117. [7, 21], [7, 21], [7, 21], [7, 21], // 0010111xx
  16118. [7, 28], [7, 28], [7, 28], [7, 28], // 0011000xx
  16119. [8, 61], [8, 61], // 00110010x
  16120. [8, 62], [8, 62], // 00110011x
  16121. [8, 63], [8, 63], // 00110100x
  16122. [8, 0], [8, 0], // 00110101x
  16123. [8, 320], [8, 320], // 00110110x
  16124. [8, 384], [8, 384], // 00110111x
  16125. [5, 10], [5, 10], [5, 10], [5, 10], // 00111xxxx
  16126. [5, 10], [5, 10], [5, 10], [5, 10],
  16127. [5, 10], [5, 10], [5, 10], [5, 10],
  16128. [5, 10], [5, 10], [5, 10], [5, 10],
  16129. [5, 11], [5, 11], [5, 11], [5, 11], // 01000xxxx
  16130. [5, 11], [5, 11], [5, 11], [5, 11],
  16131. [5, 11], [5, 11], [5, 11], [5, 11],
  16132. [5, 11], [5, 11], [5, 11], [5, 11],
  16133. [7, 27], [7, 27], [7, 27], [7, 27], // 0100100xx
  16134. [8, 59], [8, 59], // 01001010x
  16135. [8, 60], [8, 60], // 01001011x
  16136. [9, 1472], // 010011000
  16137. [9, 1536], // 010011001
  16138. [9, 1600], // 010011010
  16139. [9, 1728], // 010011011
  16140. [7, 18], [7, 18], [7, 18], [7, 18], // 0100111xx
  16141. [7, 24], [7, 24], [7, 24], [7, 24], // 0101000xx
  16142. [8, 49], [8, 49], // 01010010x
  16143. [8, 50], [8, 50], // 01010011x
  16144. [8, 51], [8, 51], // 01010100x
  16145. [8, 52], [8, 52], // 01010101x
  16146. [7, 25], [7, 25], [7, 25], [7, 25], // 0101011xx
  16147. [8, 55], [8, 55], // 01011000x
  16148. [8, 56], [8, 56], // 01011001x
  16149. [8, 57], [8, 57], // 01011010x
  16150. [8, 58], [8, 58], // 01011011x
  16151. [6, 192], [6, 192], [6, 192], [6, 192], // 010111xxx
  16152. [6, 192], [6, 192], [6, 192], [6, 192],
  16153. [6, 1664], [6, 1664], [6, 1664], [6, 1664], // 011000xxx
  16154. [6, 1664], [6, 1664], [6, 1664], [6, 1664],
  16155. [8, 448], [8, 448], // 01100100x
  16156. [8, 512], [8, 512], // 01100101x
  16157. [9, 704], // 011001100
  16158. [9, 768], // 011001101
  16159. [8, 640], [8, 640], // 01100111x
  16160. [8, 576], [8, 576], // 01101000x
  16161. [9, 832], // 011010010
  16162. [9, 896], // 011010011
  16163. [9, 960], // 011010100
  16164. [9, 1024], // 011010101
  16165. [9, 1088], // 011010110
  16166. [9, 1152], // 011010111
  16167. [9, 1216], // 011011000
  16168. [9, 1280], // 011011001
  16169. [9, 1344], // 011011010
  16170. [9, 1408], // 011011011
  16171. [7, 256], [7, 256], [7, 256], [7, 256], // 0110111xx
  16172. [4, 2], [4, 2], [4, 2], [4, 2], // 0111xxxxx
  16173. [4, 2], [4, 2], [4, 2], [4, 2],
  16174. [4, 2], [4, 2], [4, 2], [4, 2],
  16175. [4, 2], [4, 2], [4, 2], [4, 2],
  16176. [4, 2], [4, 2], [4, 2], [4, 2],
  16177. [4, 2], [4, 2], [4, 2], [4, 2],
  16178. [4, 2], [4, 2], [4, 2], [4, 2],
  16179. [4, 2], [4, 2], [4, 2], [4, 2],
  16180. [4, 3], [4, 3], [4, 3], [4, 3], // 1000xxxxx
  16181. [4, 3], [4, 3], [4, 3], [4, 3],
  16182. [4, 3], [4, 3], [4, 3], [4, 3],
  16183. [4, 3], [4, 3], [4, 3], [4, 3],
  16184. [4, 3], [4, 3], [4, 3], [4, 3],
  16185. [4, 3], [4, 3], [4, 3], [4, 3],
  16186. [4, 3], [4, 3], [4, 3], [4, 3],
  16187. [4, 3], [4, 3], [4, 3], [4, 3],
  16188. [5, 128], [5, 128], [5, 128], [5, 128], // 10010xxxx
  16189. [5, 128], [5, 128], [5, 128], [5, 128],
  16190. [5, 128], [5, 128], [5, 128], [5, 128],
  16191. [5, 128], [5, 128], [5, 128], [5, 128],
  16192. [5, 8], [5, 8], [5, 8], [5, 8], // 10011xxxx
  16193. [5, 8], [5, 8], [5, 8], [5, 8],
  16194. [5, 8], [5, 8], [5, 8], [5, 8],
  16195. [5, 8], [5, 8], [5, 8], [5, 8],
  16196. [5, 9], [5, 9], [5, 9], [5, 9], // 10100xxxx
  16197. [5, 9], [5, 9], [5, 9], [5, 9],
  16198. [5, 9], [5, 9], [5, 9], [5, 9],
  16199. [5, 9], [5, 9], [5, 9], [5, 9],
  16200. [6, 16], [6, 16], [6, 16], [6, 16], // 101010xxx
  16201. [6, 16], [6, 16], [6, 16], [6, 16],
  16202. [6, 17], [6, 17], [6, 17], [6, 17], // 101011xxx
  16203. [6, 17], [6, 17], [6, 17], [6, 17],
  16204. [4, 4], [4, 4], [4, 4], [4, 4], // 1011xxxxx
  16205. [4, 4], [4, 4], [4, 4], [4, 4],
  16206. [4, 4], [4, 4], [4, 4], [4, 4],
  16207. [4, 4], [4, 4], [4, 4], [4, 4],
  16208. [4, 4], [4, 4], [4, 4], [4, 4],
  16209. [4, 4], [4, 4], [4, 4], [4, 4],
  16210. [4, 4], [4, 4], [4, 4], [4, 4],
  16211. [4, 4], [4, 4], [4, 4], [4, 4],
  16212. [4, 5], [4, 5], [4, 5], [4, 5], // 1100xxxxx
  16213. [4, 5], [4, 5], [4, 5], [4, 5],
  16214. [4, 5], [4, 5], [4, 5], [4, 5],
  16215. [4, 5], [4, 5], [4, 5], [4, 5],
  16216. [4, 5], [4, 5], [4, 5], [4, 5],
  16217. [4, 5], [4, 5], [4, 5], [4, 5],
  16218. [4, 5], [4, 5], [4, 5], [4, 5],
  16219. [4, 5], [4, 5], [4, 5], [4, 5],
  16220. [6, 14], [6, 14], [6, 14], [6, 14], // 110100xxx
  16221. [6, 14], [6, 14], [6, 14], [6, 14],
  16222. [6, 15], [6, 15], [6, 15], [6, 15], // 110101xxx
  16223. [6, 15], [6, 15], [6, 15], [6, 15],
  16224. [5, 64], [5, 64], [5, 64], [5, 64], // 11011xxxx
  16225. [5, 64], [5, 64], [5, 64], [5, 64],
  16226. [5, 64], [5, 64], [5, 64], [5, 64],
  16227. [5, 64], [5, 64], [5, 64], [5, 64],
  16228. [4, 6], [4, 6], [4, 6], [4, 6], // 1110xxxxx
  16229. [4, 6], [4, 6], [4, 6], [4, 6],
  16230. [4, 6], [4, 6], [4, 6], [4, 6],
  16231. [4, 6], [4, 6], [4, 6], [4, 6],
  16232. [4, 6], [4, 6], [4, 6], [4, 6],
  16233. [4, 6], [4, 6], [4, 6], [4, 6],
  16234. [4, 6], [4, 6], [4, 6], [4, 6],
  16235. [4, 6], [4, 6], [4, 6], [4, 6],
  16236. [4, 7], [4, 7], [4, 7], [4, 7], // 1111xxxxx
  16237. [4, 7], [4, 7], [4, 7], [4, 7],
  16238. [4, 7], [4, 7], [4, 7], [4, 7],
  16239. [4, 7], [4, 7], [4, 7], [4, 7],
  16240. [4, 7], [4, 7], [4, 7], [4, 7],
  16241. [4, 7], [4, 7], [4, 7], [4, 7],
  16242. [4, 7], [4, 7], [4, 7], [4, 7],
  16243. [4, 7], [4, 7], [4, 7], [4, 7]
  16244. ];
  16245. var blackTable1 = [
  16246. [-1, -1], [-1, -1], // 000000000000x
  16247. [12, ccittEOL], [12, ccittEOL], // 000000000001x
  16248. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000001xx
  16249. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000010xx
  16250. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000011xx
  16251. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000100xx
  16252. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000101xx
  16253. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000110xx
  16254. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000111xx
  16255. [11, 1792], [11, 1792], [11, 1792], [11, 1792], // 00000001000xx
  16256. [12, 1984], [12, 1984], // 000000010010x
  16257. [12, 2048], [12, 2048], // 000000010011x
  16258. [12, 2112], [12, 2112], // 000000010100x
  16259. [12, 2176], [12, 2176], // 000000010101x
  16260. [12, 2240], [12, 2240], // 000000010110x
  16261. [12, 2304], [12, 2304], // 000000010111x
  16262. [11, 1856], [11, 1856], [11, 1856], [11, 1856], // 00000001100xx
  16263. [11, 1920], [11, 1920], [11, 1920], [11, 1920], // 00000001101xx
  16264. [12, 2368], [12, 2368], // 000000011100x
  16265. [12, 2432], [12, 2432], // 000000011101x
  16266. [12, 2496], [12, 2496], // 000000011110x
  16267. [12, 2560], [12, 2560], // 000000011111x
  16268. [10, 18], [10, 18], [10, 18], [10, 18], // 0000001000xxx
  16269. [10, 18], [10, 18], [10, 18], [10, 18],
  16270. [12, 52], [12, 52], // 000000100100x
  16271. [13, 640], // 0000001001010
  16272. [13, 704], // 0000001001011
  16273. [13, 768], // 0000001001100
  16274. [13, 832], // 0000001001101
  16275. [12, 55], [12, 55], // 000000100111x
  16276. [12, 56], [12, 56], // 000000101000x
  16277. [13, 1280], // 0000001010010
  16278. [13, 1344], // 0000001010011
  16279. [13, 1408], // 0000001010100
  16280. [13, 1472], // 0000001010101
  16281. [12, 59], [12, 59], // 000000101011x
  16282. [12, 60], [12, 60], // 000000101100x
  16283. [13, 1536], // 0000001011010
  16284. [13, 1600], // 0000001011011
  16285. [11, 24], [11, 24], [11, 24], [11, 24], // 00000010111xx
  16286. [11, 25], [11, 25], [11, 25], [11, 25], // 00000011000xx
  16287. [13, 1664], // 0000001100100
  16288. [13, 1728], // 0000001100101
  16289. [12, 320], [12, 320], // 000000110011x
  16290. [12, 384], [12, 384], // 000000110100x
  16291. [12, 448], [12, 448], // 000000110101x
  16292. [13, 512], // 0000001101100
  16293. [13, 576], // 0000001101101
  16294. [12, 53], [12, 53], // 000000110111x
  16295. [12, 54], [12, 54], // 000000111000x
  16296. [13, 896], // 0000001110010
  16297. [13, 960], // 0000001110011
  16298. [13, 1024], // 0000001110100
  16299. [13, 1088], // 0000001110101
  16300. [13, 1152], // 0000001110110
  16301. [13, 1216], // 0000001110111
  16302. [10, 64], [10, 64], [10, 64], [10, 64], // 0000001111xxx
  16303. [10, 64], [10, 64], [10, 64], [10, 64]
  16304. ];
  16305. var blackTable2 = [
  16306. [8, 13], [8, 13], [8, 13], [8, 13], // 00000100xxxx
  16307. [8, 13], [8, 13], [8, 13], [8, 13],
  16308. [8, 13], [8, 13], [8, 13], [8, 13],
  16309. [8, 13], [8, 13], [8, 13], [8, 13],
  16310. [11, 23], [11, 23], // 00000101000x
  16311. [12, 50], // 000001010010
  16312. [12, 51], // 000001010011
  16313. [12, 44], // 000001010100
  16314. [12, 45], // 000001010101
  16315. [12, 46], // 000001010110
  16316. [12, 47], // 000001010111
  16317. [12, 57], // 000001011000
  16318. [12, 58], // 000001011001
  16319. [12, 61], // 000001011010
  16320. [12, 256], // 000001011011
  16321. [10, 16], [10, 16], [10, 16], [10, 16], // 0000010111xx
  16322. [10, 17], [10, 17], [10, 17], [10, 17], // 0000011000xx
  16323. [12, 48], // 000001100100
  16324. [12, 49], // 000001100101
  16325. [12, 62], // 000001100110
  16326. [12, 63], // 000001100111
  16327. [12, 30], // 000001101000
  16328. [12, 31], // 000001101001
  16329. [12, 32], // 000001101010
  16330. [12, 33], // 000001101011
  16331. [12, 40], // 000001101100
  16332. [12, 41], // 000001101101
  16333. [11, 22], [11, 22], // 00000110111x
  16334. [8, 14], [8, 14], [8, 14], [8, 14], // 00000111xxxx
  16335. [8, 14], [8, 14], [8, 14], [8, 14],
  16336. [8, 14], [8, 14], [8, 14], [8, 14],
  16337. [8, 14], [8, 14], [8, 14], [8, 14],
  16338. [7, 10], [7, 10], [7, 10], [7, 10], // 0000100xxxxx
  16339. [7, 10], [7, 10], [7, 10], [7, 10],
  16340. [7, 10], [7, 10], [7, 10], [7, 10],
  16341. [7, 10], [7, 10], [7, 10], [7, 10],
  16342. [7, 10], [7, 10], [7, 10], [7, 10],
  16343. [7, 10], [7, 10], [7, 10], [7, 10],
  16344. [7, 10], [7, 10], [7, 10], [7, 10],
  16345. [7, 10], [7, 10], [7, 10], [7, 10],
  16346. [7, 11], [7, 11], [7, 11], [7, 11], // 0000101xxxxx
  16347. [7, 11], [7, 11], [7, 11], [7, 11],
  16348. [7, 11], [7, 11], [7, 11], [7, 11],
  16349. [7, 11], [7, 11], [7, 11], [7, 11],
  16350. [7, 11], [7, 11], [7, 11], [7, 11],
  16351. [7, 11], [7, 11], [7, 11], [7, 11],
  16352. [7, 11], [7, 11], [7, 11], [7, 11],
  16353. [7, 11], [7, 11], [7, 11], [7, 11],
  16354. [9, 15], [9, 15], [9, 15], [9, 15], // 000011000xxx
  16355. [9, 15], [9, 15], [9, 15], [9, 15],
  16356. [12, 128], // 000011001000
  16357. [12, 192], // 000011001001
  16358. [12, 26], // 000011001010
  16359. [12, 27], // 000011001011
  16360. [12, 28], // 000011001100
  16361. [12, 29], // 000011001101
  16362. [11, 19], [11, 19], // 00001100111x
  16363. [11, 20], [11, 20], // 00001101000x
  16364. [12, 34], // 000011010010
  16365. [12, 35], // 000011010011
  16366. [12, 36], // 000011010100
  16367. [12, 37], // 000011010101
  16368. [12, 38], // 000011010110
  16369. [12, 39], // 000011010111
  16370. [11, 21], [11, 21], // 00001101100x
  16371. [12, 42], // 000011011010
  16372. [12, 43], // 000011011011
  16373. [10, 0], [10, 0], [10, 0], [10, 0], // 0000110111xx
  16374. [7, 12], [7, 12], [7, 12], [7, 12], // 0000111xxxxx
  16375. [7, 12], [7, 12], [7, 12], [7, 12],
  16376. [7, 12], [7, 12], [7, 12], [7, 12],
  16377. [7, 12], [7, 12], [7, 12], [7, 12],
  16378. [7, 12], [7, 12], [7, 12], [7, 12],
  16379. [7, 12], [7, 12], [7, 12], [7, 12],
  16380. [7, 12], [7, 12], [7, 12], [7, 12],
  16381. [7, 12], [7, 12], [7, 12], [7, 12]
  16382. ];
  16383. var blackTable3 = [
  16384. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000xx
  16385. [6, 9], // 000100
  16386. [6, 8], // 000101
  16387. [5, 7], [5, 7], // 00011x
  16388. [4, 6], [4, 6], [4, 6], [4, 6], // 0010xx
  16389. [4, 5], [4, 5], [4, 5], [4, 5], // 0011xx
  16390. [3, 1], [3, 1], [3, 1], [3, 1], // 010xxx
  16391. [3, 1], [3, 1], [3, 1], [3, 1],
  16392. [3, 4], [3, 4], [3, 4], [3, 4], // 011xxx
  16393. [3, 4], [3, 4], [3, 4], [3, 4],
  16394. [2, 3], [2, 3], [2, 3], [2, 3], // 10xxxx
  16395. [2, 3], [2, 3], [2, 3], [2, 3],
  16396. [2, 3], [2, 3], [2, 3], [2, 3],
  16397. [2, 3], [2, 3], [2, 3], [2, 3],
  16398. [2, 2], [2, 2], [2, 2], [2, 2], // 11xxxx
  16399. [2, 2], [2, 2], [2, 2], [2, 2],
  16400. [2, 2], [2, 2], [2, 2], [2, 2],
  16401. [2, 2], [2, 2], [2, 2], [2, 2]
  16402. ];
  16403. function CCITTFaxStream(str, maybeLength, params) {
  16404. this.str = str;
  16405. this.dict = str.dict;
  16406. params = params || Dict.empty;
  16407. this.encoding = params.get('K') || 0;
  16408. this.eoline = params.get('EndOfLine') || false;
  16409. this.byteAlign = params.get('EncodedByteAlign') || false;
  16410. this.columns = params.get('Columns') || 1728;
  16411. this.rows = params.get('Rows') || 0;
  16412. var eoblock = params.get('EndOfBlock');
  16413. if (eoblock === null || eoblock === undefined) {
  16414. eoblock = true;
  16415. }
  16416. this.eoblock = eoblock;
  16417. this.black = params.get('BlackIs1') || false;
  16418. this.codingLine = new Uint32Array(this.columns + 1);
  16419. this.refLine = new Uint32Array(this.columns + 2);
  16420. this.codingLine[0] = this.columns;
  16421. this.codingPos = 0;
  16422. this.row = 0;
  16423. this.nextLine2D = this.encoding < 0;
  16424. this.inputBits = 0;
  16425. this.inputBuf = 0;
  16426. this.outputBits = 0;
  16427. var code1;
  16428. while ((code1 = this.lookBits(12)) === 0) {
  16429. this.eatBits(1);
  16430. }
  16431. if (code1 === 1) {
  16432. this.eatBits(12);
  16433. }
  16434. if (this.encoding > 0) {
  16435. this.nextLine2D = !this.lookBits(1);
  16436. this.eatBits(1);
  16437. }
  16438. DecodeStream.call(this, maybeLength);
  16439. }
  16440. CCITTFaxStream.prototype = Object.create(DecodeStream.prototype);
  16441. CCITTFaxStream.prototype.readBlock = function CCITTFaxStream_readBlock() {
  16442. while (!this.eof) {
  16443. var c = this.lookChar();
  16444. this.ensureBuffer(this.bufferLength + 1);
  16445. this.buffer[this.bufferLength++] = c;
  16446. }
  16447. };
  16448. CCITTFaxStream.prototype.addPixels =
  16449. function ccittFaxStreamAddPixels(a1, blackPixels) {
  16450. var codingLine = this.codingLine;
  16451. var codingPos = this.codingPos;
  16452. if (a1 > codingLine[codingPos]) {
  16453. if (a1 > this.columns) {
  16454. info('row is wrong length');
  16455. this.err = true;
  16456. a1 = this.columns;
  16457. }
  16458. if ((codingPos & 1) ^ blackPixels) {
  16459. ++codingPos;
  16460. }
  16461. codingLine[codingPos] = a1;
  16462. }
  16463. this.codingPos = codingPos;
  16464. };
  16465. CCITTFaxStream.prototype.addPixelsNeg =
  16466. function ccittFaxStreamAddPixelsNeg(a1, blackPixels) {
  16467. var codingLine = this.codingLine;
  16468. var codingPos = this.codingPos;
  16469. if (a1 > codingLine[codingPos]) {
  16470. if (a1 > this.columns) {
  16471. info('row is wrong length');
  16472. this.err = true;
  16473. a1 = this.columns;
  16474. }
  16475. if ((codingPos & 1) ^ blackPixels) {
  16476. ++codingPos;
  16477. }
  16478. codingLine[codingPos] = a1;
  16479. } else if (a1 < codingLine[codingPos]) {
  16480. if (a1 < 0) {
  16481. info('invalid code');
  16482. this.err = true;
  16483. a1 = 0;
  16484. }
  16485. while (codingPos > 0 && a1 < codingLine[codingPos - 1]) {
  16486. --codingPos;
  16487. }
  16488. codingLine[codingPos] = a1;
  16489. }
  16490. this.codingPos = codingPos;
  16491. };
  16492. CCITTFaxStream.prototype.lookChar = function CCITTFaxStream_lookChar() {
  16493. var refLine = this.refLine;
  16494. var codingLine = this.codingLine;
  16495. var columns = this.columns;
  16496. var refPos, blackPixels, bits, i;
  16497. if (this.outputBits === 0) {
  16498. if (this.eof) {
  16499. return null;
  16500. }
  16501. this.err = false;
  16502. var code1, code2, code3;
  16503. if (this.nextLine2D) {
  16504. for (i = 0; codingLine[i] < columns; ++i) {
  16505. refLine[i] = codingLine[i];
  16506. }
  16507. refLine[i++] = columns;
  16508. refLine[i] = columns;
  16509. codingLine[0] = 0;
  16510. this.codingPos = 0;
  16511. refPos = 0;
  16512. blackPixels = 0;
  16513. while (codingLine[this.codingPos] < columns) {
  16514. code1 = this.getTwoDimCode();
  16515. switch (code1) {
  16516. case twoDimPass:
  16517. this.addPixels(refLine[refPos + 1], blackPixels);
  16518. if (refLine[refPos + 1] < columns) {
  16519. refPos += 2;
  16520. }
  16521. break;
  16522. case twoDimHoriz:
  16523. code1 = code2 = 0;
  16524. if (blackPixels) {
  16525. do {
  16526. code1 += (code3 = this.getBlackCode());
  16527. } while (code3 >= 64);
  16528. do {
  16529. code2 += (code3 = this.getWhiteCode());
  16530. } while (code3 >= 64);
  16531. } else {
  16532. do {
  16533. code1 += (code3 = this.getWhiteCode());
  16534. } while (code3 >= 64);
  16535. do {
  16536. code2 += (code3 = this.getBlackCode());
  16537. } while (code3 >= 64);
  16538. }
  16539. this.addPixels(codingLine[this.codingPos] +
  16540. code1, blackPixels);
  16541. if (codingLine[this.codingPos] < columns) {
  16542. this.addPixels(codingLine[this.codingPos] + code2,
  16543. blackPixels ^ 1);
  16544. }
  16545. while (refLine[refPos] <= codingLine[this.codingPos] &&
  16546. refLine[refPos] < columns) {
  16547. refPos += 2;
  16548. }
  16549. break;
  16550. case twoDimVertR3:
  16551. this.addPixels(refLine[refPos] + 3, blackPixels);
  16552. blackPixels ^= 1;
  16553. if (codingLine[this.codingPos] < columns) {
  16554. ++refPos;
  16555. while (refLine[refPos] <= codingLine[this.codingPos] &&
  16556. refLine[refPos] < columns) {
  16557. refPos += 2;
  16558. }
  16559. }
  16560. break;
  16561. case twoDimVertR2:
  16562. this.addPixels(refLine[refPos] + 2, blackPixels);
  16563. blackPixels ^= 1;
  16564. if (codingLine[this.codingPos] < columns) {
  16565. ++refPos;
  16566. while (refLine[refPos] <= codingLine[this.codingPos] &&
  16567. refLine[refPos] < columns) {
  16568. refPos += 2;
  16569. }
  16570. }
  16571. break;
  16572. case twoDimVertR1:
  16573. this.addPixels(refLine[refPos] + 1, blackPixels);
  16574. blackPixels ^= 1;
  16575. if (codingLine[this.codingPos] < columns) {
  16576. ++refPos;
  16577. while (refLine[refPos] <= codingLine[this.codingPos] &&
  16578. refLine[refPos] < columns) {
  16579. refPos += 2;
  16580. }
  16581. }
  16582. break;
  16583. case twoDimVert0:
  16584. this.addPixels(refLine[refPos], blackPixels);
  16585. blackPixels ^= 1;
  16586. if (codingLine[this.codingPos] < columns) {
  16587. ++refPos;
  16588. while (refLine[refPos] <= codingLine[this.codingPos] &&
  16589. refLine[refPos] < columns) {
  16590. refPos += 2;
  16591. }
  16592. }
  16593. break;
  16594. case twoDimVertL3:
  16595. this.addPixelsNeg(refLine[refPos] - 3, blackPixels);
  16596. blackPixels ^= 1;
  16597. if (codingLine[this.codingPos] < columns) {
  16598. if (refPos > 0) {
  16599. --refPos;
  16600. } else {
  16601. ++refPos;
  16602. }
  16603. while (refLine[refPos] <= codingLine[this.codingPos] &&
  16604. refLine[refPos] < columns) {
  16605. refPos += 2;
  16606. }
  16607. }
  16608. break;
  16609. case twoDimVertL2:
  16610. this.addPixelsNeg(refLine[refPos] - 2, blackPixels);
  16611. blackPixels ^= 1;
  16612. if (codingLine[this.codingPos] < columns) {
  16613. if (refPos > 0) {
  16614. --refPos;
  16615. } else {
  16616. ++refPos;
  16617. }
  16618. while (refLine[refPos] <= codingLine[this.codingPos] &&
  16619. refLine[refPos] < columns) {
  16620. refPos += 2;
  16621. }
  16622. }
  16623. break;
  16624. case twoDimVertL1:
  16625. this.addPixelsNeg(refLine[refPos] - 1, blackPixels);
  16626. blackPixels ^= 1;
  16627. if (codingLine[this.codingPos] < columns) {
  16628. if (refPos > 0) {
  16629. --refPos;
  16630. } else {
  16631. ++refPos;
  16632. }
  16633. while (refLine[refPos] <= codingLine[this.codingPos] &&
  16634. refLine[refPos] < columns) {
  16635. refPos += 2;
  16636. }
  16637. }
  16638. break;
  16639. case EOF:
  16640. this.addPixels(columns, 0);
  16641. this.eof = true;
  16642. break;
  16643. default:
  16644. info('bad 2d code');
  16645. this.addPixels(columns, 0);
  16646. this.err = true;
  16647. }
  16648. }
  16649. } else {
  16650. codingLine[0] = 0;
  16651. this.codingPos = 0;
  16652. blackPixels = 0;
  16653. while (codingLine[this.codingPos] < columns) {
  16654. code1 = 0;
  16655. if (blackPixels) {
  16656. do {
  16657. code1 += (code3 = this.getBlackCode());
  16658. } while (code3 >= 64);
  16659. } else {
  16660. do {
  16661. code1 += (code3 = this.getWhiteCode());
  16662. } while (code3 >= 64);
  16663. }
  16664. this.addPixels(codingLine[this.codingPos] + code1, blackPixels);
  16665. blackPixels ^= 1;
  16666. }
  16667. }
  16668. var gotEOL = false;
  16669. if (this.byteAlign) {
  16670. this.inputBits &= ~7;
  16671. }
  16672. if (!this.eoblock && this.row === this.rows - 1) {
  16673. this.eof = true;
  16674. } else {
  16675. code1 = this.lookBits(12);
  16676. if (this.eoline) {
  16677. while (code1 !== EOF && code1 !== 1) {
  16678. this.eatBits(1);
  16679. code1 = this.lookBits(12);
  16680. }
  16681. } else {
  16682. while (code1 === 0) {
  16683. this.eatBits(1);
  16684. code1 = this.lookBits(12);
  16685. }
  16686. }
  16687. if (code1 === 1) {
  16688. this.eatBits(12);
  16689. gotEOL = true;
  16690. } else if (code1 === EOF) {
  16691. this.eof = true;
  16692. }
  16693. }
  16694. if (!this.eof && this.encoding > 0) {
  16695. this.nextLine2D = !this.lookBits(1);
  16696. this.eatBits(1);
  16697. }
  16698. if (this.eoblock && gotEOL && this.byteAlign) {
  16699. code1 = this.lookBits(12);
  16700. if (code1 === 1) {
  16701. this.eatBits(12);
  16702. if (this.encoding > 0) {
  16703. this.lookBits(1);
  16704. this.eatBits(1);
  16705. }
  16706. if (this.encoding >= 0) {
  16707. for (i = 0; i < 4; ++i) {
  16708. code1 = this.lookBits(12);
  16709. if (code1 !== 1) {
  16710. info('bad rtc code: ' + code1);
  16711. }
  16712. this.eatBits(12);
  16713. if (this.encoding > 0) {
  16714. this.lookBits(1);
  16715. this.eatBits(1);
  16716. }
  16717. }
  16718. }
  16719. this.eof = true;
  16720. }
  16721. } else if (this.err && this.eoline) {
  16722. while (true) {
  16723. code1 = this.lookBits(13);
  16724. if (code1 === EOF) {
  16725. this.eof = true;
  16726. return null;
  16727. }
  16728. if ((code1 >> 1) === 1) {
  16729. break;
  16730. }
  16731. this.eatBits(1);
  16732. }
  16733. this.eatBits(12);
  16734. if (this.encoding > 0) {
  16735. this.eatBits(1);
  16736. this.nextLine2D = !(code1 & 1);
  16737. }
  16738. }
  16739. if (codingLine[0] > 0) {
  16740. this.outputBits = codingLine[this.codingPos = 0];
  16741. } else {
  16742. this.outputBits = codingLine[this.codingPos = 1];
  16743. }
  16744. this.row++;
  16745. }
  16746. var c;
  16747. if (this.outputBits >= 8) {
  16748. c = (this.codingPos & 1) ? 0 : 0xFF;
  16749. this.outputBits -= 8;
  16750. if (this.outputBits === 0 && codingLine[this.codingPos] < columns) {
  16751. this.codingPos++;
  16752. this.outputBits = (codingLine[this.codingPos] -
  16753. codingLine[this.codingPos - 1]);
  16754. }
  16755. } else {
  16756. bits = 8;
  16757. c = 0;
  16758. do {
  16759. if (this.outputBits > bits) {
  16760. c <<= bits;
  16761. if (!(this.codingPos & 1)) {
  16762. c |= 0xFF >> (8 - bits);
  16763. }
  16764. this.outputBits -= bits;
  16765. bits = 0;
  16766. } else {
  16767. c <<= this.outputBits;
  16768. if (!(this.codingPos & 1)) {
  16769. c |= 0xFF >> (8 - this.outputBits);
  16770. }
  16771. bits -= this.outputBits;
  16772. this.outputBits = 0;
  16773. if (codingLine[this.codingPos] < columns) {
  16774. this.codingPos++;
  16775. this.outputBits = (codingLine[this.codingPos] -
  16776. codingLine[this.codingPos - 1]);
  16777. } else if (bits > 0) {
  16778. c <<= bits;
  16779. bits = 0;
  16780. }
  16781. }
  16782. } while (bits);
  16783. }
  16784. if (this.black) {
  16785. c ^= 0xFF;
  16786. }
  16787. return c;
  16788. };
  16789. // This functions returns the code found from the table.
  16790. // The start and end parameters set the boundaries for searching the table.
  16791. // The limit parameter is optional. Function returns an array with three
  16792. // values. The first array element indicates whether a valid code is being
  16793. // returned. The second array element is the actual code. The third array
  16794. // element indicates whether EOF was reached.
  16795. CCITTFaxStream.prototype.findTableCode =
  16796. function ccittFaxStreamFindTableCode(start, end, table, limit) {
  16797. var limitValue = limit || 0;
  16798. for (var i = start; i <= end; ++i) {
  16799. var code = this.lookBits(i);
  16800. if (code === EOF) {
  16801. return [true, 1, false];
  16802. }
  16803. if (i < end) {
  16804. code <<= end - i;
  16805. }
  16806. if (!limitValue || code >= limitValue) {
  16807. var p = table[code - limitValue];
  16808. if (p[0] === i) {
  16809. this.eatBits(i);
  16810. return [true, p[1], true];
  16811. }
  16812. }
  16813. }
  16814. return [false, 0, false];
  16815. };
  16816. CCITTFaxStream.prototype.getTwoDimCode =
  16817. function ccittFaxStreamGetTwoDimCode() {
  16818. var code = 0;
  16819. var p;
  16820. if (this.eoblock) {
  16821. code = this.lookBits(7);
  16822. p = twoDimTable[code];
  16823. if (p && p[0] > 0) {
  16824. this.eatBits(p[0]);
  16825. return p[1];
  16826. }
  16827. } else {
  16828. var result = this.findTableCode(1, 7, twoDimTable);
  16829. if (result[0] && result[2]) {
  16830. return result[1];
  16831. }
  16832. }
  16833. info('Bad two dim code');
  16834. return EOF;
  16835. };
  16836. CCITTFaxStream.prototype.getWhiteCode =
  16837. function ccittFaxStreamGetWhiteCode() {
  16838. var code = 0;
  16839. var p;
  16840. if (this.eoblock) {
  16841. code = this.lookBits(12);
  16842. if (code === EOF) {
  16843. return 1;
  16844. }
  16845. if ((code >> 5) === 0) {
  16846. p = whiteTable1[code];
  16847. } else {
  16848. p = whiteTable2[code >> 3];
  16849. }
  16850. if (p[0] > 0) {
  16851. this.eatBits(p[0]);
  16852. return p[1];
  16853. }
  16854. } else {
  16855. var result = this.findTableCode(1, 9, whiteTable2);
  16856. if (result[0]) {
  16857. return result[1];
  16858. }
  16859. result = this.findTableCode(11, 12, whiteTable1);
  16860. if (result[0]) {
  16861. return result[1];
  16862. }
  16863. }
  16864. info('bad white code');
  16865. this.eatBits(1);
  16866. return 1;
  16867. };
  16868. CCITTFaxStream.prototype.getBlackCode =
  16869. function ccittFaxStreamGetBlackCode() {
  16870. var code, p;
  16871. if (this.eoblock) {
  16872. code = this.lookBits(13);
  16873. if (code === EOF) {
  16874. return 1;
  16875. }
  16876. if ((code >> 7) === 0) {
  16877. p = blackTable1[code];
  16878. } else if ((code >> 9) === 0 && (code >> 7) !== 0) {
  16879. p = blackTable2[(code >> 1) - 64];
  16880. } else {
  16881. p = blackTable3[code >> 7];
  16882. }
  16883. if (p[0] > 0) {
  16884. this.eatBits(p[0]);
  16885. return p[1];
  16886. }
  16887. } else {
  16888. var result = this.findTableCode(2, 6, blackTable3);
  16889. if (result[0]) {
  16890. return result[1];
  16891. }
  16892. result = this.findTableCode(7, 12, blackTable2, 64);
  16893. if (result[0]) {
  16894. return result[1];
  16895. }
  16896. result = this.findTableCode(10, 13, blackTable1);
  16897. if (result[0]) {
  16898. return result[1];
  16899. }
  16900. }
  16901. info('bad black code');
  16902. this.eatBits(1);
  16903. return 1;
  16904. };
  16905. CCITTFaxStream.prototype.lookBits = function CCITTFaxStream_lookBits(n) {
  16906. var c;
  16907. while (this.inputBits < n) {
  16908. if ((c = this.str.getByte()) === -1) {
  16909. if (this.inputBits === 0) {
  16910. return EOF;
  16911. }
  16912. return ((this.inputBuf << (n - this.inputBits)) &
  16913. (0xFFFF >> (16 - n)));
  16914. }
  16915. this.inputBuf = (this.inputBuf << 8) + c;
  16916. this.inputBits += 8;
  16917. }
  16918. return (this.inputBuf >> (this.inputBits - n)) & (0xFFFF >> (16 - n));
  16919. };
  16920. CCITTFaxStream.prototype.eatBits = function CCITTFaxStream_eatBits(n) {
  16921. if ((this.inputBits -= n) < 0) {
  16922. this.inputBits = 0;
  16923. }
  16924. };
  16925. return CCITTFaxStream;
  16926. })();
  16927. var LZWStream = (function LZWStreamClosure() {
  16928. function LZWStream(str, maybeLength, earlyChange) {
  16929. this.str = str;
  16930. this.dict = str.dict;
  16931. this.cachedData = 0;
  16932. this.bitsCached = 0;
  16933. var maxLzwDictionarySize = 4096;
  16934. var lzwState = {
  16935. earlyChange: earlyChange,
  16936. codeLength: 9,
  16937. nextCode: 258,
  16938. dictionaryValues: new Uint8Array(maxLzwDictionarySize),
  16939. dictionaryLengths: new Uint16Array(maxLzwDictionarySize),
  16940. dictionaryPrevCodes: new Uint16Array(maxLzwDictionarySize),
  16941. currentSequence: new Uint8Array(maxLzwDictionarySize),
  16942. currentSequenceLength: 0
  16943. };
  16944. for (var i = 0; i < 256; ++i) {
  16945. lzwState.dictionaryValues[i] = i;
  16946. lzwState.dictionaryLengths[i] = 1;
  16947. }
  16948. this.lzwState = lzwState;
  16949. DecodeStream.call(this, maybeLength);
  16950. }
  16951. LZWStream.prototype = Object.create(DecodeStream.prototype);
  16952. LZWStream.prototype.readBits = function LZWStream_readBits(n) {
  16953. var bitsCached = this.bitsCached;
  16954. var cachedData = this.cachedData;
  16955. while (bitsCached < n) {
  16956. var c = this.str.getByte();
  16957. if (c === -1) {
  16958. this.eof = true;
  16959. return null;
  16960. }
  16961. cachedData = (cachedData << 8) | c;
  16962. bitsCached += 8;
  16963. }
  16964. this.bitsCached = (bitsCached -= n);
  16965. this.cachedData = cachedData;
  16966. this.lastCode = null;
  16967. return (cachedData >>> bitsCached) & ((1 << n) - 1);
  16968. };
  16969. LZWStream.prototype.readBlock = function LZWStream_readBlock() {
  16970. var blockSize = 512;
  16971. var estimatedDecodedSize = blockSize * 2, decodedSizeDelta = blockSize;
  16972. var i, j, q;
  16973. var lzwState = this.lzwState;
  16974. if (!lzwState) {
  16975. return; // eof was found
  16976. }
  16977. var earlyChange = lzwState.earlyChange;
  16978. var nextCode = lzwState.nextCode;
  16979. var dictionaryValues = lzwState.dictionaryValues;
  16980. var dictionaryLengths = lzwState.dictionaryLengths;
  16981. var dictionaryPrevCodes = lzwState.dictionaryPrevCodes;
  16982. var codeLength = lzwState.codeLength;
  16983. var prevCode = lzwState.prevCode;
  16984. var currentSequence = lzwState.currentSequence;
  16985. var currentSequenceLength = lzwState.currentSequenceLength;
  16986. var decodedLength = 0;
  16987. var currentBufferLength = this.bufferLength;
  16988. var buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  16989. for (i = 0; i < blockSize; i++) {
  16990. var code = this.readBits(codeLength);
  16991. var hasPrev = currentSequenceLength > 0;
  16992. if (code < 256) {
  16993. currentSequence[0] = code;
  16994. currentSequenceLength = 1;
  16995. } else if (code >= 258) {
  16996. if (code < nextCode) {
  16997. currentSequenceLength = dictionaryLengths[code];
  16998. for (j = currentSequenceLength - 1, q = code; j >= 0; j--) {
  16999. currentSequence[j] = dictionaryValues[q];
  17000. q = dictionaryPrevCodes[q];
  17001. }
  17002. } else {
  17003. currentSequence[currentSequenceLength++] = currentSequence[0];
  17004. }
  17005. } else if (code === 256) {
  17006. codeLength = 9;
  17007. nextCode = 258;
  17008. currentSequenceLength = 0;
  17009. continue;
  17010. } else {
  17011. this.eof = true;
  17012. delete this.lzwState;
  17013. break;
  17014. }
  17015. if (hasPrev) {
  17016. dictionaryPrevCodes[nextCode] = prevCode;
  17017. dictionaryLengths[nextCode] = dictionaryLengths[prevCode] + 1;
  17018. dictionaryValues[nextCode] = currentSequence[0];
  17019. nextCode++;
  17020. codeLength = (nextCode + earlyChange) & (nextCode + earlyChange - 1) ?
  17021. codeLength : Math.min(Math.log(nextCode + earlyChange) /
  17022. 0.6931471805599453 + 1, 12) | 0;
  17023. }
  17024. prevCode = code;
  17025. decodedLength += currentSequenceLength;
  17026. if (estimatedDecodedSize < decodedLength) {
  17027. do {
  17028. estimatedDecodedSize += decodedSizeDelta;
  17029. } while (estimatedDecodedSize < decodedLength);
  17030. buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  17031. }
  17032. for (j = 0; j < currentSequenceLength; j++) {
  17033. buffer[currentBufferLength++] = currentSequence[j];
  17034. }
  17035. }
  17036. lzwState.nextCode = nextCode;
  17037. lzwState.codeLength = codeLength;
  17038. lzwState.prevCode = prevCode;
  17039. lzwState.currentSequenceLength = currentSequenceLength;
  17040. this.bufferLength = currentBufferLength;
  17041. };
  17042. return LZWStream;
  17043. })();
  17044. var NullStream = (function NullStreamClosure() {
  17045. function NullStream() {
  17046. Stream.call(this, new Uint8Array(0));
  17047. }
  17048. NullStream.prototype = Stream.prototype;
  17049. return NullStream;
  17050. })();
  17051. // TODO refactor to remove dependency on parser.js
  17052. function _setCoreParser(coreParser_) {
  17053. coreParser = coreParser_;
  17054. EOF = coreParser_.EOF;
  17055. Lexer = coreParser_.Lexer;
  17056. }
  17057. exports._setCoreParser = _setCoreParser;
  17058. // TODO refactor to remove dependency on colorspace.js
  17059. function _setCoreColorSpace(coreColorSpace_) {
  17060. coreColorSpace = coreColorSpace_;
  17061. ColorSpace = coreColorSpace_.ColorSpace;
  17062. }
  17063. exports._setCoreColorSpace = _setCoreColorSpace;
  17064. exports.Ascii85Stream = Ascii85Stream;
  17065. exports.AsciiHexStream = AsciiHexStream;
  17066. exports.CCITTFaxStream = CCITTFaxStream;
  17067. exports.DecryptStream = DecryptStream;
  17068. exports.DecodeStream = DecodeStream;
  17069. exports.FlateStream = FlateStream;
  17070. exports.Jbig2Stream = Jbig2Stream;
  17071. exports.JpegStream = JpegStream;
  17072. exports.JpxStream = JpxStream;
  17073. exports.NullStream = NullStream;
  17074. exports.PredictorStream = PredictorStream;
  17075. exports.RunLengthStream = RunLengthStream;
  17076. exports.Stream = Stream;
  17077. exports.StreamsSequenceStream = StreamsSequenceStream;
  17078. exports.StringStream = StringStream;
  17079. exports.LZWStream = LZWStream;
  17080. }));
  17081. (function (root, factory) {
  17082. if (typeof define === 'function' && define.amd) {
  17083. define('pdfjs/core/crypto', ['exports', 'pdfjs/shared/util',
  17084. 'pdfjs/core/primitives', 'pdfjs/core/stream'], factory);
  17085. } else if (typeof exports !== 'undefined') {
  17086. factory(exports, require('../shared/util.js'), require('./primitives.js'),
  17087. require('./stream.js'));
  17088. } else {
  17089. factory((root.pdfjsCoreCrypto = {}), root.pdfjsSharedUtil,
  17090. root.pdfjsCorePrimitives, root.pdfjsCoreStream);
  17091. }
  17092. }(this, function (exports, sharedUtil, corePrimitives, coreStream) {
  17093. var PasswordException = sharedUtil.PasswordException;
  17094. var PasswordResponses = sharedUtil.PasswordResponses;
  17095. var bytesToString = sharedUtil.bytesToString;
  17096. var error = sharedUtil.error;
  17097. var isInt = sharedUtil.isInt;
  17098. var stringToBytes = sharedUtil.stringToBytes;
  17099. var utf8StringToString = sharedUtil.utf8StringToString;
  17100. var warn = sharedUtil.warn;
  17101. var Name = corePrimitives.Name;
  17102. var isName = corePrimitives.isName;
  17103. var DecryptStream = coreStream.DecryptStream;
  17104. var ARCFourCipher = (function ARCFourCipherClosure() {
  17105. function ARCFourCipher(key) {
  17106. this.a = 0;
  17107. this.b = 0;
  17108. var s = new Uint8Array(256);
  17109. var i, j = 0, tmp, keyLength = key.length;
  17110. for (i = 0; i < 256; ++i) {
  17111. s[i] = i;
  17112. }
  17113. for (i = 0; i < 256; ++i) {
  17114. tmp = s[i];
  17115. j = (j + tmp + key[i % keyLength]) & 0xFF;
  17116. s[i] = s[j];
  17117. s[j] = tmp;
  17118. }
  17119. this.s = s;
  17120. }
  17121. ARCFourCipher.prototype = {
  17122. encryptBlock: function ARCFourCipher_encryptBlock(data) {
  17123. var i, n = data.length, tmp, tmp2;
  17124. var a = this.a, b = this.b, s = this.s;
  17125. var output = new Uint8Array(n);
  17126. for (i = 0; i < n; ++i) {
  17127. a = (a + 1) & 0xFF;
  17128. tmp = s[a];
  17129. b = (b + tmp) & 0xFF;
  17130. tmp2 = s[b];
  17131. s[a] = tmp2;
  17132. s[b] = tmp;
  17133. output[i] = data[i] ^ s[(tmp + tmp2) & 0xFF];
  17134. }
  17135. this.a = a;
  17136. this.b = b;
  17137. return output;
  17138. }
  17139. };
  17140. ARCFourCipher.prototype.decryptBlock = ARCFourCipher.prototype.encryptBlock;
  17141. return ARCFourCipher;
  17142. })();
  17143. var calculateMD5 = (function calculateMD5Closure() {
  17144. var r = new Uint8Array([
  17145. 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22,
  17146. 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20,
  17147. 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23,
  17148. 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21]);
  17149. var k = new Int32Array([
  17150. -680876936, -389564586, 606105819, -1044525330, -176418897, 1200080426,
  17151. -1473231341, -45705983, 1770035416, -1958414417, -42063, -1990404162,
  17152. 1804603682, -40341101, -1502002290, 1236535329, -165796510, -1069501632,
  17153. 643717713, -373897302, -701558691, 38016083, -660478335, -405537848,
  17154. 568446438, -1019803690, -187363961, 1163531501, -1444681467, -51403784,
  17155. 1735328473, -1926607734, -378558, -2022574463, 1839030562, -35309556,
  17156. -1530992060, 1272893353, -155497632, -1094730640, 681279174, -358537222,
  17157. -722521979, 76029189, -640364487, -421815835, 530742520, -995338651,
  17158. -198630844, 1126891415, -1416354905, -57434055, 1700485571, -1894986606,
  17159. -1051523, -2054922799, 1873313359, -30611744, -1560198380, 1309151649,
  17160. -145523070, -1120210379, 718787259, -343485551]);
  17161. function hash(data, offset, length) {
  17162. var h0 = 1732584193, h1 = -271733879, h2 = -1732584194, h3 = 271733878;
  17163. // pre-processing
  17164. var paddedLength = (length + 72) & ~63; // data + 9 extra bytes
  17165. var padded = new Uint8Array(paddedLength);
  17166. var i, j, n;
  17167. for (i = 0; i < length; ++i) {
  17168. padded[i] = data[offset++];
  17169. }
  17170. padded[i++] = 0x80;
  17171. n = paddedLength - 8;
  17172. while (i < n) {
  17173. padded[i++] = 0;
  17174. }
  17175. padded[i++] = (length << 3) & 0xFF;
  17176. padded[i++] = (length >> 5) & 0xFF;
  17177. padded[i++] = (length >> 13) & 0xFF;
  17178. padded[i++] = (length >> 21) & 0xFF;
  17179. padded[i++] = (length >>> 29) & 0xFF;
  17180. padded[i++] = 0;
  17181. padded[i++] = 0;
  17182. padded[i++] = 0;
  17183. var w = new Int32Array(16);
  17184. for (i = 0; i < paddedLength;) {
  17185. for (j = 0; j < 16; ++j, i += 4) {
  17186. w[j] = (padded[i] | (padded[i + 1] << 8) |
  17187. (padded[i + 2] << 16) | (padded[i + 3] << 24));
  17188. }
  17189. var a = h0, b = h1, c = h2, d = h3, f, g;
  17190. for (j = 0; j < 64; ++j) {
  17191. if (j < 16) {
  17192. f = (b & c) | ((~b) & d);
  17193. g = j;
  17194. } else if (j < 32) {
  17195. f = (d & b) | ((~d) & c);
  17196. g = (5 * j + 1) & 15;
  17197. } else if (j < 48) {
  17198. f = b ^ c ^ d;
  17199. g = (3 * j + 5) & 15;
  17200. } else {
  17201. f = c ^ (b | (~d));
  17202. g = (7 * j) & 15;
  17203. }
  17204. var tmp = d, rotateArg = (a + f + k[j] + w[g]) | 0, rotate = r[j];
  17205. d = c;
  17206. c = b;
  17207. b = (b + ((rotateArg << rotate) | (rotateArg >>> (32 - rotate)))) | 0;
  17208. a = tmp;
  17209. }
  17210. h0 = (h0 + a) | 0;
  17211. h1 = (h1 + b) | 0;
  17212. h2 = (h2 + c) | 0;
  17213. h3 = (h3 + d) | 0;
  17214. }
  17215. return new Uint8Array([
  17216. h0 & 0xFF, (h0 >> 8) & 0xFF, (h0 >> 16) & 0xFF, (h0 >>> 24) & 0xFF,
  17217. h1 & 0xFF, (h1 >> 8) & 0xFF, (h1 >> 16) & 0xFF, (h1 >>> 24) & 0xFF,
  17218. h2 & 0xFF, (h2 >> 8) & 0xFF, (h2 >> 16) & 0xFF, (h2 >>> 24) & 0xFF,
  17219. h3 & 0xFF, (h3 >> 8) & 0xFF, (h3 >> 16) & 0xFF, (h3 >>> 24) & 0xFF
  17220. ]);
  17221. }
  17222. return hash;
  17223. })();
  17224. var Word64 = (function Word64Closure() {
  17225. function Word64(highInteger, lowInteger) {
  17226. this.high = highInteger | 0;
  17227. this.low = lowInteger | 0;
  17228. }
  17229. Word64.prototype = {
  17230. and: function Word64_and(word) {
  17231. this.high &= word.high;
  17232. this.low &= word.low;
  17233. },
  17234. xor: function Word64_xor(word) {
  17235. this.high ^= word.high;
  17236. this.low ^= word.low;
  17237. },
  17238. or: function Word64_or(word) {
  17239. this.high |= word.high;
  17240. this.low |= word.low;
  17241. },
  17242. shiftRight: function Word64_shiftRight(places) {
  17243. if (places >= 32) {
  17244. this.low = (this.high >>> (places - 32)) | 0;
  17245. this.high = 0;
  17246. } else {
  17247. this.low = (this.low >>> places) | (this.high << (32 - places));
  17248. this.high = (this.high >>> places) | 0;
  17249. }
  17250. },
  17251. shiftLeft: function Word64_shiftLeft(places) {
  17252. if (places >= 32) {
  17253. this.high = this.low << (places - 32);
  17254. this.low = 0;
  17255. } else {
  17256. this.high = (this.high << places) | (this.low >>> (32 - places));
  17257. this.low = this.low << places;
  17258. }
  17259. },
  17260. rotateRight: function Word64_rotateRight(places) {
  17261. var low, high;
  17262. if (places & 32) {
  17263. high = this.low;
  17264. low = this.high;
  17265. } else {
  17266. low = this.low;
  17267. high = this.high;
  17268. }
  17269. places &= 31;
  17270. this.low = (low >>> places) | (high << (32 - places));
  17271. this.high = (high >>> places) | (low << (32 - places));
  17272. },
  17273. not: function Word64_not() {
  17274. this.high = ~this.high;
  17275. this.low = ~this.low;
  17276. },
  17277. add: function Word64_add(word) {
  17278. var lowAdd = (this.low >>> 0) + (word.low >>> 0);
  17279. var highAdd = (this.high >>> 0) + (word.high >>> 0);
  17280. if (lowAdd > 0xFFFFFFFF) {
  17281. highAdd += 1;
  17282. }
  17283. this.low = lowAdd | 0;
  17284. this.high = highAdd | 0;
  17285. },
  17286. copyTo: function Word64_copyTo(bytes, offset) {
  17287. bytes[offset] = (this.high >>> 24) & 0xFF;
  17288. bytes[offset + 1] = (this.high >> 16) & 0xFF;
  17289. bytes[offset + 2] = (this.high >> 8) & 0xFF;
  17290. bytes[offset + 3] = this.high & 0xFF;
  17291. bytes[offset + 4] = (this.low >>> 24) & 0xFF;
  17292. bytes[offset + 5] = (this.low >> 16) & 0xFF;
  17293. bytes[offset + 6] = (this.low >> 8) & 0xFF;
  17294. bytes[offset + 7] = this.low & 0xFF;
  17295. },
  17296. assign: function Word64_assign(word) {
  17297. this.high = word.high;
  17298. this.low = word.low;
  17299. }
  17300. };
  17301. return Word64;
  17302. })();
  17303. var calculateSHA256 = (function calculateSHA256Closure() {
  17304. function rotr(x, n) {
  17305. return (x >>> n) | (x << 32 - n);
  17306. }
  17307. function ch(x, y, z) {
  17308. return (x & y) ^ (~x & z);
  17309. }
  17310. function maj(x, y, z) {
  17311. return (x & y) ^ (x & z) ^ (y & z);
  17312. }
  17313. function sigma(x) {
  17314. return rotr(x, 2) ^ rotr(x, 13) ^ rotr(x, 22);
  17315. }
  17316. function sigmaPrime(x) {
  17317. return rotr(x, 6) ^ rotr(x, 11) ^ rotr(x, 25);
  17318. }
  17319. function littleSigma(x) {
  17320. return rotr(x, 7) ^ rotr(x, 18) ^ x >>> 3;
  17321. }
  17322. function littleSigmaPrime(x) {
  17323. return rotr(x, 17) ^ rotr(x, 19) ^ x >>> 10;
  17324. }
  17325. var k = [0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
  17326. 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
  17327. 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
  17328. 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
  17329. 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
  17330. 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
  17331. 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
  17332. 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
  17333. 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
  17334. 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
  17335. 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
  17336. 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
  17337. 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
  17338. 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
  17339. 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
  17340. 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2];
  17341. function hash(data, offset, length) {
  17342. // initial hash values
  17343. var h0 = 0x6a09e667, h1 = 0xbb67ae85, h2 = 0x3c6ef372,
  17344. h3 = 0xa54ff53a, h4 = 0x510e527f, h5 = 0x9b05688c,
  17345. h6 = 0x1f83d9ab, h7 = 0x5be0cd19;
  17346. // pre-processing
  17347. var paddedLength = Math.ceil((length + 9) / 64) * 64;
  17348. var padded = new Uint8Array(paddedLength);
  17349. var i, j, n;
  17350. for (i = 0; i < length; ++i) {
  17351. padded[i] = data[offset++];
  17352. }
  17353. padded[i++] = 0x80;
  17354. n = paddedLength - 8;
  17355. while (i < n) {
  17356. padded[i++] = 0;
  17357. }
  17358. padded[i++] = 0;
  17359. padded[i++] = 0;
  17360. padded[i++] = 0;
  17361. padded[i++] = (length >>> 29) & 0xFF;
  17362. padded[i++] = (length >> 21) & 0xFF;
  17363. padded[i++] = (length >> 13) & 0xFF;
  17364. padded[i++] = (length >> 5) & 0xFF;
  17365. padded[i++] = (length << 3) & 0xFF;
  17366. var w = new Uint32Array(64);
  17367. // for each 512 bit block
  17368. for (i = 0; i < paddedLength;) {
  17369. for (j = 0; j < 16; ++j) {
  17370. w[j] = (padded[i] << 24 | (padded[i + 1] << 16) |
  17371. (padded[i + 2] << 8) | (padded[i + 3]));
  17372. i += 4;
  17373. }
  17374. for (j = 16; j < 64; ++j) {
  17375. w[j] = littleSigmaPrime(w[j - 2]) + w[j - 7] +
  17376. littleSigma(w[j - 15]) + w[j - 16] | 0;
  17377. }
  17378. var a = h0, b = h1, c = h2, d = h3, e = h4,
  17379. f = h5, g = h6, h = h7, t1, t2;
  17380. for (j = 0; j < 64; ++j) {
  17381. t1 = h + sigmaPrime(e) + ch(e, f, g) + k[j] + w[j];
  17382. t2 = sigma(a) + maj(a, b, c);
  17383. h = g;
  17384. g = f;
  17385. f = e;
  17386. e = (d + t1) | 0;
  17387. d = c;
  17388. c = b;
  17389. b = a;
  17390. a = (t1 + t2) | 0;
  17391. }
  17392. h0 = (h0 + a) | 0;
  17393. h1 = (h1 + b) | 0;
  17394. h2 = (h2 + c) | 0;
  17395. h3 = (h3 + d) | 0;
  17396. h4 = (h4 + e) | 0;
  17397. h5 = (h5 + f) | 0;
  17398. h6 = (h6 + g) | 0;
  17399. h7 = (h7 + h) | 0;
  17400. }
  17401. return new Uint8Array([
  17402. (h0 >> 24) & 0xFF, (h0 >> 16) & 0xFF, (h0 >> 8) & 0xFF, (h0) & 0xFF,
  17403. (h1 >> 24) & 0xFF, (h1 >> 16) & 0xFF, (h1 >> 8) & 0xFF, (h1) & 0xFF,
  17404. (h2 >> 24) & 0xFF, (h2 >> 16) & 0xFF, (h2 >> 8) & 0xFF, (h2) & 0xFF,
  17405. (h3 >> 24) & 0xFF, (h3 >> 16) & 0xFF, (h3 >> 8) & 0xFF, (h3) & 0xFF,
  17406. (h4 >> 24) & 0xFF, (h4 >> 16) & 0xFF, (h4 >> 8) & 0xFF, (h4) & 0xFF,
  17407. (h5 >> 24) & 0xFF, (h5 >> 16) & 0xFF, (h5 >> 8) & 0xFF, (h5) & 0xFF,
  17408. (h6 >> 24) & 0xFF, (h6 >> 16) & 0xFF, (h6 >> 8) & 0xFF, (h6) & 0xFF,
  17409. (h7 >> 24) & 0xFF, (h7 >> 16) & 0xFF, (h7 >> 8) & 0xFF, (h7) & 0xFF
  17410. ]);
  17411. }
  17412. return hash;
  17413. })();
  17414. var calculateSHA512 = (function calculateSHA512Closure() {
  17415. function ch(result, x, y, z, tmp) {
  17416. result.assign(x);
  17417. result.and(y);
  17418. tmp.assign(x);
  17419. tmp.not();
  17420. tmp.and(z);
  17421. result.xor(tmp);
  17422. }
  17423. function maj(result, x, y, z, tmp) {
  17424. result.assign(x);
  17425. result.and(y);
  17426. tmp.assign(x);
  17427. tmp.and(z);
  17428. result.xor(tmp);
  17429. tmp.assign(y);
  17430. tmp.and(z);
  17431. result.xor(tmp);
  17432. }
  17433. function sigma(result, x, tmp) {
  17434. result.assign(x);
  17435. result.rotateRight(28);
  17436. tmp.assign(x);
  17437. tmp.rotateRight(34);
  17438. result.xor(tmp);
  17439. tmp.assign(x);
  17440. tmp.rotateRight(39);
  17441. result.xor(tmp);
  17442. }
  17443. function sigmaPrime(result, x, tmp) {
  17444. result.assign(x);
  17445. result.rotateRight(14);
  17446. tmp.assign(x);
  17447. tmp.rotateRight(18);
  17448. result.xor(tmp);
  17449. tmp.assign(x);
  17450. tmp.rotateRight(41);
  17451. result.xor(tmp);
  17452. }
  17453. function littleSigma(result, x, tmp) {
  17454. result.assign(x);
  17455. result.rotateRight(1);
  17456. tmp.assign(x);
  17457. tmp.rotateRight(8);
  17458. result.xor(tmp);
  17459. tmp.assign(x);
  17460. tmp.shiftRight(7);
  17461. result.xor(tmp);
  17462. }
  17463. function littleSigmaPrime(result, x, tmp) {
  17464. result.assign(x);
  17465. result.rotateRight(19);
  17466. tmp.assign(x);
  17467. tmp.rotateRight(61);
  17468. result.xor(tmp);
  17469. tmp.assign(x);
  17470. tmp.shiftRight(6);
  17471. result.xor(tmp);
  17472. }
  17473. var k = [
  17474. new Word64(0x428a2f98, 0xd728ae22), new Word64(0x71374491, 0x23ef65cd),
  17475. new Word64(0xb5c0fbcf, 0xec4d3b2f), new Word64(0xe9b5dba5, 0x8189dbbc),
  17476. new Word64(0x3956c25b, 0xf348b538), new Word64(0x59f111f1, 0xb605d019),
  17477. new Word64(0x923f82a4, 0xaf194f9b), new Word64(0xab1c5ed5, 0xda6d8118),
  17478. new Word64(0xd807aa98, 0xa3030242), new Word64(0x12835b01, 0x45706fbe),
  17479. new Word64(0x243185be, 0x4ee4b28c), new Word64(0x550c7dc3, 0xd5ffb4e2),
  17480. new Word64(0x72be5d74, 0xf27b896f), new Word64(0x80deb1fe, 0x3b1696b1),
  17481. new Word64(0x9bdc06a7, 0x25c71235), new Word64(0xc19bf174, 0xcf692694),
  17482. new Word64(0xe49b69c1, 0x9ef14ad2), new Word64(0xefbe4786, 0x384f25e3),
  17483. new Word64(0x0fc19dc6, 0x8b8cd5b5), new Word64(0x240ca1cc, 0x77ac9c65),
  17484. new Word64(0x2de92c6f, 0x592b0275), new Word64(0x4a7484aa, 0x6ea6e483),
  17485. new Word64(0x5cb0a9dc, 0xbd41fbd4), new Word64(0x76f988da, 0x831153b5),
  17486. new Word64(0x983e5152, 0xee66dfab), new Word64(0xa831c66d, 0x2db43210),
  17487. new Word64(0xb00327c8, 0x98fb213f), new Word64(0xbf597fc7, 0xbeef0ee4),
  17488. new Word64(0xc6e00bf3, 0x3da88fc2), new Word64(0xd5a79147, 0x930aa725),
  17489. new Word64(0x06ca6351, 0xe003826f), new Word64(0x14292967, 0x0a0e6e70),
  17490. new Word64(0x27b70a85, 0x46d22ffc), new Word64(0x2e1b2138, 0x5c26c926),
  17491. new Word64(0x4d2c6dfc, 0x5ac42aed), new Word64(0x53380d13, 0x9d95b3df),
  17492. new Word64(0x650a7354, 0x8baf63de), new Word64(0x766a0abb, 0x3c77b2a8),
  17493. new Word64(0x81c2c92e, 0x47edaee6), new Word64(0x92722c85, 0x1482353b),
  17494. new Word64(0xa2bfe8a1, 0x4cf10364), new Word64(0xa81a664b, 0xbc423001),
  17495. new Word64(0xc24b8b70, 0xd0f89791), new Word64(0xc76c51a3, 0x0654be30),
  17496. new Word64(0xd192e819, 0xd6ef5218), new Word64(0xd6990624, 0x5565a910),
  17497. new Word64(0xf40e3585, 0x5771202a), new Word64(0x106aa070, 0x32bbd1b8),
  17498. new Word64(0x19a4c116, 0xb8d2d0c8), new Word64(0x1e376c08, 0x5141ab53),
  17499. new Word64(0x2748774c, 0xdf8eeb99), new Word64(0x34b0bcb5, 0xe19b48a8),
  17500. new Word64(0x391c0cb3, 0xc5c95a63), new Word64(0x4ed8aa4a, 0xe3418acb),
  17501. new Word64(0x5b9cca4f, 0x7763e373), new Word64(0x682e6ff3, 0xd6b2b8a3),
  17502. new Word64(0x748f82ee, 0x5defb2fc), new Word64(0x78a5636f, 0x43172f60),
  17503. new Word64(0x84c87814, 0xa1f0ab72), new Word64(0x8cc70208, 0x1a6439ec),
  17504. new Word64(0x90befffa, 0x23631e28), new Word64(0xa4506ceb, 0xde82bde9),
  17505. new Word64(0xbef9a3f7, 0xb2c67915), new Word64(0xc67178f2, 0xe372532b),
  17506. new Word64(0xca273ece, 0xea26619c), new Word64(0xd186b8c7, 0x21c0c207),
  17507. new Word64(0xeada7dd6, 0xcde0eb1e), new Word64(0xf57d4f7f, 0xee6ed178),
  17508. new Word64(0x06f067aa, 0x72176fba), new Word64(0x0a637dc5, 0xa2c898a6),
  17509. new Word64(0x113f9804, 0xbef90dae), new Word64(0x1b710b35, 0x131c471b),
  17510. new Word64(0x28db77f5, 0x23047d84), new Word64(0x32caab7b, 0x40c72493),
  17511. new Word64(0x3c9ebe0a, 0x15c9bebc), new Word64(0x431d67c4, 0x9c100d4c),
  17512. new Word64(0x4cc5d4be, 0xcb3e42b6), new Word64(0x597f299c, 0xfc657e2a),
  17513. new Word64(0x5fcb6fab, 0x3ad6faec), new Word64(0x6c44198c, 0x4a475817)];
  17514. function hash(data, offset, length, mode384) {
  17515. mode384 = !!mode384;
  17516. // initial hash values
  17517. var h0, h1, h2, h3, h4, h5, h6, h7;
  17518. if (!mode384) {
  17519. h0 = new Word64(0x6a09e667, 0xf3bcc908);
  17520. h1 = new Word64(0xbb67ae85, 0x84caa73b);
  17521. h2 = new Word64(0x3c6ef372, 0xfe94f82b);
  17522. h3 = new Word64(0xa54ff53a, 0x5f1d36f1);
  17523. h4 = new Word64(0x510e527f, 0xade682d1);
  17524. h5 = new Word64(0x9b05688c, 0x2b3e6c1f);
  17525. h6 = new Word64(0x1f83d9ab, 0xfb41bd6b);
  17526. h7 = new Word64(0x5be0cd19, 0x137e2179);
  17527. }
  17528. else {
  17529. // SHA384 is exactly the same
  17530. // except with different starting values and a trimmed result
  17531. h0 = new Word64(0xcbbb9d5d, 0xc1059ed8);
  17532. h1 = new Word64(0x629a292a, 0x367cd507);
  17533. h2 = new Word64(0x9159015a, 0x3070dd17);
  17534. h3 = new Word64(0x152fecd8, 0xf70e5939);
  17535. h4 = new Word64(0x67332667, 0xffc00b31);
  17536. h5 = new Word64(0x8eb44a87, 0x68581511);
  17537. h6 = new Word64(0xdb0c2e0d, 0x64f98fa7);
  17538. h7 = new Word64(0x47b5481d, 0xbefa4fa4);
  17539. }
  17540. // pre-processing
  17541. var paddedLength = Math.ceil((length + 17) / 128) * 128;
  17542. var padded = new Uint8Array(paddedLength);
  17543. var i, j, n;
  17544. for (i = 0; i < length; ++i) {
  17545. padded[i] = data[offset++];
  17546. }
  17547. padded[i++] = 0x80;
  17548. n = paddedLength - 16;
  17549. while (i < n) {
  17550. padded[i++] = 0;
  17551. }
  17552. padded[i++] = 0;
  17553. padded[i++] = 0;
  17554. padded[i++] = 0;
  17555. padded[i++] = 0;
  17556. padded[i++] = 0;
  17557. padded[i++] = 0;
  17558. padded[i++] = 0;
  17559. padded[i++] = 0;
  17560. padded[i++] = 0;
  17561. padded[i++] = 0;
  17562. padded[i++] = 0;
  17563. padded[i++] = (length >>> 29) & 0xFF;
  17564. padded[i++] = (length >> 21) & 0xFF;
  17565. padded[i++] = (length >> 13) & 0xFF;
  17566. padded[i++] = (length >> 5) & 0xFF;
  17567. padded[i++] = (length << 3) & 0xFF;
  17568. var w = new Array(80);
  17569. for (i = 0; i < 80; i++) {
  17570. w[i] = new Word64(0, 0);
  17571. }
  17572. var a = new Word64(0, 0), b = new Word64(0, 0), c = new Word64(0, 0);
  17573. var d = new Word64(0, 0), e = new Word64(0, 0), f = new Word64(0, 0);
  17574. var g = new Word64(0, 0), h = new Word64(0, 0);
  17575. var t1 = new Word64(0, 0), t2 = new Word64(0, 0);
  17576. var tmp1 = new Word64(0, 0), tmp2 = new Word64(0, 0), tmp3;
  17577. // for each 1024 bit block
  17578. for (i = 0; i < paddedLength;) {
  17579. for (j = 0; j < 16; ++j) {
  17580. w[j].high = (padded[i] << 24) | (padded[i + 1] << 16) |
  17581. (padded[i + 2] << 8) | (padded[i + 3]);
  17582. w[j].low = (padded[i + 4]) << 24 | (padded[i + 5]) << 16 |
  17583. (padded[i + 6]) << 8 | (padded[i + 7]);
  17584. i += 8;
  17585. }
  17586. for (j = 16; j < 80; ++j) {
  17587. tmp3 = w[j];
  17588. littleSigmaPrime(tmp3, w[j - 2], tmp2);
  17589. tmp3.add(w[j - 7]);
  17590. littleSigma(tmp1, w[j - 15], tmp2);
  17591. tmp3.add(tmp1);
  17592. tmp3.add(w[j - 16]);
  17593. }
  17594. a.assign(h0); b.assign(h1); c.assign(h2); d.assign(h3);
  17595. e.assign(h4); f.assign(h5); g.assign(h6); h.assign(h7);
  17596. for (j = 0; j < 80; ++j) {
  17597. t1.assign(h);
  17598. sigmaPrime(tmp1, e, tmp2);
  17599. t1.add(tmp1);
  17600. ch(tmp1, e, f, g, tmp2);
  17601. t1.add(tmp1);
  17602. t1.add(k[j]);
  17603. t1.add(w[j]);
  17604. sigma(t2, a, tmp2);
  17605. maj(tmp1, a, b, c, tmp2);
  17606. t2.add(tmp1);
  17607. tmp3 = h;
  17608. h = g;
  17609. g = f;
  17610. f = e;
  17611. d.add(t1);
  17612. e = d;
  17613. d = c;
  17614. c = b;
  17615. b = a;
  17616. tmp3.assign(t1);
  17617. tmp3.add(t2);
  17618. a = tmp3;
  17619. }
  17620. h0.add(a);
  17621. h1.add(b);
  17622. h2.add(c);
  17623. h3.add(d);
  17624. h4.add(e);
  17625. h5.add(f);
  17626. h6.add(g);
  17627. h7.add(h);
  17628. }
  17629. var result;
  17630. if (!mode384) {
  17631. result = new Uint8Array(64);
  17632. h0.copyTo(result,0);
  17633. h1.copyTo(result,8);
  17634. h2.copyTo(result,16);
  17635. h3.copyTo(result,24);
  17636. h4.copyTo(result,32);
  17637. h5.copyTo(result,40);
  17638. h6.copyTo(result,48);
  17639. h7.copyTo(result,56);
  17640. }
  17641. else {
  17642. result = new Uint8Array(48);
  17643. h0.copyTo(result,0);
  17644. h1.copyTo(result,8);
  17645. h2.copyTo(result,16);
  17646. h3.copyTo(result,24);
  17647. h4.copyTo(result,32);
  17648. h5.copyTo(result,40);
  17649. }
  17650. return result;
  17651. }
  17652. return hash;
  17653. })();
  17654. var calculateSHA384 = (function calculateSHA384Closure() {
  17655. function hash(data, offset, length) {
  17656. return calculateSHA512(data, offset, length, true);
  17657. }
  17658. return hash;
  17659. })();
  17660. var NullCipher = (function NullCipherClosure() {
  17661. function NullCipher() {
  17662. }
  17663. NullCipher.prototype = {
  17664. decryptBlock: function NullCipher_decryptBlock(data) {
  17665. return data;
  17666. }
  17667. };
  17668. return NullCipher;
  17669. })();
  17670. var AES128Cipher = (function AES128CipherClosure() {
  17671. var rcon = new Uint8Array([
  17672. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  17673. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  17674. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  17675. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  17676. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  17677. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  17678. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  17679. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  17680. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  17681. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  17682. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  17683. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  17684. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  17685. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  17686. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  17687. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  17688. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  17689. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  17690. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  17691. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  17692. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  17693. 0x74, 0xe8, 0xcb, 0x8d]);
  17694. var s = new Uint8Array([
  17695. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  17696. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  17697. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  17698. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  17699. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  17700. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  17701. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  17702. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  17703. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  17704. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  17705. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  17706. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  17707. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  17708. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  17709. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  17710. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  17711. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  17712. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  17713. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  17714. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  17715. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  17716. 0xb0, 0x54, 0xbb, 0x16]);
  17717. var inv_s = new Uint8Array([
  17718. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  17719. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  17720. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  17721. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  17722. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  17723. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  17724. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  17725. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  17726. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  17727. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  17728. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  17729. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  17730. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  17731. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  17732. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  17733. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  17734. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  17735. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  17736. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  17737. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  17738. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  17739. 0x55, 0x21, 0x0c, 0x7d]);
  17740. var mixCol = new Uint8Array(256);
  17741. for (var i = 0; i < 256; i++) {
  17742. if (i < 128) {
  17743. mixCol[i] = i << 1;
  17744. } else {
  17745. mixCol[i] = (i << 1) ^ 0x1b;
  17746. }
  17747. }
  17748. var mix = new Uint32Array([
  17749. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  17750. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  17751. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  17752. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  17753. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  17754. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  17755. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  17756. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  17757. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  17758. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  17759. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  17760. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  17761. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  17762. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  17763. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  17764. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  17765. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  17766. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  17767. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  17768. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  17769. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  17770. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  17771. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  17772. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  17773. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  17774. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  17775. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  17776. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  17777. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  17778. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  17779. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  17780. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  17781. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  17782. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  17783. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  17784. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  17785. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  17786. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  17787. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  17788. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  17789. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  17790. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  17791. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  17792. function expandKey128(cipherKey) {
  17793. var b = 176, result = new Uint8Array(b);
  17794. result.set(cipherKey);
  17795. for (var j = 16, i = 1; j < b; ++i) {
  17796. // RotWord
  17797. var t1 = result[j - 3], t2 = result[j - 2],
  17798. t3 = result[j - 1], t4 = result[j - 4];
  17799. // SubWord
  17800. t1 = s[t1];
  17801. t2 = s[t2];
  17802. t3 = s[t3];
  17803. t4 = s[t4];
  17804. // Rcon
  17805. t1 = t1 ^ rcon[i];
  17806. for (var n = 0; n < 4; ++n) {
  17807. result[j] = (t1 ^= result[j - 16]);
  17808. j++;
  17809. result[j] = (t2 ^= result[j - 16]);
  17810. j++;
  17811. result[j] = (t3 ^= result[j - 16]);
  17812. j++;
  17813. result[j] = (t4 ^= result[j - 16]);
  17814. j++;
  17815. }
  17816. }
  17817. return result;
  17818. }
  17819. function decrypt128(input, key) {
  17820. var state = new Uint8Array(16);
  17821. state.set(input);
  17822. var i, j, k;
  17823. var t, u, v;
  17824. // AddRoundKey
  17825. for (j = 0, k = 160; j < 16; ++j, ++k) {
  17826. state[j] ^= key[k];
  17827. }
  17828. for (i = 9; i >= 1; --i) {
  17829. // InvShiftRows
  17830. t = state[13];
  17831. state[13] = state[9];
  17832. state[9] = state[5];
  17833. state[5] = state[1];
  17834. state[1] = t;
  17835. t = state[14];
  17836. u = state[10];
  17837. state[14] = state[6];
  17838. state[10] = state[2];
  17839. state[6] = t;
  17840. state[2] = u;
  17841. t = state[15];
  17842. u = state[11];
  17843. v = state[7];
  17844. state[15] = state[3];
  17845. state[11] = t;
  17846. state[7] = u;
  17847. state[3] = v;
  17848. // InvSubBytes
  17849. for (j = 0; j < 16; ++j) {
  17850. state[j] = inv_s[state[j]];
  17851. }
  17852. // AddRoundKey
  17853. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  17854. state[j] ^= key[k];
  17855. }
  17856. // InvMixColumns
  17857. for (j = 0; j < 16; j += 4) {
  17858. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  17859. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  17860. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  17861. (s3 >>> 24) ^ (s3 << 8));
  17862. state[j] = (t >>> 24) & 0xFF;
  17863. state[j + 1] = (t >> 16) & 0xFF;
  17864. state[j + 2] = (t >> 8) & 0xFF;
  17865. state[j + 3] = t & 0xFF;
  17866. }
  17867. }
  17868. // InvShiftRows
  17869. t = state[13];
  17870. state[13] = state[9];
  17871. state[9] = state[5];
  17872. state[5] = state[1];
  17873. state[1] = t;
  17874. t = state[14];
  17875. u = state[10];
  17876. state[14] = state[6];
  17877. state[10] = state[2];
  17878. state[6] = t;
  17879. state[2] = u;
  17880. t = state[15];
  17881. u = state[11];
  17882. v = state[7];
  17883. state[15] = state[3];
  17884. state[11] = t;
  17885. state[7] = u;
  17886. state[3] = v;
  17887. for (j = 0; j < 16; ++j) {
  17888. // InvSubBytes
  17889. state[j] = inv_s[state[j]];
  17890. // AddRoundKey
  17891. state[j] ^= key[j];
  17892. }
  17893. return state;
  17894. }
  17895. function encrypt128(input, key) {
  17896. var t, u, v, k;
  17897. var state = new Uint8Array(16);
  17898. state.set(input);
  17899. for (j = 0; j < 16; ++j) {
  17900. // AddRoundKey
  17901. state[j] ^= key[j];
  17902. }
  17903. for (i = 1; i < 10; i++) {
  17904. //SubBytes
  17905. for (j = 0; j < 16; ++j) {
  17906. state[j] = s[state[j]];
  17907. }
  17908. //ShiftRows
  17909. v = state[1];
  17910. state[1] = state[5];
  17911. state[5] = state[9];
  17912. state[9] = state[13];
  17913. state[13] = v;
  17914. v = state[2];
  17915. u = state[6];
  17916. state[2] = state[10];
  17917. state[6] = state[14];
  17918. state[10] = v;
  17919. state[14] = u;
  17920. v = state[3];
  17921. u = state[7];
  17922. t = state[11];
  17923. state[3] = state[15];
  17924. state[7] = v;
  17925. state[11] = u;
  17926. state[15] = t;
  17927. //MixColumns
  17928. for (var j = 0; j < 16; j += 4) {
  17929. var s0 = state[j + 0], s1 = state[j + 1];
  17930. var s2 = state[j + 2], s3 = state[j + 3];
  17931. t = s0 ^ s1 ^ s2 ^ s3;
  17932. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  17933. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  17934. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  17935. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  17936. }
  17937. //AddRoundKey
  17938. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  17939. state[j] ^= key[k];
  17940. }
  17941. }
  17942. //SubBytes
  17943. for (j = 0; j < 16; ++j) {
  17944. state[j] = s[state[j]];
  17945. }
  17946. //ShiftRows
  17947. v = state[1];
  17948. state[1] = state[5];
  17949. state[5] = state[9];
  17950. state[9] = state[13];
  17951. state[13] = v;
  17952. v = state[2];
  17953. u = state[6];
  17954. state[2] = state[10];
  17955. state[6] = state[14];
  17956. state[10] = v;
  17957. state[14] = u;
  17958. v = state[3];
  17959. u = state[7];
  17960. t = state[11];
  17961. state[3] = state[15];
  17962. state[7] = v;
  17963. state[11] = u;
  17964. state[15] = t;
  17965. //AddRoundKey
  17966. for (j = 0, k = 160; j < 16; ++j, ++k) {
  17967. state[j] ^= key[k];
  17968. }
  17969. return state;
  17970. }
  17971. function AES128Cipher(key) {
  17972. this.key = expandKey128(key);
  17973. this.buffer = new Uint8Array(16);
  17974. this.bufferPosition = 0;
  17975. }
  17976. function decryptBlock2(data, finalize) {
  17977. var i, j, ii, sourceLength = data.length,
  17978. buffer = this.buffer, bufferLength = this.bufferPosition,
  17979. result = [], iv = this.iv;
  17980. for (i = 0; i < sourceLength; ++i) {
  17981. buffer[bufferLength] = data[i];
  17982. ++bufferLength;
  17983. if (bufferLength < 16) {
  17984. continue;
  17985. }
  17986. // buffer is full, decrypting
  17987. var plain = decrypt128(buffer, this.key);
  17988. // xor-ing the IV vector to get plain text
  17989. for (j = 0; j < 16; ++j) {
  17990. plain[j] ^= iv[j];
  17991. }
  17992. iv = buffer;
  17993. result.push(plain);
  17994. buffer = new Uint8Array(16);
  17995. bufferLength = 0;
  17996. }
  17997. // saving incomplete buffer
  17998. this.buffer = buffer;
  17999. this.bufferLength = bufferLength;
  18000. this.iv = iv;
  18001. if (result.length === 0) {
  18002. return new Uint8Array([]);
  18003. }
  18004. // combining plain text blocks into one
  18005. var outputLength = 16 * result.length;
  18006. if (finalize) {
  18007. // undo a padding that is described in RFC 2898
  18008. var lastBlock = result[result.length - 1];
  18009. var psLen = lastBlock[15];
  18010. if (psLen <= 16) {
  18011. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  18012. if (lastBlock[i] !== psLen) {
  18013. // Invalid padding, assume that the block has no padding.
  18014. psLen = 0;
  18015. break;
  18016. }
  18017. }
  18018. outputLength -= psLen;
  18019. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  18020. }
  18021. }
  18022. var output = new Uint8Array(outputLength);
  18023. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  18024. output.set(result[i], j);
  18025. }
  18026. return output;
  18027. }
  18028. AES128Cipher.prototype = {
  18029. decryptBlock: function AES128Cipher_decryptBlock(data, finalize) {
  18030. var i, sourceLength = data.length;
  18031. var buffer = this.buffer, bufferLength = this.bufferPosition;
  18032. // waiting for IV values -- they are at the start of the stream
  18033. for (i = 0; bufferLength < 16 && i < sourceLength; ++i, ++bufferLength) {
  18034. buffer[bufferLength] = data[i];
  18035. }
  18036. if (bufferLength < 16) {
  18037. // need more data
  18038. this.bufferLength = bufferLength;
  18039. return new Uint8Array([]);
  18040. }
  18041. this.iv = buffer;
  18042. this.buffer = new Uint8Array(16);
  18043. this.bufferLength = 0;
  18044. // starting decryption
  18045. this.decryptBlock = decryptBlock2;
  18046. return this.decryptBlock(data.subarray(16), finalize);
  18047. },
  18048. encrypt: function AES128Cipher_encrypt(data, iv) {
  18049. var i, j, ii, sourceLength = data.length,
  18050. buffer = this.buffer, bufferLength = this.bufferPosition,
  18051. result = [];
  18052. if (!iv) {
  18053. iv = new Uint8Array(16);
  18054. }
  18055. for (i = 0; i < sourceLength; ++i) {
  18056. buffer[bufferLength] = data[i];
  18057. ++bufferLength;
  18058. if (bufferLength < 16) {
  18059. continue;
  18060. }
  18061. for (j = 0; j < 16; ++j) {
  18062. buffer[j] ^= iv[j];
  18063. }
  18064. // buffer is full, encrypting
  18065. var cipher = encrypt128(buffer, this.key);
  18066. iv = cipher;
  18067. result.push(cipher);
  18068. buffer = new Uint8Array(16);
  18069. bufferLength = 0;
  18070. }
  18071. // saving incomplete buffer
  18072. this.buffer = buffer;
  18073. this.bufferLength = bufferLength;
  18074. this.iv = iv;
  18075. if (result.length === 0) {
  18076. return new Uint8Array([]);
  18077. }
  18078. // combining plain text blocks into one
  18079. var outputLength = 16 * result.length;
  18080. var output = new Uint8Array(outputLength);
  18081. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  18082. output.set(result[i], j);
  18083. }
  18084. return output;
  18085. }
  18086. };
  18087. return AES128Cipher;
  18088. })();
  18089. var AES256Cipher = (function AES256CipherClosure() {
  18090. var rcon = new Uint8Array([
  18091. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  18092. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  18093. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  18094. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  18095. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  18096. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  18097. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  18098. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  18099. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  18100. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  18101. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  18102. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  18103. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  18104. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  18105. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  18106. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  18107. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  18108. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  18109. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  18110. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  18111. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  18112. 0x74, 0xe8, 0xcb, 0x8d]);
  18113. var s = new Uint8Array([
  18114. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  18115. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  18116. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  18117. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  18118. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  18119. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  18120. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  18121. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  18122. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  18123. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  18124. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  18125. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  18126. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  18127. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  18128. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  18129. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  18130. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  18131. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  18132. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  18133. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  18134. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  18135. 0xb0, 0x54, 0xbb, 0x16]);
  18136. var inv_s = new Uint8Array([
  18137. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  18138. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  18139. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  18140. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  18141. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  18142. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  18143. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  18144. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  18145. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  18146. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  18147. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  18148. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  18149. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  18150. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  18151. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  18152. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  18153. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  18154. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  18155. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  18156. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  18157. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  18158. 0x55, 0x21, 0x0c, 0x7d]);
  18159. var mixCol = new Uint8Array(256);
  18160. for (var i = 0; i < 256; i++) {
  18161. if (i < 128) {
  18162. mixCol[i] = i << 1;
  18163. } else {
  18164. mixCol[i] = (i << 1) ^ 0x1b;
  18165. }
  18166. }
  18167. var mix = new Uint32Array([
  18168. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  18169. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  18170. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  18171. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  18172. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  18173. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  18174. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  18175. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  18176. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  18177. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  18178. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  18179. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  18180. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  18181. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  18182. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  18183. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  18184. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  18185. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  18186. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  18187. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  18188. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  18189. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  18190. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  18191. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  18192. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  18193. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  18194. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  18195. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  18196. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  18197. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  18198. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  18199. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  18200. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  18201. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  18202. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  18203. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  18204. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  18205. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  18206. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  18207. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  18208. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  18209. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  18210. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  18211. function expandKey256(cipherKey) {
  18212. var b = 240, result = new Uint8Array(b);
  18213. var r = 1;
  18214. result.set(cipherKey);
  18215. for (var j = 32, i = 1; j < b; ++i) {
  18216. if (j % 32 === 16) {
  18217. t1 = s[t1];
  18218. t2 = s[t2];
  18219. t3 = s[t3];
  18220. t4 = s[t4];
  18221. } else if (j % 32 === 0) {
  18222. // RotWord
  18223. var t1 = result[j - 3], t2 = result[j - 2],
  18224. t3 = result[j - 1], t4 = result[j - 4];
  18225. // SubWord
  18226. t1 = s[t1];
  18227. t2 = s[t2];
  18228. t3 = s[t3];
  18229. t4 = s[t4];
  18230. // Rcon
  18231. t1 = t1 ^ r;
  18232. if ((r <<= 1) >= 256) {
  18233. r = (r ^ 0x1b) & 0xFF;
  18234. }
  18235. }
  18236. for (var n = 0; n < 4; ++n) {
  18237. result[j] = (t1 ^= result[j - 32]);
  18238. j++;
  18239. result[j] = (t2 ^= result[j - 32]);
  18240. j++;
  18241. result[j] = (t3 ^= result[j - 32]);
  18242. j++;
  18243. result[j] = (t4 ^= result[j - 32]);
  18244. j++;
  18245. }
  18246. }
  18247. return result;
  18248. }
  18249. function decrypt256(input, key) {
  18250. var state = new Uint8Array(16);
  18251. state.set(input);
  18252. var i, j, k;
  18253. var t, u, v;
  18254. // AddRoundKey
  18255. for (j = 0, k = 224; j < 16; ++j, ++k) {
  18256. state[j] ^= key[k];
  18257. }
  18258. for (i = 13; i >= 1; --i) {
  18259. // InvShiftRows
  18260. t = state[13];
  18261. state[13] = state[9];
  18262. state[9] = state[5];
  18263. state[5] = state[1];
  18264. state[1] = t;
  18265. t = state[14];
  18266. u = state[10];
  18267. state[14] = state[6];
  18268. state[10] = state[2];
  18269. state[6] = t;
  18270. state[2] = u;
  18271. t = state[15];
  18272. u = state[11];
  18273. v = state[7];
  18274. state[15] = state[3];
  18275. state[11] = t;
  18276. state[7] = u;
  18277. state[3] = v;
  18278. // InvSubBytes
  18279. for (j = 0; j < 16; ++j) {
  18280. state[j] = inv_s[state[j]];
  18281. }
  18282. // AddRoundKey
  18283. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  18284. state[j] ^= key[k];
  18285. }
  18286. // InvMixColumns
  18287. for (j = 0; j < 16; j += 4) {
  18288. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  18289. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  18290. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  18291. (s3 >>> 24) ^ (s3 << 8));
  18292. state[j] = (t >>> 24) & 0xFF;
  18293. state[j + 1] = (t >> 16) & 0xFF;
  18294. state[j + 2] = (t >> 8) & 0xFF;
  18295. state[j + 3] = t & 0xFF;
  18296. }
  18297. }
  18298. // InvShiftRows
  18299. t = state[13];
  18300. state[13] = state[9];
  18301. state[9] = state[5];
  18302. state[5] = state[1];
  18303. state[1] = t;
  18304. t = state[14];
  18305. u = state[10];
  18306. state[14] = state[6];
  18307. state[10] = state[2];
  18308. state[6] = t;
  18309. state[2] = u;
  18310. t = state[15];
  18311. u = state[11];
  18312. v = state[7];
  18313. state[15] = state[3];
  18314. state[11] = t;
  18315. state[7] = u;
  18316. state[3] = v;
  18317. for (j = 0; j < 16; ++j) {
  18318. // InvSubBytes
  18319. state[j] = inv_s[state[j]];
  18320. // AddRoundKey
  18321. state[j] ^= key[j];
  18322. }
  18323. return state;
  18324. }
  18325. function encrypt256(input, key) {
  18326. var t, u, v, k;
  18327. var state = new Uint8Array(16);
  18328. state.set(input);
  18329. for (j = 0; j < 16; ++j) {
  18330. // AddRoundKey
  18331. state[j] ^= key[j];
  18332. }
  18333. for (i = 1; i < 14; i++) {
  18334. //SubBytes
  18335. for (j = 0; j < 16; ++j) {
  18336. state[j] = s[state[j]];
  18337. }
  18338. //ShiftRows
  18339. v = state[1];
  18340. state[1] = state[5];
  18341. state[5] = state[9];
  18342. state[9] = state[13];
  18343. state[13] = v;
  18344. v = state[2];
  18345. u = state[6];
  18346. state[2] = state[10];
  18347. state[6] = state[14];
  18348. state[10] = v;
  18349. state[14] = u;
  18350. v = state[3];
  18351. u = state[7];
  18352. t = state[11];
  18353. state[3] = state[15];
  18354. state[7] = v;
  18355. state[11] = u;
  18356. state[15] = t;
  18357. //MixColumns
  18358. for (var j = 0; j < 16; j += 4) {
  18359. var s0 = state[j + 0], s1 = state[j + 1];
  18360. var s2 = state[j + 2], s3 = state[j + 3];
  18361. t = s0 ^ s1 ^ s2 ^ s3;
  18362. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  18363. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  18364. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  18365. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  18366. }
  18367. //AddRoundKey
  18368. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  18369. state[j] ^= key[k];
  18370. }
  18371. }
  18372. //SubBytes
  18373. for (j = 0; j < 16; ++j) {
  18374. state[j] = s[state[j]];
  18375. }
  18376. //ShiftRows
  18377. v = state[1];
  18378. state[1] = state[5];
  18379. state[5] = state[9];
  18380. state[9] = state[13];
  18381. state[13] = v;
  18382. v = state[2];
  18383. u = state[6];
  18384. state[2] = state[10];
  18385. state[6] = state[14];
  18386. state[10] = v;
  18387. state[14] = u;
  18388. v = state[3];
  18389. u = state[7];
  18390. t = state[11];
  18391. state[3] = state[15];
  18392. state[7] = v;
  18393. state[11] = u;
  18394. state[15] = t;
  18395. //AddRoundKey
  18396. for (j = 0, k = 224; j < 16; ++j, ++k) {
  18397. state[j] ^= key[k];
  18398. }
  18399. return state;
  18400. }
  18401. function AES256Cipher(key) {
  18402. this.key = expandKey256(key);
  18403. this.buffer = new Uint8Array(16);
  18404. this.bufferPosition = 0;
  18405. }
  18406. function decryptBlock2(data, finalize) {
  18407. var i, j, ii, sourceLength = data.length,
  18408. buffer = this.buffer, bufferLength = this.bufferPosition,
  18409. result = [], iv = this.iv;
  18410. for (i = 0; i < sourceLength; ++i) {
  18411. buffer[bufferLength] = data[i];
  18412. ++bufferLength;
  18413. if (bufferLength < 16) {
  18414. continue;
  18415. }
  18416. // buffer is full, decrypting
  18417. var plain = decrypt256(buffer, this.key);
  18418. // xor-ing the IV vector to get plain text
  18419. for (j = 0; j < 16; ++j) {
  18420. plain[j] ^= iv[j];
  18421. }
  18422. iv = buffer;
  18423. result.push(plain);
  18424. buffer = new Uint8Array(16);
  18425. bufferLength = 0;
  18426. }
  18427. // saving incomplete buffer
  18428. this.buffer = buffer;
  18429. this.bufferLength = bufferLength;
  18430. this.iv = iv;
  18431. if (result.length === 0) {
  18432. return new Uint8Array([]);
  18433. }
  18434. // combining plain text blocks into one
  18435. var outputLength = 16 * result.length;
  18436. if (finalize) {
  18437. // undo a padding that is described in RFC 2898
  18438. var lastBlock = result[result.length - 1];
  18439. var psLen = lastBlock[15];
  18440. if (psLen <= 16) {
  18441. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  18442. if (lastBlock[i] !== psLen) {
  18443. // Invalid padding, assume that the block has no padding.
  18444. psLen = 0;
  18445. break;
  18446. }
  18447. }
  18448. outputLength -= psLen;
  18449. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  18450. }
  18451. }
  18452. var output = new Uint8Array(outputLength);
  18453. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  18454. output.set(result[i], j);
  18455. }
  18456. return output;
  18457. }
  18458. AES256Cipher.prototype = {
  18459. decryptBlock: function AES256Cipher_decryptBlock(data, finalize, iv) {
  18460. var i, sourceLength = data.length;
  18461. var buffer = this.buffer, bufferLength = this.bufferPosition;
  18462. // if not supplied an IV wait for IV values
  18463. // they are at the start of the stream
  18464. if (iv) {
  18465. this.iv = iv;
  18466. } else {
  18467. for (i = 0; bufferLength < 16 &&
  18468. i < sourceLength; ++i, ++bufferLength) {
  18469. buffer[bufferLength] = data[i];
  18470. }
  18471. if (bufferLength < 16) {
  18472. //need more data
  18473. this.bufferLength = bufferLength;
  18474. return new Uint8Array([]);
  18475. }
  18476. this.iv = buffer;
  18477. data = data.subarray(16);
  18478. }
  18479. this.buffer = new Uint8Array(16);
  18480. this.bufferLength = 0;
  18481. // starting decryption
  18482. this.decryptBlock = decryptBlock2;
  18483. return this.decryptBlock(data, finalize);
  18484. },
  18485. encrypt: function AES256Cipher_encrypt(data, iv) {
  18486. var i, j, ii, sourceLength = data.length,
  18487. buffer = this.buffer, bufferLength = this.bufferPosition,
  18488. result = [];
  18489. if (!iv) {
  18490. iv = new Uint8Array(16);
  18491. }
  18492. for (i = 0; i < sourceLength; ++i) {
  18493. buffer[bufferLength] = data[i];
  18494. ++bufferLength;
  18495. if (bufferLength < 16) {
  18496. continue;
  18497. }
  18498. for (j = 0; j < 16; ++j) {
  18499. buffer[j] ^= iv[j];
  18500. }
  18501. // buffer is full, encrypting
  18502. var cipher = encrypt256(buffer, this.key);
  18503. this.iv = cipher;
  18504. result.push(cipher);
  18505. buffer = new Uint8Array(16);
  18506. bufferLength = 0;
  18507. }
  18508. // saving incomplete buffer
  18509. this.buffer = buffer;
  18510. this.bufferLength = bufferLength;
  18511. this.iv = iv;
  18512. if (result.length === 0) {
  18513. return new Uint8Array([]);
  18514. }
  18515. // combining plain text blocks into one
  18516. var outputLength = 16 * result.length;
  18517. var output = new Uint8Array(outputLength);
  18518. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  18519. output.set(result[i], j);
  18520. }
  18521. return output;
  18522. }
  18523. };
  18524. return AES256Cipher;
  18525. })();
  18526. var PDF17 = (function PDF17Closure() {
  18527. function compareByteArrays(array1, array2) {
  18528. if (array1.length !== array2.length) {
  18529. return false;
  18530. }
  18531. for (var i = 0; i < array1.length; i++) {
  18532. if (array1[i] !== array2[i]) {
  18533. return false;
  18534. }
  18535. }
  18536. return true;
  18537. }
  18538. function PDF17() {
  18539. }
  18540. PDF17.prototype = {
  18541. checkOwnerPassword: function PDF17_checkOwnerPassword(password,
  18542. ownerValidationSalt,
  18543. userBytes,
  18544. ownerPassword) {
  18545. var hashData = new Uint8Array(password.length + 56);
  18546. hashData.set(password, 0);
  18547. hashData.set(ownerValidationSalt, password.length);
  18548. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  18549. var result = calculateSHA256(hashData, 0, hashData.length);
  18550. return compareByteArrays(result, ownerPassword);
  18551. },
  18552. checkUserPassword: function PDF17_checkUserPassword(password,
  18553. userValidationSalt,
  18554. userPassword) {
  18555. var hashData = new Uint8Array(password.length + 8);
  18556. hashData.set(password, 0);
  18557. hashData.set(userValidationSalt, password.length);
  18558. var result = calculateSHA256(hashData, 0, hashData.length);
  18559. return compareByteArrays(result, userPassword);
  18560. },
  18561. getOwnerKey: function PDF17_getOwnerKey(password, ownerKeySalt, userBytes,
  18562. ownerEncryption) {
  18563. var hashData = new Uint8Array(password.length + 56);
  18564. hashData.set(password, 0);
  18565. hashData.set(ownerKeySalt, password.length);
  18566. hashData.set(userBytes, password.length + ownerKeySalt.length);
  18567. var key = calculateSHA256(hashData, 0, hashData.length);
  18568. var cipher = new AES256Cipher(key);
  18569. return cipher.decryptBlock(ownerEncryption,
  18570. false,
  18571. new Uint8Array(16));
  18572. },
  18573. getUserKey: function PDF17_getUserKey(password, userKeySalt,
  18574. userEncryption) {
  18575. var hashData = new Uint8Array(password.length + 8);
  18576. hashData.set(password, 0);
  18577. hashData.set(userKeySalt, password.length);
  18578. //key is the decryption key for the UE string
  18579. var key = calculateSHA256(hashData, 0, hashData.length);
  18580. var cipher = new AES256Cipher(key);
  18581. return cipher.decryptBlock(userEncryption,
  18582. false,
  18583. new Uint8Array(16));
  18584. }
  18585. };
  18586. return PDF17;
  18587. })();
  18588. var PDF20 = (function PDF20Closure() {
  18589. function concatArrays(array1, array2) {
  18590. var t = new Uint8Array(array1.length + array2.length);
  18591. t.set(array1, 0);
  18592. t.set(array2, array1.length);
  18593. return t;
  18594. }
  18595. function calculatePDF20Hash(password, input, userBytes) {
  18596. //This refers to Algorithm 2.B as defined in ISO 32000-2
  18597. var k = calculateSHA256(input, 0, input.length).subarray(0, 32);
  18598. var e = [0];
  18599. var i = 0;
  18600. while (i < 64 || e[e.length - 1] > i - 32) {
  18601. var arrayLength = password.length + k.length + userBytes.length;
  18602. var k1 = new Uint8Array(arrayLength * 64);
  18603. var array = concatArrays(password, k);
  18604. array = concatArrays(array, userBytes);
  18605. for (var j = 0, pos = 0; j < 64; j++, pos += arrayLength) {
  18606. k1.set(array, pos);
  18607. }
  18608. //AES128 CBC NO PADDING with
  18609. //first 16 bytes of k as the key and the second 16 as the iv.
  18610. var cipher = new AES128Cipher(k.subarray(0, 16));
  18611. e = cipher.encrypt(k1, k.subarray(16, 32));
  18612. //Now we have to take the first 16 bytes of an unsigned
  18613. //big endian integer... and compute the remainder
  18614. //modulo 3.... That is a fairly large number and
  18615. //JavaScript isn't going to handle that well...
  18616. //So we're using a trick that allows us to perform
  18617. //modulo math byte by byte
  18618. var remainder = 0;
  18619. for (var z = 0; z < 16; z++) {
  18620. remainder *= (256 % 3);
  18621. remainder %= 3;
  18622. remainder += ((e[z] >>> 0) % 3);
  18623. remainder %= 3;
  18624. }
  18625. if (remainder === 0) {
  18626. k = calculateSHA256(e, 0, e.length);
  18627. }
  18628. else if (remainder === 1) {
  18629. k = calculateSHA384(e, 0, e.length);
  18630. }
  18631. else if (remainder === 2) {
  18632. k = calculateSHA512(e, 0, e.length);
  18633. }
  18634. i++;
  18635. }
  18636. return k.subarray(0, 32);
  18637. }
  18638. function PDF20() {
  18639. }
  18640. function compareByteArrays(array1, array2) {
  18641. if (array1.length !== array2.length) {
  18642. return false;
  18643. }
  18644. for (var i = 0; i < array1.length; i++) {
  18645. if (array1[i] !== array2[i]) {
  18646. return false;
  18647. }
  18648. }
  18649. return true;
  18650. }
  18651. PDF20.prototype = {
  18652. hash: function PDF20_hash(password, concatBytes, userBytes) {
  18653. return calculatePDF20Hash(password, concatBytes, userBytes);
  18654. },
  18655. checkOwnerPassword: function PDF20_checkOwnerPassword(password,
  18656. ownerValidationSalt,
  18657. userBytes,
  18658. ownerPassword) {
  18659. var hashData = new Uint8Array(password.length + 56);
  18660. hashData.set(password, 0);
  18661. hashData.set(ownerValidationSalt, password.length);
  18662. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  18663. var result = calculatePDF20Hash(password, hashData, userBytes);
  18664. return compareByteArrays(result, ownerPassword);
  18665. },
  18666. checkUserPassword: function PDF20_checkUserPassword(password,
  18667. userValidationSalt,
  18668. userPassword) {
  18669. var hashData = new Uint8Array(password.length + 8);
  18670. hashData.set(password, 0);
  18671. hashData.set(userValidationSalt, password.length);
  18672. var result = calculatePDF20Hash(password, hashData, []);
  18673. return compareByteArrays(result, userPassword);
  18674. },
  18675. getOwnerKey: function PDF20_getOwnerKey(password, ownerKeySalt, userBytes,
  18676. ownerEncryption) {
  18677. var hashData = new Uint8Array(password.length + 56);
  18678. hashData.set(password, 0);
  18679. hashData.set(ownerKeySalt, password.length);
  18680. hashData.set(userBytes, password.length + ownerKeySalt.length);
  18681. var key = calculatePDF20Hash(password, hashData, userBytes);
  18682. var cipher = new AES256Cipher(key);
  18683. return cipher.decryptBlock(ownerEncryption,
  18684. false,
  18685. new Uint8Array(16));
  18686. },
  18687. getUserKey: function PDF20_getUserKey(password, userKeySalt,
  18688. userEncryption) {
  18689. var hashData = new Uint8Array(password.length + 8);
  18690. hashData.set(password, 0);
  18691. hashData.set(userKeySalt, password.length);
  18692. //key is the decryption key for the UE string
  18693. var key = calculatePDF20Hash(password, hashData, []);
  18694. var cipher = new AES256Cipher(key);
  18695. return cipher.decryptBlock(userEncryption,
  18696. false,
  18697. new Uint8Array(16));
  18698. }
  18699. };
  18700. return PDF20;
  18701. })();
  18702. var CipherTransform = (function CipherTransformClosure() {
  18703. function CipherTransform(stringCipherConstructor, streamCipherConstructor) {
  18704. this.stringCipherConstructor = stringCipherConstructor;
  18705. this.streamCipherConstructor = streamCipherConstructor;
  18706. }
  18707. CipherTransform.prototype = {
  18708. createStream: function CipherTransform_createStream(stream, length) {
  18709. var cipher = new this.streamCipherConstructor();
  18710. return new DecryptStream(stream, length,
  18711. function cipherTransformDecryptStream(data, finalize) {
  18712. return cipher.decryptBlock(data, finalize);
  18713. }
  18714. );
  18715. },
  18716. decryptString: function CipherTransform_decryptString(s) {
  18717. var cipher = new this.stringCipherConstructor();
  18718. var data = stringToBytes(s);
  18719. data = cipher.decryptBlock(data, true);
  18720. return bytesToString(data);
  18721. }
  18722. };
  18723. return CipherTransform;
  18724. })();
  18725. var CipherTransformFactory = (function CipherTransformFactoryClosure() {
  18726. var defaultPasswordBytes = new Uint8Array([
  18727. 0x28, 0xBF, 0x4E, 0x5E, 0x4E, 0x75, 0x8A, 0x41,
  18728. 0x64, 0x00, 0x4E, 0x56, 0xFF, 0xFA, 0x01, 0x08,
  18729. 0x2E, 0x2E, 0x00, 0xB6, 0xD0, 0x68, 0x3E, 0x80,
  18730. 0x2F, 0x0C, 0xA9, 0xFE, 0x64, 0x53, 0x69, 0x7A]);
  18731. function createEncryptionKey20(revision, password, ownerPassword,
  18732. ownerValidationSalt, ownerKeySalt, uBytes,
  18733. userPassword, userValidationSalt, userKeySalt,
  18734. ownerEncryption, userEncryption, perms) {
  18735. if (password) {
  18736. var passwordLength = Math.min(127, password.length);
  18737. password = password.subarray(0, passwordLength);
  18738. } else {
  18739. password = [];
  18740. }
  18741. var pdfAlgorithm;
  18742. if (revision === 6) {
  18743. pdfAlgorithm = new PDF20();
  18744. } else {
  18745. pdfAlgorithm = new PDF17();
  18746. }
  18747. if (pdfAlgorithm) {
  18748. if (pdfAlgorithm.checkUserPassword(password, userValidationSalt,
  18749. userPassword)) {
  18750. return pdfAlgorithm.getUserKey(password, userKeySalt, userEncryption);
  18751. } else if (password.length && pdfAlgorithm.checkOwnerPassword(password,
  18752. ownerValidationSalt,
  18753. uBytes,
  18754. ownerPassword)) {
  18755. return pdfAlgorithm.getOwnerKey(password, ownerKeySalt, uBytes,
  18756. ownerEncryption);
  18757. }
  18758. }
  18759. return null;
  18760. }
  18761. function prepareKeyData(fileId, password, ownerPassword, userPassword,
  18762. flags, revision, keyLength, encryptMetadata) {
  18763. var hashDataSize = 40 + ownerPassword.length + fileId.length;
  18764. var hashData = new Uint8Array(hashDataSize), i = 0, j, n;
  18765. if (password) {
  18766. n = Math.min(32, password.length);
  18767. for (; i < n; ++i) {
  18768. hashData[i] = password[i];
  18769. }
  18770. }
  18771. j = 0;
  18772. while (i < 32) {
  18773. hashData[i++] = defaultPasswordBytes[j++];
  18774. }
  18775. // as now the padded password in the hashData[0..i]
  18776. for (j = 0, n = ownerPassword.length; j < n; ++j) {
  18777. hashData[i++] = ownerPassword[j];
  18778. }
  18779. hashData[i++] = flags & 0xFF;
  18780. hashData[i++] = (flags >> 8) & 0xFF;
  18781. hashData[i++] = (flags >> 16) & 0xFF;
  18782. hashData[i++] = (flags >>> 24) & 0xFF;
  18783. for (j = 0, n = fileId.length; j < n; ++j) {
  18784. hashData[i++] = fileId[j];
  18785. }
  18786. if (revision >= 4 && !encryptMetadata) {
  18787. hashData[i++] = 0xFF;
  18788. hashData[i++] = 0xFF;
  18789. hashData[i++] = 0xFF;
  18790. hashData[i++] = 0xFF;
  18791. }
  18792. var hash = calculateMD5(hashData, 0, i);
  18793. var keyLengthInBytes = keyLength >> 3;
  18794. if (revision >= 3) {
  18795. for (j = 0; j < 50; ++j) {
  18796. hash = calculateMD5(hash, 0, keyLengthInBytes);
  18797. }
  18798. }
  18799. var encryptionKey = hash.subarray(0, keyLengthInBytes);
  18800. var cipher, checkData;
  18801. if (revision >= 3) {
  18802. for (i = 0; i < 32; ++i) {
  18803. hashData[i] = defaultPasswordBytes[i];
  18804. }
  18805. for (j = 0, n = fileId.length; j < n; ++j) {
  18806. hashData[i++] = fileId[j];
  18807. }
  18808. cipher = new ARCFourCipher(encryptionKey);
  18809. checkData = cipher.encryptBlock(calculateMD5(hashData, 0, i));
  18810. n = encryptionKey.length;
  18811. var derivedKey = new Uint8Array(n), k;
  18812. for (j = 1; j <= 19; ++j) {
  18813. for (k = 0; k < n; ++k) {
  18814. derivedKey[k] = encryptionKey[k] ^ j;
  18815. }
  18816. cipher = new ARCFourCipher(derivedKey);
  18817. checkData = cipher.encryptBlock(checkData);
  18818. }
  18819. for (j = 0, n = checkData.length; j < n; ++j) {
  18820. if (userPassword[j] !== checkData[j]) {
  18821. return null;
  18822. }
  18823. }
  18824. } else {
  18825. cipher = new ARCFourCipher(encryptionKey);
  18826. checkData = cipher.encryptBlock(defaultPasswordBytes);
  18827. for (j = 0, n = checkData.length; j < n; ++j) {
  18828. if (userPassword[j] !== checkData[j]) {
  18829. return null;
  18830. }
  18831. }
  18832. }
  18833. return encryptionKey;
  18834. }
  18835. function decodeUserPassword(password, ownerPassword, revision, keyLength) {
  18836. var hashData = new Uint8Array(32), i = 0, j, n;
  18837. n = Math.min(32, password.length);
  18838. for (; i < n; ++i) {
  18839. hashData[i] = password[i];
  18840. }
  18841. j = 0;
  18842. while (i < 32) {
  18843. hashData[i++] = defaultPasswordBytes[j++];
  18844. }
  18845. var hash = calculateMD5(hashData, 0, i);
  18846. var keyLengthInBytes = keyLength >> 3;
  18847. if (revision >= 3) {
  18848. for (j = 0; j < 50; ++j) {
  18849. hash = calculateMD5(hash, 0, hash.length);
  18850. }
  18851. }
  18852. var cipher, userPassword;
  18853. if (revision >= 3) {
  18854. userPassword = ownerPassword;
  18855. var derivedKey = new Uint8Array(keyLengthInBytes), k;
  18856. for (j = 19; j >= 0; j--) {
  18857. for (k = 0; k < keyLengthInBytes; ++k) {
  18858. derivedKey[k] = hash[k] ^ j;
  18859. }
  18860. cipher = new ARCFourCipher(derivedKey);
  18861. userPassword = cipher.encryptBlock(userPassword);
  18862. }
  18863. } else {
  18864. cipher = new ARCFourCipher(hash.subarray(0, keyLengthInBytes));
  18865. userPassword = cipher.encryptBlock(ownerPassword);
  18866. }
  18867. return userPassword;
  18868. }
  18869. var identityName = Name.get('Identity');
  18870. function CipherTransformFactory(dict, fileId, password) {
  18871. var filter = dict.get('Filter');
  18872. if (!isName(filter) || filter.name !== 'Standard') {
  18873. error('unknown encryption method');
  18874. }
  18875. this.dict = dict;
  18876. var algorithm = dict.get('V');
  18877. if (!isInt(algorithm) ||
  18878. (algorithm !== 1 && algorithm !== 2 && algorithm !== 4 &&
  18879. algorithm !== 5)) {
  18880. error('unsupported encryption algorithm');
  18881. }
  18882. this.algorithm = algorithm;
  18883. var keyLength = dict.get('Length') || 40;
  18884. if (!isInt(keyLength) ||
  18885. keyLength < 40 || (keyLength % 8) !== 0) {
  18886. error('invalid key length');
  18887. }
  18888. // prepare keys
  18889. var ownerPassword = stringToBytes(dict.get('O')).subarray(0, 32);
  18890. var userPassword = stringToBytes(dict.get('U')).subarray(0, 32);
  18891. var flags = dict.get('P');
  18892. var revision = dict.get('R');
  18893. // meaningful when V is 4 or 5
  18894. var encryptMetadata = ((algorithm === 4 || algorithm === 5) &&
  18895. dict.get('EncryptMetadata') !== false);
  18896. this.encryptMetadata = encryptMetadata;
  18897. var fileIdBytes = stringToBytes(fileId);
  18898. var passwordBytes;
  18899. if (password) {
  18900. if (revision === 6) {
  18901. try {
  18902. password = utf8StringToString(password);
  18903. } catch (ex) {
  18904. warn('CipherTransformFactory: ' +
  18905. 'Unable to convert UTF8 encoded password.');
  18906. }
  18907. }
  18908. passwordBytes = stringToBytes(password);
  18909. }
  18910. var encryptionKey;
  18911. if (algorithm !== 5) {
  18912. encryptionKey = prepareKeyData(fileIdBytes, passwordBytes,
  18913. ownerPassword, userPassword, flags,
  18914. revision, keyLength, encryptMetadata);
  18915. }
  18916. else {
  18917. var ownerValidationSalt = stringToBytes(dict.get('O')).subarray(32, 40);
  18918. var ownerKeySalt = stringToBytes(dict.get('O')).subarray(40, 48);
  18919. var uBytes = stringToBytes(dict.get('U')).subarray(0, 48);
  18920. var userValidationSalt = stringToBytes(dict.get('U')).subarray(32, 40);
  18921. var userKeySalt = stringToBytes(dict.get('U')).subarray(40, 48);
  18922. var ownerEncryption = stringToBytes(dict.get('OE'));
  18923. var userEncryption = stringToBytes(dict.get('UE'));
  18924. var perms = stringToBytes(dict.get('Perms'));
  18925. encryptionKey =
  18926. createEncryptionKey20(revision, passwordBytes,
  18927. ownerPassword, ownerValidationSalt,
  18928. ownerKeySalt, uBytes,
  18929. userPassword, userValidationSalt,
  18930. userKeySalt, ownerEncryption,
  18931. userEncryption, perms);
  18932. }
  18933. if (!encryptionKey && !password) {
  18934. throw new PasswordException('No password given',
  18935. PasswordResponses.NEED_PASSWORD);
  18936. } else if (!encryptionKey && password) {
  18937. // Attempting use the password as an owner password
  18938. var decodedPassword = decodeUserPassword(passwordBytes, ownerPassword,
  18939. revision, keyLength);
  18940. encryptionKey = prepareKeyData(fileIdBytes, decodedPassword,
  18941. ownerPassword, userPassword, flags,
  18942. revision, keyLength, encryptMetadata);
  18943. }
  18944. if (!encryptionKey) {
  18945. throw new PasswordException('Incorrect Password',
  18946. PasswordResponses.INCORRECT_PASSWORD);
  18947. }
  18948. this.encryptionKey = encryptionKey;
  18949. if (algorithm >= 4) {
  18950. this.cf = dict.get('CF');
  18951. this.stmf = dict.get('StmF') || identityName;
  18952. this.strf = dict.get('StrF') || identityName;
  18953. this.eff = dict.get('EFF') || this.stmf;
  18954. }
  18955. }
  18956. function buildObjectKey(num, gen, encryptionKey, isAes) {
  18957. var key = new Uint8Array(encryptionKey.length + 9), i, n;
  18958. for (i = 0, n = encryptionKey.length; i < n; ++i) {
  18959. key[i] = encryptionKey[i];
  18960. }
  18961. key[i++] = num & 0xFF;
  18962. key[i++] = (num >> 8) & 0xFF;
  18963. key[i++] = (num >> 16) & 0xFF;
  18964. key[i++] = gen & 0xFF;
  18965. key[i++] = (gen >> 8) & 0xFF;
  18966. if (isAes) {
  18967. key[i++] = 0x73;
  18968. key[i++] = 0x41;
  18969. key[i++] = 0x6C;
  18970. key[i++] = 0x54;
  18971. }
  18972. var hash = calculateMD5(key, 0, i);
  18973. return hash.subarray(0, Math.min(encryptionKey.length + 5, 16));
  18974. }
  18975. function buildCipherConstructor(cf, name, num, gen, key) {
  18976. var cryptFilter = cf.get(name.name);
  18977. var cfm;
  18978. if (cryptFilter !== null && cryptFilter !== undefined) {
  18979. cfm = cryptFilter.get('CFM');
  18980. }
  18981. if (!cfm || cfm.name === 'None') {
  18982. return function cipherTransformFactoryBuildCipherConstructorNone() {
  18983. return new NullCipher();
  18984. };
  18985. }
  18986. if ('V2' === cfm.name) {
  18987. return function cipherTransformFactoryBuildCipherConstructorV2() {
  18988. return new ARCFourCipher(buildObjectKey(num, gen, key, false));
  18989. };
  18990. }
  18991. if ('AESV2' === cfm.name) {
  18992. return function cipherTransformFactoryBuildCipherConstructorAESV2() {
  18993. return new AES128Cipher(buildObjectKey(num, gen, key, true));
  18994. };
  18995. }
  18996. if ('AESV3' === cfm.name) {
  18997. return function cipherTransformFactoryBuildCipherConstructorAESV3() {
  18998. return new AES256Cipher(key);
  18999. };
  19000. }
  19001. error('Unknown crypto method');
  19002. }
  19003. CipherTransformFactory.prototype = {
  19004. createCipherTransform:
  19005. function CipherTransformFactory_createCipherTransform(num, gen) {
  19006. if (this.algorithm === 4 || this.algorithm === 5) {
  19007. return new CipherTransform(
  19008. buildCipherConstructor(this.cf, this.stmf,
  19009. num, gen, this.encryptionKey),
  19010. buildCipherConstructor(this.cf, this.strf,
  19011. num, gen, this.encryptionKey));
  19012. }
  19013. // algorithms 1 and 2
  19014. var key = buildObjectKey(num, gen, this.encryptionKey, false);
  19015. var cipherConstructor = function buildCipherCipherConstructor() {
  19016. return new ARCFourCipher(key);
  19017. };
  19018. return new CipherTransform(cipherConstructor, cipherConstructor);
  19019. }
  19020. };
  19021. return CipherTransformFactory;
  19022. })();
  19023. exports.AES128Cipher = AES128Cipher;
  19024. exports.AES256Cipher = AES256Cipher;
  19025. exports.ARCFourCipher = ARCFourCipher;
  19026. exports.CipherTransformFactory = CipherTransformFactory;
  19027. exports.PDF17 = PDF17;
  19028. exports.PDF20 = PDF20;
  19029. exports.calculateMD5 = calculateMD5;
  19030. exports.calculateSHA256 = calculateSHA256;
  19031. exports.calculateSHA384 = calculateSHA384;
  19032. exports.calculateSHA512 = calculateSHA512;
  19033. }));
  19034. (function (root, factory) {
  19035. if (typeof define === 'function' && define.amd) {
  19036. define('pdfjs/core/font_renderer', ['exports', 'pdfjs/shared/util',
  19037. 'pdfjs/core/stream', 'pdfjs/core/glyphlist'], factory);
  19038. } else if (typeof exports !== 'undefined') {
  19039. factory(exports, require('../shared/util.js'), require('./stream.js'),
  19040. require('./glyphlist.js'));
  19041. } else {
  19042. factory((root.pdfjsCoreFontRenderer = {}), root.pdfjsSharedUtil,
  19043. root.pdfjsCoreStream, root.pdfjsCoreGlyphList);
  19044. }
  19045. }(this, function (exports, sharedUtil, coreStream, coreGlyphList) {
  19046. var Util = sharedUtil.Util;
  19047. var bytesToString = sharedUtil.bytesToString;
  19048. var error = sharedUtil.error;
  19049. var Stream = coreStream.Stream;
  19050. var GlyphsUnicode = coreGlyphList.GlyphsUnicode;
  19051. var coreFonts; // see _setCoreFonts below
  19052. var CFFParser; // = coreFonts.CFFParser;
  19053. var Encodings; // = coreFonts.Encodings;
  19054. var FontRendererFactory = (function FontRendererFactoryClosure() {
  19055. function getLong(data, offset) {
  19056. return (data[offset] << 24) | (data[offset + 1] << 16) |
  19057. (data[offset + 2] << 8) | data[offset + 3];
  19058. }
  19059. function getUshort(data, offset) {
  19060. return (data[offset] << 8) | data[offset + 1];
  19061. }
  19062. function parseCmap(data, start, end) {
  19063. var offset = (getUshort(data, start + 2) === 1 ?
  19064. getLong(data, start + 8) : getLong(data, start + 16));
  19065. var format = getUshort(data, start + offset);
  19066. var length, ranges, p, i;
  19067. if (format === 4) {
  19068. length = getUshort(data, start + offset + 2);
  19069. var segCount = getUshort(data, start + offset + 6) >> 1;
  19070. p = start + offset + 14;
  19071. ranges = [];
  19072. for (i = 0; i < segCount; i++, p += 2) {
  19073. ranges[i] = {end: getUshort(data, p)};
  19074. }
  19075. p += 2;
  19076. for (i = 0; i < segCount; i++, p += 2) {
  19077. ranges[i].start = getUshort(data, p);
  19078. }
  19079. for (i = 0; i < segCount; i++, p += 2) {
  19080. ranges[i].idDelta = getUshort(data, p);
  19081. }
  19082. for (i = 0; i < segCount; i++, p += 2) {
  19083. var idOffset = getUshort(data, p);
  19084. if (idOffset === 0) {
  19085. continue;
  19086. }
  19087. ranges[i].ids = [];
  19088. for (var j = 0, jj = ranges[i].end - ranges[i].start + 1; j < jj; j++) {
  19089. ranges[i].ids[j] = getUshort(data, p + idOffset);
  19090. idOffset += 2;
  19091. }
  19092. }
  19093. return ranges;
  19094. } else if (format === 12) {
  19095. length = getLong(data, start + offset + 4);
  19096. var groups = getLong(data, start + offset + 12);
  19097. p = start + offset + 16;
  19098. ranges = [];
  19099. for (i = 0; i < groups; i++) {
  19100. ranges.push({
  19101. start: getLong(data, p),
  19102. end: getLong(data, p + 4),
  19103. idDelta: getLong(data, p + 8) - getLong(data, p)
  19104. });
  19105. p += 12;
  19106. }
  19107. return ranges;
  19108. }
  19109. error('not supported cmap: ' + format);
  19110. }
  19111. function parseCff(data, start, end) {
  19112. var properties = {};
  19113. var parser = new CFFParser(new Stream(data, start, end - start),
  19114. properties);
  19115. var cff = parser.parse();
  19116. return {
  19117. glyphs: cff.charStrings.objects,
  19118. subrs: (cff.topDict.privateDict && cff.topDict.privateDict.subrsIndex &&
  19119. cff.topDict.privateDict.subrsIndex.objects),
  19120. gsubrs: cff.globalSubrIndex && cff.globalSubrIndex.objects
  19121. };
  19122. }
  19123. function parseGlyfTable(glyf, loca, isGlyphLocationsLong) {
  19124. var itemSize, itemDecode;
  19125. if (isGlyphLocationsLong) {
  19126. itemSize = 4;
  19127. itemDecode = function fontItemDecodeLong(data, offset) {
  19128. return (data[offset] << 24) | (data[offset + 1] << 16) |
  19129. (data[offset + 2] << 8) | data[offset + 3];
  19130. };
  19131. } else {
  19132. itemSize = 2;
  19133. itemDecode = function fontItemDecode(data, offset) {
  19134. return (data[offset] << 9) | (data[offset + 1] << 1);
  19135. };
  19136. }
  19137. var glyphs = [];
  19138. var startOffset = itemDecode(loca, 0);
  19139. for (var j = itemSize; j < loca.length; j += itemSize) {
  19140. var endOffset = itemDecode(loca, j);
  19141. glyphs.push(glyf.subarray(startOffset, endOffset));
  19142. startOffset = endOffset;
  19143. }
  19144. return glyphs;
  19145. }
  19146. function lookupCmap(ranges, unicode) {
  19147. var code = unicode.charCodeAt(0);
  19148. var l = 0, r = ranges.length - 1;
  19149. while (l < r) {
  19150. var c = (l + r + 1) >> 1;
  19151. if (code < ranges[c].start) {
  19152. r = c - 1;
  19153. } else {
  19154. l = c;
  19155. }
  19156. }
  19157. if (ranges[l].start <= code && code <= ranges[l].end) {
  19158. return (ranges[l].idDelta + (ranges[l].ids ?
  19159. ranges[l].ids[code - ranges[l].start] : code)) & 0xFFFF;
  19160. }
  19161. return 0;
  19162. }
  19163. function compileGlyf(code, cmds, font) {
  19164. function moveTo(x, y) {
  19165. cmds.push({cmd: 'moveTo', args: [x, y]});
  19166. }
  19167. function lineTo(x, y) {
  19168. cmds.push({cmd: 'lineTo', args: [x, y]});
  19169. }
  19170. function quadraticCurveTo(xa, ya, x, y) {
  19171. cmds.push({cmd: 'quadraticCurveTo', args: [xa, ya, x, y]});
  19172. }
  19173. var i = 0;
  19174. var numberOfContours = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  19175. var flags;
  19176. var x = 0, y = 0;
  19177. i += 10;
  19178. if (numberOfContours < 0) {
  19179. // composite glyph
  19180. do {
  19181. flags = (code[i] << 8) | code[i + 1];
  19182. var glyphIndex = (code[i + 2] << 8) | code[i + 3];
  19183. i += 4;
  19184. var arg1, arg2;
  19185. if ((flags & 0x01)) {
  19186. arg1 = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  19187. arg2 = ((code[i + 2] << 24) | (code[i + 3] << 16)) >> 16;
  19188. i += 4;
  19189. } else {
  19190. arg1 = code[i++]; arg2 = code[i++];
  19191. }
  19192. if ((flags & 0x02)) {
  19193. x = arg1;
  19194. y = arg2;
  19195. } else {
  19196. x = 0; y = 0; // TODO "they are points" ?
  19197. }
  19198. var scaleX = 1, scaleY = 1, scale01 = 0, scale10 = 0;
  19199. if ((flags & 0x08)) {
  19200. scaleX =
  19201. scaleY = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  19202. i += 2;
  19203. } else if ((flags & 0x40)) {
  19204. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  19205. scaleY = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  19206. i += 4;
  19207. } else if ((flags & 0x80)) {
  19208. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  19209. scale01 = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  19210. scale10 = ((code[i + 4] << 24) | (code[i + 5] << 16)) / 1073741824;
  19211. scaleY = ((code[i + 6] << 24) | (code[i + 7] << 16)) / 1073741824;
  19212. i += 8;
  19213. }
  19214. var subglyph = font.glyphs[glyphIndex];
  19215. if (subglyph) {
  19216. cmds.push({cmd: 'save'});
  19217. cmds.push({cmd: 'transform',
  19218. args: [scaleX, scale01, scale10, scaleY, x, y]});
  19219. compileGlyf(subglyph, cmds, font);
  19220. cmds.push({cmd: 'restore'});
  19221. }
  19222. } while ((flags & 0x20));
  19223. } else {
  19224. // simple glyph
  19225. var endPtsOfContours = [];
  19226. var j, jj;
  19227. for (j = 0; j < numberOfContours; j++) {
  19228. endPtsOfContours.push((code[i] << 8) | code[i + 1]);
  19229. i += 2;
  19230. }
  19231. var instructionLength = (code[i] << 8) | code[i + 1];
  19232. i += 2 + instructionLength; // skipping the instructions
  19233. var numberOfPoints = endPtsOfContours[endPtsOfContours.length - 1] + 1;
  19234. var points = [];
  19235. while (points.length < numberOfPoints) {
  19236. flags = code[i++];
  19237. var repeat = 1;
  19238. if ((flags & 0x08)) {
  19239. repeat += code[i++];
  19240. }
  19241. while (repeat-- > 0) {
  19242. points.push({flags: flags});
  19243. }
  19244. }
  19245. for (j = 0; j < numberOfPoints; j++) {
  19246. switch (points[j].flags & 0x12) {
  19247. case 0x00:
  19248. x += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  19249. i += 2;
  19250. break;
  19251. case 0x02:
  19252. x -= code[i++];
  19253. break;
  19254. case 0x12:
  19255. x += code[i++];
  19256. break;
  19257. }
  19258. points[j].x = x;
  19259. }
  19260. for (j = 0; j < numberOfPoints; j++) {
  19261. switch (points[j].flags & 0x24) {
  19262. case 0x00:
  19263. y += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  19264. i += 2;
  19265. break;
  19266. case 0x04:
  19267. y -= code[i++];
  19268. break;
  19269. case 0x24:
  19270. y += code[i++];
  19271. break;
  19272. }
  19273. points[j].y = y;
  19274. }
  19275. var startPoint = 0;
  19276. for (i = 0; i < numberOfContours; i++) {
  19277. var endPoint = endPtsOfContours[i];
  19278. // contours might have implicit points, which is located in the middle
  19279. // between two neighboring off-curve points
  19280. var contour = points.slice(startPoint, endPoint + 1);
  19281. if ((contour[0].flags & 1)) {
  19282. contour.push(contour[0]); // using start point at the contour end
  19283. } else if ((contour[contour.length - 1].flags & 1)) {
  19284. // first is off-curve point, trying to use one from the end
  19285. contour.unshift(contour[contour.length - 1]);
  19286. } else {
  19287. // start and end are off-curve points, creating implicit one
  19288. var p = {
  19289. flags: 1,
  19290. x: (contour[0].x + contour[contour.length - 1].x) / 2,
  19291. y: (contour[0].y + contour[contour.length - 1].y) / 2
  19292. };
  19293. contour.unshift(p);
  19294. contour.push(p);
  19295. }
  19296. moveTo(contour[0].x, contour[0].y);
  19297. for (j = 1, jj = contour.length; j < jj; j++) {
  19298. if ((contour[j].flags & 1)) {
  19299. lineTo(contour[j].x, contour[j].y);
  19300. } else if ((contour[j + 1].flags & 1)){
  19301. quadraticCurveTo(contour[j].x, contour[j].y,
  19302. contour[j + 1].x, contour[j + 1].y);
  19303. j++;
  19304. } else {
  19305. quadraticCurveTo(contour[j].x, contour[j].y,
  19306. (contour[j].x + contour[j + 1].x) / 2,
  19307. (contour[j].y + contour[j + 1].y) / 2);
  19308. }
  19309. }
  19310. startPoint = endPoint + 1;
  19311. }
  19312. }
  19313. }
  19314. function compileCharString(code, cmds, font) {
  19315. var stack = [];
  19316. var x = 0, y = 0;
  19317. var stems = 0;
  19318. function moveTo(x, y) {
  19319. cmds.push({cmd: 'moveTo', args: [x, y]});
  19320. }
  19321. function lineTo(x, y) {
  19322. cmds.push({cmd: 'lineTo', args: [x, y]});
  19323. }
  19324. function bezierCurveTo(x1, y1, x2, y2, x, y) {
  19325. cmds.push({cmd: 'bezierCurveTo', args: [x1, y1, x2, y2, x, y]});
  19326. }
  19327. function parse(code) {
  19328. var i = 0;
  19329. while (i < code.length) {
  19330. var stackClean = false;
  19331. var v = code[i++];
  19332. var xa, xb, ya, yb, y1, y2, y3, n, subrCode;
  19333. switch (v) {
  19334. case 1: // hstem
  19335. stems += stack.length >> 1;
  19336. stackClean = true;
  19337. break;
  19338. case 3: // vstem
  19339. stems += stack.length >> 1;
  19340. stackClean = true;
  19341. break;
  19342. case 4: // vmoveto
  19343. y += stack.pop();
  19344. moveTo(x, y);
  19345. stackClean = true;
  19346. break;
  19347. case 5: // rlineto
  19348. while (stack.length > 0) {
  19349. x += stack.shift();
  19350. y += stack.shift();
  19351. lineTo(x, y);
  19352. }
  19353. break;
  19354. case 6: // hlineto
  19355. while (stack.length > 0) {
  19356. x += stack.shift();
  19357. lineTo(x, y);
  19358. if (stack.length === 0) {
  19359. break;
  19360. }
  19361. y += stack.shift();
  19362. lineTo(x, y);
  19363. }
  19364. break;
  19365. case 7: // vlineto
  19366. while (stack.length > 0) {
  19367. y += stack.shift();
  19368. lineTo(x, y);
  19369. if (stack.length === 0) {
  19370. break;
  19371. }
  19372. x += stack.shift();
  19373. lineTo(x, y);
  19374. }
  19375. break;
  19376. case 8: // rrcurveto
  19377. while (stack.length > 0) {
  19378. xa = x + stack.shift(); ya = y + stack.shift();
  19379. xb = xa + stack.shift(); yb = ya + stack.shift();
  19380. x = xb + stack.shift(); y = yb + stack.shift();
  19381. bezierCurveTo(xa, ya, xb, yb, x, y);
  19382. }
  19383. break;
  19384. case 10: // callsubr
  19385. n = stack.pop() + font.subrsBias;
  19386. subrCode = font.subrs[n];
  19387. if (subrCode) {
  19388. parse(subrCode);
  19389. }
  19390. break;
  19391. case 11: // return
  19392. return;
  19393. case 12:
  19394. v = code[i++];
  19395. switch (v) {
  19396. case 34: // flex
  19397. xa = x + stack.shift();
  19398. xb = xa + stack.shift(); y1 = y + stack.shift();
  19399. x = xb + stack.shift();
  19400. bezierCurveTo(xa, y, xb, y1, x, y1);
  19401. xa = x + stack.shift();
  19402. xb = xa + stack.shift();
  19403. x = xb + stack.shift();
  19404. bezierCurveTo(xa, y1, xb, y, x, y);
  19405. break;
  19406. case 35: // flex
  19407. xa = x + stack.shift(); ya = y + stack.shift();
  19408. xb = xa + stack.shift(); yb = ya + stack.shift();
  19409. x = xb + stack.shift(); y = yb + stack.shift();
  19410. bezierCurveTo(xa, ya, xb, yb, x, y);
  19411. xa = x + stack.shift(); ya = y + stack.shift();
  19412. xb = xa + stack.shift(); yb = ya + stack.shift();
  19413. x = xb + stack.shift(); y = yb + stack.shift();
  19414. bezierCurveTo(xa, ya, xb, yb, x, y);
  19415. stack.pop(); // fd
  19416. break;
  19417. case 36: // hflex1
  19418. xa = x + stack.shift(); y1 = y + stack.shift();
  19419. xb = xa + stack.shift(); y2 = y1 + stack.shift();
  19420. x = xb + stack.shift();
  19421. bezierCurveTo(xa, y1, xb, y2, x, y2);
  19422. xa = x + stack.shift();
  19423. xb = xa + stack.shift(); y3 = y2 + stack.shift();
  19424. x = xb + stack.shift();
  19425. bezierCurveTo(xa, y2, xb, y3, x, y);
  19426. break;
  19427. case 37: // flex1
  19428. var x0 = x, y0 = y;
  19429. xa = x + stack.shift(); ya = y + stack.shift();
  19430. xb = xa + stack.shift(); yb = ya + stack.shift();
  19431. x = xb + stack.shift(); y = yb + stack.shift();
  19432. bezierCurveTo(xa, ya, xb, yb, x, y);
  19433. xa = x + stack.shift(); ya = y + stack.shift();
  19434. xb = xa + stack.shift(); yb = ya + stack.shift();
  19435. x = xb; y = yb;
  19436. if (Math.abs(x - x0) > Math.abs(y - y0)) {
  19437. x += stack.shift();
  19438. } else {
  19439. y += stack.shift();
  19440. }
  19441. bezierCurveTo(xa, ya, xb, yb, x, y);
  19442. break;
  19443. default:
  19444. error('unknown operator: 12 ' + v);
  19445. }
  19446. break;
  19447. case 14: // endchar
  19448. if (stack.length >= 4) {
  19449. var achar = stack.pop();
  19450. var bchar = stack.pop();
  19451. y = stack.pop();
  19452. x = stack.pop();
  19453. cmds.push({cmd: 'save'});
  19454. cmds.push({cmd: 'translate', args: [x, y]});
  19455. var gid = lookupCmap(font.cmap, String.fromCharCode(
  19456. font.glyphNameMap[Encodings.StandardEncoding[achar]]));
  19457. compileCharString(font.glyphs[gid], cmds, font);
  19458. cmds.push({cmd: 'restore'});
  19459. gid = lookupCmap(font.cmap, String.fromCharCode(
  19460. font.glyphNameMap[Encodings.StandardEncoding[bchar]]));
  19461. compileCharString(font.glyphs[gid], cmds, font);
  19462. }
  19463. return;
  19464. case 18: // hstemhm
  19465. stems += stack.length >> 1;
  19466. stackClean = true;
  19467. break;
  19468. case 19: // hintmask
  19469. stems += stack.length >> 1;
  19470. i += (stems + 7) >> 3;
  19471. stackClean = true;
  19472. break;
  19473. case 20: // cntrmask
  19474. stems += stack.length >> 1;
  19475. i += (stems + 7) >> 3;
  19476. stackClean = true;
  19477. break;
  19478. case 21: // rmoveto
  19479. y += stack.pop();
  19480. x += stack.pop();
  19481. moveTo(x, y);
  19482. stackClean = true;
  19483. break;
  19484. case 22: // hmoveto
  19485. x += stack.pop();
  19486. moveTo(x, y);
  19487. stackClean = true;
  19488. break;
  19489. case 23: // vstemhm
  19490. stems += stack.length >> 1;
  19491. stackClean = true;
  19492. break;
  19493. case 24: // rcurveline
  19494. while (stack.length > 2) {
  19495. xa = x + stack.shift(); ya = y + stack.shift();
  19496. xb = xa + stack.shift(); yb = ya + stack.shift();
  19497. x = xb + stack.shift(); y = yb + stack.shift();
  19498. bezierCurveTo(xa, ya, xb, yb, x, y);
  19499. }
  19500. x += stack.shift();
  19501. y += stack.shift();
  19502. lineTo(x, y);
  19503. break;
  19504. case 25: // rlinecurve
  19505. while (stack.length > 6) {
  19506. x += stack.shift();
  19507. y += stack.shift();
  19508. lineTo(x, y);
  19509. }
  19510. xa = x + stack.shift(); ya = y + stack.shift();
  19511. xb = xa + stack.shift(); yb = ya + stack.shift();
  19512. x = xb + stack.shift(); y = yb + stack.shift();
  19513. bezierCurveTo(xa, ya, xb, yb, x, y);
  19514. break;
  19515. case 26: // vvcurveto
  19516. if (stack.length % 2) {
  19517. x += stack.shift();
  19518. }
  19519. while (stack.length > 0) {
  19520. xa = x; ya = y + stack.shift();
  19521. xb = xa + stack.shift(); yb = ya + stack.shift();
  19522. x = xb; y = yb + stack.shift();
  19523. bezierCurveTo(xa, ya, xb, yb, x, y);
  19524. }
  19525. break;
  19526. case 27: // hhcurveto
  19527. if (stack.length % 2) {
  19528. y += stack.shift();
  19529. }
  19530. while (stack.length > 0) {
  19531. xa = x + stack.shift(); ya = y;
  19532. xb = xa + stack.shift(); yb = ya + stack.shift();
  19533. x = xb + stack.shift(); y = yb;
  19534. bezierCurveTo(xa, ya, xb, yb, x, y);
  19535. }
  19536. break;
  19537. case 28:
  19538. stack.push(((code[i] << 24) | (code[i + 1] << 16)) >> 16);
  19539. i += 2;
  19540. break;
  19541. case 29: // callgsubr
  19542. n = stack.pop() + font.gsubrsBias;
  19543. subrCode = font.gsubrs[n];
  19544. if (subrCode) {
  19545. parse(subrCode);
  19546. }
  19547. break;
  19548. case 30: // vhcurveto
  19549. while (stack.length > 0) {
  19550. xa = x; ya = y + stack.shift();
  19551. xb = xa + stack.shift(); yb = ya + stack.shift();
  19552. x = xb + stack.shift();
  19553. y = yb + (stack.length === 1 ? stack.shift() : 0);
  19554. bezierCurveTo(xa, ya, xb, yb, x, y);
  19555. if (stack.length === 0) {
  19556. break;
  19557. }
  19558. xa = x + stack.shift(); ya = y;
  19559. xb = xa + stack.shift(); yb = ya + stack.shift();
  19560. y = yb + stack.shift();
  19561. x = xb + (stack.length === 1 ? stack.shift() : 0);
  19562. bezierCurveTo(xa, ya, xb, yb, x, y);
  19563. }
  19564. break;
  19565. case 31: // hvcurveto
  19566. while (stack.length > 0) {
  19567. xa = x + stack.shift(); ya = y;
  19568. xb = xa + stack.shift(); yb = ya + stack.shift();
  19569. y = yb + stack.shift();
  19570. x = xb + (stack.length === 1 ? stack.shift() : 0);
  19571. bezierCurveTo(xa, ya, xb, yb, x, y);
  19572. if (stack.length === 0) {
  19573. break;
  19574. }
  19575. xa = x; ya = y + stack.shift();
  19576. xb = xa + stack.shift(); yb = ya + stack.shift();
  19577. x = xb + stack.shift();
  19578. y = yb + (stack.length === 1 ? stack.shift() : 0);
  19579. bezierCurveTo(xa, ya, xb, yb, x, y);
  19580. }
  19581. break;
  19582. default:
  19583. if (v < 32) {
  19584. error('unknown operator: ' + v);
  19585. }
  19586. if (v < 247) {
  19587. stack.push(v - 139);
  19588. } else if (v < 251) {
  19589. stack.push((v - 247) * 256 + code[i++] + 108);
  19590. } else if (v < 255) {
  19591. stack.push(-(v - 251) * 256 - code[i++] - 108);
  19592. } else {
  19593. stack.push(((code[i] << 24) | (code[i + 1] << 16) |
  19594. (code[i + 2] << 8) | code[i + 3]) / 65536);
  19595. i += 4;
  19596. }
  19597. break;
  19598. }
  19599. if (stackClean) {
  19600. stack.length = 0;
  19601. }
  19602. }
  19603. }
  19604. parse(code);
  19605. }
  19606. var noop = '';
  19607. function CompiledFont(fontMatrix) {
  19608. this.compiledGlyphs = {};
  19609. this.fontMatrix = fontMatrix;
  19610. }
  19611. CompiledFont.prototype = {
  19612. getPathJs: function (unicode) {
  19613. var gid = lookupCmap(this.cmap, unicode);
  19614. var fn = this.compiledGlyphs[gid];
  19615. if (!fn) {
  19616. this.compiledGlyphs[gid] = fn = this.compileGlyph(this.glyphs[gid]);
  19617. }
  19618. return fn;
  19619. },
  19620. compileGlyph: function (code) {
  19621. if (!code || code.length === 0 || code[0] === 14) {
  19622. return noop;
  19623. }
  19624. var cmds = [];
  19625. cmds.push({cmd: 'save'});
  19626. cmds.push({cmd: 'transform', args: this.fontMatrix.slice()});
  19627. cmds.push({cmd: 'scale', args: ['size', '-size']});
  19628. this.compileGlyphImpl(code, cmds);
  19629. cmds.push({cmd: 'restore'});
  19630. return cmds;
  19631. },
  19632. compileGlyphImpl: function () {
  19633. error('Children classes should implement this.');
  19634. },
  19635. hasBuiltPath: function (unicode) {
  19636. var gid = lookupCmap(this.cmap, unicode);
  19637. return gid in this.compiledGlyphs;
  19638. }
  19639. };
  19640. function TrueTypeCompiled(glyphs, cmap, fontMatrix) {
  19641. fontMatrix = fontMatrix || [0.000488, 0, 0, 0.000488, 0, 0];
  19642. CompiledFont.call(this, fontMatrix);
  19643. this.glyphs = glyphs;
  19644. this.cmap = cmap;
  19645. this.compiledGlyphs = [];
  19646. }
  19647. Util.inherit(TrueTypeCompiled, CompiledFont, {
  19648. compileGlyphImpl: function (code, cmds) {
  19649. compileGlyf(code, cmds, this);
  19650. }
  19651. });
  19652. function Type2Compiled(cffInfo, cmap, fontMatrix, glyphNameMap) {
  19653. fontMatrix = fontMatrix || [0.001, 0, 0, 0.001, 0, 0];
  19654. CompiledFont.call(this, fontMatrix);
  19655. this.glyphs = cffInfo.glyphs;
  19656. this.gsubrs = cffInfo.gsubrs || [];
  19657. this.subrs = cffInfo.subrs || [];
  19658. this.cmap = cmap;
  19659. this.glyphNameMap = glyphNameMap || GlyphsUnicode;
  19660. this.compiledGlyphs = [];
  19661. this.gsubrsBias = (this.gsubrs.length < 1240 ?
  19662. 107 : (this.gsubrs.length < 33900 ? 1131 : 32768));
  19663. this.subrsBias = (this.subrs.length < 1240 ?
  19664. 107 : (this.subrs.length < 33900 ? 1131 : 32768));
  19665. }
  19666. Util.inherit(Type2Compiled, CompiledFont, {
  19667. compileGlyphImpl: function (code, cmds) {
  19668. compileCharString(code, cmds, this);
  19669. }
  19670. });
  19671. return {
  19672. create: function FontRendererFactory_create(font) {
  19673. var data = new Uint8Array(font.data);
  19674. var cmap, glyf, loca, cff, indexToLocFormat, unitsPerEm;
  19675. var numTables = getUshort(data, 4);
  19676. for (var i = 0, p = 12; i < numTables; i++, p += 16) {
  19677. var tag = bytesToString(data.subarray(p, p + 4));
  19678. var offset = getLong(data, p + 8);
  19679. var length = getLong(data, p + 12);
  19680. switch (tag) {
  19681. case 'cmap':
  19682. cmap = parseCmap(data, offset, offset + length);
  19683. break;
  19684. case 'glyf':
  19685. glyf = data.subarray(offset, offset + length);
  19686. break;
  19687. case 'loca':
  19688. loca = data.subarray(offset, offset + length);
  19689. break;
  19690. case 'head':
  19691. unitsPerEm = getUshort(data, offset + 18);
  19692. indexToLocFormat = getUshort(data, offset + 50);
  19693. break;
  19694. case 'CFF ':
  19695. cff = parseCff(data, offset, offset + length);
  19696. break;
  19697. }
  19698. }
  19699. if (glyf) {
  19700. var fontMatrix = (!unitsPerEm ? font.fontMatrix :
  19701. [1 / unitsPerEm, 0, 0, 1 / unitsPerEm, 0, 0]);
  19702. return new TrueTypeCompiled(
  19703. parseGlyfTable(glyf, loca, indexToLocFormat), cmap, fontMatrix);
  19704. } else {
  19705. return new Type2Compiled(cff, cmap, font.fontMatrix, font.glyphNameMap);
  19706. }
  19707. }
  19708. };
  19709. })();
  19710. // TODO refactor to remove cyclic dependency on fonts.js
  19711. function _setCoreFonts(coreFonts_) {
  19712. coreFonts = coreFonts_;
  19713. Encodings = coreFonts_.Encodings;
  19714. CFFParser = coreFonts_.CFFParser;
  19715. }
  19716. exports._setCoreFonts = _setCoreFonts;
  19717. exports.FontRendererFactory = FontRendererFactory;
  19718. }));
  19719. (function (root, factory) {
  19720. if (typeof define === 'function' && define.amd) {
  19721. define('pdfjs/core/parser', ['exports', 'pdfjs/shared/util',
  19722. 'pdfjs/core/primitives', 'pdfjs/core/stream'], factory);
  19723. } else if (typeof exports !== 'undefined') {
  19724. factory(exports, require('../shared/util.js'), require('./primitives.js'),
  19725. require('./stream.js'));
  19726. } else {
  19727. factory((root.pdfjsCoreParser = {}), root.pdfjsSharedUtil,
  19728. root.pdfjsCorePrimitives, root.pdfjsCoreStream);
  19729. }
  19730. }(this, function (exports, sharedUtil, corePrimitives, coreStream) {
  19731. var MissingDataException = sharedUtil.MissingDataException;
  19732. var StreamType = sharedUtil.StreamType;
  19733. var assert = sharedUtil.assert;
  19734. var error = sharedUtil.error;
  19735. var info = sharedUtil.info;
  19736. var isArray = sharedUtil.isArray;
  19737. var isInt = sharedUtil.isInt;
  19738. var isNum = sharedUtil.isNum;
  19739. var isString = sharedUtil.isString;
  19740. var warn = sharedUtil.warn;
  19741. var Cmd = corePrimitives.Cmd;
  19742. var Dict = corePrimitives.Dict;
  19743. var Name = corePrimitives.Name;
  19744. var Ref = corePrimitives.Ref;
  19745. var isCmd = corePrimitives.isCmd;
  19746. var isDict = corePrimitives.isDict;
  19747. var isName = corePrimitives.isName;
  19748. var Ascii85Stream = coreStream.Ascii85Stream;
  19749. var AsciiHexStream = coreStream.AsciiHexStream;
  19750. var CCITTFaxStream = coreStream.CCITTFaxStream;
  19751. var FlateStream = coreStream.FlateStream;
  19752. var Jbig2Stream = coreStream.Jbig2Stream;
  19753. var JpegStream = coreStream.JpegStream;
  19754. var JpxStream = coreStream.JpxStream;
  19755. var LZWStream = coreStream.LZWStream;
  19756. var NullStream = coreStream.NullStream;
  19757. var PredictorStream = coreStream.PredictorStream;
  19758. var RunLengthStream = coreStream.RunLengthStream;
  19759. var EOF = {};
  19760. function isEOF(v) {
  19761. return (v === EOF);
  19762. }
  19763. var MAX_LENGTH_TO_CACHE = 1000;
  19764. var Parser = (function ParserClosure() {
  19765. function Parser(lexer, allowStreams, xref) {
  19766. this.lexer = lexer;
  19767. this.allowStreams = allowStreams;
  19768. this.xref = xref;
  19769. this.imageCache = {};
  19770. this.refill();
  19771. }
  19772. Parser.prototype = {
  19773. refill: function Parser_refill() {
  19774. this.buf1 = this.lexer.getObj();
  19775. this.buf2 = this.lexer.getObj();
  19776. },
  19777. shift: function Parser_shift() {
  19778. if (isCmd(this.buf2, 'ID')) {
  19779. this.buf1 = this.buf2;
  19780. this.buf2 = null;
  19781. } else {
  19782. this.buf1 = this.buf2;
  19783. this.buf2 = this.lexer.getObj();
  19784. }
  19785. },
  19786. tryShift: function Parser_tryShift() {
  19787. try {
  19788. this.shift();
  19789. return true;
  19790. } catch (e) {
  19791. if (e instanceof MissingDataException) {
  19792. throw e;
  19793. }
  19794. // Upon failure, the caller should reset this.lexer.pos to a known good
  19795. // state and call this.shift() twice to reset the buffers.
  19796. return false;
  19797. }
  19798. },
  19799. getObj: function Parser_getObj(cipherTransform) {
  19800. var buf1 = this.buf1;
  19801. this.shift();
  19802. if (buf1 instanceof Cmd) {
  19803. switch (buf1.cmd) {
  19804. case 'BI': // inline image
  19805. return this.makeInlineImage(cipherTransform);
  19806. case '[': // array
  19807. var array = [];
  19808. while (!isCmd(this.buf1, ']') && !isEOF(this.buf1)) {
  19809. array.push(this.getObj(cipherTransform));
  19810. }
  19811. if (isEOF(this.buf1)) {
  19812. error('End of file inside array');
  19813. }
  19814. this.shift();
  19815. return array;
  19816. case '<<': // dictionary or stream
  19817. var dict = new Dict(this.xref);
  19818. while (!isCmd(this.buf1, '>>') && !isEOF(this.buf1)) {
  19819. if (!isName(this.buf1)) {
  19820. info('Malformed dictionary: key must be a name object');
  19821. this.shift();
  19822. continue;
  19823. }
  19824. var key = this.buf1.name;
  19825. this.shift();
  19826. if (isEOF(this.buf1)) {
  19827. break;
  19828. }
  19829. dict.set(key, this.getObj(cipherTransform));
  19830. }
  19831. if (isEOF(this.buf1)) {
  19832. error('End of file inside dictionary');
  19833. }
  19834. // Stream objects are not allowed inside content streams or
  19835. // object streams.
  19836. if (isCmd(this.buf2, 'stream')) {
  19837. return (this.allowStreams ?
  19838. this.makeStream(dict, cipherTransform) : dict);
  19839. }
  19840. this.shift();
  19841. return dict;
  19842. default: // simple object
  19843. return buf1;
  19844. }
  19845. }
  19846. if (isInt(buf1)) { // indirect reference or integer
  19847. var num = buf1;
  19848. if (isInt(this.buf1) && isCmd(this.buf2, 'R')) {
  19849. var ref = new Ref(num, this.buf1);
  19850. this.shift();
  19851. this.shift();
  19852. return ref;
  19853. }
  19854. return num;
  19855. }
  19856. if (isString(buf1)) { // string
  19857. var str = buf1;
  19858. if (cipherTransform) {
  19859. str = cipherTransform.decryptString(str);
  19860. }
  19861. return str;
  19862. }
  19863. // simple object
  19864. return buf1;
  19865. },
  19866. /**
  19867. * Find the end of the stream by searching for the /EI\s/.
  19868. * @returns {number} The inline stream length.
  19869. */
  19870. findDefaultInlineStreamEnd:
  19871. function Parser_findDefaultInlineStreamEnd(stream) {
  19872. var E = 0x45, I = 0x49, SPACE = 0x20, LF = 0xA, CR = 0xD;
  19873. var startPos = stream.pos, state = 0, ch, i, n, followingBytes;
  19874. while ((ch = stream.getByte()) !== -1) {
  19875. if (state === 0) {
  19876. state = (ch === E) ? 1 : 0;
  19877. } else if (state === 1) {
  19878. state = (ch === I) ? 2 : 0;
  19879. } else {
  19880. assert(state === 2);
  19881. if (ch === SPACE || ch === LF || ch === CR) {
  19882. // Let's check the next five bytes are ASCII... just be sure.
  19883. n = 5;
  19884. followingBytes = stream.peekBytes(n);
  19885. for (i = 0; i < n; i++) {
  19886. ch = followingBytes[i];
  19887. if (ch !== LF && ch !== CR && (ch < SPACE || ch > 0x7F)) {
  19888. // Not a LF, CR, SPACE or any visible ASCII character, i.e.
  19889. // it's binary stuff. Resetting the state.
  19890. state = 0;
  19891. break;
  19892. }
  19893. }
  19894. if (state === 2) {
  19895. break; // Finished!
  19896. }
  19897. } else {
  19898. state = 0;
  19899. }
  19900. }
  19901. }
  19902. return ((stream.pos - 4) - startPos);
  19903. },
  19904. /**
  19905. * Find the EOI (end-of-image) marker 0xFFD9 of the stream.
  19906. * @returns {number} The inline stream length.
  19907. */
  19908. findDCTDecodeInlineStreamEnd:
  19909. function Parser_findDCTDecodeInlineStreamEnd(stream) {
  19910. var startPos = stream.pos, foundEOI = false, b, markerLength, length;
  19911. while ((b = stream.getByte()) !== -1) {
  19912. if (b !== 0xFF) { // Not a valid marker.
  19913. continue;
  19914. }
  19915. switch (stream.getByte()) {
  19916. case 0x00: // Byte stuffing.
  19917. // 0xFF00 appears to be a very common byte sequence in JPEG images.
  19918. break;
  19919. case 0xFF: // Fill byte.
  19920. // Avoid skipping a valid marker, resetting the stream position.
  19921. stream.skip(-1);
  19922. break;
  19923. case 0xD9: // EOI
  19924. foundEOI = true;
  19925. break;
  19926. case 0xC0: // SOF0
  19927. case 0xC1: // SOF1
  19928. case 0xC2: // SOF2
  19929. case 0xC3: // SOF3
  19930. case 0xC5: // SOF5
  19931. case 0xC6: // SOF6
  19932. case 0xC7: // SOF7
  19933. case 0xC9: // SOF9
  19934. case 0xCA: // SOF10
  19935. case 0xCB: // SOF11
  19936. case 0xCD: // SOF13
  19937. case 0xCE: // SOF14
  19938. case 0xCF: // SOF15
  19939. case 0xC4: // DHT
  19940. case 0xCC: // DAC
  19941. case 0xDA: // SOS
  19942. case 0xDB: // DQT
  19943. case 0xDC: // DNL
  19944. case 0xDD: // DRI
  19945. case 0xDE: // DHP
  19946. case 0xDF: // EXP
  19947. case 0xE0: // APP0
  19948. case 0xE1: // APP1
  19949. case 0xE2: // APP2
  19950. case 0xE3: // APP3
  19951. case 0xE4: // APP4
  19952. case 0xE5: // APP5
  19953. case 0xE6: // APP6
  19954. case 0xE7: // APP7
  19955. case 0xE8: // APP8
  19956. case 0xE9: // APP9
  19957. case 0xEA: // APP10
  19958. case 0xEB: // APP11
  19959. case 0xEC: // APP12
  19960. case 0xED: // APP13
  19961. case 0xEE: // APP14
  19962. case 0xEF: // APP15
  19963. case 0xFE: // COM
  19964. // The marker should be followed by the length of the segment.
  19965. markerLength = stream.getUint16();
  19966. if (markerLength > 2) {
  19967. // |markerLength| contains the byte length of the marker segment,
  19968. // including its own length (2 bytes) and excluding the marker.
  19969. stream.skip(markerLength - 2); // Jump to the next marker.
  19970. } else {
  19971. // The marker length is invalid, resetting the stream position.
  19972. stream.skip(-2);
  19973. }
  19974. break;
  19975. }
  19976. if (foundEOI) {
  19977. break;
  19978. }
  19979. }
  19980. length = stream.pos - startPos;
  19981. if (b === -1) {
  19982. warn('Inline DCTDecode image stream: ' +
  19983. 'EOI marker not found, searching for /EI/ instead.');
  19984. stream.skip(-length); // Reset the stream position.
  19985. return this.findDefaultInlineStreamEnd(stream);
  19986. }
  19987. this.inlineStreamSkipEI(stream);
  19988. return length;
  19989. },
  19990. /**
  19991. * Find the EOD (end-of-data) marker '~>' (i.e. TILDE + GT) of the stream.
  19992. * @returns {number} The inline stream length.
  19993. */
  19994. findASCII85DecodeInlineStreamEnd:
  19995. function Parser_findASCII85DecodeInlineStreamEnd(stream) {
  19996. var TILDE = 0x7E, GT = 0x3E;
  19997. var startPos = stream.pos, ch, length;
  19998. while ((ch = stream.getByte()) !== -1) {
  19999. if (ch === TILDE && stream.peekByte() === GT) {
  20000. stream.skip();
  20001. break;
  20002. }
  20003. }
  20004. length = stream.pos - startPos;
  20005. if (ch === -1) {
  20006. warn('Inline ASCII85Decode image stream: ' +
  20007. 'EOD marker not found, searching for /EI/ instead.');
  20008. stream.skip(-length); // Reset the stream position.
  20009. return this.findDefaultInlineStreamEnd(stream);
  20010. }
  20011. this.inlineStreamSkipEI(stream);
  20012. return length;
  20013. },
  20014. /**
  20015. * Find the EOD (end-of-data) marker '>' (i.e. GT) of the stream.
  20016. * @returns {number} The inline stream length.
  20017. */
  20018. findASCIIHexDecodeInlineStreamEnd:
  20019. function Parser_findASCIIHexDecodeInlineStreamEnd(stream) {
  20020. var GT = 0x3E;
  20021. var startPos = stream.pos, ch, length;
  20022. while ((ch = stream.getByte()) !== -1) {
  20023. if (ch === GT) {
  20024. break;
  20025. }
  20026. }
  20027. length = stream.pos - startPos;
  20028. if (ch === -1) {
  20029. warn('Inline ASCIIHexDecode image stream: ' +
  20030. 'EOD marker not found, searching for /EI/ instead.');
  20031. stream.skip(-length); // Reset the stream position.
  20032. return this.findDefaultInlineStreamEnd(stream);
  20033. }
  20034. this.inlineStreamSkipEI(stream);
  20035. return length;
  20036. },
  20037. /**
  20038. * Skip over the /EI/ for streams where we search for an EOD marker.
  20039. */
  20040. inlineStreamSkipEI: function Parser_inlineStreamSkipEI(stream) {
  20041. var E = 0x45, I = 0x49;
  20042. var state = 0, ch;
  20043. while ((ch = stream.getByte()) !== -1) {
  20044. if (state === 0) {
  20045. state = (ch === E) ? 1 : 0;
  20046. } else if (state === 1) {
  20047. state = (ch === I) ? 2 : 0;
  20048. } else if (state === 2) {
  20049. break;
  20050. }
  20051. }
  20052. },
  20053. makeInlineImage: function Parser_makeInlineImage(cipherTransform) {
  20054. var lexer = this.lexer;
  20055. var stream = lexer.stream;
  20056. // Parse dictionary.
  20057. var dict = new Dict(this.xref);
  20058. while (!isCmd(this.buf1, 'ID') && !isEOF(this.buf1)) {
  20059. if (!isName(this.buf1)) {
  20060. error('Dictionary key must be a name object');
  20061. }
  20062. var key = this.buf1.name;
  20063. this.shift();
  20064. if (isEOF(this.buf1)) {
  20065. break;
  20066. }
  20067. dict.set(key, this.getObj(cipherTransform));
  20068. }
  20069. // Extract the name of the first (i.e. the current) image filter.
  20070. var filter = dict.get('Filter', 'F'), filterName;
  20071. if (isName(filter)) {
  20072. filterName = filter.name;
  20073. } else if (isArray(filter) && isName(filter[0])) {
  20074. filterName = filter[0].name;
  20075. }
  20076. // Parse image stream.
  20077. var startPos = stream.pos, length, i, ii;
  20078. if (filterName === 'DCTDecode' || filterName === 'DCT') {
  20079. length = this.findDCTDecodeInlineStreamEnd(stream);
  20080. } else if (filterName === 'ASCII85Decide' || filterName === 'A85') {
  20081. length = this.findASCII85DecodeInlineStreamEnd(stream);
  20082. } else if (filterName === 'ASCIIHexDecode' || filterName === 'AHx') {
  20083. length = this.findASCIIHexDecodeInlineStreamEnd(stream);
  20084. } else {
  20085. length = this.findDefaultInlineStreamEnd(stream);
  20086. }
  20087. var imageStream = stream.makeSubStream(startPos, length, dict);
  20088. // Cache all images below the MAX_LENGTH_TO_CACHE threshold by their
  20089. // adler32 checksum.
  20090. var adler32;
  20091. if (length < MAX_LENGTH_TO_CACHE) {
  20092. var imageBytes = imageStream.getBytes();
  20093. imageStream.reset();
  20094. var a = 1;
  20095. var b = 0;
  20096. for (i = 0, ii = imageBytes.length; i < ii; ++i) {
  20097. // No modulo required in the loop if imageBytes.length < 5552.
  20098. a += imageBytes[i] & 0xff;
  20099. b += a;
  20100. }
  20101. adler32 = ((b % 65521) << 16) | (a % 65521);
  20102. if (this.imageCache.adler32 === adler32) {
  20103. this.buf2 = Cmd.get('EI');
  20104. this.shift();
  20105. this.imageCache[adler32].reset();
  20106. return this.imageCache[adler32];
  20107. }
  20108. }
  20109. if (cipherTransform) {
  20110. imageStream = cipherTransform.createStream(imageStream, length);
  20111. }
  20112. imageStream = this.filter(imageStream, dict, length);
  20113. imageStream.dict = dict;
  20114. if (adler32 !== undefined) {
  20115. imageStream.cacheKey = 'inline_' + length + '_' + adler32;
  20116. this.imageCache[adler32] = imageStream;
  20117. }
  20118. this.buf2 = Cmd.get('EI');
  20119. this.shift();
  20120. return imageStream;
  20121. },
  20122. makeStream: function Parser_makeStream(dict, cipherTransform) {
  20123. var lexer = this.lexer;
  20124. var stream = lexer.stream;
  20125. // get stream start position
  20126. lexer.skipToNextLine();
  20127. var pos = stream.pos - 1;
  20128. // get length
  20129. var length = dict.get('Length');
  20130. if (!isInt(length)) {
  20131. info('Bad ' + length + ' attribute in stream');
  20132. length = 0;
  20133. }
  20134. // skip over the stream data
  20135. stream.pos = pos + length;
  20136. lexer.nextChar();
  20137. // Shift '>>' and check whether the new object marks the end of the stream
  20138. if (this.tryShift() && isCmd(this.buf2, 'endstream')) {
  20139. this.shift(); // 'stream'
  20140. } else {
  20141. // bad stream length, scanning for endstream
  20142. stream.pos = pos;
  20143. var SCAN_BLOCK_SIZE = 2048;
  20144. var ENDSTREAM_SIGNATURE_LENGTH = 9;
  20145. var ENDSTREAM_SIGNATURE = [0x65, 0x6E, 0x64, 0x73, 0x74, 0x72, 0x65,
  20146. 0x61, 0x6D];
  20147. var skipped = 0, found = false, i, j;
  20148. while (stream.pos < stream.end) {
  20149. var scanBytes = stream.peekBytes(SCAN_BLOCK_SIZE);
  20150. var scanLength = scanBytes.length - ENDSTREAM_SIGNATURE_LENGTH;
  20151. if (scanLength <= 0) {
  20152. break;
  20153. }
  20154. found = false;
  20155. for (i = 0, j = 0; i < scanLength; i++) {
  20156. var b = scanBytes[i];
  20157. if (b !== ENDSTREAM_SIGNATURE[j]) {
  20158. i -= j;
  20159. j = 0;
  20160. } else {
  20161. j++;
  20162. if (j >= ENDSTREAM_SIGNATURE_LENGTH) {
  20163. i++;
  20164. found = true;
  20165. break;
  20166. }
  20167. }
  20168. }
  20169. if (found) {
  20170. skipped += i - ENDSTREAM_SIGNATURE_LENGTH;
  20171. stream.pos += i - ENDSTREAM_SIGNATURE_LENGTH;
  20172. break;
  20173. }
  20174. skipped += scanLength;
  20175. stream.pos += scanLength;
  20176. }
  20177. if (!found) {
  20178. error('Missing endstream');
  20179. }
  20180. length = skipped;
  20181. lexer.nextChar();
  20182. this.shift();
  20183. this.shift();
  20184. }
  20185. this.shift(); // 'endstream'
  20186. stream = stream.makeSubStream(pos, length, dict);
  20187. if (cipherTransform) {
  20188. stream = cipherTransform.createStream(stream, length);
  20189. }
  20190. stream = this.filter(stream, dict, length);
  20191. stream.dict = dict;
  20192. return stream;
  20193. },
  20194. filter: function Parser_filter(stream, dict, length) {
  20195. var filter = dict.get('Filter', 'F');
  20196. var params = dict.get('DecodeParms', 'DP');
  20197. if (isName(filter)) {
  20198. return this.makeFilter(stream, filter.name, length, params);
  20199. }
  20200. var maybeLength = length;
  20201. if (isArray(filter)) {
  20202. var filterArray = filter;
  20203. var paramsArray = params;
  20204. for (var i = 0, ii = filterArray.length; i < ii; ++i) {
  20205. filter = filterArray[i];
  20206. if (!isName(filter)) {
  20207. error('Bad filter name: ' + filter);
  20208. }
  20209. params = null;
  20210. if (isArray(paramsArray) && (i in paramsArray)) {
  20211. params = paramsArray[i];
  20212. }
  20213. stream = this.makeFilter(stream, filter.name, maybeLength, params);
  20214. // after the first stream the length variable is invalid
  20215. maybeLength = null;
  20216. }
  20217. }
  20218. return stream;
  20219. },
  20220. makeFilter: function Parser_makeFilter(stream, name, maybeLength, params) {
  20221. if (stream.dict.get('Length') === 0 && !maybeLength) {
  20222. warn('Empty "' + name + '" stream.');
  20223. return new NullStream(stream);
  20224. }
  20225. try {
  20226. if (params && this.xref) {
  20227. params = this.xref.fetchIfRef(params);
  20228. }
  20229. var xrefStreamStats = this.xref.stats.streamTypes;
  20230. if (name === 'FlateDecode' || name === 'Fl') {
  20231. xrefStreamStats[StreamType.FLATE] = true;
  20232. if (params) {
  20233. return new PredictorStream(new FlateStream(stream, maybeLength),
  20234. maybeLength, params);
  20235. }
  20236. return new FlateStream(stream, maybeLength);
  20237. }
  20238. if (name === 'LZWDecode' || name === 'LZW') {
  20239. xrefStreamStats[StreamType.LZW] = true;
  20240. var earlyChange = 1;
  20241. if (params) {
  20242. if (params.has('EarlyChange')) {
  20243. earlyChange = params.get('EarlyChange');
  20244. }
  20245. return new PredictorStream(
  20246. new LZWStream(stream, maybeLength, earlyChange),
  20247. maybeLength, params);
  20248. }
  20249. return new LZWStream(stream, maybeLength, earlyChange);
  20250. }
  20251. if (name === 'DCTDecode' || name === 'DCT') {
  20252. xrefStreamStats[StreamType.DCT] = true;
  20253. return new JpegStream(stream, maybeLength, stream.dict, this.xref);
  20254. }
  20255. if (name === 'JPXDecode' || name === 'JPX') {
  20256. xrefStreamStats[StreamType.JPX] = true;
  20257. return new JpxStream(stream, maybeLength, stream.dict);
  20258. }
  20259. if (name === 'ASCII85Decode' || name === 'A85') {
  20260. xrefStreamStats[StreamType.A85] = true;
  20261. return new Ascii85Stream(stream, maybeLength);
  20262. }
  20263. if (name === 'ASCIIHexDecode' || name === 'AHx') {
  20264. xrefStreamStats[StreamType.AHX] = true;
  20265. return new AsciiHexStream(stream, maybeLength);
  20266. }
  20267. if (name === 'CCITTFaxDecode' || name === 'CCF') {
  20268. xrefStreamStats[StreamType.CCF] = true;
  20269. return new CCITTFaxStream(stream, maybeLength, params);
  20270. }
  20271. if (name === 'RunLengthDecode' || name === 'RL') {
  20272. xrefStreamStats[StreamType.RL] = true;
  20273. return new RunLengthStream(stream, maybeLength);
  20274. }
  20275. if (name === 'JBIG2Decode') {
  20276. xrefStreamStats[StreamType.JBIG] = true;
  20277. return new Jbig2Stream(stream, maybeLength, stream.dict);
  20278. }
  20279. warn('filter "' + name + '" not supported yet');
  20280. return stream;
  20281. } catch (ex) {
  20282. if (ex instanceof MissingDataException) {
  20283. throw ex;
  20284. }
  20285. warn('Invalid stream: \"' + ex + '\"');
  20286. return new NullStream(stream);
  20287. }
  20288. }
  20289. };
  20290. return Parser;
  20291. })();
  20292. var Lexer = (function LexerClosure() {
  20293. function Lexer(stream, knownCommands) {
  20294. this.stream = stream;
  20295. this.nextChar();
  20296. // While lexing, we build up many strings one char at a time. Using += for
  20297. // this can result in lots of garbage strings. It's better to build an
  20298. // array of single-char strings and then join() them together at the end.
  20299. // And reusing a single array (i.e. |this.strBuf|) over and over for this
  20300. // purpose uses less memory than using a new array for each string.
  20301. this.strBuf = [];
  20302. // The PDFs might have "glued" commands with other commands, operands or
  20303. // literals, e.g. "q1". The knownCommands is a dictionary of the valid
  20304. // commands and their prefixes. The prefixes are built the following way:
  20305. // if there a command that is a prefix of the other valid command or
  20306. // literal (e.g. 'f' and 'false') the following prefixes must be included,
  20307. // 'fa', 'fal', 'fals'. The prefixes are not needed, if the command has no
  20308. // other commands or literals as a prefix. The knowCommands is optional.
  20309. this.knownCommands = knownCommands;
  20310. }
  20311. Lexer.isSpace = function Lexer_isSpace(ch) {
  20312. // Space is one of the following characters: SPACE, TAB, CR or LF.
  20313. return (ch === 0x20 || ch === 0x09 || ch === 0x0D || ch === 0x0A);
  20314. };
  20315. // A '1' in this array means the character is white space. A '1' or
  20316. // '2' means the character ends a name or command.
  20317. var specialChars = [
  20318. 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, // 0x
  20319. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 1x
  20320. 1, 0, 0, 0, 0, 2, 0, 0, 2, 2, 0, 0, 0, 0, 0, 2, // 2x
  20321. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, // 3x
  20322. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 4x
  20323. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 5x
  20324. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 6x
  20325. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 7x
  20326. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 8x
  20327. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 9x
  20328. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ax
  20329. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // bx
  20330. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // cx
  20331. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // dx
  20332. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ex
  20333. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 // fx
  20334. ];
  20335. function toHexDigit(ch) {
  20336. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  20337. return ch & 0x0F;
  20338. }
  20339. if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  20340. // 'A'-'F', 'a'-'f'
  20341. return (ch & 0x0F) + 9;
  20342. }
  20343. return -1;
  20344. }
  20345. Lexer.prototype = {
  20346. nextChar: function Lexer_nextChar() {
  20347. return (this.currentChar = this.stream.getByte());
  20348. },
  20349. peekChar: function Lexer_peekChar() {
  20350. return this.stream.peekByte();
  20351. },
  20352. getNumber: function Lexer_getNumber() {
  20353. var ch = this.currentChar;
  20354. var eNotation = false;
  20355. var divideBy = 0; // different from 0 if it's a floating point value
  20356. var sign = 1;
  20357. if (ch === 0x2D) { // '-'
  20358. sign = -1;
  20359. ch = this.nextChar();
  20360. if (ch === 0x2D) { // '-'
  20361. // Ignore double negative (this is consistent with Adobe Reader).
  20362. ch = this.nextChar();
  20363. }
  20364. } else if (ch === 0x2B) { // '+'
  20365. ch = this.nextChar();
  20366. }
  20367. if (ch === 0x2E) { // '.'
  20368. divideBy = 10;
  20369. ch = this.nextChar();
  20370. }
  20371. if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  20372. error('Invalid number: ' + String.fromCharCode(ch));
  20373. return 0;
  20374. }
  20375. var baseValue = ch - 0x30; // '0'
  20376. var powerValue = 0;
  20377. var powerValueSign = 1;
  20378. while ((ch = this.nextChar()) >= 0) {
  20379. if (0x30 <= ch && ch <= 0x39) { // '0' - '9'
  20380. var currentDigit = ch - 0x30; // '0'
  20381. if (eNotation) { // We are after an 'e' or 'E'
  20382. powerValue = powerValue * 10 + currentDigit;
  20383. } else {
  20384. if (divideBy !== 0) { // We are after a point
  20385. divideBy *= 10;
  20386. }
  20387. baseValue = baseValue * 10 + currentDigit;
  20388. }
  20389. } else if (ch === 0x2E) { // '.'
  20390. if (divideBy === 0) {
  20391. divideBy = 1;
  20392. } else {
  20393. // A number can have only one '.'
  20394. break;
  20395. }
  20396. } else if (ch === 0x2D) { // '-'
  20397. // ignore minus signs in the middle of numbers to match
  20398. // Adobe's behavior
  20399. warn('Badly formated number');
  20400. } else if (ch === 0x45 || ch === 0x65) { // 'E', 'e'
  20401. // 'E' can be either a scientific notation or the beginning of a new
  20402. // operator
  20403. ch = this.peekChar();
  20404. if (ch === 0x2B || ch === 0x2D) { // '+', '-'
  20405. powerValueSign = (ch === 0x2D) ? -1 : 1;
  20406. this.nextChar(); // Consume the sign character
  20407. } else if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  20408. // The 'E' must be the beginning of a new operator
  20409. break;
  20410. }
  20411. eNotation = true;
  20412. } else {
  20413. // the last character doesn't belong to us
  20414. break;
  20415. }
  20416. }
  20417. if (divideBy !== 0) {
  20418. baseValue /= divideBy;
  20419. }
  20420. if (eNotation) {
  20421. baseValue *= Math.pow(10, powerValueSign * powerValue);
  20422. }
  20423. return sign * baseValue;
  20424. },
  20425. getString: function Lexer_getString() {
  20426. var numParen = 1;
  20427. var done = false;
  20428. var strBuf = this.strBuf;
  20429. strBuf.length = 0;
  20430. var ch = this.nextChar();
  20431. while (true) {
  20432. var charBuffered = false;
  20433. switch (ch | 0) {
  20434. case -1:
  20435. warn('Unterminated string');
  20436. done = true;
  20437. break;
  20438. case 0x28: // '('
  20439. ++numParen;
  20440. strBuf.push('(');
  20441. break;
  20442. case 0x29: // ')'
  20443. if (--numParen === 0) {
  20444. this.nextChar(); // consume strings ')'
  20445. done = true;
  20446. } else {
  20447. strBuf.push(')');
  20448. }
  20449. break;
  20450. case 0x5C: // '\\'
  20451. ch = this.nextChar();
  20452. switch (ch) {
  20453. case -1:
  20454. warn('Unterminated string');
  20455. done = true;
  20456. break;
  20457. case 0x6E: // 'n'
  20458. strBuf.push('\n');
  20459. break;
  20460. case 0x72: // 'r'
  20461. strBuf.push('\r');
  20462. break;
  20463. case 0x74: // 't'
  20464. strBuf.push('\t');
  20465. break;
  20466. case 0x62: // 'b'
  20467. strBuf.push('\b');
  20468. break;
  20469. case 0x66: // 'f'
  20470. strBuf.push('\f');
  20471. break;
  20472. case 0x5C: // '\'
  20473. case 0x28: // '('
  20474. case 0x29: // ')'
  20475. strBuf.push(String.fromCharCode(ch));
  20476. break;
  20477. case 0x30: case 0x31: case 0x32: case 0x33: // '0'-'3'
  20478. case 0x34: case 0x35: case 0x36: case 0x37: // '4'-'7'
  20479. var x = ch & 0x0F;
  20480. ch = this.nextChar();
  20481. charBuffered = true;
  20482. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  20483. x = (x << 3) + (ch & 0x0F);
  20484. ch = this.nextChar();
  20485. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  20486. charBuffered = false;
  20487. x = (x << 3) + (ch & 0x0F);
  20488. }
  20489. }
  20490. strBuf.push(String.fromCharCode(x));
  20491. break;
  20492. case 0x0D: // CR
  20493. if (this.peekChar() === 0x0A) { // LF
  20494. this.nextChar();
  20495. }
  20496. break;
  20497. case 0x0A: // LF
  20498. break;
  20499. default:
  20500. strBuf.push(String.fromCharCode(ch));
  20501. break;
  20502. }
  20503. break;
  20504. default:
  20505. strBuf.push(String.fromCharCode(ch));
  20506. break;
  20507. }
  20508. if (done) {
  20509. break;
  20510. }
  20511. if (!charBuffered) {
  20512. ch = this.nextChar();
  20513. }
  20514. }
  20515. return strBuf.join('');
  20516. },
  20517. getName: function Lexer_getName() {
  20518. var ch, previousCh;
  20519. var strBuf = this.strBuf;
  20520. strBuf.length = 0;
  20521. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  20522. if (ch === 0x23) { // '#'
  20523. ch = this.nextChar();
  20524. if (specialChars[ch]) {
  20525. warn('Lexer_getName: ' +
  20526. 'NUMBER SIGN (#) should be followed by a hexadecimal number.');
  20527. strBuf.push('#');
  20528. break;
  20529. }
  20530. var x = toHexDigit(ch);
  20531. if (x !== -1) {
  20532. previousCh = ch;
  20533. ch = this.nextChar();
  20534. var x2 = toHexDigit(ch);
  20535. if (x2 === -1) {
  20536. warn('Lexer_getName: Illegal digit (' +
  20537. String.fromCharCode(ch) +') in hexadecimal number.');
  20538. strBuf.push('#', String.fromCharCode(previousCh));
  20539. if (specialChars[ch]) {
  20540. break;
  20541. }
  20542. strBuf.push(String.fromCharCode(ch));
  20543. continue;
  20544. }
  20545. strBuf.push(String.fromCharCode((x << 4) | x2));
  20546. } else {
  20547. strBuf.push('#', String.fromCharCode(ch));
  20548. }
  20549. } else {
  20550. strBuf.push(String.fromCharCode(ch));
  20551. }
  20552. }
  20553. if (strBuf.length > 127) {
  20554. warn('name token is longer than allowed by the spec: ' + strBuf.length);
  20555. }
  20556. return Name.get(strBuf.join(''));
  20557. },
  20558. getHexString: function Lexer_getHexString() {
  20559. var strBuf = this.strBuf;
  20560. strBuf.length = 0;
  20561. var ch = this.currentChar;
  20562. var isFirstHex = true;
  20563. var firstDigit;
  20564. var secondDigit;
  20565. while (true) {
  20566. if (ch < 0) {
  20567. warn('Unterminated hex string');
  20568. break;
  20569. } else if (ch === 0x3E) { // '>'
  20570. this.nextChar();
  20571. break;
  20572. } else if (specialChars[ch] === 1) {
  20573. ch = this.nextChar();
  20574. continue;
  20575. } else {
  20576. if (isFirstHex) {
  20577. firstDigit = toHexDigit(ch);
  20578. if (firstDigit === -1) {
  20579. warn('Ignoring invalid character "' + ch + '" in hex string');
  20580. ch = this.nextChar();
  20581. continue;
  20582. }
  20583. } else {
  20584. secondDigit = toHexDigit(ch);
  20585. if (secondDigit === -1) {
  20586. warn('Ignoring invalid character "' + ch + '" in hex string');
  20587. ch = this.nextChar();
  20588. continue;
  20589. }
  20590. strBuf.push(String.fromCharCode((firstDigit << 4) | secondDigit));
  20591. }
  20592. isFirstHex = !isFirstHex;
  20593. ch = this.nextChar();
  20594. }
  20595. }
  20596. return strBuf.join('');
  20597. },
  20598. getObj: function Lexer_getObj() {
  20599. // skip whitespace and comments
  20600. var comment = false;
  20601. var ch = this.currentChar;
  20602. while (true) {
  20603. if (ch < 0) {
  20604. return EOF;
  20605. }
  20606. if (comment) {
  20607. if (ch === 0x0A || ch === 0x0D) { // LF, CR
  20608. comment = false;
  20609. }
  20610. } else if (ch === 0x25) { // '%'
  20611. comment = true;
  20612. } else if (specialChars[ch] !== 1) {
  20613. break;
  20614. }
  20615. ch = this.nextChar();
  20616. }
  20617. // start reading token
  20618. switch (ch | 0) {
  20619. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  20620. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  20621. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  20622. return this.getNumber();
  20623. case 0x28: // '('
  20624. return this.getString();
  20625. case 0x2F: // '/'
  20626. return this.getName();
  20627. // array punctuation
  20628. case 0x5B: // '['
  20629. this.nextChar();
  20630. return Cmd.get('[');
  20631. case 0x5D: // ']'
  20632. this.nextChar();
  20633. return Cmd.get(']');
  20634. // hex string or dict punctuation
  20635. case 0x3C: // '<'
  20636. ch = this.nextChar();
  20637. if (ch === 0x3C) {
  20638. // dict punctuation
  20639. this.nextChar();
  20640. return Cmd.get('<<');
  20641. }
  20642. return this.getHexString();
  20643. // dict punctuation
  20644. case 0x3E: // '>'
  20645. ch = this.nextChar();
  20646. if (ch === 0x3E) {
  20647. this.nextChar();
  20648. return Cmd.get('>>');
  20649. }
  20650. return Cmd.get('>');
  20651. case 0x7B: // '{'
  20652. this.nextChar();
  20653. return Cmd.get('{');
  20654. case 0x7D: // '}'
  20655. this.nextChar();
  20656. return Cmd.get('}');
  20657. case 0x29: // ')'
  20658. error('Illegal character: ' + ch);
  20659. break;
  20660. }
  20661. // command
  20662. var str = String.fromCharCode(ch);
  20663. var knownCommands = this.knownCommands;
  20664. var knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  20665. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  20666. // stop if known command is found and next character does not make
  20667. // the str a command
  20668. var possibleCommand = str + String.fromCharCode(ch);
  20669. if (knownCommandFound && knownCommands[possibleCommand] === undefined) {
  20670. break;
  20671. }
  20672. if (str.length === 128) {
  20673. error('Command token too long: ' + str.length);
  20674. }
  20675. str = possibleCommand;
  20676. knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  20677. }
  20678. if (str === 'true') {
  20679. return true;
  20680. }
  20681. if (str === 'false') {
  20682. return false;
  20683. }
  20684. if (str === 'null') {
  20685. return null;
  20686. }
  20687. return Cmd.get(str);
  20688. },
  20689. skipToNextLine: function Lexer_skipToNextLine() {
  20690. var ch = this.currentChar;
  20691. while (ch >= 0) {
  20692. if (ch === 0x0D) { // CR
  20693. ch = this.nextChar();
  20694. if (ch === 0x0A) { // LF
  20695. this.nextChar();
  20696. }
  20697. break;
  20698. } else if (ch === 0x0A) { // LF
  20699. this.nextChar();
  20700. break;
  20701. }
  20702. ch = this.nextChar();
  20703. }
  20704. }
  20705. };
  20706. return Lexer;
  20707. })();
  20708. var Linearization = {
  20709. create: function LinearizationCreate(stream) {
  20710. function getInt(name, allowZeroValue) {
  20711. var obj = linDict.get(name);
  20712. if (isInt(obj) && (allowZeroValue ? obj >= 0 : obj > 0)) {
  20713. return obj;
  20714. }
  20715. throw new Error('The "' + name + '" parameter in the linearization ' +
  20716. 'dictionary is invalid.');
  20717. }
  20718. function getHints() {
  20719. var hints = linDict.get('H'), hintsLength, item;
  20720. if (isArray(hints) &&
  20721. ((hintsLength = hints.length) === 2 || hintsLength === 4)) {
  20722. for (var index = 0; index < hintsLength; index++) {
  20723. if (!(isInt(item = hints[index]) && item > 0)) {
  20724. throw new Error('Hint (' + index +
  20725. ') in the linearization dictionary is invalid.');
  20726. }
  20727. }
  20728. return hints;
  20729. }
  20730. throw new Error('Hint array in the linearization dictionary is invalid.');
  20731. }
  20732. var parser = new Parser(new Lexer(stream), false, null);
  20733. var obj1 = parser.getObj();
  20734. var obj2 = parser.getObj();
  20735. var obj3 = parser.getObj();
  20736. var linDict = parser.getObj();
  20737. var obj, length;
  20738. if (!(isInt(obj1) && isInt(obj2) && isCmd(obj3, 'obj') && isDict(linDict) &&
  20739. isNum(obj = linDict.get('Linearized')) && obj > 0)) {
  20740. return null; // No valid linearization dictionary found.
  20741. } else if ((length = getInt('L')) !== stream.length) {
  20742. throw new Error('The "L" parameter in the linearization dictionary ' +
  20743. 'does not equal the stream length.');
  20744. }
  20745. return {
  20746. length: length,
  20747. hints: getHints(),
  20748. objectNumberFirst: getInt('O'),
  20749. endFirst: getInt('E'),
  20750. numPages: getInt('N'),
  20751. mainXRefEntriesOffset: getInt('T'),
  20752. pageFirst: (linDict.has('P') ? getInt('P', true) : 0)
  20753. };
  20754. }
  20755. };
  20756. exports.EOF = EOF;
  20757. exports.Lexer = Lexer;
  20758. exports.Linearization = Linearization;
  20759. exports.Parser = Parser;
  20760. exports.isEOF = isEOF;
  20761. // TODO refactor to remove dependency on stream.js
  20762. coreStream._setCoreParser(exports);
  20763. }));
  20764. (function (root, factory) {
  20765. if (typeof define === 'function' && define.amd) {
  20766. define('pdfjs/core/cmap', ['exports', 'pdfjs/shared/util',
  20767. 'pdfjs/core/primitives', 'pdfjs/core/stream', 'pdfjs/core/parser'],
  20768. factory);
  20769. } else if (typeof exports !== 'undefined') {
  20770. factory(exports, require('../shared/util.js'), require('./primitives.js'),
  20771. require('./stream.js'), require('./parser.js'));
  20772. } else {
  20773. factory((root.pdfjsCoreCMap = {}), root.pdfjsSharedUtil,
  20774. root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreParser);
  20775. }
  20776. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreParser) {
  20777. var Util = sharedUtil.Util;
  20778. var assert = sharedUtil.assert;
  20779. var error = sharedUtil.error;
  20780. var isInt = sharedUtil.isInt;
  20781. var isString = sharedUtil.isString;
  20782. var warn = sharedUtil.warn;
  20783. var isName = corePrimitives.isName;
  20784. var isCmd = corePrimitives.isCmd;
  20785. var isStream = corePrimitives.isStream;
  20786. var StringStream = coreStream.StringStream;
  20787. var Lexer = coreParser.Lexer;
  20788. var isEOF = coreParser.isEOF;
  20789. var BUILT_IN_CMAPS = [
  20790. // << Start unicode maps.
  20791. 'Adobe-GB1-UCS2',
  20792. 'Adobe-CNS1-UCS2',
  20793. 'Adobe-Japan1-UCS2',
  20794. 'Adobe-Korea1-UCS2',
  20795. // >> End unicode maps.
  20796. '78-EUC-H',
  20797. '78-EUC-V',
  20798. '78-H',
  20799. '78-RKSJ-H',
  20800. '78-RKSJ-V',
  20801. '78-V',
  20802. '78ms-RKSJ-H',
  20803. '78ms-RKSJ-V',
  20804. '83pv-RKSJ-H',
  20805. '90ms-RKSJ-H',
  20806. '90ms-RKSJ-V',
  20807. '90msp-RKSJ-H',
  20808. '90msp-RKSJ-V',
  20809. '90pv-RKSJ-H',
  20810. '90pv-RKSJ-V',
  20811. 'Add-H',
  20812. 'Add-RKSJ-H',
  20813. 'Add-RKSJ-V',
  20814. 'Add-V',
  20815. 'Adobe-CNS1-0',
  20816. 'Adobe-CNS1-1',
  20817. 'Adobe-CNS1-2',
  20818. 'Adobe-CNS1-3',
  20819. 'Adobe-CNS1-4',
  20820. 'Adobe-CNS1-5',
  20821. 'Adobe-CNS1-6',
  20822. 'Adobe-GB1-0',
  20823. 'Adobe-GB1-1',
  20824. 'Adobe-GB1-2',
  20825. 'Adobe-GB1-3',
  20826. 'Adobe-GB1-4',
  20827. 'Adobe-GB1-5',
  20828. 'Adobe-Japan1-0',
  20829. 'Adobe-Japan1-1',
  20830. 'Adobe-Japan1-2',
  20831. 'Adobe-Japan1-3',
  20832. 'Adobe-Japan1-4',
  20833. 'Adobe-Japan1-5',
  20834. 'Adobe-Japan1-6',
  20835. 'Adobe-Korea1-0',
  20836. 'Adobe-Korea1-1',
  20837. 'Adobe-Korea1-2',
  20838. 'B5-H',
  20839. 'B5-V',
  20840. 'B5pc-H',
  20841. 'B5pc-V',
  20842. 'CNS-EUC-H',
  20843. 'CNS-EUC-V',
  20844. 'CNS1-H',
  20845. 'CNS1-V',
  20846. 'CNS2-H',
  20847. 'CNS2-V',
  20848. 'ETHK-B5-H',
  20849. 'ETHK-B5-V',
  20850. 'ETen-B5-H',
  20851. 'ETen-B5-V',
  20852. 'ETenms-B5-H',
  20853. 'ETenms-B5-V',
  20854. 'EUC-H',
  20855. 'EUC-V',
  20856. 'Ext-H',
  20857. 'Ext-RKSJ-H',
  20858. 'Ext-RKSJ-V',
  20859. 'Ext-V',
  20860. 'GB-EUC-H',
  20861. 'GB-EUC-V',
  20862. 'GB-H',
  20863. 'GB-V',
  20864. 'GBK-EUC-H',
  20865. 'GBK-EUC-V',
  20866. 'GBK2K-H',
  20867. 'GBK2K-V',
  20868. 'GBKp-EUC-H',
  20869. 'GBKp-EUC-V',
  20870. 'GBT-EUC-H',
  20871. 'GBT-EUC-V',
  20872. 'GBT-H',
  20873. 'GBT-V',
  20874. 'GBTpc-EUC-H',
  20875. 'GBTpc-EUC-V',
  20876. 'GBpc-EUC-H',
  20877. 'GBpc-EUC-V',
  20878. 'H',
  20879. 'HKdla-B5-H',
  20880. 'HKdla-B5-V',
  20881. 'HKdlb-B5-H',
  20882. 'HKdlb-B5-V',
  20883. 'HKgccs-B5-H',
  20884. 'HKgccs-B5-V',
  20885. 'HKm314-B5-H',
  20886. 'HKm314-B5-V',
  20887. 'HKm471-B5-H',
  20888. 'HKm471-B5-V',
  20889. 'HKscs-B5-H',
  20890. 'HKscs-B5-V',
  20891. 'Hankaku',
  20892. 'Hiragana',
  20893. 'KSC-EUC-H',
  20894. 'KSC-EUC-V',
  20895. 'KSC-H',
  20896. 'KSC-Johab-H',
  20897. 'KSC-Johab-V',
  20898. 'KSC-V',
  20899. 'KSCms-UHC-H',
  20900. 'KSCms-UHC-HW-H',
  20901. 'KSCms-UHC-HW-V',
  20902. 'KSCms-UHC-V',
  20903. 'KSCpc-EUC-H',
  20904. 'KSCpc-EUC-V',
  20905. 'Katakana',
  20906. 'NWP-H',
  20907. 'NWP-V',
  20908. 'RKSJ-H',
  20909. 'RKSJ-V',
  20910. 'Roman',
  20911. 'UniCNS-UCS2-H',
  20912. 'UniCNS-UCS2-V',
  20913. 'UniCNS-UTF16-H',
  20914. 'UniCNS-UTF16-V',
  20915. 'UniCNS-UTF32-H',
  20916. 'UniCNS-UTF32-V',
  20917. 'UniCNS-UTF8-H',
  20918. 'UniCNS-UTF8-V',
  20919. 'UniGB-UCS2-H',
  20920. 'UniGB-UCS2-V',
  20921. 'UniGB-UTF16-H',
  20922. 'UniGB-UTF16-V',
  20923. 'UniGB-UTF32-H',
  20924. 'UniGB-UTF32-V',
  20925. 'UniGB-UTF8-H',
  20926. 'UniGB-UTF8-V',
  20927. 'UniJIS-UCS2-H',
  20928. 'UniJIS-UCS2-HW-H',
  20929. 'UniJIS-UCS2-HW-V',
  20930. 'UniJIS-UCS2-V',
  20931. 'UniJIS-UTF16-H',
  20932. 'UniJIS-UTF16-V',
  20933. 'UniJIS-UTF32-H',
  20934. 'UniJIS-UTF32-V',
  20935. 'UniJIS-UTF8-H',
  20936. 'UniJIS-UTF8-V',
  20937. 'UniJIS2004-UTF16-H',
  20938. 'UniJIS2004-UTF16-V',
  20939. 'UniJIS2004-UTF32-H',
  20940. 'UniJIS2004-UTF32-V',
  20941. 'UniJIS2004-UTF8-H',
  20942. 'UniJIS2004-UTF8-V',
  20943. 'UniJISPro-UCS2-HW-V',
  20944. 'UniJISPro-UCS2-V',
  20945. 'UniJISPro-UTF8-V',
  20946. 'UniJISX0213-UTF32-H',
  20947. 'UniJISX0213-UTF32-V',
  20948. 'UniJISX02132004-UTF32-H',
  20949. 'UniJISX02132004-UTF32-V',
  20950. 'UniKS-UCS2-H',
  20951. 'UniKS-UCS2-V',
  20952. 'UniKS-UTF16-H',
  20953. 'UniKS-UTF16-V',
  20954. 'UniKS-UTF32-H',
  20955. 'UniKS-UTF32-V',
  20956. 'UniKS-UTF8-H',
  20957. 'UniKS-UTF8-V',
  20958. 'V',
  20959. 'WP-Symbol'];
  20960. // CMap, not to be confused with TrueType's cmap.
  20961. var CMap = (function CMapClosure() {
  20962. function CMap(builtInCMap) {
  20963. // Codespace ranges are stored as follows:
  20964. // [[1BytePairs], [2BytePairs], [3BytePairs], [4BytePairs]]
  20965. // where nBytePairs are ranges e.g. [low1, high1, low2, high2, ...]
  20966. this.codespaceRanges = [[], [], [], []];
  20967. this.numCodespaceRanges = 0;
  20968. // Map entries have one of two forms.
  20969. // - cid chars are 16-bit unsigned integers, stored as integers.
  20970. // - bf chars are variable-length byte sequences, stored as strings, with
  20971. // one byte per character.
  20972. this._map = [];
  20973. this.name = '';
  20974. this.vertical = false;
  20975. this.useCMap = null;
  20976. this.builtInCMap = builtInCMap;
  20977. }
  20978. CMap.prototype = {
  20979. addCodespaceRange: function(n, low, high) {
  20980. this.codespaceRanges[n - 1].push(low, high);
  20981. this.numCodespaceRanges++;
  20982. },
  20983. mapCidRange: function(low, high, dstLow) {
  20984. while (low <= high) {
  20985. this._map[low++] = dstLow++;
  20986. }
  20987. },
  20988. mapBfRange: function(low, high, dstLow) {
  20989. var lastByte = dstLow.length - 1;
  20990. while (low <= high) {
  20991. this._map[low++] = dstLow;
  20992. // Only the last byte has to be incremented.
  20993. dstLow = dstLow.substr(0, lastByte) +
  20994. String.fromCharCode(dstLow.charCodeAt(lastByte) + 1);
  20995. }
  20996. },
  20997. mapBfRangeToArray: function(low, high, array) {
  20998. var i = 0, ii = array.length;
  20999. while (low <= high && i < ii) {
  21000. this._map[low] = array[i++];
  21001. ++low;
  21002. }
  21003. },
  21004. // This is used for both bf and cid chars.
  21005. mapOne: function(src, dst) {
  21006. this._map[src] = dst;
  21007. },
  21008. lookup: function(code) {
  21009. return this._map[code];
  21010. },
  21011. contains: function(code) {
  21012. return this._map[code] !== undefined;
  21013. },
  21014. forEach: function(callback) {
  21015. // Most maps have fewer than 65536 entries, and for those we use normal
  21016. // array iteration. But really sparse tables are possible -- e.g. with
  21017. // indices in the *billions*. For such tables we use for..in, which isn't
  21018. // ideal because it stringifies the indices for all present elements, but
  21019. // it does avoid iterating over every undefined entry.
  21020. var map = this._map;
  21021. var length = map.length;
  21022. var i;
  21023. if (length <= 0x10000) {
  21024. for (i = 0; i < length; i++) {
  21025. if (map[i] !== undefined) {
  21026. callback(i, map[i]);
  21027. }
  21028. }
  21029. } else {
  21030. for (i in this._map) {
  21031. callback(i, map[i]);
  21032. }
  21033. }
  21034. },
  21035. charCodeOf: function(value) {
  21036. return this._map.indexOf(value);
  21037. },
  21038. getMap: function() {
  21039. return this._map;
  21040. },
  21041. readCharCode: function(str, offset, out) {
  21042. var c = 0;
  21043. var codespaceRanges = this.codespaceRanges;
  21044. var codespaceRangesLen = this.codespaceRanges.length;
  21045. // 9.7.6.2 CMap Mapping
  21046. // The code length is at most 4.
  21047. for (var n = 0; n < codespaceRangesLen; n++) {
  21048. c = ((c << 8) | str.charCodeAt(offset + n)) >>> 0;
  21049. // Check each codespace range to see if it falls within.
  21050. var codespaceRange = codespaceRanges[n];
  21051. for (var k = 0, kk = codespaceRange.length; k < kk;) {
  21052. var low = codespaceRange[k++];
  21053. var high = codespaceRange[k++];
  21054. if (c >= low && c <= high) {
  21055. out.charcode = c;
  21056. out.length = n + 1;
  21057. return;
  21058. }
  21059. }
  21060. }
  21061. out.charcode = 0;
  21062. out.length = 1;
  21063. },
  21064. get length() {
  21065. return this._map.length;
  21066. },
  21067. get isIdentityCMap() {
  21068. if (!(this.name === 'Identity-H' || this.name === 'Identity-V')) {
  21069. return false;
  21070. }
  21071. if (this._map.length !== 0x10000) {
  21072. return false;
  21073. }
  21074. for (var i = 0; i < 0x10000; i++) {
  21075. if (this._map[i] !== i) {
  21076. return false;
  21077. }
  21078. }
  21079. return true;
  21080. }
  21081. };
  21082. return CMap;
  21083. })();
  21084. // A special case of CMap, where the _map array implicitly has a length of
  21085. // 65536 and each element is equal to its index.
  21086. var IdentityCMap = (function IdentityCMapClosure() {
  21087. function IdentityCMap(vertical, n) {
  21088. CMap.call(this);
  21089. this.vertical = vertical;
  21090. this.addCodespaceRange(n, 0, 0xffff);
  21091. }
  21092. Util.inherit(IdentityCMap, CMap, {});
  21093. IdentityCMap.prototype = {
  21094. addCodespaceRange: CMap.prototype.addCodespaceRange,
  21095. mapCidRange: function(low, high, dstLow) {
  21096. error('should not call mapCidRange');
  21097. },
  21098. mapBfRange: function(low, high, dstLow) {
  21099. error('should not call mapBfRange');
  21100. },
  21101. mapBfRangeToArray: function(low, high, array) {
  21102. error('should not call mapBfRangeToArray');
  21103. },
  21104. mapOne: function(src, dst) {
  21105. error('should not call mapCidOne');
  21106. },
  21107. lookup: function(code) {
  21108. return (isInt(code) && code <= 0xffff) ? code : undefined;
  21109. },
  21110. contains: function(code) {
  21111. return isInt(code) && code <= 0xffff;
  21112. },
  21113. forEach: function(callback) {
  21114. for (var i = 0; i <= 0xffff; i++) {
  21115. callback(i, i);
  21116. }
  21117. },
  21118. charCodeOf: function(value) {
  21119. return (isInt(value) && value <= 0xffff) ? value : -1;
  21120. },
  21121. getMap: function() {
  21122. // Sometimes identity maps must be instantiated, but it's rare.
  21123. var map = new Array(0x10000);
  21124. for (var i = 0; i <= 0xffff; i++) {
  21125. map[i] = i;
  21126. }
  21127. return map;
  21128. },
  21129. readCharCode: CMap.prototype.readCharCode,
  21130. get length() {
  21131. return 0x10000;
  21132. },
  21133. get isIdentityCMap() {
  21134. error('should not access .isIdentityCMap');
  21135. }
  21136. };
  21137. return IdentityCMap;
  21138. })();
  21139. var BinaryCMapReader = (function BinaryCMapReaderClosure() {
  21140. function fetchBinaryData(url) {
  21141. var nonBinaryRequest = PDFJS.disableWorker;
  21142. var request = new XMLHttpRequest();
  21143. request.open('GET', url, false);
  21144. if (!nonBinaryRequest) {
  21145. try {
  21146. request.responseType = 'arraybuffer';
  21147. nonBinaryRequest = request.responseType !== 'arraybuffer';
  21148. } catch (e) {
  21149. nonBinaryRequest = true;
  21150. }
  21151. }
  21152. if (nonBinaryRequest && request.overrideMimeType) {
  21153. request.overrideMimeType('text/plain; charset=x-user-defined');
  21154. }
  21155. request.send(null);
  21156. if (nonBinaryRequest ? !request.responseText : !request.response) {
  21157. error('Unable to get binary cMap at: ' + url);
  21158. }
  21159. if (nonBinaryRequest) {
  21160. var data = Array.prototype.map.call(request.responseText, function (ch) {
  21161. return ch.charCodeAt(0) & 255;
  21162. });
  21163. return new Uint8Array(data);
  21164. }
  21165. return new Uint8Array(request.response);
  21166. }
  21167. function hexToInt(a, size) {
  21168. var n = 0;
  21169. for (var i = 0; i <= size; i++) {
  21170. n = (n << 8) | a[i];
  21171. }
  21172. return n >>> 0;
  21173. }
  21174. function hexToStr(a, size) {
  21175. // This code is hot. Special-case some common values to avoid creating an
  21176. // object with subarray().
  21177. if (size === 1) {
  21178. return String.fromCharCode(a[0], a[1]);
  21179. }
  21180. if (size === 3) {
  21181. return String.fromCharCode(a[0], a[1], a[2], a[3]);
  21182. }
  21183. return String.fromCharCode.apply(null, a.subarray(0, size + 1));
  21184. }
  21185. function addHex(a, b, size) {
  21186. var c = 0;
  21187. for (var i = size; i >= 0; i--) {
  21188. c += a[i] + b[i];
  21189. a[i] = c & 255;
  21190. c >>= 8;
  21191. }
  21192. }
  21193. function incHex(a, size) {
  21194. var c = 1;
  21195. for (var i = size; i >= 0 && c > 0; i--) {
  21196. c += a[i];
  21197. a[i] = c & 255;
  21198. c >>= 8;
  21199. }
  21200. }
  21201. var MAX_NUM_SIZE = 16;
  21202. var MAX_ENCODED_NUM_SIZE = 19; // ceil(MAX_NUM_SIZE * 7 / 8)
  21203. function BinaryCMapStream(data) {
  21204. this.buffer = data;
  21205. this.pos = 0;
  21206. this.end = data.length;
  21207. this.tmpBuf = new Uint8Array(MAX_ENCODED_NUM_SIZE);
  21208. }
  21209. BinaryCMapStream.prototype = {
  21210. readByte: function () {
  21211. if (this.pos >= this.end) {
  21212. return -1;
  21213. }
  21214. return this.buffer[this.pos++];
  21215. },
  21216. readNumber: function () {
  21217. var n = 0;
  21218. var last;
  21219. do {
  21220. var b = this.readByte();
  21221. if (b < 0) {
  21222. error('unexpected EOF in bcmap');
  21223. }
  21224. last = !(b & 0x80);
  21225. n = (n << 7) | (b & 0x7F);
  21226. } while (!last);
  21227. return n;
  21228. },
  21229. readSigned: function () {
  21230. var n = this.readNumber();
  21231. return (n & 1) ? ~(n >>> 1) : n >>> 1;
  21232. },
  21233. readHex: function (num, size) {
  21234. num.set(this.buffer.subarray(this.pos,
  21235. this.pos + size + 1));
  21236. this.pos += size + 1;
  21237. },
  21238. readHexNumber: function (num, size) {
  21239. var last;
  21240. var stack = this.tmpBuf, sp = 0;
  21241. do {
  21242. var b = this.readByte();
  21243. if (b < 0) {
  21244. error('unexpected EOF in bcmap');
  21245. }
  21246. last = !(b & 0x80);
  21247. stack[sp++] = b & 0x7F;
  21248. } while (!last);
  21249. var i = size, buffer = 0, bufferSize = 0;
  21250. while (i >= 0) {
  21251. while (bufferSize < 8 && stack.length > 0) {
  21252. buffer = (stack[--sp] << bufferSize) | buffer;
  21253. bufferSize += 7;
  21254. }
  21255. num[i] = buffer & 255;
  21256. i--;
  21257. buffer >>= 8;
  21258. bufferSize -= 8;
  21259. }
  21260. },
  21261. readHexSigned: function (num, size) {
  21262. this.readHexNumber(num, size);
  21263. var sign = num[size] & 1 ? 255 : 0;
  21264. var c = 0;
  21265. for (var i = 0; i <= size; i++) {
  21266. c = ((c & 1) << 8) | num[i];
  21267. num[i] = (c >> 1) ^ sign;
  21268. }
  21269. },
  21270. readString: function () {
  21271. var len = this.readNumber();
  21272. var s = '';
  21273. for (var i = 0; i < len; i++) {
  21274. s += String.fromCharCode(this.readNumber());
  21275. }
  21276. return s;
  21277. }
  21278. };
  21279. function processBinaryCMap(url, cMap, extend) {
  21280. var data = fetchBinaryData(url);
  21281. var stream = new BinaryCMapStream(data);
  21282. var header = stream.readByte();
  21283. cMap.vertical = !!(header & 1);
  21284. var useCMap = null;
  21285. var start = new Uint8Array(MAX_NUM_SIZE);
  21286. var end = new Uint8Array(MAX_NUM_SIZE);
  21287. var char = new Uint8Array(MAX_NUM_SIZE);
  21288. var charCode = new Uint8Array(MAX_NUM_SIZE);
  21289. var tmp = new Uint8Array(MAX_NUM_SIZE);
  21290. var code;
  21291. var b;
  21292. while ((b = stream.readByte()) >= 0) {
  21293. var type = b >> 5;
  21294. if (type === 7) { // metadata, e.g. comment or usecmap
  21295. switch (b & 0x1F) {
  21296. case 0:
  21297. stream.readString(); // skipping comment
  21298. break;
  21299. case 1:
  21300. useCMap = stream.readString();
  21301. break;
  21302. }
  21303. continue;
  21304. }
  21305. var sequence = !!(b & 0x10);
  21306. var dataSize = b & 15;
  21307. assert(dataSize + 1 <= MAX_NUM_SIZE);
  21308. var ucs2DataSize = 1;
  21309. var subitemsCount = stream.readNumber();
  21310. var i;
  21311. switch (type) {
  21312. case 0: // codespacerange
  21313. stream.readHex(start, dataSize);
  21314. stream.readHexNumber(end, dataSize);
  21315. addHex(end, start, dataSize);
  21316. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  21317. hexToInt(end, dataSize));
  21318. for (i = 1; i < subitemsCount; i++) {
  21319. incHex(end, dataSize);
  21320. stream.readHexNumber(start, dataSize);
  21321. addHex(start, end, dataSize);
  21322. stream.readHexNumber(end, dataSize);
  21323. addHex(end, start, dataSize);
  21324. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  21325. hexToInt(end, dataSize));
  21326. }
  21327. break;
  21328. case 1: // notdefrange
  21329. stream.readHex(start, dataSize);
  21330. stream.readHexNumber(end, dataSize);
  21331. addHex(end, start, dataSize);
  21332. code = stream.readNumber();
  21333. // undefined range, skipping
  21334. for (i = 1; i < subitemsCount; i++) {
  21335. incHex(end, dataSize);
  21336. stream.readHexNumber(start, dataSize);
  21337. addHex(start, end, dataSize);
  21338. stream.readHexNumber(end, dataSize);
  21339. addHex(end, start, dataSize);
  21340. code = stream.readNumber();
  21341. // nop
  21342. }
  21343. break;
  21344. case 2: // cidchar
  21345. stream.readHex(char, dataSize);
  21346. code = stream.readNumber();
  21347. cMap.mapOne(hexToInt(char, dataSize), code);
  21348. for (i = 1; i < subitemsCount; i++) {
  21349. incHex(char, dataSize);
  21350. if (!sequence) {
  21351. stream.readHexNumber(tmp, dataSize);
  21352. addHex(char, tmp, dataSize);
  21353. }
  21354. code = stream.readSigned() + (code + 1);
  21355. cMap.mapOne(hexToInt(char, dataSize), code);
  21356. }
  21357. break;
  21358. case 3: // cidrange
  21359. stream.readHex(start, dataSize);
  21360. stream.readHexNumber(end, dataSize);
  21361. addHex(end, start, dataSize);
  21362. code = stream.readNumber();
  21363. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  21364. code);
  21365. for (i = 1; i < subitemsCount; i++) {
  21366. incHex(end, dataSize);
  21367. if (!sequence) {
  21368. stream.readHexNumber(start, dataSize);
  21369. addHex(start, end, dataSize);
  21370. } else {
  21371. start.set(end);
  21372. }
  21373. stream.readHexNumber(end, dataSize);
  21374. addHex(end, start, dataSize);
  21375. code = stream.readNumber();
  21376. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  21377. code);
  21378. }
  21379. break;
  21380. case 4: // bfchar
  21381. stream.readHex(char, ucs2DataSize);
  21382. stream.readHex(charCode, dataSize);
  21383. cMap.mapOne(hexToInt(char, ucs2DataSize),
  21384. hexToStr(charCode, dataSize));
  21385. for (i = 1; i < subitemsCount; i++) {
  21386. incHex(char, ucs2DataSize);
  21387. if (!sequence) {
  21388. stream.readHexNumber(tmp, ucs2DataSize);
  21389. addHex(char, tmp, ucs2DataSize);
  21390. }
  21391. incHex(charCode, dataSize);
  21392. stream.readHexSigned(tmp, dataSize);
  21393. addHex(charCode, tmp, dataSize);
  21394. cMap.mapOne(hexToInt(char, ucs2DataSize),
  21395. hexToStr(charCode, dataSize));
  21396. }
  21397. break;
  21398. case 5: // bfrange
  21399. stream.readHex(start, ucs2DataSize);
  21400. stream.readHexNumber(end, ucs2DataSize);
  21401. addHex(end, start, ucs2DataSize);
  21402. stream.readHex(charCode, dataSize);
  21403. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  21404. hexToInt(end, ucs2DataSize),
  21405. hexToStr(charCode, dataSize));
  21406. for (i = 1; i < subitemsCount; i++) {
  21407. incHex(end, ucs2DataSize);
  21408. if (!sequence) {
  21409. stream.readHexNumber(start, ucs2DataSize);
  21410. addHex(start, end, ucs2DataSize);
  21411. } else {
  21412. start.set(end);
  21413. }
  21414. stream.readHexNumber(end, ucs2DataSize);
  21415. addHex(end, start, ucs2DataSize);
  21416. stream.readHex(charCode, dataSize);
  21417. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  21418. hexToInt(end, ucs2DataSize),
  21419. hexToStr(charCode, dataSize));
  21420. }
  21421. break;
  21422. default:
  21423. error('Unknown type: ' + type);
  21424. break;
  21425. }
  21426. }
  21427. if (useCMap) {
  21428. extend(useCMap);
  21429. }
  21430. return cMap;
  21431. }
  21432. function BinaryCMapReader() {}
  21433. BinaryCMapReader.prototype = {
  21434. read: processBinaryCMap
  21435. };
  21436. return BinaryCMapReader;
  21437. })();
  21438. var CMapFactory = (function CMapFactoryClosure() {
  21439. function strToInt(str) {
  21440. var a = 0;
  21441. for (var i = 0; i < str.length; i++) {
  21442. a = (a << 8) | str.charCodeAt(i);
  21443. }
  21444. return a >>> 0;
  21445. }
  21446. function expectString(obj) {
  21447. if (!isString(obj)) {
  21448. error('Malformed CMap: expected string.');
  21449. }
  21450. }
  21451. function expectInt(obj) {
  21452. if (!isInt(obj)) {
  21453. error('Malformed CMap: expected int.');
  21454. }
  21455. }
  21456. function parseBfChar(cMap, lexer) {
  21457. while (true) {
  21458. var obj = lexer.getObj();
  21459. if (isEOF(obj)) {
  21460. break;
  21461. }
  21462. if (isCmd(obj, 'endbfchar')) {
  21463. return;
  21464. }
  21465. expectString(obj);
  21466. var src = strToInt(obj);
  21467. obj = lexer.getObj();
  21468. // TODO are /dstName used?
  21469. expectString(obj);
  21470. var dst = obj;
  21471. cMap.mapOne(src, dst);
  21472. }
  21473. }
  21474. function parseBfRange(cMap, lexer) {
  21475. while (true) {
  21476. var obj = lexer.getObj();
  21477. if (isEOF(obj)) {
  21478. break;
  21479. }
  21480. if (isCmd(obj, 'endbfrange')) {
  21481. return;
  21482. }
  21483. expectString(obj);
  21484. var low = strToInt(obj);
  21485. obj = lexer.getObj();
  21486. expectString(obj);
  21487. var high = strToInt(obj);
  21488. obj = lexer.getObj();
  21489. if (isInt(obj) || isString(obj)) {
  21490. var dstLow = isInt(obj) ? String.fromCharCode(obj) : obj;
  21491. cMap.mapBfRange(low, high, dstLow);
  21492. } else if (isCmd(obj, '[')) {
  21493. obj = lexer.getObj();
  21494. var array = [];
  21495. while (!isCmd(obj, ']') && !isEOF(obj)) {
  21496. array.push(obj);
  21497. obj = lexer.getObj();
  21498. }
  21499. cMap.mapBfRangeToArray(low, high, array);
  21500. } else {
  21501. break;
  21502. }
  21503. }
  21504. error('Invalid bf range.');
  21505. }
  21506. function parseCidChar(cMap, lexer) {
  21507. while (true) {
  21508. var obj = lexer.getObj();
  21509. if (isEOF(obj)) {
  21510. break;
  21511. }
  21512. if (isCmd(obj, 'endcidchar')) {
  21513. return;
  21514. }
  21515. expectString(obj);
  21516. var src = strToInt(obj);
  21517. obj = lexer.getObj();
  21518. expectInt(obj);
  21519. var dst = obj;
  21520. cMap.mapOne(src, dst);
  21521. }
  21522. }
  21523. function parseCidRange(cMap, lexer) {
  21524. while (true) {
  21525. var obj = lexer.getObj();
  21526. if (isEOF(obj)) {
  21527. break;
  21528. }
  21529. if (isCmd(obj, 'endcidrange')) {
  21530. return;
  21531. }
  21532. expectString(obj);
  21533. var low = strToInt(obj);
  21534. obj = lexer.getObj();
  21535. expectString(obj);
  21536. var high = strToInt(obj);
  21537. obj = lexer.getObj();
  21538. expectInt(obj);
  21539. var dstLow = obj;
  21540. cMap.mapCidRange(low, high, dstLow);
  21541. }
  21542. }
  21543. function parseCodespaceRange(cMap, lexer) {
  21544. while (true) {
  21545. var obj = lexer.getObj();
  21546. if (isEOF(obj)) {
  21547. break;
  21548. }
  21549. if (isCmd(obj, 'endcodespacerange')) {
  21550. return;
  21551. }
  21552. if (!isString(obj)) {
  21553. break;
  21554. }
  21555. var low = strToInt(obj);
  21556. obj = lexer.getObj();
  21557. if (!isString(obj)) {
  21558. break;
  21559. }
  21560. var high = strToInt(obj);
  21561. cMap.addCodespaceRange(obj.length, low, high);
  21562. }
  21563. error('Invalid codespace range.');
  21564. }
  21565. function parseWMode(cMap, lexer) {
  21566. var obj = lexer.getObj();
  21567. if (isInt(obj)) {
  21568. cMap.vertical = !!obj;
  21569. }
  21570. }
  21571. function parseCMapName(cMap, lexer) {
  21572. var obj = lexer.getObj();
  21573. if (isName(obj) && isString(obj.name)) {
  21574. cMap.name = obj.name;
  21575. }
  21576. }
  21577. function parseCMap(cMap, lexer, builtInCMapParams, useCMap) {
  21578. var previous;
  21579. var embededUseCMap;
  21580. objLoop: while (true) {
  21581. var obj = lexer.getObj();
  21582. if (isEOF(obj)) {
  21583. break;
  21584. } else if (isName(obj)) {
  21585. if (obj.name === 'WMode') {
  21586. parseWMode(cMap, lexer);
  21587. } else if (obj.name === 'CMapName') {
  21588. parseCMapName(cMap, lexer);
  21589. }
  21590. previous = obj;
  21591. } else if (isCmd(obj)) {
  21592. switch (obj.cmd) {
  21593. case 'endcmap':
  21594. break objLoop;
  21595. case 'usecmap':
  21596. if (isName(previous)) {
  21597. embededUseCMap = previous.name;
  21598. }
  21599. break;
  21600. case 'begincodespacerange':
  21601. parseCodespaceRange(cMap, lexer);
  21602. break;
  21603. case 'beginbfchar':
  21604. parseBfChar(cMap, lexer);
  21605. break;
  21606. case 'begincidchar':
  21607. parseCidChar(cMap, lexer);
  21608. break;
  21609. case 'beginbfrange':
  21610. parseBfRange(cMap, lexer);
  21611. break;
  21612. case 'begincidrange':
  21613. parseCidRange(cMap, lexer);
  21614. break;
  21615. }
  21616. }
  21617. }
  21618. if (!useCMap && embededUseCMap) {
  21619. // Load the usecmap definition from the file only if there wasn't one
  21620. // specified.
  21621. useCMap = embededUseCMap;
  21622. }
  21623. if (useCMap) {
  21624. extendCMap(cMap, builtInCMapParams, useCMap);
  21625. }
  21626. }
  21627. function extendCMap(cMap, builtInCMapParams, useCMap) {
  21628. cMap.useCMap = createBuiltInCMap(useCMap, builtInCMapParams);
  21629. // If there aren't any code space ranges defined clone all the parent ones
  21630. // into this cMap.
  21631. if (cMap.numCodespaceRanges === 0) {
  21632. var useCodespaceRanges = cMap.useCMap.codespaceRanges;
  21633. for (var i = 0; i < useCodespaceRanges.length; i++) {
  21634. cMap.codespaceRanges[i] = useCodespaceRanges[i].slice();
  21635. }
  21636. cMap.numCodespaceRanges = cMap.useCMap.numCodespaceRanges;
  21637. }
  21638. // Merge the map into the current one, making sure not to override
  21639. // any previously defined entries.
  21640. cMap.useCMap.forEach(function(key, value) {
  21641. if (!cMap.contains(key)) {
  21642. cMap.mapOne(key, cMap.useCMap.lookup(key));
  21643. }
  21644. });
  21645. }
  21646. function parseBinaryCMap(name, builtInCMapParams) {
  21647. var url = builtInCMapParams.url + name + '.bcmap';
  21648. var cMap = new CMap(true);
  21649. new BinaryCMapReader().read(url, cMap, function (useCMap) {
  21650. extendCMap(cMap, builtInCMapParams, useCMap);
  21651. });
  21652. return cMap;
  21653. }
  21654. function createBuiltInCMap(name, builtInCMapParams) {
  21655. if (name === 'Identity-H') {
  21656. return new IdentityCMap(false, 2);
  21657. } else if (name === 'Identity-V') {
  21658. return new IdentityCMap(true, 2);
  21659. }
  21660. if (BUILT_IN_CMAPS.indexOf(name) === -1) {
  21661. error('Unknown cMap name: ' + name);
  21662. }
  21663. assert(builtInCMapParams, 'built-in cMap parameters are not provided');
  21664. if (builtInCMapParams.packed) {
  21665. return parseBinaryCMap(name, builtInCMapParams);
  21666. }
  21667. var request = new XMLHttpRequest();
  21668. var url = builtInCMapParams.url + name;
  21669. request.open('GET', url, false);
  21670. request.send(null);
  21671. if (!request.responseText) {
  21672. error('Unable to get cMap at: ' + url);
  21673. }
  21674. var cMap = new CMap(true);
  21675. var lexer = new Lexer(new StringStream(request.responseText));
  21676. parseCMap(cMap, lexer, builtInCMapParams, null);
  21677. return cMap;
  21678. }
  21679. return {
  21680. create: function (encoding, builtInCMapParams, useCMap) {
  21681. if (isName(encoding)) {
  21682. return createBuiltInCMap(encoding.name, builtInCMapParams);
  21683. } else if (isStream(encoding)) {
  21684. var cMap = new CMap();
  21685. var lexer = new Lexer(encoding);
  21686. try {
  21687. parseCMap(cMap, lexer, builtInCMapParams, useCMap);
  21688. } catch (e) {
  21689. warn('Invalid CMap data. ' + e);
  21690. }
  21691. if (cMap.isIdentityCMap) {
  21692. return createBuiltInCMap(cMap.name, builtInCMapParams);
  21693. }
  21694. return cMap;
  21695. }
  21696. error('Encoding required.');
  21697. }
  21698. };
  21699. })();
  21700. exports.CMap = CMap;
  21701. exports.CMapFactory = CMapFactory;
  21702. exports.IdentityCMap = IdentityCMap;
  21703. }));
  21704. (function (root, factory) {
  21705. if (typeof define === 'function' && define.amd) {
  21706. define('pdfjs/core/obj', ['exports', 'pdfjs/shared/util',
  21707. 'pdfjs/core/primitives', 'pdfjs/core/crypto', 'pdfjs/core/parser',
  21708. 'pdfjs/core/chunked_stream'], factory);
  21709. } else if (typeof exports !== 'undefined') {
  21710. factory(exports, require('../shared/util.js'), require('./primitives.js'),
  21711. require('./crypto.js'), require('./parser.js'),
  21712. require('./chunked_stream.js'));
  21713. } else {
  21714. factory((root.pdfjsCoreObj = {}), root.pdfjsSharedUtil,
  21715. root.pdfjsCorePrimitives, root.pdfjsCoreCrypto, root.pdfjsCoreParser,
  21716. root.pdfjsCoreChunkedStream);
  21717. }
  21718. }(this, function (exports, sharedUtil, corePrimitives, coreCrypto, coreParser,
  21719. coreChunkedStream) {
  21720. var InvalidPDFException = sharedUtil.InvalidPDFException;
  21721. var MissingDataException = sharedUtil.MissingDataException;
  21722. var XRefParseException = sharedUtil.XRefParseException;
  21723. var assert = sharedUtil.assert;
  21724. var bytesToString = sharedUtil.bytesToString;
  21725. var createPromiseCapability = sharedUtil.createPromiseCapability;
  21726. var error = sharedUtil.error;
  21727. var info = sharedUtil.info;
  21728. var isArray = sharedUtil.isArray;
  21729. var isInt = sharedUtil.isInt;
  21730. var isString = sharedUtil.isString;
  21731. var shadow = sharedUtil.shadow;
  21732. var stringToPDFString = sharedUtil.stringToPDFString;
  21733. var stringToUTF8String = sharedUtil.stringToUTF8String;
  21734. var warn = sharedUtil.warn;
  21735. var Ref = corePrimitives.Ref;
  21736. var RefSet = corePrimitives.RefSet;
  21737. var RefSetCache = corePrimitives.RefSetCache;
  21738. var isName = corePrimitives.isName;
  21739. var isCmd = corePrimitives.isCmd;
  21740. var isDict = corePrimitives.isDict;
  21741. var isRef = corePrimitives.isRef;
  21742. var isStream = corePrimitives.isStream;
  21743. var CipherTransformFactory = coreCrypto.CipherTransformFactory;
  21744. var Lexer = coreParser.Lexer;
  21745. var Parser = coreParser.Parser;
  21746. var ChunkedStream = coreChunkedStream.ChunkedStream;
  21747. var Catalog = (function CatalogClosure() {
  21748. function Catalog(pdfManager, xref, pageFactory) {
  21749. this.pdfManager = pdfManager;
  21750. this.xref = xref;
  21751. this.catDict = xref.getCatalogObj();
  21752. this.fontCache = new RefSetCache();
  21753. assert(isDict(this.catDict),
  21754. 'catalog object is not a dictionary');
  21755. // TODO refactor to move getPage() to the PDFDocument.
  21756. this.pageFactory = pageFactory;
  21757. this.pagePromises = [];
  21758. }
  21759. Catalog.prototype = {
  21760. get metadata() {
  21761. var streamRef = this.catDict.getRaw('Metadata');
  21762. if (!isRef(streamRef)) {
  21763. return shadow(this, 'metadata', null);
  21764. }
  21765. var encryptMetadata = (!this.xref.encrypt ? false :
  21766. this.xref.encrypt.encryptMetadata);
  21767. var stream = this.xref.fetch(streamRef, !encryptMetadata);
  21768. var metadata;
  21769. if (stream && isDict(stream.dict)) {
  21770. var type = stream.dict.get('Type');
  21771. var subtype = stream.dict.get('Subtype');
  21772. if (isName(type) && isName(subtype) &&
  21773. type.name === 'Metadata' && subtype.name === 'XML') {
  21774. // XXX: This should examine the charset the XML document defines,
  21775. // however since there are currently no real means to decode
  21776. // arbitrary charsets, let's just hope that the author of the PDF
  21777. // was reasonable enough to stick with the XML default charset,
  21778. // which is UTF-8.
  21779. try {
  21780. metadata = stringToUTF8String(bytesToString(stream.getBytes()));
  21781. } catch (e) {
  21782. info('Skipping invalid metadata.');
  21783. }
  21784. }
  21785. }
  21786. return shadow(this, 'metadata', metadata);
  21787. },
  21788. get toplevelPagesDict() {
  21789. var pagesObj = this.catDict.get('Pages');
  21790. assert(isDict(pagesObj), 'invalid top-level pages dictionary');
  21791. // shadow the prototype getter
  21792. return shadow(this, 'toplevelPagesDict', pagesObj);
  21793. },
  21794. get documentOutline() {
  21795. var obj = null;
  21796. try {
  21797. obj = this.readDocumentOutline();
  21798. } catch (ex) {
  21799. if (ex instanceof MissingDataException) {
  21800. throw ex;
  21801. }
  21802. warn('Unable to read document outline');
  21803. }
  21804. return shadow(this, 'documentOutline', obj);
  21805. },
  21806. readDocumentOutline: function Catalog_readDocumentOutline() {
  21807. var xref = this.xref;
  21808. var obj = this.catDict.get('Outlines');
  21809. var root = { items: [] };
  21810. if (isDict(obj)) {
  21811. obj = obj.getRaw('First');
  21812. var processed = new RefSet();
  21813. if (isRef(obj)) {
  21814. var queue = [{obj: obj, parent: root}];
  21815. // to avoid recursion keeping track of the items
  21816. // in the processed dictionary
  21817. processed.put(obj);
  21818. while (queue.length > 0) {
  21819. var i = queue.shift();
  21820. var outlineDict = xref.fetchIfRef(i.obj);
  21821. if (outlineDict === null) {
  21822. continue;
  21823. }
  21824. if (!outlineDict.has('Title')) {
  21825. error('Invalid outline item');
  21826. }
  21827. var dest = outlineDict.get('A');
  21828. if (dest) {
  21829. dest = dest.get('D');
  21830. } else if (outlineDict.has('Dest')) {
  21831. dest = outlineDict.getRaw('Dest');
  21832. if (isName(dest)) {
  21833. dest = dest.name;
  21834. }
  21835. }
  21836. var title = outlineDict.get('Title');
  21837. var outlineItem = {
  21838. dest: dest,
  21839. title: stringToPDFString(title),
  21840. color: outlineDict.get('C') || [0, 0, 0],
  21841. count: outlineDict.get('Count'),
  21842. bold: !!(outlineDict.get('F') & 2),
  21843. italic: !!(outlineDict.get('F') & 1),
  21844. items: []
  21845. };
  21846. i.parent.items.push(outlineItem);
  21847. obj = outlineDict.getRaw('First');
  21848. if (isRef(obj) && !processed.has(obj)) {
  21849. queue.push({obj: obj, parent: outlineItem});
  21850. processed.put(obj);
  21851. }
  21852. obj = outlineDict.getRaw('Next');
  21853. if (isRef(obj) && !processed.has(obj)) {
  21854. queue.push({obj: obj, parent: i.parent});
  21855. processed.put(obj);
  21856. }
  21857. }
  21858. }
  21859. }
  21860. return (root.items.length > 0 ? root.items : null);
  21861. },
  21862. get numPages() {
  21863. var obj = this.toplevelPagesDict.get('Count');
  21864. assert(
  21865. isInt(obj),
  21866. 'page count in top level pages object is not an integer'
  21867. );
  21868. // shadow the prototype getter
  21869. return shadow(this, 'num', obj);
  21870. },
  21871. get destinations() {
  21872. function fetchDestination(dest) {
  21873. return isDict(dest) ? dest.get('D') : dest;
  21874. }
  21875. var xref = this.xref;
  21876. var dests = {}, nameTreeRef, nameDictionaryRef;
  21877. var obj = this.catDict.get('Names');
  21878. if (obj && obj.has('Dests')) {
  21879. nameTreeRef = obj.getRaw('Dests');
  21880. } else if (this.catDict.has('Dests')) {
  21881. nameDictionaryRef = this.catDict.get('Dests');
  21882. }
  21883. if (nameDictionaryRef) {
  21884. // reading simple destination dictionary
  21885. obj = nameDictionaryRef;
  21886. obj.forEach(function catalogForEach(key, value) {
  21887. if (!value) {
  21888. return;
  21889. }
  21890. dests[key] = fetchDestination(value);
  21891. });
  21892. }
  21893. if (nameTreeRef) {
  21894. var nameTree = new NameTree(nameTreeRef, xref);
  21895. var names = nameTree.getAll();
  21896. for (var name in names) {
  21897. if (!names.hasOwnProperty(name)) {
  21898. continue;
  21899. }
  21900. dests[name] = fetchDestination(names[name]);
  21901. }
  21902. }
  21903. return shadow(this, 'destinations', dests);
  21904. },
  21905. getDestination: function Catalog_getDestination(destinationId) {
  21906. function fetchDestination(dest) {
  21907. return isDict(dest) ? dest.get('D') : dest;
  21908. }
  21909. var xref = this.xref;
  21910. var dest = null, nameTreeRef, nameDictionaryRef;
  21911. var obj = this.catDict.get('Names');
  21912. if (obj && obj.has('Dests')) {
  21913. nameTreeRef = obj.getRaw('Dests');
  21914. } else if (this.catDict.has('Dests')) {
  21915. nameDictionaryRef = this.catDict.get('Dests');
  21916. }
  21917. if (nameDictionaryRef) { // Simple destination dictionary.
  21918. var value = nameDictionaryRef.get(destinationId);
  21919. if (value) {
  21920. dest = fetchDestination(value);
  21921. }
  21922. }
  21923. if (nameTreeRef) {
  21924. var nameTree = new NameTree(nameTreeRef, xref);
  21925. dest = fetchDestination(nameTree.get(destinationId));
  21926. }
  21927. return dest;
  21928. },
  21929. get attachments() {
  21930. var xref = this.xref;
  21931. var attachments = null, nameTreeRef;
  21932. var obj = this.catDict.get('Names');
  21933. if (obj) {
  21934. nameTreeRef = obj.getRaw('EmbeddedFiles');
  21935. }
  21936. if (nameTreeRef) {
  21937. var nameTree = new NameTree(nameTreeRef, xref);
  21938. var names = nameTree.getAll();
  21939. for (var name in names) {
  21940. if (!names.hasOwnProperty(name)) {
  21941. continue;
  21942. }
  21943. var fs = new FileSpec(names[name], xref);
  21944. if (!attachments) {
  21945. attachments = {};
  21946. }
  21947. attachments[stringToPDFString(name)] = fs.serializable;
  21948. }
  21949. }
  21950. return shadow(this, 'attachments', attachments);
  21951. },
  21952. get javaScript() {
  21953. var xref = this.xref;
  21954. var obj = this.catDict.get('Names');
  21955. var javaScript = [];
  21956. function appendIfJavaScriptDict(jsDict) {
  21957. var type = jsDict.get('S');
  21958. if (!isName(type) || type.name !== 'JavaScript') {
  21959. return;
  21960. }
  21961. var js = jsDict.get('JS');
  21962. if (isStream(js)) {
  21963. js = bytesToString(js.getBytes());
  21964. } else if (!isString(js)) {
  21965. return;
  21966. }
  21967. javaScript.push(stringToPDFString(js));
  21968. }
  21969. if (obj && obj.has('JavaScript')) {
  21970. var nameTree = new NameTree(obj.getRaw('JavaScript'), xref);
  21971. var names = nameTree.getAll();
  21972. for (var name in names) {
  21973. if (!names.hasOwnProperty(name)) {
  21974. continue;
  21975. }
  21976. // We don't really use the JavaScript right now. This code is
  21977. // defensive so we don't cause errors on document load.
  21978. var jsDict = names[name];
  21979. if (isDict(jsDict)) {
  21980. appendIfJavaScriptDict(jsDict);
  21981. }
  21982. }
  21983. }
  21984. // Append OpenAction actions to javaScript array
  21985. var openactionDict = this.catDict.get('OpenAction');
  21986. if (isDict(openactionDict, 'Action')) {
  21987. var actionType = openactionDict.get('S');
  21988. if (isName(actionType) && actionType.name === 'Named') {
  21989. // The named Print action is not a part of the PDF 1.7 specification,
  21990. // but is supported by many PDF readers/writers (including Adobe's).
  21991. var action = openactionDict.get('N');
  21992. if (isName(action) && action.name === 'Print') {
  21993. javaScript.push('print({});');
  21994. }
  21995. } else {
  21996. appendIfJavaScriptDict(openactionDict);
  21997. }
  21998. }
  21999. return shadow(this, 'javaScript', javaScript);
  22000. },
  22001. cleanup: function Catalog_cleanup() {
  22002. var promises = [];
  22003. this.fontCache.forEach(function (promise) {
  22004. promises.push(promise);
  22005. });
  22006. return Promise.all(promises).then(function (translatedFonts) {
  22007. for (var i = 0, ii = translatedFonts.length; i < ii; i++) {
  22008. var font = translatedFonts[i].dict;
  22009. delete font.translated;
  22010. }
  22011. this.fontCache.clear();
  22012. }.bind(this));
  22013. },
  22014. getPage: function Catalog_getPage(pageIndex) {
  22015. if (!(pageIndex in this.pagePromises)) {
  22016. this.pagePromises[pageIndex] = this.getPageDict(pageIndex).then(
  22017. function (a) {
  22018. var dict = a[0];
  22019. var ref = a[1];
  22020. return this.pageFactory.createPage(pageIndex, dict, ref,
  22021. this.fontCache);
  22022. }.bind(this)
  22023. );
  22024. }
  22025. return this.pagePromises[pageIndex];
  22026. },
  22027. getPageDict: function Catalog_getPageDict(pageIndex) {
  22028. var capability = createPromiseCapability();
  22029. var nodesToVisit = [this.catDict.getRaw('Pages')];
  22030. var currentPageIndex = 0;
  22031. var xref = this.xref;
  22032. var checkAllKids = false;
  22033. function next() {
  22034. while (nodesToVisit.length) {
  22035. var currentNode = nodesToVisit.pop();
  22036. if (isRef(currentNode)) {
  22037. xref.fetchAsync(currentNode).then(function (obj) {
  22038. if (isDict(obj, 'Page') || (isDict(obj) && !obj.has('Kids'))) {
  22039. if (pageIndex === currentPageIndex) {
  22040. capability.resolve([obj, currentNode]);
  22041. } else {
  22042. currentPageIndex++;
  22043. next();
  22044. }
  22045. return;
  22046. }
  22047. nodesToVisit.push(obj);
  22048. next();
  22049. }, capability.reject);
  22050. return;
  22051. }
  22052. // Must be a child page dictionary.
  22053. assert(
  22054. isDict(currentNode),
  22055. 'page dictionary kid reference points to wrong type of object'
  22056. );
  22057. var count = currentNode.get('Count');
  22058. // If the current node doesn't have any children, avoid getting stuck
  22059. // in an empty node further down in the tree (see issue5644.pdf).
  22060. if (count === 0) {
  22061. checkAllKids = true;
  22062. }
  22063. // Skip nodes where the page can't be.
  22064. if (currentPageIndex + count <= pageIndex) {
  22065. currentPageIndex += count;
  22066. continue;
  22067. }
  22068. var kids = currentNode.get('Kids');
  22069. assert(isArray(kids), 'page dictionary kids object is not an array');
  22070. if (!checkAllKids && count === kids.length) {
  22071. // Nodes that don't have the page have been skipped and this is the
  22072. // bottom of the tree which means the page requested must be a
  22073. // descendant of this pages node. Ideally we would just resolve the
  22074. // promise with the page ref here, but there is the case where more
  22075. // pages nodes could link to single a page (see issue 3666 pdf). To
  22076. // handle this push it back on the queue so if it is a pages node it
  22077. // will be descended into.
  22078. nodesToVisit = [kids[pageIndex - currentPageIndex]];
  22079. currentPageIndex = pageIndex;
  22080. continue;
  22081. } else {
  22082. for (var last = kids.length - 1; last >= 0; last--) {
  22083. nodesToVisit.push(kids[last]);
  22084. }
  22085. }
  22086. }
  22087. capability.reject('Page index ' + pageIndex + ' not found.');
  22088. }
  22089. next();
  22090. return capability.promise;
  22091. },
  22092. getPageIndex: function Catalog_getPageIndex(ref) {
  22093. // The page tree nodes have the count of all the leaves below them. To get
  22094. // how many pages are before we just have to walk up the tree and keep
  22095. // adding the count of siblings to the left of the node.
  22096. var xref = this.xref;
  22097. function pagesBeforeRef(kidRef) {
  22098. var total = 0;
  22099. var parentRef;
  22100. return xref.fetchAsync(kidRef).then(function (node) {
  22101. if (!node) {
  22102. return null;
  22103. }
  22104. parentRef = node.getRaw('Parent');
  22105. return node.getAsync('Parent');
  22106. }).then(function (parent) {
  22107. if (!parent) {
  22108. return null;
  22109. }
  22110. return parent.getAsync('Kids');
  22111. }).then(function (kids) {
  22112. if (!kids) {
  22113. return null;
  22114. }
  22115. var kidPromises = [];
  22116. var found = false;
  22117. for (var i = 0; i < kids.length; i++) {
  22118. var kid = kids[i];
  22119. assert(isRef(kid), 'kids must be a ref');
  22120. if (kid.num === kidRef.num) {
  22121. found = true;
  22122. break;
  22123. }
  22124. kidPromises.push(xref.fetchAsync(kid).then(function (kid) {
  22125. if (kid.has('Count')) {
  22126. var count = kid.get('Count');
  22127. total += count;
  22128. } else { // page leaf node
  22129. total++;
  22130. }
  22131. }));
  22132. }
  22133. if (!found) {
  22134. error('kid ref not found in parents kids');
  22135. }
  22136. return Promise.all(kidPromises).then(function () {
  22137. return [total, parentRef];
  22138. });
  22139. });
  22140. }
  22141. var total = 0;
  22142. function next(ref) {
  22143. return pagesBeforeRef(ref).then(function (args) {
  22144. if (!args) {
  22145. return total;
  22146. }
  22147. var count = args[0];
  22148. var parentRef = args[1];
  22149. total += count;
  22150. return next(parentRef);
  22151. });
  22152. }
  22153. return next(ref);
  22154. }
  22155. };
  22156. return Catalog;
  22157. })();
  22158. var XRef = (function XRefClosure() {
  22159. function XRef(stream, password) {
  22160. this.stream = stream;
  22161. this.entries = [];
  22162. this.xrefstms = {};
  22163. // prepare the XRef cache
  22164. this.cache = [];
  22165. this.password = password;
  22166. this.stats = {
  22167. streamTypes: [],
  22168. fontTypes: []
  22169. };
  22170. }
  22171. XRef.prototype = {
  22172. setStartXRef: function XRef_setStartXRef(startXRef) {
  22173. // Store the starting positions of xref tables as we process them
  22174. // so we can recover from missing data errors
  22175. this.startXRefQueue = [startXRef];
  22176. },
  22177. parse: function XRef_parse(recoveryMode) {
  22178. var trailerDict;
  22179. if (!recoveryMode) {
  22180. trailerDict = this.readXRef();
  22181. } else {
  22182. warn('Indexing all PDF objects');
  22183. trailerDict = this.indexObjects();
  22184. }
  22185. trailerDict.assignXref(this);
  22186. this.trailer = trailerDict;
  22187. var encrypt = trailerDict.get('Encrypt');
  22188. if (encrypt) {
  22189. var ids = trailerDict.get('ID');
  22190. var fileId = (ids && ids.length) ? ids[0] : '';
  22191. this.encrypt = new CipherTransformFactory(encrypt, fileId,
  22192. this.password);
  22193. }
  22194. // get the root dictionary (catalog) object
  22195. if (!(this.root = trailerDict.get('Root'))) {
  22196. error('Invalid root reference');
  22197. }
  22198. },
  22199. processXRefTable: function XRef_processXRefTable(parser) {
  22200. if (!('tableState' in this)) {
  22201. // Stores state of the table as we process it so we can resume
  22202. // from middle of table in case of missing data error
  22203. this.tableState = {
  22204. entryNum: 0,
  22205. streamPos: parser.lexer.stream.pos,
  22206. parserBuf1: parser.buf1,
  22207. parserBuf2: parser.buf2
  22208. };
  22209. }
  22210. var obj = this.readXRefTable(parser);
  22211. // Sanity check
  22212. if (!isCmd(obj, 'trailer')) {
  22213. error('Invalid XRef table: could not find trailer dictionary');
  22214. }
  22215. // Read trailer dictionary, e.g.
  22216. // trailer
  22217. // << /Size 22
  22218. // /Root 20R
  22219. // /Info 10R
  22220. // /ID [ <81b14aafa313db63dbd6f981e49f94f4> ]
  22221. // >>
  22222. // The parser goes through the entire stream << ... >> and provides
  22223. // a getter interface for the key-value table
  22224. var dict = parser.getObj();
  22225. // The pdflib PDF generator can generate a nested trailer dictionary
  22226. if (!isDict(dict) && dict.dict) {
  22227. dict = dict.dict;
  22228. }
  22229. if (!isDict(dict)) {
  22230. error('Invalid XRef table: could not parse trailer dictionary');
  22231. }
  22232. delete this.tableState;
  22233. return dict;
  22234. },
  22235. readXRefTable: function XRef_readXRefTable(parser) {
  22236. // Example of cross-reference table:
  22237. // xref
  22238. // 0 1 <-- subsection header (first obj #, obj count)
  22239. // 0000000000 65535 f <-- actual object (offset, generation #, f/n)
  22240. // 23 2 <-- subsection header ... and so on ...
  22241. // 0000025518 00002 n
  22242. // 0000025635 00000 n
  22243. // trailer
  22244. // ...
  22245. var stream = parser.lexer.stream;
  22246. var tableState = this.tableState;
  22247. stream.pos = tableState.streamPos;
  22248. parser.buf1 = tableState.parserBuf1;
  22249. parser.buf2 = tableState.parserBuf2;
  22250. // Outer loop is over subsection headers
  22251. var obj;
  22252. while (true) {
  22253. if (!('firstEntryNum' in tableState) || !('entryCount' in tableState)) {
  22254. if (isCmd(obj = parser.getObj(), 'trailer')) {
  22255. break;
  22256. }
  22257. tableState.firstEntryNum = obj;
  22258. tableState.entryCount = parser.getObj();
  22259. }
  22260. var first = tableState.firstEntryNum;
  22261. var count = tableState.entryCount;
  22262. if (!isInt(first) || !isInt(count)) {
  22263. error('Invalid XRef table: wrong types in subsection header');
  22264. }
  22265. // Inner loop is over objects themselves
  22266. for (var i = tableState.entryNum; i < count; i++) {
  22267. tableState.streamPos = stream.pos;
  22268. tableState.entryNum = i;
  22269. tableState.parserBuf1 = parser.buf1;
  22270. tableState.parserBuf2 = parser.buf2;
  22271. var entry = {};
  22272. entry.offset = parser.getObj();
  22273. entry.gen = parser.getObj();
  22274. var type = parser.getObj();
  22275. if (isCmd(type, 'f')) {
  22276. entry.free = true;
  22277. } else if (isCmd(type, 'n')) {
  22278. entry.uncompressed = true;
  22279. }
  22280. // Validate entry obj
  22281. if (!isInt(entry.offset) || !isInt(entry.gen) ||
  22282. !(entry.free || entry.uncompressed)) {
  22283. error('Invalid entry in XRef subsection: ' + first + ', ' + count);
  22284. }
  22285. if (!this.entries[i + first]) {
  22286. this.entries[i + first] = entry;
  22287. }
  22288. }
  22289. tableState.entryNum = 0;
  22290. tableState.streamPos = stream.pos;
  22291. tableState.parserBuf1 = parser.buf1;
  22292. tableState.parserBuf2 = parser.buf2;
  22293. delete tableState.firstEntryNum;
  22294. delete tableState.entryCount;
  22295. }
  22296. // Per issue 3248: hp scanners generate bad XRef
  22297. if (first === 1 && this.entries[1] && this.entries[1].free) {
  22298. // shifting the entries
  22299. this.entries.shift();
  22300. }
  22301. // Sanity check: as per spec, first object must be free
  22302. if (this.entries[0] && !this.entries[0].free) {
  22303. error('Invalid XRef table: unexpected first object');
  22304. }
  22305. return obj;
  22306. },
  22307. processXRefStream: function XRef_processXRefStream(stream) {
  22308. if (!('streamState' in this)) {
  22309. // Stores state of the stream as we process it so we can resume
  22310. // from middle of stream in case of missing data error
  22311. var streamParameters = stream.dict;
  22312. var byteWidths = streamParameters.get('W');
  22313. var range = streamParameters.get('Index');
  22314. if (!range) {
  22315. range = [0, streamParameters.get('Size')];
  22316. }
  22317. this.streamState = {
  22318. entryRanges: range,
  22319. byteWidths: byteWidths,
  22320. entryNum: 0,
  22321. streamPos: stream.pos
  22322. };
  22323. }
  22324. this.readXRefStream(stream);
  22325. delete this.streamState;
  22326. return stream.dict;
  22327. },
  22328. readXRefStream: function XRef_readXRefStream(stream) {
  22329. var i, j;
  22330. var streamState = this.streamState;
  22331. stream.pos = streamState.streamPos;
  22332. var byteWidths = streamState.byteWidths;
  22333. var typeFieldWidth = byteWidths[0];
  22334. var offsetFieldWidth = byteWidths[1];
  22335. var generationFieldWidth = byteWidths[2];
  22336. var entryRanges = streamState.entryRanges;
  22337. while (entryRanges.length > 0) {
  22338. var first = entryRanges[0];
  22339. var n = entryRanges[1];
  22340. if (!isInt(first) || !isInt(n)) {
  22341. error('Invalid XRef range fields: ' + first + ', ' + n);
  22342. }
  22343. if (!isInt(typeFieldWidth) || !isInt(offsetFieldWidth) ||
  22344. !isInt(generationFieldWidth)) {
  22345. error('Invalid XRef entry fields length: ' + first + ', ' + n);
  22346. }
  22347. for (i = streamState.entryNum; i < n; ++i) {
  22348. streamState.entryNum = i;
  22349. streamState.streamPos = stream.pos;
  22350. var type = 0, offset = 0, generation = 0;
  22351. for (j = 0; j < typeFieldWidth; ++j) {
  22352. type = (type << 8) | stream.getByte();
  22353. }
  22354. // if type field is absent, its default value is 1
  22355. if (typeFieldWidth === 0) {
  22356. type = 1;
  22357. }
  22358. for (j = 0; j < offsetFieldWidth; ++j) {
  22359. offset = (offset << 8) | stream.getByte();
  22360. }
  22361. for (j = 0; j < generationFieldWidth; ++j) {
  22362. generation = (generation << 8) | stream.getByte();
  22363. }
  22364. var entry = {};
  22365. entry.offset = offset;
  22366. entry.gen = generation;
  22367. switch (type) {
  22368. case 0:
  22369. entry.free = true;
  22370. break;
  22371. case 1:
  22372. entry.uncompressed = true;
  22373. break;
  22374. case 2:
  22375. break;
  22376. default:
  22377. error('Invalid XRef entry type: ' + type);
  22378. }
  22379. if (!this.entries[first + i]) {
  22380. this.entries[first + i] = entry;
  22381. }
  22382. }
  22383. streamState.entryNum = 0;
  22384. streamState.streamPos = stream.pos;
  22385. entryRanges.splice(0, 2);
  22386. }
  22387. },
  22388. indexObjects: function XRef_indexObjects() {
  22389. // Simple scan through the PDF content to find objects,
  22390. // trailers and XRef streams.
  22391. var TAB = 0x9, LF = 0xA, CR = 0xD, SPACE = 0x20;
  22392. var PERCENT = 0x25, LT = 0x3C;
  22393. function readToken(data, offset) {
  22394. var token = '', ch = data[offset];
  22395. while (ch !== LF && ch !== CR && ch !== LT) {
  22396. if (++offset >= data.length) {
  22397. break;
  22398. }
  22399. token += String.fromCharCode(ch);
  22400. ch = data[offset];
  22401. }
  22402. return token;
  22403. }
  22404. function skipUntil(data, offset, what) {
  22405. var length = what.length, dataLength = data.length;
  22406. var skipped = 0;
  22407. // finding byte sequence
  22408. while (offset < dataLength) {
  22409. var i = 0;
  22410. while (i < length && data[offset + i] === what[i]) {
  22411. ++i;
  22412. }
  22413. if (i >= length) {
  22414. break; // sequence found
  22415. }
  22416. offset++;
  22417. skipped++;
  22418. }
  22419. return skipped;
  22420. }
  22421. var objRegExp = /^(\d+)\s+(\d+)\s+obj\b/;
  22422. var trailerBytes = new Uint8Array([116, 114, 97, 105, 108, 101, 114]);
  22423. var startxrefBytes = new Uint8Array([115, 116, 97, 114, 116, 120, 114,
  22424. 101, 102]);
  22425. var endobjBytes = new Uint8Array([101, 110, 100, 111, 98, 106]);
  22426. var xrefBytes = new Uint8Array([47, 88, 82, 101, 102]);
  22427. // Clear out any existing entries, since they may be bogus.
  22428. this.entries.length = 0;
  22429. var stream = this.stream;
  22430. stream.pos = 0;
  22431. var buffer = stream.getBytes();
  22432. var position = stream.start, length = buffer.length;
  22433. var trailers = [], xrefStms = [];
  22434. while (position < length) {
  22435. var ch = buffer[position];
  22436. if (ch === TAB || ch === LF || ch === CR || ch === SPACE) {
  22437. ++position;
  22438. continue;
  22439. }
  22440. if (ch === PERCENT) { // %-comment
  22441. do {
  22442. ++position;
  22443. if (position >= length) {
  22444. break;
  22445. }
  22446. ch = buffer[position];
  22447. } while (ch !== LF && ch !== CR);
  22448. continue;
  22449. }
  22450. var token = readToken(buffer, position);
  22451. var m;
  22452. if (token.indexOf('xref') === 0 &&
  22453. (token.length === 4 || /\s/.test(token[4]))) {
  22454. position += skipUntil(buffer, position, trailerBytes);
  22455. trailers.push(position);
  22456. position += skipUntil(buffer, position, startxrefBytes);
  22457. } else if ((m = objRegExp.exec(token))) {
  22458. if (typeof this.entries[m[1]] === 'undefined') {
  22459. this.entries[m[1]] = {
  22460. offset: position - stream.start,
  22461. gen: m[2] | 0,
  22462. uncompressed: true
  22463. };
  22464. }
  22465. var contentLength = skipUntil(buffer, position, endobjBytes) + 7;
  22466. var content = buffer.subarray(position, position + contentLength);
  22467. // checking XRef stream suspect
  22468. // (it shall have '/XRef' and next char is not a letter)
  22469. var xrefTagOffset = skipUntil(content, 0, xrefBytes);
  22470. if (xrefTagOffset < contentLength &&
  22471. content[xrefTagOffset + 5] < 64) {
  22472. xrefStms.push(position - stream.start);
  22473. this.xrefstms[position - stream.start] = 1; // Avoid recursion
  22474. }
  22475. position += contentLength;
  22476. } else if (token.indexOf('trailer') === 0 &&
  22477. (token.length === 7 || /\s/.test(token[7]))) {
  22478. trailers.push(position);
  22479. position += skipUntil(buffer, position, startxrefBytes);
  22480. } else {
  22481. position += token.length + 1;
  22482. }
  22483. }
  22484. // reading XRef streams
  22485. var i, ii;
  22486. for (i = 0, ii = xrefStms.length; i < ii; ++i) {
  22487. this.startXRefQueue.push(xrefStms[i]);
  22488. this.readXRef(/* recoveryMode */ true);
  22489. }
  22490. // finding main trailer
  22491. var dict;
  22492. for (i = 0, ii = trailers.length; i < ii; ++i) {
  22493. stream.pos = trailers[i];
  22494. var parser = new Parser(new Lexer(stream), true, this);
  22495. var obj = parser.getObj();
  22496. if (!isCmd(obj, 'trailer')) {
  22497. continue;
  22498. }
  22499. // read the trailer dictionary
  22500. if (!isDict(dict = parser.getObj())) {
  22501. continue;
  22502. }
  22503. // taking the first one with 'ID'
  22504. if (dict.has('ID')) {
  22505. return dict;
  22506. }
  22507. }
  22508. // no tailer with 'ID', taking last one (if exists)
  22509. if (dict) {
  22510. return dict;
  22511. }
  22512. // nothing helps
  22513. // calling error() would reject worker with an UnknownErrorException.
  22514. throw new InvalidPDFException('Invalid PDF structure');
  22515. },
  22516. readXRef: function XRef_readXRef(recoveryMode) {
  22517. var stream = this.stream;
  22518. try {
  22519. while (this.startXRefQueue.length) {
  22520. var startXRef = this.startXRefQueue[0];
  22521. stream.pos = startXRef + stream.start;
  22522. var parser = new Parser(new Lexer(stream), true, this);
  22523. var obj = parser.getObj();
  22524. var dict;
  22525. // Get dictionary
  22526. if (isCmd(obj, 'xref')) {
  22527. // Parse end-of-file XRef
  22528. dict = this.processXRefTable(parser);
  22529. if (!this.topDict) {
  22530. this.topDict = dict;
  22531. }
  22532. // Recursively get other XRefs 'XRefStm', if any
  22533. obj = dict.get('XRefStm');
  22534. if (isInt(obj)) {
  22535. var pos = obj;
  22536. // ignore previously loaded xref streams
  22537. // (possible infinite recursion)
  22538. if (!(pos in this.xrefstms)) {
  22539. this.xrefstms[pos] = 1;
  22540. this.startXRefQueue.push(pos);
  22541. }
  22542. }
  22543. } else if (isInt(obj)) {
  22544. // Parse in-stream XRef
  22545. if (!isInt(parser.getObj()) ||
  22546. !isCmd(parser.getObj(), 'obj') ||
  22547. !isStream(obj = parser.getObj())) {
  22548. error('Invalid XRef stream');
  22549. }
  22550. dict = this.processXRefStream(obj);
  22551. if (!this.topDict) {
  22552. this.topDict = dict;
  22553. }
  22554. if (!dict) {
  22555. error('Failed to read XRef stream');
  22556. }
  22557. } else {
  22558. error('Invalid XRef stream header');
  22559. }
  22560. // Recursively get previous dictionary, if any
  22561. obj = dict.get('Prev');
  22562. if (isInt(obj)) {
  22563. this.startXRefQueue.push(obj);
  22564. } else if (isRef(obj)) {
  22565. // The spec says Prev must not be a reference, i.e. "/Prev NNN"
  22566. // This is a fallback for non-compliant PDFs, i.e. "/Prev NNN 0 R"
  22567. this.startXRefQueue.push(obj.num);
  22568. }
  22569. this.startXRefQueue.shift();
  22570. }
  22571. return this.topDict;
  22572. } catch (e) {
  22573. if (e instanceof MissingDataException) {
  22574. throw e;
  22575. }
  22576. info('(while reading XRef): ' + e);
  22577. }
  22578. if (recoveryMode) {
  22579. return;
  22580. }
  22581. throw new XRefParseException();
  22582. },
  22583. getEntry: function XRef_getEntry(i) {
  22584. var xrefEntry = this.entries[i];
  22585. if (xrefEntry && !xrefEntry.free && xrefEntry.offset) {
  22586. return xrefEntry;
  22587. }
  22588. return null;
  22589. },
  22590. fetchIfRef: function XRef_fetchIfRef(obj) {
  22591. if (!isRef(obj)) {
  22592. return obj;
  22593. }
  22594. return this.fetch(obj);
  22595. },
  22596. fetch: function XRef_fetch(ref, suppressEncryption) {
  22597. assert(isRef(ref), 'ref object is not a reference');
  22598. var num = ref.num;
  22599. if (num in this.cache) {
  22600. var cacheEntry = this.cache[num];
  22601. return cacheEntry;
  22602. }
  22603. var xrefEntry = this.getEntry(num);
  22604. // the referenced entry can be free
  22605. if (xrefEntry === null) {
  22606. return (this.cache[num] = null);
  22607. }
  22608. if (xrefEntry.uncompressed) {
  22609. xrefEntry = this.fetchUncompressed(ref, xrefEntry, suppressEncryption);
  22610. } else {
  22611. xrefEntry = this.fetchCompressed(xrefEntry, suppressEncryption);
  22612. }
  22613. if (isDict(xrefEntry)){
  22614. xrefEntry.objId = ref.toString();
  22615. } else if (isStream(xrefEntry)) {
  22616. xrefEntry.dict.objId = ref.toString();
  22617. }
  22618. return xrefEntry;
  22619. },
  22620. fetchUncompressed: function XRef_fetchUncompressed(ref, xrefEntry,
  22621. suppressEncryption) {
  22622. var gen = ref.gen;
  22623. var num = ref.num;
  22624. if (xrefEntry.gen !== gen) {
  22625. error('inconsistent generation in XRef');
  22626. }
  22627. var stream = this.stream.makeSubStream(xrefEntry.offset +
  22628. this.stream.start);
  22629. var parser = new Parser(new Lexer(stream), true, this);
  22630. var obj1 = parser.getObj();
  22631. var obj2 = parser.getObj();
  22632. var obj3 = parser.getObj();
  22633. if (!isInt(obj1) || parseInt(obj1, 10) !== num ||
  22634. !isInt(obj2) || parseInt(obj2, 10) !== gen ||
  22635. !isCmd(obj3)) {
  22636. error('bad XRef entry');
  22637. }
  22638. if (!isCmd(obj3, 'obj')) {
  22639. // some bad PDFs use "obj1234" and really mean 1234
  22640. if (obj3.cmd.indexOf('obj') === 0) {
  22641. num = parseInt(obj3.cmd.substring(3), 10);
  22642. if (!isNaN(num)) {
  22643. return num;
  22644. }
  22645. }
  22646. error('bad XRef entry');
  22647. }
  22648. if (this.encrypt && !suppressEncryption) {
  22649. xrefEntry = parser.getObj(this.encrypt.createCipherTransform(num, gen));
  22650. } else {
  22651. xrefEntry = parser.getObj();
  22652. }
  22653. if (!isStream(xrefEntry)) {
  22654. this.cache[num] = xrefEntry;
  22655. }
  22656. return xrefEntry;
  22657. },
  22658. fetchCompressed: function XRef_fetchCompressed(xrefEntry,
  22659. suppressEncryption) {
  22660. var tableOffset = xrefEntry.offset;
  22661. var stream = this.fetch(new Ref(tableOffset, 0));
  22662. if (!isStream(stream)) {
  22663. error('bad ObjStm stream');
  22664. }
  22665. var first = stream.dict.get('First');
  22666. var n = stream.dict.get('N');
  22667. if (!isInt(first) || !isInt(n)) {
  22668. error('invalid first and n parameters for ObjStm stream');
  22669. }
  22670. var parser = new Parser(new Lexer(stream), false, this);
  22671. parser.allowStreams = true;
  22672. var i, entries = [], num, nums = [];
  22673. // read the object numbers to populate cache
  22674. for (i = 0; i < n; ++i) {
  22675. num = parser.getObj();
  22676. if (!isInt(num)) {
  22677. error('invalid object number in the ObjStm stream: ' + num);
  22678. }
  22679. nums.push(num);
  22680. var offset = parser.getObj();
  22681. if (!isInt(offset)) {
  22682. error('invalid object offset in the ObjStm stream: ' + offset);
  22683. }
  22684. }
  22685. // read stream objects for cache
  22686. for (i = 0; i < n; ++i) {
  22687. entries.push(parser.getObj());
  22688. num = nums[i];
  22689. var entry = this.entries[num];
  22690. if (entry && entry.offset === tableOffset && entry.gen === i) {
  22691. this.cache[num] = entries[i];
  22692. }
  22693. }
  22694. xrefEntry = entries[xrefEntry.gen];
  22695. if (xrefEntry === undefined) {
  22696. error('bad XRef entry for compressed object');
  22697. }
  22698. return xrefEntry;
  22699. },
  22700. fetchIfRefAsync: function XRef_fetchIfRefAsync(obj) {
  22701. if (!isRef(obj)) {
  22702. return Promise.resolve(obj);
  22703. }
  22704. return this.fetchAsync(obj);
  22705. },
  22706. fetchAsync: function XRef_fetchAsync(ref, suppressEncryption) {
  22707. var streamManager = this.stream.manager;
  22708. var xref = this;
  22709. return new Promise(function tryFetch(resolve, reject) {
  22710. try {
  22711. resolve(xref.fetch(ref, suppressEncryption));
  22712. } catch (e) {
  22713. if (e instanceof MissingDataException) {
  22714. streamManager.requestRange(e.begin, e.end).then(function () {
  22715. tryFetch(resolve, reject);
  22716. }, reject);
  22717. return;
  22718. }
  22719. reject(e);
  22720. }
  22721. });
  22722. },
  22723. getCatalogObj: function XRef_getCatalogObj() {
  22724. return this.root;
  22725. }
  22726. };
  22727. return XRef;
  22728. })();
  22729. /**
  22730. * A NameTree is like a Dict but has some advantageous properties, see the
  22731. * spec (7.9.6) for more details.
  22732. * TODO: implement all the Dict functions and make this more efficent.
  22733. */
  22734. var NameTree = (function NameTreeClosure() {
  22735. function NameTree(root, xref) {
  22736. this.root = root;
  22737. this.xref = xref;
  22738. }
  22739. NameTree.prototype = {
  22740. getAll: function NameTree_getAll() {
  22741. var dict = {};
  22742. if (!this.root) {
  22743. return dict;
  22744. }
  22745. var xref = this.xref;
  22746. // reading name tree
  22747. var processed = new RefSet();
  22748. processed.put(this.root);
  22749. var queue = [this.root];
  22750. while (queue.length > 0) {
  22751. var i, n;
  22752. var obj = xref.fetchIfRef(queue.shift());
  22753. if (!isDict(obj)) {
  22754. continue;
  22755. }
  22756. if (obj.has('Kids')) {
  22757. var kids = obj.get('Kids');
  22758. for (i = 0, n = kids.length; i < n; i++) {
  22759. var kid = kids[i];
  22760. if (processed.has(kid)) {
  22761. error('invalid destinations');
  22762. }
  22763. queue.push(kid);
  22764. processed.put(kid);
  22765. }
  22766. continue;
  22767. }
  22768. var names = obj.get('Names');
  22769. if (names) {
  22770. for (i = 0, n = names.length; i < n; i += 2) {
  22771. dict[xref.fetchIfRef(names[i])] = xref.fetchIfRef(names[i + 1]);
  22772. }
  22773. }
  22774. }
  22775. return dict;
  22776. },
  22777. get: function NameTree_get(destinationId) {
  22778. if (!this.root) {
  22779. return null;
  22780. }
  22781. var xref = this.xref;
  22782. var kidsOrNames = xref.fetchIfRef(this.root);
  22783. var loopCount = 0;
  22784. var MAX_NAMES_LEVELS = 10;
  22785. var l, r, m;
  22786. // Perform a binary search to quickly find the entry that
  22787. // contains the named destination we are looking for.
  22788. while (kidsOrNames.has('Kids')) {
  22789. loopCount++;
  22790. if (loopCount > MAX_NAMES_LEVELS) {
  22791. warn('Search depth limit for named destionations has been reached.');
  22792. return null;
  22793. }
  22794. var kids = kidsOrNames.get('Kids');
  22795. if (!isArray(kids)) {
  22796. return null;
  22797. }
  22798. l = 0;
  22799. r = kids.length - 1;
  22800. while (l <= r) {
  22801. m = (l + r) >> 1;
  22802. var kid = xref.fetchIfRef(kids[m]);
  22803. var limits = kid.get('Limits');
  22804. if (destinationId < xref.fetchIfRef(limits[0])) {
  22805. r = m - 1;
  22806. } else if (destinationId > xref.fetchIfRef(limits[1])) {
  22807. l = m + 1;
  22808. } else {
  22809. kidsOrNames = xref.fetchIfRef(kids[m]);
  22810. break;
  22811. }
  22812. }
  22813. if (l > r) {
  22814. return null;
  22815. }
  22816. }
  22817. // If we get here, then we have found the right entry. Now
  22818. // go through the named destinations in the Named dictionary
  22819. // until we find the exact destination we're looking for.
  22820. var names = kidsOrNames.get('Names');
  22821. if (isArray(names)) {
  22822. // Perform a binary search to reduce the lookup time.
  22823. l = 0;
  22824. r = names.length - 2;
  22825. while (l <= r) {
  22826. // Check only even indices (0, 2, 4, ...) because the
  22827. // odd indices contain the actual D array.
  22828. m = (l + r) & ~1;
  22829. if (destinationId < xref.fetchIfRef(names[m])) {
  22830. r = m - 2;
  22831. } else if (destinationId > xref.fetchIfRef(names[m])) {
  22832. l = m + 2;
  22833. } else {
  22834. return xref.fetchIfRef(names[m + 1]);
  22835. }
  22836. }
  22837. }
  22838. return null;
  22839. }
  22840. };
  22841. return NameTree;
  22842. })();
  22843. /**
  22844. * "A PDF file can refer to the contents of another file by using a File
  22845. * Specification (PDF 1.1)", see the spec (7.11) for more details.
  22846. * NOTE: Only embedded files are supported (as part of the attachments support)
  22847. * TODO: support the 'URL' file system (with caching if !/V), portable
  22848. * collections attributes and related files (/RF)
  22849. */
  22850. var FileSpec = (function FileSpecClosure() {
  22851. function FileSpec(root, xref) {
  22852. if (!root || !isDict(root)) {
  22853. return;
  22854. }
  22855. this.xref = xref;
  22856. this.root = root;
  22857. if (root.has('FS')) {
  22858. this.fs = root.get('FS');
  22859. }
  22860. this.description = root.has('Desc') ?
  22861. stringToPDFString(root.get('Desc')) :
  22862. '';
  22863. if (root.has('RF')) {
  22864. warn('Related file specifications are not supported');
  22865. }
  22866. this.contentAvailable = true;
  22867. if (!root.has('EF')) {
  22868. this.contentAvailable = false;
  22869. warn('Non-embedded file specifications are not supported');
  22870. }
  22871. }
  22872. function pickPlatformItem(dict) {
  22873. // Look for the filename in this order:
  22874. // UF, F, Unix, Mac, DOS
  22875. if (dict.has('UF')) {
  22876. return dict.get('UF');
  22877. } else if (dict.has('F')) {
  22878. return dict.get('F');
  22879. } else if (dict.has('Unix')) {
  22880. return dict.get('Unix');
  22881. } else if (dict.has('Mac')) {
  22882. return dict.get('Mac');
  22883. } else if (dict.has('DOS')) {
  22884. return dict.get('DOS');
  22885. } else {
  22886. return null;
  22887. }
  22888. }
  22889. FileSpec.prototype = {
  22890. get filename() {
  22891. if (!this._filename && this.root) {
  22892. var filename = pickPlatformItem(this.root) || 'unnamed';
  22893. this._filename = stringToPDFString(filename).
  22894. replace(/\\\\/g, '\\').
  22895. replace(/\\\//g, '/').
  22896. replace(/\\/g, '/');
  22897. }
  22898. return this._filename;
  22899. },
  22900. get content() {
  22901. if (!this.contentAvailable) {
  22902. return null;
  22903. }
  22904. if (!this.contentRef && this.root) {
  22905. this.contentRef = pickPlatformItem(this.root.get('EF'));
  22906. }
  22907. var content = null;
  22908. if (this.contentRef) {
  22909. var xref = this.xref;
  22910. var fileObj = xref.fetchIfRef(this.contentRef);
  22911. if (fileObj && isStream(fileObj)) {
  22912. content = fileObj.getBytes();
  22913. } else {
  22914. warn('Embedded file specification points to non-existing/invalid ' +
  22915. 'content');
  22916. }
  22917. } else {
  22918. warn('Embedded file specification does not have a content');
  22919. }
  22920. return content;
  22921. },
  22922. get serializable() {
  22923. return {
  22924. filename: this.filename,
  22925. content: this.content
  22926. };
  22927. }
  22928. };
  22929. return FileSpec;
  22930. })();
  22931. /**
  22932. * A helper for loading missing data in object graphs. It traverses the graph
  22933. * depth first and queues up any objects that have missing data. Once it has
  22934. * has traversed as many objects that are available it attempts to bundle the
  22935. * missing data requests and then resume from the nodes that weren't ready.
  22936. *
  22937. * NOTE: It provides protection from circular references by keeping track of
  22938. * of loaded references. However, you must be careful not to load any graphs
  22939. * that have references to the catalog or other pages since that will cause the
  22940. * entire PDF document object graph to be traversed.
  22941. */
  22942. var ObjectLoader = (function() {
  22943. function mayHaveChildren(value) {
  22944. return isRef(value) || isDict(value) || isArray(value) || isStream(value);
  22945. }
  22946. function addChildren(node, nodesToVisit) {
  22947. var value;
  22948. if (isDict(node) || isStream(node)) {
  22949. var map;
  22950. if (isDict(node)) {
  22951. map = node.map;
  22952. } else {
  22953. map = node.dict.map;
  22954. }
  22955. for (var key in map) {
  22956. value = map[key];
  22957. if (mayHaveChildren(value)) {
  22958. nodesToVisit.push(value);
  22959. }
  22960. }
  22961. } else if (isArray(node)) {
  22962. for (var i = 0, ii = node.length; i < ii; i++) {
  22963. value = node[i];
  22964. if (mayHaveChildren(value)) {
  22965. nodesToVisit.push(value);
  22966. }
  22967. }
  22968. }
  22969. }
  22970. function ObjectLoader(obj, keys, xref) {
  22971. this.obj = obj;
  22972. this.keys = keys;
  22973. this.xref = xref;
  22974. this.refSet = null;
  22975. this.capability = null;
  22976. }
  22977. ObjectLoader.prototype = {
  22978. load: function ObjectLoader_load() {
  22979. var keys = this.keys;
  22980. this.capability = createPromiseCapability();
  22981. // Don't walk the graph if all the data is already loaded.
  22982. if (!(this.xref.stream instanceof ChunkedStream) ||
  22983. this.xref.stream.getMissingChunks().length === 0) {
  22984. this.capability.resolve();
  22985. return this.capability.promise;
  22986. }
  22987. this.refSet = new RefSet();
  22988. // Setup the initial nodes to visit.
  22989. var nodesToVisit = [];
  22990. for (var i = 0; i < keys.length; i++) {
  22991. nodesToVisit.push(this.obj[keys[i]]);
  22992. }
  22993. this._walk(nodesToVisit);
  22994. return this.capability.promise;
  22995. },
  22996. _walk: function ObjectLoader_walk(nodesToVisit) {
  22997. var nodesToRevisit = [];
  22998. var pendingRequests = [];
  22999. // DFS walk of the object graph.
  23000. while (nodesToVisit.length) {
  23001. var currentNode = nodesToVisit.pop();
  23002. // Only references or chunked streams can cause missing data exceptions.
  23003. if (isRef(currentNode)) {
  23004. // Skip nodes that have already been visited.
  23005. if (this.refSet.has(currentNode)) {
  23006. continue;
  23007. }
  23008. try {
  23009. var ref = currentNode;
  23010. this.refSet.put(ref);
  23011. currentNode = this.xref.fetch(currentNode);
  23012. } catch (e) {
  23013. if (!(e instanceof MissingDataException)) {
  23014. throw e;
  23015. }
  23016. nodesToRevisit.push(currentNode);
  23017. pendingRequests.push({ begin: e.begin, end: e.end });
  23018. }
  23019. }
  23020. if (currentNode && currentNode.getBaseStreams) {
  23021. var baseStreams = currentNode.getBaseStreams();
  23022. var foundMissingData = false;
  23023. for (var i = 0; i < baseStreams.length; i++) {
  23024. var stream = baseStreams[i];
  23025. if (stream.getMissingChunks && stream.getMissingChunks().length) {
  23026. foundMissingData = true;
  23027. pendingRequests.push({
  23028. begin: stream.start,
  23029. end: stream.end
  23030. });
  23031. }
  23032. }
  23033. if (foundMissingData) {
  23034. nodesToRevisit.push(currentNode);
  23035. }
  23036. }
  23037. addChildren(currentNode, nodesToVisit);
  23038. }
  23039. if (pendingRequests.length) {
  23040. this.xref.stream.manager.requestRanges(pendingRequests).then(
  23041. function pendingRequestCallback() {
  23042. nodesToVisit = nodesToRevisit;
  23043. for (var i = 0; i < nodesToRevisit.length; i++) {
  23044. var node = nodesToRevisit[i];
  23045. // Remove any reference nodes from the currrent refset so they
  23046. // aren't skipped when we revist them.
  23047. if (isRef(node)) {
  23048. this.refSet.remove(node);
  23049. }
  23050. }
  23051. this._walk(nodesToVisit);
  23052. }.bind(this), this.capability.reject);
  23053. return;
  23054. }
  23055. // Everything is loaded.
  23056. this.refSet = null;
  23057. this.capability.resolve();
  23058. }
  23059. };
  23060. return ObjectLoader;
  23061. })();
  23062. exports.Catalog = Catalog;
  23063. exports.ObjectLoader = ObjectLoader;
  23064. exports.XRef = XRef;
  23065. }));
  23066. (function (root, factory) {
  23067. if (typeof define === 'function' && define.amd) {
  23068. define('pdfjs/core/ps_parser', ['exports', 'pdfjs/shared/util',
  23069. 'pdfjs/core/parser'], factory);
  23070. } else if (typeof exports !== 'undefined') {
  23071. factory(exports, require('../shared/util.js'), require('./parser.js'));
  23072. } else {
  23073. factory((root.pdfjsCorePsParser = {}), root.pdfjsSharedUtil,
  23074. root.pdfjsCoreParser);
  23075. }
  23076. }(this, function (exports, sharedUtil, coreParser) {
  23077. var error = sharedUtil.error;
  23078. var EOF = coreParser.EOF;
  23079. var Lexer = coreParser.Lexer;
  23080. var PostScriptParser = (function PostScriptParserClosure() {
  23081. function PostScriptParser(lexer) {
  23082. this.lexer = lexer;
  23083. this.operators = [];
  23084. this.token = null;
  23085. this.prev = null;
  23086. }
  23087. PostScriptParser.prototype = {
  23088. nextToken: function PostScriptParser_nextToken() {
  23089. this.prev = this.token;
  23090. this.token = this.lexer.getToken();
  23091. },
  23092. accept: function PostScriptParser_accept(type) {
  23093. if (this.token.type === type) {
  23094. this.nextToken();
  23095. return true;
  23096. }
  23097. return false;
  23098. },
  23099. expect: function PostScriptParser_expect(type) {
  23100. if (this.accept(type)) {
  23101. return true;
  23102. }
  23103. error('Unexpected symbol: found ' + this.token.type + ' expected ' +
  23104. type + '.');
  23105. },
  23106. parse: function PostScriptParser_parse() {
  23107. this.nextToken();
  23108. this.expect(PostScriptTokenTypes.LBRACE);
  23109. this.parseBlock();
  23110. this.expect(PostScriptTokenTypes.RBRACE);
  23111. return this.operators;
  23112. },
  23113. parseBlock: function PostScriptParser_parseBlock() {
  23114. while (true) {
  23115. if (this.accept(PostScriptTokenTypes.NUMBER)) {
  23116. this.operators.push(this.prev.value);
  23117. } else if (this.accept(PostScriptTokenTypes.OPERATOR)) {
  23118. this.operators.push(this.prev.value);
  23119. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  23120. this.parseCondition();
  23121. } else {
  23122. return;
  23123. }
  23124. }
  23125. },
  23126. parseCondition: function PostScriptParser_parseCondition() {
  23127. // Add two place holders that will be updated later
  23128. var conditionLocation = this.operators.length;
  23129. this.operators.push(null, null);
  23130. this.parseBlock();
  23131. this.expect(PostScriptTokenTypes.RBRACE);
  23132. if (this.accept(PostScriptTokenTypes.IF)) {
  23133. // The true block is right after the 'if' so it just falls through on
  23134. // true else it jumps and skips the true block.
  23135. this.operators[conditionLocation] = this.operators.length;
  23136. this.operators[conditionLocation + 1] = 'jz';
  23137. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  23138. var jumpLocation = this.operators.length;
  23139. this.operators.push(null, null);
  23140. var endOfTrue = this.operators.length;
  23141. this.parseBlock();
  23142. this.expect(PostScriptTokenTypes.RBRACE);
  23143. this.expect(PostScriptTokenTypes.IFELSE);
  23144. // The jump is added at the end of the true block to skip the false
  23145. // block.
  23146. this.operators[jumpLocation] = this.operators.length;
  23147. this.operators[jumpLocation + 1] = 'j';
  23148. this.operators[conditionLocation] = endOfTrue;
  23149. this.operators[conditionLocation + 1] = 'jz';
  23150. } else {
  23151. error('PS Function: error parsing conditional.');
  23152. }
  23153. }
  23154. };
  23155. return PostScriptParser;
  23156. })();
  23157. var PostScriptTokenTypes = {
  23158. LBRACE: 0,
  23159. RBRACE: 1,
  23160. NUMBER: 2,
  23161. OPERATOR: 3,
  23162. IF: 4,
  23163. IFELSE: 5
  23164. };
  23165. var PostScriptToken = (function PostScriptTokenClosure() {
  23166. function PostScriptToken(type, value) {
  23167. this.type = type;
  23168. this.value = value;
  23169. }
  23170. var opCache = {};
  23171. PostScriptToken.getOperator = function PostScriptToken_getOperator(op) {
  23172. var opValue = opCache[op];
  23173. if (opValue) {
  23174. return opValue;
  23175. }
  23176. return opCache[op] = new PostScriptToken(PostScriptTokenTypes.OPERATOR, op);
  23177. };
  23178. PostScriptToken.LBRACE = new PostScriptToken(PostScriptTokenTypes.LBRACE,
  23179. '{');
  23180. PostScriptToken.RBRACE = new PostScriptToken(PostScriptTokenTypes.RBRACE,
  23181. '}');
  23182. PostScriptToken.IF = new PostScriptToken(PostScriptTokenTypes.IF, 'IF');
  23183. PostScriptToken.IFELSE = new PostScriptToken(PostScriptTokenTypes.IFELSE,
  23184. 'IFELSE');
  23185. return PostScriptToken;
  23186. })();
  23187. var PostScriptLexer = (function PostScriptLexerClosure() {
  23188. function PostScriptLexer(stream) {
  23189. this.stream = stream;
  23190. this.nextChar();
  23191. this.strBuf = [];
  23192. }
  23193. PostScriptLexer.prototype = {
  23194. nextChar: function PostScriptLexer_nextChar() {
  23195. return (this.currentChar = this.stream.getByte());
  23196. },
  23197. getToken: function PostScriptLexer_getToken() {
  23198. var comment = false;
  23199. var ch = this.currentChar;
  23200. // skip comments
  23201. while (true) {
  23202. if (ch < 0) {
  23203. return EOF;
  23204. }
  23205. if (comment) {
  23206. if (ch === 0x0A || ch === 0x0D) {
  23207. comment = false;
  23208. }
  23209. } else if (ch === 0x25) { // '%'
  23210. comment = true;
  23211. } else if (!Lexer.isSpace(ch)) {
  23212. break;
  23213. }
  23214. ch = this.nextChar();
  23215. }
  23216. switch (ch | 0) {
  23217. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  23218. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  23219. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  23220. return new PostScriptToken(PostScriptTokenTypes.NUMBER,
  23221. this.getNumber());
  23222. case 0x7B: // '{'
  23223. this.nextChar();
  23224. return PostScriptToken.LBRACE;
  23225. case 0x7D: // '}'
  23226. this.nextChar();
  23227. return PostScriptToken.RBRACE;
  23228. }
  23229. // operator
  23230. var strBuf = this.strBuf;
  23231. strBuf.length = 0;
  23232. strBuf[0] = String.fromCharCode(ch);
  23233. while ((ch = this.nextChar()) >= 0 && // and 'A'-'Z', 'a'-'z'
  23234. ((ch >= 0x41 && ch <= 0x5A) || (ch >= 0x61 && ch <= 0x7A))) {
  23235. strBuf.push(String.fromCharCode(ch));
  23236. }
  23237. var str = strBuf.join('');
  23238. switch (str.toLowerCase()) {
  23239. case 'if':
  23240. return PostScriptToken.IF;
  23241. case 'ifelse':
  23242. return PostScriptToken.IFELSE;
  23243. default:
  23244. return PostScriptToken.getOperator(str);
  23245. }
  23246. },
  23247. getNumber: function PostScriptLexer_getNumber() {
  23248. var ch = this.currentChar;
  23249. var strBuf = this.strBuf;
  23250. strBuf.length = 0;
  23251. strBuf[0] = String.fromCharCode(ch);
  23252. while ((ch = this.nextChar()) >= 0) {
  23253. if ((ch >= 0x30 && ch <= 0x39) || // '0'-'9'
  23254. ch === 0x2D || ch === 0x2E) { // '-', '.'
  23255. strBuf.push(String.fromCharCode(ch));
  23256. } else {
  23257. break;
  23258. }
  23259. }
  23260. var value = parseFloat(strBuf.join(''));
  23261. if (isNaN(value)) {
  23262. error('Invalid floating point number: ' + value);
  23263. }
  23264. return value;
  23265. }
  23266. };
  23267. return PostScriptLexer;
  23268. })();
  23269. exports.PostScriptLexer = PostScriptLexer;
  23270. exports.PostScriptParser = PostScriptParser;
  23271. }));
  23272. (function (root, factory) {
  23273. if (typeof define === 'function' && define.amd) {
  23274. define('pdfjs/core/fonts', ['exports', 'pdfjs/shared/util',
  23275. 'pdfjs/core/primitives', 'pdfjs/core/stream', 'pdfjs/core/parser',
  23276. 'pdfjs/core/cmap', 'pdfjs/core/glyphlist', 'pdfjs/core/charsets',
  23277. 'pdfjs/core/font_renderer'], factory);
  23278. } else if (typeof exports !== 'undefined') {
  23279. factory(exports, require('../shared/util.js'), require('./primitives.js'),
  23280. require('./stream.js'), require('./parser.js'), require('./cmap.js'),
  23281. require('./glyphlist.js'), require('./charsets.js'),
  23282. require('./font_renderer.js'));
  23283. } else {
  23284. factory((root.pdfjsCoreFonts = {}), root.pdfjsSharedUtil,
  23285. root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreParser,
  23286. root.pdfjsCoreCMap, root.pdfjsCoreGlyphList, root.pdfjsCoreCharsets,
  23287. root.pdfjsCoreFontRenderer);
  23288. }
  23289. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreParser,
  23290. coreCMap, coreGlyphList, coreCharsets, coreFontRenderer) {
  23291. var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
  23292. var FontType = sharedUtil.FontType;
  23293. var Util = sharedUtil.Util;
  23294. var assert = sharedUtil.assert;
  23295. var bytesToString = sharedUtil.bytesToString;
  23296. var error = sharedUtil.error;
  23297. var info = sharedUtil.info;
  23298. var isArray = sharedUtil.isArray;
  23299. var isInt = sharedUtil.isInt;
  23300. var isNum = sharedUtil.isNum;
  23301. var readUint32 = sharedUtil.readUint32;
  23302. var shadow = sharedUtil.shadow;
  23303. var stringToBytes = sharedUtil.stringToBytes;
  23304. var string32 = sharedUtil.string32;
  23305. var warn = sharedUtil.warn;
  23306. var Name = corePrimitives.Name;
  23307. var Stream = coreStream.Stream;
  23308. var Lexer = coreParser.Lexer;
  23309. var CMapFactory = coreCMap.CMapFactory;
  23310. var IdentityCMap = coreCMap.IdentityCMap;
  23311. var GlyphsUnicode = coreGlyphList.GlyphsUnicode;
  23312. var DingbatsGlyphsUnicode = coreGlyphList.DingbatsGlyphsUnicode;
  23313. var ISOAdobeCharset = coreCharsets.ISOAdobeCharset;
  23314. var ExpertCharset = coreCharsets.ExpertCharset;
  23315. var ExpertSubsetCharset = coreCharsets.ExpertSubsetCharset;
  23316. var FontRendererFactory = coreFontRenderer.FontRendererFactory;
  23317. // Unicode Private Use Area
  23318. var PRIVATE_USE_OFFSET_START = 0xE000;
  23319. var PRIVATE_USE_OFFSET_END = 0xF8FF;
  23320. var SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = false;
  23321. // PDF Glyph Space Units are one Thousandth of a TextSpace Unit
  23322. // except for Type 3 fonts
  23323. var PDF_GLYPH_SPACE_UNITS = 1000;
  23324. // Hinting is currently disabled due to unknown problems on windows
  23325. // in tracemonkey and various other pdfs with type1 fonts.
  23326. var HINTING_ENABLED = false;
  23327. // Accented charactars are not displayed properly on windows, using this flag
  23328. // to control analysis of seac charstrings.
  23329. var SEAC_ANALYSIS_ENABLED = false;
  23330. var FontFlags = {
  23331. FixedPitch: 1,
  23332. Serif: 2,
  23333. Symbolic: 4,
  23334. Script: 8,
  23335. Nonsymbolic: 32,
  23336. Italic: 64,
  23337. AllCap: 65536,
  23338. SmallCap: 131072,
  23339. ForceBold: 262144
  23340. };
  23341. var Encodings = {
  23342. ExpertEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  23343. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  23344. 'space', 'exclamsmall', 'Hungarumlautsmall', '', 'dollaroldstyle',
  23345. 'dollarsuperior', 'ampersandsmall', 'Acutesmall', 'parenleftsuperior',
  23346. 'parenrightsuperior', 'twodotenleader', 'onedotenleader', 'comma',
  23347. 'hyphen', 'period', 'fraction', 'zerooldstyle', 'oneoldstyle',
  23348. 'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle',
  23349. 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'colon',
  23350. 'semicolon', 'commasuperior', 'threequartersemdash', 'periodsuperior',
  23351. 'questionsmall', '', 'asuperior', 'bsuperior', 'centsuperior', 'dsuperior',
  23352. 'esuperior', '', '', 'isuperior', '', '', 'lsuperior', 'msuperior',
  23353. 'nsuperior', 'osuperior', '', '', 'rsuperior', 'ssuperior', 'tsuperior',
  23354. '', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior', '',
  23355. 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall',
  23356. 'Asmall', 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall',
  23357. 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall',
  23358. 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall',
  23359. 'Vsmall', 'Wsmall', 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary',
  23360. 'onefitted', 'rupiah', 'Tildesmall', '', '', '', '', '', '', '', '', '',
  23361. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  23362. '', '', '', '', '', '', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall',
  23363. '', '', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall',
  23364. 'Caronsmall', '', 'Dotaccentsmall', '', '', 'Macronsmall', '', '',
  23365. 'figuredash', 'hypheninferior', '', '', 'Ogoneksmall', 'Ringsmall',
  23366. 'Cedillasmall', '', '', '', 'onequarter', 'onehalf', 'threequarters',
  23367. 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths',
  23368. 'seveneighths', 'onethird', 'twothirds', '', '', 'zerosuperior',
  23369. 'onesuperior', 'twosuperior', 'threesuperior', 'foursuperior',
  23370. 'fivesuperior', 'sixsuperior', 'sevensuperior', 'eightsuperior',
  23371. 'ninesuperior', 'zeroinferior', 'oneinferior', 'twoinferior',
  23372. 'threeinferior', 'fourinferior', 'fiveinferior', 'sixinferior',
  23373. 'seveninferior', 'eightinferior', 'nineinferior', 'centinferior',
  23374. 'dollarinferior', 'periodinferior', 'commainferior', 'Agravesmall',
  23375. 'Aacutesmall', 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall',
  23376. 'Aringsmall', 'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall',
  23377. 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall',
  23378. 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall',
  23379. 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall',
  23380. 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall',
  23381. 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall',
  23382. 'Ydieresissmall'],
  23383. MacExpertEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  23384. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  23385. 'space', 'exclamsmall', 'Hungarumlautsmall', 'centoldstyle',
  23386. 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall', 'Acutesmall',
  23387. 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  23388. 'onedotenleader', 'comma', 'hyphen', 'period', 'fraction', 'zerooldstyle',
  23389. 'oneoldstyle', 'twooldstyle', 'threeoldstyle', 'fouroldstyle',
  23390. 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle',
  23391. 'nineoldstyle', 'colon', 'semicolon', '', 'threequartersemdash', '',
  23392. 'questionsmall', '', '', '', '', 'Ethsmall', '', '', 'onequarter',
  23393. 'onehalf', 'threequarters', 'oneeighth', 'threeeighths', 'fiveeighths',
  23394. 'seveneighths', 'onethird', 'twothirds', '', '', '', '', '', '', 'ff',
  23395. 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior', '', 'parenrightinferior',
  23396. 'Circumflexsmall', 'hypheninferior', 'Gravesmall', 'Asmall', 'Bsmall',
  23397. 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall',
  23398. 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall',
  23399. 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
  23400. 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah',
  23401. 'Tildesmall', '', '', 'asuperior', 'centsuperior', '', '', '', '',
  23402. 'Aacutesmall', 'Agravesmall', 'Acircumflexsmall', 'Adieresissmall',
  23403. 'Atildesmall', 'Aringsmall', 'Ccedillasmall', 'Eacutesmall', 'Egravesmall',
  23404. 'Ecircumflexsmall', 'Edieresissmall', 'Iacutesmall', 'Igravesmall',
  23405. 'Icircumflexsmall', 'Idieresissmall', 'Ntildesmall', 'Oacutesmall',
  23406. 'Ogravesmall', 'Ocircumflexsmall', 'Odieresissmall', 'Otildesmall',
  23407. 'Uacutesmall', 'Ugravesmall', 'Ucircumflexsmall', 'Udieresissmall', '',
  23408. 'eightsuperior', 'fourinferior', 'threeinferior', 'sixinferior',
  23409. 'eightinferior', 'seveninferior', 'Scaronsmall', '', 'centinferior',
  23410. 'twoinferior', '', 'Dieresissmall', '', 'Caronsmall', 'osuperior',
  23411. 'fiveinferior', '', 'commainferior', 'periodinferior', 'Yacutesmall', '',
  23412. 'dollarinferior', '', 'Thornsmall', '', 'nineinferior', 'zeroinferior',
  23413. 'Zcaronsmall', 'AEsmall', 'Oslashsmall', 'questiondownsmall',
  23414. 'oneinferior', 'Lslashsmall', '', '', '', '', '', '', 'Cedillasmall', '',
  23415. '', '', '', '', 'OEsmall', 'figuredash', 'hyphensuperior', '', '', '', '',
  23416. 'exclamdownsmall', '', 'Ydieresissmall', '', 'onesuperior', 'twosuperior',
  23417. 'threesuperior', 'foursuperior', 'fivesuperior', 'sixsuperior',
  23418. 'sevensuperior', 'ninesuperior', 'zerosuperior', '', 'esuperior',
  23419. 'rsuperior', 'tsuperior', '', '', 'isuperior', 'ssuperior', 'dsuperior',
  23420. '', '', '', '', '', 'lsuperior', 'Ogoneksmall', 'Brevesmall',
  23421. 'Macronsmall', 'bsuperior', 'nsuperior', 'msuperior', 'commasuperior',
  23422. 'periodsuperior', 'Dotaccentsmall', 'Ringsmall'],
  23423. MacRomanEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  23424. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  23425. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  23426. 'ampersand', 'quotesingle', 'parenleft', 'parenright', 'asterisk', 'plus',
  23427. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  23428. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  23429. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  23430. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  23431. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  23432. 'asciicircum', 'underscore', 'grave', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
  23433. 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
  23434. 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', '',
  23435. 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde', 'Odieresis',
  23436. 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis', 'atilde',
  23437. 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  23438. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute',
  23439. 'ograve', 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave',
  23440. 'ucircumflex', 'udieresis', 'dagger', 'degree', 'cent', 'sterling',
  23441. 'section', 'bullet', 'paragraph', 'germandbls', 'registered', 'copyright',
  23442. 'trademark', 'acute', 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity',
  23443. 'plusminus', 'lessequal', 'greaterequal', 'yen', 'mu', 'partialdiff',
  23444. 'summation', 'product', 'pi', 'integral', 'ordfeminine', 'ordmasculine',
  23445. 'Omega', 'ae', 'oslash', 'questiondown', 'exclamdown', 'logicalnot',
  23446. 'radical', 'florin', 'approxequal', 'Delta', 'guillemotleft',
  23447. 'guillemotright', 'ellipsis', 'space', 'Agrave', 'Atilde', 'Otilde', 'OE',
  23448. 'oe', 'endash', 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft',
  23449. 'quoteright', 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction',
  23450. 'currency', 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl',
  23451. 'periodcentered', 'quotesinglbase', 'quotedblbase', 'perthousand',
  23452. 'Acircumflex', 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute',
  23453. 'Icircumflex', 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple',
  23454. 'Ograve', 'Uacute', 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex',
  23455. 'tilde', 'macron', 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut',
  23456. 'ogonek', 'caron'],
  23457. StandardEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  23458. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  23459. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  23460. 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus',
  23461. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  23462. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  23463. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  23464. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  23465. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  23466. 'asciicircum', 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f',
  23467. 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u',
  23468. 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde',
  23469. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  23470. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', 'exclamdown',
  23471. 'cent', 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  23472. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  23473. 'guilsinglright', 'fi', 'fl', '', 'endash', 'dagger', 'daggerdbl',
  23474. 'periodcentered', '', 'paragraph', 'bullet', 'quotesinglbase',
  23475. 'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis',
  23476. 'perthousand', '', 'questiondown', '', 'grave', 'acute', 'circumflex',
  23477. 'tilde', 'macron', 'breve', 'dotaccent', 'dieresis', '', 'ring', 'cedilla',
  23478. '', 'hungarumlaut', 'ogonek', 'caron', 'emdash', '', '', '', '', '', '',
  23479. '', '', '', '', '', '', '', '', '', '', 'AE', '', 'ordfeminine', '', '',
  23480. '', '', 'Lslash', 'Oslash', 'OE', 'ordmasculine', '', '', '', '', '', 'ae',
  23481. '', '', '', 'dotlessi', '', '', 'lslash', 'oslash', 'oe', 'germandbls'],
  23482. WinAnsiEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  23483. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  23484. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  23485. 'ampersand', 'quotesingle', 'parenleft', 'parenright', 'asterisk', 'plus',
  23486. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  23487. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  23488. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  23489. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  23490. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  23491. 'asciicircum', 'underscore', 'grave', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
  23492. 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
  23493. 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde',
  23494. 'bullet', 'Euro', 'bullet', 'quotesinglbase', 'florin', 'quotedblbase',
  23495. 'ellipsis', 'dagger', 'daggerdbl', 'circumflex', 'perthousand', 'Scaron',
  23496. 'guilsinglleft', 'OE', 'bullet', 'Zcaron', 'bullet', 'bullet', 'quoteleft',
  23497. 'quoteright', 'quotedblleft', 'quotedblright', 'bullet', 'endash',
  23498. 'emdash', 'tilde', 'trademark', 'scaron', 'guilsinglright', 'oe', 'bullet',
  23499. 'zcaron', 'Ydieresis', 'space', 'exclamdown', 'cent', 'sterling',
  23500. 'currency', 'yen', 'brokenbar', 'section', 'dieresis', 'copyright',
  23501. 'ordfeminine', 'guillemotleft', 'logicalnot', 'hyphen', 'registered',
  23502. 'macron', 'degree', 'plusminus', 'twosuperior', 'threesuperior', 'acute',
  23503. 'mu', 'paragraph', 'periodcentered', 'cedilla', 'onesuperior',
  23504. 'ordmasculine', 'guillemotright', 'onequarter', 'onehalf', 'threequarters',
  23505. 'questiondown', 'Agrave', 'Aacute', 'Acircumflex', 'Atilde', 'Adieresis',
  23506. 'Aring', 'AE', 'Ccedilla', 'Egrave', 'Eacute', 'Ecircumflex', 'Edieresis',
  23507. 'Igrave', 'Iacute', 'Icircumflex', 'Idieresis', 'Eth', 'Ntilde', 'Ograve',
  23508. 'Oacute', 'Ocircumflex', 'Otilde', 'Odieresis', 'multiply', 'Oslash',
  23509. 'Ugrave', 'Uacute', 'Ucircumflex', 'Udieresis', 'Yacute', 'Thorn',
  23510. 'germandbls', 'agrave', 'aacute', 'acircumflex', 'atilde', 'adieresis',
  23511. 'aring', 'ae', 'ccedilla', 'egrave', 'eacute', 'ecircumflex', 'edieresis',
  23512. 'igrave', 'iacute', 'icircumflex', 'idieresis', 'eth', 'ntilde', 'ograve',
  23513. 'oacute', 'ocircumflex', 'otilde', 'odieresis', 'divide', 'oslash',
  23514. 'ugrave', 'uacute', 'ucircumflex', 'udieresis', 'yacute', 'thorn',
  23515. 'ydieresis'],
  23516. SymbolSetEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  23517. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  23518. 'space', 'exclam', 'universal', 'numbersign', 'existential', 'percent',
  23519. 'ampersand', 'suchthat', 'parenleft', 'parenright', 'asteriskmath', 'plus',
  23520. 'comma', 'minus', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
  23521. 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',
  23522. 'equal', 'greater', 'question', 'congruent', 'Alpha', 'Beta', 'Chi',
  23523. 'Delta', 'Epsilon', 'Phi', 'Gamma', 'Eta', 'Iota', 'theta1', 'Kappa',
  23524. 'Lambda', 'Mu', 'Nu', 'Omicron', 'Pi', 'Theta', 'Rho', 'Sigma', 'Tau',
  23525. 'Upsilon', 'sigma1', 'Omega', 'Xi', 'Psi', 'Zeta', 'bracketleft',
  23526. 'therefore', 'bracketright', 'perpendicular', 'underscore', 'radicalex',
  23527. 'alpha', 'beta', 'chi', 'delta', 'epsilon', 'phi', 'gamma', 'eta', 'iota',
  23528. 'phi1', 'kappa', 'lambda', 'mu', 'nu', 'omicron', 'pi', 'theta', 'rho',
  23529. 'sigma', 'tau', 'upsilon', 'omega1', 'omega', 'xi', 'psi', 'zeta',
  23530. 'braceleft', 'bar', 'braceright', 'similar', '', '', '', '', '', '', '',
  23531. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  23532. '', '', '', '', '', '', '', 'Euro', 'Upsilon1', 'minute', 'lessequal',
  23533. 'fraction', 'infinity', 'florin', 'club', 'diamond', 'heart', 'spade',
  23534. 'arrowboth', 'arrowleft', 'arrowup', 'arrowright', 'arrowdown', 'degree',
  23535. 'plusminus', 'second', 'greaterequal', 'multiply', 'proportional',
  23536. 'partialdiff', 'bullet', 'divide', 'notequal', 'equivalence',
  23537. 'approxequal', 'ellipsis', 'arrowvertex', 'arrowhorizex', 'carriagereturn',
  23538. 'aleph', 'Ifraktur', 'Rfraktur', 'weierstrass', 'circlemultiply',
  23539. 'circleplus', 'emptyset', 'intersection', 'union', 'propersuperset',
  23540. 'reflexsuperset', 'notsubset', 'propersubset', 'reflexsubset', 'element',
  23541. 'notelement', 'angle', 'gradient', 'registerserif', 'copyrightserif',
  23542. 'trademarkserif', 'product', 'radical', 'dotmath', 'logicalnot',
  23543. 'logicaland', 'logicalor', 'arrowdblboth', 'arrowdblleft', 'arrowdblup',
  23544. 'arrowdblright', 'arrowdbldown', 'lozenge', 'angleleft', 'registersans',
  23545. 'copyrightsans', 'trademarksans', 'summation', 'parenlefttp',
  23546. 'parenleftex', 'parenleftbt', 'bracketlefttp', 'bracketleftex',
  23547. 'bracketleftbt', 'bracelefttp', 'braceleftmid', 'braceleftbt', 'braceex',
  23548. '', 'angleright', 'integral', 'integraltp', 'integralex', 'integralbt',
  23549. 'parenrighttp', 'parenrightex', 'parenrightbt', 'bracketrighttp',
  23550. 'bracketrightex', 'bracketrightbt', 'bracerighttp', 'bracerightmid',
  23551. 'bracerightbt'],
  23552. ZapfDingbatsEncoding: ['', '', '', '', '', '', '', '', '', '', '', '', '', '',
  23553. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  23554. 'space', 'a1', 'a2', 'a202', 'a3', 'a4', 'a5', 'a119', 'a118', 'a117',
  23555. 'a11', 'a12', 'a13', 'a14', 'a15', 'a16', 'a105', 'a17', 'a18', 'a19',
  23556. 'a20', 'a21', 'a22', 'a23', 'a24', 'a25', 'a26', 'a27', 'a28', 'a6', 'a7',
  23557. 'a8', 'a9', 'a10', 'a29', 'a30', 'a31', 'a32', 'a33', 'a34', 'a35', 'a36',
  23558. 'a37', 'a38', 'a39', 'a40', 'a41', 'a42', 'a43', 'a44', 'a45', 'a46',
  23559. 'a47', 'a48', 'a49', 'a50', 'a51', 'a52', 'a53', 'a54', 'a55', 'a56',
  23560. 'a57', 'a58', 'a59', 'a60', 'a61', 'a62', 'a63', 'a64', 'a65', 'a66',
  23561. 'a67', 'a68', 'a69', 'a70', 'a71', 'a72', 'a73', 'a74', 'a203', 'a75',
  23562. 'a204', 'a76', 'a77', 'a78', 'a79', 'a81', 'a82', 'a83', 'a84', 'a97',
  23563. 'a98', 'a99', 'a100', '', 'a89', 'a90', 'a93', 'a94', 'a91', 'a92', 'a205',
  23564. 'a85', 'a206', 'a86', 'a87', 'a88', 'a95', 'a96', '', '', '', '', '', '',
  23565. '', '', '', '', '', '', '', '', '', '', '', '', '', 'a101', 'a102', 'a103',
  23566. 'a104', 'a106', 'a107', 'a108', 'a112', 'a111', 'a110', 'a109', 'a120',
  23567. 'a121', 'a122', 'a123', 'a124', 'a125', 'a126', 'a127', 'a128', 'a129',
  23568. 'a130', 'a131', 'a132', 'a133', 'a134', 'a135', 'a136', 'a137', 'a138',
  23569. 'a139', 'a140', 'a141', 'a142', 'a143', 'a144', 'a145', 'a146', 'a147',
  23570. 'a148', 'a149', 'a150', 'a151', 'a152', 'a153', 'a154', 'a155', 'a156',
  23571. 'a157', 'a158', 'a159', 'a160', 'a161', 'a163', 'a164', 'a196', 'a165',
  23572. 'a192', 'a166', 'a167', 'a168', 'a169', 'a170', 'a171', 'a172', 'a173',
  23573. 'a162', 'a174', 'a175', 'a176', 'a177', 'a178', 'a179', 'a193', 'a180',
  23574. 'a199', 'a181', 'a200', 'a182', '', 'a201', 'a183', 'a184', 'a197', 'a185',
  23575. 'a194', 'a198', 'a186', 'a195', 'a187', 'a188', 'a189', 'a190', 'a191']
  23576. };
  23577. /**
  23578. * Hold a map of decoded fonts and of the standard fourteen Type1
  23579. * fonts and their acronyms.
  23580. */
  23581. var stdFontMap = {
  23582. 'ArialNarrow': 'Helvetica',
  23583. 'ArialNarrow-Bold': 'Helvetica-Bold',
  23584. 'ArialNarrow-BoldItalic': 'Helvetica-BoldOblique',
  23585. 'ArialNarrow-Italic': 'Helvetica-Oblique',
  23586. 'ArialBlack': 'Helvetica',
  23587. 'ArialBlack-Bold': 'Helvetica-Bold',
  23588. 'ArialBlack-BoldItalic': 'Helvetica-BoldOblique',
  23589. 'ArialBlack-Italic': 'Helvetica-Oblique',
  23590. 'Arial': 'Helvetica',
  23591. 'Arial-Bold': 'Helvetica-Bold',
  23592. 'Arial-BoldItalic': 'Helvetica-BoldOblique',
  23593. 'Arial-Italic': 'Helvetica-Oblique',
  23594. 'Arial-BoldItalicMT': 'Helvetica-BoldOblique',
  23595. 'Arial-BoldMT': 'Helvetica-Bold',
  23596. 'Arial-ItalicMT': 'Helvetica-Oblique',
  23597. 'ArialMT': 'Helvetica',
  23598. 'Courier-Bold': 'Courier-Bold',
  23599. 'Courier-BoldItalic': 'Courier-BoldOblique',
  23600. 'Courier-Italic': 'Courier-Oblique',
  23601. 'CourierNew': 'Courier',
  23602. 'CourierNew-Bold': 'Courier-Bold',
  23603. 'CourierNew-BoldItalic': 'Courier-BoldOblique',
  23604. 'CourierNew-Italic': 'Courier-Oblique',
  23605. 'CourierNewPS-BoldItalicMT': 'Courier-BoldOblique',
  23606. 'CourierNewPS-BoldMT': 'Courier-Bold',
  23607. 'CourierNewPS-ItalicMT': 'Courier-Oblique',
  23608. 'CourierNewPSMT': 'Courier',
  23609. 'Helvetica': 'Helvetica',
  23610. 'Helvetica-Bold': 'Helvetica-Bold',
  23611. 'Helvetica-BoldItalic': 'Helvetica-BoldOblique',
  23612. 'Helvetica-BoldOblique': 'Helvetica-BoldOblique',
  23613. 'Helvetica-Italic': 'Helvetica-Oblique',
  23614. 'Helvetica-Oblique':'Helvetica-Oblique',
  23615. 'Symbol-Bold': 'Symbol',
  23616. 'Symbol-BoldItalic': 'Symbol',
  23617. 'Symbol-Italic': 'Symbol',
  23618. 'TimesNewRoman': 'Times-Roman',
  23619. 'TimesNewRoman-Bold': 'Times-Bold',
  23620. 'TimesNewRoman-BoldItalic': 'Times-BoldItalic',
  23621. 'TimesNewRoman-Italic': 'Times-Italic',
  23622. 'TimesNewRomanPS': 'Times-Roman',
  23623. 'TimesNewRomanPS-Bold': 'Times-Bold',
  23624. 'TimesNewRomanPS-BoldItalic': 'Times-BoldItalic',
  23625. 'TimesNewRomanPS-BoldItalicMT': 'Times-BoldItalic',
  23626. 'TimesNewRomanPS-BoldMT': 'Times-Bold',
  23627. 'TimesNewRomanPS-Italic': 'Times-Italic',
  23628. 'TimesNewRomanPS-ItalicMT': 'Times-Italic',
  23629. 'TimesNewRomanPSMT': 'Times-Roman',
  23630. 'TimesNewRomanPSMT-Bold': 'Times-Bold',
  23631. 'TimesNewRomanPSMT-BoldItalic': 'Times-BoldItalic',
  23632. 'TimesNewRomanPSMT-Italic': 'Times-Italic'
  23633. };
  23634. /**
  23635. * Holds the map of the non-standard fonts that might be included as a standard
  23636. * fonts without glyph data.
  23637. */
  23638. var nonStdFontMap = {
  23639. 'CenturyGothic': 'Helvetica',
  23640. 'CenturyGothic-Bold': 'Helvetica-Bold',
  23641. 'CenturyGothic-BoldItalic': 'Helvetica-BoldOblique',
  23642. 'CenturyGothic-Italic': 'Helvetica-Oblique',
  23643. 'ComicSansMS': 'Comic Sans MS',
  23644. 'ComicSansMS-Bold': 'Comic Sans MS-Bold',
  23645. 'ComicSansMS-BoldItalic': 'Comic Sans MS-BoldItalic',
  23646. 'ComicSansMS-Italic': 'Comic Sans MS-Italic',
  23647. 'LucidaConsole': 'Courier',
  23648. 'LucidaConsole-Bold': 'Courier-Bold',
  23649. 'LucidaConsole-BoldItalic': 'Courier-BoldOblique',
  23650. 'LucidaConsole-Italic': 'Courier-Oblique',
  23651. 'MS-Gothic': 'MS Gothic',
  23652. 'MS-Gothic-Bold': 'MS Gothic-Bold',
  23653. 'MS-Gothic-BoldItalic': 'MS Gothic-BoldItalic',
  23654. 'MS-Gothic-Italic': 'MS Gothic-Italic',
  23655. 'MS-Mincho': 'MS Mincho',
  23656. 'MS-Mincho-Bold': 'MS Mincho-Bold',
  23657. 'MS-Mincho-BoldItalic': 'MS Mincho-BoldItalic',
  23658. 'MS-Mincho-Italic': 'MS Mincho-Italic',
  23659. 'MS-PGothic': 'MS PGothic',
  23660. 'MS-PGothic-Bold': 'MS PGothic-Bold',
  23661. 'MS-PGothic-BoldItalic': 'MS PGothic-BoldItalic',
  23662. 'MS-PGothic-Italic': 'MS PGothic-Italic',
  23663. 'MS-PMincho': 'MS PMincho',
  23664. 'MS-PMincho-Bold': 'MS PMincho-Bold',
  23665. 'MS-PMincho-BoldItalic': 'MS PMincho-BoldItalic',
  23666. 'MS-PMincho-Italic': 'MS PMincho-Italic',
  23667. 'Wingdings': 'ZapfDingbats'
  23668. };
  23669. var serifFonts = {
  23670. 'Adobe Jenson': true, 'Adobe Text': true, 'Albertus': true,
  23671. 'Aldus': true, 'Alexandria': true, 'Algerian': true,
  23672. 'American Typewriter': true, 'Antiqua': true, 'Apex': true,
  23673. 'Arno': true, 'Aster': true, 'Aurora': true,
  23674. 'Baskerville': true, 'Bell': true, 'Bembo': true,
  23675. 'Bembo Schoolbook': true, 'Benguiat': true, 'Berkeley Old Style': true,
  23676. 'Bernhard Modern': true, 'Berthold City': true, 'Bodoni': true,
  23677. 'Bauer Bodoni': true, 'Book Antiqua': true, 'Bookman': true,
  23678. 'Bordeaux Roman': true, 'Californian FB': true, 'Calisto': true,
  23679. 'Calvert': true, 'Capitals': true, 'Cambria': true,
  23680. 'Cartier': true, 'Caslon': true, 'Catull': true,
  23681. 'Centaur': true, 'Century Old Style': true, 'Century Schoolbook': true,
  23682. 'Chaparral': true, 'Charis SIL': true, 'Cheltenham': true,
  23683. 'Cholla Slab': true, 'Clarendon': true, 'Clearface': true,
  23684. 'Cochin': true, 'Colonna': true, 'Computer Modern': true,
  23685. 'Concrete Roman': true, 'Constantia': true, 'Cooper Black': true,
  23686. 'Corona': true, 'Ecotype': true, 'Egyptienne': true,
  23687. 'Elephant': true, 'Excelsior': true, 'Fairfield': true,
  23688. 'FF Scala': true, 'Folkard': true, 'Footlight': true,
  23689. 'FreeSerif': true, 'Friz Quadrata': true, 'Garamond': true,
  23690. 'Gentium': true, 'Georgia': true, 'Gloucester': true,
  23691. 'Goudy Old Style': true, 'Goudy Schoolbook': true, 'Goudy Pro Font': true,
  23692. 'Granjon': true, 'Guardian Egyptian': true, 'Heather': true,
  23693. 'Hercules': true, 'High Tower Text': true, 'Hiroshige': true,
  23694. 'Hoefler Text': true, 'Humana Serif': true, 'Imprint': true,
  23695. 'Ionic No. 5': true, 'Janson': true, 'Joanna': true,
  23696. 'Korinna': true, 'Lexicon': true, 'Liberation Serif': true,
  23697. 'Linux Libertine': true, 'Literaturnaya': true, 'Lucida': true,
  23698. 'Lucida Bright': true, 'Melior': true, 'Memphis': true,
  23699. 'Miller': true, 'Minion': true, 'Modern': true,
  23700. 'Mona Lisa': true, 'Mrs Eaves': true, 'MS Serif': true,
  23701. 'Museo Slab': true, 'New York': true, 'Nimbus Roman': true,
  23702. 'NPS Rawlinson Roadway': true, 'Palatino': true, 'Perpetua': true,
  23703. 'Plantin': true, 'Plantin Schoolbook': true, 'Playbill': true,
  23704. 'Poor Richard': true, 'Rawlinson Roadway': true, 'Renault': true,
  23705. 'Requiem': true, 'Rockwell': true, 'Roman': true,
  23706. 'Rotis Serif': true, 'Sabon': true, 'Scala': true,
  23707. 'Seagull': true, 'Sistina': true, 'Souvenir': true,
  23708. 'STIX': true, 'Stone Informal': true, 'Stone Serif': true,
  23709. 'Sylfaen': true, 'Times': true, 'Trajan': true,
  23710. 'Trinité': true, 'Trump Mediaeval': true, 'Utopia': true,
  23711. 'Vale Type': true, 'Bitstream Vera': true, 'Vera Serif': true,
  23712. 'Versailles': true, 'Wanted': true, 'Weiss': true,
  23713. 'Wide Latin': true, 'Windsor': true, 'XITS': true
  23714. };
  23715. var symbolsFonts = {
  23716. 'Dingbats': true, 'Symbol': true, 'ZapfDingbats': true
  23717. };
  23718. // Glyph map for well-known standard fonts. Sometimes Ghostscript uses CID fonts
  23719. // but does not embed the CID to GID mapping. The mapping is incomplete for all
  23720. // glyphs, but common for some set of the standard fonts.
  23721. var GlyphMapForStandardFonts = {
  23722. '2': 10, '3': 32, '4': 33, '5': 34, '6': 35, '7': 36, '8': 37, '9': 38,
  23723. '10': 39, '11': 40, '12': 41, '13': 42, '14': 43, '15': 44, '16': 45,
  23724. '17': 46, '18': 47, '19': 48, '20': 49, '21': 50, '22': 51, '23': 52,
  23725. '24': 53, '25': 54, '26': 55, '27': 56, '28': 57, '29': 58, '30': 894,
  23726. '31': 60, '32': 61, '33': 62, '34': 63, '35': 64, '36': 65, '37': 66,
  23727. '38': 67, '39': 68, '40': 69, '41': 70, '42': 71, '43': 72, '44': 73,
  23728. '45': 74, '46': 75, '47': 76, '48': 77, '49': 78, '50': 79, '51': 80,
  23729. '52': 81, '53': 82, '54': 83, '55': 84, '56': 85, '57': 86, '58': 87,
  23730. '59': 88, '60': 89, '61': 90, '62': 91, '63': 92, '64': 93, '65': 94,
  23731. '66': 95, '67': 96, '68': 97, '69': 98, '70': 99, '71': 100, '72': 101,
  23732. '73': 102, '74': 103, '75': 104, '76': 105, '77': 106, '78': 107, '79': 108,
  23733. '80': 109, '81': 110, '82': 111, '83': 112, '84': 113, '85': 114, '86': 115,
  23734. '87': 116, '88': 117, '89': 118, '90': 119, '91': 120, '92': 121, '93': 122,
  23735. '94': 123, '95': 124, '96': 125, '97': 126, '98': 196, '99': 197, '100': 199,
  23736. '101': 201, '102': 209, '103': 214, '104': 220, '105': 225, '106': 224,
  23737. '107': 226, '108': 228, '109': 227, '110': 229, '111': 231, '112': 233,
  23738. '113': 232, '114': 234, '115': 235, '116': 237, '117': 236, '118': 238,
  23739. '119': 239, '120': 241, '121': 243, '122': 242, '123': 244, '124': 246,
  23740. '125': 245, '126': 250, '127': 249, '128': 251, '129': 252, '130': 8224,
  23741. '131': 176, '132': 162, '133': 163, '134': 167, '135': 8226, '136': 182,
  23742. '137': 223, '138': 174, '139': 169, '140': 8482, '141': 180, '142': 168,
  23743. '143': 8800, '144': 198, '145': 216, '146': 8734, '147': 177, '148': 8804,
  23744. '149': 8805, '150': 165, '151': 181, '152': 8706, '153': 8721, '154': 8719,
  23745. '156': 8747, '157': 170, '158': 186, '159': 8486, '160': 230, '161': 248,
  23746. '162': 191, '163': 161, '164': 172, '165': 8730, '166': 402, '167': 8776,
  23747. '168': 8710, '169': 171, '170': 187, '171': 8230, '210': 218, '223': 711,
  23748. '224': 321, '225': 322, '227': 353, '229': 382, '234': 253, '252': 263,
  23749. '253': 268, '254': 269, '258': 258, '260': 260, '261': 261, '265': 280,
  23750. '266': 281, '268': 283, '269': 313, '275': 323, '276': 324, '278': 328,
  23751. '284': 345, '285': 346, '286': 347, '292': 367, '295': 377, '296': 378,
  23752. '298': 380, '305': 963,
  23753. '306': 964, '307': 966, '308': 8215, '309': 8252, '310': 8319, '311': 8359,
  23754. '312': 8592, '313': 8593, '337': 9552, '493': 1039, '494': 1040, '705': 1524,
  23755. '706': 8362, '710': 64288, '711': 64298, '759': 1617, '761': 1776,
  23756. '763': 1778, '775': 1652, '777': 1764, '778': 1780, '779': 1781, '780': 1782,
  23757. '782': 771, '783': 64726, '786': 8363, '788': 8532, '790': 768, '791': 769,
  23758. '792': 768, '795': 803, '797': 64336, '798': 64337, '799': 64342,
  23759. '800': 64343, '801': 64344, '802': 64345, '803': 64362, '804': 64363,
  23760. '805': 64364, '2424': 7821, '2425': 7822, '2426': 7823, '2427': 7824,
  23761. '2428': 7825, '2429': 7826, '2430': 7827, '2433': 7682, '2678': 8045,
  23762. '2679': 8046, '2830': 1552, '2838': 686, '2840': 751, '2842': 753,
  23763. '2843': 754, '2844': 755, '2846': 757, '2856': 767, '2857': 848, '2858': 849,
  23764. '2862': 853, '2863': 854, '2864': 855, '2865': 861, '2866': 862, '2906': 7460,
  23765. '2908': 7462, '2909': 7463, '2910': 7464, '2912': 7466, '2913': 7467,
  23766. '2914': 7468, '2916': 7470, '2917': 7471, '2918': 7472, '2920': 7474,
  23767. '2921': 7475, '2922': 7476, '2924': 7478, '2925': 7479, '2926': 7480,
  23768. '2928': 7482, '2929': 7483, '2930': 7484, '2932': 7486, '2933': 7487,
  23769. '2934': 7488, '2936': 7490, '2937': 7491, '2938': 7492, '2940': 7494,
  23770. '2941': 7495, '2942': 7496, '2944': 7498, '2946': 7500, '2948': 7502,
  23771. '2950': 7504, '2951': 7505, '2952': 7506, '2954': 7508, '2955': 7509,
  23772. '2956': 7510, '2958': 7512, '2959': 7513, '2960': 7514, '2962': 7516,
  23773. '2963': 7517, '2964': 7518, '2966': 7520, '2967': 7521, '2968': 7522,
  23774. '2970': 7524, '2971': 7525, '2972': 7526, '2974': 7528, '2975': 7529,
  23775. '2976': 7530, '2978': 1537, '2979': 1538, '2980': 1539, '2982': 1549,
  23776. '2983': 1551, '2984': 1552, '2986': 1554, '2987': 1555, '2988': 1556,
  23777. '2990': 1623, '2991': 1624, '2995': 1775, '2999': 1791, '3002': 64290,
  23778. '3003': 64291, '3004': 64292, '3006': 64294, '3007': 64295, '3008': 64296,
  23779. '3011': 1900, '3014': 8223, '3015': 8244, '3017': 7532, '3018': 7533,
  23780. '3019': 7534, '3075': 7590, '3076': 7591, '3079': 7594, '3080': 7595,
  23781. '3083': 7598, '3084': 7599, '3087': 7602, '3088': 7603, '3091': 7606,
  23782. '3092': 7607, '3095': 7610, '3096': 7611, '3099': 7614, '3100': 7615,
  23783. '3103': 7618, '3104': 7619, '3107': 8337, '3108': 8338, '3116': 1884,
  23784. '3119': 1885, '3120': 1885, '3123': 1886, '3124': 1886, '3127': 1887,
  23785. '3128': 1887, '3131': 1888, '3132': 1888, '3135': 1889, '3136': 1889,
  23786. '3139': 1890, '3140': 1890, '3143': 1891, '3144': 1891, '3147': 1892,
  23787. '3148': 1892, '3153': 580, '3154': 581, '3157': 584, '3158': 585, '3161': 588,
  23788. '3162': 589, '3165': 891, '3166': 892, '3169': 1274, '3170': 1275,
  23789. '3173': 1278, '3174': 1279, '3181': 7622, '3182': 7623, '3282': 11799,
  23790. '3316': 578, '3379': 42785, '3393': 1159, '3416': 8377
  23791. };
  23792. // The glyph map for ArialBlack differs slightly from the glyph map used for
  23793. // other well-known standard fonts. Hence we use this (incomplete) CID to GID
  23794. // mapping to adjust the glyph map for non-embedded ArialBlack fonts.
  23795. var SupplementalGlyphMapForArialBlack = {
  23796. '227': 322, '264': 261, '291': 346,
  23797. };
  23798. // Some characters, e.g. copyrightserif, are mapped to the private use area and
  23799. // might not be displayed using standard fonts. Mapping/hacking well-known chars
  23800. // to the similar equivalents in the normal characters range.
  23801. var SpecialPUASymbols = {
  23802. '63721': 0x00A9, // copyrightsans (0xF8E9) => copyright
  23803. '63193': 0x00A9, // copyrightserif (0xF6D9) => copyright
  23804. '63720': 0x00AE, // registersans (0xF8E8) => registered
  23805. '63194': 0x00AE, // registerserif (0xF6DA) => registered
  23806. '63722': 0x2122, // trademarksans (0xF8EA) => trademark
  23807. '63195': 0x2122, // trademarkserif (0xF6DB) => trademark
  23808. '63729': 0x23A7, // bracelefttp (0xF8F1)
  23809. '63730': 0x23A8, // braceleftmid (0xF8F2)
  23810. '63731': 0x23A9, // braceleftbt (0xF8F3)
  23811. '63740': 0x23AB, // bracerighttp (0xF8FC)
  23812. '63741': 0x23AC, // bracerightmid (0xF8FD)
  23813. '63742': 0x23AD, // bracerightbt (0xF8FE)
  23814. '63726': 0x23A1, // bracketlefttp (0xF8EE)
  23815. '63727': 0x23A2, // bracketleftex (0xF8EF)
  23816. '63728': 0x23A3, // bracketleftbt (0xF8F0)
  23817. '63737': 0x23A4, // bracketrighttp (0xF8F9)
  23818. '63738': 0x23A5, // bracketrightex (0xF8FA)
  23819. '63739': 0x23A6, // bracketrightbt (0xF8FB)
  23820. '63723': 0x239B, // parenlefttp (0xF8EB)
  23821. '63724': 0x239C, // parenleftex (0xF8EC)
  23822. '63725': 0x239D, // parenleftbt (0xF8ED)
  23823. '63734': 0x239E, // parenrighttp (0xF8F6)
  23824. '63735': 0x239F, // parenrightex (0xF8F7)
  23825. '63736': 0x23A0, // parenrightbt (0xF8F8)
  23826. };
  23827. function mapSpecialUnicodeValues(code) {
  23828. if (code >= 0xFFF0 && code <= 0xFFFF) { // Specials unicode block.
  23829. return 0;
  23830. } else if (code >= 0xF600 && code <= 0xF8FF) {
  23831. return (SpecialPUASymbols[code] || code);
  23832. }
  23833. return code;
  23834. }
  23835. var UnicodeRanges = [
  23836. { 'begin': 0x0000, 'end': 0x007F }, // Basic Latin
  23837. { 'begin': 0x0080, 'end': 0x00FF }, // Latin-1 Supplement
  23838. { 'begin': 0x0100, 'end': 0x017F }, // Latin Extended-A
  23839. { 'begin': 0x0180, 'end': 0x024F }, // Latin Extended-B
  23840. { 'begin': 0x0250, 'end': 0x02AF }, // IPA Extensions
  23841. { 'begin': 0x02B0, 'end': 0x02FF }, // Spacing Modifier Letters
  23842. { 'begin': 0x0300, 'end': 0x036F }, // Combining Diacritical Marks
  23843. { 'begin': 0x0370, 'end': 0x03FF }, // Greek and Coptic
  23844. { 'begin': 0x2C80, 'end': 0x2CFF }, // Coptic
  23845. { 'begin': 0x0400, 'end': 0x04FF }, // Cyrillic
  23846. { 'begin': 0x0530, 'end': 0x058F }, // Armenian
  23847. { 'begin': 0x0590, 'end': 0x05FF }, // Hebrew
  23848. { 'begin': 0xA500, 'end': 0xA63F }, // Vai
  23849. { 'begin': 0x0600, 'end': 0x06FF }, // Arabic
  23850. { 'begin': 0x07C0, 'end': 0x07FF }, // NKo
  23851. { 'begin': 0x0900, 'end': 0x097F }, // Devanagari
  23852. { 'begin': 0x0980, 'end': 0x09FF }, // Bengali
  23853. { 'begin': 0x0A00, 'end': 0x0A7F }, // Gurmukhi
  23854. { 'begin': 0x0A80, 'end': 0x0AFF }, // Gujarati
  23855. { 'begin': 0x0B00, 'end': 0x0B7F }, // Oriya
  23856. { 'begin': 0x0B80, 'end': 0x0BFF }, // Tamil
  23857. { 'begin': 0x0C00, 'end': 0x0C7F }, // Telugu
  23858. { 'begin': 0x0C80, 'end': 0x0CFF }, // Kannada
  23859. { 'begin': 0x0D00, 'end': 0x0D7F }, // Malayalam
  23860. { 'begin': 0x0E00, 'end': 0x0E7F }, // Thai
  23861. { 'begin': 0x0E80, 'end': 0x0EFF }, // Lao
  23862. { 'begin': 0x10A0, 'end': 0x10FF }, // Georgian
  23863. { 'begin': 0x1B00, 'end': 0x1B7F }, // Balinese
  23864. { 'begin': 0x1100, 'end': 0x11FF }, // Hangul Jamo
  23865. { 'begin': 0x1E00, 'end': 0x1EFF }, // Latin Extended Additional
  23866. { 'begin': 0x1F00, 'end': 0x1FFF }, // Greek Extended
  23867. { 'begin': 0x2000, 'end': 0x206F }, // General Punctuation
  23868. { 'begin': 0x2070, 'end': 0x209F }, // Superscripts And Subscripts
  23869. { 'begin': 0x20A0, 'end': 0x20CF }, // Currency Symbol
  23870. { 'begin': 0x20D0, 'end': 0x20FF }, // Combining Diacritical Marks For Symbols
  23871. { 'begin': 0x2100, 'end': 0x214F }, // Letterlike Symbols
  23872. { 'begin': 0x2150, 'end': 0x218F }, // Number Forms
  23873. { 'begin': 0x2190, 'end': 0x21FF }, // Arrows
  23874. { 'begin': 0x2200, 'end': 0x22FF }, // Mathematical Operators
  23875. { 'begin': 0x2300, 'end': 0x23FF }, // Miscellaneous Technical
  23876. { 'begin': 0x2400, 'end': 0x243F }, // Control Pictures
  23877. { 'begin': 0x2440, 'end': 0x245F }, // Optical Character Recognition
  23878. { 'begin': 0x2460, 'end': 0x24FF }, // Enclosed Alphanumerics
  23879. { 'begin': 0x2500, 'end': 0x257F }, // Box Drawing
  23880. { 'begin': 0x2580, 'end': 0x259F }, // Block Elements
  23881. { 'begin': 0x25A0, 'end': 0x25FF }, // Geometric Shapes
  23882. { 'begin': 0x2600, 'end': 0x26FF }, // Miscellaneous Symbols
  23883. { 'begin': 0x2700, 'end': 0x27BF }, // Dingbats
  23884. { 'begin': 0x3000, 'end': 0x303F }, // CJK Symbols And Punctuation
  23885. { 'begin': 0x3040, 'end': 0x309F }, // Hiragana
  23886. { 'begin': 0x30A0, 'end': 0x30FF }, // Katakana
  23887. { 'begin': 0x3100, 'end': 0x312F }, // Bopomofo
  23888. { 'begin': 0x3130, 'end': 0x318F }, // Hangul Compatibility Jamo
  23889. { 'begin': 0xA840, 'end': 0xA87F }, // Phags-pa
  23890. { 'begin': 0x3200, 'end': 0x32FF }, // Enclosed CJK Letters And Months
  23891. { 'begin': 0x3300, 'end': 0x33FF }, // CJK Compatibility
  23892. { 'begin': 0xAC00, 'end': 0xD7AF }, // Hangul Syllables
  23893. { 'begin': 0xD800, 'end': 0xDFFF }, // Non-Plane 0 *
  23894. { 'begin': 0x10900, 'end': 0x1091F }, // Phoenicia
  23895. { 'begin': 0x4E00, 'end': 0x9FFF }, // CJK Unified Ideographs
  23896. { 'begin': 0xE000, 'end': 0xF8FF }, // Private Use Area (plane 0)
  23897. { 'begin': 0x31C0, 'end': 0x31EF }, // CJK Strokes
  23898. { 'begin': 0xFB00, 'end': 0xFB4F }, // Alphabetic Presentation Forms
  23899. { 'begin': 0xFB50, 'end': 0xFDFF }, // Arabic Presentation Forms-A
  23900. { 'begin': 0xFE20, 'end': 0xFE2F }, // Combining Half Marks
  23901. { 'begin': 0xFE10, 'end': 0xFE1F }, // Vertical Forms
  23902. { 'begin': 0xFE50, 'end': 0xFE6F }, // Small Form Variants
  23903. { 'begin': 0xFE70, 'end': 0xFEFF }, // Arabic Presentation Forms-B
  23904. { 'begin': 0xFF00, 'end': 0xFFEF }, // Halfwidth And Fullwidth Forms
  23905. { 'begin': 0xFFF0, 'end': 0xFFFF }, // Specials
  23906. { 'begin': 0x0F00, 'end': 0x0FFF }, // Tibetan
  23907. { 'begin': 0x0700, 'end': 0x074F }, // Syriac
  23908. { 'begin': 0x0780, 'end': 0x07BF }, // Thaana
  23909. { 'begin': 0x0D80, 'end': 0x0DFF }, // Sinhala
  23910. { 'begin': 0x1000, 'end': 0x109F }, // Myanmar
  23911. { 'begin': 0x1200, 'end': 0x137F }, // Ethiopic
  23912. { 'begin': 0x13A0, 'end': 0x13FF }, // Cherokee
  23913. { 'begin': 0x1400, 'end': 0x167F }, // Unified Canadian Aboriginal Syllabics
  23914. { 'begin': 0x1680, 'end': 0x169F }, // Ogham
  23915. { 'begin': 0x16A0, 'end': 0x16FF }, // Runic
  23916. { 'begin': 0x1780, 'end': 0x17FF }, // Khmer
  23917. { 'begin': 0x1800, 'end': 0x18AF }, // Mongolian
  23918. { 'begin': 0x2800, 'end': 0x28FF }, // Braille Patterns
  23919. { 'begin': 0xA000, 'end': 0xA48F }, // Yi Syllables
  23920. { 'begin': 0x1700, 'end': 0x171F }, // Tagalog
  23921. { 'begin': 0x10300, 'end': 0x1032F }, // Old Italic
  23922. { 'begin': 0x10330, 'end': 0x1034F }, // Gothic
  23923. { 'begin': 0x10400, 'end': 0x1044F }, // Deseret
  23924. { 'begin': 0x1D000, 'end': 0x1D0FF }, // Byzantine Musical Symbols
  23925. { 'begin': 0x1D400, 'end': 0x1D7FF }, // Mathematical Alphanumeric Symbols
  23926. { 'begin': 0xFF000, 'end': 0xFFFFD }, // Private Use (plane 15)
  23927. { 'begin': 0xFE00, 'end': 0xFE0F }, // Variation Selectors
  23928. { 'begin': 0xE0000, 'end': 0xE007F }, // Tags
  23929. { 'begin': 0x1900, 'end': 0x194F }, // Limbu
  23930. { 'begin': 0x1950, 'end': 0x197F }, // Tai Le
  23931. { 'begin': 0x1980, 'end': 0x19DF }, // New Tai Lue
  23932. { 'begin': 0x1A00, 'end': 0x1A1F }, // Buginese
  23933. { 'begin': 0x2C00, 'end': 0x2C5F }, // Glagolitic
  23934. { 'begin': 0x2D30, 'end': 0x2D7F }, // Tifinagh
  23935. { 'begin': 0x4DC0, 'end': 0x4DFF }, // Yijing Hexagram Symbols
  23936. { 'begin': 0xA800, 'end': 0xA82F }, // Syloti Nagri
  23937. { 'begin': 0x10000, 'end': 0x1007F }, // Linear B Syllabary
  23938. { 'begin': 0x10140, 'end': 0x1018F }, // Ancient Greek Numbers
  23939. { 'begin': 0x10380, 'end': 0x1039F }, // Ugaritic
  23940. { 'begin': 0x103A0, 'end': 0x103DF }, // Old Persian
  23941. { 'begin': 0x10450, 'end': 0x1047F }, // Shavian
  23942. { 'begin': 0x10480, 'end': 0x104AF }, // Osmanya
  23943. { 'begin': 0x10800, 'end': 0x1083F }, // Cypriot Syllabary
  23944. { 'begin': 0x10A00, 'end': 0x10A5F }, // Kharoshthi
  23945. { 'begin': 0x1D300, 'end': 0x1D35F }, // Tai Xuan Jing Symbols
  23946. { 'begin': 0x12000, 'end': 0x123FF }, // Cuneiform
  23947. { 'begin': 0x1D360, 'end': 0x1D37F }, // Counting Rod Numerals
  23948. { 'begin': 0x1B80, 'end': 0x1BBF }, // Sundanese
  23949. { 'begin': 0x1C00, 'end': 0x1C4F }, // Lepcha
  23950. { 'begin': 0x1C50, 'end': 0x1C7F }, // Ol Chiki
  23951. { 'begin': 0xA880, 'end': 0xA8DF }, // Saurashtra
  23952. { 'begin': 0xA900, 'end': 0xA92F }, // Kayah Li
  23953. { 'begin': 0xA930, 'end': 0xA95F }, // Rejang
  23954. { 'begin': 0xAA00, 'end': 0xAA5F }, // Cham
  23955. { 'begin': 0x10190, 'end': 0x101CF }, // Ancient Symbols
  23956. { 'begin': 0x101D0, 'end': 0x101FF }, // Phaistos Disc
  23957. { 'begin': 0x102A0, 'end': 0x102DF }, // Carian
  23958. { 'begin': 0x1F030, 'end': 0x1F09F } // Domino Tiles
  23959. ];
  23960. var MacStandardGlyphOrdering = [
  23961. '.notdef', '.null', 'nonmarkingreturn', 'space', 'exclam', 'quotedbl',
  23962. 'numbersign', 'dollar', 'percent', 'ampersand', 'quotesingle', 'parenleft',
  23963. 'parenright', 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash',
  23964. 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  23965. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question', 'at',
  23966. 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
  23967. 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'bracketleft',
  23968. 'backslash', 'bracketright', 'asciicircum', 'underscore', 'grave', 'a', 'b',
  23969. 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q',
  23970. 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright',
  23971. 'asciitilde', 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde',
  23972. 'Odieresis', 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis',
  23973. 'atilde', 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  23974. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute', 'ograve',
  23975. 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave', 'ucircumflex',
  23976. 'udieresis', 'dagger', 'degree', 'cent', 'sterling', 'section', 'bullet',
  23977. 'paragraph', 'germandbls', 'registered', 'copyright', 'trademark', 'acute',
  23978. 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity', 'plusminus', 'lessequal',
  23979. 'greaterequal', 'yen', 'mu', 'partialdiff', 'summation', 'product', 'pi',
  23980. 'integral', 'ordfeminine', 'ordmasculine', 'Omega', 'ae', 'oslash',
  23981. 'questiondown', 'exclamdown', 'logicalnot', 'radical', 'florin',
  23982. 'approxequal', 'Delta', 'guillemotleft', 'guillemotright', 'ellipsis',
  23983. 'nonbreakingspace', 'Agrave', 'Atilde', 'Otilde', 'OE', 'oe', 'endash',
  23984. 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft', 'quoteright',
  23985. 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction', 'currency',
  23986. 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl', 'periodcentered',
  23987. 'quotesinglbase', 'quotedblbase', 'perthousand', 'Acircumflex',
  23988. 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute', 'Icircumflex',
  23989. 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple', 'Ograve', 'Uacute',
  23990. 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex', 'tilde', 'macron',
  23991. 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron',
  23992. 'Lslash', 'lslash', 'Scaron', 'scaron', 'Zcaron', 'zcaron', 'brokenbar',
  23993. 'Eth', 'eth', 'Yacute', 'yacute', 'Thorn', 'thorn', 'minus', 'multiply',
  23994. 'onesuperior', 'twosuperior', 'threesuperior', 'onehalf', 'onequarter',
  23995. 'threequarters', 'franc', 'Gbreve', 'gbreve', 'Idotaccent', 'Scedilla',
  23996. 'scedilla', 'Cacute', 'cacute', 'Ccaron', 'ccaron', 'dcroat'];
  23997. function getUnicodeRangeFor(value) {
  23998. for (var i = 0, ii = UnicodeRanges.length; i < ii; i++) {
  23999. var range = UnicodeRanges[i];
  24000. if (value >= range.begin && value < range.end) {
  24001. return i;
  24002. }
  24003. }
  24004. return -1;
  24005. }
  24006. function isRTLRangeFor(value) {
  24007. var range = UnicodeRanges[13];
  24008. if (value >= range.begin && value < range.end) {
  24009. return true;
  24010. }
  24011. range = UnicodeRanges[11];
  24012. if (value >= range.begin && value < range.end) {
  24013. return true;
  24014. }
  24015. return false;
  24016. }
  24017. // The normalization table is obtained by filtering the Unicode characters
  24018. // database with <compat> entries.
  24019. var NormalizedUnicodes = {
  24020. '\u00A8': '\u0020\u0308',
  24021. '\u00AF': '\u0020\u0304',
  24022. '\u00B4': '\u0020\u0301',
  24023. '\u00B5': '\u03BC',
  24024. '\u00B8': '\u0020\u0327',
  24025. '\u0132': '\u0049\u004A',
  24026. '\u0133': '\u0069\u006A',
  24027. '\u013F': '\u004C\u00B7',
  24028. '\u0140': '\u006C\u00B7',
  24029. '\u0149': '\u02BC\u006E',
  24030. '\u017F': '\u0073',
  24031. '\u01C4': '\u0044\u017D',
  24032. '\u01C5': '\u0044\u017E',
  24033. '\u01C6': '\u0064\u017E',
  24034. '\u01C7': '\u004C\u004A',
  24035. '\u01C8': '\u004C\u006A',
  24036. '\u01C9': '\u006C\u006A',
  24037. '\u01CA': '\u004E\u004A',
  24038. '\u01CB': '\u004E\u006A',
  24039. '\u01CC': '\u006E\u006A',
  24040. '\u01F1': '\u0044\u005A',
  24041. '\u01F2': '\u0044\u007A',
  24042. '\u01F3': '\u0064\u007A',
  24043. '\u02D8': '\u0020\u0306',
  24044. '\u02D9': '\u0020\u0307',
  24045. '\u02DA': '\u0020\u030A',
  24046. '\u02DB': '\u0020\u0328',
  24047. '\u02DC': '\u0020\u0303',
  24048. '\u02DD': '\u0020\u030B',
  24049. '\u037A': '\u0020\u0345',
  24050. '\u0384': '\u0020\u0301',
  24051. '\u03D0': '\u03B2',
  24052. '\u03D1': '\u03B8',
  24053. '\u03D2': '\u03A5',
  24054. '\u03D5': '\u03C6',
  24055. '\u03D6': '\u03C0',
  24056. '\u03F0': '\u03BA',
  24057. '\u03F1': '\u03C1',
  24058. '\u03F2': '\u03C2',
  24059. '\u03F4': '\u0398',
  24060. '\u03F5': '\u03B5',
  24061. '\u03F9': '\u03A3',
  24062. '\u0587': '\u0565\u0582',
  24063. '\u0675': '\u0627\u0674',
  24064. '\u0676': '\u0648\u0674',
  24065. '\u0677': '\u06C7\u0674',
  24066. '\u0678': '\u064A\u0674',
  24067. '\u0E33': '\u0E4D\u0E32',
  24068. '\u0EB3': '\u0ECD\u0EB2',
  24069. '\u0EDC': '\u0EAB\u0E99',
  24070. '\u0EDD': '\u0EAB\u0EA1',
  24071. '\u0F77': '\u0FB2\u0F81',
  24072. '\u0F79': '\u0FB3\u0F81',
  24073. '\u1E9A': '\u0061\u02BE',
  24074. '\u1FBD': '\u0020\u0313',
  24075. '\u1FBF': '\u0020\u0313',
  24076. '\u1FC0': '\u0020\u0342',
  24077. '\u1FFE': '\u0020\u0314',
  24078. '\u2002': '\u0020',
  24079. '\u2003': '\u0020',
  24080. '\u2004': '\u0020',
  24081. '\u2005': '\u0020',
  24082. '\u2006': '\u0020',
  24083. '\u2008': '\u0020',
  24084. '\u2009': '\u0020',
  24085. '\u200A': '\u0020',
  24086. '\u2017': '\u0020\u0333',
  24087. '\u2024': '\u002E',
  24088. '\u2025': '\u002E\u002E',
  24089. '\u2026': '\u002E\u002E\u002E',
  24090. '\u2033': '\u2032\u2032',
  24091. '\u2034': '\u2032\u2032\u2032',
  24092. '\u2036': '\u2035\u2035',
  24093. '\u2037': '\u2035\u2035\u2035',
  24094. '\u203C': '\u0021\u0021',
  24095. '\u203E': '\u0020\u0305',
  24096. '\u2047': '\u003F\u003F',
  24097. '\u2048': '\u003F\u0021',
  24098. '\u2049': '\u0021\u003F',
  24099. '\u2057': '\u2032\u2032\u2032\u2032',
  24100. '\u205F': '\u0020',
  24101. '\u20A8': '\u0052\u0073',
  24102. '\u2100': '\u0061\u002F\u0063',
  24103. '\u2101': '\u0061\u002F\u0073',
  24104. '\u2103': '\u00B0\u0043',
  24105. '\u2105': '\u0063\u002F\u006F',
  24106. '\u2106': '\u0063\u002F\u0075',
  24107. '\u2107': '\u0190',
  24108. '\u2109': '\u00B0\u0046',
  24109. '\u2116': '\u004E\u006F',
  24110. '\u2121': '\u0054\u0045\u004C',
  24111. '\u2135': '\u05D0',
  24112. '\u2136': '\u05D1',
  24113. '\u2137': '\u05D2',
  24114. '\u2138': '\u05D3',
  24115. '\u213B': '\u0046\u0041\u0058',
  24116. '\u2160': '\u0049',
  24117. '\u2161': '\u0049\u0049',
  24118. '\u2162': '\u0049\u0049\u0049',
  24119. '\u2163': '\u0049\u0056',
  24120. '\u2164': '\u0056',
  24121. '\u2165': '\u0056\u0049',
  24122. '\u2166': '\u0056\u0049\u0049',
  24123. '\u2167': '\u0056\u0049\u0049\u0049',
  24124. '\u2168': '\u0049\u0058',
  24125. '\u2169': '\u0058',
  24126. '\u216A': '\u0058\u0049',
  24127. '\u216B': '\u0058\u0049\u0049',
  24128. '\u216C': '\u004C',
  24129. '\u216D': '\u0043',
  24130. '\u216E': '\u0044',
  24131. '\u216F': '\u004D',
  24132. '\u2170': '\u0069',
  24133. '\u2171': '\u0069\u0069',
  24134. '\u2172': '\u0069\u0069\u0069',
  24135. '\u2173': '\u0069\u0076',
  24136. '\u2174': '\u0076',
  24137. '\u2175': '\u0076\u0069',
  24138. '\u2176': '\u0076\u0069\u0069',
  24139. '\u2177': '\u0076\u0069\u0069\u0069',
  24140. '\u2178': '\u0069\u0078',
  24141. '\u2179': '\u0078',
  24142. '\u217A': '\u0078\u0069',
  24143. '\u217B': '\u0078\u0069\u0069',
  24144. '\u217C': '\u006C',
  24145. '\u217D': '\u0063',
  24146. '\u217E': '\u0064',
  24147. '\u217F': '\u006D',
  24148. '\u222C': '\u222B\u222B',
  24149. '\u222D': '\u222B\u222B\u222B',
  24150. '\u222F': '\u222E\u222E',
  24151. '\u2230': '\u222E\u222E\u222E',
  24152. '\u2474': '\u0028\u0031\u0029',
  24153. '\u2475': '\u0028\u0032\u0029',
  24154. '\u2476': '\u0028\u0033\u0029',
  24155. '\u2477': '\u0028\u0034\u0029',
  24156. '\u2478': '\u0028\u0035\u0029',
  24157. '\u2479': '\u0028\u0036\u0029',
  24158. '\u247A': '\u0028\u0037\u0029',
  24159. '\u247B': '\u0028\u0038\u0029',
  24160. '\u247C': '\u0028\u0039\u0029',
  24161. '\u247D': '\u0028\u0031\u0030\u0029',
  24162. '\u247E': '\u0028\u0031\u0031\u0029',
  24163. '\u247F': '\u0028\u0031\u0032\u0029',
  24164. '\u2480': '\u0028\u0031\u0033\u0029',
  24165. '\u2481': '\u0028\u0031\u0034\u0029',
  24166. '\u2482': '\u0028\u0031\u0035\u0029',
  24167. '\u2483': '\u0028\u0031\u0036\u0029',
  24168. '\u2484': '\u0028\u0031\u0037\u0029',
  24169. '\u2485': '\u0028\u0031\u0038\u0029',
  24170. '\u2486': '\u0028\u0031\u0039\u0029',
  24171. '\u2487': '\u0028\u0032\u0030\u0029',
  24172. '\u2488': '\u0031\u002E',
  24173. '\u2489': '\u0032\u002E',
  24174. '\u248A': '\u0033\u002E',
  24175. '\u248B': '\u0034\u002E',
  24176. '\u248C': '\u0035\u002E',
  24177. '\u248D': '\u0036\u002E',
  24178. '\u248E': '\u0037\u002E',
  24179. '\u248F': '\u0038\u002E',
  24180. '\u2490': '\u0039\u002E',
  24181. '\u2491': '\u0031\u0030\u002E',
  24182. '\u2492': '\u0031\u0031\u002E',
  24183. '\u2493': '\u0031\u0032\u002E',
  24184. '\u2494': '\u0031\u0033\u002E',
  24185. '\u2495': '\u0031\u0034\u002E',
  24186. '\u2496': '\u0031\u0035\u002E',
  24187. '\u2497': '\u0031\u0036\u002E',
  24188. '\u2498': '\u0031\u0037\u002E',
  24189. '\u2499': '\u0031\u0038\u002E',
  24190. '\u249A': '\u0031\u0039\u002E',
  24191. '\u249B': '\u0032\u0030\u002E',
  24192. '\u249C': '\u0028\u0061\u0029',
  24193. '\u249D': '\u0028\u0062\u0029',
  24194. '\u249E': '\u0028\u0063\u0029',
  24195. '\u249F': '\u0028\u0064\u0029',
  24196. '\u24A0': '\u0028\u0065\u0029',
  24197. '\u24A1': '\u0028\u0066\u0029',
  24198. '\u24A2': '\u0028\u0067\u0029',
  24199. '\u24A3': '\u0028\u0068\u0029',
  24200. '\u24A4': '\u0028\u0069\u0029',
  24201. '\u24A5': '\u0028\u006A\u0029',
  24202. '\u24A6': '\u0028\u006B\u0029',
  24203. '\u24A7': '\u0028\u006C\u0029',
  24204. '\u24A8': '\u0028\u006D\u0029',
  24205. '\u24A9': '\u0028\u006E\u0029',
  24206. '\u24AA': '\u0028\u006F\u0029',
  24207. '\u24AB': '\u0028\u0070\u0029',
  24208. '\u24AC': '\u0028\u0071\u0029',
  24209. '\u24AD': '\u0028\u0072\u0029',
  24210. '\u24AE': '\u0028\u0073\u0029',
  24211. '\u24AF': '\u0028\u0074\u0029',
  24212. '\u24B0': '\u0028\u0075\u0029',
  24213. '\u24B1': '\u0028\u0076\u0029',
  24214. '\u24B2': '\u0028\u0077\u0029',
  24215. '\u24B3': '\u0028\u0078\u0029',
  24216. '\u24B4': '\u0028\u0079\u0029',
  24217. '\u24B5': '\u0028\u007A\u0029',
  24218. '\u2A0C': '\u222B\u222B\u222B\u222B',
  24219. '\u2A74': '\u003A\u003A\u003D',
  24220. '\u2A75': '\u003D\u003D',
  24221. '\u2A76': '\u003D\u003D\u003D',
  24222. '\u2E9F': '\u6BCD',
  24223. '\u2EF3': '\u9F9F',
  24224. '\u2F00': '\u4E00',
  24225. '\u2F01': '\u4E28',
  24226. '\u2F02': '\u4E36',
  24227. '\u2F03': '\u4E3F',
  24228. '\u2F04': '\u4E59',
  24229. '\u2F05': '\u4E85',
  24230. '\u2F06': '\u4E8C',
  24231. '\u2F07': '\u4EA0',
  24232. '\u2F08': '\u4EBA',
  24233. '\u2F09': '\u513F',
  24234. '\u2F0A': '\u5165',
  24235. '\u2F0B': '\u516B',
  24236. '\u2F0C': '\u5182',
  24237. '\u2F0D': '\u5196',
  24238. '\u2F0E': '\u51AB',
  24239. '\u2F0F': '\u51E0',
  24240. '\u2F10': '\u51F5',
  24241. '\u2F11': '\u5200',
  24242. '\u2F12': '\u529B',
  24243. '\u2F13': '\u52F9',
  24244. '\u2F14': '\u5315',
  24245. '\u2F15': '\u531A',
  24246. '\u2F16': '\u5338',
  24247. '\u2F17': '\u5341',
  24248. '\u2F18': '\u535C',
  24249. '\u2F19': '\u5369',
  24250. '\u2F1A': '\u5382',
  24251. '\u2F1B': '\u53B6',
  24252. '\u2F1C': '\u53C8',
  24253. '\u2F1D': '\u53E3',
  24254. '\u2F1E': '\u56D7',
  24255. '\u2F1F': '\u571F',
  24256. '\u2F20': '\u58EB',
  24257. '\u2F21': '\u5902',
  24258. '\u2F22': '\u590A',
  24259. '\u2F23': '\u5915',
  24260. '\u2F24': '\u5927',
  24261. '\u2F25': '\u5973',
  24262. '\u2F26': '\u5B50',
  24263. '\u2F27': '\u5B80',
  24264. '\u2F28': '\u5BF8',
  24265. '\u2F29': '\u5C0F',
  24266. '\u2F2A': '\u5C22',
  24267. '\u2F2B': '\u5C38',
  24268. '\u2F2C': '\u5C6E',
  24269. '\u2F2D': '\u5C71',
  24270. '\u2F2E': '\u5DDB',
  24271. '\u2F2F': '\u5DE5',
  24272. '\u2F30': '\u5DF1',
  24273. '\u2F31': '\u5DFE',
  24274. '\u2F32': '\u5E72',
  24275. '\u2F33': '\u5E7A',
  24276. '\u2F34': '\u5E7F',
  24277. '\u2F35': '\u5EF4',
  24278. '\u2F36': '\u5EFE',
  24279. '\u2F37': '\u5F0B',
  24280. '\u2F38': '\u5F13',
  24281. '\u2F39': '\u5F50',
  24282. '\u2F3A': '\u5F61',
  24283. '\u2F3B': '\u5F73',
  24284. '\u2F3C': '\u5FC3',
  24285. '\u2F3D': '\u6208',
  24286. '\u2F3E': '\u6236',
  24287. '\u2F3F': '\u624B',
  24288. '\u2F40': '\u652F',
  24289. '\u2F41': '\u6534',
  24290. '\u2F42': '\u6587',
  24291. '\u2F43': '\u6597',
  24292. '\u2F44': '\u65A4',
  24293. '\u2F45': '\u65B9',
  24294. '\u2F46': '\u65E0',
  24295. '\u2F47': '\u65E5',
  24296. '\u2F48': '\u66F0',
  24297. '\u2F49': '\u6708',
  24298. '\u2F4A': '\u6728',
  24299. '\u2F4B': '\u6B20',
  24300. '\u2F4C': '\u6B62',
  24301. '\u2F4D': '\u6B79',
  24302. '\u2F4E': '\u6BB3',
  24303. '\u2F4F': '\u6BCB',
  24304. '\u2F50': '\u6BD4',
  24305. '\u2F51': '\u6BDB',
  24306. '\u2F52': '\u6C0F',
  24307. '\u2F53': '\u6C14',
  24308. '\u2F54': '\u6C34',
  24309. '\u2F55': '\u706B',
  24310. '\u2F56': '\u722A',
  24311. '\u2F57': '\u7236',
  24312. '\u2F58': '\u723B',
  24313. '\u2F59': '\u723F',
  24314. '\u2F5A': '\u7247',
  24315. '\u2F5B': '\u7259',
  24316. '\u2F5C': '\u725B',
  24317. '\u2F5D': '\u72AC',
  24318. '\u2F5E': '\u7384',
  24319. '\u2F5F': '\u7389',
  24320. '\u2F60': '\u74DC',
  24321. '\u2F61': '\u74E6',
  24322. '\u2F62': '\u7518',
  24323. '\u2F63': '\u751F',
  24324. '\u2F64': '\u7528',
  24325. '\u2F65': '\u7530',
  24326. '\u2F66': '\u758B',
  24327. '\u2F67': '\u7592',
  24328. '\u2F68': '\u7676',
  24329. '\u2F69': '\u767D',
  24330. '\u2F6A': '\u76AE',
  24331. '\u2F6B': '\u76BF',
  24332. '\u2F6C': '\u76EE',
  24333. '\u2F6D': '\u77DB',
  24334. '\u2F6E': '\u77E2',
  24335. '\u2F6F': '\u77F3',
  24336. '\u2F70': '\u793A',
  24337. '\u2F71': '\u79B8',
  24338. '\u2F72': '\u79BE',
  24339. '\u2F73': '\u7A74',
  24340. '\u2F74': '\u7ACB',
  24341. '\u2F75': '\u7AF9',
  24342. '\u2F76': '\u7C73',
  24343. '\u2F77': '\u7CF8',
  24344. '\u2F78': '\u7F36',
  24345. '\u2F79': '\u7F51',
  24346. '\u2F7A': '\u7F8A',
  24347. '\u2F7B': '\u7FBD',
  24348. '\u2F7C': '\u8001',
  24349. '\u2F7D': '\u800C',
  24350. '\u2F7E': '\u8012',
  24351. '\u2F7F': '\u8033',
  24352. '\u2F80': '\u807F',
  24353. '\u2F81': '\u8089',
  24354. '\u2F82': '\u81E3',
  24355. '\u2F83': '\u81EA',
  24356. '\u2F84': '\u81F3',
  24357. '\u2F85': '\u81FC',
  24358. '\u2F86': '\u820C',
  24359. '\u2F87': '\u821B',
  24360. '\u2F88': '\u821F',
  24361. '\u2F89': '\u826E',
  24362. '\u2F8A': '\u8272',
  24363. '\u2F8B': '\u8278',
  24364. '\u2F8C': '\u864D',
  24365. '\u2F8D': '\u866B',
  24366. '\u2F8E': '\u8840',
  24367. '\u2F8F': '\u884C',
  24368. '\u2F90': '\u8863',
  24369. '\u2F91': '\u897E',
  24370. '\u2F92': '\u898B',
  24371. '\u2F93': '\u89D2',
  24372. '\u2F94': '\u8A00',
  24373. '\u2F95': '\u8C37',
  24374. '\u2F96': '\u8C46',
  24375. '\u2F97': '\u8C55',
  24376. '\u2F98': '\u8C78',
  24377. '\u2F99': '\u8C9D',
  24378. '\u2F9A': '\u8D64',
  24379. '\u2F9B': '\u8D70',
  24380. '\u2F9C': '\u8DB3',
  24381. '\u2F9D': '\u8EAB',
  24382. '\u2F9E': '\u8ECA',
  24383. '\u2F9F': '\u8F9B',
  24384. '\u2FA0': '\u8FB0',
  24385. '\u2FA1': '\u8FB5',
  24386. '\u2FA2': '\u9091',
  24387. '\u2FA3': '\u9149',
  24388. '\u2FA4': '\u91C6',
  24389. '\u2FA5': '\u91CC',
  24390. '\u2FA6': '\u91D1',
  24391. '\u2FA7': '\u9577',
  24392. '\u2FA8': '\u9580',
  24393. '\u2FA9': '\u961C',
  24394. '\u2FAA': '\u96B6',
  24395. '\u2FAB': '\u96B9',
  24396. '\u2FAC': '\u96E8',
  24397. '\u2FAD': '\u9751',
  24398. '\u2FAE': '\u975E',
  24399. '\u2FAF': '\u9762',
  24400. '\u2FB0': '\u9769',
  24401. '\u2FB1': '\u97CB',
  24402. '\u2FB2': '\u97ED',
  24403. '\u2FB3': '\u97F3',
  24404. '\u2FB4': '\u9801',
  24405. '\u2FB5': '\u98A8',
  24406. '\u2FB6': '\u98DB',
  24407. '\u2FB7': '\u98DF',
  24408. '\u2FB8': '\u9996',
  24409. '\u2FB9': '\u9999',
  24410. '\u2FBA': '\u99AC',
  24411. '\u2FBB': '\u9AA8',
  24412. '\u2FBC': '\u9AD8',
  24413. '\u2FBD': '\u9ADF',
  24414. '\u2FBE': '\u9B25',
  24415. '\u2FBF': '\u9B2F',
  24416. '\u2FC0': '\u9B32',
  24417. '\u2FC1': '\u9B3C',
  24418. '\u2FC2': '\u9B5A',
  24419. '\u2FC3': '\u9CE5',
  24420. '\u2FC4': '\u9E75',
  24421. '\u2FC5': '\u9E7F',
  24422. '\u2FC6': '\u9EA5',
  24423. '\u2FC7': '\u9EBB',
  24424. '\u2FC8': '\u9EC3',
  24425. '\u2FC9': '\u9ECD',
  24426. '\u2FCA': '\u9ED1',
  24427. '\u2FCB': '\u9EF9',
  24428. '\u2FCC': '\u9EFD',
  24429. '\u2FCD': '\u9F0E',
  24430. '\u2FCE': '\u9F13',
  24431. '\u2FCF': '\u9F20',
  24432. '\u2FD0': '\u9F3B',
  24433. '\u2FD1': '\u9F4A',
  24434. '\u2FD2': '\u9F52',
  24435. '\u2FD3': '\u9F8D',
  24436. '\u2FD4': '\u9F9C',
  24437. '\u2FD5': '\u9FA0',
  24438. '\u3036': '\u3012',
  24439. '\u3038': '\u5341',
  24440. '\u3039': '\u5344',
  24441. '\u303A': '\u5345',
  24442. '\u309B': '\u0020\u3099',
  24443. '\u309C': '\u0020\u309A',
  24444. '\u3131': '\u1100',
  24445. '\u3132': '\u1101',
  24446. '\u3133': '\u11AA',
  24447. '\u3134': '\u1102',
  24448. '\u3135': '\u11AC',
  24449. '\u3136': '\u11AD',
  24450. '\u3137': '\u1103',
  24451. '\u3138': '\u1104',
  24452. '\u3139': '\u1105',
  24453. '\u313A': '\u11B0',
  24454. '\u313B': '\u11B1',
  24455. '\u313C': '\u11B2',
  24456. '\u313D': '\u11B3',
  24457. '\u313E': '\u11B4',
  24458. '\u313F': '\u11B5',
  24459. '\u3140': '\u111A',
  24460. '\u3141': '\u1106',
  24461. '\u3142': '\u1107',
  24462. '\u3143': '\u1108',
  24463. '\u3144': '\u1121',
  24464. '\u3145': '\u1109',
  24465. '\u3146': '\u110A',
  24466. '\u3147': '\u110B',
  24467. '\u3148': '\u110C',
  24468. '\u3149': '\u110D',
  24469. '\u314A': '\u110E',
  24470. '\u314B': '\u110F',
  24471. '\u314C': '\u1110',
  24472. '\u314D': '\u1111',
  24473. '\u314E': '\u1112',
  24474. '\u314F': '\u1161',
  24475. '\u3150': '\u1162',
  24476. '\u3151': '\u1163',
  24477. '\u3152': '\u1164',
  24478. '\u3153': '\u1165',
  24479. '\u3154': '\u1166',
  24480. '\u3155': '\u1167',
  24481. '\u3156': '\u1168',
  24482. '\u3157': '\u1169',
  24483. '\u3158': '\u116A',
  24484. '\u3159': '\u116B',
  24485. '\u315A': '\u116C',
  24486. '\u315B': '\u116D',
  24487. '\u315C': '\u116E',
  24488. '\u315D': '\u116F',
  24489. '\u315E': '\u1170',
  24490. '\u315F': '\u1171',
  24491. '\u3160': '\u1172',
  24492. '\u3161': '\u1173',
  24493. '\u3162': '\u1174',
  24494. '\u3163': '\u1175',
  24495. '\u3164': '\u1160',
  24496. '\u3165': '\u1114',
  24497. '\u3166': '\u1115',
  24498. '\u3167': '\u11C7',
  24499. '\u3168': '\u11C8',
  24500. '\u3169': '\u11CC',
  24501. '\u316A': '\u11CE',
  24502. '\u316B': '\u11D3',
  24503. '\u316C': '\u11D7',
  24504. '\u316D': '\u11D9',
  24505. '\u316E': '\u111C',
  24506. '\u316F': '\u11DD',
  24507. '\u3170': '\u11DF',
  24508. '\u3171': '\u111D',
  24509. '\u3172': '\u111E',
  24510. '\u3173': '\u1120',
  24511. '\u3174': '\u1122',
  24512. '\u3175': '\u1123',
  24513. '\u3176': '\u1127',
  24514. '\u3177': '\u1129',
  24515. '\u3178': '\u112B',
  24516. '\u3179': '\u112C',
  24517. '\u317A': '\u112D',
  24518. '\u317B': '\u112E',
  24519. '\u317C': '\u112F',
  24520. '\u317D': '\u1132',
  24521. '\u317E': '\u1136',
  24522. '\u317F': '\u1140',
  24523. '\u3180': '\u1147',
  24524. '\u3181': '\u114C',
  24525. '\u3182': '\u11F1',
  24526. '\u3183': '\u11F2',
  24527. '\u3184': '\u1157',
  24528. '\u3185': '\u1158',
  24529. '\u3186': '\u1159',
  24530. '\u3187': '\u1184',
  24531. '\u3188': '\u1185',
  24532. '\u3189': '\u1188',
  24533. '\u318A': '\u1191',
  24534. '\u318B': '\u1192',
  24535. '\u318C': '\u1194',
  24536. '\u318D': '\u119E',
  24537. '\u318E': '\u11A1',
  24538. '\u3200': '\u0028\u1100\u0029',
  24539. '\u3201': '\u0028\u1102\u0029',
  24540. '\u3202': '\u0028\u1103\u0029',
  24541. '\u3203': '\u0028\u1105\u0029',
  24542. '\u3204': '\u0028\u1106\u0029',
  24543. '\u3205': '\u0028\u1107\u0029',
  24544. '\u3206': '\u0028\u1109\u0029',
  24545. '\u3207': '\u0028\u110B\u0029',
  24546. '\u3208': '\u0028\u110C\u0029',
  24547. '\u3209': '\u0028\u110E\u0029',
  24548. '\u320A': '\u0028\u110F\u0029',
  24549. '\u320B': '\u0028\u1110\u0029',
  24550. '\u320C': '\u0028\u1111\u0029',
  24551. '\u320D': '\u0028\u1112\u0029',
  24552. '\u320E': '\u0028\u1100\u1161\u0029',
  24553. '\u320F': '\u0028\u1102\u1161\u0029',
  24554. '\u3210': '\u0028\u1103\u1161\u0029',
  24555. '\u3211': '\u0028\u1105\u1161\u0029',
  24556. '\u3212': '\u0028\u1106\u1161\u0029',
  24557. '\u3213': '\u0028\u1107\u1161\u0029',
  24558. '\u3214': '\u0028\u1109\u1161\u0029',
  24559. '\u3215': '\u0028\u110B\u1161\u0029',
  24560. '\u3216': '\u0028\u110C\u1161\u0029',
  24561. '\u3217': '\u0028\u110E\u1161\u0029',
  24562. '\u3218': '\u0028\u110F\u1161\u0029',
  24563. '\u3219': '\u0028\u1110\u1161\u0029',
  24564. '\u321A': '\u0028\u1111\u1161\u0029',
  24565. '\u321B': '\u0028\u1112\u1161\u0029',
  24566. '\u321C': '\u0028\u110C\u116E\u0029',
  24567. '\u321D': '\u0028\u110B\u1169\u110C\u1165\u11AB\u0029',
  24568. '\u321E': '\u0028\u110B\u1169\u1112\u116E\u0029',
  24569. '\u3220': '\u0028\u4E00\u0029',
  24570. '\u3221': '\u0028\u4E8C\u0029',
  24571. '\u3222': '\u0028\u4E09\u0029',
  24572. '\u3223': '\u0028\u56DB\u0029',
  24573. '\u3224': '\u0028\u4E94\u0029',
  24574. '\u3225': '\u0028\u516D\u0029',
  24575. '\u3226': '\u0028\u4E03\u0029',
  24576. '\u3227': '\u0028\u516B\u0029',
  24577. '\u3228': '\u0028\u4E5D\u0029',
  24578. '\u3229': '\u0028\u5341\u0029',
  24579. '\u322A': '\u0028\u6708\u0029',
  24580. '\u322B': '\u0028\u706B\u0029',
  24581. '\u322C': '\u0028\u6C34\u0029',
  24582. '\u322D': '\u0028\u6728\u0029',
  24583. '\u322E': '\u0028\u91D1\u0029',
  24584. '\u322F': '\u0028\u571F\u0029',
  24585. '\u3230': '\u0028\u65E5\u0029',
  24586. '\u3231': '\u0028\u682A\u0029',
  24587. '\u3232': '\u0028\u6709\u0029',
  24588. '\u3233': '\u0028\u793E\u0029',
  24589. '\u3234': '\u0028\u540D\u0029',
  24590. '\u3235': '\u0028\u7279\u0029',
  24591. '\u3236': '\u0028\u8CA1\u0029',
  24592. '\u3237': '\u0028\u795D\u0029',
  24593. '\u3238': '\u0028\u52B4\u0029',
  24594. '\u3239': '\u0028\u4EE3\u0029',
  24595. '\u323A': '\u0028\u547C\u0029',
  24596. '\u323B': '\u0028\u5B66\u0029',
  24597. '\u323C': '\u0028\u76E3\u0029',
  24598. '\u323D': '\u0028\u4F01\u0029',
  24599. '\u323E': '\u0028\u8CC7\u0029',
  24600. '\u323F': '\u0028\u5354\u0029',
  24601. '\u3240': '\u0028\u796D\u0029',
  24602. '\u3241': '\u0028\u4F11\u0029',
  24603. '\u3242': '\u0028\u81EA\u0029',
  24604. '\u3243': '\u0028\u81F3\u0029',
  24605. '\u32C0': '\u0031\u6708',
  24606. '\u32C1': '\u0032\u6708',
  24607. '\u32C2': '\u0033\u6708',
  24608. '\u32C3': '\u0034\u6708',
  24609. '\u32C4': '\u0035\u6708',
  24610. '\u32C5': '\u0036\u6708',
  24611. '\u32C6': '\u0037\u6708',
  24612. '\u32C7': '\u0038\u6708',
  24613. '\u32C8': '\u0039\u6708',
  24614. '\u32C9': '\u0031\u0030\u6708',
  24615. '\u32CA': '\u0031\u0031\u6708',
  24616. '\u32CB': '\u0031\u0032\u6708',
  24617. '\u3358': '\u0030\u70B9',
  24618. '\u3359': '\u0031\u70B9',
  24619. '\u335A': '\u0032\u70B9',
  24620. '\u335B': '\u0033\u70B9',
  24621. '\u335C': '\u0034\u70B9',
  24622. '\u335D': '\u0035\u70B9',
  24623. '\u335E': '\u0036\u70B9',
  24624. '\u335F': '\u0037\u70B9',
  24625. '\u3360': '\u0038\u70B9',
  24626. '\u3361': '\u0039\u70B9',
  24627. '\u3362': '\u0031\u0030\u70B9',
  24628. '\u3363': '\u0031\u0031\u70B9',
  24629. '\u3364': '\u0031\u0032\u70B9',
  24630. '\u3365': '\u0031\u0033\u70B9',
  24631. '\u3366': '\u0031\u0034\u70B9',
  24632. '\u3367': '\u0031\u0035\u70B9',
  24633. '\u3368': '\u0031\u0036\u70B9',
  24634. '\u3369': '\u0031\u0037\u70B9',
  24635. '\u336A': '\u0031\u0038\u70B9',
  24636. '\u336B': '\u0031\u0039\u70B9',
  24637. '\u336C': '\u0032\u0030\u70B9',
  24638. '\u336D': '\u0032\u0031\u70B9',
  24639. '\u336E': '\u0032\u0032\u70B9',
  24640. '\u336F': '\u0032\u0033\u70B9',
  24641. '\u3370': '\u0032\u0034\u70B9',
  24642. '\u33E0': '\u0031\u65E5',
  24643. '\u33E1': '\u0032\u65E5',
  24644. '\u33E2': '\u0033\u65E5',
  24645. '\u33E3': '\u0034\u65E5',
  24646. '\u33E4': '\u0035\u65E5',
  24647. '\u33E5': '\u0036\u65E5',
  24648. '\u33E6': '\u0037\u65E5',
  24649. '\u33E7': '\u0038\u65E5',
  24650. '\u33E8': '\u0039\u65E5',
  24651. '\u33E9': '\u0031\u0030\u65E5',
  24652. '\u33EA': '\u0031\u0031\u65E5',
  24653. '\u33EB': '\u0031\u0032\u65E5',
  24654. '\u33EC': '\u0031\u0033\u65E5',
  24655. '\u33ED': '\u0031\u0034\u65E5',
  24656. '\u33EE': '\u0031\u0035\u65E5',
  24657. '\u33EF': '\u0031\u0036\u65E5',
  24658. '\u33F0': '\u0031\u0037\u65E5',
  24659. '\u33F1': '\u0031\u0038\u65E5',
  24660. '\u33F2': '\u0031\u0039\u65E5',
  24661. '\u33F3': '\u0032\u0030\u65E5',
  24662. '\u33F4': '\u0032\u0031\u65E5',
  24663. '\u33F5': '\u0032\u0032\u65E5',
  24664. '\u33F6': '\u0032\u0033\u65E5',
  24665. '\u33F7': '\u0032\u0034\u65E5',
  24666. '\u33F8': '\u0032\u0035\u65E5',
  24667. '\u33F9': '\u0032\u0036\u65E5',
  24668. '\u33FA': '\u0032\u0037\u65E5',
  24669. '\u33FB': '\u0032\u0038\u65E5',
  24670. '\u33FC': '\u0032\u0039\u65E5',
  24671. '\u33FD': '\u0033\u0030\u65E5',
  24672. '\u33FE': '\u0033\u0031\u65E5',
  24673. '\uFB00': '\u0066\u0066',
  24674. '\uFB01': '\u0066\u0069',
  24675. '\uFB02': '\u0066\u006C',
  24676. '\uFB03': '\u0066\u0066\u0069',
  24677. '\uFB04': '\u0066\u0066\u006C',
  24678. '\uFB05': '\u017F\u0074',
  24679. '\uFB06': '\u0073\u0074',
  24680. '\uFB13': '\u0574\u0576',
  24681. '\uFB14': '\u0574\u0565',
  24682. '\uFB15': '\u0574\u056B',
  24683. '\uFB16': '\u057E\u0576',
  24684. '\uFB17': '\u0574\u056D',
  24685. '\uFB4F': '\u05D0\u05DC',
  24686. '\uFB50': '\u0671',
  24687. '\uFB51': '\u0671',
  24688. '\uFB52': '\u067B',
  24689. '\uFB53': '\u067B',
  24690. '\uFB54': '\u067B',
  24691. '\uFB55': '\u067B',
  24692. '\uFB56': '\u067E',
  24693. '\uFB57': '\u067E',
  24694. '\uFB58': '\u067E',
  24695. '\uFB59': '\u067E',
  24696. '\uFB5A': '\u0680',
  24697. '\uFB5B': '\u0680',
  24698. '\uFB5C': '\u0680',
  24699. '\uFB5D': '\u0680',
  24700. '\uFB5E': '\u067A',
  24701. '\uFB5F': '\u067A',
  24702. '\uFB60': '\u067A',
  24703. '\uFB61': '\u067A',
  24704. '\uFB62': '\u067F',
  24705. '\uFB63': '\u067F',
  24706. '\uFB64': '\u067F',
  24707. '\uFB65': '\u067F',
  24708. '\uFB66': '\u0679',
  24709. '\uFB67': '\u0679',
  24710. '\uFB68': '\u0679',
  24711. '\uFB69': '\u0679',
  24712. '\uFB6A': '\u06A4',
  24713. '\uFB6B': '\u06A4',
  24714. '\uFB6C': '\u06A4',
  24715. '\uFB6D': '\u06A4',
  24716. '\uFB6E': '\u06A6',
  24717. '\uFB6F': '\u06A6',
  24718. '\uFB70': '\u06A6',
  24719. '\uFB71': '\u06A6',
  24720. '\uFB72': '\u0684',
  24721. '\uFB73': '\u0684',
  24722. '\uFB74': '\u0684',
  24723. '\uFB75': '\u0684',
  24724. '\uFB76': '\u0683',
  24725. '\uFB77': '\u0683',
  24726. '\uFB78': '\u0683',
  24727. '\uFB79': '\u0683',
  24728. '\uFB7A': '\u0686',
  24729. '\uFB7B': '\u0686',
  24730. '\uFB7C': '\u0686',
  24731. '\uFB7D': '\u0686',
  24732. '\uFB7E': '\u0687',
  24733. '\uFB7F': '\u0687',
  24734. '\uFB80': '\u0687',
  24735. '\uFB81': '\u0687',
  24736. '\uFB82': '\u068D',
  24737. '\uFB83': '\u068D',
  24738. '\uFB84': '\u068C',
  24739. '\uFB85': '\u068C',
  24740. '\uFB86': '\u068E',
  24741. '\uFB87': '\u068E',
  24742. '\uFB88': '\u0688',
  24743. '\uFB89': '\u0688',
  24744. '\uFB8A': '\u0698',
  24745. '\uFB8B': '\u0698',
  24746. '\uFB8C': '\u0691',
  24747. '\uFB8D': '\u0691',
  24748. '\uFB8E': '\u06A9',
  24749. '\uFB8F': '\u06A9',
  24750. '\uFB90': '\u06A9',
  24751. '\uFB91': '\u06A9',
  24752. '\uFB92': '\u06AF',
  24753. '\uFB93': '\u06AF',
  24754. '\uFB94': '\u06AF',
  24755. '\uFB95': '\u06AF',
  24756. '\uFB96': '\u06B3',
  24757. '\uFB97': '\u06B3',
  24758. '\uFB98': '\u06B3',
  24759. '\uFB99': '\u06B3',
  24760. '\uFB9A': '\u06B1',
  24761. '\uFB9B': '\u06B1',
  24762. '\uFB9C': '\u06B1',
  24763. '\uFB9D': '\u06B1',
  24764. '\uFB9E': '\u06BA',
  24765. '\uFB9F': '\u06BA',
  24766. '\uFBA0': '\u06BB',
  24767. '\uFBA1': '\u06BB',
  24768. '\uFBA2': '\u06BB',
  24769. '\uFBA3': '\u06BB',
  24770. '\uFBA4': '\u06C0',
  24771. '\uFBA5': '\u06C0',
  24772. '\uFBA6': '\u06C1',
  24773. '\uFBA7': '\u06C1',
  24774. '\uFBA8': '\u06C1',
  24775. '\uFBA9': '\u06C1',
  24776. '\uFBAA': '\u06BE',
  24777. '\uFBAB': '\u06BE',
  24778. '\uFBAC': '\u06BE',
  24779. '\uFBAD': '\u06BE',
  24780. '\uFBAE': '\u06D2',
  24781. '\uFBAF': '\u06D2',
  24782. '\uFBB0': '\u06D3',
  24783. '\uFBB1': '\u06D3',
  24784. '\uFBD3': '\u06AD',
  24785. '\uFBD4': '\u06AD',
  24786. '\uFBD5': '\u06AD',
  24787. '\uFBD6': '\u06AD',
  24788. '\uFBD7': '\u06C7',
  24789. '\uFBD8': '\u06C7',
  24790. '\uFBD9': '\u06C6',
  24791. '\uFBDA': '\u06C6',
  24792. '\uFBDB': '\u06C8',
  24793. '\uFBDC': '\u06C8',
  24794. '\uFBDD': '\u0677',
  24795. '\uFBDE': '\u06CB',
  24796. '\uFBDF': '\u06CB',
  24797. '\uFBE0': '\u06C5',
  24798. '\uFBE1': '\u06C5',
  24799. '\uFBE2': '\u06C9',
  24800. '\uFBE3': '\u06C9',
  24801. '\uFBE4': '\u06D0',
  24802. '\uFBE5': '\u06D0',
  24803. '\uFBE6': '\u06D0',
  24804. '\uFBE7': '\u06D0',
  24805. '\uFBE8': '\u0649',
  24806. '\uFBE9': '\u0649',
  24807. '\uFBEA': '\u0626\u0627',
  24808. '\uFBEB': '\u0626\u0627',
  24809. '\uFBEC': '\u0626\u06D5',
  24810. '\uFBED': '\u0626\u06D5',
  24811. '\uFBEE': '\u0626\u0648',
  24812. '\uFBEF': '\u0626\u0648',
  24813. '\uFBF0': '\u0626\u06C7',
  24814. '\uFBF1': '\u0626\u06C7',
  24815. '\uFBF2': '\u0626\u06C6',
  24816. '\uFBF3': '\u0626\u06C6',
  24817. '\uFBF4': '\u0626\u06C8',
  24818. '\uFBF5': '\u0626\u06C8',
  24819. '\uFBF6': '\u0626\u06D0',
  24820. '\uFBF7': '\u0626\u06D0',
  24821. '\uFBF8': '\u0626\u06D0',
  24822. '\uFBF9': '\u0626\u0649',
  24823. '\uFBFA': '\u0626\u0649',
  24824. '\uFBFB': '\u0626\u0649',
  24825. '\uFBFC': '\u06CC',
  24826. '\uFBFD': '\u06CC',
  24827. '\uFBFE': '\u06CC',
  24828. '\uFBFF': '\u06CC',
  24829. '\uFC00': '\u0626\u062C',
  24830. '\uFC01': '\u0626\u062D',
  24831. '\uFC02': '\u0626\u0645',
  24832. '\uFC03': '\u0626\u0649',
  24833. '\uFC04': '\u0626\u064A',
  24834. '\uFC05': '\u0628\u062C',
  24835. '\uFC06': '\u0628\u062D',
  24836. '\uFC07': '\u0628\u062E',
  24837. '\uFC08': '\u0628\u0645',
  24838. '\uFC09': '\u0628\u0649',
  24839. '\uFC0A': '\u0628\u064A',
  24840. '\uFC0B': '\u062A\u062C',
  24841. '\uFC0C': '\u062A\u062D',
  24842. '\uFC0D': '\u062A\u062E',
  24843. '\uFC0E': '\u062A\u0645',
  24844. '\uFC0F': '\u062A\u0649',
  24845. '\uFC10': '\u062A\u064A',
  24846. '\uFC11': '\u062B\u062C',
  24847. '\uFC12': '\u062B\u0645',
  24848. '\uFC13': '\u062B\u0649',
  24849. '\uFC14': '\u062B\u064A',
  24850. '\uFC15': '\u062C\u062D',
  24851. '\uFC16': '\u062C\u0645',
  24852. '\uFC17': '\u062D\u062C',
  24853. '\uFC18': '\u062D\u0645',
  24854. '\uFC19': '\u062E\u062C',
  24855. '\uFC1A': '\u062E\u062D',
  24856. '\uFC1B': '\u062E\u0645',
  24857. '\uFC1C': '\u0633\u062C',
  24858. '\uFC1D': '\u0633\u062D',
  24859. '\uFC1E': '\u0633\u062E',
  24860. '\uFC1F': '\u0633\u0645',
  24861. '\uFC20': '\u0635\u062D',
  24862. '\uFC21': '\u0635\u0645',
  24863. '\uFC22': '\u0636\u062C',
  24864. '\uFC23': '\u0636\u062D',
  24865. '\uFC24': '\u0636\u062E',
  24866. '\uFC25': '\u0636\u0645',
  24867. '\uFC26': '\u0637\u062D',
  24868. '\uFC27': '\u0637\u0645',
  24869. '\uFC28': '\u0638\u0645',
  24870. '\uFC29': '\u0639\u062C',
  24871. '\uFC2A': '\u0639\u0645',
  24872. '\uFC2B': '\u063A\u062C',
  24873. '\uFC2C': '\u063A\u0645',
  24874. '\uFC2D': '\u0641\u062C',
  24875. '\uFC2E': '\u0641\u062D',
  24876. '\uFC2F': '\u0641\u062E',
  24877. '\uFC30': '\u0641\u0645',
  24878. '\uFC31': '\u0641\u0649',
  24879. '\uFC32': '\u0641\u064A',
  24880. '\uFC33': '\u0642\u062D',
  24881. '\uFC34': '\u0642\u0645',
  24882. '\uFC35': '\u0642\u0649',
  24883. '\uFC36': '\u0642\u064A',
  24884. '\uFC37': '\u0643\u0627',
  24885. '\uFC38': '\u0643\u062C',
  24886. '\uFC39': '\u0643\u062D',
  24887. '\uFC3A': '\u0643\u062E',
  24888. '\uFC3B': '\u0643\u0644',
  24889. '\uFC3C': '\u0643\u0645',
  24890. '\uFC3D': '\u0643\u0649',
  24891. '\uFC3E': '\u0643\u064A',
  24892. '\uFC3F': '\u0644\u062C',
  24893. '\uFC40': '\u0644\u062D',
  24894. '\uFC41': '\u0644\u062E',
  24895. '\uFC42': '\u0644\u0645',
  24896. '\uFC43': '\u0644\u0649',
  24897. '\uFC44': '\u0644\u064A',
  24898. '\uFC45': '\u0645\u062C',
  24899. '\uFC46': '\u0645\u062D',
  24900. '\uFC47': '\u0645\u062E',
  24901. '\uFC48': '\u0645\u0645',
  24902. '\uFC49': '\u0645\u0649',
  24903. '\uFC4A': '\u0645\u064A',
  24904. '\uFC4B': '\u0646\u062C',
  24905. '\uFC4C': '\u0646\u062D',
  24906. '\uFC4D': '\u0646\u062E',
  24907. '\uFC4E': '\u0646\u0645',
  24908. '\uFC4F': '\u0646\u0649',
  24909. '\uFC50': '\u0646\u064A',
  24910. '\uFC51': '\u0647\u062C',
  24911. '\uFC52': '\u0647\u0645',
  24912. '\uFC53': '\u0647\u0649',
  24913. '\uFC54': '\u0647\u064A',
  24914. '\uFC55': '\u064A\u062C',
  24915. '\uFC56': '\u064A\u062D',
  24916. '\uFC57': '\u064A\u062E',
  24917. '\uFC58': '\u064A\u0645',
  24918. '\uFC59': '\u064A\u0649',
  24919. '\uFC5A': '\u064A\u064A',
  24920. '\uFC5B': '\u0630\u0670',
  24921. '\uFC5C': '\u0631\u0670',
  24922. '\uFC5D': '\u0649\u0670',
  24923. '\uFC5E': '\u0020\u064C\u0651',
  24924. '\uFC5F': '\u0020\u064D\u0651',
  24925. '\uFC60': '\u0020\u064E\u0651',
  24926. '\uFC61': '\u0020\u064F\u0651',
  24927. '\uFC62': '\u0020\u0650\u0651',
  24928. '\uFC63': '\u0020\u0651\u0670',
  24929. '\uFC64': '\u0626\u0631',
  24930. '\uFC65': '\u0626\u0632',
  24931. '\uFC66': '\u0626\u0645',
  24932. '\uFC67': '\u0626\u0646',
  24933. '\uFC68': '\u0626\u0649',
  24934. '\uFC69': '\u0626\u064A',
  24935. '\uFC6A': '\u0628\u0631',
  24936. '\uFC6B': '\u0628\u0632',
  24937. '\uFC6C': '\u0628\u0645',
  24938. '\uFC6D': '\u0628\u0646',
  24939. '\uFC6E': '\u0628\u0649',
  24940. '\uFC6F': '\u0628\u064A',
  24941. '\uFC70': '\u062A\u0631',
  24942. '\uFC71': '\u062A\u0632',
  24943. '\uFC72': '\u062A\u0645',
  24944. '\uFC73': '\u062A\u0646',
  24945. '\uFC74': '\u062A\u0649',
  24946. '\uFC75': '\u062A\u064A',
  24947. '\uFC76': '\u062B\u0631',
  24948. '\uFC77': '\u062B\u0632',
  24949. '\uFC78': '\u062B\u0645',
  24950. '\uFC79': '\u062B\u0646',
  24951. '\uFC7A': '\u062B\u0649',
  24952. '\uFC7B': '\u062B\u064A',
  24953. '\uFC7C': '\u0641\u0649',
  24954. '\uFC7D': '\u0641\u064A',
  24955. '\uFC7E': '\u0642\u0649',
  24956. '\uFC7F': '\u0642\u064A',
  24957. '\uFC80': '\u0643\u0627',
  24958. '\uFC81': '\u0643\u0644',
  24959. '\uFC82': '\u0643\u0645',
  24960. '\uFC83': '\u0643\u0649',
  24961. '\uFC84': '\u0643\u064A',
  24962. '\uFC85': '\u0644\u0645',
  24963. '\uFC86': '\u0644\u0649',
  24964. '\uFC87': '\u0644\u064A',
  24965. '\uFC88': '\u0645\u0627',
  24966. '\uFC89': '\u0645\u0645',
  24967. '\uFC8A': '\u0646\u0631',
  24968. '\uFC8B': '\u0646\u0632',
  24969. '\uFC8C': '\u0646\u0645',
  24970. '\uFC8D': '\u0646\u0646',
  24971. '\uFC8E': '\u0646\u0649',
  24972. '\uFC8F': '\u0646\u064A',
  24973. '\uFC90': '\u0649\u0670',
  24974. '\uFC91': '\u064A\u0631',
  24975. '\uFC92': '\u064A\u0632',
  24976. '\uFC93': '\u064A\u0645',
  24977. '\uFC94': '\u064A\u0646',
  24978. '\uFC95': '\u064A\u0649',
  24979. '\uFC96': '\u064A\u064A',
  24980. '\uFC97': '\u0626\u062C',
  24981. '\uFC98': '\u0626\u062D',
  24982. '\uFC99': '\u0626\u062E',
  24983. '\uFC9A': '\u0626\u0645',
  24984. '\uFC9B': '\u0626\u0647',
  24985. '\uFC9C': '\u0628\u062C',
  24986. '\uFC9D': '\u0628\u062D',
  24987. '\uFC9E': '\u0628\u062E',
  24988. '\uFC9F': '\u0628\u0645',
  24989. '\uFCA0': '\u0628\u0647',
  24990. '\uFCA1': '\u062A\u062C',
  24991. '\uFCA2': '\u062A\u062D',
  24992. '\uFCA3': '\u062A\u062E',
  24993. '\uFCA4': '\u062A\u0645',
  24994. '\uFCA5': '\u062A\u0647',
  24995. '\uFCA6': '\u062B\u0645',
  24996. '\uFCA7': '\u062C\u062D',
  24997. '\uFCA8': '\u062C\u0645',
  24998. '\uFCA9': '\u062D\u062C',
  24999. '\uFCAA': '\u062D\u0645',
  25000. '\uFCAB': '\u062E\u062C',
  25001. '\uFCAC': '\u062E\u0645',
  25002. '\uFCAD': '\u0633\u062C',
  25003. '\uFCAE': '\u0633\u062D',
  25004. '\uFCAF': '\u0633\u062E',
  25005. '\uFCB0': '\u0633\u0645',
  25006. '\uFCB1': '\u0635\u062D',
  25007. '\uFCB2': '\u0635\u062E',
  25008. '\uFCB3': '\u0635\u0645',
  25009. '\uFCB4': '\u0636\u062C',
  25010. '\uFCB5': '\u0636\u062D',
  25011. '\uFCB6': '\u0636\u062E',
  25012. '\uFCB7': '\u0636\u0645',
  25013. '\uFCB8': '\u0637\u062D',
  25014. '\uFCB9': '\u0638\u0645',
  25015. '\uFCBA': '\u0639\u062C',
  25016. '\uFCBB': '\u0639\u0645',
  25017. '\uFCBC': '\u063A\u062C',
  25018. '\uFCBD': '\u063A\u0645',
  25019. '\uFCBE': '\u0641\u062C',
  25020. '\uFCBF': '\u0641\u062D',
  25021. '\uFCC0': '\u0641\u062E',
  25022. '\uFCC1': '\u0641\u0645',
  25023. '\uFCC2': '\u0642\u062D',
  25024. '\uFCC3': '\u0642\u0645',
  25025. '\uFCC4': '\u0643\u062C',
  25026. '\uFCC5': '\u0643\u062D',
  25027. '\uFCC6': '\u0643\u062E',
  25028. '\uFCC7': '\u0643\u0644',
  25029. '\uFCC8': '\u0643\u0645',
  25030. '\uFCC9': '\u0644\u062C',
  25031. '\uFCCA': '\u0644\u062D',
  25032. '\uFCCB': '\u0644\u062E',
  25033. '\uFCCC': '\u0644\u0645',
  25034. '\uFCCD': '\u0644\u0647',
  25035. '\uFCCE': '\u0645\u062C',
  25036. '\uFCCF': '\u0645\u062D',
  25037. '\uFCD0': '\u0645\u062E',
  25038. '\uFCD1': '\u0645\u0645',
  25039. '\uFCD2': '\u0646\u062C',
  25040. '\uFCD3': '\u0646\u062D',
  25041. '\uFCD4': '\u0646\u062E',
  25042. '\uFCD5': '\u0646\u0645',
  25043. '\uFCD6': '\u0646\u0647',
  25044. '\uFCD7': '\u0647\u062C',
  25045. '\uFCD8': '\u0647\u0645',
  25046. '\uFCD9': '\u0647\u0670',
  25047. '\uFCDA': '\u064A\u062C',
  25048. '\uFCDB': '\u064A\u062D',
  25049. '\uFCDC': '\u064A\u062E',
  25050. '\uFCDD': '\u064A\u0645',
  25051. '\uFCDE': '\u064A\u0647',
  25052. '\uFCDF': '\u0626\u0645',
  25053. '\uFCE0': '\u0626\u0647',
  25054. '\uFCE1': '\u0628\u0645',
  25055. '\uFCE2': '\u0628\u0647',
  25056. '\uFCE3': '\u062A\u0645',
  25057. '\uFCE4': '\u062A\u0647',
  25058. '\uFCE5': '\u062B\u0645',
  25059. '\uFCE6': '\u062B\u0647',
  25060. '\uFCE7': '\u0633\u0645',
  25061. '\uFCE8': '\u0633\u0647',
  25062. '\uFCE9': '\u0634\u0645',
  25063. '\uFCEA': '\u0634\u0647',
  25064. '\uFCEB': '\u0643\u0644',
  25065. '\uFCEC': '\u0643\u0645',
  25066. '\uFCED': '\u0644\u0645',
  25067. '\uFCEE': '\u0646\u0645',
  25068. '\uFCEF': '\u0646\u0647',
  25069. '\uFCF0': '\u064A\u0645',
  25070. '\uFCF1': '\u064A\u0647',
  25071. '\uFCF2': '\u0640\u064E\u0651',
  25072. '\uFCF3': '\u0640\u064F\u0651',
  25073. '\uFCF4': '\u0640\u0650\u0651',
  25074. '\uFCF5': '\u0637\u0649',
  25075. '\uFCF6': '\u0637\u064A',
  25076. '\uFCF7': '\u0639\u0649',
  25077. '\uFCF8': '\u0639\u064A',
  25078. '\uFCF9': '\u063A\u0649',
  25079. '\uFCFA': '\u063A\u064A',
  25080. '\uFCFB': '\u0633\u0649',
  25081. '\uFCFC': '\u0633\u064A',
  25082. '\uFCFD': '\u0634\u0649',
  25083. '\uFCFE': '\u0634\u064A',
  25084. '\uFCFF': '\u062D\u0649',
  25085. '\uFD00': '\u062D\u064A',
  25086. '\uFD01': '\u062C\u0649',
  25087. '\uFD02': '\u062C\u064A',
  25088. '\uFD03': '\u062E\u0649',
  25089. '\uFD04': '\u062E\u064A',
  25090. '\uFD05': '\u0635\u0649',
  25091. '\uFD06': '\u0635\u064A',
  25092. '\uFD07': '\u0636\u0649',
  25093. '\uFD08': '\u0636\u064A',
  25094. '\uFD09': '\u0634\u062C',
  25095. '\uFD0A': '\u0634\u062D',
  25096. '\uFD0B': '\u0634\u062E',
  25097. '\uFD0C': '\u0634\u0645',
  25098. '\uFD0D': '\u0634\u0631',
  25099. '\uFD0E': '\u0633\u0631',
  25100. '\uFD0F': '\u0635\u0631',
  25101. '\uFD10': '\u0636\u0631',
  25102. '\uFD11': '\u0637\u0649',
  25103. '\uFD12': '\u0637\u064A',
  25104. '\uFD13': '\u0639\u0649',
  25105. '\uFD14': '\u0639\u064A',
  25106. '\uFD15': '\u063A\u0649',
  25107. '\uFD16': '\u063A\u064A',
  25108. '\uFD17': '\u0633\u0649',
  25109. '\uFD18': '\u0633\u064A',
  25110. '\uFD19': '\u0634\u0649',
  25111. '\uFD1A': '\u0634\u064A',
  25112. '\uFD1B': '\u062D\u0649',
  25113. '\uFD1C': '\u062D\u064A',
  25114. '\uFD1D': '\u062C\u0649',
  25115. '\uFD1E': '\u062C\u064A',
  25116. '\uFD1F': '\u062E\u0649',
  25117. '\uFD20': '\u062E\u064A',
  25118. '\uFD21': '\u0635\u0649',
  25119. '\uFD22': '\u0635\u064A',
  25120. '\uFD23': '\u0636\u0649',
  25121. '\uFD24': '\u0636\u064A',
  25122. '\uFD25': '\u0634\u062C',
  25123. '\uFD26': '\u0634\u062D',
  25124. '\uFD27': '\u0634\u062E',
  25125. '\uFD28': '\u0634\u0645',
  25126. '\uFD29': '\u0634\u0631',
  25127. '\uFD2A': '\u0633\u0631',
  25128. '\uFD2B': '\u0635\u0631',
  25129. '\uFD2C': '\u0636\u0631',
  25130. '\uFD2D': '\u0634\u062C',
  25131. '\uFD2E': '\u0634\u062D',
  25132. '\uFD2F': '\u0634\u062E',
  25133. '\uFD30': '\u0634\u0645',
  25134. '\uFD31': '\u0633\u0647',
  25135. '\uFD32': '\u0634\u0647',
  25136. '\uFD33': '\u0637\u0645',
  25137. '\uFD34': '\u0633\u062C',
  25138. '\uFD35': '\u0633\u062D',
  25139. '\uFD36': '\u0633\u062E',
  25140. '\uFD37': '\u0634\u062C',
  25141. '\uFD38': '\u0634\u062D',
  25142. '\uFD39': '\u0634\u062E',
  25143. '\uFD3A': '\u0637\u0645',
  25144. '\uFD3B': '\u0638\u0645',
  25145. '\uFD3C': '\u0627\u064B',
  25146. '\uFD3D': '\u0627\u064B',
  25147. '\uFD50': '\u062A\u062C\u0645',
  25148. '\uFD51': '\u062A\u062D\u062C',
  25149. '\uFD52': '\u062A\u062D\u062C',
  25150. '\uFD53': '\u062A\u062D\u0645',
  25151. '\uFD54': '\u062A\u062E\u0645',
  25152. '\uFD55': '\u062A\u0645\u062C',
  25153. '\uFD56': '\u062A\u0645\u062D',
  25154. '\uFD57': '\u062A\u0645\u062E',
  25155. '\uFD58': '\u062C\u0645\u062D',
  25156. '\uFD59': '\u062C\u0645\u062D',
  25157. '\uFD5A': '\u062D\u0645\u064A',
  25158. '\uFD5B': '\u062D\u0645\u0649',
  25159. '\uFD5C': '\u0633\u062D\u062C',
  25160. '\uFD5D': '\u0633\u062C\u062D',
  25161. '\uFD5E': '\u0633\u062C\u0649',
  25162. '\uFD5F': '\u0633\u0645\u062D',
  25163. '\uFD60': '\u0633\u0645\u062D',
  25164. '\uFD61': '\u0633\u0645\u062C',
  25165. '\uFD62': '\u0633\u0645\u0645',
  25166. '\uFD63': '\u0633\u0645\u0645',
  25167. '\uFD64': '\u0635\u062D\u062D',
  25168. '\uFD65': '\u0635\u062D\u062D',
  25169. '\uFD66': '\u0635\u0645\u0645',
  25170. '\uFD67': '\u0634\u062D\u0645',
  25171. '\uFD68': '\u0634\u062D\u0645',
  25172. '\uFD69': '\u0634\u062C\u064A',
  25173. '\uFD6A': '\u0634\u0645\u062E',
  25174. '\uFD6B': '\u0634\u0645\u062E',
  25175. '\uFD6C': '\u0634\u0645\u0645',
  25176. '\uFD6D': '\u0634\u0645\u0645',
  25177. '\uFD6E': '\u0636\u062D\u0649',
  25178. '\uFD6F': '\u0636\u062E\u0645',
  25179. '\uFD70': '\u0636\u062E\u0645',
  25180. '\uFD71': '\u0637\u0645\u062D',
  25181. '\uFD72': '\u0637\u0645\u062D',
  25182. '\uFD73': '\u0637\u0645\u0645',
  25183. '\uFD74': '\u0637\u0645\u064A',
  25184. '\uFD75': '\u0639\u062C\u0645',
  25185. '\uFD76': '\u0639\u0645\u0645',
  25186. '\uFD77': '\u0639\u0645\u0645',
  25187. '\uFD78': '\u0639\u0645\u0649',
  25188. '\uFD79': '\u063A\u0645\u0645',
  25189. '\uFD7A': '\u063A\u0645\u064A',
  25190. '\uFD7B': '\u063A\u0645\u0649',
  25191. '\uFD7C': '\u0641\u062E\u0645',
  25192. '\uFD7D': '\u0641\u062E\u0645',
  25193. '\uFD7E': '\u0642\u0645\u062D',
  25194. '\uFD7F': '\u0642\u0645\u0645',
  25195. '\uFD80': '\u0644\u062D\u0645',
  25196. '\uFD81': '\u0644\u062D\u064A',
  25197. '\uFD82': '\u0644\u062D\u0649',
  25198. '\uFD83': '\u0644\u062C\u062C',
  25199. '\uFD84': '\u0644\u062C\u062C',
  25200. '\uFD85': '\u0644\u062E\u0645',
  25201. '\uFD86': '\u0644\u062E\u0645',
  25202. '\uFD87': '\u0644\u0645\u062D',
  25203. '\uFD88': '\u0644\u0645\u062D',
  25204. '\uFD89': '\u0645\u062D\u062C',
  25205. '\uFD8A': '\u0645\u062D\u0645',
  25206. '\uFD8B': '\u0645\u062D\u064A',
  25207. '\uFD8C': '\u0645\u062C\u062D',
  25208. '\uFD8D': '\u0645\u062C\u0645',
  25209. '\uFD8E': '\u0645\u062E\u062C',
  25210. '\uFD8F': '\u0645\u062E\u0645',
  25211. '\uFD92': '\u0645\u062C\u062E',
  25212. '\uFD93': '\u0647\u0645\u062C',
  25213. '\uFD94': '\u0647\u0645\u0645',
  25214. '\uFD95': '\u0646\u062D\u0645',
  25215. '\uFD96': '\u0646\u062D\u0649',
  25216. '\uFD97': '\u0646\u062C\u0645',
  25217. '\uFD98': '\u0646\u062C\u0645',
  25218. '\uFD99': '\u0646\u062C\u0649',
  25219. '\uFD9A': '\u0646\u0645\u064A',
  25220. '\uFD9B': '\u0646\u0645\u0649',
  25221. '\uFD9C': '\u064A\u0645\u0645',
  25222. '\uFD9D': '\u064A\u0645\u0645',
  25223. '\uFD9E': '\u0628\u062E\u064A',
  25224. '\uFD9F': '\u062A\u062C\u064A',
  25225. '\uFDA0': '\u062A\u062C\u0649',
  25226. '\uFDA1': '\u062A\u062E\u064A',
  25227. '\uFDA2': '\u062A\u062E\u0649',
  25228. '\uFDA3': '\u062A\u0645\u064A',
  25229. '\uFDA4': '\u062A\u0645\u0649',
  25230. '\uFDA5': '\u062C\u0645\u064A',
  25231. '\uFDA6': '\u062C\u062D\u0649',
  25232. '\uFDA7': '\u062C\u0645\u0649',
  25233. '\uFDA8': '\u0633\u062E\u0649',
  25234. '\uFDA9': '\u0635\u062D\u064A',
  25235. '\uFDAA': '\u0634\u062D\u064A',
  25236. '\uFDAB': '\u0636\u062D\u064A',
  25237. '\uFDAC': '\u0644\u062C\u064A',
  25238. '\uFDAD': '\u0644\u0645\u064A',
  25239. '\uFDAE': '\u064A\u062D\u064A',
  25240. '\uFDAF': '\u064A\u062C\u064A',
  25241. '\uFDB0': '\u064A\u0645\u064A',
  25242. '\uFDB1': '\u0645\u0645\u064A',
  25243. '\uFDB2': '\u0642\u0645\u064A',
  25244. '\uFDB3': '\u0646\u062D\u064A',
  25245. '\uFDB4': '\u0642\u0645\u062D',
  25246. '\uFDB5': '\u0644\u062D\u0645',
  25247. '\uFDB6': '\u0639\u0645\u064A',
  25248. '\uFDB7': '\u0643\u0645\u064A',
  25249. '\uFDB8': '\u0646\u062C\u062D',
  25250. '\uFDB9': '\u0645\u062E\u064A',
  25251. '\uFDBA': '\u0644\u062C\u0645',
  25252. '\uFDBB': '\u0643\u0645\u0645',
  25253. '\uFDBC': '\u0644\u062C\u0645',
  25254. '\uFDBD': '\u0646\u062C\u062D',
  25255. '\uFDBE': '\u062C\u062D\u064A',
  25256. '\uFDBF': '\u062D\u062C\u064A',
  25257. '\uFDC0': '\u0645\u062C\u064A',
  25258. '\uFDC1': '\u0641\u0645\u064A',
  25259. '\uFDC2': '\u0628\u062D\u064A',
  25260. '\uFDC3': '\u0643\u0645\u0645',
  25261. '\uFDC4': '\u0639\u062C\u0645',
  25262. '\uFDC5': '\u0635\u0645\u0645',
  25263. '\uFDC6': '\u0633\u062E\u064A',
  25264. '\uFDC7': '\u0646\u062C\u064A',
  25265. '\uFE49': '\u203E',
  25266. '\uFE4A': '\u203E',
  25267. '\uFE4B': '\u203E',
  25268. '\uFE4C': '\u203E',
  25269. '\uFE4D': '\u005F',
  25270. '\uFE4E': '\u005F',
  25271. '\uFE4F': '\u005F',
  25272. '\uFE80': '\u0621',
  25273. '\uFE81': '\u0622',
  25274. '\uFE82': '\u0622',
  25275. '\uFE83': '\u0623',
  25276. '\uFE84': '\u0623',
  25277. '\uFE85': '\u0624',
  25278. '\uFE86': '\u0624',
  25279. '\uFE87': '\u0625',
  25280. '\uFE88': '\u0625',
  25281. '\uFE89': '\u0626',
  25282. '\uFE8A': '\u0626',
  25283. '\uFE8B': '\u0626',
  25284. '\uFE8C': '\u0626',
  25285. '\uFE8D': '\u0627',
  25286. '\uFE8E': '\u0627',
  25287. '\uFE8F': '\u0628',
  25288. '\uFE90': '\u0628',
  25289. '\uFE91': '\u0628',
  25290. '\uFE92': '\u0628',
  25291. '\uFE93': '\u0629',
  25292. '\uFE94': '\u0629',
  25293. '\uFE95': '\u062A',
  25294. '\uFE96': '\u062A',
  25295. '\uFE97': '\u062A',
  25296. '\uFE98': '\u062A',
  25297. '\uFE99': '\u062B',
  25298. '\uFE9A': '\u062B',
  25299. '\uFE9B': '\u062B',
  25300. '\uFE9C': '\u062B',
  25301. '\uFE9D': '\u062C',
  25302. '\uFE9E': '\u062C',
  25303. '\uFE9F': '\u062C',
  25304. '\uFEA0': '\u062C',
  25305. '\uFEA1': '\u062D',
  25306. '\uFEA2': '\u062D',
  25307. '\uFEA3': '\u062D',
  25308. '\uFEA4': '\u062D',
  25309. '\uFEA5': '\u062E',
  25310. '\uFEA6': '\u062E',
  25311. '\uFEA7': '\u062E',
  25312. '\uFEA8': '\u062E',
  25313. '\uFEA9': '\u062F',
  25314. '\uFEAA': '\u062F',
  25315. '\uFEAB': '\u0630',
  25316. '\uFEAC': '\u0630',
  25317. '\uFEAD': '\u0631',
  25318. '\uFEAE': '\u0631',
  25319. '\uFEAF': '\u0632',
  25320. '\uFEB0': '\u0632',
  25321. '\uFEB1': '\u0633',
  25322. '\uFEB2': '\u0633',
  25323. '\uFEB3': '\u0633',
  25324. '\uFEB4': '\u0633',
  25325. '\uFEB5': '\u0634',
  25326. '\uFEB6': '\u0634',
  25327. '\uFEB7': '\u0634',
  25328. '\uFEB8': '\u0634',
  25329. '\uFEB9': '\u0635',
  25330. '\uFEBA': '\u0635',
  25331. '\uFEBB': '\u0635',
  25332. '\uFEBC': '\u0635',
  25333. '\uFEBD': '\u0636',
  25334. '\uFEBE': '\u0636',
  25335. '\uFEBF': '\u0636',
  25336. '\uFEC0': '\u0636',
  25337. '\uFEC1': '\u0637',
  25338. '\uFEC2': '\u0637',
  25339. '\uFEC3': '\u0637',
  25340. '\uFEC4': '\u0637',
  25341. '\uFEC5': '\u0638',
  25342. '\uFEC6': '\u0638',
  25343. '\uFEC7': '\u0638',
  25344. '\uFEC8': '\u0638',
  25345. '\uFEC9': '\u0639',
  25346. '\uFECA': '\u0639',
  25347. '\uFECB': '\u0639',
  25348. '\uFECC': '\u0639',
  25349. '\uFECD': '\u063A',
  25350. '\uFECE': '\u063A',
  25351. '\uFECF': '\u063A',
  25352. '\uFED0': '\u063A',
  25353. '\uFED1': '\u0641',
  25354. '\uFED2': '\u0641',
  25355. '\uFED3': '\u0641',
  25356. '\uFED4': '\u0641',
  25357. '\uFED5': '\u0642',
  25358. '\uFED6': '\u0642',
  25359. '\uFED7': '\u0642',
  25360. '\uFED8': '\u0642',
  25361. '\uFED9': '\u0643',
  25362. '\uFEDA': '\u0643',
  25363. '\uFEDB': '\u0643',
  25364. '\uFEDC': '\u0643',
  25365. '\uFEDD': '\u0644',
  25366. '\uFEDE': '\u0644',
  25367. '\uFEDF': '\u0644',
  25368. '\uFEE0': '\u0644',
  25369. '\uFEE1': '\u0645',
  25370. '\uFEE2': '\u0645',
  25371. '\uFEE3': '\u0645',
  25372. '\uFEE4': '\u0645',
  25373. '\uFEE5': '\u0646',
  25374. '\uFEE6': '\u0646',
  25375. '\uFEE7': '\u0646',
  25376. '\uFEE8': '\u0646',
  25377. '\uFEE9': '\u0647',
  25378. '\uFEEA': '\u0647',
  25379. '\uFEEB': '\u0647',
  25380. '\uFEEC': '\u0647',
  25381. '\uFEED': '\u0648',
  25382. '\uFEEE': '\u0648',
  25383. '\uFEEF': '\u0649',
  25384. '\uFEF0': '\u0649',
  25385. '\uFEF1': '\u064A',
  25386. '\uFEF2': '\u064A',
  25387. '\uFEF3': '\u064A',
  25388. '\uFEF4': '\u064A',
  25389. '\uFEF5': '\u0644\u0622',
  25390. '\uFEF6': '\u0644\u0622',
  25391. '\uFEF7': '\u0644\u0623',
  25392. '\uFEF8': '\u0644\u0623',
  25393. '\uFEF9': '\u0644\u0625',
  25394. '\uFEFA': '\u0644\u0625',
  25395. '\uFEFB': '\u0644\u0627',
  25396. '\uFEFC': '\u0644\u0627'
  25397. };
  25398. function reverseIfRtl(chars) {
  25399. var charsLength = chars.length;
  25400. //reverse an arabic ligature
  25401. if (charsLength <= 1 || !isRTLRangeFor(chars.charCodeAt(0))) {
  25402. return chars;
  25403. }
  25404. var s = '';
  25405. for (var ii = charsLength - 1; ii >= 0; ii--) {
  25406. s += chars[ii];
  25407. }
  25408. return s;
  25409. }
  25410. function adjustWidths(properties) {
  25411. if (!properties.fontMatrix) {
  25412. return;
  25413. }
  25414. if (properties.fontMatrix[0] === FONT_IDENTITY_MATRIX[0]) {
  25415. return;
  25416. }
  25417. // adjusting width to fontMatrix scale
  25418. var scale = 0.001 / properties.fontMatrix[0];
  25419. var glyphsWidths = properties.widths;
  25420. for (var glyph in glyphsWidths) {
  25421. glyphsWidths[glyph] *= scale;
  25422. }
  25423. properties.defaultWidth *= scale;
  25424. }
  25425. function getFontType(type, subtype) {
  25426. switch (type) {
  25427. case 'Type1':
  25428. return subtype === 'Type1C' ? FontType.TYPE1C : FontType.TYPE1;
  25429. case 'CIDFontType0':
  25430. return subtype === 'CIDFontType0C' ? FontType.CIDFONTTYPE0C :
  25431. FontType.CIDFONTTYPE0;
  25432. case 'OpenType':
  25433. return FontType.OPENTYPE;
  25434. case 'TrueType':
  25435. return FontType.TRUETYPE;
  25436. case 'CIDFontType2':
  25437. return FontType.CIDFONTTYPE2;
  25438. case 'MMType1':
  25439. return FontType.MMTYPE1;
  25440. case 'Type0':
  25441. return FontType.TYPE0;
  25442. default:
  25443. return FontType.UNKNOWN;
  25444. }
  25445. }
  25446. var Glyph = (function GlyphClosure() {
  25447. function Glyph(fontChar, unicode, accent, width, vmetric, operatorListId,
  25448. isSpace) {
  25449. this.fontChar = fontChar;
  25450. this.unicode = unicode;
  25451. this.accent = accent;
  25452. this.width = width;
  25453. this.vmetric = vmetric;
  25454. this.operatorListId = operatorListId;
  25455. this.isSpace = isSpace;
  25456. }
  25457. Glyph.prototype.matchesForCache = function(fontChar, unicode, accent, width,
  25458. vmetric, operatorListId, isSpace) {
  25459. return this.fontChar === fontChar &&
  25460. this.unicode === unicode &&
  25461. this.accent === accent &&
  25462. this.width === width &&
  25463. this.vmetric === vmetric &&
  25464. this.operatorListId === operatorListId &&
  25465. this.isSpace === isSpace;
  25466. };
  25467. return Glyph;
  25468. })();
  25469. var ToUnicodeMap = (function ToUnicodeMapClosure() {
  25470. function ToUnicodeMap(cmap) {
  25471. // The elements of this._map can be integers or strings, depending on how
  25472. // |cmap| was created.
  25473. this._map = cmap;
  25474. }
  25475. ToUnicodeMap.prototype = {
  25476. get length() {
  25477. return this._map.length;
  25478. },
  25479. forEach: function(callback) {
  25480. for (var charCode in this._map) {
  25481. callback(charCode, this._map[charCode].charCodeAt(0));
  25482. }
  25483. },
  25484. has: function(i) {
  25485. return this._map[i] !== undefined;
  25486. },
  25487. get: function(i) {
  25488. return this._map[i];
  25489. },
  25490. charCodeOf: function(v) {
  25491. return this._map.indexOf(v);
  25492. }
  25493. };
  25494. return ToUnicodeMap;
  25495. })();
  25496. var IdentityToUnicodeMap = (function IdentityToUnicodeMapClosure() {
  25497. function IdentityToUnicodeMap(firstChar, lastChar) {
  25498. this.firstChar = firstChar;
  25499. this.lastChar = lastChar;
  25500. }
  25501. IdentityToUnicodeMap.prototype = {
  25502. get length() {
  25503. return (this.lastChar + 1) - this.firstChar;
  25504. },
  25505. forEach: function (callback) {
  25506. for (var i = this.firstChar, ii = this.lastChar; i <= ii; i++) {
  25507. callback(i, i);
  25508. }
  25509. },
  25510. has: function (i) {
  25511. return this.firstChar <= i && i <= this.lastChar;
  25512. },
  25513. get: function (i) {
  25514. if (this.firstChar <= i && i <= this.lastChar) {
  25515. return String.fromCharCode(i);
  25516. }
  25517. return undefined;
  25518. },
  25519. charCodeOf: function (v) {
  25520. return (isInt(v) && v >= this.firstChar && v <= this.lastChar) ? v : -1;
  25521. }
  25522. };
  25523. return IdentityToUnicodeMap;
  25524. })();
  25525. var OpenTypeFileBuilder = (function OpenTypeFileBuilderClosure() {
  25526. function writeInt16(dest, offset, num) {
  25527. dest[offset] = (num >> 8) & 0xFF;
  25528. dest[offset + 1] = num & 0xFF;
  25529. }
  25530. function writeInt32(dest, offset, num) {
  25531. dest[offset] = (num >> 24) & 0xFF;
  25532. dest[offset + 1] = (num >> 16) & 0xFF;
  25533. dest[offset + 2] = (num >> 8) & 0xFF;
  25534. dest[offset + 3] = num & 0xFF;
  25535. }
  25536. function writeData(dest, offset, data) {
  25537. var i, ii;
  25538. if (data instanceof Uint8Array) {
  25539. dest.set(data, offset);
  25540. } else if (typeof data === 'string') {
  25541. for (i = 0, ii = data.length; i < ii; i++) {
  25542. dest[offset++] = data.charCodeAt(i) & 0xFF;
  25543. }
  25544. } else {
  25545. // treating everything else as array
  25546. for (i = 0, ii = data.length; i < ii; i++) {
  25547. dest[offset++] = data[i] & 0xFF;
  25548. }
  25549. }
  25550. }
  25551. function OpenTypeFileBuilder(sfnt) {
  25552. this.sfnt = sfnt;
  25553. this.tables = Object.create(null);
  25554. }
  25555. OpenTypeFileBuilder.getSearchParams =
  25556. function OpenTypeFileBuilder_getSearchParams(entriesCount, entrySize) {
  25557. var maxPower2 = 1, log2 = 0;
  25558. while ((maxPower2 ^ entriesCount) > maxPower2) {
  25559. maxPower2 <<= 1;
  25560. log2++;
  25561. }
  25562. var searchRange = maxPower2 * entrySize;
  25563. return {
  25564. range: searchRange,
  25565. entry: log2,
  25566. rangeShift: entrySize * entriesCount - searchRange
  25567. };
  25568. };
  25569. var OTF_HEADER_SIZE = 12;
  25570. var OTF_TABLE_ENTRY_SIZE = 16;
  25571. OpenTypeFileBuilder.prototype = {
  25572. toArray: function OpenTypeFileBuilder_toArray() {
  25573. var sfnt = this.sfnt;
  25574. // Tables needs to be written by ascendant alphabetic order
  25575. var tables = this.tables;
  25576. var tablesNames = Object.keys(tables);
  25577. tablesNames.sort();
  25578. var numTables = tablesNames.length;
  25579. var i, j, jj, table, tableName;
  25580. // layout the tables data
  25581. var offset = OTF_HEADER_SIZE + numTables * OTF_TABLE_ENTRY_SIZE;
  25582. var tableOffsets = [offset];
  25583. for (i = 0; i < numTables; i++) {
  25584. table = tables[tablesNames[i]];
  25585. var paddedLength = ((table.length + 3) & ~3) >>> 0;
  25586. offset += paddedLength;
  25587. tableOffsets.push(offset);
  25588. }
  25589. var file = new Uint8Array(offset);
  25590. // write the table data first (mostly for checksum)
  25591. for (i = 0; i < numTables; i++) {
  25592. table = tables[tablesNames[i]];
  25593. writeData(file, tableOffsets[i], table);
  25594. }
  25595. // sfnt version (4 bytes)
  25596. if (sfnt === 'true') {
  25597. // Windows hates the Mac TrueType sfnt version number
  25598. sfnt = string32(0x00010000);
  25599. }
  25600. file[0] = sfnt.charCodeAt(0) & 0xFF;
  25601. file[1] = sfnt.charCodeAt(1) & 0xFF;
  25602. file[2] = sfnt.charCodeAt(2) & 0xFF;
  25603. file[3] = sfnt.charCodeAt(3) & 0xFF;
  25604. // numTables (2 bytes)
  25605. writeInt16(file, 4, numTables);
  25606. var searchParams = OpenTypeFileBuilder.getSearchParams(numTables, 16);
  25607. // searchRange (2 bytes)
  25608. writeInt16(file, 6, searchParams.range);
  25609. // entrySelector (2 bytes)
  25610. writeInt16(file, 8, searchParams.entry);
  25611. // rangeShift (2 bytes)
  25612. writeInt16(file, 10, searchParams.rangeShift);
  25613. offset = OTF_HEADER_SIZE;
  25614. // writing table entries
  25615. for (i = 0; i < numTables; i++) {
  25616. tableName = tablesNames[i];
  25617. file[offset] = tableName.charCodeAt(0) & 0xFF;
  25618. file[offset + 1] = tableName.charCodeAt(1) & 0xFF;
  25619. file[offset + 2] = tableName.charCodeAt(2) & 0xFF;
  25620. file[offset + 3] = tableName.charCodeAt(3) & 0xFF;
  25621. // checksum
  25622. var checksum = 0;
  25623. for (j = tableOffsets[i], jj = tableOffsets[i + 1]; j < jj; j += 4) {
  25624. var quad = (file[j] << 24) + (file[j + 1] << 16) +
  25625. (file[j + 2] << 8) + file[j + 3];
  25626. checksum = (checksum + quad) | 0;
  25627. }
  25628. writeInt32(file, offset + 4, checksum);
  25629. // offset
  25630. writeInt32(file, offset + 8, tableOffsets[i]);
  25631. // length
  25632. writeInt32(file, offset + 12, tables[tableName].length);
  25633. offset += OTF_TABLE_ENTRY_SIZE;
  25634. }
  25635. return file;
  25636. },
  25637. addTable: function OpenTypeFileBuilder_addTable(tag, data) {
  25638. if (tag in this.tables) {
  25639. throw new Error('Table ' + tag + ' already exists');
  25640. }
  25641. this.tables[tag] = data;
  25642. }
  25643. };
  25644. return OpenTypeFileBuilder;
  25645. })();
  25646. // Problematic Unicode characters in the fonts that needs to be moved to avoid
  25647. // issues when they are painted on the canvas, e.g. complex-script shaping or
  25648. // control/whitespace characters. The ranges are listed in pairs: the first item
  25649. // is a code of the first problematic code, the second one is the next
  25650. // non-problematic code. The ranges must be in sorted order.
  25651. var ProblematicCharRanges = new Int32Array([
  25652. // Control characters.
  25653. 0x0000, 0x0020,
  25654. 0x007F, 0x00A1,
  25655. 0x00AD, 0x00AE,
  25656. // Chars that is used in complex-script shaping.
  25657. 0x0600, 0x0780,
  25658. 0x08A0, 0x10A0,
  25659. 0x1780, 0x1800,
  25660. // General punctuation chars.
  25661. 0x2000, 0x2010,
  25662. 0x2011, 0x2012,
  25663. 0x2028, 0x2030,
  25664. 0x205F, 0x2070,
  25665. 0x25CC, 0x25CD,
  25666. // Chars that is used in complex-script shaping.
  25667. 0xAA60, 0xAA80,
  25668. // Specials Unicode block.
  25669. 0xFFF0, 0x10000
  25670. ]);
  25671. /**
  25672. * 'Font' is the class the outside world should use, it encapsulate all the font
  25673. * decoding logics whatever type it is (assuming the font type is supported).
  25674. *
  25675. * For example to read a Type1 font and to attach it to the document:
  25676. * var type1Font = new Font("MyFontName", binaryFile, propertiesObject);
  25677. * type1Font.bind();
  25678. */
  25679. var Font = (function FontClosure() {
  25680. function Font(name, file, properties) {
  25681. var charCode, glyphName, fontChar;
  25682. this.name = name;
  25683. this.loadedName = properties.loadedName;
  25684. this.isType3Font = properties.isType3Font;
  25685. this.sizes = [];
  25686. this.glyphCache = {};
  25687. var names = name.split('+');
  25688. names = names.length > 1 ? names[1] : names[0];
  25689. names = names.split(/[-,_]/g)[0];
  25690. this.isSerifFont = !!(properties.flags & FontFlags.Serif);
  25691. this.isSymbolicFont = !!(properties.flags & FontFlags.Symbolic);
  25692. this.isMonospace = !!(properties.flags & FontFlags.FixedPitch);
  25693. var type = properties.type;
  25694. var subtype = properties.subtype;
  25695. this.type = type;
  25696. this.fallbackName = (this.isMonospace ? 'monospace' :
  25697. (this.isSerifFont ? 'serif' : 'sans-serif'));
  25698. this.differences = properties.differences;
  25699. this.widths = properties.widths;
  25700. this.defaultWidth = properties.defaultWidth;
  25701. this.composite = properties.composite;
  25702. this.wideChars = properties.wideChars;
  25703. this.cMap = properties.cMap;
  25704. this.ascent = properties.ascent / PDF_GLYPH_SPACE_UNITS;
  25705. this.descent = properties.descent / PDF_GLYPH_SPACE_UNITS;
  25706. this.fontMatrix = properties.fontMatrix;
  25707. this.bbox = properties.bbox;
  25708. this.toUnicode = properties.toUnicode = this.buildToUnicode(properties);
  25709. this.toFontChar = [];
  25710. if (properties.type === 'Type3') {
  25711. for (charCode = 0; charCode < 256; charCode++) {
  25712. this.toFontChar[charCode] = (this.differences[charCode] ||
  25713. properties.defaultEncoding[charCode]);
  25714. }
  25715. this.fontType = FontType.TYPE3;
  25716. return;
  25717. }
  25718. this.cidEncoding = properties.cidEncoding;
  25719. this.vertical = properties.vertical;
  25720. if (this.vertical) {
  25721. this.vmetrics = properties.vmetrics;
  25722. this.defaultVMetrics = properties.defaultVMetrics;
  25723. }
  25724. if (!file || file.isEmpty) {
  25725. if (file) {
  25726. // Some bad PDF generators will include empty font files,
  25727. // attempting to recover by assuming that no file exists.
  25728. warn('Font file is empty in "' + name + '" (' + this.loadedName + ')');
  25729. }
  25730. this.missingFile = true;
  25731. // The file data is not specified. Trying to fix the font name
  25732. // to be used with the canvas.font.
  25733. var fontName = name.replace(/[,_]/g, '-');
  25734. var isStandardFont = !!stdFontMap[fontName] ||
  25735. !!(nonStdFontMap[fontName] && stdFontMap[nonStdFontMap[fontName]]);
  25736. fontName = stdFontMap[fontName] || nonStdFontMap[fontName] || fontName;
  25737. this.bold = (fontName.search(/bold/gi) !== -1);
  25738. this.italic = ((fontName.search(/oblique/gi) !== -1) ||
  25739. (fontName.search(/italic/gi) !== -1));
  25740. // Use 'name' instead of 'fontName' here because the original
  25741. // name ArialBlack for example will be replaced by Helvetica.
  25742. this.black = (name.search(/Black/g) !== -1);
  25743. // if at least one width is present, remeasure all chars when exists
  25744. this.remeasure = Object.keys(this.widths).length > 0;
  25745. if (isStandardFont && type === 'CIDFontType2' &&
  25746. properties.cidEncoding.indexOf('Identity-') === 0) {
  25747. // Standard fonts might be embedded as CID font without glyph mapping.
  25748. // Building one based on GlyphMapForStandardFonts.
  25749. var map = [];
  25750. for (charCode in GlyphMapForStandardFonts) {
  25751. map[+charCode] = GlyphMapForStandardFonts[charCode];
  25752. }
  25753. if (/ArialBlack/i.test(name)) {
  25754. for (charCode in SupplementalGlyphMapForArialBlack) {
  25755. map[+charCode] = SupplementalGlyphMapForArialBlack[charCode];
  25756. }
  25757. }
  25758. var isIdentityUnicode = this.toUnicode instanceof IdentityToUnicodeMap;
  25759. if (!isIdentityUnicode) {
  25760. this.toUnicode.forEach(function(charCode, unicodeCharCode) {
  25761. map[+charCode] = unicodeCharCode;
  25762. });
  25763. }
  25764. this.toFontChar = map;
  25765. this.toUnicode = new ToUnicodeMap(map);
  25766. } else if (/Symbol/i.test(fontName)) {
  25767. var symbols = Encodings.SymbolSetEncoding;
  25768. for (charCode in symbols) {
  25769. fontChar = GlyphsUnicode[symbols[charCode]];
  25770. if (!fontChar) {
  25771. continue;
  25772. }
  25773. this.toFontChar[charCode] = fontChar;
  25774. }
  25775. for (charCode in properties.differences) {
  25776. fontChar = GlyphsUnicode[properties.differences[charCode]];
  25777. if (!fontChar) {
  25778. continue;
  25779. }
  25780. this.toFontChar[charCode] = fontChar;
  25781. }
  25782. } else if (/Dingbats/i.test(fontName)) {
  25783. if (/Wingdings/i.test(name)) {
  25784. warn('Wingdings font without embedded font file, ' +
  25785. 'falling back to the ZapfDingbats encoding.');
  25786. }
  25787. var dingbats = Encodings.ZapfDingbatsEncoding;
  25788. for (charCode in dingbats) {
  25789. fontChar = DingbatsGlyphsUnicode[dingbats[charCode]];
  25790. if (!fontChar) {
  25791. continue;
  25792. }
  25793. this.toFontChar[charCode] = fontChar;
  25794. }
  25795. for (charCode in properties.differences) {
  25796. fontChar = DingbatsGlyphsUnicode[properties.differences[charCode]];
  25797. if (!fontChar) {
  25798. continue;
  25799. }
  25800. this.toFontChar[charCode] = fontChar;
  25801. }
  25802. } else if (isStandardFont) {
  25803. this.toFontChar = [];
  25804. for (charCode in properties.defaultEncoding) {
  25805. glyphName = (properties.differences[charCode] ||
  25806. properties.defaultEncoding[charCode]);
  25807. this.toFontChar[charCode] = GlyphsUnicode[glyphName];
  25808. }
  25809. } else {
  25810. var unicodeCharCode, notCidFont = (type.indexOf('CIDFontType') === -1);
  25811. this.toUnicode.forEach(function(charCode, unicodeCharCode) {
  25812. if (notCidFont) {
  25813. glyphName = (properties.differences[charCode] ||
  25814. properties.defaultEncoding[charCode]);
  25815. unicodeCharCode = (GlyphsUnicode[glyphName] || unicodeCharCode);
  25816. }
  25817. this.toFontChar[charCode] = unicodeCharCode;
  25818. }.bind(this));
  25819. }
  25820. this.loadedName = fontName.split('-')[0];
  25821. this.loading = false;
  25822. this.fontType = getFontType(type, subtype);
  25823. return;
  25824. }
  25825. // Some fonts might use wrong font types for Type1C or CIDFontType0C
  25826. if (subtype === 'Type1C' && (type !== 'Type1' && type !== 'MMType1')) {
  25827. // Some TrueType fonts by mistake claim Type1C
  25828. if (isTrueTypeFile(file)) {
  25829. subtype = 'TrueType';
  25830. } else {
  25831. type = 'Type1';
  25832. }
  25833. }
  25834. if (subtype === 'CIDFontType0C' && type !== 'CIDFontType0') {
  25835. type = 'CIDFontType0';
  25836. }
  25837. if (subtype === 'OpenType') {
  25838. type = 'OpenType';
  25839. }
  25840. // Some CIDFontType0C fonts by mistake claim CIDFontType0.
  25841. if (type === 'CIDFontType0') {
  25842. subtype = isType1File(file) ? 'CIDFontType0' : 'CIDFontType0C';
  25843. }
  25844. var data;
  25845. switch (type) {
  25846. case 'MMType1':
  25847. info('MMType1 font (' + name + '), falling back to Type1.');
  25848. /* falls through */
  25849. case 'Type1':
  25850. case 'CIDFontType0':
  25851. this.mimetype = 'font/opentype';
  25852. var cff = (subtype === 'Type1C' || subtype === 'CIDFontType0C') ?
  25853. new CFFFont(file, properties) : new Type1Font(name, file, properties);
  25854. adjustWidths(properties);
  25855. // Wrap the CFF data inside an OTF font file
  25856. data = this.convert(name, cff, properties);
  25857. break;
  25858. case 'OpenType':
  25859. case 'TrueType':
  25860. case 'CIDFontType2':
  25861. this.mimetype = 'font/opentype';
  25862. // Repair the TrueType file. It is can be damaged in the point of
  25863. // view of the sanitizer
  25864. data = this.checkAndRepair(name, file, properties);
  25865. if (this.isOpenType) {
  25866. adjustWidths(properties);
  25867. type = 'OpenType';
  25868. }
  25869. break;
  25870. default:
  25871. error('Font ' + type + ' is not supported');
  25872. break;
  25873. }
  25874. this.data = data;
  25875. this.fontType = getFontType(type, subtype);
  25876. // Transfer some properties again that could change during font conversion
  25877. this.fontMatrix = properties.fontMatrix;
  25878. this.widths = properties.widths;
  25879. this.defaultWidth = properties.defaultWidth;
  25880. this.encoding = properties.baseEncoding;
  25881. this.seacMap = properties.seacMap;
  25882. this.loading = true;
  25883. }
  25884. Font.getFontID = (function () {
  25885. var ID = 1;
  25886. return function Font_getFontID() {
  25887. return String(ID++);
  25888. };
  25889. })();
  25890. function int16(b0, b1) {
  25891. return (b0 << 8) + b1;
  25892. }
  25893. function int32(b0, b1, b2, b3) {
  25894. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  25895. }
  25896. function string16(value) {
  25897. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  25898. }
  25899. function safeString16(value) {
  25900. // clamp value to the 16-bit int range
  25901. value = (value > 0x7FFF ? 0x7FFF : (value < -0x8000 ? -0x8000 : value));
  25902. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  25903. }
  25904. function isTrueTypeFile(file) {
  25905. var header = file.peekBytes(4);
  25906. return readUint32(header, 0) === 0x00010000;
  25907. }
  25908. function isType1File(file) {
  25909. var header = file.peekBytes(2);
  25910. // All Type1 font programs must begin with the comment '%!' (0x25 + 0x21).
  25911. if (header[0] === 0x25 && header[1] === 0x21) {
  25912. return true;
  25913. }
  25914. // ... obviously some fonts violate that part of the specification,
  25915. // please refer to the comment in |Type1Font| below.
  25916. if (header[0] === 0x80 && header[1] === 0x01) { // pfb file header.
  25917. return true;
  25918. }
  25919. return false;
  25920. }
  25921. /**
  25922. * Helper function for |adjustMapping|.
  25923. * @return {boolean}
  25924. */
  25925. function isProblematicUnicodeLocation(code) {
  25926. // Using binary search to find a range start.
  25927. var i = 0, j = ProblematicCharRanges.length - 1;
  25928. while (i < j) {
  25929. var c = (i + j + 1) >> 1;
  25930. if (code < ProblematicCharRanges[c]) {
  25931. j = c - 1;
  25932. } else {
  25933. i = c;
  25934. }
  25935. }
  25936. // Even index means code in problematic range.
  25937. return !(i & 1);
  25938. }
  25939. /**
  25940. * Rebuilds the char code to glyph ID map by trying to replace the char codes
  25941. * with their unicode value. It also moves char codes that are in known
  25942. * problematic locations.
  25943. * @return {Object} Two properties:
  25944. * 'toFontChar' - maps original char codes(the value that will be read
  25945. * from commands such as show text) to the char codes that will be used in the
  25946. * font that we build
  25947. * 'charCodeToGlyphId' - maps the new font char codes to glyph ids
  25948. */
  25949. function adjustMapping(charCodeToGlyphId, properties) {
  25950. var toUnicode = properties.toUnicode;
  25951. var isSymbolic = !!(properties.flags & FontFlags.Symbolic);
  25952. var isIdentityUnicode =
  25953. properties.toUnicode instanceof IdentityToUnicodeMap;
  25954. var newMap = Object.create(null);
  25955. var toFontChar = [];
  25956. var usedFontCharCodes = [];
  25957. var nextAvailableFontCharCode = PRIVATE_USE_OFFSET_START;
  25958. for (var originalCharCode in charCodeToGlyphId) {
  25959. originalCharCode |= 0;
  25960. var glyphId = charCodeToGlyphId[originalCharCode];
  25961. var fontCharCode = originalCharCode;
  25962. // First try to map the value to a unicode position if a non identity map
  25963. // was created.
  25964. if (!isIdentityUnicode && toUnicode.has(originalCharCode)) {
  25965. var unicode = toUnicode.get(fontCharCode);
  25966. // TODO: Try to map ligatures to the correct spot.
  25967. if (unicode.length === 1) {
  25968. fontCharCode = unicode.charCodeAt(0);
  25969. }
  25970. }
  25971. // Try to move control characters, special characters and already mapped
  25972. // characters to the private use area since they will not be drawn by
  25973. // canvas if left in their current position. Also, move characters if the
  25974. // font was symbolic and there is only an identity unicode map since the
  25975. // characters probably aren't in the correct position (fixes an issue
  25976. // with firefox and thuluthfont).
  25977. if ((usedFontCharCodes[fontCharCode] !== undefined ||
  25978. isProblematicUnicodeLocation(fontCharCode) ||
  25979. (isSymbolic && isIdentityUnicode)) &&
  25980. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END) { // Room left.
  25981. // Loop to try and find a free spot in the private use area.
  25982. do {
  25983. fontCharCode = nextAvailableFontCharCode++;
  25984. if (SKIP_PRIVATE_USE_RANGE_F000_TO_F01F && fontCharCode === 0xF000) {
  25985. fontCharCode = 0xF020;
  25986. nextAvailableFontCharCode = fontCharCode + 1;
  25987. }
  25988. } while (usedFontCharCodes[fontCharCode] !== undefined &&
  25989. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END);
  25990. }
  25991. newMap[fontCharCode] = glyphId;
  25992. toFontChar[originalCharCode] = fontCharCode;
  25993. usedFontCharCodes[fontCharCode] = true;
  25994. }
  25995. return {
  25996. toFontChar: toFontChar,
  25997. charCodeToGlyphId: newMap,
  25998. nextAvailableFontCharCode: nextAvailableFontCharCode
  25999. };
  26000. }
  26001. function getRanges(glyphs, numGlyphs) {
  26002. // Array.sort() sorts by characters, not numerically, so convert to an
  26003. // array of characters.
  26004. var codes = [];
  26005. for (var charCode in glyphs) {
  26006. // Remove an invalid glyph ID mappings to make OTS happy.
  26007. if (glyphs[charCode] >= numGlyphs) {
  26008. continue;
  26009. }
  26010. codes.push({ fontCharCode: charCode | 0, glyphId: glyphs[charCode] });
  26011. }
  26012. codes.sort(function fontGetRangesSort(a, b) {
  26013. return a.fontCharCode - b.fontCharCode;
  26014. });
  26015. // Split the sorted codes into ranges.
  26016. var ranges = [];
  26017. var length = codes.length;
  26018. for (var n = 0; n < length; ) {
  26019. var start = codes[n].fontCharCode;
  26020. var codeIndices = [codes[n].glyphId];
  26021. ++n;
  26022. var end = start;
  26023. while (n < length && end + 1 === codes[n].fontCharCode) {
  26024. codeIndices.push(codes[n].glyphId);
  26025. ++end;
  26026. ++n;
  26027. if (end === 0xFFFF) {
  26028. break;
  26029. }
  26030. }
  26031. ranges.push([start, end, codeIndices]);
  26032. }
  26033. return ranges;
  26034. }
  26035. function createCmapTable(glyphs, numGlyphs) {
  26036. var ranges = getRanges(glyphs, numGlyphs);
  26037. var numTables = ranges[ranges.length - 1][1] > 0xFFFF ? 2 : 1;
  26038. var cmap = '\x00\x00' + // version
  26039. string16(numTables) + // numTables
  26040. '\x00\x03' + // platformID
  26041. '\x00\x01' + // encodingID
  26042. string32(4 + numTables * 8); // start of the table record
  26043. var i, ii, j, jj;
  26044. for (i = ranges.length - 1; i >= 0; --i) {
  26045. if (ranges[i][0] <= 0xFFFF) { break; }
  26046. }
  26047. var bmpLength = i + 1;
  26048. if (ranges[i][0] < 0xFFFF && ranges[i][1] === 0xFFFF) {
  26049. ranges[i][1] = 0xFFFE;
  26050. }
  26051. var trailingRangesCount = ranges[i][1] < 0xFFFF ? 1 : 0;
  26052. var segCount = bmpLength + trailingRangesCount;
  26053. var searchParams = OpenTypeFileBuilder.getSearchParams(segCount, 2);
  26054. // Fill up the 4 parallel arrays describing the segments.
  26055. var startCount = '';
  26056. var endCount = '';
  26057. var idDeltas = '';
  26058. var idRangeOffsets = '';
  26059. var glyphsIds = '';
  26060. var bias = 0;
  26061. var range, start, end, codes;
  26062. for (i = 0, ii = bmpLength; i < ii; i++) {
  26063. range = ranges[i];
  26064. start = range[0];
  26065. end = range[1];
  26066. startCount += string16(start);
  26067. endCount += string16(end);
  26068. codes = range[2];
  26069. var contiguous = true;
  26070. for (j = 1, jj = codes.length; j < jj; ++j) {
  26071. if (codes[j] !== codes[j - 1] + 1) {
  26072. contiguous = false;
  26073. break;
  26074. }
  26075. }
  26076. if (!contiguous) {
  26077. var offset = (segCount - i) * 2 + bias * 2;
  26078. bias += (end - start + 1);
  26079. idDeltas += string16(0);
  26080. idRangeOffsets += string16(offset);
  26081. for (j = 0, jj = codes.length; j < jj; ++j) {
  26082. glyphsIds += string16(codes[j]);
  26083. }
  26084. } else {
  26085. var startCode = codes[0];
  26086. idDeltas += string16((startCode - start) & 0xFFFF);
  26087. idRangeOffsets += string16(0);
  26088. }
  26089. }
  26090. if (trailingRangesCount > 0) {
  26091. endCount += '\xFF\xFF';
  26092. startCount += '\xFF\xFF';
  26093. idDeltas += '\x00\x01';
  26094. idRangeOffsets += '\x00\x00';
  26095. }
  26096. var format314 = '\x00\x00' + // language
  26097. string16(2 * segCount) +
  26098. string16(searchParams.range) +
  26099. string16(searchParams.entry) +
  26100. string16(searchParams.rangeShift) +
  26101. endCount + '\x00\x00' + startCount +
  26102. idDeltas + idRangeOffsets + glyphsIds;
  26103. var format31012 = '';
  26104. var header31012 = '';
  26105. if (numTables > 1) {
  26106. cmap += '\x00\x03' + // platformID
  26107. '\x00\x0A' + // encodingID
  26108. string32(4 + numTables * 8 +
  26109. 4 + format314.length); // start of the table record
  26110. format31012 = '';
  26111. for (i = 0, ii = ranges.length; i < ii; i++) {
  26112. range = ranges[i];
  26113. start = range[0];
  26114. codes = range[2];
  26115. var code = codes[0];
  26116. for (j = 1, jj = codes.length; j < jj; ++j) {
  26117. if (codes[j] !== codes[j - 1] + 1) {
  26118. end = range[0] + j - 1;
  26119. format31012 += string32(start) + // startCharCode
  26120. string32(end) + // endCharCode
  26121. string32(code); // startGlyphID
  26122. start = end + 1;
  26123. code = codes[j];
  26124. }
  26125. }
  26126. format31012 += string32(start) + // startCharCode
  26127. string32(range[1]) + // endCharCode
  26128. string32(code); // startGlyphID
  26129. }
  26130. header31012 = '\x00\x0C' + // format
  26131. '\x00\x00' + // reserved
  26132. string32(format31012.length + 16) + // length
  26133. '\x00\x00\x00\x00' + // language
  26134. string32(format31012.length / 12); // nGroups
  26135. }
  26136. return cmap + '\x00\x04' + // format
  26137. string16(format314.length + 4) + // length
  26138. format314 + header31012 + format31012;
  26139. }
  26140. function validateOS2Table(os2) {
  26141. var stream = new Stream(os2.data);
  26142. var version = stream.getUint16();
  26143. // TODO verify all OS/2 tables fields, but currently we validate only those
  26144. // that give us issues
  26145. stream.getBytes(60); // skipping type, misc sizes, panose, unicode ranges
  26146. var selection = stream.getUint16();
  26147. if (version < 4 && (selection & 0x0300)) {
  26148. return false;
  26149. }
  26150. var firstChar = stream.getUint16();
  26151. var lastChar = stream.getUint16();
  26152. if (firstChar > lastChar) {
  26153. return false;
  26154. }
  26155. stream.getBytes(6); // skipping sTypoAscender/Descender/LineGap
  26156. var usWinAscent = stream.getUint16();
  26157. if (usWinAscent === 0) { // makes font unreadable by windows
  26158. return false;
  26159. }
  26160. // OS/2 appears to be valid, resetting some fields
  26161. os2.data[8] = os2.data[9] = 0; // IE rejects fonts if fsType != 0
  26162. return true;
  26163. }
  26164. function createOS2Table(properties, charstrings, override) {
  26165. override = override || {
  26166. unitsPerEm: 0,
  26167. yMax: 0,
  26168. yMin: 0,
  26169. ascent: 0,
  26170. descent: 0
  26171. };
  26172. var ulUnicodeRange1 = 0;
  26173. var ulUnicodeRange2 = 0;
  26174. var ulUnicodeRange3 = 0;
  26175. var ulUnicodeRange4 = 0;
  26176. var firstCharIndex = null;
  26177. var lastCharIndex = 0;
  26178. if (charstrings) {
  26179. for (var code in charstrings) {
  26180. code |= 0;
  26181. if (firstCharIndex > code || !firstCharIndex) {
  26182. firstCharIndex = code;
  26183. }
  26184. if (lastCharIndex < code) {
  26185. lastCharIndex = code;
  26186. }
  26187. var position = getUnicodeRangeFor(code);
  26188. if (position < 32) {
  26189. ulUnicodeRange1 |= 1 << position;
  26190. } else if (position < 64) {
  26191. ulUnicodeRange2 |= 1 << position - 32;
  26192. } else if (position < 96) {
  26193. ulUnicodeRange3 |= 1 << position - 64;
  26194. } else if (position < 123) {
  26195. ulUnicodeRange4 |= 1 << position - 96;
  26196. } else {
  26197. error('Unicode ranges Bits > 123 are reserved for internal usage');
  26198. }
  26199. }
  26200. } else {
  26201. // TODO
  26202. firstCharIndex = 0;
  26203. lastCharIndex = 255;
  26204. }
  26205. var bbox = properties.bbox || [0, 0, 0, 0];
  26206. var unitsPerEm = (override.unitsPerEm ||
  26207. 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0]);
  26208. // if the font units differ to the PDF glyph space units
  26209. // then scale up the values
  26210. var scale = (properties.ascentScaled ? 1.0 :
  26211. unitsPerEm / PDF_GLYPH_SPACE_UNITS);
  26212. var typoAscent = (override.ascent ||
  26213. Math.round(scale * (properties.ascent || bbox[3])));
  26214. var typoDescent = (override.descent ||
  26215. Math.round(scale * (properties.descent || bbox[1])));
  26216. if (typoDescent > 0 && properties.descent > 0 && bbox[1] < 0) {
  26217. typoDescent = -typoDescent; // fixing incorrect descent
  26218. }
  26219. var winAscent = override.yMax || typoAscent;
  26220. var winDescent = -override.yMin || -typoDescent;
  26221. return '\x00\x03' + // version
  26222. '\x02\x24' + // xAvgCharWidth
  26223. '\x01\xF4' + // usWeightClass
  26224. '\x00\x05' + // usWidthClass
  26225. '\x00\x00' + // fstype (0 to let the font loads via font-face on IE)
  26226. '\x02\x8A' + // ySubscriptXSize
  26227. '\x02\xBB' + // ySubscriptYSize
  26228. '\x00\x00' + // ySubscriptXOffset
  26229. '\x00\x8C' + // ySubscriptYOffset
  26230. '\x02\x8A' + // ySuperScriptXSize
  26231. '\x02\xBB' + // ySuperScriptYSize
  26232. '\x00\x00' + // ySuperScriptXOffset
  26233. '\x01\xDF' + // ySuperScriptYOffset
  26234. '\x00\x31' + // yStrikeOutSize
  26235. '\x01\x02' + // yStrikeOutPosition
  26236. '\x00\x00' + // sFamilyClass
  26237. '\x00\x00\x06' +
  26238. String.fromCharCode(properties.fixedPitch ? 0x09 : 0x00) +
  26239. '\x00\x00\x00\x00\x00\x00' + // Panose
  26240. string32(ulUnicodeRange1) + // ulUnicodeRange1 (Bits 0-31)
  26241. string32(ulUnicodeRange2) + // ulUnicodeRange2 (Bits 32-63)
  26242. string32(ulUnicodeRange3) + // ulUnicodeRange3 (Bits 64-95)
  26243. string32(ulUnicodeRange4) + // ulUnicodeRange4 (Bits 96-127)
  26244. '\x2A\x32\x31\x2A' + // achVendID
  26245. string16(properties.italicAngle ? 1 : 0) + // fsSelection
  26246. string16(firstCharIndex ||
  26247. properties.firstChar) + // usFirstCharIndex
  26248. string16(lastCharIndex || properties.lastChar) + // usLastCharIndex
  26249. string16(typoAscent) + // sTypoAscender
  26250. string16(typoDescent) + // sTypoDescender
  26251. '\x00\x64' + // sTypoLineGap (7%-10% of the unitsPerEM value)
  26252. string16(winAscent) + // usWinAscent
  26253. string16(winDescent) + // usWinDescent
  26254. '\x00\x00\x00\x00' + // ulCodePageRange1 (Bits 0-31)
  26255. '\x00\x00\x00\x00' + // ulCodePageRange2 (Bits 32-63)
  26256. string16(properties.xHeight) + // sxHeight
  26257. string16(properties.capHeight) + // sCapHeight
  26258. string16(0) + // usDefaultChar
  26259. string16(firstCharIndex || properties.firstChar) + // usBreakChar
  26260. '\x00\x03'; // usMaxContext
  26261. }
  26262. function createPostTable(properties) {
  26263. var angle = Math.floor(properties.italicAngle * (Math.pow(2, 16)));
  26264. return ('\x00\x03\x00\x00' + // Version number
  26265. string32(angle) + // italicAngle
  26266. '\x00\x00' + // underlinePosition
  26267. '\x00\x00' + // underlineThickness
  26268. string32(properties.fixedPitch) + // isFixedPitch
  26269. '\x00\x00\x00\x00' + // minMemType42
  26270. '\x00\x00\x00\x00' + // maxMemType42
  26271. '\x00\x00\x00\x00' + // minMemType1
  26272. '\x00\x00\x00\x00'); // maxMemType1
  26273. }
  26274. function createNameTable(name, proto) {
  26275. if (!proto) {
  26276. proto = [[], []]; // no strings and unicode strings
  26277. }
  26278. var strings = [
  26279. proto[0][0] || 'Original licence', // 0.Copyright
  26280. proto[0][1] || name, // 1.Font family
  26281. proto[0][2] || 'Unknown', // 2.Font subfamily (font weight)
  26282. proto[0][3] || 'uniqueID', // 3.Unique ID
  26283. proto[0][4] || name, // 4.Full font name
  26284. proto[0][5] || 'Version 0.11', // 5.Version
  26285. proto[0][6] || '', // 6.Postscript name
  26286. proto[0][7] || 'Unknown', // 7.Trademark
  26287. proto[0][8] || 'Unknown', // 8.Manufacturer
  26288. proto[0][9] || 'Unknown' // 9.Designer
  26289. ];
  26290. // Mac want 1-byte per character strings while Windows want
  26291. // 2-bytes per character, so duplicate the names table
  26292. var stringsUnicode = [];
  26293. var i, ii, j, jj, str;
  26294. for (i = 0, ii = strings.length; i < ii; i++) {
  26295. str = proto[1][i] || strings[i];
  26296. var strBufUnicode = [];
  26297. for (j = 0, jj = str.length; j < jj; j++) {
  26298. strBufUnicode.push(string16(str.charCodeAt(j)));
  26299. }
  26300. stringsUnicode.push(strBufUnicode.join(''));
  26301. }
  26302. var names = [strings, stringsUnicode];
  26303. var platforms = ['\x00\x01', '\x00\x03'];
  26304. var encodings = ['\x00\x00', '\x00\x01'];
  26305. var languages = ['\x00\x00', '\x04\x09'];
  26306. var namesRecordCount = strings.length * platforms.length;
  26307. var nameTable =
  26308. '\x00\x00' + // format
  26309. string16(namesRecordCount) + // Number of names Record
  26310. string16(namesRecordCount * 12 + 6); // Storage
  26311. // Build the name records field
  26312. var strOffset = 0;
  26313. for (i = 0, ii = platforms.length; i < ii; i++) {
  26314. var strs = names[i];
  26315. for (j = 0, jj = strs.length; j < jj; j++) {
  26316. str = strs[j];
  26317. var nameRecord =
  26318. platforms[i] + // platform ID
  26319. encodings[i] + // encoding ID
  26320. languages[i] + // language ID
  26321. string16(j) + // name ID
  26322. string16(str.length) +
  26323. string16(strOffset);
  26324. nameTable += nameRecord;
  26325. strOffset += str.length;
  26326. }
  26327. }
  26328. nameTable += strings.join('') + stringsUnicode.join('');
  26329. return nameTable;
  26330. }
  26331. Font.prototype = {
  26332. name: null,
  26333. font: null,
  26334. mimetype: null,
  26335. encoding: null,
  26336. get renderer() {
  26337. var renderer = FontRendererFactory.create(this);
  26338. return shadow(this, 'renderer', renderer);
  26339. },
  26340. exportData: function Font_exportData() {
  26341. var data = {};
  26342. for (var i in this) {
  26343. if (this.hasOwnProperty(i)) {
  26344. data[i] = this[i];
  26345. }
  26346. }
  26347. return data;
  26348. },
  26349. checkAndRepair: function Font_checkAndRepair(name, font, properties) {
  26350. function readTableEntry(file) {
  26351. var tag = bytesToString(file.getBytes(4));
  26352. var checksum = file.getInt32();
  26353. var offset = file.getInt32() >>> 0;
  26354. var length = file.getInt32() >>> 0;
  26355. // Read the table associated data
  26356. var previousPosition = file.pos;
  26357. file.pos = file.start ? file.start : 0;
  26358. file.skip(offset);
  26359. var data = file.getBytes(length);
  26360. file.pos = previousPosition;
  26361. if (tag === 'head') {
  26362. // clearing checksum adjustment
  26363. data[8] = data[9] = data[10] = data[11] = 0;
  26364. data[17] |= 0x20; //Set font optimized for cleartype flag
  26365. }
  26366. return {
  26367. tag: tag,
  26368. checksum: checksum,
  26369. length: length,
  26370. offset: offset,
  26371. data: data
  26372. };
  26373. }
  26374. function readOpenTypeHeader(ttf) {
  26375. return {
  26376. version: bytesToString(ttf.getBytes(4)),
  26377. numTables: ttf.getUint16(),
  26378. searchRange: ttf.getUint16(),
  26379. entrySelector: ttf.getUint16(),
  26380. rangeShift: ttf.getUint16()
  26381. };
  26382. }
  26383. /**
  26384. * Read the appropriate subtable from the cmap according to 9.6.6.4 from
  26385. * PDF spec
  26386. */
  26387. function readCmapTable(cmap, font, isSymbolicFont, hasEncoding) {
  26388. if (!cmap) {
  26389. warn('No cmap table available.');
  26390. return {
  26391. platformId: -1,
  26392. encodingId: -1,
  26393. mappings: [],
  26394. hasShortCmap: false
  26395. };
  26396. }
  26397. var segment;
  26398. var start = (font.start ? font.start : 0) + cmap.offset;
  26399. font.pos = start;
  26400. var version = font.getUint16();
  26401. var numTables = font.getUint16();
  26402. var potentialTable;
  26403. var canBreak = false;
  26404. // There's an order of preference in terms of which cmap subtable to
  26405. // use:
  26406. // - non-symbolic fonts the preference is a 3,1 table then a 1,0 table
  26407. // - symbolic fonts the preference is a 3,0 table then a 1,0 table
  26408. // The following takes advantage of the fact that the tables are sorted
  26409. // to work.
  26410. for (var i = 0; i < numTables; i++) {
  26411. var platformId = font.getUint16();
  26412. var encodingId = font.getUint16();
  26413. var offset = font.getInt32() >>> 0;
  26414. var useTable = false;
  26415. if (platformId === 0 && encodingId === 0) {
  26416. useTable = true;
  26417. // Continue the loop since there still may be a higher priority
  26418. // table.
  26419. } else if (platformId === 1 && encodingId === 0) {
  26420. useTable = true;
  26421. // Continue the loop since there still may be a higher priority
  26422. // table.
  26423. } else if (platformId === 3 && encodingId === 1 &&
  26424. ((!isSymbolicFont && hasEncoding) || !potentialTable)) {
  26425. useTable = true;
  26426. if (!isSymbolicFont) {
  26427. canBreak = true;
  26428. }
  26429. } else if (isSymbolicFont && platformId === 3 && encodingId === 0) {
  26430. useTable = true;
  26431. canBreak = true;
  26432. }
  26433. if (useTable) {
  26434. potentialTable = {
  26435. platformId: platformId,
  26436. encodingId: encodingId,
  26437. offset: offset
  26438. };
  26439. }
  26440. if (canBreak) {
  26441. break;
  26442. }
  26443. }
  26444. if (potentialTable) {
  26445. font.pos = start + potentialTable.offset;
  26446. }
  26447. if (!potentialTable || font.peekByte() === -1) {
  26448. warn('Could not find a preferred cmap table.');
  26449. return {
  26450. platformId: -1,
  26451. encodingId: -1,
  26452. mappings: [],
  26453. hasShortCmap: false
  26454. };
  26455. }
  26456. var format = font.getUint16();
  26457. var length = font.getUint16();
  26458. var language = font.getUint16();
  26459. var hasShortCmap = false;
  26460. var mappings = [];
  26461. var j, glyphId;
  26462. // TODO(mack): refactor this cmap subtable reading logic out
  26463. if (format === 0) {
  26464. for (j = 0; j < 256; j++) {
  26465. var index = font.getByte();
  26466. if (!index) {
  26467. continue;
  26468. }
  26469. mappings.push({
  26470. charCode: j,
  26471. glyphId: index
  26472. });
  26473. }
  26474. hasShortCmap = true;
  26475. } else if (format === 4) {
  26476. // re-creating the table in format 4 since the encoding
  26477. // might be changed
  26478. var segCount = (font.getUint16() >> 1);
  26479. font.getBytes(6); // skipping range fields
  26480. var segIndex, segments = [];
  26481. for (segIndex = 0; segIndex < segCount; segIndex++) {
  26482. segments.push({ end: font.getUint16() });
  26483. }
  26484. font.getUint16();
  26485. for (segIndex = 0; segIndex < segCount; segIndex++) {
  26486. segments[segIndex].start = font.getUint16();
  26487. }
  26488. for (segIndex = 0; segIndex < segCount; segIndex++) {
  26489. segments[segIndex].delta = font.getUint16();
  26490. }
  26491. var offsetsCount = 0;
  26492. for (segIndex = 0; segIndex < segCount; segIndex++) {
  26493. segment = segments[segIndex];
  26494. var rangeOffset = font.getUint16();
  26495. if (!rangeOffset) {
  26496. segment.offsetIndex = -1;
  26497. continue;
  26498. }
  26499. var offsetIndex = (rangeOffset >> 1) - (segCount - segIndex);
  26500. segment.offsetIndex = offsetIndex;
  26501. offsetsCount = Math.max(offsetsCount, offsetIndex +
  26502. segment.end - segment.start + 1);
  26503. }
  26504. var offsets = [];
  26505. for (j = 0; j < offsetsCount; j++) {
  26506. offsets.push(font.getUint16());
  26507. }
  26508. for (segIndex = 0; segIndex < segCount; segIndex++) {
  26509. segment = segments[segIndex];
  26510. start = segment.start;
  26511. var end = segment.end;
  26512. var delta = segment.delta;
  26513. offsetIndex = segment.offsetIndex;
  26514. for (j = start; j <= end; j++) {
  26515. if (j === 0xFFFF) {
  26516. continue;
  26517. }
  26518. glyphId = (offsetIndex < 0 ?
  26519. j : offsets[offsetIndex + j - start]);
  26520. glyphId = (glyphId + delta) & 0xFFFF;
  26521. if (glyphId === 0) {
  26522. continue;
  26523. }
  26524. mappings.push({
  26525. charCode: j,
  26526. glyphId: glyphId
  26527. });
  26528. }
  26529. }
  26530. } else if (format === 6) {
  26531. // Format 6 is a 2-bytes dense mapping, which means the font data
  26532. // lives glue together even if they are pretty far in the unicode
  26533. // table. (This looks weird, so I can have missed something), this
  26534. // works on Linux but seems to fails on Mac so let's rewrite the
  26535. // cmap table to a 3-1-4 style
  26536. var firstCode = font.getUint16();
  26537. var entryCount = font.getUint16();
  26538. for (j = 0; j < entryCount; j++) {
  26539. glyphId = font.getUint16();
  26540. var charCode = firstCode + j;
  26541. mappings.push({
  26542. charCode: charCode,
  26543. glyphId: glyphId
  26544. });
  26545. }
  26546. } else {
  26547. warn('cmap table has unsupported format: ' + format);
  26548. return {
  26549. platformId: -1,
  26550. encodingId: -1,
  26551. mappings: [],
  26552. hasShortCmap: false
  26553. };
  26554. }
  26555. // removing duplicate entries
  26556. mappings.sort(function (a, b) {
  26557. return a.charCode - b.charCode;
  26558. });
  26559. for (i = 1; i < mappings.length; i++) {
  26560. if (mappings[i - 1].charCode === mappings[i].charCode) {
  26561. mappings.splice(i, 1);
  26562. i--;
  26563. }
  26564. }
  26565. return {
  26566. platformId: potentialTable.platformId,
  26567. encodingId: potentialTable.encodingId,
  26568. mappings: mappings,
  26569. hasShortCmap: hasShortCmap
  26570. };
  26571. }
  26572. function sanitizeMetrics(font, header, metrics, numGlyphs) {
  26573. if (!header) {
  26574. if (metrics) {
  26575. metrics.data = null;
  26576. }
  26577. return;
  26578. }
  26579. font.pos = (font.start ? font.start : 0) + header.offset;
  26580. font.pos += header.length - 2;
  26581. var numOfMetrics = font.getUint16();
  26582. if (numOfMetrics > numGlyphs) {
  26583. info('The numOfMetrics (' + numOfMetrics + ') should not be ' +
  26584. 'greater than the numGlyphs (' + numGlyphs + ')');
  26585. // Reduce numOfMetrics if it is greater than numGlyphs
  26586. numOfMetrics = numGlyphs;
  26587. header.data[34] = (numOfMetrics & 0xff00) >> 8;
  26588. header.data[35] = numOfMetrics & 0x00ff;
  26589. }
  26590. var numOfSidebearings = numGlyphs - numOfMetrics;
  26591. var numMissing = numOfSidebearings -
  26592. ((metrics.length - numOfMetrics * 4) >> 1);
  26593. if (numMissing > 0) {
  26594. // For each missing glyph, we set both the width and lsb to 0 (zero).
  26595. // Since we need to add two properties for each glyph, this explains
  26596. // the use of |numMissing * 2| when initializing the typed array.
  26597. var entries = new Uint8Array(metrics.length + numMissing * 2);
  26598. entries.set(metrics.data);
  26599. metrics.data = entries;
  26600. }
  26601. }
  26602. function sanitizeGlyph(source, sourceStart, sourceEnd, dest, destStart,
  26603. hintsValid) {
  26604. if (sourceEnd - sourceStart <= 12) {
  26605. // glyph with data less than 12 is invalid one
  26606. return 0;
  26607. }
  26608. var glyf = source.subarray(sourceStart, sourceEnd);
  26609. var contoursCount = (glyf[0] << 8) | glyf[1];
  26610. if (contoursCount & 0x8000) {
  26611. // complex glyph, writing as is
  26612. dest.set(glyf, destStart);
  26613. return glyf.length;
  26614. }
  26615. var i, j = 10, flagsCount = 0;
  26616. for (i = 0; i < contoursCount; i++) {
  26617. var endPoint = (glyf[j] << 8) | glyf[j + 1];
  26618. flagsCount = endPoint + 1;
  26619. j += 2;
  26620. }
  26621. // skipping instructions
  26622. var instructionsStart = j;
  26623. var instructionsLength = (glyf[j] << 8) | glyf[j + 1];
  26624. j += 2 + instructionsLength;
  26625. var instructionsEnd = j;
  26626. // validating flags
  26627. var coordinatesLength = 0;
  26628. for (i = 0; i < flagsCount; i++) {
  26629. var flag = glyf[j++];
  26630. if (flag & 0xC0) {
  26631. // reserved flags must be zero, cleaning up
  26632. glyf[j - 1] = flag & 0x3F;
  26633. }
  26634. var xyLength = ((flag & 2) ? 1 : (flag & 16) ? 0 : 2) +
  26635. ((flag & 4) ? 1 : (flag & 32) ? 0 : 2);
  26636. coordinatesLength += xyLength;
  26637. if (flag & 8) {
  26638. var repeat = glyf[j++];
  26639. i += repeat;
  26640. coordinatesLength += repeat * xyLength;
  26641. }
  26642. }
  26643. // glyph without coordinates will be rejected
  26644. if (coordinatesLength === 0) {
  26645. return 0;
  26646. }
  26647. var glyphDataLength = j + coordinatesLength;
  26648. if (glyphDataLength > glyf.length) {
  26649. // not enough data for coordinates
  26650. return 0;
  26651. }
  26652. if (!hintsValid && instructionsLength > 0) {
  26653. dest.set(glyf.subarray(0, instructionsStart), destStart);
  26654. dest.set([0, 0], destStart + instructionsStart);
  26655. dest.set(glyf.subarray(instructionsEnd, glyphDataLength),
  26656. destStart + instructionsStart + 2);
  26657. glyphDataLength -= instructionsLength;
  26658. if (glyf.length - glyphDataLength > 3) {
  26659. glyphDataLength = (glyphDataLength + 3) & ~3;
  26660. }
  26661. return glyphDataLength;
  26662. }
  26663. if (glyf.length - glyphDataLength > 3) {
  26664. // truncating and aligning to 4 bytes the long glyph data
  26665. glyphDataLength = (glyphDataLength + 3) & ~3;
  26666. dest.set(glyf.subarray(0, glyphDataLength), destStart);
  26667. return glyphDataLength;
  26668. }
  26669. // glyph data is fine
  26670. dest.set(glyf, destStart);
  26671. return glyf.length;
  26672. }
  26673. function sanitizeHead(head, numGlyphs, locaLength) {
  26674. var data = head.data;
  26675. // Validate version:
  26676. // Should always be 0x00010000
  26677. var version = int32(data[0], data[1], data[2], data[3]);
  26678. if (version >> 16 !== 1) {
  26679. info('Attempting to fix invalid version in head table: ' + version);
  26680. data[0] = 0;
  26681. data[1] = 1;
  26682. data[2] = 0;
  26683. data[3] = 0;
  26684. }
  26685. var indexToLocFormat = int16(data[50], data[51]);
  26686. if (indexToLocFormat < 0 || indexToLocFormat > 1) {
  26687. info('Attempting to fix invalid indexToLocFormat in head table: ' +
  26688. indexToLocFormat);
  26689. // The value of indexToLocFormat should be 0 if the loca table
  26690. // consists of short offsets, and should be 1 if the loca table
  26691. // consists of long offsets.
  26692. //
  26693. // The number of entries in the loca table should be numGlyphs + 1.
  26694. //
  26695. // Using this information, we can work backwards to deduce if the
  26696. // size of each offset in the loca table, and thus figure out the
  26697. // appropriate value for indexToLocFormat.
  26698. var numGlyphsPlusOne = numGlyphs + 1;
  26699. if (locaLength === numGlyphsPlusOne << 1) {
  26700. // 0x0000 indicates the loca table consists of short offsets
  26701. data[50] = 0;
  26702. data[51] = 0;
  26703. } else if (locaLength === numGlyphsPlusOne << 2) {
  26704. // 0x0001 indicates the loca table consists of long offsets
  26705. data[50] = 0;
  26706. data[51] = 1;
  26707. } else {
  26708. warn('Could not fix indexToLocFormat: ' + indexToLocFormat);
  26709. }
  26710. }
  26711. }
  26712. function sanitizeGlyphLocations(loca, glyf, numGlyphs,
  26713. isGlyphLocationsLong, hintsValid,
  26714. dupFirstEntry) {
  26715. var itemSize, itemDecode, itemEncode;
  26716. if (isGlyphLocationsLong) {
  26717. itemSize = 4;
  26718. itemDecode = function fontItemDecodeLong(data, offset) {
  26719. return (data[offset] << 24) | (data[offset + 1] << 16) |
  26720. (data[offset + 2] << 8) | data[offset + 3];
  26721. };
  26722. itemEncode = function fontItemEncodeLong(data, offset, value) {
  26723. data[offset] = (value >>> 24) & 0xFF;
  26724. data[offset + 1] = (value >> 16) & 0xFF;
  26725. data[offset + 2] = (value >> 8) & 0xFF;
  26726. data[offset + 3] = value & 0xFF;
  26727. };
  26728. } else {
  26729. itemSize = 2;
  26730. itemDecode = function fontItemDecode(data, offset) {
  26731. return (data[offset] << 9) | (data[offset + 1] << 1);
  26732. };
  26733. itemEncode = function fontItemEncode(data, offset, value) {
  26734. data[offset] = (value >> 9) & 0xFF;
  26735. data[offset + 1] = (value >> 1) & 0xFF;
  26736. };
  26737. }
  26738. var locaData = loca.data;
  26739. var locaDataSize = itemSize * (1 + numGlyphs);
  26740. // is loca.data too short or long?
  26741. if (locaData.length !== locaDataSize) {
  26742. locaData = new Uint8Array(locaDataSize);
  26743. locaData.set(loca.data.subarray(0, locaDataSize));
  26744. loca.data = locaData;
  26745. }
  26746. // removing the invalid glyphs
  26747. var oldGlyfData = glyf.data;
  26748. var oldGlyfDataLength = oldGlyfData.length;
  26749. var newGlyfData = new Uint8Array(oldGlyfDataLength);
  26750. var startOffset = itemDecode(locaData, 0);
  26751. var writeOffset = 0;
  26752. var missingGlyphData = {};
  26753. itemEncode(locaData, 0, writeOffset);
  26754. var i, j;
  26755. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  26756. var endOffset = itemDecode(locaData, j);
  26757. if (endOffset > oldGlyfDataLength &&
  26758. ((oldGlyfDataLength + 3) & ~3) === endOffset) {
  26759. // Aspose breaks fonts by aligning the glyphs to the qword, but not
  26760. // the glyf table size, which makes last glyph out of range.
  26761. endOffset = oldGlyfDataLength;
  26762. }
  26763. if (endOffset > oldGlyfDataLength) {
  26764. // glyph end offset points outside glyf data, rejecting the glyph
  26765. itemEncode(locaData, j, writeOffset);
  26766. startOffset = endOffset;
  26767. continue;
  26768. }
  26769. if (startOffset === endOffset) {
  26770. missingGlyphData[i] = true;
  26771. }
  26772. var newLength = sanitizeGlyph(oldGlyfData, startOffset, endOffset,
  26773. newGlyfData, writeOffset, hintsValid);
  26774. writeOffset += newLength;
  26775. itemEncode(locaData, j, writeOffset);
  26776. startOffset = endOffset;
  26777. }
  26778. if (writeOffset === 0) {
  26779. // glyf table cannot be empty -- redoing the glyf and loca tables
  26780. // to have single glyph with one point
  26781. var simpleGlyph = new Uint8Array(
  26782. [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 49, 0]);
  26783. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  26784. itemEncode(locaData, j, simpleGlyph.length);
  26785. }
  26786. glyf.data = simpleGlyph;
  26787. return missingGlyphData;
  26788. }
  26789. if (dupFirstEntry) {
  26790. var firstEntryLength = itemDecode(locaData, itemSize);
  26791. if (newGlyfData.length > firstEntryLength + writeOffset) {
  26792. glyf.data = newGlyfData.subarray(0, firstEntryLength + writeOffset);
  26793. } else {
  26794. glyf.data = new Uint8Array(firstEntryLength + writeOffset);
  26795. glyf.data.set(newGlyfData.subarray(0, writeOffset));
  26796. }
  26797. glyf.data.set(newGlyfData.subarray(0, firstEntryLength), writeOffset);
  26798. itemEncode(loca.data, locaData.length - itemSize,
  26799. writeOffset + firstEntryLength);
  26800. } else {
  26801. glyf.data = newGlyfData.subarray(0, writeOffset);
  26802. }
  26803. return missingGlyphData;
  26804. }
  26805. function readPostScriptTable(post, properties, maxpNumGlyphs) {
  26806. var start = (font.start ? font.start : 0) + post.offset;
  26807. font.pos = start;
  26808. var length = post.length, end = start + length;
  26809. var version = font.getInt32();
  26810. // skip rest to the tables
  26811. font.getBytes(28);
  26812. var glyphNames;
  26813. var valid = true;
  26814. var i;
  26815. switch (version) {
  26816. case 0x00010000:
  26817. glyphNames = MacStandardGlyphOrdering;
  26818. break;
  26819. case 0x00020000:
  26820. var numGlyphs = font.getUint16();
  26821. if (numGlyphs !== maxpNumGlyphs) {
  26822. valid = false;
  26823. break;
  26824. }
  26825. var glyphNameIndexes = [];
  26826. for (i = 0; i < numGlyphs; ++i) {
  26827. var index = font.getUint16();
  26828. if (index >= 32768) {
  26829. valid = false;
  26830. break;
  26831. }
  26832. glyphNameIndexes.push(index);
  26833. }
  26834. if (!valid) {
  26835. break;
  26836. }
  26837. var customNames = [];
  26838. var strBuf = [];
  26839. while (font.pos < end) {
  26840. var stringLength = font.getByte();
  26841. strBuf.length = stringLength;
  26842. for (i = 0; i < stringLength; ++i) {
  26843. strBuf[i] = String.fromCharCode(font.getByte());
  26844. }
  26845. customNames.push(strBuf.join(''));
  26846. }
  26847. glyphNames = [];
  26848. for (i = 0; i < numGlyphs; ++i) {
  26849. var j = glyphNameIndexes[i];
  26850. if (j < 258) {
  26851. glyphNames.push(MacStandardGlyphOrdering[j]);
  26852. continue;
  26853. }
  26854. glyphNames.push(customNames[j - 258]);
  26855. }
  26856. break;
  26857. case 0x00030000:
  26858. break;
  26859. default:
  26860. warn('Unknown/unsupported post table version ' + version);
  26861. valid = false;
  26862. if (properties.defaultEncoding) {
  26863. glyphNames = properties.defaultEncoding;
  26864. }
  26865. break;
  26866. }
  26867. properties.glyphNames = glyphNames;
  26868. return valid;
  26869. }
  26870. function readNameTable(nameTable) {
  26871. var start = (font.start ? font.start : 0) + nameTable.offset;
  26872. font.pos = start;
  26873. var names = [[], []];
  26874. var length = nameTable.length, end = start + length;
  26875. var format = font.getUint16();
  26876. var FORMAT_0_HEADER_LENGTH = 6;
  26877. if (format !== 0 || length < FORMAT_0_HEADER_LENGTH) {
  26878. // unsupported name table format or table "too" small
  26879. return names;
  26880. }
  26881. var numRecords = font.getUint16();
  26882. var stringsStart = font.getUint16();
  26883. var records = [];
  26884. var NAME_RECORD_LENGTH = 12;
  26885. var i, ii;
  26886. for (i = 0; i < numRecords &&
  26887. font.pos + NAME_RECORD_LENGTH <= end; i++) {
  26888. var r = {
  26889. platform: font.getUint16(),
  26890. encoding: font.getUint16(),
  26891. language: font.getUint16(),
  26892. name: font.getUint16(),
  26893. length: font.getUint16(),
  26894. offset: font.getUint16()
  26895. };
  26896. // using only Macintosh and Windows platform/encoding names
  26897. if ((r.platform === 1 && r.encoding === 0 && r.language === 0) ||
  26898. (r.platform === 3 && r.encoding === 1 && r.language === 0x409)) {
  26899. records.push(r);
  26900. }
  26901. }
  26902. for (i = 0, ii = records.length; i < ii; i++) {
  26903. var record = records[i];
  26904. var pos = start + stringsStart + record.offset;
  26905. if (pos + record.length > end) {
  26906. continue; // outside of name table, ignoring
  26907. }
  26908. font.pos = pos;
  26909. var nameIndex = record.name;
  26910. if (record.encoding) {
  26911. // unicode
  26912. var str = '';
  26913. for (var j = 0, jj = record.length; j < jj; j += 2) {
  26914. str += String.fromCharCode(font.getUint16());
  26915. }
  26916. names[1][nameIndex] = str;
  26917. } else {
  26918. names[0][nameIndex] = bytesToString(font.getBytes(record.length));
  26919. }
  26920. }
  26921. return names;
  26922. }
  26923. var TTOpsStackDeltas = [
  26924. 0, 0, 0, 0, 0, 0, 0, 0, -2, -2, -2, -2, 0, 0, -2, -5,
  26925. -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, -1, -1,
  26926. 1, -1, -999, 0, 1, 0, -1, -2, 0, -1, -2, -1, -1, 0, -1, -1,
  26927. 0, 0, -999, -999, -1, -1, -1, -1, -2, -999, -2, -2, -999, 0, -2, -2,
  26928. 0, 0, -2, 0, -2, 0, 0, 0, -2, -1, -1, 1, 1, 0, 0, -1,
  26929. -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, 0, -999, -1, -1,
  26930. -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  26931. -2, -999, -999, -999, -999, -999, -1, -1, -2, -2, 0, 0, 0, 0, -1, -1,
  26932. -999, -2, -2, 0, 0, -1, -2, -2, 0, 0, 0, -1, -1, -1, -2];
  26933. // 0xC0-DF == -1 and 0xE0-FF == -2
  26934. function sanitizeTTProgram(table, ttContext) {
  26935. var data = table.data;
  26936. var i = 0, j, n, b, funcId, pc, lastEndf = 0, lastDeff = 0;
  26937. var stack = [];
  26938. var callstack = [];
  26939. var functionsCalled = [];
  26940. var tooComplexToFollowFunctions =
  26941. ttContext.tooComplexToFollowFunctions;
  26942. var inFDEF = false, ifLevel = 0, inELSE = 0;
  26943. for (var ii = data.length; i < ii;) {
  26944. var op = data[i++];
  26945. // The TrueType instruction set docs can be found at
  26946. // https://developer.apple.com/fonts/TTRefMan/RM05/Chap5.html
  26947. if (op === 0x40) { // NPUSHB - pushes n bytes
  26948. n = data[i++];
  26949. if (inFDEF || inELSE) {
  26950. i += n;
  26951. } else {
  26952. for (j = 0; j < n; j++) {
  26953. stack.push(data[i++]);
  26954. }
  26955. }
  26956. } else if (op === 0x41) { // NPUSHW - pushes n words
  26957. n = data[i++];
  26958. if (inFDEF || inELSE) {
  26959. i += n * 2;
  26960. } else {
  26961. for (j = 0; j < n; j++) {
  26962. b = data[i++];
  26963. stack.push((b << 8) | data[i++]);
  26964. }
  26965. }
  26966. } else if ((op & 0xF8) === 0xB0) { // PUSHB - pushes bytes
  26967. n = op - 0xB0 + 1;
  26968. if (inFDEF || inELSE) {
  26969. i += n;
  26970. } else {
  26971. for (j = 0; j < n; j++) {
  26972. stack.push(data[i++]);
  26973. }
  26974. }
  26975. } else if ((op & 0xF8) === 0xB8) { // PUSHW - pushes words
  26976. n = op - 0xB8 + 1;
  26977. if (inFDEF || inELSE) {
  26978. i += n * 2;
  26979. } else {
  26980. for (j = 0; j < n; j++) {
  26981. b = data[i++];
  26982. stack.push((b << 8) | data[i++]);
  26983. }
  26984. }
  26985. } else if (op === 0x2B && !tooComplexToFollowFunctions) { // CALL
  26986. if (!inFDEF && !inELSE) {
  26987. // collecting inforamtion about which functions are used
  26988. funcId = stack[stack.length - 1];
  26989. ttContext.functionsUsed[funcId] = true;
  26990. if (funcId in ttContext.functionsStackDeltas) {
  26991. stack.length += ttContext.functionsStackDeltas[funcId];
  26992. } else if (funcId in ttContext.functionsDefined &&
  26993. functionsCalled.indexOf(funcId) < 0) {
  26994. callstack.push({data: data, i: i, stackTop: stack.length - 1});
  26995. functionsCalled.push(funcId);
  26996. pc = ttContext.functionsDefined[funcId];
  26997. if (!pc) {
  26998. warn('TT: CALL non-existent function');
  26999. ttContext.hintsValid = false;
  27000. return;
  27001. }
  27002. data = pc.data;
  27003. i = pc.i;
  27004. }
  27005. }
  27006. } else if (op === 0x2C && !tooComplexToFollowFunctions) { // FDEF
  27007. if (inFDEF || inELSE) {
  27008. warn('TT: nested FDEFs not allowed');
  27009. tooComplexToFollowFunctions = true;
  27010. }
  27011. inFDEF = true;
  27012. // collecting inforamtion about which functions are defined
  27013. lastDeff = i;
  27014. funcId = stack.pop();
  27015. ttContext.functionsDefined[funcId] = {data: data, i: i};
  27016. } else if (op === 0x2D) { // ENDF - end of function
  27017. if (inFDEF) {
  27018. inFDEF = false;
  27019. lastEndf = i;
  27020. } else {
  27021. pc = callstack.pop();
  27022. if (!pc) {
  27023. warn('TT: ENDF bad stack');
  27024. ttContext.hintsValid = false;
  27025. return;
  27026. }
  27027. funcId = functionsCalled.pop();
  27028. data = pc.data;
  27029. i = pc.i;
  27030. ttContext.functionsStackDeltas[funcId] =
  27031. stack.length - pc.stackTop;
  27032. }
  27033. } else if (op === 0x89) { // IDEF - instruction definition
  27034. if (inFDEF || inELSE) {
  27035. warn('TT: nested IDEFs not allowed');
  27036. tooComplexToFollowFunctions = true;
  27037. }
  27038. inFDEF = true;
  27039. // recording it as a function to track ENDF
  27040. lastDeff = i;
  27041. } else if (op === 0x58) { // IF
  27042. ++ifLevel;
  27043. } else if (op === 0x1B) { // ELSE
  27044. inELSE = ifLevel;
  27045. } else if (op === 0x59) { // EIF
  27046. if (inELSE === ifLevel) {
  27047. inELSE = 0;
  27048. }
  27049. --ifLevel;
  27050. } else if (op === 0x1C) { // JMPR
  27051. if (!inFDEF && !inELSE) {
  27052. var offset = stack[stack.length - 1];
  27053. // only jumping forward to prevent infinite loop
  27054. if (offset > 0) {
  27055. i += offset - 1;
  27056. }
  27057. }
  27058. }
  27059. // Adjusting stack not extactly, but just enough to get function id
  27060. if (!inFDEF && !inELSE) {
  27061. var stackDelta = op <= 0x8E ? TTOpsStackDeltas[op] :
  27062. op >= 0xC0 && op <= 0xDF ? -1 : op >= 0xE0 ? -2 : 0;
  27063. if (op >= 0x71 && op <= 0x75) {
  27064. n = stack.pop();
  27065. if (n === n) {
  27066. stackDelta = -n * 2;
  27067. }
  27068. }
  27069. while (stackDelta < 0 && stack.length > 0) {
  27070. stack.pop();
  27071. stackDelta++;
  27072. }
  27073. while (stackDelta > 0) {
  27074. stack.push(NaN); // pushing any number into stack
  27075. stackDelta--;
  27076. }
  27077. }
  27078. }
  27079. ttContext.tooComplexToFollowFunctions = tooComplexToFollowFunctions;
  27080. var content = [data];
  27081. if (i > data.length) {
  27082. content.push(new Uint8Array(i - data.length));
  27083. }
  27084. if (lastDeff > lastEndf) {
  27085. warn('TT: complementing a missing function tail');
  27086. // new function definition started, but not finished
  27087. // complete function by [CLEAR, ENDF]
  27088. content.push(new Uint8Array([0x22, 0x2D]));
  27089. }
  27090. foldTTTable(table, content);
  27091. }
  27092. function checkInvalidFunctions(ttContext, maxFunctionDefs) {
  27093. if (ttContext.tooComplexToFollowFunctions) {
  27094. return;
  27095. }
  27096. if (ttContext.functionsDefined.length > maxFunctionDefs) {
  27097. warn('TT: more functions defined than expected');
  27098. ttContext.hintsValid = false;
  27099. return;
  27100. }
  27101. for (var j = 0, jj = ttContext.functionsUsed.length; j < jj; j++) {
  27102. if (j > maxFunctionDefs) {
  27103. warn('TT: invalid function id: ' + j);
  27104. ttContext.hintsValid = false;
  27105. return;
  27106. }
  27107. if (ttContext.functionsUsed[j] && !ttContext.functionsDefined[j]) {
  27108. warn('TT: undefined function: ' + j);
  27109. ttContext.hintsValid = false;
  27110. return;
  27111. }
  27112. }
  27113. }
  27114. function foldTTTable(table, content) {
  27115. if (content.length > 1) {
  27116. // concatenating the content items
  27117. var newLength = 0;
  27118. var j, jj;
  27119. for (j = 0, jj = content.length; j < jj; j++) {
  27120. newLength += content[j].length;
  27121. }
  27122. newLength = (newLength + 3) & ~3;
  27123. var result = new Uint8Array(newLength);
  27124. var pos = 0;
  27125. for (j = 0, jj = content.length; j < jj; j++) {
  27126. result.set(content[j], pos);
  27127. pos += content[j].length;
  27128. }
  27129. table.data = result;
  27130. table.length = newLength;
  27131. }
  27132. }
  27133. function sanitizeTTPrograms(fpgm, prep, cvt) {
  27134. var ttContext = {
  27135. functionsDefined: [],
  27136. functionsUsed: [],
  27137. functionsStackDeltas: [],
  27138. tooComplexToFollowFunctions: false,
  27139. hintsValid: true
  27140. };
  27141. if (fpgm) {
  27142. sanitizeTTProgram(fpgm, ttContext);
  27143. }
  27144. if (prep) {
  27145. sanitizeTTProgram(prep, ttContext);
  27146. }
  27147. if (fpgm) {
  27148. checkInvalidFunctions(ttContext, maxFunctionDefs);
  27149. }
  27150. if (cvt && (cvt.length & 1)) {
  27151. var cvtData = new Uint8Array(cvt.length + 1);
  27152. cvtData.set(cvt.data);
  27153. cvt.data = cvtData;
  27154. }
  27155. return ttContext.hintsValid;
  27156. }
  27157. // The following steps modify the original font data, making copy
  27158. font = new Stream(new Uint8Array(font.getBytes()));
  27159. var VALID_TABLES = ['OS/2', 'cmap', 'head', 'hhea', 'hmtx', 'maxp',
  27160. 'name', 'post', 'loca', 'glyf', 'fpgm', 'prep', 'cvt ', 'CFF '];
  27161. var header = readOpenTypeHeader(font);
  27162. var numTables = header.numTables;
  27163. var cff, cffFile;
  27164. var tables = { 'OS/2': null, cmap: null, head: null, hhea: null,
  27165. hmtx: null, maxp: null, name: null, post: null };
  27166. var table;
  27167. for (var i = 0; i < numTables; i++) {
  27168. table = readTableEntry(font);
  27169. if (VALID_TABLES.indexOf(table.tag) < 0) {
  27170. continue; // skipping table if it's not a required or optional table
  27171. }
  27172. if (table.length === 0) {
  27173. continue; // skipping empty tables
  27174. }
  27175. tables[table.tag] = table;
  27176. }
  27177. var isTrueType = !tables['CFF '];
  27178. if (!isTrueType) {
  27179. // OpenType font
  27180. if ((header.version === 'OTTO' && properties.type !== 'CIDFontType2') ||
  27181. !tables.head || !tables.hhea || !tables.maxp || !tables.post) {
  27182. // no major tables: throwing everything at CFFFont
  27183. cffFile = new Stream(tables['CFF '].data);
  27184. cff = new CFFFont(cffFile, properties);
  27185. adjustWidths(properties);
  27186. return this.convert(name, cff, properties);
  27187. }
  27188. delete tables.glyf;
  27189. delete tables.loca;
  27190. delete tables.fpgm;
  27191. delete tables.prep;
  27192. delete tables['cvt '];
  27193. this.isOpenType = true;
  27194. } else {
  27195. if (!tables.glyf || !tables.loca) {
  27196. error('Required "glyf" or "loca" tables are not found');
  27197. }
  27198. this.isOpenType = false;
  27199. }
  27200. if (!tables.maxp) {
  27201. error('Required "maxp" table is not found');
  27202. }
  27203. font.pos = (font.start || 0) + tables.maxp.offset;
  27204. var version = font.getInt32();
  27205. var numGlyphs = font.getUint16();
  27206. var maxFunctionDefs = 0;
  27207. if (version >= 0x00010000 && tables.maxp.length >= 22) {
  27208. // maxZones can be invalid
  27209. font.pos += 8;
  27210. var maxZones = font.getUint16();
  27211. if (maxZones > 2) { // reset to 2 if font has invalid maxZones
  27212. tables.maxp.data[14] = 0;
  27213. tables.maxp.data[15] = 2;
  27214. }
  27215. font.pos += 4;
  27216. maxFunctionDefs = font.getUint16();
  27217. }
  27218. var dupFirstEntry = false;
  27219. if (properties.type === 'CIDFontType2' && properties.toUnicode &&
  27220. properties.toUnicode.get(0) > '\u0000') {
  27221. // oracle's defect (see 3427), duplicating first entry
  27222. dupFirstEntry = true;
  27223. numGlyphs++;
  27224. tables.maxp.data[4] = numGlyphs >> 8;
  27225. tables.maxp.data[5] = numGlyphs & 255;
  27226. }
  27227. var hintsValid = sanitizeTTPrograms(tables.fpgm, tables.prep,
  27228. tables['cvt '], maxFunctionDefs);
  27229. if (!hintsValid) {
  27230. delete tables.fpgm;
  27231. delete tables.prep;
  27232. delete tables['cvt '];
  27233. }
  27234. // Ensure the hmtx table contains the advance width and
  27235. // sidebearings information for numGlyphs in the maxp table
  27236. sanitizeMetrics(font, tables.hhea, tables.hmtx, numGlyphs);
  27237. if (!tables.head) {
  27238. error('Required "head" table is not found');
  27239. }
  27240. sanitizeHead(tables.head, numGlyphs, isTrueType ? tables.loca.length : 0);
  27241. var missingGlyphs = {};
  27242. if (isTrueType) {
  27243. var isGlyphLocationsLong = int16(tables.head.data[50],
  27244. tables.head.data[51]);
  27245. missingGlyphs = sanitizeGlyphLocations(tables.loca, tables.glyf,
  27246. numGlyphs, isGlyphLocationsLong,
  27247. hintsValid, dupFirstEntry);
  27248. }
  27249. if (!tables.hhea) {
  27250. error('Required "hhea" table is not found');
  27251. }
  27252. // Sanitizer reduces the glyph advanceWidth to the maxAdvanceWidth
  27253. // Sometimes it's 0. That needs to be fixed
  27254. if (tables.hhea.data[10] === 0 && tables.hhea.data[11] === 0) {
  27255. tables.hhea.data[10] = 0xFF;
  27256. tables.hhea.data[11] = 0xFF;
  27257. }
  27258. // Extract some more font properties from the OpenType head and
  27259. // hhea tables; yMin and descent value are always negative.
  27260. var metricsOverride = {
  27261. unitsPerEm: int16(tables.head.data[18], tables.head.data[19]),
  27262. yMax: int16(tables.head.data[42], tables.head.data[43]),
  27263. yMin: int16(tables.head.data[38], tables.head.data[39]) - 0x10000,
  27264. ascent: int16(tables.hhea.data[4], tables.hhea.data[5]),
  27265. descent: int16(tables.hhea.data[6], tables.hhea.data[7]) - 0x10000
  27266. };
  27267. // PDF FontDescriptor metrics lie -- using data from actual font.
  27268. this.ascent = metricsOverride.ascent / metricsOverride.unitsPerEm;
  27269. this.descent = metricsOverride.descent / metricsOverride.unitsPerEm;
  27270. // The 'post' table has glyphs names.
  27271. if (tables.post) {
  27272. var valid = readPostScriptTable(tables.post, properties, numGlyphs);
  27273. if (!valid) {
  27274. tables.post = null;
  27275. }
  27276. }
  27277. var charCodeToGlyphId = [], charCode;
  27278. var toUnicode = properties.toUnicode, widths = properties.widths;
  27279. var skipToUnicode = (toUnicode instanceof IdentityToUnicodeMap ||
  27280. toUnicode.length === 0x10000);
  27281. // Helper function to try to skip mapping of empty glyphs.
  27282. // Note: In some cases, just relying on the glyph data doesn't work,
  27283. // hence we also use a few heuristics to fix various PDF files.
  27284. function hasGlyph(glyphId, charCode, widthCode) {
  27285. if (!missingGlyphs[glyphId]) {
  27286. return true;
  27287. }
  27288. if (!skipToUnicode && charCode >= 0 && toUnicode.has(charCode)) {
  27289. return true;
  27290. }
  27291. if (widths && widthCode >= 0 && isNum(widths[widthCode])) {
  27292. return true;
  27293. }
  27294. return false;
  27295. }
  27296. if (properties.type === 'CIDFontType2') {
  27297. var cidToGidMap = properties.cidToGidMap || [];
  27298. var isCidToGidMapEmpty = cidToGidMap.length === 0;
  27299. properties.cMap.forEach(function(charCode, cid) {
  27300. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  27301. var glyphId = -1;
  27302. if (isCidToGidMapEmpty) {
  27303. glyphId = charCode;
  27304. } else if (cidToGidMap[cid] !== undefined) {
  27305. glyphId = cidToGidMap[cid];
  27306. }
  27307. if (glyphId >= 0 && glyphId < numGlyphs &&
  27308. hasGlyph(glyphId, charCode, cid)) {
  27309. charCodeToGlyphId[charCode] = glyphId;
  27310. }
  27311. });
  27312. if (dupFirstEntry) {
  27313. charCodeToGlyphId[0] = numGlyphs - 1;
  27314. }
  27315. } else {
  27316. // Most of the following logic in this code branch is based on the
  27317. // 9.6.6.4 of the PDF spec.
  27318. var hasEncoding =
  27319. properties.differences.length > 0 || !!properties.baseEncodingName;
  27320. var cmapTable =
  27321. readCmapTable(tables.cmap, font, this.isSymbolicFont, hasEncoding);
  27322. var cmapPlatformId = cmapTable.platformId;
  27323. var cmapEncodingId = cmapTable.encodingId;
  27324. var cmapMappings = cmapTable.mappings;
  27325. var cmapMappingsLength = cmapMappings.length;
  27326. // The spec seems to imply that if the font is symbolic the encoding
  27327. // should be ignored, this doesn't appear to work for 'preistabelle.pdf'
  27328. // where the the font is symbolic and it has an encoding.
  27329. if (hasEncoding &&
  27330. (cmapPlatformId === 3 && cmapEncodingId === 1 ||
  27331. cmapPlatformId === 1 && cmapEncodingId === 0) ||
  27332. (cmapPlatformId === -1 && cmapEncodingId === -1 && // Temporary hack
  27333. !!Encodings[properties.baseEncodingName])) { // Temporary hack
  27334. // When no preferred cmap table was found and |baseEncodingName| is
  27335. // one of the predefined encodings, we seem to obtain a better
  27336. // |charCodeToGlyphId| map from the code below (fixes bug 1057544).
  27337. // TODO: Note that this is a hack which should be removed as soon as
  27338. // we have proper support for more exotic cmap tables.
  27339. var baseEncoding = [];
  27340. if (properties.baseEncodingName === 'MacRomanEncoding' ||
  27341. properties.baseEncodingName === 'WinAnsiEncoding') {
  27342. baseEncoding = Encodings[properties.baseEncodingName];
  27343. }
  27344. for (charCode = 0; charCode < 256; charCode++) {
  27345. var glyphName;
  27346. if (this.differences && charCode in this.differences) {
  27347. glyphName = this.differences[charCode];
  27348. } else if (charCode in baseEncoding &&
  27349. baseEncoding[charCode] !== '') {
  27350. glyphName = baseEncoding[charCode];
  27351. } else {
  27352. glyphName = Encodings.StandardEncoding[charCode];
  27353. }
  27354. if (!glyphName) {
  27355. continue;
  27356. }
  27357. var unicodeOrCharCode, isUnicode = false;
  27358. if (cmapPlatformId === 3 && cmapEncodingId === 1) {
  27359. unicodeOrCharCode = GlyphsUnicode[glyphName];
  27360. isUnicode = true;
  27361. } else if (cmapPlatformId === 1 && cmapEncodingId === 0) {
  27362. // TODO: the encoding needs to be updated with mac os table.
  27363. unicodeOrCharCode = Encodings.MacRomanEncoding.indexOf(glyphName);
  27364. }
  27365. var found = false;
  27366. for (i = 0; i < cmapMappingsLength; ++i) {
  27367. if (cmapMappings[i].charCode !== unicodeOrCharCode) {
  27368. continue;
  27369. }
  27370. var code = isUnicode ? charCode : unicodeOrCharCode;
  27371. if (hasGlyph(cmapMappings[i].glyphId, code, -1)) {
  27372. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  27373. found = true;
  27374. break;
  27375. }
  27376. }
  27377. if (!found && properties.glyphNames) {
  27378. // Try to map using the post table.
  27379. var glyphId = properties.glyphNames.indexOf(glyphName);
  27380. if (glyphId > 0 && hasGlyph(glyphId, -1, -1)) {
  27381. charCodeToGlyphId[charCode] = glyphId;
  27382. } else {
  27383. charCodeToGlyphId[charCode] = 0; // notdef
  27384. }
  27385. }
  27386. }
  27387. } else if (cmapPlatformId === 0 && cmapEncodingId === 0) {
  27388. // Default Unicode semantics, use the charcodes as is.
  27389. for (i = 0; i < cmapMappingsLength; ++i) {
  27390. charCodeToGlyphId[cmapMappings[i].charCode] =
  27391. cmapMappings[i].glyphId;
  27392. }
  27393. } else {
  27394. // For (3, 0) cmap tables:
  27395. // The charcode key being stored in charCodeToGlyphId is the lower
  27396. // byte of the two-byte charcodes of the cmap table since according to
  27397. // the spec: 'each byte from the string shall be prepended with the
  27398. // high byte of the range [of charcodes in the cmap table], to form
  27399. // a two-byte character, which shall be used to select the
  27400. // associated glyph description from the subtable'.
  27401. //
  27402. // For (1, 0) cmap tables:
  27403. // 'single bytes from the string shall be used to look up the
  27404. // associated glyph descriptions from the subtable'. This means
  27405. // charcodes in the cmap will be single bytes, so no-op since
  27406. // glyph.charCode & 0xFF === glyph.charCode
  27407. for (i = 0; i < cmapMappingsLength; ++i) {
  27408. charCode = cmapMappings[i].charCode & 0xFF;
  27409. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  27410. }
  27411. }
  27412. }
  27413. if (charCodeToGlyphId.length === 0) {
  27414. // defines at least one glyph
  27415. charCodeToGlyphId[0] = 0;
  27416. }
  27417. // Converting glyphs and ids into font's cmap table
  27418. var newMapping = adjustMapping(charCodeToGlyphId, properties);
  27419. this.toFontChar = newMapping.toFontChar;
  27420. tables.cmap = {
  27421. tag: 'cmap',
  27422. data: createCmapTable(newMapping.charCodeToGlyphId, numGlyphs)
  27423. };
  27424. if (!tables['OS/2'] || !validateOS2Table(tables['OS/2'])) {
  27425. tables['OS/2'] = {
  27426. tag: 'OS/2',
  27427. data: createOS2Table(properties, newMapping.charCodeToGlyphId,
  27428. metricsOverride)
  27429. };
  27430. }
  27431. // Rewrite the 'post' table if needed
  27432. if (!tables.post) {
  27433. tables.post = {
  27434. tag: 'post',
  27435. data: createPostTable(properties)
  27436. };
  27437. }
  27438. if (!isTrueType) {
  27439. try {
  27440. // Trying to repair CFF file
  27441. cffFile = new Stream(tables['CFF '].data);
  27442. var parser = new CFFParser(cffFile, properties);
  27443. cff = parser.parse();
  27444. var compiler = new CFFCompiler(cff);
  27445. tables['CFF '].data = compiler.compile();
  27446. } catch (e) {
  27447. warn('Failed to compile font ' + properties.loadedName);
  27448. }
  27449. }
  27450. // Re-creating 'name' table
  27451. if (!tables.name) {
  27452. tables.name = {
  27453. tag: 'name',
  27454. data: createNameTable(this.name)
  27455. };
  27456. } else {
  27457. // ... using existing 'name' table as prototype
  27458. var namePrototype = readNameTable(tables.name);
  27459. tables.name.data = createNameTable(name, namePrototype);
  27460. }
  27461. var builder = new OpenTypeFileBuilder(header.version);
  27462. for (var tableTag in tables) {
  27463. builder.addTable(tableTag, tables[tableTag].data);
  27464. }
  27465. return builder.toArray();
  27466. },
  27467. convert: function Font_convert(fontName, font, properties) {
  27468. // TODO: Check the charstring widths to determine this.
  27469. properties.fixedPitch = false;
  27470. var mapping = font.getGlyphMapping(properties);
  27471. var newMapping = adjustMapping(mapping, properties);
  27472. this.toFontChar = newMapping.toFontChar;
  27473. var numGlyphs = font.numGlyphs;
  27474. function getCharCodes(charCodeToGlyphId, glyphId) {
  27475. var charCodes = null;
  27476. for (var charCode in charCodeToGlyphId) {
  27477. if (glyphId === charCodeToGlyphId[charCode]) {
  27478. if (!charCodes) {
  27479. charCodes = [];
  27480. }
  27481. charCodes.push(charCode | 0);
  27482. }
  27483. }
  27484. return charCodes;
  27485. }
  27486. function createCharCode(charCodeToGlyphId, glyphId) {
  27487. for (var charCode in charCodeToGlyphId) {
  27488. if (glyphId === charCodeToGlyphId[charCode]) {
  27489. return charCode | 0;
  27490. }
  27491. }
  27492. newMapping.charCodeToGlyphId[newMapping.nextAvailableFontCharCode] =
  27493. glyphId;
  27494. return newMapping.nextAvailableFontCharCode++;
  27495. }
  27496. var seacs = font.seacs;
  27497. if (SEAC_ANALYSIS_ENABLED && seacs && seacs.length) {
  27498. var matrix = properties.fontMatrix || FONT_IDENTITY_MATRIX;
  27499. var charset = font.getCharset();
  27500. var seacMap = Object.create(null);
  27501. for (var glyphId in seacs) {
  27502. glyphId |= 0;
  27503. var seac = seacs[glyphId];
  27504. var baseGlyphName = Encodings.StandardEncoding[seac[2]];
  27505. var accentGlyphName = Encodings.StandardEncoding[seac[3]];
  27506. var baseGlyphId = charset.indexOf(baseGlyphName);
  27507. var accentGlyphId = charset.indexOf(accentGlyphName);
  27508. if (baseGlyphId < 0 || accentGlyphId < 0) {
  27509. continue;
  27510. }
  27511. var accentOffset = {
  27512. x: seac[0] * matrix[0] + seac[1] * matrix[2] + matrix[4],
  27513. y: seac[0] * matrix[1] + seac[1] * matrix[3] + matrix[5]
  27514. };
  27515. var charCodes = getCharCodes(mapping, glyphId);
  27516. if (!charCodes) {
  27517. // There's no point in mapping it if the char code was never mapped
  27518. // to begin with.
  27519. continue;
  27520. }
  27521. for (var i = 0, ii = charCodes.length; i < ii; i++) {
  27522. var charCode = charCodes[i];
  27523. // Find a fontCharCode that maps to the base and accent glyphs.
  27524. // If one doesn't exists, create it.
  27525. var charCodeToGlyphId = newMapping.charCodeToGlyphId;
  27526. var baseFontCharCode = createCharCode(charCodeToGlyphId,
  27527. baseGlyphId);
  27528. var accentFontCharCode = createCharCode(charCodeToGlyphId,
  27529. accentGlyphId);
  27530. seacMap[charCode] = {
  27531. baseFontCharCode: baseFontCharCode,
  27532. accentFontCharCode: accentFontCharCode,
  27533. accentOffset: accentOffset
  27534. };
  27535. }
  27536. }
  27537. properties.seacMap = seacMap;
  27538. }
  27539. var unitsPerEm = 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0];
  27540. var builder = new OpenTypeFileBuilder('\x4F\x54\x54\x4F');
  27541. // PostScript Font Program
  27542. builder.addTable('CFF ', font.data);
  27543. // OS/2 and Windows Specific metrics
  27544. builder.addTable('OS/2', createOS2Table(properties,
  27545. newMapping.charCodeToGlyphId));
  27546. // Character to glyphs mapping
  27547. builder.addTable('cmap', createCmapTable(newMapping.charCodeToGlyphId,
  27548. numGlyphs));
  27549. // Font header
  27550. builder.addTable('head',
  27551. '\x00\x01\x00\x00' + // Version number
  27552. '\x00\x00\x10\x00' + // fontRevision
  27553. '\x00\x00\x00\x00' + // checksumAdjustement
  27554. '\x5F\x0F\x3C\xF5' + // magicNumber
  27555. '\x00\x00' + // Flags
  27556. safeString16(unitsPerEm) + // unitsPerEM
  27557. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // creation date
  27558. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // modifification date
  27559. '\x00\x00' + // xMin
  27560. safeString16(properties.descent) + // yMin
  27561. '\x0F\xFF' + // xMax
  27562. safeString16(properties.ascent) + // yMax
  27563. string16(properties.italicAngle ? 2 : 0) + // macStyle
  27564. '\x00\x11' + // lowestRecPPEM
  27565. '\x00\x00' + // fontDirectionHint
  27566. '\x00\x00' + // indexToLocFormat
  27567. '\x00\x00'); // glyphDataFormat
  27568. // Horizontal header
  27569. builder.addTable('hhea',
  27570. '\x00\x01\x00\x00' + // Version number
  27571. safeString16(properties.ascent) + // Typographic Ascent
  27572. safeString16(properties.descent) + // Typographic Descent
  27573. '\x00\x00' + // Line Gap
  27574. '\xFF\xFF' + // advanceWidthMax
  27575. '\x00\x00' + // minLeftSidebearing
  27576. '\x00\x00' + // minRightSidebearing
  27577. '\x00\x00' + // xMaxExtent
  27578. safeString16(properties.capHeight) + // caretSlopeRise
  27579. safeString16(Math.tan(properties.italicAngle) *
  27580. properties.xHeight) + // caretSlopeRun
  27581. '\x00\x00' + // caretOffset
  27582. '\x00\x00' + // -reserved-
  27583. '\x00\x00' + // -reserved-
  27584. '\x00\x00' + // -reserved-
  27585. '\x00\x00' + // -reserved-
  27586. '\x00\x00' + // metricDataFormat
  27587. string16(numGlyphs)); // Number of HMetrics
  27588. // Horizontal metrics
  27589. builder.addTable('hmtx', (function fontFieldsHmtx() {
  27590. var charstrings = font.charstrings;
  27591. var cffWidths = font.cff ? font.cff.widths : null;
  27592. var hmtx = '\x00\x00\x00\x00'; // Fake .notdef
  27593. for (var i = 1, ii = numGlyphs; i < ii; i++) {
  27594. var width = 0;
  27595. if (charstrings) {
  27596. var charstring = charstrings[i - 1];
  27597. width = 'width' in charstring ? charstring.width : 0;
  27598. } else if (cffWidths) {
  27599. width = Math.ceil(cffWidths[i] || 0);
  27600. }
  27601. hmtx += string16(width) + string16(0);
  27602. }
  27603. return hmtx;
  27604. })());
  27605. // Maximum profile
  27606. builder.addTable('maxp',
  27607. '\x00\x00\x50\x00' + // Version number
  27608. string16(numGlyphs)); // Num of glyphs
  27609. // Naming tables
  27610. builder.addTable('name', createNameTable(fontName));
  27611. // PostScript informations
  27612. builder.addTable('post', createPostTable(properties));
  27613. return builder.toArray();
  27614. },
  27615. /**
  27616. * Builds a char code to unicode map based on section 9.10 of the spec.
  27617. * @param {Object} properties Font properties object.
  27618. * @return {Object} A ToUnicodeMap object.
  27619. */
  27620. buildToUnicode: function Font_buildToUnicode(properties) {
  27621. // Section 9.10.2 Mapping Character Codes to Unicode Values
  27622. if (properties.toUnicode && properties.toUnicode.length !== 0) {
  27623. return properties.toUnicode;
  27624. }
  27625. // According to the spec if the font is a simple font we should only map
  27626. // to unicode if the base encoding is MacRoman, MacExpert, or WinAnsi or
  27627. // the differences array only contains adobe standard or symbol set names,
  27628. // in pratice it seems better to always try to create a toUnicode
  27629. // map based of the default encoding.
  27630. var toUnicode, charcode;
  27631. if (!properties.composite /* is simple font */) {
  27632. toUnicode = [];
  27633. var encoding = properties.defaultEncoding.slice();
  27634. var baseEncodingName = properties.baseEncodingName;
  27635. // Merge in the differences array.
  27636. var differences = properties.differences;
  27637. for (charcode in differences) {
  27638. encoding[charcode] = differences[charcode];
  27639. }
  27640. for (charcode in encoding) {
  27641. // a) Map the character code to a character name.
  27642. var glyphName = encoding[charcode];
  27643. // b) Look up the character name in the Adobe Glyph List (see the
  27644. // Bibliography) to obtain the corresponding Unicode value.
  27645. if (glyphName === '') {
  27646. continue;
  27647. } else if (GlyphsUnicode[glyphName] === undefined) {
  27648. // (undocumented) c) Few heuristics to recognize unknown glyphs
  27649. // NOTE: Adobe Reader does not do this step, but OSX Preview does
  27650. var code = 0;
  27651. switch (glyphName[0]) {
  27652. case 'G': // Gxx glyph
  27653. if (glyphName.length === 3) {
  27654. code = parseInt(glyphName.substr(1), 16);
  27655. }
  27656. break;
  27657. case 'g': // g00xx glyph
  27658. if (glyphName.length === 5) {
  27659. code = parseInt(glyphName.substr(1), 16);
  27660. }
  27661. break;
  27662. case 'C': // Cddd glyph
  27663. case 'c': // cddd glyph
  27664. if (glyphName.length >= 3) {
  27665. code = +glyphName.substr(1);
  27666. }
  27667. break;
  27668. }
  27669. if (code) {
  27670. // If |baseEncodingName| is one the predefined encodings,
  27671. // and |code| equals |charcode|, using the glyph defined in the
  27672. // baseEncoding seems to yield a better |toUnicode| mapping
  27673. // (fixes issue 5070).
  27674. if (baseEncodingName && code === +charcode) {
  27675. var baseEncoding = Encodings[baseEncodingName];
  27676. if (baseEncoding && (glyphName = baseEncoding[charcode])) {
  27677. toUnicode[charcode] =
  27678. String.fromCharCode(GlyphsUnicode[glyphName]);
  27679. continue;
  27680. }
  27681. }
  27682. toUnicode[charcode] = String.fromCharCode(code);
  27683. }
  27684. continue;
  27685. }
  27686. toUnicode[charcode] = String.fromCharCode(GlyphsUnicode[glyphName]);
  27687. }
  27688. return new ToUnicodeMap(toUnicode);
  27689. }
  27690. // If the font is a composite font that uses one of the predefined CMaps
  27691. // listed in Table 118 (except Identity–H and Identity–V) or whose
  27692. // descendant CIDFont uses the Adobe-GB1, Adobe-CNS1, Adobe-Japan1, or
  27693. // Adobe-Korea1 character collection:
  27694. if (properties.composite && (
  27695. (properties.cMap.builtInCMap &&
  27696. !(properties.cMap instanceof IdentityCMap)) ||
  27697. (properties.cidSystemInfo.registry === 'Adobe' &&
  27698. (properties.cidSystemInfo.ordering === 'GB1' ||
  27699. properties.cidSystemInfo.ordering === 'CNS1' ||
  27700. properties.cidSystemInfo.ordering === 'Japan1' ||
  27701. properties.cidSystemInfo.ordering === 'Korea1')))) {
  27702. // Then:
  27703. // a) Map the character code to a character identifier (CID) according
  27704. // to the font’s CMap.
  27705. // b) Obtain the registry and ordering of the character collection used
  27706. // by the font’s CMap (for example, Adobe and Japan1) from its
  27707. // CIDSystemInfo dictionary.
  27708. var registry = properties.cidSystemInfo.registry;
  27709. var ordering = properties.cidSystemInfo.ordering;
  27710. // c) Construct a second CMap name by concatenating the registry and
  27711. // ordering obtained in step (b) in the format registry–ordering–UCS2
  27712. // (for example, Adobe–Japan1–UCS2).
  27713. var ucs2CMapName = new Name(registry + '-' + ordering + '-UCS2');
  27714. // d) Obtain the CMap with the name constructed in step (c) (available
  27715. // from the ASN Web site; see the Bibliography).
  27716. var ucs2CMap = CMapFactory.create(ucs2CMapName,
  27717. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  27718. var cMap = properties.cMap;
  27719. toUnicode = [];
  27720. cMap.forEach(function(charcode, cid) {
  27721. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  27722. // e) Map the CID obtained in step (a) according to the CMap obtained
  27723. // in step (d), producing a Unicode value.
  27724. var ucs2 = ucs2CMap.lookup(cid);
  27725. if (ucs2) {
  27726. toUnicode[charcode] =
  27727. String.fromCharCode((ucs2.charCodeAt(0) << 8) +
  27728. ucs2.charCodeAt(1));
  27729. }
  27730. });
  27731. return new ToUnicodeMap(toUnicode);
  27732. }
  27733. // The viewer's choice, just use an identity map.
  27734. return new IdentityToUnicodeMap(properties.firstChar,
  27735. properties.lastChar);
  27736. },
  27737. get spaceWidth() {
  27738. if ('_shadowWidth' in this) {
  27739. return this._shadowWidth;
  27740. }
  27741. // trying to estimate space character width
  27742. var possibleSpaceReplacements = ['space', 'minus', 'one', 'i'];
  27743. var width;
  27744. for (var i = 0, ii = possibleSpaceReplacements.length; i < ii; i++) {
  27745. var glyphName = possibleSpaceReplacements[i];
  27746. // if possible, getting width by glyph name
  27747. if (glyphName in this.widths) {
  27748. width = this.widths[glyphName];
  27749. break;
  27750. }
  27751. var glyphUnicode = GlyphsUnicode[glyphName];
  27752. // finding the charcode via unicodeToCID map
  27753. var charcode = 0;
  27754. if (this.composite) {
  27755. if (this.cMap.contains(glyphUnicode)) {
  27756. charcode = this.cMap.lookup(glyphUnicode);
  27757. }
  27758. }
  27759. // ... via toUnicode map
  27760. if (!charcode && this.toUnicode) {
  27761. charcode = this.toUnicode.charCodeOf(glyphUnicode);
  27762. }
  27763. // setting it to unicode if negative or undefined
  27764. if (charcode <= 0) {
  27765. charcode = glyphUnicode;
  27766. }
  27767. // trying to get width via charcode
  27768. width = this.widths[charcode];
  27769. if (width) {
  27770. break; // the non-zero width found
  27771. }
  27772. }
  27773. width = width || this.defaultWidth;
  27774. // Do not shadow the property here. See discussion:
  27775. // https://github.com/mozilla/pdf.js/pull/2127#discussion_r1662280
  27776. this._shadowWidth = width;
  27777. return width;
  27778. },
  27779. charToGlyph: function Font_charToGlyph(charcode, isSpace) {
  27780. var fontCharCode, width, operatorListId;
  27781. var widthCode = charcode;
  27782. if (this.cMap && this.cMap.contains(charcode)) {
  27783. widthCode = this.cMap.lookup(charcode);
  27784. }
  27785. width = this.widths[widthCode];
  27786. width = isNum(width) ? width : this.defaultWidth;
  27787. var vmetric = this.vmetrics && this.vmetrics[widthCode];
  27788. var unicode = this.toUnicode.get(charcode) || charcode;
  27789. if (typeof unicode === 'number') {
  27790. unicode = String.fromCharCode(unicode);
  27791. }
  27792. // First try the toFontChar map, if it's not there then try falling
  27793. // back to the char code.
  27794. fontCharCode = this.toFontChar[charcode] || charcode;
  27795. if (this.missingFile) {
  27796. fontCharCode = mapSpecialUnicodeValues(fontCharCode);
  27797. }
  27798. if (this.isType3Font) {
  27799. // Font char code in this case is actually a glyph name.
  27800. operatorListId = fontCharCode;
  27801. }
  27802. var accent = null;
  27803. if (this.seacMap && this.seacMap[charcode]) {
  27804. var seac = this.seacMap[charcode];
  27805. fontCharCode = seac.baseFontCharCode;
  27806. accent = {
  27807. fontChar: String.fromCharCode(seac.accentFontCharCode),
  27808. offset: seac.accentOffset
  27809. };
  27810. }
  27811. var fontChar = String.fromCharCode(fontCharCode);
  27812. var glyph = this.glyphCache[charcode];
  27813. if (!glyph ||
  27814. !glyph.matchesForCache(fontChar, unicode, accent, width, vmetric,
  27815. operatorListId, isSpace)) {
  27816. glyph = new Glyph(fontChar, unicode, accent, width, vmetric,
  27817. operatorListId, isSpace);
  27818. this.glyphCache[charcode] = glyph;
  27819. }
  27820. return glyph;
  27821. },
  27822. charsToGlyphs: function Font_charsToGlyphs(chars) {
  27823. var charsCache = this.charsCache;
  27824. var glyphs, glyph, charcode;
  27825. // if we translated this string before, just grab it from the cache
  27826. if (charsCache) {
  27827. glyphs = charsCache[chars];
  27828. if (glyphs) {
  27829. return glyphs;
  27830. }
  27831. }
  27832. // lazily create the translation cache
  27833. if (!charsCache) {
  27834. charsCache = this.charsCache = Object.create(null);
  27835. }
  27836. glyphs = [];
  27837. var charsCacheKey = chars;
  27838. var i = 0, ii;
  27839. if (this.cMap) {
  27840. // composite fonts have multi-byte strings convert the string from
  27841. // single-byte to multi-byte
  27842. var c = {};
  27843. while (i < chars.length) {
  27844. this.cMap.readCharCode(chars, i, c);
  27845. charcode = c.charcode;
  27846. var length = c.length;
  27847. i += length;
  27848. // Space is char with code 0x20 and length 1 in multiple-byte codes.
  27849. var isSpace = length === 1 && chars.charCodeAt(i - 1) === 0x20;
  27850. glyph = this.charToGlyph(charcode, isSpace);
  27851. glyphs.push(glyph);
  27852. }
  27853. } else {
  27854. for (i = 0, ii = chars.length; i < ii; ++i) {
  27855. charcode = chars.charCodeAt(i);
  27856. glyph = this.charToGlyph(charcode, charcode === 0x20);
  27857. glyphs.push(glyph);
  27858. }
  27859. }
  27860. // Enter the translated string into the cache
  27861. return (charsCache[charsCacheKey] = glyphs);
  27862. }
  27863. };
  27864. return Font;
  27865. })();
  27866. var ErrorFont = (function ErrorFontClosure() {
  27867. function ErrorFont(error) {
  27868. this.error = error;
  27869. this.loadedName = 'g_font_error';
  27870. this.loading = false;
  27871. }
  27872. ErrorFont.prototype = {
  27873. charsToGlyphs: function ErrorFont_charsToGlyphs() {
  27874. return [];
  27875. },
  27876. exportData: function ErrorFont_exportData() {
  27877. return {error: this.error};
  27878. }
  27879. };
  27880. return ErrorFont;
  27881. })();
  27882. /**
  27883. * Shared logic for building a char code to glyph id mapping for Type1 and
  27884. * simple CFF fonts. See section 9.6.6.2 of the spec.
  27885. * @param {Object} properties Font properties object.
  27886. * @param {Object} builtInEncoding The encoding contained within the actual font
  27887. * data.
  27888. * @param {Array} Array of glyph names where the index is the glyph ID.
  27889. * @returns {Object} A char code to glyph ID map.
  27890. */
  27891. function type1FontGlyphMapping(properties, builtInEncoding, glyphNames) {
  27892. var charCodeToGlyphId = Object.create(null);
  27893. var glyphId, charCode, baseEncoding;
  27894. if (properties.baseEncodingName) {
  27895. // If a valid base encoding name was used, the mapping is initialized with
  27896. // that.
  27897. baseEncoding = Encodings[properties.baseEncodingName];
  27898. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  27899. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  27900. if (glyphId >= 0) {
  27901. charCodeToGlyphId[charCode] = glyphId;
  27902. } else {
  27903. charCodeToGlyphId[charCode] = 0; // notdef
  27904. }
  27905. }
  27906. } else if (!!(properties.flags & FontFlags.Symbolic)) {
  27907. // For a symbolic font the encoding should be the fonts built-in
  27908. // encoding.
  27909. for (charCode in builtInEncoding) {
  27910. charCodeToGlyphId[charCode] = builtInEncoding[charCode];
  27911. }
  27912. } else {
  27913. // For non-symbolic fonts that don't have a base encoding the standard
  27914. // encoding should be used.
  27915. baseEncoding = Encodings.StandardEncoding;
  27916. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  27917. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  27918. if (glyphId >= 0) {
  27919. charCodeToGlyphId[charCode] = glyphId;
  27920. } else {
  27921. charCodeToGlyphId[charCode] = 0; // notdef
  27922. }
  27923. }
  27924. }
  27925. // Lastly, merge in the differences.
  27926. var differences = properties.differences;
  27927. if (differences) {
  27928. for (charCode in differences) {
  27929. var glyphName = differences[charCode];
  27930. glyphId = glyphNames.indexOf(glyphName);
  27931. if (glyphId >= 0) {
  27932. charCodeToGlyphId[charCode] = glyphId;
  27933. } else {
  27934. charCodeToGlyphId[charCode] = 0; // notdef
  27935. }
  27936. }
  27937. }
  27938. return charCodeToGlyphId;
  27939. }
  27940. /*
  27941. * CharStrings are encoded following the the CharString Encoding sequence
  27942. * describe in Chapter 6 of the "Adobe Type1 Font Format" specification.
  27943. * The value in a byte indicates a command, a number, or subsequent bytes
  27944. * that are to be interpreted in a special way.
  27945. *
  27946. * CharString Number Encoding:
  27947. * A CharString byte containing the values from 32 through 255 inclusive
  27948. * indicate an integer. These values are decoded in four ranges.
  27949. *
  27950. * 1. A CharString byte containing a value, v, between 32 and 246 inclusive,
  27951. * indicate the integer v - 139. Thus, the integer values from -107 through
  27952. * 107 inclusive may be encoded in single byte.
  27953. *
  27954. * 2. A CharString byte containing a value, v, between 247 and 250 inclusive,
  27955. * indicates an integer involving the next byte, w, according to the formula:
  27956. * [(v - 247) x 256] + w + 108
  27957. *
  27958. * 3. A CharString byte containing a value, v, between 251 and 254 inclusive,
  27959. * indicates an integer involving the next byte, w, according to the formula:
  27960. * -[(v - 251) * 256] - w - 108
  27961. *
  27962. * 4. A CharString containing the value 255 indicates that the next 4 bytes
  27963. * are a two complement signed integer. The first of these bytes contains the
  27964. * highest order bits, the second byte contains the next higher order bits
  27965. * and the fourth byte contain the lowest order bits.
  27966. *
  27967. *
  27968. * CharString Command Encoding:
  27969. * CharStrings commands are encoded in 1 or 2 bytes.
  27970. *
  27971. * Single byte commands are encoded in 1 byte that contains a value between
  27972. * 0 and 31 inclusive.
  27973. * If a command byte contains the value 12, then the value in the next byte
  27974. * indicates a command. This "escape" mechanism allows many extra commands
  27975. * to be encoded and this encoding technique helps to minimize the length of
  27976. * the charStrings.
  27977. */
  27978. var Type1CharString = (function Type1CharStringClosure() {
  27979. var COMMAND_MAP = {
  27980. 'hstem': [1],
  27981. 'vstem': [3],
  27982. 'vmoveto': [4],
  27983. 'rlineto': [5],
  27984. 'hlineto': [6],
  27985. 'vlineto': [7],
  27986. 'rrcurveto': [8],
  27987. 'callsubr': [10],
  27988. 'flex': [12, 35],
  27989. 'drop' : [12, 18],
  27990. 'endchar': [14],
  27991. 'rmoveto': [21],
  27992. 'hmoveto': [22],
  27993. 'vhcurveto': [30],
  27994. 'hvcurveto': [31]
  27995. };
  27996. function Type1CharString() {
  27997. this.width = 0;
  27998. this.lsb = 0;
  27999. this.flexing = false;
  28000. this.output = [];
  28001. this.stack = [];
  28002. }
  28003. Type1CharString.prototype = {
  28004. convert: function Type1CharString_convert(encoded, subrs) {
  28005. var count = encoded.length;
  28006. var error = false;
  28007. var wx, sbx, subrNumber;
  28008. for (var i = 0; i < count; i++) {
  28009. var value = encoded[i];
  28010. if (value < 32) {
  28011. if (value === 12) {
  28012. value = (value << 8) + encoded[++i];
  28013. }
  28014. switch (value) {
  28015. case 1: // hstem
  28016. if (!HINTING_ENABLED) {
  28017. this.stack = [];
  28018. break;
  28019. }
  28020. error = this.executeCommand(2, COMMAND_MAP.hstem);
  28021. break;
  28022. case 3: // vstem
  28023. if (!HINTING_ENABLED) {
  28024. this.stack = [];
  28025. break;
  28026. }
  28027. error = this.executeCommand(2, COMMAND_MAP.vstem);
  28028. break;
  28029. case 4: // vmoveto
  28030. if (this.flexing) {
  28031. if (this.stack.length < 1) {
  28032. error = true;
  28033. break;
  28034. }
  28035. // Add the dx for flex and but also swap the values so they are
  28036. // the right order.
  28037. var dy = this.stack.pop();
  28038. this.stack.push(0, dy);
  28039. break;
  28040. }
  28041. error = this.executeCommand(1, COMMAND_MAP.vmoveto);
  28042. break;
  28043. case 5: // rlineto
  28044. error = this.executeCommand(2, COMMAND_MAP.rlineto);
  28045. break;
  28046. case 6: // hlineto
  28047. error = this.executeCommand(1, COMMAND_MAP.hlineto);
  28048. break;
  28049. case 7: // vlineto
  28050. error = this.executeCommand(1, COMMAND_MAP.vlineto);
  28051. break;
  28052. case 8: // rrcurveto
  28053. error = this.executeCommand(6, COMMAND_MAP.rrcurveto);
  28054. break;
  28055. case 9: // closepath
  28056. // closepath is a Type1 command that does not take argument and is
  28057. // useless in Type2 and it can simply be ignored.
  28058. this.stack = [];
  28059. break;
  28060. case 10: // callsubr
  28061. if (this.stack.length < 1) {
  28062. error = true;
  28063. break;
  28064. }
  28065. subrNumber = this.stack.pop();
  28066. error = this.convert(subrs[subrNumber], subrs);
  28067. break;
  28068. case 11: // return
  28069. return error;
  28070. case 13: // hsbw
  28071. if (this.stack.length < 2) {
  28072. error = true;
  28073. break;
  28074. }
  28075. // To convert to type2 we have to move the width value to the
  28076. // first part of the charstring and then use hmoveto with lsb.
  28077. wx = this.stack.pop();
  28078. sbx = this.stack.pop();
  28079. this.lsb = sbx;
  28080. this.width = wx;
  28081. this.stack.push(wx, sbx);
  28082. error = this.executeCommand(2, COMMAND_MAP.hmoveto);
  28083. break;
  28084. case 14: // endchar
  28085. this.output.push(COMMAND_MAP.endchar[0]);
  28086. break;
  28087. case 21: // rmoveto
  28088. if (this.flexing) {
  28089. break;
  28090. }
  28091. error = this.executeCommand(2, COMMAND_MAP.rmoveto);
  28092. break;
  28093. case 22: // hmoveto
  28094. if (this.flexing) {
  28095. // Add the dy for flex.
  28096. this.stack.push(0);
  28097. break;
  28098. }
  28099. error = this.executeCommand(1, COMMAND_MAP.hmoveto);
  28100. break;
  28101. case 30: // vhcurveto
  28102. error = this.executeCommand(4, COMMAND_MAP.vhcurveto);
  28103. break;
  28104. case 31: // hvcurveto
  28105. error = this.executeCommand(4, COMMAND_MAP.hvcurveto);
  28106. break;
  28107. case (12 << 8) + 0: // dotsection
  28108. // dotsection is a Type1 command to specify some hinting feature
  28109. // for dots that do not take a parameter and it can safely be
  28110. // ignored for Type2.
  28111. this.stack = [];
  28112. break;
  28113. case (12 << 8) + 1: // vstem3
  28114. if (!HINTING_ENABLED) {
  28115. this.stack = [];
  28116. break;
  28117. }
  28118. // [vh]stem3 are Type1 only and Type2 supports [vh]stem with
  28119. // multiple parameters, so instead of returning [vh]stem3 take a
  28120. // shortcut and return [vhstem] instead.
  28121. error = this.executeCommand(2, COMMAND_MAP.vstem);
  28122. break;
  28123. case (12 << 8) + 2: // hstem3
  28124. if (!HINTING_ENABLED) {
  28125. this.stack = [];
  28126. break;
  28127. }
  28128. // See vstem3.
  28129. error = this.executeCommand(2, COMMAND_MAP.hstem);
  28130. break;
  28131. case (12 << 8) + 6: // seac
  28132. // seac is like type 2's special endchar but it doesn't use the
  28133. // first argument asb, so remove it.
  28134. if (SEAC_ANALYSIS_ENABLED) {
  28135. this.seac = this.stack.splice(-4, 4);
  28136. error = this.executeCommand(0, COMMAND_MAP.endchar);
  28137. } else {
  28138. error = this.executeCommand(4, COMMAND_MAP.endchar);
  28139. }
  28140. break;
  28141. case (12 << 8) + 7: // sbw
  28142. if (this.stack.length < 4) {
  28143. error = true;
  28144. break;
  28145. }
  28146. // To convert to type2 we have to move the width value to the
  28147. // first part of the charstring and then use rmoveto with
  28148. // (dx, dy). The height argument will not be used for vmtx and
  28149. // vhea tables reconstruction -- ignoring it.
  28150. var wy = this.stack.pop();
  28151. wx = this.stack.pop();
  28152. var sby = this.stack.pop();
  28153. sbx = this.stack.pop();
  28154. this.lsb = sbx;
  28155. this.width = wx;
  28156. this.stack.push(wx, sbx, sby);
  28157. error = this.executeCommand(3, COMMAND_MAP.rmoveto);
  28158. break;
  28159. case (12 << 8) + 12: // div
  28160. if (this.stack.length < 2) {
  28161. error = true;
  28162. break;
  28163. }
  28164. var num2 = this.stack.pop();
  28165. var num1 = this.stack.pop();
  28166. this.stack.push(num1 / num2);
  28167. break;
  28168. case (12 << 8) + 16: // callothersubr
  28169. if (this.stack.length < 2) {
  28170. error = true;
  28171. break;
  28172. }
  28173. subrNumber = this.stack.pop();
  28174. var numArgs = this.stack.pop();
  28175. if (subrNumber === 0 && numArgs === 3) {
  28176. var flexArgs = this.stack.splice(this.stack.length - 17, 17);
  28177. this.stack.push(
  28178. flexArgs[2] + flexArgs[0], // bcp1x + rpx
  28179. flexArgs[3] + flexArgs[1], // bcp1y + rpy
  28180. flexArgs[4], // bcp2x
  28181. flexArgs[5], // bcp2y
  28182. flexArgs[6], // p2x
  28183. flexArgs[7], // p2y
  28184. flexArgs[8], // bcp3x
  28185. flexArgs[9], // bcp3y
  28186. flexArgs[10], // bcp4x
  28187. flexArgs[11], // bcp4y
  28188. flexArgs[12], // p3x
  28189. flexArgs[13], // p3y
  28190. flexArgs[14] // flexDepth
  28191. // 15 = finalx unused by flex
  28192. // 16 = finaly unused by flex
  28193. );
  28194. error = this.executeCommand(13, COMMAND_MAP.flex, true);
  28195. this.flexing = false;
  28196. this.stack.push(flexArgs[15], flexArgs[16]);
  28197. } else if (subrNumber === 1 && numArgs === 0) {
  28198. this.flexing = true;
  28199. }
  28200. break;
  28201. case (12 << 8) + 17: // pop
  28202. // Ignore this since it is only used with othersubr.
  28203. break;
  28204. case (12 << 8) + 33: // setcurrentpoint
  28205. // Ignore for now.
  28206. this.stack = [];
  28207. break;
  28208. default:
  28209. warn('Unknown type 1 charstring command of "' + value + '"');
  28210. break;
  28211. }
  28212. if (error) {
  28213. break;
  28214. }
  28215. continue;
  28216. } else if (value <= 246) {
  28217. value = value - 139;
  28218. } else if (value <= 250) {
  28219. value = ((value - 247) * 256) + encoded[++i] + 108;
  28220. } else if (value <= 254) {
  28221. value = -((value - 251) * 256) - encoded[++i] - 108;
  28222. } else {
  28223. value = (encoded[++i] & 0xff) << 24 | (encoded[++i] & 0xff) << 16 |
  28224. (encoded[++i] & 0xff) << 8 | (encoded[++i] & 0xff) << 0;
  28225. }
  28226. this.stack.push(value);
  28227. }
  28228. return error;
  28229. },
  28230. executeCommand: function(howManyArgs, command, keepStack) {
  28231. var stackLength = this.stack.length;
  28232. if (howManyArgs > stackLength) {
  28233. return true;
  28234. }
  28235. var start = stackLength - howManyArgs;
  28236. for (var i = start; i < stackLength; i++) {
  28237. var value = this.stack[i];
  28238. if (value === (value | 0)) { // int
  28239. this.output.push(28, (value >> 8) & 0xff, value & 0xff);
  28240. } else { // fixed point
  28241. value = (65536 * value) | 0;
  28242. this.output.push(255,
  28243. (value >> 24) & 0xFF,
  28244. (value >> 16) & 0xFF,
  28245. (value >> 8) & 0xFF,
  28246. value & 0xFF);
  28247. }
  28248. }
  28249. this.output.push.apply(this.output, command);
  28250. if (keepStack) {
  28251. this.stack.splice(start, howManyArgs);
  28252. } else {
  28253. this.stack.length = 0;
  28254. }
  28255. return false;
  28256. }
  28257. };
  28258. return Type1CharString;
  28259. })();
  28260. /*
  28261. * Type1Parser encapsulate the needed code for parsing a Type1 font
  28262. * program. Some of its logic depends on the Type2 charstrings
  28263. * structure.
  28264. * Note: this doesn't really parse the font since that would require evaluation
  28265. * of PostScript, but it is possible in most cases to extract what we need
  28266. * without a full parse.
  28267. */
  28268. var Type1Parser = (function Type1ParserClosure() {
  28269. /*
  28270. * Decrypt a Sequence of Ciphertext Bytes to Produce the Original Sequence
  28271. * of Plaintext Bytes. The function took a key as a parameter which can be
  28272. * for decrypting the eexec block of for decoding charStrings.
  28273. */
  28274. var EEXEC_ENCRYPT_KEY = 55665;
  28275. var CHAR_STRS_ENCRYPT_KEY = 4330;
  28276. function isHexDigit(code) {
  28277. return code >= 48 && code <= 57 || // '0'-'9'
  28278. code >= 65 && code <= 70 || // 'A'-'F'
  28279. code >= 97 && code <= 102; // 'a'-'f'
  28280. }
  28281. function decrypt(data, key, discardNumber) {
  28282. var r = key | 0, c1 = 52845, c2 = 22719;
  28283. var count = data.length;
  28284. var decrypted = new Uint8Array(count);
  28285. for (var i = 0; i < count; i++) {
  28286. var value = data[i];
  28287. decrypted[i] = value ^ (r >> 8);
  28288. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  28289. }
  28290. return Array.prototype.slice.call(decrypted, discardNumber);
  28291. }
  28292. function decryptAscii(data, key, discardNumber) {
  28293. var r = key | 0, c1 = 52845, c2 = 22719;
  28294. var count = data.length, maybeLength = count >>> 1;
  28295. var decrypted = new Uint8Array(maybeLength);
  28296. var i, j;
  28297. for (i = 0, j = 0; i < count; i++) {
  28298. var digit1 = data[i];
  28299. if (!isHexDigit(digit1)) {
  28300. continue;
  28301. }
  28302. i++;
  28303. var digit2;
  28304. while (i < count && !isHexDigit(digit2 = data[i])) {
  28305. i++;
  28306. }
  28307. if (i < count) {
  28308. var value = parseInt(String.fromCharCode(digit1, digit2), 16);
  28309. decrypted[j++] = value ^ (r >> 8);
  28310. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  28311. }
  28312. }
  28313. return Array.prototype.slice.call(decrypted, discardNumber, j);
  28314. }
  28315. function isSpecial(c) {
  28316. return c === 0x2F || // '/'
  28317. c === 0x5B || c === 0x5D || // '[', ']'
  28318. c === 0x7B || c === 0x7D || // '{', '}'
  28319. c === 0x28 || c === 0x29; // '(', ')'
  28320. }
  28321. function Type1Parser(stream, encrypted) {
  28322. if (encrypted) {
  28323. var data = stream.getBytes();
  28324. var isBinary = !(isHexDigit(data[0]) && isHexDigit(data[1]) &&
  28325. isHexDigit(data[2]) && isHexDigit(data[3]));
  28326. stream = new Stream(isBinary ? decrypt(data, EEXEC_ENCRYPT_KEY, 4) :
  28327. decryptAscii(data, EEXEC_ENCRYPT_KEY, 4));
  28328. }
  28329. this.stream = stream;
  28330. this.nextChar();
  28331. }
  28332. Type1Parser.prototype = {
  28333. readNumberArray: function Type1Parser_readNumberArray() {
  28334. this.getToken(); // read '[' or '{' (arrays can start with either)
  28335. var array = [];
  28336. while (true) {
  28337. var token = this.getToken();
  28338. if (token === null || token === ']' || token === '}') {
  28339. break;
  28340. }
  28341. array.push(parseFloat(token || 0));
  28342. }
  28343. return array;
  28344. },
  28345. readNumber: function Type1Parser_readNumber() {
  28346. var token = this.getToken();
  28347. return parseFloat(token || 0);
  28348. },
  28349. readInt: function Type1Parser_readInt() {
  28350. // Use '| 0' to prevent setting a double into length such as the double
  28351. // does not flow into the loop variable.
  28352. var token = this.getToken();
  28353. return parseInt(token || 0, 10) | 0;
  28354. },
  28355. readBoolean: function Type1Parser_readBoolean() {
  28356. var token = this.getToken();
  28357. // Use 1 and 0 since that's what type2 charstrings use.
  28358. return token === 'true' ? 1 : 0;
  28359. },
  28360. nextChar : function Type1_nextChar() {
  28361. return (this.currentChar = this.stream.getByte());
  28362. },
  28363. getToken: function Type1Parser_getToken() {
  28364. // Eat whitespace and comments.
  28365. var comment = false;
  28366. var ch = this.currentChar;
  28367. while (true) {
  28368. if (ch === -1) {
  28369. return null;
  28370. }
  28371. if (comment) {
  28372. if (ch === 0x0A || ch === 0x0D) {
  28373. comment = false;
  28374. }
  28375. } else if (ch === 0x25) { // '%'
  28376. comment = true;
  28377. } else if (!Lexer.isSpace(ch)) {
  28378. break;
  28379. }
  28380. ch = this.nextChar();
  28381. }
  28382. if (isSpecial(ch)) {
  28383. this.nextChar();
  28384. return String.fromCharCode(ch);
  28385. }
  28386. var token = '';
  28387. do {
  28388. token += String.fromCharCode(ch);
  28389. ch = this.nextChar();
  28390. } while (ch >= 0 && !Lexer.isSpace(ch) && !isSpecial(ch));
  28391. return token;
  28392. },
  28393. /*
  28394. * Returns an object containing a Subrs array and a CharStrings
  28395. * array extracted from and eexec encrypted block of data
  28396. */
  28397. extractFontProgram: function Type1Parser_extractFontProgram() {
  28398. var stream = this.stream;
  28399. var subrs = [], charstrings = [];
  28400. var program = {
  28401. subrs: [],
  28402. charstrings: [],
  28403. properties: {
  28404. 'privateData': {
  28405. 'lenIV': 4
  28406. }
  28407. }
  28408. };
  28409. var token, length, data, lenIV, encoded;
  28410. while ((token = this.getToken()) !== null) {
  28411. if (token !== '/') {
  28412. continue;
  28413. }
  28414. token = this.getToken();
  28415. switch (token) {
  28416. case 'CharStrings':
  28417. // The number immediately following CharStrings must be greater or
  28418. // equal to the number of CharStrings.
  28419. this.getToken();
  28420. this.getToken(); // read in 'dict'
  28421. this.getToken(); // read in 'dup'
  28422. this.getToken(); // read in 'begin'
  28423. while(true) {
  28424. token = this.getToken();
  28425. if (token === null || token === 'end') {
  28426. break;
  28427. }
  28428. if (token !== '/') {
  28429. continue;
  28430. }
  28431. var glyph = this.getToken();
  28432. length = this.readInt();
  28433. this.getToken(); // read in 'RD' or '-|'
  28434. data = stream.makeSubStream(stream.pos, length);
  28435. lenIV = program.properties.privateData['lenIV'];
  28436. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  28437. // Skip past the required space and binary data.
  28438. stream.skip(length);
  28439. this.nextChar();
  28440. token = this.getToken(); // read in 'ND' or '|-'
  28441. if (token === 'noaccess') {
  28442. this.getToken(); // read in 'def'
  28443. }
  28444. charstrings.push({
  28445. glyph: glyph,
  28446. encoded: encoded
  28447. });
  28448. }
  28449. break;
  28450. case 'Subrs':
  28451. var num = this.readInt();
  28452. this.getToken(); // read in 'array'
  28453. while ((token = this.getToken()) === 'dup') {
  28454. var index = this.readInt();
  28455. length = this.readInt();
  28456. this.getToken(); // read in 'RD' or '-|'
  28457. data = stream.makeSubStream(stream.pos, length);
  28458. lenIV = program.properties.privateData['lenIV'];
  28459. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  28460. // Skip past the required space and binary data.
  28461. stream.skip(length);
  28462. this.nextChar();
  28463. token = this.getToken(); // read in 'NP' or '|'
  28464. if (token === 'noaccess') {
  28465. this.getToken(); // read in 'put'
  28466. }
  28467. subrs[index] = encoded;
  28468. }
  28469. break;
  28470. case 'BlueValues':
  28471. case 'OtherBlues':
  28472. case 'FamilyBlues':
  28473. case 'FamilyOtherBlues':
  28474. var blueArray = this.readNumberArray();
  28475. // *Blue* values may contain invalid data: disables reading of
  28476. // those values when hinting is disabled.
  28477. if (blueArray.length > 0 && (blueArray.length % 2) === 0 &&
  28478. HINTING_ENABLED) {
  28479. program.properties.privateData[token] = blueArray;
  28480. }
  28481. break;
  28482. case 'StemSnapH':
  28483. case 'StemSnapV':
  28484. program.properties.privateData[token] = this.readNumberArray();
  28485. break;
  28486. case 'StdHW':
  28487. case 'StdVW':
  28488. program.properties.privateData[token] =
  28489. this.readNumberArray()[0];
  28490. break;
  28491. case 'BlueShift':
  28492. case 'lenIV':
  28493. case 'BlueFuzz':
  28494. case 'BlueScale':
  28495. case 'LanguageGroup':
  28496. case 'ExpansionFactor':
  28497. program.properties.privateData[token] = this.readNumber();
  28498. break;
  28499. case 'ForceBold':
  28500. program.properties.privateData[token] = this.readBoolean();
  28501. break;
  28502. }
  28503. }
  28504. for (var i = 0; i < charstrings.length; i++) {
  28505. glyph = charstrings[i].glyph;
  28506. encoded = charstrings[i].encoded;
  28507. var charString = new Type1CharString();
  28508. var error = charString.convert(encoded, subrs);
  28509. var output = charString.output;
  28510. if (error) {
  28511. // It seems when FreeType encounters an error while evaluating a glyph
  28512. // that it completely ignores the glyph so we'll mimic that behaviour
  28513. // here and put an endchar to make the validator happy.
  28514. output = [14];
  28515. }
  28516. program.charstrings.push({
  28517. glyphName: glyph,
  28518. charstring: output,
  28519. width: charString.width,
  28520. lsb: charString.lsb,
  28521. seac: charString.seac
  28522. });
  28523. }
  28524. return program;
  28525. },
  28526. extractFontHeader: function Type1Parser_extractFontHeader(properties) {
  28527. var token;
  28528. while ((token = this.getToken()) !== null) {
  28529. if (token !== '/') {
  28530. continue;
  28531. }
  28532. token = this.getToken();
  28533. switch (token) {
  28534. case 'FontMatrix':
  28535. var matrix = this.readNumberArray();
  28536. properties.fontMatrix = matrix;
  28537. break;
  28538. case 'Encoding':
  28539. var encodingArg = this.getToken();
  28540. var encoding;
  28541. if (!/^\d+$/.test(encodingArg)) {
  28542. // encoding name is specified
  28543. encoding = Encodings[encodingArg];
  28544. } else {
  28545. encoding = [];
  28546. var size = parseInt(encodingArg, 10) | 0;
  28547. this.getToken(); // read in 'array'
  28548. for (var j = 0; j < size; j++) {
  28549. token = this.getToken();
  28550. // skipping till first dup or def (e.g. ignoring for statement)
  28551. while (token !== 'dup' && token !== 'def') {
  28552. token = this.getToken();
  28553. if (token === null) {
  28554. return; // invalid header
  28555. }
  28556. }
  28557. if (token === 'def') {
  28558. break; // read all array data
  28559. }
  28560. var index = this.readInt();
  28561. this.getToken(); // read in '/'
  28562. var glyph = this.getToken();
  28563. encoding[index] = glyph;
  28564. this.getToken(); // read the in 'put'
  28565. }
  28566. }
  28567. properties.builtInEncoding = encoding;
  28568. break;
  28569. case 'FontBBox':
  28570. var fontBBox = this.readNumberArray();
  28571. // adjusting ascent/descent
  28572. properties.ascent = fontBBox[3];
  28573. properties.descent = fontBBox[1];
  28574. properties.ascentScaled = true;
  28575. break;
  28576. }
  28577. }
  28578. }
  28579. };
  28580. return Type1Parser;
  28581. })();
  28582. /**
  28583. * The CFF class takes a Type1 file and wrap it into a
  28584. * 'Compact Font Format' which itself embed Type2 charstrings.
  28585. */
  28586. var CFFStandardStrings = [
  28587. '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  28588. 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus',
  28589. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
  28590. 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',
  28591. 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
  28592. 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
  28593. 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright', 'asciicircum',
  28594. 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
  28595. 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
  28596. 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
  28597. 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  28598. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  28599. 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
  28600. 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase', 'quotedblbase',
  28601. 'quotedblright', 'guillemotright', 'ellipsis', 'perthousand', 'questiondown',
  28602. 'grave', 'acute', 'circumflex', 'tilde', 'macron', 'breve', 'dotaccent',
  28603. 'dieresis', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron', 'emdash',
  28604. 'AE', 'ordfeminine', 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae',
  28605. 'dotlessi', 'lslash', 'oslash', 'oe', 'germandbls', 'onesuperior',
  28606. 'logicalnot', 'mu', 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn',
  28607. 'onequarter', 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters',
  28608. 'twosuperior', 'registered', 'minus', 'eth', 'multiply', 'threesuperior',
  28609. 'copyright', 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring',
  28610. 'Atilde', 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave',
  28611. 'Iacute', 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute',
  28612. 'Ocircumflex', 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute',
  28613. 'Ucircumflex', 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron',
  28614. 'aacute', 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde',
  28615. 'ccedilla', 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute',
  28616. 'icircumflex', 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex',
  28617. 'odieresis', 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex',
  28618. 'udieresis', 'ugrave', 'yacute', 'ydieresis', 'zcaron', 'exclamsmall',
  28619. 'Hungarumlautsmall', 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall',
  28620. 'Acutesmall', 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  28621. 'onedotenleader', 'zerooldstyle', 'oneoldstyle', 'twooldstyle',
  28622. 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle',
  28623. 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'commasuperior',
  28624. 'threequartersemdash', 'periodsuperior', 'questionsmall', 'asuperior',
  28625. 'bsuperior', 'centsuperior', 'dsuperior', 'esuperior', 'isuperior',
  28626. 'lsuperior', 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  28627. 'tsuperior', 'ff', 'ffi', 'ffl', 'parenleftinferior', 'parenrightinferior',
  28628. 'Circumflexsmall', 'hyphensuperior', 'Gravesmall', 'Asmall', 'Bsmall',
  28629. 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall',
  28630. 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall',
  28631. 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
  28632. 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah',
  28633. 'Tildesmall', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall',
  28634. 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall', 'Caronsmall',
  28635. 'Dotaccentsmall', 'Macronsmall', 'figuredash', 'hypheninferior',
  28636. 'Ogoneksmall', 'Ringsmall', 'Cedillasmall', 'questiondownsmall', 'oneeighth',
  28637. 'threeeighths', 'fiveeighths', 'seveneighths', 'onethird', 'twothirds',
  28638. 'zerosuperior', 'foursuperior', 'fivesuperior', 'sixsuperior',
  28639. 'sevensuperior', 'eightsuperior', 'ninesuperior', 'zeroinferior',
  28640. 'oneinferior', 'twoinferior', 'threeinferior', 'fourinferior',
  28641. 'fiveinferior', 'sixinferior', 'seveninferior', 'eightinferior',
  28642. 'nineinferior', 'centinferior', 'dollarinferior', 'periodinferior',
  28643. 'commainferior', 'Agravesmall', 'Aacutesmall', 'Acircumflexsmall',
  28644. 'Atildesmall', 'Adieresissmall', 'Aringsmall', 'AEsmall', 'Ccedillasmall',
  28645. 'Egravesmall', 'Eacutesmall', 'Ecircumflexsmall', 'Edieresissmall',
  28646. 'Igravesmall', 'Iacutesmall', 'Icircumflexsmall', 'Idieresissmall',
  28647. 'Ethsmall', 'Ntildesmall', 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall',
  28648. 'Otildesmall', 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall',
  28649. 'Uacutesmall', 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall',
  28650. 'Thornsmall', 'Ydieresissmall', '001.000', '001.001', '001.002', '001.003',
  28651. 'Black', 'Bold', 'Book', 'Light', 'Medium', 'Regular', 'Roman', 'Semibold'
  28652. ];
  28653. // Type1Font is also a CIDFontType0.
  28654. var Type1Font = function Type1Font(name, file, properties) {
  28655. // Some bad generators embed pfb file as is, we have to strip 6-byte headers.
  28656. // Also, length1 and length2 might be off by 6 bytes as well.
  28657. // http://www.math.ubc.ca/~cass/piscript/type1.pdf
  28658. var PFB_HEADER_SIZE = 6;
  28659. var headerBlockLength = properties.length1;
  28660. var eexecBlockLength = properties.length2;
  28661. var pfbHeader = file.peekBytes(PFB_HEADER_SIZE);
  28662. var pfbHeaderPresent = pfbHeader[0] === 0x80 && pfbHeader[1] === 0x01;
  28663. if (pfbHeaderPresent) {
  28664. file.skip(PFB_HEADER_SIZE);
  28665. headerBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  28666. (pfbHeader[3] << 8) | pfbHeader[2];
  28667. }
  28668. // Get the data block containing glyphs and subrs informations
  28669. var headerBlock = new Stream(file.getBytes(headerBlockLength));
  28670. var headerBlockParser = new Type1Parser(headerBlock);
  28671. headerBlockParser.extractFontHeader(properties);
  28672. if (pfbHeaderPresent) {
  28673. pfbHeader = file.getBytes(PFB_HEADER_SIZE);
  28674. eexecBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  28675. (pfbHeader[3] << 8) | pfbHeader[2];
  28676. }
  28677. // Decrypt the data blocks and retrieve it's content
  28678. var eexecBlock = new Stream(file.getBytes(eexecBlockLength));
  28679. var eexecBlockParser = new Type1Parser(eexecBlock, true);
  28680. var data = eexecBlockParser.extractFontProgram();
  28681. for (var info in data.properties) {
  28682. properties[info] = data.properties[info];
  28683. }
  28684. var charstrings = data.charstrings;
  28685. var type2Charstrings = this.getType2Charstrings(charstrings);
  28686. var subrs = this.getType2Subrs(data.subrs);
  28687. this.charstrings = charstrings;
  28688. this.data = this.wrap(name, type2Charstrings, this.charstrings,
  28689. subrs, properties);
  28690. this.seacs = this.getSeacs(data.charstrings);
  28691. };
  28692. Type1Font.prototype = {
  28693. get numGlyphs() {
  28694. return this.charstrings.length + 1;
  28695. },
  28696. getCharset: function Type1Font_getCharset() {
  28697. var charset = ['.notdef'];
  28698. var charstrings = this.charstrings;
  28699. for (var glyphId = 0; glyphId < charstrings.length; glyphId++) {
  28700. charset.push(charstrings[glyphId].glyphName);
  28701. }
  28702. return charset;
  28703. },
  28704. getGlyphMapping: function Type1Font_getGlyphMapping(properties) {
  28705. var charstrings = this.charstrings;
  28706. var glyphNames = ['.notdef'], glyphId;
  28707. for (glyphId = 0; glyphId < charstrings.length; glyphId++) {
  28708. glyphNames.push(charstrings[glyphId].glyphName);
  28709. }
  28710. var encoding = properties.builtInEncoding;
  28711. if (encoding) {
  28712. var builtInEncoding = {};
  28713. for (var charCode in encoding) {
  28714. glyphId = glyphNames.indexOf(encoding[charCode]);
  28715. if (glyphId >= 0) {
  28716. builtInEncoding[charCode] = glyphId;
  28717. }
  28718. }
  28719. }
  28720. return type1FontGlyphMapping(properties, builtInEncoding, glyphNames);
  28721. },
  28722. getSeacs: function Type1Font_getSeacs(charstrings) {
  28723. var i, ii;
  28724. var seacMap = [];
  28725. for (i = 0, ii = charstrings.length; i < ii; i++) {
  28726. var charstring = charstrings[i];
  28727. if (charstring.seac) {
  28728. // Offset by 1 for .notdef
  28729. seacMap[i + 1] = charstring.seac;
  28730. }
  28731. }
  28732. return seacMap;
  28733. },
  28734. getType2Charstrings: function Type1Font_getType2Charstrings(
  28735. type1Charstrings) {
  28736. var type2Charstrings = [];
  28737. for (var i = 0, ii = type1Charstrings.length; i < ii; i++) {
  28738. type2Charstrings.push(type1Charstrings[i].charstring);
  28739. }
  28740. return type2Charstrings;
  28741. },
  28742. getType2Subrs: function Type1Font_getType2Subrs(type1Subrs) {
  28743. var bias = 0;
  28744. var count = type1Subrs.length;
  28745. if (count < 1133) {
  28746. bias = 107;
  28747. } else if (count < 33769) {
  28748. bias = 1131;
  28749. } else {
  28750. bias = 32768;
  28751. }
  28752. // Add a bunch of empty subrs to deal with the Type2 bias
  28753. var type2Subrs = [];
  28754. var i;
  28755. for (i = 0; i < bias; i++) {
  28756. type2Subrs.push([0x0B]);
  28757. }
  28758. for (i = 0; i < count; i++) {
  28759. type2Subrs.push(type1Subrs[i]);
  28760. }
  28761. return type2Subrs;
  28762. },
  28763. wrap: function Type1Font_wrap(name, glyphs, charstrings, subrs, properties) {
  28764. var cff = new CFF();
  28765. cff.header = new CFFHeader(1, 0, 4, 4);
  28766. cff.names = [name];
  28767. var topDict = new CFFTopDict();
  28768. // CFF strings IDs 0...390 are predefined names, so refering
  28769. // to entries in our own String INDEX starts at SID 391.
  28770. topDict.setByName('version', 391);
  28771. topDict.setByName('Notice', 392);
  28772. topDict.setByName('FullName', 393);
  28773. topDict.setByName('FamilyName', 394);
  28774. topDict.setByName('Weight', 395);
  28775. topDict.setByName('Encoding', null); // placeholder
  28776. topDict.setByName('FontMatrix', properties.fontMatrix);
  28777. topDict.setByName('FontBBox', properties.bbox);
  28778. topDict.setByName('charset', null); // placeholder
  28779. topDict.setByName('CharStrings', null); // placeholder
  28780. topDict.setByName('Private', null); // placeholder
  28781. cff.topDict = topDict;
  28782. var strings = new CFFStrings();
  28783. strings.add('Version 0.11'); // Version
  28784. strings.add('See original notice'); // Notice
  28785. strings.add(name); // FullName
  28786. strings.add(name); // FamilyName
  28787. strings.add('Medium'); // Weight
  28788. cff.strings = strings;
  28789. cff.globalSubrIndex = new CFFIndex();
  28790. var count = glyphs.length;
  28791. var charsetArray = [0];
  28792. var i, ii;
  28793. for (i = 0; i < count; i++) {
  28794. var index = CFFStandardStrings.indexOf(charstrings[i].glyphName);
  28795. // TODO: Insert the string and correctly map it. Previously it was
  28796. // thought mapping names that aren't in the standard strings to .notdef
  28797. // was fine, however in issue818 when mapping them all to .notdef the
  28798. // adieresis glyph no longer worked.
  28799. if (index === -1) {
  28800. index = 0;
  28801. }
  28802. charsetArray.push((index >> 8) & 0xff, index & 0xff);
  28803. }
  28804. cff.charset = new CFFCharset(false, 0, [], charsetArray);
  28805. var charStringsIndex = new CFFIndex();
  28806. charStringsIndex.add([0x8B, 0x0E]); // .notdef
  28807. for (i = 0; i < count; i++) {
  28808. charStringsIndex.add(glyphs[i]);
  28809. }
  28810. cff.charStrings = charStringsIndex;
  28811. var privateDict = new CFFPrivateDict();
  28812. privateDict.setByName('Subrs', null); // placeholder
  28813. var fields = [
  28814. 'BlueValues',
  28815. 'OtherBlues',
  28816. 'FamilyBlues',
  28817. 'FamilyOtherBlues',
  28818. 'StemSnapH',
  28819. 'StemSnapV',
  28820. 'BlueShift',
  28821. 'BlueFuzz',
  28822. 'BlueScale',
  28823. 'LanguageGroup',
  28824. 'ExpansionFactor',
  28825. 'ForceBold',
  28826. 'StdHW',
  28827. 'StdVW'
  28828. ];
  28829. for (i = 0, ii = fields.length; i < ii; i++) {
  28830. var field = fields[i];
  28831. if (!properties.privateData.hasOwnProperty(field)) {
  28832. continue;
  28833. }
  28834. var value = properties.privateData[field];
  28835. if (isArray(value)) {
  28836. // All of the private dictionary array data in CFF must be stored as
  28837. // "delta-encoded" numbers.
  28838. for (var j = value.length - 1; j > 0; j--) {
  28839. value[j] -= value[j - 1]; // ... difference from previous value
  28840. }
  28841. }
  28842. privateDict.setByName(field, value);
  28843. }
  28844. cff.topDict.privateDict = privateDict;
  28845. var subrIndex = new CFFIndex();
  28846. for (i = 0, ii = subrs.length; i < ii; i++) {
  28847. subrIndex.add(subrs[i]);
  28848. }
  28849. privateDict.subrsIndex = subrIndex;
  28850. var compiler = new CFFCompiler(cff);
  28851. return compiler.compile();
  28852. }
  28853. };
  28854. var CFFFont = (function CFFFontClosure() {
  28855. function CFFFont(file, properties) {
  28856. this.properties = properties;
  28857. var parser = new CFFParser(file, properties);
  28858. this.cff = parser.parse();
  28859. var compiler = new CFFCompiler(this.cff);
  28860. this.seacs = this.cff.seacs;
  28861. try {
  28862. this.data = compiler.compile();
  28863. } catch (e) {
  28864. warn('Failed to compile font ' + properties.loadedName);
  28865. // There may have just been an issue with the compiler, set the data
  28866. // anyway and hope the font loaded.
  28867. this.data = file;
  28868. }
  28869. }
  28870. CFFFont.prototype = {
  28871. get numGlyphs() {
  28872. return this.cff.charStrings.count;
  28873. },
  28874. getCharset: function CFFFont_getCharset() {
  28875. return this.cff.charset.charset;
  28876. },
  28877. getGlyphMapping: function CFFFont_getGlyphMapping() {
  28878. var cff = this.cff;
  28879. var properties = this.properties;
  28880. var charsets = cff.charset.charset;
  28881. var charCodeToGlyphId;
  28882. var glyphId;
  28883. if (properties.composite) {
  28884. charCodeToGlyphId = Object.create(null);
  28885. if (cff.isCIDFont) {
  28886. // If the font is actually a CID font then we should use the charset
  28887. // to map CIDs to GIDs.
  28888. for (glyphId = 0; glyphId < charsets.length; glyphId++) {
  28889. var cid = charsets[glyphId];
  28890. var charCode = properties.cMap.charCodeOf(cid);
  28891. charCodeToGlyphId[charCode] = glyphId;
  28892. }
  28893. } else {
  28894. // If it is NOT actually a CID font then CIDs should be mapped
  28895. // directly to GIDs.
  28896. for (glyphId = 0; glyphId < cff.charStrings.count; glyphId++) {
  28897. charCodeToGlyphId[glyphId] = glyphId;
  28898. }
  28899. }
  28900. return charCodeToGlyphId;
  28901. }
  28902. var encoding = cff.encoding ? cff.encoding.encoding : null;
  28903. charCodeToGlyphId = type1FontGlyphMapping(properties, encoding, charsets);
  28904. return charCodeToGlyphId;
  28905. }
  28906. };
  28907. return CFFFont;
  28908. })();
  28909. var CFFParser = (function CFFParserClosure() {
  28910. var CharstringValidationData = [
  28911. null,
  28912. { id: 'hstem', min: 2, stackClearing: true, stem: true },
  28913. null,
  28914. { id: 'vstem', min: 2, stackClearing: true, stem: true },
  28915. { id: 'vmoveto', min: 1, stackClearing: true },
  28916. { id: 'rlineto', min: 2, resetStack: true },
  28917. { id: 'hlineto', min: 1, resetStack: true },
  28918. { id: 'vlineto', min: 1, resetStack: true },
  28919. { id: 'rrcurveto', min: 6, resetStack: true },
  28920. null,
  28921. { id: 'callsubr', min: 1, undefStack: true },
  28922. { id: 'return', min: 0, undefStack: true },
  28923. null, // 12
  28924. null,
  28925. { id: 'endchar', min: 0, stackClearing: true },
  28926. null,
  28927. null,
  28928. null,
  28929. { id: 'hstemhm', min: 2, stackClearing: true, stem: true },
  28930. { id: 'hintmask', min: 0, stackClearing: true },
  28931. { id: 'cntrmask', min: 0, stackClearing: true },
  28932. { id: 'rmoveto', min: 2, stackClearing: true },
  28933. { id: 'hmoveto', min: 1, stackClearing: true },
  28934. { id: 'vstemhm', min: 2, stackClearing: true, stem: true },
  28935. { id: 'rcurveline', min: 8, resetStack: true },
  28936. { id: 'rlinecurve', min: 8, resetStack: true },
  28937. { id: 'vvcurveto', min: 4, resetStack: true },
  28938. { id: 'hhcurveto', min: 4, resetStack: true },
  28939. null, // shortint
  28940. { id: 'callgsubr', min: 1, undefStack: true },
  28941. { id: 'vhcurveto', min: 4, resetStack: true },
  28942. { id: 'hvcurveto', min: 4, resetStack: true }
  28943. ];
  28944. var CharstringValidationData12 = [
  28945. null,
  28946. null,
  28947. null,
  28948. { id: 'and', min: 2, stackDelta: -1 },
  28949. { id: 'or', min: 2, stackDelta: -1 },
  28950. { id: 'not', min: 1, stackDelta: 0 },
  28951. null,
  28952. null,
  28953. null,
  28954. { id: 'abs', min: 1, stackDelta: 0 },
  28955. { id: 'add', min: 2, stackDelta: -1,
  28956. stackFn: function stack_div(stack, index) {
  28957. stack[index - 2] = stack[index - 2] + stack[index - 1];
  28958. }
  28959. },
  28960. { id: 'sub', min: 2, stackDelta: -1,
  28961. stackFn: function stack_div(stack, index) {
  28962. stack[index - 2] = stack[index - 2] - stack[index - 1];
  28963. }
  28964. },
  28965. { id: 'div', min: 2, stackDelta: -1,
  28966. stackFn: function stack_div(stack, index) {
  28967. stack[index - 2] = stack[index - 2] / stack[index - 1];
  28968. }
  28969. },
  28970. null,
  28971. { id: 'neg', min: 1, stackDelta: 0,
  28972. stackFn: function stack_div(stack, index) {
  28973. stack[index - 1] = -stack[index - 1];
  28974. }
  28975. },
  28976. { id: 'eq', min: 2, stackDelta: -1 },
  28977. null,
  28978. null,
  28979. { id: 'drop', min: 1, stackDelta: -1 },
  28980. null,
  28981. { id: 'put', min: 2, stackDelta: -2 },
  28982. { id: 'get', min: 1, stackDelta: 0 },
  28983. { id: 'ifelse', min: 4, stackDelta: -3 },
  28984. { id: 'random', min: 0, stackDelta: 1 },
  28985. { id: 'mul', min: 2, stackDelta: -1,
  28986. stackFn: function stack_div(stack, index) {
  28987. stack[index - 2] = stack[index - 2] * stack[index - 1];
  28988. }
  28989. },
  28990. null,
  28991. { id: 'sqrt', min: 1, stackDelta: 0 },
  28992. { id: 'dup', min: 1, stackDelta: 1 },
  28993. { id: 'exch', min: 2, stackDelta: 0 },
  28994. { id: 'index', min: 2, stackDelta: 0 },
  28995. { id: 'roll', min: 3, stackDelta: -2 },
  28996. null,
  28997. null,
  28998. null,
  28999. { id: 'hflex', min: 7, resetStack: true },
  29000. { id: 'flex', min: 13, resetStack: true },
  29001. { id: 'hflex1', min: 9, resetStack: true },
  29002. { id: 'flex1', min: 11, resetStack: true }
  29003. ];
  29004. function CFFParser(file, properties) {
  29005. this.bytes = file.getBytes();
  29006. this.properties = properties;
  29007. }
  29008. CFFParser.prototype = {
  29009. parse: function CFFParser_parse() {
  29010. var properties = this.properties;
  29011. var cff = new CFF();
  29012. this.cff = cff;
  29013. // The first five sections must be in order, all the others are reached
  29014. // via offsets contained in one of the below.
  29015. var header = this.parseHeader();
  29016. var nameIndex = this.parseIndex(header.endPos);
  29017. var topDictIndex = this.parseIndex(nameIndex.endPos);
  29018. var stringIndex = this.parseIndex(topDictIndex.endPos);
  29019. var globalSubrIndex = this.parseIndex(stringIndex.endPos);
  29020. var topDictParsed = this.parseDict(topDictIndex.obj.get(0));
  29021. var topDict = this.createDict(CFFTopDict, topDictParsed, cff.strings);
  29022. cff.header = header.obj;
  29023. cff.names = this.parseNameIndex(nameIndex.obj);
  29024. cff.strings = this.parseStringIndex(stringIndex.obj);
  29025. cff.topDict = topDict;
  29026. cff.globalSubrIndex = globalSubrIndex.obj;
  29027. this.parsePrivateDict(cff.topDict);
  29028. cff.isCIDFont = topDict.hasName('ROS');
  29029. var charStringOffset = topDict.getByName('CharStrings');
  29030. var charStringsAndSeacs = this.parseCharStrings(charStringOffset);
  29031. cff.charStrings = charStringsAndSeacs.charStrings;
  29032. cff.seacs = charStringsAndSeacs.seacs;
  29033. cff.widths = charStringsAndSeacs.widths;
  29034. var fontMatrix = topDict.getByName('FontMatrix');
  29035. if (fontMatrix) {
  29036. properties.fontMatrix = fontMatrix;
  29037. }
  29038. var fontBBox = topDict.getByName('FontBBox');
  29039. if (fontBBox) {
  29040. // adjusting ascent/descent
  29041. properties.ascent = fontBBox[3];
  29042. properties.descent = fontBBox[1];
  29043. properties.ascentScaled = true;
  29044. }
  29045. var charset, encoding;
  29046. if (cff.isCIDFont) {
  29047. var fdArrayIndex = this.parseIndex(topDict.getByName('FDArray')).obj;
  29048. for (var i = 0, ii = fdArrayIndex.count; i < ii; ++i) {
  29049. var dictRaw = fdArrayIndex.get(i);
  29050. var fontDict = this.createDict(CFFTopDict, this.parseDict(dictRaw),
  29051. cff.strings);
  29052. this.parsePrivateDict(fontDict);
  29053. cff.fdArray.push(fontDict);
  29054. }
  29055. // cid fonts don't have an encoding
  29056. encoding = null;
  29057. charset = this.parseCharsets(topDict.getByName('charset'),
  29058. cff.charStrings.count, cff.strings, true);
  29059. cff.fdSelect = this.parseFDSelect(topDict.getByName('FDSelect'),
  29060. cff.charStrings.count);
  29061. } else {
  29062. charset = this.parseCharsets(topDict.getByName('charset'),
  29063. cff.charStrings.count, cff.strings, false);
  29064. encoding = this.parseEncoding(topDict.getByName('Encoding'),
  29065. properties,
  29066. cff.strings, charset.charset);
  29067. }
  29068. cff.charset = charset;
  29069. cff.encoding = encoding;
  29070. return cff;
  29071. },
  29072. parseHeader: function CFFParser_parseHeader() {
  29073. var bytes = this.bytes;
  29074. var bytesLength = bytes.length;
  29075. var offset = 0;
  29076. // Prevent an infinite loop, by checking that the offset is within the
  29077. // bounds of the bytes array. Necessary in empty, or invalid, font files.
  29078. while (offset < bytesLength && bytes[offset] !== 1) {
  29079. ++offset;
  29080. }
  29081. if (offset >= bytesLength) {
  29082. error('Invalid CFF header');
  29083. } else if (offset !== 0) {
  29084. info('cff data is shifted');
  29085. bytes = bytes.subarray(offset);
  29086. this.bytes = bytes;
  29087. }
  29088. var major = bytes[0];
  29089. var minor = bytes[1];
  29090. var hdrSize = bytes[2];
  29091. var offSize = bytes[3];
  29092. var header = new CFFHeader(major, minor, hdrSize, offSize);
  29093. return { obj: header, endPos: hdrSize };
  29094. },
  29095. parseDict: function CFFParser_parseDict(dict) {
  29096. var pos = 0;
  29097. function parseOperand() {
  29098. var value = dict[pos++];
  29099. if (value === 30) {
  29100. return parseFloatOperand(pos);
  29101. } else if (value === 28) {
  29102. value = dict[pos++];
  29103. value = ((value << 24) | (dict[pos++] << 16)) >> 16;
  29104. return value;
  29105. } else if (value === 29) {
  29106. value = dict[pos++];
  29107. value = (value << 8) | dict[pos++];
  29108. value = (value << 8) | dict[pos++];
  29109. value = (value << 8) | dict[pos++];
  29110. return value;
  29111. } else if (value >= 32 && value <= 246) {
  29112. return value - 139;
  29113. } else if (value >= 247 && value <= 250) {
  29114. return ((value - 247) * 256) + dict[pos++] + 108;
  29115. } else if (value >= 251 && value <= 254) {
  29116. return -((value - 251) * 256) - dict[pos++] - 108;
  29117. } else {
  29118. error('255 is not a valid DICT command');
  29119. }
  29120. return -1;
  29121. }
  29122. function parseFloatOperand() {
  29123. var str = '';
  29124. var eof = 15;
  29125. var lookup = ['0', '1', '2', '3', '4', '5', '6', '7', '8',
  29126. '9', '.', 'E', 'E-', null, '-'];
  29127. var length = dict.length;
  29128. while (pos < length) {
  29129. var b = dict[pos++];
  29130. var b1 = b >> 4;
  29131. var b2 = b & 15;
  29132. if (b1 === eof) {
  29133. break;
  29134. }
  29135. str += lookup[b1];
  29136. if (b2 === eof) {
  29137. break;
  29138. }
  29139. str += lookup[b2];
  29140. }
  29141. return parseFloat(str);
  29142. }
  29143. var operands = [];
  29144. var entries = [];
  29145. pos = 0;
  29146. var end = dict.length;
  29147. while (pos < end) {
  29148. var b = dict[pos];
  29149. if (b <= 21) {
  29150. if (b === 12) {
  29151. b = (b << 8) | dict[++pos];
  29152. }
  29153. entries.push([b, operands]);
  29154. operands = [];
  29155. ++pos;
  29156. } else {
  29157. operands.push(parseOperand());
  29158. }
  29159. }
  29160. return entries;
  29161. },
  29162. parseIndex: function CFFParser_parseIndex(pos) {
  29163. var cffIndex = new CFFIndex();
  29164. var bytes = this.bytes;
  29165. var count = (bytes[pos++] << 8) | bytes[pos++];
  29166. var offsets = [];
  29167. var end = pos;
  29168. var i, ii;
  29169. if (count !== 0) {
  29170. var offsetSize = bytes[pos++];
  29171. // add 1 for offset to determine size of last object
  29172. var startPos = pos + ((count + 1) * offsetSize) - 1;
  29173. for (i = 0, ii = count + 1; i < ii; ++i) {
  29174. var offset = 0;
  29175. for (var j = 0; j < offsetSize; ++j) {
  29176. offset <<= 8;
  29177. offset += bytes[pos++];
  29178. }
  29179. offsets.push(startPos + offset);
  29180. }
  29181. end = offsets[count];
  29182. }
  29183. for (i = 0, ii = offsets.length - 1; i < ii; ++i) {
  29184. var offsetStart = offsets[i];
  29185. var offsetEnd = offsets[i + 1];
  29186. cffIndex.add(bytes.subarray(offsetStart, offsetEnd));
  29187. }
  29188. return {obj: cffIndex, endPos: end};
  29189. },
  29190. parseNameIndex: function CFFParser_parseNameIndex(index) {
  29191. var names = [];
  29192. for (var i = 0, ii = index.count; i < ii; ++i) {
  29193. var name = index.get(i);
  29194. // OTS doesn't allow names to be over 127 characters.
  29195. var length = Math.min(name.length, 127);
  29196. var data = [];
  29197. // OTS also only permits certain characters in the name.
  29198. for (var j = 0; j < length; ++j) {
  29199. var c = name[j];
  29200. if (j === 0 && c === 0) {
  29201. data[j] = c;
  29202. continue;
  29203. }
  29204. if ((c < 33 || c > 126) || c === 91 /* [ */ || c === 93 /* ] */ ||
  29205. c === 40 /* ( */ || c === 41 /* ) */ || c === 123 /* { */ ||
  29206. c === 125 /* } */ || c === 60 /* < */ || c === 62 /* > */ ||
  29207. c === 47 /* / */ || c === 37 /* % */ || c === 35 /* # */) {
  29208. data[j] = 95;
  29209. continue;
  29210. }
  29211. data[j] = c;
  29212. }
  29213. names.push(bytesToString(data));
  29214. }
  29215. return names;
  29216. },
  29217. parseStringIndex: function CFFParser_parseStringIndex(index) {
  29218. var strings = new CFFStrings();
  29219. for (var i = 0, ii = index.count; i < ii; ++i) {
  29220. var data = index.get(i);
  29221. strings.add(bytesToString(data));
  29222. }
  29223. return strings;
  29224. },
  29225. createDict: function CFFParser_createDict(Type, dict, strings) {
  29226. var cffDict = new Type(strings);
  29227. for (var i = 0, ii = dict.length; i < ii; ++i) {
  29228. var pair = dict[i];
  29229. var key = pair[0];
  29230. var value = pair[1];
  29231. cffDict.setByKey(key, value);
  29232. }
  29233. return cffDict;
  29234. },
  29235. parseCharStrings: function CFFParser_parseCharStrings(charStringOffset) {
  29236. var charStrings = this.parseIndex(charStringOffset).obj;
  29237. var seacs = [];
  29238. var widths = [];
  29239. var count = charStrings.count;
  29240. for (var i = 0; i < count; i++) {
  29241. var charstring = charStrings.get(i);
  29242. var stackSize = 0;
  29243. var stack = [];
  29244. var undefStack = true;
  29245. var hints = 0;
  29246. var valid = true;
  29247. var data = charstring;
  29248. var length = data.length;
  29249. var firstStackClearing = true;
  29250. for (var j = 0; j < length;) {
  29251. var value = data[j++];
  29252. var validationCommand = null;
  29253. if (value === 12) {
  29254. var q = data[j++];
  29255. if (q === 0) {
  29256. // The CFF specification state that the 'dotsection' command
  29257. // (12, 0) is deprecated and treated as a no-op, but all Type2
  29258. // charstrings processors should support them. Unfortunately
  29259. // the font sanitizer don't. As a workaround the sequence (12, 0)
  29260. // is replaced by a useless (0, hmoveto).
  29261. data[j - 2] = 139;
  29262. data[j - 1] = 22;
  29263. stackSize = 0;
  29264. } else {
  29265. validationCommand = CharstringValidationData12[q];
  29266. }
  29267. } else if (value === 28) { // number (16 bit)
  29268. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16)) >> 16;
  29269. j += 2;
  29270. stackSize++;
  29271. } else if (value === 14) {
  29272. if (stackSize >= 4) {
  29273. stackSize -= 4;
  29274. if (SEAC_ANALYSIS_ENABLED) {
  29275. seacs[i] = stack.slice(stackSize, stackSize + 4);
  29276. valid = false;
  29277. }
  29278. }
  29279. validationCommand = CharstringValidationData[value];
  29280. } else if (value >= 32 && value <= 246) { // number
  29281. stack[stackSize] = value - 139;
  29282. stackSize++;
  29283. } else if (value >= 247 && value <= 254) { // number (+1 bytes)
  29284. stack[stackSize] = (value < 251 ?
  29285. ((value - 247) << 8) + data[j] + 108 :
  29286. -((value - 251) << 8) - data[j] - 108);
  29287. j++;
  29288. stackSize++;
  29289. } else if (value === 255) { // number (32 bit)
  29290. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16) |
  29291. (data[j + 2] << 8) | data[j + 3]) / 65536;
  29292. j += 4;
  29293. stackSize++;
  29294. } else if (value === 19 || value === 20) {
  29295. hints += stackSize >> 1;
  29296. j += (hints + 7) >> 3; // skipping right amount of hints flag data
  29297. stackSize %= 2;
  29298. validationCommand = CharstringValidationData[value];
  29299. } else {
  29300. validationCommand = CharstringValidationData[value];
  29301. }
  29302. if (validationCommand) {
  29303. if (validationCommand.stem) {
  29304. hints += stackSize >> 1;
  29305. }
  29306. if ('min' in validationCommand) {
  29307. if (!undefStack && stackSize < validationCommand.min) {
  29308. warn('Not enough parameters for ' + validationCommand.id +
  29309. '; actual: ' + stackSize +
  29310. ', expected: ' + validationCommand.min);
  29311. valid = false;
  29312. break;
  29313. }
  29314. }
  29315. if (firstStackClearing && validationCommand.stackClearing) {
  29316. firstStackClearing = false;
  29317. // the optional character width can be found before the first
  29318. // stack-clearing command arguments
  29319. stackSize -= validationCommand.min;
  29320. if (stackSize >= 2 && validationCommand.stem) {
  29321. // there are even amount of arguments for stem commands
  29322. stackSize %= 2;
  29323. } else if (stackSize > 1) {
  29324. warn('Found too many parameters for stack-clearing command');
  29325. }
  29326. if (stackSize > 0 && stack[stackSize - 1] >= 0) {
  29327. widths[i] = stack[stackSize - 1];
  29328. }
  29329. }
  29330. if ('stackDelta' in validationCommand) {
  29331. if ('stackFn' in validationCommand) {
  29332. validationCommand.stackFn(stack, stackSize);
  29333. }
  29334. stackSize += validationCommand.stackDelta;
  29335. } else if (validationCommand.stackClearing) {
  29336. stackSize = 0;
  29337. } else if (validationCommand.resetStack) {
  29338. stackSize = 0;
  29339. undefStack = false;
  29340. } else if (validationCommand.undefStack) {
  29341. stackSize = 0;
  29342. undefStack = true;
  29343. firstStackClearing = false;
  29344. }
  29345. }
  29346. }
  29347. if (!valid) {
  29348. // resetting invalid charstring to single 'endchar'
  29349. charStrings.set(i, new Uint8Array([14]));
  29350. }
  29351. }
  29352. return { charStrings: charStrings, seacs: seacs, widths: widths };
  29353. },
  29354. emptyPrivateDictionary:
  29355. function CFFParser_emptyPrivateDictionary(parentDict) {
  29356. var privateDict = this.createDict(CFFPrivateDict, [],
  29357. parentDict.strings);
  29358. parentDict.setByKey(18, [0, 0]);
  29359. parentDict.privateDict = privateDict;
  29360. },
  29361. parsePrivateDict: function CFFParser_parsePrivateDict(parentDict) {
  29362. // no private dict, do nothing
  29363. if (!parentDict.hasName('Private')) {
  29364. this.emptyPrivateDictionary(parentDict);
  29365. return;
  29366. }
  29367. var privateOffset = parentDict.getByName('Private');
  29368. // make sure the params are formatted correctly
  29369. if (!isArray(privateOffset) || privateOffset.length !== 2) {
  29370. parentDict.removeByName('Private');
  29371. return;
  29372. }
  29373. var size = privateOffset[0];
  29374. var offset = privateOffset[1];
  29375. // remove empty dicts or ones that refer to invalid location
  29376. if (size === 0 || offset >= this.bytes.length) {
  29377. this.emptyPrivateDictionary(parentDict);
  29378. return;
  29379. }
  29380. var privateDictEnd = offset + size;
  29381. var dictData = this.bytes.subarray(offset, privateDictEnd);
  29382. var dict = this.parseDict(dictData);
  29383. var privateDict = this.createDict(CFFPrivateDict, dict,
  29384. parentDict.strings);
  29385. parentDict.privateDict = privateDict;
  29386. // Parse the Subrs index also since it's relative to the private dict.
  29387. if (!privateDict.getByName('Subrs')) {
  29388. return;
  29389. }
  29390. var subrsOffset = privateDict.getByName('Subrs');
  29391. var relativeOffset = offset + subrsOffset;
  29392. // Validate the offset.
  29393. if (subrsOffset === 0 || relativeOffset >= this.bytes.length) {
  29394. this.emptyPrivateDictionary(parentDict);
  29395. return;
  29396. }
  29397. var subrsIndex = this.parseIndex(relativeOffset);
  29398. privateDict.subrsIndex = subrsIndex.obj;
  29399. },
  29400. parseCharsets: function CFFParser_parseCharsets(pos, length, strings, cid) {
  29401. if (pos === 0) {
  29402. return new CFFCharset(true, CFFCharsetPredefinedTypes.ISO_ADOBE,
  29403. ISOAdobeCharset);
  29404. } else if (pos === 1) {
  29405. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT,
  29406. ExpertCharset);
  29407. } else if (pos === 2) {
  29408. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT_SUBSET,
  29409. ExpertSubsetCharset);
  29410. }
  29411. var bytes = this.bytes;
  29412. var start = pos;
  29413. var format = bytes[pos++];
  29414. var charset = ['.notdef'];
  29415. var id, count, i;
  29416. // subtract 1 for the .notdef glyph
  29417. length -= 1;
  29418. switch (format) {
  29419. case 0:
  29420. for (i = 0; i < length; i++) {
  29421. id = (bytes[pos++] << 8) | bytes[pos++];
  29422. charset.push(cid ? id : strings.get(id));
  29423. }
  29424. break;
  29425. case 1:
  29426. while (charset.length <= length) {
  29427. id = (bytes[pos++] << 8) | bytes[pos++];
  29428. count = bytes[pos++];
  29429. for (i = 0; i <= count; i++) {
  29430. charset.push(cid ? id++ : strings.get(id++));
  29431. }
  29432. }
  29433. break;
  29434. case 2:
  29435. while (charset.length <= length) {
  29436. id = (bytes[pos++] << 8) | bytes[pos++];
  29437. count = (bytes[pos++] << 8) | bytes[pos++];
  29438. for (i = 0; i <= count; i++) {
  29439. charset.push(cid ? id++ : strings.get(id++));
  29440. }
  29441. }
  29442. break;
  29443. default:
  29444. error('Unknown charset format');
  29445. }
  29446. // Raw won't be needed if we actually compile the charset.
  29447. var end = pos;
  29448. var raw = bytes.subarray(start, end);
  29449. return new CFFCharset(false, format, charset, raw);
  29450. },
  29451. parseEncoding: function CFFParser_parseEncoding(pos,
  29452. properties,
  29453. strings,
  29454. charset) {
  29455. var encoding = {};
  29456. var bytes = this.bytes;
  29457. var predefined = false;
  29458. var hasSupplement = false;
  29459. var format, i, ii;
  29460. var raw = null;
  29461. function readSupplement() {
  29462. var supplementsCount = bytes[pos++];
  29463. for (i = 0; i < supplementsCount; i++) {
  29464. var code = bytes[pos++];
  29465. var sid = (bytes[pos++] << 8) + (bytes[pos++] & 0xff);
  29466. encoding[code] = charset.indexOf(strings.get(sid));
  29467. }
  29468. }
  29469. if (pos === 0 || pos === 1) {
  29470. predefined = true;
  29471. format = pos;
  29472. var baseEncoding = pos ? Encodings.ExpertEncoding :
  29473. Encodings.StandardEncoding;
  29474. for (i = 0, ii = charset.length; i < ii; i++) {
  29475. var index = baseEncoding.indexOf(charset[i]);
  29476. if (index !== -1) {
  29477. encoding[index] = i;
  29478. }
  29479. }
  29480. } else {
  29481. var dataStart = pos;
  29482. format = bytes[pos++];
  29483. switch (format & 0x7f) {
  29484. case 0:
  29485. var glyphsCount = bytes[pos++];
  29486. for (i = 1; i <= glyphsCount; i++) {
  29487. encoding[bytes[pos++]] = i;
  29488. }
  29489. break;
  29490. case 1:
  29491. var rangesCount = bytes[pos++];
  29492. var gid = 1;
  29493. for (i = 0; i < rangesCount; i++) {
  29494. var start = bytes[pos++];
  29495. var left = bytes[pos++];
  29496. for (var j = start; j <= start + left; j++) {
  29497. encoding[j] = gid++;
  29498. }
  29499. }
  29500. break;
  29501. default:
  29502. error('Unknow encoding format: ' + format + ' in CFF');
  29503. break;
  29504. }
  29505. var dataEnd = pos;
  29506. if (format & 0x80) {
  29507. // The font sanitizer does not support CFF encoding with a
  29508. // supplement, since the encoding is not really used to map
  29509. // between gid to glyph, let's overwrite what is declared in
  29510. // the top dictionary to let the sanitizer think the font use
  29511. // StandardEncoding, that's a lie but that's ok.
  29512. bytes[dataStart] &= 0x7f;
  29513. readSupplement();
  29514. hasSupplement = true;
  29515. }
  29516. raw = bytes.subarray(dataStart, dataEnd);
  29517. }
  29518. format = format & 0x7f;
  29519. return new CFFEncoding(predefined, format, encoding, raw);
  29520. },
  29521. parseFDSelect: function CFFParser_parseFDSelect(pos, length) {
  29522. var start = pos;
  29523. var bytes = this.bytes;
  29524. var format = bytes[pos++];
  29525. var fdSelect = [];
  29526. var i;
  29527. switch (format) {
  29528. case 0:
  29529. for (i = 0; i < length; ++i) {
  29530. var id = bytes[pos++];
  29531. fdSelect.push(id);
  29532. }
  29533. break;
  29534. case 3:
  29535. var rangesCount = (bytes[pos++] << 8) | bytes[pos++];
  29536. for (i = 0; i < rangesCount; ++i) {
  29537. var first = (bytes[pos++] << 8) | bytes[pos++];
  29538. var fdIndex = bytes[pos++];
  29539. var next = (bytes[pos] << 8) | bytes[pos + 1];
  29540. for (var j = first; j < next; ++j) {
  29541. fdSelect.push(fdIndex);
  29542. }
  29543. }
  29544. // Advance past the sentinel(next).
  29545. pos += 2;
  29546. break;
  29547. default:
  29548. error('Unknown fdselect format ' + format);
  29549. break;
  29550. }
  29551. var end = pos;
  29552. return new CFFFDSelect(fdSelect, bytes.subarray(start, end));
  29553. }
  29554. };
  29555. return CFFParser;
  29556. })();
  29557. // Compact Font Format
  29558. var CFF = (function CFFClosure() {
  29559. function CFF() {
  29560. this.header = null;
  29561. this.names = [];
  29562. this.topDict = null;
  29563. this.strings = new CFFStrings();
  29564. this.globalSubrIndex = null;
  29565. // The following could really be per font, but since we only have one font
  29566. // store them here.
  29567. this.encoding = null;
  29568. this.charset = null;
  29569. this.charStrings = null;
  29570. this.fdArray = [];
  29571. this.fdSelect = null;
  29572. this.isCIDFont = false;
  29573. }
  29574. return CFF;
  29575. })();
  29576. var CFFHeader = (function CFFHeaderClosure() {
  29577. function CFFHeader(major, minor, hdrSize, offSize) {
  29578. this.major = major;
  29579. this.minor = minor;
  29580. this.hdrSize = hdrSize;
  29581. this.offSize = offSize;
  29582. }
  29583. return CFFHeader;
  29584. })();
  29585. var CFFStrings = (function CFFStringsClosure() {
  29586. function CFFStrings() {
  29587. this.strings = [];
  29588. }
  29589. CFFStrings.prototype = {
  29590. get: function CFFStrings_get(index) {
  29591. if (index >= 0 && index <= 390) {
  29592. return CFFStandardStrings[index];
  29593. }
  29594. if (index - 391 <= this.strings.length) {
  29595. return this.strings[index - 391];
  29596. }
  29597. return CFFStandardStrings[0];
  29598. },
  29599. add: function CFFStrings_add(value) {
  29600. this.strings.push(value);
  29601. },
  29602. get count() {
  29603. return this.strings.length;
  29604. }
  29605. };
  29606. return CFFStrings;
  29607. })();
  29608. var CFFIndex = (function CFFIndexClosure() {
  29609. function CFFIndex() {
  29610. this.objects = [];
  29611. this.length = 0;
  29612. }
  29613. CFFIndex.prototype = {
  29614. add: function CFFIndex_add(data) {
  29615. this.length += data.length;
  29616. this.objects.push(data);
  29617. },
  29618. set: function CFFIndex_set(index, data) {
  29619. this.length += data.length - this.objects[index].length;
  29620. this.objects[index] = data;
  29621. },
  29622. get: function CFFIndex_get(index) {
  29623. return this.objects[index];
  29624. },
  29625. get count() {
  29626. return this.objects.length;
  29627. }
  29628. };
  29629. return CFFIndex;
  29630. })();
  29631. var CFFDict = (function CFFDictClosure() {
  29632. function CFFDict(tables, strings) {
  29633. this.keyToNameMap = tables.keyToNameMap;
  29634. this.nameToKeyMap = tables.nameToKeyMap;
  29635. this.defaults = tables.defaults;
  29636. this.types = tables.types;
  29637. this.opcodes = tables.opcodes;
  29638. this.order = tables.order;
  29639. this.strings = strings;
  29640. this.values = {};
  29641. }
  29642. CFFDict.prototype = {
  29643. // value should always be an array
  29644. setByKey: function CFFDict_setByKey(key, value) {
  29645. if (!(key in this.keyToNameMap)) {
  29646. return false;
  29647. }
  29648. // ignore empty values
  29649. if (value.length === 0) {
  29650. return true;
  29651. }
  29652. var type = this.types[key];
  29653. // remove the array wrapping these types of values
  29654. if (type === 'num' || type === 'sid' || type === 'offset') {
  29655. value = value[0];
  29656. }
  29657. this.values[key] = value;
  29658. return true;
  29659. },
  29660. setByName: function CFFDict_setByName(name, value) {
  29661. if (!(name in this.nameToKeyMap)) {
  29662. error('Invalid dictionary name "' + name + '"');
  29663. }
  29664. this.values[this.nameToKeyMap[name]] = value;
  29665. },
  29666. hasName: function CFFDict_hasName(name) {
  29667. return this.nameToKeyMap[name] in this.values;
  29668. },
  29669. getByName: function CFFDict_getByName(name) {
  29670. if (!(name in this.nameToKeyMap)) {
  29671. error('Invalid dictionary name "' + name + '"');
  29672. }
  29673. var key = this.nameToKeyMap[name];
  29674. if (!(key in this.values)) {
  29675. return this.defaults[key];
  29676. }
  29677. return this.values[key];
  29678. },
  29679. removeByName: function CFFDict_removeByName(name) {
  29680. delete this.values[this.nameToKeyMap[name]];
  29681. }
  29682. };
  29683. CFFDict.createTables = function CFFDict_createTables(layout) {
  29684. var tables = {
  29685. keyToNameMap: {},
  29686. nameToKeyMap: {},
  29687. defaults: {},
  29688. types: {},
  29689. opcodes: {},
  29690. order: []
  29691. };
  29692. for (var i = 0, ii = layout.length; i < ii; ++i) {
  29693. var entry = layout[i];
  29694. var key = isArray(entry[0]) ? (entry[0][0] << 8) + entry[0][1] : entry[0];
  29695. tables.keyToNameMap[key] = entry[1];
  29696. tables.nameToKeyMap[entry[1]] = key;
  29697. tables.types[key] = entry[2];
  29698. tables.defaults[key] = entry[3];
  29699. tables.opcodes[key] = isArray(entry[0]) ? entry[0] : [entry[0]];
  29700. tables.order.push(key);
  29701. }
  29702. return tables;
  29703. };
  29704. return CFFDict;
  29705. })();
  29706. var CFFTopDict = (function CFFTopDictClosure() {
  29707. var layout = [
  29708. [[12, 30], 'ROS', ['sid', 'sid', 'num'], null],
  29709. [[12, 20], 'SyntheticBase', 'num', null],
  29710. [0, 'version', 'sid', null],
  29711. [1, 'Notice', 'sid', null],
  29712. [[12, 0], 'Copyright', 'sid', null],
  29713. [2, 'FullName', 'sid', null],
  29714. [3, 'FamilyName', 'sid', null],
  29715. [4, 'Weight', 'sid', null],
  29716. [[12, 1], 'isFixedPitch', 'num', 0],
  29717. [[12, 2], 'ItalicAngle', 'num', 0],
  29718. [[12, 3], 'UnderlinePosition', 'num', -100],
  29719. [[12, 4], 'UnderlineThickness', 'num', 50],
  29720. [[12, 5], 'PaintType', 'num', 0],
  29721. [[12, 6], 'CharstringType', 'num', 2],
  29722. [[12, 7], 'FontMatrix', ['num', 'num', 'num', 'num', 'num', 'num'],
  29723. [0.001, 0, 0, 0.001, 0, 0]],
  29724. [13, 'UniqueID', 'num', null],
  29725. [5, 'FontBBox', ['num', 'num', 'num', 'num'], [0, 0, 0, 0]],
  29726. [[12, 8], 'StrokeWidth', 'num', 0],
  29727. [14, 'XUID', 'array', null],
  29728. [15, 'charset', 'offset', 0],
  29729. [16, 'Encoding', 'offset', 0],
  29730. [17, 'CharStrings', 'offset', 0],
  29731. [18, 'Private', ['offset', 'offset'], null],
  29732. [[12, 21], 'PostScript', 'sid', null],
  29733. [[12, 22], 'BaseFontName', 'sid', null],
  29734. [[12, 23], 'BaseFontBlend', 'delta', null],
  29735. [[12, 31], 'CIDFontVersion', 'num', 0],
  29736. [[12, 32], 'CIDFontRevision', 'num', 0],
  29737. [[12, 33], 'CIDFontType', 'num', 0],
  29738. [[12, 34], 'CIDCount', 'num', 8720],
  29739. [[12, 35], 'UIDBase', 'num', null],
  29740. // XXX: CID Fonts on DirectWrite 6.1 only seem to work if FDSelect comes
  29741. // before FDArray.
  29742. [[12, 37], 'FDSelect', 'offset', null],
  29743. [[12, 36], 'FDArray', 'offset', null],
  29744. [[12, 38], 'FontName', 'sid', null]
  29745. ];
  29746. var tables = null;
  29747. function CFFTopDict(strings) {
  29748. if (tables === null) {
  29749. tables = CFFDict.createTables(layout);
  29750. }
  29751. CFFDict.call(this, tables, strings);
  29752. this.privateDict = null;
  29753. }
  29754. CFFTopDict.prototype = Object.create(CFFDict.prototype);
  29755. return CFFTopDict;
  29756. })();
  29757. var CFFPrivateDict = (function CFFPrivateDictClosure() {
  29758. var layout = [
  29759. [6, 'BlueValues', 'delta', null],
  29760. [7, 'OtherBlues', 'delta', null],
  29761. [8, 'FamilyBlues', 'delta', null],
  29762. [9, 'FamilyOtherBlues', 'delta', null],
  29763. [[12, 9], 'BlueScale', 'num', 0.039625],
  29764. [[12, 10], 'BlueShift', 'num', 7],
  29765. [[12, 11], 'BlueFuzz', 'num', 1],
  29766. [10, 'StdHW', 'num', null],
  29767. [11, 'StdVW', 'num', null],
  29768. [[12, 12], 'StemSnapH', 'delta', null],
  29769. [[12, 13], 'StemSnapV', 'delta', null],
  29770. [[12, 14], 'ForceBold', 'num', 0],
  29771. [[12, 17], 'LanguageGroup', 'num', 0],
  29772. [[12, 18], 'ExpansionFactor', 'num', 0.06],
  29773. [[12, 19], 'initialRandomSeed', 'num', 0],
  29774. [20, 'defaultWidthX', 'num', 0],
  29775. [21, 'nominalWidthX', 'num', 0],
  29776. [19, 'Subrs', 'offset', null]
  29777. ];
  29778. var tables = null;
  29779. function CFFPrivateDict(strings) {
  29780. if (tables === null) {
  29781. tables = CFFDict.createTables(layout);
  29782. }
  29783. CFFDict.call(this, tables, strings);
  29784. this.subrsIndex = null;
  29785. }
  29786. CFFPrivateDict.prototype = Object.create(CFFDict.prototype);
  29787. return CFFPrivateDict;
  29788. })();
  29789. var CFFCharsetPredefinedTypes = {
  29790. ISO_ADOBE: 0,
  29791. EXPERT: 1,
  29792. EXPERT_SUBSET: 2
  29793. };
  29794. var CFFCharset = (function CFFCharsetClosure() {
  29795. function CFFCharset(predefined, format, charset, raw) {
  29796. this.predefined = predefined;
  29797. this.format = format;
  29798. this.charset = charset;
  29799. this.raw = raw;
  29800. }
  29801. return CFFCharset;
  29802. })();
  29803. var CFFEncoding = (function CFFEncodingClosure() {
  29804. function CFFEncoding(predefined, format, encoding, raw) {
  29805. this.predefined = predefined;
  29806. this.format = format;
  29807. this.encoding = encoding;
  29808. this.raw = raw;
  29809. }
  29810. return CFFEncoding;
  29811. })();
  29812. var CFFFDSelect = (function CFFFDSelectClosure() {
  29813. function CFFFDSelect(fdSelect, raw) {
  29814. this.fdSelect = fdSelect;
  29815. this.raw = raw;
  29816. }
  29817. return CFFFDSelect;
  29818. })();
  29819. // Helper class to keep track of where an offset is within the data and helps
  29820. // filling in that offset once it's known.
  29821. var CFFOffsetTracker = (function CFFOffsetTrackerClosure() {
  29822. function CFFOffsetTracker() {
  29823. this.offsets = {};
  29824. }
  29825. CFFOffsetTracker.prototype = {
  29826. isTracking: function CFFOffsetTracker_isTracking(key) {
  29827. return key in this.offsets;
  29828. },
  29829. track: function CFFOffsetTracker_track(key, location) {
  29830. if (key in this.offsets) {
  29831. error('Already tracking location of ' + key);
  29832. }
  29833. this.offsets[key] = location;
  29834. },
  29835. offset: function CFFOffsetTracker_offset(value) {
  29836. for (var key in this.offsets) {
  29837. this.offsets[key] += value;
  29838. }
  29839. },
  29840. setEntryLocation: function CFFOffsetTracker_setEntryLocation(key,
  29841. values,
  29842. output) {
  29843. if (!(key in this.offsets)) {
  29844. error('Not tracking location of ' + key);
  29845. }
  29846. var data = output.data;
  29847. var dataOffset = this.offsets[key];
  29848. var size = 5;
  29849. for (var i = 0, ii = values.length; i < ii; ++i) {
  29850. var offset0 = i * size + dataOffset;
  29851. var offset1 = offset0 + 1;
  29852. var offset2 = offset0 + 2;
  29853. var offset3 = offset0 + 3;
  29854. var offset4 = offset0 + 4;
  29855. // It's easy to screw up offsets so perform this sanity check.
  29856. if (data[offset0] !== 0x1d || data[offset1] !== 0 ||
  29857. data[offset2] !== 0 || data[offset3] !== 0 || data[offset4] !== 0) {
  29858. error('writing to an offset that is not empty');
  29859. }
  29860. var value = values[i];
  29861. data[offset0] = 0x1d;
  29862. data[offset1] = (value >> 24) & 0xFF;
  29863. data[offset2] = (value >> 16) & 0xFF;
  29864. data[offset3] = (value >> 8) & 0xFF;
  29865. data[offset4] = value & 0xFF;
  29866. }
  29867. }
  29868. };
  29869. return CFFOffsetTracker;
  29870. })();
  29871. // Takes a CFF and converts it to the binary representation.
  29872. var CFFCompiler = (function CFFCompilerClosure() {
  29873. function CFFCompiler(cff) {
  29874. this.cff = cff;
  29875. }
  29876. CFFCompiler.prototype = {
  29877. compile: function CFFCompiler_compile() {
  29878. var cff = this.cff;
  29879. var output = {
  29880. data: [],
  29881. length: 0,
  29882. add: function CFFCompiler_add(data) {
  29883. this.data = this.data.concat(data);
  29884. this.length = this.data.length;
  29885. }
  29886. };
  29887. // Compile the five entries that must be in order.
  29888. var header = this.compileHeader(cff.header);
  29889. output.add(header);
  29890. var nameIndex = this.compileNameIndex(cff.names);
  29891. output.add(nameIndex);
  29892. if (cff.isCIDFont) {
  29893. // The spec is unclear on how font matrices should relate to each other
  29894. // when there is one in the main top dict and the sub top dicts.
  29895. // Windows handles this differently than linux and osx so we have to
  29896. // normalize to work on all.
  29897. // Rules based off of some mailing list discussions:
  29898. // - If main font has a matrix and subfont doesn't, use the main matrix.
  29899. // - If no main font matrix and there is a subfont matrix, use the
  29900. // subfont matrix.
  29901. // - If both have matrices, concat together.
  29902. // - If neither have matrices, use default.
  29903. // To make this work on all platforms we move the top matrix into each
  29904. // sub top dict and concat if necessary.
  29905. if (cff.topDict.hasName('FontMatrix')) {
  29906. var base = cff.topDict.getByName('FontMatrix');
  29907. cff.topDict.removeByName('FontMatrix');
  29908. for (var i = 0, ii = cff.fdArray.length; i < ii; i++) {
  29909. var subDict = cff.fdArray[i];
  29910. var matrix = base.slice(0);
  29911. if (subDict.hasName('FontMatrix')) {
  29912. matrix = Util.transform(matrix, subDict.getByName('FontMatrix'));
  29913. }
  29914. subDict.setByName('FontMatrix', matrix);
  29915. }
  29916. }
  29917. }
  29918. var compiled = this.compileTopDicts([cff.topDict],
  29919. output.length,
  29920. cff.isCIDFont);
  29921. output.add(compiled.output);
  29922. var topDictTracker = compiled.trackers[0];
  29923. var stringIndex = this.compileStringIndex(cff.strings.strings);
  29924. output.add(stringIndex);
  29925. var globalSubrIndex = this.compileIndex(cff.globalSubrIndex);
  29926. output.add(globalSubrIndex);
  29927. // Now start on the other entries that have no specfic order.
  29928. if (cff.encoding && cff.topDict.hasName('Encoding')) {
  29929. if (cff.encoding.predefined) {
  29930. topDictTracker.setEntryLocation('Encoding', [cff.encoding.format],
  29931. output);
  29932. } else {
  29933. var encoding = this.compileEncoding(cff.encoding);
  29934. topDictTracker.setEntryLocation('Encoding', [output.length], output);
  29935. output.add(encoding);
  29936. }
  29937. }
  29938. if (cff.charset && cff.topDict.hasName('charset')) {
  29939. if (cff.charset.predefined) {
  29940. topDictTracker.setEntryLocation('charset', [cff.charset.format],
  29941. output);
  29942. } else {
  29943. var charset = this.compileCharset(cff.charset);
  29944. topDictTracker.setEntryLocation('charset', [output.length], output);
  29945. output.add(charset);
  29946. }
  29947. }
  29948. var charStrings = this.compileCharStrings(cff.charStrings);
  29949. topDictTracker.setEntryLocation('CharStrings', [output.length], output);
  29950. output.add(charStrings);
  29951. if (cff.isCIDFont) {
  29952. // For some reason FDSelect must be in front of FDArray on windows. OSX
  29953. // and linux don't seem to care.
  29954. topDictTracker.setEntryLocation('FDSelect', [output.length], output);
  29955. var fdSelect = this.compileFDSelect(cff.fdSelect.raw);
  29956. output.add(fdSelect);
  29957. // It is unclear if the sub font dictionary can have CID related
  29958. // dictionary keys, but the sanitizer doesn't like them so remove them.
  29959. compiled = this.compileTopDicts(cff.fdArray, output.length, true);
  29960. topDictTracker.setEntryLocation('FDArray', [output.length], output);
  29961. output.add(compiled.output);
  29962. var fontDictTrackers = compiled.trackers;
  29963. this.compilePrivateDicts(cff.fdArray, fontDictTrackers, output);
  29964. }
  29965. this.compilePrivateDicts([cff.topDict], [topDictTracker], output);
  29966. // If the font data ends with INDEX whose object data is zero-length,
  29967. // the sanitizer will bail out. Add a dummy byte to avoid that.
  29968. output.add([0]);
  29969. return output.data;
  29970. },
  29971. encodeNumber: function CFFCompiler_encodeNumber(value) {
  29972. if (parseFloat(value) === parseInt(value, 10) && !isNaN(value)) { // isInt
  29973. return this.encodeInteger(value);
  29974. } else {
  29975. return this.encodeFloat(value);
  29976. }
  29977. },
  29978. encodeFloat: function CFFCompiler_encodeFloat(num) {
  29979. var value = num.toString();
  29980. // rounding inaccurate doubles
  29981. var m = /\.(\d*?)(?:9{5,20}|0{5,20})\d{0,2}(?:e(.+)|$)/.exec(value);
  29982. if (m) {
  29983. var epsilon = parseFloat('1e' + ((m[2] ? +m[2] : 0) + m[1].length));
  29984. value = (Math.round(num * epsilon) / epsilon).toString();
  29985. }
  29986. var nibbles = '';
  29987. var i, ii;
  29988. for (i = 0, ii = value.length; i < ii; ++i) {
  29989. var a = value[i];
  29990. if (a === 'e') {
  29991. nibbles += value[++i] === '-' ? 'c' : 'b';
  29992. } else if (a === '.') {
  29993. nibbles += 'a';
  29994. } else if (a === '-') {
  29995. nibbles += 'e';
  29996. } else {
  29997. nibbles += a;
  29998. }
  29999. }
  30000. nibbles += (nibbles.length & 1) ? 'f' : 'ff';
  30001. var out = [30];
  30002. for (i = 0, ii = nibbles.length; i < ii; i += 2) {
  30003. out.push(parseInt(nibbles.substr(i, 2), 16));
  30004. }
  30005. return out;
  30006. },
  30007. encodeInteger: function CFFCompiler_encodeInteger(value) {
  30008. var code;
  30009. if (value >= -107 && value <= 107) {
  30010. code = [value + 139];
  30011. } else if (value >= 108 && value <= 1131) {
  30012. value = [value - 108];
  30013. code = [(value >> 8) + 247, value & 0xFF];
  30014. } else if (value >= -1131 && value <= -108) {
  30015. value = -value - 108;
  30016. code = [(value >> 8) + 251, value & 0xFF];
  30017. } else if (value >= -32768 && value <= 32767) {
  30018. code = [0x1c, (value >> 8) & 0xFF, value & 0xFF];
  30019. } else {
  30020. code = [0x1d,
  30021. (value >> 24) & 0xFF,
  30022. (value >> 16) & 0xFF,
  30023. (value >> 8) & 0xFF,
  30024. value & 0xFF];
  30025. }
  30026. return code;
  30027. },
  30028. compileHeader: function CFFCompiler_compileHeader(header) {
  30029. return [
  30030. header.major,
  30031. header.minor,
  30032. header.hdrSize,
  30033. header.offSize
  30034. ];
  30035. },
  30036. compileNameIndex: function CFFCompiler_compileNameIndex(names) {
  30037. var nameIndex = new CFFIndex();
  30038. for (var i = 0, ii = names.length; i < ii; ++i) {
  30039. nameIndex.add(stringToBytes(names[i]));
  30040. }
  30041. return this.compileIndex(nameIndex);
  30042. },
  30043. compileTopDicts: function CFFCompiler_compileTopDicts(dicts,
  30044. length,
  30045. removeCidKeys) {
  30046. var fontDictTrackers = [];
  30047. var fdArrayIndex = new CFFIndex();
  30048. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  30049. var fontDict = dicts[i];
  30050. if (removeCidKeys) {
  30051. fontDict.removeByName('CIDFontVersion');
  30052. fontDict.removeByName('CIDFontRevision');
  30053. fontDict.removeByName('CIDFontType');
  30054. fontDict.removeByName('CIDCount');
  30055. fontDict.removeByName('UIDBase');
  30056. }
  30057. var fontDictTracker = new CFFOffsetTracker();
  30058. var fontDictData = this.compileDict(fontDict, fontDictTracker);
  30059. fontDictTrackers.push(fontDictTracker);
  30060. fdArrayIndex.add(fontDictData);
  30061. fontDictTracker.offset(length);
  30062. }
  30063. fdArrayIndex = this.compileIndex(fdArrayIndex, fontDictTrackers);
  30064. return {
  30065. trackers: fontDictTrackers,
  30066. output: fdArrayIndex
  30067. };
  30068. },
  30069. compilePrivateDicts: function CFFCompiler_compilePrivateDicts(dicts,
  30070. trackers,
  30071. output) {
  30072. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  30073. var fontDict = dicts[i];
  30074. assert(fontDict.privateDict && fontDict.hasName('Private'),
  30075. 'There must be an private dictionary.');
  30076. var privateDict = fontDict.privateDict;
  30077. var privateDictTracker = new CFFOffsetTracker();
  30078. var privateDictData = this.compileDict(privateDict, privateDictTracker);
  30079. var outputLength = output.length;
  30080. privateDictTracker.offset(outputLength);
  30081. if (!privateDictData.length) {
  30082. // The private dictionary was empty, set the output length to zero to
  30083. // ensure the offset length isn't out of bounds in the eyes of the
  30084. // sanitizer.
  30085. outputLength = 0;
  30086. }
  30087. trackers[i].setEntryLocation('Private',
  30088. [privateDictData.length, outputLength],
  30089. output);
  30090. output.add(privateDictData);
  30091. if (privateDict.subrsIndex && privateDict.hasName('Subrs')) {
  30092. var subrs = this.compileIndex(privateDict.subrsIndex);
  30093. privateDictTracker.setEntryLocation('Subrs', [privateDictData.length],
  30094. output);
  30095. output.add(subrs);
  30096. }
  30097. }
  30098. },
  30099. compileDict: function CFFCompiler_compileDict(dict, offsetTracker) {
  30100. var out = [];
  30101. // The dictionary keys must be in a certain order.
  30102. var order = dict.order;
  30103. for (var i = 0; i < order.length; ++i) {
  30104. var key = order[i];
  30105. if (!(key in dict.values)) {
  30106. continue;
  30107. }
  30108. var values = dict.values[key];
  30109. var types = dict.types[key];
  30110. if (!isArray(types)) {
  30111. types = [types];
  30112. }
  30113. if (!isArray(values)) {
  30114. values = [values];
  30115. }
  30116. // Remove any empty dict values.
  30117. if (values.length === 0) {
  30118. continue;
  30119. }
  30120. for (var j = 0, jj = types.length; j < jj; ++j) {
  30121. var type = types[j];
  30122. var value = values[j];
  30123. switch (type) {
  30124. case 'num':
  30125. case 'sid':
  30126. out = out.concat(this.encodeNumber(value));
  30127. break;
  30128. case 'offset':
  30129. // For offsets we just insert a 32bit integer so we don't have to
  30130. // deal with figuring out the length of the offset when it gets
  30131. // replaced later on by the compiler.
  30132. var name = dict.keyToNameMap[key];
  30133. // Some offsets have the offset and the length, so just record the
  30134. // position of the first one.
  30135. if (!offsetTracker.isTracking(name)) {
  30136. offsetTracker.track(name, out.length);
  30137. }
  30138. out = out.concat([0x1d, 0, 0, 0, 0]);
  30139. break;
  30140. case 'array':
  30141. case 'delta':
  30142. out = out.concat(this.encodeNumber(value));
  30143. for (var k = 1, kk = values.length; k < kk; ++k) {
  30144. out = out.concat(this.encodeNumber(values[k]));
  30145. }
  30146. break;
  30147. default:
  30148. error('Unknown data type of ' + type);
  30149. break;
  30150. }
  30151. }
  30152. out = out.concat(dict.opcodes[key]);
  30153. }
  30154. return out;
  30155. },
  30156. compileStringIndex: function CFFCompiler_compileStringIndex(strings) {
  30157. var stringIndex = new CFFIndex();
  30158. for (var i = 0, ii = strings.length; i < ii; ++i) {
  30159. stringIndex.add(stringToBytes(strings[i]));
  30160. }
  30161. return this.compileIndex(stringIndex);
  30162. },
  30163. compileGlobalSubrIndex: function CFFCompiler_compileGlobalSubrIndex() {
  30164. var globalSubrIndex = this.cff.globalSubrIndex;
  30165. this.out.writeByteArray(this.compileIndex(globalSubrIndex));
  30166. },
  30167. compileCharStrings: function CFFCompiler_compileCharStrings(charStrings) {
  30168. return this.compileIndex(charStrings);
  30169. },
  30170. compileCharset: function CFFCompiler_compileCharset(charset) {
  30171. return this.compileTypedArray(charset.raw);
  30172. },
  30173. compileEncoding: function CFFCompiler_compileEncoding(encoding) {
  30174. return this.compileTypedArray(encoding.raw);
  30175. },
  30176. compileFDSelect: function CFFCompiler_compileFDSelect(fdSelect) {
  30177. return this.compileTypedArray(fdSelect);
  30178. },
  30179. compileTypedArray: function CFFCompiler_compileTypedArray(data) {
  30180. var out = [];
  30181. for (var i = 0, ii = data.length; i < ii; ++i) {
  30182. out[i] = data[i];
  30183. }
  30184. return out;
  30185. },
  30186. compileIndex: function CFFCompiler_compileIndex(index, trackers) {
  30187. trackers = trackers || [];
  30188. var objects = index.objects;
  30189. // First 2 bytes contains the number of objects contained into this index
  30190. var count = objects.length;
  30191. // If there is no object, just create an index. This technically
  30192. // should just be [0, 0] but OTS has an issue with that.
  30193. if (count === 0) {
  30194. return [0, 0, 0];
  30195. }
  30196. var data = [(count >> 8) & 0xFF, count & 0xff];
  30197. var lastOffset = 1, i;
  30198. for (i = 0; i < count; ++i) {
  30199. lastOffset += objects[i].length;
  30200. }
  30201. var offsetSize;
  30202. if (lastOffset < 0x100) {
  30203. offsetSize = 1;
  30204. } else if (lastOffset < 0x10000) {
  30205. offsetSize = 2;
  30206. } else if (lastOffset < 0x1000000) {
  30207. offsetSize = 3;
  30208. } else {
  30209. offsetSize = 4;
  30210. }
  30211. // Next byte contains the offset size use to reference object in the file
  30212. data.push(offsetSize);
  30213. // Add another offset after this one because we need a new offset
  30214. var relativeOffset = 1;
  30215. for (i = 0; i < count + 1; i++) {
  30216. if (offsetSize === 1) {
  30217. data.push(relativeOffset & 0xFF);
  30218. } else if (offsetSize === 2) {
  30219. data.push((relativeOffset >> 8) & 0xFF,
  30220. relativeOffset & 0xFF);
  30221. } else if (offsetSize === 3) {
  30222. data.push((relativeOffset >> 16) & 0xFF,
  30223. (relativeOffset >> 8) & 0xFF,
  30224. relativeOffset & 0xFF);
  30225. } else {
  30226. data.push((relativeOffset >>> 24) & 0xFF,
  30227. (relativeOffset >> 16) & 0xFF,
  30228. (relativeOffset >> 8) & 0xFF,
  30229. relativeOffset & 0xFF);
  30230. }
  30231. if (objects[i]) {
  30232. relativeOffset += objects[i].length;
  30233. }
  30234. }
  30235. for (i = 0; i < count; i++) {
  30236. // Notify the tracker where the object will be offset in the data.
  30237. if (trackers[i]) {
  30238. trackers[i].offset(data.length);
  30239. }
  30240. for (var j = 0, jj = objects[i].length; j < jj; j++) {
  30241. data.push(objects[i][j]);
  30242. }
  30243. }
  30244. return data;
  30245. }
  30246. };
  30247. return CFFCompiler;
  30248. })();
  30249. function _enableSeacAnalysis(enabled) {
  30250. exports.SEAC_ANALYSIS_ENABLED = SEAC_ANALYSIS_ENABLED = enabled;
  30251. }
  30252. // Workaround for seac on Windows.
  30253. (function checkSeacSupport() {
  30254. if (typeof navigator !== 'undefined' && /Windows/.test(navigator.userAgent)) {
  30255. SEAC_ANALYSIS_ENABLED = true;
  30256. }
  30257. })();
  30258. // Workaround for Private Use Area characters in Chrome on Windows
  30259. // http://code.google.com/p/chromium/issues/detail?id=122465
  30260. // https://github.com/mozilla/pdf.js/issues/1689
  30261. (function checkChromeWindows() {
  30262. if (typeof navigator !== 'undefined' &&
  30263. /Windows.*Chrome/.test(navigator.userAgent)) {
  30264. SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = true;
  30265. }
  30266. })();
  30267. exports.SEAC_ANALYSIS_ENABLED = SEAC_ANALYSIS_ENABLED;
  30268. exports.CFFCompiler = CFFCompiler;
  30269. exports.CFFIndex = CFFIndex;
  30270. exports.CFFParser = CFFParser;
  30271. exports.CFFStrings = CFFStrings;
  30272. exports.Encodings = Encodings;
  30273. exports.ErrorFont = ErrorFont;
  30274. exports.FontFlags = FontFlags;
  30275. exports.Font = Font;
  30276. exports.IdentityToUnicodeMap = IdentityToUnicodeMap;
  30277. exports.NormalizedUnicodes = NormalizedUnicodes;
  30278. exports.ToUnicodeMap = ToUnicodeMap;
  30279. exports.Type1Parser = Type1Parser;
  30280. exports.getFontType = getFontType;
  30281. exports.reverseIfRtl = reverseIfRtl;
  30282. exports.serifFonts = serifFonts;
  30283. exports.symbolsFonts = symbolsFonts;
  30284. exports.stdFontMap = stdFontMap;
  30285. exports._enableSeacAnalysis = _enableSeacAnalysis;
  30286. // TODO refactor to remove cyclic dependency on font_renderer.js
  30287. coreFontRenderer._setCoreFonts(exports);
  30288. }));
  30289. (function (root, factory) {
  30290. if (typeof define === 'function' && define.amd) {
  30291. define('pdfjs/core/function', ['exports', 'pdfjs/shared/util',
  30292. 'pdfjs/core/primitives', 'pdfjs/core/ps_parser'], factory);
  30293. } else if (typeof exports !== 'undefined') {
  30294. factory(exports, require('../shared/util.js'), require('./primitives.js'),
  30295. require('./ps_parser.js'));
  30296. } else {
  30297. factory((root.pdfjsCoreFunction = {}), root.pdfjsSharedUtil,
  30298. root.pdfjsCorePrimitives, root.pdfjsCorePsParser);
  30299. }
  30300. }(this, function (exports, sharedUtil, corePrimitives, corePsParser) {
  30301. var error = sharedUtil.error;
  30302. var info = sharedUtil.info;
  30303. var isArray = sharedUtil.isArray;
  30304. var isBool = sharedUtil.isBool;
  30305. var isDict = corePrimitives.isDict;
  30306. var isStream = corePrimitives.isStream;
  30307. var PostScriptLexer = corePsParser.PostScriptLexer;
  30308. var PostScriptParser = corePsParser.PostScriptParser;
  30309. var PDFFunction = (function PDFFunctionClosure() {
  30310. var CONSTRUCT_SAMPLED = 0;
  30311. var CONSTRUCT_INTERPOLATED = 2;
  30312. var CONSTRUCT_STICHED = 3;
  30313. var CONSTRUCT_POSTSCRIPT = 4;
  30314. return {
  30315. getSampleArray: function PDFFunction_getSampleArray(size, outputSize, bps,
  30316. str) {
  30317. var i, ii;
  30318. var length = 1;
  30319. for (i = 0, ii = size.length; i < ii; i++) {
  30320. length *= size[i];
  30321. }
  30322. length *= outputSize;
  30323. var array = new Array(length);
  30324. var codeSize = 0;
  30325. var codeBuf = 0;
  30326. // 32 is a valid bps so shifting won't work
  30327. var sampleMul = 1.0 / (Math.pow(2.0, bps) - 1);
  30328. var strBytes = str.getBytes((length * bps + 7) / 8);
  30329. var strIdx = 0;
  30330. for (i = 0; i < length; i++) {
  30331. while (codeSize < bps) {
  30332. codeBuf <<= 8;
  30333. codeBuf |= strBytes[strIdx++];
  30334. codeSize += 8;
  30335. }
  30336. codeSize -= bps;
  30337. array[i] = (codeBuf >> codeSize) * sampleMul;
  30338. codeBuf &= (1 << codeSize) - 1;
  30339. }
  30340. return array;
  30341. },
  30342. getIR: function PDFFunction_getIR(xref, fn) {
  30343. var dict = fn.dict;
  30344. if (!dict) {
  30345. dict = fn;
  30346. }
  30347. var types = [this.constructSampled,
  30348. null,
  30349. this.constructInterpolated,
  30350. this.constructStiched,
  30351. this.constructPostScript];
  30352. var typeNum = dict.get('FunctionType');
  30353. var typeFn = types[typeNum];
  30354. if (!typeFn) {
  30355. error('Unknown type of function');
  30356. }
  30357. return typeFn.call(this, fn, dict, xref);
  30358. },
  30359. fromIR: function PDFFunction_fromIR(IR) {
  30360. var type = IR[0];
  30361. switch (type) {
  30362. case CONSTRUCT_SAMPLED:
  30363. return this.constructSampledFromIR(IR);
  30364. case CONSTRUCT_INTERPOLATED:
  30365. return this.constructInterpolatedFromIR(IR);
  30366. case CONSTRUCT_STICHED:
  30367. return this.constructStichedFromIR(IR);
  30368. //case CONSTRUCT_POSTSCRIPT:
  30369. default:
  30370. return this.constructPostScriptFromIR(IR);
  30371. }
  30372. },
  30373. parse: function PDFFunction_parse(xref, fn) {
  30374. var IR = this.getIR(xref, fn);
  30375. return this.fromIR(IR);
  30376. },
  30377. parseArray: function PDFFunction_parseArray(xref, fnObj) {
  30378. if (!isArray(fnObj)) {
  30379. // not an array -- parsing as regular function
  30380. return this.parse(xref, fnObj);
  30381. }
  30382. var fnArray = [];
  30383. for (var j = 0, jj = fnObj.length; j < jj; j++) {
  30384. var obj = xref.fetchIfRef(fnObj[j]);
  30385. fnArray.push(PDFFunction.parse(xref, obj));
  30386. }
  30387. return function (src, srcOffset, dest, destOffset) {
  30388. for (var i = 0, ii = fnArray.length; i < ii; i++) {
  30389. fnArray[i](src, srcOffset, dest, destOffset + i);
  30390. }
  30391. };
  30392. },
  30393. constructSampled: function PDFFunction_constructSampled(str, dict) {
  30394. function toMultiArray(arr) {
  30395. var inputLength = arr.length;
  30396. var out = [];
  30397. var index = 0;
  30398. for (var i = 0; i < inputLength; i += 2) {
  30399. out[index] = [arr[i], arr[i + 1]];
  30400. ++index;
  30401. }
  30402. return out;
  30403. }
  30404. var domain = dict.get('Domain');
  30405. var range = dict.get('Range');
  30406. if (!domain || !range) {
  30407. error('No domain or range');
  30408. }
  30409. var inputSize = domain.length / 2;
  30410. var outputSize = range.length / 2;
  30411. domain = toMultiArray(domain);
  30412. range = toMultiArray(range);
  30413. var size = dict.get('Size');
  30414. var bps = dict.get('BitsPerSample');
  30415. var order = dict.get('Order') || 1;
  30416. if (order !== 1) {
  30417. // No description how cubic spline interpolation works in PDF32000:2008
  30418. // As in poppler, ignoring order, linear interpolation may work as good
  30419. info('No support for cubic spline interpolation: ' + order);
  30420. }
  30421. var encode = dict.get('Encode');
  30422. if (!encode) {
  30423. encode = [];
  30424. for (var i = 0; i < inputSize; ++i) {
  30425. encode.push(0);
  30426. encode.push(size[i] - 1);
  30427. }
  30428. }
  30429. encode = toMultiArray(encode);
  30430. var decode = dict.get('Decode');
  30431. if (!decode) {
  30432. decode = range;
  30433. } else {
  30434. decode = toMultiArray(decode);
  30435. }
  30436. var samples = this.getSampleArray(size, outputSize, bps, str);
  30437. return [
  30438. CONSTRUCT_SAMPLED, inputSize, domain, encode, decode, samples, size,
  30439. outputSize, Math.pow(2, bps) - 1, range
  30440. ];
  30441. },
  30442. constructSampledFromIR: function PDFFunction_constructSampledFromIR(IR) {
  30443. // See chapter 3, page 109 of the PDF reference
  30444. function interpolate(x, xmin, xmax, ymin, ymax) {
  30445. return ymin + ((x - xmin) * ((ymax - ymin) / (xmax - xmin)));
  30446. }
  30447. return function constructSampledFromIRResult(src, srcOffset,
  30448. dest, destOffset) {
  30449. // See chapter 3, page 110 of the PDF reference.
  30450. var m = IR[1];
  30451. var domain = IR[2];
  30452. var encode = IR[3];
  30453. var decode = IR[4];
  30454. var samples = IR[5];
  30455. var size = IR[6];
  30456. var n = IR[7];
  30457. //var mask = IR[8];
  30458. var range = IR[9];
  30459. // Building the cube vertices: its part and sample index
  30460. // http://rjwagner49.com/Mathematics/Interpolation.pdf
  30461. var cubeVertices = 1 << m;
  30462. var cubeN = new Float64Array(cubeVertices);
  30463. var cubeVertex = new Uint32Array(cubeVertices);
  30464. var i, j;
  30465. for (j = 0; j < cubeVertices; j++) {
  30466. cubeN[j] = 1;
  30467. }
  30468. var k = n, pos = 1;
  30469. // Map x_i to y_j for 0 <= i < m using the sampled function.
  30470. for (i = 0; i < m; ++i) {
  30471. // x_i' = min(max(x_i, Domain_2i), Domain_2i+1)
  30472. var domain_2i = domain[i][0];
  30473. var domain_2i_1 = domain[i][1];
  30474. var xi = Math.min(Math.max(src[srcOffset +i], domain_2i),
  30475. domain_2i_1);
  30476. // e_i = Interpolate(x_i', Domain_2i, Domain_2i+1,
  30477. // Encode_2i, Encode_2i+1)
  30478. var e = interpolate(xi, domain_2i, domain_2i_1,
  30479. encode[i][0], encode[i][1]);
  30480. // e_i' = min(max(e_i, 0), Size_i - 1)
  30481. var size_i = size[i];
  30482. e = Math.min(Math.max(e, 0), size_i - 1);
  30483. // Adjusting the cube: N and vertex sample index
  30484. var e0 = e < size_i - 1 ? Math.floor(e) : e - 1; // e1 = e0 + 1;
  30485. var n0 = e0 + 1 - e; // (e1 - e) / (e1 - e0);
  30486. var n1 = e - e0; // (e - e0) / (e1 - e0);
  30487. var offset0 = e0 * k;
  30488. var offset1 = offset0 + k; // e1 * k
  30489. for (j = 0; j < cubeVertices; j++) {
  30490. if (j & pos) {
  30491. cubeN[j] *= n1;
  30492. cubeVertex[j] += offset1;
  30493. } else {
  30494. cubeN[j] *= n0;
  30495. cubeVertex[j] += offset0;
  30496. }
  30497. }
  30498. k *= size_i;
  30499. pos <<= 1;
  30500. }
  30501. for (j = 0; j < n; ++j) {
  30502. // Sum all cube vertices' samples portions
  30503. var rj = 0;
  30504. for (i = 0; i < cubeVertices; i++) {
  30505. rj += samples[cubeVertex[i] + j] * cubeN[i];
  30506. }
  30507. // r_j' = Interpolate(r_j, 0, 2^BitsPerSample - 1,
  30508. // Decode_2j, Decode_2j+1)
  30509. rj = interpolate(rj, 0, 1, decode[j][0], decode[j][1]);
  30510. // y_j = min(max(r_j, range_2j), range_2j+1)
  30511. dest[destOffset + j] = Math.min(Math.max(rj, range[j][0]),
  30512. range[j][1]);
  30513. }
  30514. };
  30515. },
  30516. constructInterpolated: function PDFFunction_constructInterpolated(str,
  30517. dict) {
  30518. var c0 = dict.get('C0') || [0];
  30519. var c1 = dict.get('C1') || [1];
  30520. var n = dict.get('N');
  30521. if (!isArray(c0) || !isArray(c1)) {
  30522. error('Illegal dictionary for interpolated function');
  30523. }
  30524. var length = c0.length;
  30525. var diff = [];
  30526. for (var i = 0; i < length; ++i) {
  30527. diff.push(c1[i] - c0[i]);
  30528. }
  30529. return [CONSTRUCT_INTERPOLATED, c0, diff, n];
  30530. },
  30531. constructInterpolatedFromIR:
  30532. function PDFFunction_constructInterpolatedFromIR(IR) {
  30533. var c0 = IR[1];
  30534. var diff = IR[2];
  30535. var n = IR[3];
  30536. var length = diff.length;
  30537. return function constructInterpolatedFromIRResult(src, srcOffset,
  30538. dest, destOffset) {
  30539. var x = n === 1 ? src[srcOffset] : Math.pow(src[srcOffset], n);
  30540. for (var j = 0; j < length; ++j) {
  30541. dest[destOffset + j] = c0[j] + (x * diff[j]);
  30542. }
  30543. };
  30544. },
  30545. constructStiched: function PDFFunction_constructStiched(fn, dict, xref) {
  30546. var domain = dict.get('Domain');
  30547. if (!domain) {
  30548. error('No domain');
  30549. }
  30550. var inputSize = domain.length / 2;
  30551. if (inputSize !== 1) {
  30552. error('Bad domain for stiched function');
  30553. }
  30554. var fnRefs = dict.get('Functions');
  30555. var fns = [];
  30556. for (var i = 0, ii = fnRefs.length; i < ii; ++i) {
  30557. fns.push(PDFFunction.getIR(xref, xref.fetchIfRef(fnRefs[i])));
  30558. }
  30559. var bounds = dict.get('Bounds');
  30560. var encode = dict.get('Encode');
  30561. return [CONSTRUCT_STICHED, domain, bounds, encode, fns];
  30562. },
  30563. constructStichedFromIR: function PDFFunction_constructStichedFromIR(IR) {
  30564. var domain = IR[1];
  30565. var bounds = IR[2];
  30566. var encode = IR[3];
  30567. var fnsIR = IR[4];
  30568. var fns = [];
  30569. var tmpBuf = new Float32Array(1);
  30570. for (var i = 0, ii = fnsIR.length; i < ii; i++) {
  30571. fns.push(PDFFunction.fromIR(fnsIR[i]));
  30572. }
  30573. return function constructStichedFromIRResult(src, srcOffset,
  30574. dest, destOffset) {
  30575. var clip = function constructStichedFromIRClip(v, min, max) {
  30576. if (v > max) {
  30577. v = max;
  30578. } else if (v < min) {
  30579. v = min;
  30580. }
  30581. return v;
  30582. };
  30583. // clip to domain
  30584. var v = clip(src[srcOffset], domain[0], domain[1]);
  30585. // calulate which bound the value is in
  30586. for (var i = 0, ii = bounds.length; i < ii; ++i) {
  30587. if (v < bounds[i]) {
  30588. break;
  30589. }
  30590. }
  30591. // encode value into domain of function
  30592. var dmin = domain[0];
  30593. if (i > 0) {
  30594. dmin = bounds[i - 1];
  30595. }
  30596. var dmax = domain[1];
  30597. if (i < bounds.length) {
  30598. dmax = bounds[i];
  30599. }
  30600. var rmin = encode[2 * i];
  30601. var rmax = encode[2 * i + 1];
  30602. // Prevent the value from becoming NaN as a result
  30603. // of division by zero (fixes issue6113.pdf).
  30604. tmpBuf[0] = dmin === dmax ? rmin :
  30605. rmin + (v - dmin) * (rmax - rmin) / (dmax - dmin);
  30606. // call the appropriate function
  30607. fns[i](tmpBuf, 0, dest, destOffset);
  30608. };
  30609. },
  30610. constructPostScript: function PDFFunction_constructPostScript(fn, dict,
  30611. xref) {
  30612. var domain = dict.get('Domain');
  30613. var range = dict.get('Range');
  30614. if (!domain) {
  30615. error('No domain.');
  30616. }
  30617. if (!range) {
  30618. error('No range.');
  30619. }
  30620. var lexer = new PostScriptLexer(fn);
  30621. var parser = new PostScriptParser(lexer);
  30622. var code = parser.parse();
  30623. return [CONSTRUCT_POSTSCRIPT, domain, range, code];
  30624. },
  30625. constructPostScriptFromIR: function PDFFunction_constructPostScriptFromIR(
  30626. IR) {
  30627. var domain = IR[1];
  30628. var range = IR[2];
  30629. var code = IR[3];
  30630. var compiled = (new PostScriptCompiler()).compile(code, domain, range);
  30631. if (compiled) {
  30632. // Compiled function consists of simple expressions such as addition,
  30633. // subtraction, Math.max, and also contains 'var' and 'return'
  30634. // statements. See the generation in the PostScriptCompiler below.
  30635. /*jshint -W054 */
  30636. return new Function('src', 'srcOffset', 'dest', 'destOffset', compiled);
  30637. }
  30638. info('Unable to compile PS function');
  30639. var numOutputs = range.length >> 1;
  30640. var numInputs = domain.length >> 1;
  30641. var evaluator = new PostScriptEvaluator(code);
  30642. // Cache the values for a big speed up, the cache size is limited though
  30643. // since the number of possible values can be huge from a PS function.
  30644. var cache = {};
  30645. // The MAX_CACHE_SIZE is set to ~4x the maximum number of distinct values
  30646. // seen in our tests.
  30647. var MAX_CACHE_SIZE = 2048 * 4;
  30648. var cache_available = MAX_CACHE_SIZE;
  30649. var tmpBuf = new Float32Array(numInputs);
  30650. return function constructPostScriptFromIRResult(src, srcOffset,
  30651. dest, destOffset) {
  30652. var i, value;
  30653. var key = '';
  30654. var input = tmpBuf;
  30655. for (i = 0; i < numInputs; i++) {
  30656. value = src[srcOffset + i];
  30657. input[i] = value;
  30658. key += value + '_';
  30659. }
  30660. var cachedValue = cache[key];
  30661. if (cachedValue !== undefined) {
  30662. dest.set(cachedValue, destOffset);
  30663. return;
  30664. }
  30665. var output = new Float32Array(numOutputs);
  30666. var stack = evaluator.execute(input);
  30667. var stackIndex = stack.length - numOutputs;
  30668. for (i = 0; i < numOutputs; i++) {
  30669. value = stack[stackIndex + i];
  30670. var bound = range[i * 2];
  30671. if (value < bound) {
  30672. value = bound;
  30673. } else {
  30674. bound = range[i * 2 +1];
  30675. if (value > bound) {
  30676. value = bound;
  30677. }
  30678. }
  30679. output[i] = value;
  30680. }
  30681. if (cache_available > 0) {
  30682. cache_available--;
  30683. cache[key] = output;
  30684. }
  30685. dest.set(output, destOffset);
  30686. };
  30687. }
  30688. };
  30689. })();
  30690. function isPDFFunction(v) {
  30691. var fnDict;
  30692. if (typeof v !== 'object') {
  30693. return false;
  30694. } else if (isDict(v)) {
  30695. fnDict = v;
  30696. } else if (isStream(v)) {
  30697. fnDict = v.dict;
  30698. } else {
  30699. return false;
  30700. }
  30701. return fnDict.has('FunctionType');
  30702. }
  30703. var PostScriptStack = (function PostScriptStackClosure() {
  30704. var MAX_STACK_SIZE = 100;
  30705. function PostScriptStack(initialStack) {
  30706. this.stack = !initialStack ? [] :
  30707. Array.prototype.slice.call(initialStack, 0);
  30708. }
  30709. PostScriptStack.prototype = {
  30710. push: function PostScriptStack_push(value) {
  30711. if (this.stack.length >= MAX_STACK_SIZE) {
  30712. error('PostScript function stack overflow.');
  30713. }
  30714. this.stack.push(value);
  30715. },
  30716. pop: function PostScriptStack_pop() {
  30717. if (this.stack.length <= 0) {
  30718. error('PostScript function stack underflow.');
  30719. }
  30720. return this.stack.pop();
  30721. },
  30722. copy: function PostScriptStack_copy(n) {
  30723. if (this.stack.length + n >= MAX_STACK_SIZE) {
  30724. error('PostScript function stack overflow.');
  30725. }
  30726. var stack = this.stack;
  30727. for (var i = stack.length - n, j = n - 1; j >= 0; j--, i++) {
  30728. stack.push(stack[i]);
  30729. }
  30730. },
  30731. index: function PostScriptStack_index(n) {
  30732. this.push(this.stack[this.stack.length - n - 1]);
  30733. },
  30734. // rotate the last n stack elements p times
  30735. roll: function PostScriptStack_roll(n, p) {
  30736. var stack = this.stack;
  30737. var l = stack.length - n;
  30738. var r = stack.length - 1, c = l + (p - Math.floor(p / n) * n), i, j, t;
  30739. for (i = l, j = r; i < j; i++, j--) {
  30740. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  30741. }
  30742. for (i = l, j = c - 1; i < j; i++, j--) {
  30743. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  30744. }
  30745. for (i = c, j = r; i < j; i++, j--) {
  30746. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  30747. }
  30748. }
  30749. };
  30750. return PostScriptStack;
  30751. })();
  30752. var PostScriptEvaluator = (function PostScriptEvaluatorClosure() {
  30753. function PostScriptEvaluator(operators) {
  30754. this.operators = operators;
  30755. }
  30756. PostScriptEvaluator.prototype = {
  30757. execute: function PostScriptEvaluator_execute(initialStack) {
  30758. var stack = new PostScriptStack(initialStack);
  30759. var counter = 0;
  30760. var operators = this.operators;
  30761. var length = operators.length;
  30762. var operator, a, b;
  30763. while (counter < length) {
  30764. operator = operators[counter++];
  30765. if (typeof operator === 'number') {
  30766. // Operator is really an operand and should be pushed to the stack.
  30767. stack.push(operator);
  30768. continue;
  30769. }
  30770. switch (operator) {
  30771. // non standard ps operators
  30772. case 'jz': // jump if false
  30773. b = stack.pop();
  30774. a = stack.pop();
  30775. if (!a) {
  30776. counter = b;
  30777. }
  30778. break;
  30779. case 'j': // jump
  30780. a = stack.pop();
  30781. counter = a;
  30782. break;
  30783. // all ps operators in alphabetical order (excluding if/ifelse)
  30784. case 'abs':
  30785. a = stack.pop();
  30786. stack.push(Math.abs(a));
  30787. break;
  30788. case 'add':
  30789. b = stack.pop();
  30790. a = stack.pop();
  30791. stack.push(a + b);
  30792. break;
  30793. case 'and':
  30794. b = stack.pop();
  30795. a = stack.pop();
  30796. if (isBool(a) && isBool(b)) {
  30797. stack.push(a && b);
  30798. } else {
  30799. stack.push(a & b);
  30800. }
  30801. break;
  30802. case 'atan':
  30803. a = stack.pop();
  30804. stack.push(Math.atan(a));
  30805. break;
  30806. case 'bitshift':
  30807. b = stack.pop();
  30808. a = stack.pop();
  30809. if (a > 0) {
  30810. stack.push(a << b);
  30811. } else {
  30812. stack.push(a >> b);
  30813. }
  30814. break;
  30815. case 'ceiling':
  30816. a = stack.pop();
  30817. stack.push(Math.ceil(a));
  30818. break;
  30819. case 'copy':
  30820. a = stack.pop();
  30821. stack.copy(a);
  30822. break;
  30823. case 'cos':
  30824. a = stack.pop();
  30825. stack.push(Math.cos(a));
  30826. break;
  30827. case 'cvi':
  30828. a = stack.pop() | 0;
  30829. stack.push(a);
  30830. break;
  30831. case 'cvr':
  30832. // noop
  30833. break;
  30834. case 'div':
  30835. b = stack.pop();
  30836. a = stack.pop();
  30837. stack.push(a / b);
  30838. break;
  30839. case 'dup':
  30840. stack.copy(1);
  30841. break;
  30842. case 'eq':
  30843. b = stack.pop();
  30844. a = stack.pop();
  30845. stack.push(a === b);
  30846. break;
  30847. case 'exch':
  30848. stack.roll(2, 1);
  30849. break;
  30850. case 'exp':
  30851. b = stack.pop();
  30852. a = stack.pop();
  30853. stack.push(Math.pow(a, b));
  30854. break;
  30855. case 'false':
  30856. stack.push(false);
  30857. break;
  30858. case 'floor':
  30859. a = stack.pop();
  30860. stack.push(Math.floor(a));
  30861. break;
  30862. case 'ge':
  30863. b = stack.pop();
  30864. a = stack.pop();
  30865. stack.push(a >= b);
  30866. break;
  30867. case 'gt':
  30868. b = stack.pop();
  30869. a = stack.pop();
  30870. stack.push(a > b);
  30871. break;
  30872. case 'idiv':
  30873. b = stack.pop();
  30874. a = stack.pop();
  30875. stack.push((a / b) | 0);
  30876. break;
  30877. case 'index':
  30878. a = stack.pop();
  30879. stack.index(a);
  30880. break;
  30881. case 'le':
  30882. b = stack.pop();
  30883. a = stack.pop();
  30884. stack.push(a <= b);
  30885. break;
  30886. case 'ln':
  30887. a = stack.pop();
  30888. stack.push(Math.log(a));
  30889. break;
  30890. case 'log':
  30891. a = stack.pop();
  30892. stack.push(Math.log(a) / Math.LN10);
  30893. break;
  30894. case 'lt':
  30895. b = stack.pop();
  30896. a = stack.pop();
  30897. stack.push(a < b);
  30898. break;
  30899. case 'mod':
  30900. b = stack.pop();
  30901. a = stack.pop();
  30902. stack.push(a % b);
  30903. break;
  30904. case 'mul':
  30905. b = stack.pop();
  30906. a = stack.pop();
  30907. stack.push(a * b);
  30908. break;
  30909. case 'ne':
  30910. b = stack.pop();
  30911. a = stack.pop();
  30912. stack.push(a !== b);
  30913. break;
  30914. case 'neg':
  30915. a = stack.pop();
  30916. stack.push(-a);
  30917. break;
  30918. case 'not':
  30919. a = stack.pop();
  30920. if (isBool(a)) {
  30921. stack.push(!a);
  30922. } else {
  30923. stack.push(~a);
  30924. }
  30925. break;
  30926. case 'or':
  30927. b = stack.pop();
  30928. a = stack.pop();
  30929. if (isBool(a) && isBool(b)) {
  30930. stack.push(a || b);
  30931. } else {
  30932. stack.push(a | b);
  30933. }
  30934. break;
  30935. case 'pop':
  30936. stack.pop();
  30937. break;
  30938. case 'roll':
  30939. b = stack.pop();
  30940. a = stack.pop();
  30941. stack.roll(a, b);
  30942. break;
  30943. case 'round':
  30944. a = stack.pop();
  30945. stack.push(Math.round(a));
  30946. break;
  30947. case 'sin':
  30948. a = stack.pop();
  30949. stack.push(Math.sin(a));
  30950. break;
  30951. case 'sqrt':
  30952. a = stack.pop();
  30953. stack.push(Math.sqrt(a));
  30954. break;
  30955. case 'sub':
  30956. b = stack.pop();
  30957. a = stack.pop();
  30958. stack.push(a - b);
  30959. break;
  30960. case 'true':
  30961. stack.push(true);
  30962. break;
  30963. case 'truncate':
  30964. a = stack.pop();
  30965. a = a < 0 ? Math.ceil(a) : Math.floor(a);
  30966. stack.push(a);
  30967. break;
  30968. case 'xor':
  30969. b = stack.pop();
  30970. a = stack.pop();
  30971. if (isBool(a) && isBool(b)) {
  30972. stack.push(a !== b);
  30973. } else {
  30974. stack.push(a ^ b);
  30975. }
  30976. break;
  30977. default:
  30978. error('Unknown operator ' + operator);
  30979. break;
  30980. }
  30981. }
  30982. return stack.stack;
  30983. }
  30984. };
  30985. return PostScriptEvaluator;
  30986. })();
  30987. // Most of the PDFs functions consist of simple operations such as:
  30988. // roll, exch, sub, cvr, pop, index, dup, mul, if, gt, add.
  30989. //
  30990. // We can compile most of such programs, and at the same moment, we can
  30991. // optimize some expressions using basic math properties. Keeping track of
  30992. // min/max values will allow us to avoid extra Math.min/Math.max calls.
  30993. var PostScriptCompiler = (function PostScriptCompilerClosure() {
  30994. function AstNode(type) {
  30995. this.type = type;
  30996. }
  30997. AstNode.prototype.visit = function (visitor) {
  30998. throw new Error('abstract method');
  30999. };
  31000. function AstArgument(index, min, max) {
  31001. AstNode.call(this, 'args');
  31002. this.index = index;
  31003. this.min = min;
  31004. this.max = max;
  31005. }
  31006. AstArgument.prototype = Object.create(AstNode.prototype);
  31007. AstArgument.prototype.visit = function (visitor) {
  31008. visitor.visitArgument(this);
  31009. };
  31010. function AstLiteral(number) {
  31011. AstNode.call(this, 'literal');
  31012. this.number = number;
  31013. this.min = number;
  31014. this.max = number;
  31015. }
  31016. AstLiteral.prototype = Object.create(AstNode.prototype);
  31017. AstLiteral.prototype.visit = function (visitor) {
  31018. visitor.visitLiteral(this);
  31019. };
  31020. function AstBinaryOperation(op, arg1, arg2, min, max) {
  31021. AstNode.call(this, 'binary');
  31022. this.op = op;
  31023. this.arg1 = arg1;
  31024. this.arg2 = arg2;
  31025. this.min = min;
  31026. this.max = max;
  31027. }
  31028. AstBinaryOperation.prototype = Object.create(AstNode.prototype);
  31029. AstBinaryOperation.prototype.visit = function (visitor) {
  31030. visitor.visitBinaryOperation(this);
  31031. };
  31032. function AstMin(arg, max) {
  31033. AstNode.call(this, 'max');
  31034. this.arg = arg;
  31035. this.min = arg.min;
  31036. this.max = max;
  31037. }
  31038. AstMin.prototype = Object.create(AstNode.prototype);
  31039. AstMin.prototype.visit = function (visitor) {
  31040. visitor.visitMin(this);
  31041. };
  31042. function AstVariable(index, min, max) {
  31043. AstNode.call(this, 'var');
  31044. this.index = index;
  31045. this.min = min;
  31046. this.max = max;
  31047. }
  31048. AstVariable.prototype = Object.create(AstNode.prototype);
  31049. AstVariable.prototype.visit = function (visitor) {
  31050. visitor.visitVariable(this);
  31051. };
  31052. function AstVariableDefinition(variable, arg) {
  31053. AstNode.call(this, 'definition');
  31054. this.variable = variable;
  31055. this.arg = arg;
  31056. }
  31057. AstVariableDefinition.prototype = Object.create(AstNode.prototype);
  31058. AstVariableDefinition.prototype.visit = function (visitor) {
  31059. visitor.visitVariableDefinition(this);
  31060. };
  31061. function ExpressionBuilderVisitor() {
  31062. this.parts = [];
  31063. }
  31064. ExpressionBuilderVisitor.prototype = {
  31065. visitArgument: function (arg) {
  31066. this.parts.push('Math.max(', arg.min, ', Math.min(',
  31067. arg.max, ', src[srcOffset + ', arg.index, ']))');
  31068. },
  31069. visitVariable: function (variable) {
  31070. this.parts.push('v', variable.index);
  31071. },
  31072. visitLiteral: function (literal) {
  31073. this.parts.push(literal.number);
  31074. },
  31075. visitBinaryOperation: function (operation) {
  31076. this.parts.push('(');
  31077. operation.arg1.visit(this);
  31078. this.parts.push(' ', operation.op, ' ');
  31079. operation.arg2.visit(this);
  31080. this.parts.push(')');
  31081. },
  31082. visitVariableDefinition: function (definition) {
  31083. this.parts.push('var ');
  31084. definition.variable.visit(this);
  31085. this.parts.push(' = ');
  31086. definition.arg.visit(this);
  31087. this.parts.push(';');
  31088. },
  31089. visitMin: function (max) {
  31090. this.parts.push('Math.min(');
  31091. max.arg.visit(this);
  31092. this.parts.push(', ', max.max, ')');
  31093. },
  31094. toString: function () {
  31095. return this.parts.join('');
  31096. }
  31097. };
  31098. function buildAddOperation(num1, num2) {
  31099. if (num2.type === 'literal' && num2.number === 0) {
  31100. // optimization: second operand is 0
  31101. return num1;
  31102. }
  31103. if (num1.type === 'literal' && num1.number === 0) {
  31104. // optimization: first operand is 0
  31105. return num2;
  31106. }
  31107. if (num2.type === 'literal' && num1.type === 'literal') {
  31108. // optimization: operands operand are literals
  31109. return new AstLiteral(num1.number + num2.number);
  31110. }
  31111. return new AstBinaryOperation('+', num1, num2,
  31112. num1.min + num2.min, num1.max + num2.max);
  31113. }
  31114. function buildMulOperation(num1, num2) {
  31115. if (num2.type === 'literal') {
  31116. // optimization: second operands is a literal...
  31117. if (num2.number === 0) {
  31118. return new AstLiteral(0); // and it's 0
  31119. } else if (num2.number === 1) {
  31120. return num1; // and it's 1
  31121. } else if (num1.type === 'literal') {
  31122. // ... and first operands is a literal too
  31123. return new AstLiteral(num1.number * num2.number);
  31124. }
  31125. }
  31126. if (num1.type === 'literal') {
  31127. // optimization: first operands is a literal...
  31128. if (num1.number === 0) {
  31129. return new AstLiteral(0); // and it's 0
  31130. } else if (num1.number === 1) {
  31131. return num2; // and it's 1
  31132. }
  31133. }
  31134. var min = Math.min(num1.min * num2.min, num1.min * num2.max,
  31135. num1.max * num2.min, num1.max * num2.max);
  31136. var max = Math.max(num1.min * num2.min, num1.min * num2.max,
  31137. num1.max * num2.min, num1.max * num2.max);
  31138. return new AstBinaryOperation('*', num1, num2, min, max);
  31139. }
  31140. function buildSubOperation(num1, num2) {
  31141. if (num2.type === 'literal') {
  31142. // optimization: second operands is a literal...
  31143. if (num2.number === 0) {
  31144. return num1; // ... and it's 0
  31145. } else if (num1.type === 'literal') {
  31146. // ... and first operands is a literal too
  31147. return new AstLiteral(num1.number - num2.number);
  31148. }
  31149. }
  31150. if (num2.type === 'binary' && num2.op === '-' &&
  31151. num1.type === 'literal' && num1.number === 1 &&
  31152. num2.arg1.type === 'literal' && num2.arg1.number === 1) {
  31153. // optimization for case: 1 - (1 - x)
  31154. return num2.arg2;
  31155. }
  31156. return new AstBinaryOperation('-', num1, num2,
  31157. num1.min - num2.max, num1.max - num2.min);
  31158. }
  31159. function buildMinOperation(num1, max) {
  31160. if (num1.min >= max) {
  31161. // optimization: num1 min value is not less than required max
  31162. return new AstLiteral(max); // just returning max
  31163. } else if (num1.max <= max) {
  31164. // optimization: num1 max value is not greater than required max
  31165. return num1; // just returning an argument
  31166. }
  31167. return new AstMin(num1, max);
  31168. }
  31169. function PostScriptCompiler() {}
  31170. PostScriptCompiler.prototype = {
  31171. compile: function PostScriptCompiler_compile(code, domain, range) {
  31172. var stack = [];
  31173. var i, ii;
  31174. var instructions = [];
  31175. var inputSize = domain.length >> 1, outputSize = range.length >> 1;
  31176. var lastRegister = 0;
  31177. var n, j, min, max;
  31178. var num1, num2, ast1, ast2, tmpVar, item;
  31179. for (i = 0; i < inputSize; i++) {
  31180. stack.push(new AstArgument(i, domain[i * 2], domain[i * 2 + 1]));
  31181. }
  31182. for (i = 0, ii = code.length; i < ii; i++) {
  31183. item = code[i];
  31184. if (typeof item === 'number') {
  31185. stack.push(new AstLiteral(item));
  31186. continue;
  31187. }
  31188. switch (item) {
  31189. case 'add':
  31190. if (stack.length < 2) {
  31191. return null;
  31192. }
  31193. num2 = stack.pop();
  31194. num1 = stack.pop();
  31195. stack.push(buildAddOperation(num1, num2));
  31196. break;
  31197. case 'cvr':
  31198. if (stack.length < 1) {
  31199. return null;
  31200. }
  31201. break;
  31202. case 'mul':
  31203. if (stack.length < 2) {
  31204. return null;
  31205. }
  31206. num2 = stack.pop();
  31207. num1 = stack.pop();
  31208. stack.push(buildMulOperation(num1, num2));
  31209. break;
  31210. case 'sub':
  31211. if (stack.length < 2) {
  31212. return null;
  31213. }
  31214. num2 = stack.pop();
  31215. num1 = stack.pop();
  31216. stack.push(buildSubOperation(num1, num2));
  31217. break;
  31218. case 'exch':
  31219. if (stack.length < 2) {
  31220. return null;
  31221. }
  31222. ast1 = stack.pop(); ast2 = stack.pop();
  31223. stack.push(ast1, ast2);
  31224. break;
  31225. case 'pop':
  31226. if (stack.length < 1) {
  31227. return null;
  31228. }
  31229. stack.pop();
  31230. break;
  31231. case 'index':
  31232. if (stack.length < 1) {
  31233. return null;
  31234. }
  31235. num1 = stack.pop();
  31236. if (num1.type !== 'literal') {
  31237. return null;
  31238. }
  31239. n = num1.number;
  31240. if (n < 0 || (n|0) !== n || stack.length < n) {
  31241. return null;
  31242. }
  31243. ast1 = stack[stack.length - n - 1];
  31244. if (ast1.type === 'literal' || ast1.type === 'var') {
  31245. stack.push(ast1);
  31246. break;
  31247. }
  31248. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  31249. stack[stack.length - n - 1] = tmpVar;
  31250. stack.push(tmpVar);
  31251. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  31252. break;
  31253. case 'dup':
  31254. if (stack.length < 1) {
  31255. return null;
  31256. }
  31257. if (typeof code[i + 1] === 'number' && code[i + 2] === 'gt' &&
  31258. code[i + 3] === i + 7 && code[i + 4] === 'jz' &&
  31259. code[i + 5] === 'pop' && code[i + 6] === code[i + 1]) {
  31260. // special case of the commands sequence for the min operation
  31261. num1 = stack.pop();
  31262. stack.push(buildMinOperation(num1, code[i + 1]));
  31263. i += 6;
  31264. break;
  31265. }
  31266. ast1 = stack[stack.length - 1];
  31267. if (ast1.type === 'literal' || ast1.type === 'var') {
  31268. // we don't have to save into intermediate variable a literal or
  31269. // variable.
  31270. stack.push(ast1);
  31271. break;
  31272. }
  31273. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  31274. stack[stack.length - 1] = tmpVar;
  31275. stack.push(tmpVar);
  31276. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  31277. break;
  31278. case 'roll':
  31279. if (stack.length < 2) {
  31280. return null;
  31281. }
  31282. num2 = stack.pop();
  31283. num1 = stack.pop();
  31284. if (num2.type !== 'literal' || num1.type !== 'literal') {
  31285. // both roll operands must be numbers
  31286. return null;
  31287. }
  31288. j = num2.number;
  31289. n = num1.number;
  31290. if (n <= 0 || (n|0) !== n || (j|0) !== j || stack.length < n) {
  31291. // ... and integers
  31292. return null;
  31293. }
  31294. j = ((j % n) + n) % n;
  31295. if (j === 0) {
  31296. break; // just skipping -- there are nothing to rotate
  31297. }
  31298. Array.prototype.push.apply(stack,
  31299. stack.splice(stack.length - n, n - j));
  31300. break;
  31301. default:
  31302. return null; // unsupported operator
  31303. }
  31304. }
  31305. if (stack.length !== outputSize) {
  31306. return null;
  31307. }
  31308. var result = [];
  31309. instructions.forEach(function (instruction) {
  31310. var statementBuilder = new ExpressionBuilderVisitor();
  31311. instruction.visit(statementBuilder);
  31312. result.push(statementBuilder.toString());
  31313. });
  31314. stack.forEach(function (expr, i) {
  31315. var statementBuilder = new ExpressionBuilderVisitor();
  31316. expr.visit(statementBuilder);
  31317. var min = range[i * 2], max = range[i * 2 + 1];
  31318. var out = [statementBuilder.toString()];
  31319. if (min > expr.min) {
  31320. out.unshift('Math.max(', min, ', ');
  31321. out.push(')');
  31322. }
  31323. if (max < expr.max) {
  31324. out.unshift('Math.min(', max, ', ');
  31325. out.push(')');
  31326. }
  31327. out.unshift('dest[destOffset + ', i, '] = ');
  31328. out.push(';');
  31329. result.push(out.join(''));
  31330. });
  31331. return result.join('\n');
  31332. }
  31333. };
  31334. return PostScriptCompiler;
  31335. })();
  31336. exports.isPDFFunction = isPDFFunction;
  31337. exports.PDFFunction = PDFFunction;
  31338. exports.PostScriptEvaluator = PostScriptEvaluator;
  31339. exports.PostScriptCompiler = PostScriptCompiler;
  31340. }));
  31341. (function (root, factory) {
  31342. if (typeof define === 'function' && define.amd) {
  31343. define('pdfjs/core/colorspace', ['exports', 'pdfjs/shared/util',
  31344. 'pdfjs/core/primitives', 'pdfjs/core/function', 'pdfjs/core/stream'],
  31345. factory);
  31346. } else if (typeof exports !== 'undefined') {
  31347. factory(exports, require('../shared/util.js'), require('./primitives.js'),
  31348. require('./function.js'), require('./stream.js'));
  31349. } else {
  31350. factory((root.pdfjsCoreColorSpace = {}), root.pdfjsSharedUtil,
  31351. root.pdfjsCorePrimitives, root.pdfjsCoreFunction, root.pdfjsCoreStream);
  31352. }
  31353. }(this, function (exports, sharedUtil, corePrimitives, coreFunction,
  31354. coreStream) {
  31355. var error = sharedUtil.error;
  31356. var info = sharedUtil.info;
  31357. var isArray = sharedUtil.isArray;
  31358. var isString = sharedUtil.isString;
  31359. var shadow = sharedUtil.shadow;
  31360. var warn = sharedUtil.warn;
  31361. var isDict = corePrimitives.isDict;
  31362. var isName = corePrimitives.isName;
  31363. var isStream = corePrimitives.isStream;
  31364. var PDFFunction = coreFunction.PDFFunction;
  31365. var coreImage; // see _setCoreImage below
  31366. var PDFImage; // = coreImage.PDFImage;
  31367. var ColorSpace = (function ColorSpaceClosure() {
  31368. // Constructor should define this.numComps, this.defaultColor, this.name
  31369. function ColorSpace() {
  31370. error('should not call ColorSpace constructor');
  31371. }
  31372. ColorSpace.prototype = {
  31373. /**
  31374. * Converts the color value to the RGB color. The color components are
  31375. * located in the src array starting from the srcOffset. Returns the array
  31376. * of the rgb components, each value ranging from [0,255].
  31377. */
  31378. getRgb: function ColorSpace_getRgb(src, srcOffset) {
  31379. var rgb = new Uint8Array(3);
  31380. this.getRgbItem(src, srcOffset, rgb, 0);
  31381. return rgb;
  31382. },
  31383. /**
  31384. * Converts the color value to the RGB color, similar to the getRgb method.
  31385. * The result placed into the dest array starting from the destOffset.
  31386. */
  31387. getRgbItem: function ColorSpace_getRgbItem(src, srcOffset,
  31388. dest, destOffset) {
  31389. error('Should not call ColorSpace.getRgbItem');
  31390. },
  31391. /**
  31392. * Converts the specified number of the color values to the RGB colors.
  31393. * The colors are located in the src array starting from the srcOffset.
  31394. * The result is placed into the dest array starting from the destOffset.
  31395. * The src array items shall be in [0,2^bits) range, the dest array items
  31396. * will be in [0,255] range. alpha01 indicates how many alpha components
  31397. * there are in the dest array; it will be either 0 (RGB array) or 1 (RGBA
  31398. * array).
  31399. */
  31400. getRgbBuffer: function ColorSpace_getRgbBuffer(src, srcOffset, count,
  31401. dest, destOffset, bits,
  31402. alpha01) {
  31403. error('Should not call ColorSpace.getRgbBuffer');
  31404. },
  31405. /**
  31406. * Determines the number of bytes required to store the result of the
  31407. * conversion done by the getRgbBuffer method. As in getRgbBuffer,
  31408. * |alpha01| is either 0 (RGB output) or 1 (RGBA output).
  31409. */
  31410. getOutputLength: function ColorSpace_getOutputLength(inputLength,
  31411. alpha01) {
  31412. error('Should not call ColorSpace.getOutputLength');
  31413. },
  31414. /**
  31415. * Returns true if source data will be equal the result/output data.
  31416. */
  31417. isPassthrough: function ColorSpace_isPassthrough(bits) {
  31418. return false;
  31419. },
  31420. /**
  31421. * Fills in the RGB colors in the destination buffer. alpha01 indicates
  31422. * how many alpha components there are in the dest array; it will be either
  31423. * 0 (RGB array) or 1 (RGBA array).
  31424. */
  31425. fillRgb: function ColorSpace_fillRgb(dest, originalWidth,
  31426. originalHeight, width, height,
  31427. actualHeight, bpc, comps, alpha01) {
  31428. var count = originalWidth * originalHeight;
  31429. var rgbBuf = null;
  31430. var numComponentColors = 1 << bpc;
  31431. var needsResizing = originalHeight !== height || originalWidth !== width;
  31432. var i, ii;
  31433. if (this.isPassthrough(bpc)) {
  31434. rgbBuf = comps;
  31435. } else if (this.numComps === 1 && count > numComponentColors &&
  31436. this.name !== 'DeviceGray' && this.name !== 'DeviceRGB') {
  31437. // Optimization: create a color map when there is just one component and
  31438. // we are converting more colors than the size of the color map. We
  31439. // don't build the map if the colorspace is gray or rgb since those
  31440. // methods are faster than building a map. This mainly offers big speed
  31441. // ups for indexed and alternate colorspaces.
  31442. //
  31443. // TODO it may be worth while to cache the color map. While running
  31444. // testing I never hit a cache so I will leave that out for now (perhaps
  31445. // we are reparsing colorspaces too much?).
  31446. var allColors = bpc <= 8 ? new Uint8Array(numComponentColors) :
  31447. new Uint16Array(numComponentColors);
  31448. var key;
  31449. for (i = 0; i < numComponentColors; i++) {
  31450. allColors[i] = i;
  31451. }
  31452. var colorMap = new Uint8Array(numComponentColors * 3);
  31453. this.getRgbBuffer(allColors, 0, numComponentColors, colorMap, 0, bpc,
  31454. /* alpha01 = */ 0);
  31455. var destPos, rgbPos;
  31456. if (!needsResizing) {
  31457. // Fill in the RGB values directly into |dest|.
  31458. destPos = 0;
  31459. for (i = 0; i < count; ++i) {
  31460. key = comps[i] * 3;
  31461. dest[destPos++] = colorMap[key];
  31462. dest[destPos++] = colorMap[key + 1];
  31463. dest[destPos++] = colorMap[key + 2];
  31464. destPos += alpha01;
  31465. }
  31466. } else {
  31467. rgbBuf = new Uint8Array(count * 3);
  31468. rgbPos = 0;
  31469. for (i = 0; i < count; ++i) {
  31470. key = comps[i] * 3;
  31471. rgbBuf[rgbPos++] = colorMap[key];
  31472. rgbBuf[rgbPos++] = colorMap[key + 1];
  31473. rgbBuf[rgbPos++] = colorMap[key + 2];
  31474. }
  31475. }
  31476. } else {
  31477. if (!needsResizing) {
  31478. // Fill in the RGB values directly into |dest|.
  31479. this.getRgbBuffer(comps, 0, width * actualHeight, dest, 0, bpc,
  31480. alpha01);
  31481. } else {
  31482. rgbBuf = new Uint8Array(count * 3);
  31483. this.getRgbBuffer(comps, 0, count, rgbBuf, 0, bpc,
  31484. /* alpha01 = */ 0);
  31485. }
  31486. }
  31487. if (rgbBuf) {
  31488. if (needsResizing) {
  31489. PDFImage.resize(rgbBuf, bpc, 3, originalWidth, originalHeight, width,
  31490. height, dest, alpha01);
  31491. } else {
  31492. rgbPos = 0;
  31493. destPos = 0;
  31494. for (i = 0, ii = width * actualHeight; i < ii; i++) {
  31495. dest[destPos++] = rgbBuf[rgbPos++];
  31496. dest[destPos++] = rgbBuf[rgbPos++];
  31497. dest[destPos++] = rgbBuf[rgbPos++];
  31498. destPos += alpha01;
  31499. }
  31500. }
  31501. }
  31502. },
  31503. /**
  31504. * True if the colorspace has components in the default range of [0, 1].
  31505. * This should be true for all colorspaces except for lab color spaces
  31506. * which are [0,100], [-128, 127], [-128, 127].
  31507. */
  31508. usesZeroToOneRange: true
  31509. };
  31510. ColorSpace.parse = function ColorSpace_parse(cs, xref, res) {
  31511. var IR = ColorSpace.parseToIR(cs, xref, res);
  31512. if (IR instanceof AlternateCS) {
  31513. return IR;
  31514. }
  31515. return ColorSpace.fromIR(IR);
  31516. };
  31517. ColorSpace.fromIR = function ColorSpace_fromIR(IR) {
  31518. var name = isArray(IR) ? IR[0] : IR;
  31519. var whitePoint, blackPoint, gamma;
  31520. switch (name) {
  31521. case 'DeviceGrayCS':
  31522. return this.singletons.gray;
  31523. case 'DeviceRgbCS':
  31524. return this.singletons.rgb;
  31525. case 'DeviceCmykCS':
  31526. return this.singletons.cmyk;
  31527. case 'CalGrayCS':
  31528. whitePoint = IR[1].WhitePoint;
  31529. blackPoint = IR[1].BlackPoint;
  31530. gamma = IR[1].Gamma;
  31531. return new CalGrayCS(whitePoint, blackPoint, gamma);
  31532. case 'CalRGBCS':
  31533. whitePoint = IR[1].WhitePoint;
  31534. blackPoint = IR[1].BlackPoint;
  31535. gamma = IR[1].Gamma;
  31536. var matrix = IR[1].Matrix;
  31537. return new CalRGBCS(whitePoint, blackPoint, gamma, matrix);
  31538. case 'PatternCS':
  31539. var basePatternCS = IR[1];
  31540. if (basePatternCS) {
  31541. basePatternCS = ColorSpace.fromIR(basePatternCS);
  31542. }
  31543. return new PatternCS(basePatternCS);
  31544. case 'IndexedCS':
  31545. var baseIndexedCS = IR[1];
  31546. var hiVal = IR[2];
  31547. var lookup = IR[3];
  31548. return new IndexedCS(ColorSpace.fromIR(baseIndexedCS), hiVal, lookup);
  31549. case 'AlternateCS':
  31550. var numComps = IR[1];
  31551. var alt = IR[2];
  31552. var tintFnIR = IR[3];
  31553. return new AlternateCS(numComps, ColorSpace.fromIR(alt),
  31554. PDFFunction.fromIR(tintFnIR));
  31555. case 'LabCS':
  31556. whitePoint = IR[1].WhitePoint;
  31557. blackPoint = IR[1].BlackPoint;
  31558. var range = IR[1].Range;
  31559. return new LabCS(whitePoint, blackPoint, range);
  31560. default:
  31561. error('Unknown name ' + name);
  31562. }
  31563. return null;
  31564. };
  31565. ColorSpace.parseToIR = function ColorSpace_parseToIR(cs, xref, res) {
  31566. if (isName(cs)) {
  31567. var colorSpaces = res.get('ColorSpace');
  31568. if (isDict(colorSpaces)) {
  31569. var refcs = colorSpaces.get(cs.name);
  31570. if (refcs) {
  31571. cs = refcs;
  31572. }
  31573. }
  31574. }
  31575. cs = xref.fetchIfRef(cs);
  31576. var mode;
  31577. if (isName(cs)) {
  31578. mode = cs.name;
  31579. this.mode = mode;
  31580. switch (mode) {
  31581. case 'DeviceGray':
  31582. case 'G':
  31583. return 'DeviceGrayCS';
  31584. case 'DeviceRGB':
  31585. case 'RGB':
  31586. return 'DeviceRgbCS';
  31587. case 'DeviceCMYK':
  31588. case 'CMYK':
  31589. return 'DeviceCmykCS';
  31590. case 'Pattern':
  31591. return ['PatternCS', null];
  31592. default:
  31593. error('unrecognized colorspace ' + mode);
  31594. }
  31595. } else if (isArray(cs)) {
  31596. mode = xref.fetchIfRef(cs[0]).name;
  31597. this.mode = mode;
  31598. var numComps, params, alt;
  31599. switch (mode) {
  31600. case 'DeviceGray':
  31601. case 'G':
  31602. return 'DeviceGrayCS';
  31603. case 'DeviceRGB':
  31604. case 'RGB':
  31605. return 'DeviceRgbCS';
  31606. case 'DeviceCMYK':
  31607. case 'CMYK':
  31608. return 'DeviceCmykCS';
  31609. case 'CalGray':
  31610. params = xref.fetchIfRef(cs[1]).getAll();
  31611. return ['CalGrayCS', params];
  31612. case 'CalRGB':
  31613. params = xref.fetchIfRef(cs[1]).getAll();
  31614. return ['CalRGBCS', params];
  31615. case 'ICCBased':
  31616. var stream = xref.fetchIfRef(cs[1]);
  31617. var dict = stream.dict;
  31618. numComps = dict.get('N');
  31619. alt = dict.get('Alternate');
  31620. if (alt) {
  31621. var altIR = ColorSpace.parseToIR(alt, xref, res);
  31622. // Parse the /Alternate CS to ensure that the number of components
  31623. // are correct, and also (indirectly) that it is not a PatternCS.
  31624. var altCS = ColorSpace.fromIR(altIR);
  31625. if (altCS.numComps === numComps) {
  31626. return altIR;
  31627. }
  31628. warn('ICCBased color space: Ignoring incorrect /Alternate entry.');
  31629. }
  31630. if (numComps === 1) {
  31631. return 'DeviceGrayCS';
  31632. } else if (numComps === 3) {
  31633. return 'DeviceRgbCS';
  31634. } else if (numComps === 4) {
  31635. return 'DeviceCmykCS';
  31636. }
  31637. break;
  31638. case 'Pattern':
  31639. var basePatternCS = cs[1] || null;
  31640. if (basePatternCS) {
  31641. basePatternCS = ColorSpace.parseToIR(basePatternCS, xref, res);
  31642. }
  31643. return ['PatternCS', basePatternCS];
  31644. case 'Indexed':
  31645. case 'I':
  31646. var baseIndexedCS = ColorSpace.parseToIR(cs[1], xref, res);
  31647. var hiVal = xref.fetchIfRef(cs[2]) + 1;
  31648. var lookup = xref.fetchIfRef(cs[3]);
  31649. if (isStream(lookup)) {
  31650. lookup = lookup.getBytes();
  31651. }
  31652. return ['IndexedCS', baseIndexedCS, hiVal, lookup];
  31653. case 'Separation':
  31654. case 'DeviceN':
  31655. var name = xref.fetchIfRef(cs[1]);
  31656. numComps = 1;
  31657. if (isName(name)) {
  31658. numComps = 1;
  31659. } else if (isArray(name)) {
  31660. numComps = name.length;
  31661. }
  31662. alt = ColorSpace.parseToIR(cs[2], xref, res);
  31663. var tintFnIR = PDFFunction.getIR(xref, xref.fetchIfRef(cs[3]));
  31664. return ['AlternateCS', numComps, alt, tintFnIR];
  31665. case 'Lab':
  31666. params = xref.fetchIfRef(cs[1]).getAll();
  31667. return ['LabCS', params];
  31668. default:
  31669. error('unimplemented color space object "' + mode + '"');
  31670. }
  31671. } else {
  31672. error('unrecognized color space object: "' + cs + '"');
  31673. }
  31674. return null;
  31675. };
  31676. /**
  31677. * Checks if a decode map matches the default decode map for a color space.
  31678. * This handles the general decode maps where there are two values per
  31679. * component. e.g. [0, 1, 0, 1, 0, 1] for a RGB color.
  31680. * This does not handle Lab, Indexed, or Pattern decode maps since they are
  31681. * slightly different.
  31682. * @param {Array} decode Decode map (usually from an image).
  31683. * @param {Number} n Number of components the color space has.
  31684. */
  31685. ColorSpace.isDefaultDecode = function ColorSpace_isDefaultDecode(decode, n) {
  31686. if (!isArray(decode)) {
  31687. return true;
  31688. }
  31689. if (n * 2 !== decode.length) {
  31690. warn('The decode map is not the correct length');
  31691. return true;
  31692. }
  31693. for (var i = 0, ii = decode.length; i < ii; i += 2) {
  31694. if (decode[i] !== 0 || decode[i + 1] !== 1) {
  31695. return false;
  31696. }
  31697. }
  31698. return true;
  31699. };
  31700. ColorSpace.singletons = {
  31701. get gray() {
  31702. return shadow(this, 'gray', new DeviceGrayCS());
  31703. },
  31704. get rgb() {
  31705. return shadow(this, 'rgb', new DeviceRgbCS());
  31706. },
  31707. get cmyk() {
  31708. return shadow(this, 'cmyk', new DeviceCmykCS());
  31709. }
  31710. };
  31711. return ColorSpace;
  31712. })();
  31713. /**
  31714. * Alternate color space handles both Separation and DeviceN color spaces. A
  31715. * Separation color space is actually just a DeviceN with one color component.
  31716. * Both color spaces use a tinting function to convert colors to a base color
  31717. * space.
  31718. */
  31719. var AlternateCS = (function AlternateCSClosure() {
  31720. function AlternateCS(numComps, base, tintFn) {
  31721. this.name = 'Alternate';
  31722. this.numComps = numComps;
  31723. this.defaultColor = new Float32Array(numComps);
  31724. for (var i = 0; i < numComps; ++i) {
  31725. this.defaultColor[i] = 1;
  31726. }
  31727. this.base = base;
  31728. this.tintFn = tintFn;
  31729. this.tmpBuf = new Float32Array(base.numComps);
  31730. }
  31731. AlternateCS.prototype = {
  31732. getRgb: ColorSpace.prototype.getRgb,
  31733. getRgbItem: function AlternateCS_getRgbItem(src, srcOffset,
  31734. dest, destOffset) {
  31735. var tmpBuf = this.tmpBuf;
  31736. this.tintFn(src, srcOffset, tmpBuf, 0);
  31737. this.base.getRgbItem(tmpBuf, 0, dest, destOffset);
  31738. },
  31739. getRgbBuffer: function AlternateCS_getRgbBuffer(src, srcOffset, count,
  31740. dest, destOffset, bits,
  31741. alpha01) {
  31742. var tintFn = this.tintFn;
  31743. var base = this.base;
  31744. var scale = 1 / ((1 << bits) - 1);
  31745. var baseNumComps = base.numComps;
  31746. var usesZeroToOneRange = base.usesZeroToOneRange;
  31747. var isPassthrough = (base.isPassthrough(8) || !usesZeroToOneRange) &&
  31748. alpha01 === 0;
  31749. var pos = isPassthrough ? destOffset : 0;
  31750. var baseBuf = isPassthrough ? dest : new Uint8Array(baseNumComps * count);
  31751. var numComps = this.numComps;
  31752. var scaled = new Float32Array(numComps);
  31753. var tinted = new Float32Array(baseNumComps);
  31754. var i, j;
  31755. if (usesZeroToOneRange) {
  31756. for (i = 0; i < count; i++) {
  31757. for (j = 0; j < numComps; j++) {
  31758. scaled[j] = src[srcOffset++] * scale;
  31759. }
  31760. tintFn(scaled, 0, tinted, 0);
  31761. for (j = 0; j < baseNumComps; j++) {
  31762. baseBuf[pos++] = tinted[j] * 255;
  31763. }
  31764. }
  31765. } else {
  31766. for (i = 0; i < count; i++) {
  31767. for (j = 0; j < numComps; j++) {
  31768. scaled[j] = src[srcOffset++] * scale;
  31769. }
  31770. tintFn(scaled, 0, tinted, 0);
  31771. base.getRgbItem(tinted, 0, baseBuf, pos);
  31772. pos += baseNumComps;
  31773. }
  31774. }
  31775. if (!isPassthrough) {
  31776. base.getRgbBuffer(baseBuf, 0, count, dest, destOffset, 8, alpha01);
  31777. }
  31778. },
  31779. getOutputLength: function AlternateCS_getOutputLength(inputLength,
  31780. alpha01) {
  31781. return this.base.getOutputLength(inputLength *
  31782. this.base.numComps / this.numComps,
  31783. alpha01);
  31784. },
  31785. isPassthrough: ColorSpace.prototype.isPassthrough,
  31786. fillRgb: ColorSpace.prototype.fillRgb,
  31787. isDefaultDecode: function AlternateCS_isDefaultDecode(decodeMap) {
  31788. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  31789. },
  31790. usesZeroToOneRange: true
  31791. };
  31792. return AlternateCS;
  31793. })();
  31794. var PatternCS = (function PatternCSClosure() {
  31795. function PatternCS(baseCS) {
  31796. this.name = 'Pattern';
  31797. this.base = baseCS;
  31798. }
  31799. PatternCS.prototype = {};
  31800. return PatternCS;
  31801. })();
  31802. var IndexedCS = (function IndexedCSClosure() {
  31803. function IndexedCS(base, highVal, lookup) {
  31804. this.name = 'Indexed';
  31805. this.numComps = 1;
  31806. this.defaultColor = new Uint8Array([0]);
  31807. this.base = base;
  31808. this.highVal = highVal;
  31809. var baseNumComps = base.numComps;
  31810. var length = baseNumComps * highVal;
  31811. var lookupArray;
  31812. if (isStream(lookup)) {
  31813. lookupArray = new Uint8Array(length);
  31814. var bytes = lookup.getBytes(length);
  31815. lookupArray.set(bytes);
  31816. } else if (isString(lookup)) {
  31817. lookupArray = new Uint8Array(length);
  31818. for (var i = 0; i < length; ++i) {
  31819. lookupArray[i] = lookup.charCodeAt(i);
  31820. }
  31821. } else if (lookup instanceof Uint8Array || lookup instanceof Array) {
  31822. lookupArray = lookup;
  31823. } else {
  31824. error('Unrecognized lookup table: ' + lookup);
  31825. }
  31826. this.lookup = lookupArray;
  31827. }
  31828. IndexedCS.prototype = {
  31829. getRgb: ColorSpace.prototype.getRgb,
  31830. getRgbItem: function IndexedCS_getRgbItem(src, srcOffset,
  31831. dest, destOffset) {
  31832. var numComps = this.base.numComps;
  31833. var start = src[srcOffset] * numComps;
  31834. this.base.getRgbItem(this.lookup, start, dest, destOffset);
  31835. },
  31836. getRgbBuffer: function IndexedCS_getRgbBuffer(src, srcOffset, count,
  31837. dest, destOffset, bits,
  31838. alpha01) {
  31839. var base = this.base;
  31840. var numComps = base.numComps;
  31841. var outputDelta = base.getOutputLength(numComps, alpha01);
  31842. var lookup = this.lookup;
  31843. for (var i = 0; i < count; ++i) {
  31844. var lookupPos = src[srcOffset++] * numComps;
  31845. base.getRgbBuffer(lookup, lookupPos, 1, dest, destOffset, 8, alpha01);
  31846. destOffset += outputDelta;
  31847. }
  31848. },
  31849. getOutputLength: function IndexedCS_getOutputLength(inputLength, alpha01) {
  31850. return this.base.getOutputLength(inputLength * this.base.numComps,
  31851. alpha01);
  31852. },
  31853. isPassthrough: ColorSpace.prototype.isPassthrough,
  31854. fillRgb: ColorSpace.prototype.fillRgb,
  31855. isDefaultDecode: function IndexedCS_isDefaultDecode(decodeMap) {
  31856. // indexed color maps shouldn't be changed
  31857. return true;
  31858. },
  31859. usesZeroToOneRange: true
  31860. };
  31861. return IndexedCS;
  31862. })();
  31863. var DeviceGrayCS = (function DeviceGrayCSClosure() {
  31864. function DeviceGrayCS() {
  31865. this.name = 'DeviceGray';
  31866. this.numComps = 1;
  31867. this.defaultColor = new Float32Array([0]);
  31868. }
  31869. DeviceGrayCS.prototype = {
  31870. getRgb: ColorSpace.prototype.getRgb,
  31871. getRgbItem: function DeviceGrayCS_getRgbItem(src, srcOffset,
  31872. dest, destOffset) {
  31873. var c = (src[srcOffset] * 255) | 0;
  31874. c = c < 0 ? 0 : c > 255 ? 255 : c;
  31875. dest[destOffset] = dest[destOffset + 1] = dest[destOffset + 2] = c;
  31876. },
  31877. getRgbBuffer: function DeviceGrayCS_getRgbBuffer(src, srcOffset, count,
  31878. dest, destOffset, bits,
  31879. alpha01) {
  31880. var scale = 255 / ((1 << bits) - 1);
  31881. var j = srcOffset, q = destOffset;
  31882. for (var i = 0; i < count; ++i) {
  31883. var c = (scale * src[j++]) | 0;
  31884. dest[q++] = c;
  31885. dest[q++] = c;
  31886. dest[q++] = c;
  31887. q += alpha01;
  31888. }
  31889. },
  31890. getOutputLength: function DeviceGrayCS_getOutputLength(inputLength,
  31891. alpha01) {
  31892. return inputLength * (3 + alpha01);
  31893. },
  31894. isPassthrough: ColorSpace.prototype.isPassthrough,
  31895. fillRgb: ColorSpace.prototype.fillRgb,
  31896. isDefaultDecode: function DeviceGrayCS_isDefaultDecode(decodeMap) {
  31897. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  31898. },
  31899. usesZeroToOneRange: true
  31900. };
  31901. return DeviceGrayCS;
  31902. })();
  31903. var DeviceRgbCS = (function DeviceRgbCSClosure() {
  31904. function DeviceRgbCS() {
  31905. this.name = 'DeviceRGB';
  31906. this.numComps = 3;
  31907. this.defaultColor = new Float32Array([0, 0, 0]);
  31908. }
  31909. DeviceRgbCS.prototype = {
  31910. getRgb: ColorSpace.prototype.getRgb,
  31911. getRgbItem: function DeviceRgbCS_getRgbItem(src, srcOffset,
  31912. dest, destOffset) {
  31913. var r = (src[srcOffset] * 255) | 0;
  31914. var g = (src[srcOffset + 1] * 255) | 0;
  31915. var b = (src[srcOffset + 2] * 255) | 0;
  31916. dest[destOffset] = r < 0 ? 0 : r > 255 ? 255 : r;
  31917. dest[destOffset + 1] = g < 0 ? 0 : g > 255 ? 255 : g;
  31918. dest[destOffset + 2] = b < 0 ? 0 : b > 255 ? 255 : b;
  31919. },
  31920. getRgbBuffer: function DeviceRgbCS_getRgbBuffer(src, srcOffset, count,
  31921. dest, destOffset, bits,
  31922. alpha01) {
  31923. if (bits === 8 && alpha01 === 0) {
  31924. dest.set(src.subarray(srcOffset, srcOffset + count * 3), destOffset);
  31925. return;
  31926. }
  31927. var scale = 255 / ((1 << bits) - 1);
  31928. var j = srcOffset, q = destOffset;
  31929. for (var i = 0; i < count; ++i) {
  31930. dest[q++] = (scale * src[j++]) | 0;
  31931. dest[q++] = (scale * src[j++]) | 0;
  31932. dest[q++] = (scale * src[j++]) | 0;
  31933. q += alpha01;
  31934. }
  31935. },
  31936. getOutputLength: function DeviceRgbCS_getOutputLength(inputLength,
  31937. alpha01) {
  31938. return (inputLength * (3 + alpha01) / 3) | 0;
  31939. },
  31940. isPassthrough: function DeviceRgbCS_isPassthrough(bits) {
  31941. return bits === 8;
  31942. },
  31943. fillRgb: ColorSpace.prototype.fillRgb,
  31944. isDefaultDecode: function DeviceRgbCS_isDefaultDecode(decodeMap) {
  31945. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  31946. },
  31947. usesZeroToOneRange: true
  31948. };
  31949. return DeviceRgbCS;
  31950. })();
  31951. var DeviceCmykCS = (function DeviceCmykCSClosure() {
  31952. // The coefficients below was found using numerical analysis: the method of
  31953. // steepest descent for the sum((f_i - color_value_i)^2) for r/g/b colors,
  31954. // where color_value is the tabular value from the table of sampled RGB colors
  31955. // from CMYK US Web Coated (SWOP) colorspace, and f_i is the corresponding
  31956. // CMYK color conversion using the estimation below:
  31957. // f(A, B,.. N) = Acc+Bcm+Ccy+Dck+c+Fmm+Gmy+Hmk+Im+Jyy+Kyk+Ly+Mkk+Nk+255
  31958. function convertToRgb(src, srcOffset, srcScale, dest, destOffset) {
  31959. var c = src[srcOffset + 0] * srcScale;
  31960. var m = src[srcOffset + 1] * srcScale;
  31961. var y = src[srcOffset + 2] * srcScale;
  31962. var k = src[srcOffset + 3] * srcScale;
  31963. var r =
  31964. (c * (-4.387332384609988 * c + 54.48615194189176 * m +
  31965. 18.82290502165302 * y + 212.25662451639585 * k +
  31966. -285.2331026137004) +
  31967. m * (1.7149763477362134 * m - 5.6096736904047315 * y +
  31968. -17.873870861415444 * k - 5.497006427196366) +
  31969. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  31970. 17.5119270841813) +
  31971. k * (-21.86122147463605 * k - 189.48180835922747) + 255) | 0;
  31972. var g =
  31973. (c * (8.841041422036149 * c + 60.118027045597366 * m +
  31974. 6.871425592049007 * y + 31.159100130055922 * k +
  31975. -79.2970844816548) +
  31976. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  31977. 131.35250912493976 * k - 190.9453302588951) +
  31978. y * (4.444339102852739 * y + 9.8632861493405 * k - 24.86741582555878) +
  31979. k * (-20.737325471181034 * k - 187.80453709719578) + 255) | 0;
  31980. var b =
  31981. (c * (0.8842522430003296 * c + 8.078677503112928 * m +
  31982. 30.89978309703729 * y - 0.23883238689178934 * k +
  31983. -14.183576799673286) +
  31984. m * (10.49593273432072 * m + 63.02378494754052 * y +
  31985. 50.606957656360734 * k - 112.23884253719248) +
  31986. y * (0.03296041114873217 * y + 115.60384449646641 * k +
  31987. -193.58209356861505) +
  31988. k * (-22.33816807309886 * k - 180.12613974708367) + 255) | 0;
  31989. dest[destOffset] = r > 255 ? 255 : r < 0 ? 0 : r;
  31990. dest[destOffset + 1] = g > 255 ? 255 : g < 0 ? 0 : g;
  31991. dest[destOffset + 2] = b > 255 ? 255 : b < 0 ? 0 : b;
  31992. }
  31993. function DeviceCmykCS() {
  31994. this.name = 'DeviceCMYK';
  31995. this.numComps = 4;
  31996. this.defaultColor = new Float32Array([0, 0, 0, 1]);
  31997. }
  31998. DeviceCmykCS.prototype = {
  31999. getRgb: ColorSpace.prototype.getRgb,
  32000. getRgbItem: function DeviceCmykCS_getRgbItem(src, srcOffset,
  32001. dest, destOffset) {
  32002. convertToRgb(src, srcOffset, 1, dest, destOffset);
  32003. },
  32004. getRgbBuffer: function DeviceCmykCS_getRgbBuffer(src, srcOffset, count,
  32005. dest, destOffset, bits,
  32006. alpha01) {
  32007. var scale = 1 / ((1 << bits) - 1);
  32008. for (var i = 0; i < count; i++) {
  32009. convertToRgb(src, srcOffset, scale, dest, destOffset);
  32010. srcOffset += 4;
  32011. destOffset += 3 + alpha01;
  32012. }
  32013. },
  32014. getOutputLength: function DeviceCmykCS_getOutputLength(inputLength,
  32015. alpha01) {
  32016. return (inputLength / 4 * (3 + alpha01)) | 0;
  32017. },
  32018. isPassthrough: ColorSpace.prototype.isPassthrough,
  32019. fillRgb: ColorSpace.prototype.fillRgb,
  32020. isDefaultDecode: function DeviceCmykCS_isDefaultDecode(decodeMap) {
  32021. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  32022. },
  32023. usesZeroToOneRange: true
  32024. };
  32025. return DeviceCmykCS;
  32026. })();
  32027. //
  32028. // CalGrayCS: Based on "PDF Reference, Sixth Ed", p.245
  32029. //
  32030. var CalGrayCS = (function CalGrayCSClosure() {
  32031. function CalGrayCS(whitePoint, blackPoint, gamma) {
  32032. this.name = 'CalGray';
  32033. this.numComps = 1;
  32034. this.defaultColor = new Float32Array([0]);
  32035. if (!whitePoint) {
  32036. error('WhitePoint missing - required for color space CalGray');
  32037. }
  32038. blackPoint = blackPoint || [0, 0, 0];
  32039. gamma = gamma || 1;
  32040. // Translate arguments to spec variables.
  32041. this.XW = whitePoint[0];
  32042. this.YW = whitePoint[1];
  32043. this.ZW = whitePoint[2];
  32044. this.XB = blackPoint[0];
  32045. this.YB = blackPoint[1];
  32046. this.ZB = blackPoint[2];
  32047. this.G = gamma;
  32048. // Validate variables as per spec.
  32049. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  32050. error('Invalid WhitePoint components for ' + this.name +
  32051. ', no fallback available');
  32052. }
  32053. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  32054. info('Invalid BlackPoint for ' + this.name + ', falling back to default');
  32055. this.XB = this.YB = this.ZB = 0;
  32056. }
  32057. if (this.XB !== 0 || this.YB !== 0 || this.ZB !== 0) {
  32058. warn(this.name + ', BlackPoint: XB: ' + this.XB + ', YB: ' + this.YB +
  32059. ', ZB: ' + this.ZB + ', only default values are supported.');
  32060. }
  32061. if (this.G < 1) {
  32062. info('Invalid Gamma: ' + this.G + ' for ' + this.name +
  32063. ', falling back to default');
  32064. this.G = 1;
  32065. }
  32066. }
  32067. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  32068. // A represents a gray component of a calibrated gray space.
  32069. // A <---> AG in the spec
  32070. var A = src[srcOffset] * scale;
  32071. var AG = Math.pow(A, cs.G);
  32072. // Computes L as per spec. ( = cs.YW * AG )
  32073. // Except if other than default BlackPoint values are used.
  32074. var L = cs.YW * AG;
  32075. // http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html, Ch 4.
  32076. // Convert values to rgb range [0, 255].
  32077. var val = Math.max(295.8 * Math.pow(L, 0.333333333333333333) - 40.8, 0) | 0;
  32078. dest[destOffset] = val;
  32079. dest[destOffset + 1] = val;
  32080. dest[destOffset + 2] = val;
  32081. }
  32082. CalGrayCS.prototype = {
  32083. getRgb: ColorSpace.prototype.getRgb,
  32084. getRgbItem: function CalGrayCS_getRgbItem(src, srcOffset,
  32085. dest, destOffset) {
  32086. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  32087. },
  32088. getRgbBuffer: function CalGrayCS_getRgbBuffer(src, srcOffset, count,
  32089. dest, destOffset, bits,
  32090. alpha01) {
  32091. var scale = 1 / ((1 << bits) - 1);
  32092. for (var i = 0; i < count; ++i) {
  32093. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  32094. srcOffset += 1;
  32095. destOffset += 3 + alpha01;
  32096. }
  32097. },
  32098. getOutputLength: function CalGrayCS_getOutputLength(inputLength, alpha01) {
  32099. return inputLength * (3 + alpha01);
  32100. },
  32101. isPassthrough: ColorSpace.prototype.isPassthrough,
  32102. fillRgb: ColorSpace.prototype.fillRgb,
  32103. isDefaultDecode: function CalGrayCS_isDefaultDecode(decodeMap) {
  32104. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  32105. },
  32106. usesZeroToOneRange: true
  32107. };
  32108. return CalGrayCS;
  32109. })();
  32110. //
  32111. // CalRGBCS: Based on "PDF Reference, Sixth Ed", p.247
  32112. //
  32113. var CalRGBCS = (function CalRGBCSClosure() {
  32114. // See http://www.brucelindbloom.com/index.html?Eqn_ChromAdapt.html for these
  32115. // matrices.
  32116. var BRADFORD_SCALE_MATRIX = new Float32Array([
  32117. 0.8951, 0.2664, -0.1614,
  32118. -0.7502, 1.7135, 0.0367,
  32119. 0.0389, -0.0685, 1.0296]);
  32120. var BRADFORD_SCALE_INVERSE_MATRIX = new Float32Array([
  32121. 0.9869929, -0.1470543, 0.1599627,
  32122. 0.4323053, 0.5183603, 0.0492912,
  32123. -0.0085287, 0.0400428, 0.9684867]);
  32124. // See http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html.
  32125. var SRGB_D65_XYZ_TO_RGB_MATRIX = new Float32Array([
  32126. 3.2404542, -1.5371385, -0.4985314,
  32127. -0.9692660, 1.8760108, 0.0415560,
  32128. 0.0556434, -0.2040259, 1.0572252]);
  32129. var FLAT_WHITEPOINT_MATRIX = new Float32Array([1, 1, 1]);
  32130. var tempNormalizeMatrix = new Float32Array(3);
  32131. var tempConvertMatrix1 = new Float32Array(3);
  32132. var tempConvertMatrix2 = new Float32Array(3);
  32133. var DECODE_L_CONSTANT = Math.pow(((8 + 16) / 116), 3) / 8.0;
  32134. function CalRGBCS(whitePoint, blackPoint, gamma, matrix) {
  32135. this.name = 'CalRGB';
  32136. this.numComps = 3;
  32137. this.defaultColor = new Float32Array(3);
  32138. if (!whitePoint) {
  32139. error('WhitePoint missing - required for color space CalRGB');
  32140. }
  32141. blackPoint = blackPoint || new Float32Array(3);
  32142. gamma = gamma || new Float32Array([1, 1, 1]);
  32143. matrix = matrix || new Float32Array([1, 0, 0, 0, 1, 0, 0, 0, 1]);
  32144. // Translate arguments to spec variables.
  32145. var XW = whitePoint[0];
  32146. var YW = whitePoint[1];
  32147. var ZW = whitePoint[2];
  32148. this.whitePoint = whitePoint;
  32149. var XB = blackPoint[0];
  32150. var YB = blackPoint[1];
  32151. var ZB = blackPoint[2];
  32152. this.blackPoint = blackPoint;
  32153. this.GR = gamma[0];
  32154. this.GG = gamma[1];
  32155. this.GB = gamma[2];
  32156. this.MXA = matrix[0];
  32157. this.MYA = matrix[1];
  32158. this.MZA = matrix[2];
  32159. this.MXB = matrix[3];
  32160. this.MYB = matrix[4];
  32161. this.MZB = matrix[5];
  32162. this.MXC = matrix[6];
  32163. this.MYC = matrix[7];
  32164. this.MZC = matrix[8];
  32165. // Validate variables as per spec.
  32166. if (XW < 0 || ZW < 0 || YW !== 1) {
  32167. error('Invalid WhitePoint components for ' + this.name +
  32168. ', no fallback available');
  32169. }
  32170. if (XB < 0 || YB < 0 || ZB < 0) {
  32171. info('Invalid BlackPoint for ' + this.name + ' [' + XB + ', ' + YB +
  32172. ', ' + ZB + '], falling back to default');
  32173. this.blackPoint = new Float32Array(3);
  32174. }
  32175. if (this.GR < 0 || this.GG < 0 || this.GB < 0) {
  32176. info('Invalid Gamma [' + this.GR + ', ' + this.GG + ', ' + this.GB +
  32177. '] for ' + this.name + ', falling back to default');
  32178. this.GR = this.GG = this.GB = 1;
  32179. }
  32180. if (this.MXA < 0 || this.MYA < 0 || this.MZA < 0 ||
  32181. this.MXB < 0 || this.MYB < 0 || this.MZB < 0 ||
  32182. this.MXC < 0 || this.MYC < 0 || this.MZC < 0) {
  32183. info('Invalid Matrix for ' + this.name + ' [' +
  32184. this.MXA + ', ' + this.MYA + ', ' + this.MZA +
  32185. this.MXB + ', ' + this.MYB + ', ' + this.MZB +
  32186. this.MXC + ', ' + this.MYC + ', ' + this.MZC +
  32187. '], falling back to default');
  32188. this.MXA = this.MYB = this.MZC = 1;
  32189. this.MXB = this.MYA = this.MZA = this.MXC = this.MYC = this.MZB = 0;
  32190. }
  32191. }
  32192. function matrixProduct(a, b, result) {
  32193. result[0] = a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
  32194. result[1] = a[3] * b[0] + a[4] * b[1] + a[5] * b[2];
  32195. result[2] = a[6] * b[0] + a[7] * b[1] + a[8] * b[2];
  32196. }
  32197. function convertToFlat(sourceWhitePoint, LMS, result) {
  32198. result[0] = LMS[0] * 1 / sourceWhitePoint[0];
  32199. result[1] = LMS[1] * 1 / sourceWhitePoint[1];
  32200. result[2] = LMS[2] * 1 / sourceWhitePoint[2];
  32201. }
  32202. function convertToD65(sourceWhitePoint, LMS, result) {
  32203. var D65X = 0.95047;
  32204. var D65Y = 1;
  32205. var D65Z = 1.08883;
  32206. result[0] = LMS[0] * D65X / sourceWhitePoint[0];
  32207. result[1] = LMS[1] * D65Y / sourceWhitePoint[1];
  32208. result[2] = LMS[2] * D65Z / sourceWhitePoint[2];
  32209. }
  32210. function sRGBTransferFunction(color) {
  32211. // See http://en.wikipedia.org/wiki/SRGB.
  32212. if (color <= 0.0031308){
  32213. return adjustToRange(0, 1, 12.92 * color);
  32214. }
  32215. return adjustToRange(0, 1, (1 + 0.055) * Math.pow(color, 1 / 2.4) - 0.055);
  32216. }
  32217. function adjustToRange(min, max, value) {
  32218. return Math.max(min, Math.min(max, value));
  32219. }
  32220. function decodeL(L) {
  32221. if (L < 0) {
  32222. return -decodeL(-L);
  32223. }
  32224. if (L > 8.0) {
  32225. return Math.pow(((L + 16) / 116), 3);
  32226. }
  32227. return L * DECODE_L_CONSTANT;
  32228. }
  32229. function compensateBlackPoint(sourceBlackPoint, XYZ_Flat, result) {
  32230. // In case the blackPoint is already the default blackPoint then there is
  32231. // no need to do compensation.
  32232. if (sourceBlackPoint[0] === 0 &&
  32233. sourceBlackPoint[1] === 0 &&
  32234. sourceBlackPoint[2] === 0) {
  32235. result[0] = XYZ_Flat[0];
  32236. result[1] = XYZ_Flat[1];
  32237. result[2] = XYZ_Flat[2];
  32238. return;
  32239. }
  32240. // For the blackPoint calculation details, please see
  32241. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  32242. // AdobeBPC.pdf.
  32243. // The destination blackPoint is the default blackPoint [0, 0, 0].
  32244. var zeroDecodeL = decodeL(0);
  32245. var X_DST = zeroDecodeL;
  32246. var X_SRC = decodeL(sourceBlackPoint[0]);
  32247. var Y_DST = zeroDecodeL;
  32248. var Y_SRC = decodeL(sourceBlackPoint[1]);
  32249. var Z_DST = zeroDecodeL;
  32250. var Z_SRC = decodeL(sourceBlackPoint[2]);
  32251. var X_Scale = (1 - X_DST) / (1 - X_SRC);
  32252. var X_Offset = 1 - X_Scale;
  32253. var Y_Scale = (1 - Y_DST) / (1 - Y_SRC);
  32254. var Y_Offset = 1 - Y_Scale;
  32255. var Z_Scale = (1 - Z_DST) / (1 - Z_SRC);
  32256. var Z_Offset = 1 - Z_Scale;
  32257. result[0] = XYZ_Flat[0] * X_Scale + X_Offset;
  32258. result[1] = XYZ_Flat[1] * Y_Scale + Y_Offset;
  32259. result[2] = XYZ_Flat[2] * Z_Scale + Z_Offset;
  32260. }
  32261. function normalizeWhitePointToFlat(sourceWhitePoint, XYZ_In, result) {
  32262. // In case the whitePoint is already flat then there is no need to do
  32263. // normalization.
  32264. if (sourceWhitePoint[0] === 1 && sourceWhitePoint[2] === 1) {
  32265. result[0] = XYZ_In[0];
  32266. result[1] = XYZ_In[1];
  32267. result[2] = XYZ_In[2];
  32268. return;
  32269. }
  32270. var LMS = result;
  32271. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  32272. var LMS_Flat = tempNormalizeMatrix;
  32273. convertToFlat(sourceWhitePoint, LMS, LMS_Flat);
  32274. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_Flat, result);
  32275. }
  32276. function normalizeWhitePointToD65(sourceWhitePoint, XYZ_In, result) {
  32277. var LMS = result;
  32278. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  32279. var LMS_D65 = tempNormalizeMatrix;
  32280. convertToD65(sourceWhitePoint, LMS, LMS_D65);
  32281. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_D65, result);
  32282. }
  32283. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  32284. // A, B and C represent a red, green and blue components of a calibrated
  32285. // rgb space.
  32286. var A = adjustToRange(0, 1, src[srcOffset] * scale);
  32287. var B = adjustToRange(0, 1, src[srcOffset + 1] * scale);
  32288. var C = adjustToRange(0, 1, src[srcOffset + 2] * scale);
  32289. // A <---> AGR in the spec
  32290. // B <---> BGG in the spec
  32291. // C <---> CGB in the spec
  32292. var AGR = Math.pow(A, cs.GR);
  32293. var BGG = Math.pow(B, cs.GG);
  32294. var CGB = Math.pow(C, cs.GB);
  32295. // Computes intermediate variables L, M, N as per spec.
  32296. // To decode X, Y, Z values map L, M, N directly to them.
  32297. var X = cs.MXA * AGR + cs.MXB * BGG + cs.MXC * CGB;
  32298. var Y = cs.MYA * AGR + cs.MYB * BGG + cs.MYC * CGB;
  32299. var Z = cs.MZA * AGR + cs.MZB * BGG + cs.MZC * CGB;
  32300. // The following calculations are based on this document:
  32301. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  32302. // AdobeBPC.pdf.
  32303. var XYZ = tempConvertMatrix1;
  32304. XYZ[0] = X;
  32305. XYZ[1] = Y;
  32306. XYZ[2] = Z;
  32307. var XYZ_Flat = tempConvertMatrix2;
  32308. normalizeWhitePointToFlat(cs.whitePoint, XYZ, XYZ_Flat);
  32309. var XYZ_Black = tempConvertMatrix1;
  32310. compensateBlackPoint(cs.blackPoint, XYZ_Flat, XYZ_Black);
  32311. var XYZ_D65 = tempConvertMatrix2;
  32312. normalizeWhitePointToD65(FLAT_WHITEPOINT_MATRIX, XYZ_Black, XYZ_D65);
  32313. var SRGB = tempConvertMatrix1;
  32314. matrixProduct(SRGB_D65_XYZ_TO_RGB_MATRIX, XYZ_D65, SRGB);
  32315. var sR = sRGBTransferFunction(SRGB[0]);
  32316. var sG = sRGBTransferFunction(SRGB[1]);
  32317. var sB = sRGBTransferFunction(SRGB[2]);
  32318. // Convert the values to rgb range [0, 255].
  32319. dest[destOffset] = Math.round(sR * 255);
  32320. dest[destOffset + 1] = Math.round(sG * 255);
  32321. dest[destOffset + 2] = Math.round(sB * 255);
  32322. }
  32323. CalRGBCS.prototype = {
  32324. getRgb: function CalRGBCS_getRgb(src, srcOffset) {
  32325. var rgb = new Uint8Array(3);
  32326. this.getRgbItem(src, srcOffset, rgb, 0);
  32327. return rgb;
  32328. },
  32329. getRgbItem: function CalRGBCS_getRgbItem(src, srcOffset,
  32330. dest, destOffset) {
  32331. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  32332. },
  32333. getRgbBuffer: function CalRGBCS_getRgbBuffer(src, srcOffset, count,
  32334. dest, destOffset, bits,
  32335. alpha01) {
  32336. var scale = 1 / ((1 << bits) - 1);
  32337. for (var i = 0; i < count; ++i) {
  32338. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  32339. srcOffset += 3;
  32340. destOffset += 3 + alpha01;
  32341. }
  32342. },
  32343. getOutputLength: function CalRGBCS_getOutputLength(inputLength, alpha01) {
  32344. return (inputLength * (3 + alpha01) / 3) | 0;
  32345. },
  32346. isPassthrough: ColorSpace.prototype.isPassthrough,
  32347. fillRgb: ColorSpace.prototype.fillRgb,
  32348. isDefaultDecode: function CalRGBCS_isDefaultDecode(decodeMap) {
  32349. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  32350. },
  32351. usesZeroToOneRange: true
  32352. };
  32353. return CalRGBCS;
  32354. })();
  32355. //
  32356. // LabCS: Based on "PDF Reference, Sixth Ed", p.250
  32357. //
  32358. var LabCS = (function LabCSClosure() {
  32359. function LabCS(whitePoint, blackPoint, range) {
  32360. this.name = 'Lab';
  32361. this.numComps = 3;
  32362. this.defaultColor = new Float32Array([0, 0, 0]);
  32363. if (!whitePoint) {
  32364. error('WhitePoint missing - required for color space Lab');
  32365. }
  32366. blackPoint = blackPoint || [0, 0, 0];
  32367. range = range || [-100, 100, -100, 100];
  32368. // Translate args to spec variables
  32369. this.XW = whitePoint[0];
  32370. this.YW = whitePoint[1];
  32371. this.ZW = whitePoint[2];
  32372. this.amin = range[0];
  32373. this.amax = range[1];
  32374. this.bmin = range[2];
  32375. this.bmax = range[3];
  32376. // These are here just for completeness - the spec doesn't offer any
  32377. // formulas that use BlackPoint in Lab
  32378. this.XB = blackPoint[0];
  32379. this.YB = blackPoint[1];
  32380. this.ZB = blackPoint[2];
  32381. // Validate vars as per spec
  32382. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  32383. error('Invalid WhitePoint components, no fallback available');
  32384. }
  32385. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  32386. info('Invalid BlackPoint, falling back to default');
  32387. this.XB = this.YB = this.ZB = 0;
  32388. }
  32389. if (this.amin > this.amax || this.bmin > this.bmax) {
  32390. info('Invalid Range, falling back to defaults');
  32391. this.amin = -100;
  32392. this.amax = 100;
  32393. this.bmin = -100;
  32394. this.bmax = 100;
  32395. }
  32396. }
  32397. // Function g(x) from spec
  32398. function fn_g(x) {
  32399. if (x >= 6 / 29) {
  32400. return x * x * x;
  32401. } else {
  32402. return (108 / 841) * (x - 4 / 29);
  32403. }
  32404. }
  32405. function decode(value, high1, low2, high2) {
  32406. return low2 + (value) * (high2 - low2) / (high1);
  32407. }
  32408. // If decoding is needed maxVal should be 2^bits per component - 1.
  32409. function convertToRgb(cs, src, srcOffset, maxVal, dest, destOffset) {
  32410. // XXX: Lab input is in the range of [0, 100], [amin, amax], [bmin, bmax]
  32411. // not the usual [0, 1]. If a command like setFillColor is used the src
  32412. // values will already be within the correct range. However, if we are
  32413. // converting an image we have to map the values to the correct range given
  32414. // above.
  32415. // Ls,as,bs <---> L*,a*,b* in the spec
  32416. var Ls = src[srcOffset];
  32417. var as = src[srcOffset + 1];
  32418. var bs = src[srcOffset + 2];
  32419. if (maxVal !== false) {
  32420. Ls = decode(Ls, maxVal, 0, 100);
  32421. as = decode(as, maxVal, cs.amin, cs.amax);
  32422. bs = decode(bs, maxVal, cs.bmin, cs.bmax);
  32423. }
  32424. // Adjust limits of 'as' and 'bs'
  32425. as = as > cs.amax ? cs.amax : as < cs.amin ? cs.amin : as;
  32426. bs = bs > cs.bmax ? cs.bmax : bs < cs.bmin ? cs.bmin : bs;
  32427. // Computes intermediate variables X,Y,Z as per spec
  32428. var M = (Ls + 16) / 116;
  32429. var L = M + (as / 500);
  32430. var N = M - (bs / 200);
  32431. var X = cs.XW * fn_g(L);
  32432. var Y = cs.YW * fn_g(M);
  32433. var Z = cs.ZW * fn_g(N);
  32434. var r, g, b;
  32435. // Using different conversions for D50 and D65 white points,
  32436. // per http://www.color.org/srgb.pdf
  32437. if (cs.ZW < 1) {
  32438. // Assuming D50 (X=0.9642, Y=1.00, Z=0.8249)
  32439. r = X * 3.1339 + Y * -1.6170 + Z * -0.4906;
  32440. g = X * -0.9785 + Y * 1.9160 + Z * 0.0333;
  32441. b = X * 0.0720 + Y * -0.2290 + Z * 1.4057;
  32442. } else {
  32443. // Assuming D65 (X=0.9505, Y=1.00, Z=1.0888)
  32444. r = X * 3.2406 + Y * -1.5372 + Z * -0.4986;
  32445. g = X * -0.9689 + Y * 1.8758 + Z * 0.0415;
  32446. b = X * 0.0557 + Y * -0.2040 + Z * 1.0570;
  32447. }
  32448. // clamp color values to [0,1] range then convert to [0,255] range.
  32449. dest[destOffset] = r <= 0 ? 0 : r >= 1 ? 255 : Math.sqrt(r) * 255 | 0;
  32450. dest[destOffset + 1] = g <= 0 ? 0 : g >= 1 ? 255 : Math.sqrt(g) * 255 | 0;
  32451. dest[destOffset + 2] = b <= 0 ? 0 : b >= 1 ? 255 : Math.sqrt(b) * 255 | 0;
  32452. }
  32453. LabCS.prototype = {
  32454. getRgb: ColorSpace.prototype.getRgb,
  32455. getRgbItem: function LabCS_getRgbItem(src, srcOffset, dest, destOffset) {
  32456. convertToRgb(this, src, srcOffset, false, dest, destOffset);
  32457. },
  32458. getRgbBuffer: function LabCS_getRgbBuffer(src, srcOffset, count,
  32459. dest, destOffset, bits,
  32460. alpha01) {
  32461. var maxVal = (1 << bits) - 1;
  32462. for (var i = 0; i < count; i++) {
  32463. convertToRgb(this, src, srcOffset, maxVal, dest, destOffset);
  32464. srcOffset += 3;
  32465. destOffset += 3 + alpha01;
  32466. }
  32467. },
  32468. getOutputLength: function LabCS_getOutputLength(inputLength, alpha01) {
  32469. return (inputLength * (3 + alpha01) / 3) | 0;
  32470. },
  32471. isPassthrough: ColorSpace.prototype.isPassthrough,
  32472. fillRgb: ColorSpace.prototype.fillRgb,
  32473. isDefaultDecode: function LabCS_isDefaultDecode(decodeMap) {
  32474. // XXX: Decoding is handled with the lab conversion because of the strange
  32475. // ranges that are used.
  32476. return true;
  32477. },
  32478. usesZeroToOneRange: false
  32479. };
  32480. return LabCS;
  32481. })();
  32482. // TODO refactor to remove dependency on image.js
  32483. function _setCoreImage(coreImage_) {
  32484. coreImage = coreImage_;
  32485. PDFImage = coreImage_.PDFImage;
  32486. }
  32487. exports._setCoreImage = _setCoreImage;
  32488. exports.ColorSpace = ColorSpace;
  32489. // TODO refactor to remove dependency on colorspace.js
  32490. coreStream._setCoreColorSpace(exports);
  32491. }));
  32492. (function (root, factory) {
  32493. if (typeof define === 'function' && define.amd) {
  32494. define('pdfjs/core/image', ['exports', 'pdfjs/shared/util',
  32495. 'pdfjs/core/primitives', 'pdfjs/core/colorspace', 'pdfjs/core/stream',
  32496. 'pdfjs/core/jpx'], factory);
  32497. } else if (typeof exports !== 'undefined') {
  32498. factory(exports, require('../shared/util.js'), require('./primitives.js'),
  32499. require('./colorspace.js'), require('./stream.js'),
  32500. require('./jpx.js'));
  32501. } else {
  32502. factory((root.pdfjsCoreImage = {}), root.pdfjsSharedUtil,
  32503. root.pdfjsCorePrimitives, root.pdfjsCoreColorSpace, root.pdfjsCoreStream,
  32504. root.pdfjsCoreJpx);
  32505. }
  32506. }(this, function (exports, sharedUtil, corePrimitives, coreColorSpace,
  32507. coreStream, coreJpx) {
  32508. var ImageKind = sharedUtil.ImageKind;
  32509. var assert = sharedUtil.assert;
  32510. var error = sharedUtil.error;
  32511. var info = sharedUtil.info;
  32512. var isArray = sharedUtil.isArray;
  32513. var warn = sharedUtil.warn;
  32514. var Name = corePrimitives.Name;
  32515. var isStream = corePrimitives.isStream;
  32516. var ColorSpace = coreColorSpace.ColorSpace;
  32517. var DecodeStream = coreStream.DecodeStream;
  32518. var Stream = coreStream.Stream;
  32519. var JpegStream = coreStream.JpegStream;
  32520. var JpxImage = coreJpx.JpxImage;
  32521. var PDFImage = (function PDFImageClosure() {
  32522. /**
  32523. * Decode the image in the main thread if it supported. Resovles the promise
  32524. * when the image data is ready.
  32525. */
  32526. function handleImageData(handler, xref, res, image) {
  32527. if (image instanceof JpegStream && image.isNativelyDecodable(xref, res)) {
  32528. // For natively supported jpegs send them to the main thread for decoding.
  32529. var dict = image.dict;
  32530. var colorSpace = dict.get('ColorSpace', 'CS');
  32531. colorSpace = ColorSpace.parse(colorSpace, xref, res);
  32532. var numComps = colorSpace.numComps;
  32533. var decodePromise = handler.sendWithPromise('JpegDecode',
  32534. [image.getIR(), numComps]);
  32535. return decodePromise.then(function (message) {
  32536. var data = message.data;
  32537. return new Stream(data, 0, data.length, image.dict);
  32538. });
  32539. } else {
  32540. return Promise.resolve(image);
  32541. }
  32542. }
  32543. /**
  32544. * Decode and clamp a value. The formula is different from the spec because we
  32545. * don't decode to float range [0,1], we decode it in the [0,max] range.
  32546. */
  32547. function decodeAndClamp(value, addend, coefficient, max) {
  32548. value = addend + value * coefficient;
  32549. // Clamp the value to the range
  32550. return (value < 0 ? 0 : (value > max ? max : value));
  32551. }
  32552. function PDFImage(xref, res, image, inline, smask, mask, isMask) {
  32553. this.image = image;
  32554. var dict = image.dict;
  32555. if (dict.has('Filter')) {
  32556. var filter = dict.get('Filter').name;
  32557. if (filter === 'JPXDecode') {
  32558. var jpxImage = new JpxImage();
  32559. jpxImage.parseImageProperties(image.stream);
  32560. image.stream.reset();
  32561. image.bitsPerComponent = jpxImage.bitsPerComponent;
  32562. image.numComps = jpxImage.componentsCount;
  32563. } else if (filter === 'JBIG2Decode') {
  32564. image.bitsPerComponent = 1;
  32565. image.numComps = 1;
  32566. }
  32567. }
  32568. // TODO cache rendered images?
  32569. this.width = dict.get('Width', 'W');
  32570. this.height = dict.get('Height', 'H');
  32571. if (this.width < 1 || this.height < 1) {
  32572. error('Invalid image width: ' + this.width + ' or height: ' +
  32573. this.height);
  32574. }
  32575. this.interpolate = dict.get('Interpolate', 'I') || false;
  32576. this.imageMask = dict.get('ImageMask', 'IM') || false;
  32577. this.matte = dict.get('Matte') || false;
  32578. var bitsPerComponent = image.bitsPerComponent;
  32579. if (!bitsPerComponent) {
  32580. bitsPerComponent = dict.get('BitsPerComponent', 'BPC');
  32581. if (!bitsPerComponent) {
  32582. if (this.imageMask) {
  32583. bitsPerComponent = 1;
  32584. } else {
  32585. error('Bits per component missing in image: ' + this.imageMask);
  32586. }
  32587. }
  32588. }
  32589. this.bpc = bitsPerComponent;
  32590. if (!this.imageMask) {
  32591. var colorSpace = dict.get('ColorSpace', 'CS');
  32592. if (!colorSpace) {
  32593. info('JPX images (which do not require color spaces)');
  32594. switch (image.numComps) {
  32595. case 1:
  32596. colorSpace = Name.get('DeviceGray');
  32597. break;
  32598. case 3:
  32599. colorSpace = Name.get('DeviceRGB');
  32600. break;
  32601. case 4:
  32602. colorSpace = Name.get('DeviceCMYK');
  32603. break;
  32604. default:
  32605. error('JPX images with ' + this.numComps +
  32606. ' color components not supported.');
  32607. }
  32608. }
  32609. this.colorSpace = ColorSpace.parse(colorSpace, xref, res);
  32610. this.numComps = this.colorSpace.numComps;
  32611. }
  32612. this.decode = dict.get('Decode', 'D');
  32613. this.needsDecode = false;
  32614. if (this.decode &&
  32615. ((this.colorSpace && !this.colorSpace.isDefaultDecode(this.decode)) ||
  32616. (isMask && !ColorSpace.isDefaultDecode(this.decode, 1)))) {
  32617. this.needsDecode = true;
  32618. // Do some preprocessing to avoid more math.
  32619. var max = (1 << bitsPerComponent) - 1;
  32620. this.decodeCoefficients = [];
  32621. this.decodeAddends = [];
  32622. for (var i = 0, j = 0; i < this.decode.length; i += 2, ++j) {
  32623. var dmin = this.decode[i];
  32624. var dmax = this.decode[i + 1];
  32625. this.decodeCoefficients[j] = dmax - dmin;
  32626. this.decodeAddends[j] = max * dmin;
  32627. }
  32628. }
  32629. if (smask) {
  32630. this.smask = new PDFImage(xref, res, smask, false);
  32631. } else if (mask) {
  32632. if (isStream(mask)) {
  32633. var maskDict = mask.dict, imageMask = maskDict.get('ImageMask', 'IM');
  32634. if (!imageMask) {
  32635. warn('Ignoring /Mask in image without /ImageMask.');
  32636. } else {
  32637. this.mask = new PDFImage(xref, res, mask, false, null, null, true);
  32638. }
  32639. } else {
  32640. // Color key mask (just an array).
  32641. this.mask = mask;
  32642. }
  32643. }
  32644. }
  32645. /**
  32646. * Handles processing of image data and returns the Promise that is resolved
  32647. * with a PDFImage when the image is ready to be used.
  32648. */
  32649. PDFImage.buildImage = function PDFImage_buildImage(handler, xref,
  32650. res, image, inline) {
  32651. var imagePromise = handleImageData(handler, xref, res, image);
  32652. var smaskPromise;
  32653. var maskPromise;
  32654. var smask = image.dict.get('SMask');
  32655. var mask = image.dict.get('Mask');
  32656. if (smask) {
  32657. smaskPromise = handleImageData(handler, xref, res, smask);
  32658. maskPromise = Promise.resolve(null);
  32659. } else {
  32660. smaskPromise = Promise.resolve(null);
  32661. if (mask) {
  32662. if (isStream(mask)) {
  32663. maskPromise = handleImageData(handler, xref, res, mask);
  32664. } else if (isArray(mask)) {
  32665. maskPromise = Promise.resolve(mask);
  32666. } else {
  32667. warn('Unsupported mask format.');
  32668. maskPromise = Promise.resolve(null);
  32669. }
  32670. } else {
  32671. maskPromise = Promise.resolve(null);
  32672. }
  32673. }
  32674. return Promise.all([imagePromise, smaskPromise, maskPromise]).then(
  32675. function(results) {
  32676. var imageData = results[0];
  32677. var smaskData = results[1];
  32678. var maskData = results[2];
  32679. return new PDFImage(xref, res, imageData, inline, smaskData, maskData);
  32680. });
  32681. };
  32682. /**
  32683. * Resize an image using the nearest neighbor algorithm. Currently only
  32684. * supports one and three component images.
  32685. * @param {TypedArray} pixels The original image with one component.
  32686. * @param {Number} bpc Number of bits per component.
  32687. * @param {Number} components Number of color components, 1 or 3 is supported.
  32688. * @param {Number} w1 Original width.
  32689. * @param {Number} h1 Original height.
  32690. * @param {Number} w2 New width.
  32691. * @param {Number} h2 New height.
  32692. * @param {TypedArray} dest (Optional) The destination buffer.
  32693. * @param {Number} alpha01 (Optional) Size reserved for the alpha channel.
  32694. * @return {TypedArray} Resized image data.
  32695. */
  32696. PDFImage.resize = function PDFImage_resize(pixels, bpc, components,
  32697. w1, h1, w2, h2, dest, alpha01) {
  32698. if (components !== 1 && components !== 3) {
  32699. error('Unsupported component count for resizing.');
  32700. }
  32701. var length = w2 * h2 * components;
  32702. var temp = dest ? dest : (bpc <= 8 ? new Uint8Array(length) :
  32703. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  32704. var xRatio = w1 / w2;
  32705. var yRatio = h1 / h2;
  32706. var i, j, py, newIndex = 0, oldIndex;
  32707. var xScaled = new Uint16Array(w2);
  32708. var w1Scanline = w1 * components;
  32709. if (alpha01 !== 1) {
  32710. alpha01 = 0;
  32711. }
  32712. for (j = 0; j < w2; j++) {
  32713. xScaled[j] = Math.floor(j * xRatio) * components;
  32714. }
  32715. if (components === 1) {
  32716. for (i = 0; i < h2; i++) {
  32717. py = Math.floor(i * yRatio) * w1Scanline;
  32718. for (j = 0; j < w2; j++) {
  32719. oldIndex = py + xScaled[j];
  32720. temp[newIndex++] = pixels[oldIndex];
  32721. }
  32722. }
  32723. } else if (components === 3) {
  32724. for (i = 0; i < h2; i++) {
  32725. py = Math.floor(i * yRatio) * w1Scanline;
  32726. for (j = 0; j < w2; j++) {
  32727. oldIndex = py + xScaled[j];
  32728. temp[newIndex++] = pixels[oldIndex++];
  32729. temp[newIndex++] = pixels[oldIndex++];
  32730. temp[newIndex++] = pixels[oldIndex++];
  32731. newIndex += alpha01;
  32732. }
  32733. }
  32734. }
  32735. return temp;
  32736. };
  32737. PDFImage.createMask =
  32738. function PDFImage_createMask(imgArray, width, height,
  32739. imageIsFromDecodeStream, inverseDecode) {
  32740. // |imgArray| might not contain full data for every pixel of the mask, so
  32741. // we need to distinguish between |computedLength| and |actualLength|.
  32742. // In particular, if inverseDecode is true, then the array we return must
  32743. // have a length of |computedLength|.
  32744. var computedLength = ((width + 7) >> 3) * height;
  32745. var actualLength = imgArray.byteLength;
  32746. var haveFullData = computedLength === actualLength;
  32747. var data, i;
  32748. if (imageIsFromDecodeStream && (!inverseDecode || haveFullData)) {
  32749. // imgArray came from a DecodeStream and its data is in an appropriate
  32750. // form, so we can just transfer it.
  32751. data = imgArray;
  32752. } else if (!inverseDecode) {
  32753. data = new Uint8Array(actualLength);
  32754. data.set(imgArray);
  32755. } else {
  32756. data = new Uint8Array(computedLength);
  32757. data.set(imgArray);
  32758. for (i = actualLength; i < computedLength; i++) {
  32759. data[i] = 0xff;
  32760. }
  32761. }
  32762. // If necessary, invert the original mask data (but not any extra we might
  32763. // have added above). It's safe to modify the array -- whether it's the
  32764. // original or a copy, we're about to transfer it anyway, so nothing else
  32765. // in this thread can be relying on its contents.
  32766. if (inverseDecode) {
  32767. for (i = 0; i < actualLength; i++) {
  32768. data[i] = ~data[i];
  32769. }
  32770. }
  32771. return {data: data, width: width, height: height};
  32772. };
  32773. PDFImage.prototype = {
  32774. get drawWidth() {
  32775. return Math.max(this.width,
  32776. this.smask && this.smask.width || 0,
  32777. this.mask && this.mask.width || 0);
  32778. },
  32779. get drawHeight() {
  32780. return Math.max(this.height,
  32781. this.smask && this.smask.height || 0,
  32782. this.mask && this.mask.height || 0);
  32783. },
  32784. decodeBuffer: function PDFImage_decodeBuffer(buffer) {
  32785. var bpc = this.bpc;
  32786. var numComps = this.numComps;
  32787. var decodeAddends = this.decodeAddends;
  32788. var decodeCoefficients = this.decodeCoefficients;
  32789. var max = (1 << bpc) - 1;
  32790. var i, ii;
  32791. if (bpc === 1) {
  32792. // If the buffer needed decode that means it just needs to be inverted.
  32793. for (i = 0, ii = buffer.length; i < ii; i++) {
  32794. buffer[i] = +!(buffer[i]);
  32795. }
  32796. return;
  32797. }
  32798. var index = 0;
  32799. for (i = 0, ii = this.width * this.height; i < ii; i++) {
  32800. for (var j = 0; j < numComps; j++) {
  32801. buffer[index] = decodeAndClamp(buffer[index], decodeAddends[j],
  32802. decodeCoefficients[j], max);
  32803. index++;
  32804. }
  32805. }
  32806. },
  32807. getComponents: function PDFImage_getComponents(buffer) {
  32808. var bpc = this.bpc;
  32809. // This image doesn't require any extra work.
  32810. if (bpc === 8) {
  32811. return buffer;
  32812. }
  32813. var width = this.width;
  32814. var height = this.height;
  32815. var numComps = this.numComps;
  32816. var length = width * height * numComps;
  32817. var bufferPos = 0;
  32818. var output = (bpc <= 8 ? new Uint8Array(length) :
  32819. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  32820. var rowComps = width * numComps;
  32821. var max = (1 << bpc) - 1;
  32822. var i = 0, ii, buf;
  32823. if (bpc === 1) {
  32824. // Optimization for reading 1 bpc images.
  32825. var mask, loop1End, loop2End;
  32826. for (var j = 0; j < height; j++) {
  32827. loop1End = i + (rowComps & ~7);
  32828. loop2End = i + rowComps;
  32829. // unroll loop for all full bytes
  32830. while (i < loop1End) {
  32831. buf = buffer[bufferPos++];
  32832. output[i] = (buf >> 7) & 1;
  32833. output[i + 1] = (buf >> 6) & 1;
  32834. output[i + 2] = (buf >> 5) & 1;
  32835. output[i + 3] = (buf >> 4) & 1;
  32836. output[i + 4] = (buf >> 3) & 1;
  32837. output[i + 5] = (buf >> 2) & 1;
  32838. output[i + 6] = (buf >> 1) & 1;
  32839. output[i + 7] = buf & 1;
  32840. i += 8;
  32841. }
  32842. // handle remaing bits
  32843. if (i < loop2End) {
  32844. buf = buffer[bufferPos++];
  32845. mask = 128;
  32846. while (i < loop2End) {
  32847. output[i++] = +!!(buf & mask);
  32848. mask >>= 1;
  32849. }
  32850. }
  32851. }
  32852. } else {
  32853. // The general case that handles all other bpc values.
  32854. var bits = 0;
  32855. buf = 0;
  32856. for (i = 0, ii = length; i < ii; ++i) {
  32857. if (i % rowComps === 0) {
  32858. buf = 0;
  32859. bits = 0;
  32860. }
  32861. while (bits < bpc) {
  32862. buf = (buf << 8) | buffer[bufferPos++];
  32863. bits += 8;
  32864. }
  32865. var remainingBits = bits - bpc;
  32866. var value = buf >> remainingBits;
  32867. output[i] = (value < 0 ? 0 : (value > max ? max : value));
  32868. buf = buf & ((1 << remainingBits) - 1);
  32869. bits = remainingBits;
  32870. }
  32871. }
  32872. return output;
  32873. },
  32874. fillOpacity: function PDFImage_fillOpacity(rgbaBuf, width, height,
  32875. actualHeight, image) {
  32876. var smask = this.smask;
  32877. var mask = this.mask;
  32878. var alphaBuf, sw, sh, i, ii, j;
  32879. if (smask) {
  32880. sw = smask.width;
  32881. sh = smask.height;
  32882. alphaBuf = new Uint8Array(sw * sh);
  32883. smask.fillGrayBuffer(alphaBuf);
  32884. if (sw !== width || sh !== height) {
  32885. alphaBuf = PDFImage.resize(alphaBuf, smask.bpc, 1, sw, sh, width,
  32886. height);
  32887. }
  32888. } else if (mask) {
  32889. if (mask instanceof PDFImage) {
  32890. sw = mask.width;
  32891. sh = mask.height;
  32892. alphaBuf = new Uint8Array(sw * sh);
  32893. mask.numComps = 1;
  32894. mask.fillGrayBuffer(alphaBuf);
  32895. // Need to invert values in rgbaBuf
  32896. for (i = 0, ii = sw * sh; i < ii; ++i) {
  32897. alphaBuf[i] = 255 - alphaBuf[i];
  32898. }
  32899. if (sw !== width || sh !== height) {
  32900. alphaBuf = PDFImage.resize(alphaBuf, mask.bpc, 1, sw, sh, width,
  32901. height);
  32902. }
  32903. } else if (isArray(mask)) {
  32904. // Color key mask: if any of the compontents are outside the range
  32905. // then they should be painted.
  32906. alphaBuf = new Uint8Array(width * height);
  32907. var numComps = this.numComps;
  32908. for (i = 0, ii = width * height; i < ii; ++i) {
  32909. var opacity = 0;
  32910. var imageOffset = i * numComps;
  32911. for (j = 0; j < numComps; ++j) {
  32912. var color = image[imageOffset + j];
  32913. var maskOffset = j * 2;
  32914. if (color < mask[maskOffset] || color > mask[maskOffset + 1]) {
  32915. opacity = 255;
  32916. break;
  32917. }
  32918. }
  32919. alphaBuf[i] = opacity;
  32920. }
  32921. } else {
  32922. error('Unknown mask format.');
  32923. }
  32924. }
  32925. if (alphaBuf) {
  32926. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  32927. rgbaBuf[j] = alphaBuf[i];
  32928. }
  32929. } else {
  32930. // No mask.
  32931. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  32932. rgbaBuf[j] = 255;
  32933. }
  32934. }
  32935. },
  32936. undoPreblend: function PDFImage_undoPreblend(buffer, width, height) {
  32937. var matte = this.smask && this.smask.matte;
  32938. if (!matte) {
  32939. return;
  32940. }
  32941. var matteRgb = this.colorSpace.getRgb(matte, 0);
  32942. var matteR = matteRgb[0];
  32943. var matteG = matteRgb[1];
  32944. var matteB = matteRgb[2];
  32945. var length = width * height * 4;
  32946. var r, g, b;
  32947. for (var i = 0; i < length; i += 4) {
  32948. var alpha = buffer[i + 3];
  32949. if (alpha === 0) {
  32950. // according formula we have to get Infinity in all components
  32951. // making it white (typical paper color) should be okay
  32952. buffer[i] = 255;
  32953. buffer[i + 1] = 255;
  32954. buffer[i + 2] = 255;
  32955. continue;
  32956. }
  32957. var k = 255 / alpha;
  32958. r = (buffer[i] - matteR) * k + matteR;
  32959. g = (buffer[i + 1] - matteG) * k + matteG;
  32960. b = (buffer[i + 2] - matteB) * k + matteB;
  32961. buffer[i] = r <= 0 ? 0 : r >= 255 ? 255 : r | 0;
  32962. buffer[i + 1] = g <= 0 ? 0 : g >= 255 ? 255 : g | 0;
  32963. buffer[i + 2] = b <= 0 ? 0 : b >= 255 ? 255 : b | 0;
  32964. }
  32965. },
  32966. createImageData: function PDFImage_createImageData(forceRGBA) {
  32967. var drawWidth = this.drawWidth;
  32968. var drawHeight = this.drawHeight;
  32969. var imgData = { // other fields are filled in below
  32970. width: drawWidth,
  32971. height: drawHeight
  32972. };
  32973. var numComps = this.numComps;
  32974. var originalWidth = this.width;
  32975. var originalHeight = this.height;
  32976. var bpc = this.bpc;
  32977. // Rows start at byte boundary.
  32978. var rowBytes = (originalWidth * numComps * bpc + 7) >> 3;
  32979. var imgArray;
  32980. if (!forceRGBA) {
  32981. // If it is a 1-bit-per-pixel grayscale (i.e. black-and-white) image
  32982. // without any complications, we pass a same-sized copy to the main
  32983. // thread rather than expanding by 32x to RGBA form. This saves *lots*
  32984. // of memory for many scanned documents. It's also much faster.
  32985. //
  32986. // Similarly, if it is a 24-bit-per pixel RGB image without any
  32987. // complications, we avoid expanding by 1.333x to RGBA form.
  32988. var kind;
  32989. if (this.colorSpace.name === 'DeviceGray' && bpc === 1) {
  32990. kind = ImageKind.GRAYSCALE_1BPP;
  32991. } else if (this.colorSpace.name === 'DeviceRGB' && bpc === 8 &&
  32992. !this.needsDecode) {
  32993. kind = ImageKind.RGB_24BPP;
  32994. }
  32995. if (kind && !this.smask && !this.mask &&
  32996. drawWidth === originalWidth && drawHeight === originalHeight) {
  32997. imgData.kind = kind;
  32998. imgArray = this.getImageBytes(originalHeight * rowBytes);
  32999. // If imgArray came from a DecodeStream, we're safe to transfer it
  33000. // (and thus neuter it) because it will constitute the entire
  33001. // DecodeStream's data. But if it came from a Stream, we need to
  33002. // copy it because it'll only be a portion of the Stream's data, and
  33003. // the rest will be read later on.
  33004. if (this.image instanceof DecodeStream) {
  33005. imgData.data = imgArray;
  33006. } else {
  33007. var newArray = new Uint8Array(imgArray.length);
  33008. newArray.set(imgArray);
  33009. imgData.data = newArray;
  33010. }
  33011. if (this.needsDecode) {
  33012. // Invert the buffer (which must be grayscale if we reached here).
  33013. assert(kind === ImageKind.GRAYSCALE_1BPP);
  33014. var buffer = imgData.data;
  33015. for (var i = 0, ii = buffer.length; i < ii; i++) {
  33016. buffer[i] ^= 0xff;
  33017. }
  33018. }
  33019. return imgData;
  33020. }
  33021. if (this.image instanceof JpegStream && !this.smask && !this.mask &&
  33022. (this.colorSpace.name === 'DeviceGray' ||
  33023. this.colorSpace.name === 'DeviceRGB' ||
  33024. this.colorSpace.name === 'DeviceCMYK')) {
  33025. imgData.kind = ImageKind.RGB_24BPP;
  33026. imgData.data = this.getImageBytes(originalHeight * rowBytes,
  33027. drawWidth, drawHeight, true);
  33028. return imgData;
  33029. }
  33030. }
  33031. imgArray = this.getImageBytes(originalHeight * rowBytes);
  33032. // imgArray can be incomplete (e.g. after CCITT fax encoding).
  33033. var actualHeight = 0 | (imgArray.length / rowBytes *
  33034. drawHeight / originalHeight);
  33035. var comps = this.getComponents(imgArray);
  33036. // If opacity data is present, use RGBA_32BPP form. Otherwise, use the
  33037. // more compact RGB_24BPP form if allowable.
  33038. var alpha01, maybeUndoPreblend;
  33039. if (!forceRGBA && !this.smask && !this.mask) {
  33040. imgData.kind = ImageKind.RGB_24BPP;
  33041. imgData.data = new Uint8Array(drawWidth * drawHeight * 3);
  33042. alpha01 = 0;
  33043. maybeUndoPreblend = false;
  33044. } else {
  33045. imgData.kind = ImageKind.RGBA_32BPP;
  33046. imgData.data = new Uint8Array(drawWidth * drawHeight * 4);
  33047. alpha01 = 1;
  33048. maybeUndoPreblend = true;
  33049. // Color key masking (opacity) must be performed before decoding.
  33050. this.fillOpacity(imgData.data, drawWidth, drawHeight, actualHeight,
  33051. comps);
  33052. }
  33053. if (this.needsDecode) {
  33054. this.decodeBuffer(comps);
  33055. }
  33056. this.colorSpace.fillRgb(imgData.data, originalWidth, originalHeight,
  33057. drawWidth, drawHeight, actualHeight, bpc, comps,
  33058. alpha01);
  33059. if (maybeUndoPreblend) {
  33060. this.undoPreblend(imgData.data, drawWidth, actualHeight);
  33061. }
  33062. return imgData;
  33063. },
  33064. fillGrayBuffer: function PDFImage_fillGrayBuffer(buffer) {
  33065. var numComps = this.numComps;
  33066. if (numComps !== 1) {
  33067. error('Reading gray scale from a color image: ' + numComps);
  33068. }
  33069. var width = this.width;
  33070. var height = this.height;
  33071. var bpc = this.bpc;
  33072. // rows start at byte boundary
  33073. var rowBytes = (width * numComps * bpc + 7) >> 3;
  33074. var imgArray = this.getImageBytes(height * rowBytes);
  33075. var comps = this.getComponents(imgArray);
  33076. var i, length;
  33077. if (bpc === 1) {
  33078. // inline decoding (= inversion) for 1 bpc images
  33079. length = width * height;
  33080. if (this.needsDecode) {
  33081. // invert and scale to {0, 255}
  33082. for (i = 0; i < length; ++i) {
  33083. buffer[i] = (comps[i] - 1) & 255;
  33084. }
  33085. } else {
  33086. // scale to {0, 255}
  33087. for (i = 0; i < length; ++i) {
  33088. buffer[i] = (-comps[i]) & 255;
  33089. }
  33090. }
  33091. return;
  33092. }
  33093. if (this.needsDecode) {
  33094. this.decodeBuffer(comps);
  33095. }
  33096. length = width * height;
  33097. // we aren't using a colorspace so we need to scale the value
  33098. var scale = 255 / ((1 << bpc) - 1);
  33099. for (i = 0; i < length; ++i) {
  33100. buffer[i] = (scale * comps[i]) | 0;
  33101. }
  33102. },
  33103. getImageBytes: function PDFImage_getImageBytes(length,
  33104. drawWidth, drawHeight,
  33105. forceRGB) {
  33106. this.image.reset();
  33107. this.image.drawWidth = drawWidth || this.width;
  33108. this.image.drawHeight = drawHeight || this.height;
  33109. this.image.forceRGB = !!forceRGB;
  33110. return this.image.getBytes(length);
  33111. }
  33112. };
  33113. return PDFImage;
  33114. })();
  33115. exports.PDFImage = PDFImage;
  33116. // TODO refactor to remove dependency on colorspace.js
  33117. coreColorSpace._setCoreImage(exports);
  33118. }));
  33119. (function (root, factory) {
  33120. if (typeof define === 'function' && define.amd) {
  33121. define('pdfjs/core/pattern', ['exports', 'pdfjs/shared/util',
  33122. 'pdfjs/core/primitives', 'pdfjs/core/function',
  33123. 'pdfjs/core/colorspace'], factory);
  33124. } else if (typeof exports !== 'undefined') {
  33125. factory(exports, require('../shared/util.js'), require('./primitives.js'),
  33126. require('./function.js'), require('./colorspace.js'));
  33127. } else {
  33128. factory((root.pdfjsCorePattern = {}), root.pdfjsSharedUtil,
  33129. root.pdfjsCorePrimitives, root.pdfjsCoreFunction,
  33130. root.pdfjsCoreColorSpace);
  33131. }
  33132. }(this, function (exports, sharedUtil, corePrimitives, coreFunction,
  33133. coreColorSpace) {
  33134. var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  33135. var MissingDataException = sharedUtil.MissingDataException;
  33136. var Util = sharedUtil.Util;
  33137. var assert = sharedUtil.assert;
  33138. var error = sharedUtil.error;
  33139. var info = sharedUtil.info;
  33140. var warn = sharedUtil.warn;
  33141. var isStream = corePrimitives.isStream;
  33142. var PDFFunction = coreFunction.PDFFunction;
  33143. var ColorSpace = coreColorSpace.ColorSpace;
  33144. var ShadingType = {
  33145. FUNCTION_BASED: 1,
  33146. AXIAL: 2,
  33147. RADIAL: 3,
  33148. FREE_FORM_MESH: 4,
  33149. LATTICE_FORM_MESH: 5,
  33150. COONS_PATCH_MESH: 6,
  33151. TENSOR_PATCH_MESH: 7
  33152. };
  33153. var Pattern = (function PatternClosure() {
  33154. // Constructor should define this.getPattern
  33155. function Pattern() {
  33156. error('should not call Pattern constructor');
  33157. }
  33158. Pattern.prototype = {
  33159. // Input: current Canvas context
  33160. // Output: the appropriate fillStyle or strokeStyle
  33161. getPattern: function Pattern_getPattern(ctx) {
  33162. error('Should not call Pattern.getStyle: ' + ctx);
  33163. }
  33164. };
  33165. Pattern.parseShading = function Pattern_parseShading(shading, matrix, xref,
  33166. res, handler) {
  33167. var dict = isStream(shading) ? shading.dict : shading;
  33168. var type = dict.get('ShadingType');
  33169. try {
  33170. switch (type) {
  33171. case ShadingType.AXIAL:
  33172. case ShadingType.RADIAL:
  33173. // Both radial and axial shadings are handled by RadialAxial shading.
  33174. return new Shadings.RadialAxial(dict, matrix, xref, res);
  33175. case ShadingType.FREE_FORM_MESH:
  33176. case ShadingType.LATTICE_FORM_MESH:
  33177. case ShadingType.COONS_PATCH_MESH:
  33178. case ShadingType.TENSOR_PATCH_MESH:
  33179. return new Shadings.Mesh(shading, matrix, xref, res);
  33180. default:
  33181. throw new Error('Unsupported ShadingType: ' + type);
  33182. }
  33183. } catch (ex) {
  33184. if (ex instanceof MissingDataException) {
  33185. throw ex;
  33186. }
  33187. handler.send('UnsupportedFeature',
  33188. {featureId: UNSUPPORTED_FEATURES.shadingPattern});
  33189. warn(ex);
  33190. return new Shadings.Dummy();
  33191. }
  33192. };
  33193. return Pattern;
  33194. })();
  33195. var Shadings = {};
  33196. // A small number to offset the first/last color stops so we can insert ones to
  33197. // support extend. Number.MIN_VALUE appears to be too small and breaks the
  33198. // extend. 1e-7 works in FF but chrome seems to use an even smaller sized number
  33199. // internally so we have to go bigger.
  33200. Shadings.SMALL_NUMBER = 1e-2;
  33201. // Radial and axial shading have very similar implementations
  33202. // If needed, the implementations can be broken into two classes
  33203. Shadings.RadialAxial = (function RadialAxialClosure() {
  33204. function RadialAxial(dict, matrix, xref, res) {
  33205. this.matrix = matrix;
  33206. this.coordsArr = dict.get('Coords');
  33207. this.shadingType = dict.get('ShadingType');
  33208. this.type = 'Pattern';
  33209. var cs = dict.get('ColorSpace', 'CS');
  33210. cs = ColorSpace.parse(cs, xref, res);
  33211. this.cs = cs;
  33212. var t0 = 0.0, t1 = 1.0;
  33213. if (dict.has('Domain')) {
  33214. var domainArr = dict.get('Domain');
  33215. t0 = domainArr[0];
  33216. t1 = domainArr[1];
  33217. }
  33218. var extendStart = false, extendEnd = false;
  33219. if (dict.has('Extend')) {
  33220. var extendArr = dict.get('Extend');
  33221. extendStart = extendArr[0];
  33222. extendEnd = extendArr[1];
  33223. }
  33224. if (this.shadingType === ShadingType.RADIAL &&
  33225. (!extendStart || !extendEnd)) {
  33226. // Radial gradient only currently works if either circle is fully within
  33227. // the other circle.
  33228. var x1 = this.coordsArr[0];
  33229. var y1 = this.coordsArr[1];
  33230. var r1 = this.coordsArr[2];
  33231. var x2 = this.coordsArr[3];
  33232. var y2 = this.coordsArr[4];
  33233. var r2 = this.coordsArr[5];
  33234. var distance = Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
  33235. if (r1 <= r2 + distance &&
  33236. r2 <= r1 + distance) {
  33237. warn('Unsupported radial gradient.');
  33238. }
  33239. }
  33240. this.extendStart = extendStart;
  33241. this.extendEnd = extendEnd;
  33242. var fnObj = dict.get('Function');
  33243. var fn = PDFFunction.parseArray(xref, fnObj);
  33244. // 10 samples seems good enough for now, but probably won't work
  33245. // if there are sharp color changes. Ideally, we would implement
  33246. // the spec faithfully and add lossless optimizations.
  33247. var diff = t1 - t0;
  33248. var step = diff / 10;
  33249. var colorStops = this.colorStops = [];
  33250. // Protect against bad domains so we don't end up in an infinte loop below.
  33251. if (t0 >= t1 || step <= 0) {
  33252. // Acrobat doesn't seem to handle these cases so we'll ignore for
  33253. // now.
  33254. info('Bad shading domain.');
  33255. return;
  33256. }
  33257. var color = new Float32Array(cs.numComps), ratio = new Float32Array(1);
  33258. var rgbColor;
  33259. for (var i = t0; i <= t1; i += step) {
  33260. ratio[0] = i;
  33261. fn(ratio, 0, color, 0);
  33262. rgbColor = cs.getRgb(color, 0);
  33263. var cssColor = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  33264. colorStops.push([(i - t0) / diff, cssColor]);
  33265. }
  33266. var background = 'transparent';
  33267. if (dict.has('Background')) {
  33268. rgbColor = cs.getRgb(dict.get('Background'), 0);
  33269. background = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  33270. }
  33271. if (!extendStart) {
  33272. // Insert a color stop at the front and offset the first real color stop
  33273. // so it doesn't conflict with the one we insert.
  33274. colorStops.unshift([0, background]);
  33275. colorStops[1][0] += Shadings.SMALL_NUMBER;
  33276. }
  33277. if (!extendEnd) {
  33278. // Same idea as above in extendStart but for the end.
  33279. colorStops[colorStops.length - 1][0] -= Shadings.SMALL_NUMBER;
  33280. colorStops.push([1, background]);
  33281. }
  33282. this.colorStops = colorStops;
  33283. }
  33284. RadialAxial.prototype = {
  33285. getIR: function RadialAxial_getIR() {
  33286. var coordsArr = this.coordsArr;
  33287. var shadingType = this.shadingType;
  33288. var type, p0, p1, r0, r1;
  33289. if (shadingType === ShadingType.AXIAL) {
  33290. p0 = [coordsArr[0], coordsArr[1]];
  33291. p1 = [coordsArr[2], coordsArr[3]];
  33292. r0 = null;
  33293. r1 = null;
  33294. type = 'axial';
  33295. } else if (shadingType === ShadingType.RADIAL) {
  33296. p0 = [coordsArr[0], coordsArr[1]];
  33297. p1 = [coordsArr[3], coordsArr[4]];
  33298. r0 = coordsArr[2];
  33299. r1 = coordsArr[5];
  33300. type = 'radial';
  33301. } else {
  33302. error('getPattern type unknown: ' + shadingType);
  33303. }
  33304. var matrix = this.matrix;
  33305. if (matrix) {
  33306. p0 = Util.applyTransform(p0, matrix);
  33307. p1 = Util.applyTransform(p1, matrix);
  33308. if (shadingType === ShadingType.RADIAL) {
  33309. var scale = Util.singularValueDecompose2dScale(matrix);
  33310. r0 *= scale[0];
  33311. r1 *= scale[1];
  33312. }
  33313. }
  33314. return ['RadialAxial', type, this.colorStops, p0, p1, r0, r1];
  33315. }
  33316. };
  33317. return RadialAxial;
  33318. })();
  33319. // All mesh shading. For now, they will be presented as set of the triangles
  33320. // to be drawn on the canvas and rgb color for each vertex.
  33321. Shadings.Mesh = (function MeshClosure() {
  33322. function MeshStreamReader(stream, context) {
  33323. this.stream = stream;
  33324. this.context = context;
  33325. this.buffer = 0;
  33326. this.bufferLength = 0;
  33327. var numComps = context.numComps;
  33328. this.tmpCompsBuf = new Float32Array(numComps);
  33329. var csNumComps = context.colorSpace.numComps;
  33330. this.tmpCsCompsBuf = context.colorFn ? new Float32Array(csNumComps) :
  33331. this.tmpCompsBuf;
  33332. }
  33333. MeshStreamReader.prototype = {
  33334. get hasData() {
  33335. if (this.stream.end) {
  33336. return this.stream.pos < this.stream.end;
  33337. }
  33338. if (this.bufferLength > 0) {
  33339. return true;
  33340. }
  33341. var nextByte = this.stream.getByte();
  33342. if (nextByte < 0) {
  33343. return false;
  33344. }
  33345. this.buffer = nextByte;
  33346. this.bufferLength = 8;
  33347. return true;
  33348. },
  33349. readBits: function MeshStreamReader_readBits(n) {
  33350. var buffer = this.buffer;
  33351. var bufferLength = this.bufferLength;
  33352. if (n === 32) {
  33353. if (bufferLength === 0) {
  33354. return ((this.stream.getByte() << 24) |
  33355. (this.stream.getByte() << 16) | (this.stream.getByte() << 8) |
  33356. this.stream.getByte()) >>> 0;
  33357. }
  33358. buffer = (buffer << 24) | (this.stream.getByte() << 16) |
  33359. (this.stream.getByte() << 8) | this.stream.getByte();
  33360. var nextByte = this.stream.getByte();
  33361. this.buffer = nextByte & ((1 << bufferLength) - 1);
  33362. return ((buffer << (8 - bufferLength)) |
  33363. ((nextByte & 0xFF) >> bufferLength)) >>> 0;
  33364. }
  33365. if (n === 8 && bufferLength === 0) {
  33366. return this.stream.getByte();
  33367. }
  33368. while (bufferLength < n) {
  33369. buffer = (buffer << 8) | this.stream.getByte();
  33370. bufferLength += 8;
  33371. }
  33372. bufferLength -= n;
  33373. this.bufferLength = bufferLength;
  33374. this.buffer = buffer & ((1 << bufferLength) - 1);
  33375. return buffer >> bufferLength;
  33376. },
  33377. align: function MeshStreamReader_align() {
  33378. this.buffer = 0;
  33379. this.bufferLength = 0;
  33380. },
  33381. readFlag: function MeshStreamReader_readFlag() {
  33382. return this.readBits(this.context.bitsPerFlag);
  33383. },
  33384. readCoordinate: function MeshStreamReader_readCoordinate() {
  33385. var bitsPerCoordinate = this.context.bitsPerCoordinate;
  33386. var xi = this.readBits(bitsPerCoordinate);
  33387. var yi = this.readBits(bitsPerCoordinate);
  33388. var decode = this.context.decode;
  33389. var scale = bitsPerCoordinate < 32 ? 1 / ((1 << bitsPerCoordinate) - 1) :
  33390. 2.3283064365386963e-10; // 2 ^ -32
  33391. return [
  33392. xi * scale * (decode[1] - decode[0]) + decode[0],
  33393. yi * scale * (decode[3] - decode[2]) + decode[2]
  33394. ];
  33395. },
  33396. readComponents: function MeshStreamReader_readComponents() {
  33397. var numComps = this.context.numComps;
  33398. var bitsPerComponent = this.context.bitsPerComponent;
  33399. var scale = bitsPerComponent < 32 ? 1 / ((1 << bitsPerComponent) - 1) :
  33400. 2.3283064365386963e-10; // 2 ^ -32
  33401. var decode = this.context.decode;
  33402. var components = this.tmpCompsBuf;
  33403. for (var i = 0, j = 4; i < numComps; i++, j += 2) {
  33404. var ci = this.readBits(bitsPerComponent);
  33405. components[i] = ci * scale * (decode[j + 1] - decode[j]) + decode[j];
  33406. }
  33407. var color = this.tmpCsCompsBuf;
  33408. if (this.context.colorFn) {
  33409. this.context.colorFn(components, 0, color, 0);
  33410. }
  33411. return this.context.colorSpace.getRgb(color, 0);
  33412. }
  33413. };
  33414. function decodeType4Shading(mesh, reader) {
  33415. var coords = mesh.coords;
  33416. var colors = mesh.colors;
  33417. var operators = [];
  33418. var ps = []; // not maintaining cs since that will match ps
  33419. var verticesLeft = 0; // assuming we have all data to start a new triangle
  33420. while (reader.hasData) {
  33421. var f = reader.readFlag();
  33422. var coord = reader.readCoordinate();
  33423. var color = reader.readComponents();
  33424. if (verticesLeft === 0) { // ignoring flags if we started a triangle
  33425. assert(0 <= f && f <= 2, 'Unknown type4 flag');
  33426. switch (f) {
  33427. case 0:
  33428. verticesLeft = 3;
  33429. break;
  33430. case 1:
  33431. ps.push(ps[ps.length - 2], ps[ps.length - 1]);
  33432. verticesLeft = 1;
  33433. break;
  33434. case 2:
  33435. ps.push(ps[ps.length - 3], ps[ps.length - 1]);
  33436. verticesLeft = 1;
  33437. break;
  33438. }
  33439. operators.push(f);
  33440. }
  33441. ps.push(coords.length);
  33442. coords.push(coord);
  33443. colors.push(color);
  33444. verticesLeft--;
  33445. reader.align();
  33446. }
  33447. mesh.figures.push({
  33448. type: 'triangles',
  33449. coords: new Int32Array(ps),
  33450. colors: new Int32Array(ps),
  33451. });
  33452. }
  33453. function decodeType5Shading(mesh, reader, verticesPerRow) {
  33454. var coords = mesh.coords;
  33455. var colors = mesh.colors;
  33456. var ps = []; // not maintaining cs since that will match ps
  33457. while (reader.hasData) {
  33458. var coord = reader.readCoordinate();
  33459. var color = reader.readComponents();
  33460. ps.push(coords.length);
  33461. coords.push(coord);
  33462. colors.push(color);
  33463. }
  33464. mesh.figures.push({
  33465. type: 'lattice',
  33466. coords: new Int32Array(ps),
  33467. colors: new Int32Array(ps),
  33468. verticesPerRow: verticesPerRow
  33469. });
  33470. }
  33471. var MIN_SPLIT_PATCH_CHUNKS_AMOUNT = 3;
  33472. var MAX_SPLIT_PATCH_CHUNKS_AMOUNT = 20;
  33473. var TRIANGLE_DENSITY = 20; // count of triangles per entire mesh bounds
  33474. var getB = (function getBClosure() {
  33475. function buildB(count) {
  33476. var lut = [];
  33477. for (var i = 0; i <= count; i++) {
  33478. var t = i / count, t_ = 1 - t;
  33479. lut.push(new Float32Array([t_ * t_ * t_, 3 * t * t_ * t_,
  33480. 3 * t * t * t_, t * t * t]));
  33481. }
  33482. return lut;
  33483. }
  33484. var cache = [];
  33485. return function getB(count) {
  33486. if (!cache[count]) {
  33487. cache[count] = buildB(count);
  33488. }
  33489. return cache[count];
  33490. };
  33491. })();
  33492. function buildFigureFromPatch(mesh, index) {
  33493. var figure = mesh.figures[index];
  33494. assert(figure.type === 'patch', 'Unexpected patch mesh figure');
  33495. var coords = mesh.coords, colors = mesh.colors;
  33496. var pi = figure.coords;
  33497. var ci = figure.colors;
  33498. var figureMinX = Math.min(coords[pi[0]][0], coords[pi[3]][0],
  33499. coords[pi[12]][0], coords[pi[15]][0]);
  33500. var figureMinY = Math.min(coords[pi[0]][1], coords[pi[3]][1],
  33501. coords[pi[12]][1], coords[pi[15]][1]);
  33502. var figureMaxX = Math.max(coords[pi[0]][0], coords[pi[3]][0],
  33503. coords[pi[12]][0], coords[pi[15]][0]);
  33504. var figureMaxY = Math.max(coords[pi[0]][1], coords[pi[3]][1],
  33505. coords[pi[12]][1], coords[pi[15]][1]);
  33506. var splitXBy = Math.ceil((figureMaxX - figureMinX) * TRIANGLE_DENSITY /
  33507. (mesh.bounds[2] - mesh.bounds[0]));
  33508. splitXBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  33509. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitXBy));
  33510. var splitYBy = Math.ceil((figureMaxY - figureMinY) * TRIANGLE_DENSITY /
  33511. (mesh.bounds[3] - mesh.bounds[1]));
  33512. splitYBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  33513. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitYBy));
  33514. var verticesPerRow = splitXBy + 1;
  33515. var figureCoords = new Int32Array((splitYBy + 1) * verticesPerRow);
  33516. var figureColors = new Int32Array((splitYBy + 1) * verticesPerRow);
  33517. var k = 0;
  33518. var cl = new Uint8Array(3), cr = new Uint8Array(3);
  33519. var c0 = colors[ci[0]], c1 = colors[ci[1]],
  33520. c2 = colors[ci[2]], c3 = colors[ci[3]];
  33521. var bRow = getB(splitYBy), bCol = getB(splitXBy);
  33522. for (var row = 0; row <= splitYBy; row++) {
  33523. cl[0] = ((c0[0] * (splitYBy - row) + c2[0] * row) / splitYBy) | 0;
  33524. cl[1] = ((c0[1] * (splitYBy - row) + c2[1] * row) / splitYBy) | 0;
  33525. cl[2] = ((c0[2] * (splitYBy - row) + c2[2] * row) / splitYBy) | 0;
  33526. cr[0] = ((c1[0] * (splitYBy - row) + c3[0] * row) / splitYBy) | 0;
  33527. cr[1] = ((c1[1] * (splitYBy - row) + c3[1] * row) / splitYBy) | 0;
  33528. cr[2] = ((c1[2] * (splitYBy - row) + c3[2] * row) / splitYBy) | 0;
  33529. for (var col = 0; col <= splitXBy; col++, k++) {
  33530. if ((row === 0 || row === splitYBy) &&
  33531. (col === 0 || col === splitXBy)) {
  33532. continue;
  33533. }
  33534. var x = 0, y = 0;
  33535. var q = 0;
  33536. for (var i = 0; i <= 3; i++) {
  33537. for (var j = 0; j <= 3; j++, q++) {
  33538. var m = bRow[row][i] * bCol[col][j];
  33539. x += coords[pi[q]][0] * m;
  33540. y += coords[pi[q]][1] * m;
  33541. }
  33542. }
  33543. figureCoords[k] = coords.length;
  33544. coords.push([x, y]);
  33545. figureColors[k] = colors.length;
  33546. var newColor = new Uint8Array(3);
  33547. newColor[0] = ((cl[0] * (splitXBy - col) + cr[0] * col) / splitXBy) | 0;
  33548. newColor[1] = ((cl[1] * (splitXBy - col) + cr[1] * col) / splitXBy) | 0;
  33549. newColor[2] = ((cl[2] * (splitXBy - col) + cr[2] * col) / splitXBy) | 0;
  33550. colors.push(newColor);
  33551. }
  33552. }
  33553. figureCoords[0] = pi[0];
  33554. figureColors[0] = ci[0];
  33555. figureCoords[splitXBy] = pi[3];
  33556. figureColors[splitXBy] = ci[1];
  33557. figureCoords[verticesPerRow * splitYBy] = pi[12];
  33558. figureColors[verticesPerRow * splitYBy] = ci[2];
  33559. figureCoords[verticesPerRow * splitYBy + splitXBy] = pi[15];
  33560. figureColors[verticesPerRow * splitYBy + splitXBy] = ci[3];
  33561. mesh.figures[index] = {
  33562. type: 'lattice',
  33563. coords: figureCoords,
  33564. colors: figureColors,
  33565. verticesPerRow: verticesPerRow
  33566. };
  33567. }
  33568. function decodeType6Shading(mesh, reader) {
  33569. // A special case of Type 7. The p11, p12, p21, p22 automatically filled
  33570. var coords = mesh.coords;
  33571. var colors = mesh.colors;
  33572. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  33573. var cs = new Int32Array(4); // c00, c30, c03, c33
  33574. while (reader.hasData) {
  33575. var f = reader.readFlag();
  33576. assert(0 <= f && f <= 3, 'Unknown type6 flag');
  33577. var i, ii;
  33578. var pi = coords.length;
  33579. for (i = 0, ii = (f !== 0 ? 8 : 12); i < ii; i++) {
  33580. coords.push(reader.readCoordinate());
  33581. }
  33582. var ci = colors.length;
  33583. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  33584. colors.push(reader.readComponents());
  33585. }
  33586. var tmp1, tmp2, tmp3, tmp4;
  33587. switch (f) {
  33588. case 0:
  33589. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  33590. ps[ 8] = pi + 2; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 7;
  33591. ps[ 4] = pi + 1; /* calculated below */ ps[ 7] = pi + 8;
  33592. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  33593. cs[2] = ci + 1; cs[3] = ci + 2;
  33594. cs[0] = ci; cs[1] = ci + 3;
  33595. break;
  33596. case 1:
  33597. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  33598. ps[12] = tmp4; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  33599. ps[ 8] = tmp3; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 3;
  33600. ps[ 4] = tmp2; /* calculated below */ ps[ 7] = pi + 4;
  33601. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  33602. tmp1 = cs[2]; tmp2 = cs[3];
  33603. cs[2] = tmp2; cs[3] = ci;
  33604. cs[0] = tmp1; cs[1] = ci + 1;
  33605. break;
  33606. case 2:
  33607. tmp1 = ps[15];
  33608. tmp2 = ps[11];
  33609. ps[12] = ps[3]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  33610. ps[ 8] = ps[7]; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 3;
  33611. ps[ 4] = tmp2; /* calculated below */ ps[ 7] = pi + 4;
  33612. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  33613. tmp1 = cs[3];
  33614. cs[2] = cs[1]; cs[3] = ci;
  33615. cs[0] = tmp1; cs[1] = ci + 1;
  33616. break;
  33617. case 3:
  33618. ps[12] = ps[0]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  33619. ps[ 8] = ps[1]; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 3;
  33620. ps[ 4] = ps[2]; /* calculated below */ ps[ 7] = pi + 4;
  33621. ps[ 0] = ps[3]; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  33622. cs[2] = cs[0]; cs[3] = ci;
  33623. cs[0] = cs[1]; cs[1] = ci + 1;
  33624. break;
  33625. }
  33626. // set p11, p12, p21, p22
  33627. ps[5] = coords.length;
  33628. coords.push([
  33629. (-4 * coords[ps[0]][0] - coords[ps[15]][0] +
  33630. 6 * (coords[ps[4]][0] + coords[ps[1]][0]) -
  33631. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  33632. 3 * (coords[ps[13]][0] + coords[ps[7]][0])) / 9,
  33633. (-4 * coords[ps[0]][1] - coords[ps[15]][1] +
  33634. 6 * (coords[ps[4]][1] + coords[ps[1]][1]) -
  33635. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  33636. 3 * (coords[ps[13]][1] + coords[ps[7]][1])) / 9
  33637. ]);
  33638. ps[6] = coords.length;
  33639. coords.push([
  33640. (-4 * coords[ps[3]][0] - coords[ps[12]][0] +
  33641. 6 * (coords[ps[2]][0] + coords[ps[7]][0]) -
  33642. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  33643. 3 * (coords[ps[4]][0] + coords[ps[14]][0])) / 9,
  33644. (-4 * coords[ps[3]][1] - coords[ps[12]][1] +
  33645. 6 * (coords[ps[2]][1] + coords[ps[7]][1]) -
  33646. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  33647. 3 * (coords[ps[4]][1] + coords[ps[14]][1])) / 9
  33648. ]);
  33649. ps[9] = coords.length;
  33650. coords.push([
  33651. (-4 * coords[ps[12]][0] - coords[ps[3]][0] +
  33652. 6 * (coords[ps[8]][0] + coords[ps[13]][0]) -
  33653. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  33654. 3 * (coords[ps[11]][0] + coords[ps[1]][0])) / 9,
  33655. (-4 * coords[ps[12]][1] - coords[ps[3]][1] +
  33656. 6 * (coords[ps[8]][1] + coords[ps[13]][1]) -
  33657. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  33658. 3 * (coords[ps[11]][1] + coords[ps[1]][1])) / 9
  33659. ]);
  33660. ps[10] = coords.length;
  33661. coords.push([
  33662. (-4 * coords[ps[15]][0] - coords[ps[0]][0] +
  33663. 6 * (coords[ps[11]][0] + coords[ps[14]][0]) -
  33664. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  33665. 3 * (coords[ps[2]][0] + coords[ps[8]][0])) / 9,
  33666. (-4 * coords[ps[15]][1] - coords[ps[0]][1] +
  33667. 6 * (coords[ps[11]][1] + coords[ps[14]][1]) -
  33668. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  33669. 3 * (coords[ps[2]][1] + coords[ps[8]][1])) / 9
  33670. ]);
  33671. mesh.figures.push({
  33672. type: 'patch',
  33673. coords: new Int32Array(ps), // making copies of ps and cs
  33674. colors: new Int32Array(cs)
  33675. });
  33676. }
  33677. }
  33678. function decodeType7Shading(mesh, reader) {
  33679. var coords = mesh.coords;
  33680. var colors = mesh.colors;
  33681. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  33682. var cs = new Int32Array(4); // c00, c30, c03, c33
  33683. while (reader.hasData) {
  33684. var f = reader.readFlag();
  33685. assert(0 <= f && f <= 3, 'Unknown type7 flag');
  33686. var i, ii;
  33687. var pi = coords.length;
  33688. for (i = 0, ii = (f !== 0 ? 12 : 16); i < ii; i++) {
  33689. coords.push(reader.readCoordinate());
  33690. }
  33691. var ci = colors.length;
  33692. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  33693. colors.push(reader.readComponents());
  33694. }
  33695. var tmp1, tmp2, tmp3, tmp4;
  33696. switch (f) {
  33697. case 0:
  33698. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  33699. ps[ 8] = pi + 2; ps[ 9] = pi + 13; ps[10] = pi + 14; ps[11] = pi + 7;
  33700. ps[ 4] = pi + 1; ps[ 5] = pi + 12; ps[ 6] = pi + 15; ps[ 7] = pi + 8;
  33701. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  33702. cs[2] = ci + 1; cs[3] = ci + 2;
  33703. cs[0] = ci; cs[1] = ci + 3;
  33704. break;
  33705. case 1:
  33706. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  33707. ps[12] = tmp4; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  33708. ps[ 8] = tmp3; ps[ 9] = pi + 9; ps[10] = pi + 10; ps[11] = pi + 3;
  33709. ps[ 4] = tmp2; ps[ 5] = pi + 8; ps[ 6] = pi + 11; ps[ 7] = pi + 4;
  33710. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  33711. tmp1 = cs[2]; tmp2 = cs[3];
  33712. cs[2] = tmp2; cs[3] = ci;
  33713. cs[0] = tmp1; cs[1] = ci + 1;
  33714. break;
  33715. case 2:
  33716. tmp1 = ps[15];
  33717. tmp2 = ps[11];
  33718. ps[12] = ps[3]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  33719. ps[ 8] = ps[7]; ps[ 9] = pi + 9; ps[10] = pi + 10; ps[11] = pi + 3;
  33720. ps[ 4] = tmp2; ps[ 5] = pi + 8; ps[ 6] = pi + 11; ps[ 7] = pi + 4;
  33721. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  33722. tmp1 = cs[3];
  33723. cs[2] = cs[1]; cs[3] = ci;
  33724. cs[0] = tmp1; cs[1] = ci + 1;
  33725. break;
  33726. case 3:
  33727. ps[12] = ps[0]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  33728. ps[ 8] = ps[1]; ps[ 9] = pi + 9; ps[10] = pi + 10; ps[11] = pi + 3;
  33729. ps[ 4] = ps[2]; ps[ 5] = pi + 8; ps[ 6] = pi + 11; ps[ 7] = pi + 4;
  33730. ps[ 0] = ps[3]; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  33731. cs[2] = cs[0]; cs[3] = ci;
  33732. cs[0] = cs[1]; cs[1] = ci + 1;
  33733. break;
  33734. }
  33735. mesh.figures.push({
  33736. type: 'patch',
  33737. coords: new Int32Array(ps), // making copies of ps and cs
  33738. colors: new Int32Array(cs)
  33739. });
  33740. }
  33741. }
  33742. function updateBounds(mesh) {
  33743. var minX = mesh.coords[0][0], minY = mesh.coords[0][1],
  33744. maxX = minX, maxY = minY;
  33745. for (var i = 1, ii = mesh.coords.length; i < ii; i++) {
  33746. var x = mesh.coords[i][0], y = mesh.coords[i][1];
  33747. minX = minX > x ? x : minX;
  33748. minY = minY > y ? y : minY;
  33749. maxX = maxX < x ? x : maxX;
  33750. maxY = maxY < y ? y : maxY;
  33751. }
  33752. mesh.bounds = [minX, minY, maxX, maxY];
  33753. }
  33754. function packData(mesh) {
  33755. var i, ii, j, jj;
  33756. var coords = mesh.coords;
  33757. var coordsPacked = new Float32Array(coords.length * 2);
  33758. for (i = 0, j = 0, ii = coords.length; i < ii; i++) {
  33759. var xy = coords[i];
  33760. coordsPacked[j++] = xy[0];
  33761. coordsPacked[j++] = xy[1];
  33762. }
  33763. mesh.coords = coordsPacked;
  33764. var colors = mesh.colors;
  33765. var colorsPacked = new Uint8Array(colors.length * 3);
  33766. for (i = 0, j = 0, ii = colors.length; i < ii; i++) {
  33767. var c = colors[i];
  33768. colorsPacked[j++] = c[0];
  33769. colorsPacked[j++] = c[1];
  33770. colorsPacked[j++] = c[2];
  33771. }
  33772. mesh.colors = colorsPacked;
  33773. var figures = mesh.figures;
  33774. for (i = 0, ii = figures.length; i < ii; i++) {
  33775. var figure = figures[i], ps = figure.coords, cs = figure.colors;
  33776. for (j = 0, jj = ps.length; j < jj; j++) {
  33777. ps[j] *= 2;
  33778. cs[j] *= 3;
  33779. }
  33780. }
  33781. }
  33782. function Mesh(stream, matrix, xref, res) {
  33783. assert(isStream(stream), 'Mesh data is not a stream');
  33784. var dict = stream.dict;
  33785. this.matrix = matrix;
  33786. this.shadingType = dict.get('ShadingType');
  33787. this.type = 'Pattern';
  33788. this.bbox = dict.get('BBox');
  33789. var cs = dict.get('ColorSpace', 'CS');
  33790. cs = ColorSpace.parse(cs, xref, res);
  33791. this.cs = cs;
  33792. this.background = dict.has('Background') ?
  33793. cs.getRgb(dict.get('Background'), 0) : null;
  33794. var fnObj = dict.get('Function');
  33795. var fn = fnObj ? PDFFunction.parseArray(xref, fnObj) : null;
  33796. this.coords = [];
  33797. this.colors = [];
  33798. this.figures = [];
  33799. var decodeContext = {
  33800. bitsPerCoordinate: dict.get('BitsPerCoordinate'),
  33801. bitsPerComponent: dict.get('BitsPerComponent'),
  33802. bitsPerFlag: dict.get('BitsPerFlag'),
  33803. decode: dict.get('Decode'),
  33804. colorFn: fn,
  33805. colorSpace: cs,
  33806. numComps: fn ? 1 : cs.numComps
  33807. };
  33808. var reader = new MeshStreamReader(stream, decodeContext);
  33809. var patchMesh = false;
  33810. switch (this.shadingType) {
  33811. case ShadingType.FREE_FORM_MESH:
  33812. decodeType4Shading(this, reader);
  33813. break;
  33814. case ShadingType.LATTICE_FORM_MESH:
  33815. var verticesPerRow = dict.get('VerticesPerRow') | 0;
  33816. assert(verticesPerRow >= 2, 'Invalid VerticesPerRow');
  33817. decodeType5Shading(this, reader, verticesPerRow);
  33818. break;
  33819. case ShadingType.COONS_PATCH_MESH:
  33820. decodeType6Shading(this, reader);
  33821. patchMesh = true;
  33822. break;
  33823. case ShadingType.TENSOR_PATCH_MESH:
  33824. decodeType7Shading(this, reader);
  33825. patchMesh = true;
  33826. break;
  33827. default:
  33828. error('Unsupported mesh type.');
  33829. break;
  33830. }
  33831. if (patchMesh) {
  33832. // dirty bounds calculation for determining, how dense shall be triangles
  33833. updateBounds(this);
  33834. for (var i = 0, ii = this.figures.length; i < ii; i++) {
  33835. buildFigureFromPatch(this, i);
  33836. }
  33837. }
  33838. // calculate bounds
  33839. updateBounds(this);
  33840. packData(this);
  33841. }
  33842. Mesh.prototype = {
  33843. getIR: function Mesh_getIR() {
  33844. return ['Mesh', this.shadingType, this.coords, this.colors, this.figures,
  33845. this.bounds, this.matrix, this.bbox, this.background];
  33846. }
  33847. };
  33848. return Mesh;
  33849. })();
  33850. Shadings.Dummy = (function DummyClosure() {
  33851. function Dummy() {
  33852. this.type = 'Pattern';
  33853. }
  33854. Dummy.prototype = {
  33855. getIR: function Dummy_getIR() {
  33856. return ['Dummy'];
  33857. }
  33858. };
  33859. return Dummy;
  33860. })();
  33861. function getTilingPatternIR(operatorList, dict, args) {
  33862. var matrix = dict.get('Matrix');
  33863. var bbox = dict.get('BBox');
  33864. var xstep = dict.get('XStep');
  33865. var ystep = dict.get('YStep');
  33866. var paintType = dict.get('PaintType');
  33867. var tilingType = dict.get('TilingType');
  33868. return [
  33869. 'TilingPattern', args, operatorList, matrix, bbox, xstep, ystep,
  33870. paintType, tilingType
  33871. ];
  33872. }
  33873. exports.Pattern = Pattern;
  33874. exports.getTilingPatternIR = getTilingPatternIR;
  33875. }));
  33876. (function (root, factory) {
  33877. if (typeof define === 'function' && define.amd) {
  33878. define('pdfjs/core/evaluator', ['exports', 'pdfjs/shared/util',
  33879. 'pdfjs/core/primitives', 'pdfjs/core/stream', 'pdfjs/core/parser',
  33880. 'pdfjs/core/image', 'pdfjs/core/colorspace', 'pdfjs/core/murmurhash3',
  33881. 'pdfjs/core/fonts', 'pdfjs/core/function', 'pdfjs/core/pattern',
  33882. 'pdfjs/core/cmap', 'pdfjs/core/metrics', 'pdfjs/core/bidi'], factory);
  33883. } else if (typeof exports !== 'undefined') {
  33884. factory(exports, require('../shared/util.js'), require('./primitives.js'),
  33885. require('./stream.js'), require('./parser.js'), require('./image.js'),
  33886. require('./colorspace.js'), require('./murmurhash3.js'),
  33887. require('./fonts.js'), require('./function.js'), require('./pattern.js'),
  33888. require('./cmap.js'), require('./metrics.js'), require('./bidi.js'));
  33889. } else {
  33890. factory((root.pdfjsCoreEvaluator = {}), root.pdfjsSharedUtil,
  33891. root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreParser,
  33892. root.pdfjsCoreImage, root.pdfjsCoreColorSpace, root.pdfjsCoreMurmurHash3,
  33893. root.pdfjsCoreFonts, root.pdfjsCoreFunction, root.pdfjsCorePattern,
  33894. root.pdfjsCoreCMap, root.pdfjsCoreMetrics, root.pdfjsCoreBidi);
  33895. }
  33896. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreParser,
  33897. coreImage, coreColorSpace, coreMurmurHash3, coreFonts,
  33898. coreFunction, corePattern, coreCMap, coreMetrics, coreBidi) {
  33899. var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
  33900. var IDENTITY_MATRIX = sharedUtil.IDENTITY_MATRIX;
  33901. var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  33902. var ImageKind = sharedUtil.ImageKind;
  33903. var OPS = sharedUtil.OPS;
  33904. var TextRenderingMode = sharedUtil.TextRenderingMode;
  33905. var Util = sharedUtil.Util;
  33906. var assert = sharedUtil.assert;
  33907. var createPromiseCapability = sharedUtil.createPromiseCapability;
  33908. var error = sharedUtil.error;
  33909. var info = sharedUtil.info;
  33910. var isArray = sharedUtil.isArray;
  33911. var isNum = sharedUtil.isNum;
  33912. var isString = sharedUtil.isString;
  33913. var warn = sharedUtil.warn;
  33914. var Dict = corePrimitives.Dict;
  33915. var Name = corePrimitives.Name;
  33916. var isCmd = corePrimitives.isCmd;
  33917. var isDict = corePrimitives.isDict;
  33918. var isName = corePrimitives.isName;
  33919. var isRef = corePrimitives.isRef;
  33920. var isStream = corePrimitives.isStream;
  33921. var DecodeStream = coreStream.DecodeStream;
  33922. var JpegStream = coreStream.JpegStream;
  33923. var Lexer = coreParser.Lexer;
  33924. var Parser = coreParser.Parser;
  33925. var isEOF = coreParser.isEOF;
  33926. var PDFImage = coreImage.PDFImage;
  33927. var ColorSpace = coreColorSpace.ColorSpace;
  33928. var MurmurHash3_64 = coreMurmurHash3.MurmurHash3_64;
  33929. var Encodings = coreFonts.Encodings;
  33930. var ErrorFont = coreFonts.ErrorFont;
  33931. var FontFlags = coreFonts.FontFlags;
  33932. var Font = coreFonts.Font;
  33933. var IdentityToUnicodeMap = coreFonts.IdentityToUnicodeMap;
  33934. var NormalizedUnicodes = coreFonts.NormalizedUnicodes;
  33935. var ToUnicodeMap = coreFonts.ToUnicodeMap;
  33936. var getFontType = coreFonts.getFontType;
  33937. var reverseIfRtl = coreFonts.reverseIfRtl;
  33938. var serifFonts = coreFonts.serifFonts;
  33939. var symbolsFonts = coreFonts.symbolsFonts;
  33940. var stdFontMap = coreFonts.stdFontMap;
  33941. var isPDFFunction = coreFunction.isPDFFunction;
  33942. var PDFFunction = coreFunction.PDFFunction;
  33943. var Pattern = corePattern.Pattern;
  33944. var getTilingPatternIR = corePattern.getTilingPatternIR;
  33945. var CMapFactory = coreCMap.CMapFactory;
  33946. var IdentityCMap = coreCMap.IdentityCMap;
  33947. var Metrics = coreMetrics.Metrics;
  33948. var bidi = coreBidi.bidi;
  33949. var PartialEvaluator = (function PartialEvaluatorClosure() {
  33950. function PartialEvaluator(pdfManager, xref, handler, pageIndex,
  33951. uniquePrefix, idCounters, fontCache) {
  33952. this.pdfManager = pdfManager;
  33953. this.xref = xref;
  33954. this.handler = handler;
  33955. this.pageIndex = pageIndex;
  33956. this.uniquePrefix = uniquePrefix;
  33957. this.idCounters = idCounters;
  33958. this.fontCache = fontCache;
  33959. }
  33960. // Trying to minimize Date.now() usage and check every 100 time
  33961. var TIME_SLOT_DURATION_MS = 20;
  33962. var CHECK_TIME_EVERY = 100;
  33963. function TimeSlotManager() {
  33964. this.reset();
  33965. }
  33966. TimeSlotManager.prototype = {
  33967. check: function TimeSlotManager_check() {
  33968. if (++this.checked < CHECK_TIME_EVERY) {
  33969. return false;
  33970. }
  33971. this.checked = 0;
  33972. return this.endTime <= Date.now();
  33973. },
  33974. reset: function TimeSlotManager_reset() {
  33975. this.endTime = Date.now() + TIME_SLOT_DURATION_MS;
  33976. this.checked = 0;
  33977. }
  33978. };
  33979. var deferred = Promise.resolve();
  33980. var TILING_PATTERN = 1, SHADING_PATTERN = 2;
  33981. PartialEvaluator.prototype = {
  33982. hasBlendModes: function PartialEvaluator_hasBlendModes(resources) {
  33983. if (!isDict(resources)) {
  33984. return false;
  33985. }
  33986. var processed = Object.create(null);
  33987. if (resources.objId) {
  33988. processed[resources.objId] = true;
  33989. }
  33990. var nodes = [resources];
  33991. while (nodes.length) {
  33992. var key;
  33993. var node = nodes.shift();
  33994. // First check the current resources for blend modes.
  33995. var graphicStates = node.get('ExtGState');
  33996. if (isDict(graphicStates)) {
  33997. graphicStates = graphicStates.getAll();
  33998. for (key in graphicStates) {
  33999. var graphicState = graphicStates[key];
  34000. var bm = graphicState['BM'];
  34001. if (isName(bm) && bm.name !== 'Normal') {
  34002. return true;
  34003. }
  34004. }
  34005. }
  34006. // Descend into the XObjects to look for more resources and blend modes.
  34007. var xObjects = node.get('XObject');
  34008. if (!isDict(xObjects)) {
  34009. continue;
  34010. }
  34011. xObjects = xObjects.getAll();
  34012. for (key in xObjects) {
  34013. var xObject = xObjects[key];
  34014. if (!isStream(xObject)) {
  34015. continue;
  34016. }
  34017. if (xObject.dict.objId) {
  34018. if (processed[xObject.dict.objId]) {
  34019. // stream has objId and is processed already
  34020. continue;
  34021. }
  34022. processed[xObject.dict.objId] = true;
  34023. }
  34024. var xResources = xObject.dict.get('Resources');
  34025. // Checking objId to detect an infinite loop.
  34026. if (isDict(xResources) &&
  34027. (!xResources.objId || !processed[xResources.objId])) {
  34028. nodes.push(xResources);
  34029. if (xResources.objId) {
  34030. processed[xResources.objId] = true;
  34031. }
  34032. }
  34033. }
  34034. }
  34035. return false;
  34036. },
  34037. buildFormXObject: function PartialEvaluator_buildFormXObject(resources,
  34038. xobj, smask,
  34039. operatorList,
  34040. task,
  34041. initialState) {
  34042. var matrix = xobj.dict.getArray('Matrix');
  34043. var bbox = xobj.dict.getArray('BBox');
  34044. var group = xobj.dict.get('Group');
  34045. if (group) {
  34046. var groupOptions = {
  34047. matrix: matrix,
  34048. bbox: bbox,
  34049. smask: smask,
  34050. isolated: false,
  34051. knockout: false
  34052. };
  34053. var groupSubtype = group.get('S');
  34054. var colorSpace;
  34055. if (isName(groupSubtype) && groupSubtype.name === 'Transparency') {
  34056. groupOptions.isolated = (group.get('I') || false);
  34057. groupOptions.knockout = (group.get('K') || false);
  34058. colorSpace = (group.has('CS') ?
  34059. ColorSpace.parse(group.get('CS'), this.xref, resources) : null);
  34060. }
  34061. if (smask && smask.backdrop) {
  34062. colorSpace = colorSpace || ColorSpace.singletons.rgb;
  34063. smask.backdrop = colorSpace.getRgb(smask.backdrop, 0);
  34064. }
  34065. operatorList.addOp(OPS.beginGroup, [groupOptions]);
  34066. }
  34067. operatorList.addOp(OPS.paintFormXObjectBegin, [matrix, bbox]);
  34068. return this.getOperatorList(xobj, task,
  34069. (xobj.dict.get('Resources') || resources), operatorList, initialState).
  34070. then(function () {
  34071. operatorList.addOp(OPS.paintFormXObjectEnd, []);
  34072. if (group) {
  34073. operatorList.addOp(OPS.endGroup, [groupOptions]);
  34074. }
  34075. });
  34076. },
  34077. buildPaintImageXObject:
  34078. function PartialEvaluator_buildPaintImageXObject(resources, image,
  34079. inline, operatorList,
  34080. cacheKey, imageCache) {
  34081. var self = this;
  34082. var dict = image.dict;
  34083. var w = dict.get('Width', 'W');
  34084. var h = dict.get('Height', 'H');
  34085. if (!(w && isNum(w)) || !(h && isNum(h))) {
  34086. warn('Image dimensions are missing, or not numbers.');
  34087. return;
  34088. }
  34089. if (PDFJS.maxImageSize !== -1 && w * h > PDFJS.maxImageSize) {
  34090. warn('Image exceeded maximum allowed size and was removed.');
  34091. return;
  34092. }
  34093. var imageMask = (dict.get('ImageMask', 'IM') || false);
  34094. var imgData, args;
  34095. if (imageMask) {
  34096. // This depends on a tmpCanvas being filled with the
  34097. // current fillStyle, such that processing the pixel
  34098. // data can't be done here. Instead of creating a
  34099. // complete PDFImage, only read the information needed
  34100. // for later.
  34101. var width = dict.get('Width', 'W');
  34102. var height = dict.get('Height', 'H');
  34103. var bitStrideLength = (width + 7) >> 3;
  34104. var imgArray = image.getBytes(bitStrideLength * height);
  34105. var decode = dict.get('Decode', 'D');
  34106. var inverseDecode = (!!decode && decode[0] > 0);
  34107. imgData = PDFImage.createMask(imgArray, width, height,
  34108. image instanceof DecodeStream,
  34109. inverseDecode);
  34110. imgData.cached = true;
  34111. args = [imgData];
  34112. operatorList.addOp(OPS.paintImageMaskXObject, args);
  34113. if (cacheKey) {
  34114. imageCache[cacheKey] = {
  34115. fn: OPS.paintImageMaskXObject,
  34116. args: args
  34117. };
  34118. }
  34119. return;
  34120. }
  34121. var softMask = (dict.get('SMask', 'SM') || false);
  34122. var mask = (dict.get('Mask') || false);
  34123. var SMALL_IMAGE_DIMENSIONS = 200;
  34124. // Inlining small images into the queue as RGB data
  34125. if (inline && !softMask && !mask && !(image instanceof JpegStream) &&
  34126. (w + h) < SMALL_IMAGE_DIMENSIONS) {
  34127. var imageObj = new PDFImage(this.xref, resources, image,
  34128. inline, null, null);
  34129. // We force the use of RGBA_32BPP images here, because we can't handle
  34130. // any other kind.
  34131. imgData = imageObj.createImageData(/* forceRGBA = */ true);
  34132. operatorList.addOp(OPS.paintInlineImageXObject, [imgData]);
  34133. return;
  34134. }
  34135. // If there is no imageMask, create the PDFImage and a lot
  34136. // of image processing can be done here.
  34137. var uniquePrefix = (this.uniquePrefix || '');
  34138. var objId = 'img_' + uniquePrefix + (++this.idCounters.obj);
  34139. operatorList.addDependency(objId);
  34140. args = [objId, w, h];
  34141. if (!softMask && !mask && image instanceof JpegStream &&
  34142. image.isNativelySupported(this.xref, resources)) {
  34143. // These JPEGs don't need any more processing so we can just send it.
  34144. operatorList.addOp(OPS.paintJpegXObject, args);
  34145. this.handler.send('obj',
  34146. [objId, this.pageIndex, 'JpegStream', image.getIR()]);
  34147. return;
  34148. }
  34149. PDFImage.buildImage(self.handler, self.xref, resources, image, inline).
  34150. then(function(imageObj) {
  34151. var imgData = imageObj.createImageData(/* forceRGBA = */ false);
  34152. self.handler.send('obj', [objId, self.pageIndex, 'Image', imgData],
  34153. [imgData.data.buffer]);
  34154. }).then(undefined, function (reason) {
  34155. warn('Unable to decode image: ' + reason);
  34156. self.handler.send('obj', [objId, self.pageIndex, 'Image', null]);
  34157. });
  34158. operatorList.addOp(OPS.paintImageXObject, args);
  34159. if (cacheKey) {
  34160. imageCache[cacheKey] = {
  34161. fn: OPS.paintImageXObject,
  34162. args: args
  34163. };
  34164. }
  34165. },
  34166. handleSMask: function PartialEvaluator_handleSmask(smask, resources,
  34167. operatorList, task,
  34168. stateManager) {
  34169. var smaskContent = smask.get('G');
  34170. var smaskOptions = {
  34171. subtype: smask.get('S').name,
  34172. backdrop: smask.get('BC')
  34173. };
  34174. // The SMask might have a alpha/luminosity value transfer function --
  34175. // we will build a map of integer values in range 0..255 to be fast.
  34176. var transferObj = smask.get('TR');
  34177. if (isPDFFunction(transferObj)) {
  34178. var transferFn = PDFFunction.parse(this.xref, transferObj);
  34179. var transferMap = new Uint8Array(256);
  34180. var tmp = new Float32Array(1);
  34181. for (var i = 0; i < 255; i++) {
  34182. tmp[0] = i / 255;
  34183. transferFn(tmp, 0, tmp, 0);
  34184. transferMap[i] = (tmp[0] * 255) | 0;
  34185. }
  34186. smaskOptions.transferMap = transferMap;
  34187. }
  34188. return this.buildFormXObject(resources, smaskContent, smaskOptions,
  34189. operatorList, task, stateManager.state.clone());
  34190. },
  34191. handleTilingType:
  34192. function PartialEvaluator_handleTilingType(fn, args, resources,
  34193. pattern, patternDict,
  34194. operatorList, task) {
  34195. // Create an IR of the pattern code.
  34196. var tilingOpList = new OperatorList();
  34197. // Merge the available resources, to prevent issues when the patternDict
  34198. // is missing some /Resources entries (fixes issue6541.pdf).
  34199. var resourcesArray = [patternDict.get('Resources'), resources];
  34200. var patternResources = Dict.merge(this.xref, resourcesArray);
  34201. return this.getOperatorList(pattern, task, patternResources,
  34202. tilingOpList).then(function () {
  34203. // Add the dependencies to the parent operator list so they are
  34204. // resolved before sub operator list is executed synchronously.
  34205. operatorList.addDependencies(tilingOpList.dependencies);
  34206. operatorList.addOp(fn, getTilingPatternIR({
  34207. fnArray: tilingOpList.fnArray,
  34208. argsArray: tilingOpList.argsArray
  34209. }, patternDict, args));
  34210. });
  34211. },
  34212. handleSetFont:
  34213. function PartialEvaluator_handleSetFont(resources, fontArgs, fontRef,
  34214. operatorList, task, state) {
  34215. // TODO(mack): Not needed?
  34216. var fontName;
  34217. if (fontArgs) {
  34218. fontArgs = fontArgs.slice();
  34219. fontName = fontArgs[0].name;
  34220. }
  34221. var self = this;
  34222. return this.loadFont(fontName, fontRef, this.xref, resources).then(
  34223. function (translated) {
  34224. if (!translated.font.isType3Font) {
  34225. return translated;
  34226. }
  34227. return translated.loadType3Data(self, resources, operatorList, task).
  34228. then(function () {
  34229. return translated;
  34230. }, function (reason) {
  34231. // Error in the font data -- sending unsupported feature notification.
  34232. self.handler.send('UnsupportedFeature',
  34233. {featureId: UNSUPPORTED_FEATURES.font});
  34234. return new TranslatedFont('g_font_error',
  34235. new ErrorFont('Type3 font load error: ' + reason), translated.font);
  34236. });
  34237. }).then(function (translated) {
  34238. state.font = translated.font;
  34239. translated.send(self.handler);
  34240. return translated.loadedName;
  34241. });
  34242. },
  34243. handleText: function PartialEvaluator_handleText(chars, state) {
  34244. var font = state.font;
  34245. var glyphs = font.charsToGlyphs(chars);
  34246. var isAddToPathSet = !!(state.textRenderingMode &
  34247. TextRenderingMode.ADD_TO_PATH_FLAG);
  34248. if (font.data && (isAddToPathSet || PDFJS.disableFontFace)) {
  34249. var buildPath = function (fontChar) {
  34250. if (!font.renderer.hasBuiltPath(fontChar)) {
  34251. var path = font.renderer.getPathJs(fontChar);
  34252. this.handler.send('commonobj', [
  34253. font.loadedName + '_path_' + fontChar,
  34254. 'FontPath',
  34255. path
  34256. ]);
  34257. }
  34258. }.bind(this);
  34259. for (var i = 0, ii = glyphs.length; i < ii; i++) {
  34260. var glyph = glyphs[i];
  34261. buildPath(glyph.fontChar);
  34262. // If the glyph has an accent we need to build a path for its
  34263. // fontChar too, otherwise CanvasGraphics_paintChar will fail.
  34264. var accent = glyph.accent;
  34265. if (accent && accent.fontChar) {
  34266. buildPath(accent.fontChar);
  34267. }
  34268. }
  34269. }
  34270. return glyphs;
  34271. },
  34272. setGState: function PartialEvaluator_setGState(resources, gState,
  34273. operatorList, task,
  34274. xref, stateManager) {
  34275. // This array holds the converted/processed state data.
  34276. var gStateObj = [];
  34277. var gStateMap = gState.map;
  34278. var self = this;
  34279. var promise = Promise.resolve();
  34280. for (var key in gStateMap) {
  34281. var value = gStateMap[key];
  34282. switch (key) {
  34283. case 'Type':
  34284. break;
  34285. case 'LW':
  34286. case 'LC':
  34287. case 'LJ':
  34288. case 'ML':
  34289. case 'D':
  34290. case 'RI':
  34291. case 'FL':
  34292. case 'CA':
  34293. case 'ca':
  34294. gStateObj.push([key, value]);
  34295. break;
  34296. case 'Font':
  34297. promise = promise.then(function () {
  34298. return self.handleSetFont(resources, null, value[0], operatorList,
  34299. task, stateManager.state).
  34300. then(function (loadedName) {
  34301. operatorList.addDependency(loadedName);
  34302. gStateObj.push([key, [loadedName, value[1]]]);
  34303. });
  34304. });
  34305. break;
  34306. case 'BM':
  34307. gStateObj.push([key, value]);
  34308. break;
  34309. case 'SMask':
  34310. if (isName(value) && value.name === 'None') {
  34311. gStateObj.push([key, false]);
  34312. break;
  34313. }
  34314. var dict = xref.fetchIfRef(value);
  34315. if (isDict(dict)) {
  34316. promise = promise.then(function () {
  34317. return self.handleSMask(dict, resources, operatorList,
  34318. task, stateManager);
  34319. });
  34320. gStateObj.push([key, true]);
  34321. } else {
  34322. warn('Unsupported SMask type');
  34323. }
  34324. break;
  34325. // Only generate info log messages for the following since
  34326. // they are unlikely to have a big impact on the rendering.
  34327. case 'OP':
  34328. case 'op':
  34329. case 'OPM':
  34330. case 'BG':
  34331. case 'BG2':
  34332. case 'UCR':
  34333. case 'UCR2':
  34334. case 'TR':
  34335. case 'TR2':
  34336. case 'HT':
  34337. case 'SM':
  34338. case 'SA':
  34339. case 'AIS':
  34340. case 'TK':
  34341. // TODO implement these operators.
  34342. info('graphic state operator ' + key);
  34343. break;
  34344. default:
  34345. info('Unknown graphic state operator ' + key);
  34346. break;
  34347. }
  34348. }
  34349. return promise.then(function () {
  34350. if (gStateObj.length >= 0) {
  34351. operatorList.addOp(OPS.setGState, [gStateObj]);
  34352. }
  34353. });
  34354. },
  34355. loadFont: function PartialEvaluator_loadFont(fontName, font, xref,
  34356. resources) {
  34357. function errorFont() {
  34358. return Promise.resolve(new TranslatedFont('g_font_error',
  34359. new ErrorFont('Font ' + fontName + ' is not available'), font));
  34360. }
  34361. var fontRef;
  34362. if (font) { // Loading by ref.
  34363. assert(isRef(font));
  34364. fontRef = font;
  34365. } else { // Loading by name.
  34366. var fontRes = resources.get('Font');
  34367. if (fontRes) {
  34368. fontRef = fontRes.getRaw(fontName);
  34369. } else {
  34370. warn('fontRes not available');
  34371. return errorFont();
  34372. }
  34373. }
  34374. if (!fontRef) {
  34375. warn('fontRef not available');
  34376. return errorFont();
  34377. }
  34378. if (this.fontCache.has(fontRef)) {
  34379. return this.fontCache.get(fontRef);
  34380. }
  34381. font = xref.fetchIfRef(fontRef);
  34382. if (!isDict(font)) {
  34383. return errorFont();
  34384. }
  34385. // We are holding font.translated references just for fontRef that are not
  34386. // dictionaries (Dict). See explanation below.
  34387. if (font.translated) {
  34388. return font.translated;
  34389. }
  34390. var fontCapability = createPromiseCapability();
  34391. var preEvaluatedFont = this.preEvaluateFont(font, xref);
  34392. var descriptor = preEvaluatedFont.descriptor;
  34393. var fontID = fontRef.num + '_' + fontRef.gen;
  34394. if (isDict(descriptor)) {
  34395. if (!descriptor.fontAliases) {
  34396. descriptor.fontAliases = Object.create(null);
  34397. }
  34398. var fontAliases = descriptor.fontAliases;
  34399. var hash = preEvaluatedFont.hash;
  34400. if (fontAliases[hash]) {
  34401. var aliasFontRef = fontAliases[hash].aliasRef;
  34402. if (aliasFontRef && this.fontCache.has(aliasFontRef)) {
  34403. this.fontCache.putAlias(fontRef, aliasFontRef);
  34404. return this.fontCache.get(fontRef);
  34405. }
  34406. }
  34407. if (!fontAliases[hash]) {
  34408. fontAliases[hash] = {
  34409. fontID: Font.getFontID()
  34410. };
  34411. }
  34412. fontAliases[hash].aliasRef = fontRef;
  34413. fontID = fontAliases[hash].fontID;
  34414. }
  34415. // Workaround for bad PDF generators that don't reference fonts
  34416. // properly, i.e. by not using an object identifier.
  34417. // Check if the fontRef is a Dict (as opposed to a standard object),
  34418. // in which case we don't cache the font and instead reference it by
  34419. // fontName in font.loadedName below.
  34420. var fontRefIsDict = isDict(fontRef);
  34421. if (!fontRefIsDict) {
  34422. this.fontCache.put(fontRef, fontCapability.promise);
  34423. }
  34424. // Keep track of each font we translated so the caller can
  34425. // load them asynchronously before calling display on a page.
  34426. font.loadedName = 'g_' + this.pdfManager.docId + '_f' + (fontRefIsDict ?
  34427. fontName.replace(/\W/g, '') : fontID);
  34428. font.translated = fontCapability.promise;
  34429. // TODO move promises into translate font
  34430. var translatedPromise;
  34431. try {
  34432. translatedPromise = Promise.resolve(
  34433. this.translateFont(preEvaluatedFont, xref));
  34434. } catch (e) {
  34435. translatedPromise = Promise.reject(e);
  34436. }
  34437. var self = this;
  34438. translatedPromise.then(function (translatedFont) {
  34439. if (translatedFont.fontType !== undefined) {
  34440. var xrefFontStats = xref.stats.fontTypes;
  34441. xrefFontStats[translatedFont.fontType] = true;
  34442. }
  34443. fontCapability.resolve(new TranslatedFont(font.loadedName,
  34444. translatedFont, font));
  34445. }, function (reason) {
  34446. // TODO fontCapability.reject?
  34447. // Error in the font data -- sending unsupported feature notification.
  34448. self.handler.send('UnsupportedFeature',
  34449. {featureId: UNSUPPORTED_FEATURES.font});
  34450. try {
  34451. // error, but it's still nice to have font type reported
  34452. var descriptor = preEvaluatedFont.descriptor;
  34453. var fontFile3 = descriptor && descriptor.get('FontFile3');
  34454. var subtype = fontFile3 && fontFile3.get('Subtype');
  34455. var fontType = getFontType(preEvaluatedFont.type,
  34456. subtype && subtype.name);
  34457. var xrefFontStats = xref.stats.fontTypes;
  34458. xrefFontStats[fontType] = true;
  34459. } catch (ex) { }
  34460. fontCapability.resolve(new TranslatedFont(font.loadedName,
  34461. new ErrorFont(reason instanceof Error ? reason.message : reason),
  34462. font));
  34463. });
  34464. return fontCapability.promise;
  34465. },
  34466. buildPath: function PartialEvaluator_buildPath(operatorList, fn, args) {
  34467. var lastIndex = operatorList.length - 1;
  34468. if (!args) {
  34469. args = [];
  34470. }
  34471. if (lastIndex < 0 ||
  34472. operatorList.fnArray[lastIndex] !== OPS.constructPath) {
  34473. operatorList.addOp(OPS.constructPath, [[fn], args]);
  34474. } else {
  34475. var opArgs = operatorList.argsArray[lastIndex];
  34476. opArgs[0].push(fn);
  34477. Array.prototype.push.apply(opArgs[1], args);
  34478. }
  34479. },
  34480. handleColorN: function PartialEvaluator_handleColorN(operatorList, fn, args,
  34481. cs, patterns, resources, task, xref) {
  34482. // compile tiling patterns
  34483. var patternName = args[args.length - 1];
  34484. // SCN/scn applies patterns along with normal colors
  34485. var pattern;
  34486. if (isName(patternName) &&
  34487. (pattern = patterns.get(patternName.name))) {
  34488. var dict = (isStream(pattern) ? pattern.dict : pattern);
  34489. var typeNum = dict.get('PatternType');
  34490. if (typeNum === TILING_PATTERN) {
  34491. var color = cs.base ? cs.base.getRgb(args, 0) : null;
  34492. return this.handleTilingType(fn, color, resources, pattern,
  34493. dict, operatorList, task);
  34494. } else if (typeNum === SHADING_PATTERN) {
  34495. var shading = dict.get('Shading');
  34496. var matrix = dict.get('Matrix');
  34497. pattern = Pattern.parseShading(shading, matrix, xref, resources,
  34498. this.handler);
  34499. operatorList.addOp(fn, pattern.getIR());
  34500. return Promise.resolve();
  34501. } else {
  34502. return Promise.reject('Unknown PatternType: ' + typeNum);
  34503. }
  34504. }
  34505. // TODO shall we fail here?
  34506. operatorList.addOp(fn, args);
  34507. return Promise.resolve();
  34508. },
  34509. getOperatorList: function PartialEvaluator_getOperatorList(stream,
  34510. task,
  34511. resources,
  34512. operatorList,
  34513. initialState) {
  34514. var self = this;
  34515. var xref = this.xref;
  34516. var imageCache = {};
  34517. assert(operatorList);
  34518. resources = (resources || Dict.empty);
  34519. var xobjs = (resources.get('XObject') || Dict.empty);
  34520. var patterns = (resources.get('Pattern') || Dict.empty);
  34521. var stateManager = new StateManager(initialState || new EvalState());
  34522. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  34523. var timeSlotManager = new TimeSlotManager();
  34524. return new Promise(function next(resolve, reject) {
  34525. task.ensureNotTerminated();
  34526. timeSlotManager.reset();
  34527. var stop, operation = {}, i, ii, cs;
  34528. while (!(stop = timeSlotManager.check())) {
  34529. // The arguments parsed by read() are used beyond this loop, so we
  34530. // cannot reuse the same array on each iteration. Therefore we pass
  34531. // in |null| as the initial value (see the comment on
  34532. // EvaluatorPreprocessor_read() for why).
  34533. operation.args = null;
  34534. if (!(preprocessor.read(operation))) {
  34535. break;
  34536. }
  34537. var args = operation.args;
  34538. var fn = operation.fn;
  34539. switch (fn | 0) {
  34540. case OPS.paintXObject:
  34541. if (args[0].code) {
  34542. break;
  34543. }
  34544. // eagerly compile XForm objects
  34545. var name = args[0].name;
  34546. if (!name) {
  34547. warn('XObject must be referred to by name.');
  34548. continue;
  34549. }
  34550. if (imageCache[name] !== undefined) {
  34551. operatorList.addOp(imageCache[name].fn, imageCache[name].args);
  34552. args = null;
  34553. continue;
  34554. }
  34555. var xobj = xobjs.get(name);
  34556. if (xobj) {
  34557. assert(isStream(xobj), 'XObject should be a stream');
  34558. var type = xobj.dict.get('Subtype');
  34559. assert(isName(type),
  34560. 'XObject should have a Name subtype');
  34561. if (type.name === 'Form') {
  34562. stateManager.save();
  34563. return self.buildFormXObject(resources, xobj, null,
  34564. operatorList, task,
  34565. stateManager.state.clone()).
  34566. then(function () {
  34567. stateManager.restore();
  34568. next(resolve, reject);
  34569. }, reject);
  34570. } else if (type.name === 'Image') {
  34571. self.buildPaintImageXObject(resources, xobj, false,
  34572. operatorList, name, imageCache);
  34573. args = null;
  34574. continue;
  34575. } else if (type.name === 'PS') {
  34576. // PostScript XObjects are unused when viewing documents.
  34577. // See section 4.7.1 of Adobe's PDF reference.
  34578. info('Ignored XObject subtype PS');
  34579. continue;
  34580. } else {
  34581. error('Unhandled XObject subtype ' + type.name);
  34582. }
  34583. }
  34584. break;
  34585. case OPS.setFont:
  34586. var fontSize = args[1];
  34587. // eagerly collect all fonts
  34588. return self.handleSetFont(resources, args, null, operatorList,
  34589. task, stateManager.state).
  34590. then(function (loadedName) {
  34591. operatorList.addDependency(loadedName);
  34592. operatorList.addOp(OPS.setFont, [loadedName, fontSize]);
  34593. next(resolve, reject);
  34594. }, reject);
  34595. case OPS.endInlineImage:
  34596. var cacheKey = args[0].cacheKey;
  34597. if (cacheKey) {
  34598. var cacheEntry = imageCache[cacheKey];
  34599. if (cacheEntry !== undefined) {
  34600. operatorList.addOp(cacheEntry.fn, cacheEntry.args);
  34601. args = null;
  34602. continue;
  34603. }
  34604. }
  34605. self.buildPaintImageXObject(resources, args[0], true,
  34606. operatorList, cacheKey, imageCache);
  34607. args = null;
  34608. continue;
  34609. case OPS.showText:
  34610. args[0] = self.handleText(args[0], stateManager.state);
  34611. break;
  34612. case OPS.showSpacedText:
  34613. var arr = args[0];
  34614. var combinedGlyphs = [];
  34615. var arrLength = arr.length;
  34616. var state = stateManager.state;
  34617. for (i = 0; i < arrLength; ++i) {
  34618. var arrItem = arr[i];
  34619. if (isString(arrItem)) {
  34620. Array.prototype.push.apply(combinedGlyphs,
  34621. self.handleText(arrItem, state));
  34622. } else if (isNum(arrItem)) {
  34623. combinedGlyphs.push(arrItem);
  34624. }
  34625. }
  34626. args[0] = combinedGlyphs;
  34627. fn = OPS.showText;
  34628. break;
  34629. case OPS.nextLineShowText:
  34630. operatorList.addOp(OPS.nextLine);
  34631. args[0] = self.handleText(args[0], stateManager.state);
  34632. fn = OPS.showText;
  34633. break;
  34634. case OPS.nextLineSetSpacingShowText:
  34635. operatorList.addOp(OPS.nextLine);
  34636. operatorList.addOp(OPS.setWordSpacing, [args.shift()]);
  34637. operatorList.addOp(OPS.setCharSpacing, [args.shift()]);
  34638. args[0] = self.handleText(args[0], stateManager.state);
  34639. fn = OPS.showText;
  34640. break;
  34641. case OPS.setTextRenderingMode:
  34642. stateManager.state.textRenderingMode = args[0];
  34643. break;
  34644. case OPS.setFillColorSpace:
  34645. stateManager.state.fillColorSpace =
  34646. ColorSpace.parse(args[0], xref, resources);
  34647. continue;
  34648. case OPS.setStrokeColorSpace:
  34649. stateManager.state.strokeColorSpace =
  34650. ColorSpace.parse(args[0], xref, resources);
  34651. continue;
  34652. case OPS.setFillColor:
  34653. cs = stateManager.state.fillColorSpace;
  34654. args = cs.getRgb(args, 0);
  34655. fn = OPS.setFillRGBColor;
  34656. break;
  34657. case OPS.setStrokeColor:
  34658. cs = stateManager.state.strokeColorSpace;
  34659. args = cs.getRgb(args, 0);
  34660. fn = OPS.setStrokeRGBColor;
  34661. break;
  34662. case OPS.setFillGray:
  34663. stateManager.state.fillColorSpace = ColorSpace.singletons.gray;
  34664. args = ColorSpace.singletons.gray.getRgb(args, 0);
  34665. fn = OPS.setFillRGBColor;
  34666. break;
  34667. case OPS.setStrokeGray:
  34668. stateManager.state.strokeColorSpace = ColorSpace.singletons.gray;
  34669. args = ColorSpace.singletons.gray.getRgb(args, 0);
  34670. fn = OPS.setStrokeRGBColor;
  34671. break;
  34672. case OPS.setFillCMYKColor:
  34673. stateManager.state.fillColorSpace = ColorSpace.singletons.cmyk;
  34674. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  34675. fn = OPS.setFillRGBColor;
  34676. break;
  34677. case OPS.setStrokeCMYKColor:
  34678. stateManager.state.strokeColorSpace = ColorSpace.singletons.cmyk;
  34679. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  34680. fn = OPS.setStrokeRGBColor;
  34681. break;
  34682. case OPS.setFillRGBColor:
  34683. stateManager.state.fillColorSpace = ColorSpace.singletons.rgb;
  34684. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  34685. break;
  34686. case OPS.setStrokeRGBColor:
  34687. stateManager.state.strokeColorSpace = ColorSpace.singletons.rgb;
  34688. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  34689. break;
  34690. case OPS.setFillColorN:
  34691. cs = stateManager.state.fillColorSpace;
  34692. if (cs.name === 'Pattern') {
  34693. return self.handleColorN(operatorList, OPS.setFillColorN,
  34694. args, cs, patterns, resources, task, xref).then(function() {
  34695. next(resolve, reject);
  34696. }, reject);
  34697. }
  34698. args = cs.getRgb(args, 0);
  34699. fn = OPS.setFillRGBColor;
  34700. break;
  34701. case OPS.setStrokeColorN:
  34702. cs = stateManager.state.strokeColorSpace;
  34703. if (cs.name === 'Pattern') {
  34704. return self.handleColorN(operatorList, OPS.setStrokeColorN,
  34705. args, cs, patterns, resources, task, xref).then(function() {
  34706. next(resolve, reject);
  34707. }, reject);
  34708. }
  34709. args = cs.getRgb(args, 0);
  34710. fn = OPS.setStrokeRGBColor;
  34711. break;
  34712. case OPS.shadingFill:
  34713. var shadingRes = resources.get('Shading');
  34714. if (!shadingRes) {
  34715. error('No shading resource found');
  34716. }
  34717. var shading = shadingRes.get(args[0].name);
  34718. if (!shading) {
  34719. error('No shading object found');
  34720. }
  34721. var shadingFill = Pattern.parseShading(shading, null, xref,
  34722. resources, self.handler);
  34723. var patternIR = shadingFill.getIR();
  34724. args = [patternIR];
  34725. fn = OPS.shadingFill;
  34726. break;
  34727. case OPS.setGState:
  34728. var dictName = args[0];
  34729. var extGState = resources.get('ExtGState');
  34730. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  34731. break;
  34732. }
  34733. var gState = extGState.get(dictName.name);
  34734. return self.setGState(resources, gState, operatorList, task,
  34735. xref, stateManager).then(function() {
  34736. next(resolve, reject);
  34737. }, reject);
  34738. case OPS.moveTo:
  34739. case OPS.lineTo:
  34740. case OPS.curveTo:
  34741. case OPS.curveTo2:
  34742. case OPS.curveTo3:
  34743. case OPS.closePath:
  34744. self.buildPath(operatorList, fn, args);
  34745. continue;
  34746. case OPS.rectangle:
  34747. self.buildPath(operatorList, fn, args);
  34748. continue;
  34749. case OPS.markPoint:
  34750. case OPS.markPointProps:
  34751. case OPS.beginMarkedContent:
  34752. case OPS.beginMarkedContentProps:
  34753. case OPS.endMarkedContent:
  34754. case OPS.beginCompat:
  34755. case OPS.endCompat:
  34756. // Ignore operators where the corresponding handlers are known to
  34757. // be no-op in CanvasGraphics (display/canvas.js). This prevents
  34758. // serialization errors and is also a bit more efficient.
  34759. // We could also try to serialize all objects in a general way,
  34760. // e.g. as done in https://github.com/mozilla/pdf.js/pull/6266,
  34761. // but doing so is meaningless without knowing the semantics.
  34762. continue;
  34763. default:
  34764. // Note: Let's hope that the ignored operator does not have any
  34765. // non-serializable arguments, otherwise postMessage will throw
  34766. // "An object could not be cloned.".
  34767. }
  34768. operatorList.addOp(fn, args);
  34769. }
  34770. if (stop) {
  34771. deferred.then(function () {
  34772. next(resolve, reject);
  34773. }, reject);
  34774. return;
  34775. }
  34776. // Some PDFs don't close all restores inside object/form.
  34777. // Closing those for them.
  34778. for (i = 0, ii = preprocessor.savedStatesDepth; i < ii; i++) {
  34779. operatorList.addOp(OPS.restore, []);
  34780. }
  34781. resolve();
  34782. });
  34783. },
  34784. getTextContent:
  34785. function PartialEvaluator_getTextContent(stream, task, resources,
  34786. stateManager,
  34787. normalizeWhitespace) {
  34788. stateManager = (stateManager || new StateManager(new TextState()));
  34789. var WhitespaceRegexp = /\s/g;
  34790. var textContent = {
  34791. items: [],
  34792. styles: Object.create(null)
  34793. };
  34794. var textContentItem = {
  34795. initialized: false,
  34796. str: [],
  34797. width: 0,
  34798. height: 0,
  34799. vertical: false,
  34800. lastAdvanceWidth: 0,
  34801. lastAdvanceHeight: 0,
  34802. textAdvanceScale: 0,
  34803. spaceWidth: 0,
  34804. fakeSpaceMin: Infinity,
  34805. fakeMultiSpaceMin: Infinity,
  34806. fakeMultiSpaceMax: -0,
  34807. textRunBreakAllowed: false,
  34808. transform: null,
  34809. fontName: null
  34810. };
  34811. var SPACE_FACTOR = 0.3;
  34812. var MULTI_SPACE_FACTOR = 1.5;
  34813. var MULTI_SPACE_FACTOR_MAX = 4;
  34814. var self = this;
  34815. var xref = this.xref;
  34816. resources = (xref.fetchIfRef(resources) || Dict.empty);
  34817. // The xobj is parsed iff it's needed, e.g. if there is a `DO` cmd.
  34818. var xobjs = null;
  34819. var xobjsCache = {};
  34820. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  34821. var textState;
  34822. function ensureTextContentItem() {
  34823. if (textContentItem.initialized) {
  34824. return textContentItem;
  34825. }
  34826. var font = textState.font;
  34827. if (!(font.loadedName in textContent.styles)) {
  34828. textContent.styles[font.loadedName] = {
  34829. fontFamily: font.fallbackName,
  34830. ascent: font.ascent,
  34831. descent: font.descent,
  34832. vertical: font.vertical
  34833. };
  34834. }
  34835. textContentItem.fontName = font.loadedName;
  34836. // 9.4.4 Text Space Details
  34837. var tsm = [textState.fontSize * textState.textHScale, 0,
  34838. 0, textState.fontSize,
  34839. 0, textState.textRise];
  34840. if (font.isType3Font &&
  34841. textState.fontMatrix !== FONT_IDENTITY_MATRIX &&
  34842. textState.fontSize === 1) {
  34843. var glyphHeight = font.bbox[3] - font.bbox[1];
  34844. if (glyphHeight > 0) {
  34845. glyphHeight = glyphHeight * textState.fontMatrix[3];
  34846. tsm[3] *= glyphHeight;
  34847. }
  34848. }
  34849. var trm = Util.transform(textState.ctm,
  34850. Util.transform(textState.textMatrix, tsm));
  34851. textContentItem.transform = trm;
  34852. if (!font.vertical) {
  34853. textContentItem.width = 0;
  34854. textContentItem.height = Math.sqrt(trm[2] * trm[2] + trm[3] * trm[3]);
  34855. textContentItem.vertical = false;
  34856. } else {
  34857. textContentItem.width = Math.sqrt(trm[0] * trm[0] + trm[1] * trm[1]);
  34858. textContentItem.height = 0;
  34859. textContentItem.vertical = true;
  34860. }
  34861. var a = textState.textLineMatrix[0];
  34862. var b = textState.textLineMatrix[1];
  34863. var scaleLineX = Math.sqrt(a * a + b * b);
  34864. a = textState.ctm[0];
  34865. b = textState.ctm[1];
  34866. var scaleCtmX = Math.sqrt(a * a + b * b);
  34867. textContentItem.textAdvanceScale = scaleCtmX * scaleLineX;
  34868. textContentItem.lastAdvanceWidth = 0;
  34869. textContentItem.lastAdvanceHeight = 0;
  34870. var spaceWidth = font.spaceWidth / 1000 * textState.fontSize;
  34871. if (spaceWidth) {
  34872. textContentItem.spaceWidth = spaceWidth;
  34873. textContentItem.fakeSpaceMin = spaceWidth * SPACE_FACTOR;
  34874. textContentItem.fakeMultiSpaceMin = spaceWidth * MULTI_SPACE_FACTOR;
  34875. textContentItem.fakeMultiSpaceMax =
  34876. spaceWidth * MULTI_SPACE_FACTOR_MAX;
  34877. // It's okay for monospace fonts to fake as much space as needed.
  34878. textContentItem.textRunBreakAllowed = !font.isMonospace;
  34879. } else {
  34880. textContentItem.spaceWidth = 0;
  34881. textContentItem.fakeSpaceMin = Infinity;
  34882. textContentItem.fakeMultiSpaceMin = Infinity;
  34883. textContentItem.fakeMultiSpaceMax = 0;
  34884. textContentItem.textRunBreakAllowed = false;
  34885. }
  34886. textContentItem.initialized = true;
  34887. return textContentItem;
  34888. }
  34889. function replaceWhitespace(str) {
  34890. // Replaces all whitespaces with standard spaces (0x20), to avoid
  34891. // alignment issues between the textLayer and the canvas if the text
  34892. // contains e.g. tabs (fixes issue6612.pdf).
  34893. var i = 0, ii = str.length, code;
  34894. while (i < ii && (code = str.charCodeAt(i)) >= 0x20 && code <= 0x7F) {
  34895. i++;
  34896. }
  34897. return (i < ii ? str.replace(WhitespaceRegexp, ' ') : str);
  34898. }
  34899. function runBidiTransform(textChunk) {
  34900. var str = textChunk.str.join('');
  34901. var bidiResult = PDFJS.bidi(str, -1, textChunk.vertical);
  34902. return {
  34903. str: (normalizeWhitespace ? replaceWhitespace(bidiResult.str) :
  34904. bidiResult.str),
  34905. dir: bidiResult.dir,
  34906. width: textChunk.width,
  34907. height: textChunk.height,
  34908. transform: textChunk.transform,
  34909. fontName: textChunk.fontName
  34910. };
  34911. }
  34912. function handleSetFont(fontName, fontRef) {
  34913. return self.loadFont(fontName, fontRef, xref, resources).
  34914. then(function (translated) {
  34915. textState.font = translated.font;
  34916. textState.fontMatrix = translated.font.fontMatrix ||
  34917. FONT_IDENTITY_MATRIX;
  34918. });
  34919. }
  34920. function buildTextContentItem(chars) {
  34921. var font = textState.font;
  34922. var textChunk = ensureTextContentItem();
  34923. var width = 0;
  34924. var height = 0;
  34925. var glyphs = font.charsToGlyphs(chars);
  34926. var defaultVMetrics = font.defaultVMetrics;
  34927. for (var i = 0; i < glyphs.length; i++) {
  34928. var glyph = glyphs[i];
  34929. var vMetricX = null;
  34930. var vMetricY = null;
  34931. var glyphWidth = null;
  34932. if (font.vertical) {
  34933. if (glyph.vmetric) {
  34934. glyphWidth = glyph.vmetric[0];
  34935. vMetricX = glyph.vmetric[1];
  34936. vMetricY = glyph.vmetric[2];
  34937. } else {
  34938. glyphWidth = glyph.width;
  34939. vMetricX = glyph.width * 0.5;
  34940. vMetricY = defaultVMetrics[2];
  34941. }
  34942. } else {
  34943. glyphWidth = glyph.width;
  34944. }
  34945. var glyphUnicode = glyph.unicode;
  34946. if (NormalizedUnicodes[glyphUnicode] !== undefined) {
  34947. glyphUnicode = NormalizedUnicodes[glyphUnicode];
  34948. }
  34949. glyphUnicode = reverseIfRtl(glyphUnicode);
  34950. // The following will calculate the x and y of the individual glyphs.
  34951. // if (font.vertical) {
  34952. // tsm[4] -= vMetricX * Math.abs(textState.fontSize) *
  34953. // textState.fontMatrix[0];
  34954. // tsm[5] -= vMetricY * textState.fontSize *
  34955. // textState.fontMatrix[0];
  34956. // }
  34957. // var trm = Util.transform(textState.textMatrix, tsm);
  34958. // var pt = Util.applyTransform([trm[4], trm[5]], textState.ctm);
  34959. // var x = pt[0];
  34960. // var y = pt[1];
  34961. var charSpacing = textState.charSpacing;
  34962. if (glyph.isSpace) {
  34963. var wordSpacing = textState.wordSpacing;
  34964. charSpacing += wordSpacing;
  34965. if (wordSpacing > 0) {
  34966. addFakeSpaces(wordSpacing, textChunk.str);
  34967. }
  34968. }
  34969. var tx = 0;
  34970. var ty = 0;
  34971. if (!font.vertical) {
  34972. var w0 = glyphWidth * textState.fontMatrix[0];
  34973. tx = (w0 * textState.fontSize + charSpacing) *
  34974. textState.textHScale;
  34975. width += tx;
  34976. } else {
  34977. var w1 = glyphWidth * textState.fontMatrix[0];
  34978. ty = w1 * textState.fontSize + charSpacing;
  34979. height += ty;
  34980. }
  34981. textState.translateTextMatrix(tx, ty);
  34982. textChunk.str.push(glyphUnicode);
  34983. }
  34984. if (!font.vertical) {
  34985. textChunk.lastAdvanceWidth = width;
  34986. textChunk.width += width * textChunk.textAdvanceScale;
  34987. } else {
  34988. textChunk.lastAdvanceHeight = height;
  34989. textChunk.height += Math.abs(height * textChunk.textAdvanceScale);
  34990. }
  34991. return textChunk;
  34992. }
  34993. function addFakeSpaces(width, strBuf) {
  34994. if (width < textContentItem.fakeSpaceMin) {
  34995. return;
  34996. }
  34997. if (width < textContentItem.fakeMultiSpaceMin) {
  34998. strBuf.push(' ');
  34999. return;
  35000. }
  35001. var fakeSpaces = Math.round(width / textContentItem.spaceWidth);
  35002. while (fakeSpaces-- > 0) {
  35003. strBuf.push(' ');
  35004. }
  35005. }
  35006. function flushTextContentItem() {
  35007. if (!textContentItem.initialized) {
  35008. return;
  35009. }
  35010. textContent.items.push(runBidiTransform(textContentItem));
  35011. textContentItem.initialized = false;
  35012. textContentItem.str.length = 0;
  35013. }
  35014. var timeSlotManager = new TimeSlotManager();
  35015. return new Promise(function next(resolve, reject) {
  35016. task.ensureNotTerminated();
  35017. timeSlotManager.reset();
  35018. var stop, operation = {}, args = [];
  35019. while (!(stop = timeSlotManager.check())) {
  35020. // The arguments parsed by read() are not used beyond this loop, so
  35021. // we can reuse the same array on every iteration, thus avoiding
  35022. // unnecessary allocations.
  35023. args.length = 0;
  35024. operation.args = args;
  35025. if (!(preprocessor.read(operation))) {
  35026. break;
  35027. }
  35028. textState = stateManager.state;
  35029. var fn = operation.fn;
  35030. args = operation.args;
  35031. var advance;
  35032. switch (fn | 0) {
  35033. case OPS.setFont:
  35034. flushTextContentItem();
  35035. textState.fontSize = args[1];
  35036. return handleSetFont(args[0].name).then(function() {
  35037. next(resolve, reject);
  35038. }, reject);
  35039. case OPS.setTextRise:
  35040. flushTextContentItem();
  35041. textState.textRise = args[0];
  35042. break;
  35043. case OPS.setHScale:
  35044. flushTextContentItem();
  35045. textState.textHScale = args[0] / 100;
  35046. break;
  35047. case OPS.setLeading:
  35048. flushTextContentItem();
  35049. textState.leading = args[0];
  35050. break;
  35051. case OPS.moveText:
  35052. // Optimization to treat same line movement as advance
  35053. var isSameTextLine = !textState.font ? false :
  35054. ((textState.font.vertical ? args[0] : args[1]) === 0);
  35055. advance = args[0] - args[1];
  35056. if (isSameTextLine && textContentItem.initialized &&
  35057. advance > 0 &&
  35058. advance <= textContentItem.fakeMultiSpaceMax) {
  35059. textState.translateTextLineMatrix(args[0], args[1]);
  35060. textContentItem.width +=
  35061. (args[0] - textContentItem.lastAdvanceWidth);
  35062. textContentItem.height +=
  35063. (args[1] - textContentItem.lastAdvanceHeight);
  35064. var diff = (args[0] - textContentItem.lastAdvanceWidth) -
  35065. (args[1] - textContentItem.lastAdvanceHeight);
  35066. addFakeSpaces(diff, textContentItem.str);
  35067. break;
  35068. }
  35069. flushTextContentItem();
  35070. textState.translateTextLineMatrix(args[0], args[1]);
  35071. textState.textMatrix = textState.textLineMatrix.slice();
  35072. break;
  35073. case OPS.setLeadingMoveText:
  35074. flushTextContentItem();
  35075. textState.leading = -args[1];
  35076. textState.translateTextLineMatrix(args[0], args[1]);
  35077. textState.textMatrix = textState.textLineMatrix.slice();
  35078. break;
  35079. case OPS.nextLine:
  35080. flushTextContentItem();
  35081. textState.carriageReturn();
  35082. break;
  35083. case OPS.setTextMatrix:
  35084. flushTextContentItem();
  35085. textState.setTextMatrix(args[0], args[1], args[2], args[3],
  35086. args[4], args[5]);
  35087. textState.setTextLineMatrix(args[0], args[1], args[2], args[3],
  35088. args[4], args[5]);
  35089. break;
  35090. case OPS.setCharSpacing:
  35091. textState.charSpacing = args[0];
  35092. break;
  35093. case OPS.setWordSpacing:
  35094. textState.wordSpacing = args[0];
  35095. break;
  35096. case OPS.beginText:
  35097. flushTextContentItem();
  35098. textState.textMatrix = IDENTITY_MATRIX.slice();
  35099. textState.textLineMatrix = IDENTITY_MATRIX.slice();
  35100. break;
  35101. case OPS.showSpacedText:
  35102. var items = args[0];
  35103. var offset;
  35104. for (var j = 0, jj = items.length; j < jj; j++) {
  35105. if (typeof items[j] === 'string') {
  35106. buildTextContentItem(items[j]);
  35107. } else {
  35108. ensureTextContentItem();
  35109. // PDF Specification 5.3.2 states:
  35110. // The number is expressed in thousandths of a unit of text
  35111. // space.
  35112. // This amount is subtracted from the current horizontal or
  35113. // vertical coordinate, depending on the writing mode.
  35114. // In the default coordinate system, a positive adjustment
  35115. // has the effect of moving the next glyph painted either to
  35116. // the left or down by the given amount.
  35117. advance = items[j] * textState.fontSize / 1000;
  35118. var breakTextRun = false;
  35119. if (textState.font.vertical) {
  35120. offset = advance *
  35121. (textState.textHScale * textState.textMatrix[2] +
  35122. textState.textMatrix[3]);
  35123. textState.translateTextMatrix(0, advance);
  35124. breakTextRun = textContentItem.textRunBreakAllowed &&
  35125. advance > textContentItem.fakeMultiSpaceMax;
  35126. if (!breakTextRun) {
  35127. // Value needs to be added to height to paint down.
  35128. textContentItem.height += offset;
  35129. }
  35130. } else {
  35131. advance = -advance;
  35132. offset = advance * (
  35133. textState.textHScale * textState.textMatrix[0] +
  35134. textState.textMatrix[1]);
  35135. textState.translateTextMatrix(advance, 0);
  35136. breakTextRun = textContentItem.textRunBreakAllowed &&
  35137. advance > textContentItem.fakeMultiSpaceMax;
  35138. if (!breakTextRun) {
  35139. // Value needs to be subtracted from width to paint left.
  35140. textContentItem.width += offset;
  35141. }
  35142. }
  35143. if (breakTextRun) {
  35144. flushTextContentItem();
  35145. } else if (advance > 0) {
  35146. addFakeSpaces(advance, textContentItem.str);
  35147. }
  35148. }
  35149. }
  35150. break;
  35151. case OPS.showText:
  35152. buildTextContentItem(args[0]);
  35153. break;
  35154. case OPS.nextLineShowText:
  35155. flushTextContentItem();
  35156. textState.carriageReturn();
  35157. buildTextContentItem(args[0]);
  35158. break;
  35159. case OPS.nextLineSetSpacingShowText:
  35160. flushTextContentItem();
  35161. textState.wordSpacing = args[0];
  35162. textState.charSpacing = args[1];
  35163. textState.carriageReturn();
  35164. buildTextContentItem(args[2]);
  35165. break;
  35166. case OPS.paintXObject:
  35167. flushTextContentItem();
  35168. if (args[0].code) {
  35169. break;
  35170. }
  35171. if (!xobjs) {
  35172. xobjs = (resources.get('XObject') || Dict.empty);
  35173. }
  35174. var name = args[0].name;
  35175. if (xobjsCache.key === name) {
  35176. if (xobjsCache.texts) {
  35177. Util.appendToArray(textContent.items, xobjsCache.texts.items);
  35178. Util.extendObj(textContent.styles, xobjsCache.texts.styles);
  35179. }
  35180. break;
  35181. }
  35182. var xobj = xobjs.get(name);
  35183. if (!xobj) {
  35184. break;
  35185. }
  35186. assert(isStream(xobj), 'XObject should be a stream');
  35187. var type = xobj.dict.get('Subtype');
  35188. assert(isName(type),
  35189. 'XObject should have a Name subtype');
  35190. if ('Form' !== type.name) {
  35191. xobjsCache.key = name;
  35192. xobjsCache.texts = null;
  35193. break;
  35194. }
  35195. stateManager.save();
  35196. var matrix = xobj.dict.get('Matrix');
  35197. if (isArray(matrix) && matrix.length === 6) {
  35198. stateManager.transform(matrix);
  35199. }
  35200. return self.getTextContent(xobj, task,
  35201. xobj.dict.get('Resources') || resources, stateManager,
  35202. normalizeWhitespace).then(function (formTextContent) {
  35203. Util.appendToArray(textContent.items, formTextContent.items);
  35204. Util.extendObj(textContent.styles, formTextContent.styles);
  35205. stateManager.restore();
  35206. xobjsCache.key = name;
  35207. xobjsCache.texts = formTextContent;
  35208. next(resolve, reject);
  35209. }, reject);
  35210. case OPS.setGState:
  35211. flushTextContentItem();
  35212. var dictName = args[0];
  35213. var extGState = resources.get('ExtGState');
  35214. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  35215. break;
  35216. }
  35217. var gsStateMap = extGState.get(dictName.name);
  35218. var gsStateFont = null;
  35219. for (var key in gsStateMap) {
  35220. if (key === 'Font') {
  35221. assert(!gsStateFont);
  35222. gsStateFont = gsStateMap[key];
  35223. }
  35224. }
  35225. if (gsStateFont) {
  35226. textState.fontSize = gsStateFont[1];
  35227. return handleSetFont(gsStateFont[0]).then(function() {
  35228. next(resolve, reject);
  35229. }, reject);
  35230. }
  35231. break;
  35232. } // switch
  35233. } // while
  35234. if (stop) {
  35235. deferred.then(function () {
  35236. next(resolve, reject);
  35237. }, reject);
  35238. return;
  35239. }
  35240. flushTextContentItem();
  35241. resolve(textContent);
  35242. });
  35243. },
  35244. extractDataStructures: function
  35245. partialEvaluatorExtractDataStructures(dict, baseDict,
  35246. xref, properties) {
  35247. // 9.10.2
  35248. var toUnicode = (dict.get('ToUnicode') || baseDict.get('ToUnicode'));
  35249. if (toUnicode) {
  35250. properties.toUnicode = this.readToUnicode(toUnicode);
  35251. }
  35252. if (properties.composite) {
  35253. // CIDSystemInfo helps to match CID to glyphs
  35254. var cidSystemInfo = dict.get('CIDSystemInfo');
  35255. if (isDict(cidSystemInfo)) {
  35256. properties.cidSystemInfo = {
  35257. registry: cidSystemInfo.get('Registry'),
  35258. ordering: cidSystemInfo.get('Ordering'),
  35259. supplement: cidSystemInfo.get('Supplement')
  35260. };
  35261. }
  35262. var cidToGidMap = dict.get('CIDToGIDMap');
  35263. if (isStream(cidToGidMap)) {
  35264. properties.cidToGidMap = this.readCidToGidMap(cidToGidMap);
  35265. }
  35266. }
  35267. // Based on 9.6.6 of the spec the encoding can come from multiple places
  35268. // and depends on the font type. The base encoding and differences are
  35269. // read here, but the encoding that is actually used is chosen during
  35270. // glyph mapping in the font.
  35271. // TODO: Loading the built in encoding in the font would allow the
  35272. // differences to be merged in here not require us to hold on to it.
  35273. var differences = [];
  35274. var baseEncodingName = null;
  35275. var encoding;
  35276. if (dict.has('Encoding')) {
  35277. encoding = dict.get('Encoding');
  35278. if (isDict(encoding)) {
  35279. baseEncodingName = encoding.get('BaseEncoding');
  35280. baseEncodingName = (isName(baseEncodingName) ?
  35281. baseEncodingName.name : null);
  35282. // Load the differences between the base and original
  35283. if (encoding.has('Differences')) {
  35284. var diffEncoding = encoding.get('Differences');
  35285. var index = 0;
  35286. for (var j = 0, jj = diffEncoding.length; j < jj; j++) {
  35287. var data = diffEncoding[j];
  35288. if (isNum(data)) {
  35289. index = data;
  35290. } else if (isName(data)) {
  35291. differences[index++] = data.name;
  35292. } else if (isRef(data)) {
  35293. diffEncoding[j--] = xref.fetch(data);
  35294. continue;
  35295. } else {
  35296. error('Invalid entry in \'Differences\' array: ' + data);
  35297. }
  35298. }
  35299. }
  35300. } else if (isName(encoding)) {
  35301. baseEncodingName = encoding.name;
  35302. } else {
  35303. error('Encoding is not a Name nor a Dict');
  35304. }
  35305. // According to table 114 if the encoding is a named encoding it must be
  35306. // one of these predefined encodings.
  35307. if ((baseEncodingName !== 'MacRomanEncoding' &&
  35308. baseEncodingName !== 'MacExpertEncoding' &&
  35309. baseEncodingName !== 'WinAnsiEncoding')) {
  35310. baseEncodingName = null;
  35311. }
  35312. }
  35313. if (baseEncodingName) {
  35314. properties.defaultEncoding = Encodings[baseEncodingName].slice();
  35315. } else {
  35316. encoding = (properties.type === 'TrueType' ?
  35317. Encodings.WinAnsiEncoding : Encodings.StandardEncoding);
  35318. // The Symbolic attribute can be misused for regular fonts
  35319. // Heuristic: we have to check if the font is a standard one also
  35320. if (!!(properties.flags & FontFlags.Symbolic)) {
  35321. encoding = Encodings.MacRomanEncoding;
  35322. if (!properties.file) {
  35323. if (/Symbol/i.test(properties.name)) {
  35324. encoding = Encodings.SymbolSetEncoding;
  35325. } else if (/Dingbats/i.test(properties.name)) {
  35326. encoding = Encodings.ZapfDingbatsEncoding;
  35327. }
  35328. }
  35329. }
  35330. properties.defaultEncoding = encoding;
  35331. }
  35332. properties.differences = differences;
  35333. properties.baseEncodingName = baseEncodingName;
  35334. properties.dict = dict;
  35335. },
  35336. readToUnicode: function PartialEvaluator_readToUnicode(toUnicode) {
  35337. var cmap, cmapObj = toUnicode;
  35338. if (isName(cmapObj)) {
  35339. cmap = CMapFactory.create(cmapObj,
  35340. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  35341. if (cmap instanceof IdentityCMap) {
  35342. return new IdentityToUnicodeMap(0, 0xFFFF);
  35343. }
  35344. return new ToUnicodeMap(cmap.getMap());
  35345. } else if (isStream(cmapObj)) {
  35346. cmap = CMapFactory.create(cmapObj,
  35347. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  35348. if (cmap instanceof IdentityCMap) {
  35349. return new IdentityToUnicodeMap(0, 0xFFFF);
  35350. }
  35351. var map = new Array(cmap.length);
  35352. // Convert UTF-16BE
  35353. // NOTE: cmap can be a sparse array, so use forEach instead of for(;;)
  35354. // to iterate over all keys.
  35355. cmap.forEach(function(charCode, token) {
  35356. var str = [];
  35357. for (var k = 0; k < token.length; k += 2) {
  35358. var w1 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  35359. if ((w1 & 0xF800) !== 0xD800) { // w1 < 0xD800 || w1 > 0xDFFF
  35360. str.push(w1);
  35361. continue;
  35362. }
  35363. k += 2;
  35364. var w2 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  35365. str.push(((w1 & 0x3ff) << 10) + (w2 & 0x3ff) + 0x10000);
  35366. }
  35367. map[charCode] = String.fromCharCode.apply(String, str);
  35368. });
  35369. return new ToUnicodeMap(map);
  35370. }
  35371. return null;
  35372. },
  35373. readCidToGidMap: function PartialEvaluator_readCidToGidMap(cidToGidStream) {
  35374. // Extract the encoding from the CIDToGIDMap
  35375. var glyphsData = cidToGidStream.getBytes();
  35376. // Set encoding 0 to later verify the font has an encoding
  35377. var result = [];
  35378. for (var j = 0, jj = glyphsData.length; j < jj; j++) {
  35379. var glyphID = (glyphsData[j++] << 8) | glyphsData[j];
  35380. if (glyphID === 0) {
  35381. continue;
  35382. }
  35383. var code = j >> 1;
  35384. result[code] = glyphID;
  35385. }
  35386. return result;
  35387. },
  35388. extractWidths: function PartialEvaluator_extractWidths(dict, xref,
  35389. descriptor,
  35390. properties) {
  35391. var glyphsWidths = [];
  35392. var defaultWidth = 0;
  35393. var glyphsVMetrics = [];
  35394. var defaultVMetrics;
  35395. var i, ii, j, jj, start, code, widths;
  35396. if (properties.composite) {
  35397. defaultWidth = dict.get('DW') || 1000;
  35398. widths = dict.get('W');
  35399. if (widths) {
  35400. for (i = 0, ii = widths.length; i < ii; i++) {
  35401. start = widths[i++];
  35402. code = xref.fetchIfRef(widths[i]);
  35403. if (isArray(code)) {
  35404. for (j = 0, jj = code.length; j < jj; j++) {
  35405. glyphsWidths[start++] = code[j];
  35406. }
  35407. } else {
  35408. var width = widths[++i];
  35409. for (j = start; j <= code; j++) {
  35410. glyphsWidths[j] = width;
  35411. }
  35412. }
  35413. }
  35414. }
  35415. if (properties.vertical) {
  35416. var vmetrics = (dict.get('DW2') || [880, -1000]);
  35417. defaultVMetrics = [vmetrics[1], defaultWidth * 0.5, vmetrics[0]];
  35418. vmetrics = dict.get('W2');
  35419. if (vmetrics) {
  35420. for (i = 0, ii = vmetrics.length; i < ii; i++) {
  35421. start = vmetrics[i++];
  35422. code = xref.fetchIfRef(vmetrics[i]);
  35423. if (isArray(code)) {
  35424. for (j = 0, jj = code.length; j < jj; j++) {
  35425. glyphsVMetrics[start++] = [code[j++], code[j++], code[j]];
  35426. }
  35427. } else {
  35428. var vmetric = [vmetrics[++i], vmetrics[++i], vmetrics[++i]];
  35429. for (j = start; j <= code; j++) {
  35430. glyphsVMetrics[j] = vmetric;
  35431. }
  35432. }
  35433. }
  35434. }
  35435. }
  35436. } else {
  35437. var firstChar = properties.firstChar;
  35438. widths = dict.get('Widths');
  35439. if (widths) {
  35440. j = firstChar;
  35441. for (i = 0, ii = widths.length; i < ii; i++) {
  35442. glyphsWidths[j++] = widths[i];
  35443. }
  35444. defaultWidth = (parseFloat(descriptor.get('MissingWidth')) || 0);
  35445. } else {
  35446. // Trying get the BaseFont metrics (see comment above).
  35447. var baseFontName = dict.get('BaseFont');
  35448. if (isName(baseFontName)) {
  35449. var metrics = this.getBaseFontMetrics(baseFontName.name);
  35450. glyphsWidths = this.buildCharCodeToWidth(metrics.widths,
  35451. properties);
  35452. defaultWidth = metrics.defaultWidth;
  35453. }
  35454. }
  35455. }
  35456. // Heuristic: detection of monospace font by checking all non-zero widths
  35457. var isMonospace = true;
  35458. var firstWidth = defaultWidth;
  35459. for (var glyph in glyphsWidths) {
  35460. var glyphWidth = glyphsWidths[glyph];
  35461. if (!glyphWidth) {
  35462. continue;
  35463. }
  35464. if (!firstWidth) {
  35465. firstWidth = glyphWidth;
  35466. continue;
  35467. }
  35468. if (firstWidth !== glyphWidth) {
  35469. isMonospace = false;
  35470. break;
  35471. }
  35472. }
  35473. if (isMonospace) {
  35474. properties.flags |= FontFlags.FixedPitch;
  35475. }
  35476. properties.defaultWidth = defaultWidth;
  35477. properties.widths = glyphsWidths;
  35478. properties.defaultVMetrics = defaultVMetrics;
  35479. properties.vmetrics = glyphsVMetrics;
  35480. },
  35481. isSerifFont: function PartialEvaluator_isSerifFont(baseFontName) {
  35482. // Simulating descriptor flags attribute
  35483. var fontNameWoStyle = baseFontName.split('-')[0];
  35484. return (fontNameWoStyle in serifFonts) ||
  35485. (fontNameWoStyle.search(/serif/gi) !== -1);
  35486. },
  35487. getBaseFontMetrics: function PartialEvaluator_getBaseFontMetrics(name) {
  35488. var defaultWidth = 0;
  35489. var widths = [];
  35490. var monospace = false;
  35491. var lookupName = (stdFontMap[name] || name);
  35492. if (!(lookupName in Metrics)) {
  35493. // Use default fonts for looking up font metrics if the passed
  35494. // font is not a base font
  35495. if (this.isSerifFont(name)) {
  35496. lookupName = 'Times-Roman';
  35497. } else {
  35498. lookupName = 'Helvetica';
  35499. }
  35500. }
  35501. var glyphWidths = Metrics[lookupName];
  35502. if (isNum(glyphWidths)) {
  35503. defaultWidth = glyphWidths;
  35504. monospace = true;
  35505. } else {
  35506. widths = glyphWidths;
  35507. }
  35508. return {
  35509. defaultWidth: defaultWidth,
  35510. monospace: monospace,
  35511. widths: widths
  35512. };
  35513. },
  35514. buildCharCodeToWidth:
  35515. function PartialEvaluator_bulildCharCodeToWidth(widthsByGlyphName,
  35516. properties) {
  35517. var widths = Object.create(null);
  35518. var differences = properties.differences;
  35519. var encoding = properties.defaultEncoding;
  35520. for (var charCode = 0; charCode < 256; charCode++) {
  35521. if (charCode in differences &&
  35522. widthsByGlyphName[differences[charCode]]) {
  35523. widths[charCode] = widthsByGlyphName[differences[charCode]];
  35524. continue;
  35525. }
  35526. if (charCode in encoding && widthsByGlyphName[encoding[charCode]]) {
  35527. widths[charCode] = widthsByGlyphName[encoding[charCode]];
  35528. continue;
  35529. }
  35530. }
  35531. return widths;
  35532. },
  35533. preEvaluateFont: function PartialEvaluator_preEvaluateFont(dict, xref) {
  35534. var baseDict = dict;
  35535. var type = dict.get('Subtype');
  35536. assert(isName(type), 'invalid font Subtype');
  35537. var composite = false;
  35538. var uint8array;
  35539. if (type.name === 'Type0') {
  35540. // If font is a composite
  35541. // - get the descendant font
  35542. // - set the type according to the descendant font
  35543. // - get the FontDescriptor from the descendant font
  35544. var df = dict.get('DescendantFonts');
  35545. if (!df) {
  35546. error('Descendant fonts are not specified');
  35547. }
  35548. dict = (isArray(df) ? xref.fetchIfRef(df[0]) : df);
  35549. type = dict.get('Subtype');
  35550. assert(isName(type), 'invalid font Subtype');
  35551. composite = true;
  35552. }
  35553. var descriptor = dict.get('FontDescriptor');
  35554. if (descriptor) {
  35555. var hash = new MurmurHash3_64();
  35556. var encoding = baseDict.getRaw('Encoding');
  35557. if (isName(encoding)) {
  35558. hash.update(encoding.name);
  35559. } else if (isRef(encoding)) {
  35560. hash.update(encoding.num + '_' + encoding.gen);
  35561. } else if (isDict(encoding)) {
  35562. var keys = encoding.getKeys();
  35563. for (var i = 0, ii = keys.length; i < ii; i++) {
  35564. var entry = encoding.getRaw(keys[i]);
  35565. if (isName(entry)) {
  35566. hash.update(entry.name);
  35567. } else if (isRef(entry)) {
  35568. hash.update(entry.num + '_' + entry.gen);
  35569. } else if (isArray(entry)) { // 'Differences' entry.
  35570. // Ideally we should check the contents of the array, but to avoid
  35571. // parsing it here and then again in |extractDataStructures|,
  35572. // we only use the array length for now (fixes bug1157493.pdf).
  35573. hash.update(entry.length.toString());
  35574. }
  35575. }
  35576. }
  35577. var toUnicode = dict.get('ToUnicode') || baseDict.get('ToUnicode');
  35578. if (isStream(toUnicode)) {
  35579. var stream = toUnicode.str || toUnicode;
  35580. uint8array = stream.buffer ?
  35581. new Uint8Array(stream.buffer.buffer, 0, stream.bufferLength) :
  35582. new Uint8Array(stream.bytes.buffer,
  35583. stream.start, stream.end - stream.start);
  35584. hash.update(uint8array);
  35585. } else if (isName(toUnicode)) {
  35586. hash.update(toUnicode.name);
  35587. }
  35588. var widths = dict.get('Widths') || baseDict.get('Widths');
  35589. if (widths) {
  35590. uint8array = new Uint8Array(new Uint32Array(widths).buffer);
  35591. hash.update(uint8array);
  35592. }
  35593. }
  35594. return {
  35595. descriptor: descriptor,
  35596. dict: dict,
  35597. baseDict: baseDict,
  35598. composite: composite,
  35599. type: type.name,
  35600. hash: hash ? hash.hexdigest() : ''
  35601. };
  35602. },
  35603. translateFont: function PartialEvaluator_translateFont(preEvaluatedFont,
  35604. xref) {
  35605. var baseDict = preEvaluatedFont.baseDict;
  35606. var dict = preEvaluatedFont.dict;
  35607. var composite = preEvaluatedFont.composite;
  35608. var descriptor = preEvaluatedFont.descriptor;
  35609. var type = preEvaluatedFont.type;
  35610. var maxCharIndex = (composite ? 0xFFFF : 0xFF);
  35611. var properties;
  35612. if (!descriptor) {
  35613. if (type === 'Type3') {
  35614. // FontDescriptor is only required for Type3 fonts when the document
  35615. // is a tagged pdf. Create a barbebones one to get by.
  35616. descriptor = new Dict(null);
  35617. descriptor.set('FontName', Name.get(type));
  35618. descriptor.set('FontBBox', dict.get('FontBBox'));
  35619. } else {
  35620. // Before PDF 1.5 if the font was one of the base 14 fonts, having a
  35621. // FontDescriptor was not required.
  35622. // This case is here for compatibility.
  35623. var baseFontName = dict.get('BaseFont');
  35624. if (!isName(baseFontName)) {
  35625. error('Base font is not specified');
  35626. }
  35627. // Using base font name as a font name.
  35628. baseFontName = baseFontName.name.replace(/[,_]/g, '-');
  35629. var metrics = this.getBaseFontMetrics(baseFontName);
  35630. // Simulating descriptor flags attribute
  35631. var fontNameWoStyle = baseFontName.split('-')[0];
  35632. var flags =
  35633. (this.isSerifFont(fontNameWoStyle) ? FontFlags.Serif : 0) |
  35634. (metrics.monospace ? FontFlags.FixedPitch : 0) |
  35635. (symbolsFonts[fontNameWoStyle] ? FontFlags.Symbolic :
  35636. FontFlags.Nonsymbolic);
  35637. properties = {
  35638. type: type,
  35639. name: baseFontName,
  35640. widths: metrics.widths,
  35641. defaultWidth: metrics.defaultWidth,
  35642. flags: flags,
  35643. firstChar: 0,
  35644. lastChar: maxCharIndex
  35645. };
  35646. this.extractDataStructures(dict, dict, xref, properties);
  35647. properties.widths = this.buildCharCodeToWidth(metrics.widths,
  35648. properties);
  35649. return new Font(baseFontName, null, properties);
  35650. }
  35651. }
  35652. // According to the spec if 'FontDescriptor' is declared, 'FirstChar',
  35653. // 'LastChar' and 'Widths' should exist too, but some PDF encoders seem
  35654. // to ignore this rule when a variant of a standart font is used.
  35655. // TODO Fill the width array depending on which of the base font this is
  35656. // a variant.
  35657. var firstChar = (dict.get('FirstChar') || 0);
  35658. var lastChar = (dict.get('LastChar') || maxCharIndex);
  35659. var fontName = descriptor.get('FontName');
  35660. var baseFont = dict.get('BaseFont');
  35661. // Some bad PDFs have a string as the font name.
  35662. if (isString(fontName)) {
  35663. fontName = Name.get(fontName);
  35664. }
  35665. if (isString(baseFont)) {
  35666. baseFont = Name.get(baseFont);
  35667. }
  35668. if (type !== 'Type3') {
  35669. var fontNameStr = fontName && fontName.name;
  35670. var baseFontStr = baseFont && baseFont.name;
  35671. if (fontNameStr !== baseFontStr) {
  35672. info('The FontDescriptor\'s FontName is "' + fontNameStr +
  35673. '" but should be the same as the Font\'s BaseFont "' +
  35674. baseFontStr + '"');
  35675. // Workaround for cases where e.g. fontNameStr = 'Arial' and
  35676. // baseFontStr = 'Arial,Bold' (needed when no font file is embedded).
  35677. if (fontNameStr && baseFontStr &&
  35678. baseFontStr.indexOf(fontNameStr) === 0) {
  35679. fontName = baseFont;
  35680. }
  35681. }
  35682. }
  35683. fontName = (fontName || baseFont);
  35684. assert(isName(fontName), 'invalid font name');
  35685. var fontFile = descriptor.get('FontFile', 'FontFile2', 'FontFile3');
  35686. if (fontFile) {
  35687. if (fontFile.dict) {
  35688. var subtype = fontFile.dict.get('Subtype');
  35689. if (subtype) {
  35690. subtype = subtype.name;
  35691. }
  35692. var length1 = fontFile.dict.get('Length1');
  35693. var length2 = fontFile.dict.get('Length2');
  35694. }
  35695. }
  35696. properties = {
  35697. type: type,
  35698. name: fontName.name,
  35699. subtype: subtype,
  35700. file: fontFile,
  35701. length1: length1,
  35702. length2: length2,
  35703. loadedName: baseDict.loadedName,
  35704. composite: composite,
  35705. wideChars: composite,
  35706. fixedPitch: false,
  35707. fontMatrix: (dict.get('FontMatrix') || FONT_IDENTITY_MATRIX),
  35708. firstChar: firstChar || 0,
  35709. lastChar: (lastChar || maxCharIndex),
  35710. bbox: descriptor.get('FontBBox'),
  35711. ascent: descriptor.get('Ascent'),
  35712. descent: descriptor.get('Descent'),
  35713. xHeight: descriptor.get('XHeight'),
  35714. capHeight: descriptor.get('CapHeight'),
  35715. flags: descriptor.get('Flags'),
  35716. italicAngle: descriptor.get('ItalicAngle'),
  35717. coded: false
  35718. };
  35719. if (composite) {
  35720. var cidEncoding = baseDict.get('Encoding');
  35721. if (isName(cidEncoding)) {
  35722. properties.cidEncoding = cidEncoding.name;
  35723. }
  35724. properties.cMap = CMapFactory.create(cidEncoding,
  35725. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  35726. properties.vertical = properties.cMap.vertical;
  35727. }
  35728. this.extractDataStructures(dict, baseDict, xref, properties);
  35729. this.extractWidths(dict, xref, descriptor, properties);
  35730. if (type === 'Type3') {
  35731. properties.isType3Font = true;
  35732. }
  35733. return new Font(fontName.name, fontFile, properties);
  35734. }
  35735. };
  35736. return PartialEvaluator;
  35737. })();
  35738. var TranslatedFont = (function TranslatedFontClosure() {
  35739. function TranslatedFont(loadedName, font, dict) {
  35740. this.loadedName = loadedName;
  35741. this.font = font;
  35742. this.dict = dict;
  35743. this.type3Loaded = null;
  35744. this.sent = false;
  35745. }
  35746. TranslatedFont.prototype = {
  35747. send: function (handler) {
  35748. if (this.sent) {
  35749. return;
  35750. }
  35751. var fontData = this.font.exportData();
  35752. handler.send('commonobj', [
  35753. this.loadedName,
  35754. 'Font',
  35755. fontData
  35756. ]);
  35757. this.sent = true;
  35758. },
  35759. loadType3Data: function (evaluator, resources, parentOperatorList, task) {
  35760. assert(this.font.isType3Font);
  35761. if (this.type3Loaded) {
  35762. return this.type3Loaded;
  35763. }
  35764. var translatedFont = this.font;
  35765. var loadCharProcsPromise = Promise.resolve();
  35766. var charProcs = this.dict.get('CharProcs').getAll();
  35767. var fontResources = this.dict.get('Resources') || resources;
  35768. var charProcKeys = Object.keys(charProcs);
  35769. var charProcOperatorList = {};
  35770. for (var i = 0, n = charProcKeys.length; i < n; ++i) {
  35771. loadCharProcsPromise = loadCharProcsPromise.then(function (key) {
  35772. var glyphStream = charProcs[key];
  35773. var operatorList = new OperatorList();
  35774. return evaluator.getOperatorList(glyphStream, task, fontResources,
  35775. operatorList).then(function () {
  35776. charProcOperatorList[key] = operatorList.getIR();
  35777. // Add the dependencies to the parent operator list so they are
  35778. // resolved before sub operator list is executed synchronously.
  35779. parentOperatorList.addDependencies(operatorList.dependencies);
  35780. }, function (reason) {
  35781. warn('Type3 font resource \"' + key + '\" is not available');
  35782. var operatorList = new OperatorList();
  35783. charProcOperatorList[key] = operatorList.getIR();
  35784. });
  35785. }.bind(this, charProcKeys[i]));
  35786. }
  35787. this.type3Loaded = loadCharProcsPromise.then(function () {
  35788. translatedFont.charProcOperatorList = charProcOperatorList;
  35789. });
  35790. return this.type3Loaded;
  35791. }
  35792. };
  35793. return TranslatedFont;
  35794. })();
  35795. var OperatorList = (function OperatorListClosure() {
  35796. var CHUNK_SIZE = 1000;
  35797. var CHUNK_SIZE_ABOUT = CHUNK_SIZE - 5; // close to chunk size
  35798. function getTransfers(queue) {
  35799. var transfers = [];
  35800. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  35801. for (var i = 0, ii = queue.length; i < ii; i++) {
  35802. switch (fnArray[i]) {
  35803. case OPS.paintInlineImageXObject:
  35804. case OPS.paintInlineImageXObjectGroup:
  35805. case OPS.paintImageMaskXObject:
  35806. var arg = argsArray[i][0]; // first param in imgData
  35807. if (!arg.cached) {
  35808. transfers.push(arg.data.buffer);
  35809. }
  35810. break;
  35811. }
  35812. }
  35813. return transfers;
  35814. }
  35815. function OperatorList(intent, messageHandler, pageIndex) {
  35816. this.messageHandler = messageHandler;
  35817. this.fnArray = [];
  35818. this.argsArray = [];
  35819. this.dependencies = {};
  35820. this._totalLength = 0;
  35821. this.pageIndex = pageIndex;
  35822. this.intent = intent;
  35823. }
  35824. OperatorList.prototype = {
  35825. get length() {
  35826. return this.argsArray.length;
  35827. },
  35828. /**
  35829. * @returns {number} The total length of the entire operator list,
  35830. * since `this.length === 0` after flushing.
  35831. */
  35832. get totalLength() {
  35833. return (this._totalLength + this.length);
  35834. },
  35835. addOp: function(fn, args) {
  35836. this.fnArray.push(fn);
  35837. this.argsArray.push(args);
  35838. if (this.messageHandler) {
  35839. if (this.fnArray.length >= CHUNK_SIZE) {
  35840. this.flush();
  35841. } else if (this.fnArray.length >= CHUNK_SIZE_ABOUT &&
  35842. (fn === OPS.restore || fn === OPS.endText)) {
  35843. // heuristic to flush on boundary of restore or endText
  35844. this.flush();
  35845. }
  35846. }
  35847. },
  35848. addDependency: function(dependency) {
  35849. if (dependency in this.dependencies) {
  35850. return;
  35851. }
  35852. this.dependencies[dependency] = true;
  35853. this.addOp(OPS.dependency, [dependency]);
  35854. },
  35855. addDependencies: function(dependencies) {
  35856. for (var key in dependencies) {
  35857. this.addDependency(key);
  35858. }
  35859. },
  35860. addOpList: function(opList) {
  35861. Util.extendObj(this.dependencies, opList.dependencies);
  35862. for (var i = 0, ii = opList.length; i < ii; i++) {
  35863. this.addOp(opList.fnArray[i], opList.argsArray[i]);
  35864. }
  35865. },
  35866. getIR: function() {
  35867. return {
  35868. fnArray: this.fnArray,
  35869. argsArray: this.argsArray,
  35870. length: this.length
  35871. };
  35872. },
  35873. flush: function(lastChunk) {
  35874. if (this.intent !== 'oplist') {
  35875. new QueueOptimizer().optimize(this);
  35876. }
  35877. var transfers = getTransfers(this);
  35878. var length = this.length;
  35879. this._totalLength += length;
  35880. this.messageHandler.send('RenderPageChunk', {
  35881. operatorList: {
  35882. fnArray: this.fnArray,
  35883. argsArray: this.argsArray,
  35884. lastChunk: lastChunk,
  35885. length: length
  35886. },
  35887. pageIndex: this.pageIndex,
  35888. intent: this.intent
  35889. }, transfers);
  35890. this.dependencies = {};
  35891. this.fnArray.length = 0;
  35892. this.argsArray.length = 0;
  35893. }
  35894. };
  35895. return OperatorList;
  35896. })();
  35897. var StateManager = (function StateManagerClosure() {
  35898. function StateManager(initialState) {
  35899. this.state = initialState;
  35900. this.stateStack = [];
  35901. }
  35902. StateManager.prototype = {
  35903. save: function () {
  35904. var old = this.state;
  35905. this.stateStack.push(this.state);
  35906. this.state = old.clone();
  35907. },
  35908. restore: function () {
  35909. var prev = this.stateStack.pop();
  35910. if (prev) {
  35911. this.state = prev;
  35912. }
  35913. },
  35914. transform: function (args) {
  35915. this.state.ctm = Util.transform(this.state.ctm, args);
  35916. }
  35917. };
  35918. return StateManager;
  35919. })();
  35920. var TextState = (function TextStateClosure() {
  35921. function TextState() {
  35922. this.ctm = new Float32Array(IDENTITY_MATRIX);
  35923. this.fontSize = 0;
  35924. this.font = null;
  35925. this.fontMatrix = FONT_IDENTITY_MATRIX;
  35926. this.textMatrix = IDENTITY_MATRIX.slice();
  35927. this.textLineMatrix = IDENTITY_MATRIX.slice();
  35928. this.charSpacing = 0;
  35929. this.wordSpacing = 0;
  35930. this.leading = 0;
  35931. this.textHScale = 1;
  35932. this.textRise = 0;
  35933. }
  35934. TextState.prototype = {
  35935. setTextMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  35936. var m = this.textMatrix;
  35937. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  35938. },
  35939. setTextLineMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  35940. var m = this.textLineMatrix;
  35941. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  35942. },
  35943. translateTextMatrix: function TextState_translateTextMatrix(x, y) {
  35944. var m = this.textMatrix;
  35945. m[4] = m[0] * x + m[2] * y + m[4];
  35946. m[5] = m[1] * x + m[3] * y + m[5];
  35947. },
  35948. translateTextLineMatrix: function TextState_translateTextMatrix(x, y) {
  35949. var m = this.textLineMatrix;
  35950. m[4] = m[0] * x + m[2] * y + m[4];
  35951. m[5] = m[1] * x + m[3] * y + m[5];
  35952. },
  35953. calcRenderMatrix: function TextState_calcRendeMatrix(ctm) {
  35954. // 9.4.4 Text Space Details
  35955. var tsm = [this.fontSize * this.textHScale, 0,
  35956. 0, this.fontSize,
  35957. 0, this.textRise];
  35958. return Util.transform(ctm, Util.transform(this.textMatrix, tsm));
  35959. },
  35960. carriageReturn: function TextState_carriageReturn() {
  35961. this.translateTextLineMatrix(0, -this.leading);
  35962. this.textMatrix = this.textLineMatrix.slice();
  35963. },
  35964. clone: function TextState_clone() {
  35965. var clone = Object.create(this);
  35966. clone.textMatrix = this.textMatrix.slice();
  35967. clone.textLineMatrix = this.textLineMatrix.slice();
  35968. clone.fontMatrix = this.fontMatrix.slice();
  35969. return clone;
  35970. }
  35971. };
  35972. return TextState;
  35973. })();
  35974. var EvalState = (function EvalStateClosure() {
  35975. function EvalState() {
  35976. this.ctm = new Float32Array(IDENTITY_MATRIX);
  35977. this.font = null;
  35978. this.textRenderingMode = TextRenderingMode.FILL;
  35979. this.fillColorSpace = ColorSpace.singletons.gray;
  35980. this.strokeColorSpace = ColorSpace.singletons.gray;
  35981. }
  35982. EvalState.prototype = {
  35983. clone: function CanvasExtraState_clone() {
  35984. return Object.create(this);
  35985. },
  35986. };
  35987. return EvalState;
  35988. })();
  35989. var EvaluatorPreprocessor = (function EvaluatorPreprocessorClosure() {
  35990. // Specifies properties for each command
  35991. //
  35992. // If variableArgs === true: [0, `numArgs`] expected
  35993. // If variableArgs === false: exactly `numArgs` expected
  35994. var OP_MAP = {
  35995. // Graphic state
  35996. w: { id: OPS.setLineWidth, numArgs: 1, variableArgs: false },
  35997. J: { id: OPS.setLineCap, numArgs: 1, variableArgs: false },
  35998. j: { id: OPS.setLineJoin, numArgs: 1, variableArgs: false },
  35999. M: { id: OPS.setMiterLimit, numArgs: 1, variableArgs: false },
  36000. d: { id: OPS.setDash, numArgs: 2, variableArgs: false },
  36001. ri: { id: OPS.setRenderingIntent, numArgs: 1, variableArgs: false },
  36002. i: { id: OPS.setFlatness, numArgs: 1, variableArgs: false },
  36003. gs: { id: OPS.setGState, numArgs: 1, variableArgs: false },
  36004. q: { id: OPS.save, numArgs: 0, variableArgs: false },
  36005. Q: { id: OPS.restore, numArgs: 0, variableArgs: false },
  36006. cm: { id: OPS.transform, numArgs: 6, variableArgs: false },
  36007. // Path
  36008. m: { id: OPS.moveTo, numArgs: 2, variableArgs: false },
  36009. l: { id: OPS.lineTo, numArgs: 2, variableArgs: false },
  36010. c: { id: OPS.curveTo, numArgs: 6, variableArgs: false },
  36011. v: { id: OPS.curveTo2, numArgs: 4, variableArgs: false },
  36012. y: { id: OPS.curveTo3, numArgs: 4, variableArgs: false },
  36013. h: { id: OPS.closePath, numArgs: 0, variableArgs: false },
  36014. re: { id: OPS.rectangle, numArgs: 4, variableArgs: false },
  36015. S: { id: OPS.stroke, numArgs: 0, variableArgs: false },
  36016. s: { id: OPS.closeStroke, numArgs: 0, variableArgs: false },
  36017. f: { id: OPS.fill, numArgs: 0, variableArgs: false },
  36018. F: { id: OPS.fill, numArgs: 0, variableArgs: false },
  36019. 'f*': { id: OPS.eoFill, numArgs: 0, variableArgs: false },
  36020. B: { id: OPS.fillStroke, numArgs: 0, variableArgs: false },
  36021. 'B*': { id: OPS.eoFillStroke, numArgs: 0, variableArgs: false },
  36022. b: { id: OPS.closeFillStroke, numArgs: 0, variableArgs: false },
  36023. 'b*': { id: OPS.closeEOFillStroke, numArgs: 0, variableArgs: false },
  36024. n: { id: OPS.endPath, numArgs: 0, variableArgs: false },
  36025. // Clipping
  36026. W: { id: OPS.clip, numArgs: 0, variableArgs: false },
  36027. 'W*': { id: OPS.eoClip, numArgs: 0, variableArgs: false },
  36028. // Text
  36029. BT: { id: OPS.beginText, numArgs: 0, variableArgs: false },
  36030. ET: { id: OPS.endText, numArgs: 0, variableArgs: false },
  36031. Tc: { id: OPS.setCharSpacing, numArgs: 1, variableArgs: false },
  36032. Tw: { id: OPS.setWordSpacing, numArgs: 1, variableArgs: false },
  36033. Tz: { id: OPS.setHScale, numArgs: 1, variableArgs: false },
  36034. TL: { id: OPS.setLeading, numArgs: 1, variableArgs: false },
  36035. Tf: { id: OPS.setFont, numArgs: 2, variableArgs: false },
  36036. Tr: { id: OPS.setTextRenderingMode, numArgs: 1, variableArgs: false },
  36037. Ts: { id: OPS.setTextRise, numArgs: 1, variableArgs: false },
  36038. Td: { id: OPS.moveText, numArgs: 2, variableArgs: false },
  36039. TD: { id: OPS.setLeadingMoveText, numArgs: 2, variableArgs: false },
  36040. Tm: { id: OPS.setTextMatrix, numArgs: 6, variableArgs: false },
  36041. 'T*': { id: OPS.nextLine, numArgs: 0, variableArgs: false },
  36042. Tj: { id: OPS.showText, numArgs: 1, variableArgs: false },
  36043. TJ: { id: OPS.showSpacedText, numArgs: 1, variableArgs: false },
  36044. '\'': { id: OPS.nextLineShowText, numArgs: 1, variableArgs: false },
  36045. '"': { id: OPS.nextLineSetSpacingShowText, numArgs: 3,
  36046. variableArgs: false },
  36047. // Type3 fonts
  36048. d0: { id: OPS.setCharWidth, numArgs: 2, variableArgs: false },
  36049. d1: { id: OPS.setCharWidthAndBounds, numArgs: 6, variableArgs: false },
  36050. // Color
  36051. CS: { id: OPS.setStrokeColorSpace, numArgs: 1, variableArgs: false },
  36052. cs: { id: OPS.setFillColorSpace, numArgs: 1, variableArgs: false },
  36053. SC: { id: OPS.setStrokeColor, numArgs: 4, variableArgs: true },
  36054. SCN: { id: OPS.setStrokeColorN, numArgs: 33, variableArgs: true },
  36055. sc: { id: OPS.setFillColor, numArgs: 4, variableArgs: true },
  36056. scn: { id: OPS.setFillColorN, numArgs: 33, variableArgs: true },
  36057. G: { id: OPS.setStrokeGray, numArgs: 1, variableArgs: false },
  36058. g: { id: OPS.setFillGray, numArgs: 1, variableArgs: false },
  36059. RG: { id: OPS.setStrokeRGBColor, numArgs: 3, variableArgs: false },
  36060. rg: { id: OPS.setFillRGBColor, numArgs: 3, variableArgs: false },
  36061. K: { id: OPS.setStrokeCMYKColor, numArgs: 4, variableArgs: false },
  36062. k: { id: OPS.setFillCMYKColor, numArgs: 4, variableArgs: false },
  36063. // Shading
  36064. sh: { id: OPS.shadingFill, numArgs: 1, variableArgs: false },
  36065. // Images
  36066. BI: { id: OPS.beginInlineImage, numArgs: 0, variableArgs: false },
  36067. ID: { id: OPS.beginImageData, numArgs: 0, variableArgs: false },
  36068. EI: { id: OPS.endInlineImage, numArgs: 1, variableArgs: false },
  36069. // XObjects
  36070. Do: { id: OPS.paintXObject, numArgs: 1, variableArgs: false },
  36071. MP: { id: OPS.markPoint, numArgs: 1, variableArgs: false },
  36072. DP: { id: OPS.markPointProps, numArgs: 2, variableArgs: false },
  36073. BMC: { id: OPS.beginMarkedContent, numArgs: 1, variableArgs: false },
  36074. BDC: { id: OPS.beginMarkedContentProps, numArgs: 2,
  36075. variableArgs: false },
  36076. EMC: { id: OPS.endMarkedContent, numArgs: 0, variableArgs: false },
  36077. // Compatibility
  36078. BX: { id: OPS.beginCompat, numArgs: 0, variableArgs: false },
  36079. EX: { id: OPS.endCompat, numArgs: 0, variableArgs: false },
  36080. // (reserved partial commands for the lexer)
  36081. BM: null,
  36082. BD: null,
  36083. 'true': null,
  36084. fa: null,
  36085. fal: null,
  36086. fals: null,
  36087. 'false': null,
  36088. nu: null,
  36089. nul: null,
  36090. 'null': null
  36091. };
  36092. function EvaluatorPreprocessor(stream, xref, stateManager) {
  36093. // TODO(mduan): pass array of knownCommands rather than OP_MAP
  36094. // dictionary
  36095. this.parser = new Parser(new Lexer(stream, OP_MAP), false, xref);
  36096. this.stateManager = stateManager;
  36097. this.nonProcessedArgs = [];
  36098. }
  36099. EvaluatorPreprocessor.prototype = {
  36100. get savedStatesDepth() {
  36101. return this.stateManager.stateStack.length;
  36102. },
  36103. // |operation| is an object with two fields:
  36104. //
  36105. // - |fn| is an out param.
  36106. //
  36107. // - |args| is an inout param. On entry, it should have one of two values.
  36108. //
  36109. // - An empty array. This indicates that the caller is providing the
  36110. // array in which the args will be stored in. The caller should use
  36111. // this value if it can reuse a single array for each call to read().
  36112. //
  36113. // - |null|. This indicates that the caller needs this function to create
  36114. // the array in which any args are stored in. If there are zero args,
  36115. // this function will leave |operation.args| as |null| (thus avoiding
  36116. // allocations that would occur if we used an empty array to represent
  36117. // zero arguments). Otherwise, it will replace |null| with a new array
  36118. // containing the arguments. The caller should use this value if it
  36119. // cannot reuse an array for each call to read().
  36120. //
  36121. // These two modes are present because this function is very hot and so
  36122. // avoiding allocations where possible is worthwhile.
  36123. //
  36124. read: function EvaluatorPreprocessor_read(operation) {
  36125. var args = operation.args;
  36126. while (true) {
  36127. var obj = this.parser.getObj();
  36128. if (isCmd(obj)) {
  36129. var cmd = obj.cmd;
  36130. // Check that the command is valid
  36131. var opSpec = OP_MAP[cmd];
  36132. if (!opSpec) {
  36133. warn('Unknown command "' + cmd + '"');
  36134. continue;
  36135. }
  36136. var fn = opSpec.id;
  36137. var numArgs = opSpec.numArgs;
  36138. var argsLength = args !== null ? args.length : 0;
  36139. if (!opSpec.variableArgs) {
  36140. // Postscript commands can be nested, e.g. /F2 /GS2 gs 5.711 Tf
  36141. if (argsLength !== numArgs) {
  36142. var nonProcessedArgs = this.nonProcessedArgs;
  36143. while (argsLength > numArgs) {
  36144. nonProcessedArgs.push(args.shift());
  36145. argsLength--;
  36146. }
  36147. while (argsLength < numArgs && nonProcessedArgs.length !== 0) {
  36148. if (!args) {
  36149. args = [];
  36150. }
  36151. args.unshift(nonProcessedArgs.pop());
  36152. argsLength++;
  36153. }
  36154. }
  36155. if (argsLength < numArgs) {
  36156. // If we receive too few args, it's not possible to possible
  36157. // to execute the command, so skip the command
  36158. info('Command ' + fn + ': because expected ' +
  36159. numArgs + ' args, but received ' + argsLength +
  36160. ' args; skipping');
  36161. args = null;
  36162. continue;
  36163. }
  36164. } else if (argsLength > numArgs) {
  36165. info('Command ' + fn + ': expected [0,' + numArgs +
  36166. '] args, but received ' + argsLength + ' args');
  36167. }
  36168. // TODO figure out how to type-check vararg functions
  36169. this.preprocessCommand(fn, args);
  36170. operation.fn = fn;
  36171. operation.args = args;
  36172. return true;
  36173. } else {
  36174. if (isEOF(obj)) {
  36175. return false; // no more commands
  36176. }
  36177. // argument
  36178. if (obj !== null) {
  36179. if (!args) {
  36180. args = [];
  36181. }
  36182. args.push((obj instanceof Dict ? obj.getAll() : obj));
  36183. assert(args.length <= 33, 'Too many arguments');
  36184. }
  36185. }
  36186. }
  36187. },
  36188. preprocessCommand:
  36189. function EvaluatorPreprocessor_preprocessCommand(fn, args) {
  36190. switch (fn | 0) {
  36191. case OPS.save:
  36192. this.stateManager.save();
  36193. break;
  36194. case OPS.restore:
  36195. this.stateManager.restore();
  36196. break;
  36197. case OPS.transform:
  36198. this.stateManager.transform(args);
  36199. break;
  36200. }
  36201. }
  36202. };
  36203. return EvaluatorPreprocessor;
  36204. })();
  36205. var QueueOptimizer = (function QueueOptimizerClosure() {
  36206. function addState(parentState, pattern, fn) {
  36207. var state = parentState;
  36208. for (var i = 0, ii = pattern.length - 1; i < ii; i++) {
  36209. var item = pattern[i];
  36210. state = (state[item] || (state[item] = []));
  36211. }
  36212. state[pattern[pattern.length - 1]] = fn;
  36213. }
  36214. function handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  36215. argsArray) {
  36216. // Handles special case of mainly LaTeX documents which use image masks to
  36217. // draw lines with the current fill style.
  36218. // 'count' groups of (save, transform, paintImageMaskXObject, restore)+
  36219. // have been found at iFirstSave.
  36220. var iFirstPIMXO = iFirstSave + 2;
  36221. for (var i = 0; i < count; i++) {
  36222. var arg = argsArray[iFirstPIMXO + 4 * i];
  36223. var imageMask = arg.length === 1 && arg[0];
  36224. if (imageMask && imageMask.width === 1 && imageMask.height === 1 &&
  36225. (!imageMask.data.length ||
  36226. (imageMask.data.length === 1 && imageMask.data[0] === 0))) {
  36227. fnArray[iFirstPIMXO + 4 * i] = OPS.paintSolidColorImageMask;
  36228. continue;
  36229. }
  36230. break;
  36231. }
  36232. return count - i;
  36233. }
  36234. var InitialState = [];
  36235. // This replaces (save, transform, paintInlineImageXObject, restore)+
  36236. // sequences with one |paintInlineImageXObjectGroup| operation.
  36237. addState(InitialState,
  36238. [OPS.save, OPS.transform, OPS.paintInlineImageXObject, OPS.restore],
  36239. function foundInlineImageGroup(context) {
  36240. var MIN_IMAGES_IN_INLINE_IMAGES_BLOCK = 10;
  36241. var MAX_IMAGES_IN_INLINE_IMAGES_BLOCK = 200;
  36242. var MAX_WIDTH = 1000;
  36243. var IMAGE_PADDING = 1;
  36244. var fnArray = context.fnArray, argsArray = context.argsArray;
  36245. var curr = context.iCurr;
  36246. var iFirstSave = curr - 3;
  36247. var iFirstTransform = curr - 2;
  36248. var iFirstPIIXO = curr - 1;
  36249. // Look for the quartets.
  36250. var i = iFirstSave + 4;
  36251. var ii = fnArray.length;
  36252. while (i + 3 < ii) {
  36253. if (fnArray[i] !== OPS.save ||
  36254. fnArray[i + 1] !== OPS.transform ||
  36255. fnArray[i + 2] !== OPS.paintInlineImageXObject ||
  36256. fnArray[i + 3] !== OPS.restore) {
  36257. break; // ops don't match
  36258. }
  36259. i += 4;
  36260. }
  36261. // At this point, i is the index of the first op past the last valid
  36262. // quartet.
  36263. var count = Math.min((i - iFirstSave) / 4,
  36264. MAX_IMAGES_IN_INLINE_IMAGES_BLOCK);
  36265. if (count < MIN_IMAGES_IN_INLINE_IMAGES_BLOCK) {
  36266. return i;
  36267. }
  36268. // assuming that heights of those image is too small (~1 pixel)
  36269. // packing as much as possible by lines
  36270. var maxX = 0;
  36271. var map = [], maxLineHeight = 0;
  36272. var currentX = IMAGE_PADDING, currentY = IMAGE_PADDING;
  36273. var q;
  36274. for (q = 0; q < count; q++) {
  36275. var transform = argsArray[iFirstTransform + (q << 2)];
  36276. var img = argsArray[iFirstPIIXO + (q << 2)][0];
  36277. if (currentX + img.width > MAX_WIDTH) {
  36278. // starting new line
  36279. maxX = Math.max(maxX, currentX);
  36280. currentY += maxLineHeight + 2 * IMAGE_PADDING;
  36281. currentX = 0;
  36282. maxLineHeight = 0;
  36283. }
  36284. map.push({
  36285. transform: transform,
  36286. x: currentX, y: currentY,
  36287. w: img.width, h: img.height
  36288. });
  36289. currentX += img.width + 2 * IMAGE_PADDING;
  36290. maxLineHeight = Math.max(maxLineHeight, img.height);
  36291. }
  36292. var imgWidth = Math.max(maxX, currentX) + IMAGE_PADDING;
  36293. var imgHeight = currentY + maxLineHeight + IMAGE_PADDING;
  36294. var imgData = new Uint8Array(imgWidth * imgHeight * 4);
  36295. var imgRowSize = imgWidth << 2;
  36296. for (q = 0; q < count; q++) {
  36297. var data = argsArray[iFirstPIIXO + (q << 2)][0].data;
  36298. // Copy image by lines and extends pixels into padding.
  36299. var rowSize = map[q].w << 2;
  36300. var dataOffset = 0;
  36301. var offset = (map[q].x + map[q].y * imgWidth) << 2;
  36302. imgData.set(data.subarray(0, rowSize), offset - imgRowSize);
  36303. for (var k = 0, kk = map[q].h; k < kk; k++) {
  36304. imgData.set(data.subarray(dataOffset, dataOffset + rowSize), offset);
  36305. dataOffset += rowSize;
  36306. offset += imgRowSize;
  36307. }
  36308. imgData.set(data.subarray(dataOffset - rowSize, dataOffset), offset);
  36309. while (offset >= 0) {
  36310. data[offset - 4] = data[offset];
  36311. data[offset - 3] = data[offset + 1];
  36312. data[offset - 2] = data[offset + 2];
  36313. data[offset - 1] = data[offset + 3];
  36314. data[offset + rowSize] = data[offset + rowSize - 4];
  36315. data[offset + rowSize + 1] = data[offset + rowSize - 3];
  36316. data[offset + rowSize + 2] = data[offset + rowSize - 2];
  36317. data[offset + rowSize + 3] = data[offset + rowSize - 1];
  36318. offset -= imgRowSize;
  36319. }
  36320. }
  36321. // Replace queue items.
  36322. fnArray.splice(iFirstSave, count * 4, OPS.paintInlineImageXObjectGroup);
  36323. argsArray.splice(iFirstSave, count * 4,
  36324. [{ width: imgWidth, height: imgHeight, kind: ImageKind.RGBA_32BPP,
  36325. data: imgData }, map]);
  36326. return iFirstSave + 1;
  36327. });
  36328. // This replaces (save, transform, paintImageMaskXObject, restore)+
  36329. // sequences with one |paintImageMaskXObjectGroup| or one
  36330. // |paintImageMaskXObjectRepeat| operation.
  36331. addState(InitialState,
  36332. [OPS.save, OPS.transform, OPS.paintImageMaskXObject, OPS.restore],
  36333. function foundImageMaskGroup(context) {
  36334. var MIN_IMAGES_IN_MASKS_BLOCK = 10;
  36335. var MAX_IMAGES_IN_MASKS_BLOCK = 100;
  36336. var MAX_SAME_IMAGES_IN_MASKS_BLOCK = 1000;
  36337. var fnArray = context.fnArray, argsArray = context.argsArray;
  36338. var curr = context.iCurr;
  36339. var iFirstSave = curr - 3;
  36340. var iFirstTransform = curr - 2;
  36341. var iFirstPIMXO = curr - 1;
  36342. // Look for the quartets.
  36343. var i = iFirstSave + 4;
  36344. var ii = fnArray.length;
  36345. while (i + 3 < ii) {
  36346. if (fnArray[i] !== OPS.save ||
  36347. fnArray[i + 1] !== OPS.transform ||
  36348. fnArray[i + 2] !== OPS.paintImageMaskXObject ||
  36349. fnArray[i + 3] !== OPS.restore) {
  36350. break; // ops don't match
  36351. }
  36352. i += 4;
  36353. }
  36354. // At this point, i is the index of the first op past the last valid
  36355. // quartet.
  36356. var count = (i - iFirstSave) / 4;
  36357. count = handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  36358. argsArray);
  36359. if (count < MIN_IMAGES_IN_MASKS_BLOCK) {
  36360. return i;
  36361. }
  36362. var q;
  36363. var isSameImage = false;
  36364. var iTransform, transformArgs;
  36365. var firstPIMXOArg0 = argsArray[iFirstPIMXO][0];
  36366. if (argsArray[iFirstTransform][1] === 0 &&
  36367. argsArray[iFirstTransform][2] === 0) {
  36368. isSameImage = true;
  36369. var firstTransformArg0 = argsArray[iFirstTransform][0];
  36370. var firstTransformArg3 = argsArray[iFirstTransform][3];
  36371. iTransform = iFirstTransform + 4;
  36372. var iPIMXO = iFirstPIMXO + 4;
  36373. for (q = 1; q < count; q++, iTransform += 4, iPIMXO += 4) {
  36374. transformArgs = argsArray[iTransform];
  36375. if (argsArray[iPIMXO][0] !== firstPIMXOArg0 ||
  36376. transformArgs[0] !== firstTransformArg0 ||
  36377. transformArgs[1] !== 0 ||
  36378. transformArgs[2] !== 0 ||
  36379. transformArgs[3] !== firstTransformArg3) {
  36380. if (q < MIN_IMAGES_IN_MASKS_BLOCK) {
  36381. isSameImage = false;
  36382. } else {
  36383. count = q;
  36384. }
  36385. break; // different image or transform
  36386. }
  36387. }
  36388. }
  36389. if (isSameImage) {
  36390. count = Math.min(count, MAX_SAME_IMAGES_IN_MASKS_BLOCK);
  36391. var positions = new Float32Array(count * 2);
  36392. iTransform = iFirstTransform;
  36393. for (q = 0; q < count; q++, iTransform += 4) {
  36394. transformArgs = argsArray[iTransform];
  36395. positions[(q << 1)] = transformArgs[4];
  36396. positions[(q << 1) + 1] = transformArgs[5];
  36397. }
  36398. // Replace queue items.
  36399. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectRepeat);
  36400. argsArray.splice(iFirstSave, count * 4,
  36401. [firstPIMXOArg0, firstTransformArg0, firstTransformArg3, positions]);
  36402. } else {
  36403. count = Math.min(count, MAX_IMAGES_IN_MASKS_BLOCK);
  36404. var images = [];
  36405. for (q = 0; q < count; q++) {
  36406. transformArgs = argsArray[iFirstTransform + (q << 2)];
  36407. var maskParams = argsArray[iFirstPIMXO + (q << 2)][0];
  36408. images.push({ data: maskParams.data, width: maskParams.width,
  36409. height: maskParams.height,
  36410. transform: transformArgs });
  36411. }
  36412. // Replace queue items.
  36413. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectGroup);
  36414. argsArray.splice(iFirstSave, count * 4, [images]);
  36415. }
  36416. return iFirstSave + 1;
  36417. });
  36418. // This replaces (save, transform, paintImageXObject, restore)+ sequences
  36419. // with one paintImageXObjectRepeat operation, if the |transform| and
  36420. // |paintImageXObjectRepeat| ops are appropriate.
  36421. addState(InitialState,
  36422. [OPS.save, OPS.transform, OPS.paintImageXObject, OPS.restore],
  36423. function (context) {
  36424. var MIN_IMAGES_IN_BLOCK = 3;
  36425. var MAX_IMAGES_IN_BLOCK = 1000;
  36426. var fnArray = context.fnArray, argsArray = context.argsArray;
  36427. var curr = context.iCurr;
  36428. var iFirstSave = curr - 3;
  36429. var iFirstTransform = curr - 2;
  36430. var iFirstPIXO = curr - 1;
  36431. var iFirstRestore = curr;
  36432. if (argsArray[iFirstTransform][1] !== 0 ||
  36433. argsArray[iFirstTransform][2] !== 0) {
  36434. return iFirstRestore + 1; // transform has the wrong form
  36435. }
  36436. // Look for the quartets.
  36437. var firstPIXOArg0 = argsArray[iFirstPIXO][0];
  36438. var firstTransformArg0 = argsArray[iFirstTransform][0];
  36439. var firstTransformArg3 = argsArray[iFirstTransform][3];
  36440. var i = iFirstSave + 4;
  36441. var ii = fnArray.length;
  36442. while (i + 3 < ii) {
  36443. if (fnArray[i] !== OPS.save ||
  36444. fnArray[i + 1] !== OPS.transform ||
  36445. fnArray[i + 2] !== OPS.paintImageXObject ||
  36446. fnArray[i + 3] !== OPS.restore) {
  36447. break; // ops don't match
  36448. }
  36449. if (argsArray[i + 1][0] !== firstTransformArg0 ||
  36450. argsArray[i + 1][1] !== 0 ||
  36451. argsArray[i + 1][2] !== 0 ||
  36452. argsArray[i + 1][3] !== firstTransformArg3) {
  36453. break; // transforms don't match
  36454. }
  36455. if (argsArray[i + 2][0] !== firstPIXOArg0) {
  36456. break; // images don't match
  36457. }
  36458. i += 4;
  36459. }
  36460. // At this point, i is the index of the first op past the last valid
  36461. // quartet.
  36462. var count = Math.min((i - iFirstSave) / 4, MAX_IMAGES_IN_BLOCK);
  36463. if (count < MIN_IMAGES_IN_BLOCK) {
  36464. return i;
  36465. }
  36466. // Extract the (x,y) positions from all of the matching transforms.
  36467. var positions = new Float32Array(count * 2);
  36468. var iTransform = iFirstTransform;
  36469. for (var q = 0; q < count; q++, iTransform += 4) {
  36470. var transformArgs = argsArray[iTransform];
  36471. positions[(q << 1)] = transformArgs[4];
  36472. positions[(q << 1) + 1] = transformArgs[5];
  36473. }
  36474. // Replace queue items.
  36475. var args = [firstPIXOArg0, firstTransformArg0, firstTransformArg3,
  36476. positions];
  36477. fnArray.splice(iFirstSave, count * 4, OPS.paintImageXObjectRepeat);
  36478. argsArray.splice(iFirstSave, count * 4, args);
  36479. return iFirstSave + 1;
  36480. });
  36481. // This replaces (beginText, setFont, setTextMatrix, showText, endText)+
  36482. // sequences with (beginText, setFont, (setTextMatrix, showText)+, endText)+
  36483. // sequences, if the font for each one is the same.
  36484. addState(InitialState,
  36485. [OPS.beginText, OPS.setFont, OPS.setTextMatrix, OPS.showText, OPS.endText],
  36486. function (context) {
  36487. var MIN_CHARS_IN_BLOCK = 3;
  36488. var MAX_CHARS_IN_BLOCK = 1000;
  36489. var fnArray = context.fnArray, argsArray = context.argsArray;
  36490. var curr = context.iCurr;
  36491. var iFirstBeginText = curr - 4;
  36492. var iFirstSetFont = curr - 3;
  36493. var iFirstSetTextMatrix = curr - 2;
  36494. var iFirstShowText = curr - 1;
  36495. var iFirstEndText = curr;
  36496. // Look for the quintets.
  36497. var firstSetFontArg0 = argsArray[iFirstSetFont][0];
  36498. var firstSetFontArg1 = argsArray[iFirstSetFont][1];
  36499. var i = iFirstBeginText + 5;
  36500. var ii = fnArray.length;
  36501. while (i + 4 < ii) {
  36502. if (fnArray[i] !== OPS.beginText ||
  36503. fnArray[i + 1] !== OPS.setFont ||
  36504. fnArray[i + 2] !== OPS.setTextMatrix ||
  36505. fnArray[i + 3] !== OPS.showText ||
  36506. fnArray[i + 4] !== OPS.endText) {
  36507. break; // ops don't match
  36508. }
  36509. if (argsArray[i + 1][0] !== firstSetFontArg0 ||
  36510. argsArray[i + 1][1] !== firstSetFontArg1) {
  36511. break; // fonts don't match
  36512. }
  36513. i += 5;
  36514. }
  36515. // At this point, i is the index of the first op past the last valid
  36516. // quintet.
  36517. var count = Math.min(((i - iFirstBeginText) / 5), MAX_CHARS_IN_BLOCK);
  36518. if (count < MIN_CHARS_IN_BLOCK) {
  36519. return i;
  36520. }
  36521. // If the preceding quintet is (<something>, setFont, setTextMatrix,
  36522. // showText, endText), include that as well. (E.g. <something> might be
  36523. // |dependency|.)
  36524. var iFirst = iFirstBeginText;
  36525. if (iFirstBeginText >= 4 &&
  36526. fnArray[iFirstBeginText - 4] === fnArray[iFirstSetFont] &&
  36527. fnArray[iFirstBeginText - 3] === fnArray[iFirstSetTextMatrix] &&
  36528. fnArray[iFirstBeginText - 2] === fnArray[iFirstShowText] &&
  36529. fnArray[iFirstBeginText - 1] === fnArray[iFirstEndText] &&
  36530. argsArray[iFirstBeginText - 4][0] === firstSetFontArg0 &&
  36531. argsArray[iFirstBeginText - 4][1] === firstSetFontArg1) {
  36532. count++;
  36533. iFirst -= 5;
  36534. }
  36535. // Remove (endText, beginText, setFont) trios.
  36536. var iEndText = iFirst + 4;
  36537. for (var q = 1; q < count; q++) {
  36538. fnArray.splice(iEndText, 3);
  36539. argsArray.splice(iEndText, 3);
  36540. iEndText += 2;
  36541. }
  36542. return iEndText + 1;
  36543. });
  36544. function QueueOptimizer() {}
  36545. QueueOptimizer.prototype = {
  36546. optimize: function QueueOptimizer_optimize(queue) {
  36547. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  36548. var context = {
  36549. iCurr: 0,
  36550. fnArray: fnArray,
  36551. argsArray: argsArray
  36552. };
  36553. var state;
  36554. var i = 0, ii = fnArray.length;
  36555. while (i < ii) {
  36556. state = (state || InitialState)[fnArray[i]];
  36557. if (typeof state === 'function') { // we found some handler
  36558. context.iCurr = i;
  36559. // state() returns the index of the first non-matching op (if we
  36560. // didn't match) or the first op past the modified ops (if we did
  36561. // match and replace).
  36562. i = state(context);
  36563. state = undefined; // reset the state machine
  36564. ii = context.fnArray.length;
  36565. } else {
  36566. i++;
  36567. }
  36568. }
  36569. }
  36570. };
  36571. return QueueOptimizer;
  36572. })();
  36573. exports.OperatorList = OperatorList;
  36574. exports.PartialEvaluator = PartialEvaluator;
  36575. }));
  36576. (function (root, factory) {
  36577. if (typeof define === 'function' && define.amd) {
  36578. define('pdfjs/core/annotation', ['exports', 'pdfjs/shared/util',
  36579. 'pdfjs/core/primitives', 'pdfjs/core/stream', 'pdfjs/core/colorspace',
  36580. 'pdfjs/core/obj', 'pdfjs/core/evaluator'], factory);
  36581. } else if (typeof exports !== 'undefined') {
  36582. factory(exports, require('../shared/util.js'), require('./primitives.js'),
  36583. require('./stream.js'), require('./colorspace.js'), require('./obj.js'),
  36584. require('./evaluator.js'));
  36585. } else {
  36586. factory((root.pdfjsCoreAnnotation = {}), root.pdfjsSharedUtil,
  36587. root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreColorSpace,
  36588. root.pdfjsCoreObj, root.pdfjsCoreEvaluator);
  36589. }
  36590. }(this, function (exports, sharedUtil, corePrimitives, coreStream,
  36591. coreColorSpace, coreObj, coreEvaluator) {
  36592. var AnnotationBorderStyleType = sharedUtil.AnnotationBorderStyleType;
  36593. var AnnotationFlag = sharedUtil.AnnotationFlag;
  36594. var AnnotationType = sharedUtil.AnnotationType;
  36595. var OPS = sharedUtil.OPS;
  36596. var Util = sharedUtil.Util;
  36597. var isArray = sharedUtil.isArray;
  36598. var isInt = sharedUtil.isInt;
  36599. var isValidUrl = sharedUtil.isValidUrl;
  36600. var stringToBytes = sharedUtil.stringToBytes;
  36601. var stringToPDFString = sharedUtil.stringToPDFString;
  36602. var stringToUTF8String = sharedUtil.stringToUTF8String;
  36603. var warn = sharedUtil.warn;
  36604. var Dict = corePrimitives.Dict;
  36605. var Name = corePrimitives.Name;
  36606. var isDict = corePrimitives.isDict;
  36607. var isName = corePrimitives.isName;
  36608. var Stream = coreStream.Stream;
  36609. var ColorSpace = coreColorSpace.ColorSpace;
  36610. var ObjectLoader = coreObj.ObjectLoader;
  36611. var OperatorList = coreEvaluator.OperatorList;
  36612. var DEFAULT_ICON_SIZE = 22; // px
  36613. /**
  36614. * @class
  36615. * @alias AnnotationFactory
  36616. */
  36617. function AnnotationFactory() {}
  36618. AnnotationFactory.prototype = /** @lends AnnotationFactory.prototype */ {
  36619. /**
  36620. * @param {XRef} xref
  36621. * @param {Object} ref
  36622. * @returns {Annotation}
  36623. */
  36624. create: function AnnotationFactory_create(xref, ref) {
  36625. var dict = xref.fetchIfRef(ref);
  36626. if (!isDict(dict)) {
  36627. return;
  36628. }
  36629. // Determine the annotation's subtype.
  36630. var subtype = dict.get('Subtype');
  36631. subtype = isName(subtype) ? subtype.name : '';
  36632. // Return the right annotation object based on the subtype and field type.
  36633. var parameters = {
  36634. dict: dict,
  36635. ref: ref
  36636. };
  36637. switch (subtype) {
  36638. case 'Link':
  36639. return new LinkAnnotation(parameters);
  36640. case 'Text':
  36641. return new TextAnnotation(parameters);
  36642. case 'Widget':
  36643. var fieldType = Util.getInheritableProperty(dict, 'FT');
  36644. if (isName(fieldType) && fieldType.name === 'Tx') {
  36645. return new TextWidgetAnnotation(parameters);
  36646. }
  36647. return new WidgetAnnotation(parameters);
  36648. default:
  36649. warn('Unimplemented annotation type "' + subtype + '", ' +
  36650. 'falling back to base annotation');
  36651. return new Annotation(parameters);
  36652. }
  36653. }
  36654. };
  36655. var Annotation = (function AnnotationClosure() {
  36656. // 12.5.5: Algorithm: Appearance streams
  36657. function getTransformMatrix(rect, bbox, matrix) {
  36658. var bounds = Util.getAxialAlignedBoundingBox(bbox, matrix);
  36659. var minX = bounds[0];
  36660. var minY = bounds[1];
  36661. var maxX = bounds[2];
  36662. var maxY = bounds[3];
  36663. if (minX === maxX || minY === maxY) {
  36664. // From real-life file, bbox was [0, 0, 0, 0]. In this case,
  36665. // just apply the transform for rect
  36666. return [1, 0, 0, 1, rect[0], rect[1]];
  36667. }
  36668. var xRatio = (rect[2] - rect[0]) / (maxX - minX);
  36669. var yRatio = (rect[3] - rect[1]) / (maxY - minY);
  36670. return [
  36671. xRatio,
  36672. 0,
  36673. 0,
  36674. yRatio,
  36675. rect[0] - minX * xRatio,
  36676. rect[1] - minY * yRatio
  36677. ];
  36678. }
  36679. function getDefaultAppearance(dict) {
  36680. var appearanceState = dict.get('AP');
  36681. if (!isDict(appearanceState)) {
  36682. return;
  36683. }
  36684. var appearance;
  36685. var appearances = appearanceState.get('N');
  36686. if (isDict(appearances)) {
  36687. var as = dict.get('AS');
  36688. if (as && appearances.has(as.name)) {
  36689. appearance = appearances.get(as.name);
  36690. }
  36691. } else {
  36692. appearance = appearances;
  36693. }
  36694. return appearance;
  36695. }
  36696. function Annotation(params) {
  36697. var dict = params.dict;
  36698. this.setFlags(dict.get('F'));
  36699. this.setRectangle(dict.get('Rect'));
  36700. this.setColor(dict.get('C'));
  36701. this.setBorderStyle(dict);
  36702. this.appearance = getDefaultAppearance(dict);
  36703. // Expose public properties using a data object.
  36704. this.data = {};
  36705. this.data.id = params.ref.num;
  36706. this.data.subtype = dict.get('Subtype').name;
  36707. this.data.annotationFlags = this.flags;
  36708. this.data.rect = this.rectangle;
  36709. this.data.color = this.color;
  36710. this.data.borderStyle = this.borderStyle;
  36711. this.data.hasAppearance = !!this.appearance;
  36712. }
  36713. Annotation.prototype = {
  36714. /**
  36715. * @return {boolean}
  36716. */
  36717. get viewable() {
  36718. if (this.flags) {
  36719. return !this.hasFlag(AnnotationFlag.INVISIBLE) &&
  36720. !this.hasFlag(AnnotationFlag.HIDDEN) &&
  36721. !this.hasFlag(AnnotationFlag.NOVIEW);
  36722. }
  36723. return true;
  36724. },
  36725. /**
  36726. * @return {boolean}
  36727. */
  36728. get printable() {
  36729. if (this.flags) {
  36730. return this.hasFlag(AnnotationFlag.PRINT) &&
  36731. !this.hasFlag(AnnotationFlag.INVISIBLE) &&
  36732. !this.hasFlag(AnnotationFlag.HIDDEN);
  36733. }
  36734. return false;
  36735. },
  36736. /**
  36737. * Set the flags.
  36738. *
  36739. * @public
  36740. * @memberof Annotation
  36741. * @param {number} flags - Unsigned 32-bit integer specifying annotation
  36742. * characteristics
  36743. * @see {@link shared/util.js}
  36744. */
  36745. setFlags: function Annotation_setFlags(flags) {
  36746. if (isInt(flags)) {
  36747. this.flags = flags;
  36748. } else {
  36749. this.flags = 0;
  36750. }
  36751. },
  36752. /**
  36753. * Check if a provided flag is set.
  36754. *
  36755. * @public
  36756. * @memberof Annotation
  36757. * @param {number} flag - Hexadecimal representation for an annotation
  36758. * characteristic
  36759. * @return {boolean}
  36760. * @see {@link shared/util.js}
  36761. */
  36762. hasFlag: function Annotation_hasFlag(flag) {
  36763. if (this.flags) {
  36764. return (this.flags & flag) > 0;
  36765. }
  36766. return false;
  36767. },
  36768. /**
  36769. * Set the rectangle.
  36770. *
  36771. * @public
  36772. * @memberof Annotation
  36773. * @param {Array} rectangle - The rectangle array with exactly four entries
  36774. */
  36775. setRectangle: function Annotation_setRectangle(rectangle) {
  36776. if (isArray(rectangle) && rectangle.length === 4) {
  36777. this.rectangle = Util.normalizeRect(rectangle);
  36778. } else {
  36779. this.rectangle = [0, 0, 0, 0];
  36780. }
  36781. },
  36782. /**
  36783. * Set the color and take care of color space conversion.
  36784. *
  36785. * @public
  36786. * @memberof Annotation
  36787. * @param {Array} color - The color array containing either 0
  36788. * (transparent), 1 (grayscale), 3 (RGB) or
  36789. * 4 (CMYK) elements
  36790. */
  36791. setColor: function Annotation_setColor(color) {
  36792. var rgbColor = new Uint8Array(3); // Black in RGB color space (default)
  36793. if (!isArray(color)) {
  36794. this.color = rgbColor;
  36795. return;
  36796. }
  36797. switch (color.length) {
  36798. case 0: // Transparent, which we indicate with a null value
  36799. this.color = null;
  36800. break;
  36801. case 1: // Convert grayscale to RGB
  36802. ColorSpace.singletons.gray.getRgbItem(color, 0, rgbColor, 0);
  36803. this.color = rgbColor;
  36804. break;
  36805. case 3: // Convert RGB percentages to RGB
  36806. ColorSpace.singletons.rgb.getRgbItem(color, 0, rgbColor, 0);
  36807. this.color = rgbColor;
  36808. break;
  36809. case 4: // Convert CMYK to RGB
  36810. ColorSpace.singletons.cmyk.getRgbItem(color, 0, rgbColor, 0);
  36811. this.color = rgbColor;
  36812. break;
  36813. default:
  36814. this.color = rgbColor;
  36815. break;
  36816. }
  36817. },
  36818. /**
  36819. * Set the border style (as AnnotationBorderStyle object).
  36820. *
  36821. * @public
  36822. * @memberof Annotation
  36823. * @param {Dict} borderStyle - The border style dictionary
  36824. */
  36825. setBorderStyle: function Annotation_setBorderStyle(borderStyle) {
  36826. this.borderStyle = new AnnotationBorderStyle();
  36827. if (!isDict(borderStyle)) {
  36828. return;
  36829. }
  36830. if (borderStyle.has('BS')) {
  36831. var dict = borderStyle.get('BS');
  36832. var dictType;
  36833. if (!dict.has('Type') || (isName(dictType = dict.get('Type')) &&
  36834. dictType.name === 'Border')) {
  36835. this.borderStyle.setWidth(dict.get('W'));
  36836. this.borderStyle.setStyle(dict.get('S'));
  36837. this.borderStyle.setDashArray(dict.get('D'));
  36838. }
  36839. } else if (borderStyle.has('Border')) {
  36840. var array = borderStyle.get('Border');
  36841. if (isArray(array) && array.length >= 3) {
  36842. this.borderStyle.setHorizontalCornerRadius(array[0]);
  36843. this.borderStyle.setVerticalCornerRadius(array[1]);
  36844. this.borderStyle.setWidth(array[2]);
  36845. if (array.length === 4) { // Dash array available
  36846. this.borderStyle.setDashArray(array[3]);
  36847. }
  36848. }
  36849. } else {
  36850. // There are no border entries in the dictionary. According to the
  36851. // specification, we should draw a solid border of width 1 in that
  36852. // case, but Adobe Reader did not implement that part of the
  36853. // specification and instead draws no border at all, so we do the same.
  36854. // See also https://github.com/mozilla/pdf.js/issues/6179.
  36855. this.borderStyle.setWidth(0);
  36856. }
  36857. },
  36858. loadResources: function Annotation_loadResources(keys) {
  36859. return new Promise(function (resolve, reject) {
  36860. this.appearance.dict.getAsync('Resources').then(function (resources) {
  36861. if (!resources) {
  36862. resolve();
  36863. return;
  36864. }
  36865. var objectLoader = new ObjectLoader(resources.map,
  36866. keys,
  36867. resources.xref);
  36868. objectLoader.load().then(function() {
  36869. resolve(resources);
  36870. }, reject);
  36871. }, reject);
  36872. }.bind(this));
  36873. },
  36874. getOperatorList: function Annotation_getOperatorList(evaluator, task) {
  36875. if (!this.appearance) {
  36876. return Promise.resolve(new OperatorList());
  36877. }
  36878. var data = this.data;
  36879. var appearanceDict = this.appearance.dict;
  36880. var resourcesPromise = this.loadResources([
  36881. 'ExtGState',
  36882. 'ColorSpace',
  36883. 'Pattern',
  36884. 'Shading',
  36885. 'XObject',
  36886. 'Font'
  36887. // ProcSet
  36888. // Properties
  36889. ]);
  36890. var bbox = appearanceDict.get('BBox') || [0, 0, 1, 1];
  36891. var matrix = appearanceDict.get('Matrix') || [1, 0, 0, 1, 0 ,0];
  36892. var transform = getTransformMatrix(data.rect, bbox, matrix);
  36893. var self = this;
  36894. return resourcesPromise.then(function(resources) {
  36895. var opList = new OperatorList();
  36896. opList.addOp(OPS.beginAnnotation, [data.rect, transform, matrix]);
  36897. return evaluator.getOperatorList(self.appearance, task,
  36898. resources, opList).
  36899. then(function () {
  36900. opList.addOp(OPS.endAnnotation, []);
  36901. self.appearance.reset();
  36902. return opList;
  36903. });
  36904. });
  36905. }
  36906. };
  36907. Annotation.appendToOperatorList = function Annotation_appendToOperatorList(
  36908. annotations, opList, partialEvaluator, task, intent) {
  36909. var annotationPromises = [];
  36910. for (var i = 0, n = annotations.length; i < n; ++i) {
  36911. if ((intent === 'display' && annotations[i].viewable) ||
  36912. (intent === 'print' && annotations[i].printable)) {
  36913. annotationPromises.push(
  36914. annotations[i].getOperatorList(partialEvaluator, task));
  36915. }
  36916. }
  36917. return Promise.all(annotationPromises).then(function(operatorLists) {
  36918. opList.addOp(OPS.beginAnnotations, []);
  36919. for (var i = 0, n = operatorLists.length; i < n; ++i) {
  36920. opList.addOpList(operatorLists[i]);
  36921. }
  36922. opList.addOp(OPS.endAnnotations, []);
  36923. });
  36924. };
  36925. return Annotation;
  36926. })();
  36927. /**
  36928. * Contains all data regarding an annotation's border style.
  36929. *
  36930. * @class
  36931. */
  36932. var AnnotationBorderStyle = (function AnnotationBorderStyleClosure() {
  36933. /**
  36934. * @constructor
  36935. * @private
  36936. */
  36937. function AnnotationBorderStyle() {
  36938. this.width = 1;
  36939. this.style = AnnotationBorderStyleType.SOLID;
  36940. this.dashArray = [3];
  36941. this.horizontalCornerRadius = 0;
  36942. this.verticalCornerRadius = 0;
  36943. }
  36944. AnnotationBorderStyle.prototype = {
  36945. /**
  36946. * Set the width.
  36947. *
  36948. * @public
  36949. * @memberof AnnotationBorderStyle
  36950. * @param {integer} width - The width
  36951. */
  36952. setWidth: function AnnotationBorderStyle_setWidth(width) {
  36953. if (width === (width | 0)) {
  36954. this.width = width;
  36955. }
  36956. },
  36957. /**
  36958. * Set the style.
  36959. *
  36960. * @public
  36961. * @memberof AnnotationBorderStyle
  36962. * @param {Object} style - The style object
  36963. * @see {@link shared/util.js}
  36964. */
  36965. setStyle: function AnnotationBorderStyle_setStyle(style) {
  36966. if (!style) {
  36967. return;
  36968. }
  36969. switch (style.name) {
  36970. case 'S':
  36971. this.style = AnnotationBorderStyleType.SOLID;
  36972. break;
  36973. case 'D':
  36974. this.style = AnnotationBorderStyleType.DASHED;
  36975. break;
  36976. case 'B':
  36977. this.style = AnnotationBorderStyleType.BEVELED;
  36978. break;
  36979. case 'I':
  36980. this.style = AnnotationBorderStyleType.INSET;
  36981. break;
  36982. case 'U':
  36983. this.style = AnnotationBorderStyleType.UNDERLINE;
  36984. break;
  36985. default:
  36986. break;
  36987. }
  36988. },
  36989. /**
  36990. * Set the dash array.
  36991. *
  36992. * @public
  36993. * @memberof AnnotationBorderStyle
  36994. * @param {Array} dashArray - The dash array with at least one element
  36995. */
  36996. setDashArray: function AnnotationBorderStyle_setDashArray(dashArray) {
  36997. // We validate the dash array, but we do not use it because CSS does not
  36998. // allow us to change spacing of dashes. For more information, visit
  36999. // http://www.w3.org/TR/css3-background/#the-border-style.
  37000. if (isArray(dashArray) && dashArray.length > 0) {
  37001. // According to the PDF specification: the elements in a dashArray
  37002. // shall be numbers that are nonnegative and not all equal to zero.
  37003. var isValid = true;
  37004. var allZeros = true;
  37005. for (var i = 0, len = dashArray.length; i < len; i++) {
  37006. var element = dashArray[i];
  37007. var validNumber = (+element >= 0);
  37008. if (!validNumber) {
  37009. isValid = false;
  37010. break;
  37011. } else if (element > 0) {
  37012. allZeros = false;
  37013. }
  37014. }
  37015. if (isValid && !allZeros) {
  37016. this.dashArray = dashArray;
  37017. } else {
  37018. this.width = 0; // Adobe behavior when the array is invalid.
  37019. }
  37020. } else if (dashArray) {
  37021. this.width = 0; // Adobe behavior when the array is invalid.
  37022. }
  37023. },
  37024. /**
  37025. * Set the horizontal corner radius (from a Border dictionary).
  37026. *
  37027. * @public
  37028. * @memberof AnnotationBorderStyle
  37029. * @param {integer} radius - The horizontal corner radius
  37030. */
  37031. setHorizontalCornerRadius:
  37032. function AnnotationBorderStyle_setHorizontalCornerRadius(radius) {
  37033. if (radius === (radius | 0)) {
  37034. this.horizontalCornerRadius = radius;
  37035. }
  37036. },
  37037. /**
  37038. * Set the vertical corner radius (from a Border dictionary).
  37039. *
  37040. * @public
  37041. * @memberof AnnotationBorderStyle
  37042. * @param {integer} radius - The vertical corner radius
  37043. */
  37044. setVerticalCornerRadius:
  37045. function AnnotationBorderStyle_setVerticalCornerRadius(radius) {
  37046. if (radius === (radius | 0)) {
  37047. this.verticalCornerRadius = radius;
  37048. }
  37049. }
  37050. };
  37051. return AnnotationBorderStyle;
  37052. })();
  37053. var WidgetAnnotation = (function WidgetAnnotationClosure() {
  37054. function WidgetAnnotation(params) {
  37055. Annotation.call(this, params);
  37056. var dict = params.dict;
  37057. var data = this.data;
  37058. data.annotationType = AnnotationType.WIDGET;
  37059. data.fieldValue = stringToPDFString(
  37060. Util.getInheritableProperty(dict, 'V') || '');
  37061. data.alternativeText = stringToPDFString(dict.get('TU') || '');
  37062. data.defaultAppearance = Util.getInheritableProperty(dict, 'DA') || '';
  37063. var fieldType = Util.getInheritableProperty(dict, 'FT');
  37064. data.fieldType = isName(fieldType) ? fieldType.name : '';
  37065. data.fieldFlags = Util.getInheritableProperty(dict, 'Ff') || 0;
  37066. this.fieldResources = Util.getInheritableProperty(dict, 'DR') || Dict.empty;
  37067. // Hide unsupported Widget signatures.
  37068. if (data.fieldType === 'Sig') {
  37069. warn('unimplemented annotation type: Widget signature');
  37070. this.setFlags(AnnotationFlag.HIDDEN);
  37071. }
  37072. // Building the full field name by collecting the field and
  37073. // its ancestors 'T' data and joining them using '.'.
  37074. var fieldName = [];
  37075. var namedItem = dict;
  37076. var ref = params.ref;
  37077. while (namedItem) {
  37078. var parent = namedItem.get('Parent');
  37079. var parentRef = namedItem.getRaw('Parent');
  37080. var name = namedItem.get('T');
  37081. if (name) {
  37082. fieldName.unshift(stringToPDFString(name));
  37083. } else if (parent && ref) {
  37084. // The field name is absent, that means more than one field
  37085. // with the same name may exist. Replacing the empty name
  37086. // with the '`' plus index in the parent's 'Kids' array.
  37087. // This is not in the PDF spec but necessary to id the
  37088. // the input controls.
  37089. var kids = parent.get('Kids');
  37090. var j, jj;
  37091. for (j = 0, jj = kids.length; j < jj; j++) {
  37092. var kidRef = kids[j];
  37093. if (kidRef.num === ref.num && kidRef.gen === ref.gen) {
  37094. break;
  37095. }
  37096. }
  37097. fieldName.unshift('`' + j);
  37098. }
  37099. namedItem = parent;
  37100. ref = parentRef;
  37101. }
  37102. data.fullName = fieldName.join('.');
  37103. }
  37104. Util.inherit(WidgetAnnotation, Annotation, {});
  37105. return WidgetAnnotation;
  37106. })();
  37107. var TextWidgetAnnotation = (function TextWidgetAnnotationClosure() {
  37108. function TextWidgetAnnotation(params) {
  37109. WidgetAnnotation.call(this, params);
  37110. this.data.textAlignment = Util.getInheritableProperty(params.dict, 'Q');
  37111. this.data.hasHtml = !this.data.hasAppearance && !!this.data.fieldValue;
  37112. }
  37113. Util.inherit(TextWidgetAnnotation, WidgetAnnotation, {
  37114. getOperatorList: function TextWidgetAnnotation_getOperatorList(evaluator,
  37115. task) {
  37116. if (this.appearance) {
  37117. return Annotation.prototype.getOperatorList.call(this, evaluator, task);
  37118. }
  37119. var opList = new OperatorList();
  37120. var data = this.data;
  37121. // Even if there is an appearance stream, ignore it. This is the
  37122. // behaviour used by Adobe Reader.
  37123. if (!data.defaultAppearance) {
  37124. return Promise.resolve(opList);
  37125. }
  37126. var stream = new Stream(stringToBytes(data.defaultAppearance));
  37127. return evaluator.getOperatorList(stream, task,
  37128. this.fieldResources, opList).
  37129. then(function () {
  37130. return opList;
  37131. });
  37132. }
  37133. });
  37134. return TextWidgetAnnotation;
  37135. })();
  37136. var TextAnnotation = (function TextAnnotationClosure() {
  37137. function TextAnnotation(params) {
  37138. Annotation.call(this, params);
  37139. var dict = params.dict;
  37140. var data = this.data;
  37141. var content = dict.get('Contents');
  37142. var title = dict.get('T');
  37143. data.annotationType = AnnotationType.TEXT;
  37144. data.content = stringToPDFString(content || '');
  37145. data.title = stringToPDFString(title || '');
  37146. data.hasHtml = true;
  37147. if (data.hasAppearance) {
  37148. data.name = 'NoIcon';
  37149. } else {
  37150. data.rect[1] = data.rect[3] - DEFAULT_ICON_SIZE;
  37151. data.rect[2] = data.rect[0] + DEFAULT_ICON_SIZE;
  37152. data.name = dict.has('Name') ? dict.get('Name').name : 'Note';
  37153. }
  37154. if (dict.has('C')) {
  37155. data.hasBgColor = true;
  37156. }
  37157. }
  37158. Util.inherit(TextAnnotation, Annotation, {});
  37159. return TextAnnotation;
  37160. })();
  37161. var LinkAnnotation = (function LinkAnnotationClosure() {
  37162. function LinkAnnotation(params) {
  37163. Annotation.call(this, params);
  37164. var dict = params.dict;
  37165. var data = this.data;
  37166. data.annotationType = AnnotationType.LINK;
  37167. data.hasHtml = true;
  37168. var action = dict.get('A');
  37169. if (action && isDict(action)) {
  37170. var linkType = action.get('S').name;
  37171. if (linkType === 'URI') {
  37172. var url = action.get('URI');
  37173. if (isName(url)) {
  37174. // Some bad PDFs do not put parentheses around relative URLs.
  37175. url = '/' + url.name;
  37176. } else if (url) {
  37177. url = addDefaultProtocolToUrl(url);
  37178. }
  37179. // TODO: pdf spec mentions urls can be relative to a Base
  37180. // entry in the dictionary.
  37181. if (!isValidUrl(url, false)) {
  37182. url = '';
  37183. }
  37184. // According to ISO 32000-1:2008, section 12.6.4.7,
  37185. // URI should to be encoded in 7-bit ASCII.
  37186. // Some bad PDFs may have URIs in UTF-8 encoding, see Bugzilla 1122280.
  37187. try {
  37188. data.url = stringToUTF8String(url);
  37189. } catch (e) {
  37190. // Fall back to a simple copy.
  37191. data.url = url;
  37192. }
  37193. } else if (linkType === 'GoTo') {
  37194. data.dest = action.get('D');
  37195. } else if (linkType === 'GoToR') {
  37196. var urlDict = action.get('F');
  37197. if (isDict(urlDict)) {
  37198. // We assume that the 'url' is a Filspec dictionary
  37199. // and fetch the url without checking any further
  37200. url = urlDict.get('F') || '';
  37201. }
  37202. // TODO: pdf reference says that GoToR
  37203. // can also have 'NewWindow' attribute
  37204. if (!isValidUrl(url, false)) {
  37205. url = '';
  37206. }
  37207. data.url = url;
  37208. data.dest = action.get('D');
  37209. } else if (linkType === 'Named') {
  37210. data.action = action.get('N').name;
  37211. } else {
  37212. warn('unrecognized link type: ' + linkType);
  37213. }
  37214. } else if (dict.has('Dest')) {
  37215. // simple destination link
  37216. var dest = dict.get('Dest');
  37217. data.dest = isName(dest) ? dest.name : dest;
  37218. }
  37219. }
  37220. // Lets URLs beginning with 'www.' default to using the 'http://' protocol.
  37221. function addDefaultProtocolToUrl(url) {
  37222. if (url && url.indexOf('www.') === 0) {
  37223. return ('http://' + url);
  37224. }
  37225. return url;
  37226. }
  37227. Util.inherit(LinkAnnotation, Annotation, {});
  37228. return LinkAnnotation;
  37229. })();
  37230. exports.Annotation = Annotation;
  37231. exports.AnnotationBorderStyle = AnnotationBorderStyle;
  37232. exports.AnnotationFactory = AnnotationFactory;
  37233. }));
  37234. (function (root, factory) {
  37235. if (typeof define === 'function' && define.amd) {
  37236. define('pdfjs/core/document', ['exports', 'pdfjs/shared/util',
  37237. 'pdfjs/core/primitives', 'pdfjs/core/stream', 'pdfjs/core/obj',
  37238. 'pdfjs/core/parser', 'pdfjs/core/crypto', 'pdfjs/core/evaluator',
  37239. 'pdfjs/core/annotation'], factory);
  37240. } else if (typeof exports !== 'undefined') {
  37241. factory(exports, require('../shared/util.js'), require('./primitives.js'),
  37242. require('./stream.js'), require('./obj.js'), require('./parser.js'),
  37243. require('./crypto.js'), require('./evaluator.js'),
  37244. require('./annotation.js'));
  37245. } else {
  37246. factory((root.pdfjsCoreDocument = {}), root.pdfjsSharedUtil,
  37247. root.pdfjsCorePrimitives, root.pdfjsCoreStream,
  37248. root.pdfjsCoreObj, root.pdfjsCoreParser, root.pdfjsCoreCrypto,
  37249. root.pdfjsCoreEvaluator, root.pdfjsCoreAnnotation);
  37250. }
  37251. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreObj,
  37252. coreParser, coreCrypto, coreEvaluator, coreAnnotation) {
  37253. var MissingDataException = sharedUtil.MissingDataException;
  37254. var Util = sharedUtil.Util;
  37255. var assert = sharedUtil.assert;
  37256. var error = sharedUtil.error;
  37257. var info = sharedUtil.info;
  37258. var isArray = sharedUtil.isArray;
  37259. var isArrayBuffer = sharedUtil.isArrayBuffer;
  37260. var isString = sharedUtil.isString;
  37261. var shadow = sharedUtil.shadow;
  37262. var stringToBytes = sharedUtil.stringToBytes;
  37263. var stringToPDFString = sharedUtil.stringToPDFString;
  37264. var warn = sharedUtil.warn;
  37265. var Dict = corePrimitives.Dict;
  37266. var isDict = corePrimitives.isDict;
  37267. var isName = corePrimitives.isName;
  37268. var isStream = corePrimitives.isStream;
  37269. var NullStream = coreStream.NullStream;
  37270. var Stream = coreStream.Stream;
  37271. var StreamsSequenceStream = coreStream.StreamsSequenceStream;
  37272. var Catalog = coreObj.Catalog;
  37273. var ObjectLoader = coreObj.ObjectLoader;
  37274. var XRef = coreObj.XRef;
  37275. var Lexer = coreParser.Lexer;
  37276. var Linearization = coreParser.Linearization;
  37277. var calculateMD5 = coreCrypto.calculateMD5;
  37278. var OperatorList = coreEvaluator.OperatorList;
  37279. var PartialEvaluator = coreEvaluator.PartialEvaluator;
  37280. var Annotation = coreAnnotation.Annotation;
  37281. var AnnotationFactory = coreAnnotation.AnnotationFactory;
  37282. var Page = (function PageClosure() {
  37283. var LETTER_SIZE_MEDIABOX = [0, 0, 612, 792];
  37284. function Page(pdfManager, xref, pageIndex, pageDict, ref, fontCache) {
  37285. this.pdfManager = pdfManager;
  37286. this.pageIndex = pageIndex;
  37287. this.pageDict = pageDict;
  37288. this.xref = xref;
  37289. this.ref = ref;
  37290. this.fontCache = fontCache;
  37291. this.idCounters = {
  37292. obj: 0
  37293. };
  37294. this.resourcesPromise = null;
  37295. }
  37296. Page.prototype = {
  37297. getPageProp: function Page_getPageProp(key) {
  37298. return this.pageDict.get(key);
  37299. },
  37300. getInheritedPageProp: function Page_getInheritedPageProp(key) {
  37301. var dict = this.pageDict, valueArray = null, loopCount = 0;
  37302. var MAX_LOOP_COUNT = 100;
  37303. // Always walk up the entire parent chain, to be able to find
  37304. // e.g. \Resources placed on multiple levels of the tree.
  37305. while (dict) {
  37306. var value = dict.get(key);
  37307. if (value) {
  37308. if (!valueArray) {
  37309. valueArray = [];
  37310. }
  37311. valueArray.push(value);
  37312. }
  37313. if (++loopCount > MAX_LOOP_COUNT) {
  37314. warn('Page_getInheritedPageProp: maximum loop count exceeded.');
  37315. break;
  37316. }
  37317. dict = dict.get('Parent');
  37318. }
  37319. if (!valueArray) {
  37320. return Dict.empty;
  37321. }
  37322. if (valueArray.length === 1 || !isDict(valueArray[0]) ||
  37323. loopCount > MAX_LOOP_COUNT) {
  37324. return valueArray[0];
  37325. }
  37326. return Dict.merge(this.xref, valueArray);
  37327. },
  37328. get content() {
  37329. return this.getPageProp('Contents');
  37330. },
  37331. get resources() {
  37332. // For robustness: The spec states that a \Resources entry has to be
  37333. // present, but can be empty. Some document omit it still, in this case
  37334. // we return an empty dictionary.
  37335. return shadow(this, 'resources', this.getInheritedPageProp('Resources'));
  37336. },
  37337. get mediaBox() {
  37338. var obj = this.getInheritedPageProp('MediaBox');
  37339. // Reset invalid media box to letter size.
  37340. if (!isArray(obj) || obj.length !== 4) {
  37341. obj = LETTER_SIZE_MEDIABOX;
  37342. }
  37343. return shadow(this, 'mediaBox', obj);
  37344. },
  37345. get view() {
  37346. var mediaBox = this.mediaBox;
  37347. var cropBox = this.getInheritedPageProp('CropBox');
  37348. if (!isArray(cropBox) || cropBox.length !== 4) {
  37349. return shadow(this, 'view', mediaBox);
  37350. }
  37351. // From the spec, 6th ed., p.963:
  37352. // "The crop, bleed, trim, and art boxes should not ordinarily
  37353. // extend beyond the boundaries of the media box. If they do, they are
  37354. // effectively reduced to their intersection with the media box."
  37355. cropBox = Util.intersect(cropBox, mediaBox);
  37356. if (!cropBox) {
  37357. return shadow(this, 'view', mediaBox);
  37358. }
  37359. return shadow(this, 'view', cropBox);
  37360. },
  37361. get rotate() {
  37362. var rotate = this.getInheritedPageProp('Rotate') || 0;
  37363. // Normalize rotation so it's a multiple of 90 and between 0 and 270
  37364. if (rotate % 90 !== 0) {
  37365. rotate = 0;
  37366. } else if (rotate >= 360) {
  37367. rotate = rotate % 360;
  37368. } else if (rotate < 0) {
  37369. // The spec doesn't cover negatives, assume its counterclockwise
  37370. // rotation. The following is the other implementation of modulo.
  37371. rotate = ((rotate % 360) + 360) % 360;
  37372. }
  37373. return shadow(this, 'rotate', rotate);
  37374. },
  37375. getContentStream: function Page_getContentStream() {
  37376. var content = this.content;
  37377. var stream;
  37378. if (isArray(content)) {
  37379. // fetching items
  37380. var xref = this.xref;
  37381. var i, n = content.length;
  37382. var streams = [];
  37383. for (i = 0; i < n; ++i) {
  37384. streams.push(xref.fetchIfRef(content[i]));
  37385. }
  37386. stream = new StreamsSequenceStream(streams);
  37387. } else if (isStream(content)) {
  37388. stream = content;
  37389. } else {
  37390. // replacing non-existent page content with empty one
  37391. stream = new NullStream();
  37392. }
  37393. return stream;
  37394. },
  37395. loadResources: function Page_loadResources(keys) {
  37396. if (!this.resourcesPromise) {
  37397. // TODO: add async getInheritedPageProp and remove this.
  37398. this.resourcesPromise = this.pdfManager.ensure(this, 'resources');
  37399. }
  37400. return this.resourcesPromise.then(function resourceSuccess() {
  37401. var objectLoader = new ObjectLoader(this.resources.map,
  37402. keys,
  37403. this.xref);
  37404. return objectLoader.load();
  37405. }.bind(this));
  37406. },
  37407. getOperatorList: function Page_getOperatorList(handler, task, intent) {
  37408. var self = this;
  37409. var pdfManager = this.pdfManager;
  37410. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  37411. []);
  37412. var resourcesPromise = this.loadResources([
  37413. 'ExtGState',
  37414. 'ColorSpace',
  37415. 'Pattern',
  37416. 'Shading',
  37417. 'XObject',
  37418. 'Font'
  37419. // ProcSet
  37420. // Properties
  37421. ]);
  37422. var partialEvaluator = new PartialEvaluator(pdfManager, this.xref,
  37423. handler, this.pageIndex,
  37424. 'p' + this.pageIndex + '_',
  37425. this.idCounters,
  37426. this.fontCache);
  37427. var dataPromises = Promise.all([contentStreamPromise, resourcesPromise]);
  37428. var pageListPromise = dataPromises.then(function(data) {
  37429. var contentStream = data[0];
  37430. var opList = new OperatorList(intent, handler, self.pageIndex);
  37431. handler.send('StartRenderPage', {
  37432. transparency: partialEvaluator.hasBlendModes(self.resources),
  37433. pageIndex: self.pageIndex,
  37434. intent: intent
  37435. });
  37436. return partialEvaluator.getOperatorList(contentStream, task,
  37437. self.resources, opList).then(function () {
  37438. return opList;
  37439. });
  37440. });
  37441. var annotationsPromise = pdfManager.ensure(this, 'annotations');
  37442. return Promise.all([pageListPromise, annotationsPromise]).then(
  37443. function(datas) {
  37444. var pageOpList = datas[0];
  37445. var annotations = datas[1];
  37446. if (annotations.length === 0) {
  37447. pageOpList.flush(true);
  37448. return pageOpList;
  37449. }
  37450. var annotationsReadyPromise = Annotation.appendToOperatorList(
  37451. annotations, pageOpList, partialEvaluator, task, intent);
  37452. return annotationsReadyPromise.then(function () {
  37453. pageOpList.flush(true);
  37454. return pageOpList;
  37455. });
  37456. });
  37457. },
  37458. extractTextContent: function Page_extractTextContent(task,
  37459. normalizeWhitespace) {
  37460. var handler = {
  37461. on: function nullHandlerOn() {},
  37462. send: function nullHandlerSend() {}
  37463. };
  37464. var self = this;
  37465. var pdfManager = this.pdfManager;
  37466. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  37467. []);
  37468. var resourcesPromise = this.loadResources([
  37469. 'ExtGState',
  37470. 'XObject',
  37471. 'Font'
  37472. ]);
  37473. var dataPromises = Promise.all([contentStreamPromise,
  37474. resourcesPromise]);
  37475. return dataPromises.then(function(data) {
  37476. var contentStream = data[0];
  37477. var partialEvaluator = new PartialEvaluator(pdfManager, self.xref,
  37478. handler, self.pageIndex,
  37479. 'p' + self.pageIndex + '_',
  37480. self.idCounters,
  37481. self.fontCache);
  37482. return partialEvaluator.getTextContent(contentStream,
  37483. task,
  37484. self.resources,
  37485. /* stateManager = */ null,
  37486. normalizeWhitespace);
  37487. });
  37488. },
  37489. getAnnotationsData: function Page_getAnnotationsData(intent) {
  37490. var annotations = this.annotations;
  37491. var annotationsData = [];
  37492. for (var i = 0, n = annotations.length; i < n; ++i) {
  37493. if (intent) {
  37494. if (!(intent === 'display' && annotations[i].viewable) &&
  37495. !(intent === 'print' && annotations[i].printable)) {
  37496. continue;
  37497. }
  37498. }
  37499. annotationsData.push(annotations[i].data);
  37500. }
  37501. return annotationsData;
  37502. },
  37503. get annotations() {
  37504. var annotations = [];
  37505. var annotationRefs = this.getInheritedPageProp('Annots') || [];
  37506. var annotationFactory = new AnnotationFactory();
  37507. for (var i = 0, n = annotationRefs.length; i < n; ++i) {
  37508. var annotationRef = annotationRefs[i];
  37509. var annotation = annotationFactory.create(this.xref, annotationRef);
  37510. if (annotation) {
  37511. annotations.push(annotation);
  37512. }
  37513. }
  37514. return shadow(this, 'annotations', annotations);
  37515. }
  37516. };
  37517. return Page;
  37518. })();
  37519. /**
  37520. * The `PDFDocument` holds all the data of the PDF file. Compared to the
  37521. * `PDFDoc`, this one doesn't have any job management code.
  37522. * Right now there exists one PDFDocument on the main thread + one object
  37523. * for each worker. If there is no worker support enabled, there are two
  37524. * `PDFDocument` objects on the main thread created.
  37525. */
  37526. var PDFDocument = (function PDFDocumentClosure() {
  37527. var FINGERPRINT_FIRST_BYTES = 1024;
  37528. var EMPTY_FINGERPRINT = '\x00\x00\x00\x00\x00\x00\x00' +
  37529. '\x00\x00\x00\x00\x00\x00\x00\x00\x00';
  37530. function PDFDocument(pdfManager, arg, password) {
  37531. if (isStream(arg)) {
  37532. init.call(this, pdfManager, arg, password);
  37533. } else if (isArrayBuffer(arg)) {
  37534. init.call(this, pdfManager, new Stream(arg), password);
  37535. } else {
  37536. error('PDFDocument: Unknown argument type');
  37537. }
  37538. }
  37539. function init(pdfManager, stream, password) {
  37540. assert(stream.length > 0, 'stream must have data');
  37541. this.pdfManager = pdfManager;
  37542. this.stream = stream;
  37543. var xref = new XRef(this.stream, password, pdfManager);
  37544. this.xref = xref;
  37545. }
  37546. function find(stream, needle, limit, backwards) {
  37547. var pos = stream.pos;
  37548. var end = stream.end;
  37549. var strBuf = [];
  37550. if (pos + limit > end) {
  37551. limit = end - pos;
  37552. }
  37553. for (var n = 0; n < limit; ++n) {
  37554. strBuf.push(String.fromCharCode(stream.getByte()));
  37555. }
  37556. var str = strBuf.join('');
  37557. stream.pos = pos;
  37558. var index = backwards ? str.lastIndexOf(needle) : str.indexOf(needle);
  37559. if (index === -1) {
  37560. return false; /* not found */
  37561. }
  37562. stream.pos += index;
  37563. return true; /* found */
  37564. }
  37565. var DocumentInfoValidators = {
  37566. get entries() {
  37567. // Lazily build this since all the validation functions below are not
  37568. // defined until after this file loads.
  37569. return shadow(this, 'entries', {
  37570. Title: isString,
  37571. Author: isString,
  37572. Subject: isString,
  37573. Keywords: isString,
  37574. Creator: isString,
  37575. Producer: isString,
  37576. CreationDate: isString,
  37577. ModDate: isString,
  37578. Trapped: isName
  37579. });
  37580. }
  37581. };
  37582. PDFDocument.prototype = {
  37583. parse: function PDFDocument_parse(recoveryMode) {
  37584. this.setup(recoveryMode);
  37585. var version = this.catalog.catDict.get('Version');
  37586. if (isName(version)) {
  37587. this.pdfFormatVersion = version.name;
  37588. }
  37589. try {
  37590. // checking if AcroForm is present
  37591. this.acroForm = this.catalog.catDict.get('AcroForm');
  37592. if (this.acroForm) {
  37593. this.xfa = this.acroForm.get('XFA');
  37594. var fields = this.acroForm.get('Fields');
  37595. if ((!fields || !isArray(fields) || fields.length === 0) &&
  37596. !this.xfa) {
  37597. // no fields and no XFA -- not a form (?)
  37598. this.acroForm = null;
  37599. }
  37600. }
  37601. } catch (ex) {
  37602. info('Something wrong with AcroForm entry');
  37603. this.acroForm = null;
  37604. }
  37605. },
  37606. get linearization() {
  37607. var linearization = null;
  37608. if (this.stream.length) {
  37609. try {
  37610. linearization = Linearization.create(this.stream);
  37611. } catch (err) {
  37612. if (err instanceof MissingDataException) {
  37613. throw err;
  37614. }
  37615. info(err);
  37616. }
  37617. }
  37618. // shadow the prototype getter with a data property
  37619. return shadow(this, 'linearization', linearization);
  37620. },
  37621. get startXRef() {
  37622. var stream = this.stream;
  37623. var startXRef = 0;
  37624. var linearization = this.linearization;
  37625. if (linearization) {
  37626. // Find end of first obj.
  37627. stream.reset();
  37628. if (find(stream, 'endobj', 1024)) {
  37629. startXRef = stream.pos + 6;
  37630. }
  37631. } else {
  37632. // Find startxref by jumping backward from the end of the file.
  37633. var step = 1024;
  37634. var found = false, pos = stream.end;
  37635. while (!found && pos > 0) {
  37636. pos -= step - 'startxref'.length;
  37637. if (pos < 0) {
  37638. pos = 0;
  37639. }
  37640. stream.pos = pos;
  37641. found = find(stream, 'startxref', step, true);
  37642. }
  37643. if (found) {
  37644. stream.skip(9);
  37645. var ch;
  37646. do {
  37647. ch = stream.getByte();
  37648. } while (Lexer.isSpace(ch));
  37649. var str = '';
  37650. while (ch >= 0x20 && ch <= 0x39) { // < '9'
  37651. str += String.fromCharCode(ch);
  37652. ch = stream.getByte();
  37653. }
  37654. startXRef = parseInt(str, 10);
  37655. if (isNaN(startXRef)) {
  37656. startXRef = 0;
  37657. }
  37658. }
  37659. }
  37660. // shadow the prototype getter with a data property
  37661. return shadow(this, 'startXRef', startXRef);
  37662. },
  37663. get mainXRefEntriesOffset() {
  37664. var mainXRefEntriesOffset = 0;
  37665. var linearization = this.linearization;
  37666. if (linearization) {
  37667. mainXRefEntriesOffset = linearization.mainXRefEntriesOffset;
  37668. }
  37669. // shadow the prototype getter with a data property
  37670. return shadow(this, 'mainXRefEntriesOffset', mainXRefEntriesOffset);
  37671. },
  37672. // Find the header, remove leading garbage and setup the stream
  37673. // starting from the header.
  37674. checkHeader: function PDFDocument_checkHeader() {
  37675. var stream = this.stream;
  37676. stream.reset();
  37677. if (find(stream, '%PDF-', 1024)) {
  37678. // Found the header, trim off any garbage before it.
  37679. stream.moveStart();
  37680. // Reading file format version
  37681. var MAX_VERSION_LENGTH = 12;
  37682. var version = '', ch;
  37683. while ((ch = stream.getByte()) > 0x20) { // SPACE
  37684. if (version.length >= MAX_VERSION_LENGTH) {
  37685. break;
  37686. }
  37687. version += String.fromCharCode(ch);
  37688. }
  37689. if (!this.pdfFormatVersion) {
  37690. // removing "%PDF-"-prefix
  37691. this.pdfFormatVersion = version.substring(5);
  37692. }
  37693. return;
  37694. }
  37695. // May not be a PDF file, continue anyway.
  37696. },
  37697. parseStartXRef: function PDFDocument_parseStartXRef() {
  37698. var startXRef = this.startXRef;
  37699. this.xref.setStartXRef(startXRef);
  37700. },
  37701. setup: function PDFDocument_setup(recoveryMode) {
  37702. this.xref.parse(recoveryMode);
  37703. var self = this;
  37704. var pageFactory = {
  37705. createPage: function (pageIndex, dict, ref, fontCache) {
  37706. return new Page(self.pdfManager, self.xref, pageIndex, dict, ref,
  37707. fontCache);
  37708. }
  37709. };
  37710. this.catalog = new Catalog(this.pdfManager, this.xref, pageFactory);
  37711. },
  37712. get numPages() {
  37713. var linearization = this.linearization;
  37714. var num = linearization ? linearization.numPages : this.catalog.numPages;
  37715. // shadow the prototype getter
  37716. return shadow(this, 'numPages', num);
  37717. },
  37718. get documentInfo() {
  37719. var docInfo = {
  37720. PDFFormatVersion: this.pdfFormatVersion,
  37721. IsAcroFormPresent: !!this.acroForm,
  37722. IsXFAPresent: !!this.xfa
  37723. };
  37724. var infoDict;
  37725. try {
  37726. infoDict = this.xref.trailer.get('Info');
  37727. } catch (err) {
  37728. info('The document information dictionary is invalid.');
  37729. }
  37730. if (infoDict) {
  37731. var validEntries = DocumentInfoValidators.entries;
  37732. // Only fill the document info with valid entries from the spec.
  37733. for (var key in validEntries) {
  37734. if (infoDict.has(key)) {
  37735. var value = infoDict.get(key);
  37736. // Make sure the value conforms to the spec.
  37737. if (validEntries[key](value)) {
  37738. docInfo[key] = (typeof value !== 'string' ?
  37739. value : stringToPDFString(value));
  37740. } else {
  37741. info('Bad value in document info for "' + key + '"');
  37742. }
  37743. }
  37744. }
  37745. }
  37746. return shadow(this, 'documentInfo', docInfo);
  37747. },
  37748. get fingerprint() {
  37749. var xref = this.xref, hash, fileID = '';
  37750. var idArray = xref.trailer.get('ID');
  37751. if (idArray && isArray(idArray) && idArray[0] && isString(idArray[0]) &&
  37752. idArray[0] !== EMPTY_FINGERPRINT) {
  37753. hash = stringToBytes(idArray[0]);
  37754. } else {
  37755. if (this.stream.ensureRange) {
  37756. this.stream.ensureRange(0,
  37757. Math.min(FINGERPRINT_FIRST_BYTES, this.stream.end));
  37758. }
  37759. hash = calculateMD5(this.stream.bytes.subarray(0,
  37760. FINGERPRINT_FIRST_BYTES), 0, FINGERPRINT_FIRST_BYTES);
  37761. }
  37762. for (var i = 0, n = hash.length; i < n; i++) {
  37763. var hex = hash[i].toString(16);
  37764. fileID += hex.length === 1 ? '0' + hex : hex;
  37765. }
  37766. return shadow(this, 'fingerprint', fileID);
  37767. },
  37768. getPage: function PDFDocument_getPage(pageIndex) {
  37769. return this.catalog.getPage(pageIndex);
  37770. },
  37771. cleanup: function PDFDocument_cleanup() {
  37772. return this.catalog.cleanup();
  37773. }
  37774. };
  37775. return PDFDocument;
  37776. })();
  37777. exports.Page = Page;
  37778. exports.PDFDocument = PDFDocument;
  37779. }));
  37780. (function (root, factory) {
  37781. if (typeof define === 'function' && define.amd) {
  37782. define('pdfjs/core/pdf_manager', ['exports', 'pdfjs/shared/util',
  37783. 'pdfjs/core/stream', 'pdfjs/core/chunked_stream', 'pdfjs/core/document'],
  37784. factory);
  37785. } else if (typeof exports !== 'undefined') {
  37786. factory(exports, require('../shared/util.js'), require('./stream.js'),
  37787. require('./chunked_stream.js'), require('./document.js'));
  37788. } else {
  37789. factory((root.pdfjsCorePdfManager = {}), root.pdfjsSharedUtil,
  37790. root.pdfjsCoreStream, root.pdfjsCoreChunkedStream,
  37791. root.pdfjsCoreDocument);
  37792. }
  37793. }(this, function (exports, sharedUtil, coreStream, coreChunkedStream,
  37794. coreDocument) {
  37795. var NotImplementedException = sharedUtil.NotImplementedException;
  37796. var MissingDataException = sharedUtil.MissingDataException;
  37797. var createPromiseCapability = sharedUtil.createPromiseCapability;
  37798. var Util = sharedUtil.Util;
  37799. var Stream = coreStream.Stream;
  37800. var ChunkedStreamManager = coreChunkedStream.ChunkedStreamManager;
  37801. var PDFDocument = coreDocument.PDFDocument;
  37802. var BasePdfManager = (function BasePdfManagerClosure() {
  37803. function BasePdfManager() {
  37804. throw new Error('Cannot initialize BaseManagerManager');
  37805. }
  37806. BasePdfManager.prototype = {
  37807. get docId() {
  37808. return this._docId;
  37809. },
  37810. onLoadedStream: function BasePdfManager_onLoadedStream() {
  37811. throw new NotImplementedException();
  37812. },
  37813. ensureDoc: function BasePdfManager_ensureDoc(prop, args) {
  37814. return this.ensure(this.pdfDocument, prop, args);
  37815. },
  37816. ensureXRef: function BasePdfManager_ensureXRef(prop, args) {
  37817. return this.ensure(this.pdfDocument.xref, prop, args);
  37818. },
  37819. ensureCatalog: function BasePdfManager_ensureCatalog(prop, args) {
  37820. return this.ensure(this.pdfDocument.catalog, prop, args);
  37821. },
  37822. getPage: function BasePdfManager_getPage(pageIndex) {
  37823. return this.pdfDocument.getPage(pageIndex);
  37824. },
  37825. cleanup: function BasePdfManager_cleanup() {
  37826. return this.pdfDocument.cleanup();
  37827. },
  37828. ensure: function BasePdfManager_ensure(obj, prop, args) {
  37829. return new NotImplementedException();
  37830. },
  37831. requestRange: function BasePdfManager_requestRange(begin, end) {
  37832. return new NotImplementedException();
  37833. },
  37834. requestLoadedStream: function BasePdfManager_requestLoadedStream() {
  37835. return new NotImplementedException();
  37836. },
  37837. sendProgressiveData: function BasePdfManager_sendProgressiveData(chunk) {
  37838. return new NotImplementedException();
  37839. },
  37840. updatePassword: function BasePdfManager_updatePassword(password) {
  37841. this.pdfDocument.xref.password = this.password = password;
  37842. if (this._passwordChangedCapability) {
  37843. this._passwordChangedCapability.resolve();
  37844. }
  37845. },
  37846. passwordChanged: function BasePdfManager_passwordChanged() {
  37847. this._passwordChangedCapability = createPromiseCapability();
  37848. return this._passwordChangedCapability.promise;
  37849. },
  37850. terminate: function BasePdfManager_terminate() {
  37851. return new NotImplementedException();
  37852. }
  37853. };
  37854. return BasePdfManager;
  37855. })();
  37856. var LocalPdfManager = (function LocalPdfManagerClosure() {
  37857. function LocalPdfManager(docId, data, password) {
  37858. this._docId = docId;
  37859. var stream = new Stream(data);
  37860. this.pdfDocument = new PDFDocument(this, stream, password);
  37861. this._loadedStreamCapability = createPromiseCapability();
  37862. this._loadedStreamCapability.resolve(stream);
  37863. }
  37864. Util.inherit(LocalPdfManager, BasePdfManager, {
  37865. ensure: function LocalPdfManager_ensure(obj, prop, args) {
  37866. return new Promise(function (resolve, reject) {
  37867. try {
  37868. var value = obj[prop];
  37869. var result;
  37870. if (typeof value === 'function') {
  37871. result = value.apply(obj, args);
  37872. } else {
  37873. result = value;
  37874. }
  37875. resolve(result);
  37876. } catch (e) {
  37877. reject(e);
  37878. }
  37879. });
  37880. },
  37881. requestRange: function LocalPdfManager_requestRange(begin, end) {
  37882. return Promise.resolve();
  37883. },
  37884. requestLoadedStream: function LocalPdfManager_requestLoadedStream() {
  37885. return;
  37886. },
  37887. onLoadedStream: function LocalPdfManager_onLoadedStream() {
  37888. return this._loadedStreamCapability.promise;
  37889. },
  37890. terminate: function LocalPdfManager_terminate() {
  37891. return;
  37892. }
  37893. });
  37894. return LocalPdfManager;
  37895. })();
  37896. var NetworkPdfManager = (function NetworkPdfManagerClosure() {
  37897. function NetworkPdfManager(docId, args, msgHandler) {
  37898. this._docId = docId;
  37899. this.msgHandler = msgHandler;
  37900. var params = {
  37901. msgHandler: msgHandler,
  37902. httpHeaders: args.httpHeaders,
  37903. withCredentials: args.withCredentials,
  37904. chunkedViewerLoading: args.chunkedViewerLoading,
  37905. disableAutoFetch: args.disableAutoFetch,
  37906. initialData: args.initialData
  37907. };
  37908. this.streamManager = new ChunkedStreamManager(args.length,
  37909. args.rangeChunkSize,
  37910. args.url, params);
  37911. this.pdfDocument = new PDFDocument(this, this.streamManager.getStream(),
  37912. args.password);
  37913. }
  37914. Util.inherit(NetworkPdfManager, BasePdfManager, {
  37915. ensure: function NetworkPdfManager_ensure(obj, prop, args) {
  37916. var pdfManager = this;
  37917. return new Promise(function (resolve, reject) {
  37918. function ensureHelper() {
  37919. try {
  37920. var result;
  37921. var value = obj[prop];
  37922. if (typeof value === 'function') {
  37923. result = value.apply(obj, args);
  37924. } else {
  37925. result = value;
  37926. }
  37927. resolve(result);
  37928. } catch(e) {
  37929. if (!(e instanceof MissingDataException)) {
  37930. reject(e);
  37931. return;
  37932. }
  37933. pdfManager.streamManager.requestRange(e.begin, e.end).
  37934. then(ensureHelper, reject);
  37935. }
  37936. }
  37937. ensureHelper();
  37938. });
  37939. },
  37940. requestRange: function NetworkPdfManager_requestRange(begin, end) {
  37941. return this.streamManager.requestRange(begin, end);
  37942. },
  37943. requestLoadedStream: function NetworkPdfManager_requestLoadedStream() {
  37944. this.streamManager.requestAllChunks();
  37945. },
  37946. sendProgressiveData:
  37947. function NetworkPdfManager_sendProgressiveData(chunk) {
  37948. this.streamManager.onReceiveData({ chunk: chunk });
  37949. },
  37950. onLoadedStream: function NetworkPdfManager_onLoadedStream() {
  37951. return this.streamManager.onLoadedStream();
  37952. },
  37953. terminate: function NetworkPdfManager_terminate() {
  37954. this.streamManager.abort();
  37955. }
  37956. });
  37957. return NetworkPdfManager;
  37958. })();
  37959. exports.LocalPdfManager = LocalPdfManager;
  37960. exports.NetworkPdfManager = NetworkPdfManager;
  37961. }));
  37962. (function (root, factory) {
  37963. if (typeof define === 'function' && define.amd) {
  37964. define('pdfjs/core/worker', ['exports', 'pdfjs/shared/util',
  37965. 'pdfjs/core/primitives', 'pdfjs/core/pdf_manager', 'pdfjs/shared/global'],
  37966. factory);
  37967. } else if (typeof exports !== 'undefined') {
  37968. factory(exports, require('../shared/util.js'), require('./primitives.js'),
  37969. require('./pdf_manager.js'), require('../shared/global.js'));
  37970. } else {
  37971. factory((root.pdfjsCoreWorker = {}), root.pdfjsSharedUtil,
  37972. root.pdfjsCorePrimitives, root.pdfjsCorePdfManager,
  37973. root.pdfjsSharedGlobal);
  37974. }
  37975. }(this, function (exports, sharedUtil, corePrimitives, corePdfManager,
  37976. sharedGlobal) {
  37977. var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  37978. var InvalidPDFException = sharedUtil.InvalidPDFException;
  37979. var MessageHandler = sharedUtil.MessageHandler;
  37980. var MissingPDFException = sharedUtil.MissingPDFException;
  37981. var UnexpectedResponseException = sharedUtil.UnexpectedResponseException;
  37982. var PasswordException = sharedUtil.PasswordException;
  37983. var PasswordResponses = sharedUtil.PasswordResponses;
  37984. var UnknownErrorException = sharedUtil.UnknownErrorException;
  37985. var XRefParseException = sharedUtil.XRefParseException;
  37986. var createPromiseCapability = sharedUtil.createPromiseCapability;
  37987. var error = sharedUtil.error;
  37988. var info = sharedUtil.info;
  37989. var isInt = sharedUtil.isInt;
  37990. var warn = sharedUtil.warn;
  37991. var Ref = corePrimitives.Ref;
  37992. var LocalPdfManager = corePdfManager.LocalPdfManager;
  37993. var NetworkPdfManager = corePdfManager.NetworkPdfManager;
  37994. var globalScope = sharedGlobal.globalScope;
  37995. var PDFJS = sharedGlobal.PDFJS;
  37996. var WorkerTask = (function WorkerTaskClosure() {
  37997. function WorkerTask(name) {
  37998. this.name = name;
  37999. this.terminated = false;
  38000. this._capability = createPromiseCapability();
  38001. }
  38002. WorkerTask.prototype = {
  38003. get finished() {
  38004. return this._capability.promise;
  38005. },
  38006. finish: function () {
  38007. this._capability.resolve();
  38008. },
  38009. terminate: function () {
  38010. this.terminated = true;
  38011. },
  38012. ensureNotTerminated: function () {
  38013. if (this.terminated) {
  38014. throw new Error('Worker task was terminated');
  38015. }
  38016. }
  38017. };
  38018. return WorkerTask;
  38019. })();
  38020. var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
  38021. setup: function wphSetup(handler, port) {
  38022. handler.on('test', function wphSetupTest(data) {
  38023. // check if Uint8Array can be sent to worker
  38024. if (!(data instanceof Uint8Array)) {
  38025. handler.send('test', 'main', false);
  38026. return;
  38027. }
  38028. // making sure postMessage transfers are working
  38029. var supportTransfers = data[0] === 255;
  38030. handler.postMessageTransfers = supportTransfers;
  38031. // check if the response property is supported by xhr
  38032. var xhr = new XMLHttpRequest();
  38033. var responseExists = 'response' in xhr;
  38034. // check if the property is actually implemented
  38035. try {
  38036. var dummy = xhr.responseType;
  38037. } catch (e) {
  38038. responseExists = false;
  38039. }
  38040. if (!responseExists) {
  38041. handler.send('test', false);
  38042. return;
  38043. }
  38044. handler.send('test', {
  38045. supportTypedArray: true,
  38046. supportTransfers: supportTransfers
  38047. });
  38048. });
  38049. handler.on('GetDocRequest', function wphSetupDoc(data) {
  38050. return WorkerMessageHandler.createDocumentHandler(data, port);
  38051. });
  38052. },
  38053. createDocumentHandler: function wphCreateDocumentHandler(docParams, port) {
  38054. // This context is actually holds references on pdfManager and handler,
  38055. // until the latter is destroyed.
  38056. var pdfManager;
  38057. var terminated = false;
  38058. var cancelXHRs = null;
  38059. var WorkerTasks = [];
  38060. var docId = docParams.docId;
  38061. var workerHandlerName = docParams.docId + '_worker';
  38062. var handler = new MessageHandler(workerHandlerName, docId, port);
  38063. function ensureNotTerminated() {
  38064. if (terminated) {
  38065. throw new Error('Worker was terminated');
  38066. }
  38067. }
  38068. function startWorkerTask(task) {
  38069. WorkerTasks.push(task);
  38070. }
  38071. function finishWorkerTask(task) {
  38072. task.finish();
  38073. var i = WorkerTasks.indexOf(task);
  38074. WorkerTasks.splice(i, 1);
  38075. }
  38076. function loadDocument(recoveryMode) {
  38077. var loadDocumentCapability = createPromiseCapability();
  38078. var parseSuccess = function parseSuccess() {
  38079. var numPagesPromise = pdfManager.ensureDoc('numPages');
  38080. var fingerprintPromise = pdfManager.ensureDoc('fingerprint');
  38081. var encryptedPromise = pdfManager.ensureXRef('encrypt');
  38082. Promise.all([numPagesPromise, fingerprintPromise,
  38083. encryptedPromise]).then(function onDocReady(results) {
  38084. var doc = {
  38085. numPages: results[0],
  38086. fingerprint: results[1],
  38087. encrypted: !!results[2],
  38088. };
  38089. loadDocumentCapability.resolve(doc);
  38090. },
  38091. parseFailure);
  38092. };
  38093. var parseFailure = function parseFailure(e) {
  38094. loadDocumentCapability.reject(e);
  38095. };
  38096. pdfManager.ensureDoc('checkHeader', []).then(function() {
  38097. pdfManager.ensureDoc('parseStartXRef', []).then(function() {
  38098. pdfManager.ensureDoc('parse', [recoveryMode]).then(
  38099. parseSuccess, parseFailure);
  38100. }, parseFailure);
  38101. }, parseFailure);
  38102. return loadDocumentCapability.promise;
  38103. }
  38104. function getPdfManager(data) {
  38105. var pdfManagerCapability = createPromiseCapability();
  38106. var pdfManager;
  38107. var source = data.source;
  38108. var disableRange = data.disableRange;
  38109. if (source.data) {
  38110. try {
  38111. pdfManager = new LocalPdfManager(docId, source.data, source.password);
  38112. pdfManagerCapability.resolve(pdfManager);
  38113. } catch (ex) {
  38114. pdfManagerCapability.reject(ex);
  38115. }
  38116. return pdfManagerCapability.promise;
  38117. } else if (source.chunkedViewerLoading) {
  38118. try {
  38119. pdfManager = new NetworkPdfManager(docId, source, handler);
  38120. pdfManagerCapability.resolve(pdfManager);
  38121. } catch (ex) {
  38122. pdfManagerCapability.reject(ex);
  38123. }
  38124. return pdfManagerCapability.promise;
  38125. }
  38126. var networkManager = new NetworkManager(source.url, {
  38127. httpHeaders: source.httpHeaders,
  38128. withCredentials: source.withCredentials
  38129. });
  38130. var cachedChunks = [];
  38131. var fullRequestXhrId = networkManager.requestFull({
  38132. onHeadersReceived: function onHeadersReceived() {
  38133. if (disableRange) {
  38134. return;
  38135. }
  38136. var fullRequestXhr = networkManager.getRequestXhr(fullRequestXhrId);
  38137. if (fullRequestXhr.getResponseHeader('Accept-Ranges') !== 'bytes') {
  38138. return;
  38139. }
  38140. var contentEncoding =
  38141. fullRequestXhr.getResponseHeader('Content-Encoding') || 'identity';
  38142. if (contentEncoding !== 'identity') {
  38143. return;
  38144. }
  38145. var length = fullRequestXhr.getResponseHeader('Content-Length');
  38146. length = parseInt(length, 10);
  38147. if (!isInt(length)) {
  38148. return;
  38149. }
  38150. source.length = length;
  38151. if (length <= 2 * source.rangeChunkSize) {
  38152. // The file size is smaller than the size of two chunks, so it does
  38153. // not make any sense to abort the request and retry with a range
  38154. // request.
  38155. return;
  38156. }
  38157. if (networkManager.isStreamingRequest(fullRequestXhrId)) {
  38158. // We can continue fetching when progressive loading is enabled,
  38159. // and we don't need the autoFetch feature.
  38160. source.disableAutoFetch = true;
  38161. } else {
  38162. // NOTE: by cancelling the full request, and then issuing range
  38163. // requests, there will be an issue for sites where you can only
  38164. // request the pdf once. However, if this is the case, then the
  38165. // server should not be returning that it can support range
  38166. // requests.
  38167. networkManager.abortRequest(fullRequestXhrId);
  38168. }
  38169. try {
  38170. pdfManager = new NetworkPdfManager(docId, source, handler);
  38171. pdfManagerCapability.resolve(pdfManager);
  38172. } catch (ex) {
  38173. pdfManagerCapability.reject(ex);
  38174. }
  38175. cancelXHRs = null;
  38176. },
  38177. onProgressiveData: source.disableStream ? null :
  38178. function onProgressiveData(chunk) {
  38179. if (!pdfManager) {
  38180. cachedChunks.push(chunk);
  38181. return;
  38182. }
  38183. pdfManager.sendProgressiveData(chunk);
  38184. },
  38185. onDone: function onDone(args) {
  38186. if (pdfManager) {
  38187. return; // already processed
  38188. }
  38189. var pdfFile;
  38190. if (args === null) {
  38191. // TODO add some streaming manager, e.g. for unknown length files.
  38192. // The data was returned in the onProgressiveData, combining...
  38193. var pdfFileLength = 0, pos = 0;
  38194. cachedChunks.forEach(function (chunk) {
  38195. pdfFileLength += chunk.byteLength;
  38196. });
  38197. if (source.length && pdfFileLength !== source.length) {
  38198. warn('reported HTTP length is different from actual');
  38199. }
  38200. var pdfFileArray = new Uint8Array(pdfFileLength);
  38201. cachedChunks.forEach(function (chunk) {
  38202. pdfFileArray.set(new Uint8Array(chunk), pos);
  38203. pos += chunk.byteLength;
  38204. });
  38205. pdfFile = pdfFileArray.buffer;
  38206. } else {
  38207. pdfFile = args.chunk;
  38208. }
  38209. // the data is array, instantiating directly from it
  38210. try {
  38211. pdfManager = new LocalPdfManager(docId, pdfFile, source.password);
  38212. pdfManagerCapability.resolve(pdfManager);
  38213. } catch (ex) {
  38214. pdfManagerCapability.reject(ex);
  38215. }
  38216. cancelXHRs = null;
  38217. },
  38218. onError: function onError(status) {
  38219. var exception;
  38220. if (status === 404 || status === 0 && /^file:/.test(source.url)) {
  38221. exception = new MissingPDFException('Missing PDF "' +
  38222. source.url + '".');
  38223. handler.send('MissingPDF', exception);
  38224. } else {
  38225. exception = new UnexpectedResponseException(
  38226. 'Unexpected server response (' + status +
  38227. ') while retrieving PDF "' + source.url + '".', status);
  38228. handler.send('UnexpectedResponse', exception);
  38229. }
  38230. cancelXHRs = null;
  38231. },
  38232. onProgress: function onProgress(evt) {
  38233. handler.send('DocProgress', {
  38234. loaded: evt.loaded,
  38235. total: evt.lengthComputable ? evt.total : source.length
  38236. });
  38237. }
  38238. });
  38239. cancelXHRs = function () {
  38240. networkManager.abortRequest(fullRequestXhrId);
  38241. };
  38242. return pdfManagerCapability.promise;
  38243. }
  38244. var setupDoc = function(data) {
  38245. var onSuccess = function(doc) {
  38246. ensureNotTerminated();
  38247. handler.send('GetDoc', { pdfInfo: doc });
  38248. };
  38249. var onFailure = function(e) {
  38250. if (e instanceof PasswordException) {
  38251. if (e.code === PasswordResponses.NEED_PASSWORD) {
  38252. handler.send('NeedPassword', e);
  38253. } else if (e.code === PasswordResponses.INCORRECT_PASSWORD) {
  38254. handler.send('IncorrectPassword', e);
  38255. }
  38256. } else if (e instanceof InvalidPDFException) {
  38257. handler.send('InvalidPDF', e);
  38258. } else if (e instanceof MissingPDFException) {
  38259. handler.send('MissingPDF', e);
  38260. } else if (e instanceof UnexpectedResponseException) {
  38261. handler.send('UnexpectedResponse', e);
  38262. } else {
  38263. handler.send('UnknownError',
  38264. new UnknownErrorException(e.message, e.toString()));
  38265. }
  38266. };
  38267. ensureNotTerminated();
  38268. PDFJS.maxImageSize = data.maxImageSize === undefined ?
  38269. -1 : data.maxImageSize;
  38270. PDFJS.disableFontFace = data.disableFontFace;
  38271. PDFJS.disableCreateObjectURL = data.disableCreateObjectURL;
  38272. PDFJS.verbosity = data.verbosity;
  38273. PDFJS.cMapUrl = data.cMapUrl === undefined ?
  38274. null : data.cMapUrl;
  38275. PDFJS.cMapPacked = data.cMapPacked === true;
  38276. getPdfManager(data).then(function (newPdfManager) {
  38277. if (terminated) {
  38278. // We were in a process of setting up the manager, but it got
  38279. // terminated in the middle.
  38280. newPdfManager.terminate();
  38281. throw new Error('Worker was terminated');
  38282. }
  38283. pdfManager = newPdfManager;
  38284. handler.send('PDFManagerReady', null);
  38285. pdfManager.onLoadedStream().then(function(stream) {
  38286. handler.send('DataLoaded', { length: stream.bytes.byteLength });
  38287. });
  38288. }).then(function pdfManagerReady() {
  38289. ensureNotTerminated();
  38290. loadDocument(false).then(onSuccess, function loadFailure(ex) {
  38291. ensureNotTerminated();
  38292. // Try again with recoveryMode == true
  38293. if (!(ex instanceof XRefParseException)) {
  38294. if (ex instanceof PasswordException) {
  38295. // after password exception prepare to receive a new password
  38296. // to repeat loading
  38297. pdfManager.passwordChanged().then(pdfManagerReady);
  38298. }
  38299. onFailure(ex);
  38300. return;
  38301. }
  38302. pdfManager.requestLoadedStream();
  38303. pdfManager.onLoadedStream().then(function() {
  38304. ensureNotTerminated();
  38305. loadDocument(true).then(onSuccess, onFailure);
  38306. });
  38307. }, onFailure);
  38308. }, onFailure);
  38309. };
  38310. handler.on('GetPage', function wphSetupGetPage(data) {
  38311. return pdfManager.getPage(data.pageIndex).then(function(page) {
  38312. var rotatePromise = pdfManager.ensure(page, 'rotate');
  38313. var refPromise = pdfManager.ensure(page, 'ref');
  38314. var viewPromise = pdfManager.ensure(page, 'view');
  38315. return Promise.all([rotatePromise, refPromise, viewPromise]).then(
  38316. function(results) {
  38317. return {
  38318. rotate: results[0],
  38319. ref: results[1],
  38320. view: results[2]
  38321. };
  38322. });
  38323. });
  38324. });
  38325. handler.on('GetPageIndex', function wphSetupGetPageIndex(data) {
  38326. var ref = new Ref(data.ref.num, data.ref.gen);
  38327. var catalog = pdfManager.pdfDocument.catalog;
  38328. return catalog.getPageIndex(ref);
  38329. });
  38330. handler.on('GetDestinations',
  38331. function wphSetupGetDestinations(data) {
  38332. return pdfManager.ensureCatalog('destinations');
  38333. }
  38334. );
  38335. handler.on('GetDestination',
  38336. function wphSetupGetDestination(data) {
  38337. return pdfManager.ensureCatalog('getDestination', [data.id]);
  38338. }
  38339. );
  38340. handler.on('GetAttachments',
  38341. function wphSetupGetAttachments(data) {
  38342. return pdfManager.ensureCatalog('attachments');
  38343. }
  38344. );
  38345. handler.on('GetJavaScript',
  38346. function wphSetupGetJavaScript(data) {
  38347. return pdfManager.ensureCatalog('javaScript');
  38348. }
  38349. );
  38350. handler.on('GetOutline',
  38351. function wphSetupGetOutline(data) {
  38352. return pdfManager.ensureCatalog('documentOutline');
  38353. }
  38354. );
  38355. handler.on('GetMetadata',
  38356. function wphSetupGetMetadata(data) {
  38357. return Promise.all([pdfManager.ensureDoc('documentInfo'),
  38358. pdfManager.ensureCatalog('metadata')]);
  38359. }
  38360. );
  38361. handler.on('GetData', function wphSetupGetData(data) {
  38362. pdfManager.requestLoadedStream();
  38363. return pdfManager.onLoadedStream().then(function(stream) {
  38364. return stream.bytes;
  38365. });
  38366. });
  38367. handler.on('GetStats',
  38368. function wphSetupGetStats(data) {
  38369. return pdfManager.pdfDocument.xref.stats;
  38370. }
  38371. );
  38372. handler.on('UpdatePassword', function wphSetupUpdatePassword(data) {
  38373. pdfManager.updatePassword(data);
  38374. });
  38375. handler.on('GetAnnotations', function wphSetupGetAnnotations(data) {
  38376. return pdfManager.getPage(data.pageIndex).then(function(page) {
  38377. return pdfManager.ensure(page, 'getAnnotationsData', [data.intent]);
  38378. });
  38379. });
  38380. handler.on('RenderPageRequest', function wphSetupRenderPage(data) {
  38381. var pageIndex = data.pageIndex;
  38382. pdfManager.getPage(pageIndex).then(function(page) {
  38383. var task = new WorkerTask('RenderPageRequest: page ' + pageIndex);
  38384. startWorkerTask(task);
  38385. var pageNum = pageIndex + 1;
  38386. var start = Date.now();
  38387. // Pre compile the pdf page and fetch the fonts/images.
  38388. page.getOperatorList(handler, task, data.intent).then(
  38389. function(operatorList) {
  38390. finishWorkerTask(task);
  38391. info('page=' + pageNum + ' - getOperatorList: time=' +
  38392. (Date.now() - start) + 'ms, len=' + operatorList.totalLength);
  38393. }, function(e) {
  38394. finishWorkerTask(task);
  38395. if (task.terminated) {
  38396. return; // ignoring errors from the terminated thread
  38397. }
  38398. // For compatibility with older behavior, generating unknown
  38399. // unsupported feature notification on errors.
  38400. handler.send('UnsupportedFeature',
  38401. {featureId: UNSUPPORTED_FEATURES.unknown});
  38402. var minimumStackMessage =
  38403. 'worker.js: while trying to getPage() and getOperatorList()';
  38404. var wrappedException;
  38405. // Turn the error into an obj that can be serialized
  38406. if (typeof e === 'string') {
  38407. wrappedException = {
  38408. message: e,
  38409. stack: minimumStackMessage
  38410. };
  38411. } else if (typeof e === 'object') {
  38412. wrappedException = {
  38413. message: e.message || e.toString(),
  38414. stack: e.stack || minimumStackMessage
  38415. };
  38416. } else {
  38417. wrappedException = {
  38418. message: 'Unknown exception type: ' + (typeof e),
  38419. stack: minimumStackMessage
  38420. };
  38421. }
  38422. handler.send('PageError', {
  38423. pageNum: pageNum,
  38424. error: wrappedException,
  38425. intent: data.intent
  38426. });
  38427. });
  38428. });
  38429. }, this);
  38430. handler.on('GetTextContent', function wphExtractText(data) {
  38431. var pageIndex = data.pageIndex;
  38432. var normalizeWhitespace = data.normalizeWhitespace;
  38433. return pdfManager.getPage(pageIndex).then(function(page) {
  38434. var task = new WorkerTask('GetTextContent: page ' + pageIndex);
  38435. startWorkerTask(task);
  38436. var pageNum = pageIndex + 1;
  38437. var start = Date.now();
  38438. return page.extractTextContent(task, normalizeWhitespace).then(
  38439. function(textContent) {
  38440. finishWorkerTask(task);
  38441. info('text indexing: page=' + pageNum + ' - time=' +
  38442. (Date.now() - start) + 'ms');
  38443. return textContent;
  38444. }, function (reason) {
  38445. finishWorkerTask(task);
  38446. if (task.terminated) {
  38447. return; // ignoring errors from the terminated thread
  38448. }
  38449. throw reason;
  38450. });
  38451. });
  38452. });
  38453. handler.on('Cleanup', function wphCleanup(data) {
  38454. return pdfManager.cleanup();
  38455. });
  38456. handler.on('Terminate', function wphTerminate(data) {
  38457. terminated = true;
  38458. if (pdfManager) {
  38459. pdfManager.terminate();
  38460. pdfManager = null;
  38461. }
  38462. if (cancelXHRs) {
  38463. cancelXHRs();
  38464. }
  38465. var waitOn = [];
  38466. WorkerTasks.forEach(function (task) {
  38467. waitOn.push(task.finished);
  38468. task.terminate();
  38469. });
  38470. return Promise.all(waitOn).then(function () {
  38471. // Notice that even if we destroying handler, resolved response promise
  38472. // must be sent back.
  38473. handler.destroy();
  38474. handler = null;
  38475. });
  38476. });
  38477. handler.on('Ready', function wphReady(data) {
  38478. setupDoc(docParams);
  38479. docParams = null; // we don't need docParams anymore -- saving memory.
  38480. });
  38481. return workerHandlerName;
  38482. }
  38483. };
  38484. var consoleTimer = {};
  38485. var workerConsole = {
  38486. log: function log() {
  38487. var args = Array.prototype.slice.call(arguments);
  38488. globalScope.postMessage({
  38489. targetName: 'main',
  38490. action: 'console_log',
  38491. data: args
  38492. });
  38493. },
  38494. error: function error() {
  38495. var args = Array.prototype.slice.call(arguments);
  38496. globalScope.postMessage({
  38497. targetName: 'main',
  38498. action: 'console_error',
  38499. data: args
  38500. });
  38501. throw 'pdf.js execution error';
  38502. },
  38503. time: function time(name) {
  38504. consoleTimer[name] = Date.now();
  38505. },
  38506. timeEnd: function timeEnd(name) {
  38507. var time = consoleTimer[name];
  38508. if (!time) {
  38509. error('Unknown timer name ' + name);
  38510. }
  38511. this.log('Timer:', name, Date.now() - time);
  38512. }
  38513. };
  38514. // Worker thread?
  38515. if (typeof window === 'undefined' && typeof require === 'undefined') {
  38516. if (!('console' in globalScope)) {
  38517. globalScope.console = workerConsole;
  38518. }
  38519. var handler = new MessageHandler('worker', 'main', self);
  38520. WorkerMessageHandler.setup(handler, self);
  38521. }
  38522. exports.WorkerTask = WorkerTask;
  38523. exports.WorkerMessageHandler = WorkerMessageHandler;
  38524. }));
  38525. }).call((typeof window === 'undefined') ? this : window);
  38526. if (!PDFJS.workerSrc && typeof document !== 'undefined') {
  38527. // workerSrc is not set -- using last script url to define default location
  38528. PDFJS.workerSrc = (function () {
  38529. 'use strict';
  38530. var pdfJsSrc = document.currentScript.src;
  38531. return pdfJsSrc && pdfJsSrc.replace(/\.js$/i, '.worker.js');
  38532. })();
  38533. }